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
66
67
68
69
70
71
ash / display / mouse_cursor_event_filter.cc [blame]
// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/display/mouse_cursor_event_filter.h"
#include <cmath>
#include "ash/display/cursor_window_controller.h"
#include "ash/display/display_util.h"
#include "ash/display/mouse_warp_controller.h"
#include "ash/display/window_tree_host_manager.h"
#include "ash/shell.h"
#include "ui/events/event.h"
namespace ash {
MouseCursorEventFilter::MouseCursorEventFilter() : mouse_warp_enabled_(true) {
Shell::Get()->display_manager()->AddDisplayManagerObserver(this);
}
MouseCursorEventFilter::~MouseCursorEventFilter() {
Shell::Get()->display_manager()->RemoveDisplayManagerObserver(this);
}
void MouseCursorEventFilter::ShowSharedEdgeIndicator(aura::Window* from) {
mouse_warp_controller_ =
CreateMouseWarpController(Shell::Get()->display_manager(), from);
}
void MouseCursorEventFilter::HideSharedEdgeIndicator() {
OnDidApplyDisplayChanges();
}
void MouseCursorEventFilter::OnDisplaysInitialized() {
OnDidApplyDisplayChanges();
}
void MouseCursorEventFilter::OnDidApplyDisplayChanges() {
mouse_warp_controller_ =
CreateMouseWarpController(Shell::Get()->display_manager(), nullptr);
}
void MouseCursorEventFilter::OnMouseEvent(ui::MouseEvent* event) {
// Don't warp due to synthesized event.
if (event->flags() & ui::EF_IS_SYNTHESIZED)
return;
// Handle both MOVED and DRAGGED events here because when the mouse pointer
// enters the other root window while dragging, the underlying window system
// (at least X11) stops generating a ui::EventType::kMouseMoved event.
if (event->type() != ui::EventType::kMouseMoved &&
event->type() != ui::EventType::kMouseDragged) {
return;
}
bool mouse_warp_enabled =
mouse_warp_enabled_ &&
(event->flags() & ui::EF_NOT_SUITABLE_FOR_MOUSE_WARPING) == 0;
Shell::Get()
->window_tree_host_manager()
->cursor_window_controller()
->UpdateLocation();
mouse_warp_controller_->SetEnabled(mouse_warp_enabled);
if (mouse_warp_controller_->WarpMouseCursor(event))
event->StopPropagation();
}
} // namespace ash