diff options
author | sadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-16 17:49:04 +0000 |
---|---|---|
committer | sadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-16 17:49:04 +0000 |
commit | ea1fc4b19a5eac5d072646932e06205d6e51b08c (patch) | |
tree | 46f339940327014094152621ef255132215101f8 /views/view_unittest.cc | |
parent | cc5e6d0e30b7d0b51d1d84e2286626f3b0fb79a1 (diff) | |
download | chromium_src-ea1fc4b19a5eac5d072646932e06205d6e51b08c.zip chromium_src-ea1fc4b19a5eac5d072646932e06205d6e51b08c.tar.gz chromium_src-ea1fc4b19a5eac5d072646932e06205d6e51b08c.tar.bz2 |
Add View::ReorderChildView and Widget::MoveToTop.
The z-ordering of child views is currently maintained (implicitly?) by the order
they are added to the parent view. It may often be necessary to change the
z-order of views, and View::ReorderChildView can be used to do that.
I changed views_desktop to have the two pure-views windows to have overlapping
regions, and View::ReorderChildView is used to change the z-ordering of the two
windows. So it is possible to click a window to activate it and bring it on top
of the other. It could have been done without adding Widget::MoveToTop, but
given Widget::MoveAbove and MoveAboveWidget, it sounded like a good idea to have
Widget::MoveToTop (MoveToFront?). I do now know what the implementation for
windows should be, though. So left it as NOTIMPLEMENTED.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/7185005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@89363 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views/view_unittest.cc')
-rw-r--r-- | views/view_unittest.cc | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/views/view_unittest.cc b/views/view_unittest.cc index 65c704c..81b5e48 100644 --- a/views/view_unittest.cc +++ b/views/view_unittest.cc @@ -2111,4 +2111,58 @@ TEST_F(ViewTest, GetIndexOf) { ASSERT_EQ(-1, child2->GetIndexOf(foo1)); } +// Verifies that the child views can be reordered correctly. +TEST_F(ViewTest, ReorderChildren) { + View root; + + View* child = new View(); + root.AddChildView(child); + + View* foo1 = new View(); + child->AddChildView(foo1); + View* foo2 = new View(); + child->AddChildView(foo2); + View* foo3 = new View(); + child->AddChildView(foo3); + foo1->set_focusable(true); + foo2->set_focusable(true); + foo3->set_focusable(true); + + ASSERT_EQ(0, child->GetIndexOf(foo1)); + ASSERT_EQ(1, child->GetIndexOf(foo2)); + ASSERT_EQ(2, child->GetIndexOf(foo3)); + ASSERT_EQ(foo2, foo1->GetNextFocusableView()); + ASSERT_EQ(foo3, foo2->GetNextFocusableView()); + ASSERT_EQ(NULL, foo3->GetNextFocusableView()); + + // Move |foo2| at the end. + child->ReorderChildView(foo2, -1); + ASSERT_EQ(0, child->GetIndexOf(foo1)); + ASSERT_EQ(1, child->GetIndexOf(foo3)); + ASSERT_EQ(2, child->GetIndexOf(foo2)); + ASSERT_EQ(foo3, foo1->GetNextFocusableView()); + ASSERT_EQ(foo2, foo3->GetNextFocusableView()); + ASSERT_EQ(NULL, foo2->GetNextFocusableView()); + + // Move |foo1| at the end. + child->ReorderChildView(foo1, -1); + ASSERT_EQ(0, child->GetIndexOf(foo3)); + ASSERT_EQ(1, child->GetIndexOf(foo2)); + ASSERT_EQ(2, child->GetIndexOf(foo1)); + ASSERT_EQ(NULL, foo1->GetNextFocusableView()); + ASSERT_EQ(foo2, foo1->GetPreviousFocusableView()); + ASSERT_EQ(foo2, foo3->GetNextFocusableView()); + ASSERT_EQ(foo1, foo2->GetNextFocusableView()); + + // Move |foo2| to the front. + child->ReorderChildView(foo2, 0); + ASSERT_EQ(0, child->GetIndexOf(foo2)); + ASSERT_EQ(1, child->GetIndexOf(foo3)); + ASSERT_EQ(2, child->GetIndexOf(foo1)); + ASSERT_EQ(NULL, foo1->GetNextFocusableView()); + ASSERT_EQ(foo3, foo1->GetPreviousFocusableView()); + ASSERT_EQ(foo3, foo2->GetNextFocusableView()); + ASSERT_EQ(foo1, foo3->GetNextFocusableView()); +} + } // namespace views |