diff options
author | bryeung@chromium.org <bryeung@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-03 00:38:27 +0000 |
---|---|---|
committer | bryeung@chromium.org <bryeung@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-03 00:38:27 +0000 |
commit | 7f05552488f8f9ea5000512fd1972894aee7ee82 (patch) | |
tree | 0e2ed5a562335907e44307a1d99e9c6ab8d8a3ec /app/event_synthesis_gtk.cc | |
parent | 9d7e8fd4a448491817b816585d6f375d71c0a97a (diff) | |
download | chromium_src-7f05552488f8f9ea5000512fd1972894aee7ee82.zip chromium_src-7f05552488f8f9ea5000512fd1972894aee7ee82.tar.gz chromium_src-7f05552488f8f9ea5000512fd1972894aee7ee82.tar.bz2 |
Re-lands 58186:
Original message:
"""
Move the keyboard files from base/ to app/.
Also moves the associated classes/enums from base:: to app::.
TEST=try bots compile
BUG=NONE
Review URL: http://codereview.chromium.org/3165064
"""
TBR=phajdan.jr@chromium.org
Review URL: http://codereview.chromium.org/3354005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@58438 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'app/event_synthesis_gtk.cc')
-rw-r--r-- | app/event_synthesis_gtk.cc | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/app/event_synthesis_gtk.cc b/app/event_synthesis_gtk.cc new file mode 100644 index 0000000..9163fcc --- /dev/null +++ b/app/event_synthesis_gtk.cc @@ -0,0 +1,90 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "app/event_synthesis_gtk.h" + +#include "app/keyboard_code_conversion_gtk.h" + +namespace app { + +GdkEvent* SynthesizeKeyEvent(GdkWindow* window, + bool press, guint gdk_key, guint state) { + GdkEvent* event = gdk_event_new(press ? GDK_KEY_PRESS : GDK_KEY_RELEASE); + + event->key.type = press ? GDK_KEY_PRESS : GDK_KEY_RELEASE; + event->key.window = window; + if (window) + g_object_ref(window); + event->key.send_event = false; + + struct timespec ts; + clock_gettime(CLOCK_MONOTONIC, &ts); + event->key.time = ts.tv_sec * 1000 + ts.tv_nsec / 1000000; + + event->key.state = state; + event->key.keyval = gdk_key; + + GdkKeymapKey* keys; + gint n_keys; + if (event->key.keyval != 0 && + gdk_keymap_get_entries_for_keyval(gdk_keymap_get_default(), + event->key.keyval, &keys, &n_keys)) { + event->key.hardware_keycode = keys[0].keycode; + event->key.group = keys[0].group; + g_free(keys); + } + + return event; +} + +void SynthesizeKeyPressEvents(GdkWindow* window, + app::KeyboardCode key, + bool control, bool shift, bool alt, + std::vector<GdkEvent*>* events) { + if (control) + events->push_back( + SynthesizeKeyEvent(window, true, GDK_Control_L, 0)); + + if (shift) { + events->push_back(SynthesizeKeyEvent(window, true, GDK_Shift_L, + control ? GDK_CONTROL_MASK : 0)); + } + + if (alt) { + guint state = (control ? GDK_CONTROL_MASK : 0) | + (shift ? GDK_SHIFT_MASK : 0); + events->push_back( + SynthesizeKeyEvent(window, true, GDK_Alt_L, state)); + } + + // TODO(estade): handle other state flags besides control, shift, alt? + // For example caps lock. + guint state = (control ? GDK_CONTROL_MASK : 0) | + (shift ? GDK_SHIFT_MASK : 0) | + (alt ? GDK_MOD1_MASK : 0); + + guint gdk_key = GdkKeyCodeForWindowsKeyCode(key, shift); + events->push_back(SynthesizeKeyEvent(window, true, gdk_key, state)); + events->push_back(SynthesizeKeyEvent(window, false, gdk_key, state)); + + if (alt) { + guint state = (control ? GDK_CONTROL_MASK : 0) | + (shift ? GDK_SHIFT_MASK : 0) | GDK_MOD1_MASK; + events->push_back( + SynthesizeKeyEvent(window, false, GDK_Alt_L, state)); + } + + if (shift) { + events->push_back( + SynthesizeKeyEvent(window, false, GDK_Shift_L, + (control ? GDK_CONTROL_MASK : 0) | GDK_SHIFT_MASK)); + } + + if (control) { + events->push_back( + SynthesizeKeyEvent(window, false, GDK_Control_L, GDK_CONTROL_MASK)); + } +} + +} // namespace app |