summaryrefslogtreecommitdiffstats
path: root/views/view_unittest.cc
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/view_unittest.cc
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/view_unittest.cc')
-rw-r--r--views/view_unittest.cc51
1 files changed, 42 insertions, 9 deletions
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);
+}