Line data Source code
1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
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 : #include "nsRect.h"
7 : #include "mozilla/gfx/Types.h" // for eSideBottom, etc
8 : #include "mozilla/CheckedInt.h" // for CheckedInt
9 : #include "nsDeviceContext.h" // for nsDeviceContext
10 : #include "nsString.h" // for nsAutoString, etc
11 : #include "nsMargin.h" // for nsMargin
12 :
13 : static_assert((int(eSideTop) == 0) &&
14 : (int(eSideRight) == 1) &&
15 : (int(eSideBottom) == 2) &&
16 : (int(eSideLeft) == 3),
17 : "The mozilla::Side sequence must match the nsMargin nscoord sequence");
18 :
19 43 : const mozilla::gfx::IntRect& GetMaxSizedIntRect() {
20 43 : static const mozilla::gfx::IntRect r(0, 0, INT32_MAX, INT32_MAX);
21 43 : return r;
22 : }
23 :
24 :
25 780 : bool nsRect::Overflows() const {
26 : #ifdef NS_COORD_IS_FLOAT
27 : return false;
28 : #else
29 780 : mozilla::CheckedInt<int32_t> xMost = this->x;
30 780 : xMost += this->width;
31 780 : mozilla::CheckedInt<int32_t> yMost = this->y;
32 780 : yMost += this->height;
33 780 : return !xMost.isValid() || !yMost.isValid();
34 : #endif
35 : }
36 :
37 : #ifdef DEBUG
38 : // Diagnostics
39 :
40 0 : FILE* operator<<(FILE* out, const nsRect& rect)
41 : {
42 0 : nsAutoString tmp;
43 :
44 : // Output the coordinates in fractional pixels so they're easier to read
45 0 : tmp.Append('{');
46 0 : tmp.AppendFloat(NSAppUnitsToFloatPixels(rect.x,
47 0 : nsDeviceContext::AppUnitsPerCSSPixel()));
48 0 : tmp.AppendLiteral(", ");
49 0 : tmp.AppendFloat(NSAppUnitsToFloatPixels(rect.y,
50 0 : nsDeviceContext::AppUnitsPerCSSPixel()));
51 0 : tmp.AppendLiteral(", ");
52 0 : tmp.AppendFloat(NSAppUnitsToFloatPixels(rect.width,
53 0 : nsDeviceContext::AppUnitsPerCSSPixel()));
54 0 : tmp.AppendLiteral(", ");
55 0 : tmp.AppendFloat(NSAppUnitsToFloatPixels(rect.height,
56 0 : nsDeviceContext::AppUnitsPerCSSPixel()));
57 0 : tmp.Append('}');
58 0 : fputs(NS_LossyConvertUTF16toASCII(tmp).get(), out);
59 0 : return out;
60 : }
61 :
62 : #endif // DEBUG
|