Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dist/include/mozilla/gfx/Rect.h
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
3
/* This Source Code Form is subject to the terms of the Mozilla Public
4
 * License, v. 2.0. If a copy of the MPL was not distributed with this
5
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#ifndef MOZILLA_GFX_RECT_H_
8
#define MOZILLA_GFX_RECT_H_
9
10
#include "BaseRect.h"
11
#include "BaseMargin.h"
12
#include "NumericTools.h"
13
#include "Point.h"
14
#include "Tools.h"
15
#include "mozilla/Maybe.h"
16
17
#include <cmath>
18
19
namespace mozilla {
20
21
template <typename> struct IsPixel;
22
23
namespace gfx {
24
25
template<class units, class F> struct RectTyped;
26
27
template<class units>
28
struct IntMarginTyped:
29
    public BaseMargin<int32_t, IntMarginTyped<units> >,
30
    public units {
31
    static_assert(IsPixel<units>::value,
32
                  "'units' must be a coordinate system tag");
33
34
    typedef BaseMargin<int32_t, IntMarginTyped<units> > Super;
35
36
0
    IntMarginTyped() : Super() {}
Unexecuted instantiation: mozilla::gfx::IntMarginTyped<mozilla::gfx::UnknownUnits>::IntMarginTyped()
Unexecuted instantiation: mozilla::gfx::IntMarginTyped<mozilla::LayoutDevicePixel>::IntMarginTyped()
37
    IntMarginTyped(int32_t aTop, int32_t aRight, int32_t aBottom, int32_t aLeft) :
38
0
        Super(aTop, aRight, aBottom, aLeft) {}
Unexecuted instantiation: mozilla::gfx::IntMarginTyped<mozilla::gfx::UnknownUnits>::IntMarginTyped(int, int, int, int)
Unexecuted instantiation: mozilla::gfx::IntMarginTyped<mozilla::LayoutDevicePixel>::IntMarginTyped(int, int, int, int)
39
40
    // XXX When all of the code is ported, the following functions to convert
41
    // to and from unknown types should be removed.
42
43
0
    static IntMarginTyped<units> FromUnknownMargin(const IntMarginTyped<UnknownUnits>& aMargin) {
44
0
        return IntMarginTyped<units>(aMargin.top, aMargin.right,
45
0
                                     aMargin.bottom, aMargin.left);
46
0
    }
47
48
    IntMarginTyped<UnknownUnits> ToUnknownMargin() const {
49
        return IntMarginTyped<UnknownUnits>(this->top, this->right,
50
                                            this->bottom, this->left);
51
    }
52
};
53
typedef IntMarginTyped<UnknownUnits> IntMargin;
54
55
template<class units, class F = Float>
56
struct MarginTyped:
57
    public BaseMargin<F, MarginTyped<units, F> >,
58
    public units {
59
    static_assert(IsPixel<units>::value,
60
                  "'units' must be a coordinate system tag");
61
62
    typedef BaseMargin<F, MarginTyped<units, F> > Super;
63
64
0
    MarginTyped() : Super() {}
Unexecuted instantiation: mozilla::gfx::MarginTyped<mozilla::ScreenPixel, float>::MarginTyped()
Unexecuted instantiation: mozilla::gfx::MarginTyped<mozilla::CSSPixel, float>::MarginTyped()
Unexecuted instantiation: mozilla::gfx::MarginTyped<mozilla::gfx::UnknownUnits, float>::MarginTyped()
65
    MarginTyped(F aTop, F aRight, F aBottom, F aLeft) :
66
0
        Super(aTop, aRight, aBottom, aLeft) {}
Unexecuted instantiation: mozilla::gfx::MarginTyped<mozilla::ScreenPixel, float>::MarginTyped(float, float, float, float)
Unexecuted instantiation: mozilla::gfx::MarginTyped<mozilla::gfx::UnknownUnits, double>::MarginTyped(double, double, double, double)
Unexecuted instantiation: mozilla::gfx::MarginTyped<mozilla::gfx::UnknownUnits, float>::MarginTyped(float, float, float, float)
Unexecuted instantiation: mozilla::gfx::MarginTyped<mozilla::CSSPixel, float>::MarginTyped(float, float, float, float)
Unexecuted instantiation: mozilla::gfx::MarginTyped<mozilla::ParentLayerPixel, float>::MarginTyped(float, float, float, float)
Unexecuted instantiation: mozilla::gfx::MarginTyped<mozilla::LayoutDevicePixel, float>::MarginTyped(float, float, float, float)
67
    explicit MarginTyped(const IntMarginTyped<units>& aMargin) :
68
        Super(F(aMargin.top), F(aMargin.right),
69
0
              F(aMargin.bottom), F(aMargin.left)) {}
70
};
71
typedef MarginTyped<UnknownUnits> Margin;
72
typedef MarginTyped<UnknownUnits, double> MarginDouble;
73
74
template<class units>
75
IntMarginTyped<units> RoundedToInt(const MarginTyped<units>& aMargin)
76
{
77
  return IntMarginTyped<units>(int32_t(floorf(aMargin.top + 0.5f)),
78
                               int32_t(floorf(aMargin.right + 0.5f)),
79
                               int32_t(floorf(aMargin.bottom + 0.5f)),
80
                               int32_t(floorf(aMargin.left + 0.5f)));
81
}
82
83
template<class units>
84
struct IntRectTyped :
85
    public BaseRect<int32_t, IntRectTyped<units>, IntPointTyped<units>, IntSizeTyped<units>, IntMarginTyped<units> >,
86
    public units {
87
    static_assert(IsPixel<units>::value,
88
                  "'units' must be a coordinate system tag");
89
90
    typedef BaseRect<int32_t, IntRectTyped<units>, IntPointTyped<units>, IntSizeTyped<units>, IntMarginTyped<units> > Super;
91
    typedef IntRectTyped<units> Self;
92
    typedef IntParam<int32_t> ToInt;
93
94
0
    IntRectTyped() : Super() {}
Unexecuted instantiation: mozilla::gfx::IntRectTyped<mozilla::gfx::UnknownUnits>::IntRectTyped()
Unexecuted instantiation: mozilla::gfx::IntRectTyped<mozilla::LayerPixel>::IntRectTyped()
Unexecuted instantiation: mozilla::gfx::IntRectTyped<mozilla::ParentLayerPixel>::IntRectTyped()
Unexecuted instantiation: mozilla::gfx::IntRectTyped<mozilla::LayoutDevicePixel>::IntRectTyped()
Unexecuted instantiation: mozilla::gfx::IntRectTyped<mozilla::DesktopPixel>::IntRectTyped()
Unexecuted instantiation: mozilla::gfx::IntRectTyped<mozilla::ImagePixel>::IntRectTyped()
Unexecuted instantiation: mozilla::gfx::IntRectTyped<mozilla::RenderTargetPixel>::IntRectTyped()
Unexecuted instantiation: mozilla::gfx::IntRectTyped<mozilla::CSSPixel>::IntRectTyped()
95
    IntRectTyped(const IntPointTyped<units>& aPos, const IntSizeTyped<units>& aSize) :
96
0
        Super(aPos, aSize) {}
Unexecuted instantiation: mozilla::gfx::IntRectTyped<mozilla::gfx::UnknownUnits>::IntRectTyped(mozilla::gfx::IntPointTyped<mozilla::gfx::UnknownUnits> const&, mozilla::gfx::IntSizeTyped<mozilla::gfx::UnknownUnits> const&)
Unexecuted instantiation: mozilla::gfx::IntRectTyped<mozilla::RenderTargetPixel>::IntRectTyped(mozilla::gfx::IntPointTyped<mozilla::RenderTargetPixel> const&, mozilla::gfx::IntSizeTyped<mozilla::RenderTargetPixel> const&)
Unexecuted instantiation: mozilla::gfx::IntRectTyped<mozilla::LayerPixel>::IntRectTyped(mozilla::gfx::IntPointTyped<mozilla::LayerPixel> const&, mozilla::gfx::IntSizeTyped<mozilla::LayerPixel> const&)
Unexecuted instantiation: mozilla::gfx::IntRectTyped<mozilla::LayoutDevicePixel>::IntRectTyped(mozilla::gfx::IntPointTyped<mozilla::LayoutDevicePixel> const&, mozilla::gfx::IntSizeTyped<mozilla::LayoutDevicePixel> const&)
97
98
    IntRectTyped(ToInt aX, ToInt aY, ToInt aWidth, ToInt aHeight) :
99
3
        Super(aX.value, aY.value, aWidth.value, aHeight.value) {}
mozilla::gfx::IntRectTyped<mozilla::gfx::UnknownUnits>::IntRectTyped(mozilla::gfx::IntParam<int>, mozilla::gfx::IntParam<int>, mozilla::gfx::IntParam<int>, mozilla::gfx::IntParam<int>)
Line
Count
Source
99
3
        Super(aX.value, aY.value, aWidth.value, aHeight.value) {}
Unexecuted instantiation: mozilla::gfx::IntRectTyped<mozilla::LayerPixel>::IntRectTyped(mozilla::gfx::IntParam<int>, mozilla::gfx::IntParam<int>, mozilla::gfx::IntParam<int>, mozilla::gfx::IntParam<int>)
Unexecuted instantiation: mozilla::gfx::IntRectTyped<mozilla::LayoutDevicePixel>::IntRectTyped(mozilla::gfx::IntParam<int>, mozilla::gfx::IntParam<int>, mozilla::gfx::IntParam<int>, mozilla::gfx::IntParam<int>)
Unexecuted instantiation: mozilla::gfx::IntRectTyped<mozilla::ParentLayerPixel>::IntRectTyped(mozilla::gfx::IntParam<int>, mozilla::gfx::IntParam<int>, mozilla::gfx::IntParam<int>, mozilla::gfx::IntParam<int>)
Unexecuted instantiation: mozilla::gfx::IntRectTyped<mozilla::RenderTargetPixel>::IntRectTyped(mozilla::gfx::IntParam<int>, mozilla::gfx::IntParam<int>, mozilla::gfx::IntParam<int>, mozilla::gfx::IntParam<int>)
Unexecuted instantiation: mozilla::gfx::IntRectTyped<mozilla::ImagePixel>::IntRectTyped(mozilla::gfx::IntParam<int>, mozilla::gfx::IntParam<int>, mozilla::gfx::IntParam<int>, mozilla::gfx::IntParam<int>)
Unexecuted instantiation: mozilla::gfx::IntRectTyped<mozilla::CSSPixel>::IntRectTyped(mozilla::gfx::IntParam<int>, mozilla::gfx::IntParam<int>, mozilla::gfx::IntParam<int>, mozilla::gfx::IntParam<int>)
Unexecuted instantiation: mozilla::gfx::IntRectTyped<mozilla::ScreenPixel>::IntRectTyped(mozilla::gfx::IntParam<int>, mozilla::gfx::IntParam<int>, mozilla::gfx::IntParam<int>, mozilla::gfx::IntParam<int>)
Unexecuted instantiation: mozilla::gfx::IntRectTyped<mozilla::DesktopPixel>::IntRectTyped(mozilla::gfx::IntParam<int>, mozilla::gfx::IntParam<int>, mozilla::gfx::IntParam<int>, mozilla::gfx::IntParam<int>)
100
101
0
    static IntRectTyped<units> RoundIn(float aX, float aY, float aW, float aH) {
102
0
      return IntRectTyped<units>::RoundIn(RectTyped<units, float>(aX, aY, aW, aH));
103
0
    }
104
105
0
    static IntRectTyped<units> RoundOut(float aX, float aY, float aW, float aH) {
106
0
      return IntRectTyped<units>::RoundOut(RectTyped<units, float>(aX, aY, aW, aH));
107
0
    }
108
109
    static IntRectTyped<units> Round(float aX, float aY, float aW, float aH) {
110
      return IntRectTyped<units>::Round(RectTyped<units, float>(aX, aY, aW, aH));
111
    }
112
113
0
    static IntRectTyped<units> Truncate(float aX, float aY, float aW, float aH) {
114
0
      return IntRectTyped<units>(IntPointTyped<units>::Truncate(aX, aY),
115
0
                                 IntSizeTyped<units>::Truncate(aW, aH));
116
0
    }
Unexecuted instantiation: mozilla::gfx::IntRectTyped<mozilla::gfx::UnknownUnits>::Truncate(float, float, float, float)
Unexecuted instantiation: mozilla::gfx::IntRectTyped<mozilla::LayoutDevicePixel>::Truncate(float, float, float, float)
117
118
0
    static IntRectTyped<units> RoundIn(const RectTyped<units, float>& aRect) {
119
0
      auto tmp(aRect);
120
0
      tmp.RoundIn();
121
0
      return IntRectTyped(int32_t(tmp.X()), int32_t(tmp.Y()),
122
0
                          int32_t(tmp.Width()), int32_t(tmp.Height()));
123
0
    }
Unexecuted instantiation: mozilla::gfx::IntRectTyped<mozilla::gfx::UnknownUnits>::RoundIn(mozilla::gfx::RectTyped<mozilla::gfx::UnknownUnits, float> const&)
Unexecuted instantiation: mozilla::gfx::IntRectTyped<mozilla::CSSPixel>::RoundIn(mozilla::gfx::RectTyped<mozilla::CSSPixel, float> const&)
124
125
0
    static IntRectTyped<units> RoundOut(const RectTyped<units, float>& aRect) {
126
0
      auto tmp(aRect);
127
0
      tmp.RoundOut();
128
0
      return IntRectTyped(int32_t(tmp.X()), int32_t(tmp.Y()),
129
0
                          int32_t(tmp.Width()), int32_t(tmp.Height()));
130
0
    }
Unexecuted instantiation: mozilla::gfx::IntRectTyped<mozilla::gfx::UnknownUnits>::RoundOut(mozilla::gfx::RectTyped<mozilla::gfx::UnknownUnits, float> const&)
Unexecuted instantiation: mozilla::gfx::IntRectTyped<mozilla::CSSPixel>::RoundOut(mozilla::gfx::RectTyped<mozilla::CSSPixel, float> const&)
Unexecuted instantiation: mozilla::gfx::IntRectTyped<mozilla::LayerPixel>::RoundOut(mozilla::gfx::RectTyped<mozilla::LayerPixel, float> const&)
Unexecuted instantiation: mozilla::gfx::IntRectTyped<mozilla::ParentLayerPixel>::RoundOut(mozilla::gfx::RectTyped<mozilla::ParentLayerPixel, float> const&)
131
132
    static IntRectTyped<units> Round(const RectTyped<units, float>& aRect) {
133
      auto tmp(aRect);
134
      tmp.Round();
135
      return IntRectTyped(int32_t(tmp.X()), int32_t(tmp.Y()),
136
                          int32_t(tmp.Width()), int32_t(tmp.Height()));
137
    }
138
139
0
    static IntRectTyped<units> Truncate(const RectTyped<units, float>& aRect) {
140
0
      return IntRectTyped::Truncate(aRect.X(), aRect.Y(), aRect.Width(), aRect.Height());
141
0
    }
142
143
    // Rounding isn't meaningful on an integer rectangle.
144
    void Round() {}
145
    void RoundIn() {}
146
    void RoundOut() {}
147
148
    // XXX When all of the code is ported, the following functions to convert
149
    // to and from unknown types should be removed.
150
151
0
    static IntRectTyped<units> FromUnknownRect(const IntRectTyped<UnknownUnits>& rect) {
152
0
      return IntRectTyped<units>(rect.X(), rect.Y(), rect.Width(), rect.Height());
153
0
    }
Unexecuted instantiation: mozilla::gfx::IntRectTyped<mozilla::CSSPixel>::FromUnknownRect(mozilla::gfx::IntRectTyped<mozilla::gfx::UnknownUnits> const&)
Unexecuted instantiation: mozilla::gfx::IntRectTyped<mozilla::LayoutDevicePixel>::FromUnknownRect(mozilla::gfx::IntRectTyped<mozilla::gfx::UnknownUnits> const&)
Unexecuted instantiation: mozilla::gfx::IntRectTyped<mozilla::RenderTargetPixel>::FromUnknownRect(mozilla::gfx::IntRectTyped<mozilla::gfx::UnknownUnits> const&)
Unexecuted instantiation: mozilla::gfx::IntRectTyped<mozilla::LayerPixel>::FromUnknownRect(mozilla::gfx::IntRectTyped<mozilla::gfx::UnknownUnits> const&)
154
155
0
    IntRectTyped<UnknownUnits> ToUnknownRect() const {
156
0
      return IntRectTyped<UnknownUnits>(this->X(), this->Y(), this->Width(), this->Height());
157
0
    }
Unexecuted instantiation: mozilla::gfx::IntRectTyped<mozilla::gfx::UnknownUnits>::ToUnknownRect() const
Unexecuted instantiation: mozilla::gfx::IntRectTyped<mozilla::LayerPixel>::ToUnknownRect() const
Unexecuted instantiation: mozilla::gfx::IntRectTyped<mozilla::ParentLayerPixel>::ToUnknownRect() const
Unexecuted instantiation: mozilla::gfx::IntRectTyped<mozilla::RenderTargetPixel>::ToUnknownRect() const
Unexecuted instantiation: mozilla::gfx::IntRectTyped<mozilla::LayoutDevicePixel>::ToUnknownRect() const
158
159
0
    bool Overflows() const {
160
0
      CheckedInt<int32_t> xMost = this->X();
161
0
      xMost += this->Width();
162
0
      CheckedInt<int32_t> yMost = this->Y();
163
0
      yMost += this->Height();
164
0
      return !xMost.isValid() || !yMost.isValid();
165
0
    }
166
167
    // Same as Union(), but in the cases where aRect is non-empty, the union is
168
    // done while guarding against overflow. If an overflow is detected, Nothing
169
    // is returned.
170
    MOZ_MUST_USE Maybe<Self> SafeUnion(const Self& aRect) const
171
0
    {
172
0
      if (this->IsEmpty()) {
173
0
        return aRect.Overflows() ? Nothing() : Some(aRect);
174
0
      } else if (aRect.IsEmpty()) {
175
0
        return Some(*static_cast<const Self*>(this));
176
0
      } else {
177
0
        return this->SafeUnionEdges(aRect);
178
0
      }
179
0
    }
180
181
    // Same as UnionEdges, but guards against overflow. If an overflow is detected,
182
    // Nothing is returned.
183
    MOZ_MUST_USE Maybe<Self> SafeUnionEdges(const Self& aRect) const
184
0
    {
185
0
      if (this->Overflows() || aRect.Overflows()) {
186
0
        return Nothing();
187
0
      }
188
0
      // If neither |this| nor |aRect| overflow, then their XMost/YMost values
189
0
      // should be safe to use.
190
0
      CheckedInt<int32_t> newX = std::min(this->x, aRect.x);
191
0
      CheckedInt<int32_t> newY = std::min(this->y, aRect.y);
192
0
      CheckedInt<int32_t> newXMost = std::max(this->XMost(), aRect.XMost());
193
0
      CheckedInt<int32_t> newYMost = std::max(this->YMost(), aRect.YMost());
194
0
      CheckedInt<int32_t> newW = newXMost - newX;
195
0
      CheckedInt<int32_t> newH = newYMost - newY;
196
0
      if (!newW.isValid() || !newH.isValid()) {
197
0
        return Nothing();
198
0
      }
199
0
      return Some(Self(newX.value(), newY.value(), newW.value(), newH.value()));
200
0
    }
201
202
    // This is here only to keep IPDL-generated code happy. DO NOT USE.
203
    bool operator==(const IntRectTyped<units>& aRect) const
204
0
    {
205
0
      return IntRectTyped<units>::IsEqualEdges(aRect);
206
0
    }
Unexecuted instantiation: mozilla::gfx::IntRectTyped<mozilla::ParentLayerPixel>::operator==(mozilla::gfx::IntRectTyped<mozilla::ParentLayerPixel> const&) const
Unexecuted instantiation: mozilla::gfx::IntRectTyped<mozilla::LayoutDevicePixel>::operator==(mozilla::gfx::IntRectTyped<mozilla::LayoutDevicePixel> const&) const
Unexecuted instantiation: mozilla::gfx::IntRectTyped<mozilla::DesktopPixel>::operator==(mozilla::gfx::IntRectTyped<mozilla::DesktopPixel> const&) const
Unexecuted instantiation: mozilla::gfx::IntRectTyped<mozilla::gfx::UnknownUnits>::operator==(mozilla::gfx::IntRectTyped<mozilla::gfx::UnknownUnits> const&) const
Unexecuted instantiation: mozilla::gfx::IntRectTyped<mozilla::ImagePixel>::operator==(mozilla::gfx::IntRectTyped<mozilla::ImagePixel> const&) const
207
208
    void InflateToMultiple(const IntSizeTyped<units>& aTileSize)
209
0
    {
210
0
      if (this->IsEmpty()) {
211
0
        return;
212
0
      }
213
0
214
0
      int32_t yMost = this->YMost();
215
0
      int32_t xMost = this->XMost();
216
0
217
0
      this->x = mozilla::RoundDownToMultiple(this->x, aTileSize.width);
218
0
      this->y = mozilla::RoundDownToMultiple(this->y, aTileSize.height);
219
0
      xMost = mozilla::RoundUpToMultiple(xMost, aTileSize.width);
220
0
      yMost = mozilla::RoundUpToMultiple(yMost, aTileSize.height);
221
0
222
0
      this->SetWidth(xMost - this->x);
223
0
      this->SetHeight(yMost - this->y);
224
0
    }
225
226
};
227
typedef IntRectTyped<UnknownUnits> IntRect;
228
229
template<class units, class F = Float>
230
struct RectTyped :
231
    public BaseRect<F, RectTyped<units, F>, PointTyped<units, F>, SizeTyped<units, F>, MarginTyped<units, F> >,
232
    public units {
233
    static_assert(IsPixel<units>::value,
234
                  "'units' must be a coordinate system tag");
235
236
    typedef BaseRect<F, RectTyped<units, F>, PointTyped<units, F>, SizeTyped<units, F>, MarginTyped<units, F> > Super;
237
238
0
    RectTyped() : Super() {}
Unexecuted instantiation: mozilla::gfx::RectTyped<mozilla::CSSPixel, float>::RectTyped()
Unexecuted instantiation: mozilla::gfx::RectTyped<mozilla::gfx::UnknownUnits, float>::RectTyped()
Unexecuted instantiation: mozilla::gfx::RectTyped<mozilla::LayoutDevicePixel, float>::RectTyped()
Unexecuted instantiation: mozilla::gfx::RectTyped<mozilla::gfx::UnknownUnits, double>::RectTyped()
Unexecuted instantiation: mozilla::gfx::RectTyped<mozilla::LayerPixel, float>::RectTyped()
Unexecuted instantiation: mozilla::gfx::RectTyped<mozilla::ParentLayerPixel, float>::RectTyped()
239
    RectTyped(const PointTyped<units, F>& aPos, const SizeTyped<units, F>& aSize) :
240
0
        Super(aPos, aSize) {}
Unexecuted instantiation: mozilla::gfx::RectTyped<mozilla::gfx::UnknownUnits, float>::RectTyped(mozilla::gfx::PointTyped<mozilla::gfx::UnknownUnits, float> const&, mozilla::gfx::SizeTyped<mozilla::gfx::UnknownUnits, float> const&)
Unexecuted instantiation: mozilla::gfx::RectTyped<mozilla::CSSPixel, float>::RectTyped(mozilla::gfx::PointTyped<mozilla::CSSPixel, float> const&, mozilla::gfx::SizeTyped<mozilla::CSSPixel, float> const&)
Unexecuted instantiation: mozilla::gfx::RectTyped<mozilla::LayoutDevicePixel, float>::RectTyped(mozilla::gfx::PointTyped<mozilla::LayoutDevicePixel, float> const&, mozilla::gfx::SizeTyped<mozilla::LayoutDevicePixel, float> const&)
Unexecuted instantiation: mozilla::gfx::RectTyped<mozilla::LayerPixel, float>::RectTyped(mozilla::gfx::PointTyped<mozilla::LayerPixel, float> const&, mozilla::gfx::SizeTyped<mozilla::LayerPixel, float> const&)
Unexecuted instantiation: mozilla::gfx::RectTyped<mozilla::ParentLayerPixel, float>::RectTyped(mozilla::gfx::PointTyped<mozilla::ParentLayerPixel, float> const&, mozilla::gfx::SizeTyped<mozilla::ParentLayerPixel, float> const&)
Unexecuted instantiation: mozilla::gfx::RectTyped<mozilla::gfx::UnknownUnits, double>::RectTyped(mozilla::gfx::PointTyped<mozilla::gfx::UnknownUnits, double> const&, mozilla::gfx::SizeTyped<mozilla::gfx::UnknownUnits, double> const&)
241
    RectTyped(F _x, F _y, F _width, F _height) :
242
0
        Super(_x, _y, _width, _height) {}
Unexecuted instantiation: mozilla::gfx::RectTyped<mozilla::ParentLayerPixel, float>::RectTyped(float, float, float, float)
Unexecuted instantiation: mozilla::gfx::RectTyped<mozilla::CSSPixel, float>::RectTyped(float, float, float, float)
Unexecuted instantiation: mozilla::gfx::RectTyped<mozilla::gfx::UnknownUnits, double>::RectTyped(double, double, double, double)
Unexecuted instantiation: mozilla::gfx::RectTyped<mozilla::gfx::UnknownUnits, float>::RectTyped(float, float, float, float)
Unexecuted instantiation: mozilla::gfx::RectTyped<mozilla::RenderTargetPixel, float>::RectTyped(float, float, float, float)
Unexecuted instantiation: mozilla::gfx::RectTyped<mozilla::LayoutDevicePixel, float>::RectTyped(float, float, float, float)
Unexecuted instantiation: mozilla::gfx::RectTyped<mozilla::LayerPixel, float>::RectTyped(float, float, float, float)
Unexecuted instantiation: mozilla::gfx::RectTyped<mozilla::DesktopPixel, float>::RectTyped(float, float, float, float)
Unexecuted instantiation: mozilla::gfx::RectTyped<mozilla::ScreenPixel, float>::RectTyped(float, float, float, float)
243
    explicit RectTyped(const IntRectTyped<units>& rect) :
244
        Super(F(rect.X()), F(rect.Y()),
245
0
              F(rect.Width()), F(rect.Height())) {}
Unexecuted instantiation: mozilla::gfx::RectTyped<mozilla::gfx::UnknownUnits, float>::RectTyped(mozilla::gfx::IntRectTyped<mozilla::gfx::UnknownUnits> const&)
Unexecuted instantiation: mozilla::gfx::RectTyped<mozilla::LayerPixel, float>::RectTyped(mozilla::gfx::IntRectTyped<mozilla::LayerPixel> const&)
Unexecuted instantiation: mozilla::gfx::RectTyped<mozilla::ParentLayerPixel, float>::RectTyped(mozilla::gfx::IntRectTyped<mozilla::ParentLayerPixel> const&)
Unexecuted instantiation: mozilla::gfx::RectTyped<mozilla::LayoutDevicePixel, float>::RectTyped(mozilla::gfx::IntRectTyped<mozilla::LayoutDevicePixel> const&)
246
247
    void NudgeToIntegers()
248
0
    {
249
0
      NudgeToInteger(&(this->x));
250
0
      NudgeToInteger(&(this->y));
251
0
      NudgeToInteger(&(this->width));
252
0
      NudgeToInteger(&(this->height));
253
0
    }
254
255
    bool ToIntRect(IntRectTyped<units> *aOut) const
256
0
    {
257
0
      *aOut = IntRectTyped<units>(int32_t(this->X()), int32_t(this->Y()),
258
0
                                  int32_t(this->Width()), int32_t(this->Height()));
259
0
      return RectTyped<units, F>(F(aOut->X()), F(aOut->Y()),
260
0
                                 F(aOut->Width()), F(aOut->Height()))
261
0
             .IsEqualEdges(*this);
262
0
    }
Unexecuted instantiation: mozilla::gfx::RectTyped<mozilla::gfx::UnknownUnits, float>::ToIntRect(mozilla::gfx::IntRectTyped<mozilla::gfx::UnknownUnits>*) const
Unexecuted instantiation: mozilla::gfx::RectTyped<mozilla::gfx::UnknownUnits, double>::ToIntRect(mozilla::gfx::IntRectTyped<mozilla::gfx::UnknownUnits>*) const
Unexecuted instantiation: mozilla::gfx::RectTyped<mozilla::ParentLayerPixel, float>::ToIntRect(mozilla::gfx::IntRectTyped<mozilla::ParentLayerPixel>*) const
Unexecuted instantiation: mozilla::gfx::RectTyped<mozilla::LayerPixel, float>::ToIntRect(mozilla::gfx::IntRectTyped<mozilla::LayerPixel>*) const
Unexecuted instantiation: mozilla::gfx::RectTyped<mozilla::LayoutDevicePixel, float>::ToIntRect(mozilla::gfx::IntRectTyped<mozilla::LayoutDevicePixel>*) const
263
264
    // XXX When all of the code is ported, the following functions to convert to and from
265
    // unknown types should be removed.
266
267
0
    static RectTyped<units, F> FromUnknownRect(const RectTyped<UnknownUnits, F>& rect) {
268
0
      return RectTyped<units, F>(rect.X(), rect.Y(), rect.Width(), rect.Height());
269
0
    }
Unexecuted instantiation: mozilla::gfx::RectTyped<mozilla::RenderTargetPixel, float>::FromUnknownRect(mozilla::gfx::RectTyped<mozilla::gfx::UnknownUnits, float> const&)
Unexecuted instantiation: mozilla::gfx::RectTyped<mozilla::LayoutDevicePixel, float>::FromUnknownRect(mozilla::gfx::RectTyped<mozilla::gfx::UnknownUnits, float> const&)
270
271
0
    RectTyped<UnknownUnits, F> ToUnknownRect() const {
272
0
      return RectTyped<UnknownUnits, F>(this->X(), this->Y(), this->Width(), this->Height());
273
0
    }
Unexecuted instantiation: mozilla::gfx::RectTyped<mozilla::LayerPixel, float>::ToUnknownRect() const
Unexecuted instantiation: mozilla::gfx::RectTyped<mozilla::ParentLayerPixel, float>::ToUnknownRect() const
Unexecuted instantiation: mozilla::gfx::RectTyped<mozilla::LayoutDevicePixel, float>::ToUnknownRect() const
274
275
    // This is here only to keep IPDL-generated code happy. DO NOT USE.
276
    bool operator==(const RectTyped<units, F>& aRect) const
277
0
    {
278
0
      return RectTyped<units, F>::IsEqualEdges(aRect);
279
0
    }
Unexecuted instantiation: mozilla::gfx::RectTyped<mozilla::CSSPixel, float>::operator==(mozilla::gfx::RectTyped<mozilla::CSSPixel, float> const&) const
Unexecuted instantiation: mozilla::gfx::RectTyped<mozilla::LayoutDevicePixel, float>::operator==(mozilla::gfx::RectTyped<mozilla::LayoutDevicePixel, float> const&) const
Unexecuted instantiation: mozilla::gfx::RectTyped<mozilla::gfx::UnknownUnits, float>::operator==(mozilla::gfx::RectTyped<mozilla::gfx::UnknownUnits, float> const&) const
280
};
281
typedef RectTyped<UnknownUnits> Rect;
282
typedef RectTyped<UnknownUnits, double> RectDouble;
283
284
template<class units>
285
IntRectTyped<units> RoundedToInt(const RectTyped<units>& aRect)
286
0
{
287
0
  RectTyped<units> copy(aRect);
288
0
  copy.Round();
289
0
  return IntRectTyped<units>(int32_t(copy.X()),
290
0
                             int32_t(copy.Y()),
291
0
                             int32_t(copy.Width()),
292
0
                             int32_t(copy.Height()));
293
0
}
Unexecuted instantiation: mozilla::gfx::IntRectTyped<mozilla::LayoutDevicePixel> mozilla::gfx::RoundedToInt<mozilla::LayoutDevicePixel>(mozilla::gfx::RectTyped<mozilla::LayoutDevicePixel, float> const&)
Unexecuted instantiation: mozilla::gfx::IntRectTyped<mozilla::gfx::UnknownUnits> mozilla::gfx::RoundedToInt<mozilla::gfx::UnknownUnits>(mozilla::gfx::RectTyped<mozilla::gfx::UnknownUnits, float> const&)
Unexecuted instantiation: mozilla::gfx::IntRectTyped<mozilla::LayerPixel> mozilla::gfx::RoundedToInt<mozilla::LayerPixel>(mozilla::gfx::RectTyped<mozilla::LayerPixel, float> const&)
Unexecuted instantiation: mozilla::gfx::IntRectTyped<mozilla::ParentLayerPixel> mozilla::gfx::RoundedToInt<mozilla::ParentLayerPixel>(mozilla::gfx::RectTyped<mozilla::ParentLayerPixel, float> const&)
Unexecuted instantiation: mozilla::gfx::IntRectTyped<mozilla::RenderTargetPixel> mozilla::gfx::RoundedToInt<mozilla::RenderTargetPixel>(mozilla::gfx::RectTyped<mozilla::RenderTargetPixel, float> const&)
Unexecuted instantiation: mozilla::gfx::IntRectTyped<mozilla::DesktopPixel> mozilla::gfx::RoundedToInt<mozilla::DesktopPixel>(mozilla::gfx::RectTyped<mozilla::DesktopPixel, float> const&)
294
295
template<class units>
296
0
bool RectIsInt32Safe(const RectTyped<units>& aRect) {
297
0
  float min = (float)std::numeric_limits<std::int32_t>::min();
298
0
  float max = (float)std::numeric_limits<std::int32_t>::max();
299
0
  return aRect.x > min && aRect.y > min && aRect.XMost() < max && aRect.YMost() < max;
300
0
}
301
302
template<class units>
303
IntRectTyped<units> RoundedIn(const RectTyped<units>& aRect)
304
0
{
305
0
  return IntRectTyped<units>::RoundIn(aRect);
306
0
}
Unexecuted instantiation: mozilla::gfx::IntRectTyped<mozilla::gfx::UnknownUnits> mozilla::gfx::RoundedIn<mozilla::gfx::UnknownUnits>(mozilla::gfx::RectTyped<mozilla::gfx::UnknownUnits, float> const&)
Unexecuted instantiation: mozilla::gfx::IntRectTyped<mozilla::CSSPixel> mozilla::gfx::RoundedIn<mozilla::CSSPixel>(mozilla::gfx::RectTyped<mozilla::CSSPixel, float> const&)
307
308
template<class units>
309
IntRectTyped<units> RoundedOut(const RectTyped<units>& aRect)
310
0
{
311
0
  return IntRectTyped<units>::RoundOut(aRect);
312
0
}
Unexecuted instantiation: mozilla::gfx::IntRectTyped<mozilla::gfx::UnknownUnits> mozilla::gfx::RoundedOut<mozilla::gfx::UnknownUnits>(mozilla::gfx::RectTyped<mozilla::gfx::UnknownUnits, float> const&)
Unexecuted instantiation: mozilla::gfx::IntRectTyped<mozilla::CSSPixel> mozilla::gfx::RoundedOut<mozilla::CSSPixel>(mozilla::gfx::RectTyped<mozilla::CSSPixel, float> const&)
Unexecuted instantiation: mozilla::gfx::IntRectTyped<mozilla::LayerPixel> mozilla::gfx::RoundedOut<mozilla::LayerPixel>(mozilla::gfx::RectTyped<mozilla::LayerPixel, float> const&)
Unexecuted instantiation: mozilla::gfx::IntRectTyped<mozilla::ParentLayerPixel> mozilla::gfx::RoundedOut<mozilla::ParentLayerPixel>(mozilla::gfx::RectTyped<mozilla::ParentLayerPixel, float> const&)
313
314
template<class units>
315
0
IntRectTyped<units> TruncatedToInt(const RectTyped<units>& aRect) {
316
0
  return IntRectTyped<units>::Truncate(aRect);
317
0
}
318
319
template<class units>
320
RectTyped<units> IntRectToRect(const IntRectTyped<units>& aRect)
321
0
{
322
0
  return RectTyped<units>(aRect.X(), aRect.Y(), aRect.Width(), aRect.Height());
323
0
}
Unexecuted instantiation: mozilla::gfx::RectTyped<mozilla::LayoutDevicePixel, float> mozilla::gfx::IntRectToRect<mozilla::LayoutDevicePixel>(mozilla::gfx::IntRectTyped<mozilla::LayoutDevicePixel> const&)
Unexecuted instantiation: mozilla::gfx::RectTyped<mozilla::gfx::UnknownUnits, float> mozilla::gfx::IntRectToRect<mozilla::gfx::UnknownUnits>(mozilla::gfx::IntRectTyped<mozilla::gfx::UnknownUnits> const&)
324
325
// Convenience functions for intersecting and unioning two rectangles wrapped in Maybes.
326
template <typename Rect>
327
Maybe<Rect>
328
IntersectMaybeRects(const Maybe<Rect>& a, const Maybe<Rect>& b)
329
0
{
330
0
  if (!a) {
331
0
    return b;
332
0
  } else if (!b) {
333
0
    return a;
334
0
  } else {
335
0
    return Some(a->Intersect(*b));
336
0
  }
337
0
}
Unexecuted instantiation: mozilla::Maybe<mozilla::gfx::IntRectTyped<mozilla::ParentLayerPixel> > mozilla::gfx::IntersectMaybeRects<mozilla::gfx::IntRectTyped<mozilla::ParentLayerPixel> >(mozilla::Maybe<mozilla::gfx::IntRectTyped<mozilla::ParentLayerPixel> > const&, mozilla::Maybe<mozilla::gfx::IntRectTyped<mozilla::ParentLayerPixel> > const&)
Unexecuted instantiation: mozilla::Maybe<mozilla::gfx::IntRectTyped<mozilla::RenderTargetPixel> > mozilla::gfx::IntersectMaybeRects<mozilla::gfx::IntRectTyped<mozilla::RenderTargetPixel> >(mozilla::Maybe<mozilla::gfx::IntRectTyped<mozilla::RenderTargetPixel> > const&, mozilla::Maybe<mozilla::gfx::IntRectTyped<mozilla::RenderTargetPixel> > const&)
Unexecuted instantiation: mozilla::Maybe<nsRect> mozilla::gfx::IntersectMaybeRects<nsRect>(mozilla::Maybe<nsRect> const&, mozilla::Maybe<nsRect> const&)
338
template <typename Rect>
339
Maybe<Rect>
340
UnionMaybeRects(const Maybe<Rect>& a, const Maybe<Rect>& b)
341
0
{
342
0
  if (!a) {
343
0
    return b;
344
0
  } else if (!b) {
345
0
    return a;
346
0
  } else {
347
0
    return Some(a->Union(*b));
348
0
  }
349
0
}
350
351
struct RectCornerRadii {
352
  Size radii[eCornerCount];
353
354
0
  RectCornerRadii() {}
355
356
0
  explicit RectCornerRadii(Float radius) {
357
0
    NS_FOR_CSS_FULL_CORNERS(i) {
358
0
      radii[i].SizeTo(radius, radius);
359
0
    }
360
0
  }
361
362
0
  explicit RectCornerRadii(Float radiusX, Float radiusY) {
363
0
    NS_FOR_CSS_FULL_CORNERS(i) {
364
0
      radii[i].SizeTo(radiusX, radiusY);
365
0
    }
366
0
  }
367
368
0
  RectCornerRadii(Float tl, Float tr, Float br, Float bl) {
369
0
    radii[eCornerTopLeft].SizeTo(tl, tl);
370
0
    radii[eCornerTopRight].SizeTo(tr, tr);
371
0
    radii[eCornerBottomRight].SizeTo(br, br);
372
0
    radii[eCornerBottomLeft].SizeTo(bl, bl);
373
0
  }
374
375
  RectCornerRadii(const Size& tl, const Size& tr,
376
0
                  const Size& br, const Size& bl) {
377
0
    radii[eCornerTopLeft] = tl;
378
0
    radii[eCornerTopRight] = tr;
379
0
    radii[eCornerBottomRight] = br;
380
0
    radii[eCornerBottomLeft] = bl;
381
0
  }
382
383
0
  const Size& operator[](size_t aCorner) const {
384
0
    return radii[aCorner];
385
0
  }
386
387
0
  Size& operator[](size_t aCorner) {
388
0
    return radii[aCorner];
389
0
  }
390
391
0
  bool operator==(const RectCornerRadii& aOther) const {
392
0
    return TopLeft() == aOther.TopLeft() &&
393
0
           TopRight() == aOther.TopRight() &&
394
0
           BottomRight() == aOther.BottomRight() &&
395
0
           BottomLeft() == aOther.BottomLeft();
396
0
  }
397
398
0
  bool AreRadiiSame() const {
399
0
    return TopLeft() == TopRight() &&
400
0
           TopLeft() == BottomRight() &&
401
0
           TopLeft() == BottomLeft();
402
0
  }
403
404
0
  void Scale(Float aXScale, Float aYScale) {
405
0
    NS_FOR_CSS_FULL_CORNERS(i) {
406
0
      radii[i].Scale(aXScale, aYScale);
407
0
    }
408
0
  }
409
410
0
  const Size TopLeft() const { return radii[eCornerTopLeft]; }
411
0
  Size& TopLeft() { return radii[eCornerTopLeft]; }
412
413
0
  const Size TopRight() const { return radii[eCornerTopRight]; }
414
0
  Size& TopRight() { return radii[eCornerTopRight]; }
415
416
0
  const Size BottomRight() const { return radii[eCornerBottomRight]; }
417
0
  Size& BottomRight() { return radii[eCornerBottomRight]; }
418
419
0
  const Size BottomLeft() const { return radii[eCornerBottomLeft]; }
420
0
  Size& BottomLeft() { return radii[eCornerBottomLeft]; }
421
422
0
  bool IsEmpty() const {
423
0
    return TopLeft().IsEmpty() && TopRight().IsEmpty() &&
424
0
           BottomRight().IsEmpty() && BottomLeft().IsEmpty();
425
0
  }
426
};
427
428
/* A rounded rectangle abstraction.
429
 *
430
 * This can represent a rectangle with a different pair of radii on each corner.
431
 *
432
 * Note: CoreGraphics and Direct2D only support rounded rectangle with the same
433
 * radii on all corners. However, supporting CSS's border-radius requires the extra flexibility. */
