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

Side by Side Diff: ash/wm/toplevel_window_event_handler.cc

Issue 10911256: Change the way the ToplevelEventHandler is hooked up. It is now both a pre- and post-target event h… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 3 months 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
« no previous file with comments | « ash/wm/toplevel_window_event_handler.h ('k') | ash/wm/workspace/workspace2.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/toplevel_window_event_handler.h" 5 #include "ash/wm/toplevel_window_event_handler.h"
6 6
7 #include "ash/shell.h" 7 #include "ash/shell.h"
8 #include "ash/wm/default_window_resizer.h" 8 #include "ash/wm/default_window_resizer.h"
9 #include "ash/wm/property_util.h" 9 #include "ash/wm/property_util.h"
10 #include "ash/wm/resize_shadow_controller.h" 10 #include "ash/wm/resize_shadow_controller.h"
11 #include "ash/wm/window_resizer.h" 11 #include "ash/wm/window_resizer.h"
12 #include "ash/wm/window_util.h" 12 #include "ash/wm/window_util.h"
13 #include "ash/wm/workspace/snap_sizer.h" 13 #include "ash/wm/workspace/snap_sizer.h"
14 #include "base/message_loop.h" 14 #include "base/message_loop.h"
15 #include "base/run_loop.h" 15 #include "base/run_loop.h"
16 #include "ui/aura/client/aura_constants.h" 16 #include "ui/aura/client/aura_constants.h"
17 #include "ui/aura/client/cursor_client.h" 17 #include "ui/aura/client/cursor_client.h"
18 #include "ui/aura/env.h" 18 #include "ui/aura/env.h"
19 #include "ui/aura/root_window.h" 19 #include "ui/aura/root_window.h"
20 #include "ui/aura/window.h" 20 #include "ui/aura/window.h"
21 #include "ui/aura/window_delegate.h" 21 #include "ui/aura/window_delegate.h"
22 #include "ui/aura/window_observer.h" 22 #include "ui/aura/window_observer.h"
23 #include "ui/base/cursor/cursor.h" 23 #include "ui/base/cursor/cursor.h"
24 #include "ui/base/events/event.h" 24 #include "ui/base/events/event.h"
25 #include "ui/base/events/event_functions.h"
25 #include "ui/base/gestures/gesture_recognizer.h" 26 #include "ui/base/gestures/gesture_recognizer.h"
26 #include "ui/base/hit_test.h" 27 #include "ui/base/hit_test.h"
27 #include "ui/base/ui_base_types.h" 28 #include "ui/base/ui_base_types.h"
28 #include "ui/compositor/layer.h" 29 #include "ui/compositor/layer.h"
29 #include "ui/compositor/scoped_layer_animation_settings.h" 30 #include "ui/compositor/scoped_layer_animation_settings.h"
30 #include "ui/gfx/screen.h" 31 #include "ui/gfx/screen.h"
31 32
32 namespace { 33 namespace {
33 const double kMinHorizVelocityForWindowSwipe = 1100; 34 const double kMinHorizVelocityForWindowSwipe = 1100;
34 const double kMinVertVelocityForWindowMinimize = 1000; 35 const double kMinVertVelocityForWindowMinimize = 1000;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 } 94 }
94 95
95 96
96 // ToplevelWindowEventHandler -------------------------------------------------- 97 // ToplevelWindowEventHandler --------------------------------------------------
97 98
98 ToplevelWindowEventHandler::ToplevelWindowEventHandler(aura::Window* owner) 99 ToplevelWindowEventHandler::ToplevelWindowEventHandler(aura::Window* owner)
99 : in_move_loop_(false), 100 : in_move_loop_(false),
100 move_cancelled_(false) { 101 move_cancelled_(false) {
101 aura::client::SetWindowMoveClient(owner, this); 102 aura::client::SetWindowMoveClient(owner, this);
102 Shell::GetInstance()->display_controller()->AddObserver(this); 103 Shell::GetInstance()->display_controller()->AddObserver(this);
104 owner->AddPreTargetHandler(this);
105 owner->AddPostTargetHandler(this);
103 } 106 }
104 107
105 ToplevelWindowEventHandler::~ToplevelWindowEventHandler() { 108 ToplevelWindowEventHandler::~ToplevelWindowEventHandler() {
106 Shell::GetInstance()->display_controller()->RemoveObserver(this); 109 Shell::GetInstance()->display_controller()->RemoveObserver(this);
107 } 110 }
108 111
109 ui::EventResult ToplevelWindowEventHandler::OnKeyEvent(ui::KeyEvent* event) { 112 ui::EventResult ToplevelWindowEventHandler::OnKeyEvent(ui::KeyEvent* event) {
110 if (window_resizer_.get() && event->type() == ui::ET_KEY_PRESSED && 113 if (window_resizer_.get() && event->type() == ui::ET_KEY_PRESSED &&
111 event->key_code() == ui::VKEY_ESCAPE) { 114 event->key_code() == ui::VKEY_ESCAPE) {
112 CompleteDrag(DRAG_REVERT, event->flags()); 115 CompleteDrag(DRAG_REVERT, event->flags());
113 } 116 }
114 return ui::ER_UNHANDLED; 117 return ui::ER_UNHANDLED;
115 } 118 }
116 119
117 ui::EventResult ToplevelWindowEventHandler::OnMouseEvent( 120 ui::EventResult ToplevelWindowEventHandler::OnMouseEvent(
118 ui::MouseEvent* event) { 121 ui::MouseEvent* event) {
119 if ((event->flags() & 122 if ((event->flags() &
120 (ui::EF_MIDDLE_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON)) != 0) 123 (ui::EF_MIDDLE_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON)) != 0)
121 return ui::ER_UNHANDLED; 124 return ui::ER_UNHANDLED;
122 125
123 aura::Window* target = static_cast<aura::Window*>(event->target()); 126 aura::Window* target = static_cast<aura::Window*>(event->target());
124 switch (event->type()) { 127 switch (event->type()) {
125 case ui::ET_MOUSE_PRESSED: { 128 case ui::ET_MOUSE_PRESSED:
126 // We also update the current window component here because for the 129 return HandleMousePressed(target, event);
127 // mouse-drag-release-press case, where the mouse is released and
128 // pressed without mouse move event.
129 int component =
130 target->delegate()->GetNonClientComponent(event->location());
131 if ((event->flags() &
132 (ui::EF_IS_DOUBLE_CLICK | ui::EF_IS_TRIPLE_CLICK)) == 0 &&
133 WindowResizer::GetBoundsChangeForWindowComponent(component)) {
134 gfx::Point location_in_parent(
135 ConvertPointToParent(target, event->location()));
136 CreateScopedWindowResizer(target, location_in_parent, component);
137 } else {
138 window_resizer_.reset();
139 }
140 return WindowResizer::GetBoundsChangeForWindowComponent(component) != 0 ?
141 ui::ER_CONSUMED : ui::ER_UNHANDLED;
142 }
143 case ui::ET_MOUSE_DRAGGED: 130 case ui::ET_MOUSE_DRAGGED:
144 return HandleDrag(target, event) ? ui::ER_CONSUMED : ui::ER_UNHANDLED; 131 return HandleDrag(target, event) ? ui::ER_CONSUMED : ui::ER_UNHANDLED;
145 case ui::ET_MOUSE_CAPTURE_CHANGED: 132 case ui::ET_MOUSE_CAPTURE_CHANGED:
146 case ui::ET_MOUSE_RELEASED: 133 case ui::ET_MOUSE_RELEASED:
147 CompleteDrag(event->type() == ui::ET_MOUSE_RELEASED ? 134 return HandleMouseReleased(target, event);
148 DRAG_COMPLETE : DRAG_REVERT,
149 event->flags());
150 if (in_move_loop_) {
151 quit_closure_.Run();
152 in_move_loop_ = false;
153 }
154 // Completing the drag may result in hiding the window. If this happens
155 // return true so no other handlers/observers see the event. Otherwise
156 // they see the event on a hidden window.
157 if (event->type() == ui::ET_MOUSE_CAPTURE_CHANGED &&
158 !target->IsVisible()) {
159 return ui::ER_CONSUMED;
160 }
161 break;
162 case ui::ET_MOUSE_MOVED: 135 case ui::ET_MOUSE_MOVED:
163 return HandleMouseMoved(target, event) ? 136 return HandleMouseMoved(target, event);
164 ui::ER_CONSUMED : ui::ER_UNHANDLED;
165 case ui::ET_MOUSE_EXITED: 137 case ui::ET_MOUSE_EXITED:
166 return HandleMouseExited(target, event) ? 138 return HandleMouseExited(target, event);
167 ui::ER_CONSUMED : ui::ER_UNHANDLED;
168 default: 139 default:
169 break; 140 break;
170 } 141 }
171 return ui::ER_UNHANDLED; 142 return ui::ER_UNHANDLED;
172 } 143 }
173 144
174 ui::EventResult ToplevelWindowEventHandler::OnScrollEvent( 145 ui::EventResult ToplevelWindowEventHandler::OnScrollEvent(
175 ui::ScrollEvent* event) { 146 ui::ScrollEvent* event) {
176 return ui::ER_UNHANDLED; 147 return ui::ER_UNHANDLED;
177 } 148 }
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 int event_flags) { 313 int event_flags) {
343 scoped_ptr<ScopedWindowResizer> resizer(window_resizer_.release()); 314 scoped_ptr<ScopedWindowResizer> resizer(window_resizer_.release());
344 if (resizer.get()) { 315 if (resizer.get()) {
345 if (status == DRAG_COMPLETE) 316 if (status == DRAG_COMPLETE)
346 resizer->resizer()->CompleteDrag(event_flags); 317 resizer->resizer()->CompleteDrag(event_flags);
347 else 318 else
348 resizer->resizer()->RevertDrag(); 319 resizer->resizer()->RevertDrag();
349 } 320 }
350 } 321 }
351 322
352 bool ToplevelWindowEventHandler::HandleDrag(aura::Window* target, 323 ui::EventResult ToplevelWindowEventHandler::HandleMousePressed(
353 ui::LocatedEvent* event) { 324 aura::Window* target,
325 ui::MouseEvent* event) {
326
sky 2012/09/12 21:25:39 nit: remove newline.
327 // Move/size operations are initiated post-target handling to give the target
328 // an opportunity to cancel this default behavior by returning ER_HANDLED.
329 if (ui::EventCanceledDefaultHandling(*event))
330 return ui::ER_UNHANDLED;
331
332 // We also update the current window component here because for the
333 // mouse-drag-release-press case, where the mouse is released and
334 // pressed without mouse move event.
335 int component =
336 target->delegate()->GetNonClientComponent(event->location());
337 if ((event->flags() &
338 (ui::EF_IS_DOUBLE_CLICK | ui::EF_IS_TRIPLE_CLICK)) == 0 &&
339 WindowResizer::GetBoundsChangeForWindowComponent(component)) {
340 gfx::Point location_in_parent(
341 ConvertPointToParent(target, event->location()));
342 CreateScopedWindowResizer(target, location_in_parent, component);
343 } else {
344 window_resizer_.reset();
345 }
346 return WindowResizer::GetBoundsChangeForWindowComponent(component) != 0 ?
347 ui::ER_CONSUMED : ui::ER_UNHANDLED;
348 }
349
350 ui::EventResult ToplevelWindowEventHandler::HandleMouseReleased(
351 aura::Window* target,
352 ui::MouseEvent* event) {
353 if (event->phase() != ui::EP_PRETARGET)
354 return ui::ER_UNHANDLED;
355
356 CompleteDrag(event->type() == ui::ET_MOUSE_RELEASED ?
357 DRAG_COMPLETE : DRAG_REVERT,
358 event->flags());
359 if (in_move_loop_) {
360 quit_closure_.Run();
361 in_move_loop_ = false;
362 }
363 // Completing the drag may result in hiding the window. If this happens
364 // return true so no other handlers/observers see the event. Otherwise
365 // they see the event on a hidden window.
366 if (event->type() == ui::ET_MOUSE_CAPTURE_CHANGED &&
367 !target->IsVisible()) {
368 return ui::ER_CONSUMED;
369 }
370 return ui::ER_UNHANDLED;
371 }
372
373 ui::EventResult ToplevelWindowEventHandler::HandleDrag(
374 aura::Window* target,
375 ui::LocatedEvent* event) {
354 // This function only be triggered to move window 376 // This function only be triggered to move window
355 // by mouse drag or touch move event. 377 // by mouse drag or touch move event.
356 DCHECK(event->type() == ui::ET_MOUSE_DRAGGED || 378 DCHECK(event->type() == ui::ET_MOUSE_DRAGGED ||
357 event->type() == ui::ET_TOUCH_MOVED || 379 event->type() == ui::ET_TOUCH_MOVED ||
358 event->type() == ui::ET_GESTURE_SCROLL_UPDATE); 380 event->type() == ui::ET_GESTURE_SCROLL_UPDATE);
359 381
382 // Drag actions are performed pre-target handling to prevent spurious mouse
383 // moves from the move/size operation from being sent to the target.
384 if (event->phase() != ui::EP_PRETARGET)
385 return ui::ER_UNHANDLED;
386
360 if (!window_resizer_.get()) 387 if (!window_resizer_.get())
361 return false; 388 return ui::ER_UNHANDLED;
362 window_resizer_->resizer()->Drag( 389 window_resizer_->resizer()->Drag(
363 ConvertPointToParent(target, event->location()), event->flags()); 390 ConvertPointToParent(target, event->location()), event->flags());
364 return true; 391 return ui::ER_CONSUMED;
365 } 392 }
366 393
367 bool ToplevelWindowEventHandler::HandleMouseMoved(aura::Window* target, 394 ui::EventResult ToplevelWindowEventHandler::HandleMouseMoved(
368 ui::LocatedEvent* event) { 395 aura::Window* target,
396 ui::LocatedEvent* event) {
397 // Shadow effects are applied after target handling. Note that we don't
398 // respect ER_HANDLED here right now since we have not had a reason to allow
399 // the target to cancel shadow rendering.
400 if (event->phase() != ui::EP_POSTTARGET)
401 return ui::ER_UNHANDLED;
402
369 // TODO(jamescook): Move the resize cursor update code into here from 403 // TODO(jamescook): Move the resize cursor update code into here from
370 // CompoundEventFilter? 404 // CompoundEventFilter?
371 internal::ResizeShadowController* controller = 405 internal::ResizeShadowController* controller =
372 Shell::GetInstance()->resize_shadow_controller(); 406 Shell::GetInstance()->resize_shadow_controller();
373 if (controller) { 407 if (controller) {
374 if (event->flags() & ui::EF_IS_NON_CLIENT) { 408 if (event->flags() & ui::EF_IS_NON_CLIENT) {
375 int component = 409 int component =
376 target->delegate()->GetNonClientComponent(event->location()); 410 target->delegate()->GetNonClientComponent(event->location());
377 controller->ShowShadow(target, component); 411 controller->ShowShadow(target, component);
378 } else { 412 } else {
379 controller->HideShadow(target); 413 controller->HideShadow(target);
380 } 414 }
381 } 415 }
382 return false; 416 return ui::ER_UNHANDLED;
383 } 417 }
384 418
385 bool ToplevelWindowEventHandler::HandleMouseExited(aura::Window* target, 419 ui::EventResult ToplevelWindowEventHandler::HandleMouseExited(
386 ui::LocatedEvent* event) { 420 aura::Window* target,
421 ui::LocatedEvent* event) {
422 // Shadow effects are applied after target handling. Note that we don't
423 // respect ER_HANDLED here right now since we have not had a reason to allow
424 // the target to cancel shadow rendering.
425 if (event->phase() != ui::EP_POSTTARGET)
426 return ui::ER_UNHANDLED;
427
387 internal::ResizeShadowController* controller = 428 internal::ResizeShadowController* controller =
388 Shell::GetInstance()->resize_shadow_controller(); 429 Shell::GetInstance()->resize_shadow_controller();
389 if (controller) 430 if (controller)
390 controller->HideShadow(target); 431 controller->HideShadow(target);
391 return false; 432 return ui::ER_UNHANDLED;
392 } 433 }
393 434
394 void ToplevelWindowEventHandler::ResizerWindowDestroyed() { 435 void ToplevelWindowEventHandler::ResizerWindowDestroyed() {
395 // We explicitly don't invoke RevertDrag() since that may do things to window. 436 // We explicitly don't invoke RevertDrag() since that may do things to window.
396 // Instead we destroy the resizer. 437 // Instead we destroy the resizer.
397 window_resizer_.reset(); 438 window_resizer_.reset();
398 439
399 // End the move loop. This does nothing if we're not in a move loop. 440 // End the move loop. This does nothing if we're not in a move loop.
400 EndMoveLoop(); 441 EndMoveLoop();
401 } 442 }
402 443
403 } // namespace ash 444 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/toplevel_window_event_handler.h ('k') | ash/wm/workspace/workspace2.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698