Line data Source code
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/. */
5 :
6 : #ifndef ROUNDED_RECT_H
7 : #define ROUNDED_RECT_H
8 :
9 : #include "gfxRect.h"
10 : #include "gfxTypes.h"
11 : #include "mozilla/gfx/PathHelpers.h"
12 :
13 : namespace mozilla {
14 : /* A rounded rectangle abstraction.
15 : *
16 : * This can represent a rectangle with a different pair of radii on each corner.
17 : *
18 : * Note: CoreGraphics and Direct2D only support rounded rectangle with the same
19 : * radii on all corners. However, supporting CSS's border-radius requires the extra flexibility. */
20 : struct RoundedRect {
21 : typedef mozilla::gfx::RectCornerRadii RectCornerRadii;
22 :
23 17 : RoundedRect(gfxRect &aRect, RectCornerRadii &aCorners) : rect(aRect), corners(aCorners) { }
24 17 : void Deflate(gfxFloat aTopWidth, gfxFloat aBottomWidth, gfxFloat aLeftWidth, gfxFloat aRightWidth) {
25 : // deflate the internal rect
26 17 : rect.x += aLeftWidth;
27 17 : rect.y += aTopWidth;
28 17 : rect.width = std::max(0., rect.width - aLeftWidth - aRightWidth);
29 17 : rect.height = std::max(0., rect.height - aTopWidth - aBottomWidth);
30 :
31 17 : corners.radii[mozilla::eCornerTopLeft].width =
32 34 : std::max(0., corners.radii[mozilla::eCornerTopLeft].width - aLeftWidth);
33 17 : corners.radii[mozilla::eCornerTopLeft].height =
34 34 : std::max(0., corners.radii[mozilla::eCornerTopLeft].height - aTopWidth);
35 :
36 17 : corners.radii[mozilla::eCornerTopRight].width =
37 34 : std::max(0., corners.radii[mozilla::eCornerTopRight].width - aRightWidth);
38 17 : corners.radii[mozilla::eCornerTopRight].height =
39 34 : std::max(0., corners.radii[mozilla::eCornerTopRight].height - aTopWidth);
40 :
41 17 : corners.radii[mozilla::eCornerBottomLeft].width =
42 34 : std::max(0., corners.radii[mozilla::eCornerBottomLeft].width - aLeftWidth);
43 17 : corners.radii[mozilla::eCornerBottomLeft].height =
44 34 : std::max(0., corners.radii[mozilla::eCornerBottomLeft].height - aBottomWidth);
45 :
46 17 : corners.radii[mozilla::eCornerBottomRight].width =
47 34 : std::max(0., corners.radii[mozilla::eCornerBottomRight].width - aRightWidth);
48 17 : corners.radii[mozilla::eCornerBottomRight].height =
49 34 : std::max(0., corners.radii[mozilla::eCornerBottomRight].height - aBottomWidth);
50 17 : }
51 : gfxRect rect;
52 : RectCornerRadii corners;
53 : };
54 :
55 : } // namespace mozilla
56 :
57 : #endif
|