forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pointer_watcher_delegate_aura.cc
65 lines (53 loc) · 2.24 KB
/
pointer_watcher_delegate_aura.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/pointer_watcher_delegate_aura.h"
#include "ash/shell.h"
#include "ui/aura/client/screen_position_client.h"
#include "ui/aura/window.h"
#include "ui/events/event.h"
#include "ui/events/event_constants.h"
#include "ui/gfx/geometry/point.h"
#include "ui/views/pointer_watcher.h"
#include "ui/views/widget/widget.h"
namespace ash {
PointerWatcherDelegateAura::PointerWatcherDelegateAura() {
Shell::GetInstance()->AddPreTargetHandler(this);
}
PointerWatcherDelegateAura::~PointerWatcherDelegateAura() {
Shell::GetInstance()->RemovePreTargetHandler(this);
}
void PointerWatcherDelegateAura::AddPointerWatcher(
views::PointerWatcher* watcher) {
pointer_watchers_.AddObserver(watcher);
}
void PointerWatcherDelegateAura::RemovePointerWatcher(
views::PointerWatcher* watcher) {
pointer_watchers_.RemoveObserver(watcher);
}
void PointerWatcherDelegateAura::OnMouseEvent(ui::MouseEvent* event) {
if (event->type() == ui::ET_MOUSE_PRESSED)
FOR_EACH_OBSERVER(views::PointerWatcher, pointer_watchers_,
OnMousePressed(*event, GetLocationInScreen(*event),
GetTargetWidget(*event)));
}
void PointerWatcherDelegateAura::OnTouchEvent(ui::TouchEvent* event) {
if (event->type() == ui::ET_TOUCH_PRESSED)
FOR_EACH_OBSERVER(views::PointerWatcher, pointer_watchers_,
OnTouchPressed(*event, GetLocationInScreen(*event),
GetTargetWidget(*event)));
}
gfx::Point PointerWatcherDelegateAura::GetLocationInScreen(
const ui::LocatedEvent& event) const {
aura::Window* target = static_cast<aura::Window*>(event.target());
gfx::Point location_in_screen = event.location();
aura::client::GetScreenPositionClient(target->GetRootWindow())
->ConvertPointToScreen(target, &location_in_screen);
return location_in_screen;
}
views::Widget* PointerWatcherDelegateAura::GetTargetWidget(
const ui::LocatedEvent& event) const {
aura::Window* window = static_cast<aura::Window*>(event.target());
return views::Widget::GetTopLevelWidgetForNativeView(window);
}
} // namespace ash