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

Unified Diff: ui/gfx/geometry/rect.cc

Issue 2499783002: Move SaturatedArithmetic from Blink to base (Closed)
Patch Set: Revert flag addition Created 4 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/gfx/geometry/rect.h ('k') | ui/gfx/geometry/safe_integer_conversions.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/geometry/rect.cc
diff --git a/ui/gfx/geometry/rect.cc b/ui/gfx/geometry/rect.cc
index 3f7a1c0d8911bec2ef24177fc92aa21ab7a08cb7..f3c47b2b378e9b0bd8087330560a4b7541e6384d 100644
--- a/ui/gfx/geometry/rect.cc
+++ b/ui/gfx/geometry/rect.cc
@@ -15,6 +15,7 @@
#endif
#include "base/logging.h"
+#include "base/numerics/saturated_arithmetic.h"
#include "base/strings/stringprintf.h"
#include "build/build_config.h"
#include "ui/gfx/geometry/insets.h"
@@ -67,8 +68,10 @@ void Rect::Inset(int left, int top, int right, int bottom) {
origin_ += Vector2d(left, top);
// left+right might overflow/underflow, but width() - (left+right) might
// overflow as well.
- set_width(SafeSubtract(width(), SafeAdd(left, right)));
- set_height(SafeSubtract(height(), SafeAdd(top, bottom)));
+ set_width(base::SaturatedSubtraction(width(),
+ base::SaturatedAddition(left, right)));
+ set_height(base::SaturatedSubtraction(height(),
+ base::SaturatedAddition(top, bottom)));
}
void Rect::Offset(int horizontal, int vertical) {
@@ -154,8 +157,8 @@ void Rect::Union(const Rect& rect) {
int rb = std::max(bottom(), rect.bottom());
// Subtracting to get width/height might overflow integers, so clamp them.
- SetRect(rx, ry, GetClampedWidthFromExtents(rx, rr),
- GetClampedWidthFromExtents(ry, rb));
+ SetRect(rx, ry, base::SaturatedSubtraction(rr, rx),
+ base::SaturatedSubtraction(rb, ry));
}
void Rect::Subtract(const Rect& rect) {
« no previous file with comments | « ui/gfx/geometry/rect.h ('k') | ui/gfx/geometry/safe_integer_conversions.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698