summaryrefslogtreecommitdiffstats
path: root/views
diff options
context:
space:
mode:
authordavemoore@chromium.org <davemoore@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-09 16:52:00 +0000
committerdavemoore@chromium.org <davemoore@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-09 16:52:00 +0000
commit8eb52a9ae0407aa717113d48b540b1abdb0616e8 (patch)
tree358644668ef2e16d94c86d04b56bb7c1e8673c4e /views
parent470ed45abe7452e9f72122e0273cc0506114860a (diff)
downloadchromium_src-8eb52a9ae0407aa717113d48b540b1abdb0616e8.zip
chromium_src-8eb52a9ae0407aa717113d48b540b1abdb0616e8.tar.gz
chromium_src-8eb52a9ae0407aa717113d48b540b1abdb0616e8.tar.bz2
This will help minimize the area we paint various views, including BrowserView in cros. Before the default when a child's preferred view size changed was to propagate it up and
paint everything from the rootview down. This will limit the area to the parts that actually changed size. I expect we may find things that aren't being painted because they were assuming the behavior of Layout(). We should fix this as necessary. Also, a subsequent change will minimize our calls to SchedulePaint(). We frequently do it when we don't need to. BUG=None TEST=ViewTest.SetBoundsPaint Review URL: http://codereview.chromium.org/6531032 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@77481 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views')
-rw-r--r--views/controls/label.cc8
-rw-r--r--views/controls/label.h23
-rw-r--r--views/controls/menu/menu_scroll_view_container.cc15
-rw-r--r--views/controls/menu/menu_scroll_view_container.h15
-rw-r--r--views/controls/menu/submenu_view.cc8
-rw-r--r--views/controls/menu/submenu_view.h34
-rw-r--r--views/controls/single_split_view.cc12
-rw-r--r--views/controls/single_split_view.h21
-rw-r--r--views/controls/table/table_view.cc22
-rw-r--r--views/controls/table/table_view.h9
-rw-r--r--views/controls/textfield/native_textfield_views.cc8
-rw-r--r--views/controls/textfield/native_textfield_views.h4
-rw-r--r--views/view.cc37
-rw-r--r--views/view.h8
-rw-r--r--views/view_unittest.cc51
-rw-r--r--views/window/client_view.cc2
-rw-r--r--views/window/client_view.h11
-rw-r--r--views/window/non_client_view.cc10
-rw-r--r--views/window/non_client_view.h6
19 files changed, 175 insertions, 129 deletions
diff --git a/views/controls/label.cc b/views/controls/label.cc
index 5bc1a2a..a428bcd 100644
--- a/views/controls/label.cc
+++ b/views/controls/label.cc
@@ -73,10 +73,6 @@ int Label::GetHeightForWidth(int w) {
return h + GetInsets().height();
}
-void Label::OnBoundsChanged() {
- text_size_valid_ &= !is_multi_line_;
-}
-
std::string Label::GetClassName() const {
return kViewClassName;
}
@@ -316,6 +312,10 @@ gfx::Size Label::GetTextSize() const {
return text_size_;
}
+void Label::OnBoundsChanged(const gfx::Rect& previous_bounds) {
+ text_size_valid_ &= !is_multi_line_;
+}
+
// static
gfx::Font Label::GetDefaultFont() {
return ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::BaseFont);
diff --git a/views/controls/label.h b/views/controls/label.h
index 017b33c7..a3bef8f 100644
--- a/views/controls/label.h
+++ b/views/controls/label.h
@@ -55,28 +55,25 @@ class Label : public View {
virtual ~Label();
// Overridden to compute the size required to display this label.
- virtual gfx::Size GetPreferredSize();
+ virtual gfx::Size GetPreferredSize() OVERRIDE;
// Overriden to return the baseline of the label.
- virtual int GetBaseline();
+ virtual int GetBaseline() OVERRIDE;
// Return the height necessary to display this label with the provided width.
// This method is used to layout multi-line labels. It is equivalent to
// GetPreferredSize().height() if the receiver is not multi-line.
virtual int GetHeightForWidth(int w);
- // Overriden to dirty our text bounds if we're multi-line.
- virtual void OnBoundsChanged();
-
// Returns views/Label.
- virtual std::string GetClassName() const;
+ virtual std::string GetClassName() const OVERRIDE;
// Overridden to paint
- virtual void OnPaint(gfx::Canvas* canvas);
+ virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
// If the mouse is over the label, and a mouse over background has been
// specified, its used. Otherwise super's implementation is invoked.
- virtual void OnPaintBackground(gfx::Canvas* canvas);
+ virtual void OnPaintBackground(gfx::Canvas* canvas) OVERRIDE;
// Set the font.
void SetFont(const gfx::Font& font);
@@ -166,7 +163,7 @@ class Label : public View {
const Background* GetMouseOverBackground() const;
// Sets the enabled state. Setting the enabled state resets the color.
- virtual void SetEnabled(bool enabled);
+ virtual void SetEnabled(bool enabled) OVERRIDE;
// Overridden from View:
virtual gfx::Insets GetInsets() const;
@@ -180,8 +177,8 @@ class Label : public View {
void SizeToFit(int max_width);
// Accessibility accessors, overridden from View.
- virtual AccessibilityTypes::Role GetAccessibleRole();
- virtual AccessibilityTypes::State GetAccessibleState();
+ virtual AccessibilityTypes::Role GetAccessibleRole() OVERRIDE;
+ virtual AccessibilityTypes::State GetAccessibleState() OVERRIDE;
// Gets/sets the flag to determine whether the label should be collapsed when
// it's hidden (not visible). If this flag is true, the label will return a
@@ -208,6 +205,10 @@ class Label : public View {
void invalidate_text_size() { text_size_valid_ = false; }
virtual gfx::Size GetTextSize() const;
+
+ // Overriden to dirty our text bounds if we're multi-line.
+ virtual void OnBoundsChanged(const gfx::Rect& previous_bounds) OVERRIDE;
+
private:
// These tests call CalculateDrawStringParams in order to verify the
// calculations done for drawing text.
diff --git a/views/controls/menu/menu_scroll_view_container.cc b/views/controls/menu/menu_scroll_view_container.cc
index 6089838..28ce10a 100644
--- a/views/controls/menu/menu_scroll_view_container.cc
+++ b/views/controls/menu/menu_scroll_view_container.cc
@@ -252,13 +252,6 @@ void MenuScrollViewContainer::Layout() {
scroll_view_->Layout();
}
-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());
- Layout();
-}
-
gfx::Size MenuScrollViewContainer::GetPreferredSize() {
gfx::Size prefsize = scroll_view_->GetContents()->GetPreferredSize();
gfx::Insets insets = GetInsets();
@@ -276,4 +269,12 @@ AccessibilityTypes::State MenuScrollViewContainer::GetAccessibleState() {
return AccessibilityTypes::STATE_FOCUSED;
}
+void MenuScrollViewContainer::OnBoundsChanged(
+ const gfx::Rect& previous_bounds) {
+ gfx::Size content_pref = scroll_view_->GetContents()->GetPreferredSize();
+ scroll_up_button_->SetVisible(content_pref.height() > height());
+ scroll_down_button_->SetVisible(content_pref.height() > height());
+ Layout();
+}
+
} // namespace views
diff --git a/views/controls/menu/menu_scroll_view_container.h b/views/controls/menu/menu_scroll_view_container.h
index 5472091..d6ca679 100644
--- a/views/controls/menu/menu_scroll_view_container.h
+++ b/views/controls/menu/menu_scroll_view_container.h
@@ -24,12 +24,15 @@ class MenuScrollViewContainer : public View {
View* scroll_up_button() const { return scroll_up_button_; }
// View overrides.
- virtual void OnPaintBackground(gfx::Canvas* canvas);
- virtual void Layout();
- virtual void OnBoundsChanged();
- virtual gfx::Size GetPreferredSize();
- virtual AccessibilityTypes::Role GetAccessibleRole();
- virtual AccessibilityTypes::State GetAccessibleState();
+ virtual void OnPaintBackground(gfx::Canvas* canvas) OVERRIDE;
+ virtual void Layout() OVERRIDE;
+ virtual gfx::Size GetPreferredSize() OVERRIDE;
+ virtual AccessibilityTypes::Role GetAccessibleRole() OVERRIDE;
+ virtual AccessibilityTypes::State GetAccessibleState() OVERRIDE;
+
+ protected:
+ // View override.
+ virtual void OnBoundsChanged(const gfx::Rect& previous_bounds) OVERRIDE;
private:
class MenuScrollView;
diff --git a/views/controls/menu/submenu_view.cc b/views/controls/menu/submenu_view.cc
index f3ecaea..9e2214a 100644
--- a/views/controls/menu/submenu_view.cc
+++ b/views/controls/menu/submenu_view.cc
@@ -121,10 +121,6 @@ gfx::Size SubmenuView::GetPreferredSize() {
height + insets.height());
}
-void SubmenuView::OnBoundsChanged() {
- SchedulePaint();
-}
-
AccessibilityTypes::Role SubmenuView::GetAccessibleRole() {
return AccessibilityTypes::ROLE_MENUPOPUP;
}
@@ -327,6 +323,10 @@ std::string SubmenuView::GetClassName() const {
return kViewClassName;
}
+void SubmenuView::OnBoundsChanged(const gfx::Rect& previous_bounds) {
+ SchedulePaint();
+}
+
void SubmenuView::PaintDropIndicator(gfx::Canvas* canvas,
MenuItemView* item,
MenuDelegate::DropPosition position) {
diff --git a/views/controls/menu/submenu_view.h b/views/controls/menu/submenu_view.h
index 792189f..61e42b5 100644
--- a/views/controls/menu/submenu_view.h
+++ b/views/controls/menu/submenu_view.h
@@ -50,32 +50,28 @@ class SubmenuView : public View {
// Positions and sizes the child views. This tiles the views vertically,
// giving each child the available width.
- virtual void Layout();
- virtual gfx::Size GetPreferredSize();
-
- // View method. Overridden to schedule a paint. We do this so that when
- // scrolling occurs, everything is repainted correctly.
- virtual void OnBoundsChanged();
+ virtual void Layout() OVERRIDE;
+ virtual gfx::Size GetPreferredSize() OVERRIDE;
// Override from View.
- virtual AccessibilityTypes::Role GetAccessibleRole();
+ virtual AccessibilityTypes::Role GetAccessibleRole() OVERRIDE;
// Painting.
- virtual void PaintChildren(gfx::Canvas* canvas);
+ virtual void PaintChildren(gfx::Canvas* canvas) OVERRIDE;
// Drag and drop methods. These are forwarded to the MenuController.
virtual bool GetDropFormats(
int* formats,
- std::set<OSExchangeData::CustomFormat>* custom_formats);
- virtual bool AreDropTypesRequired();
+ std::set<OSExchangeData::CustomFormat>* custom_formats) OVERRIDE;
+ virtual bool AreDropTypesRequired() OVERRIDE;
virtual bool CanDrop(const OSExchangeData& data);
- virtual void OnDragEntered(const DropTargetEvent& event);
- virtual int OnDragUpdated(const DropTargetEvent& event);
- virtual void OnDragExited();
- virtual int OnPerformDrop(const DropTargetEvent& event);
+ virtual void OnDragEntered(const DropTargetEvent& event) OVERRIDE;
+ virtual int OnDragUpdated(const DropTargetEvent& event) OVERRIDE;
+ virtual void OnDragExited() OVERRIDE;
+ virtual int OnPerformDrop(const DropTargetEvent& event) OVERRIDE;
// Scrolls on menu item boundaries.
- virtual bool OnMouseWheel(const MouseWheelEvent& e);
+ virtual bool OnMouseWheel(const MouseWheelEvent& e) OVERRIDE;
// Returns true if the menu is showing.
bool IsShowing();
@@ -141,7 +137,13 @@ class SubmenuView : public View {
static const int kSubmenuBorderSize;
protected:
- virtual std::string GetClassName() const;
+ // View override.
+ virtual std::string GetClassName() const OVERRIDE;
+
+ // View method. Overridden to schedule a paint. We do this so that when
+ // scrolling occurs, everything is repainted correctly.
+ virtual void OnBoundsChanged(const gfx::Rect& previous_bounds) OVERRIDE;
+
private:
// Paints the drop indicator. This is only invoked if item is non-NULL and
diff --git a/views/controls/single_split_view.cc b/views/controls/single_split_view.cc
index 2b076d6..7522667 100644
--- a/views/controls/single_split_view.cc
+++ b/views/controls/single_split_view.cc
@@ -38,13 +38,6 @@ SingleSplitView::SingleSplitView(View* leading,
#endif
}
-void SingleSplitView::OnBoundsChanged() {
- divider_offset_ = CalculateDividerOffset(divider_offset_, previous_bounds_,
- bounds());
- View::OnBoundsChanged();
- previous_bounds_ = bounds();
-}
-
void SingleSplitView::Layout() {
gfx::Rect leading_bounds;
gfx::Rect trailing_bounds;
@@ -194,6 +187,11 @@ void SingleSplitView::OnMouseReleased(const MouseEvent& event, bool canceled) {
}
}
+void SingleSplitView::OnBoundsChanged(const gfx::Rect& previous_bounds) {
+ divider_offset_ = CalculateDividerOffset(divider_offset_, previous_bounds,
+ bounds());
+}
+
bool SingleSplitView::IsPointInDivider(const gfx::Point& p) {
if (child_count() < 2)
return false;
diff --git a/views/controls/single_split_view.h b/views/controls/single_split_view.h
index dc69c67..5b7f477 100644
--- a/views/controls/single_split_view.h
+++ b/views/controls/single_split_view.h
@@ -39,18 +39,17 @@ class SingleSplitView : public views::View {
Orientation orientation,
Observer* observer);
- virtual void OnBoundsChanged();
- virtual void Layout();
+ virtual void Layout() OVERRIDE;
- virtual AccessibilityTypes::Role GetAccessibleRole();
+ virtual AccessibilityTypes::Role GetAccessibleRole() OVERRIDE;
// SingleSplitView's preferred size is the sum of the preferred widths
// and the max of the heights.
- virtual gfx::Size GetPreferredSize();
+ virtual gfx::Size GetPreferredSize() OVERRIDE;
// Overriden to return a resize cursor when over the divider.
virtual gfx::NativeCursor GetCursorForPoint(ui::EventType event_type,
- const gfx::Point& p);
+ const gfx::Point& p) OVERRIDE;
Orientation orientation() const {
return is_horizontal_ ? HORIZONTAL_SPLIT : VERTICAL_SPLIT;
@@ -76,9 +75,11 @@ class SingleSplitView : public views::View {
gfx::Rect* trailing_bounds) const;
protected:
- virtual bool OnMousePressed(const MouseEvent& event);
- virtual bool OnMouseDragged(const MouseEvent& event);
- virtual void OnMouseReleased(const MouseEvent& event, bool canceled);
+ // View overrides.
+ virtual bool OnMousePressed(const MouseEvent& event) OVERRIDE;
+ virtual bool OnMouseDragged(const MouseEvent& event) OVERRIDE;
+ virtual void OnMouseReleased(const MouseEvent& event, bool canceled) OVERRIDE;
+ virtual void OnBoundsChanged(const gfx::Rect& previous_bounds) OVERRIDE;
private:
// This test calls OnMouse* functions.
@@ -123,10 +124,6 @@ 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/table/table_view.cc b/views/controls/table/table_view.cc
index f226cd0..59f5d62 100644
--- a/views/controls/table/table_view.cc
+++ b/views/controls/table/table_view.cc
@@ -128,17 +128,6 @@ void TableView::SetSortDescriptors(const SortDescriptors& sort_descriptors) {
SendMessage(list_view_, WM_SETREDRAW, static_cast<WPARAM>(TRUE), 0);
}
-void TableView::OnBoundsChanged() {
- if (!list_view_)
- return;
- SendMessage(list_view_, WM_SETREDRAW, static_cast<WPARAM>(FALSE), 0);
- Layout();
- if ((autosize_columns_ || !column_sizes_valid_) && width() > 0)
- ResetColumnSizes();
- UpdateContentOffset();
- SendMessage(list_view_, WM_SETREDRAW, static_cast<WPARAM>(TRUE), 0);
-}
-
int TableView::RowCount() const {
if (!list_view_)
return 0;
@@ -1511,6 +1500,17 @@ bool TableView::OnKeyDown(ui::KeyboardCode virtual_keycode) {
return false; // Let the key event be processed as ususal.
}
+void TableView::OnBoundsChanged(const gfx::Rect& previous_bounds) {
+ if (!list_view_)
+ return;
+ SendMessage(list_view_, WM_SETREDRAW, static_cast<WPARAM>(FALSE), 0);
+ Layout();
+ if ((autosize_columns_ || !column_sizes_valid_) && width() > 0)
+ ResetColumnSizes();
+ UpdateContentOffset();
+ SendMessage(list_view_, WM_SETREDRAW, static_cast<WPARAM>(TRUE), 0);
+}
+
int TableView::PreviousSelectedViewIndex(int view_index) {
DCHECK_GE(view_index, 0);
if (!list_view_ || view_index <= 0)
diff --git a/views/controls/table/table_view.h b/views/controls/table/table_view.h
index 620845d..a0181c9 100644
--- a/views/controls/table/table_view.h
+++ b/views/controls/table/table_view.h
@@ -162,8 +162,6 @@ class TableView : public NativeControl,
// Current sort.
const SortDescriptors& sort_descriptors() const { return sort_descriptors_; }
- virtual void OnBoundsChanged();
-
// Returns the number of rows in the TableView.
int RowCount() const;
@@ -246,7 +244,7 @@ class TableView : public NativeControl,
protected:
// Overriden to return the position of the first selected row.
- virtual gfx::Point GetKeyboardContextMenuLocation();
+ virtual gfx::Point GetKeyboardContextMenuLocation() OVERRIDE;
// Subclasses that want to customize the colors of a particular row/column,
// must invoke this passing in true. The default value is false, such that
@@ -264,7 +262,10 @@ class TableView : public NativeControl,
virtual void OnMiddleClick();
// Overridden from NativeControl. Notifies the observer.
- virtual bool OnKeyDown(ui::KeyboardCode virtual_keycode);
+ virtual bool OnKeyDown(ui::KeyboardCode virtual_keycode) OVERRIDE;
+
+ // View override.
+ virtual void OnBoundsChanged(const gfx::Rect& previous_bounds) OVERRIDE;
// Invoked to customize the colors or font at a particular cell. If you
// change the colors or font, return true. This is only invoked if
diff --git a/views/controls/textfield/native_textfield_views.cc b/views/controls/textfield/native_textfield_views.cc
index 4950ebe..775308a 100644
--- a/views/controls/textfield/native_textfield_views.cc
+++ b/views/controls/textfield/native_textfield_views.cc
@@ -122,10 +122,6 @@ void NativeTextfieldViews::OnPaint(gfx::Canvas* canvas) {
OnPaintBorder(canvas);
}
-void NativeTextfieldViews::OnBoundsChanged() {
- UpdateCursorBoundsAndTextOffset();
-}
-
void NativeTextfieldViews::OnFocus() {
NOTREACHED();
}
@@ -406,6 +402,10 @@ void NativeTextfieldViews::SetEnableTextfieldViews(bool enabled) {
textfield_view_enabled = enabled;
}
+void NativeTextfieldViews::OnBoundsChanged(const gfx::Rect& previous_bounds) {
+ UpdateCursorBoundsAndTextOffset();
+}
+
///////////////////////////////////////////////////////////////////////////////
// NativeTextfieldViews private:
diff --git a/views/controls/textfield/native_textfield_views.h b/views/controls/textfield/native_textfield_views.h
index 488551d..5a21596 100644
--- a/views/controls/textfield/native_textfield_views.h
+++ b/views/controls/textfield/native_textfield_views.h
@@ -54,7 +54,6 @@ class NativeTextfieldViews : public views::View,
virtual bool OnKeyPressed(const views::KeyEvent& e) OVERRIDE;
virtual bool OnKeyReleased(const views::KeyEvent& e) OVERRIDE;
virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
- virtual void OnBoundsChanged() OVERRIDE;
virtual void OnFocus() OVERRIDE;
virtual void OnBlur() OVERRIDE;
virtual gfx::NativeCursor GetCursorForPoint(ui::EventType event_type,
@@ -119,6 +118,9 @@ class NativeTextfieldViews : public views::View,
NONE,
};
+ protected:
+ // View override.
+ virtual void OnBoundsChanged(const gfx::Rect& previous_bounds) OVERRIDE;
private:
friend class NativeTextfieldViewsTest;
diff --git a/views/view.cc b/views/view.cc
index ac5911d..aede253 100644
--- a/views/view.cc
+++ b/views/view.cc
@@ -214,17 +214,14 @@ void View::SetBoundsRect(const gfx::Rect& bounds) {
if (needs_layout_) {
needs_layout_ = false;
Layout();
+ SchedulePaint();
}
return;
}
gfx::Rect prev = bounds_;
bounds_ = bounds;
- bool size_changed = prev.size() != bounds_.size();
- bool position_changed = prev.origin() != bounds_.origin();
-
- if (size_changed || position_changed)
- BoundsChanged();
+ BoundsChanged(prev);
}
void View::SetSize(const gfx::Size& size) {
@@ -243,11 +240,6 @@ 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()) {
@@ -468,10 +460,8 @@ void View::Layout() {
needs_layout_ = false;
// If we have a layout manager, let it handle the layout for us.
- if (layout_manager_.get()) {
+ if (layout_manager_.get())
layout_manager_->Layout(this);
- SchedulePaint();
- }
// Make sure to propagate the Layout() call to any children that haven't
// received it yet through the layout manager and need to be laid out. This
@@ -1085,6 +1075,9 @@ int View::GetLineScrollIncrement(ScrollView* scroll_view,
// Size and disposition --------------------------------------------------------
+void View::OnBoundsChanged(const gfx::Rect& previous_bounds) {
+}
+
void View::PreferredSizeChanged() {
InvalidateLayout();
if (parent_)
@@ -1361,8 +1354,22 @@ void View::VisibilityChangedImpl(View* starting_from, bool is_visible) {
VisibilityChanged(starting_from, is_visible);
}
-void View::BoundsChanged() {
- OnBoundsChanged();
+void View::BoundsChanged(const gfx::Rect& previous_bounds) {
+ if (parent_) {
+ parent_->SchedulePaintInRect(previous_bounds);
+ parent_->SchedulePaintInRect(bounds_);
+ } else {
+ // Previous bounds has no meaning to an orphan. This should only happen
+ // when the View is a RootView.
+ SchedulePaintInRect(gfx::Rect(0, 0, bounds_.width(), bounds_.height()));
+ }
+
+ OnBoundsChanged(previous_bounds);
+
+ if (previous_bounds.size() != size()) {
+ needs_layout_ = false;
+ Layout();
+ }
// Notify interested Views that visible bounds within the root view may have
// changed.
diff --git a/views/view.h b/views/view.h
index d32bf02..f0939a3 100644
--- a/views/view.h
+++ b/views/view.h
@@ -249,9 +249,6 @@ class View : public AcceleratorTarget {
void SetX(int x);
void SetY(int y);
- // Override to be notified when the bounds of the view have changed.
- virtual void OnBoundsChanged();
-
// No transformation is applied on the size or the locations.
const gfx::Rect& bounds() const { return bounds_; }
int x() const { return bounds_.x(); }
@@ -956,6 +953,9 @@ class View : public AcceleratorTarget {
protected:
// Size and disposition ------------------------------------------------------
+ // Override to be notified when the bounds of the view have changed.
+ virtual void OnBoundsChanged(const gfx::Rect& previous_bounds);
+
// Called when the preferred size of a child view changed. This gives the
// parent an opportunity to do a fresh layout if that makes sense.
virtual void ChildPreferredSizeChanged(View* child) {}
@@ -1200,7 +1200,7 @@ class View : public AcceleratorTarget {
// Responsible for propagating bounds change notifications to relevant
// views.
- void BoundsChanged();
+ void BoundsChanged(const gfx::Rect& previous_bounds);
// Visible bounds notification registration.
// When a view is added to a hierarchy, it and all its children are asked if
diff --git a/views/view_unittest.cc b/views/view_unittest.cc
index 3eaa9e0..76eb1c9 100644
--- a/views/view_unittest.cc
+++ b/views/view_unittest.cc
@@ -148,16 +148,18 @@ class TestView : public View {
accelerator_count_map_.clear();
}
- 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);
- virtual void OnMouseReleased(const MouseEvent& event, bool canceled);
+ virtual void OnBoundsChanged(const gfx::Rect& previous_bounds) OVERRIDE;
+ virtual void ViewHierarchyChanged(
+ bool is_add, View *parent, View *child) OVERRIDE;
+ virtual bool OnMousePressed(const MouseEvent& event) OVERRIDE;
+ virtual bool OnMouseDragged(const MouseEvent& event) OVERRIDE;
+ virtual void OnMouseReleased(const MouseEvent& event, bool canceled) OVERRIDE;
#if defined(TOUCH_UI)
virtual TouchStatus OnTouchEvent(const TouchEvent& event);
#endif
- virtual void Paint(gfx::Canvas* canvas);
- virtual bool AcceleratorPressed(const Accelerator& accelerator);
+ virtual void Paint(gfx::Canvas* canvas) OVERRIDE;
+ virtual void SchedulePaintInRect(const gfx::Rect& rect) OVERRIDE;
+ virtual bool AcceleratorPressed(const Accelerator& accelerator) OVERRIDE;
// OnBoundsChanged test
bool did_change_bounds_;
@@ -173,7 +175,10 @@ class TestView : public View {
int last_mouse_event_type_;
gfx::Point location_;
-#if defined(TOUCH_UI)
+ // Painting
+ std::vector<gfx::Rect> scheduled_paint_rects_;
+
+ #if defined(TOUCH_UI)
// TouchEvent
int last_touch_event_type_;
bool last_touch_event_was_handled_;
@@ -218,7 +223,7 @@ class MockGestureManager : public GestureManager {
// OnBoundsChanged
////////////////////////////////////////////////////////////////////////////////
-void TestView::OnBoundsChanged() {
+void TestView::OnBoundsChanged(const gfx::Rect& previous_bounds) {
did_change_bounds_ = true;
new_bounds_ = bounds();
}
@@ -561,6 +566,11 @@ void TestView::Paint(gfx::Canvas* canvas) {
canvas->AsCanvasSkia()->getClipBounds(&last_clip_);
}
+void TestView::SchedulePaintInRect(const gfx::Rect& rect) {
+ scheduled_paint_rects_.push_back(rect);
+ View::SchedulePaintInRect(rect);
+}
+
void CheckRect(const SkRect& check_rect, const SkRect& target_rect) {
EXPECT_EQ(target_rect.fLeft, check_rect.fLeft);
EXPECT_EQ(target_rect.fRight, check_rect.fRight);
@@ -1778,3 +1788,26 @@ TEST_F(ViewTest, OnVisibleBoundsChanged) {
}
#endif
+
+////////////////////////////////////////////////////////////////////////////////
+// BoundsChanged()
+
+TEST_F(ViewTest, SetBoundsPaint) {
+ TestView* top_view = new TestView;
+ TestView* child_view = new TestView;
+
+ top_view->SetBounds(0, 0, 100, 100);
+ top_view->scheduled_paint_rects_.clear();
+ child_view->SetBounds(10, 10, 20, 20);
+ top_view->AddChildView(child_view);
+
+ top_view->scheduled_paint_rects_.clear();
+ child_view->SetBounds(30, 30, 20, 20);
+ EXPECT_EQ(2U, top_view->scheduled_paint_rects_.size());
+
+ // There should be 2 rects, spanning from (10, 10) to (50, 50).
+ gfx::Rect paint_rect =
+ top_view->scheduled_paint_rects_[0].Union(
+ top_view->scheduled_paint_rects_[1]);
+ EXPECT_EQ(gfx::Rect(10, 10, 40, 40), paint_rect);
+}
diff --git a/views/window/client_view.cc b/views/window/client_view.cc
index 5d964de..6ec3f90 100644
--- a/views/window/client_view.cc
+++ b/views/window/client_view.cc
@@ -63,7 +63,7 @@ void ClientView::ViewHierarchyChanged(bool is_add, View* parent, View* child) {
}
}
-void ClientView::OnBoundsChanged() {
+void ClientView::OnBoundsChanged(const gfx::Rect& previous_bounds) {
// 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 405ec4e..b50eafa 100644
--- a/views/window/client_view.h
+++ b/views/window/client_view.h
@@ -55,14 +55,15 @@ class ClientView : public View {
virtual int NonClientHitTest(const gfx::Point& point);
// Overridden from View:
- virtual gfx::Size GetPreferredSize();
- virtual void Layout();
+ virtual gfx::Size GetPreferredSize() OVERRIDE;
+ virtual void Layout() OVERRIDE;
protected:
// Overridden from View:
- virtual void ViewHierarchyChanged(bool is_add, View* parent, View* child);
- virtual void OnBoundsChanged();
- virtual AccessibilityTypes::Role GetAccessibleRole();
+ virtual void ViewHierarchyChanged(
+ bool is_add, View* parent, View* child) OVERRIDE;
+ virtual void OnBoundsChanged(const gfx::Rect& previous_bounds) OVERRIDE;
+ virtual AccessibilityTypes::Role GetAccessibleRole() OVERRIDE;
// Accessors for private data members.
Window* window() const { return window_; }
diff --git a/views/window/non_client_view.cc b/views/window/non_client_view.cc
index f297c45..ec82685 100644
--- a/views/window/non_client_view.cc
+++ b/views/window/non_client_view.cc
@@ -196,11 +196,6 @@ bool NonClientFrameView::HitTest(const gfx::Point& l) const {
return !GetWindow()->client_view()->bounds().Contains(l);
}
-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.
-}
-
////////////////////////////////////////////////////////////////////////////////
// NonClientFrameView, protected:
@@ -261,4 +256,9 @@ AccessibilityTypes::Role NonClientFrameView::GetAccessibleRole() {
return AccessibilityTypes::ROLE_WINDOW;
}
+void NonClientFrameView::OnBoundsChanged(const gfx::Rect& previous_bounds) {
+ // Overridden to do nothing. The NonClientView manually calls Layout on the
+ // FrameView when it is itself laid out, see comment in NonClientView::Layout.
+}
+
} // namespace views
diff --git a/views/window/non_client_view.h b/views/window/non_client_view.h
index d45c30e..38fc0b1 100644
--- a/views/window/non_client_view.h
+++ b/views/window/non_client_view.h
@@ -69,11 +69,11 @@ class NonClientFrameView : public View {
virtual void ResetWindowControls() = 0;
// Overridden from View:
- virtual bool HitTest(const gfx::Point& l) const;
- virtual AccessibilityTypes::Role GetAccessibleRole();
+ virtual bool HitTest(const gfx::Point& l) const OVERRIDE;
+ virtual AccessibilityTypes::Role GetAccessibleRole() OVERRIDE;
protected:
- virtual void OnBoundsChanged();
+ virtual void OnBoundsChanged(const gfx::Rect& previous_bounds) OVERRIDE;
NonClientFrameView() : paint_as_active_(false) {}