434
struct RoundedRect {
435
    typedef mozilla::gfx::RectCornerRadii RectCornerRadii;
436
437
    RoundedRect(const Rect& aRect, const RectCornerRadii& aCorners)
438
      : rect(aRect)
439
      , corners(aCorners)
440
0
    {
441
0
    }
442
443
0
    void Deflate(Float aTopWidth, Float aBottomWidth, Float aLeftWidth, Float aRightWidth) {
444
0
        // deflate the internal rect
445
0
        rect.SetRect(rect.X() + aLeftWidth,
446
0
                     rect.Y() + aTopWidth,
447
0
                     std::max(0.f, rect.Width() - aLeftWidth - aRightWidth),
448
0
                     std::max(0.f, rect.Height() - aTopWidth - aBottomWidth));
449
0
450
0
        corners.radii[mozilla::eCornerTopLeft].width =
451
0
            std::max(0.f, corners.radii[mozilla::eCornerTopLeft].width - aLeftWidth);
452
0
        corners.radii[mozilla::eCornerTopLeft].height =
453
0
            std::max(0.f, corners.radii[mozilla::eCornerTopLeft].height - aTopWidth);
454
0
455
0
        corners.radii[mozilla::eCornerTopRight].width =
456
0
            std::max(0.f, corners.radii[mozilla::eCornerTopRight].width - aRightWidth);
457
0
        corners.radii[mozilla::eCornerTopRight].height =
458
0
            std::max(0.f, corners.radii[mozilla::eCornerTopRight].height - aTopWidth);
459
0
460
0
        corners.radii[mozilla::eCornerBottomLeft].width =
461
0
            std::max(0.f, corners.radii[mozilla::eCornerBottomLeft].width - aLeftWidth);
462
0
        corners.radii[mozilla::eCornerBottomLeft].height =
463
0
            std::max(0.f, corners.radii[mozilla::eCornerBottomLeft].height - aBottomWidth);
464
0
465
0
        corners.radii[mozilla::eCornerBottomRight].width =
466
0
            std::max(0.f, corners.radii[mozilla::eCornerBottomRight].width - aRightWidth);
467
0
        corners.radii[mozilla::eCornerBottomRight].height =
468
0
            std::max(0.f, corners.radii[mozilla::eCornerBottomRight].height - aBottomWidth);
469
0
    }
470
    Rect rect;
471
    RectCornerRadii corners;
472
};
473
474
} // namespace gfx
475
} // namespace mozilla
476
477
#endif /* MOZILLA_GFX_RECT_H_ */