Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(190)

Side by Side Diff: ui/gfx/geometry/rect.cc

Issue 2268423003: Adjust gfx::Rect's width and height to avoid integer overflow (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add comment. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/gfx/geometry/rect.h ('k') | ui/gfx/geometry/rect_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/gfx/geometry/rect.h" 5 #include "ui/gfx/geometry/rect.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #if defined(OS_WIN) 9 #if defined(OS_WIN)
10 #include <windows.h> 10 #include <windows.h>
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 } 64 }
65 65
66 void Rect::Inset(int left, int top, int right, int bottom) { 66 void Rect::Inset(int left, int top, int right, int bottom) {
67 origin_ += Vector2d(left, top); 67 origin_ += Vector2d(left, top);
68 set_width(std::max(width() - left - right, static_cast<int>(0))); 68 set_width(std::max(width() - left - right, static_cast<int>(0)));
69 set_height(std::max(height() - top - bottom, static_cast<int>(0))); 69 set_height(std::max(height() - top - bottom, static_cast<int>(0)));
70 } 70 }
71 71
72 void Rect::Offset(int horizontal, int vertical) { 72 void Rect::Offset(int horizontal, int vertical) {
73 origin_ += Vector2d(horizontal, vertical); 73 origin_ += Vector2d(horizontal, vertical);
74 // Ensure that width and height remain valid.
75 set_width(width());
76 set_height(height());
74 } 77 }
75 78
76 void Rect::operator+=(const Vector2d& offset) { 79 void Rect::operator+=(const Vector2d& offset) {
77 origin_ += offset; 80 origin_ += offset;
81 // Ensure that width and height remain valid.
82 set_width(width());
83 set_height(height());
78 } 84 }
79 85
80 void Rect::operator-=(const Vector2d& offset) { 86 void Rect::operator-=(const Vector2d& offset) {
81 origin_ -= offset; 87 origin_ -= offset;
82 } 88 }
83 89
84 Insets Rect::InsetsFrom(const Rect& inner) const { 90 Insets Rect::InsetsFrom(const Rect& inner) const {
85 return Insets(inner.y() - y(), 91 return Insets(inner.y() - y(),
86 inner.x() - x(), 92 inner.x() - x(),
87 bottom() - inner.bottom(), 93 bottom() - inner.bottom(),
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 290
285 Rect BoundingRect(const Point& p1, const Point& p2) { 291 Rect BoundingRect(const Point& p1, const Point& p2) {
286 int rx = std::min(p1.x(), p2.x()); 292 int rx = std::min(p1.x(), p2.x());
287 int ry = std::min(p1.y(), p2.y()); 293 int ry = std::min(p1.y(), p2.y());
288 int rr = std::max(p1.x(), p2.x()); 294 int rr = std::max(p1.x(), p2.x());
289 int rb = std::max(p1.y(), p2.y()); 295 int rb = std::max(p1.y(), p2.y());
290 return Rect(rx, ry, rr - rx, rb - ry); 296 return Rect(rx, ry, rr - rx, rb - ry);
291 } 297 }
292 298
293 } // namespace gfx 299 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/geometry/rect.h ('k') | ui/gfx/geometry/rect_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698