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

Side by Side Diff: ash/pointer_watcher_delegate_aura.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, 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "ash/pointer_watcher_delegate_aura.h" 5 #include "ash/pointer_watcher_delegate_aura.h"
6 6
7 #include "ash/shell.h" 7 #include "ash/shell.h"
8 #include "ui/aura/client/screen_position_client.h" 8 #include "ui/aura/client/screen_position_client.h"
9 #include "ui/aura/window.h" 9 #include "ui/aura/window.h"
10 #include "ui/display/screen.h"
10 #include "ui/events/event.h" 11 #include "ui/events/event.h"
11 #include "ui/events/event_constants.h" 12 #include "ui/events/event_constants.h"
12 #include "ui/gfx/geometry/point.h" 13 #include "ui/gfx/geometry/point.h"
13 #include "ui/views/pointer_watcher.h" 14 #include "ui/views/pointer_watcher.h"
14 #include "ui/views/widget/widget.h" 15 #include "ui/views/widget/widget.h"
15 16
16 namespace ash { 17 namespace ash {
17 18
18 PointerWatcherDelegateAura::PointerWatcherDelegateAura() { 19 PointerWatcherDelegateAura::PointerWatcherDelegateAura() {
19 Shell::GetInstance()->AddPreTargetHandler(this); 20 Shell::GetInstance()->AddPreTargetHandler(this);
(...skipping 17 matching lines...) Expand all
37 } 38 }
38 } 39 }
39 40
40 void PointerWatcherDelegateAura::RemovePointerWatcher( 41 void PointerWatcherDelegateAura::RemovePointerWatcher(
41 views::PointerWatcher* watcher) { 42 views::PointerWatcher* watcher) {
42 non_move_watchers_.RemoveObserver(watcher); 43 non_move_watchers_.RemoveObserver(watcher);
43 move_watchers_.RemoveObserver(watcher); 44 move_watchers_.RemoveObserver(watcher);
44 } 45 }
45 46
46 void PointerWatcherDelegateAura::OnMouseEvent(ui::MouseEvent* event) { 47 void PointerWatcherDelegateAura::OnMouseEvent(ui::MouseEvent* event) {
47 if (event->type() == ui::ET_MOUSE_CAPTURE_CHANGED) {
48 FOR_EACH_OBSERVER(views::PointerWatcher, non_move_watchers_,
49 OnMouseCaptureChanged());
50 FOR_EACH_OBSERVER(views::PointerWatcher, move_watchers_,
51 OnMouseCaptureChanged());
52 return;
53 }
54
55 // For compatibility with the mus version, don't send drags. 48 // For compatibility with the mus version, don't send drags.
56 if (event->type() != ui::ET_MOUSE_PRESSED && 49 if (event->type() != ui::ET_MOUSE_PRESSED &&
57 event->type() != ui::ET_MOUSE_RELEASED && 50 event->type() != ui::ET_MOUSE_RELEASED &&
58 event->type() != ui::ET_MOUSE_MOVED) 51 event->type() != ui::ET_MOUSE_MOVED &&
52 event->type() != ui::ET_MOUSEWHEEL &&
53 event->type() != ui::ET_MOUSE_CAPTURE_CHANGED)
59 return; 54 return;
60 55
61 DCHECK(ui::PointerEvent::CanConvertFrom(*event)); 56 DCHECK(ui::PointerEvent::CanConvertFrom(*event));
62 NotifyWatchers(ui::PointerEvent(*event), *event); 57 NotifyWatchers(ui::PointerEvent(*event), *event);
63 } 58 }
64 59
65 void PointerWatcherDelegateAura::OnTouchEvent(ui::TouchEvent* event) { 60 void PointerWatcherDelegateAura::OnTouchEvent(ui::TouchEvent* event) {
66 // For compatibility with the mus version, don't send drags. 61 // For compatibility with the mus version, don't send drags.
67 if (event->type() != ui::ET_TOUCH_PRESSED && 62 if (event->type() != ui::ET_TOUCH_PRESSED &&
68 event->type() != ui::ET_TOUCH_RELEASED) 63 event->type() != ui::ET_TOUCH_RELEASED)
69 return; 64 return;
70 65
71 DCHECK(ui::PointerEvent::CanConvertFrom(*event)); 66 DCHECK(ui::PointerEvent::CanConvertFrom(*event));
72 NotifyWatchers(ui::PointerEvent(*event), *event); 67 NotifyWatchers(ui::PointerEvent(*event), *event);
73 } 68 }
74 69
75 gfx::Point PointerWatcherDelegateAura::GetLocationInScreen( 70 gfx::Point PointerWatcherDelegateAura::GetLocationInScreen(
76 const ui::LocatedEvent& event) const { 71 const ui::LocatedEvent& event) const {
77 aura::Window* target = static_cast<aura::Window*>(event.target()); 72 gfx::Point location_in_screen;
78 gfx::Point location_in_screen = event.location(); 73 if (event.type() == ui::ET_MOUSE_CAPTURE_CHANGED) {
79 aura::client::GetScreenPositionClient(target->GetRootWindow()) 74 location_in_screen = display::Screen::GetScreen()->GetCursorScreenPoint();
80 ->ConvertPointToScreen(target, &location_in_screen); 75 } else {
76 aura::Window* target = static_cast<aura::Window*>(event.target());
77 location_in_screen = event.location();
78 aura::client::GetScreenPositionClient(target->GetRootWindow())
79 ->ConvertPointToScreen(target, &location_in_screen);
80 }
81 return location_in_screen; 81 return location_in_screen;
82 } 82 }
83 83
84 views::Widget* PointerWatcherDelegateAura::GetTargetWidget( 84 views::Widget* PointerWatcherDelegateAura::GetTargetWidget(
85 const ui::LocatedEvent& event) const { 85 const ui::LocatedEvent& event) const {
86 aura::Window* window = static_cast<aura::Window*>(event.target()); 86 aura::Window* window = static_cast<aura::Window*>(event.target());
87 return views::Widget::GetTopLevelWidgetForNativeView(window); 87 return views::Widget::GetTopLevelWidgetForNativeView(window);
88 } 88 }
89 89
90 void PointerWatcherDelegateAura::NotifyWatchers( 90 void PointerWatcherDelegateAura::NotifyWatchers(
91 const ui::PointerEvent& event, 91 const ui::PointerEvent& event,
92 const ui::LocatedEvent& original_event) { 92 const ui::LocatedEvent& original_event) {
93 const gfx::Point screen_location(GetLocationInScreen(original_event)); 93 const gfx::Point screen_location(GetLocationInScreen(original_event));
94 views::Widget* target_widget = GetTargetWidget(original_event); 94 views::Widget* target_widget = GetTargetWidget(original_event);
95 FOR_EACH_OBSERVER( 95 FOR_EACH_OBSERVER(
96 views::PointerWatcher, move_watchers_, 96 views::PointerWatcher, move_watchers_,
97 OnPointerEventObserved(event, screen_location, target_widget)); 97 OnPointerEventObserved(event, screen_location, target_widget));
98 if (event.type() != ui::ET_POINTER_MOVED) { 98 if (event.type() != ui::ET_POINTER_MOVED) {
99 FOR_EACH_OBSERVER( 99 FOR_EACH_OBSERVER(
100 views::PointerWatcher, non_move_watchers_, 100 views::PointerWatcher, non_move_watchers_,
101 OnPointerEventObserved(event, screen_location, target_widget)); 101 OnPointerEventObserved(event, screen_location, target_widget));
102 } 102 }
103 } 103 }
104 104
105 } // namespace ash 105 } // namespace ash
OLDNEW
« no previous file with comments | « no previous file | ash/pointer_watcher_delegate_aura_unittest.cc » ('j') | services/ui/ws/event_dispatcher.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698