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/common/wm/workspace/workspace_event_handler.h" |
6 | 6 |
7 #include "ash/aura/wm_window_aura.h" | |
8 #include "ash/common/wm/window_state.h" | 7 #include "ash/common/wm/window_state.h" |
9 #include "ash/common/wm/wm_event.h" | 8 #include "ash/common/wm/wm_event.h" |
10 #include "ash/common/wm_shell.h" | 9 #include "ash/common/wm_shell.h" |
11 #include "ash/common/wm_window.h" | 10 #include "ash/common/wm_window.h" |
12 #include "ash/wm/window_state_aura.h" | |
13 #include "ui/aura/window.h" | |
14 #include "ui/aura/window_delegate.h" | |
15 #include "ui/base/hit_test.h" | 11 #include "ui/base/hit_test.h" |
16 #include "ui/events/event.h" | 12 #include "ui/events/event.h" |
17 | 13 |
18 namespace ash { | 14 namespace ash { |
19 | 15 |
20 WorkspaceEventHandler::WorkspaceEventHandler() : click_component_(HTNOWHERE) {} | 16 WorkspaceEventHandler::WorkspaceEventHandler() : click_component_(HTNOWHERE) {} |
21 | 17 |
22 WorkspaceEventHandler::~WorkspaceEventHandler() {} | 18 WorkspaceEventHandler::~WorkspaceEventHandler() {} |
23 | 19 |
24 void WorkspaceEventHandler::OnMouseEvent(ui::MouseEvent* event) { | 20 void WorkspaceEventHandler::OnMouseEvent(ui::MouseEvent* event, |
25 aura::Window* target = static_cast<aura::Window*>(event->target()); | 21 WmWindow* target) { |
26 if (event->type() == ui::ET_MOUSE_PRESSED && event->IsOnlyLeftMouseButton() && | 22 if (event->type() == ui::ET_MOUSE_PRESSED && event->IsOnlyLeftMouseButton() && |
27 ((event->flags() & (ui::EF_IS_DOUBLE_CLICK | ui::EF_IS_TRIPLE_CLICK)) == | 23 ((event->flags() & (ui::EF_IS_DOUBLE_CLICK | ui::EF_IS_TRIPLE_CLICK)) == |
28 0)) { | 24 0)) { |
29 click_component_ = | 25 click_component_ = target->GetNonClientComponent(event->location()); |
30 target->delegate()->GetNonClientComponent(event->location()); | |
31 } | 26 } |
32 | 27 |
33 if (event->handled()) | 28 if (event->handled()) |
34 return; | 29 return; |
35 | 30 |
36 switch (event->type()) { | 31 switch (event->type()) { |
37 case ui::ET_MOUSE_MOVED: { | 32 case ui::ET_MOUSE_MOVED: { |
38 int component = | 33 int component = target->GetNonClientComponent(event->location()); |
39 target->delegate()->GetNonClientComponent(event->location()); | 34 multi_window_resize_controller_.Show(target, component, |
40 multi_window_resize_controller_.Show(WmWindowAura::Get(target), component, | |
41 event->location()); | 35 event->location()); |
42 break; | 36 break; |
43 } | 37 } |
44 case ui::ET_MOUSE_ENTERED: | 38 case ui::ET_MOUSE_ENTERED: |
45 break; | 39 break; |
46 case ui::ET_MOUSE_CAPTURE_CHANGED: | 40 case ui::ET_MOUSE_CAPTURE_CHANGED: |
47 case ui::ET_MOUSE_EXITED: | 41 case ui::ET_MOUSE_EXITED: |
48 break; | 42 break; |
49 case ui::ET_MOUSE_PRESSED: { | 43 case ui::ET_MOUSE_PRESSED: { |
50 wm::WindowState* target_state = wm::GetWindowState(target); | 44 wm::WindowState* target_state = target->GetWindowState(); |
51 | 45 |
52 if (event->IsOnlyLeftMouseButton()) { | 46 if (event->IsOnlyLeftMouseButton()) { |
53 if (event->flags() & ui::EF_IS_DOUBLE_CLICK) { | 47 if (event->flags() & ui::EF_IS_DOUBLE_CLICK) { |
54 int component = | 48 int component = target->GetNonClientComponent(event->location()); |
55 target->delegate()->GetNonClientComponent(event->location()); | |
56 if (component == HTCAPTION && component == click_component_) { | 49 if (component == HTCAPTION && component == click_component_) { |
57 WmShell::Get()->RecordUserMetricsAction( | 50 WmShell::Get()->RecordUserMetricsAction( |
58 UMA_TOGGLE_MAXIMIZE_CAPTION_CLICK); | 51 UMA_TOGGLE_MAXIMIZE_CAPTION_CLICK); |
59 const wm::WMEvent wm_event(wm::WM_EVENT_TOGGLE_MAXIMIZE_CAPTION); | 52 const wm::WMEvent wm_event(wm::WM_EVENT_TOGGLE_MAXIMIZE_CAPTION); |
60 target_state->OnWMEvent(&wm_event); | 53 target_state->OnWMEvent(&wm_event); |
61 event->StopPropagation(); | 54 event->StopPropagation(); |
62 } | 55 } |
63 click_component_ = HTNOWHERE; | 56 click_component_ = HTNOWHERE; |
64 } | 57 } |
65 } else { | 58 } else { |
66 click_component_ = HTNOWHERE; | 59 click_component_ = HTNOWHERE; |
67 } | 60 } |
68 | 61 |
69 HandleVerticalResizeDoubleClick(target_state, event); | 62 HandleVerticalResizeDoubleClick(target_state, event); |
70 break; | 63 break; |
71 } | 64 } |
72 default: | 65 default: |
73 break; | 66 break; |
74 } | 67 } |
75 } | 68 } |
76 | 69 |
77 void WorkspaceEventHandler::OnGestureEvent(ui::GestureEvent* event) { | 70 void WorkspaceEventHandler::OnGestureEvent(ui::GestureEvent* event, |
| 71 WmWindow* target) { |
78 if (event->handled() || event->type() != ui::ET_GESTURE_TAP) | 72 if (event->handled() || event->type() != ui::ET_GESTURE_TAP) |
79 return; | 73 return; |
80 | 74 |
81 aura::Window* target = static_cast<aura::Window*>(event->target()); | |
82 int previous_target_component = click_component_; | 75 int previous_target_component = click_component_; |
83 click_component_ = | 76 click_component_ = target->GetNonClientComponent(event->location()); |
84 target->delegate()->GetNonClientComponent(event->location()); | |
85 | 77 |
86 if (click_component_ != HTCAPTION) | 78 if (click_component_ != HTCAPTION) |
87 return; | 79 return; |
88 | 80 |
89 if (event->details().tap_count() != 2) { | 81 if (event->details().tap_count() != 2) { |
90 WmShell::Get()->RecordGestureAction(GESTURE_FRAMEVIEW_TAP); | 82 WmShell::Get()->RecordGestureAction(GESTURE_FRAMEVIEW_TAP); |
91 return; | 83 return; |
92 } | 84 } |
93 | 85 |
94 if (click_component_ == previous_target_component) { | 86 if (click_component_ == previous_target_component) { |
95 WmShell::Get()->RecordUserMetricsAction( | 87 WmShell::Get()->RecordUserMetricsAction( |
96 UMA_TOGGLE_MAXIMIZE_CAPTION_GESTURE); | 88 UMA_TOGGLE_MAXIMIZE_CAPTION_GESTURE); |
97 WmShell::Get()->RecordGestureAction(GESTURE_MAXIMIZE_DOUBLETAP); | 89 WmShell::Get()->RecordGestureAction(GESTURE_MAXIMIZE_DOUBLETAP); |
98 const wm::WMEvent wm_event(wm::WM_EVENT_TOGGLE_MAXIMIZE_CAPTION); | 90 const wm::WMEvent wm_event(wm::WM_EVENT_TOGGLE_MAXIMIZE_CAPTION); |
99 wm::GetWindowState(target)->OnWMEvent(&wm_event); | 91 target->GetWindowState()->OnWMEvent(&wm_event); |
100 event->StopPropagation(); | 92 event->StopPropagation(); |
101 } | 93 } |
102 click_component_ = HTNOWHERE; | 94 click_component_ = HTNOWHERE; |
103 } | 95 } |
104 | 96 |
105 void WorkspaceEventHandler::HandleVerticalResizeDoubleClick( | 97 void WorkspaceEventHandler::HandleVerticalResizeDoubleClick( |
106 wm::WindowState* target_state, | 98 wm::WindowState* target_state, |
107 ui::MouseEvent* event) { | 99 ui::MouseEvent* event) { |
108 WmWindow* target = target_state->window(); | 100 WmWindow* target = target_state->window(); |
109 if (event->flags() & ui::EF_IS_DOUBLE_CLICK) { | 101 if (event->flags() & ui::EF_IS_DOUBLE_CLICK) { |
110 int component = target->GetNonClientComponent(event->location()); | 102 int component = target->GetNonClientComponent(event->location()); |
111 if (component == HTBOTTOM || component == HTTOP) { | 103 if (component == HTBOTTOM || component == HTTOP) { |
112 WmShell::Get()->RecordUserMetricsAction( | 104 WmShell::Get()->RecordUserMetricsAction( |
113 UMA_TOGGLE_SINGLE_AXIS_MAXIMIZE_BORDER_CLICK); | 105 UMA_TOGGLE_SINGLE_AXIS_MAXIMIZE_BORDER_CLICK); |
114 const wm::WMEvent wm_event(wm::WM_EVENT_TOGGLE_VERTICAL_MAXIMIZE); | 106 const wm::WMEvent wm_event(wm::WM_EVENT_TOGGLE_VERTICAL_MAXIMIZE); |
115 target_state->OnWMEvent(&wm_event); | 107 target_state->OnWMEvent(&wm_event); |
116 event->StopPropagation(); | 108 event->StopPropagation(); |
117 } else if (component == HTLEFT || component == HTRIGHT) { | 109 } else if (component == HTLEFT || component == HTRIGHT) { |
118 WmShell::Get()->RecordUserMetricsAction( | 110 WmShell::Get()->RecordUserMetricsAction( |
119 UMA_TOGGLE_SINGLE_AXIS_MAXIMIZE_BORDER_CLICK); | 111 UMA_TOGGLE_SINGLE_AXIS_MAXIMIZE_BORDER_CLICK); |
120 const wm::WMEvent wm_event(wm::WM_EVENT_TOGGLE_HORIZONTAL_MAXIMIZE); | 112 const wm::WMEvent wm_event(wm::WM_EVENT_TOGGLE_HORIZONTAL_MAXIMIZE); |
121 target_state->OnWMEvent(&wm_event); | 113 target_state->OnWMEvent(&wm_event); |
122 event->StopPropagation(); | 114 event->StopPropagation(); |
123 } | 115 } |
124 } | 116 } |
125 } | 117 } |
126 | 118 |
127 } // namespace ash | 119 } // namespace ash |
OLD | NEW |