|
Packit |
f0b94e |
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
Packit |
f0b94e |
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
Packit |
f0b94e |
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
Packit |
f0b94e |
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
Packit |
f0b94e |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
Packit |
f0b94e |
|
|
Packit |
f0b94e |
#include "nsRect.h"
|
|
Packit |
f0b94e |
#include "mozilla/gfx/Types.h" // for eSideBottom, etc
|
|
Packit |
f0b94e |
#include "mozilla/CheckedInt.h" // for CheckedInt
|
|
Packit |
f0b94e |
#include "nsDeviceContext.h" // for nsDeviceContext
|
|
Packit |
f0b94e |
#include "nsString.h" // for nsAutoString, etc
|
|
Packit |
f0b94e |
#include "nsMargin.h" // for nsMargin
|
|
Packit |
f0b94e |
|
|
Packit |
f0b94e |
static_assert(
|
|
Packit |
f0b94e |
(int(eSideTop) == 0) && (int(eSideRight) == 1) && (int(eSideBottom) == 2) &&
|
|
Packit |
f0b94e |
(int(eSideLeft) == 3),
|
|
Packit |
f0b94e |
"The mozilla::Side sequence must match the nsMargin nscoord sequence");
|
|
Packit |
f0b94e |
|
|
Packit |
f0b94e |
const mozilla::gfx::IntRect& GetMaxSizedIntRect() {
|
|
Packit |
f0b94e |
static const mozilla::gfx::IntRect r(0, 0, INT32_MAX, INT32_MAX);
|
|
Packit |
f0b94e |
return r;
|
|
Packit |
f0b94e |
}
|
|
Packit |
f0b94e |
|
|
Packit |
f0b94e |
bool nsRect::Overflows() const {
|
|
Packit |
f0b94e |
#ifdef NS_COORD_IS_FLOAT
|
|
Packit |
f0b94e |
return false;
|
|
Packit |
f0b94e |
#else
|
|
Packit |
f0b94e |
mozilla::CheckedInt<int32_t> xMost = this->x;
|
|
Packit |
f0b94e |
xMost += this->width;
|
|
Packit |
f0b94e |
mozilla::CheckedInt<int32_t> yMost = this->y;
|
|
Packit |
f0b94e |
yMost += this->height;
|
|
Packit |
f0b94e |
return !xMost.isValid() || !yMost.isValid();
|
|
Packit |
f0b94e |
#endif
|
|
Packit |
f0b94e |
}
|
|
Packit |
f0b94e |
|
|
Packit |
f0b94e |
#ifdef DEBUG
|
|
Packit |
f0b94e |
// Diagnostics
|
|
Packit |
f0b94e |
|
|
Packit |
f0b94e |
FILE* operator<<(FILE* out, const nsRect& rect) {
|
|
Packit |
f0b94e |
nsAutoString tmp;
|
|
Packit |
f0b94e |
|
|
Packit |
f0b94e |
// Output the coordinates in fractional pixels so they're easier to read
|
|
Packit |
f0b94e |
tmp.Append('{');
|
|
Packit |
f0b94e |
tmp.AppendFloat(NSAppUnitsToFloatPixels(
|
|
Packit |
f0b94e |
rect.X(), nsDeviceContext::AppUnitsPerCSSPixel()));
|
|
Packit |
f0b94e |
tmp.AppendLiteral(", ");
|
|
Packit |
f0b94e |
tmp.AppendFloat(NSAppUnitsToFloatPixels(
|
|
Packit |
f0b94e |
rect.Y(), nsDeviceContext::AppUnitsPerCSSPixel()));
|
|
Packit |
f0b94e |
tmp.AppendLiteral(", ");
|
|
Packit |
f0b94e |
tmp.AppendFloat(NSAppUnitsToFloatPixels(
|
|
Packit |
f0b94e |
rect.Width(), nsDeviceContext::AppUnitsPerCSSPixel()));
|
|
Packit |
f0b94e |
tmp.AppendLiteral(", ");
|
|
Packit |
f0b94e |
tmp.AppendFloat(NSAppUnitsToFloatPixels(
|
|
Packit |
f0b94e |
rect.Height(), nsDeviceContext::AppUnitsPerCSSPixel()));
|
|
Packit |
f0b94e |
tmp.Append('}');
|
|
Packit |
f0b94e |
fputs(NS_LossyConvertUTF16toASCII(tmp).get(), out);
|
|
Packit |
f0b94e |
return out;
|
|
Packit |
f0b94e |
}
|
|
Packit |
f0b94e |
|
|
Packit |
f0b94e |
#endif // DEBUG
|