| 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 "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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 } | 73 } |
| 74 | 74 |
| 75 while (!pointer_targets_.empty()) | 75 while (!pointer_targets_.empty()) |
| 76 StopTrackingPointer(pointer_targets_.begin()->first); | 76 StopTrackingPointer(pointer_targets_.begin()->first); |
| 77 | 77 |
| 78 mouse_button_down_ = false; | 78 mouse_button_down_ = false; |
| 79 } | 79 } |
| 80 | 80 |
| 81 void EventDispatcher::SetMousePointerDisplayLocation( | 81 void EventDispatcher::SetMousePointerDisplayLocation( |
| 82 const gfx::Point& display_location, | 82 const gfx::Point& display_location, |
| 83 const int64_t display_id) { | 83 int64_t display_id) { |
| 84 DCHECK(pointer_targets_.empty()); | 84 DCHECK(pointer_targets_.empty()); |
| 85 mouse_pointer_last_location_ = display_location; | 85 SetMousePointerLocation(display_location, display_id); |
| 86 mouse_pointer_display_id_ = display_id; | |
| 87 UpdateCursorProviderByLastKnownLocation(); | 86 UpdateCursorProviderByLastKnownLocation(); |
| 88 // Write our initial location back to our shared screen coordinate. This | 87 // Write our initial location back to our shared screen coordinate. This |
| 89 // shouldn't cause problems because we already read the cursor before we | 88 // shouldn't cause problems because we already read the cursor before we |
| 90 // process any events in views during window construction. | 89 // process any events in views during window construction. |
| 91 delegate_->OnMouseCursorLocationChanged(display_location, display_id); | 90 delegate_->OnMouseCursorLocationChanged(display_location, display_id); |
| 92 } | 91 } |
| 93 | 92 |
| 94 ui::CursorData EventDispatcher::GetCurrentMouseCursor() const { | 93 ui::CursorData EventDispatcher::GetCurrentMouseCursor() const { |
| 95 if (drag_controller_) | 94 if (drag_controller_) |
| 96 return drag_controller_->current_cursor(); | 95 return drag_controller_->current_cursor(); |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 const ClientSpecificId target_client_id = delegate_->GetEventTargetClientId( | 215 const ClientSpecificId target_client_id = delegate_->GetEventTargetClientId( |
| 217 mouse_cursor_source_window_, mouse_cursor_in_non_client_area_); | 216 mouse_cursor_source_window_, mouse_cursor_in_non_client_area_); |
| 218 const ServerWindow* window = mouse_cursor_source_window_; | 217 const ServerWindow* window = mouse_cursor_source_window_; |
| 219 while (window && window->id().client_id == target_client_id) | 218 while (window && window->id().client_id == target_client_id) |
| 220 window = window->parent(); | 219 window = window->parent(); |
| 221 return window; | 220 return window; |
| 222 } | 221 } |
| 223 | 222 |
| 224 void EventDispatcher::UpdateNonClientAreaForCurrentWindow() { | 223 void EventDispatcher::UpdateNonClientAreaForCurrentWindow() { |
| 225 if (mouse_cursor_source_window_) { | 224 if (mouse_cursor_source_window_) { |
| 226 DeepestWindow deepest_window = | 225 event_targeter_->FindDeepestVisibleWindowForLocation( |
| 227 event_targeter_->FindDeepestVisibleWindowForEvents( | 226 mouse_pointer_last_location_, mouse_pointer_display_id_, |
| 228 &mouse_pointer_last_location_, &mouse_pointer_display_id_); | 227 base::BindOnce( |
| 229 if (deepest_window.window == mouse_cursor_source_window_) { | 228 &EventDispatcher::UpdateNonClientAreaForCurrentWindowOnFoundWindow, |
| 230 mouse_cursor_in_non_client_area_ = mouse_cursor_source_window_ | 229 base::Unretained(this))); |
| 231 ? deepest_window.in_non_client_area | |
| 232 : false; | |
| 233 } | |
| 234 } | 230 } |
| 235 } | 231 } |
| 236 | 232 |
| 237 void EventDispatcher::UpdateCursorProviderByLastKnownLocation() { | 233 void EventDispatcher::UpdateCursorProviderByLastKnownLocation() { |
| 238 if (!mouse_button_down_) { | 234 if (!mouse_button_down_) { |
| 239 DeepestWindow deepest_window = | 235 event_targeter_->FindDeepestVisibleWindowForLocation( |
| 240 event_targeter_->FindDeepestVisibleWindowForEvents( | 236 mouse_pointer_last_location_, mouse_pointer_display_id_, |
| 241 &mouse_pointer_last_location_, &mouse_pointer_display_id_); | 237 base::BindOnce(&EventDispatcher:: |
| 242 SetMouseCursorSourceWindow(deepest_window.window); | 238 UpdateCursorProviderByLastKnownLocationOnFoundWindow, |
| 243 if (mouse_cursor_source_window_) { | 239 base::Unretained(this))); |
| 244 mouse_cursor_in_non_client_area_ = deepest_window.in_non_client_area; | |
| 245 } else { | |
| 246 SetMouseCursorSourceWindow(delegate_->GetRootWindowContaining( | |
| 247 &mouse_pointer_last_location_, &mouse_pointer_display_id_)); | |
| 248 mouse_cursor_in_non_client_area_ = true; | |
| 249 } | |
| 250 } | 240 } |
| 251 } | 241 } |
| 252 | 242 |
| 253 bool EventDispatcher::AddAccelerator(uint32_t id, | 243 bool EventDispatcher::AddAccelerator(uint32_t id, |
| 254 mojom::EventMatcherPtr event_matcher) { | 244 mojom::EventMatcherPtr event_matcher) { |
| 255 std::unique_ptr<Accelerator> accelerator(new Accelerator(id, *event_matcher)); | 245 std::unique_ptr<Accelerator> accelerator(new Accelerator(id, *event_matcher)); |
| 256 // If an accelerator with the same id or matcher already exists, then abort. | 246 // If an accelerator with the same id or matcher already exists, then abort. |
| 257 for (const auto& pair : accelerators_) { | 247 for (const auto& pair : accelerators_) { |
| 258 if (pair.first == id) { | 248 if (pair.first == id) { |
| 259 DVLOG(1) << "duplicate accelerator. Accelerator id=" << accelerator->id() | 249 DVLOG(1) << "duplicate accelerator. Accelerator id=" << accelerator->id() |
| (...skipping 12 matching lines...) Expand all Loading... |
| 272 } | 262 } |
| 273 | 263 |
| 274 void EventDispatcher::RemoveAccelerator(uint32_t id) { | 264 void EventDispatcher::RemoveAccelerator(uint32_t id) { |
| 275 auto it = accelerators_.find(id); | 265 auto it = accelerators_.find(id); |
| 276 // Clients may pass bogus ids. | 266 // Clients may pass bogus ids. |
| 277 if (it != accelerators_.end()) | 267 if (it != accelerators_.end()) |
| 278 accelerators_.erase(it); | 268 accelerators_.erase(it); |
| 279 } | 269 } |
| 280 | 270 |
| 281 void EventDispatcher::ProcessEvent(const ui::Event& event, | 271 void EventDispatcher::ProcessEvent(const ui::Event& event, |
| 282 const int64_t display_id, | 272 int64_t display_id, |
| 283 AcceleratorMatchPhase match_phase) { | 273 AcceleratorMatchPhase match_phase) { |
| 284 #if !defined(NDEBUG) | 274 #if !defined(NDEBUG) |
| 285 if (match_phase == AcceleratorMatchPhase::POST_ONLY) { | 275 if (match_phase == AcceleratorMatchPhase::POST_ONLY) { |
| 286 // POST_ONLY should always be preceeded by ANY with the same event. | 276 // POST_ONLY should always be preceeded by ANY with the same event. |
| 287 DCHECK(previous_event_); | 277 DCHECK(previous_event_); |
| 288 // Event doesn't define ==, so this compares the key fields. | 278 // Event doesn't define ==, so this compares the key fields. |
| 289 DCHECK(event.type() == previous_event_->type() && | 279 DCHECK(event.type() == previous_event_->type() && |
| 290 event.time_stamp() == previous_event_->time_stamp() && | 280 event.time_stamp() == previous_event_->time_stamp() && |
| 291 event.flags() == previous_event_->flags()); | 281 event.flags() == previous_event_->flags()); |
| 292 DCHECK_EQ(previous_accelerator_match_phase_, AcceleratorMatchPhase::ANY); | 282 DCHECK_EQ(previous_accelerator_match_phase_, AcceleratorMatchPhase::ANY); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 305 pre_target->id(), event_display_id_, event, | 295 pre_target->id(), event_display_id_, event, |
| 306 EventDispatcherDelegate::AcceleratorPhase::PRE); | 296 EventDispatcherDelegate::AcceleratorPhase::PRE); |
| 307 return; | 297 return; |
| 308 } | 298 } |
| 309 } | 299 } |
| 310 ProcessKeyEvent(*key_event, match_phase); | 300 ProcessKeyEvent(*key_event, match_phase); |
| 311 return; | 301 return; |
| 312 } | 302 } |
| 313 | 303 |
| 314 DCHECK(event.IsPointerEvent()); | 304 DCHECK(event.IsPointerEvent()); |
| 315 ProcessPointerEvent(*event.AsPointerEvent()); | 305 event_targeter_->PointerTargetForEvent( |
| 316 return; | 306 *event.AsPointerEvent(), event_display_id_, |
| 307 base::BindOnce(&EventDispatcher::ProcessPointerEventOnFoundTarget, |
| 308 base::Unretained(this), *event.AsPointerEvent())); |
| 317 } | 309 } |
| 318 | 310 |
| 319 ServerWindow* EventDispatcher::GetRootWindowContaining( | 311 ServerWindow* EventDispatcher::GetRootWindowContaining( |
| 320 gfx::Point* location_in_display, | 312 gfx::Point* location_in_display, |
| 321 int64_t* display_id) { | 313 int64_t* display_id) { |
| 322 return delegate_->GetRootWindowContaining(location_in_display, display_id); | 314 return delegate_->GetRootWindowContaining(location_in_display, display_id); |
| 323 } | 315 } |
| 324 | 316 |
| 317 void EventDispatcher::ProcessNextEventFromQueue() { |
| 318 delegate_->ProcessNextEventFromQueue(); |
| 319 } |
| 320 |
| 325 void EventDispatcher::SetMouseCursorSourceWindow(ServerWindow* window) { | 321 void EventDispatcher::SetMouseCursorSourceWindow(ServerWindow* window) { |
| 326 if (mouse_cursor_source_window_ == window) | 322 if (mouse_cursor_source_window_ == window) |
| 327 return; | 323 return; |
| 328 | 324 |
| 329 if (mouse_cursor_source_window_) | 325 if (mouse_cursor_source_window_) |
| 330 UnobserveWindow(mouse_cursor_source_window_); | 326 UnobserveWindow(mouse_cursor_source_window_); |
| 331 mouse_cursor_source_window_ = window; | 327 mouse_cursor_source_window_ = window; |
| 332 if (mouse_cursor_source_window_) | 328 if (mouse_cursor_source_window_) |
| 333 ObserveWindow(mouse_cursor_source_window_); | 329 ObserveWindow(mouse_cursor_source_window_); |
| 334 } | 330 } |
| 335 | 331 |
| 332 void EventDispatcher::SetMousePointerLocation( |
| 333 const gfx::Point& new_mouse_location, |
| 334 int64_t new_mouse_display_id) { |
| 335 mouse_pointer_last_location_ = new_mouse_location; |
| 336 mouse_pointer_display_id_ = new_mouse_display_id; |
| 337 } |
| 338 |
| 336 void EventDispatcher::ProcessKeyEvent(const ui::KeyEvent& event, | 339 void EventDispatcher::ProcessKeyEvent(const ui::KeyEvent& event, |
| 337 AcceleratorMatchPhase match_phase) { | 340 AcceleratorMatchPhase match_phase) { |
| 338 Accelerator* post_target = | 341 Accelerator* post_target = |
| 339 FindAccelerator(event, ui::mojom::AcceleratorPhase::POST_TARGET); | 342 FindAccelerator(event, ui::mojom::AcceleratorPhase::POST_TARGET); |
| 340 if (drag_controller_ && event.type() == ui::ET_KEY_PRESSED && | 343 if (drag_controller_ && event.type() == ui::ET_KEY_PRESSED && |
| 341 event.key_code() == ui::VKEY_ESCAPE) { | 344 event.key_code() == ui::VKEY_ESCAPE) { |
| 342 drag_controller_->Cancel(); | 345 drag_controller_->Cancel(); |
| 343 return; | 346 return; |
| 344 } | 347 } |
| 345 ServerWindow* focused_window = | 348 ServerWindow* focused_window = |
| 346 delegate_->GetFocusedWindowForEventDispatcher(event_display_id_); | 349 delegate_->GetFocusedWindowForEventDispatcher(event_display_id_); |
| 347 if (focused_window) { | 350 if (focused_window) { |
| 348 // Assume key events are for the client area. | 351 // Assume key events are for the client area. |
| 349 const bool in_nonclient_area = false; | 352 const bool in_nonclient_area = false; |
| 350 const ClientSpecificId client_id = | 353 const ClientSpecificId client_id = |
| 351 delegate_->GetEventTargetClientId(focused_window, in_nonclient_area); | 354 delegate_->GetEventTargetClientId(focused_window, in_nonclient_area); |
| 352 delegate_->DispatchInputEventToWindow( | 355 delegate_->DispatchInputEventToWindow( |
| 353 focused_window, client_id, event_display_id_, event, post_target); | 356 focused_window, client_id, event_display_id_, event, post_target); |
| 354 return; | 357 return; |
| 355 } | 358 } |
| 356 delegate_->OnEventTargetNotFound(event, event_display_id_); | 359 delegate_->OnEventTargetNotFound(event, event_display_id_); |
| 357 if (post_target) | 360 if (post_target) |
| 358 delegate_->OnAccelerator(post_target->id(), event_display_id_, event, | 361 delegate_->OnAccelerator(post_target->id(), event_display_id_, event, |
| 359 EventDispatcherDelegate::AcceleratorPhase::POST); | 362 EventDispatcherDelegate::AcceleratorPhase::POST); |
| 360 } | 363 } |
| 361 | 364 |
| 362 void EventDispatcher::ProcessPointerEvent(const ui::PointerEvent& event) { | 365 void EventDispatcher::ProcessPointerEventOnFoundTarget( |
| 363 DCHECK(event.IsPointerEvent()); | 366 const ui::PointerEvent& event, |
| 367 const PointerTarget& pointer_target, |
| 368 const DeepestWindow& deepest_window, |
| 369 const gfx::Point& location_in_display, |
| 370 int64_t display_id) { |
| 371 std::unique_ptr<ui::Event> cloned_event = ui::Event::Clone(event); |
| 372 if (display_id != event_display_id_) { |
| 373 event_display_id_ = display_id; |
| 374 cloned_event->AsLocatedEvent()->set_root_location(location_in_display); |
| 375 } |
| 376 |
| 364 const bool is_mouse_event = event.IsMousePointerEvent(); | 377 const bool is_mouse_event = event.IsMousePointerEvent(); |
| 365 | 378 |
| 366 if (is_mouse_event) { | 379 if (is_mouse_event) { |
| 367 mouse_pointer_last_location_ = event.root_location(); | 380 SetMousePointerLocation(location_in_display, display_id); |
| 368 mouse_pointer_display_id_ = event_display_id_; | 381 delegate_->OnMouseCursorLocationChanged(location_in_display, display_id); |
| 369 delegate_->OnMouseCursorLocationChanged(event.root_location(), | |
| 370 event_display_id_); | |
| 371 } | 382 } |
| 372 | 383 |
| 373 // Release capture on pointer up. For mouse we only release if there are | 384 // Release capture on pointer up. For mouse we only release if there are |
| 374 // no buttons down. | 385 // no buttons down. |
| 375 const bool is_pointer_going_up = | 386 const bool is_pointer_going_up = |
| 376 (event.type() == ui::ET_POINTER_UP || | 387 (event.type() == ui::ET_POINTER_UP || |
| 377 event.type() == ui::ET_POINTER_CANCELLED) && | 388 event.type() == ui::ET_POINTER_CANCELLED) && |
| 378 (!is_mouse_event || IsOnlyOneMouseButtonDown(event.flags())); | 389 (!is_mouse_event || IsOnlyOneMouseButtonDown(event.flags())); |
| 379 | 390 |
| 380 // Update mouse down state upon events which change it. | 391 // Update mouse down state upon events which change it. |
| 381 if (is_mouse_event) { | 392 if (is_mouse_event) { |
| 382 if (event.type() == ui::ET_POINTER_DOWN) | 393 if (event.type() == ui::ET_POINTER_DOWN) |
| 383 mouse_button_down_ = true; | 394 mouse_button_down_ = true; |
| 384 else if (is_pointer_going_up) | 395 else if (is_pointer_going_up) |
| 385 mouse_button_down_ = false; | 396 mouse_button_down_ = false; |
| 386 } | 397 } |
| 387 | 398 |
| 388 if (drag_controller_) { | 399 if (drag_controller_) { |
| 389 const PointerTarget target = | 400 if (drag_controller_->DispatchPointerEvent(*cloned_event->AsPointerEvent(), |
| 390 event_targeter_->PointerTargetForEvent(event, &event_display_id_); | 401 pointer_target.window)) |
| 391 if (drag_controller_->DispatchPointerEvent(event, target.window)) | |
| 392 return; | 402 return; |
| 393 } | 403 } |
| 394 | 404 |
| 395 if (capture_window_) { | 405 if (capture_window_) { |
| 396 SetMouseCursorSourceWindow(capture_window_); | 406 SetMouseCursorSourceWindow(capture_window_); |
| 397 DispatchToClient(capture_window_, capture_window_client_id_, event); | 407 DispatchToClient(capture_window_, capture_window_client_id_, |
| 408 *cloned_event->AsPointerEvent()); |
| 398 return; | 409 return; |
| 399 } | 410 } |
| 400 | 411 |
| 401 const int32_t pointer_id = event.pointer_details().id; | 412 const int32_t pointer_id = event.pointer_details().id; |
| 402 if (!IsTrackingPointer(pointer_id) || | 413 if (!IsTrackingPointer(pointer_id) || |
| 403 !pointer_targets_[pointer_id].is_pointer_down) { | 414 !pointer_targets_[pointer_id].is_pointer_down) { |
| 404 const bool any_pointers_down = AreAnyPointersDown(); | 415 const bool any_pointers_down = AreAnyPointersDown(); |
| 405 UpdateTargetForPointer(pointer_id, event); | 416 UpdateTargetForPointer(pointer_id, *cloned_event->AsPointerEvent(), |
| 417 pointer_target); |
| 406 if (is_mouse_event) | 418 if (is_mouse_event) |
| 407 SetMouseCursorSourceWindow(pointer_targets_[pointer_id].window); | 419 SetMouseCursorSourceWindow(pointer_targets_[pointer_id].window); |
| 408 | 420 |
| 409 PointerTarget& pointer_target = pointer_targets_[pointer_id]; | 421 PointerTarget& pointer_target = pointer_targets_[pointer_id]; |
| 410 if (pointer_target.is_pointer_down) { | 422 if (pointer_target.is_pointer_down) { |
| 411 if (is_mouse_event) | 423 if (is_mouse_event) |
| 412 SetMouseCursorSourceWindow(pointer_target.window); | 424 SetMouseCursorSourceWindow(pointer_target.window); |
| 413 if (!any_pointers_down) { | 425 if (!any_pointers_down) { |
| 414 if (pointer_target.window) | 426 if (pointer_target.window) |
| 415 delegate_->SetFocusedWindowFromEventDispatcher(pointer_target.window); | 427 delegate_->SetFocusedWindowFromEventDispatcher(pointer_target.window); |
| 416 ServerWindow* capture_window = pointer_target.window; | 428 ServerWindow* capture_window = pointer_target.window; |
| 417 if (!capture_window) { | 429 if (!capture_window) { |
| 418 gfx::Point event_location = event.root_location(); | 430 gfx::Point event_location = |
| 431 cloned_event->AsPointerEvent()->root_location(); |
| 419 int64_t event_display_id = event_display_id_; | 432 int64_t event_display_id = event_display_id_; |
| 420 capture_window = delegate_->GetRootWindowContaining( | 433 capture_window = delegate_->GetRootWindowContaining( |
| 421 &event_location, &event_display_id); | 434 &event_location, &event_display_id); |
| 422 } | 435 } |
| 423 delegate_->SetNativeCapture(capture_window); | 436 delegate_->SetNativeCapture(capture_window); |
| 424 } | 437 } |
| 425 } | 438 } |
| 426 } | 439 } |
| 427 | 440 |
| 428 // When we release the mouse button, we want the cursor to be sourced from | 441 // When we release the mouse button, we want the cursor to be sourced from |
| 429 // the window under the mouse pointer, even though we're sending the button | 442 // the window under the mouse pointer, even though we're sending the button |
| 430 // up event to the window that had implicit capture. We have to set this | 443 // up event to the window that had implicit capture. We have to set this |
| 431 // before we perform dispatch because the Delegate is going to read this | 444 // before we perform dispatch because the Delegate is going to read this |
| 432 // information from us. | 445 // information from us. |
| 433 if (is_pointer_going_up && is_mouse_event) | 446 if (is_pointer_going_up && is_mouse_event) { |
| 434 UpdateCursorProviderByLastKnownLocation(); | 447 UpdateCursorProviderByLastKnownLocationOnFoundWindow( |
| 448 deepest_window, location_in_display, display_id); |
| 449 } |
| 435 | 450 |
| 436 DispatchToPointerTarget(pointer_targets_[pointer_id], event); | 451 DispatchToPointerTarget(pointer_targets_[pointer_id], |
| 452 *cloned_event->AsPointerEvent()); |
| 437 | 453 |
| 438 if (is_pointer_going_up) { | 454 if (is_pointer_going_up) { |
| 439 if (is_mouse_event) | 455 if (is_mouse_event) |
| 440 pointer_targets_[pointer_id].is_pointer_down = false; | 456 pointer_targets_[pointer_id].is_pointer_down = false; |
| 441 else | 457 else |
| 442 StopTrackingPointer(pointer_id); | 458 StopTrackingPointer(pointer_id); |
| 443 if (!AreAnyPointersDown()) | 459 if (!AreAnyPointersDown()) |
| 444 delegate_->ReleaseNativeCapture(); | 460 delegate_->ReleaseNativeCapture(); |
| 445 } | 461 } |
| 446 } | 462 } |
| 447 | 463 |
| 464 void EventDispatcher::UpdateNonClientAreaForCurrentWindowOnFoundWindow( |
| 465 const DeepestWindow& deepest_window, |
| 466 const gfx::Point& location_in_display, |
| 467 int64_t display_id) { |
| 468 if (!mouse_cursor_source_window_) |
| 469 return; |
| 470 |
| 471 if (deepest_window.window == mouse_cursor_source_window_) { |
| 472 mouse_cursor_in_non_client_area_ = |
| 473 mouse_cursor_source_window_ ? deepest_window.in_non_client_area : false; |
| 474 } |
| 475 SetMousePointerLocation(location_in_display, display_id); |
| 476 delegate_->UpdateNativeCursorFromDispatcher(); |
| 477 } |
| 478 |
| 479 void EventDispatcher::UpdateCursorProviderByLastKnownLocationOnFoundWindow( |
| 480 const DeepestWindow& deepest_window, |
| 481 const gfx::Point& location_in_display, |
| 482 int64_t display_id) { |
| 483 if (mouse_button_down_) |
| 484 return; |
| 485 |
| 486 SetMouseCursorSourceWindow(deepest_window.window); |
| 487 if (mouse_cursor_source_window_) { |
| 488 mouse_cursor_in_non_client_area_ = deepest_window.in_non_client_area; |
| 489 } else { |
| 490 SetMouseCursorSourceWindow(delegate_->GetRootWindowContaining( |
| 491 &mouse_pointer_last_location_, &mouse_pointer_display_id_)); |
| 492 mouse_cursor_in_non_client_area_ = true; |
| 493 } |
| 494 SetMousePointerLocation(location_in_display, display_id); |
| 495 delegate_->UpdateNativeCursorFromDispatcher(); |
| 496 } |
| 497 |
| 448 void EventDispatcher::StartTrackingPointer( | 498 void EventDispatcher::StartTrackingPointer( |
| 449 int32_t pointer_id, | 499 int32_t pointer_id, |
| 450 const PointerTarget& pointer_target) { | 500 const PointerTarget& pointer_target) { |
| 451 DCHECK(!IsTrackingPointer(pointer_id)); | 501 DCHECK(!IsTrackingPointer(pointer_id)); |
| 452 if (pointer_target.window) | 502 if (pointer_target.window) |
| 453 ObserveWindow(pointer_target.window); | 503 ObserveWindow(pointer_target.window); |
| 454 pointer_targets_[pointer_id] = pointer_target; | 504 pointer_targets_[pointer_id] = pointer_target; |
| 455 } | 505 } |
| 456 | 506 |
| 457 void EventDispatcher::StopTrackingPointer(int32_t pointer_id) { | 507 void EventDispatcher::StopTrackingPointer(int32_t pointer_id) { |
| 458 DCHECK(IsTrackingPointer(pointer_id)); | 508 DCHECK(IsTrackingPointer(pointer_id)); |
| 459 ServerWindow* window = pointer_targets_[pointer_id].window; | 509 ServerWindow* window = pointer_targets_[pointer_id].window; |
| 460 pointer_targets_.erase(pointer_id); | 510 pointer_targets_.erase(pointer_id); |
| 461 if (window) | 511 if (window) |
| 462 UnobserveWindow(window); | 512 UnobserveWindow(window); |
| 463 } | 513 } |
| 464 | 514 |
| 465 void EventDispatcher::UpdateTargetForPointer(int32_t pointer_id, | 515 void EventDispatcher::UpdateTargetForPointer( |
| 466 const ui::LocatedEvent& event) { | 516 int32_t pointer_id, |
| 517 const ui::PointerEvent& event, |
| 518 const PointerTarget& pointer_target) { |
| 467 if (!IsTrackingPointer(pointer_id)) { | 519 if (!IsTrackingPointer(pointer_id)) { |
| 468 StartTrackingPointer(pointer_id, event_targeter_->PointerTargetForEvent( | 520 StartTrackingPointer(pointer_id, pointer_target); |
| 469 event, &event_display_id_)); | |
| 470 return; | 521 return; |
| 471 } | 522 } |
| 472 | 523 |
| 473 const PointerTarget pointer_target = | |
| 474 event_targeter_->PointerTargetForEvent(event, &event_display_id_); | |
| 475 if (pointer_target.window == pointer_targets_[pointer_id].window && | 524 if (pointer_target.window == pointer_targets_[pointer_id].window && |
| 476 pointer_target.in_nonclient_area == | 525 pointer_target.in_nonclient_area == |
| 477 pointer_targets_[pointer_id].in_nonclient_area) { | 526 pointer_targets_[pointer_id].in_nonclient_area) { |
| 478 // The targets are the same, only set the down state to true if necessary. | 527 // The targets are the same, only set the down state to true if necessary. |
| 479 // Down going to up is handled by ProcessLocatedEvent(). | 528 // Down going to up is handled by ProcessLocatedEvent(). |
| 480 if (pointer_target.is_pointer_down) | 529 if (pointer_target.is_pointer_down) |
| 481 pointer_targets_[pointer_id].is_pointer_down = true; | 530 pointer_targets_[pointer_id].is_pointer_down = true; |
| 482 return; | 531 return; |
| 483 } | 532 } |
| 484 | 533 |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 650 if (mouse_cursor_source_window_ == window) | 699 if (mouse_cursor_source_window_ == window) |
| 651 SetMouseCursorSourceWindow(nullptr); | 700 SetMouseCursorSourceWindow(nullptr); |
| 652 } | 701 } |
| 653 | 702 |
| 654 void EventDispatcher::OnDragCursorUpdated() { | 703 void EventDispatcher::OnDragCursorUpdated() { |
| 655 delegate_->UpdateNativeCursorFromDispatcher(); | 704 delegate_->UpdateNativeCursorFromDispatcher(); |
| 656 } | 705 } |
| 657 | 706 |
| 658 } // namespace ws | 707 } // namespace ws |
| 659 } // namespace ui | 708 } // namespace ui |
| OLD | NEW |