Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(272)

Unified Diff: ui/views/controls/menu/activation_change_observer_impl.cc

Issue 2155243007: Turn Bookmark Menus Async (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove nested flag Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ui/views/controls/menu/activation_change_observer_impl.cc
diff --git a/ui/views/controls/menu/activation_change_observer_impl.cc b/ui/views/controls/menu/activation_change_observer_impl.cc
new file mode 100644
index 0000000000000000000000000000000000000000..7a34bf275c4a5b66148cc9bee339c18f9310c868
--- /dev/null
+++ b/ui/views/controls/menu/activation_change_observer_impl.cc
@@ -0,0 +1,64 @@
+// Copyright 2016 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.
+
+#include "ui/views/controls/menu/activation_change_observer_impl.h"
+
+#include "ui/aura/window.h"
+#include "ui/views/controls/menu/menu_controller.h"
+#include "ui/views/widget/widget.h"
+#include "ui/wm/public/activation_client.h"
+
+namespace views {
+
+namespace {
+
+aura::Window* GetOwnerRootWindow(views::Widget* owner) {
+ return owner ? owner->GetNativeWindow()->GetRootWindow() : nullptr;
+}
+
+} // namespace
+
+ActivationChangeObserverImpl::ActivationChangeObserverImpl(
+ MenuController* controller,
+ Widget* owner)
+ : controller_(controller), root_(GetOwnerRootWindow(owner)) {
+ aura::client::GetActivationClient(root_)->AddObserver(this);
+ root_->AddObserver(this);
+ root_->AddPreTargetHandler(this);
+}
+
+ActivationChangeObserverImpl::~ActivationChangeObserverImpl() {
+ Cleanup();
+}
+
+void ActivationChangeObserverImpl::OnWindowActivated(
+ aura::client::ActivationChangeObserver::ActivationReason reason,
+ aura::Window* gained_active,
+ aura::Window* lost_active) {
+ if (!controller_->drag_in_progress())
+ controller_->CancelAll();
+}
+
+void ActivationChangeObserverImpl::OnWindowDestroying(aura::Window* window) {
+ Cleanup();
+}
+
+void ActivationChangeObserverImpl::OnCancelMode(ui::CancelModeEvent* event) {
+ controller_->CancelAll();
+}
+
+void ActivationChangeObserverImpl::Cleanup() {
+ if (!root_)
+ return;
+ // The ActivationClient may have been destroyed by the time we get here.
+ aura::client::ActivationClient* client =
+ aura::client::GetActivationClient(root_);
+ if (client)
+ client->RemoveObserver(this);
+ root_->RemovePreTargetHandler(this);
+ root_->RemoveObserver(this);
+ root_ = nullptr;
+}
+
+} // namespace views

Powered by Google App Engine
This is Rietveld 408576698