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

Side by Side Diff: chrome/browser/chromeos/events/event_rewriter.cc

Issue 183893031: x11: Simplify some more event-rewrite code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: tot-merge Created 6 years, 9 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
« no previous file with comments | « chrome/browser/chromeos/events/event_rewriter.h ('k') | ui/aura/window_tree_host.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 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 "chrome/browser/chromeos/events/event_rewriter.h" 5 #include "chrome/browser/chromeos/events/event_rewriter.h"
6 6
7 #include <X11/extensions/XInput2.h> 7 #include <X11/extensions/XInput2.h>
8 #include <X11/keysym.h> 8 #include <X11/keysym.h>
9 #include <X11/XF86keysym.h> 9 #include <X11/XF86keysym.h>
10 #include <X11/Xlib.h> 10 #include <X11/Xlib.h>
11 // Get rid of macros from Xlib.h that conflicts with other parts of the code. 11 // Get rid of macros from Xlib.h that conflicts with other parts of the code.
12 #undef RootWindow 12 #undef RootWindow
13 #undef Status 13 #undef Status
14 14
15 #include <vector> 15 #include <vector>
16 16
17 #include "ash/shell.h"
18 #include "ash/wm/window_state.h" 17 #include "ash/wm/window_state.h"
19 #include "ash/wm/window_util.h" 18 #include "ash/wm/window_util.h"
20 #include "base/command_line.h" 19 #include "base/command_line.h"
21 #include "base/logging.h" 20 #include "base/logging.h"
22 #include "base/prefs/pref_service.h" 21 #include "base/prefs/pref_service.h"
23 #include "base/strings/string_util.h" 22 #include "base/strings/string_util.h"
24 #include "base/sys_info.h" 23 #include "base/sys_info.h"
25 #include "chrome/browser/chromeos/events/keyboard_driven_event_rewriter.h" 24 #include "chrome/browser/chromeos/events/keyboard_driven_event_rewriter.h"
26 #include "chrome/browser/chromeos/events/xinput_hierarchy_changed_event_listener .h" 25 #include "chrome/browser/chromeos/events/xinput_hierarchy_changed_event_listener .h"
27 #include "chrome/browser/chromeos/login/login_display_host_impl.h" 26 #include "chrome/browser/chromeos/login/login_display_host_impl.h"
28 #include "chrome/browser/chromeos/login/user_manager.h" 27 #include "chrome/browser/chromeos/login/user_manager.h"
29 #include "chrome/browser/profiles/profile_manager.h" 28 #include "chrome/browser/profiles/profile_manager.h"
30 #include "chrome/common/pref_names.h" 29 #include "chrome/common/pref_names.h"
31 #include "chromeos/chromeos_switches.h" 30 #include "chromeos/chromeos_switches.h"
32 #include "chromeos/ime/input_method_manager.h" 31 #include "chromeos/ime/input_method_manager.h"
33 #include "chromeos/ime/xkeyboard.h" 32 #include "chromeos/ime/xkeyboard.h"
34 #include "ui/aura/window_event_dispatcher.h"
35 #include "ui/base/x/x11_util.h" 33 #include "ui/base/x/x11_util.h"
36 #include "ui/events/event.h" 34 #include "ui/events/event.h"
37 #include "ui/events/event_utils.h" 35 #include "ui/events/event_utils.h"
38 #include "ui/events/keycodes/keyboard_code_conversion_x.h" 36 #include "ui/events/keycodes/keyboard_code_conversion_x.h"
39 #include "ui/views/corewm/window_util.h" 37 #include "ui/views/corewm/window_util.h"
40 38
41 namespace { 39 namespace {
42 40
43 const int kBadDeviceId = -1; 41 const int kBadDeviceId = -1;
44 42
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 132
135 } // namespace 133 } // namespace
136 134
137 namespace chromeos { 135 namespace chromeos {
138 136
139 EventRewriter::EventRewriter() 137 EventRewriter::EventRewriter()
140 : last_device_id_(kBadDeviceId), 138 : last_device_id_(kBadDeviceId),
141 xkeyboard_for_testing_(NULL), 139 xkeyboard_for_testing_(NULL),
142 keyboard_driven_event_rewriter_(new KeyboardDrivenEventRewriter), 140 keyboard_driven_event_rewriter_(new KeyboardDrivenEventRewriter),
143 pref_service_for_testing_(NULL) { 141 pref_service_for_testing_(NULL) {
144 // The ash shell isn't instantiated for our unit tests.
145 if (ash::Shell::HasInstance()) {
146 ash::Shell::GetPrimaryRootWindow()->GetHost()->AddObserver(this);
147 }
148 base::MessageLoopForUI::current()->AddObserver(this); 142 base::MessageLoopForUI::current()->AddObserver(this);
149 if (base::SysInfo::IsRunningOnChromeOS()) { 143 if (base::SysInfo::IsRunningOnChromeOS()) {
150 XInputHierarchyChangedEventListener::GetInstance()->AddObserver(this); 144 XInputHierarchyChangedEventListener::GetInstance()->AddObserver(this);
151 } 145 }
152 RefreshKeycodes(); 146 RefreshKeycodes();
153 } 147 }
154 148
155 EventRewriter::~EventRewriter() { 149 EventRewriter::~EventRewriter() {
156 base::MessageLoopForUI::current()->RemoveObserver(this); 150 base::MessageLoopForUI::current()->RemoveObserver(this);
157 if (ash::Shell::HasInstance()) {
158 ash::Shell::GetPrimaryRootWindow()->GetHost()->RemoveObserver(this);
159 }
160 if (base::SysInfo::IsRunningOnChromeOS()) { 151 if (base::SysInfo::IsRunningOnChromeOS()) {
161 XInputHierarchyChangedEventListener::GetInstance()->RemoveObserver(this); 152 XInputHierarchyChangedEventListener::GetInstance()->RemoveObserver(this);
162 } 153 }
163 } 154 }
164 155
165 EventRewriter::DeviceType EventRewriter::DeviceAddedForTesting( 156 EventRewriter::DeviceType EventRewriter::DeviceAddedForTesting(
166 int device_id, 157 int device_id,
167 const std::string& device_name) { 158 const std::string& device_name) {
168 return DeviceAddedInternal(device_id, device_name); 159 return DeviceAddedInternal(device_id, device_name);
169 } 160 }
(...skipping 17 matching lines...) Expand all
187 return kDeviceAppleKeyboard; 178 return kDeviceAppleKeyboard;
188 } 179 }
189 180
190 return kDeviceUnknown; 181 return kDeviceUnknown;
191 } 182 }
192 183
193 void EventRewriter::RewriteForTesting(XEvent* event) { 184 void EventRewriter::RewriteForTesting(XEvent* event) {
194 Rewrite(event); 185 Rewrite(event);
195 } 186 }
196 187
197 void EventRewriter::OnKeyboardMappingChanged(const aura::WindowTreeHost* host) {
198 RefreshKeycodes();
199 }
200
201 base::EventStatus EventRewriter::WillProcessEvent( 188 base::EventStatus EventRewriter::WillProcessEvent(
202 const base::NativeEvent& event) { 189 const base::NativeEvent& event) {
203 XEvent* xevent = event; 190 XEvent* xevent = event;
204 if (xevent->type == KeyPress || xevent->type == KeyRelease) 191 if (xevent->type == KeyPress || xevent->type == KeyRelease) {
205 Rewrite(xevent); 192 Rewrite(xevent);
206 else if (xevent->type == GenericEvent) 193 } else if (xevent->type == GenericEvent) {
207 RewriteLocatedEvent(xevent); 194 RewriteLocatedEvent(xevent);
195 } else if (xevent->type == MappingNotify) {
196 if (xevent->xmapping.request == MappingModifier ||
197 xevent->xmapping.request == MappingKeyboard) {
198 RefreshKeycodes();
199 }
200 }
208 return base::EVENT_CONTINUE; 201 return base::EVENT_CONTINUE;
209 } 202 }
210 203
211 void EventRewriter::DidProcessEvent(const base::NativeEvent& event) { 204 void EventRewriter::DidProcessEvent(const base::NativeEvent& event) {
212 } 205 }
213 206
214 void EventRewriter::DeviceAdded(int device_id) { 207 void EventRewriter::DeviceAdded(int device_id) {
215 DCHECK_NE(XIAllDevices, device_id); 208 DCHECK_NE(XIAllDevices, device_id);
216 DCHECK_NE(XIAllMasterDevices, device_id); 209 DCHECK_NE(XIAllMasterDevices, device_id);
217 if (device_id == XIAllDevices || device_id == XIAllMasterDevices) { 210 if (device_id == XIAllDevices || device_id == XIAllMasterDevices) {
(...skipping 678 matching lines...) Expand 10 before | Expand all | Expand 10 after
896 VLOG(1) << "Apple keyboard '" << device_name << "' connected: " 889 VLOG(1) << "Apple keyboard '" << device_name << "' connected: "
897 << "id=" << device_id; 890 << "id=" << device_id;
898 } 891 }
899 // Always overwrite the existing device_id since the X server may reuse a 892 // Always overwrite the existing device_id since the X server may reuse a
900 // device id for an unattached device. 893 // device id for an unattached device.
901 device_id_to_type_[device_id] = type; 894 device_id_to_type_[device_id] = type;
902 return type; 895 return type;
903 } 896 }
904 897
905 } // namespace chromeos 898 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/events/event_rewriter.h ('k') | ui/aura/window_tree_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698