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 click_component_
= HTNOWHERE
;
69 click_component_
= HTNOWHERE
;
72 HandleVerticalResizeDoubleClick(target_state
, event
);
80 void WorkspaceEventHandler::OnGestureEvent(ui::GestureEvent
* event
) {
81 if (event
->handled() || event
->type() != ui::ET_GESTURE_TAP
)
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
)
92 if (event
->details().tap_count() != 2) {
93 TouchUMA::GetInstance()->
94 RecordGestureAction(TouchUMA::GESTURE_FRAMEVIEW_TAP
);
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
) {
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();