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

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

Issue 2354783004: Fix overflow/underflow in gfx geometry once and for all (Closed)
Patch Set: Remove accessibility test changes Created 4 years, 2 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/safe_integer_conversions_unittest.cc ('k') | ui/gfx/geometry/size_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/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/strings/stringprintf.h" 16 #include "base/strings/stringprintf.h"
17 #include "build/build_config.h" 17 #include "build/build_config.h"
18 #include "ui/gfx/geometry/safe_integer_conversions.h"
18 #include "ui/gfx/geometry/size_conversions.h" 19 #include "ui/gfx/geometry/size_conversions.h"
19 20
20 namespace gfx { 21 namespace gfx {
21 22
22 #if defined(OS_MACOSX) 23 #if defined(OS_MACOSX)
23 Size::Size(const CGSize& s) 24 Size::Size(const CGSize& s)
24 : width_(s.width < 0 ? 0 : s.width), 25 : width_(s.width < 0 ? 0 : s.width),
25 height_(s.height < 0 ? 0 : s.height) { 26 height_(s.height < 0 ? 0 : s.height) {
26 } 27 }
27 28
(...skipping 21 matching lines...) Expand all
49 return GetCheckedArea().ValueOrDie(); 50 return GetCheckedArea().ValueOrDie();
50 } 51 }
51 52
52 base::CheckedNumeric<int> Size::GetCheckedArea() const { 53 base::CheckedNumeric<int> Size::GetCheckedArea() const {
53 base::CheckedNumeric<int> checked_area = width(); 54 base::CheckedNumeric<int> checked_area = width();
54 checked_area *= height(); 55 checked_area *= height();
55 return checked_area; 56 return checked_area;
56 } 57 }
57 58
58 void Size::Enlarge(int grow_width, int grow_height) { 59 void Size::Enlarge(int grow_width, int grow_height) {
59 SetSize(width() + grow_width, height() + grow_height); 60 SetSize(SafeAdd(width(), grow_width), SafeAdd(height(), grow_height));
60 } 61 }
61 62
62 void Size::SetToMin(const Size& other) { 63 void Size::SetToMin(const Size& other) {
63 width_ = width() <= other.width() ? width() : other.width(); 64 width_ = width() <= other.width() ? width() : other.width();
64 height_ = height() <= other.height() ? height() : other.height(); 65 height_ = height() <= other.height() ? height() : other.height();
65 } 66 }
66 67
67 void Size::SetToMax(const Size& other) { 68 void Size::SetToMax(const Size& other) {
68 width_ = width() >= other.width() ? width() : other.width(); 69 width_ = width() >= other.width() ? width() : other.width();
69 height_ = height() >= other.height() ? height() : other.height(); 70 height_ = height() >= other.height() ? height() : other.height();
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 return ToRoundedSize(ScaleSize(gfx::SizeF(size), x_scale, y_scale)); 104 return ToRoundedSize(ScaleSize(gfx::SizeF(size), x_scale, y_scale));
104 } 105 }
105 106
106 Size ScaleToRoundedSize(const Size& size, float scale) { 107 Size ScaleToRoundedSize(const Size& size, float scale) {
107 if (scale == 1.f) 108 if (scale == 1.f)
108 return size; 109 return size;
109 return ToRoundedSize(ScaleSize(gfx::SizeF(size), scale, scale)); 110 return ToRoundedSize(ScaleSize(gfx::SizeF(size), scale, scale));
110 } 111 }
111 112
112 } // namespace gfx 113 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/geometry/safe_integer_conversions_unittest.cc ('k') | ui/gfx/geometry/size_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698