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

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: location, target etc 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
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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
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) { 55 uint32_t PointerId(const ui::LocatedEvent& event) {
56 if (event.IsPointerEvent()) 56 DCHECK(event.IsPointerEvent());
57 return event.AsPointerEvent()->pointer_id(); 57 return event.AsPointerEvent()->pointer_id();
58 if (event.IsMouseWheelEvent())
59 return ui::PointerEvent::kMousePointerId;
60
61 NOTREACHED();
62 return 0;
63 } 58 }
64 59
65 } // namespace 60 } // namespace
66 61
67 //////////////////////////////////////////////////////////////////////////////// 62 ////////////////////////////////////////////////////////////////////////////////
68 63
69 EventDispatcher::EventDispatcher(EventDispatcherDelegate* delegate) 64 EventDispatcher::EventDispatcher(EventDispatcherDelegate* delegate)
70 : delegate_(delegate), 65 : delegate_(delegate),
71 capture_window_(nullptr), 66 capture_window_(nullptr),
72 capture_window_client_id_(kInvalidClientId), 67 capture_window_client_id_(kInvalidClientId),
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 delegate_->OnAccelerator( 275 delegate_->OnAccelerator(
281 pre_target->id(), event, 276 pre_target->id(), event,
282 EventDispatcherDelegate::AcceleratorPhase::PRE); 277 EventDispatcherDelegate::AcceleratorPhase::PRE);
283 return; 278 return;
284 } 279 }
285 } 280 }
286 ProcessKeyEvent(*key_event, match_phase); 281 ProcessKeyEvent(*key_event, match_phase);
287 return; 282 return;
288 } 283 }
289 284
290 if (event.IsPointerEvent() || event.IsMouseWheelEvent()) { 285 if (event.IsPointerEvent()) {
291 ProcessLocatedEvent(*event.AsLocatedEvent()); 286 ProcessLocatedEvent(*event.AsLocatedEvent());
292 return; 287 return;
293 } 288 }
294 289
295 NOTREACHED(); 290 NOTREACHED();
296 } 291 }
297 292
298 void EventDispatcher::ProcessKeyEvent(const ui::KeyEvent& event, 293 void EventDispatcher::ProcessKeyEvent(const ui::KeyEvent& event,
299 AcceleratorMatchPhase match_phase) { 294 AcceleratorMatchPhase match_phase) {
300 Accelerator* post_target = 295 Accelerator* post_target =
301 FindAccelerator(event, ui::mojom::AcceleratorPhase::POST_TARGET); 296 FindAccelerator(event, ui::mojom::AcceleratorPhase::POST_TARGET);
302 ServerWindow* focused_window = 297 ServerWindow* focused_window =
303 delegate_->GetFocusedWindowForEventDispatcher(); 298 delegate_->GetFocusedWindowForEventDispatcher();
304 if (focused_window) { 299 if (focused_window) {
305 // Assume key events are for the client area. 300 // Assume key events are for the client area.
306 const bool in_nonclient_area = false; 301 const bool in_nonclient_area = false;
307 const ClientSpecificId client_id = 302 const ClientSpecificId client_id =
308 delegate_->GetEventTargetClientId(focused_window, in_nonclient_area); 303 delegate_->GetEventTargetClientId(focused_window, in_nonclient_area);
309 delegate_->DispatchInputEventToWindow(focused_window, client_id, event, 304 delegate_->DispatchInputEventToWindow(focused_window, client_id, event,
310 post_target); 305 post_target);
311 return; 306 return;
312 } 307 }
313 delegate_->OnEventTargetNotFound(event); 308 delegate_->OnEventTargetNotFound(event);
314 if (post_target) 309 if (post_target)
315 delegate_->OnAccelerator(post_target->id(), event, 310 delegate_->OnAccelerator(post_target->id(), event,
316 EventDispatcherDelegate::AcceleratorPhase::POST); 311 EventDispatcherDelegate::AcceleratorPhase::POST);
317 } 312 }
318 313
319 void EventDispatcher::ProcessLocatedEvent(const ui::LocatedEvent& event) { 314 void EventDispatcher::ProcessLocatedEvent(const ui::LocatedEvent& event) {
sadrul 2016/08/22 17:15:57 ProcessPointerEvent(const ui::PointerEvent&)?
riajiang 2016/08/22 20:16:41 Sorry I forgot. Done.
320 DCHECK(event.IsPointerEvent() || event.IsMouseWheelEvent()); 315 // TODO(moshayedi): crbug.com/602859. Handle scroll events as
321 const bool is_mouse_event = 316 // they are once we have proper support for scroll events.
322 event.IsMousePointerEvent() || event.IsMouseWheelEvent(); 317 DCHECK(event.IsPointerEvent());
318 const bool is_mouse_event = event.IsMousePointerEvent();
323 319
324 if (is_mouse_event) { 320 if (is_mouse_event) {
325 mouse_pointer_last_location_ = event.root_location(); 321 mouse_pointer_last_location_ = event.root_location();
326 delegate_->OnMouseCursorLocationChanged(event.root_location()); 322 delegate_->OnMouseCursorLocationChanged(event.root_location());
327 } 323 }
328 324
329 // Release capture on pointer up. For mouse we only release if there are 325 // Release capture on pointer up. For mouse we only release if there are
330 // no buttons down. 326 // no buttons down.
331 const bool is_pointer_going_up = 327 const bool is_pointer_going_up =
332 (event.type() == ui::ET_POINTER_UP || 328 (event.type() == ui::ET_POINTER_UP ||
333 event.type() == ui::ET_POINTER_CANCELLED) && 329 event.type() == ui::ET_POINTER_CANCELLED) &&
334 (!is_mouse_event || IsOnlyOneMouseButtonDown(event.flags())); 330 (!is_mouse_event || IsOnlyOneMouseButtonDown(event.flags()));
335 331
336 // Update mouse down state upon events which change it. 332 // Update mouse down state upon events which change it.
337 if (is_mouse_event) { 333 if (is_mouse_event) {
338 if (event.type() == ui::ET_POINTER_DOWN) 334 if (event.type() == ui::ET_POINTER_DOWN)
339 mouse_button_down_ = true; 335 mouse_button_down_ = true;
340 else if (is_pointer_going_up) 336 else if (is_pointer_going_up)
341 mouse_button_down_ = false; 337 mouse_button_down_ = false;
342 } 338 }
343 339
344 if (capture_window_) { 340 if (capture_window_) {
345 mouse_cursor_source_window_ = capture_window_; 341 mouse_cursor_source_window_ = capture_window_;
346 DispatchToClient(capture_window_, capture_window_client_id_, event); 342 DispatchToClient(capture_window_, capture_window_client_id_, event);
347 return; 343 return;
348 } 344 }
349 345
350 const int32_t pointer_id = PointerId(event); 346 const int32_t pointer_id = PointerId(event);
sadrul 2016/08/22 17:15:57 Just use |event.pointer_id()| (since |event| will
riajiang 2016/08/22 20:16:41 Done.
351 if (!IsTrackingPointer(pointer_id) || 347 if (!IsTrackingPointer(pointer_id) ||
352 !pointer_targets_[pointer_id].is_pointer_down) { 348 !pointer_targets_[pointer_id].is_pointer_down) {
353 const bool any_pointers_down = AreAnyPointersDown(); 349 const bool any_pointers_down = AreAnyPointersDown();
354 UpdateTargetForPointer(pointer_id, event); 350 UpdateTargetForPointer(pointer_id, event);
355 if (is_mouse_event) 351 if (is_mouse_event)
356 mouse_cursor_source_window_ = pointer_targets_[pointer_id].window; 352 mouse_cursor_source_window_ = pointer_targets_[pointer_id].window;
357 353
358 PointerTarget& pointer_target = pointer_targets_[pointer_id]; 354 PointerTarget& pointer_target = pointer_targets_[pointer_id];
359 if (pointer_target.is_pointer_down) { 355 if (pointer_target.is_pointer_down) {
360 if (is_mouse_event) 356 if (is_mouse_event)
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
570 566
571 void EventDispatcher::OnWindowDestroyed(ServerWindow* window) { 567 void EventDispatcher::OnWindowDestroyed(ServerWindow* window) {
572 CancelPointerEventsToTarget(window); 568 CancelPointerEventsToTarget(window);
573 569
574 if (mouse_cursor_source_window_ == window) 570 if (mouse_cursor_source_window_ == window)
575 mouse_cursor_source_window_ = nullptr; 571 mouse_cursor_source_window_ = nullptr;
576 } 572 }
577 573
578 } // namespace ws 574 } // namespace ws
579 } // namespace ui 575 } // namespace ui
OLDNEW
« no previous file with comments | « mojo/converters/blink/blink_input_events_type_converters_unittest.cc ('k') | services/ui/ws/event_dispatcher_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698