summaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorvmpstr <vmpstr@chromium.org>2015-11-03 17:44:29 -0800
committerCommit bot <commit-bot@chromium.org>2015-11-04 01:45:38 +0000
commit5612bdb7ea4e21bf7d229aeb7329e137ac1ad807 (patch)
tree4719c30d0171117e1f7cc94d5915099fa6091cab /ui
parentaecc0d7c0805a11cf40778819f2493c0afc50481 (diff)
downloadchromium_src-5612bdb7ea4e21bf7d229aeb7329e137ac1ad807.zip
chromium_src-5612bdb7ea4e21bf7d229aeb7329e137ac1ad807.tar.gz
chromium_src-5612bdb7ea4e21bf7d229aeb7329e137ac1ad807.tar.bz2
Add gfx::Size::GetCheckedArea and use it where appropriate.
This patch adds a GetCheckedArea call to gfx::Size, which returns a checked numeric object. This can be used in places that either want a checked object or when the code expects to have a size that might be too large to fit into an int. BUG=352761, 548876 R=danakj, pkasting, dalecurtis CQ_INCLUDE_TRYBOTS=tryserver.blink:linux_blink_rel Review URL: https://codereview.chromium.org/1418043006 Cr-Commit-Position: refs/heads/master@{#357718}
Diffstat (limited to 'ui')
-rw-r--r--ui/gfx/geometry/size.cc6
-rw-r--r--ui/gfx/geometry/size.h3
2 files changed, 8 insertions, 1 deletions
diff --git a/ui/gfx/geometry/size.cc b/ui/gfx/geometry/size.cc
index e58bb22..7b5b522 100644
--- a/ui/gfx/geometry/size.cc
+++ b/ui/gfx/geometry/size.cc
@@ -45,9 +45,13 @@ CGSize Size::ToCGSize() const {
#endif
int Size::GetArea() const {
+ return GetCheckedArea().ValueOrDie();
+}
+
+base::CheckedNumeric<int> Size::GetCheckedArea() const {
base::CheckedNumeric<int> checked_area = width();
checked_area *= height();
- return checked_area.ValueOrDie();
+ return checked_area;
}
void Size::Enlarge(int grow_width, int grow_height) {
diff --git a/ui/gfx/geometry/size.h b/ui/gfx/geometry/size.h
index 27face1..de1df59 100644
--- a/ui/gfx/geometry/size.h
+++ b/ui/gfx/geometry/size.h
@@ -9,6 +9,7 @@
#include <string>
#include "base/compiler_specific.h"
+#include "base/numerics/safe_math.h"
#include "ui/gfx/gfx_export.h"
#if defined(OS_WIN)
@@ -49,6 +50,8 @@ class GFX_EXPORT Size {
// This call will CHECK if the area of this size would overflow int.
int GetArea() const;
+ // Returns a checked numeric representation of the area.
+ base::CheckedNumeric<int> GetCheckedArea() const;
void SetSize(int width, int height) {
set_width(width);