summaryrefslogtreecommitdiffstats
path: root/ui/gfx
diff options
context:
space:
mode:
authordanakj@chromium.org <danakj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-08 16:02:05 +0000
committerdanakj@chromium.org <danakj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-08 16:02:05 +0000
commit190d06bf03d4c310f042396046b2b5b5f7af43cf (patch)
treed2b11881ccfe6f6c78557b83f14fe9c64d7d1b21 /ui/gfx
parent41b9266435fba2235d705ee0df8ca960b3c72f03 (diff)
downloadchromium_src-190d06bf03d4c310f042396046b2b5b5f7af43cf.zip
chromium_src-190d06bf03d4c310f042396046b2b5b5f7af43cf.tar.gz
chromium_src-190d06bf03d4c310f042396046b2b5b5f7af43cf.tar.bz2
ui: Remove gfx::Size::ClampToNonNegative, prevent negative sizes always.
This was added with the intention of using Size as a vector, replacing use of IntSize. Since we have Vector2d now, negative sizes should not exist, so clamp them in set_width/set_height and the constructor. Not covered by tests, as we can't test DCHECKs. TBR=sky BUG=160158 Relanding: https://codereview.chromium.org/11365160/ Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=167255 Review URL: https://chromiumcodereview.appspot.com/11410024 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@175535 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/gfx')
-rw-r--r--ui/gfx/rect_f.h5
-rw-r--r--ui/gfx/rect_unittest.cc5
-rw-r--r--ui/gfx/size.cc8
-rw-r--r--ui/gfx/size_base.h17
-rw-r--r--ui/gfx/size_base_impl.h37
-rw-r--r--ui/gfx/size_f.cc2
-rw-r--r--ui/gfx/size_unittest.cc18
7 files changed, 47 insertions, 45 deletions
diff --git a/ui/gfx/rect_f.h b/ui/gfx/rect_f.h
index bbc16cc..78524a0 100644
--- a/ui/gfx/rect_f.h
+++ b/ui/gfx/rect_f.h
@@ -49,10 +49,7 @@ class UI_EXPORT RectF
void Scale(float x_scale, float y_scale) {
set_origin(ScalePoint(origin(), x_scale, y_scale));
-
- SizeF new_size = gfx::ScaleSize(size(), x_scale, y_scale);
- new_size.ClampToNonNegative();
- set_size(new_size);
+ set_size(ScaleSize(size(), x_scale, y_scale));
}
// This method reports if the RectF can be safely converted to an integer
diff --git a/ui/gfx/rect_unittest.cc b/ui/gfx/rect_unittest.cc
index bf15c8f..f0bf7d5 100644
--- a/ui/gfx/rect_unittest.cc
+++ b/ui/gfx/rect_unittest.cc
@@ -441,10 +441,7 @@ TEST(RectTest, ScaleRect) {
std::numeric_limits<float>::max(),
std::numeric_limits<float>::max(),
std::numeric_limits<float>::max(),
- std::numeric_limits<float>::max() },
- { 3, 3, 3, 3,
- -1.0f,
- -3.0f, -3.0f, 0.0f, 0.0f }
+ std::numeric_limits<float>::max() }
};
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
diff --git a/ui/gfx/size.cc b/ui/gfx/size.cc
index a9a0bdd..4f9ff64 100644
--- a/ui/gfx/size.cc
+++ b/ui/gfx/size.cc
@@ -8,18 +8,16 @@
#include <windows.h>
#endif
-#include "base/logging.h"
#include "base/stringprintf.h"
-#include "ui/gfx/size_base.h"
+#include "ui/gfx/size_base_impl.h"
namespace gfx {
template class SizeBase<Size, int>;
#if defined(OS_MACOSX)
-Size::Size(const CGSize& s) : SizeBase<Size, int>(0, 0) {
- set_width(s.width);
- set_height(s.height);
+Size::Size(const CGSize& s)
+ : SizeBase<Size, int>(s.width, s.height) {
}
Size& Size::operator=(const CGSize& s) {
diff --git a/ui/gfx/size_base.h b/ui/gfx/size_base.h
index 0ec62e4..3d171f1 100644
--- a/ui/gfx/size_base.h
+++ b/ui/gfx/size_base.h
@@ -28,8 +28,8 @@ class UI_EXPORT SizeBase {
set_height(height_ + height);
}
- void set_width(Type width) { width_ = width; }
- void set_height(Type height) { height_ = height; }
+ void set_width(Type width);
+ void set_height(Type height);
void ClampToMax(const Class& max) {
width_ = width_ <= max.width_ ? width_ : max.width_;
@@ -42,20 +42,11 @@ class UI_EXPORT SizeBase {
}
bool IsEmpty() const {
- return (width_ <= 0) || (height_ <= 0);
- }
-
- void ClampToNonNegative() {
- if (width_ < 0)
- width_ = 0;
- if (height_ < 0)
- height_ = 0;
+ return (width_ == 0) || (height_ == 0);
}
protected:
- SizeBase(Type width, Type height)
- : width_(width),
- height_(height) {}
+ SizeBase(Type width, Type height);
// Destructor is intentionally made non virtual and protected.
// Do not make this public.
diff --git a/ui/gfx/size_base_impl.h b/ui/gfx/size_base_impl.h
new file mode 100644
index 0000000..9e87468
--- /dev/null
+++ b/ui/gfx/size_base_impl.h
@@ -0,0 +1,37 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ui/gfx/size_base.h"
+
+#include "base/logging.h"
+
+// This file provides the implementation for SizeBase template and
+// used to instantiate the base class for Size and SizeF classes.
+#if !defined(UI_IMPLEMENTATION)
+#error "This file is intended for UI implementation only"
+#endif
+
+namespace gfx {
+
+template<typename Class, typename Type>
+void SizeBase<Class, Type>::set_width(Type width) {
+ DCHECK(!(width < 0));
+ width_ = width < 0 ? 0 : width;
+}
+
+template<typename Class, typename Type>
+void SizeBase<Class, Type>::set_height(Type height) {
+ DCHECK(!(height < 0));
+ height_ = height < 0 ? 0 : height;
+}
+
+template<typename Class, typename Type>
+SizeBase<Class, Type>::SizeBase(Type width, Type height)
+ : width_(width < 0 ? 0 : width),
+ height_(height < 0 ? 0 : height) {
+ DCHECK(!(width < 0));
+ DCHECK(!(height < 0));
+}
+
+} // namespace gfx
diff --git a/ui/gfx/size_f.cc b/ui/gfx/size_f.cc
index 69e0ee9..53849633 100644
--- a/ui/gfx/size_f.cc
+++ b/ui/gfx/size_f.cc
@@ -4,8 +4,8 @@
#include "ui/gfx/size_f.h"
-#include "base/logging.h"
#include "base/stringprintf.h"
+#include "ui/gfx/size_base_impl.h"
namespace gfx {
diff --git a/ui/gfx/size_unittest.cc b/ui/gfx/size_unittest.cc
index a6fda9d..e68bdd6 100644
--- a/ui/gfx/size_unittest.cc
+++ b/ui/gfx/size_unittest.cc
@@ -43,12 +43,6 @@ TEST(SizeTest, ToFlooredSize) {
EXPECT_EQ(Size(10, 10), ToFlooredSize(SizeF(10.4999f, 10.4999f)));
EXPECT_EQ(Size(10, 10), ToFlooredSize(SizeF(10.5f, 10.5f)));
EXPECT_EQ(Size(10, 10), ToFlooredSize(SizeF(10.9999f, 10.9999f)));
-
- EXPECT_EQ(Size(-10, -10), ToFlooredSize(SizeF(-10, -10)));
- EXPECT_EQ(Size(-11, -11), ToFlooredSize(SizeF(-10.0001f, -10.0001f)));
- EXPECT_EQ(Size(-11, -11), ToFlooredSize(SizeF(-10.4999f, -10.4999f)));
- EXPECT_EQ(Size(-11, -11), ToFlooredSize(SizeF(-10.5f, -10.5f)));
- EXPECT_EQ(Size(-11, -11), ToFlooredSize(SizeF(-10.9999f, -10.9999f)));
}
TEST(SizeTest, ToCeiledSize) {
@@ -63,12 +57,6 @@ TEST(SizeTest, ToCeiledSize) {
EXPECT_EQ(Size(11, 11), ToCeiledSize(SizeF(10.4999f, 10.4999f)));
EXPECT_EQ(Size(11, 11), ToCeiledSize(SizeF(10.5f, 10.5f)));
EXPECT_EQ(Size(11, 11), ToCeiledSize(SizeF(10.9999f, 10.9999f)));
-
- EXPECT_EQ(Size(-10, -10), ToCeiledSize(SizeF(-10, -10)));
- EXPECT_EQ(Size(-10, -10), ToCeiledSize(SizeF(-10.0001f, -10.0001f)));
- EXPECT_EQ(Size(-10, -10), ToCeiledSize(SizeF(-10.4999f, -10.4999f)));
- EXPECT_EQ(Size(-10, -10), ToCeiledSize(SizeF(-10.5f, -10.5f)));
- EXPECT_EQ(Size(-10, -10), ToCeiledSize(SizeF(-10.9999f, -10.9999f)));
}
TEST(SizeTest, ToRoundedSize) {
@@ -83,12 +71,6 @@ TEST(SizeTest, ToRoundedSize) {
EXPECT_EQ(Size(10, 10), ToRoundedSize(SizeF(10.4999f, 10.4999f)));
EXPECT_EQ(Size(11, 11), ToRoundedSize(SizeF(10.5f, 10.5f)));
EXPECT_EQ(Size(11, 11), ToRoundedSize(SizeF(10.9999f, 10.9999f)));
-
- EXPECT_EQ(Size(-10, -10), ToRoundedSize(SizeF(-10, -10)));
- EXPECT_EQ(Size(-10, -10), ToRoundedSize(SizeF(-10.0001f, -10.0001f)));
- EXPECT_EQ(Size(-10, -10), ToRoundedSize(SizeF(-10.4999f, -10.4999f)));
- EXPECT_EQ(Size(-11, -11), ToRoundedSize(SizeF(-10.5f, -10.5f)));
- EXPECT_EQ(Size(-11, -11), ToRoundedSize(SizeF(-10.9999f, -10.9999f)));
}
TEST(SizeTest, ClampSize) {