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

Side by Side Diff: ash/wm/maximize_mode/scoped_disable_internal_mouse_and_keyboard_x11.cc

Issue 313913004: Block internal PlatformEvents before they are dispatched in touchview. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix updating cursor on enter notify. Created 6 years, 6 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2014 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/wm/maximize_mode/scoped_disable_internal_mouse_and_keyboard_x11.h"
6
7 #include <set>
8 #include <X11/extensions/XInput2.h>
9 #include <X11/Xlib.h>
10
11 #include "ash/display/display_controller.h"
12 #include "ash/screen_util.h"
13 #include "ash/shell.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/strings/string_util.h"
16 #include "ui/aura/client/screen_position_client.h"
17 #include "ui/aura/env.h"
18 #include "ui/aura/window.h"
19 #include "ui/aura/window_event_dispatcher.h"
20 #include "ui/aura/window_tree_host.h"
21 #include "ui/events/event.h"
22 #include "ui/events/event_utils.h"
23 #include "ui/events/keycodes/keyboard_codes_posix.h"
24 #include "ui/events/platform/platform_event_source.h"
25 #include "ui/events/x/device_data_manager_x11.h"
26 #include "ui/events/x/device_list_cache_x.h"
27 #include "ui/gfx/x/x11_types.h"
28
29 namespace ash {
30
31 namespace {
32
33 // The name of the xinput device corresponding to the internal touchpad.
34 const char kInternalTouchpadName[] = "Elan Touchpad";
35
36 // The name of the xinput device corresponding to the internal keyboard.
37 const char kInternalKeyboardName[] = "AT Translated Set 2 keyboard";
38
39 // Device id used to indicate that a device has not been detected.
40 const int kDeviceIdNone = -1;
41
42 gfx::Point GetMouseLocationInScreen() {
43 return aura::Env::GetInstance()->last_mouse_location();
44 }
45
46 void SetMouseLocationInScreen(const gfx::Point& screen_location) {
47 gfx::Display display = ash::ScreenUtil::FindDisplayContainingPoint(
48 screen_location);
49 if (!display.is_valid())
50 return;
51 aura::Window* root_window = Shell::GetInstance()->display_controller()->
52 GetRootWindowForDisplayId(display.id());
53 gfx::Point host_location(screen_location);
54 aura::client::ScreenPositionClient* client =
55 aura::client::GetScreenPositionClient(root_window);
56 if (client)
57 client->ConvertPointFromScreen(root_window, &host_location);
58 root_window->GetHost()->MoveCursorTo(host_location);
59 }
60
61 } // namespace
62
63 ScopedDisableInternalMouseAndKeyboardX11::
64 ScopedDisableInternalMouseAndKeyboardX11()
65 : touchpad_device_id_(kDeviceIdNone),
66 keyboard_device_id_(kDeviceIdNone),
67 last_mouse_location_(GetMouseLocationInScreen()) {
68
69 ui::DeviceDataManagerX11* device_data_manager =
70 static_cast<ui::DeviceDataManagerX11*>(
71 ui::DeviceDataManager::GetInstance());
72 if (device_data_manager->IsXInput2Available()) {
73 XIDeviceList xi_dev_list = ui::DeviceListCacheX::GetInstance()->
74 GetXI2DeviceList(gfx::GetXDisplay());
75 for (int i = 0; i < xi_dev_list.count; ++i) {
76 std::string device_name(xi_dev_list[i].name);
77 base::TrimWhitespaceASCII(device_name, base::TRIM_TRAILING, &device_name);
78 if (device_name == kInternalTouchpadName) {
79 touchpad_device_id_ = xi_dev_list[i].deviceid;
80 device_data_manager->DisableDevice(touchpad_device_id_);
81 } else if (device_name == kInternalKeyboardName) {
82 keyboard_device_id_ = xi_dev_list[i].deviceid;
83 device_data_manager->DisableDevice(keyboard_device_id_);
84 }
85 }
86 }
87 // Allow the accessible keys present on the side of some devices to continue
88 // working.
89 scoped_ptr<std::set<ui::KeyboardCode> > excepted_keys(
90 new std::set<ui::KeyboardCode>);
91 excepted_keys->insert(ui::VKEY_VOLUME_DOWN);
92 excepted_keys->insert(ui::VKEY_VOLUME_UP);
93 excepted_keys->insert(ui::VKEY_POWER);
94 device_data_manager->DisableKeyboard(excepted_keys.Pass());
95 ui::PlatformEventSource::GetInstance()->AddPlatformEventObserver(this);
96 }
97
98 ScopedDisableInternalMouseAndKeyboardX11::
99 ~ScopedDisableInternalMouseAndKeyboardX11() {
100 ui::DeviceDataManagerX11* device_data_manager =
101 static_cast<ui::DeviceDataManagerX11*>(
102 ui::DeviceDataManager::GetInstance());
103 if (touchpad_device_id_ != kDeviceIdNone)
104 device_data_manager->EnableDevice(touchpad_device_id_);
105 if (keyboard_device_id_ != kDeviceIdNone)
106 device_data_manager->EnableDevice(keyboard_device_id_);
107 device_data_manager->EnableKeyboard();
108 ui::PlatformEventSource::GetInstance()->RemovePlatformEventObserver(this);
109 }
110
111 void ScopedDisableInternalMouseAndKeyboardX11::WillProcessEvent(
112 const ui::PlatformEvent& event) {
113 }
114
115 void ScopedDisableInternalMouseAndKeyboardX11::DidProcessEvent(
116 const ui::PlatformEvent& event) {
117 if (event->type != GenericEvent)
118 return;
119 XIDeviceEvent* xievent =
120 static_cast<XIDeviceEvent*>(event->xcookie.data);
121 ui::DeviceDataManagerX11* device_data_manager =
122 static_cast<ui::DeviceDataManagerX11*>(
123 ui::DeviceDataManager::GetInstance());
124 if (xievent->evtype != XI_Motion ||
125 device_data_manager->IsFlingEvent(event) ||
126 device_data_manager->IsScrollEvent(event) ||
127 device_data_manager->IsCMTMetricsEvent(event)) {
128 return;
129 }
130 if (xievent->sourceid == touchpad_device_id_) {
131 // The cursor will have already moved even though the move event will be
132 // blocked. Move the mouse cursor back to its last known location resulting
133 // from an external mouse to prevent the internal touchpad from moving it.
134 SetMouseLocationInScreen(last_mouse_location_);
135 } else {
136 // Track the last location seen from an external mouse event.
137 last_mouse_location_ = GetMouseLocationInScreen();
138 }
139 }
140
141 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/maximize_mode/scoped_disable_internal_mouse_and_keyboard_x11.h ('k') | ui/aura/window_tree_host_x11.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698