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/. */
13 #include "mozilla/gfx/BaseMargin.h"
14 #include "mozilla/gfx/BaseRect.h"
15 #include "mozilla/Assertions.h"
17 struct gfxMargin
: public mozilla::gfx::BaseMargin
<gfxFloat
, gfxMargin
> {
18 typedef mozilla::gfx::BaseMargin
<gfxFloat
, gfxMargin
> Super
;
21 gfxMargin() : Super() {}
22 gfxMargin(const gfxMargin
& aMargin
) : Super(aMargin
) {}
23 gfxMargin(gfxFloat aTop
, gfxFloat aRight
, gfxFloat aBottom
, gfxFloat aLeft
)
24 : Super(aTop
, aRight
, aBottom
, aLeft
) {}
30 // this order is important!
33 eCornerBottomRight
= 2,
34 eCornerBottomLeft
= 3,
39 #define NS_CORNER_TOP_LEFT mozilla::css::eCornerTopLeft
40 #define NS_CORNER_TOP_RIGHT mozilla::css::eCornerTopRight
41 #define NS_CORNER_BOTTOM_RIGHT mozilla::css::eCornerBottomRight
42 #define NS_CORNER_BOTTOM_LEFT mozilla::css::eCornerBottomLeft
43 #define NS_NUM_CORNERS mozilla::css::eNumCorners
45 #define NS_FOR_CSS_CORNERS(var_) \
46 for (mozilla::css::Corner var_ = NS_CORNER_TOP_LEFT; \
47 var_ <= NS_CORNER_BOTTOM_LEFT; \
50 static inline mozilla::css::Corner
operator++(mozilla::css::Corner
& corner
, int) {
51 NS_PRECONDITION(corner
>= NS_CORNER_TOP_LEFT
&&
52 corner
< NS_NUM_CORNERS
, "Out of range corner");
53 corner
= mozilla::css::Corner(corner
+ 1);
58 public mozilla::gfx::BaseRect
<gfxFloat
, gfxRect
, gfxPoint
, gfxSize
, gfxMargin
> {
59 typedef mozilla::gfx::BaseRect
<gfxFloat
, gfxRect
, gfxPoint
, gfxSize
, gfxMargin
> Super
;
61 gfxRect() : Super() {}
62 gfxRect(const gfxPoint
& aPos
, const gfxSize
& aSize
) :
64 gfxRect(gfxFloat aX
, gfxFloat aY
, gfxFloat aWidth
, gfxFloat aHeight
) :
65 Super(aX
, aY
, aWidth
, aHeight
) {}
66 MOZ_IMPLICIT
gfxRect(const nsIntRect
& aRect
) :
67 Super(aRect
.x
, aRect
.y
, aRect
.width
, aRect
.height
) {}
70 * Return true if all components of this rect are within
71 * aEpsilon of integer coordinates, defined as
72 * |round(coord) - coord| <= |aEpsilon|
73 * for x,y,width,height.
75 bool WithinEpsilonOfIntegerPixels(gfxFloat aEpsilon
) const;
77 gfxPoint
AtCorner(mozilla::css::Corner corner
) const {
79 case NS_CORNER_TOP_LEFT
: return TopLeft();
80 case NS_CORNER_TOP_RIGHT
: return TopRight();
81 case NS_CORNER_BOTTOM_RIGHT
: return BottomRight();
82 case NS_CORNER_BOTTOM_LEFT
: return BottomLeft();
84 NS_ERROR("Invalid corner!");
87 return gfxPoint(0.0, 0.0);
90 gfxPoint
CCWCorner(mozilla::Side side
) const {
92 case NS_SIDE_TOP
: return TopLeft();
93 case NS_SIDE_RIGHT
: return TopRight();
94 case NS_SIDE_BOTTOM
: return BottomRight();
95 case NS_SIDE_LEFT
: return BottomLeft();
97 MOZ_CRASH("Incomplete switch");
100 gfxPoint
CWCorner(mozilla::Side side
) const {
102 case NS_SIDE_TOP
: return TopRight();
103 case NS_SIDE_RIGHT
: return BottomRight();
104 case NS_SIDE_BOTTOM
: return BottomLeft();
105 case NS_SIDE_LEFT
: return TopLeft();
107 MOZ_CRASH("Incomplete switch");
110 /* Conditions this border to Cairo's max coordinate space.
111 * The caller can check IsEmpty() after Condition() -- if it's TRUE,
112 * the caller can possibly avoid doing any extra rendering.
116 void Scale(gfxFloat k
) {
117 NS_ASSERTION(k
>= 0.0, "Invalid (negative) scale factor");
124 void Scale(gfxFloat sx
, gfxFloat sy
) {
125 NS_ASSERTION(sx
>= 0.0, "Invalid (negative) scale factor");
126 NS_ASSERTION(sy
>= 0.0, "Invalid (negative) scale factor");
133 void ScaleInverse(gfxFloat k
) {
134 NS_ASSERTION(k
> 0.0, "Invalid (negative) scale factor");
142 #endif /* GFX_RECT_H */