Chromium Code Reviews| Index: ui/gfx/geometry/rect.h |
| diff --git a/ui/gfx/geometry/rect.h b/ui/gfx/geometry/rect.h |
| index 2a5fe8e39d2d0714d893e27dd7ee3fc950480e71..47d28dd0f9eeb86d5a16c7a401291465499f2d58 100644 |
| --- a/ui/gfx/geometry/rect.h |
| +++ b/ui/gfx/geometry/rect.h |
| @@ -32,15 +32,23 @@ namespace gfx { |
| class Insets; |
| +#define GetClampedValue(origin, size) \ |
|
danakj
2016/08/25 17:59:21
can this be a constexpr function instead, in an in
sunxd
2016/08/25 19:25:09
Acknowledged.
|
| + origin > 0 && std::numeric_limits<int>::max() - origin < size \ |
| + ? std::numeric_limits<int>::max() - origin \ |
| + : size |
| + |
| class GFX_EXPORT Rect { |
| public: |
| constexpr Rect() = default; |
| constexpr Rect(int width, int height) : size_(width, height) {} |
| constexpr Rect(int x, int y, int width, int height) |
| - : origin_(x, y), size_(width, height) {} |
| + : origin_(x, y), |
| + size_(GetClampedValue(x, width), GetClampedValue(y, height)) {} |
| constexpr explicit Rect(const Size& size) : size_(size) {} |
| constexpr Rect(const Point& origin, const Size& size) |
| - : origin_(origin), size_(size) {} |
| + : origin_(origin), |
| + size_(GetClampedValue(origin.x(), size.width()), |
| + GetClampedValue(origin.y(), size.height())) {} |
| #if defined(OS_WIN) |
| explicit Rect(const RECT& r); |