Put WeakPtrFactory member last in USBEventRouter
[chromium-blink-merge.git] / ash / wm / workspace / workspace_event_handler.cc
blobafd017bb0e8bacea4a2de7bffe13d8844074a046
1 // Copyright (c) 2012 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.
5 #include "ash/wm/workspace/workspace_event_handler.h"
7 #include "ash/metrics/user_metrics_recorder.h"
8 #include "ash/shell.h"
9 #include "ash/touch/touch_uma.h"
10 #include "ash/wm/window_state.h"
11 #include "ash/wm/wm_event.h"
12 #include "ui/aura/window.h"
13 #include "ui/aura/window_delegate.h"
14 #include "ui/base/hit_test.h"
16 namespace ash {
18 WorkspaceEventHandler::WorkspaceEventHandler()
19 : click_component_(HTNOWHERE) {
22 WorkspaceEventHandler::~WorkspaceEventHandler() {
25 void WorkspaceEventHandler::OnMouseEvent(ui::MouseEvent* event) {
26 aura::Window* target = static_cast<aura::Window*>(event->target());
27 if (event->type() == ui::ET_MOUSE_PRESSED &&
28 event->IsOnlyLeftMouseButton() &&
29 ((event->flags() &
30 (ui::EF_IS_DOUBLE_CLICK | ui::EF_IS_TRIPLE_CLICK)) == 0)) {
31 click_component_ = target->delegate()->
32 GetNonClientComponent(event->location());
35 if (event->handled())
36 return;
38 switch (event->type()) {
39 case ui::ET_MOUSE_MOVED: {
40 int component =
41 target->delegate()->GetNonClientComponent(event->location());
42 multi_window_resize_controller_.Show(target, component,
43 event->location());
44 break;
46 case ui::ET_MOUSE_ENTERED:
47 break;
48 case ui::ET_MOUSE_CAPTURE_CHANGED:
49 case ui::ET_MOUSE_EXITED:
50 break;
51 case ui::ET_MOUSE_PRESSED: {
52 wm::WindowState* target_state = wm::GetWindowState(target);
54 if (event->IsOnlyLeftMouseButton()) {
55 if (event->flags() & ui::EF_IS_DOUBLE_CLICK) {
56 int component = target->delegate()->
57 GetNonClientComponent(event->location());
58 if (component == HTCAPTION &&
59 component == click_component_) {
60 ash::Shell::GetInstance()->metrics()->RecordUserMetricsAction(
61 ash::UMA_TOGGLE_MAXIMIZE_CAPTION_CLICK);
62 const wm::WMEvent wm_event(wm::WM_EVENT_TOGGLE_MAXIMIZE_CAPTION);
63 target_state->OnWMEvent(&wm_event);
64 event->StopPropagation();
66 click_component_ = HTNOWHERE;
68 } else {
69 click_component_ = HTNOWHERE;
72 HandleVerticalResizeDoubleClick(target_state, event);
73 break;
75 default:
76 break;
80 void WorkspaceEventHandler::OnGestureEvent(ui::GestureEvent* event) {
81 if (event->handled() || event->type() != ui::ET_GESTURE_TAP)
82 return;
84 aura::Window* target = static_cast<aura::Window*>(event->target());
85 int previous_target_component = click_component_;
86 click_component_ = target->delegate()->
87 GetNonClientComponent(event->location());
89 if (click_component_ != HTCAPTION)
90 return;
92 if (event->details().tap_count() != 2) {
93 TouchUMA::GetInstance()->
94 RecordGestureAction(TouchUMA::GESTURE_FRAMEVIEW_TAP);
95 return;
98 if (click_component_ == previous_target_component) {
99 ash::Shell::GetInstance()->metrics()->RecordUserMetricsAction(
100 ash::UMA_TOGGLE_MAXIMIZE_CAPTION_GESTURE);
101 TouchUMA::GetInstance()->RecordGestureAction(
102 TouchUMA::GESTURE_MAXIMIZE_DOUBLETAP);
103 const wm::WMEvent wm_event(wm::WM_EVENT_TOGGLE_MAXIMIZE_CAPTION);
104 wm::GetWindowState(target)->OnWMEvent(&wm_event);
105 event->StopPropagation();
107 click_component_ = HTNOWHERE;
110 void WorkspaceEventHandler::HandleVerticalResizeDoubleClick(
111 wm::WindowState* target_state,
112 ui::MouseEvent* event) {
113 aura::Window* target = target_state->window();
114 if (event->flags() & ui::EF_IS_DOUBLE_CLICK) {
115 int component =
116 target->delegate()->GetNonClientComponent(event->location());
117 if (component == HTBOTTOM || component == HTTOP) {
118 Shell::GetInstance()->metrics()->RecordUserMetricsAction(
119 UMA_TOGGLE_SINGLE_AXIS_MAXIMIZE_BORDER_CLICK);
120 const wm::WMEvent wm_event(wm::WM_EVENT_TOGGLE_VERTICAL_MAXIMIZE);
121 target_state->OnWMEvent(&wm_event);
122 event->StopPropagation();
123 } else if (component == HTLEFT || component == HTRIGHT) {
124 Shell::GetInstance()->metrics()->RecordUserMetricsAction(
125 UMA_TOGGLE_SINGLE_AXIS_MAXIMIZE_BORDER_CLICK);
126 const wm::WMEvent wm_event(wm::WM_EVENT_TOGGLE_HORIZONTAL_MAXIMIZE);
127 target_state->OnWMEvent(&wm_event);
128 event->StopPropagation();
133 } // namespace ash