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

Side by Side Diff: ui/views/widget/root_view.cc

Issue 10479010: Gesture related changes for views: (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix test and add some mores Created 8 years, 6 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 | « ui/views/widget/root_view.h ('k') | ui/views/widget/widget.h » ('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 "ui/views/widget/root_view.h" 5 #include "ui/views/widget/root_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 RootView::RootView(Widget* widget) 59 RootView::RootView(Widget* widget)
60 : widget_(widget), 60 : widget_(widget),
61 mouse_pressed_handler_(NULL), 61 mouse_pressed_handler_(NULL),
62 mouse_move_handler_(NULL), 62 mouse_move_handler_(NULL),
63 last_click_handler_(NULL), 63 last_click_handler_(NULL),
64 explicit_mouse_handler_(false), 64 explicit_mouse_handler_(false),
65 last_mouse_event_flags_(0), 65 last_mouse_event_flags_(0),
66 last_mouse_event_x_(-1), 66 last_mouse_event_x_(-1),
67 last_mouse_event_y_(-1), 67 last_mouse_event_y_(-1),
68 touch_pressed_handler_(NULL), 68 touch_pressed_handler_(NULL),
69 gesture_handling_view_(NULL), 69 gesture_handler_(NULL),
70 ALLOW_THIS_IN_INITIALIZER_LIST(focus_search_(this, false, false)), 70 ALLOW_THIS_IN_INITIALIZER_LIST(focus_search_(this, false, false)),
71 focus_traversable_parent_(NULL), 71 focus_traversable_parent_(NULL),
72 focus_traversable_parent_view_(NULL) { 72 focus_traversable_parent_view_(NULL) {
73 } 73 }
74 74
75 RootView::~RootView() { 75 RootView::~RootView() {
76 // If we have children remove them explicitly so to make sure a remove 76 // If we have children remove them explicitly so to make sure a remove
77 // notification is sent for each one of them. 77 // notification is sent for each one of them.
78 if (has_children()) 78 if (has_children())
79 RemoveAllChildViews(true); 79 RemoveAllChildViews(true);
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 // We allow the view to delete us from ProcessMouseReleased. As such, 293 // We allow the view to delete us from ProcessMouseReleased. As such,
294 // configure state such that we're done first, then call View. 294 // configure state such that we're done first, then call View.
295 View* mouse_pressed_handler = mouse_pressed_handler_; 295 View* mouse_pressed_handler = mouse_pressed_handler_;
296 SetMouseHandler(NULL); 296 SetMouseHandler(NULL);
297 mouse_pressed_handler->ProcessMouseReleased(mouse_released); 297 mouse_pressed_handler->ProcessMouseReleased(mouse_released);
298 // WARNING: we may have been deleted. 298 // WARNING: we may have been deleted.
299 } 299 }
300 } 300 }
301 301
302 void RootView::OnMouseCaptureLost() { 302 void RootView::OnMouseCaptureLost() {
303 if (mouse_pressed_handler_) { 303 // TODO: this likely needs to reset touch handler too.
304
305 if (mouse_pressed_handler_ || gesture_handler_) {
304 // Synthesize a release event for UpdateCursor. 306 // Synthesize a release event for UpdateCursor.
305 MouseEvent release_event(ui::ET_MOUSE_RELEASED, last_mouse_event_x_, 307 if (mouse_pressed_handler_) {
306 last_mouse_event_y_, last_mouse_event_flags_); 308 MouseEvent release_event(ui::ET_MOUSE_RELEASED, last_mouse_event_x_,
307 UpdateCursor(release_event); 309 last_mouse_event_y_, last_mouse_event_flags_);
310 UpdateCursor(release_event);
311 }
308 // We allow the view to delete us from OnMouseCaptureLost. As such, 312 // We allow the view to delete us from OnMouseCaptureLost. As such,
309 // configure state such that we're done first, then call View. 313 // configure state such that we're done first, then call View.
310 View* mouse_pressed_handler = mouse_pressed_handler_; 314 View* mouse_pressed_handler = mouse_pressed_handler_;
315 View* gesture_handler = gesture_handler_;
311 SetMouseHandler(NULL); 316 SetMouseHandler(NULL);
312 mouse_pressed_handler->OnMouseCaptureLost(); 317 if (mouse_pressed_handler)
318 mouse_pressed_handler->OnMouseCaptureLost();
319 else
320 gesture_handler->OnMouseCaptureLost();
313 // WARNING: we may have been deleted. 321 // WARNING: we may have been deleted.
314 } 322 }
315 } 323 }
316 324
317 void RootView::OnMouseMoved(const MouseEvent& event) { 325 void RootView::OnMouseMoved(const MouseEvent& event) {
318 MouseEvent e(event, this); 326 MouseEvent e(event, this);
319 View* v = GetEventHandlerForPoint(e.location()); 327 View* v = GetEventHandlerForPoint(e.location());
320 // Find the first enabled view, or the existing move handler, whichever comes 328 // Find the first enabled view, or the existing move handler, whichever comes
321 // first. The check for the existing handler is because if a view becomes 329 // first. The check for the existing handler is because if a view becomes
322 // disabled while handling moves, it's wrong to suddenly send ET_MOUSE_EXITED 330 // disabled while handling moves, it's wrong to suddenly send ET_MOUSE_EXITED
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 bool RootView::OnMouseWheel(const MouseWheelEvent& event) { 375 bool RootView::OnMouseWheel(const MouseWheelEvent& event) {
368 MouseWheelEvent e(event, this); 376 MouseWheelEvent e(event, this);
369 bool consumed = false; 377 bool consumed = false;
370 for (View* v = GetFocusManager()->GetFocusedView(); 378 for (View* v = GetFocusManager()->GetFocusedView();
371 v && v != this && !consumed; v = v->parent()) 379 v && v != this && !consumed; v = v->parent())
372 consumed = v->OnMouseWheel(e); 380 consumed = v->OnMouseWheel(e);
373 return consumed; 381 return consumed;
374 } 382 }
375 383
376 ui::TouchStatus RootView::OnTouchEvent(const TouchEvent& event) { 384 ui::TouchStatus RootView::OnTouchEvent(const TouchEvent& event) {
385 // TODO: this looks all wrong. On a TOUCH_PRESSED we should figure out the
386 // view and target that view with all touches with the same id until the
387 // release (or keep it if captured).
388
377 TouchEvent e(event, this); 389 TouchEvent e(event, this);
378 390
379 // If touch_pressed_handler_ is non null, we are currently processing 391 // If touch_pressed_handler_ is non null, we are currently processing
380 // a touch down on the screen situation. In that case we send the 392 // a touch down on the screen situation. In that case we send the
381 // event to touch_pressed_handler_ 393 // event to touch_pressed_handler_
382 ui::TouchStatus status = ui::TOUCH_STATUS_UNKNOWN; 394 ui::TouchStatus status = ui::TOUCH_STATUS_UNKNOWN;
383 395
384 if (touch_pressed_handler_) { 396 if (touch_pressed_handler_) {
385 TouchEvent touch_event(e, this, touch_pressed_handler_); 397 TouchEvent touch_event(e, this, touch_pressed_handler_);
386 status = touch_pressed_handler_->ProcessTouchEvent(touch_event); 398 status = touch_pressed_handler_->ProcessTouchEvent(touch_event);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 // Reset touch_pressed_handler_ to indicate that no processing is occurring. 438 // Reset touch_pressed_handler_ to indicate that no processing is occurring.
427 touch_pressed_handler_ = NULL; 439 touch_pressed_handler_ = NULL;
428 440
429 return status; 441 return status;
430 } 442 }
431 443
432 ui::GestureStatus RootView::OnGestureEvent(const GestureEvent& event) { 444 ui::GestureStatus RootView::OnGestureEvent(const GestureEvent& event) {
433 GestureEvent e(event, this); 445 GestureEvent e(event, this);
434 ui::GestureStatus status = ui::GESTURE_STATUS_UNKNOWN; 446 ui::GestureStatus status = ui::GESTURE_STATUS_UNKNOWN;
435 447
448 if (gesture_handler_) {
449 // Allow |gesture_handler_| to delete this during processing.
450 View* handler = gesture_handler_;
451 GestureEvent handler_event(event, this, gesture_handler_);
452 // TODO: should only do this for the last touch id that goes up.
453 if (event.type() == ui::ET_GESTURE_TAP_UP)
454 gesture_handler_ = NULL;
455 return handler->OnGestureEvent(handler_event);
456 }
457
436 // Walk up the tree until we find a view that wants the gesture event. 458 // Walk up the tree until we find a view that wants the gesture event.
437 for (gesture_handling_view_ = GetEventHandlerForPoint(e.location()); 459 for (gesture_handler_ = GetEventHandlerForPoint(e.location());
438 gesture_handling_view_ && (gesture_handling_view_ != this); 460 gesture_handler_ && (gesture_handler_ != this);
439 gesture_handling_view_ = gesture_handling_view_->parent()) { 461 gesture_handler_ = gesture_handler_->parent()) {
440 if (!gesture_handling_view_->enabled()) { 462 if (!gesture_handler_->enabled()) {
441 // Disabled views eat events but are treated as not handled. 463 // Disabled views eat events but are treated as not handled.
442 return ui::GESTURE_STATUS_UNKNOWN; 464 return ui::GESTURE_STATUS_UNKNOWN;
443 } 465 }
444 466
445 // See if this view wants to handle the Gesture. 467 // See if this view wants to handle the Gesture.
446 GestureEvent gesture_event(e, this, gesture_handling_view_); 468 GestureEvent gesture_event(e, this, gesture_handler_);
447 status = gesture_handling_view_->ProcessGestureEvent(gesture_event); 469 status = gesture_handler_->OnGestureEvent(gesture_event);
448 470
449 // The view could have removed itself from the tree when handling 471 // The view could have removed itself from the tree when handling
450 // OnGestureEvent(). So handle as per OnMousePressed. NB: we 472 // OnGestureEvent(). So handle as per OnMousePressed. NB: we
451 // assume that the RootView itself cannot be so removed. 473 // assume that the RootView itself cannot be so removed.
452 if (!gesture_handling_view_) 474 if (!gesture_handler_)
453 return ui::GESTURE_STATUS_UNKNOWN; 475 return ui::GESTURE_STATUS_UNKNOWN;
454 476
455 // The gesture event wasn't processed. Go up the view hierarchy and 477 // The gesture event wasn't processed. Go up the view hierarchy and
456 // dispatch the gesture event. 478 // dispatch the gesture event.
457 if (status == ui::GESTURE_STATUS_UNKNOWN) 479 if (status == ui::GESTURE_STATUS_UNKNOWN)
458 continue; 480 continue;
459 else if (status == ui::GESTURE_STATUS_CONSUMED) 481 else if (status == ui::GESTURE_STATUS_CONSUMED)
460 return status; 482 return status;
461 else 483 else
462 return ui::GESTURE_STATUS_UNKNOWN; 484 return ui::GESTURE_STATUS_UNKNOWN;
463 } 485 }
486
487 gesture_handler_ = NULL;
488
464 return status; 489 return status;
465 } 490 }
466 491
467 void RootView::SetMouseHandler(View *new_mh) { 492 void RootView::SetMouseHandler(View* new_mh) {
468 // If we're clearing the mouse handler, clear explicit_mouse_handler_ as well. 493 // If we're clearing the mouse handler, clear explicit_mouse_handler_ as well.
469 explicit_mouse_handler_ = (new_mh != NULL); 494 explicit_mouse_handler_ = (new_mh != NULL);
470 mouse_pressed_handler_ = new_mh; 495 mouse_pressed_handler_ = new_mh;
496 gesture_handler_ = new_mh;
471 drag_info_.Reset(); 497 drag_info_.Reset();
472 } 498 }
473 499
474 void RootView::GetAccessibleState(ui::AccessibleViewState* state) { 500 void RootView::GetAccessibleState(ui::AccessibleViewState* state) {
475 state->role = ui::AccessibilityTypes::ROLE_APPLICATION; 501 state->role = ui::AccessibilityTypes::ROLE_APPLICATION;
476 } 502 }
477 503
478 void RootView::ReorderChildLayers(ui::Layer* parent_layer) { 504 void RootView::ReorderChildLayers(ui::Layer* parent_layer) {
479 View::ReorderChildLayers(parent_layer); 505 View::ReorderChildLayers(parent_layer);
480 } 506 }
481 507
482 //////////////////////////////////////////////////////////////////////////////// 508 ////////////////////////////////////////////////////////////////////////////////
483 // RootView, protected: 509 // RootView, protected:
484 510
485 void RootView::ViewHierarchyChanged(bool is_add, View* parent, View* child) { 511 void RootView::ViewHierarchyChanged(bool is_add, View* parent, View* child) {
486 widget_->ViewHierarchyChanged(is_add, parent, child); 512 widget_->ViewHierarchyChanged(is_add, parent, child);
487 513
488 if (!is_add) { 514 if (!is_add) {
489 if (!explicit_mouse_handler_ && mouse_pressed_handler_ == child) 515 if (!explicit_mouse_handler_ && mouse_pressed_handler_ == child)
490 mouse_pressed_handler_ = NULL; 516 mouse_pressed_handler_ = NULL;
491 if (mouse_move_handler_ == child) 517 if (mouse_move_handler_ == child)
492 mouse_move_handler_ = NULL; 518 mouse_move_handler_ = NULL;
493 if (touch_pressed_handler_ == child) 519 if (touch_pressed_handler_ == child)
494 touch_pressed_handler_ = NULL; 520 touch_pressed_handler_ = NULL;
495 if (gesture_handling_view_ == child) 521 if (gesture_handler_ == child)
496 gesture_handling_view_ = NULL; 522 gesture_handler_ = NULL;
497 } 523 }
498 } 524 }
499 525
500 void RootView::OnPaint(gfx::Canvas* canvas) { 526 void RootView::OnPaint(gfx::Canvas* canvas) {
501 if (!layer() || !layer()->fills_bounds_opaquely()) 527 if (!layer() || !layer()->fills_bounds_opaquely())
502 canvas->DrawColor(SK_ColorBLACK, SkXfermode::kClear_Mode); 528 canvas->DrawColor(SK_ColorBLACK, SkXfermode::kClear_Mode);
503 529
504 // TODO (pkotwicz): Remove this once we switch over to Aura desktop. 530 // TODO (pkotwicz): Remove this once we switch over to Aura desktop.
505 // This is needed so that we can set the background behind the RWHV when the 531 // This is needed so that we can set the background behind the RWHV when the
506 // RWHV is not visible. Not needed once there is a view between the RootView 532 // RWHV is not visible. Not needed once there is a view between the RootView
(...skipping 21 matching lines...) Expand all
528 } 554 }
529 555
530 void RootView::SetMouseLocationAndFlags(const MouseEvent& event) { 556 void RootView::SetMouseLocationAndFlags(const MouseEvent& event) {
531 last_mouse_event_flags_ = event.flags(); 557 last_mouse_event_flags_ = event.flags();
532 last_mouse_event_x_ = event.x(); 558 last_mouse_event_x_ = event.x();
533 last_mouse_event_y_ = event.y(); 559 last_mouse_event_y_ = event.y();
534 } 560 }
535 561
536 } // namespace internal 562 } // namespace internal
537 } // namespace views 563 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/widget/root_view.h ('k') | ui/views/widget/widget.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698