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

Side by Side Diff: ash/pointer_watcher_delegate_aura.cc

Issue 2267023003: ash: Eliminate PointerWatcherDelegate (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
« no previous file with comments | « ash/pointer_watcher_delegate_aura.h ('k') | ash/pointer_watcher_delegate_aura_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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "ash/pointer_watcher_delegate_aura.h"
6
7 #include "ash/shell.h"
8 #include "ui/aura/client/screen_position_client.h"
9 #include "ui/aura/window.h"
10 #include "ui/events/event.h"
11 #include "ui/events/event_constants.h"
12 #include "ui/gfx/geometry/point.h"
13 #include "ui/views/pointer_watcher.h"
14 #include "ui/views/widget/widget.h"
15
16 namespace ash {
17
18 PointerWatcherDelegateAura::PointerWatcherDelegateAura() {
19 Shell::GetInstance()->AddPreTargetHandler(this);
20 }
21
22 PointerWatcherDelegateAura::~PointerWatcherDelegateAura() {
23 Shell::GetInstance()->RemovePreTargetHandler(this);
24 }
25
26 void PointerWatcherDelegateAura::AddPointerWatcher(
27 views::PointerWatcher* watcher,
28 bool wants_moves) {
29 // We only allow a watcher to be added once. That is, we don't consider
30 // the pair of |watcher| and |wants_move| unique, just |watcher|.
31 if (wants_moves) {
32 DCHECK(!non_move_watchers_.HasObserver(watcher));
33 move_watchers_.AddObserver(watcher);
34 } else {
35 DCHECK(!move_watchers_.HasObserver(watcher));
36 non_move_watchers_.AddObserver(watcher);
37 }
38 }
39
40 void PointerWatcherDelegateAura::RemovePointerWatcher(
41 views::PointerWatcher* watcher) {
42 non_move_watchers_.RemoveObserver(watcher);
43 move_watchers_.RemoveObserver(watcher);
44 }
45
46 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.
56 if (event->type() != ui::ET_MOUSE_PRESSED &&
57 event->type() != ui::ET_MOUSE_RELEASED &&
58 event->type() != ui::ET_MOUSE_MOVED)
59 return;
60
61 DCHECK(ui::PointerEvent::CanConvertFrom(*event));
62 NotifyWatchers(ui::PointerEvent(*event), *event);
63 }
64
65 void PointerWatcherDelegateAura::OnTouchEvent(ui::TouchEvent* event) {
66 // For compatibility with the mus version, don't send drags.
67 if (event->type() != ui::ET_TOUCH_PRESSED &&
68 event->type() != ui::ET_TOUCH_RELEASED)
69 return;
70
71 DCHECK(ui::PointerEvent::CanConvertFrom(*event));
72 NotifyWatchers(ui::PointerEvent(*event), *event);
73 }
74
75 gfx::Point PointerWatcherDelegateAura::GetLocationInScreen(
76 const ui::LocatedEvent& event) const {
77 aura::Window* target = static_cast<aura::Window*>(event.target());
78 gfx::Point location_in_screen = event.location();
79 aura::client::GetScreenPositionClient(target->GetRootWindow())
80 ->ConvertPointToScreen(target, &location_in_screen);
81 return location_in_screen;
82 }
83
84 views::Widget* PointerWatcherDelegateAura::GetTargetWidget(
85 const ui::LocatedEvent& event) const {
86 aura::Window* window = static_cast<aura::Window*>(event.target());
87 return views::Widget::GetTopLevelWidgetForNativeView(window);
88 }
89
90 void PointerWatcherDelegateAura::NotifyWatchers(
91 const ui::PointerEvent& event,
92 const ui::LocatedEvent& original_event) {
93 const gfx::Point screen_location(GetLocationInScreen(original_event));
94 views::Widget* target_widget = GetTargetWidget(original_event);
95 FOR_EACH_OBSERVER(
96 views::PointerWatcher, move_watchers_,
97 OnPointerEventObserved(event, screen_location, target_widget));
98 if (event.type() != ui::ET_POINTER_MOVED) {
99 FOR_EACH_OBSERVER(
100 views::PointerWatcher, non_move_watchers_,
101 OnPointerEventObserved(event, screen_location, target_widget));
102 }
103 }
104
105 } // namespace ash
OLDNEW
« no previous file with comments | « ash/pointer_watcher_delegate_aura.h ('k') | ash/pointer_watcher_delegate_aura_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698