OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // This file defines utility functions for X11 (Linux only). This code has been | 5 // This file defines utility functions for X11 (Linux only). This code has been |
6 // ported from XCB since we can't use XCB on Ubuntu while its 32-bit support | 6 // ported from XCB since we can't use XCB on Ubuntu while its 32-bit support |
7 // remains woefully incomplete. | 7 // remains woefully incomplete. |
8 | 8 |
9 #include "ui/base/x/x11_util.h" | 9 #include "ui/base/x/x11_util.h" |
10 | 10 |
(...skipping 17 matching lines...) Expand all Loading... |
28 #include "base/message_loop/message_loop.h" | 28 #include "base/message_loop/message_loop.h" |
29 #include "base/metrics/histogram.h" | 29 #include "base/metrics/histogram.h" |
30 #include "base/strings/string_number_conversions.h" | 30 #include "base/strings/string_number_conversions.h" |
31 #include "base/strings/string_util.h" | 31 #include "base/strings/string_util.h" |
32 #include "base/strings/stringprintf.h" | 32 #include "base/strings/stringprintf.h" |
33 #include "base/sys_byteorder.h" | 33 #include "base/sys_byteorder.h" |
34 #include "base/threading/thread.h" | 34 #include "base/threading/thread.h" |
35 #include "third_party/skia/include/core/SkBitmap.h" | 35 #include "third_party/skia/include/core/SkBitmap.h" |
36 #include "third_party/skia/include/core/SkPostConfig.h" | 36 #include "third_party/skia/include/core/SkPostConfig.h" |
37 #include "ui/base/touch/touch_factory_x11.h" | 37 #include "ui/base/touch/touch_factory_x11.h" |
38 #include "ui/base/x/device_data_manager.h" | |
39 #include "ui/base/x/x11_error_tracker.h" | 38 #include "ui/base/x/x11_error_tracker.h" |
40 #include "ui/base/x/x11_util_internal.h" | 39 #include "ui/base/x/x11_util_internal.h" |
41 #include "ui/events/event_utils.h" | 40 #include "ui/events/event_utils.h" |
42 #include "ui/events/keycodes/keyboard_code_conversion_x.h" | 41 #include "ui/events/keycodes/keyboard_code_conversion_x.h" |
| 42 #include "ui/events/x/device_data_manager.h" |
43 #include "ui/gfx/canvas.h" | 43 #include "ui/gfx/canvas.h" |
44 #include "ui/gfx/image/image_skia.h" | 44 #include "ui/gfx/image/image_skia.h" |
45 #include "ui/gfx/image/image_skia_rep.h" | 45 #include "ui/gfx/image/image_skia_rep.h" |
46 #include "ui/gfx/point.h" | 46 #include "ui/gfx/point.h" |
47 #include "ui/gfx/point_conversions.h" | 47 #include "ui/gfx/point_conversions.h" |
48 #include "ui/gfx/rect.h" | 48 #include "ui/gfx/rect.h" |
49 #include "ui/gfx/size.h" | 49 #include "ui/gfx/size.h" |
50 | 50 |
51 #if defined(OS_FREEBSD) | 51 #if defined(OS_FREEBSD) |
52 #include <sys/sysctl.h> | 52 #include <sys/sysctl.h> |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 max_length, // max length to get | 128 max_length, // max length to get |
129 False, // deleted | 129 False, // deleted |
130 AnyPropertyType, | 130 AnyPropertyType, |
131 type, | 131 type, |
132 format, | 132 format, |
133 num_items, | 133 num_items, |
134 &remaining_bytes, | 134 &remaining_bytes, |
135 property); | 135 property); |
136 } | 136 } |
137 | 137 |
138 // Converts ui::EventType to XKeyEvent state. | |
139 unsigned int XKeyEventState(int flags) { | |
140 return | |
141 ((flags & ui::EF_SHIFT_DOWN) ? ShiftMask : 0) | | |
142 ((flags & ui::EF_CONTROL_DOWN) ? ControlMask : 0) | | |
143 ((flags & ui::EF_ALT_DOWN) ? Mod1Mask : 0) | | |
144 ((flags & ui::EF_CAPS_LOCK_DOWN) ? LockMask : 0); | |
145 } | |
146 | |
147 // Converts EventType to XKeyEvent type. | |
148 int XKeyEventType(ui::EventType type) { | |
149 switch (type) { | |
150 case ui::ET_KEY_PRESSED: | |
151 return KeyPress; | |
152 case ui::ET_KEY_RELEASED: | |
153 return KeyRelease; | |
154 default: | |
155 return 0; | |
156 } | |
157 } | |
158 | |
159 // Converts KeyboardCode to XKeyEvent keycode. | |
160 unsigned int XKeyEventKeyCode(ui::KeyboardCode key_code, | |
161 int flags, | |
162 XDisplay* display) { | |
163 const int keysym = XKeysymForWindowsKeyCode(key_code, | |
164 flags & ui::EF_SHIFT_DOWN); | |
165 // Tests assume the keycode for XK_less is equal to the one of XK_comma, | |
166 // but XKeysymToKeycode returns 94 for XK_less while it returns 59 for | |
167 // XK_comma. Here we convert the value for XK_less to the value for XK_comma. | |
168 return (keysym == XK_less) ? 59 : XKeysymToKeycode(display, keysym); | |
169 } | |
170 | |
171 // A process wide singleton that manages the usage of X cursors. | 138 // A process wide singleton that manages the usage of X cursors. |
172 class XCursorCache { | 139 class XCursorCache { |
173 public: | 140 public: |
174 XCursorCache() {} | 141 XCursorCache() {} |
175 ~XCursorCache() { | 142 ~XCursorCache() { |
176 Clear(); | 143 Clear(); |
177 } | 144 } |
178 | 145 |
179 ::Cursor GetCursor(int cursor_shape) { | 146 ::Cursor GetCursor(int cursor_shape) { |
180 // Lookup cursor by attempting to insert a null value, which avoids | 147 // Lookup cursor by attempting to insert a null value, which avoids |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 XCustomCursorCache() {} | 244 XCustomCursorCache() {} |
278 ~XCustomCursorCache() { | 245 ~XCustomCursorCache() { |
279 Clear(); | 246 Clear(); |
280 } | 247 } |
281 | 248 |
282 std::map< ::Cursor, XCustomCursor*> cache_; | 249 std::map< ::Cursor, XCustomCursor*> cache_; |
283 DISALLOW_COPY_AND_ASSIGN(XCustomCursorCache); | 250 DISALLOW_COPY_AND_ASSIGN(XCustomCursorCache); |
284 }; | 251 }; |
285 #endif // defined(USE_AURA) | 252 #endif // defined(USE_AURA) |
286 | 253 |
287 // A singleton object that remembers remappings of mouse buttons. | |
288 class XButtonMap { | |
289 public: | |
290 static XButtonMap* GetInstance() { | |
291 return Singleton<XButtonMap>::get(); | |
292 } | |
293 | |
294 void UpdateMapping() { | |
295 count_ = XGetPointerMapping(gfx::GetXDisplay(), map_, arraysize(map_)); | |
296 } | |
297 | |
298 int GetMappedButton(int button) { | |
299 return button > 0 && button <= count_ ? map_[button - 1] : button; | |
300 } | |
301 | |
302 private: | |
303 friend struct DefaultSingletonTraits<XButtonMap>; | |
304 | |
305 XButtonMap() { | |
306 UpdateMapping(); | |
307 } | |
308 | |
309 ~XButtonMap() {} | |
310 | |
311 unsigned char map_[256]; | |
312 int count_; | |
313 | |
314 DISALLOW_COPY_AND_ASSIGN(XButtonMap); | |
315 }; | |
316 | |
317 bool IsShapeAvailable() { | 254 bool IsShapeAvailable() { |
318 int dummy; | 255 int dummy; |
319 static bool is_shape_available = | 256 static bool is_shape_available = |
320 XShapeQueryExtension(gfx::GetXDisplay(), &dummy, &dummy); | 257 XShapeQueryExtension(gfx::GetXDisplay(), &dummy, &dummy); |
321 return is_shape_available; | 258 return is_shape_available; |
322 | 259 |
323 } | 260 } |
324 | 261 |
325 } // namespace | 262 } // namespace |
326 | 263 |
(...skipping 1041 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1368 // TODO(erg): Actually doing this correctly would require pulling out xrandr, | 1305 // TODO(erg): Actually doing this correctly would require pulling out xrandr, |
1369 // which we don't even do in the desktop screen yet. | 1306 // which we don't even do in the desktop screen yet. |
1370 ::XDisplay* display = gfx::GetXDisplay(); | 1307 ::XDisplay* display = gfx::GetXDisplay(); |
1371 ::Screen* screen = DefaultScreenOfDisplay(display); | 1308 ::Screen* screen = DefaultScreenOfDisplay(display); |
1372 int width = WidthOfScreen(screen); | 1309 int width = WidthOfScreen(screen); |
1373 int height = HeightOfScreen(screen); | 1310 int height = HeightOfScreen(screen); |
1374 return window_rect.size() == gfx::Size(width, height); | 1311 return window_rect.size() == gfx::Size(width, height); |
1375 #endif | 1312 #endif |
1376 } | 1313 } |
1377 | 1314 |
1378 bool IsMotionEvent(XEvent* event) { | |
1379 int type = event->type; | |
1380 if (type == GenericEvent) | |
1381 type = event->xgeneric.evtype; | |
1382 return type == MotionNotify; | |
1383 } | |
1384 | |
1385 int GetMappedButton(int button) { | |
1386 return XButtonMap::GetInstance()->GetMappedButton(button); | |
1387 } | |
1388 | |
1389 void UpdateButtonMap() { | |
1390 XButtonMap::GetInstance()->UpdateMapping(); | |
1391 } | |
1392 | |
1393 void InitXKeyEventForTesting(EventType type, | |
1394 KeyboardCode key_code, | |
1395 int flags, | |
1396 XEvent* event) { | |
1397 CHECK(event); | |
1398 XDisplay* display = gfx::GetXDisplay(); | |
1399 XKeyEvent key_event; | |
1400 key_event.type = XKeyEventType(type); | |
1401 CHECK_NE(0, key_event.type); | |
1402 key_event.serial = 0; | |
1403 key_event.send_event = 0; | |
1404 key_event.display = display; | |
1405 key_event.time = 0; | |
1406 key_event.window = 0; | |
1407 key_event.root = 0; | |
1408 key_event.subwindow = 0; | |
1409 key_event.x = 0; | |
1410 key_event.y = 0; | |
1411 key_event.x_root = 0; | |
1412 key_event.y_root = 0; | |
1413 key_event.state = XKeyEventState(flags); | |
1414 key_event.keycode = XKeyEventKeyCode(key_code, flags, display); | |
1415 key_event.same_screen = 1; | |
1416 event->type = key_event.type; | |
1417 event->xkey = key_event; | |
1418 } | |
1419 | |
1420 const unsigned char* XRefcountedMemory::front() const { | 1315 const unsigned char* XRefcountedMemory::front() const { |
1421 return x11_data_; | 1316 return x11_data_; |
1422 } | 1317 } |
1423 | 1318 |
1424 size_t XRefcountedMemory::size() const { | 1319 size_t XRefcountedMemory::size() const { |
1425 return length_; | 1320 return length_; |
1426 } | 1321 } |
1427 | 1322 |
1428 XRefcountedMemory::~XRefcountedMemory() { | 1323 XRefcountedMemory::~XRefcountedMemory() { |
1429 XFree(x11_data_); | 1324 XFree(x11_data_); |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1587 << "request_code " << static_cast<int>(error_event.request_code) << ", " | 1482 << "request_code " << static_cast<int>(error_event.request_code) << ", " |
1588 << "minor_code " << static_cast<int>(error_event.minor_code) | 1483 << "minor_code " << static_cast<int>(error_event.minor_code) |
1589 << " (" << request_str << ")"; | 1484 << " (" << request_str << ")"; |
1590 } | 1485 } |
1591 | 1486 |
1592 // ---------------------------------------------------------------------------- | 1487 // ---------------------------------------------------------------------------- |
1593 // End of x11_util_internal.h | 1488 // End of x11_util_internal.h |
1594 | 1489 |
1595 | 1490 |
1596 } // namespace ui | 1491 } // namespace ui |
OLD | NEW |