Commit 190d06bf authored by danakj@chromium.org's avatar danakj@chromium.org

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
parent 41b92664
......@@ -432,8 +432,9 @@ void UserView::Layout() {
// Give the remaining space to the user card.
gfx::Rect user_card_area = contents_area;
user_card_area.set_width(contents_area.width() -
(logout_area.width() + kTrayPopupPaddingBetweenItems));
int remaining_width = contents_area.width() -
(logout_area.width() + kTrayPopupPaddingBetweenItems);
user_card_area.set_width(std::max(0, remaining_width));
user_card_->SetBoundsRect(user_card_area);
} else if (user_card_) {
user_card_->SetBoundsRect(contents_area);
......
......@@ -362,7 +362,7 @@ TEST(DrawQuadTest, copyTextureDrawQuad)
gfx::Rect opaqueRect(3, 7, 10, 12);
unsigned resourceId = 82;
bool premultipliedAlpha = true;
gfx::RectF uvRect(0.5, 224, -51, 36);
gfx::RectF uvRect(0.5f, 224.f, 51.f, 36.f);
const float vertex_opacity[] = {1.0f, 1.0f, 1.0f, 1.0f};
bool flipped = true;
CREATE_SHARED_STATE();
......
......@@ -90,7 +90,7 @@ void SuspendRenderViewHost(RenderViewHost* rvh) {
ShellWindow::CreateParams::CreateParams()
: window_type(ShellWindow::WINDOW_TYPE_DEFAULT),
frame(ShellWindow::FRAME_CHROME),
bounds(INT_MIN, INT_MIN, INT_MIN, INT_MIN),
bounds(INT_MIN, INT_MIN, 0, 0),
creator_process_id(0), hidden(false) {
}
......@@ -138,9 +138,9 @@ void ShellWindow::Init(const GURL& url,
gfx::Rect bounds = params.bounds;
if (bounds.width() == INT_MIN)
if (bounds.width() == 0)
bounds.set_width(kDefaultWidth);
if (bounds.height() == INT_MIN)
if (bounds.height() == 0)
bounds.set_height(kDefaultHeight);
// If left and top are left undefined, the native shell window will center
......
......@@ -62,8 +62,9 @@ class ShellWindow : public content::NotificationObserver,
Frame frame;
// Specify the initial content bounds of the window (excluding any window
// decorations). INT_MIN designates 'unspecified' for any coordinate, and
// should be replaced with a default value.
// 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.
gfx::Rect bounds;
gfx::Size minimum_size;
......
......@@ -537,7 +537,9 @@ 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_ == 1) {
if (point_count_ == 0) {
bounding_box_.SetRect(0, 0, 0, 0);
} else if (point_count_ == 1) {
bounding_box_ = GetPointByPointId(0)->enclosing_rectangle();
} else {
int left = INT_MAX / 20, top = INT_MAX / 20;
......
......@@ -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
......
......@@ -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) {
......
......@@ -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) {
......
......@@ -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.
......
// 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
......@@ -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 {
......
......@@ -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) {
......
......@@ -498,6 +498,7 @@
'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',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment