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

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

Issue 8364039: Initial views touchui GestureRecognizer support (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Reverted chrome_switches.cc changes and TOT sync up Created 9 years, 1 month 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "views/widget/root_view.h" 5 #include "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"
11 #include "ui/base/accessibility/accessible_view_state.h" 11 #include "ui/base/accessibility/accessible_view_state.h"
12 #include "ui/base/dragdrop/drag_drop_types.h" 12 #include "ui/base/dragdrop/drag_drop_types.h"
13 #include "ui/base/keycodes/keyboard_codes.h" 13 #include "ui/base/keycodes/keyboard_codes.h"
14 #include "ui/gfx/canvas_skia.h" 14 #include "ui/gfx/canvas_skia.h"
15 #include "ui/gfx/compositor/layer.h" 15 #include "ui/gfx/compositor/layer.h"
16 #include "views/focus/view_storage.h" 16 #include "views/focus/view_storage.h"
17 #include "views/layout/fill_layout.h" 17 #include "views/layout/fill_layout.h"
18 #include "views/touchui/gesture_manager.h" 18 #include "views/touchui/gesture_manager.h"
19 #include "views/touchui/gesture_recognizer.h"
19 #include "views/widget/widget.h" 20 #include "views/widget/widget.h"
20 21
21 namespace views { 22 namespace views {
22 namespace internal { 23 namespace internal {
23 24
24 // static 25 // static
25 const char RootView::kViewClassName[] = "views/RootView"; 26 const char RootView::kViewClassName[] = "views/RootView";
26 27
27 //////////////////////////////////////////////////////////////////////////////// 28 ////////////////////////////////////////////////////////////////////////////////
28 // RootView, public: 29 // RootView, public:
29 30
30 // Creation and lifetime ------------------------------------------------------- 31 // Creation and lifetime -------------------------------------------------------
31 32
32 RootView::RootView(Widget* widget) 33 RootView::RootView(Widget* widget)
33 : widget_(widget), 34 : widget_(widget),
34 mouse_pressed_handler_(NULL), 35 mouse_pressed_handler_(NULL),
35 mouse_move_handler_(NULL), 36 mouse_move_handler_(NULL),
36 last_click_handler_(NULL), 37 last_click_handler_(NULL),
37 explicit_mouse_handler_(false), 38 explicit_mouse_handler_(false),
38 last_mouse_event_flags_(0), 39 last_mouse_event_flags_(0),
39 last_mouse_event_x_(-1), 40 last_mouse_event_x_(-1),
40 last_mouse_event_y_(-1), 41 last_mouse_event_y_(-1),
41 gesture_manager_(GestureManager::GetInstance()), 42 gesture_manager_(GestureManager::GetInstance()),
42 touch_pressed_handler_(NULL), 43 touch_pressed_handler_(NULL),
44 gesture_recognizer_(GestureRecognizer::GetInstance()),
45 gesture_handling_view_(NULL),
43 ALLOW_THIS_IN_INITIALIZER_LIST(focus_search_(this, false, false)), 46 ALLOW_THIS_IN_INITIALIZER_LIST(focus_search_(this, false, false)),
44 focus_traversable_parent_(NULL), 47 focus_traversable_parent_(NULL),
45 focus_traversable_parent_view_(NULL) { 48 focus_traversable_parent_view_(NULL) {
46 } 49 }
47 50
48 RootView::~RootView() { 51 RootView::~RootView() {
49 // If we have children remove them explicitly so to make sure a remove 52 // If we have children remove them explicitly so to make sure a remove
50 // notification is sent for each one of them. 53 // notification is sent for each one of them.
51 if (has_children()) 54 if (has_children())
52 RemoveAllChildViews(true); 55 RemoveAllChildViews(true);
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 TouchEvent e(event, this); 332 TouchEvent e(event, this);
330 333
331 // If touch_pressed_handler_ is non null, we are currently processing 334 // If touch_pressed_handler_ is non null, we are currently processing
332 // a touch down on the screen situation. In that case we send the 335 // a touch down on the screen situation. In that case we send the
333 // event to touch_pressed_handler_ 336 // event to touch_pressed_handler_
334 ui::TouchStatus status = ui::TOUCH_STATUS_UNKNOWN; 337 ui::TouchStatus status = ui::TOUCH_STATUS_UNKNOWN;
335 338
336 if (touch_pressed_handler_) { 339 if (touch_pressed_handler_) {
337 TouchEvent touch_event(e, this, touch_pressed_handler_); 340 TouchEvent touch_event(e, this, touch_pressed_handler_);
338 status = touch_pressed_handler_->ProcessTouchEvent(touch_event); 341 status = touch_pressed_handler_->ProcessTouchEvent(touch_event);
339 if (gesture_manager_->ProcessTouchEventForGesture(e, this, status)) 342 if (DoGestureProcessing(e, status))
340 status = ui::TOUCH_STATUS_SYNTH_MOUSE; 343 status = ui::TOUCH_STATUS_SYNTH_MOUSE;
341 if (status == ui::TOUCH_STATUS_END) 344 if (status == ui::TOUCH_STATUS_END)
342 touch_pressed_handler_ = NULL; 345 touch_pressed_handler_ = NULL;
343 return status; 346 return status;
344 } 347 }
345 348
346 // Walk up the tree until we find a view that wants the touch event. 349 // Walk up the tree until we find a view that wants the touch event.
347 for (touch_pressed_handler_ = GetEventHandlerForPoint(e.location()); 350 for (touch_pressed_handler_ = GetEventHandlerForPoint(e.location());
348 touch_pressed_handler_ && (touch_pressed_handler_ != this); 351 touch_pressed_handler_ && (touch_pressed_handler_ != this);
349 touch_pressed_handler_ = touch_pressed_handler_->parent()) { 352 touch_pressed_handler_ = touch_pressed_handler_->parent()) {
(...skipping 18 matching lines...) Expand all
368 // the touch event. 371 // the touch event.
369 if (status == ui::TOUCH_STATUS_UNKNOWN) 372 if (status == ui::TOUCH_STATUS_UNKNOWN)
370 continue; 373 continue;
371 374
372 // If the touch didn't initiate a touch-sequence, then reset the touch event 375 // If the touch didn't initiate a touch-sequence, then reset the touch event
373 // handler. Otherwise, leave it set so that subsequent touch events are 376 // handler. Otherwise, leave it set so that subsequent touch events are
374 // dispatched to the same handler. 377 // dispatched to the same handler.
375 if (status != ui::TOUCH_STATUS_START) 378 if (status != ui::TOUCH_STATUS_START)
376 touch_pressed_handler_ = NULL; 379 touch_pressed_handler_ = NULL;
377 380
378 if (gesture_manager_->ProcessTouchEventForGesture(e, this, status)) 381 if (DoGestureProcessing(e, status))
379 status = ui::TOUCH_STATUS_SYNTH_MOUSE; 382 status = ui::TOUCH_STATUS_SYNTH_MOUSE;
380 return status; 383 return status;
381 } 384 }
382 385
383 // Reset touch_pressed_handler_ to indicate that no processing is occurring. 386 // Reset touch_pressed_handler_ to indicate that no processing is occurring.
384 touch_pressed_handler_ = NULL; 387 touch_pressed_handler_ = NULL;
385 388
386 // Give the touch event to the gesture manager. 389 // Give the touch event to the gesture manager.
387 if (gesture_manager_->ProcessTouchEventForGesture(e, this, status)) 390 if (DoGestureProcessing(e, status))
388 status = ui::TOUCH_STATUS_SYNTH_MOUSE; 391 status = ui::TOUCH_STATUS_SYNTH_MOUSE;
389 return status; 392 return status;
390 } 393 }
391 394
395 ui::GestureStatus RootView::OnGestureEvent(const GestureEvent& event) {
396 GestureEvent e(event, this);
397 ui::GestureStatus status = ui::GESTURE_STATUS_UNKNOWN;
398
399 // Walk up the tree until we find a view that wants the gesture event.
400 for (gesture_handling_view_ = GetEventHandlerForPoint(e.location());
401 gesture_handling_view_ && (gesture_handling_view_ != this);
402 gesture_handling_view_ = gesture_handling_view_->parent()) {
403 if (!gesture_handling_view_->IsEnabled()) {
404 // Disabled views eat events but are treated as not handled by the
405 // the GestureManager.
406 return ui::GESTURE_STATUS_UNKNOWN;
407 }
408
409 // See if this view wants to handle the Gesture.
410 GestureEvent gesture_event(e, this, gesture_handling_view_);
411 status = gesture_handling_view_->ProcessGestureEvent(gesture_event);
412
413 // The view could have removed itself from the tree when handling
414 // OnGestureEvent(). So handle as per OnMousePressed. NB: we
415 // assume that the RootView itself cannot be so removed.
416 if (!gesture_handling_view_) return ui::GESTURE_STATUS_UNKNOWN;
417
418 // The gesture event wasn't processed. Go up the view hierarchy and
419 // dispatch the gesture event.
420 if (status == ui::GESTURE_STATUS_UNKNOWN) {
421 continue;
422 } else if (status == ui::GESTURE_STATUS_CONSUMED) {
423 return status;
424 } else {
425 return ui::GESTURE_STATUS_UNKNOWN;
426 }
427 }
428 return status;
429 }
430
392 void RootView::SetMouseHandler(View *new_mh) { 431 void RootView::SetMouseHandler(View *new_mh) {
393 // If we're clearing the mouse handler, clear explicit_mouse_handler_ as well. 432 // If we're clearing the mouse handler, clear explicit_mouse_handler_ as well.
394 explicit_mouse_handler_ = (new_mh != NULL); 433 explicit_mouse_handler_ = (new_mh != NULL);
395 mouse_pressed_handler_ = new_mh; 434 mouse_pressed_handler_ = new_mh;
396 } 435 }
397 436
398 void RootView::GetAccessibleState(ui::AccessibleViewState* state) { 437 void RootView::GetAccessibleState(ui::AccessibleViewState* state) {
399 state->role = ui::AccessibilityTypes::ROLE_APPLICATION; 438 state->role = ui::AccessibilityTypes::ROLE_APPLICATION;
400 } 439 }
401 440
402 //////////////////////////////////////////////////////////////////////////////// 441 ////////////////////////////////////////////////////////////////////////////////
403 // RootView, protected: 442 // RootView, protected:
404 443
405 void RootView::ViewHierarchyChanged(bool is_add, View* parent, View* child) { 444 void RootView::ViewHierarchyChanged(bool is_add, View* parent, View* child) {
406 widget_->ViewHierarchyChanged(is_add, parent, child); 445 widget_->ViewHierarchyChanged(is_add, parent, child);
407 446
408 if (!is_add) { 447 if (!is_add) {
409 if (!explicit_mouse_handler_ && mouse_pressed_handler_ == child) 448 if (!explicit_mouse_handler_ && mouse_pressed_handler_ == child)
410 mouse_pressed_handler_ = NULL; 449 mouse_pressed_handler_ = NULL;
411 if (mouse_move_handler_ == child) 450 if (mouse_move_handler_ == child)
412 mouse_move_handler_ = NULL; 451 mouse_move_handler_ = NULL;
413 if (touch_pressed_handler_ == child) 452 if (touch_pressed_handler_ == child)
414 touch_pressed_handler_ = NULL; 453 touch_pressed_handler_ = NULL;
454 if (gesture_handling_view_ == child)
455 gesture_handling_view_ = NULL;
415 } 456 }
416 } 457 }
417 458
418 void RootView::OnPaint(gfx::Canvas* canvas) { 459 void RootView::OnPaint(gfx::Canvas* canvas) {
419 if (!layer() || !layer()->fills_bounds_opaquely()) 460 if (!layer() || !layer()->fills_bounds_opaquely())
420 canvas->GetSkCanvas()->drawColor(SK_ColorBLACK, SkXfermode::kClear_Mode); 461 canvas->GetSkCanvas()->drawColor(SK_ColorBLACK, SkXfermode::kClear_Mode);
421 462
422 // TODO (pkotwicz): Remove this once we switch over to Aura desktop. 463 // TODO (pkotwicz): Remove this once we switch over to Aura desktop.
423 // This is needed so that we can set the background behind the RWHV when the 464 // This is needed so that we can set the background behind the RWHV when the
424 // RWHV is not visible. Not needed once there is a view between the RootView 465 // RWHV is not visible. Not needed once there is a view between the RootView
(...skipping 19 matching lines...) Expand all
444 widget_->SetCursor(v->GetCursor(MouseEvent(event, this, v))); 485 widget_->SetCursor(v->GetCursor(MouseEvent(event, this, v)));
445 } 486 }
446 } 487 }
447 488
448 void RootView::SetMouseLocationAndFlags(const MouseEvent& event) { 489 void RootView::SetMouseLocationAndFlags(const MouseEvent& event) {
449 last_mouse_event_flags_ = event.flags(); 490 last_mouse_event_flags_ = event.flags();
450 last_mouse_event_x_ = event.x(); 491 last_mouse_event_x_ = event.x();
451 last_mouse_event_y_ = event.y(); 492 last_mouse_event_y_ = event.y();
452 } 493 }
453 494
495 bool RootView::DoGestureProcessing(const TouchEvent& event,
496 ui::TouchStatus status) {
497 if (status != ui::TOUCH_STATUS_UNKNOWN)
498 return false; // The event was consumed by a touch sequence.
499
500 // Get the GestureEvent list processed from GestureRecognizer.
501 scoped_ptr<GestureRecognizer::Gestures> gestures;
502 gestures.reset(gesture_recognizer_->ProcessTouchEventForGesture(event,
503 status));
504 bool synthetic = true;
505 for (unsigned int i = 0; i < gestures->size(); i++) {
506 GestureEvent* event = gestures->at(i).get();
507 GestureEvent e(*event, this);
508 if (OnGestureEvent(e) == ui::GESTURE_STATUS_CONSUMED) {
509 // All gesture events should be consumed.
510 synthetic = false;
511 } else {
512 synthetic = true;
513 break;
514 }
515 }
516 if (synthetic) {
517 // TODO(Gajen): This should be removed in future once all views are capable
518 // of handling OnGestureEvent.
519 return gesture_manager_->ProcessTouchEventForGesture(event, this,
520 status);
521 }
522 return synthetic;
523 }
524
454 } // namespace internal 525 } // namespace internal
455 } // namespace views 526 } // namespace views
OLDNEW
« views/views.gyp ('K') | « views/widget/root_view.h ('k') | views/widget/widget.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698