summaryrefslogtreecommitdiffstats
path: root/views
diff options
context:
space:
mode:
authorasanka@chromium.org <asanka@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-31 23:19:45 +0000
committerasanka@chromium.org <asanka@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-31 23:19:45 +0000
commit7dc9c31ecbb69fad9339b0ca60a9d04cd8227aa4 (patch)
treef9aad9d5f95feccd85f65367593cbc166639dbe4 /views
parentfc7baafb399296475b7e476c59ef717c01d67746 (diff)
downloadchromium_src-7dc9c31ecbb69fad9339b0ca60a9d04cd8227aa4.zip
chromium_src-7dc9c31ecbb69fad9339b0ca60a9d04cd8227aa4.tar.gz
chromium_src-7dc9c31ecbb69fad9339b0ca60a9d04cd8227aa4.tar.bz2
Notify child widgets before and after a reparenting.
Attaching a native view to a NativeViewHostWin may cause that view to be disassociated from a view hierarchy with a different FocusManager. Notifying the widgets that they are about to be removed from their current parent gives them the opportunity to disassociate themselves from their current FocusManager. BUG=77447 TEST=none Review URL: http://codereview.chromium.org/6776025 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@80096 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views')
-rw-r--r--views/controls/native/native_view_host_win.cc24
-rw-r--r--views/widget/native_widget.h5
-rw-r--r--views/widget/widget_win.cc32
3 files changed, 40 insertions, 21 deletions
diff --git a/views/controls/native/native_view_host_win.cc b/views/controls/native/native_view_host_win.cc
index f8bda8e..f25e722 100644
--- a/views/controls/native/native_view_host_win.cc
+++ b/views/controls/native/native_view_host_win.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -35,33 +35,15 @@ void NativeViewHostWin::NativeViewAttached() {
// borders), when we change the parent below.
ShowWindow(host_->native_view(), SW_HIDE);
- // Need to set the HWND's parent before changing its size to avoid flashing.
- SetParent(host_->native_view(), host_->GetWidget()->GetNativeView());
+ NativeWidget::ReparentNativeView(host_->native_view(),
+ host_->GetWidget()->GetNativeView());
host_->Layout();
- // Notify children that parent changed, so they can adjust focus.
- NativeWidget::NativeWidgets widgets;
- NativeWidget::GetAllNativeWidgets(host_->native_view(), &widgets);
- for (NativeWidget::NativeWidgets::iterator it = widgets.begin();
- it != widgets.end(); ++it) {
- (*it)->GetWidget()->NotifyNativeViewHierarchyChanged(
- true,
- host_->GetWidget()->GetNativeView());
- }
}
void NativeViewHostWin::NativeViewDetaching(bool destroyed) {
if (!destroyed && installed_clip_)
UninstallClip();
installed_clip_ = false;
- // Notify children that parent is removed.
- NativeWidget::NativeWidgets widgets;
- NativeWidget::GetAllNativeWidgets(host_->native_view(), &widgets);
- for (NativeWidget::NativeWidgets::iterator it = widgets.begin();
- it != widgets.end(); ++it) {
- (*it)->GetWidget()->NotifyNativeViewHierarchyChanged(
- false,
- host_->GetWidget()->GetNativeView());
- }
}
void NativeViewHostWin::AddedToWidget() {
diff --git a/views/widget/native_widget.h b/views/widget/native_widget.h
index 089cfb3..9b28ac7 100644
--- a/views/widget/native_widget.h
+++ b/views/widget/native_widget.h
@@ -52,6 +52,11 @@ class NativeWidget {
static void GetAllNativeWidgets(gfx::NativeView native_view,
NativeWidgets* children);
+ // Reparent a NativeView and notify all NativeWidgets in
+ // |native_view|'s hierarchy of the change.
+ static void ReparentNativeView(gfx::NativeView native_view,
+ gfx::NativeView new_parent);
+
// Returns the Widget associated with this NativeWidget. This function is
// guaranteed to return non-NULL for the lifetime of the NativeWidget.
virtual Widget* GetWidget() = 0;
diff --git a/views/widget/widget_win.cc b/views/widget/widget_win.cc
index 613ddb6..0d6f47c 100644
--- a/views/widget/widget_win.cc
+++ b/views/widget/widget_win.cc
@@ -1150,4 +1150,36 @@ void NativeWidget::GetAllNativeWidgets(gfx::NativeView native_view,
reinterpret_cast<LPARAM>(children));
}
+void NativeWidget::ReparentNativeView(gfx::NativeView native_view,
+ gfx::NativeView new_parent) {
+ if (!native_view)
+ return;
+
+ HWND previous_parent = ::GetParent(native_view);
+ if (previous_parent == new_parent)
+ return;
+
+ NativeWidgets widgets;
+ GetAllNativeWidgets(native_view, &widgets);
+
+ // First notify all the widgets that they are being disassociated
+ // from their previous parent.
+ for (NativeWidgets::iterator it = widgets.begin();
+ it != widgets.end(); ++it) {
+ // TODO(beng): Rename this notification to NotifyNativeViewChanging()
+ // and eliminate the bool parameter.
+ (*it)->GetWidget()->NotifyNativeViewHierarchyChanged(false,
+ previous_parent);
+ }
+
+ ::SetParent(native_view, new_parent);
+
+ // And now, notify them that they have a brand new parent.
+ for (NativeWidgets::iterator it = widgets.begin();
+ it != widgets.end(); ++it) {
+ (*it)->GetWidget()->NotifyNativeViewHierarchyChanged(true,
+ new_parent);
+ }
+}
+
} // namespace views