Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
michael@0 | 2 | * This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #include "gfxRect.h" |
michael@0 | 7 | |
michael@0 | 8 | namespace mozilla { |
michael@0 | 9 | /* A rounded rectangle abstraction. |
michael@0 | 10 | * |
michael@0 | 11 | * This can represent a rectangle with a different pair of radii on each corner. |
michael@0 | 12 | * |
michael@0 | 13 | * Note: CoreGraphics and Direct2D only support rounded rectangle with the same |
michael@0 | 14 | * radii on all corners. However, supporting CSS's border-radius requires the extra flexibility. */ |
michael@0 | 15 | struct RoundedRect { |
michael@0 | 16 | RoundedRect(gfxRect &aRect, gfxCornerSizes &aCorners) : rect(aRect), corners(aCorners) { } |
michael@0 | 17 | void Deflate(gfxFloat aTopWidth, gfxFloat aBottomWidth, gfxFloat aLeftWidth, gfxFloat aRightWidth) { |
michael@0 | 18 | // deflate the internal rect |
michael@0 | 19 | rect.x += aLeftWidth; |
michael@0 | 20 | rect.y += aTopWidth; |
michael@0 | 21 | rect.width = std::max(0., rect.width - aLeftWidth - aRightWidth); |
michael@0 | 22 | rect.height = std::max(0., rect.height - aTopWidth - aBottomWidth); |
michael@0 | 23 | |
michael@0 | 24 | corners.sizes[NS_CORNER_TOP_LEFT].width = std::max(0., corners.sizes[NS_CORNER_TOP_LEFT].width - aLeftWidth); |
michael@0 | 25 | corners.sizes[NS_CORNER_TOP_LEFT].height = std::max(0., corners.sizes[NS_CORNER_TOP_LEFT].height - aTopWidth); |
michael@0 | 26 | |
michael@0 | 27 | corners.sizes[NS_CORNER_TOP_RIGHT].width = std::max(0., corners.sizes[NS_CORNER_TOP_RIGHT].width - aRightWidth); |
michael@0 | 28 | corners.sizes[NS_CORNER_TOP_RIGHT].height = std::max(0., corners.sizes[NS_CORNER_TOP_RIGHT].height - aTopWidth); |
michael@0 | 29 | |
michael@0 | 30 | corners.sizes[NS_CORNER_BOTTOM_LEFT].width = std::max(0., corners.sizes[NS_CORNER_BOTTOM_LEFT].width - aLeftWidth); |
michael@0 | 31 | corners.sizes[NS_CORNER_BOTTOM_LEFT].height = std::max(0., corners.sizes[NS_CORNER_BOTTOM_LEFT].height - aBottomWidth); |
michael@0 | 32 | |
michael@0 | 33 | corners.sizes[NS_CORNER_BOTTOM_RIGHT].width = std::max(0., corners.sizes[NS_CORNER_BOTTOM_RIGHT].width - aRightWidth); |
michael@0 | 34 | corners.sizes[NS_CORNER_BOTTOM_RIGHT].height = std::max(0., corners.sizes[NS_CORNER_BOTTOM_RIGHT].height - aBottomWidth); |
michael@0 | 35 | } |
michael@0 | 36 | gfxRect rect; |
michael@0 | 37 | gfxCornerSizes corners; |
michael@0 | 38 | }; |
michael@0 | 39 | |
michael@0 | 40 | } // namespace mozilla |