OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "ui/aura/desktop_host.h" | 5 #include "ui/aura/desktop_host.h" |
6 | 6 |
7 #include <X11/cursorfont.h> | 7 #include <X11/cursorfont.h> |
8 #include <X11/Xlib.h> | 8 #include <X11/Xlib.h> |
9 | 9 |
10 // Get rid of a macro from Xlib.h that conflicts with Aura's RootWindow class. | 10 // Get rid of a macro from Xlib.h that conflicts with Aura's RootWindow class. |
11 #undef RootWindow | 11 #undef RootWindow |
12 | 12 |
13 #include <algorithm> | 13 #include <algorithm> |
14 | 14 |
15 #include "base/message_loop.h" | 15 #include "base/message_loop.h" |
16 #include "base/message_pump_x.h" | 16 #include "base/message_pump_x.h" |
17 #include "ui/aura/cursor.h" | 17 #include "ui/aura/cursor.h" |
18 #include "ui/aura/desktop.h" | 18 #include "ui/aura/desktop.h" |
19 #include "ui/aura/event.h" | 19 #include "ui/aura/event.h" |
20 #include "ui/base/keycodes/keyboard_codes.h" | |
20 #include "ui/base/touch/touch_factory.h" | 21 #include "ui/base/touch/touch_factory.h" |
21 #include "ui/base/x/x11_util.h" | 22 #include "ui/base/x/x11_util.h" |
22 #include "ui/gfx/compositor/layer.h" | 23 #include "ui/gfx/compositor/layer.h" |
23 | 24 |
24 #include <X11/cursorfont.h> | 25 #include <X11/cursorfont.h> |
25 #include <X11/extensions/XInput2.h> | 26 #include <X11/extensions/XInput2.h> |
26 #include <X11/Xlib.h> | 27 #include <X11/Xlib.h> |
27 | 28 |
28 using std::max; | 29 using std::max; |
29 using std::min; | 30 using std::min; |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
173 } else { | 174 } else { |
174 // This isn't an event we want so free its cookie data. | 175 // This isn't an event we want so free its cookie data. |
175 XFreeEventData(display, &next_event.xcookie); | 176 XFreeEventData(display, &next_event.xcookie); |
176 } | 177 } |
177 } | 178 } |
178 break; | 179 break; |
179 } | 180 } |
180 return num_coalesed; | 181 return num_coalesed; |
181 } | 182 } |
182 | 183 |
184 // We emulate Windows' WM_KEYDOWN and WM_CHAR messages. WM_CHAR events are only | |
185 // generated for certain keys; see | |
186 // http://msdn.microsoft.com/en-us/library/windows/desktop/ms646268(v=vs.85).asp x | |
187 bool ShouldSendCharEventForKeyboardCode(ui::KeyboardCode keycode) { | |
Hironori Bono
2011/10/28 05:10:12
nit: we also need true when we type graphic-charac
| |
188 return (keycode >= ui::VKEY_0 && keycode <= ui::VKEY_9) || | |
189 (keycode >= ui::VKEY_A && keycode <= ui::VKEY_Z) || | |
190 keycode == ui::VKEY_BACK || | |
191 keycode == ui::VKEY_RETURN || | |
192 keycode == ui::VKEY_ESCAPE || | |
193 // TODO: SHIFT+ENTER (linefeed)? | |
194 keycode == ui::VKEY_TAB; | |
195 } | |
196 | |
183 class DesktopHostLinux : public DesktopHost { | 197 class DesktopHostLinux : public DesktopHost { |
184 public: | 198 public: |
185 explicit DesktopHostLinux(const gfx::Rect& bounds); | 199 explicit DesktopHostLinux(const gfx::Rect& bounds); |
186 virtual ~DesktopHostLinux(); | 200 virtual ~DesktopHostLinux(); |
187 | 201 |
188 private: | 202 private: |
189 // base::MessageLoop::Dispatcher Override. | 203 // base::MessageLoop::Dispatcher Override. |
190 virtual DispatchStatus Dispatch(XEvent* xev) OVERRIDE; | 204 virtual DispatchStatus Dispatch(XEvent* xev) OVERRIDE; |
191 | 205 |
192 // DesktopHost Overrides. | 206 // DesktopHost Overrides. |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
249 XEvent* xev) { | 263 XEvent* xev) { |
250 bool handled = false; | 264 bool handled = false; |
251 switch (xev->type) { | 265 switch (xev->type) { |
252 case Expose: | 266 case Expose: |
253 desktop_->Draw(); | 267 desktop_->Draw(); |
254 handled = true; | 268 handled = true; |
255 break; | 269 break; |
256 case KeyPress: { | 270 case KeyPress: { |
257 KeyEvent keydown_event(xev, false); | 271 KeyEvent keydown_event(xev, false); |
258 handled = desktop_->DispatchKeyEvent(&keydown_event); | 272 handled = desktop_->DispatchKeyEvent(&keydown_event); |
259 KeyEvent char_event(xev, true); | 273 if (ShouldSendCharEventForKeyboardCode(keydown_event.key_code())) { |
260 handled |= desktop_->DispatchKeyEvent(&char_event); | 274 KeyEvent char_event(xev, true); |
275 handled |= desktop_->DispatchKeyEvent(&char_event); | |
276 } | |
261 break; | 277 break; |
262 } | 278 } |
263 case KeyRelease: { | 279 case KeyRelease: { |
264 KeyEvent keyup_event(xev, false); | 280 KeyEvent keyup_event(xev, false); |
265 handled = desktop_->DispatchKeyEvent(&keyup_event); | 281 handled = desktop_->DispatchKeyEvent(&keyup_event); |
266 break; | 282 break; |
267 } | 283 } |
268 case ButtonPress: | 284 case ButtonPress: |
269 case ButtonRelease: { | 285 case ButtonRelease: { |
270 MouseEvent mouseev(xev); | 286 MouseEvent mouseev(xev); |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
440 return new DesktopHostLinux(bounds); | 456 return new DesktopHostLinux(bounds); |
441 } | 457 } |
442 | 458 |
443 // static | 459 // static |
444 gfx::Size DesktopHost::GetNativeDisplaySize() { | 460 gfx::Size DesktopHost::GetNativeDisplaySize() { |
445 ::Display* xdisplay = base::MessagePumpX::GetDefaultXDisplay(); | 461 ::Display* xdisplay = base::MessagePumpX::GetDefaultXDisplay(); |
446 return gfx::Size(DisplayWidth(xdisplay, 0), DisplayHeight(xdisplay, 0)); | 462 return gfx::Size(DisplayWidth(xdisplay, 0), DisplayHeight(xdisplay, 0)); |
447 } | 463 } |
448 | 464 |
449 } // namespace aura | 465 } // namespace aura |
OLD | NEW |