Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/mus/ws/event_dispatcher.h" | 5 #include "components/mus/ws/event_dispatcher.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "cc/surfaces/surface_hittest.h" | 9 #include "cc/surfaces/surface_hittest.h" |
| 10 #include "components/mus/surfaces/surfaces_state.h" | 10 #include "components/mus/surfaces/surfaces_state.h" |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 134 mojom::EventType event_type_; | 134 mojom::EventType event_type_; |
| 135 mojom::EventFlags event_flags_; | 135 mojom::EventFlags event_flags_; |
| 136 mojom::KeyboardCode keyboard_code_; | 136 mojom::KeyboardCode keyboard_code_; |
| 137 mojom::PointerKind pointer_kind_; | 137 mojom::PointerKind pointer_kind_; |
| 138 gfx::RectF pointer_region_; | 138 gfx::RectF pointer_region_; |
| 139 }; | 139 }; |
| 140 | 140 |
| 141 //////////////////////////////////////////////////////////////////////////////// | 141 //////////////////////////////////////////////////////////////////////////////// |
| 142 | 142 |
| 143 EventDispatcher::EventDispatcher(EventDispatcherDelegate* delegate) | 143 EventDispatcher::EventDispatcher(EventDispatcherDelegate* delegate) |
| 144 : delegate_(delegate), root_(nullptr) {} | 144 : delegate_(delegate), root_(nullptr), capture_window_(nullptr) {} |
| 145 | 145 |
| 146 EventDispatcher::~EventDispatcher() { | 146 EventDispatcher::~EventDispatcher() { |
| 147 std::set<ServerWindow*> pointer_targets; | 147 CancelAllPointerEvents(); |
| 148 for (const auto& pair : pointer_targets_) { | 148 } |
| 149 if (pair.second.window && | 149 |
| 150 pointer_targets.insert(pair.second.window).second) { | 150 void EventDispatcher::SetCaptureWindow(ServerWindow* window) { |
| 151 pair.second.window->RemoveObserver(this); | 151 // Cancel all implicit captures. |
| 152 } | 152 CancelAllPointerEvents(); |
|
sky
2015/11/17 01:06:42
If window is in pointer_targets_ won't this incorr
| |
| 153 } | 153 capture_window_ = window; |
| 154 // Track the lifetime of the window with explicit capture. | |
| 155 if (window) | |
| 156 window->AddObserver(this); | |
| 154 } | 157 } |
| 155 | 158 |
| 156 void EventDispatcher::AddAccelerator(uint32_t id, | 159 void EventDispatcher::AddAccelerator(uint32_t id, |
| 157 mojom::EventMatcherPtr event_matcher) { | 160 mojom::EventMatcherPtr event_matcher) { |
| 158 EventMatcher matcher(*event_matcher); | 161 EventMatcher matcher(*event_matcher); |
| 159 #if !defined(NDEBUG) | 162 #if !defined(NDEBUG) |
| 160 for (const auto& pair : accelerators_) { | 163 for (const auto& pair : accelerators_) { |
| 161 DCHECK_NE(pair.first, id); | 164 DCHECK_NE(pair.first, id); |
| 162 DCHECK(!matcher.Equals(pair.second)); | 165 DCHECK(!matcher.Equals(pair.second)); |
| 163 } | 166 } |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 198 } | 201 } |
| 199 | 202 |
| 200 void EventDispatcher::ProcessKeyEvent(mojom::EventPtr event) { | 203 void EventDispatcher::ProcessKeyEvent(mojom::EventPtr event) { |
| 201 ServerWindow* focused_window = | 204 ServerWindow* focused_window = |
| 202 delegate_->GetFocusedWindowForEventDispatcher(); | 205 delegate_->GetFocusedWindowForEventDispatcher(); |
| 203 if (focused_window) | 206 if (focused_window) |
| 204 delegate_->DispatchInputEventToWindow(focused_window, false, event.Pass()); | 207 delegate_->DispatchInputEventToWindow(focused_window, false, event.Pass()); |
| 205 } | 208 } |
| 206 | 209 |
| 207 void EventDispatcher::ProcessPointerEvent(mojom::EventPtr event) { | 210 void EventDispatcher::ProcessPointerEvent(mojom::EventPtr event) { |
| 211 if (capture_window_) { | |
| 212 PointerTarget pointer_target; | |
| 213 pointer_target.window = capture_window_; | |
| 214 DispatchToPointerTarget(pointer_target, event.Pass()); | |
| 215 return; | |
| 216 } | |
| 217 | |
| 208 const int32_t pointer_id = event->pointer_data->pointer_id; | 218 const int32_t pointer_id = event->pointer_data->pointer_id; |
| 209 if (event->action == mojom::EVENT_TYPE_WHEEL || | 219 if (event->action == mojom::EVENT_TYPE_WHEEL || |
| 210 (event->action == mojom::EVENT_TYPE_POINTER_MOVE && | 220 (event->action == mojom::EVENT_TYPE_POINTER_MOVE && |
| 211 pointer_targets_.count(pointer_id) == 0)) { | 221 pointer_targets_.count(pointer_id) == 0)) { |
| 212 PointerTarget pointer_target; | 222 PointerTarget pointer_target; |
| 213 if (pointer_targets_.count(pointer_id) != 0) { | 223 if (pointer_targets_.count(pointer_id) != 0) { |
| 214 pointer_target = pointer_targets_[pointer_id]; | 224 pointer_target = pointer_targets_[pointer_id]; |
| 215 } else { | 225 } else { |
| 216 gfx::Point location(EventLocationToPoint(*event)); | 226 gfx::Point location(EventLocationToPoint(*event)); |
| 217 pointer_target.window = | 227 pointer_target.window = |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 265 | 275 |
| 266 gfx::Point location(EventLocationToPoint(*event)); | 276 gfx::Point location(EventLocationToPoint(*event)); |
| 267 gfx::Transform transform(GetTransformToWindow(surface_id_, target.window)); | 277 gfx::Transform transform(GetTransformToWindow(surface_id_, target.window)); |
| 268 transform.TransformPoint(&location); | 278 transform.TransformPoint(&location); |
| 269 event->pointer_data->location->x = location.x(); | 279 event->pointer_data->location->x = location.x(); |
| 270 event->pointer_data->location->y = location.y(); | 280 event->pointer_data->location->y = location.y(); |
| 271 delegate_->DispatchInputEventToWindow(target.window, target.in_nonclient_area, | 281 delegate_->DispatchInputEventToWindow(target.window, target.in_nonclient_area, |
| 272 event.Pass()); | 282 event.Pass()); |
| 273 } | 283 } |
| 274 | 284 |
| 285 void EventDispatcher::CancelAllPointerEvents() { | |
| 286 if (capture_window_) { | |
|
sky
2015/11/17 01:06:42
Based on the name I wouldn't expect this to reset
| |
| 287 capture_window_->RemoveObserver(this); | |
| 288 capture_window_ = nullptr; | |
| 289 } | |
| 290 std::set<ServerWindow*> pointer_targets; | |
|
sky
2015/11/17 01:06:42
The windows should see a cancel when this happens.
| |
| 291 for (const auto& pair : pointer_targets_) { | |
| 292 if (pair.second.window && | |
| 293 pointer_targets.insert(pair.second.window).second) { | |
| 294 pair.second.window->RemoveObserver(this); | |
| 295 } | |
| 296 } | |
| 297 pointer_targets_.clear(); | |
| 298 } | |
| 299 | |
| 275 void EventDispatcher::CancelPointerEventsToTarget(ServerWindow* window) { | 300 void EventDispatcher::CancelPointerEventsToTarget(ServerWindow* window) { |
| 276 window->RemoveObserver(this); | 301 window->RemoveObserver(this); |
| 302 if (capture_window_ == window) { | |
| 303 capture_window_ = nullptr; | |
| 304 // A window only cares to be informed that it lost capture if it explicitly | |
| 305 // requested capture. A window can lose capture if another window gains | |
| 306 // explicit capture. | |
| 307 delegate_->OnLostCapture(window); | |
| 308 return; | |
| 309 } | |
| 277 | 310 |
| 278 for (auto& pair : pointer_targets_) { | 311 for (auto& pair : pointer_targets_) { |
| 279 if (pair.second.window == window) | 312 if (pair.second.window == window) |
| 280 pair.second.window = nullptr; | 313 pair.second.window = nullptr; |
| 281 } | 314 } |
| 282 } | 315 } |
| 283 | 316 |
| 284 bool EventDispatcher::IsObservingWindow(ServerWindow* window) { | 317 bool EventDispatcher::IsObservingWindow(ServerWindow* window) { |
| 285 for (const auto& pair : pointer_targets_) { | 318 for (const auto& pair : pointer_targets_) { |
| 286 if (pair.second.window == window) | 319 if (pair.second.window == window) |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 310 void EventDispatcher::OnWindowVisibilityChanged(ServerWindow* window) { | 343 void EventDispatcher::OnWindowVisibilityChanged(ServerWindow* window) { |
| 311 CancelPointerEventsToTarget(window); | 344 CancelPointerEventsToTarget(window); |
| 312 } | 345 } |
| 313 | 346 |
| 314 void EventDispatcher::OnWindowDestroyed(ServerWindow* window) { | 347 void EventDispatcher::OnWindowDestroyed(ServerWindow* window) { |
| 315 CancelPointerEventsToTarget(window); | 348 CancelPointerEventsToTarget(window); |
| 316 } | 349 } |
| 317 | 350 |
| 318 } // namespace ws | 351 } // namespace ws |
| 319 } // namespace mus | 352 } // namespace mus |
| OLD | NEW |