| Index: ui/wm/core/window_activation_pre_target_handler.cc
|
| diff --git a/ui/wm/core/window_activation_pre_target_handler.cc b/ui/wm/core/window_activation_pre_target_handler.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..2e4793ff3aa2015e52485b59f3a75520774a3c23
|
| --- /dev/null
|
| +++ b/ui/wm/core/window_activation_pre_target_handler.cc
|
| @@ -0,0 +1,60 @@
|
| +// Copyright 2015 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/wm/core/window_activation_pre_target_handler.h"
|
| +
|
| +#include "ui/aura/window.h"
|
| +#include "ui/events/event.h"
|
| +#include "ui/events/event_constants.h"
|
| +#include "ui/wm/core/window_activation_pre_target_handler_observer.h"
|
| +#include "ui/wm/public/activation_client.h"
|
| +
|
| +namespace wm {
|
| +
|
| +WindowActivationPreTargetHandler::WindowActivationPreTargetHandler(
|
| + aura::client::ActivationClient* activation_client)
|
| + : activation_client_(activation_client) {
|
| +}
|
| +
|
| +WindowActivationPreTargetHandler::~WindowActivationPreTargetHandler() {
|
| +}
|
| +
|
| +void WindowActivationPreTargetHandler::AddObserver(
|
| + WindowActivationPreTargetHandlerObserver* observer) {
|
| + observers_.AddObserver(observer);
|
| +}
|
| +
|
| +void WindowActivationPreTargetHandler::RemoveObserver(
|
| + WindowActivationPreTargetHandlerObserver* observer) {
|
| + observers_.RemoveObserver(observer);
|
| +}
|
| +
|
| +void WindowActivationPreTargetHandler::OnMouseEvent(ui::MouseEvent* event) {
|
| + if (event->type() == ui::ET_MOUSE_PRESSED && !event->handled())
|
| + ActivateWindowFromEvent(event);
|
| +}
|
| +
|
| +void WindowActivationPreTargetHandler::OnGestureEvent(ui::GestureEvent* event) {
|
| + if (event->type() == ui::ET_GESTURE_BEGIN &&
|
| + event->details().touch_points() == 1 && !event->handled()) {
|
| + ActivateWindowFromEvent(event);
|
| + }
|
| +}
|
| +
|
| +void WindowActivationPreTargetHandler::ActivateWindowFromEvent(
|
| + ui::Event* event) {
|
| + aura::Window* window = static_cast<aura::Window*>(event->target());
|
| + if (activation_client_->CanActivateWindow(window)) {
|
| + aura::Window* lost_active_window = activation_client_->GetActiveWindow();
|
| + FOR_EACH_OBSERVER(WindowActivationPreTargetHandlerObserver, observers_,
|
| + BeforeWindowActivatedByPreTargetHandler());
|
| + activation_client_->ActivateWindow(window);
|
| + FOR_EACH_OBSERVER(
|
| + WindowActivationPreTargetHandlerObserver, observers_,
|
| + OnWindowActivatedByPreTargetHandler(
|
| + activation_client_->GetActiveWindow(), lost_active_window));
|
| + }
|
| +}
|
| +
|
| +} // namespace wm
|
|
|