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

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

Issue 2025843003: Introduce aura::Env controller to abstract away changes to aura::Env Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add new files to gyp build Created 4 years, 6 months 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
« no previous file with comments | « ui/aura/window_event_dispatcher.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/window_event_dispatcher.h" 5 #include "ui/aura/window_event_dispatcher.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/threading/thread_task_runner_handle.h" 11 #include "base/threading/thread_task_runner_handle.h"
12 #include "base/trace_event/trace_event.h" 12 #include "base/trace_event/trace_event.h"
13 #include "build/build_config.h" 13 #include "build/build_config.h"
14 #include "ui/aura/client/capture_client.h" 14 #include "ui/aura/client/capture_client.h"
15 #include "ui/aura/client/cursor_client.h" 15 #include "ui/aura/client/cursor_client.h"
16 #include "ui/aura/client/event_client.h" 16 #include "ui/aura/client/event_client.h"
17 #include "ui/aura/client/focus_client.h" 17 #include "ui/aura/client/focus_client.h"
18 #include "ui/aura/client/screen_position_client.h" 18 #include "ui/aura/client/screen_position_client.h"
19 #include "ui/aura/env.h" 19 #include "ui/aura/env.h"
20 #include "ui/aura/env_input_state_controller.h"
20 #include "ui/aura/window.h" 21 #include "ui/aura/window.h"
21 #include "ui/aura/window_delegate.h" 22 #include "ui/aura/window_delegate.h"
22 #include "ui/aura/window_targeter.h" 23 #include "ui/aura/window_targeter.h"
23 #include "ui/aura/window_tracker.h" 24 #include "ui/aura/window_tracker.h"
24 #include "ui/aura/window_tree_host.h" 25 #include "ui/aura/window_tree_host.h"
25 #include "ui/base/hit_test.h" 26 #include "ui/base/hit_test.h"
26 #include "ui/compositor/dip_util.h" 27 #include "ui/compositor/dip_util.h"
27 #include "ui/events/event.h" 28 #include "ui/events/event.h"
28 #include "ui/events/event_utils.h" 29 #include "ui/events/event_utils.h"
29 #include "ui/events/gestures/gesture_recognizer.h" 30 #include "ui/events/gestures/gesture_recognizer.h"
(...skipping 11 matching lines...) Expand all
41 if (!target->delegate()) 42 if (!target->delegate())
42 return false; 43 return false;
43 int hit_test_code = target->delegate()->GetNonClientComponent(location); 44 int hit_test_code = target->delegate()->GetNonClientComponent(location);
44 return hit_test_code != HTCLIENT && hit_test_code != HTNOWHERE; 45 return hit_test_code != HTCLIENT && hit_test_code != HTNOWHERE;
45 } 46 }
46 47
47 Window* ConsumerToWindow(ui::GestureConsumer* consumer) { 48 Window* ConsumerToWindow(ui::GestureConsumer* consumer) {
48 return consumer ? static_cast<Window*>(consumer) : NULL; 49 return consumer ? static_cast<Window*>(consumer) : NULL;
49 } 50 }
50 51
51 void SetLastMouseLocation(const Window* root_window,
52 const gfx::Point& location_in_root) {
53 client::ScreenPositionClient* client =
54 client::GetScreenPositionClient(root_window);
55 if (client) {
56 gfx::Point location_in_screen = location_in_root;
57 client->ConvertPointToScreen(root_window, &location_in_screen);
58 Env::GetInstance()->set_last_mouse_location(location_in_screen);
59 } else {
60 Env::GetInstance()->set_last_mouse_location(location_in_root);
61 }
62 }
63
64 bool IsEventCandidateForHold(const ui::Event& event) { 52 bool IsEventCandidateForHold(const ui::Event& event) {
65 if (event.type() == ui::ET_TOUCH_MOVED) 53 if (event.type() == ui::ET_TOUCH_MOVED)
66 return true; 54 return true;
67 if (event.type() == ui::ET_MOUSE_DRAGGED) 55 if (event.type() == ui::ET_MOUSE_DRAGGED)
68 return true; 56 return true;
69 if (event.IsMouseEvent() && (event.flags() & ui::EF_IS_SYNTHESIZED)) 57 if (event.IsMouseEvent() && (event.flags() & ui::EF_IS_SYNTHESIZED))
70 return true; 58 return true;
71 return false; 59 return false;
72 } 60 }
73 61
74 } // namespace 62 } // namespace
75 63
76 //////////////////////////////////////////////////////////////////////////////// 64 ////////////////////////////////////////////////////////////////////////////////
77 // WindowEventDispatcher, public: 65 // WindowEventDispatcher, public:
78 66
79 WindowEventDispatcher::WindowEventDispatcher(WindowTreeHost* host) 67 WindowEventDispatcher::WindowEventDispatcher(WindowTreeHost* host)
80 : host_(host), 68 : host_(host),
81 touch_ids_down_(0), 69 touch_ids_down_(0),
82 mouse_pressed_handler_(NULL), 70 mouse_pressed_handler_(NULL),
83 mouse_moved_handler_(NULL), 71 mouse_moved_handler_(NULL),
84 event_dispatch_target_(NULL), 72 event_dispatch_target_(NULL),
85 old_dispatch_target_(NULL), 73 old_dispatch_target_(NULL),
86 synthesize_mouse_move_(false), 74 synthesize_mouse_move_(false),
87 move_hold_count_(0), 75 move_hold_count_(0),
88 dispatching_held_event_(nullptr), 76 dispatching_held_event_(nullptr),
89 observer_manager_(this), 77 observer_manager_(this),
90 transform_events_(true), 78 transform_events_(true),
79 env_controller_(new EnvInputStateController),
91 repost_event_factory_(this), 80 repost_event_factory_(this),
92 held_event_factory_(this) { 81 held_event_factory_(this) {
93 ui::GestureRecognizer::Get()->AddGestureEventHelper(this); 82 ui::GestureRecognizer::Get()->AddGestureEventHelper(this);
94 Env::GetInstance()->AddObserver(this); 83 Env::GetInstance()->AddObserver(this);
95 } 84 }
96 85
97 WindowEventDispatcher::~WindowEventDispatcher() { 86 WindowEventDispatcher::~WindowEventDispatcher() {
98 TRACE_EVENT0("shutdown", "WindowEventDispatcher::Destructor"); 87 TRACE_EVENT0("shutdown", "WindowEventDispatcher::Destructor");
99 Env::GetInstance()->RemoveObserver(this); 88 Env::GetInstance()->RemoveObserver(this);
100 ui::GestureRecognizer::Get()->RemoveGestureEventHelper(this); 89 ui::GestureRecognizer::Get()->RemoveGestureEventHelper(this);
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 // may cancel if HoldPointerMoves is called again before it executes. 186 // may cancel if HoldPointerMoves is called again before it executes.
198 base::ThreadTaskRunnerHandle::Get()->PostNonNestableTask( 187 base::ThreadTaskRunnerHandle::Get()->PostNonNestableTask(
199 FROM_HERE, base::Bind( 188 FROM_HERE, base::Bind(
200 base::IgnoreResult(&WindowEventDispatcher::DispatchHeldEvents), 189 base::IgnoreResult(&WindowEventDispatcher::DispatchHeldEvents),
201 held_event_factory_.GetWeakPtr())); 190 held_event_factory_.GetWeakPtr()));
202 } 191 }
203 TRACE_EVENT_ASYNC_END0("ui", "WindowEventDispatcher::HoldPointerMoves", this); 192 TRACE_EVENT_ASYNC_END0("ui", "WindowEventDispatcher::HoldPointerMoves", this);
204 } 193 }
205 194
206 gfx::Point WindowEventDispatcher::GetLastMouseLocationInRoot() const { 195 gfx::Point WindowEventDispatcher::GetLastMouseLocationInRoot() const {
207 gfx::Point location = Env::GetInstance()->last_mouse_location(); 196 return env_controller_->GetLastMouseLocationInRoot(window());
208 client::ScreenPositionClient* client =
209 client::GetScreenPositionClient(window());
210 if (client)
211 client->ConvertPointFromScreen(window(), &location);
212 return location;
213 } 197 }
sadrul 2016/05/31 18:27:02 Let's keep this here, and remove that from env_con
214 198
215 void WindowEventDispatcher::OnHostLostMouseGrab() { 199 void WindowEventDispatcher::OnHostLostMouseGrab() {
216 mouse_pressed_handler_ = NULL; 200 mouse_pressed_handler_ = NULL;
217 mouse_moved_handler_ = NULL; 201 mouse_moved_handler_ = NULL;
218 } 202 }
219 203
220 void WindowEventDispatcher::OnCursorMovedToRootLocation( 204 void WindowEventDispatcher::OnCursorMovedToRootLocation(
221 const gfx::Point& root_location) { 205 const gfx::Point& root_location) {
222 SetLastMouseLocation(window(), root_location); 206 env_controller_->SetLastMouseLocation(window(), root_location);
223 207
224 // Synthesize a mouse move in case the cursor's location in root coordinates 208 // Synthesize a mouse move in case the cursor's location in root coordinates
225 // changed but its position in WindowTreeHost coordinates did not. 209 // changed but its position in WindowTreeHost coordinates did not.
226 PostSynthesizeMouseMove(); 210 PostSynthesizeMouseMove();
227 } 211 }
228 212
229 void WindowEventDispatcher::OnPostNotifiedWindowDestroying(Window* window) { 213 void WindowEventDispatcher::OnPostNotifiedWindowDestroying(Window* window) {
230 OnWindowHidden(window, WINDOW_DESTROYED); 214 OnWindowHidden(window, WINDOW_DESTROYED);
231 } 215 }
232 216
(...skipping 28 matching lines...) Expand all
261 return; 245 return;
262 } 246 }
263 } 247 }
264 248
265 ui::EventDispatchDetails WindowEventDispatcher::DispatchMouseEnterOrExit( 249 ui::EventDispatchDetails WindowEventDispatcher::DispatchMouseEnterOrExit(
266 Window* target, 250 Window* target,
267 const ui::MouseEvent& event, 251 const ui::MouseEvent& event,
268 ui::EventType type) { 252 ui::EventType type) {
269 if (event.type() != ui::ET_MOUSE_CAPTURE_CHANGED && 253 if (event.type() != ui::ET_MOUSE_CAPTURE_CHANGED &&
270 !(event.flags() & ui::EF_IS_SYNTHESIZED)) { 254 !(event.flags() & ui::EF_IS_SYNTHESIZED)) {
271 SetLastMouseLocation(window(), event.root_location()); 255 env_controller_->SetLastMouseLocation(window(), event.root_location());
272 } 256 }
273 257
274 if (!mouse_moved_handler_ || !mouse_moved_handler_->delegate() || 258 if (!mouse_moved_handler_ || !mouse_moved_handler_->delegate() ||
275 !window()->Contains(mouse_moved_handler_)) 259 !window()->Contains(mouse_moved_handler_))
276 return DispatchDetails(); 260 return DispatchDetails();
277 261
278 // |event| may be an event in the process of being dispatched to a target (in 262 // |event| may be an event in the process of being dispatched to a target (in
279 // which case its locations will be in the event's target's coordinate 263 // which case its locations will be in the event's target's coordinate
280 // system), or a synthetic event created in root-window (in which case, the 264 // system), or a synthetic event created in root-window (in which case, the
281 // event's target will be NULL, and the event will be in the root-window's 265 // event's target will be NULL, and the event will be in the root-window's
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after
745 ui::LocatedEvent* event) { 729 ui::LocatedEvent* event) {
746 int flags = event->flags(); 730 int flags = event->flags();
747 if (IsNonClientLocation(target, event->location())) 731 if (IsNonClientLocation(target, event->location()))
748 flags |= ui::EF_IS_NON_CLIENT; 732 flags |= ui::EF_IS_NON_CLIENT;
749 event->set_flags(flags); 733 event->set_flags(flags);
750 734
751 if (!is_dispatched_held_event(*event) && 735 if (!is_dispatched_held_event(*event) &&
752 (event->IsMouseEvent() || event->IsScrollEvent()) && 736 (event->IsMouseEvent() || event->IsScrollEvent()) &&
753 !(event->flags() & ui::EF_IS_SYNTHESIZED)) { 737 !(event->flags() & ui::EF_IS_SYNTHESIZED)) {
754 if (event->type() != ui::ET_MOUSE_CAPTURE_CHANGED) 738 if (event->type() != ui::ET_MOUSE_CAPTURE_CHANGED)
755 SetLastMouseLocation(window(), event->root_location()); 739 env_controller_->SetLastMouseLocation(window(), event->root_location());
756 synthesize_mouse_move_ = false; 740 synthesize_mouse_move_ = false;
757 } 741 }
758 742
759 return DispatchDetails(); 743 return DispatchDetails();
760 } 744 }
761 745
762 DispatchDetails WindowEventDispatcher::PreDispatchMouseEvent( 746 DispatchDetails WindowEventDispatcher::PreDispatchMouseEvent(
763 Window* target, 747 Window* target,
764 ui::MouseEvent* event) { 748 ui::MouseEvent* event) {
765 client::CursorClient* cursor_client = client::GetCursorClient(window()); 749 client::CursorClient* cursor_client = client::GetCursorClient(window());
766 // We allow synthesized mouse exit events through even if mouse events are 750 // We allow synthesized mouse exit events through even if mouse events are
767 // disabled. This ensures that hover state, etc on controls like buttons is 751 // disabled. This ensures that hover state, etc on controls like buttons is
768 // cleared. 752 // cleared.
769 if (cursor_client && 753 if (cursor_client &&
770 !cursor_client->IsMouseEventsEnabled() && 754 !cursor_client->IsMouseEventsEnabled() &&
771 (event->flags() & ui::EF_IS_SYNTHESIZED) && 755 (event->flags() & ui::EF_IS_SYNTHESIZED) &&
772 (event->type() != ui::ET_MOUSE_EXITED)) { 756 (event->type() != ui::ET_MOUSE_EXITED)) {
773 event->SetHandled(); 757 event->SetHandled();
774 return DispatchDetails(); 758 return DispatchDetails();
775 } 759 }
776 760
777 if (IsEventCandidateForHold(*event) && !dispatching_held_event_) { 761 if (IsEventCandidateForHold(*event) && !dispatching_held_event_) {
778 if (move_hold_count_) { 762 if (move_hold_count_) {
779 if (!(event->flags() & ui::EF_IS_SYNTHESIZED) && 763 if (!(event->flags() & ui::EF_IS_SYNTHESIZED) &&
780 event->type() != ui::ET_MOUSE_CAPTURE_CHANGED) { 764 event->type() != ui::ET_MOUSE_CAPTURE_CHANGED) {
781 SetLastMouseLocation(window(), event->root_location()); 765 env_controller_->SetLastMouseLocation(window(), event->root_location());
782 } 766 }
783 held_move_event_.reset(new ui::MouseEvent(*event, target, window())); 767 held_move_event_.reset(new ui::MouseEvent(*event, target, window()));
784 event->SetHandled(); 768 event->SetHandled();
785 return DispatchDetails(); 769 return DispatchDetails();
786 } else { 770 } else {
787 // We may have a held event for a period between the time move_hold_count_ 771 // We may have a held event for a period between the time move_hold_count_
788 // fell to 0 and the DispatchHeldEvents executes. Since we're going to 772 // fell to 0 and the DispatchHeldEvents executes. Since we're going to
789 // dispatch the new event directly below, we can reset the old one. 773 // dispatch the new event directly below, we can reset the old one.
790 held_move_event_.reset(); 774 held_move_event_.reset();
791 } 775 }
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
844 } 828 }
845 } 829 }
846 break; 830 break;
847 case ui::ET_MOUSE_PRESSED: 831 case ui::ET_MOUSE_PRESSED:
848 // Don't set the mouse pressed handler for non client mouse down events. 832 // Don't set the mouse pressed handler for non client mouse down events.
849 // These are only sent by Windows and are not always followed with non 833 // These are only sent by Windows and are not always followed with non
850 // client mouse up events which causes subsequent mouse events to be 834 // client mouse up events which causes subsequent mouse events to be
851 // sent to the wrong target. 835 // sent to the wrong target.
852 if (!(event->flags() & ui::EF_IS_NON_CLIENT) && !mouse_pressed_handler_) 836 if (!(event->flags() & ui::EF_IS_NON_CLIENT) && !mouse_pressed_handler_)
853 mouse_pressed_handler_ = target; 837 mouse_pressed_handler_ = target;
854 Env::GetInstance()->set_mouse_button_flags(event->button_flags());
855 break; 838 break;
856 case ui::ET_MOUSE_RELEASED: 839 case ui::ET_MOUSE_RELEASED:
857 mouse_pressed_handler_ = NULL; 840 mouse_pressed_handler_ = NULL;
858 Env::GetInstance()->set_mouse_button_flags(
859 event->button_flags() & ~event->changed_button_flags());
860 break; 841 break;
861 default: 842 default:
862 break; 843 break;
863 } 844 }
864 845
846 env_controller_->PreDispatchMouseEvent(event);
sadrul 2016/05/31 18:27:02 Looking at all the various places that explicitly
847
865 return PreDispatchLocatedEvent(target, event); 848 return PreDispatchLocatedEvent(target, event);
866 } 849 }
867 850
868 DispatchDetails WindowEventDispatcher::PreDispatchTouchEvent( 851 DispatchDetails WindowEventDispatcher::PreDispatchTouchEvent(
869 Window* target, 852 Window* target,
870 ui::TouchEvent* event) { 853 ui::TouchEvent* event) {
871 switch (event->type()) { 854 switch (event->type()) {
872 case ui::ET_TOUCH_PRESSED: 855 case ui::ET_TOUCH_PRESSED:
873 touch_ids_down_ |= (1 << event->touch_id()); 856 touch_ids_down_ |= (1 << event->touch_id());
874 Env::GetInstance()->set_touch_down(touch_ids_down_ != 0);
875 break; 857 break;
876 858
877 // Handle ET_TOUCH_CANCELLED only if it has a native event. 859 // Handle ET_TOUCH_CANCELLED only if it has a native event.
878 case ui::ET_TOUCH_CANCELLED: 860 case ui::ET_TOUCH_CANCELLED:
879 if (!event->HasNativeEvent()) 861 if (!event->HasNativeEvent())
880 break; 862 break;
881 // fallthrough 863 // fallthrough
882 case ui::ET_TOUCH_RELEASED: 864 case ui::ET_TOUCH_RELEASED:
883 touch_ids_down_ = (touch_ids_down_ | (1 << event->touch_id())) ^ 865 touch_ids_down_ = (touch_ids_down_ | (1 << event->touch_id())) ^
884 (1 << event->touch_id()); 866 (1 << event->touch_id());
885 Env::GetInstance()->set_touch_down(touch_ids_down_ != 0);
886 break; 867 break;
887 868
888 case ui::ET_TOUCH_MOVED: 869 case ui::ET_TOUCH_MOVED:
889 if (move_hold_count_ && !dispatching_held_event_) { 870 if (move_hold_count_ && !dispatching_held_event_) {
890 held_move_event_.reset(new ui::TouchEvent(*event, target, window())); 871 held_move_event_.reset(new ui::TouchEvent(*event, target, window()));
891 event->SetHandled(); 872 event->SetHandled();
892 return DispatchDetails(); 873 return DispatchDetails();
893 } 874 }
894 break; 875 break;
895 876
896 default: 877 default:
897 NOTREACHED(); 878 NOTREACHED();
898 break; 879 break;
899 } 880 }
900 881
882 env_controller_->PreDispatchTouchEvent(event, touch_ids_down_);
883
901 ui::TouchEvent orig_event(*event, target, window()); 884 ui::TouchEvent orig_event(*event, target, window());
902 if (!ui::GestureRecognizer::Get()->ProcessTouchEventPreDispatch(&orig_event, 885 if (!ui::GestureRecognizer::Get()->ProcessTouchEventPreDispatch(&orig_event,
903 target)) { 886 target)) {
904 // The event is invalid - ignore it. 887 // The event is invalid - ignore it.
905 event->StopPropagation(); 888 event->StopPropagation();
906 event->DisableSynchronousHandling(); 889 event->DisableSynchronousHandling();
907 return DispatchDetails(); 890 return DispatchDetails();
908 } 891 }
909 892
910 // This flag is set depending on the gestures recognized in the call above, 893 // This flag is set depending on the gestures recognized in the call above,
911 // and needs to propagate with the forwarded event. 894 // and needs to propagate with the forwarded event.
912 event->set_may_cause_scrolling(orig_event.may_cause_scrolling()); 895 event->set_may_cause_scrolling(orig_event.may_cause_scrolling());
913 896
914 return PreDispatchLocatedEvent(target, event); 897 return PreDispatchLocatedEvent(target, event);
915 } 898 }
916 899
917 } // namespace aura 900 } // namespace aura
OLDNEW
« no previous file with comments | « ui/aura/window_event_dispatcher.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698