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 | 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) { |
| 25 if (event->handled()) | 26 if (event->handled()) |
| 26 return; | 27 return; |
| 28 | |
| 27 aura::Window* target = static_cast<aura::Window*>(event->target()); | 29 aura::Window* target = static_cast<aura::Window*>(event->target()); |
| 28 switch (event->type()) { | 30 switch (event->type()) { |
| 29 case ui::ET_MOUSE_MOVED: { | 31 case ui::ET_MOUSE_MOVED: { |
| 30 int component = | 32 int component = |
| 31 target->delegate()->GetNonClientComponent(event->location()); | 33 target->delegate()->GetNonClientComponent(event->location()); |
| 32 multi_window_resize_controller_.Show(target, component, | 34 multi_window_resize_controller_.Show(target, component, |
| 33 event->location()); | 35 event->location()); |
| 34 break; | 36 break; |
| 35 } | 37 } |
| 36 case ui::ET_MOUSE_ENTERED: | 38 case ui::ET_MOUSE_ENTERED: |
| 37 break; | 39 break; |
| 38 case ui::ET_MOUSE_CAPTURE_CHANGED: | 40 case ui::ET_MOUSE_CAPTURE_CHANGED: |
| 39 case ui::ET_MOUSE_EXITED: | 41 case ui::ET_MOUSE_EXITED: |
| 40 break; | 42 break; |
| 43 case ui::ET_MOUSE_RELEASED: | |
| 44 // WindowEventHandler is not guaranteed to get paired ET_MOUSE_PRESSED | |
| 45 // and ET_MOUSE_RELEASED events. | |
|
flackr
2014/04/08 21:11:39
So it can not get the first released event but sti
jonross
2014/04/08 22:29:08
Make a fix at the source: topleve_window_event_han
| |
| 46 if (event->IsOnlyLeftMouseButton()) { | |
| 47 double_click_component_ = target->delegate()-> | |
| 48 GetNonClientComponent(event->location()); | |
|
flackr
2014/04/08 21:11:39
nit: indent 4
| |
| 49 } else { | |
| 50 double_click_component_ = HTNOWHERE; | |
| 51 } | |
| 52 break; | |
| 41 case ui::ET_MOUSE_PRESSED: { | 53 case ui::ET_MOUSE_PRESSED: { |
| 42 wm::WindowState* target_state = wm::GetWindowState(target); | 54 wm::WindowState* target_state = wm::GetWindowState(target); |
| 43 if (event->flags() & ui::EF_IS_DOUBLE_CLICK && | 55 int component = target->delegate()-> |
| 44 event->IsOnlyLeftMouseButton() && | 56 GetNonClientComponent(event->location()); |
|
flackr
2014/04/08 21:11:39
nit: move these to scopes where used.
jonross
2014/04/08 22:29:08
Done.
| |
| 45 target->delegate()->GetNonClientComponent(event->location()) == | 57 |
| 46 HTCAPTION) { | 58 if (event->IsOnlyLeftMouseButton()) { |
| 47 ash::Shell::GetInstance()->metrics()->RecordUserMetricsAction( | 59 if (event->flags() & ui::EF_IS_DOUBLE_CLICK) { |
| 48 ash::UMA_TOGGLE_MAXIMIZE_CAPTION_CLICK); | 60 if (component == HTCAPTION && |
| 49 const wm::WMEvent wm_event(wm::WM_EVENT_TOGGLE_MAXIMIZE_CAPTION); | 61 component == double_click_component_) { |
| 50 target_state->OnWMEvent(&wm_event); | 62 ash::Shell::GetInstance()->metrics()->RecordUserMetricsAction( |
| 51 event->StopPropagation(); | 63 ash::UMA_TOGGLE_MAXIMIZE_CAPTION_CLICK); |
| 64 const wm::WMEvent wm_event(wm::WM_EVENT_TOGGLE_MAXIMIZE_CAPTION); | |
| 65 target_state->OnWMEvent(&wm_event); | |
| 66 event->StopPropagation(); | |
| 67 } | |
| 68 // WindowEventHandler can receive each event up to two times. Once a | |
|
flackr
2014/04/08 21:11:39
May i ask why? If different targeting phases we sh
jonross
2014/04/08 22:29:08
We can see this event during both pre and post dis
| |
| 69 // double-click has been received clear the target. Otherwise a | |
| 70 // duplicate of the event will be checking target history against | |
| 71 // itself. | |
| 72 double_click_component_ = HTNOWHERE; | |
| 73 } else { | |
| 74 double_click_component_ = component; | |
| 75 } | |
| 76 } else { | |
| 77 double_click_component_ = HTNOWHERE; | |
| 52 } | 78 } |
| 79 | |
| 53 multi_window_resize_controller_.Hide(); | 80 multi_window_resize_controller_.Hide(); |
| 54 HandleVerticalResizeDoubleClick(target_state, event); | 81 HandleVerticalResizeDoubleClick(target_state, event); |
| 55 break; | 82 break; |
| 56 } | 83 } |
| 57 default: | 84 default: |
| 58 break; | 85 break; |
| 59 } | 86 } |
| 60 } | 87 } |
| 61 | 88 |
| 62 void WorkspaceEventHandler::OnGestureEvent(ui::GestureEvent* event) { | 89 void WorkspaceEventHandler::OnGestureEvent(ui::GestureEvent* event) { |
| 63 if (event->handled()) | 90 if (event->handled() || event->type() != ui::ET_GESTURE_TAP) |
| 64 return; | 91 return; |
| 92 | |
| 65 aura::Window* target = static_cast<aura::Window*>(event->target()); | 93 aura::Window* target = static_cast<aura::Window*>(event->target()); |
| 66 if (event->type() == ui::ET_GESTURE_TAP && | 94 int previous_target_component = double_click_component_; |
| 67 target->delegate()->GetNonClientComponent(event->location()) == | 95 double_click_component_ = target->delegate()-> |
| 68 HTCAPTION) { | 96 GetNonClientComponent(event->location()); |
| 69 if (event->details().tap_count() == 2) { | 97 |
| 98 if (double_click_component_ != HTCAPTION) | |
| 99 return; | |
| 100 | |
| 101 if (event->details().tap_count() == 2) { | |
|
flackr
2014/04/08 21:11:39
How about an early return when tap count is not ye
jonross
2014/04/08 22:29:08
Done.
| |
| 102 if (double_click_component_ == previous_target_component) { | |
| 70 ash::Shell::GetInstance()->metrics()->RecordUserMetricsAction( | 103 ash::Shell::GetInstance()->metrics()->RecordUserMetricsAction( |
| 71 ash::UMA_TOGGLE_MAXIMIZE_CAPTION_GESTURE); | 104 ash::UMA_TOGGLE_MAXIMIZE_CAPTION_GESTURE); |
| 72 // Note: TouchUMA::GESTURE_FRAMEVIEW_TAP is counted twice each time | 105 // Note: TouchUMA::GESTURE_FRAMEVIEW_TAP is counted twice each time |
| 73 // TouchUMA::GESTURE_MAXIMIZE_DOUBLETAP is counted once. | 106 // TouchUMA::GESTURE_MAXIMIZE_DOUBLETAP is counted once. |
| 74 TouchUMA::GetInstance()->RecordGestureAction( | 107 TouchUMA::GetInstance()->RecordGestureAction( |
| 75 TouchUMA::GESTURE_MAXIMIZE_DOUBLETAP); | 108 TouchUMA::GESTURE_MAXIMIZE_DOUBLETAP); |
| 76 const wm::WMEvent wm_event(wm::WM_EVENT_TOGGLE_MAXIMIZE_CAPTION); | 109 const wm::WMEvent wm_event(wm::WM_EVENT_TOGGLE_MAXIMIZE_CAPTION); |
| 77 wm::GetWindowState(target)->OnWMEvent(&wm_event); | 110 wm::GetWindowState(target)->OnWMEvent(&wm_event); |
| 78 event->StopPropagation(); | 111 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 } | 112 } |
| 113 double_click_component_ = HTNOWHERE; | |
| 114 return; | |
| 85 } | 115 } |
| 116 // Note: TouchUMA::GESTURE_FRAMEVIEW_TAP is counted twice for each tap. | |
| 117 TouchUMA::GetInstance()->RecordGestureAction(TouchUMA::GESTURE_FRAMEVIEW_TAP); | |
| 86 } | 118 } |
| 87 | 119 |
| 88 void WorkspaceEventHandler::HandleVerticalResizeDoubleClick( | 120 void WorkspaceEventHandler::HandleVerticalResizeDoubleClick( |
| 89 wm::WindowState* target_state, | 121 wm::WindowState* target_state, |
| 90 ui::MouseEvent* event) { | 122 ui::MouseEvent* event) { |
| 91 aura::Window* target = target_state->window(); | 123 aura::Window* target = target_state->window(); |
| 92 if (event->flags() & ui::EF_IS_DOUBLE_CLICK) { | 124 if (event->flags() & ui::EF_IS_DOUBLE_CLICK) { |
| 93 int component = | 125 int component = |
| 94 target->delegate()->GetNonClientComponent(event->location()); | 126 target->delegate()->GetNonClientComponent(event->location()); |
| 95 if (component == HTBOTTOM || component == HTTOP) { | 127 if (component == HTBOTTOM || component == HTTOP) { |
| 96 Shell::GetInstance()->metrics()->RecordUserMetricsAction( | 128 Shell::GetInstance()->metrics()->RecordUserMetricsAction( |
| 97 UMA_TOGGLE_SINGLE_AXIS_MAXIMIZE_BORDER_CLICK); | 129 UMA_TOGGLE_SINGLE_AXIS_MAXIMIZE_BORDER_CLICK); |
| 98 const wm::WMEvent wm_event(wm::WM_EVENT_TOGGLE_VERTICAL_MAXIMIZE); | 130 const wm::WMEvent wm_event(wm::WM_EVENT_TOGGLE_VERTICAL_MAXIMIZE); |
| 99 target_state->OnWMEvent(&wm_event); | 131 target_state->OnWMEvent(&wm_event); |
| 100 event->StopPropagation(); | 132 event->StopPropagation(); |
| 101 } else if (component == HTLEFT || component == HTRIGHT) { | 133 } else if (component == HTLEFT || component == HTRIGHT) { |
| 102 Shell::GetInstance()->metrics()->RecordUserMetricsAction( | 134 Shell::GetInstance()->metrics()->RecordUserMetricsAction( |
| 103 UMA_TOGGLE_SINGLE_AXIS_MAXIMIZE_BORDER_CLICK); | 135 UMA_TOGGLE_SINGLE_AXIS_MAXIMIZE_BORDER_CLICK); |
| 104 const wm::WMEvent wm_event(wm::WM_EVENT_TOGGLE_HORIZONTAL_MAXIMIZE); | 136 const wm::WMEvent wm_event(wm::WM_EVENT_TOGGLE_HORIZONTAL_MAXIMIZE); |
| 105 target_state->OnWMEvent(&wm_event); | 137 target_state->OnWMEvent(&wm_event); |
| 106 event->StopPropagation(); | 138 event->StopPropagation(); |
| 107 } | 139 } |
| 108 } | 140 } |
| 109 } | 141 } |
| 110 | 142 |
| 111 } // namespace ash | 143 } // namespace ash |
| OLD | NEW |