| 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.aspx. |
| 187 bool ShouldSendCharEventForKeyboardCode(ui::KeyboardCode keycode) { |
| 188 if ((keycode >= ui::VKEY_0 && keycode <= ui::VKEY_9) || |
| 189 (keycode >= ui::VKEY_A && keycode <= ui::VKEY_Z) || |
| 190 (keycode >= ui::VKEY_NUMPAD0 && keycode <= ui::VKEY_NUMPAD9)) { |
| 191 return true; |
| 192 } |
| 193 |
| 194 switch (keycode) { |
| 195 case ui::VKEY_BACK: |
| 196 case ui::VKEY_RETURN: |
| 197 case ui::VKEY_ESCAPE: |
| 198 case ui::VKEY_TAB: |
| 199 // In addition to the keys listed at MSDN, we include other |
| 200 // graphic-character and numpad keys. |
| 201 case ui::VKEY_MULTIPLY: |
| 202 case ui::VKEY_ADD: |
| 203 case ui::VKEY_SUBTRACT: |
| 204 case ui::VKEY_DECIMAL: |
| 205 case ui::VKEY_DIVIDE: |
| 206 case ui::VKEY_OEM_1: |
| 207 case ui::VKEY_OEM_2: |
| 208 case ui::VKEY_OEM_3: |
| 209 case ui::VKEY_OEM_4: |
| 210 case ui::VKEY_OEM_5: |
| 211 case ui::VKEY_OEM_6: |
| 212 case ui::VKEY_OEM_7: |
| 213 case ui::VKEY_OEM_102: |
| 214 case ui::VKEY_OEM_PLUS: |
| 215 case ui::VKEY_OEM_COMMA: |
| 216 case ui::VKEY_OEM_MINUS: |
| 217 case ui::VKEY_OEM_PERIOD: |
| 218 return true; |
| 219 default: |
| 220 return false; |
| 221 } |
| 222 } |
| 223 |
| 183 class DesktopHostLinux : public DesktopHost { | 224 class DesktopHostLinux : public DesktopHost { |
| 184 public: | 225 public: |
| 185 explicit DesktopHostLinux(const gfx::Rect& bounds); | 226 explicit DesktopHostLinux(const gfx::Rect& bounds); |
| 186 virtual ~DesktopHostLinux(); | 227 virtual ~DesktopHostLinux(); |
| 187 | 228 |
| 188 private: | 229 private: |
| 189 // base::MessageLoop::Dispatcher Override. | 230 // base::MessageLoop::Dispatcher Override. |
| 190 virtual DispatchStatus Dispatch(XEvent* xev) OVERRIDE; | 231 virtual DispatchStatus Dispatch(XEvent* xev) OVERRIDE; |
| 191 | 232 |
| 192 // DesktopHost Overrides. | 233 // DesktopHost Overrides. |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 XEvent* xev) { | 290 XEvent* xev) { |
| 250 bool handled = false; | 291 bool handled = false; |
| 251 switch (xev->type) { | 292 switch (xev->type) { |
| 252 case Expose: | 293 case Expose: |
| 253 desktop_->Draw(); | 294 desktop_->Draw(); |
| 254 handled = true; | 295 handled = true; |
| 255 break; | 296 break; |
| 256 case KeyPress: { | 297 case KeyPress: { |
| 257 KeyEvent keydown_event(xev, false); | 298 KeyEvent keydown_event(xev, false); |
| 258 handled = desktop_->DispatchKeyEvent(&keydown_event); | 299 handled = desktop_->DispatchKeyEvent(&keydown_event); |
| 259 KeyEvent char_event(xev, true); | 300 if (ShouldSendCharEventForKeyboardCode(keydown_event.key_code())) { |
| 260 handled |= desktop_->DispatchKeyEvent(&char_event); | 301 KeyEvent char_event(xev, true); |
| 302 handled |= desktop_->DispatchKeyEvent(&char_event); |
| 303 } |
| 261 break; | 304 break; |
| 262 } | 305 } |
| 263 case KeyRelease: { | 306 case KeyRelease: { |
| 264 KeyEvent keyup_event(xev, false); | 307 KeyEvent keyup_event(xev, false); |
| 265 handled = desktop_->DispatchKeyEvent(&keyup_event); | 308 handled = desktop_->DispatchKeyEvent(&keyup_event); |
| 266 break; | 309 break; |
| 267 } | 310 } |
| 268 case ButtonPress: | 311 case ButtonPress: |
| 269 case ButtonRelease: { | 312 case ButtonRelease: { |
| 270 MouseEvent mouseev(xev); | 313 MouseEvent mouseev(xev); |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 return new DesktopHostLinux(bounds); | 483 return new DesktopHostLinux(bounds); |
| 441 } | 484 } |
| 442 | 485 |
| 443 // static | 486 // static |
| 444 gfx::Size DesktopHost::GetNativeDisplaySize() { | 487 gfx::Size DesktopHost::GetNativeDisplaySize() { |
| 445 ::Display* xdisplay = base::MessagePumpX::GetDefaultXDisplay(); | 488 ::Display* xdisplay = base::MessagePumpX::GetDefaultXDisplay(); |
| 446 return gfx::Size(DisplayWidth(xdisplay, 0), DisplayHeight(xdisplay, 0)); | 489 return gfx::Size(DisplayWidth(xdisplay, 0), DisplayHeight(xdisplay, 0)); |
| 447 } | 490 } |
| 448 | 491 |
| 449 } // namespace aura | 492 } // namespace aura |
| OLD | NEW |