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

Side by Side Diff: ash/pointer_watcher_delegate_aura.cc

Issue 2235363003: Wires up WmShellMus::Add/RemovePointerWatcher (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@pointer_watcher_capture
Patch Set: cleanup Created 4 years, 4 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
OLDNEW
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 pointer_watchers_.AddObserver(watcher); 28 bool wants_moves) {
29 // We only allow a watcher to be added once. That is, we don't consider
30 // the pair of |watcher| and |wants_move| unique, just |watcher|.
31 if (wants_moves) {
32 DCHECK(!pointer_watchers_.HasObserver(watcher));
33 move_pointer_watchers_.AddObserver(watcher);
34 } else {
35 DCHECK(!move_pointer_watchers_.HasObserver(watcher));
36 pointer_watchers_.AddObserver(watcher);
37 }
29 } 38 }
30 39
31 void PointerWatcherDelegateAura::RemovePointerWatcher( 40 void PointerWatcherDelegateAura::RemovePointerWatcher(
32 views::PointerWatcher* watcher) { 41 views::PointerWatcher* watcher) {
33 pointer_watchers_.RemoveObserver(watcher); 42 pointer_watchers_.RemoveObserver(watcher);
43 move_pointer_watchers_.RemoveObserver(watcher);
34 } 44 }
35 45
36 void PointerWatcherDelegateAura::OnMouseEvent(ui::MouseEvent* event) { 46 void PointerWatcherDelegateAura::OnMouseEvent(ui::MouseEvent* event) {
37 // For compatibility with the mus version, don't send moves. 47 // For compatibility with the mus version, don't send moves.
38 if (event->type() != ui::ET_MOUSE_PRESSED && 48 if (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 if (event->type() == ui::ET_MOUSE_CAPTURE_CHANGED) { 52 if (event->type() == ui::ET_MOUSE_CAPTURE_CHANGED) {
James Cook 2016/08/12 16:08:53 Move above 47 (merge should handle that I think)
sky 2016/08/12 17:59:37 Ya, sorry, I fixed it after you pointed the error
42 FOR_EACH_OBSERVER(views::PointerWatcher, pointer_watchers_, 53 FOR_EACH_OBSERVER(views::PointerWatcher, pointer_watchers_,
43 OnMouseCaptureChanged()); 54 OnMouseCaptureChanged());
55 FOR_EACH_OBSERVER(views::PointerWatcher, move_pointer_watchers_,
56 OnMouseCaptureChanged());
44 return; 57 return;
45 } 58 }
59
46 if (!ui::PointerEvent::CanConvertFrom(*event)) 60 if (!ui::PointerEvent::CanConvertFrom(*event))
James Cook 2016/08/12 16:08:53 DCHECK here instead? event must be pressed or rele
sky 2016/08/12 17:59:37 Turns out mouse wheel events aren't pointer events
47 return; 61 return;
48 ui::PointerEvent mouse_pointer_event(*event); 62
49 FOR_EACH_OBSERVER( 63 NotifyWatchers(ui::PointerEvent(*event), *event);
50 views::PointerWatcher, pointer_watchers_,
51 OnPointerEventObserved(mouse_pointer_event, GetLocationInScreen(*event),
52 GetTargetWidget(*event)));
53 } 64 }
54 65
55 void PointerWatcherDelegateAura::OnTouchEvent(ui::TouchEvent* event) { 66 void PointerWatcherDelegateAura::OnTouchEvent(ui::TouchEvent* event) {
56 // For compatibility with the mus version, don't send moves. 67 // For compatibility with the mus version, don't send moves.
57 if (event->type() != ui::ET_TOUCH_PRESSED && 68 if (event->type() != ui::ET_TOUCH_PRESSED &&
58 event->type() != ui::ET_TOUCH_RELEASED) 69 event->type() != ui::ET_TOUCH_RELEASED)
59 return; 70 return;
60 ui::PointerEvent touch_pointer_event(*event); 71
61 FOR_EACH_OBSERVER( 72 DCHECK(ui::PointerEvent::CanConvertFrom(*event));
62 views::PointerWatcher, pointer_watchers_, 73 NotifyWatchers(ui::PointerEvent(*event), *event);
63 OnPointerEventObserved(touch_pointer_event, GetLocationInScreen(*event),
64 GetTargetWidget(*event)));
65 } 74 }
66 75
67 gfx::Point PointerWatcherDelegateAura::GetLocationInScreen( 76 gfx::Point PointerWatcherDelegateAura::GetLocationInScreen(
68 const ui::LocatedEvent& event) const { 77 const ui::LocatedEvent& event) const {
69 aura::Window* target = static_cast<aura::Window*>(event.target()); 78 aura::Window* target = static_cast<aura::Window*>(event.target());
70 gfx::Point location_in_screen = event.location(); 79 gfx::Point location_in_screen = event.location();
71 aura::client::GetScreenPositionClient(target->GetRootWindow()) 80 aura::client::GetScreenPositionClient(target->GetRootWindow())
72 ->ConvertPointToScreen(target, &location_in_screen); 81 ->ConvertPointToScreen(target, &location_in_screen);
73 return location_in_screen; 82 return location_in_screen;
74 } 83 }
75 84
76 views::Widget* PointerWatcherDelegateAura::GetTargetWidget( 85 views::Widget* PointerWatcherDelegateAura::GetTargetWidget(
77 const ui::LocatedEvent& event) const { 86 const ui::LocatedEvent& event) const {
78 aura::Window* window = static_cast<aura::Window*>(event.target()); 87 aura::Window* window = static_cast<aura::Window*>(event.target());
79 return views::Widget::GetTopLevelWidgetForNativeView(window); 88 return views::Widget::GetTopLevelWidgetForNativeView(window);
80 } 89 }
81 90
91 void PointerWatcherDelegateAura::NotifyWatchers(
92 const ui::PointerEvent& event,
93 const ui::LocatedEvent& original_event) {
94 const gfx::Point screen_location(GetLocationInScreen(original_event));
95 views::Widget* target_widget = GetTargetWidget(original_event);
96 FOR_EACH_OBSERVER(
97 views::PointerWatcher, move_pointer_watchers_,
98 OnPointerEventObserved(event, screen_location, target_widget));
99 if (event.type() != ui::ET_MOUSE_MOVED &&
100 event.type() != ui::ET_TOUCH_MOVED) {
101 FOR_EACH_OBSERVER(
102 views::PointerWatcher, pointer_watchers_,
103 OnPointerEventObserved(event, screen_location, target_widget));
104 }
105 }
106
82 } // namespace ash 107 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698