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

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

Issue 2155243007: Turn Bookmark Menus Async (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge the pretarget handlers Created 4 years, 4 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
« no previous file with comments | « ui/views/controls/menu/menu_pre_target_handler.h ('k') | ui/views/controls/menu/submenu_view.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/controls/menu/menu_pre_target_handler.cc
diff --git a/ui/views/controls/menu/menu_pre_target_handler.cc b/ui/views/controls/menu/menu_pre_target_handler.cc
new file mode 100644
index 0000000000000000000000000000000000000000..97cceb3104d761a8c24dfbc690743b5c41035f72
--- /dev/null
+++ b/ui/views/controls/menu/menu_pre_target_handler.cc
@@ -0,0 +1,68 @@
+// 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/menu_pre_target_handler.h"
+
+#include "ui/aura/env.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
+
+MenuPreTargetHandler::MenuPreTargetHandler(MenuController* controller,
+ Widget* owner)
+ : controller_(controller), root_(GetOwnerRootWindow(owner)) {
+ aura::Env::GetInstanceDontCreate()->PrependPreTargetHandler(this);
+ aura::client::GetActivationClient(root_)->AddObserver(this);
+ root_->AddObserver(this);
+}
+
+MenuPreTargetHandler::~MenuPreTargetHandler() {
+ Cleanup();
+}
+
+void MenuPreTargetHandler::OnWindowActivated(
+ aura::client::ActivationChangeObserver::ActivationReason reason,
+ aura::Window* gained_active,
+ aura::Window* lost_active) {
+ if (!controller_->drag_in_progress())
+ controller_->CancelAll();
+}
+
+void MenuPreTargetHandler::OnWindowDestroying(aura::Window* window) {
+ Cleanup();
+}
+
+void MenuPreTargetHandler::OnCancelMode(ui::CancelModeEvent* event) {
+ controller_->CancelAll();
+}
+
+void MenuPreTargetHandler::OnKeyEvent(ui::KeyEvent* event) {
+ controller_->OnWillDispatchKeyEvent(event);
+}
+
+void MenuPreTargetHandler::Cleanup() {
+ if (!root_)
+ return;
+ aura::Env::GetInstanceDontCreate()->RemovePreTargetHandler(this);
+ // 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_->RemoveObserver(this);
+ root_ = nullptr;
+}
+
+} // namespace views
« no previous file with comments | « ui/views/controls/menu/menu_pre_target_handler.h ('k') | ui/views/controls/menu/submenu_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698