| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 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 "ui/views/controls/menu/activation_change_observer_impl.h" |
| 6 |
| 7 #include "ui/aura/window.h" |
| 8 #include "ui/views/controls/menu/menu_controller.h" |
| 9 #include "ui/views/widget/widget.h" |
| 10 #include "ui/wm/public/activation_client.h" |
| 11 |
| 12 namespace views { |
| 13 |
| 14 namespace { |
| 15 |
| 16 aura::Window* GetOwnerRootWindow(views::Widget* owner) { |
| 17 return owner ? owner->GetNativeWindow()->GetRootWindow() : nullptr; |
| 18 } |
| 19 |
| 20 } // namespace |
| 21 |
| 22 ActivationChangeObserverImpl::ActivationChangeObserverImpl( |
| 23 MenuController* controller, |
| 24 Widget* owner) |
| 25 : controller_(controller), root_(GetOwnerRootWindow(owner)) { |
| 26 aura::client::GetActivationClient(root_)->AddObserver(this); |
| 27 root_->AddObserver(this); |
| 28 root_->AddPreTargetHandler(this); |
| 29 } |
| 30 |
| 31 ActivationChangeObserverImpl::~ActivationChangeObserverImpl() { |
| 32 Cleanup(); |
| 33 } |
| 34 |
| 35 void ActivationChangeObserverImpl::OnWindowActivated( |
| 36 aura::client::ActivationChangeObserver::ActivationReason reason, |
| 37 aura::Window* gained_active, |
| 38 aura::Window* lost_active) { |
| 39 if (!controller_->drag_in_progress()) |
| 40 controller_->CancelAll(); |
| 41 } |
| 42 |
| 43 void ActivationChangeObserverImpl::OnWindowDestroying(aura::Window* window) { |
| 44 Cleanup(); |
| 45 } |
| 46 |
| 47 void ActivationChangeObserverImpl::OnCancelMode(ui::CancelModeEvent* event) { |
| 48 controller_->CancelAll(); |
| 49 } |
| 50 |
| 51 void ActivationChangeObserverImpl::Cleanup() { |
| 52 if (!root_) |
| 53 return; |
| 54 // The ActivationClient may have been destroyed by the time we get here. |
| 55 aura::client::ActivationClient* client = |
| 56 aura::client::GetActivationClient(root_); |
| 57 if (client) |
| 58 client->RemoveObserver(this); |
| 59 root_->RemovePreTargetHandler(this); |
| 60 root_->RemoveObserver(this); |
| 61 root_ = nullptr; |
| 62 } |
| 63 |
| 64 } // namespace views |
| OLD | NEW |