diff options
author | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-08 00:09:16 +0000 |
---|---|---|
committer | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-08 00:09:16 +0000 |
commit | 97a311466bc7db336d8315587ff1b2ec06f7ea9c (patch) | |
tree | 524babd269504a1a13a6a9874014d0dd52fc25ea /views | |
parent | 9d333fa174e9653dcbe60e525d4c03628bb217ae (diff) | |
download | chromium_src-97a311466bc7db336d8315587ff1b2ec06f7ea9c.zip chromium_src-97a311466bc7db336d8315587ff1b2ec06f7ea9c.tar.gz chromium_src-97a311466bc7db336d8315587ff1b2ec06f7ea9c.tar.bz2 |
Rework basic bounds methods on View to match new V2 API:
SetBounds(const gfx::Rect& rect) -> SetBoundsRect();
DidChangeBounds()->OnBoundsChanged()
GetLocalBounds(false)->GetLocalBounds()
GetLocalBounds(true)->GetContentsBounds()
Moved GetBounds(), GetX(), and GetPosition into RTL section.
http://crbug.com/72040
TEST=none
Review URL: http://codereview.chromium.org/6410109
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@74052 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views')
43 files changed, 195 insertions, 211 deletions
diff --git a/views/animation/bounds_animator.cc b/views/animation/bounds_animator.cc index 4ba8d86..652f743 100644 --- a/views/animation/bounds_animator.cc +++ b/views/animation/bounds_animator.cc @@ -215,7 +215,7 @@ void BoundsAnimator::AnimationProgressed(const Animation* animation) { else repaint_bounds_ = repaint_bounds_.Union(total_bounds); - view->SetBounds(new_bounds); + view->SetBoundsRect(new_bounds); } if (data.delegate) diff --git a/views/animation/bounds_animator_unittest.cc b/views/animation/bounds_animator_unittest.cc index c234b1f..ba4b93b 100644 --- a/views/animation/bounds_animator_unittest.cc +++ b/views/animation/bounds_animator_unittest.cc @@ -115,7 +115,7 @@ class BoundsAnimatorTest : public testing::Test { TEST_F(BoundsAnimatorTest, AnimateViewTo) { TestAnimationDelegate delegate; gfx::Rect initial_bounds(0, 0, 10, 10); - child()->SetBounds(initial_bounds); + child()->SetBoundsRect(initial_bounds); gfx::Rect target_bounds(10, 10, 20, 20); animator()->AnimateViewTo(child(), target_bounds); animator()->SetAnimationDelegate(child(), &delegate, false); diff --git a/views/controls/button/button_dropdown.cc b/views/controls/button/button_dropdown.cc index 01d62e7..8d3ce74 100644 --- a/views/controls/button/button_dropdown.cc +++ b/views/controls/button/button_dropdown.cc @@ -129,7 +129,7 @@ bool ButtonDropDown::ShouldEnterPushedState(const MouseEvent& e) { void ButtonDropDown::ShowDropDownMenu(gfx::NativeView window) { if (model_) { - gfx::Rect lb = GetLocalBounds(true); + gfx::Rect lb = GetContentsBounds(); // Both the menu position and the menu anchor type change if the UI layout // is right-to-left. diff --git a/views/controls/button/checkbox.cc b/views/controls/button/checkbox.cc index 980efbc..36825b9 100644 --- a/views/controls/button/checkbox.cc +++ b/views/controls/button/checkbox.cc @@ -127,7 +127,7 @@ View* Checkbox::GetViewForPoint(const gfx::Point& point) { View* Checkbox::GetViewForPoint(const gfx::Point& point, bool can_create_floating) { - return GetLocalBounds(true).Contains(point) ? this : NULL; + return GetContentsBounds().Contains(point) ? this : NULL; } void Checkbox::OnMouseEntered(const MouseEvent& e) { diff --git a/views/controls/button/menu_button.cc b/views/controls/button/menu_button.cc index f56f343..79b72e27 100644 --- a/views/controls/button/menu_button.cc +++ b/views/controls/button/menu_button.cc @@ -126,7 +126,7 @@ bool MenuButton::Activate() { // after the menu closes. PaintNow(); if (menu_delegate_) { - gfx::Rect lb = GetLocalBounds(true); + gfx::Rect lb = GetContentsBounds(); // The position of the menu depends on whether or not the locale is // right-to-left. diff --git a/views/controls/label.cc b/views/controls/label.cc index 8f0c536..427d7ad 100644 --- a/views/controls/label.cc +++ b/views/controls/label.cc @@ -73,8 +73,7 @@ int Label::GetHeightForWidth(int w) { return h + GetInsets().height(); } -void Label::DidChangeBounds(const gfx::Rect& previous, - const gfx::Rect& current) { +void Label::OnBoundsChanged() { text_size_valid_ &= !is_multi_line_; } diff --git a/views/controls/label.h b/views/controls/label.h index 608b9cf..8ff6e51 100644 --- a/views/controls/label.h +++ b/views/controls/label.h @@ -66,8 +66,7 @@ class Label : public View { virtual int GetHeightForWidth(int w); // Overriden to dirty our text bounds if we're multi-line. - virtual void DidChangeBounds(const gfx::Rect& previous, - const gfx::Rect& current); + virtual void OnBoundsChanged(); // Returns views/Label. virtual std::string GetClassName() const { return kViewClassName; } diff --git a/views/controls/label_unittest.cc b/views/controls/label_unittest.cc index 879bdc2..d556512 100644 --- a/views/controls/label_unittest.cc +++ b/views/controls/label_unittest.cc @@ -208,12 +208,12 @@ TEST(LabelTest, MultiLineSizing) { // SizeToFit with unlimited width. label.SizeToFit(0); - int required_width = label.GetLocalBounds(true).width(); + int required_width = label.GetContentsBounds().width(); EXPECT_GT(required_width, kMinTextDimension); // SizeToFit with limited width. label.SizeToFit(required_width - 1); - int constrained_width = label.GetLocalBounds(true).width(); + int constrained_width = label.GetContentsBounds().width(); #if defined(OS_WIN) // Canvas::SizeStringInt (in app/gfx/canvas_linux.cc) // has to be fixed to return the size that fits to given width/height. @@ -223,7 +223,7 @@ TEST(LabelTest, MultiLineSizing) { // Change the width back to the desire width. label.SizeToFit(required_width); - EXPECT_EQ(required_width, label.GetLocalBounds(true).width()); + EXPECT_EQ(required_width, label.GetContentsBounds().width()); // General tests for GetHeightForWidth. int required_height = label.GetHeightForWidth(required_width); @@ -249,7 +249,7 @@ TEST(LabelTest, MultiLineSizing) { // SizeToFit and borders. label.SizeToFit(0); - int required_width_with_border = label.GetLocalBounds(true).width(); + int required_width_with_border = label.GetLocalBounds().width(); EXPECT_EQ(required_width_with_border, required_width + border.width()); // GetHeightForWidth and borders. diff --git a/views/controls/menu/menu_controller.cc b/views/controls/menu/menu_controller.cc index b670212..72c6ca4 100644 --- a/views/controls/menu/menu_controller.cc +++ b/views/controls/menu/menu_controller.cc @@ -70,7 +70,7 @@ bool TitleMatchesMnemonic(MenuItemView* menu, wchar_t key) { // Convenience for scrolling the view such that the origin is visible. static void ScrollToVisible(View* view) { - view->ScrollRectToVisible(gfx::Rect(gfx::Point(), view->size())); + view->ScrollRectToVisible(view->GetLocalBounds()); } // Returns the first descendant of |view| that is hot tracked. diff --git a/views/controls/menu/menu_scroll_view_container.cc b/views/controls/menu/menu_scroll_view_container.cc index 61f8994..3ecc3ba 100644 --- a/views/controls/menu/menu_scroll_view_container.cc +++ b/views/controls/menu/menu_scroll_view_container.cc @@ -252,8 +252,7 @@ void MenuScrollViewContainer::Layout() { scroll_view_->Layout(); } -void MenuScrollViewContainer::DidChangeBounds(const gfx::Rect& previous, - const gfx::Rect& current) { +void MenuScrollViewContainer::OnBoundsChanged() { gfx::Size content_pref = scroll_view_->GetContents()->GetPreferredSize(); scroll_up_button_->SetVisible(content_pref.height() > height()); scroll_down_button_->SetVisible(content_pref.height() > height()); diff --git a/views/controls/menu/menu_scroll_view_container.h b/views/controls/menu/menu_scroll_view_container.h index 52a2b78..d8dbe0c 100644 --- a/views/controls/menu/menu_scroll_view_container.h +++ b/views/controls/menu/menu_scroll_view_container.h @@ -26,8 +26,7 @@ class MenuScrollViewContainer : public View { // View overrides. virtual void PaintBackground(gfx::Canvas* canvas); virtual void Layout(); - virtual void DidChangeBounds(const gfx::Rect& previous, - const gfx::Rect& current); + virtual void OnBoundsChanged(); virtual gfx::Size GetPreferredSize(); virtual AccessibilityTypes::Role GetAccessibleRole(); virtual AccessibilityTypes::State GetAccessibleState(); diff --git a/views/controls/menu/submenu_view.cc b/views/controls/menu/submenu_view.cc index 4a0c1ba..2a81484 100644 --- a/views/controls/menu/submenu_view.cc +++ b/views/controls/menu/submenu_view.cc @@ -122,8 +122,7 @@ gfx::Size SubmenuView::GetPreferredSize() { height + insets.height()); } -void SubmenuView::DidChangeBounds(const gfx::Rect& previous, - const gfx::Rect& current) { +void SubmenuView::OnBoundsChanged() { SchedulePaint(); } diff --git a/views/controls/menu/submenu_view.h b/views/controls/menu/submenu_view.h index fa2b9a7..cbe2674 100644 --- a/views/controls/menu/submenu_view.h +++ b/views/controls/menu/submenu_view.h @@ -53,10 +53,9 @@ class SubmenuView : public View { virtual void Layout(); virtual gfx::Size GetPreferredSize(); - // View method. Overriden to schedule a paint. We do this so that when + // View method. Overridden to schedule a paint. We do this so that when // scrolling occurs, everything is repainted correctly. - virtual void DidChangeBounds(const gfx::Rect& previous, - const gfx::Rect& current); + virtual void OnBoundsChanged(); // Override from View. virtual AccessibilityTypes::Role GetAccessibleRole(); diff --git a/views/controls/native/native_view_host.cc b/views/controls/native/native_view_host.cc index c3fc77e..2ccd207 100644 --- a/views/controls/native/native_view_host.cc +++ b/views/controls/native/native_view_host.cc @@ -121,7 +121,7 @@ void NativeViewHost::Layout() { gfx::Insets insets = GetInsets(); gfx::Point top_left(insets.left(), insets.top()); ConvertPointToWidget(this, &top_left); - gfx::Rect local_bounds = GetLocalBounds(false); + gfx::Rect local_bounds = GetLocalBounds(); native_wrapper_->ShowWidget(top_left.x(), top_left.y(), local_bounds.width(), local_bounds.height()); diff --git a/views/controls/native_control.cc b/views/controls/native_control.cc index 5b643a6..caea8c1 100644 --- a/views/controls/native_control.cc +++ b/views/controls/native_control.cc @@ -223,7 +223,7 @@ void NativeControl::Layout() { ValidateNativeControl(); if (hwnd_view_) { - gfx::Rect lb = GetLocalBounds(false); + gfx::Rect lb = GetLocalBounds(); int x = lb.x(); int y = lb.y(); diff --git a/views/controls/scroll_view.cc b/views/controls/scroll_view.cc index 86e7a00..ecaf3e2 100644 --- a/views/controls/scroll_view.cc +++ b/views/controls/scroll_view.cc @@ -147,7 +147,7 @@ void ScrollView::Layout() { // override this default behavior, the inner view has to calculate the // available space, used ComputeScrollBarsVisibility() to use the same // calculation that is done here and sets its bound to fit within. - gfx::Rect viewport_bounds = GetLocalBounds(true); + gfx::Rect viewport_bounds = GetContentsBounds(); // Realign it to 0 so it can be used as-is for SetBounds(). viewport_bounds.set_origin(gfx::Point(0, 0)); // viewport_size is the total client space available. @@ -163,7 +163,7 @@ void ScrollView::Layout() { int vert_sb_width = GetScrollBarWidth(); viewport_bounds.set_width(viewport_bounds.width() - vert_sb_width); // Update the bounds right now so the inner views can fit in it. - viewport_->SetBounds(viewport_bounds); + viewport_->SetBoundsRect(viewport_bounds); // Give contents_ a chance to update its bounds if it depends on the // viewport. @@ -220,7 +220,7 @@ void ScrollView::Layout() { } // Update to the real client size with the visible scrollbars. - viewport_->SetBounds(viewport_bounds); + viewport_->SetBoundsRect(viewport_bounds); if (should_layout_contents && contents_) contents_->Layout(); diff --git a/views/controls/scrollbar/bitmap_scroll_bar.cc b/views/controls/scrollbar/bitmap_scroll_bar.cc index 9fccb46..cf0e919 100644 --- a/views/controls/scrollbar/bitmap_scroll_bar.cc +++ b/views/controls/scrollbar/bitmap_scroll_bar.cc @@ -118,7 +118,7 @@ class BitmapScrollBarThumb : public View { } else { thumb_bounds.set_height(size); } - SetBounds(thumb_bounds); + SetBoundsRect(thumb_bounds); } // Retrieves the size (width or height) of the thumb. @@ -137,7 +137,7 @@ class BitmapScrollBarThumb : public View { } else { thumb_bounds.set_y(track_bounds.y() + position); } - SetBounds(thumb_bounds); + SetBoundsRect(thumb_bounds); } // Gets the position of the thumb on the x or y axis. diff --git a/views/controls/scrollbar/native_scroll_bar_gtk.cc b/views/controls/scrollbar/native_scroll_bar_gtk.cc index 0a1bc73..225dbaa 100644 --- a/views/controls/scrollbar/native_scroll_bar_gtk.cc +++ b/views/controls/scrollbar/native_scroll_bar_gtk.cc @@ -28,7 +28,7 @@ NativeScrollBarGtk::~NativeScrollBarGtk() { // NativeScrollBarGtk, View overrides: void NativeScrollBarGtk::Layout() { - SetBounds(native_scroll_bar_->GetLocalBounds(true)); + SetBoundsRect(native_scroll_bar_->GetContentsBounds()); NativeControlGtk::Layout(); } diff --git a/views/controls/scrollbar/native_scroll_bar_win.cc b/views/controls/scrollbar/native_scroll_bar_win.cc index 02b790a..70cf432 100644 --- a/views/controls/scrollbar/native_scroll_bar_win.cc +++ b/views/controls/scrollbar/native_scroll_bar_win.cc @@ -216,7 +216,7 @@ NativeScrollBarWin::~NativeScrollBarWin() { // NativeScrollBarWin, View overrides: void NativeScrollBarWin::Layout() { - SetBounds(native_scroll_bar_->GetLocalBounds(true)); + SetBoundsRect(native_scroll_bar_->GetContentsBounds()); NativeControlWin::Layout(); } diff --git a/views/controls/single_split_view.cc b/views/controls/single_split_view.cc index 9f5d7dd..3936ad6 100644 --- a/views/controls/single_split_view.cc +++ b/views/controls/single_split_view.cc @@ -38,10 +38,10 @@ SingleSplitView::SingleSplitView(View* leading, #endif } -void SingleSplitView::DidChangeBounds(const gfx::Rect& previous, - const gfx::Rect& current) { - divider_offset_ = CalculateDividerOffset(divider_offset_, previous, current); - View::DidChangeBounds(previous, current); +void SingleSplitView::OnBoundsChanged() { + divider_offset_ = CalculateDividerOffset(divider_offset_, previous_bounds_, bounds()); + View::OnBoundsChanged(); + previous_bounds_ = bounds(); } void SingleSplitView::Layout() { @@ -51,10 +51,10 @@ void SingleSplitView::Layout() { if (GetChildViewCount() > 0) { if (GetChildViewAt(0)->IsVisible()) - GetChildViewAt(0)->SetBounds(leading_bounds); + GetChildViewAt(0)->SetBoundsRect(leading_bounds); if (GetChildViewCount() > 1) { if (GetChildViewAt(1)->IsVisible()) - GetChildViewAt(1)->SetBounds(trailing_bounds); + GetChildViewAt(1)->SetBoundsRect(trailing_bounds); } } diff --git a/views/controls/single_split_view.h b/views/controls/single_split_view.h index a1b0534..57f4cc3 100644 --- a/views/controls/single_split_view.h +++ b/views/controls/single_split_view.h @@ -39,9 +39,7 @@ class SingleSplitView : public views::View { Orientation orientation, Observer* observer); - virtual void DidChangeBounds(const gfx::Rect& previous, - const gfx::Rect& current); - + virtual void OnBoundsChanged(); virtual void Layout(); virtual AccessibilityTypes::Role GetAccessibleRole(); @@ -125,6 +123,10 @@ class SingleSplitView : public views::View { // Position of the divider. int divider_offset_; + // The bounds of the SingleSplitView as a result of the last resize. Used to + // determine the divider position when a subsequent resize occurs. + gfx::Rect previous_bounds_; + bool resize_leading_on_bounds_change_; // Observer to notify about user initiated handle movements. Not own by us. diff --git a/views/controls/single_split_view_unittest.cc b/views/controls/single_split_view_unittest.cc index b788a37..3d84bd7 100644 --- a/views/controls/single_split_view_unittest.cc +++ b/views/controls/single_split_view_unittest.cc @@ -116,15 +116,13 @@ TEST(SingleSplitViewTest, Resize) { split.GetChildViewAt(0)->SetVisible(false); split.Layout(); - EXPECT_EQ(split.bounds().size(), - split.GetChildViewAt(1)->bounds().size()); + EXPECT_EQ(split.size(), split.GetChildViewAt(1)->size()); split.GetChildViewAt(0)->SetVisible(true); split.GetChildViewAt(1)->SetVisible(false); split.Layout(); - EXPECT_EQ(split.bounds().size(), - split.GetChildViewAt(0)->bounds().size()); + EXPECT_EQ(split.size(), split.GetChildViewAt(0)->size()); } } diff --git a/views/controls/slider/slider.cc b/views/controls/slider/slider.cc index 00dba0c..66615fd 100644 --- a/views/controls/slider/slider.cc +++ b/views/controls/slider/slider.cc @@ -57,7 +57,7 @@ void Slider::SetValue(double value) { void Slider::Layout() { if (native_wrapper_) { - native_wrapper_->GetView()->SetBounds(GetLocalBounds(true)); + native_wrapper_->GetView()->SetBoundsRect(GetContentsBounds()); native_wrapper_->GetView()->Layout(); } } diff --git a/views/controls/tabbed_pane/native_tabbed_pane_win.cc b/views/controls/tabbed_pane/native_tabbed_pane_win.cc index 93b1c80..1b64f61 100644 --- a/views/controls/tabbed_pane/native_tabbed_pane_win.cc +++ b/views/controls/tabbed_pane/native_tabbed_pane_win.cc @@ -57,7 +57,7 @@ class TabLayout : public LayoutManager { View* child = host->GetChildViewAt(i); // The child might not have been laid out yet. if (child == page) - child->SetBounds(gfx::Rect(host->size())); + child->SetBoundsRect(host->GetLocalBounds()); child->SetVisible(child == page); } @@ -72,12 +72,12 @@ class TabLayout : public LayoutManager { private: // LayoutManager overrides: virtual void Layout(View* host) { - gfx::Rect bounds(host->size()); + gfx::Rect bounds(host->GetLocalBounds()); for (int i = 0; i < host->GetChildViewCount(); ++i) { View* child = host->GetChildViewAt(i); // We only layout visible children, since it may be expensive. if (child->IsVisible() && child->bounds() != bounds) - child->SetBounds(bounds); + child->SetBoundsRect(bounds); } } diff --git a/views/controls/table/table_view.cc b/views/controls/table/table_view.cc index df79b91..f226cd0 100644 --- a/views/controls/table/table_view.cc +++ b/views/controls/table/table_view.cc @@ -128,8 +128,7 @@ void TableView::SetSortDescriptors(const SortDescriptors& sort_descriptors) { SendMessage(list_view_, WM_SETREDRAW, static_cast<WPARAM>(TRUE), 0); } -void TableView::DidChangeBounds(const gfx::Rect& previous, - const gfx::Rect& current) { +void TableView::OnBoundsChanged() { if (!list_view_) return; SendMessage(list_view_, WM_SETREDRAW, static_cast<WPARAM>(FALSE), 0); diff --git a/views/controls/table/table_view.h b/views/controls/table/table_view.h index 0d56302..620845d 100644 --- a/views/controls/table/table_view.h +++ b/views/controls/table/table_view.h @@ -162,8 +162,7 @@ class TableView : public NativeControl, // Current sort. const SortDescriptors& sort_descriptors() const { return sort_descriptors_; } - void DidChangeBounds(const gfx::Rect& previous, - const gfx::Rect& current); + virtual void OnBoundsChanged(); // Returns the number of rows in the TableView. int RowCount() const; diff --git a/views/controls/table/table_view2.cc b/views/controls/table/table_view2.cc index 444dd9b..6359e25 100644 --- a/views/controls/table/table_view2.cc +++ b/views/controls/table/table_view2.cc @@ -291,11 +291,6 @@ void TableView2::ResetColumnSizes() { } } -void TableView2::DidChangeBounds(const gfx::Rect& previous, - const gfx::Rect& current) { - Layout(); -} - void TableView2::Layout() { if (native_wrapper_) { native_wrapper_->GetView()->SetBounds(0, 0, width(), height()); diff --git a/views/controls/table/table_view2.h b/views/controls/table/table_view2.h index 679a6c8..b6b8234 100644 --- a/views/controls/table/table_view2.h +++ b/views/controls/table/table_view2.h @@ -195,8 +195,6 @@ class TableView2 : public View, public TableModelObserver { return vertical_lines_; } - virtual void DidChangeBounds(const gfx::Rect& previous, - const gfx::Rect& current); virtual void Layout(); virtual void PaintFocusBorder(gfx::Canvas* canvas); diff --git a/views/controls/textfield/native_textfield_views.cc b/views/controls/textfield/native_textfield_views.cc index 8b112e0..b02545f 100644 --- a/views/controls/textfield/native_textfield_views.cc +++ b/views/controls/textfield/native_textfield_views.cc @@ -122,8 +122,7 @@ void NativeTextfieldViews::Paint(gfx::Canvas* canvas) { PaintBorder(canvas); } -void NativeTextfieldViews::DidChangeBounds(const gfx::Rect& previous, - const gfx::Rect& current) { +void NativeTextfieldViews::OnBoundsChanged() { UpdateCursorBoundsAndTextOffset(); } diff --git a/views/controls/textfield/native_textfield_views.h b/views/controls/textfield/native_textfield_views.h index 5acbd03..4bf2be0 100644 --- a/views/controls/textfield/native_textfield_views.h +++ b/views/controls/textfield/native_textfield_views.h @@ -53,8 +53,7 @@ class NativeTextfieldViews : public views::View, virtual bool OnKeyPressed(const views::KeyEvent& e); virtual bool OnKeyReleased(const views::KeyEvent& e); virtual void Paint(gfx::Canvas* canvas); - virtual void DidChangeBounds(const gfx::Rect& previous, - const gfx::Rect& current); + virtual void OnBoundsChanged(); virtual void WillGainFocus(); virtual void DidGainFocus(); virtual void WillLoseFocus(); diff --git a/views/controls/textfield/textfield.cc b/views/controls/textfield/textfield.cc index dcd6061..09ac2f7 100644 --- a/views/controls/textfield/textfield.cc +++ b/views/controls/textfield/textfield.cc @@ -284,7 +284,7 @@ size_t Textfield::GetCursorPosition() const { void Textfield::Layout() { if (native_wrapper_) { - native_wrapper_->GetView()->SetBounds(GetLocalBounds(true)); + native_wrapper_->GetView()->SetBoundsRect(GetContentsBounds()); native_wrapper_->GetView()->Layout(); } } diff --git a/views/layout/box_layout.cc b/views/layout/box_layout.cc index 739d23e..a9aa227 100644 --- a/views/layout/box_layout.cc +++ b/views/layout/box_layout.cc @@ -24,16 +24,16 @@ BoxLayout::~BoxLayout() { } void BoxLayout::Layout(View* host) { - gfx::Rect childArea(gfx::Rect(host->size())); - childArea.Inset(host->GetInsets()); - childArea.Inset(inside_border_horizontal_spacing_, - inside_border_vertical_spacing_); - int x = childArea.x(); - int y = childArea.y(); + gfx::Rect child_area(host->GetLocalBounds()); + child_area.Inset(host->GetInsets()); + child_area.Inset(inside_border_horizontal_spacing_, + inside_border_vertical_spacing_); + int x = child_area.x(); + int y = child_area.y(); for (int i = 0; i < host->GetChildViewCount(); ++i) { View* child = host->GetChildViewAt(i); if (child->IsVisible()) { - gfx::Rect bounds(x, y, childArea.width(), childArea.height()); + gfx::Rect bounds(x, y, child_area.width(), child_area.height()); gfx::Size size(child->GetPreferredSize()); if (orientation_ == kHorizontal) { bounds.set_width(size.width()); @@ -42,8 +42,8 @@ void BoxLayout::Layout(View* host) { bounds.set_height(size.height()); y += size.height() + between_child_spacing_; } - // Clamp child view bounds to |childArea|. - child->SetBounds(bounds.Intersect(childArea)); + // Clamp child view bounds to |child_area|. + child->SetBoundsRect(bounds.Intersect(child_area)); } } } diff --git a/views/mouse_watcher.cc b/views/mouse_watcher.cc index 033a6f6b..b4c76d8 100644 --- a/views/mouse_watcher.cc +++ b/views/mouse_watcher.cc @@ -80,7 +80,7 @@ class MouseWatcher::Observer : public MessageLoopForUI::Observer { // Returns whether or not the cursor is currently in the view's "zone" which // is defined as a slightly larger region than the view. bool IsCursorInViewZone() { - gfx::Rect bounds = view()->GetLocalBounds(true); + gfx::Rect bounds = view()->GetContentsBounds(); gfx::Point view_topleft(bounds.origin()); View::ConvertPointToScreen(view(), &view_topleft); bounds.set_origin(view_topleft); diff --git a/views/view.cc b/views/view.cc index 2b23bb1..ff5a660 100644 --- a/views/view.cc +++ b/views/view.cc @@ -208,19 +208,11 @@ void View::PrintFocusHierarchy() { // Size and disposition -------------------------------------------------------- -gfx::Rect View::GetBounds(PositionMirroringSettings settings) const { - gfx::Rect bounds(bounds_); - - // If the parent uses an RTL UI layout and if we are asked to transform the - // bounds to their mirrored position if necessary, then we should shift the - // rectangle appropriately. - if (settings == APPLY_MIRRORING_TRANSFORMATION) - bounds.set_x(MirroredX()); - - return bounds; +void View::SetBounds(int x, int y, int width, int height) { + SetBoundsRect(gfx::Rect(x, y, std::max(0, width), std::max(0, height))); } -void View::SetBounds(const gfx::Rect& bounds) { +void View::SetBoundsRect(const gfx::Rect& bounds) { if (bounds == bounds_) { if (needs_layout_) { needs_layout_ = false; @@ -235,7 +227,7 @@ void View::SetBounds(const gfx::Rect& bounds) { bool position_changed = prev.origin() != bounds_.origin(); if (size_changed || position_changed) { - DidChangeBounds(prev, bounds_); + OnBoundsChanged(); RootView* root = GetRootView(); if (root) @@ -243,21 +235,39 @@ void View::SetBounds(const gfx::Rect& bounds) { } } -// y(), width() and height() are agnostic to the RTL UI layout of the -// parent view. x(), on the other hand, is not. -int View::GetX(PositionMirroringSettings settings) const { - return settings == IGNORE_MIRRORING_TRANSFORMATION ? x() : MirroredX(); +void View::SetSize(const gfx::Size& size) { + SetBounds(x(), y(), size.width(), size.height()); } -gfx::Rect View::GetLocalBounds(bool include_border) const { - if (include_border || !border_.get()) - return gfx::Rect(0, 0, width(), height()); +void View::SetPosition(const gfx::Point& position) { + SetBounds(position.x(), position.y(), width(), height()); +} - gfx::Insets insets; - border_->GetInsets(&insets); - return gfx::Rect(insets.left(), insets.top(), - std::max(0, width() - insets.width()), - std::max(0, height() - insets.height())); +void View::SetX(int x) { + SetBounds(x, y(), width(), height()); +} + +void View::SetY(int y) { + SetBounds(x(), y, width(), height()); +} + +void View::OnBoundsChanged() { + needs_layout_ = false; + Layout(); +} + +gfx::Rect View::GetContentsBounds() const { + gfx::Rect contents_bounds(GetLocalBounds()); + if (border_.get()) { + gfx::Insets insets; + border_->GetInsets(&insets); + contents_bounds.Inset(insets); + } + return contents_bounds; +} + +gfx::Rect View::GetLocalBounds() const { + return gfx::Rect(0, 0, width(), height()); } gfx::Insets View::GetInsets() const { @@ -303,10 +313,6 @@ gfx::Rect View::GetScreenBounds() const { return gfx::Rect(origin, size()); } -gfx::Point View::GetPosition() const { - return gfx::Point(GetX(APPLY_MIRRORING_TRANSFORMATION), y()); -} - gfx::Size View::GetPreferredSize() { if (layout_manager_.get()) return layout_manager_->GetPreferredSize(this); @@ -333,12 +339,6 @@ int View::GetHeightForWidth(int w) { return GetPreferredSize().height(); } -void View::DidChangeBounds(const gfx::Rect& previous, - const gfx::Rect& current) { - needs_layout_ = false; - Layout(); -} - void View::SetVisible(bool flag) { if (flag != is_visible_) { // If the tab is currently visible, schedule paint to @@ -378,6 +378,28 @@ bool View::IsEnabled() const { // RTL positioning ------------------------------------------------------------- +gfx::Rect View::GetBounds(PositionMirroringSettings settings) const { + gfx::Rect bounds(bounds_); + + // If the parent uses an RTL UI layout and if we are asked to transform the + // bounds to their mirrored position if necessary, then we should shift the + // rectangle appropriately. + if (settings == APPLY_MIRRORING_TRANSFORMATION) + bounds.set_x(MirroredX()); + + return bounds; +} + +// y(), width() and height() are agnostic to the RTL UI layout of the +// parent view. x(), on the other hand, is not. +int View::GetX(PositionMirroringSettings settings) const { + return settings == IGNORE_MIRRORING_TRANSFORMATION ? x() : MirroredX(); +} + +gfx::Point View::GetPosition() const { + return gfx::Point(GetX(APPLY_MIRRORING_TRANSFORMATION), y()); +} + int View::MirroredX() const { View* parent = GetParent(); return parent ? parent->MirroredLeftPointForRect(bounds_) : x(); @@ -557,7 +579,7 @@ void View::SchedulePaint(const gfx::Rect& r, bool urgent) { } void View::SchedulePaint() { - SchedulePaint(GetLocalBounds(true), false); + SchedulePaint(GetContentsBounds(), false); } void View::Paint(gfx::Canvas* canvas) { diff --git a/views/view.h b/views/view.h index 3ffd05f..1180841 100644 --- a/views/view.h +++ b/views/view.h @@ -257,68 +257,35 @@ class View : public AcceleratorTarget { #endif // Size and disposition ------------------------------------------------------ + // Methods for obtaining and modifying the position and size of the view. + // Position is in the coordinate system of the view's parent. + // Position is NOT flipped for RTL. See "RTL positioning" for RTL-sensitive + // position accessors. - // Get the bounds of the View, relative to the parent. Essentially, this - // function returns the bounds_ rectangle. - // - // This is the function subclasses should use whenever they need to obtain - // the bounds of one of their child views (for example, when implementing - // View::Layout()). - const gfx::Rect& bounds() const { return bounds_; } - - // Get the size of the View. - const gfx::Size& size() const { return bounds_.size(); } - - // Return the bounds of the View, relative to the parent. If - // |settings| is IGNORE_MIRRORING_TRANSFORMATION, the function returns the - // bounds_ rectangle. If |settings| is APPLY_MIRRORING_TRANSFORMATION AND the - // parent View is using a right-to-left UI layout, then the function returns - // a shifted version of the bounds_ rectangle that represents the mirrored - // View bounds. - // - // NOTE: in the vast majority of the cases, the mirroring implementation is - // transparent to the View subclasses and therefore you should use the - // version of GetBounds() which does not take a transformation settings - // parameter. - gfx::Rect GetBounds(PositionMirroringSettings settings) const; + void SetBounds(int x, int y, int width, int height); + void SetBoundsRect(const gfx::Rect& bounds); + void SetSize(const gfx::Size& size); + void SetPosition(const gfx::Point& position); + void SetX(int x); + void SetY(int y); - // Set the bounds in the parent's coordinate system. - void SetBounds(const gfx::Rect& bounds); - void SetBounds(int x, int y, int width, int height) { - SetBounds(gfx::Rect(x, y, std::max(0, width), std::max(0, height))); - } - void SetX(int x) { SetBounds(x, y(), width(), height()); } - void SetY(int y) { SetBounds(x(), y, width(), height()); } + // Override to be notified when the bounds of the view have changed. + virtual void OnBoundsChanged(); - // Returns the left coordinate of the View, relative to the parent View, - // which is the value of bounds_.x(). - // - // This is the function subclasses should use whenever they need to obtain - // the left position of one of their child views (for example, when - // implementing View::Layout()). - // This is equivalent to GetX(IGNORE_MIRRORING_TRANSFORMATION), but - // inlinable. + const gfx::Rect& bounds() const { return bounds_; } int x() const { return bounds_.x(); } int y() const { return bounds_.y(); } int width() const { return bounds_.width(); } int height() const { return bounds_.height(); } + const gfx::Size& size() const { return bounds_.size(); } - // Return the left coordinate of the View, relative to the parent. If - // |settings| is IGNORE_MIRRORING_SETTINGS, the function returns the value of - // bounds_.x(). If |settings| is APPLY_MIRRORING_SETTINGS AND the parent - // View is using a right-to-left UI layout, then the function returns the - // mirrored value of bounds_.x(). - // - // NOTE: in the vast majority of the cases, the mirroring implementation is - // transparent to the View subclasses and therefore you should use the - // paremeterless version of x() when you need to get the X - // coordinate of a child View. - int GetX(PositionMirroringSettings settings) const; + // Returns the bounds of the content area of the view, i.e. the rectangle + // enclosed by the view's border. + gfx::Rect GetContentsBounds() const; - // Return this control local bounds. If include_border is true, local bounds - // is the rectangle {0, 0, width(), height()}, otherwise, it does not - // include the area where the border (if any) is painted. - gfx::Rect GetLocalBounds(bool include_border) const; + // Returns the bounds of the view in its own coordinates (i.e. position is + // 0, 0). + gfx::Rect GetLocalBounds() const; // Returns the insets of the current border. If there is no border an empty // insets is returned. @@ -331,25 +298,19 @@ class View : public AcceleratorTarget { // function takes into account the mirroring setting for each View and // therefore it will return the mirrored version of the visible bounds if // need be. + // TODO(beng): const. gfx::Rect GetVisibleBounds(); // Return the bounds of the View in screen coordinate system. gfx::Rect GetScreenBounds() const; - // Get the position of the View, relative to the parent. - // - // Note that if the parent uses right-to-left UI layout, then the mirrored - // position of this View is returned. Use x()/y() if you want to ignore - // mirroring. - gfx::Point GetPosition() const; - - // Get the size the View would like to be, if enough space were available. - virtual gfx::Size GetPreferredSize(); - // Returns the baseline of this view, or -1 if this view has no baseline. The // return value is relative to the preferred height. virtual int GetBaseline(); + // Get the size the View would like to be, if enough space were available. + virtual gfx::Size GetPreferredSize(); + // Convenience method that sizes this view to its preferred size. void SizeToPreferredSize(); @@ -363,11 +324,6 @@ class View : public AcceleratorTarget { // as with Labels). virtual int GetHeightForWidth(int w); - // This method is invoked when this object size or position changes. - // The default implementation does nothing. - virtual void DidChangeBounds(const gfx::Rect& previous, - const gfx::Rect& current); - // Set whether the receiving view is visible. Painting is scheduled as needed virtual void SetVisible(bool flag); @@ -388,6 +344,38 @@ class View : public AcceleratorTarget { // RTL positioning ----------------------------------------------------------- + // Return the bounds of the View, relative to the parent. If + // |settings| is IGNORE_MIRRORING_TRANSFORMATION, the function returns the + // bounds_ rectangle. If |settings| is APPLY_MIRRORING_TRANSFORMATION AND the + // parent View is using a right-to-left UI layout, then the function returns + // a shifted version of the bounds_ rectangle that represents the mirrored + // View bounds. + // + // NOTE: in the vast majority of the cases, the mirroring implementation is + // transparent to the View subclasses and therefore you should use the + // version of GetBounds() which does not take a transformation settings + // parameter. + gfx::Rect GetBounds(PositionMirroringSettings settings) const; + + // Return the left coordinate of the View, relative to the parent. If + // |settings| is IGNORE_MIRRORING_SETTINGS, the function returns the value of + // bounds_.x(). If |settings| is APPLY_MIRRORING_SETTINGS AND the parent + // View is using a right-to-left UI layout, then the function returns the + // mirrored value of bounds_.x(). + // + // NOTE: in the vast majority of the cases, the mirroring implementation is + // transparent to the View subclasses and therefore you should use the + // paremeterless version of x() when you need to get the X + // coordinate of a child View. + int GetX(PositionMirroringSettings settings) const; + + // Get the position of the View, relative to the parent. + // + // Note that if the parent uses right-to-left UI layout, then the mirrored + // position of this View is returned. Use x()/y() if you want to ignore + // mirroring. + gfx::Point GetPosition() const; + // Returns the mirrored X position for the view, relative to the parent. If // the parent view is not mirrored, this function returns bound_.left. // diff --git a/views/view_unittest.cc b/views/view_unittest.cc index 48a9f6f..2d81524 100644 --- a/views/view_unittest.cc +++ b/views/view_unittest.cc @@ -147,8 +147,7 @@ class TestView : public View { accelerator_count_map_.clear(); } - virtual void DidChangeBounds(const gfx::Rect& previous, - const gfx::Rect& current); + virtual void OnBoundsChanged(); virtual void ViewHierarchyChanged(bool is_add, View *parent, View *child); virtual bool OnMousePressed(const MouseEvent& event); virtual bool OnMouseDragged(const MouseEvent& event); @@ -159,9 +158,8 @@ class TestView : public View { virtual void Paint(gfx::Canvas* canvas); virtual bool AcceleratorPressed(const Accelerator& accelerator); - // DidChangeBounds test + // OnBoundsChanged test bool did_change_bounds_; - gfx::Rect previous_bounds_; gfx::Rect new_bounds_; // AddRemoveNotifications test @@ -216,28 +214,25 @@ class MockGestureManager : public GestureManager { #endif //////////////////////////////////////////////////////////////////////////////// -// DidChangeBounds +// OnBoundsChanged //////////////////////////////////////////////////////////////////////////////// -void TestView::DidChangeBounds(const gfx::Rect& previous, - const gfx::Rect& current) { +void TestView::OnBoundsChanged() { did_change_bounds_ = true; - previous_bounds_ = previous; - new_bounds_ = current; + new_bounds_ = bounds(); } -TEST_F(ViewTest, DidChangeBounds) { +TEST_F(ViewTest, OnBoundsChanged) { TestView* v = new TestView(); gfx::Rect prev_rect(0, 0, 200, 200); gfx::Rect new_rect(100, 100, 250, 250); - v->SetBounds(prev_rect); + v->SetBoundsRect(prev_rect); v->Reset(); - v->SetBounds(new_rect); + v->SetBoundsRect(new_rect); EXPECT_EQ(v->did_change_bounds_, true); - EXPECT_EQ(v->previous_bounds_, prev_rect); EXPECT_EQ(v->new_bounds_, new_rect); EXPECT_EQ(v->bounds(), gfx::Rect(new_rect)); @@ -776,12 +771,12 @@ TEST_F(ViewTest, HitTestMasks) { gfx::Rect v1_bounds = gfx::Rect(0, 0, 100, 100); HitTestView* v1 = new HitTestView(false); - v1->SetBounds(v1_bounds); + v1->SetBoundsRect(v1_bounds); root_view->AddChildView(v1); gfx::Rect v2_bounds = gfx::Rect(105, 0, 100, 100); HitTestView* v2 = new HitTestView(true); - v2->SetBounds(v2_bounds); + v2->SetBoundsRect(v2_bounds); root_view->AddChildView(v2); gfx::Point v1_centerpoint = v1_bounds.CenterPoint(); diff --git a/views/widget/root_view.cc b/views/widget/root_view.cc index 5ce171f..68f1639 100644 --- a/views/widget/root_view.cc +++ b/views/widget/root_view.cc @@ -243,7 +243,7 @@ gfx::Rect RootView::GetScheduledPaintRectConstrainedToSize() { if (invalid_rect_.IsEmpty()) return invalid_rect_; - return invalid_rect_.Intersect(GetLocalBounds(true)); + return invalid_rect_.Intersect(GetContentsBounds()); } ///////////////////////////////////////////////////////////////////////////// diff --git a/views/window/client_view.cc b/views/window/client_view.cc index 4535867..312424c 100644 --- a/views/window/client_view.cc +++ b/views/window/client_view.cc @@ -56,8 +56,7 @@ void ClientView::ViewHierarchyChanged(bool is_add, View* parent, View* child) { } } -void ClientView::DidChangeBounds(const gfx::Rect& previous, - const gfx::Rect& current) { +void ClientView::OnBoundsChanged() { // Overridden to do nothing. The NonClientView manually calls Layout on the // ClientView when it is itself laid out, see comment in // NonClientView::Layout. diff --git a/views/window/client_view.h b/views/window/client_view.h index aa5e257..fc3d531 100644 --- a/views/window/client_view.h +++ b/views/window/client_view.h @@ -61,8 +61,7 @@ class ClientView : public View { protected: // Overridden from View: virtual void ViewHierarchyChanged(bool is_add, View* parent, View* child); - virtual void DidChangeBounds(const gfx::Rect& previous, - const gfx::Rect& current); + virtual void OnBoundsChanged(); virtual AccessibilityTypes::Role GetAccessibleRole(); // Accessors for private data members. diff --git a/views/window/custom_frame_view.cc b/views/window/custom_frame_view.cc index 0645aee..a78193b 100644 --- a/views/window/custom_frame_view.cc +++ b/views/window/custom_frame_view.cc @@ -540,7 +540,7 @@ void CustomFrameView::LayoutTitleBar() { gfx::Rect icon_bounds(IconBounds()); views::WindowDelegate* d = frame_->GetDelegate(); if (d->ShouldShowWindowIcon()) - window_icon_->SetBounds(icon_bounds); + window_icon_->SetBoundsRect(icon_bounds); // Size the title. int title_x = d->ShouldShowWindowIcon() ? diff --git a/views/window/dialog_client_view.cc b/views/window/dialog_client_view.cc index 6350d9d..172cceb 100644 --- a/views/window/dialog_client_view.cc +++ b/views/window/dialog_client_view.cc @@ -321,7 +321,7 @@ void DialogClientView::Layout() { if (has_dialog_buttons()) LayoutDialogButtons(); if (bottom_view_) { - gfx::Rect bounds = GetLocalBounds(false); + gfx::Rect bounds = GetContentsBounds(); gfx::Size pref = bottom_view_->GetPreferredSize(); bottom_view_->SetBounds(bounds.x(), bounds.bottom() - pref.height() - kButtonVEdgeMargin, @@ -431,7 +431,7 @@ void DialogClientView::PaintSizeBox(gfx::Canvas* canvas) { // a theme-supplied gripper. We should probably improvise // something, which would also require changing |gripper_size| // to have different default values, too... - size_box_bounds_ = GetLocalBounds(false); + size_box_bounds_ = GetLocalBounds(); size_box_bounds_.set_x(size_box_bounds_.right() - gripper_size.cx); size_box_bounds_.set_y(size_box_bounds_.bottom() - gripper_size.cy); RECT native_bounds = size_box_bounds_.ToRECT(); @@ -465,7 +465,7 @@ int DialogClientView::GetButtonsHeight() const { } void DialogClientView::LayoutDialogButtons() { - gfx::Rect lb = GetLocalBounds(false); + gfx::Rect lb = GetContentsBounds(); gfx::Rect extra_bounds; int bottom_y = lb.bottom() - kButtonVEdgeMargin; int button_height = 0; @@ -507,14 +507,14 @@ void DialogClientView::LayoutDialogButtons() { int height = size_extra_view_height_to_buttons_ ? std::max(ps.height(), button_height) : ps.height(); extra_bounds.set_height(height); - extra_view_->SetBounds(extra_bounds); + extra_view_->SetBoundsRect(extra_bounds); } } void DialogClientView::LayoutContentsView() { - gfx::Rect lb = GetLocalBounds(false); + gfx::Rect lb = GetContentsBounds(); lb.set_height(std::max(0, lb.height() - GetButtonsHeight())); - contents_view()->SetBounds(lb); + contents_view()->SetBoundsRect(lb); contents_view()->Layout(); } diff --git a/views/window/non_client_view.cc b/views/window/non_client_view.cc index 02b51c3..51936aa 100644 --- a/views/window/non_client_view.cc +++ b/views/window/non_client_view.cc @@ -115,7 +115,7 @@ void NonClientView::LayoutFrameView() { // change independently of the bounds changing - e.g. after the initial // display of the window the metrics of the native window controls can change, // which does not change the bounds of the window but requires a re-layout to - // trigger a repaint. We override DidChangeBounds for the NonClientFrameView + // trigger a repaint. We override OnBoundsChanged() for the NonClientFrameView // to do nothing so that SetBounds above doesn't cause Layout to be called // twice. frame_view_->Layout(); @@ -140,7 +140,7 @@ void NonClientView::Layout() { LayoutFrameView(); // Then layout the ClientView, using those bounds. - client_view_->SetBounds(frame_view_->GetBoundsForClientView()); + client_view_->SetBoundsRect(frame_view_->GetBoundsForClientView()); // We need to manually call Layout on the ClientView as well for the same // reason as above. @@ -187,8 +187,7 @@ bool NonClientFrameView::HitTest(const gfx::Point& l) const { return !GetWindow()->GetClientView()->bounds().Contains(l); } -void NonClientFrameView::DidChangeBounds(const gfx::Rect& previous, - const gfx::Rect& current) { +void NonClientFrameView::OnBoundsChanged() { // Overridden to do nothing. The NonClientView manually calls Layout on the // FrameView when it is itself laid out, see comment in NonClientView::Layout. } diff --git a/views/window/non_client_view.h b/views/window/non_client_view.h index e13e90a..2cd78f6 100644 --- a/views/window/non_client_view.h +++ b/views/window/non_client_view.h @@ -73,8 +73,7 @@ class NonClientFrameView : public View { virtual AccessibilityTypes::Role GetAccessibleRole(); protected: - virtual void DidChangeBounds(const gfx::Rect& previous, - const gfx::Rect& current); + virtual void OnBoundsChanged(); NonClientFrameView() : paint_as_active_(false) {} |