summaryrefslogtreecommitdiffstats
path: root/ui/views/view_unittest.cc
diff options
context:
space:
mode:
authorflint <flint@yandex-team.ru>2015-11-19 02:39:02 -0800
committerCommit bot <commit-bot@chromium.org>2015-11-19 10:40:10 +0000
commitb5412060fc9373b1f48a2799523a167ba4fcef63 (patch)
treeb3bf85e065c39ef70ae7673c8fcb4512d544561d /ui/views/view_unittest.cc
parent3f5f999e36c6b9935dcfad5893ca62e3aea606a6 (diff)
downloadchromium_src-b5412060fc9373b1f48a2799523a167ba4fcef63.zip
chromium_src-b5412060fc9373b1f48a2799523a167ba4fcef63.tar.gz
chromium_src-b5412060fc9373b1f48a2799523a167ba4fcef63.tar.bz2
Fix views::View::BoundsChanged
View::Layout is not invoked if only origin has been changed. R=sadrul@chromium.org,sky@chromium.org BUG=none TEST=See unittest. Review URL: https://codereview.chromium.org/1442683002 Cr-Commit-Position: refs/heads/master@{#360551}
Diffstat (limited to 'ui/views/view_unittest.cc')
-rw-r--r--ui/views/view_unittest.cc39
1 files changed, 39 insertions, 0 deletions
diff --git a/ui/views/view_unittest.cc b/ui/views/view_unittest.cc
index 75fa552..8e42476 100644
--- a/ui/views/view_unittest.cc
+++ b/ui/views/view_unittest.cc
@@ -202,6 +202,7 @@ class TestView : public View {
public:
TestView()
: View(),
+ did_layout_(false),
delete_on_pressed_(false),
did_paint_(false),
native_theme_(NULL),
@@ -211,6 +212,7 @@ class TestView : public View {
// Reset all test state
void Reset() {
did_change_bounds_ = false;
+ did_layout_ = false;
last_mouse_event_type_ = 0;
location_.SetPoint(0, 0);
received_mouse_enter_ = false;
@@ -239,6 +241,11 @@ class TestView : public View {
return can_process_events_within_subtree_;
}
+ void Layout() override {
+ did_layout_ = true;
+ View::Layout();
+ }
+
void OnBoundsChanged(const gfx::Rect& previous_bounds) override;
bool OnMousePressed(const ui::MouseEvent& event) override;
bool OnMouseDragged(const ui::MouseEvent& event) override;
@@ -256,6 +263,9 @@ class TestView : public View {
bool did_change_bounds_;
gfx::Rect new_bounds_;
+ // Layout.
+ bool did_layout_;
+
// MouseEvent.
int last_mouse_event_type_;
gfx::Point location_;
@@ -278,6 +288,35 @@ class TestView : public View {
};
////////////////////////////////////////////////////////////////////////////////
+// Layout
+////////////////////////////////////////////////////////////////////////////////
+
+TEST_F(ViewTest, LayoutCalledInvalidateAndOriginChanges) {
+ TestView parent;
+ TestView* child = new TestView;
+ gfx::Rect parent_rect(0, 0, 100, 100);
+ parent.SetBoundsRect(parent_rect);
+
+ parent.Reset();
+ // |AddChildView| invalidates parent's layout.
+ parent.AddChildView(child);
+ // Change rect so that only rect's origin is affected.
+ parent.SetBoundsRect(parent_rect + gfx::Vector2d(10, 0));
+
+ EXPECT_TRUE(parent.did_layout_);
+
+ // After child layout is invalidated, parent and child must be laid out
+ // during parent->BoundsChanged(...) call.
+ parent.Reset();
+ child->Reset();
+
+ child->InvalidateLayout();
+ parent.SetBoundsRect(parent_rect + gfx::Vector2d(20, 0));
+ EXPECT_TRUE(parent.did_layout_);
+ EXPECT_TRUE(child->did_layout_);
+}
+
+////////////////////////////////////////////////////////////////////////////////
// OnBoundsChanged
////////////////////////////////////////////////////////////////////////////////