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"
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"
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() &&
30 (ui::EF_IS_DOUBLE_CLICK
| ui::EF_IS_TRIPLE_CLICK
)) == 0)) {
31 click_component_
= target
->delegate()->
32 GetNonClientComponent(event
->location());
38 switch (event
->type()) {
39 case ui::ET_MOUSE_MOVED
: {
41 target
->delegate()->GetNonClientComponent(event
->location());
42 multi_window_resize_controller_
.Show(target
, component
,
46 case ui::ET_MOUSE_ENTERED
:
48 case ui::ET_MOUSE_CAPTURE_CHANGED
:
49 case ui::ET_MOUSE_EXITED
:
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 // WindowEventHandler can receive each event up to two times. Once a
67 // double-click has been received clear the target. Otherwise a
68 // duplicate of the event will be checking target history against
70 click_component_
= HTNOWHERE
;
73 click_component_
= HTNOWHERE
;
76 multi_window_resize_controller_
.Hide();
77 HandleVerticalResizeDoubleClick(target_state
, event
);
85 void WorkspaceEventHandler::OnGestureEvent(ui::GestureEvent
* event
) {
86 if (event
->handled() || event
->type() != ui::ET_GESTURE_TAP
)
89 aura::Window
* target
= static_cast<aura::Window
*>(event
->target());
90 int previous_target_component
= click_component_
;
91 click_component_
= target
->delegate()->
92 GetNonClientComponent(event
->location());
94 if (click_component_
!= HTCAPTION
)
97 if (event
->details().tap_count() != 2) {
98 // Note: TouchUMA::GESTURE_FRAMEVIEW_TAP is counted twice for each tap.
99 TouchUMA::GetInstance()->
100 RecordGestureAction(TouchUMA::GESTURE_FRAMEVIEW_TAP
);
104 if (click_component_
== previous_target_component
) {
105 ash::Shell::GetInstance()->metrics()->RecordUserMetricsAction(
106 ash::UMA_TOGGLE_MAXIMIZE_CAPTION_GESTURE
);
107 // Note: TouchUMA::GESTURE_FRAMEVIEW_TAP is counted twice each time
108 // TouchUMA::GESTURE_MAXIMIZE_DOUBLETAP is counted once.
109 TouchUMA::GetInstance()->RecordGestureAction(
110 TouchUMA::GESTURE_MAXIMIZE_DOUBLETAP
);
111 const wm::WMEvent
wm_event(wm::WM_EVENT_TOGGLE_MAXIMIZE_CAPTION
);
112 wm::GetWindowState(target
)->OnWMEvent(&wm_event
);
113 event
->StopPropagation();
115 click_component_
= HTNOWHERE
;
118 void WorkspaceEventHandler::HandleVerticalResizeDoubleClick(
119 wm::WindowState
* target_state
,
120 ui::MouseEvent
* event
) {
121 aura::Window
* target
= target_state
->window();
122 if (event
->flags() & ui::EF_IS_DOUBLE_CLICK
) {
124 target
->delegate()->GetNonClientComponent(event
->location());
125 if (component
== HTBOTTOM
|| component
== HTTOP
) {
126 Shell::GetInstance()->metrics()->RecordUserMetricsAction(
127 UMA_TOGGLE_SINGLE_AXIS_MAXIMIZE_BORDER_CLICK
);
128 const wm::WMEvent
wm_event(wm::WM_EVENT_TOGGLE_VERTICAL_MAXIMIZE
);
129 target_state
->OnWMEvent(&wm_event
);
130 event
->StopPropagation();
131 } else if (component
== HTLEFT
|| component
== HTRIGHT
) {
132 Shell::GetInstance()->metrics()->RecordUserMetricsAction(
133 UMA_TOGGLE_SINGLE_AXIS_MAXIMIZE_BORDER_CLICK
);
134 const wm::WMEvent
wm_event(wm::WM_EVENT_TOGGLE_HORIZONTAL_MAXIMIZE
);
135 target_state
->OnWMEvent(&wm_event
);
136 event
->StopPropagation();