| 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 "ui/views/mus/pointer_watcher_event_router.h" | 5 #include "ui/views/mus/pointer_watcher_event_router.h" |
| 6 | 6 |
| 7 #include "services/ui/public/cpp/window.h" | 7 #include "services/ui/public/cpp/window.h" |
| 8 #include "services/ui/public/cpp/window_tree_client.h" | 8 #include "services/ui/public/cpp/window_tree_client.h" |
| 9 #include "ui/display/screen.h" | 9 #include "ui/display/screen.h" |
| 10 #include "ui/events/base_event_utils.h" | 10 #include "ui/events/base_event_utils.h" |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 while (window && !target_widget) { | 91 while (window && !target_widget) { |
| 92 target_widget = NativeWidgetMus::GetWidgetForWindow(target); | 92 target_widget = NativeWidgetMus::GetWidgetForWindow(target); |
| 93 window = window->parent(); | 93 window = window->parent(); |
| 94 } | 94 } |
| 95 } | 95 } |
| 96 | 96 |
| 97 // The mojo input events type converter uses the event root_location field | 97 // The mojo input events type converter uses the event root_location field |
| 98 // to store screen coordinates. Screen coordinates really should be returned | 98 // to store screen coordinates. Screen coordinates really should be returned |
| 99 // separately. See http://crbug.com/608547 | 99 // separately. See http://crbug.com/608547 |
| 100 gfx::Point location_in_screen = event.AsLocatedEvent()->root_location(); | 100 gfx::Point location_in_screen = event.AsLocatedEvent()->root_location(); |
| 101 FOR_EACH_OBSERVER( | 101 for (auto& observer : move_watchers_) |
| 102 PointerWatcher, move_watchers_, | 102 observer.OnPointerEventObserved(event, location_in_screen, target_widget); |
| 103 OnPointerEventObserved(event, location_in_screen, target_widget)); | |
| 104 if (event.type() != ui::ET_POINTER_MOVED) { | 103 if (event.type() != ui::ET_POINTER_MOVED) { |
| 105 FOR_EACH_OBSERVER( | 104 for (auto& observer : non_move_watchers_) |
| 106 PointerWatcher, non_move_watchers_, | 105 observer.OnPointerEventObserved(event, location_in_screen, target_widget); |
| 107 OnPointerEventObserved(event, location_in_screen, target_widget)); | |
| 108 } | 106 } |
| 109 } | 107 } |
| 110 | 108 |
| 111 PointerWatcherEventRouter::EventTypes | 109 PointerWatcherEventRouter::EventTypes |
| 112 PointerWatcherEventRouter::DetermineEventTypes() { | 110 PointerWatcherEventRouter::DetermineEventTypes() { |
| 113 if (HasPointerWatcher(&move_watchers_)) | 111 if (HasPointerWatcher(&move_watchers_)) |
| 114 return EventTypes::MOVE_EVENTS; | 112 return EventTypes::MOVE_EVENTS; |
| 115 | 113 |
| 116 if (HasPointerWatcher(&non_move_watchers_)) | 114 if (HasPointerWatcher(&non_move_watchers_)) |
| 117 return EventTypes::NON_MOVE_EVENTS; | 115 return EventTypes::NON_MOVE_EVENTS; |
| 118 | 116 |
| 119 return EventTypes::NONE; | 117 return EventTypes::NONE; |
| 120 } | 118 } |
| 121 | 119 |
| 122 void PointerWatcherEventRouter::OnWindowTreeCaptureChanged( | 120 void PointerWatcherEventRouter::OnWindowTreeCaptureChanged( |
| 123 ui::Window* gained_capture, | 121 ui::Window* gained_capture, |
| 124 ui::Window* lost_capture) { | 122 ui::Window* lost_capture) { |
| 125 const ui::MouseEvent mouse_event(ui::ET_MOUSE_CAPTURE_CHANGED, gfx::Point(), | 123 const ui::MouseEvent mouse_event(ui::ET_MOUSE_CAPTURE_CHANGED, gfx::Point(), |
| 126 gfx::Point(), ui::EventTimeForNow(), 0, 0); | 124 gfx::Point(), ui::EventTimeForNow(), 0, 0); |
| 127 const ui::PointerEvent event(mouse_event); | 125 const ui::PointerEvent event(mouse_event); |
| 128 gfx::Point location_in_screen = | 126 gfx::Point location_in_screen = |
| 129 display::Screen::GetScreen()->GetCursorScreenPoint(); | 127 display::Screen::GetScreen()->GetCursorScreenPoint(); |
| 130 FOR_EACH_OBSERVER(PointerWatcher, move_watchers_, | 128 for (auto& observer : move_watchers_) |
| 131 OnPointerEventObserved(event, location_in_screen, nullptr)); | 129 observer.OnPointerEventObserved(event, location_in_screen, nullptr); |
| 132 FOR_EACH_OBSERVER(PointerWatcher, non_move_watchers_, | 130 for (auto& observer : non_move_watchers_) |
| 133 OnPointerEventObserved(event, location_in_screen, nullptr)); | 131 observer.OnPointerEventObserved(event, location_in_screen, nullptr); |
| 134 } | 132 } |
| 135 | 133 |
| 136 void PointerWatcherEventRouter::OnDidDestroyClient( | 134 void PointerWatcherEventRouter::OnDidDestroyClient( |
| 137 ui::WindowTreeClient* client) { | 135 ui::WindowTreeClient* client) { |
| 138 // We expect that all observers have been removed by this time. | 136 // We expect that all observers have been removed by this time. |
| 139 DCHECK_EQ(event_types_, EventTypes::NONE); | 137 DCHECK_EQ(event_types_, EventTypes::NONE); |
| 140 DCHECK_EQ(client, window_tree_client_); | 138 DCHECK_EQ(client, window_tree_client_); |
| 141 window_tree_client_->RemoveObserver(this); | 139 window_tree_client_->RemoveObserver(this); |
| 142 window_tree_client_ = nullptr; | 140 window_tree_client_ = nullptr; |
| 143 } | 141 } |
| 144 | 142 |
| 145 } // namespace views | 143 } // namespace views |
| OLD | NEW |