Merge m-c to inbound.
[gecko.git] / gfx / thebes / RoundedRect.h
blobd14d08610442f049e8a0d74e1a09c98756445673
1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "gfxRect.h"
8 namespace mozilla {
9 /* A rounded rectangle abstraction.
11 * This can represent a rectangle with a different pair of radii on each corner.
13 * Note: CoreGraphics and Direct2D only support rounded rectangle with the same
14 * radii on all corners. However, supporting CSS's border-radius requires the extra flexibility. */
15 struct RoundedRect {
16 RoundedRect(gfxRect &aRect, gfxCornerSizes &aCorners) : rect(aRect), corners(aCorners) { }
17 void Deflate(gfxFloat aTopWidth, gfxFloat aBottomWidth, gfxFloat aLeftWidth, gfxFloat aRightWidth) {
18 // deflate the internal rect
19 rect.x += aLeftWidth;
20 rect.y += aTopWidth;
21 rect.width = std::max(0., rect.width - aLeftWidth - aRightWidth);
22 rect.height = std::max(0., rect.height - aTopWidth - aBottomWidth);
24 corners.sizes[NS_CORNER_TOP_LEFT].width = std::max(0., corners.sizes[NS_CORNER_TOP_LEFT].width - aLeftWidth);
25 corners.sizes[NS_CORNER_TOP_LEFT].height = std::max(0., corners.sizes[NS_CORNER_TOP_LEFT].height - aTopWidth);
27 corners.sizes[NS_CORNER_TOP_RIGHT].width = std::max(0., corners.sizes[NS_CORNER_TOP_RIGHT].width - aRightWidth);
28 corners.sizes[NS_CORNER_TOP_RIGHT].height = std::max(0., corners.sizes[NS_CORNER_TOP_RIGHT].height - aTopWidth);
30 corners.sizes[NS_CORNER_BOTTOM_LEFT].width = std::max(0., corners.sizes[NS_CORNER_BOTTOM_LEFT].width - aLeftWidth);
31 corners.sizes[NS_CORNER_BOTTOM_LEFT].height = std::max(0., corners.sizes[NS_CORNER_BOTTOM_LEFT].height - aBottomWidth);
33 corners.sizes[NS_CORNER_BOTTOM_RIGHT].width = std::max(0., corners.sizes[NS_CORNER_BOTTOM_RIGHT].width - aRightWidth);
34 corners.sizes[NS_CORNER_BOTTOM_RIGHT].height = std::max(0., corners.sizes[NS_CORNER_BOTTOM_RIGHT].height - aBottomWidth);
36 gfxRect rect;
37 gfxCornerSizes corners;
40 } // namespace mozilla