| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ash/wm/workspace/workspace_event_handler.h" | 5 #include "ash/wm/workspace/workspace_event_handler.h" |
| 6 | 6 |
| 7 #include "ash/metrics/user_metrics_recorder.h" | 7 #include "ash/metrics/user_metrics_recorder.h" |
| 8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
| 9 #include "ash/touch/touch_uma.h" | 9 #include "ash/touch/touch_uma.h" |
| 10 #include "ash/wm/window_state.h" | 10 #include "ash/wm/window_state.h" |
| 11 #include "ash/wm/wm_event.h" | 11 #include "ash/wm/wm_event.h" |
| 12 #include "ui/aura/window.h" | 12 #include "ui/aura/window.h" |
| 13 #include "ui/aura/window_delegate.h" | 13 #include "ui/aura/window_delegate.h" |
| 14 #include "ui/base/hit_test.h" | 14 #include "ui/base/hit_test.h" |
| 15 | 15 |
| 16 namespace ash { | 16 namespace ash { |
| 17 | 17 |
| 18 WorkspaceEventHandler::WorkspaceEventHandler() { | 18 WorkspaceEventHandler::WorkspaceEventHandler() |
| 19 : double_click_component_(HTNOWHERE) { |
| 19 } | 20 } |
| 20 | 21 |
| 21 WorkspaceEventHandler::~WorkspaceEventHandler() { | 22 WorkspaceEventHandler::~WorkspaceEventHandler() { |
| 22 } | 23 } |
| 23 | 24 |
| 24 void WorkspaceEventHandler::OnMouseEvent(ui::MouseEvent* event) { | 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 double_click_component_ = target->delegate()-> |
| 32 GetNonClientComponent(event->location()); |
| 33 } |
| 34 |
| 25 if (event->handled()) | 35 if (event->handled()) |
| 26 return; | 36 return; |
| 27 aura::Window* target = static_cast<aura::Window*>(event->target()); | 37 |
| 28 switch (event->type()) { | 38 switch (event->type()) { |
| 29 case ui::ET_MOUSE_MOVED: { | 39 case ui::ET_MOUSE_MOVED: { |
| 30 int component = | 40 int component = |
| 31 target->delegate()->GetNonClientComponent(event->location()); | 41 target->delegate()->GetNonClientComponent(event->location()); |
| 32 multi_window_resize_controller_.Show(target, component, | 42 multi_window_resize_controller_.Show(target, component, |
| 33 event->location()); | 43 event->location()); |
| 34 break; | 44 break; |
| 35 } | 45 } |
| 36 case ui::ET_MOUSE_ENTERED: | 46 case ui::ET_MOUSE_ENTERED: |
| 37 break; | 47 break; |
| 38 case ui::ET_MOUSE_CAPTURE_CHANGED: | 48 case ui::ET_MOUSE_CAPTURE_CHANGED: |
| 39 case ui::ET_MOUSE_EXITED: | 49 case ui::ET_MOUSE_EXITED: |
| 40 break; | 50 break; |
| 41 case ui::ET_MOUSE_PRESSED: { | 51 case ui::ET_MOUSE_PRESSED: { |
| 42 wm::WindowState* target_state = wm::GetWindowState(target); | 52 wm::WindowState* target_state = wm::GetWindowState(target); |
| 43 if (event->flags() & ui::EF_IS_DOUBLE_CLICK && | 53 |
| 44 event->IsOnlyLeftMouseButton() && | 54 if (event->IsOnlyLeftMouseButton()) { |
| 45 target->delegate()->GetNonClientComponent(event->location()) == | 55 if (event->flags() & ui::EF_IS_DOUBLE_CLICK) { |
| 46 HTCAPTION) { | 56 int component = target->delegate()-> |
| 47 ash::Shell::GetInstance()->metrics()->RecordUserMetricsAction( | 57 GetNonClientComponent(event->location()); |
| 48 ash::UMA_TOGGLE_MAXIMIZE_CAPTION_CLICK); | 58 if (component == HTCAPTION && |
| 49 const wm::WMEvent wm_event(wm::WM_EVENT_TOGGLE_MAXIMIZE_CAPTION); | 59 component == double_click_component_) { |
| 50 target_state->OnWMEvent(&wm_event); | 60 ash::Shell::GetInstance()->metrics()->RecordUserMetricsAction( |
| 51 event->StopPropagation(); | 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(); |
| 65 } |
| 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 |
| 69 // itself. |
| 70 double_click_component_ = HTNOWHERE; |
| 71 } |
| 72 } else { |
| 73 double_click_component_ = HTNOWHERE; |
| 52 } | 74 } |
| 75 |
| 53 multi_window_resize_controller_.Hide(); | 76 multi_window_resize_controller_.Hide(); |
| 54 HandleVerticalResizeDoubleClick(target_state, event); | 77 HandleVerticalResizeDoubleClick(target_state, event); |
| 55 break; | 78 break; |
| 56 } | 79 } |
| 57 default: | 80 default: |
| 58 break; | 81 break; |
| 59 } | 82 } |
| 60 } | 83 } |
| 61 | 84 |
| 62 void WorkspaceEventHandler::OnGestureEvent(ui::GestureEvent* event) { | 85 void WorkspaceEventHandler::OnGestureEvent(ui::GestureEvent* event) { |
| 63 if (event->handled()) | 86 if (event->handled() || event->type() != ui::ET_GESTURE_TAP) |
| 64 return; | 87 return; |
| 88 |
| 65 aura::Window* target = static_cast<aura::Window*>(event->target()); | 89 aura::Window* target = static_cast<aura::Window*>(event->target()); |
| 66 if (event->type() == ui::ET_GESTURE_TAP && | 90 int previous_target_component = double_click_component_; |
| 67 target->delegate()->GetNonClientComponent(event->location()) == | 91 double_click_component_ = target->delegate()-> |
| 68 HTCAPTION) { | 92 GetNonClientComponent(event->location()); |
| 69 if (event->details().tap_count() == 2) { | 93 |
| 70 ash::Shell::GetInstance()->metrics()->RecordUserMetricsAction( | 94 if (double_click_component_ != HTCAPTION) |
| 71 ash::UMA_TOGGLE_MAXIMIZE_CAPTION_GESTURE); | 95 return; |
| 72 // Note: TouchUMA::GESTURE_FRAMEVIEW_TAP is counted twice each time | 96 |
| 73 // TouchUMA::GESTURE_MAXIMIZE_DOUBLETAP is counted once. | 97 if (event->details().tap_count() != 2) { |
| 74 TouchUMA::GetInstance()->RecordGestureAction( | 98 // Note: TouchUMA::GESTURE_FRAMEVIEW_TAP is counted twice for each tap. |
| 75 TouchUMA::GESTURE_MAXIMIZE_DOUBLETAP); | 99 TouchUMA::GetInstance()-> |
| 76 const wm::WMEvent wm_event(wm::WM_EVENT_TOGGLE_MAXIMIZE_CAPTION); | 100 RecordGestureAction(TouchUMA::GESTURE_FRAMEVIEW_TAP); |
| 77 wm::GetWindowState(target)->OnWMEvent(&wm_event); | 101 return; |
| 78 event->StopPropagation(); | |
| 79 return; | |
| 80 } else { | |
| 81 // Note: TouchUMA::GESTURE_FRAMEVIEW_TAP is counted twice for each tap. | |
| 82 TouchUMA::GetInstance()->RecordGestureAction( | |
| 83 TouchUMA::GESTURE_FRAMEVIEW_TAP); | |
| 84 } | |
| 85 } | 102 } |
| 103 |
| 104 if (double_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(); |
| 114 } |
| 115 double_click_component_ = HTNOWHERE; |
| 86 } | 116 } |
| 87 | 117 |
| 88 void WorkspaceEventHandler::HandleVerticalResizeDoubleClick( | 118 void WorkspaceEventHandler::HandleVerticalResizeDoubleClick( |
| 89 wm::WindowState* target_state, | 119 wm::WindowState* target_state, |
| 90 ui::MouseEvent* event) { | 120 ui::MouseEvent* event) { |
| 91 aura::Window* target = target_state->window(); | 121 aura::Window* target = target_state->window(); |
| 92 if (event->flags() & ui::EF_IS_DOUBLE_CLICK) { | 122 if (event->flags() & ui::EF_IS_DOUBLE_CLICK) { |
| 93 int component = | 123 int component = |
| 94 target->delegate()->GetNonClientComponent(event->location()); | 124 target->delegate()->GetNonClientComponent(event->location()); |
| 95 if (component == HTBOTTOM || component == HTTOP) { | 125 if (component == HTBOTTOM || component == HTTOP) { |
| 96 Shell::GetInstance()->metrics()->RecordUserMetricsAction( | 126 Shell::GetInstance()->metrics()->RecordUserMetricsAction( |
| 97 UMA_TOGGLE_SINGLE_AXIS_MAXIMIZE_BORDER_CLICK); | 127 UMA_TOGGLE_SINGLE_AXIS_MAXIMIZE_BORDER_CLICK); |
| 98 const wm::WMEvent wm_event(wm::WM_EVENT_TOGGLE_VERTICAL_MAXIMIZE); | 128 const wm::WMEvent wm_event(wm::WM_EVENT_TOGGLE_VERTICAL_MAXIMIZE); |
| 99 target_state->OnWMEvent(&wm_event); | 129 target_state->OnWMEvent(&wm_event); |
| 100 event->StopPropagation(); | 130 event->StopPropagation(); |
| 101 } else if (component == HTLEFT || component == HTRIGHT) { | 131 } else if (component == HTLEFT || component == HTRIGHT) { |
| 102 Shell::GetInstance()->metrics()->RecordUserMetricsAction( | 132 Shell::GetInstance()->metrics()->RecordUserMetricsAction( |
| 103 UMA_TOGGLE_SINGLE_AXIS_MAXIMIZE_BORDER_CLICK); | 133 UMA_TOGGLE_SINGLE_AXIS_MAXIMIZE_BORDER_CLICK); |
| 104 const wm::WMEvent wm_event(wm::WM_EVENT_TOGGLE_HORIZONTAL_MAXIMIZE); | 134 const wm::WMEvent wm_event(wm::WM_EVENT_TOGGLE_HORIZONTAL_MAXIMIZE); |
| 105 target_state->OnWMEvent(&wm_event); | 135 target_state->OnWMEvent(&wm_event); |
| 106 event->StopPropagation(); | 136 event->StopPropagation(); |
| 107 } | 137 } |
| 108 } | 138 } |
| 109 } | 139 } |
| 110 | 140 |
| 111 } // namespace ash | 141 } // namespace ash |
| OLD | NEW |