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 | |
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')
-rw-r--r-- | views/desktop/desktop_window.cc | 3 | ||||
-rw-r--r-- | views/view.cc | 26 | ||||
-rw-r--r-- | views/view.h | 4 | ||||
-rw-r--r-- | views/view_unittest.cc | 54 | ||||
-rw-r--r-- | views/widget/native_widget_gtk.cc | 5 | ||||
-rw-r--r-- | views/widget/native_widget_gtk.h | 1 | ||||
-rw-r--r-- | views/widget/native_widget_private.h | 1 | ||||
-rw-r--r-- | views/widget/native_widget_views.cc | 5 | ||||
-rw-r--r-- | views/widget/native_widget_views.h | 1 | ||||
-rw-r--r-- | views/widget/native_widget_win.cc | 4 | ||||
-rw-r--r-- | views/widget/native_widget_win.h | 1 | ||||
-rw-r--r-- | views/widget/widget.cc | 4 | ||||
-rw-r--r-- | views/widget/widget.h | 1 |
13 files changed, 109 insertions, 1 deletions
diff --git a/views/desktop/desktop_window.cc b/views/desktop/desktop_window.cc index c0999fb..7260826 100644 --- a/views/desktop/desktop_window.cc +++ b/views/desktop/desktop_window.cc @@ -99,7 +99,7 @@ void DesktopWindow::CreateDesktopWindow() { desktop->CreateTestWindow(L"Sample Window 1", SK_ColorWHITE, gfx::Rect(500, 200, 400, 400), true); desktop->CreateTestWindow(L"Sample Window 2", SK_ColorRED, - gfx::Rect(600, 650, 450, 300), false); + gfx::Rect(600, 450, 450, 300), false); } void DesktopWindow::ActivateWidget(Widget* widget) { @@ -109,6 +109,7 @@ void DesktopWindow::ActivateWidget(Widget* widget) { if (active_widget_) active_widget_->OnActivate(false); if (widget) { + widget->MoveToTop(); active_widget_ = static_cast<NativeWidgetViews*>(widget->native_widget()); active_widget_->OnActivate(true); } diff --git a/views/view.cc b/views/view.cc index c411621..a89ee23 100644 --- a/views/view.cc +++ b/views/view.cc @@ -176,6 +176,32 @@ void View::AddChildViewAt(View* view, int index) { view->MarkTextureDirty(); } +void View::ReorderChildView(View* view, int index) { + DCHECK_EQ(view->parent_, this); + if (index < 0) + index = child_count() - 1; + else if (index >= child_count()) + return; + if (children_[index] == view) + return; + + const Views::iterator i(std::find(children_.begin(), children_.end(), view)); + DCHECK(i != children_.end()); + children_.erase(i); + + // Unlink the view first + View* next_focusable = view->next_focusable_view_; + View* prev_focusable = view->previous_focusable_view_; + if (prev_focusable) + prev_focusable->next_focusable_view_ = next_focusable; + if (next_focusable) + next_focusable->previous_focusable_view_ = prev_focusable; + + // Add it in the specified index now. + InitFocusSiblings(view, index); + children_.insert(children_.begin() + index, view); +} + void View::RemoveChildView(View* view) { DoRemoveChildView(view, true, true, false); } diff --git a/views/view.h b/views/view.h index 1c412ab..3a37e75 100644 --- a/views/view.h +++ b/views/view.h @@ -177,6 +177,10 @@ class View : public AcceleratorTarget { void AddChildView(View* view); void AddChildViewAt(View* view, int index); + // Moves |view| to the specified |index|. A negative value for |index| moves + // the view at the end. + void ReorderChildView(View* view, int index); + // Removes |view| from this view. The view's parent will change to NULL. void RemoveChildView(View* view); 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 diff --git a/views/widget/native_widget_gtk.cc b/views/widget/native_widget_gtk.cc index 8ca9870..6fc908f 100644 --- a/views/widget/native_widget_gtk.cc +++ b/views/widget/native_widget_gtk.cc @@ -1060,6 +1060,11 @@ void NativeWidgetGtk::MoveAbove(gfx::NativeView native_view) { ui::StackPopupWindow(GetNativeView(), native_view); } +void NativeWidgetGtk::MoveToTop() { + DCHECK(GTK_IS_WINDOW(GetNativeView())); + gtk_window_present(GTK_WINDOW(GetNativeView())); +} + void NativeWidgetGtk::SetShape(gfx::NativeRegion region) { if (widget_ && widget_->window) { gdk_window_shape_combine_region(widget_->window, region, 0, 0); diff --git a/views/widget/native_widget_gtk.h b/views/widget/native_widget_gtk.h index 4565b39..2171d52 100644 --- a/views/widget/native_widget_gtk.h +++ b/views/widget/native_widget_gtk.h @@ -195,6 +195,7 @@ class NativeWidgetGtk : public internal::NativeWidgetPrivate, virtual void SetBoundsConstrained(const gfx::Rect& bounds, Widget* other_widget) OVERRIDE; virtual void MoveAbove(gfx::NativeView native_view) OVERRIDE; + virtual void MoveToTop() OVERRIDE; virtual void SetShape(gfx::NativeRegion shape) OVERRIDE; virtual void Close() OVERRIDE; virtual void CloseNow() OVERRIDE; diff --git a/views/widget/native_widget_private.h b/views/widget/native_widget_private.h index 1e08184..91ea7d6 100644 --- a/views/widget/native_widget_private.h +++ b/views/widget/native_widget_private.h @@ -167,6 +167,7 @@ class NativeWidgetPrivate : public NativeWidget { virtual void SetBoundsConstrained(const gfx::Rect& bounds, Widget* other_widget) = 0; virtual void MoveAbove(gfx::NativeView native_view) = 0; + virtual void MoveToTop() = 0; virtual void SetShape(gfx::NativeRegion shape) = 0; virtual void Close() = 0; virtual void CloseNow() = 0; diff --git a/views/widget/native_widget_views.cc b/views/widget/native_widget_views.cc index 438b755..dfdd553 100644 --- a/views/widget/native_widget_views.cc +++ b/views/widget/native_widget_views.cc @@ -42,6 +42,7 @@ void NativeWidgetViews::OnActivate(bool active) { void NativeWidgetViews::InitNativeWidget(const Widget::InitParams& params) { view_ = new internal::NativeWidgetView(this); + view_->SetPaintToTexture(true); host_view_->AddChildView(view_); // TODO(beng): handle parenting. @@ -202,6 +203,10 @@ void NativeWidgetViews::MoveAbove(gfx::NativeView native_view) { NOTIMPLEMENTED(); } +void NativeWidgetViews::MoveToTop() { + host_view_->ReorderChildView(view_, -1); +} + void NativeWidgetViews::SetShape(gfx::NativeRegion region) { NOTIMPLEMENTED(); } diff --git a/views/widget/native_widget_views.h b/views/widget/native_widget_views.h index db6e097..34809a3 100644 --- a/views/widget/native_widget_views.h +++ b/views/widget/native_widget_views.h @@ -76,6 +76,7 @@ class NativeWidgetViews : public internal::NativeWidgetPrivate { virtual void SetBoundsConstrained(const gfx::Rect& bounds, Widget* other_widget) OVERRIDE; virtual void MoveAbove(gfx::NativeView native_view) OVERRIDE; + virtual void MoveToTop() OVERRIDE; virtual void SetShape(gfx::NativeRegion shape) OVERRIDE; virtual void Close() OVERRIDE; virtual void CloseNow() OVERRIDE; diff --git a/views/widget/native_widget_win.cc b/views/widget/native_widget_win.cc index cb1482d..5ffe7f2 100644 --- a/views/widget/native_widget_win.cc +++ b/views/widget/native_widget_win.cc @@ -790,6 +790,10 @@ void NativeWidgetWin::MoveAbove(gfx::NativeView native_view) { SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE); } +void NativeWidgetWin::MoveToTop() { + NOTIMPLEMENTED(); +} + void NativeWidgetWin::SetShape(gfx::NativeRegion region) { SetWindowRgn(region, TRUE); } diff --git a/views/widget/native_widget_win.h b/views/widget/native_widget_win.h index dadbc38..ed40644 100644 --- a/views/widget/native_widget_win.h +++ b/views/widget/native_widget_win.h @@ -229,6 +229,7 @@ class NativeWidgetWin : public ui::WindowImpl, virtual void SetBoundsConstrained(const gfx::Rect& bounds, Widget* other_widget) OVERRIDE; virtual void MoveAbove(gfx::NativeView native_view) OVERRIDE; + virtual void MoveToTop() OVERRIDE; virtual void SetShape(gfx::NativeRegion shape) OVERRIDE; virtual void Close() OVERRIDE; virtual void CloseNow() OVERRIDE; diff --git a/views/widget/widget.cc b/views/widget/widget.cc index 8b19ce2..292b081 100644 --- a/views/widget/widget.cc +++ b/views/widget/widget.cc @@ -357,6 +357,10 @@ void Widget::MoveAbove(gfx::NativeView native_view) { native_widget_->MoveAbove(native_view); } +void Widget::MoveToTop() { + native_widget_->MoveToTop(); +} + void Widget::SetShape(gfx::NativeRegion shape) { native_widget_->SetShape(shape); } diff --git a/views/widget/widget.h b/views/widget/widget.h index 1e1b6f8..a320a07 100644 --- a/views/widget/widget.h +++ b/views/widget/widget.h @@ -281,6 +281,7 @@ class Widget : public internal::NativeWidgetDelegate, // Places the widget in front of the specified widget in z-order. void MoveAboveWidget(Widget* widget); void MoveAbove(gfx::NativeView native_view); + void MoveToTop(); // Sets a shape on the widget. This takes ownership of shape. void SetShape(gfx::NativeRegion shape); |