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 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 149 mojom::KeyboardCode keyboard_code_; | 149 mojom::KeyboardCode keyboard_code_; |
| 150 mojom::PointerKind pointer_kind_; | 150 mojom::PointerKind pointer_kind_; |
| 151 gfx::RectF pointer_region_; | 151 gfx::RectF pointer_region_; |
| 152 }; | 152 }; |
| 153 | 153 |
| 154 //////////////////////////////////////////////////////////////////////////////// | 154 //////////////////////////////////////////////////////////////////////////////// |
| 155 | 155 |
| 156 EventDispatcher::EventDispatcher(EventDispatcherDelegate* delegate) | 156 EventDispatcher::EventDispatcher(EventDispatcherDelegate* delegate) |
| 157 : delegate_(delegate), | 157 : delegate_(delegate), |
| 158 root_(nullptr), | 158 root_(nullptr), |
| 159 capture_window_(nullptr), | |
| 159 mouse_button_down_(false), | 160 mouse_button_down_(false), |
| 160 mouse_cursor_source_window_(nullptr) {} | 161 mouse_cursor_source_window_(nullptr) {} |
| 161 | 162 |
| 162 EventDispatcher::~EventDispatcher() { | 163 EventDispatcher::~EventDispatcher() { |
| 163 std::set<ServerWindow*> pointer_targets; | 164 std::set<ServerWindow*> pointer_targets; |
| 165 if (capture_window_) { | |
| 166 pointer_targets.insert(capture_window_); | |
| 167 capture_window_->RemoveObserver(this); | |
| 168 capture_window_ = nullptr; | |
| 169 } | |
| 164 for (const auto& pair : pointer_targets_) { | 170 for (const auto& pair : pointer_targets_) { |
| 165 if (pair.second.window && | 171 if (pair.second.window && |
| 166 pointer_targets.insert(pair.second.window).second) { | 172 pointer_targets.insert(pair.second.window).second) { |
| 167 pair.second.window->RemoveObserver(this); | 173 pair.second.window->RemoveObserver(this); |
| 168 } | 174 } |
| 169 } | 175 } |
| 176 pointer_targets_.clear(); | |
| 177 } | |
| 178 | |
| 179 void EventDispatcher::SetCaptureWindow(ServerWindow* window) { | |
|
sky
2016/01/22 00:55:00
You need to also pass in in_nonclient_area. I thin
jonross
2016/01/22 20:31:28
I'm not sure if that is needed. There will not alw
sky
2016/01/22 22:15:37
For windows with no one embedded in them there is
jonross
2016/01/26 18:38:50
That makes sense. I'm passing this in now based on
| |
| 180 if (window == capture_window_) | |
| 181 return; | |
| 182 | |
| 183 // Cancel implicit capture to all other windows. | |
| 184 PointerIdToTargetMap window_implicit_targets; | |
| 185 std::set<ServerWindow*> unobserved_windows; | |
|
jonross
2016/01/21 22:01:12
There was a comment in the previous review:
"The
jonross
2016/01/26 18:38:50
Done.
| |
| 186 if (capture_window_) { | |
| 187 delegate_->OnLostCapture(capture_window_); | |
| 188 unobserved_windows.insert(capture_window_); | |
| 189 capture_window_->RemoveObserver(this); | |
| 190 } | |
| 191 | |
| 192 for (const auto& pair : pointer_targets_) { | |
| 193 ServerWindow* target = pair.second.window; | |
| 194 if (!target) | |
| 195 continue; | |
| 196 if (target == window) | |
| 197 window_implicit_targets[pair.first] = pair.second; | |
|
sky
2016/01/22 00:55:00
Why do you need to maintain pointer_targets_ when
jonross
2016/01/22 20:31:28
This was based on a comment in the original review
jonross
2016/01/26 18:38:50
Done.
| |
| 198 else if (unobserved_windows.insert(target).second) | |
| 199 target->RemoveObserver(this); | |
|
sky
2016/01/22 00:55:00
You should send POINTER_CANCEL here.
jonross
2016/01/26 18:38:50
Done.
| |
| 200 } | |
| 201 pointer_targets_.swap(window_implicit_targets); | |
| 202 | |
| 203 capture_window_ = window; | |
| 204 // Begin tracking the capture window if it is not yet being observed. | |
| 205 if (window && pointer_targets_.empty()) | |
| 206 window->AddObserver(this); | |
| 170 } | 207 } |
| 171 | 208 |
| 172 void EventDispatcher::UpdateCursorProviderByLastKnownLocation() { | 209 void EventDispatcher::UpdateCursorProviderByLastKnownLocation() { |
| 173 if (!mouse_button_down_) { | 210 if (!mouse_button_down_) { |
| 174 gfx::Point location = mouse_pointer_last_location_; | 211 gfx::Point location = mouse_pointer_last_location_; |
| 175 mouse_cursor_source_window_ = | 212 mouse_cursor_source_window_ = |
| 176 FindDeepestVisibleWindowForEvents(root_, surface_id_, &location); | 213 FindDeepestVisibleWindowForEvents(root_, surface_id_, &location); |
| 177 } | 214 } |
| 178 } | 215 } |
| 179 | 216 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 223 | 260 |
| 224 void EventDispatcher::ProcessKeyEvent(mojom::EventPtr event) { | 261 void EventDispatcher::ProcessKeyEvent(mojom::EventPtr event) { |
| 225 ServerWindow* focused_window = | 262 ServerWindow* focused_window = |
| 226 delegate_->GetFocusedWindowForEventDispatcher(); | 263 delegate_->GetFocusedWindowForEventDispatcher(); |
| 227 if (focused_window) | 264 if (focused_window) |
| 228 delegate_->DispatchInputEventToWindow(focused_window, false, | 265 delegate_->DispatchInputEventToWindow(focused_window, false, |
| 229 std::move(event)); | 266 std::move(event)); |
| 230 } | 267 } |
| 231 | 268 |
| 232 void EventDispatcher::ProcessPointerEvent(mojom::EventPtr event) { | 269 void EventDispatcher::ProcessPointerEvent(mojom::EventPtr event) { |
| 270 if (capture_window_) { | |
| 271 PointerTarget pointer_target; | |
| 272 pointer_target.window = capture_window_; | |
| 273 DispatchToPointerTarget(pointer_target, std::move(event)); | |
| 274 return; | |
| 275 } | |
| 276 | |
| 233 const bool is_mouse_event = | 277 const bool is_mouse_event = |
| 234 event->pointer_data && | 278 event->pointer_data && |
| 235 event->pointer_data->kind == mojom::PointerKind::POINTER_KIND_MOUSE; | 279 event->pointer_data->kind == mojom::PointerKind::POINTER_KIND_MOUSE; |
| 236 | 280 |
| 237 if (is_mouse_event) | 281 if (is_mouse_event) |
| 238 mouse_pointer_last_location_ = EventLocationToPoint(*event); | 282 mouse_pointer_last_location_ = EventLocationToPoint(*event); |
| 239 | 283 |
| 240 const int32_t pointer_id = event->pointer_data->pointer_id; | 284 const int32_t pointer_id = event->pointer_data->pointer_id; |
| 241 if (!IsTrackingPointer(pointer_id) || | 285 if (!IsTrackingPointer(pointer_id) || |
| 242 !pointer_targets_[pointer_id].is_pointer_down) { | 286 !pointer_targets_[pointer_id].is_pointer_down) { |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 373 transform.TransformPoint(&location); | 417 transform.TransformPoint(&location); |
| 374 event->pointer_data->location->x = location.x(); | 418 event->pointer_data->location->x = location.x(); |
| 375 event->pointer_data->location->y = location.y(); | 419 event->pointer_data->location->y = location.y(); |
| 376 delegate_->DispatchInputEventToWindow(target.window, target.in_nonclient_area, | 420 delegate_->DispatchInputEventToWindow(target.window, target.in_nonclient_area, |
| 377 std::move(event)); | 421 std::move(event)); |
| 378 } | 422 } |
| 379 | 423 |
| 380 void EventDispatcher::CancelPointerEventsToTarget(ServerWindow* window) { | 424 void EventDispatcher::CancelPointerEventsToTarget(ServerWindow* window) { |
| 381 window->RemoveObserver(this); | 425 window->RemoveObserver(this); |
| 382 | 426 |
| 427 if (capture_window_ == window) { | |
| 428 capture_window_ = nullptr; | |
| 429 // A window only cares to be informed that it lost capture if it explicitly | |
| 430 // requested capture. A window can lose capture if another window gains | |
| 431 // explicit capture. | |
| 432 delegate_->OnLostCapture(window); | |
| 433 return; | |
|
sky
2016/01/22 00:55:00
Why the early out here? Don't we still need to res
jonross
2016/01/26 18:38:50
With the change to always clear pointer_targets_ i
| |
| 434 } | |
| 435 | |
| 383 for (auto& pair : pointer_targets_) { | 436 for (auto& pair : pointer_targets_) { |
| 384 if (pair.second.window == window) | 437 if (pair.second.window == window) |
| 385 pair.second.window = nullptr; | 438 pair.second.window = nullptr; |
| 386 } | 439 } |
| 387 } | 440 } |
| 388 | 441 |
| 389 bool EventDispatcher::IsObservingWindow(ServerWindow* window) { | 442 bool EventDispatcher::IsObservingWindow(ServerWindow* window) { |
| 390 for (const auto& pair : pointer_targets_) { | 443 for (const auto& pair : pointer_targets_) { |
| 391 if (pair.second.window == window) | 444 if (pair.second.window == window) |
| 392 return true; | 445 return true; |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 418 | 471 |
| 419 void EventDispatcher::OnWindowDestroyed(ServerWindow* window) { | 472 void EventDispatcher::OnWindowDestroyed(ServerWindow* window) { |
| 420 CancelPointerEventsToTarget(window); | 473 CancelPointerEventsToTarget(window); |
| 421 | 474 |
| 422 if (mouse_cursor_source_window_ == window) | 475 if (mouse_cursor_source_window_ == window) |
| 423 mouse_cursor_source_window_ = nullptr; | 476 mouse_cursor_source_window_ = nullptr; |
| 424 } | 477 } |
| 425 | 478 |
| 426 } // namespace ws | 479 } // namespace ws |
| 427 } // namespace mus | 480 } // namespace mus |
| OLD | NEW |