Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/ui/views/extensions/extension_popup_aura.h" | |
| 6 | |
| 7 #include "ui/aura/window.h" | |
| 8 #include "ui/views/widget/widget.h" | |
| 9 #include "ui/wm/core/window_animations.h" | |
| 10 #include "ui/wm/core/window_util.h" | |
| 11 #include "ui/wm/public/activation_client.h" | |
| 12 | |
| 13 // static | |
| 14 ExtensionPopup* ExtensionPopup::Create(extensions::ExtensionViewHost* host, | |
| 15 views::View* anchor_view, | |
| 16 views::BubbleBorder::Arrow arrow, | |
| 17 ShowAction show_action) { | |
| 18 auto popup = new ExtensionPopupAura(host, anchor_view, arrow, show_action); | |
| 19 views::BubbleDelegateView::CreateBubble(popup); | |
| 20 | |
| 21 gfx::NativeView native_view = popup->GetWidget()->GetNativeView(); | |
| 22 wm::SetWindowVisibilityAnimationType( | |
| 23 native_view, wm::WINDOW_VISIBILITY_ANIMATION_TYPE_VERTICAL); | |
| 24 wm::SetWindowVisibilityAnimationVerticalPosition(native_view, -3.0f); | |
| 25 | |
| 26 return popup; | |
| 27 } | |
| 28 | |
| 29 ExtensionPopupAura::ExtensionPopupAura(extensions::ExtensionViewHost* host, | |
| 30 views::View* anchor_view, | |
| 31 views::BubbleBorder::Arrow arrow, | |
| 32 ShowAction show_action) | |
| 33 : ExtensionPopup(host, anchor_view, arrow, show_action) { | |
| 34 } | |
| 35 | |
| 36 ExtensionPopupAura::~ExtensionPopupAura() { | |
| 37 } | |
| 38 | |
| 39 void ExtensionPopupAura::OnWidgetDestroying(views::Widget* widget) { | |
| 40 ExtensionPopup::OnWidgetDestroying(widget); | |
| 41 | |
| 42 if (widget == GetWidget()) { | |
|
Andre
2015/03/06 00:59:39
This check was not there, but seems like it should
msw
2015/03/06 19:26:49
Probably, unless this was also observing the ancho
| |
| 43 auto activation_client = aura::client::GetActivationClient( | |
| 44 widget->GetNativeWindow()->GetRootWindow()); | |
| 45 // If the popup was being inspected with devtools and the browser window | |
| 46 // was closed, then the root window and activation client are already | |
| 47 // destroyed. | |
| 48 if (activation_client) | |
| 49 activation_client->RemoveObserver(this); | |
| 50 } | |
| 51 } | |
| 52 | |
| 53 void ExtensionPopupAura::OnWidgetActivationChanged(views::Widget* widget, | |
| 54 bool active) { | |
| 55 ExtensionPopup::OnWidgetActivationChanged(widget, active); | |
| 56 | |
| 57 if (active && widget == GetWidget()) { | |
| 58 aura::Window* root_window = widget->GetNativeWindow()->GetRootWindow(); | |
| 59 aura::client::GetActivationClient(root_window)->AddObserver(this); | |
|
Andre
2015/03/06 00:59:39
This moved here from ExtensionPopup::ShowPopup().
msw
2015/03/06 19:26:49
Is it okay that this will call AddObserver multipl
Andre
2015/03/07 00:56:26
Good point. I moved it to Create() above.
| |
| 60 } | |
| 61 } | |
| 62 | |
| 63 void ExtensionPopupAura::OnWindowActivated(aura::Window* gained_active, | |
| 64 aura::Window* lost_active) { | |
| 65 // Close on anchor window activation (ie. user clicked the browser window). | |
| 66 // DesktopNativeWidgetAura does not trigger the expected browser widget | |
| 67 // [de]activation events when activating widgets in its own root window. | |
| 68 // This additional check handles those cases. See: http://crbug.com/320889 | |
| 69 if (gained_active == anchor_widget()->GetNativeWindow()) | |
| 70 OnAnchorWindowActivation(); | |
| 71 } | |
| OLD | NEW |