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

Side by Side Diff: services/ui/ws/event_dispatcher.cc

Issue 2778943005: Keep root_location to be in pixels and display coordinates in WS. (Closed)
Patch Set: . Created 3 years, 7 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 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 "services/ui/ws/event_dispatcher.h" 5 #include "services/ui/ws/event_dispatcher.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "base/time/time.h" 10 #include "base/time/time.h"
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 CancelPointerEventsToTarget(capture_window_); 69 CancelPointerEventsToTarget(capture_window_);
70 DCHECK(capture_window_ == nullptr); 70 DCHECK(capture_window_ == nullptr);
71 } 71 }
72 72
73 while (!pointer_targets_.empty()) 73 while (!pointer_targets_.empty())
74 StopTrackingPointer(pointer_targets_.begin()->first); 74 StopTrackingPointer(pointer_targets_.begin()->first);
75 75
76 mouse_button_down_ = false; 76 mouse_button_down_ = false;
77 } 77 }
78 78
79 void EventDispatcher::SetMousePointerScreenLocation( 79 void EventDispatcher::SetMousePointerDisplayLocationAndId(
80 const gfx::Point& screen_location) { 80 const gfx::Point& display_location,
81 const int64_t display_id) {
81 DCHECK(pointer_targets_.empty()); 82 DCHECK(pointer_targets_.empty());
82 mouse_pointer_last_location_ = screen_location; 83 mouse_pointer_last_location_ = display_location;
84 mouse_pointer_display_id_ = display_id;
83 UpdateCursorProviderByLastKnownLocation(); 85 UpdateCursorProviderByLastKnownLocation();
84 // Write our initial location back to our shared screen coordinate. This 86 // Write our initial location back to our shared screen coordinate. This
85 // shouldn't cause problems because we already read the cursor before we 87 // shouldn't cause problems because we already read the cursor before we
86 // process any events in views during window construction. 88 // process any events in views during window construction.
87 delegate_->OnMouseCursorLocationChanged(screen_location); 89 delegate_->OnMouseCursorLocationChanged(display_location, display_id);
88 } 90 }
89 91
90 ui::CursorData EventDispatcher::GetCurrentMouseCursor() const { 92 ui::CursorData EventDispatcher::GetCurrentMouseCursor() const {
91 if (drag_controller_) 93 if (drag_controller_)
92 return drag_controller_->current_cursor(); 94 return drag_controller_->current_cursor();
93 95
94 if (!mouse_cursor_source_window_) 96 if (!mouse_cursor_source_window_)
95 return ui::CursorData(ui::CursorType::kPointer); 97 return ui::CursorData(ui::CursorType::kPointer);
96 98
97 if (mouse_cursor_in_non_client_area_) 99 if (mouse_cursor_in_non_client_area_)
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 const ClientSpecificId target_client_id = delegate_->GetEventTargetClientId( 214 const ClientSpecificId target_client_id = delegate_->GetEventTargetClientId(
213 mouse_cursor_source_window_, mouse_cursor_in_non_client_area_); 215 mouse_cursor_source_window_, mouse_cursor_in_non_client_area_);
214 const ServerWindow* window = mouse_cursor_source_window_; 216 const ServerWindow* window = mouse_cursor_source_window_;
215 while (window && window->id().client_id == target_client_id) 217 while (window && window->id().client_id == target_client_id)
216 window = window->parent(); 218 window = window->parent();
217 return window; 219 return window;
218 } 220 }
219 221
220 void EventDispatcher::UpdateNonClientAreaForCurrentWindow() { 222 void EventDispatcher::UpdateNonClientAreaForCurrentWindow() {
221 if (mouse_cursor_source_window_) { 223 if (mouse_cursor_source_window_) {
222 DeepestWindow deepest_window = 224 DeepestWindow deepest_window = FindDeepestVisibleWindowForEvents(
223 FindDeepestVisibleWindowForEvents(mouse_pointer_last_location_); 225 &mouse_pointer_last_location_, &mouse_pointer_display_id_);
224 if (deepest_window.window == mouse_cursor_source_window_) { 226 if (deepest_window.window == mouse_cursor_source_window_) {
225 mouse_cursor_in_non_client_area_ = mouse_cursor_source_window_ 227 mouse_cursor_in_non_client_area_ = mouse_cursor_source_window_
226 ? deepest_window.in_non_client_area 228 ? deepest_window.in_non_client_area
227 : false; 229 : false;
228 } 230 }
229 } 231 }
230 } 232 }
231 233
232 void EventDispatcher::UpdateCursorProviderByLastKnownLocation() { 234 void EventDispatcher::UpdateCursorProviderByLastKnownLocation() {
233 if (!mouse_button_down_) { 235 if (!mouse_button_down_) {
234 DeepestWindow deepest_window = 236 DeepestWindow deepest_window = FindDeepestVisibleWindowForEvents(
235 FindDeepestVisibleWindowForEvents(mouse_pointer_last_location_); 237 &mouse_pointer_last_location_, &mouse_pointer_display_id_);
236 SetMouseCursorSourceWindow(deepest_window.window); 238 SetMouseCursorSourceWindow(deepest_window.window);
237 if (mouse_cursor_source_window_) { 239 if (mouse_cursor_source_window_) {
238 mouse_cursor_in_non_client_area_ = deepest_window.in_non_client_area; 240 mouse_cursor_in_non_client_area_ = deepest_window.in_non_client_area;
239 } else { 241 } else {
240 gfx::Point location = mouse_pointer_last_location_; 242 SetMouseCursorSourceWindow(delegate_->GetRootWindowContaining(
241 SetMouseCursorSourceWindow(delegate_->GetRootWindowContaining(&location)); 243 &mouse_pointer_last_location_, &mouse_pointer_display_id_));
242 mouse_cursor_in_non_client_area_ = true; 244 mouse_cursor_in_non_client_area_ = true;
243 } 245 }
244 } 246 }
245 } 247 }
246 248
247 bool EventDispatcher::AddAccelerator(uint32_t id, 249 bool EventDispatcher::AddAccelerator(uint32_t id,
248 mojom::EventMatcherPtr event_matcher) { 250 mojom::EventMatcherPtr event_matcher) {
249 std::unique_ptr<Accelerator> accelerator(new Accelerator(id, *event_matcher)); 251 std::unique_ptr<Accelerator> accelerator(new Accelerator(id, *event_matcher));
250 // If an accelerator with the same id or matcher already exists, then abort. 252 // If an accelerator with the same id or matcher already exists, then abort.
251 for (const auto& pair : accelerators_) { 253 for (const auto& pair : accelerators_) {
(...skipping 14 matching lines...) Expand all
266 } 268 }
267 269
268 void EventDispatcher::RemoveAccelerator(uint32_t id) { 270 void EventDispatcher::RemoveAccelerator(uint32_t id) {
269 auto it = accelerators_.find(id); 271 auto it = accelerators_.find(id);
270 // Clients may pass bogus ids. 272 // Clients may pass bogus ids.
271 if (it != accelerators_.end()) 273 if (it != accelerators_.end())
272 accelerators_.erase(it); 274 accelerators_.erase(it);
273 } 275 }
274 276
275 void EventDispatcher::ProcessEvent(const ui::Event& event, 277 void EventDispatcher::ProcessEvent(const ui::Event& event,
278 const int64_t display_id,
276 AcceleratorMatchPhase match_phase) { 279 AcceleratorMatchPhase match_phase) {
277 #if !defined(NDEBUG) 280 #if !defined(NDEBUG)
278 if (match_phase == AcceleratorMatchPhase::POST_ONLY) { 281 if (match_phase == AcceleratorMatchPhase::POST_ONLY) {
279 // POST_ONLY should always be preceeded by ANY with the same event. 282 // POST_ONLY should always be preceeded by ANY with the same event.
280 DCHECK(previous_event_); 283 DCHECK(previous_event_);
281 // Event doesn't define ==, so this compares the key fields. 284 // Event doesn't define ==, so this compares the key fields.
282 DCHECK(event.type() == previous_event_->type() && 285 DCHECK(event.type() == previous_event_->type() &&
283 event.time_stamp() == previous_event_->time_stamp() && 286 event.time_stamp() == previous_event_->time_stamp() &&
284 event.flags() == previous_event_->flags()); 287 event.flags() == previous_event_->flags());
285 DCHECK_EQ(previous_accelerator_match_phase_, AcceleratorMatchPhase::ANY); 288 DCHECK_EQ(previous_accelerator_match_phase_, AcceleratorMatchPhase::ANY);
(...skipping 11 matching lines...) Expand all
297 pre_target->id(), event, 300 pre_target->id(), event,
298 EventDispatcherDelegate::AcceleratorPhase::PRE); 301 EventDispatcherDelegate::AcceleratorPhase::PRE);
299 return; 302 return;
300 } 303 }
301 } 304 }
302 ProcessKeyEvent(*key_event, match_phase); 305 ProcessKeyEvent(*key_event, match_phase);
303 return; 306 return;
304 } 307 }
305 308
306 DCHECK(event.IsPointerEvent()); 309 DCHECK(event.IsPointerEvent());
307 ProcessPointerEvent(*event.AsPointerEvent()); 310 ProcessPointerEvent(*event.AsPointerEvent(), display_id);
308 return; 311 return;
309 } 312 }
310 313
311 void EventDispatcher::SetMouseCursorSourceWindow(ServerWindow* window) { 314 void EventDispatcher::SetMouseCursorSourceWindow(ServerWindow* window) {
312 if (mouse_cursor_source_window_ == window) 315 if (mouse_cursor_source_window_ == window)
313 return; 316 return;
314 317
315 if (mouse_cursor_source_window_) 318 if (mouse_cursor_source_window_)
316 UnobserveWindow(mouse_cursor_source_window_); 319 UnobserveWindow(mouse_cursor_source_window_);
317 mouse_cursor_source_window_ = window; 320 mouse_cursor_source_window_ = window;
(...skipping 20 matching lines...) Expand all
338 delegate_->DispatchInputEventToWindow(focused_window, client_id, event, 341 delegate_->DispatchInputEventToWindow(focused_window, client_id, event,
339 post_target); 342 post_target);
340 return; 343 return;
341 } 344 }
342 delegate_->OnEventTargetNotFound(event); 345 delegate_->OnEventTargetNotFound(event);
343 if (post_target) 346 if (post_target)
344 delegate_->OnAccelerator(post_target->id(), event, 347 delegate_->OnAccelerator(post_target->id(), event,
345 EventDispatcherDelegate::AcceleratorPhase::POST); 348 EventDispatcherDelegate::AcceleratorPhase::POST);
346 } 349 }
347 350
348 void EventDispatcher::ProcessPointerEvent(const ui::PointerEvent& event) { 351 void EventDispatcher::ProcessPointerEvent(const ui::PointerEvent& event,
352 const int64_t display_id) {
349 DCHECK(event.IsPointerEvent()); 353 DCHECK(event.IsPointerEvent());
354 event_display_id_ = display_id;
350 const bool is_mouse_event = event.IsMousePointerEvent(); 355 const bool is_mouse_event = event.IsMousePointerEvent();
351 356
352 if (is_mouse_event) { 357 if (is_mouse_event) {
353 mouse_pointer_last_location_ = event.root_location(); 358 mouse_pointer_last_location_ = event.root_location();
354 delegate_->OnMouseCursorLocationChanged(event.root_location()); 359 mouse_pointer_display_id_ = display_id;
360 delegate_->OnMouseCursorLocationChanged(event.root_location(), display_id);
355 } 361 }
356 362
357 // Release capture on pointer up. For mouse we only release if there are 363 // Release capture on pointer up. For mouse we only release if there are
358 // no buttons down. 364 // no buttons down.
359 const bool is_pointer_going_up = 365 const bool is_pointer_going_up =
360 (event.type() == ui::ET_POINTER_UP || 366 (event.type() == ui::ET_POINTER_UP ||
361 event.type() == ui::ET_POINTER_CANCELLED) && 367 event.type() == ui::ET_POINTER_CANCELLED) &&
362 (!is_mouse_event || IsOnlyOneMouseButtonDown(event.flags())); 368 (!is_mouse_event || IsOnlyOneMouseButtonDown(event.flags()));
363 369
364 // Update mouse down state upon events which change it. 370 // Update mouse down state upon events which change it.
(...skipping 27 matching lines...) Expand all
392 PointerTarget& pointer_target = pointer_targets_[pointer_id]; 398 PointerTarget& pointer_target = pointer_targets_[pointer_id];
393 if (pointer_target.is_pointer_down) { 399 if (pointer_target.is_pointer_down) {
394 if (is_mouse_event) 400 if (is_mouse_event)
395 SetMouseCursorSourceWindow(pointer_target.window); 401 SetMouseCursorSourceWindow(pointer_target.window);
396 if (!any_pointers_down) { 402 if (!any_pointers_down) {
397 if (pointer_target.window) 403 if (pointer_target.window)
398 delegate_->SetFocusedWindowFromEventDispatcher(pointer_target.window); 404 delegate_->SetFocusedWindowFromEventDispatcher(pointer_target.window);
399 ServerWindow* capture_window = pointer_target.window; 405 ServerWindow* capture_window = pointer_target.window;
400 if (!capture_window) { 406 if (!capture_window) {
401 gfx::Point event_location = event.root_location(); 407 gfx::Point event_location = event.root_location();
402 capture_window = delegate_->GetRootWindowContaining(&event_location); 408 capture_window = delegate_->GetRootWindowContaining(
409 &event_location, &event_display_id_);
403 } 410 }
404 delegate_->SetNativeCapture(capture_window); 411 delegate_->SetNativeCapture(capture_window);
405 } 412 }
406 } 413 }
407 } 414 }
408 415
409 // When we release the mouse button, we want the cursor to be sourced from 416 // When we release the mouse button, we want the cursor to be sourced from
410 // the window under the mouse pointer, even though we're sending the button 417 // the window under the mouse pointer, even though we're sending the button
411 // up event to the window that had implicit capture. We have to set this 418 // up event to the window that had implicit capture. We have to set this
412 // before we perform dispatch because the Delegate is going to read this 419 // before we perform dispatch because the Delegate is going to read this
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 481
475 // Technically we're updating in place, but calling start then stop makes for 482 // Technically we're updating in place, but calling start then stop makes for
476 // simpler code. 483 // simpler code.
477 StopTrackingPointer(pointer_id); 484 StopTrackingPointer(pointer_id);
478 StartTrackingPointer(pointer_id, pointer_target); 485 StartTrackingPointer(pointer_id, pointer_target);
479 } 486 }
480 487
481 EventDispatcher::PointerTarget EventDispatcher::PointerTargetForEvent( 488 EventDispatcher::PointerTarget EventDispatcher::PointerTargetForEvent(
482 const ui::LocatedEvent& event) { 489 const ui::LocatedEvent& event) {
483 PointerTarget pointer_target; 490 PointerTarget pointer_target;
484 DeepestWindow deepest_window = 491 gfx::Point event_root_location(event.root_location());
485 FindDeepestVisibleWindowForEvents(event.root_location()); 492 DeepestWindow deepest_window = FindDeepestVisibleWindowForEvents(
493 &event_root_location, &event_display_id_);
486 pointer_target.window = 494 pointer_target.window =
487 modal_window_controller_.GetTargetForWindow(deepest_window.window); 495 modal_window_controller_.GetTargetForWindow(deepest_window.window);
488 pointer_target.is_mouse_event = event.IsMousePointerEvent(); 496 pointer_target.is_mouse_event = event.IsMousePointerEvent();
489 pointer_target.in_nonclient_area = 497 pointer_target.in_nonclient_area =
490 deepest_window.window != pointer_target.window || 498 deepest_window.window != pointer_target.window ||
491 !pointer_target.window || deepest_window.in_non_client_area; 499 !pointer_target.window || deepest_window.in_non_client_area;
492 pointer_target.is_pointer_down = event.type() == ui::ET_POINTER_DOWN; 500 pointer_target.is_pointer_down = event.type() == ui::ET_POINTER_DOWN;
493 return pointer_target; 501 return pointer_target;
494 } 502 }
495 503
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
574 const ui::KeyEvent& event, 582 const ui::KeyEvent& event,
575 const ui::mojom::AcceleratorPhase phase) { 583 const ui::mojom::AcceleratorPhase phase) {
576 for (const auto& pair : accelerators_) { 584 for (const auto& pair : accelerators_) {
577 if (pair.second->MatchesEvent(event, phase)) 585 if (pair.second->MatchesEvent(event, phase))
578 return pair.second.get(); 586 return pair.second.get();
579 } 587 }
580 return nullptr; 588 return nullptr;
581 } 589 }
582 590
583 DeepestWindow EventDispatcher::FindDeepestVisibleWindowForEvents( 591 DeepestWindow EventDispatcher::FindDeepestVisibleWindowForEvents(
584 const gfx::Point& location) { 592 gfx::Point* location,
585 gfx::Point relative_location(location); 593 int64_t* display_id) {
586 // For the case of no root. 594 ServerWindow* root = delegate_->GetRootWindowContaining(location, display_id);
587 ServerWindow* root = delegate_->GetRootWindowContaining(&relative_location); 595 return root ? ui::ws::FindDeepestVisibleWindowForEvents(root, *location)
588 return root ? ui::ws::FindDeepestVisibleWindowForEvents(root,
589 relative_location)
590 : DeepestWindow(); 596 : DeepestWindow();
591 } 597 }
592 598
593 void EventDispatcher::CancelImplicitCaptureExcept(ServerWindow* window, 599 void EventDispatcher::CancelImplicitCaptureExcept(ServerWindow* window,
594 ClientSpecificId client_id) { 600 ClientSpecificId client_id) {
595 for (const auto& pair : pointer_targets_) { 601 for (const auto& pair : pointer_targets_) {
596 ServerWindow* target = pair.second.window; 602 ServerWindow* target = pair.second.window;
597 if (!target) 603 if (!target)
598 continue; 604 continue;
599 UnobserveWindow(target); 605 UnobserveWindow(target);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
653 if (mouse_cursor_source_window_ == window) 659 if (mouse_cursor_source_window_ == window)
654 SetMouseCursorSourceWindow(nullptr); 660 SetMouseCursorSourceWindow(nullptr);
655 } 661 }
656 662
657 void EventDispatcher::OnDragCursorUpdated() { 663 void EventDispatcher::OnDragCursorUpdated() {
658 delegate_->UpdateNativeCursorFromDispatcher(); 664 delegate_->UpdateNativeCursorFromDispatcher();
659 } 665 }
660 666
661 } // namespace ws 667 } // namespace ws
662 } // namespace ui 668 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698