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

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: rebase Created 4 years, 3 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
« no previous file with comments | « services/ui/ws/event_dispatcher.h ('k') | services/ui/ws/event_dispatcher_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 delegate_->OnAccelerator( 271 delegate_->OnAccelerator(
282 pre_target->id(), event, 272 pre_target->id(), event,
283 EventDispatcherDelegate::AcceleratorPhase::PRE); 273 EventDispatcherDelegate::AcceleratorPhase::PRE);
284 return; 274 return;
285 } 275 }
286 } 276 }
287 ProcessKeyEvent(*key_event, match_phase); 277 ProcessKeyEvent(*key_event, match_phase);
288 return; 278 return;
289 } 279 }
290 280
291 if (event.IsPointerEvent() || event.IsMouseWheelEvent()) { 281 DCHECK(event.IsPointerEvent());
292 ProcessLocatedEvent(*event.AsLocatedEvent()); 282 ProcessPointerEvent(*event.AsPointerEvent());
293 return; 283 return;
294 }
295
296 NOTREACHED();
297 } 284 }
298 285
299 void EventDispatcher::ProcessKeyEvent(const ui::KeyEvent& event, 286 void EventDispatcher::ProcessKeyEvent(const ui::KeyEvent& event,
300 AcceleratorMatchPhase match_phase) { 287 AcceleratorMatchPhase match_phase) {
301 Accelerator* post_target = 288 Accelerator* post_target =
302 FindAccelerator(event, ui::mojom::AcceleratorPhase::POST_TARGET); 289 FindAccelerator(event, ui::mojom::AcceleratorPhase::POST_TARGET);
303 ServerWindow* focused_window = 290 ServerWindow* focused_window =
304 delegate_->GetFocusedWindowForEventDispatcher(); 291 delegate_->GetFocusedWindowForEventDispatcher();
305 if (focused_window) { 292 if (focused_window) {
306 // Assume key events are for the client area. 293 // Assume key events are for the client area.
307 const bool in_nonclient_area = false; 294 const bool in_nonclient_area = false;
308 const ClientSpecificId client_id = 295 const ClientSpecificId client_id =
309 delegate_->GetEventTargetClientId(focused_window, in_nonclient_area); 296 delegate_->GetEventTargetClientId(focused_window, in_nonclient_area);
310 delegate_->DispatchInputEventToWindow(focused_window, client_id, event, 297 delegate_->DispatchInputEventToWindow(focused_window, client_id, event,
311 post_target); 298 post_target);
312 return; 299 return;
313 } 300 }
314 delegate_->OnEventTargetNotFound(event); 301 delegate_->OnEventTargetNotFound(event);
315 if (post_target) 302 if (post_target)
316 delegate_->OnAccelerator(post_target->id(), event, 303 delegate_->OnAccelerator(post_target->id(), event,
317 EventDispatcherDelegate::AcceleratorPhase::POST); 304 EventDispatcherDelegate::AcceleratorPhase::POST);
318 } 305 }
319 306
320 void EventDispatcher::ProcessLocatedEvent(const ui::LocatedEvent& event) { 307 void EventDispatcher::ProcessPointerEvent(const ui::PointerEvent& event) {
321 DCHECK(event.IsPointerEvent() || event.IsMouseWheelEvent()); 308 DCHECK(event.IsPointerEvent());
322 const bool is_mouse_event = 309 const bool is_mouse_event = event.IsMousePointerEvent();
323 event.IsMousePointerEvent() || event.IsMouseWheelEvent();
324 310
325 if (is_mouse_event) { 311 if (is_mouse_event) {
326 mouse_pointer_last_location_ = event.root_location(); 312 mouse_pointer_last_location_ = event.root_location();
327 delegate_->OnMouseCursorLocationChanged(event.root_location()); 313 delegate_->OnMouseCursorLocationChanged(event.root_location());
328 } 314 }
329 315
330 // Release capture on pointer up. For mouse we only release if there are 316 // Release capture on pointer up. For mouse we only release if there are
331 // no buttons down. 317 // no buttons down.
332 const bool is_pointer_going_up = 318 const bool is_pointer_going_up =
333 (event.type() == ui::ET_POINTER_UP || 319 (event.type() == ui::ET_POINTER_UP ||
334 event.type() == ui::ET_POINTER_CANCELLED) && 320 event.type() == ui::ET_POINTER_CANCELLED) &&
335 (!is_mouse_event || IsOnlyOneMouseButtonDown(event.flags())); 321 (!is_mouse_event || IsOnlyOneMouseButtonDown(event.flags()));
336 322
337 // Update mouse down state upon events which change it. 323 // Update mouse down state upon events which change it.
338 if (is_mouse_event) { 324 if (is_mouse_event) {
339 if (event.type() == ui::ET_POINTER_DOWN) 325 if (event.type() == ui::ET_POINTER_DOWN)
340 mouse_button_down_ = true; 326 mouse_button_down_ = true;
341 else if (is_pointer_going_up) 327 else if (is_pointer_going_up)
342 mouse_button_down_ = false; 328 mouse_button_down_ = false;
343 } 329 }
344 330
345 if (capture_window_) { 331 if (capture_window_) {
346 mouse_cursor_source_window_ = capture_window_; 332 mouse_cursor_source_window_ = capture_window_;
347 DispatchToClient(capture_window_, capture_window_client_id_, event); 333 DispatchToClient(capture_window_, capture_window_client_id_, event);
348 return; 334 return;
349 } 335 }
350 336
351 const int32_t pointer_id = PointerId(event); 337 const int32_t pointer_id = event.pointer_id();
352 if (!IsTrackingPointer(pointer_id) || 338 if (!IsTrackingPointer(pointer_id) ||
353 !pointer_targets_[pointer_id].is_pointer_down) { 339 !pointer_targets_[pointer_id].is_pointer_down) {
354 const bool any_pointers_down = AreAnyPointersDown(); 340 const bool any_pointers_down = AreAnyPointersDown();
355 UpdateTargetForPointer(pointer_id, event); 341 UpdateTargetForPointer(pointer_id, event);
356 if (is_mouse_event) 342 if (is_mouse_event)
357 mouse_cursor_source_window_ = pointer_targets_[pointer_id].window; 343 mouse_cursor_source_window_ = pointer_targets_[pointer_id].window;
358 344
359 PointerTarget& pointer_target = pointer_targets_[pointer_id]; 345 PointerTarget& pointer_target = pointer_targets_[pointer_id];
360 if (pointer_target.is_pointer_down) { 346 if (pointer_target.is_pointer_down) {
361 if (is_mouse_event) 347 if (is_mouse_event)
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
572 558
573 void EventDispatcher::OnWindowDestroyed(ServerWindow* window) { 559 void EventDispatcher::OnWindowDestroyed(ServerWindow* window) {
574 CancelPointerEventsToTarget(window); 560 CancelPointerEventsToTarget(window);
575 561
576 if (mouse_cursor_source_window_ == window) 562 if (mouse_cursor_source_window_ == window)
577 mouse_cursor_source_window_ = nullptr; 563 mouse_cursor_source_window_ = nullptr;
578 } 564 }
579 565
580 } // namespace ws 566 } // namespace ws
581 } // namespace ui 567 } // namespace ui
OLDNEW
« no previous file with comments | « services/ui/ws/event_dispatcher.h ('k') | services/ui/ws/event_dispatcher_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698