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

Side by Side Diff: ui/aura/root_window.cc

Issue 113283005: aura: Start using EventPrcessor interface for event dispatch. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years 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/aura/root_window.h ('k') | ui/aura/root_window_unittest.cc » ('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/aura/root_window.h" 5 #include "ui/aura/root_window.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 } 83 }
84 84
85 RootWindowHost* CreateHost(RootWindow* root_window, 85 RootWindowHost* CreateHost(RootWindow* root_window,
86 const RootWindow::CreateParams& params) { 86 const RootWindow::CreateParams& params) {
87 RootWindowHost* host = params.host ? 87 RootWindowHost* host = params.host ?
88 params.host : RootWindowHost::Create(params.initial_bounds); 88 params.host : RootWindowHost::Create(params.initial_bounds);
89 host->set_delegate(root_window); 89 host->set_delegate(root_window);
90 return host; 90 return host;
91 } 91 }
92 92
93 bool IsUsingEventProcessorForDispatch(const ui::Event& event) {
94 return event.IsKeyEvent() ||
95 event.IsScrollEvent();
96 }
97
93 class SimpleRootWindowTransformer : public RootWindowTransformer { 98 class SimpleRootWindowTransformer : public RootWindowTransformer {
94 public: 99 public:
95 SimpleRootWindowTransformer(const Window* root_window, 100 SimpleRootWindowTransformer(const Window* root_window,
96 const gfx::Transform& transform) 101 const gfx::Transform& transform)
97 : root_window_(root_window), 102 : root_window_(root_window),
98 transform_(transform) { 103 transform_(transform) {
99 } 104 }
100 105
101 // RootWindowTransformer overrides: 106 // RootWindowTransformer overrides:
102 virtual gfx::Transform GetTransform() const OVERRIDE { 107 virtual gfx::Transform GetTransform() const OVERRIDE {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 : window_(new Window(NULL)), 150 : window_(new Window(NULL)),
146 host_(CreateHost(this, params)), 151 host_(CreateHost(this, params)),
147 touch_ids_down_(0), 152 touch_ids_down_(0),
148 last_cursor_(ui::kCursorNull), 153 last_cursor_(ui::kCursorNull),
149 mouse_pressed_handler_(NULL), 154 mouse_pressed_handler_(NULL),
150 mouse_moved_handler_(NULL), 155 mouse_moved_handler_(NULL),
151 event_dispatch_target_(NULL), 156 event_dispatch_target_(NULL),
152 old_dispatch_target_(NULL), 157 old_dispatch_target_(NULL),
153 synthesize_mouse_move_(false), 158 synthesize_mouse_move_(false),
154 move_hold_count_(0), 159 move_hold_count_(0),
160 dispatching_held_event_(false),
155 repost_event_factory_(this), 161 repost_event_factory_(this),
156 held_event_factory_(this) { 162 held_event_factory_(this) {
157 window()->set_dispatcher(this); 163 window()->set_dispatcher(this);
158 window()->SetName("RootWindow"); 164 window()->SetName("RootWindow");
159 window()->set_event_targeter( 165 window()->set_event_targeter(
160 scoped_ptr<ui::EventTargeter>(new WindowTargeter())); 166 scoped_ptr<ui::EventTargeter>(new WindowTargeter()));
161 167
162 compositor_.reset(new ui::Compositor(host_->GetAcceleratedWidget())); 168 compositor_.reset(new ui::Compositor(host_->GetAcceleratedWidget()));
163 DCHECK(compositor_.get()); 169 DCHECK(compositor_.get());
164 170
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 // We allow for only one outstanding repostable event. This is used 230 // We allow for only one outstanding repostable event. This is used
225 // in exiting context menus. A dropped repost request is allowed. 231 // in exiting context menus. A dropped repost request is allowed.
226 if (event.type() == ui::ET_MOUSE_PRESSED) { 232 if (event.type() == ui::ET_MOUSE_PRESSED) {
227 held_repostable_event_.reset( 233 held_repostable_event_.reset(
228 new ui::MouseEvent( 234 new ui::MouseEvent(
229 static_cast<const ui::MouseEvent&>(event), 235 static_cast<const ui::MouseEvent&>(event),
230 static_cast<aura::Window*>(event.target()), 236 static_cast<aura::Window*>(event.target()),
231 window())); 237 window()));
232 base::MessageLoop::current()->PostTask( 238 base::MessageLoop::current()->PostTask(
233 FROM_HERE, 239 FROM_HERE,
234 base::Bind(&RootWindow::DispatchHeldEventsAsync, 240 base::Bind(base::IgnoreResult(&RootWindow::DispatchHeldEvents),
235 repost_event_factory_.GetWeakPtr())); 241 repost_event_factory_.GetWeakPtr()));
236 } else { 242 } else {
237 DCHECK(event.type() == ui::ET_GESTURE_TAP_DOWN); 243 DCHECK(event.type() == ui::ET_GESTURE_TAP_DOWN);
238 held_repostable_event_.reset(); 244 held_repostable_event_.reset();
239 // TODO(rbyers): Reposing of gestures is tricky to get 245 // TODO(rbyers): Reposing of gestures is tricky to get
240 // right, so it's not yet supported. crbug.com/170987. 246 // right, so it's not yet supported. crbug.com/170987.
241 } 247 }
242 } 248 }
243 249
244 RootWindowHostDelegate* RootWindow::AsRootWindowHostDelegate() { 250 RootWindowHostDelegate* RootWindow::AsRootWindowHostDelegate() {
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 void RootWindow::ReleasePointerMoves() { 454 void RootWindow::ReleasePointerMoves() {
449 --move_hold_count_; 455 --move_hold_count_;
450 DCHECK_GE(move_hold_count_, 0); 456 DCHECK_GE(move_hold_count_, 0);
451 if (!move_hold_count_ && held_move_event_) { 457 if (!move_hold_count_ && held_move_event_) {
452 // We don't want to call DispatchHeldEvents directly, because this might be 458 // We don't want to call DispatchHeldEvents directly, because this might be
453 // called from a deep stack while another event, in which case dispatching 459 // called from a deep stack while another event, in which case dispatching
454 // another one may not be safe/expected. Instead we post a task, that we 460 // another one may not be safe/expected. Instead we post a task, that we
455 // may cancel if HoldPointerMoves is called again before it executes. 461 // may cancel if HoldPointerMoves is called again before it executes.
456 base::MessageLoop::current()->PostTask( 462 base::MessageLoop::current()->PostTask(
457 FROM_HERE, 463 FROM_HERE,
458 base::Bind(&RootWindow::DispatchHeldEventsAsync, 464 base::Bind(base::IgnoreResult(&RootWindow::DispatchHeldEvents),
459 held_event_factory_.GetWeakPtr())); 465 held_event_factory_.GetWeakPtr()));
460 } 466 }
461 TRACE_EVENT_ASYNC_END0("ui", "RootWindow::HoldPointerMoves", this); 467 TRACE_EVENT_ASYNC_END0("ui", "RootWindow::HoldPointerMoves", this);
462 } 468 }
463 469
464 gfx::Point RootWindow::GetLastMouseLocationInRoot() const { 470 gfx::Point RootWindow::GetLastMouseLocationInRoot() const {
465 gfx::Point location = Env::GetInstance()->last_mouse_location(); 471 gfx::Point location = Env::GetInstance()->last_mouse_location();
466 client::ScreenPositionClient* client = 472 client::ScreenPositionClient* client =
467 client::GetScreenPositionClient(window()); 473 client::GetScreenPositionClient(window());
468 if (client) 474 if (client)
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
574 // crbug.com/157583 580 // crbug.com/157583
575 if (reason != WINDOW_MOVING) { 581 if (reason != WINDOW_MOVING) {
576 Window* capture_window = aura::client::GetCaptureWindow(window()); 582 Window* capture_window = aura::client::GetCaptureWindow(window());
577 // If the ancestor of the capture window is hidden, 583 // If the ancestor of the capture window is hidden,
578 // release the capture. 584 // release the capture.
579 if (invisible->Contains(capture_window) && invisible != window()) 585 if (invisible->Contains(capture_window) && invisible != window())
580 capture_window->ReleaseCapture(); 586 capture_window->ReleaseCapture();
581 587
582 if (invisible->Contains(event_dispatch_target_)) 588 if (invisible->Contains(event_dispatch_target_))
583 event_dispatch_target_ = NULL; 589 event_dispatch_target_ = NULL;
590
591 if (invisible->Contains(old_dispatch_target_))
592 old_dispatch_target_ = NULL;
584 } 593 }
585 594
586 // If the ancestor of any event handler windows are invisible, release the 595 // If the ancestor of any event handler windows are invisible, release the
587 // pointer to those windows. 596 // pointer to those windows.
588 if (invisible->Contains(mouse_pressed_handler_)) 597 if (invisible->Contains(mouse_pressed_handler_))
589 mouse_pressed_handler_ = NULL; 598 mouse_pressed_handler_ = NULL;
590 if (invisible->Contains(mouse_moved_handler_)) 599 if (invisible->Contains(mouse_moved_handler_))
591 mouse_moved_handler_ = NULL; 600 mouse_moved_handler_ = NULL;
592 601
593 CleanupGestureState(invisible); 602 CleanupGestureState(invisible);
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
658 void RootWindow::ReleaseNativeCapture() { 667 void RootWindow::ReleaseNativeCapture() {
659 host_->ReleaseCapture(); 668 host_->ReleaseCapture();
660 } 669 }
661 670
662 //////////////////////////////////////////////////////////////////////////////// 671 ////////////////////////////////////////////////////////////////////////////////
663 // RootWindow, ui::EventProcessor implementation: 672 // RootWindow, ui::EventProcessor implementation:
664 ui::EventTarget* RootWindow::GetRootTarget() { 673 ui::EventTarget* RootWindow::GetRootTarget() {
665 return window(); 674 return window();
666 } 675 }
667 676
677 void RootWindow::PrepareEventForDispatch(ui::Event* event) {
678 if (event->IsMouseEvent() ||
679 event->IsScrollEvent() ||
680 event->IsTouchEvent() ||
681 event->IsGestureEvent()) {
682 TransformEventForDeviceScaleFactor(static_cast<ui::LocatedEvent*>(event));
683 }
684 }
685
668 //////////////////////////////////////////////////////////////////////////////// 686 ////////////////////////////////////////////////////////////////////////////////
669 // RootWindow, ui::EventDispatcherDelegate implementation: 687 // RootWindow, ui::EventDispatcherDelegate implementation:
670 688
671 bool RootWindow::CanDispatchToTarget(ui::EventTarget* target) { 689 bool RootWindow::CanDispatchToTarget(ui::EventTarget* target) {
672 return event_dispatch_target_ == target; 690 return event_dispatch_target_ == target;
673 } 691 }
674 692
675 ui::EventDispatchDetails RootWindow::PreDispatchEvent(ui::EventTarget* target, 693 ui::EventDispatchDetails RootWindow::PreDispatchEvent(ui::EventTarget* target,
676 ui::Event* event) { 694 ui::Event* event) {
695 if (!dispatching_held_event_ && IsUsingEventProcessorForDispatch(*event)) {
696 DispatchDetails details = DispatchHeldEvents();
697 if (details.dispatcher_destroyed || details.target_destroyed)
698 return details;
699
700 Window* target_window = static_cast<Window*>(target);
701 if (event->IsScrollEvent()) {
702 PreDispatchLocatedEvent(target_window,
703 static_cast<ui::ScrollEvent*>(event));
704 }
705 }
677 old_dispatch_target_ = event_dispatch_target_; 706 old_dispatch_target_ = event_dispatch_target_;
678 event_dispatch_target_ = static_cast<Window*>(target); 707 event_dispatch_target_ = static_cast<Window*>(target);
679 return DispatchDetails(); 708 return DispatchDetails();
680 } 709 }
681 710
682 ui::EventDispatchDetails RootWindow::PostDispatchEvent(ui::EventTarget* target, 711 ui::EventDispatchDetails RootWindow::PostDispatchEvent(ui::EventTarget* target,
683 const ui::Event& event) { 712 const ui::Event& event) {
684 DispatchDetails details; 713 DispatchDetails details;
685 if (target != event_dispatch_target_) 714 if (target != event_dispatch_target_)
686 details.target_destroyed = true; 715 details.target_destroyed = true;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
721 } 750 }
722 751
723 void RootWindow::OnLayerAnimationAborted( 752 void RootWindow::OnLayerAnimationAborted(
724 ui::LayerAnimationSequence* animation) { 753 ui::LayerAnimationSequence* animation) {
725 } 754 }
726 755
727 //////////////////////////////////////////////////////////////////////////////// 756 ////////////////////////////////////////////////////////////////////////////////
728 // RootWindow, RootWindowHostDelegate implementation: 757 // RootWindow, RootWindowHostDelegate implementation:
729 758
730 bool RootWindow::OnHostKeyEvent(ui::KeyEvent* event) { 759 bool RootWindow::OnHostKeyEvent(ui::KeyEvent* event) {
731 DispatchDetails details = DispatchHeldEvents(); 760 DispatchDetails details = OnEventFromSource(event);
732 if (details.dispatcher_destroyed) 761 if (details.dispatcher_destroyed)
733 return false; 762 event->SetHandled();
734 if (event->key_code() == ui::VKEY_UNKNOWN)
735 return false;
736 client::EventClient* client = client::GetEventClient(window());
737 Window* focused_window = client::GetFocusClient(window())->GetFocusedWindow();
738 if (client && !client->CanProcessEventsWithinSubtree(focused_window)) {
739 client::GetFocusClient(window())->FocusWindow(NULL);
740 return false;
741 }
742 details = DispatchEvent(focused_window ? focused_window : window(), event);
743 if (details.dispatcher_destroyed)
744 return true;
745 return event->handled(); 763 return event->handled();
746 } 764 }
747 765
748 bool RootWindow::OnHostMouseEvent(ui::MouseEvent* event) { 766 bool RootWindow::OnHostMouseEvent(ui::MouseEvent* event) {
749 DispatchDetails details = OnHostMouseEventImpl(event); 767 DispatchDetails details = OnHostMouseEventImpl(event);
750 return event->handled() || details.dispatcher_destroyed; 768 return event->handled() || details.dispatcher_destroyed;
751 } 769 }
752 770
753 bool RootWindow::OnHostScrollEvent(ui::ScrollEvent* event) { 771 bool RootWindow::OnHostScrollEvent(ui::ScrollEvent* event) {
754 DispatchDetails details = DispatchHeldEvents(); 772 DispatchDetails details = OnEventFromSource(event);
755 if (details.dispatcher_destroyed) 773 if (details.dispatcher_destroyed)
756 return false; 774 event->SetHandled();
757
758 TransformEventForDeviceScaleFactor(event);
759 SetLastMouseLocation(window(), event->location());
760 synthesize_mouse_move_ = false;
761
762 Window* target = mouse_pressed_handler_ ?
763 mouse_pressed_handler_ : client::GetCaptureWindow(window());
764
765 if (!target)
766 target = window()->GetEventHandlerForPoint(event->location());
767
768 if (!target)
769 target = window();
770
771 event->ConvertLocationToTarget(window(), target);
772 int flags = event->flags();
773 if (IsNonClientLocation(target, event->location()))
774 flags |= ui::EF_IS_NON_CLIENT;
775 event->set_flags(flags);
776
777 details = DispatchEvent(target, event);
778 if (details.dispatcher_destroyed)
779 return true;
780 return event->handled(); 775 return event->handled();
781 } 776 }
782 777
783 bool RootWindow::OnHostTouchEvent(ui::TouchEvent* event) { 778 bool RootWindow::OnHostTouchEvent(ui::TouchEvent* event) {
784 if ((event->type() == ui::ET_TOUCH_MOVED)) { 779 if ((event->type() == ui::ET_TOUCH_MOVED)) {
785 if (move_hold_count_) { 780 if (move_hold_count_) {
786 Window* null_window = static_cast<Window*>(NULL); 781 Window* null_window = static_cast<Window*>(NULL);
787 held_move_event_.reset( 782 held_move_event_.reset(
788 new ui::TouchEvent(*event, null_window, null_window)); 783 new ui::TouchEvent(*event, null_window, null_window));
789 return true; 784 return true;
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
1072 1067
1073 // Get the list of GestureEvents from GestureRecognizer. 1068 // Get the list of GestureEvents from GestureRecognizer.
1074 scoped_ptr<ui::GestureRecognizer::Gestures> gestures; 1069 scoped_ptr<ui::GestureRecognizer::Gestures> gestures;
1075 gestures.reset(ui::GestureRecognizer::Get()-> 1070 gestures.reset(ui::GestureRecognizer::Get()->
1076 ProcessTouchEventForGesture(event_for_gr, result, target)); 1071 ProcessTouchEventForGesture(event_for_gr, result, target));
1077 1072
1078 return ProcessGestures(gestures.get()); 1073 return ProcessGestures(gestures.get());
1079 } 1074 }
1080 1075
1081 ui::EventDispatchDetails RootWindow::DispatchHeldEvents() { 1076 ui::EventDispatchDetails RootWindow::DispatchHeldEvents() {
1077 CHECK(!dispatching_held_event_);
1078 dispatching_held_event_ = true;
1079
1082 DispatchDetails dispatch_details; 1080 DispatchDetails dispatch_details;
1083 if (held_repostable_event_) { 1081 if (held_repostable_event_) {
1084 if (held_repostable_event_->type() == ui::ET_MOUSE_PRESSED) { 1082 if (held_repostable_event_->type() == ui::ET_MOUSE_PRESSED) {
1085 scoped_ptr<ui::MouseEvent> mouse_event( 1083 scoped_ptr<ui::MouseEvent> mouse_event(
1086 static_cast<ui::MouseEvent*>(held_repostable_event_.release())); 1084 static_cast<ui::MouseEvent*>(held_repostable_event_.release()));
1087 dispatch_details = DispatchMouseEventRepost(mouse_event.get()); 1085 dispatch_details = DispatchMouseEventRepost(mouse_event.get());
1088 } else { 1086 } else {
1089 // TODO(rbyers): GESTURE_TAP_DOWN not yet supported: crbug.com/170987. 1087 // TODO(rbyers): GESTURE_TAP_DOWN not yet supported: crbug.com/170987.
1090 NOTREACHED(); 1088 NOTREACHED();
1091 } 1089 }
1092 if (dispatch_details.dispatcher_destroyed) 1090 if (dispatch_details.dispatcher_destroyed)
1093 return dispatch_details; 1091 return dispatch_details;
1094 } 1092 }
1095 1093
1096 if (held_move_event_ && held_move_event_->IsMouseEvent()) { 1094 if (held_move_event_ && held_move_event_->IsMouseEvent()) {
1097 // If a mouse move has been synthesized, the target location is suspect, 1095 // If a mouse move has been synthesized, the target location is suspect,
1098 // so drop the held event. 1096 // so drop the held event.
1099 if (!synthesize_mouse_move_) 1097 if (!synthesize_mouse_move_) {
1100 dispatch_details = DispatchMouseEventImpl( 1098 dispatch_details = DispatchMouseEventImpl(
1101 static_cast<ui::MouseEvent*>(held_move_event_.get())); 1099 static_cast<ui::MouseEvent*>(held_move_event_.get()));
1100 }
1102 if (!dispatch_details.dispatcher_destroyed) 1101 if (!dispatch_details.dispatcher_destroyed)
1103 held_move_event_.reset(); 1102 held_move_event_.reset();
1104 } else if (held_move_event_ && held_move_event_->IsTouchEvent()) { 1103 } else if (held_move_event_ && held_move_event_->IsTouchEvent()) {
1105 dispatch_details = DispatchTouchEventImpl( 1104 dispatch_details = DispatchTouchEventImpl(
1106 static_cast<ui::TouchEvent*>(held_move_event_.get())); 1105 static_cast<ui::TouchEvent*>(held_move_event_.get()));
1107 if (!dispatch_details.dispatcher_destroyed) 1106 if (!dispatch_details.dispatcher_destroyed)
1108 held_move_event_.reset(); 1107 held_move_event_.reset();
1109 } 1108 }
1110 1109
1110 if (!dispatch_details.dispatcher_destroyed)
1111 dispatching_held_event_ = false;
1111 return dispatch_details; 1112 return dispatch_details;
1112 } 1113 }
1113 1114
1114 void RootWindow::DispatchHeldEventsAsync() {
1115 DispatchDetails details = DispatchHeldEvents();
1116 if (details.dispatcher_destroyed)
1117 return;
1118 }
1119
1120 void RootWindow::PostMouseMoveEventAfterWindowChange() { 1115 void RootWindow::PostMouseMoveEventAfterWindowChange() {
1121 if (synthesize_mouse_move_) 1116 if (synthesize_mouse_move_)
1122 return; 1117 return;
1123 synthesize_mouse_move_ = true; 1118 synthesize_mouse_move_ = true;
1124 base::MessageLoop::current()->PostTask( 1119 base::MessageLoop::current()->PostTask(
1125 FROM_HERE, 1120 FROM_HERE,
1126 base::Bind(&RootWindow::SynthesizeMouseMoveEventAsync, 1121 base::Bind(&RootWindow::SynthesizeMouseMoveEventAsync,
1127 held_event_factory_.GetWeakPtr())); 1122 held_event_factory_.GetWeakPtr()));
1128 } 1123 }
1129 1124
(...skipping 21 matching lines...) Expand all
1151 return; 1146 return;
1152 } 1147 }
1153 1148
1154 gfx::Transform RootWindow::GetInverseRootTransform() const { 1149 gfx::Transform RootWindow::GetInverseRootTransform() const {
1155 float scale = ui::GetDeviceScaleFactor(window()->layer()); 1150 float scale = ui::GetDeviceScaleFactor(window()->layer());
1156 gfx::Transform transform; 1151 gfx::Transform transform;
1157 transform.Scale(1.0f / scale, 1.0f / scale); 1152 transform.Scale(1.0f / scale, 1.0f / scale);
1158 return transformer_->GetInverseTransform() * transform; 1153 return transformer_->GetInverseTransform() * transform;
1159 } 1154 }
1160 1155
1156 void RootWindow::PreDispatchLocatedEvent(Window* target,
1157 ui::LocatedEvent* event) {
1158 int flags = event->flags();
1159 if (IsNonClientLocation(target, event->location()))
1160 flags |= ui::EF_IS_NON_CLIENT;
1161 event->set_flags(flags);
1162
1163 if (!dispatching_held_event_) {
1164 SetLastMouseLocation(window(), event->location());
1165 synthesize_mouse_move_ = false;
1166 }
1167 }
1168
1161 } // namespace aura 1169 } // namespace aura
OLDNEW
« no previous file with comments | « ui/aura/root_window.h ('k') | ui/aura/root_window_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698