| 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
|
|
|