OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "ash/pointer_watcher_delegate_aura.h" | 5 #include "ash/pointer_watcher_delegate_aura.h" |
6 | 6 |
7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
8 #include "ui/aura/client/screen_position_client.h" | 8 #include "ui/aura/client/screen_position_client.h" |
9 #include "ui/aura/window.h" | 9 #include "ui/aura/window.h" |
10 #include "ui/events/event.h" | 10 #include "ui/events/event.h" |
11 #include "ui/events/event_constants.h" | 11 #include "ui/events/event_constants.h" |
12 #include "ui/gfx/geometry/point.h" | 12 #include "ui/gfx/geometry/point.h" |
13 #include "ui/views/pointer_watcher.h" | 13 #include "ui/views/pointer_watcher.h" |
14 #include "ui/views/widget/widget.h" | 14 #include "ui/views/widget/widget.h" |
15 | 15 |
16 namespace ash { | 16 namespace ash { |
17 | 17 |
18 PointerWatcherDelegateAura::PointerWatcherDelegateAura() { | 18 PointerWatcherDelegateAura::PointerWatcherDelegateAura() { |
19 Shell::GetInstance()->AddPreTargetHandler(this); | 19 Shell::GetInstance()->AddPreTargetHandler(this); |
20 } | 20 } |
21 | 21 |
22 PointerWatcherDelegateAura::~PointerWatcherDelegateAura() { | 22 PointerWatcherDelegateAura::~PointerWatcherDelegateAura() { |
23 Shell::GetInstance()->RemovePreTargetHandler(this); | 23 Shell::GetInstance()->RemovePreTargetHandler(this); |
24 } | 24 } |
25 | 25 |
26 void PointerWatcherDelegateAura::AddPointerWatcher( | 26 void PointerWatcherDelegateAura::AddPointerWatcher( |
27 views::PointerWatcher* watcher) { | 27 views::PointerWatcher* watcher, |
28 bool wants_moves) { | |
28 pointer_watchers_.AddObserver(watcher); | 29 pointer_watchers_.AddObserver(watcher); |
30 if (wants_moves) { | |
James Cook
2016/08/11 23:51:10
Since want_moves is always true in the map, you co
| |
31 wants_moves_map_.insert( | |
32 std::pair<views::PointerWatcher*, bool>(watcher, wants_moves)); | |
33 } | |
29 } | 34 } |
30 | 35 |
31 void PointerWatcherDelegateAura::RemovePointerWatcher( | 36 void PointerWatcherDelegateAura::RemovePointerWatcher( |
32 views::PointerWatcher* watcher) { | 37 views::PointerWatcher* watcher) { |
33 pointer_watchers_.RemoveObserver(watcher); | 38 pointer_watchers_.RemoveObserver(watcher); |
39 auto it = wants_moves_map_.find(watcher); | |
40 if (it != wants_moves_map_.end()) | |
41 wants_moves_map_.erase(it); | |
34 } | 42 } |
35 | 43 |
36 void PointerWatcherDelegateAura::OnMouseEvent(ui::MouseEvent* event) { | 44 void PointerWatcherDelegateAura::OnMouseEvent(ui::MouseEvent* event) { |
37 // For compatibility with the mus version, don't send moves. | 45 // For compatibility with the mus version, don't send moves. |
38 if (event->type() != ui::ET_MOUSE_PRESSED && | 46 if (event->type() != ui::ET_MOUSE_DRAGGED && |
James Cook
2016/08/11 23:51:10
Good catch on drags.
| |
47 event->type() != ui::ET_MOUSE_MOVED && | |
48 event->type() != ui::ET_MOUSE_PRESSED && | |
39 event->type() != ui::ET_MOUSE_RELEASED) | 49 event->type() != ui::ET_MOUSE_RELEASED) |
40 return; | 50 return; |
51 | |
41 ui::PointerEvent mouse_pointer_event(*event); | 52 ui::PointerEvent mouse_pointer_event(*event); |
42 FOR_EACH_OBSERVER( | 53 // Mouse move events only sent to a select number of observers. |
43 views::PointerWatcher, pointer_watchers_, | 54 if (event->type() == ui::ET_MOUSE_DRAGGED || |
44 OnPointerEventObserved(mouse_pointer_event, GetLocationInScreen(*event), | 55 event->type() == ui::ET_MOUSE_MOVED) { |
45 GetTargetWidget(*event))); | 56 auto it = wants_moves_map_.begin(); |
57 for (; it != wants_moves_map_.end(); it++) { | |
58 it->first->OnPointerEventObserved(mouse_pointer_event, | |
59 GetLocationInScreen(*event), | |
60 GetTargetWidget(*event)); | |
61 } | |
62 } else { | |
63 FOR_EACH_OBSERVER( | |
64 views::PointerWatcher, pointer_watchers_, | |
65 OnPointerEventObserved(mouse_pointer_event, GetLocationInScreen(*event), | |
66 GetTargetWidget(*event))); | |
67 } | |
46 } | 68 } |
47 | 69 |
48 void PointerWatcherDelegateAura::OnTouchEvent(ui::TouchEvent* event) { | 70 void PointerWatcherDelegateAura::OnTouchEvent(ui::TouchEvent* event) { |
49 // For compatibility with the mus version, don't send moves. | 71 // For compatibility with the mus version, don't send moves. |
50 if (event->type() != ui::ET_TOUCH_PRESSED && | 72 if (event->type() != ui::ET_TOUCH_PRESSED && |
51 event->type() != ui::ET_TOUCH_RELEASED) | 73 event->type() != ui::ET_TOUCH_RELEASED) |
52 return; | 74 return; |
53 ui::PointerEvent touch_pointer_event(*event); | 75 ui::PointerEvent touch_pointer_event(*event); |
54 FOR_EACH_OBSERVER( | 76 FOR_EACH_OBSERVER( |
55 views::PointerWatcher, pointer_watchers_, | 77 views::PointerWatcher, pointer_watchers_, |
(...skipping 10 matching lines...) Expand all Loading... | |
66 return location_in_screen; | 88 return location_in_screen; |
67 } | 89 } |
68 | 90 |
69 views::Widget* PointerWatcherDelegateAura::GetTargetWidget( | 91 views::Widget* PointerWatcherDelegateAura::GetTargetWidget( |
70 const ui::LocatedEvent& event) const { | 92 const ui::LocatedEvent& event) const { |
71 aura::Window* window = static_cast<aura::Window*>(event.target()); | 93 aura::Window* window = static_cast<aura::Window*>(event.target()); |
72 return views::Widget::GetTopLevelWidgetForNativeView(window); | 94 return views::Widget::GetTopLevelWidgetForNativeView(window); |
73 } | 95 } |
74 | 96 |
75 } // namespace ash | 97 } // namespace ash |
OLD | NEW |