Chromium Code Reviews| OLD | NEW |
|---|---|
| 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" | |
| 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 Loading... | |
| 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_handler_(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 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableGesture)) | |
|
rjkroege
2011/11/01 18:42:22
I don't think you want to do it this way.
My pre
Gajen
2011/11/02 12:59:35
Currently is it done same way in GR's PTEFG, where
rjkroege
2011/11/04 17:19:28
Currently, we have the following: RootView::OnTouc
Gajen
2011/11/08 08:11:44
Look promising and Great.
Can we push current impl
| |
| 50 gesture_manager_ = GestureRecognizer::GetInstance(); | |
| 51 else | |
| 52 gesture_manager_ = GestureManager::GetInstance(); | |
| 46 } | 53 } |
| 47 | 54 |
| 48 RootView::~RootView() { | 55 RootView::~RootView() { |
| 49 // If we have children remove them explicitly so to make sure a remove | 56 // If we have children remove them explicitly so to make sure a remove |
| 50 // notification is sent for each one of them. | 57 // notification is sent for each one of them. |
| 51 if (has_children()) | 58 if (has_children()) |
| 52 RemoveAllChildViews(true); | 59 RemoveAllChildViews(true); |
| 53 } | 60 } |
| 54 | 61 |
| 55 // Tree operations ------------------------------------------------------------- | 62 // Tree operations ------------------------------------------------------------- |
| (...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 393 void RootView::SetMouseHandler(View *new_mh) { | 400 void RootView::SetMouseHandler(View *new_mh) { |
| 394 // If we're clearing the mouse handler, clear explicit_mouse_handler_ as well. | 401 // If we're clearing the mouse handler, clear explicit_mouse_handler_ as well. |
| 395 explicit_mouse_handler_ = (new_mh != NULL); | 402 explicit_mouse_handler_ = (new_mh != NULL); |
| 396 mouse_pressed_handler_ = new_mh; | 403 mouse_pressed_handler_ = new_mh; |
| 397 } | 404 } |
| 398 | 405 |
| 399 void RootView::GetAccessibleState(ui::AccessibleViewState* state) { | 406 void RootView::GetAccessibleState(ui::AccessibleViewState* state) { |
| 400 state->role = ui::AccessibilityTypes::ROLE_APPLICATION; | 407 state->role = ui::AccessibilityTypes::ROLE_APPLICATION; |
| 401 } | 408 } |
| 402 | 409 |
| 410 bool RootView::ForwardGestureEvents(GestureRecognizer::Gestures* gestures) { | |
| 411 scoped_ptr<GestureRecognizer::Gestures> events; | |
| 412 events.reset(gestures); | |
| 413 bool return_value = false; | |
| 414 for (unsigned int i = 0; i < events->size(); i++) { | |
| 415 GestureEvent* event = gestures->at(i).GetGestureEvent(); | |
| 416 GestureEvent e(*event, this); | |
| 417 | |
| 418 ui::GestureStatus status = ui::GESTURE_STATUS_UNKNOWN; | |
| 419 | |
| 420 // Walk up the tree until we find a view that wants the gesture event. | |
| 421 for (gesture_handler_ = GetEventHandlerForPoint(e.location()); | |
| 422 gesture_handler_ && (gesture_handler_ != this); | |
| 423 gesture_handler_ = gesture_handler_->parent()) { | |
| 424 if (!gesture_handler_->IsEnabled()) { | |
| 425 // Disabled views eat events but are treated as not handled by the | |
| 426 // the GestureManager. | |
| 427 status = ui::GESTURE_STATUS_UNKNOWN; | |
| 428 break; | |
| 429 } | |
| 430 | |
| 431 // See if this view wants to handle the Gesture. | |
| 432 GestureEvent gesture_event(e, this, gesture_handler_); | |
| 433 status = gesture_handler_->ProcessGestureEvent(gesture_event); | |
|
rjkroege
2011/11/01 18:42:22
see comment about gesture_handler_ -- please renam
Gajen
2011/11/08 08:11:44
Done.
| |
| 434 | |
| 435 // The view could have removed itself from the tree when handling | |
| 436 // OnGestureEvent(). So handle as per OnMousePressed. NB: we | |
| 437 // assume that the RootView itself cannot be so removed. | |
| 438 if (!gesture_handler_) | |
| 439 break; | |
| 440 | |
| 441 // The gesture event wasn't processed. Go up the view hierarchy and | |
| 442 // dispatch the gesture event. | |
| 443 if (status == ui::GESTURE_STATUS_UNKNOWN) { | |
| 444 continue; | |
| 445 } else if (status == ui::GESTURE_STATUS_CONSUMED) { | |
| 446 return_value = true; | |
| 447 } else { | |
| 448 return_value = false; | |
| 449 } | |
| 450 } | |
| 451 if (!return_value) return false; | |
| 452 } | |
| 453 return return_value; | |
| 454 } | |
| 455 | |
| 403 //////////////////////////////////////////////////////////////////////////////// | 456 //////////////////////////////////////////////////////////////////////////////// |
| 404 // RootView, protected: | 457 // RootView, protected: |
| 405 | 458 |
| 406 void RootView::ViewHierarchyChanged(bool is_add, View* parent, View* child) { | 459 void RootView::ViewHierarchyChanged(bool is_add, View* parent, View* child) { |
| 407 widget_->ViewHierarchyChanged(is_add, parent, child); | 460 widget_->ViewHierarchyChanged(is_add, parent, child); |
| 408 | 461 |
| 409 if (!is_add) { | 462 if (!is_add) { |
| 410 if (!explicit_mouse_handler_ && mouse_pressed_handler_ == child) | 463 if (!explicit_mouse_handler_ && mouse_pressed_handler_ == child) |
| 411 mouse_pressed_handler_ = NULL; | 464 mouse_pressed_handler_ = NULL; |
| 412 if (mouse_move_handler_ == child) | 465 if (mouse_move_handler_ == child) |
| 413 mouse_move_handler_ = NULL; | 466 mouse_move_handler_ = NULL; |
| 414 if (touch_pressed_handler_ == child) | 467 if (touch_pressed_handler_ == child) |
| 415 touch_pressed_handler_ = NULL; | 468 touch_pressed_handler_ = NULL; |
| 469 if (gesture_handler_ == child) | |
| 470 gesture_handler_ = NULL; | |
| 416 } | 471 } |
| 417 } | 472 } |
| 418 | 473 |
| 419 void RootView::OnPaint(gfx::Canvas* canvas) { | 474 void RootView::OnPaint(gfx::Canvas* canvas) { |
| 420 #if !defined(TOUCH_UI) | 475 #if !defined(TOUCH_UI) |
| 421 canvas->GetSkCanvas()->drawColor(SK_ColorBLACK, SkXfermode::kClear_Mode); | 476 canvas->GetSkCanvas()->drawColor(SK_ColorBLACK, SkXfermode::kClear_Mode); |
| 422 #endif | 477 #endif |
| 423 | 478 |
| 424 // TODO (pkotwicz): Remove this once we switch over to Aura desktop. | 479 // TODO (pkotwicz): Remove this once we switch over to Aura desktop. |
| 425 // This is needed so that we can set the background behind the RWHV when the | 480 // This is needed so that we can set the background behind the RWHV when the |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 448 } | 503 } |
| 449 | 504 |
| 450 void RootView::SetMouseLocationAndFlags(const MouseEvent& event) { | 505 void RootView::SetMouseLocationAndFlags(const MouseEvent& event) { |
| 451 last_mouse_event_flags_ = event.flags(); | 506 last_mouse_event_flags_ = event.flags(); |
| 452 last_mouse_event_x_ = event.x(); | 507 last_mouse_event_x_ = event.x(); |
| 453 last_mouse_event_y_ = event.y(); | 508 last_mouse_event_y_ = event.y(); |
| 454 } | 509 } |
| 455 | 510 |
| 456 } // namespace internal | 511 } // namespace internal |
| 457 } // namespace views | 512 } // namespace views |
| OLD | NEW |