summaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorshawnsingh@chromium.org <shawnsingh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-13 22:56:32 +0000
committershawnsingh@chromium.org <shawnsingh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-13 22:56:32 +0000
commitb1b842bbf7f21c593f0fb08ac19e213ec2f710eb (patch)
tree9b3fca6b021476b9e75e3ea08d8a39bc6e7f3e31 /ui
parent440ad534bead94ffc6c0237ef86b7fbb55aa3bda (diff)
downloadchromium_src-b1b842bbf7f21c593f0fb08ac19e213ec2f710eb.zip
chromium_src-b1b842bbf7f21c593f0fb08ac19e213ec2f710eb.tar.gz
chromium_src-b1b842bbf7f21c593f0fb08ac19e213ec2f710eb.tar.bz2
Revert 167255 - 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/ Review URL: https://codereview.chromium.org/11410024 TBR=danakj@chromium.org Review URL: https://codereview.chromium.org/11359194 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@167504 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r--ui/base/gestures/gesture_sequence.cc4
-rw-r--r--ui/gfx/rect_f.h5
-rw-r--r--ui/gfx/rect_unittest.cc5
-rw-r--r--ui/gfx/size.cc13
-rw-r--r--ui/gfx/size_base.h17
-rw-r--r--ui/gfx/size_base_impl.h37
-rw-r--r--ui/gfx/size_f.cc7
-rw-r--r--ui/gfx/size_unittest.cc18
-rw-r--r--ui/ui.gyp1
9 files changed, 52 insertions, 55 deletions
diff --git a/ui/base/gestures/gesture_sequence.cc b/ui/base/gestures/gesture_sequence.cc
index a044145..c4a6d31 100644
--- a/ui/base/gestures/gesture_sequence.cc
+++ b/ui/base/gestures/gesture_sequence.cc
@@ -583,9 +583,7 @@ GestureSequence::Gestures* GestureSequence::ProcessTouchEventForGesture(
void GestureSequence::RecreateBoundingBox() {
// TODO(sad): Recreating the bounding box at every touch-event is not very
// efficient. This should be made better.
- if (point_count_ == 0) {
- bounding_box_.SetRect(0, 0, 0, 0);
- } else if (point_count_ == 1) {
+ if (point_count_ == 1) {
bounding_box_ = GetPointByPointId(0)->enclosing_rectangle();
} else {
int left = INT_MAX / 20, top = INT_MAX / 20;
diff --git a/ui/gfx/rect_f.h b/ui/gfx/rect_f.h
index 272eb3c..2bc367c 100644
--- a/ui/gfx/rect_f.h
+++ b/ui/gfx/rect_f.h
@@ -35,7 +35,10 @@ class UI_EXPORT RectF
void Scale(float x_scale, float y_scale) {
set_origin(ScalePoint(origin(), x_scale, y_scale));
- set_size(ScaleSize(size(), x_scale, y_scale));
+
+ SizeF new_size = gfx::ScaleSize(size(), x_scale, y_scale);
+ new_size.ClampToNonNegative();
+ set_size(new_size);
}
// 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 dce1e38..f8222c6 100644
--- a/ui/gfx/rect_unittest.cc
+++ b/ui/gfx/rect_unittest.cc
@@ -433,7 +433,10 @@ TEST(RectTest, ScaleRect) {
std::numeric_limits<float>::max(),
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 }
};
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
diff --git a/ui/gfx/size.cc b/ui/gfx/size.cc
index 26bb973..6d28ded 100644
--- a/ui/gfx/size.cc
+++ b/ui/gfx/size.cc
@@ -8,8 +8,9 @@
#include <windows.h>
#endif
+#include "base/logging.h"
#include "base/stringprintf.h"
-#include "ui/gfx/size_base_impl.h"
+#include "ui/gfx/size_base.h"
namespace gfx {
@@ -17,13 +18,15 @@ template class SizeBase<Size, int>;
Size::Size() : SizeBase<Size, int>(0, 0) {}
-Size::Size(int width, int height)
- : SizeBase<Size, int>(width, height) {
+Size::Size(int width, int height) : SizeBase<Size, int>(0, 0) {
+ set_width(width);
+ set_height(height);
}
#if defined(OS_MACOSX)
-Size::Size(const CGSize& s)
- : SizeBase<Size, int>(s.width, s.height) {
+Size::Size(const CGSize& s) : SizeBase<Size, int>(0, 0) {
+ set_width(s.width);
+ set_height(s.height);
}
Size& Size::operator=(const CGSize& s) {
diff --git a/ui/gfx/size_base.h b/ui/gfx/size_base.h
index 3d171f1..0ec62e4 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);
- void set_height(Type height);
+ void set_width(Type width) { width_ = width; }
+ void set_height(Type height) { height_ = height; }
void ClampToMax(const Class& max) {
width_ = width_ <= max.width_ ? width_ : max.width_;
@@ -42,11 +42,20 @@ class UI_EXPORT SizeBase {
}
bool IsEmpty() const {
- return (width_ == 0) || (height_ == 0);
+ return (width_ <= 0) || (height_ <= 0);
+ }
+
+ void ClampToNonNegative() {
+ if (width_ < 0)
+ width_ = 0;
+ if (height_ < 0)
+ height_ = 0;
}
protected:
- SizeBase(Type width, Type height);
+ SizeBase(Type width, Type height)
+ : width_(width),
+ height_(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
deleted file mode 100644
index 9e87468..0000000
--- a/ui/gfx/size_base_impl.h
+++ /dev/null
@@ -1,37 +0,0 @@
-// 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 1dc407e..03c34ec 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 {
@@ -13,8 +13,9 @@ template class SizeBase<SizeF, float>;
SizeF::SizeF() : SizeBase<SizeF, float>(0, 0) {}
-SizeF::SizeF(float width, float height)
- : SizeBase<SizeF, float>(width, height) {
+SizeF::SizeF(float width, float height) : SizeBase<SizeF, float>(0, 0) {
+ set_width(width);
+ set_height(height);
}
SizeF::~SizeF() {}
diff --git a/ui/gfx/size_unittest.cc b/ui/gfx/size_unittest.cc
index e68bdd6..a6fda9d 100644
--- a/ui/gfx/size_unittest.cc
+++ b/ui/gfx/size_unittest.cc
@@ -43,6 +43,12 @@ 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) {
@@ -57,6 +63,12 @@ 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) {
@@ -71,6 +83,12 @@ 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) {
diff --git a/ui/ui.gyp b/ui/ui.gyp
index 82c8757..0b1d0c2 100644
--- a/ui/ui.gyp
+++ b/ui/ui.gyp
@@ -499,7 +499,6 @@
'gfx/size.cc',
'gfx/size.h',
'gfx/size_base.h',
- 'gfx/size_base_impl.h',
'gfx/size_conversions.cc',
'gfx/size_conversions.h',
'gfx/size_f.cc',