diff options
author | danakj@chromium.org <danakj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-22 23:59:26 +0000 |
---|---|---|
committer | danakj@chromium.org <danakj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-22 23:59:26 +0000 |
commit | c27760a741d147470546da1fb3ba3e7b0cf45748 (patch) | |
tree | c95b75a17022199dce0b727978425a75eb23ba6d | |
parent | cd75f65816b3c5a66e42b3b94960d902fc5c3709 (diff) | |
download | chromium_src-c27760a741d147470546da1fb3ba3e7b0cf45748.zip chromium_src-c27760a741d147470546da1fb3ba3e7b0cf45748.tar.gz chromium_src-c27760a741d147470546da1fb3ba3e7b0cf45748.tar.bz2 |
Revert "ui: Remove gfx::Size::ClampToNonNegative, prevent negative sizes always."
This reverts commit 190d06bf03d4c310f042396046b2b5b5f7af43cf.
TBR=sky
> 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=175535
Review URL: https://codereview.chromium.org/12049019
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@178162 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | ash/system/user/tray_user.cc | 5 | ||||
-rw-r--r-- | chrome/browser/ui/extensions/shell_window.cc | 6 | ||||
-rw-r--r-- | chrome/browser/ui/extensions/shell_window.h | 5 | ||||
-rw-r--r-- | ui/base/gestures/gesture_sequence.cc | 4 | ||||
-rw-r--r-- | ui/gfx/rect_f.h | 5 | ||||
-rw-r--r-- | ui/gfx/rect_unittest.cc | 5 | ||||
-rw-r--r-- | ui/gfx/size.cc | 8 | ||||
-rw-r--r-- | ui/gfx/size_base.h | 17 | ||||
-rw-r--r-- | ui/gfx/size_base_impl.h | 37 | ||||
-rw-r--r-- | ui/gfx/size_f.cc | 2 | ||||
-rw-r--r-- | ui/gfx/size_unittest.cc | 18 | ||||
-rw-r--r-- | ui/ui.gyp | 1 |
12 files changed, 53 insertions, 60 deletions
diff --git a/ash/system/user/tray_user.cc b/ash/system/user/tray_user.cc index de5f7cb..f433887 100644 --- a/ash/system/user/tray_user.cc +++ b/ash/system/user/tray_user.cc @@ -432,9 +432,8 @@ void UserView::Layout() { // Give the remaining space to the user card. gfx::Rect user_card_area = contents_area; - int remaining_width = contents_area.width() - - (logout_area.width() + kTrayPopupPaddingBetweenItems); - user_card_area.set_width(std::max(0, remaining_width)); + user_card_area.set_width(contents_area.width() - + (logout_area.width() + kTrayPopupPaddingBetweenItems)); user_card_->SetBoundsRect(user_card_area); } else if (user_card_) { user_card_->SetBoundsRect(contents_area); diff --git a/chrome/browser/ui/extensions/shell_window.cc b/chrome/browser/ui/extensions/shell_window.cc index 64bec39..14b2524 100644 --- a/chrome/browser/ui/extensions/shell_window.cc +++ b/chrome/browser/ui/extensions/shell_window.cc @@ -91,7 +91,7 @@ ShellWindow::CreateParams::CreateParams() : window_type(ShellWindow::WINDOW_TYPE_DEFAULT), frame(ShellWindow::FRAME_CHROME), transparent_background(false), - bounds(INT_MIN, INT_MIN, 0, 0), + bounds(INT_MIN, INT_MIN, INT_MIN, INT_MIN), creator_process_id(0), hidden(false) { } @@ -139,9 +139,9 @@ void ShellWindow::Init(const GURL& url, gfx::Rect bounds = params.bounds; - if (bounds.width() == 0) + if (bounds.width() == INT_MIN) bounds.set_width(kDefaultWidth); - if (bounds.height() == 0) + if (bounds.height() == INT_MIN) bounds.set_height(kDefaultHeight); // If left and top are left undefined, the native shell window will center diff --git a/chrome/browser/ui/extensions/shell_window.h b/chrome/browser/ui/extensions/shell_window.h index 1f7844b..507c8e5 100644 --- a/chrome/browser/ui/extensions/shell_window.h +++ b/chrome/browser/ui/extensions/shell_window.h @@ -63,9 +63,8 @@ class ShellWindow : public content::NotificationObserver, bool transparent_background; // Only supported on ash. // Specify the initial content bounds of the window (excluding any window - // decorations). INT_MIN designates 'unspecified' for the position - // components, and 0 for the size components. When unspecified, they should - // be replaced with a default value. + // decorations). INT_MIN designates 'unspecified' for any coordinate, and + // should be replaced with a default value. gfx::Rect bounds; gfx::Size minimum_size; diff --git a/ui/base/gestures/gesture_sequence.cc b/ui/base/gestures/gesture_sequence.cc index 56c12a8..75932ec 100644 --- a/ui/base/gestures/gesture_sequence.cc +++ b/ui/base/gestures/gesture_sequence.cc @@ -537,9 +537,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 78524a0..bbc16cc 100644 --- a/ui/gfx/rect_f.h +++ b/ui/gfx/rect_f.h @@ -49,7 +49,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 f0bf7d5..bf15c8f 100644 --- a/ui/gfx/rect_unittest.cc +++ b/ui/gfx/rect_unittest.cc @@ -441,7 +441,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 4f9ff64..a9a0bdd 100644 --- a/ui/gfx/size.cc +++ b/ui/gfx/size.cc @@ -8,16 +8,18 @@ #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 { template class SizeBase<Size, int>; #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 53849633..69e0ee9 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 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) { @@ -477,7 +477,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', |