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

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: Added gesture tests in view_unittest 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/command_line.h"
9 #include "base/logging.h" 10 #include "base/logging.h"
10 #include "base/message_loop.h" 11 #include "base/message_loop.h"
12 #include "chrome/common/chrome_switches.h"
Ian Vollick 2011/11/08 20:07:54 views/ is not allowed to depend on chrome/, so you
Gajen 2011/11/10 15:52:55 Deprecated, as no longer required in new Design.
11 #include "ui/base/accessibility/accessible_view_state.h" 13 #include "ui/base/accessibility/accessible_view_state.h"
12 #include "ui/base/dragdrop/drag_drop_types.h" 14 #include "ui/base/dragdrop/drag_drop_types.h"
13 #include "ui/base/keycodes/keyboard_codes.h" 15 #include "ui/base/keycodes/keyboard_codes.h"
14 #include "ui/gfx/canvas_skia.h" 16 #include "ui/gfx/canvas_skia.h"
15 #include "ui/gfx/compositor/layer.h" 17 #include "ui/gfx/compositor/layer.h"
16 #include "views/focus/view_storage.h" 18 #include "views/focus/view_storage.h"
17 #include "views/layout/fill_layout.h" 19 #include "views/layout/fill_layout.h"
18 #include "views/touchui/gesture_manager.h" 20 #include "views/touchui/gesture_manager.h"
19 #include "views/widget/widget.h" 21 #include "views/widget/widget.h"
20 22
(...skipping 10 matching lines...) Expand all
31 33
32 RootView::RootView(Widget* widget) 34 RootView::RootView(Widget* widget)
33 : widget_(widget), 35 : widget_(widget),
34 mouse_pressed_handler_(NULL), 36 mouse_pressed_handler_(NULL),
35 mouse_move_handler_(NULL), 37 mouse_move_handler_(NULL),
36 last_click_handler_(NULL), 38 last_click_handler_(NULL),
37 explicit_mouse_handler_(false), 39 explicit_mouse_handler_(false),
38 last_mouse_event_flags_(0), 40 last_mouse_event_flags_(0),
39 last_mouse_event_x_(-1), 41 last_mouse_event_x_(-1),
40 last_mouse_event_y_(-1), 42 last_mouse_event_y_(-1),
41 gesture_manager_(GestureManager::GetInstance()), 43 gesture_manager_(NULL),
42 touch_pressed_handler_(NULL), 44 touch_pressed_handler_(NULL),
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) {
49 // TODO(Gajen): Refactor gesture recognizer integration with new approach
50 // proposed in http://codereview.chromium.org/8364039/.
51 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableGesture))
52 gesture_manager_ = GestureRecognizer::GetInstance();
53 else
54 gesture_manager_ = GestureManager::GetInstance();
46 } 55 }
47 56
48 RootView::~RootView() { 57 RootView::~RootView() {
49 // If we have children remove them explicitly so to make sure a remove 58 // If we have children remove them explicitly so to make sure a remove
50 // notification is sent for each one of them. 59 // notification is sent for each one of them.
51 if (has_children()) 60 if (has_children())
52 RemoveAllChildViews(true); 61 RemoveAllChildViews(true);
53 } 62 }
54 63
55 // Tree operations ------------------------------------------------------------- 64 // Tree operations -------------------------------------------------------------
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 void RootView::SetMouseHandler(View *new_mh) { 402 void RootView::SetMouseHandler(View *new_mh) {
394 // If we're clearing the mouse handler, clear explicit_mouse_handler_ as well. 403 // If we're clearing the mouse handler, clear explicit_mouse_handler_ as well.
395 explicit_mouse_handler_ = (new_mh != NULL); 404 explicit_mouse_handler_ = (new_mh != NULL);
396 mouse_pressed_handler_ = new_mh; 405 mouse_pressed_handler_ = new_mh;
397 } 406 }
398 407
399 void RootView::GetAccessibleState(ui::AccessibleViewState* state) { 408 void RootView::GetAccessibleState(ui::AccessibleViewState* state) {
400 state->role = ui::AccessibilityTypes::ROLE_APPLICATION; 409 state->role = ui::AccessibilityTypes::ROLE_APPLICATION;
401 } 410 }
402 411
412 bool RootView::ForwardGestureEvents(GestureRecognizer::Gestures* gestures) {
413 scoped_ptr<GestureRecognizer::Gestures> events;
414 events.reset(gestures);
415 bool return_value = false;
416 for (unsigned int i = 0; i < events->size(); i++) {
417 GestureEvent* event = gestures->at(i).GetGestureEvent();
418 GestureEvent e(*event, this);
419
420 ui::GestureStatus status = ui::GESTURE_STATUS_UNKNOWN;
421
422 // Walk up the tree until we find a view that wants the gesture event.
423 for (gesture_handling_view_ = GetEventHandlerForPoint(e.location());
424 gesture_handling_view_ && (gesture_handling_view_ != this);
425 gesture_handling_view_ = gesture_handling_view_->parent()) {
426 if (!gesture_handling_view_->IsEnabled()) {
427 // Disabled views eat events but are treated as not handled by the
428 // the GestureManager.
429 status = ui::GESTURE_STATUS_UNKNOWN;
430 break;
431 }
432
433 // See if this view wants to handle the Gesture.
434 GestureEvent gesture_event(e, this, gesture_handling_view_);
435 status = gesture_handling_view_->ProcessGestureEvent(gesture_event);
436
437 // The view could have removed itself from the tree when handling
438 // OnGestureEvent(). So handle as per OnMousePressed. NB: we
439 // assume that the RootView itself cannot be so removed.
440 if (!gesture_handling_view_)
441 break;
442
443 // The gesture event wasn't processed. Go up the view hierarchy and
444 // dispatch the gesture event.
445 if (status == ui::GESTURE_STATUS_UNKNOWN) {
446 continue;
447 } else if (status == ui::GESTURE_STATUS_CONSUMED) {
448 return_value = true;
449 } else {
450 return_value = false;
451 }
452 }
453 if (!return_value) return false;
454 }
455 return return_value;
456 }
457
403 //////////////////////////////////////////////////////////////////////////////// 458 ////////////////////////////////////////////////////////////////////////////////
404 // RootView, protected: 459 // RootView, protected:
405 460
406 void RootView::ViewHierarchyChanged(bool is_add, View* parent, View* child) { 461 void RootView::ViewHierarchyChanged(bool is_add, View* parent, View* child) {
407 widget_->ViewHierarchyChanged(is_add, parent, child); 462 widget_->ViewHierarchyChanged(is_add, parent, child);
408 463
409 if (!is_add) { 464 if (!is_add) {
410 if (!explicit_mouse_handler_ && mouse_pressed_handler_ == child) 465 if (!explicit_mouse_handler_ && mouse_pressed_handler_ == child)
411 mouse_pressed_handler_ = NULL; 466 mouse_pressed_handler_ = NULL;
412 if (mouse_move_handler_ == child) 467 if (mouse_move_handler_ == child)
413 mouse_move_handler_ = NULL; 468 mouse_move_handler_ = NULL;
414 if (touch_pressed_handler_ == child) 469 if (touch_pressed_handler_ == child)
415 touch_pressed_handler_ = NULL; 470 touch_pressed_handler_ = NULL;
471 if (gesture_handling_view_ == child)
472 gesture_handling_view_ = NULL;
416 } 473 }
417 } 474 }
418 475
419 void RootView::OnPaint(gfx::Canvas* canvas) { 476 void RootView::OnPaint(gfx::Canvas* canvas) {
420 if (!layer() || !layer()->fills_bounds_opaquely()) 477 if (!layer() || !layer()->fills_bounds_opaquely())
421 canvas->GetSkCanvas()->drawColor(SK_ColorBLACK, SkXfermode::kClear_Mode); 478 canvas->GetSkCanvas()->drawColor(SK_ColorBLACK, SkXfermode::kClear_Mode);
422 479
423 // TODO (pkotwicz): Remove this once we switch over to Aura desktop. 480 // TODO (pkotwicz): Remove this once we switch over to Aura desktop.
424 // This is needed so that we can set the background behind the RWHV when the 481 // This is needed so that we can set the background behind the RWHV when the
425 // RWHV is not visible. Not needed once there is a view between the RootView 482 // RWHV is not visible. Not needed once there is a view between the RootView
(...skipping 21 matching lines...) Expand all
447 } 504 }
448 505
449 void RootView::SetMouseLocationAndFlags(const MouseEvent& event) { 506 void RootView::SetMouseLocationAndFlags(const MouseEvent& event) {
450 last_mouse_event_flags_ = event.flags(); 507 last_mouse_event_flags_ = event.flags();
451 last_mouse_event_x_ = event.x(); 508 last_mouse_event_x_ = event.x();
452 last_mouse_event_y_ = event.y(); 509 last_mouse_event_y_ = event.y();
453 } 510 }
454 511
455 } // namespace internal 512 } // namespace internal
456 } // namespace views 513 } // namespace views
OLDNEW
« views/view_unittest.cc ('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