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

Side by Side Diff: ui/gfx/geometry/size.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 unified diff | Download patch
« no previous file with comments | « ui/gfx/geometry/safe_integer_conversions_unittest.cc ('k') | ui/gfx/geometry/vector2d.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/size.h" 5 #include "ui/gfx/geometry/size.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <windows.h> 8 #include <windows.h>
9 #elif defined(OS_IOS) 9 #elif defined(OS_IOS)
10 #include <CoreGraphics/CoreGraphics.h> 10 #include <CoreGraphics/CoreGraphics.h>
11 #elif defined(OS_MACOSX) 11 #elif defined(OS_MACOSX)
12 #include <ApplicationServices/ApplicationServices.h> 12 #include <ApplicationServices/ApplicationServices.h>
13 #endif 13 #endif
14 14
15 #include "base/numerics/safe_math.h" 15 #include "base/numerics/safe_math.h"
16 #include "base/numerics/saturated_arithmetic.h"
16 #include "base/strings/stringprintf.h" 17 #include "base/strings/stringprintf.h"
17 #include "build/build_config.h" 18 #include "build/build_config.h"
18 #include "ui/gfx/geometry/safe_integer_conversions.h" 19 #include "ui/gfx/geometry/safe_integer_conversions.h"
19 #include "ui/gfx/geometry/size_conversions.h" 20 #include "ui/gfx/geometry/size_conversions.h"
20 21
21 namespace gfx { 22 namespace gfx {
22 23
23 #if defined(OS_MACOSX) 24 #if defined(OS_MACOSX)
24 Size::Size(const CGSize& s) 25 Size::Size(const CGSize& s)
25 : width_(s.width < 0 ? 0 : s.width), 26 : width_(s.width < 0 ? 0 : s.width),
(...skipping 24 matching lines...) Expand all
50 return GetCheckedArea().ValueOrDie(); 51 return GetCheckedArea().ValueOrDie();
51 } 52 }
52 53
53 base::CheckedNumeric<int> Size::GetCheckedArea() const { 54 base::CheckedNumeric<int> Size::GetCheckedArea() const {
54 base::CheckedNumeric<int> checked_area = width(); 55 base::CheckedNumeric<int> checked_area = width();
55 checked_area *= height(); 56 checked_area *= height();
56 return checked_area; 57 return checked_area;
57 } 58 }
58 59
59 void Size::Enlarge(int grow_width, int grow_height) { 60 void Size::Enlarge(int grow_width, int grow_height) {
60 SetSize(SafeAdd(width(), grow_width), SafeAdd(height(), grow_height)); 61 SetSize(base::SaturatedAddition(width(), grow_width),
62 base::SaturatedAddition(height(), grow_height));
61 } 63 }
62 64
63 void Size::SetToMin(const Size& other) { 65 void Size::SetToMin(const Size& other) {
64 width_ = width() <= other.width() ? width() : other.width(); 66 width_ = width() <= other.width() ? width() : other.width();
65 height_ = height() <= other.height() ? height() : other.height(); 67 height_ = height() <= other.height() ? height() : other.height();
66 } 68 }
67 69
68 void Size::SetToMax(const Size& other) { 70 void Size::SetToMax(const Size& other) {
69 width_ = width() >= other.width() ? width() : other.width(); 71 width_ = width() >= other.width() ? width() : other.width();
70 height_ = height() >= other.height() ? height() : other.height(); 72 height_ = height() >= other.height() ? height() : other.height();
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 return ToRoundedSize(ScaleSize(gfx::SizeF(size), x_scale, y_scale)); 106 return ToRoundedSize(ScaleSize(gfx::SizeF(size), x_scale, y_scale));
105 } 107 }
106 108
107 Size ScaleToRoundedSize(const Size& size, float scale) { 109 Size ScaleToRoundedSize(const Size& size, float scale) {
108 if (scale == 1.f) 110 if (scale == 1.f)
109 return size; 111 return size;
110 return ToRoundedSize(ScaleSize(gfx::SizeF(size), scale, scale)); 112 return ToRoundedSize(ScaleSize(gfx::SizeF(size), scale, scale));
111 } 113 }
112 114
113 } // namespace gfx 115 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/geometry/safe_integer_conversions_unittest.cc ('k') | ui/gfx/geometry/vector2d.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698