Chromium Code Reviews| 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 namespace internal { | 17 namespace internal { |
| 18 | 18 |
| 19 WorkspaceEventHandler::WorkspaceEventHandler() { | 19 WorkspaceEventHandler::WorkspaceEventHandler() |
| 20 : double_click_component_(HTNOWHERE) { | |
| 20 } | 21 } |
| 21 | 22 |
| 22 WorkspaceEventHandler::~WorkspaceEventHandler() { | 23 WorkspaceEventHandler::~WorkspaceEventHandler() { |
| 23 } | 24 } |
| 24 | 25 |
| 25 void WorkspaceEventHandler::OnMouseEvent(ui::MouseEvent* event) { | 26 void WorkspaceEventHandler::OnMouseEvent(ui::MouseEvent* event) { |
| 26 if (event->handled()) | 27 if (event->handled()) |
| 27 return; | 28 return; |
| 29 | |
| 28 aura::Window* target = static_cast<aura::Window*>(event->target()); | 30 aura::Window* target = static_cast<aura::Window*>(event->target()); |
| 29 switch (event->type()) { | 31 switch (event->type()) { |
| 30 case ui::ET_MOUSE_MOVED: { | 32 case ui::ET_MOUSE_MOVED: { |
| 31 int component = | 33 int component = |
| 32 target->delegate()->GetNonClientComponent(event->location()); | 34 target->delegate()->GetNonClientComponent(event->location()); |
| 33 multi_window_resize_controller_.Show(target, component, | 35 multi_window_resize_controller_.Show(target, component, |
| 34 event->location()); | 36 event->location()); |
| 35 break; | 37 break; |
| 36 } | 38 } |
| 37 case ui::ET_MOUSE_ENTERED: | 39 case ui::ET_MOUSE_ENTERED: |
| 38 break; | 40 break; |
| 39 case ui::ET_MOUSE_CAPTURE_CHANGED: | 41 case ui::ET_MOUSE_CAPTURE_CHANGED: |
| 40 case ui::ET_MOUSE_EXITED: | 42 case ui::ET_MOUSE_EXITED: |
| 41 break; | 43 break; |
| 44 case ui::ET_MOUSE_RELEASED: | |
| 45 // WindowEventHandler is not guaranteed to get paired ET_MOUSE_PRESSED | |
| 46 // and ET_MOUSE_RELEASED events. | |
| 47 if (event->IsOnlyLeftMouseButton()) { | |
| 48 double_click_component_ = target->delegate()-> | |
| 49 GetNonClientComponent(event->location()); | |
| 50 } else { | |
| 51 double_click_component_ = HTNOWHERE; | |
| 52 } | |
| 53 break; | |
| 42 case ui::ET_MOUSE_PRESSED: { | 54 case ui::ET_MOUSE_PRESSED: { |
| 43 wm::WindowState* target_state = wm::GetWindowState(target); | 55 wm::WindowState* target_state = wm::GetWindowState(target); |
| 44 if (event->flags() & ui::EF_IS_DOUBLE_CLICK && | 56 int component = target->delegate()-> |
| 45 event->IsOnlyLeftMouseButton() && | 57 GetNonClientComponent(event->location()); |
| 46 target->delegate()->GetNonClientComponent(event->location()) == | 58 |
| 47 HTCAPTION) { | 59 if (event->IsOnlyLeftMouseButton()) { |
| 48 ash::Shell::GetInstance()->metrics()->RecordUserMetricsAction( | 60 int previous_target_component = double_click_component_; |
| 49 ash::UMA_TOGGLE_MAXIMIZE_CAPTION_CLICK); | 61 double_click_component_ = component; |
|
flackr
2014/04/08 14:08:00
why not only change the double click component if
jonross
2014/04/08 15:34:36
A nice cleanup vs caching the last one. Will make
| |
| 50 const wm::WMEvent wm_event(wm::WM_EVENT_TOGGLE_MAXIMIZE_CAPTION); | 62 if (event->flags() & ui::EF_IS_DOUBLE_CLICK) { |
| 51 target_state->OnWMEvent(&wm_event); | 63 if (double_click_component_ == HTCAPTION && |
| 52 event->StopPropagation(); | 64 double_click_component_ == previous_target_component) { |
|
flackr
2014/04/08 14:08:00
i.e. compare component to double click component h
jonross
2014/04/08 15:34:36
Done.
| |
| 65 ash::Shell::GetInstance()->metrics()->RecordUserMetricsAction( | |
| 66 ash::UMA_TOGGLE_MAXIMIZE_CAPTION_CLICK); | |
| 67 const wm::WMEvent wm_event(wm::WM_EVENT_TOGGLE_MAXIMIZE_CAPTION); | |
| 68 target_state->OnWMEvent(&wm_event); | |
| 69 event->StopPropagation(); | |
| 70 } | |
| 71 // WindowEventHandler can receive each event up to two times. Once a | |
| 72 // double-click has been received clear the target. Otherwise a | |
| 73 // duplicate of the event will be checking target history against | |
| 74 // itself. | |
| 75 double_click_component_ = HTNOWHERE; | |
| 76 } | |
| 77 } else { | |
| 78 double_click_component_ = HTNOWHERE; | |
| 53 } | 79 } |
| 80 | |
| 54 multi_window_resize_controller_.Hide(); | 81 multi_window_resize_controller_.Hide(); |
| 55 HandleVerticalResizeDoubleClick(target_state, event); | 82 HandleVerticalResizeDoubleClick(target_state, event); |
| 56 break; | 83 break; |
| 57 } | 84 } |
| 58 default: | 85 default: |
| 59 break; | 86 break; |
| 60 } | 87 } |
| 61 } | 88 } |
| 62 | 89 |
| 63 void WorkspaceEventHandler::OnGestureEvent(ui::GestureEvent* event) { | 90 void WorkspaceEventHandler::OnGestureEvent(ui::GestureEvent* event) { |
| 64 if (event->handled()) | 91 if (event->handled() || event->type() != ui::ET_GESTURE_TAP) |
| 65 return; | 92 return; |
| 93 | |
| 66 aura::Window* target = static_cast<aura::Window*>(event->target()); | 94 aura::Window* target = static_cast<aura::Window*>(event->target()); |
| 67 if (event->type() == ui::ET_GESTURE_TAP && | 95 int previous_target_component = double_click_component_; |
| 68 target->delegate()->GetNonClientComponent(event->location()) == | 96 double_click_component_ = target->delegate()-> |
| 69 HTCAPTION) { | 97 GetNonClientComponent(event->location()); |
| 70 if (event->details().tap_count() == 2) { | 98 |
| 99 if (double_click_component_ != HTCAPTION) | |
| 100 return; | |
| 101 | |
| 102 if (event->details().tap_count() == 2) { | |
| 103 if (double_click_component_ == previous_target_component) { | |
| 71 ash::Shell::GetInstance()->metrics()->RecordUserMetricsAction( | 104 ash::Shell::GetInstance()->metrics()->RecordUserMetricsAction( |
| 72 ash::UMA_TOGGLE_MAXIMIZE_CAPTION_GESTURE); | 105 ash::UMA_TOGGLE_MAXIMIZE_CAPTION_GESTURE); |
| 73 // Note: TouchUMA::GESTURE_FRAMEVIEW_TAP is counted twice each time | 106 // Note: TouchUMA::GESTURE_FRAMEVIEW_TAP is counted twice each time |
| 74 // TouchUMA::GESTURE_MAXIMIZE_DOUBLETAP is counted once. | 107 // TouchUMA::GESTURE_MAXIMIZE_DOUBLETAP is counted once. |
| 75 TouchUMA::GetInstance()->RecordGestureAction( | 108 TouchUMA::GetInstance()->RecordGestureAction( |
| 76 TouchUMA::GESTURE_MAXIMIZE_DOUBLETAP); | 109 TouchUMA::GESTURE_MAXIMIZE_DOUBLETAP); |
| 77 const wm::WMEvent wm_event(wm::WM_EVENT_TOGGLE_MAXIMIZE_CAPTION); | 110 const wm::WMEvent wm_event(wm::WM_EVENT_TOGGLE_MAXIMIZE_CAPTION); |
| 78 wm::GetWindowState(target)->OnWMEvent(&wm_event); | 111 wm::GetWindowState(target)->OnWMEvent(&wm_event); |
| 79 event->StopPropagation(); | 112 event->StopPropagation(); |
| 80 return; | |
| 81 } else { | |
| 82 // Note: TouchUMA::GESTURE_FRAMEVIEW_TAP is counted twice for each tap. | |
| 83 TouchUMA::GetInstance()->RecordGestureAction( | |
| 84 TouchUMA::GESTURE_FRAMEVIEW_TAP); | |
| 85 } | 113 } |
| 114 double_click_component_ = HTNOWHERE; | |
| 115 return; | |
| 86 } | 116 } |
| 117 // Note: TouchUMA::GESTURE_FRAMEVIEW_TAP is counted twice for each tap. | |
| 118 TouchUMA::GetInstance()->RecordGestureAction(TouchUMA::GESTURE_FRAMEVIEW_TAP); | |
| 87 } | 119 } |
| 88 | 120 |
| 89 void WorkspaceEventHandler::HandleVerticalResizeDoubleClick( | 121 void WorkspaceEventHandler::HandleVerticalResizeDoubleClick( |
| 90 wm::WindowState* target_state, | 122 wm::WindowState* target_state, |
| 91 ui::MouseEvent* event) { | 123 ui::MouseEvent* event) { |
| 92 aura::Window* target = target_state->window(); | 124 aura::Window* target = target_state->window(); |
| 93 if (event->flags() & ui::EF_IS_DOUBLE_CLICK) { | 125 if (event->flags() & ui::EF_IS_DOUBLE_CLICK) { |
| 94 int component = | 126 int component = |
| 95 target->delegate()->GetNonClientComponent(event->location()); | 127 target->delegate()->GetNonClientComponent(event->location()); |
| 96 if (component == HTBOTTOM || component == HTTOP) { | 128 if (component == HTBOTTOM || component == HTTOP) { |
| 97 Shell::GetInstance()->metrics()->RecordUserMetricsAction( | 129 Shell::GetInstance()->metrics()->RecordUserMetricsAction( |
| 98 UMA_TOGGLE_SINGLE_AXIS_MAXIMIZE_BORDER_CLICK); | 130 UMA_TOGGLE_SINGLE_AXIS_MAXIMIZE_BORDER_CLICK); |
| 99 const wm::WMEvent wm_event(wm::WM_EVENT_TOGGLE_VERTICAL_MAXIMIZE); | 131 const wm::WMEvent wm_event(wm::WM_EVENT_TOGGLE_VERTICAL_MAXIMIZE); |
| 100 target_state->OnWMEvent(&wm_event); | 132 target_state->OnWMEvent(&wm_event); |
| 101 event->StopPropagation(); | 133 event->StopPropagation(); |
| 102 } else if (component == HTLEFT || component == HTRIGHT) { | 134 } else if (component == HTLEFT || component == HTRIGHT) { |
| 103 Shell::GetInstance()->metrics()->RecordUserMetricsAction( | 135 Shell::GetInstance()->metrics()->RecordUserMetricsAction( |
| 104 UMA_TOGGLE_SINGLE_AXIS_MAXIMIZE_BORDER_CLICK); | 136 UMA_TOGGLE_SINGLE_AXIS_MAXIMIZE_BORDER_CLICK); |
| 105 const wm::WMEvent wm_event(wm::WM_EVENT_TOGGLE_HORIZONTAL_MAXIMIZE); | 137 const wm::WMEvent wm_event(wm::WM_EVENT_TOGGLE_HORIZONTAL_MAXIMIZE); |
| 106 target_state->OnWMEvent(&wm_event); | 138 target_state->OnWMEvent(&wm_event); |
| 107 event->StopPropagation(); | 139 event->StopPropagation(); |
| 108 } | 140 } |
| 109 } | 141 } |
| 110 } | 142 } |
| 111 | 143 |
| 112 } // namespace internal | 144 } // namespace internal |
| 113 } // namespace ash | 145 } // namespace ash |
| OLD | NEW |