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/aura/pointer_watcher_adapter.h" | 5 #include "ash/aura/pointer_watcher_adapter.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/display/screen.h" |
10 #include "ui/events/event.h" | 11 #include "ui/events/event.h" |
11 #include "ui/events/event_constants.h" | 12 #include "ui/events/event_constants.h" |
12 #include "ui/gfx/geometry/point.h" | 13 #include "ui/gfx/geometry/point.h" |
13 #include "ui/views/pointer_watcher.h" | 14 #include "ui/views/pointer_watcher.h" |
14 #include "ui/views/widget/widget.h" | 15 #include "ui/views/widget/widget.h" |
15 | 16 |
16 namespace ash { | 17 namespace ash { |
17 | 18 |
18 PointerWatcherAdapter::PointerWatcherAdapter() { | 19 PointerWatcherAdapter::PointerWatcherAdapter() { |
19 Shell::GetInstance()->AddPreTargetHandler(this); | 20 Shell::GetInstance()->AddPreTargetHandler(this); |
(...skipping 16 matching lines...) Expand all Loading... |
36 } | 37 } |
37 } | 38 } |
38 | 39 |
39 void PointerWatcherAdapter::RemovePointerWatcher( | 40 void PointerWatcherAdapter::RemovePointerWatcher( |
40 views::PointerWatcher* watcher) { | 41 views::PointerWatcher* watcher) { |
41 non_move_watchers_.RemoveObserver(watcher); | 42 non_move_watchers_.RemoveObserver(watcher); |
42 move_watchers_.RemoveObserver(watcher); | 43 move_watchers_.RemoveObserver(watcher); |
43 } | 44 } |
44 | 45 |
45 void PointerWatcherAdapter::OnMouseEvent(ui::MouseEvent* event) { | 46 void PointerWatcherAdapter::OnMouseEvent(ui::MouseEvent* event) { |
46 if (event->type() == ui::ET_MOUSE_CAPTURE_CHANGED) { | |
47 FOR_EACH_OBSERVER(views::PointerWatcher, non_move_watchers_, | |
48 OnMouseCaptureChanged()); | |
49 FOR_EACH_OBSERVER(views::PointerWatcher, move_watchers_, | |
50 OnMouseCaptureChanged()); | |
51 return; | |
52 } | |
53 | |
54 // For compatibility with the mus version, don't send drags. | 47 // For compatibility with the mus version, don't send drags. |
55 if (event->type() != ui::ET_MOUSE_PRESSED && | 48 if (event->type() != ui::ET_MOUSE_PRESSED && |
56 event->type() != ui::ET_MOUSE_RELEASED && | 49 event->type() != ui::ET_MOUSE_RELEASED && |
57 event->type() != ui::ET_MOUSE_MOVED) | 50 event->type() != ui::ET_MOUSE_MOVED && |
| 51 event->type() != ui::ET_MOUSEWHEEL && |
| 52 event->type() != ui::ET_MOUSE_CAPTURE_CHANGED) |
58 return; | 53 return; |
59 | 54 |
60 DCHECK(ui::PointerEvent::CanConvertFrom(*event)); | 55 DCHECK(ui::PointerEvent::CanConvertFrom(*event)); |
61 NotifyWatchers(ui::PointerEvent(*event), *event); | 56 NotifyWatchers(ui::PointerEvent(*event), *event); |
62 } | 57 } |
63 | 58 |
64 void PointerWatcherAdapter::OnTouchEvent(ui::TouchEvent* event) { | 59 void PointerWatcherAdapter::OnTouchEvent(ui::TouchEvent* event) { |
65 // For compatibility with the mus version, don't send drags. | 60 // For compatibility with the mus version, don't send drags. |
66 if (event->type() != ui::ET_TOUCH_PRESSED && | 61 if (event->type() != ui::ET_TOUCH_PRESSED && |
67 event->type() != ui::ET_TOUCH_RELEASED) | 62 event->type() != ui::ET_TOUCH_RELEASED) |
68 return; | 63 return; |
69 | 64 |
70 DCHECK(ui::PointerEvent::CanConvertFrom(*event)); | 65 DCHECK(ui::PointerEvent::CanConvertFrom(*event)); |
71 NotifyWatchers(ui::PointerEvent(*event), *event); | 66 NotifyWatchers(ui::PointerEvent(*event), *event); |
72 } | 67 } |
73 | 68 |
74 gfx::Point PointerWatcherAdapter::GetLocationInScreen( | 69 gfx::Point PointerWatcherAdapter::GetLocationInScreen( |
75 const ui::LocatedEvent& event) const { | 70 const ui::LocatedEvent& event) const { |
76 aura::Window* target = static_cast<aura::Window*>(event.target()); | 71 gfx::Point location_in_screen; |
77 gfx::Point location_in_screen = event.location(); | 72 if (event.type() == ui::ET_MOUSE_CAPTURE_CHANGED) { |
78 aura::client::GetScreenPositionClient(target->GetRootWindow()) | 73 location_in_screen = display::Screen::GetScreen()->GetCursorScreenPoint(); |
79 ->ConvertPointToScreen(target, &location_in_screen); | 74 } else { |
| 75 aura::Window* target = static_cast<aura::Window*>(event.target()); |
| 76 location_in_screen = event.location(); |
| 77 aura::client::GetScreenPositionClient(target->GetRootWindow()) |
| 78 ->ConvertPointToScreen(target, &location_in_screen); |
| 79 } |
80 return location_in_screen; | 80 return location_in_screen; |
81 } | 81 } |
82 | 82 |
83 views::Widget* PointerWatcherAdapter::GetTargetWidget( | 83 views::Widget* PointerWatcherAdapter::GetTargetWidget( |
84 const ui::LocatedEvent& event) const { | 84 const ui::LocatedEvent& event) const { |
85 aura::Window* window = static_cast<aura::Window*>(event.target()); | 85 aura::Window* window = static_cast<aura::Window*>(event.target()); |
86 return views::Widget::GetTopLevelWidgetForNativeView(window); | 86 return views::Widget::GetTopLevelWidgetForNativeView(window); |
87 } | 87 } |
88 | 88 |
89 void PointerWatcherAdapter::NotifyWatchers( | 89 void PointerWatcherAdapter::NotifyWatchers( |
90 const ui::PointerEvent& event, | 90 const ui::PointerEvent& event, |
91 const ui::LocatedEvent& original_event) { | 91 const ui::LocatedEvent& original_event) { |
92 const gfx::Point screen_location(GetLocationInScreen(original_event)); | 92 const gfx::Point screen_location(GetLocationInScreen(original_event)); |
93 views::Widget* target_widget = GetTargetWidget(original_event); | 93 views::Widget* target_widget = GetTargetWidget(original_event); |
94 FOR_EACH_OBSERVER( | 94 FOR_EACH_OBSERVER( |
95 views::PointerWatcher, move_watchers_, | 95 views::PointerWatcher, move_watchers_, |
96 OnPointerEventObserved(event, screen_location, target_widget)); | 96 OnPointerEventObserved(event, screen_location, target_widget)); |
97 if (event.type() != ui::ET_POINTER_MOVED) { | 97 if (event.type() != ui::ET_POINTER_MOVED) { |
98 FOR_EACH_OBSERVER( | 98 FOR_EACH_OBSERVER( |
99 views::PointerWatcher, non_move_watchers_, | 99 views::PointerWatcher, non_move_watchers_, |
100 OnPointerEventObserved(event, screen_location, target_widget)); | 100 OnPointerEventObserved(event, screen_location, target_widget)); |
101 } | 101 } |
102 } | 102 } |
103 | 103 |
104 } // namespace ash | 104 } // namespace ash |
OLD | NEW |