Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 248 ui::EventTarget* RootView::GetRootTarget() { | 248 ui::EventTarget* RootView::GetRootTarget() { |
| 249 return this; | 249 return this; |
| 250 } | 250 } |
| 251 | 251 |
| 252 ui::EventDispatchDetails RootView::OnEventFromSource(ui::Event* event) { | 252 ui::EventDispatchDetails RootView::OnEventFromSource(ui::Event* event) { |
| 253 // TODO(tdanderson): Replace the calls to Dispatch*Event() with calls to | 253 // TODO(tdanderson): Replace the calls to Dispatch*Event() with calls to |
| 254 // EventProcessor::OnEventFromSource() once the code for | 254 // EventProcessor::OnEventFromSource() once the code for |
| 255 // that event type has been refactored, and then | 255 // that event type has been refactored, and then |
| 256 // eventually remove this function altogether. See | 256 // eventually remove this function altogether. See |
| 257 // crbug.com/348083. | 257 // crbug.com/348083. |
| 258 if (event->IsKeyEvent()) | 258 if (event->IsKeyEvent()) { |
| 259 return EventProcessor::OnEventFromSource(event); | 259 return EventProcessor::OnEventFromSource(event); |
| 260 else if (event->IsScrollEvent()) | 260 } else if (event->IsScrollEvent()) { |
| 261 return EventProcessor::OnEventFromSource(event); | 261 return EventProcessor::OnEventFromSource(event); |
| 262 else if (event->IsTouchEvent()) | 262 } else if (event->IsTouchEvent()) { |
| 263 NOTREACHED() << "Touch events should not be sent to RootView."; | 263 NOTREACHED() << "Touch events should not be sent to RootView."; |
| 264 else if (event->IsGestureEvent()) | 264 } else if (event->IsGestureEvent()) { |
| 265 // Ignore subsequent gesture scroll events if no handler was set for a | |
| 266 // ui::ET_GESTURE_SCROLL_BEGIN event. | |
| 267 if (!gesture_handler_ && | |
| 268 (event->type() == ui::ET_GESTURE_SCROLL_UPDATE || | |
| 269 event->type() == ui::ET_GESTURE_SCROLL_END || | |
| 270 event->type() == ui::ET_SCROLL_FLING_START)) { | |
| 271 return DispatchDetails(); | |
| 272 } | |
| 273 | |
| 265 DispatchGestureEvent(event->AsGestureEvent()); | 274 DispatchGestureEvent(event->AsGestureEvent()); |
| 266 else if (event->IsMouseEvent()) | 275 } else if (event->IsMouseEvent()) { |
| 267 NOTREACHED() << "Should not be called with a MouseEvent."; | 276 NOTREACHED() << "Should not be called with a MouseEvent."; |
| 268 else | 277 } else { |
| 269 NOTREACHED() << "Invalid event type."; | 278 NOTREACHED() << "Invalid event type."; |
| 279 } | |
|
sadrul
2014/07/21 06:40:30
Let's get rid of the elses in this block:
if (ke
tdanderson
2014/07/21 14:27:40
Done.
| |
| 270 | 280 |
| 271 return DispatchDetails(); | 281 return DispatchDetails(); |
| 272 } | 282 } |
| 273 | 283 |
| 274 //////////////////////////////////////////////////////////////////////////////// | 284 //////////////////////////////////////////////////////////////////////////////// |
| 275 // RootView, View overrides: | 285 // RootView, View overrides: |
| 276 | 286 |
| 277 const Widget* RootView::GetWidget() const { | 287 const Widget* RootView::GetWidget() const { |
| 278 return widget_; | 288 return widget_; |
| 279 } | 289 } |
| (...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 675 dispatch_details.target_destroyed) { | 685 dispatch_details.target_destroyed) { |
| 676 return; | 686 return; |
| 677 } | 687 } |
| 678 } | 688 } |
| 679 scroll_gesture_handler_ = NULL; | 689 scroll_gesture_handler_ = NULL; |
| 680 } | 690 } |
| 681 | 691 |
| 682 return; | 692 return; |
| 683 } | 693 } |
| 684 | 694 |
| 685 // If there was no handler for a SCROLL_BEGIN event, then subsequent scroll | |
| 686 // events are not dispatched to any views. | |
| 687 switch (event->type()) { | |
| 688 case ui::ET_GESTURE_SCROLL_UPDATE: | |
| 689 case ui::ET_GESTURE_SCROLL_END: | |
| 690 case ui::ET_SCROLL_FLING_START: | |
| 691 return; | |
| 692 default: | |
| 693 break; | |
| 694 } | |
| 695 | |
| 696 View* gesture_handler = NULL; | 695 View* gesture_handler = NULL; |
| 697 if (views::switches::IsRectBasedTargetingEnabled() && | 696 if (views::switches::IsRectBasedTargetingEnabled() && |
| 698 !event->details().bounding_box().IsEmpty()) { | 697 !event->details().bounding_box().IsEmpty()) { |
| 699 // TODO(tdanderson): Pass in the bounding box to GetEventHandlerForRect() | 698 // TODO(tdanderson): Pass in the bounding box to GetEventHandlerForRect() |
| 700 // once crbug.com/313392 is resolved. | 699 // once crbug.com/313392 is resolved. |
| 701 gfx::Rect touch_rect(event->details().bounding_box()); | 700 gfx::Rect touch_rect(event->details().bounding_box()); |
| 702 touch_rect.set_origin(event->location()); | 701 touch_rect.set_origin(event->location()); |
| 703 touch_rect.Offset(-touch_rect.width() / 2, -touch_rect.height() / 2); | 702 touch_rect.Offset(-touch_rect.width() / 2, -touch_rect.height() / 2); |
| 704 gesture_handler = GetEventHandlerForRect(touch_rect); | 703 gesture_handler = GetEventHandlerForRect(touch_rect); |
| 705 } else { | 704 } else { |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 808 | 807 |
| 809 #ifndef NDEBUG | 808 #ifndef NDEBUG |
| 810 DCHECK(!event_dispatch_target_ || Contains(event_dispatch_target_)); | 809 DCHECK(!event_dispatch_target_ || Contains(event_dispatch_target_)); |
| 811 #endif | 810 #endif |
| 812 | 811 |
| 813 return details; | 812 return details; |
| 814 } | 813 } |
| 815 | 814 |
| 816 } // namespace internal | 815 } // namespace internal |
| 817 } // namespace views | 816 } // namespace views |
| OLD | NEW |