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

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

Issue 2256343003: Update ui::PointerEvent to support mouse wheel and capture change events. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: pointer id Created 4 years, 4 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/time/time.h" 9 #include "base/time/time.h"
10 #include "services/ui/ws/accelerator.h" 10 #include "services/ui/ws/accelerator.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 return false; 45 return false;
46 46
47 for (const auto& rect : target->additional_client_areas()) { 47 for (const auto& rect : target->additional_client_areas()) {
48 if (rect.Contains(location)) 48 if (rect.Contains(location))
49 return false; 49 return false;
50 } 50 }
51 51
52 return true; 52 return true;
53 } 53 }
54 54
55 uint32_t PointerId(const ui::LocatedEvent& event) {
56 if (event.IsPointerEvent())
57 return event.AsPointerEvent()->pointer_id();
58 if (event.IsMouseWheelEvent())
59 return ui::PointerEvent::kMousePointerId;
60
61 NOTREACHED();
62 return 0;
63 }
64
65 } // namespace 55 } // namespace
66 56
67 //////////////////////////////////////////////////////////////////////////////// 57 ////////////////////////////////////////////////////////////////////////////////
68 58
69 EventDispatcher::EventDispatcher(EventDispatcherDelegate* delegate) 59 EventDispatcher::EventDispatcher(EventDispatcherDelegate* delegate)
70 : delegate_(delegate), 60 : delegate_(delegate),
71 capture_window_(nullptr), 61 capture_window_(nullptr),
72 capture_window_client_id_(kInvalidClientId), 62 capture_window_client_id_(kInvalidClientId),
73 modal_window_controller_(this), 63 modal_window_controller_(this),
74 mouse_button_down_(false), 64 mouse_button_down_(false),
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 delegate_->OnAccelerator( 270 delegate_->OnAccelerator(
281 pre_target->id(), event, 271 pre_target->id(), event,
282 EventDispatcherDelegate::AcceleratorPhase::PRE); 272 EventDispatcherDelegate::AcceleratorPhase::PRE);
283 return; 273 return;
284 } 274 }
285 } 275 }
286 ProcessKeyEvent(*key_event, match_phase); 276 ProcessKeyEvent(*key_event, match_phase);
287 return; 277 return;
288 } 278 }
289 279
290 if (event.IsPointerEvent() || event.IsMouseWheelEvent()) { 280 DCHECK(event.IsPointerEvent());
291 ProcessLocatedEvent(*event.AsLocatedEvent()); 281 ProcessPointerEvent(*event.AsPointerEvent());
292 return; 282 return;
293 }
294
295 NOTREACHED();
296 } 283 }
297 284
298 void EventDispatcher::ProcessKeyEvent(const ui::KeyEvent& event, 285 void EventDispatcher::ProcessKeyEvent(const ui::KeyEvent& event,
299 AcceleratorMatchPhase match_phase) { 286 AcceleratorMatchPhase match_phase) {
300 Accelerator* post_target = 287 Accelerator* post_target =
301 FindAccelerator(event, ui::mojom::AcceleratorPhase::POST_TARGET); 288 FindAccelerator(event, ui::mojom::AcceleratorPhase::POST_TARGET);
302 ServerWindow* focused_window = 289 ServerWindow* focused_window =
303 delegate_->GetFocusedWindowForEventDispatcher(); 290 delegate_->GetFocusedWindowForEventDispatcher();
304 if (focused_window) { 291 if (focused_window) {
305 // Assume key events are for the client area. 292 // Assume key events are for the client area.
306 const bool in_nonclient_area = false; 293 const bool in_nonclient_area = false;
307 const ClientSpecificId client_id = 294 const ClientSpecificId client_id =
308 delegate_->GetEventTargetClientId(focused_window, in_nonclient_area); 295 delegate_->GetEventTargetClientId(focused_window, in_nonclient_area);
309 delegate_->DispatchInputEventToWindow(focused_window, client_id, event, 296 delegate_->DispatchInputEventToWindow(focused_window, client_id, event,
310 post_target); 297 post_target);
311 return; 298 return;
312 } 299 }
313 delegate_->OnEventTargetNotFound(event); 300 delegate_->OnEventTargetNotFound(event);
314 if (post_target) 301 if (post_target)
315 delegate_->OnAccelerator(post_target->id(), event, 302 delegate_->OnAccelerator(post_target->id(), event,
316 EventDispatcherDelegate::AcceleratorPhase::POST); 303 EventDispatcherDelegate::AcceleratorPhase::POST);
317 } 304 }
318 305
319 void EventDispatcher::ProcessLocatedEvent(const ui::LocatedEvent& event) { 306 void EventDispatcher::ProcessPointerEvent(const ui::PointerEvent& event) {
320 DCHECK(event.IsPointerEvent() || event.IsMouseWheelEvent()); 307 DCHECK(event.IsPointerEvent());
321 const bool is_mouse_event = 308 const bool is_mouse_event = event.IsMousePointerEvent();
322 event.IsMousePointerEvent() || event.IsMouseWheelEvent();
323 309
324 if (is_mouse_event) { 310 if (is_mouse_event) {
325 mouse_pointer_last_location_ = event.root_location(); 311 mouse_pointer_last_location_ = event.root_location();
326 delegate_->OnMouseCursorLocationChanged(event.root_location()); 312 delegate_->OnMouseCursorLocationChanged(event.root_location());
327 } 313 }
328 314
329 // Release capture on pointer up. For mouse we only release if there are 315 // Release capture on pointer up. For mouse we only release if there are
330 // no buttons down. 316 // no buttons down.
331 const bool is_pointer_going_up = 317 const bool is_pointer_going_up =
332 (event.type() == ui::ET_POINTER_UP || 318 (event.type() == ui::ET_POINTER_UP ||
333 event.type() == ui::ET_POINTER_CANCELLED) && 319 event.type() == ui::ET_POINTER_CANCELLED) &&
334 (!is_mouse_event || IsOnlyOneMouseButtonDown(event.flags())); 320 (!is_mouse_event || IsOnlyOneMouseButtonDown(event.flags()));
335 321
336 // Update mouse down state upon events which change it. 322 // Update mouse down state upon events which change it.
337 if (is_mouse_event) { 323 if (is_mouse_event) {
338 if (event.type() == ui::ET_POINTER_DOWN) 324 if (event.type() == ui::ET_POINTER_DOWN)
339 mouse_button_down_ = true; 325 mouse_button_down_ = true;
340 else if (is_pointer_going_up) 326 else if (is_pointer_going_up)
341 mouse_button_down_ = false; 327 mouse_button_down_ = false;
342 } 328 }
343 329
344 if (capture_window_) { 330 if (capture_window_) {
345 mouse_cursor_source_window_ = capture_window_; 331 mouse_cursor_source_window_ = capture_window_;
346 DispatchToClient(capture_window_, capture_window_client_id_, event); 332 DispatchToClient(capture_window_, capture_window_client_id_, event);
347 return; 333 return;
348 } 334 }
349 335
350 const int32_t pointer_id = PointerId(event); 336 const int32_t pointer_id = event.pointer_id();
351 if (!IsTrackingPointer(pointer_id) || 337 if (!IsTrackingPointer(pointer_id) ||
352 !pointer_targets_[pointer_id].is_pointer_down) { 338 !pointer_targets_[pointer_id].is_pointer_down) {
353 const bool any_pointers_down = AreAnyPointersDown(); 339 const bool any_pointers_down = AreAnyPointersDown();
354 UpdateTargetForPointer(pointer_id, event); 340 UpdateTargetForPointer(pointer_id, event);
355 if (is_mouse_event) 341 if (is_mouse_event)
356 mouse_cursor_source_window_ = pointer_targets_[pointer_id].window; 342 mouse_cursor_source_window_ = pointer_targets_[pointer_id].window;
357 343
358 PointerTarget& pointer_target = pointer_targets_[pointer_id]; 344 PointerTarget& pointer_target = pointer_targets_[pointer_id];
359 if (pointer_target.is_pointer_down) { 345 if (pointer_target.is_pointer_down) {
360 if (is_mouse_event) 346 if (is_mouse_event)
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
570 556
571 void EventDispatcher::OnWindowDestroyed(ServerWindow* window) { 557 void EventDispatcher::OnWindowDestroyed(ServerWindow* window) {
572 CancelPointerEventsToTarget(window); 558 CancelPointerEventsToTarget(window);
573 559
574 if (mouse_cursor_source_window_ == window) 560 if (mouse_cursor_source_window_ == window)
575 mouse_cursor_source_window_ = nullptr; 561 mouse_cursor_source_window_ = nullptr;
576 } 562 }
577 563
578 } // namespace ws 564 } // namespace ws
579 } // namespace ui 565 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698