BookmarkManager: Fix 'new folder text field size changes on clicking it' issue.
[chromium-blink-merge.git] / chrome / browser / ui / views / extensions / extension_popup_aura.cc
blob7901f3f2f7cfe70f472582db3833e966892808ca
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.
5 #include "chrome/browser/ui/views/extensions/extension_popup_aura.h"
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"
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::Widget* widget = views::BubbleDelegateView::CreateBubble(popup);
20 gfx::NativeView native_view = widget->GetNativeView();
22 wm::SetWindowVisibilityAnimationType(
23 native_view, wm::WINDOW_VISIBILITY_ANIMATION_TYPE_VERTICAL);
24 wm::SetWindowVisibilityAnimationVerticalPosition(native_view, -3.0f);
26 aura::client::GetActivationClient(native_view->GetRootWindow())
27 ->AddObserver(popup);
29 return popup;
32 ExtensionPopupAura::ExtensionPopupAura(extensions::ExtensionViewHost* host,
33 views::View* anchor_view,
34 views::BubbleBorder::Arrow arrow,
35 ShowAction show_action)
36 : ExtensionPopup(host, anchor_view, arrow, show_action) {
39 ExtensionPopupAura::~ExtensionPopupAura() {
42 void ExtensionPopupAura::OnWidgetDestroying(views::Widget* widget) {
43 ExtensionPopup::OnWidgetDestroying(widget);
45 if (widget == GetWidget()) {
46 auto activation_client = aura::client::GetActivationClient(
47 widget->GetNativeWindow()->GetRootWindow());
48 // If the popup was being inspected with devtools and the browser window
49 // was closed, then the root window and activation client are already
50 // destroyed.
51 if (activation_client)
52 activation_client->RemoveObserver(this);
56 void ExtensionPopupAura::OnWindowActivated(
57 aura::client::ActivationChangeObserver::ActivationReason reason,
58 aura::Window* gained_active,
59 aura::Window* lost_active) {
60 // Close on anchor window activation (ie. user clicked the browser window).
61 // DesktopNativeWidgetAura does not trigger the expected browser widget
62 // [de]activation events when activating widgets in its own root window.
63 // This additional check handles those cases. See: http://crbug.com/320889
64 if (gained_active == anchor_widget()->GetNativeWindow())
65 OnAnchorWindowActivation();