diff options
author | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-30 22:37:31 +0000 |
---|---|---|
committer | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-30 22:37:31 +0000 |
commit | 3a264fcb1464f1c87680a82d5e2e56fbfa8758ec (patch) | |
tree | 3d032d98c0ba92bef5bcebcf42fda79641ebd5a9 /ui | |
parent | a93e915e5e26f0ad6170aea2136039a1e4dd23bf (diff) | |
download | chromium_src-3a264fcb1464f1c87680a82d5e2e56fbfa8758ec.zip chromium_src-3a264fcb1464f1c87680a82d5e2e56fbfa8758ec.tar.gz chromium_src-3a264fcb1464f1c87680a82d5e2e56fbfa8758ec.tar.bz2 |
Fixes crash that occured because NativeViewHostAura::Detach was not
changing the parent of the attached window. This meant that if the
parent was destroyed the attached window would be destroyed. Fix for
windows was done here: https://chromiumcodereview.appspot.com/10832011
BUG=132090, 141870
TEST=see bug
R=ben@chromium.org
Review URL: https://chromiumcodereview.appspot.com/10916017
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@154289 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r-- | ui/views/controls/native/native_view_host.cc | 17 | ||||
-rw-r--r-- | ui/views/controls/native/native_view_host.h | 5 | ||||
-rw-r--r-- | ui/views/controls/native/native_view_host_aura.cc | 2 | ||||
-rw-r--r-- | ui/views/controls/native/native_view_host_win.cc | 15 | ||||
-rw-r--r-- | ui/views/controls/native/native_view_host_win.h | 5 | ||||
-rw-r--r-- | ui/views/widget/native_widget_aura.cc | 2 |
6 files changed, 25 insertions, 21 deletions
diff --git a/ui/views/controls/native/native_view_host.cc b/ui/views/controls/native/native_view_host.cc index 3accab5..e75d779 100644 --- a/ui/views/controls/native/native_view_host.cc +++ b/ui/views/controls/native/native_view_host.cc @@ -181,9 +181,26 @@ gfx::NativeViewAccessible NativeViewHost::GetNativeViewAccessible() { void NativeViewHost::Detach(bool destroyed) { if (native_view_) { + if (!destroyed) + ClearFocus(); native_wrapper_->NativeViewDetaching(destroyed); native_view_ = NULL; } } +void NativeViewHost::ClearFocus() { + FocusManager* focus_manager = GetFocusManager(); + if (!focus_manager || !focus_manager->GetFocusedView()) + return; + + Widget::Widgets widgets; + Widget::GetAllChildWidgets(native_view(), &widgets); + for (Widget::Widgets::iterator i = widgets.begin(); i != widgets.end(); ++i) { + focus_manager->ViewRemoved((*i)->GetRootView()); + if (!focus_manager->GetFocusedView()) + return; + } +} + + } // namespace views diff --git a/ui/views/controls/native/native_view_host.h b/ui/views/controls/native/native_view_host.h index 4aa3d85..d0adf6c 100644 --- a/ui/views/controls/native/native_view_host.h +++ b/ui/views/controls/native/native_view_host.h @@ -95,6 +95,11 @@ class VIEWS_EXPORT NativeViewHost : public View { // detached because it's being destroyed, or false otherwise. void Detach(bool destroyed); + // Invokes ViewRemoved() on the FocusManager for all the child Widgets of our + // NativeView. This is used when detaching to ensure the FocusManager doesn't + // have a reference to a View that is no longer reachable. + void ClearFocus(); + // The attached native view. There is exactly one native_view_ attached. gfx::NativeView native_view_; diff --git a/ui/views/controls/native/native_view_host_aura.cc b/ui/views/controls/native/native_view_host_aura.cc index 8198311..cfebcb3 100644 --- a/ui/views/controls/native/native_view_host_aura.cc +++ b/ui/views/controls/native/native_view_host_aura.cc @@ -35,6 +35,8 @@ void NativeViewHostAura::NativeViewDetaching(bool destroyed) { if (!destroyed) { host_->native_view()->RemoveObserver(this); host_->native_view()->Hide(); + if (host_->native_view()->parent()) + host_->native_view()->parent()->RemoveChild(host_->native_view()); } } diff --git a/ui/views/controls/native/native_view_host_win.cc b/ui/views/controls/native/native_view_host_win.cc index 72e8d42..4916752 100644 --- a/ui/views/controls/native/native_view_host_win.cc +++ b/ui/views/controls/native/native_view_host_win.cc @@ -48,7 +48,6 @@ void NativeViewHostWin::NativeViewDetaching(bool destroyed) { if (!destroyed) { if (installed_clip_) UninstallClip(); - ClearFocus(); SetParent(host_->native_view(), ui::GetHiddenWindow()); } installed_clip_ = false; @@ -148,20 +147,6 @@ gfx::NativeViewAccessible NativeViewHostWin::GetNativeViewAccessible() { } } -void NativeViewHostWin::ClearFocus() { - FocusManager* focus_manager = host_->GetFocusManager(); - if (!focus_manager || !focus_manager->GetFocusedView()) - return; - - Widget::Widgets widgets; - Widget::GetAllChildWidgets(host_->native_view(), &widgets); - for (Widget::Widgets::iterator i = widgets.begin(); i != widgets.end(); ++i) { - focus_manager->ViewRemoved((*i)->GetRootView()); - if (!focus_manager->GetFocusedView()) - return; - } -} - //////////////////////////////////////////////////////////////////////////////// // NativeViewHostWrapper, public: diff --git a/ui/views/controls/native/native_view_host_win.h b/ui/views/controls/native/native_view_host_win.h index ab83ae6..2b67c50 100644 --- a/ui/views/controls/native/native_view_host_win.h +++ b/ui/views/controls/native/native_view_host_win.h @@ -32,11 +32,6 @@ class NativeViewHostWin : public NativeViewHostWrapper { virtual gfx::NativeViewAccessible GetNativeViewAccessible(); private: - // Invokes ViewRemoved() on the FocusManager for all the child Widgets of our - // NativeView. This is used when detaching to ensure the FocusManager doesn't - // have a reference to a View that is no longer reachable. - void ClearFocus(); - // Our associated NativeViewHost. NativeViewHost* host_; diff --git a/ui/views/widget/native_widget_aura.cc b/ui/views/widget/native_widget_aura.cc index b9e3e8e..c82c823 100644 --- a/ui/views/widget/native_widget_aura.cc +++ b/ui/views/widget/native_widget_aura.cc @@ -998,7 +998,7 @@ void NativeWidgetPrivate::GetAllChildWidgets(gfx::NativeView native_view, // Code expects widget for |native_view| to be added to |children|. NativeWidgetAura* native_widget = static_cast<NativeWidgetAura*>( GetNativeWidgetForNativeView(native_view)); - if (native_widget->GetWidget()) + if (native_widget && native_widget->GetWidget()) children->insert(native_widget->GetWidget()); } |