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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
72 } | 72 } |
73 | 73 |
74 while (!pointer_targets_.empty()) | 74 while (!pointer_targets_.empty()) |
75 StopTrackingPointer(pointer_targets_.begin()->first); | 75 StopTrackingPointer(pointer_targets_.begin()->first); |
76 | 76 |
77 mouse_button_down_ = false; | 77 mouse_button_down_ = false; |
78 } | 78 } |
79 | 79 |
80 void EventDispatcher::SetMousePointerDisplayLocation( | 80 void EventDispatcher::SetMousePointerDisplayLocation( |
81 const gfx::Point& display_location, | 81 const gfx::Point& display_location, |
82 const int64_t display_id) { | 82 int64_t display_id) { |
83 DCHECK(pointer_targets_.empty()); | 83 DCHECK(pointer_targets_.empty()); |
84 SetMousePointerLocation(display_location, display_id); | 84 SetMousePointerLocation(display_location, display_id); |
85 UpdateCursorProviderByLastKnownLocation(); | 85 UpdateCursorProviderByLastKnownLocation(); |
86 // Write our initial location back to our shared screen coordinate. This | 86 // Write our initial location back to our shared screen coordinate. This |
87 // 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 |
88 // process any events in views during window construction. | 88 // process any events in views during window construction. |
89 delegate_->OnMouseCursorLocationChanged(display_location, display_id); | 89 delegate_->OnMouseCursorLocationChanged(display_location, display_id); |
90 } | 90 } |
91 | 91 |
92 ui::CursorData EventDispatcher::GetCurrentMouseCursor() const { | 92 ui::CursorData EventDispatcher::GetCurrentMouseCursor() const { |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
214 const ClientSpecificId target_client_id = delegate_->GetEventTargetClientId( | 214 const ClientSpecificId target_client_id = delegate_->GetEventTargetClientId( |
215 mouse_cursor_source_window_, mouse_cursor_in_non_client_area_); | 215 mouse_cursor_source_window_, mouse_cursor_in_non_client_area_); |
216 const ServerWindow* window = mouse_cursor_source_window_; | 216 const ServerWindow* window = mouse_cursor_source_window_; |
217 while (window && window->id().client_id == target_client_id) | 217 while (window && window->id().client_id == target_client_id) |
218 window = window->parent(); | 218 window = window->parent(); |
219 return window; | 219 return window; |
220 } | 220 } |
221 | 221 |
222 void EventDispatcher::UpdateNonClientAreaForCurrentWindow() { | 222 void EventDispatcher::UpdateNonClientAreaForCurrentWindow() { |
223 if (mouse_cursor_source_window_) { | 223 if (mouse_cursor_source_window_) { |
224 LocationTarget location_target = event_targeter_->FindTargetForLocation( | 224 event_targeter_->FindTargetForLocation( |
225 mouse_pointer_last_location_, mouse_pointer_display_id_); | 225 mouse_pointer_last_location_, mouse_pointer_display_id_, |
226 if (location_target.deepest_window.window == mouse_cursor_source_window_) { | 226 base::BindOnce( |
227 mouse_cursor_in_non_client_area_ = | 227 &EventDispatcher::UpdateNonClientAreaForCurrentWindowOnFoundWindow, |
228 mouse_cursor_source_window_ | 228 base::Unretained(this))); |
229 ? location_target.deepest_window.in_non_client_area | |
230 : false; | |
231 } | |
232 SetMousePointerLocation(location_target.location_in_root, | |
233 location_target.display_id); | |
234 } | 229 } |
235 } | 230 } |
236 | 231 |
237 void EventDispatcher::UpdateCursorProviderByLastKnownLocation() { | 232 void EventDispatcher::UpdateCursorProviderByLastKnownLocation() { |
238 if (!mouse_button_down_) { | 233 if (!mouse_button_down_) { |
239 LocationTarget location_target = event_targeter_->FindTargetForLocation( | 234 event_targeter_->FindTargetForLocation( |
240 mouse_pointer_last_location_, mouse_pointer_display_id_); | 235 mouse_pointer_last_location_, mouse_pointer_display_id_, |
241 SetMouseCursorSourceWindow(location_target.deepest_window.window); | 236 base::BindOnce(&EventDispatcher:: |
242 if (mouse_cursor_source_window_) { | 237 UpdateCursorProviderByLastKnownLocationOnFoundWindow, |
243 mouse_cursor_in_non_client_area_ = | 238 base::Unretained(this))); |
244 location_target.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 SetMousePointerLocation(location_target.location_in_root, | |
251 location_target.display_id); | |
252 } | 239 } |
253 } | 240 } |
254 | 241 |
255 bool EventDispatcher::AddAccelerator(uint32_t id, | 242 bool EventDispatcher::AddAccelerator(uint32_t id, |
256 mojom::EventMatcherPtr event_matcher) { | 243 mojom::EventMatcherPtr event_matcher) { |
257 std::unique_ptr<Accelerator> accelerator(new Accelerator(id, *event_matcher)); | 244 std::unique_ptr<Accelerator> accelerator(new Accelerator(id, *event_matcher)); |
258 // If an accelerator with the same id or matcher already exists, then abort. | 245 // If an accelerator with the same id or matcher already exists, then abort. |
259 for (const auto& pair : accelerators_) { | 246 for (const auto& pair : accelerators_) { |
260 if (pair.first == id) { | 247 if (pair.first == id) { |
261 DVLOG(1) << "duplicate accelerator. Accelerator id=" << accelerator->id() | 248 DVLOG(1) << "duplicate accelerator. Accelerator id=" << accelerator->id() |
(...skipping 11 matching lines...) Expand all Loading... | |
273 return true; | 260 return true; |
274 } | 261 } |
275 | 262 |
276 void EventDispatcher::RemoveAccelerator(uint32_t id) { | 263 void EventDispatcher::RemoveAccelerator(uint32_t id) { |
277 auto it = accelerators_.find(id); | 264 auto it = accelerators_.find(id); |
278 // Clients may pass bogus ids. | 265 // Clients may pass bogus ids. |
279 if (it != accelerators_.end()) | 266 if (it != accelerators_.end()) |
280 accelerators_.erase(it); | 267 accelerators_.erase(it); |
281 } | 268 } |
282 | 269 |
270 bool EventDispatcher::IsProcessingEvent() { | |
271 return event_targeter_->IsHitTestInFlight(); | |
272 } | |
273 | |
283 void EventDispatcher::ProcessEvent(const ui::Event& event, | 274 void EventDispatcher::ProcessEvent(const ui::Event& event, |
284 const int64_t display_id, | 275 int64_t display_id, |
285 AcceleratorMatchPhase match_phase) { | 276 AcceleratorMatchPhase match_phase) { |
286 #if !defined(NDEBUG) | 277 #if !defined(NDEBUG) |
287 if (match_phase == AcceleratorMatchPhase::POST_ONLY) { | 278 if (match_phase == AcceleratorMatchPhase::POST_ONLY) { |
288 // POST_ONLY should always be preceeded by ANY with the same event. | 279 // POST_ONLY should always be preceeded by ANY with the same event. |
289 DCHECK(previous_event_); | 280 DCHECK(previous_event_); |
290 // Event doesn't define ==, so this compares the key fields. | 281 // Event doesn't define ==, so this compares the key fields. |
291 DCHECK(event.type() == previous_event_->type() && | 282 DCHECK(event.type() == previous_event_->type() && |
292 event.time_stamp() == previous_event_->time_stamp() && | 283 event.time_stamp() == previous_event_->time_stamp() && |
293 event.flags() == previous_event_->flags()); | 284 event.flags() == previous_event_->flags()); |
294 DCHECK_EQ(previous_accelerator_match_phase_, AcceleratorMatchPhase::ANY); | 285 DCHECK_EQ(previous_accelerator_match_phase_, AcceleratorMatchPhase::ANY); |
(...skipping 12 matching lines...) Expand all Loading... | |
307 pre_target->id(), event_display_id_, event, | 298 pre_target->id(), event_display_id_, event, |
308 EventDispatcherDelegate::AcceleratorPhase::PRE); | 299 EventDispatcherDelegate::AcceleratorPhase::PRE); |
309 return; | 300 return; |
310 } | 301 } |
311 } | 302 } |
312 ProcessKeyEvent(*key_event, match_phase); | 303 ProcessKeyEvent(*key_event, match_phase); |
313 return; | 304 return; |
314 } | 305 } |
315 | 306 |
316 DCHECK(event.IsPointerEvent()); | 307 DCHECK(event.IsPointerEvent()); |
317 ProcessPointerEvent(*event.AsPointerEvent()); | 308 event_targeter_->FindTargetForLocation( |
318 return; | 309 (event.AsPointerEvent())->root_location(), event_display_id_, |
sky
2017/06/07 17:05:07
Looks like you have unnecessary () around event.As
riajiang
2017/06/07 18:15:04
Done.
| |
310 base::BindOnce(&EventDispatcher::ProcessPointerEventOnFoundTarget, | |
311 base::Unretained(this), *event.AsPointerEvent())); | |
319 } | 312 } |
320 | 313 |
321 ServerWindow* EventDispatcher::GetRootWindowContaining( | 314 ServerWindow* EventDispatcher::GetRootWindowContaining( |
322 gfx::Point* location_in_display, | 315 gfx::Point* location_in_display, |
323 int64_t* display_id) { | 316 int64_t* display_id) { |
324 return delegate_->GetRootWindowContaining(location_in_display, display_id); | 317 return delegate_->GetRootWindowContaining(location_in_display, display_id); |
325 } | 318 } |
326 | 319 |
320 void EventDispatcher::ProcessNextEventFromQueue() { | |
321 delegate_->ProcessNextEventFromQueue(); | |
322 } | |
323 | |
327 void EventDispatcher::SetMouseCursorSourceWindow(ServerWindow* window) { | 324 void EventDispatcher::SetMouseCursorSourceWindow(ServerWindow* window) { |
328 if (mouse_cursor_source_window_ == window) | 325 if (mouse_cursor_source_window_ == window) |
329 return; | 326 return; |
330 | 327 |
331 if (mouse_cursor_source_window_) | 328 if (mouse_cursor_source_window_) |
332 UnobserveWindow(mouse_cursor_source_window_); | 329 UnobserveWindow(mouse_cursor_source_window_); |
333 mouse_cursor_source_window_ = window; | 330 mouse_cursor_source_window_ = window; |
334 if (mouse_cursor_source_window_) | 331 if (mouse_cursor_source_window_) |
335 ObserveWindow(mouse_cursor_source_window_); | 332 ObserveWindow(mouse_cursor_source_window_); |
336 } | 333 } |
(...skipping 24 matching lines...) Expand all Loading... | |
361 delegate_->DispatchInputEventToWindow( | 358 delegate_->DispatchInputEventToWindow( |
362 focused_window, client_id, event_display_id_, event, post_target); | 359 focused_window, client_id, event_display_id_, event, post_target); |
363 return; | 360 return; |
364 } | 361 } |
365 delegate_->OnEventTargetNotFound(event, event_display_id_); | 362 delegate_->OnEventTargetNotFound(event, event_display_id_); |
366 if (post_target) | 363 if (post_target) |
367 delegate_->OnAccelerator(post_target->id(), event_display_id_, event, | 364 delegate_->OnAccelerator(post_target->id(), event_display_id_, event, |
368 EventDispatcherDelegate::AcceleratorPhase::POST); | 365 EventDispatcherDelegate::AcceleratorPhase::POST); |
369 } | 366 } |
370 | 367 |
371 void EventDispatcher::ProcessPointerEvent(const ui::PointerEvent& event) { | 368 void EventDispatcher::ProcessPointerEventOnFoundTarget( |
372 DCHECK(event.IsPointerEvent()); | 369 const ui::PointerEvent& event, |
373 | 370 const LocationTarget& location_target) { |
374 PointerTarget pointer_target; | 371 PointerTarget pointer_target; |
375 LocationTarget location_target = event_targeter_->FindTargetForLocation( | |
376 event.root_location(), event_display_id_); | |
377 pointer_target.window = modal_window_controller_.GetTargetForWindow( | 372 pointer_target.window = modal_window_controller_.GetTargetForWindow( |
378 location_target.deepest_window.window); | 373 location_target.deepest_window.window); |
379 pointer_target.is_mouse_event = event.IsMousePointerEvent(); | 374 pointer_target.is_mouse_event = event.IsMousePointerEvent(); |
380 pointer_target.in_nonclient_area = | 375 pointer_target.in_nonclient_area = |
381 location_target.deepest_window.window != pointer_target.window || | 376 location_target.deepest_window.window != pointer_target.window || |
382 !pointer_target.window || | 377 !pointer_target.window || |
383 location_target.deepest_window.in_non_client_area; | 378 location_target.deepest_window.in_non_client_area; |
384 pointer_target.is_pointer_down = event.type() == ui::ET_POINTER_DOWN; | 379 pointer_target.is_pointer_down = event.type() == ui::ET_POINTER_DOWN; |
385 | 380 |
386 std::unique_ptr<ui::Event> cloned_event = ui::Event::Clone(event); | 381 std::unique_ptr<ui::Event> cloned_event = ui::Event::Clone(event); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
455 } | 450 } |
456 } | 451 } |
457 } | 452 } |
458 | 453 |
459 // When we release the mouse button, we want the cursor to be sourced from | 454 // When we release the mouse button, we want the cursor to be sourced from |
460 // the window under the mouse pointer, even though we're sending the button | 455 // the window under the mouse pointer, even though we're sending the button |
461 // up event to the window that had implicit capture. We have to set this | 456 // up event to the window that had implicit capture. We have to set this |
462 // before we perform dispatch because the Delegate is going to read this | 457 // before we perform dispatch because the Delegate is going to read this |
463 // information from us. | 458 // information from us. |
464 if (is_pointer_going_up && is_mouse_event) | 459 if (is_pointer_going_up && is_mouse_event) |
465 UpdateCursorProviderByLastKnownLocation(); | 460 UpdateCursorProviderByLastKnownLocationOnFoundWindow(location_target); |
466 | 461 |
467 DispatchToPointerTarget(pointer_targets_[pointer_id], | 462 DispatchToPointerTarget(pointer_targets_[pointer_id], |
468 *cloned_event->AsPointerEvent()); | 463 *cloned_event->AsPointerEvent()); |
469 | 464 |
470 if (is_pointer_going_up) { | 465 if (is_pointer_going_up) { |
471 if (is_mouse_event) | 466 if (is_mouse_event) |
472 pointer_targets_[pointer_id].is_pointer_down = false; | 467 pointer_targets_[pointer_id].is_pointer_down = false; |
473 else | 468 else |
474 StopTrackingPointer(pointer_id); | 469 StopTrackingPointer(pointer_id); |
475 if (!AreAnyPointersDown()) | 470 if (!AreAnyPointersDown()) |
476 delegate_->ReleaseNativeCapture(); | 471 delegate_->ReleaseNativeCapture(); |
477 } | 472 } |
478 } | 473 } |
479 | 474 |
475 void EventDispatcher::UpdateNonClientAreaForCurrentWindowOnFoundWindow( | |
476 const LocationTarget& location_target) { | |
477 if (!mouse_cursor_source_window_) | |
478 return; | |
479 | |
480 if (location_target.deepest_window.window == mouse_cursor_source_window_) { | |
481 mouse_cursor_in_non_client_area_ = | |
482 mouse_cursor_source_window_ | |
483 ? location_target.deepest_window.in_non_client_area | |
484 : false; | |
485 } | |
486 SetMousePointerLocation(location_target.location_in_root, | |
487 location_target.display_id); | |
488 delegate_->UpdateNativeCursorFromDispatcher(); | |
489 } | |
490 | |
491 void EventDispatcher::UpdateCursorProviderByLastKnownLocationOnFoundWindow( | |
492 const LocationTarget& location_target) { | |
493 if (mouse_button_down_) | |
494 return; | |
495 | |
496 SetMouseCursorSourceWindow(location_target.deepest_window.window); | |
497 if (mouse_cursor_source_window_) { | |
498 mouse_cursor_in_non_client_area_ = | |
499 location_target.deepest_window.in_non_client_area; | |
500 } else { | |
501 SetMouseCursorSourceWindow(delegate_->GetRootWindowContaining( | |
502 &mouse_pointer_last_location_, &mouse_pointer_display_id_)); | |
503 mouse_cursor_in_non_client_area_ = true; | |
504 } | |
505 SetMousePointerLocation(location_target.location_in_root, | |
506 location_target.display_id); | |
507 delegate_->UpdateNativeCursorFromDispatcher(); | |
508 } | |
509 | |
480 void EventDispatcher::StartTrackingPointer( | 510 void EventDispatcher::StartTrackingPointer( |
481 int32_t pointer_id, | 511 int32_t pointer_id, |
482 const PointerTarget& pointer_target) { | 512 const PointerTarget& pointer_target) { |
483 DCHECK(!IsTrackingPointer(pointer_id)); | 513 DCHECK(!IsTrackingPointer(pointer_id)); |
484 if (pointer_target.window) | 514 if (pointer_target.window) |
485 ObserveWindow(pointer_target.window); | 515 ObserveWindow(pointer_target.window); |
486 pointer_targets_[pointer_id] = pointer_target; | 516 pointer_targets_[pointer_id] = pointer_target; |
487 } | 517 } |
488 | 518 |
489 void EventDispatcher::StopTrackingPointer(int32_t pointer_id) { | 519 void EventDispatcher::StopTrackingPointer(int32_t pointer_id) { |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
679 if (mouse_cursor_source_window_ == window) | 709 if (mouse_cursor_source_window_ == window) |
680 SetMouseCursorSourceWindow(nullptr); | 710 SetMouseCursorSourceWindow(nullptr); |
681 } | 711 } |
682 | 712 |
683 void EventDispatcher::OnDragCursorUpdated() { | 713 void EventDispatcher::OnDragCursorUpdated() { |
684 delegate_->UpdateNativeCursorFromDispatcher(); | 714 delegate_->UpdateNativeCursorFromDispatcher(); |
685 } | 715 } |
686 | 716 |
687 } // namespace ws | 717 } // namespace ws |
688 } // namespace ui | 718 } // namespace ui |
OLD | NEW |