Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(530)

Side by Side Diff: ash/wm/workspace/workspace_event_handler.cc

Issue 114643003: Use a single ToplevelWindowEventHandler for the ash::Shell (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/screen_ash.h" 8 #include "ash/screen_ash.h"
9 #include "ash/shell.h" 9 #include "ash/shell.h"
10 #include "ash/touch/touch_uma.h" 10 #include "ash/touch/touch_uma.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 } 47 }
48 } else if (window_state->CanMaximize()) { 48 } else if (window_state->CanMaximize()) {
49 window_state->Maximize(); 49 window_state->Maximize();
50 } 50 }
51 } 51 }
52 52
53 } // namespace 53 } // namespace
54 54
55 namespace internal { 55 namespace internal {
56 56
57 WorkspaceEventHandler::WorkspaceEventHandler(aura::Window* owner) 57 WorkspaceEventHandler::WorkspaceEventHandler() {
58 : ToplevelWindowEventHandler(owner) {
59 } 58 }
60 59
61 WorkspaceEventHandler::~WorkspaceEventHandler() { 60 WorkspaceEventHandler::~WorkspaceEventHandler() {
62 } 61 }
63 62
64 void WorkspaceEventHandler::OnMouseEvent(ui::MouseEvent* event) { 63 void WorkspaceEventHandler::OnMouseEvent(ui::MouseEvent* event) {
65 aura::Window* target = static_cast<aura::Window*>(event->target()); 64 aura::Window* target = static_cast<aura::Window*>(event->target());
66 switch (event->type()) { 65 switch (event->type()) {
67 case ui::ET_MOUSE_MOVED: { 66 case ui::ET_MOUSE_MOVED: {
68 int component = 67 int component =
69 target->delegate()->GetNonClientComponent(event->location()); 68 target->delegate()->GetNonClientComponent(event->location());
70 multi_window_resize_controller_.Show(target, component, 69 multi_window_resize_controller_.Show(target, component,
71 event->location()); 70 event->location());
72 break; 71 break;
73 } 72 }
74 case ui::ET_MOUSE_ENTERED: 73 case ui::ET_MOUSE_ENTERED:
75 break; 74 break;
76 case ui::ET_MOUSE_CAPTURE_CHANGED: 75 case ui::ET_MOUSE_CAPTURE_CHANGED:
77 case ui::ET_MOUSE_EXITED: 76 case ui::ET_MOUSE_EXITED:
78 break; 77 break;
79 case ui::ET_MOUSE_PRESSED: { 78 case ui::ET_MOUSE_PRESSED: {
80 // Maximize behavior is implemented as post-target handling so the target 79 // Maximize behavior is implemented as post-target handling so the target
81 // can cancel it. 80 // can cancel it.
82 if (ui::EventCanceledDefaultHandling(*event)) { 81 if (ui::EventCanceledDefaultHandling(*event))
83 ToplevelWindowEventHandler::OnMouseEvent(event);
84 return; 82 return;
85 }
86 wm::WindowState* target_state = wm::GetWindowState(target); 83 wm::WindowState* target_state = wm::GetWindowState(target);
87 if (event->flags() & ui::EF_IS_DOUBLE_CLICK && 84 if (event->flags() & ui::EF_IS_DOUBLE_CLICK &&
88 event->IsOnlyLeftMouseButton() && 85 event->IsOnlyLeftMouseButton() &&
89 target->delegate()->GetNonClientComponent(event->location()) == 86 target->delegate()->GetNonClientComponent(event->location()) ==
90 HTCAPTION) { 87 HTCAPTION) {
91 ash::Shell::GetInstance()->metrics()->RecordUserMetricsAction( 88 ash::Shell::GetInstance()->metrics()->RecordUserMetricsAction(
92 ash::UMA_TOGGLE_MAXIMIZE_CAPTION_CLICK); 89 ash::UMA_TOGGLE_MAXIMIZE_CAPTION_CLICK);
93 ToggleMaximizedState(target_state); 90 ToggleMaximizedState(target_state);
91 event->StopPropagation();
94 } 92 }
95 multi_window_resize_controller_.Hide(); 93 multi_window_resize_controller_.Hide();
96 HandleVerticalResizeDoubleClick(target_state, event); 94 HandleVerticalResizeDoubleClick(target_state, event);
97 break; 95 break;
98 } 96 }
99 default: 97 default:
100 break; 98 break;
101 } 99 }
102 ToplevelWindowEventHandler::OnMouseEvent(event);
103 } 100 }
104 101
105 void WorkspaceEventHandler::OnGestureEvent(ui::GestureEvent* event) { 102 void WorkspaceEventHandler::OnGestureEvent(ui::GestureEvent* event) {
106 aura::Window* target = static_cast<aura::Window*>(event->target()); 103 aura::Window* target = static_cast<aura::Window*>(event->target());
107 if (event->type() == ui::ET_GESTURE_TAP && 104 if (event->type() == ui::ET_GESTURE_TAP &&
108 target->delegate()->GetNonClientComponent(event->location()) == 105 target->delegate()->GetNonClientComponent(event->location()) ==
109 HTCAPTION) { 106 HTCAPTION) {
110 if (event->details().tap_count() == 2) { 107 if (event->details().tap_count() == 2) {
111 ash::Shell::GetInstance()->metrics()->RecordUserMetricsAction( 108 ash::Shell::GetInstance()->metrics()->RecordUserMetricsAction(
112 ash::UMA_TOGGLE_MAXIMIZE_CAPTION_GESTURE); 109 ash::UMA_TOGGLE_MAXIMIZE_CAPTION_GESTURE);
113 // Note: TouchUMA::GESTURE_FRAMEVIEW_TAP is counted twice each time 110 // Note: TouchUMA::GESTURE_FRAMEVIEW_TAP is counted twice each time
114 // TouchUMA::GESTURE_MAXIMIZE_DOUBLETAP is counted once. 111 // TouchUMA::GESTURE_MAXIMIZE_DOUBLETAP is counted once.
115 TouchUMA::GetInstance()->RecordGestureAction( 112 TouchUMA::GetInstance()->RecordGestureAction(
116 TouchUMA::GESTURE_MAXIMIZE_DOUBLETAP); 113 TouchUMA::GESTURE_MAXIMIZE_DOUBLETAP);
117 ToggleMaximizedState(wm::GetWindowState(target)); 114 ToggleMaximizedState(wm::GetWindowState(target));
118 event->StopPropagation(); 115 event->StopPropagation();
119 return; 116 return;
120 } else { 117 } else {
121 // Note: TouchUMA::GESTURE_FRAMEVIEW_TAP is counted twice for each tap. 118 // Note: TouchUMA::GESTURE_FRAMEVIEW_TAP is counted twice for each tap.
122 TouchUMA::GetInstance()->RecordGestureAction( 119 TouchUMA::GetInstance()->RecordGestureAction(
123 TouchUMA::GESTURE_FRAMEVIEW_TAP); 120 TouchUMA::GESTURE_FRAMEVIEW_TAP);
124 } 121 }
125 } 122 }
126 ToplevelWindowEventHandler::OnGestureEvent(event);
127 } 123 }
128 124
129 void WorkspaceEventHandler::HandleVerticalResizeDoubleClick( 125 void WorkspaceEventHandler::HandleVerticalResizeDoubleClick(
130 wm::WindowState* target_state, 126 wm::WindowState* target_state,
131 ui::MouseEvent* event) { 127 ui::MouseEvent* event) {
132 aura::Window* target = target_state->window(); 128 aura::Window* target = target_state->window();
133 gfx::Rect max_size(target->delegate()->GetMaximumSize()); 129 gfx::Rect max_size(target->delegate()->GetMaximumSize());
134 if (event->flags() & ui::EF_IS_DOUBLE_CLICK && !target_state->IsMaximized()) { 130 if (event->flags() & ui::EF_IS_DOUBLE_CLICK && !target_state->IsMaximized()) {
135 int component = 131 int component =
136 target->delegate()->GetNonClientComponent(event->location()); 132 target->delegate()->GetNonClientComponent(event->location());
137 gfx::Rect work_area = Shell::GetScreen()->GetDisplayNearestWindow( 133 gfx::Rect work_area = Shell::GetScreen()->GetDisplayNearestWindow(
138 target).work_area(); 134 target).work_area();
139 if (component == HTBOTTOM || component == HTTOP) { 135 if (component == HTBOTTOM || component == HTTOP) {
140 // Don't maximize vertically if the window has a max height defined. 136 // Don't maximize vertically if the window has a max height defined.
141 if (max_size.height() != 0) 137 if (max_size.height() != 0)
142 return; 138 return;
143 if (target_state->HasRestoreBounds() && 139 if (target_state->HasRestoreBounds() &&
144 (target->bounds().height() == work_area.height() && 140 (target->bounds().height() == work_area.height() &&
145 target->bounds().y() == work_area.y())) { 141 target->bounds().y() == work_area.y())) {
146 SingleAxisUnmaximize(target_state, 142 SingleAxisUnmaximize(target_state,
147 target_state->GetRestoreBoundsInScreen()); 143 target_state->GetRestoreBoundsInScreen());
144 event->StopPropagation();
148 } else { 145 } else {
149 gfx::Point origin = target->bounds().origin(); 146 gfx::Point origin = target->bounds().origin();
150 wm::ConvertPointToScreen(target->parent(), &origin); 147 wm::ConvertPointToScreen(target->parent(), &origin);
151 SingleAxisMaximize(target_state, 148 SingleAxisMaximize(target_state,
152 gfx::Rect(origin.x(), 149 gfx::Rect(origin.x(),
153 work_area.y(), 150 work_area.y(),
154 target->bounds().width(), 151 target->bounds().width(),
155 work_area.height())); 152 work_area.height()));
153 event->StopPropagation();
156 } 154 }
oshima 2013/12/17 00:33:46 can't you just call StopPropagation here once?
157 } else if (component == HTLEFT || component == HTRIGHT) { 155 } else if (component == HTLEFT || component == HTRIGHT) {
158 // Don't maximize horizontally if the window has a max width defined. 156 // Don't maximize horizontally if the window has a max width defined.
159 if (max_size.width() != 0) 157 if (max_size.width() != 0)
160 return; 158 return;
161 if (target_state->HasRestoreBounds() && 159 if (target_state->HasRestoreBounds() &&
162 (target->bounds().width() == work_area.width() && 160 (target->bounds().width() == work_area.width() &&
163 target->bounds().x() == work_area.x())) { 161 target->bounds().x() == work_area.x())) {
164 SingleAxisUnmaximize(target_state, 162 SingleAxisUnmaximize(target_state,
165 target_state->GetRestoreBoundsInScreen()); 163 target_state->GetRestoreBoundsInScreen());
164 event->StopPropagation();
166 } else { 165 } else {
167 gfx::Point origin = target->bounds().origin(); 166 gfx::Point origin = target->bounds().origin();
168 wm::ConvertPointToScreen(target->parent(), &origin); 167 wm::ConvertPointToScreen(target->parent(), &origin);
169 SingleAxisMaximize(target_state, 168 SingleAxisMaximize(target_state,
170 gfx::Rect(work_area.x(), 169 gfx::Rect(work_area.x(),
171 origin.y(), 170 origin.y(),
172 work_area.width(), 171 work_area.width(),
173 target->bounds().height())); 172 target->bounds().height()));
173 event->StopPropagation();
174 } 174 }
oshima 2013/12/17 00:33:46 ditto
175 } 175 }
176 } 176 }
177 } 177 }
178 178
179 } // namespace internal 179 } // namespace internal
180 } // namespace ash 180 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698