diff options
Diffstat (limited to 'content/common')
-rw-r--r-- | content/common/native_web_keyboard_event.h | 28 | ||||
-rw-r--r-- | content/common/native_web_keyboard_event_views.cc | 86 |
2 files changed, 113 insertions, 1 deletions
diff --git a/content/common/native_web_keyboard_event.h b/content/common/native_web_keyboard_event.h index 08de652..6e94a34 100644 --- a/content/common/native_web_keyboard_event.h +++ b/content/common/native_web_keyboard_event.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 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. @@ -7,6 +7,7 @@ #pragma once #include "base/basictypes.h" +#include "build/build_config.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" #if defined(OS_WIN) @@ -21,6 +22,12 @@ class NSEvent; typedef struct _GdkEventKey GdkEventKey; #endif +#if defined(TOOLKIT_VIEWS) +namespace views { +class KeyEvent; +} +#endif + // Owns a platform specific event; used to pass own and pass event through // platform independent code. struct NativeWebKeyboardEvent : public WebKit::WebKeyboardEvent { @@ -34,12 +41,31 @@ struct NativeWebKeyboardEvent : public WebKit::WebKeyboardEvent { int state, double time_stamp_seconds); #elif defined(TOOLKIT_USES_GTK) + // TODO(suzhe): Limit these constructors to Linux native Gtk port. + // For Linux Views port, after using RenderWidgetHostViewViews to replace + // RenderWidgetHostViewGtk, we can use constructors for TOOLKIT_VIEWS defined + // below. explicit NativeWebKeyboardEvent(const GdkEventKey* event); NativeWebKeyboardEvent(wchar_t character, int state, double time_stamp_seconds); #endif +#if defined(TOOLKIT_VIEWS) + // TODO(suzhe): remove once we get rid of Gtk from Views. + struct FromViewsEvent {}; + // These two constructors are shared between Windows and Linux Views ports. + explicit NativeWebKeyboardEvent(const views::KeyEvent& event); + // TODO(suzhe): Sadly, we need to add a meanless FromViewsEvent parameter to + // distinguish between this contructor and above Gtk one, because they use + // different modifier flags. We can remove this extra parameter as soon as we + // disable above Gtk constructor in Linux Views port. + NativeWebKeyboardEvent(uint16 character, + int flags, + double time_stamp_seconds, + FromViewsEvent); +#endif + NativeWebKeyboardEvent(const NativeWebKeyboardEvent& event); ~NativeWebKeyboardEvent(); diff --git a/content/common/native_web_keyboard_event_views.cc b/content/common/native_web_keyboard_event_views.cc new file mode 100644 index 0000000..8c6eb12 --- /dev/null +++ b/content/common/native_web_keyboard_event_views.cc @@ -0,0 +1,86 @@ +// Copyright (c) 2011 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 "content/common/native_web_keyboard_event.h" + +#if defined(TOOLKIT_USES_GTK) +#include <gdk/gdk.h> +#endif + +#include "base/logging.h" +#include "views/events/event.h" + +namespace { + +int ViewsFlagsToWebInputEventModifiers(int flags) { + return + (flags & ui::EF_SHIFT_DOWN ? WebKit::WebInputEvent::ShiftKey : 0) | + (flags & ui::EF_CONTROL_DOWN ? WebKit::WebInputEvent::ControlKey : 0) | + (flags & ui::EF_CAPS_LOCK_DOWN ? WebKit::WebInputEvent::CapsLockOn : 0) | + (flags & ui::EF_ALT_DOWN ? WebKit::WebInputEvent::AltKey : 0); +} + +} // namespace + +NativeWebKeyboardEvent::NativeWebKeyboardEvent( + const views::KeyEvent& event) + : skip_in_browser(false) { + DCHECK(event.type() == ui::ET_KEY_PRESSED || + event.type() == ui::ET_KEY_RELEASED); + + if (event.type() == ui::ET_KEY_PRESSED) + type = WebKit::WebInputEvent::RawKeyDown; + else + type = WebKit::WebInputEvent::KeyUp; + + modifiers = ViewsFlagsToWebInputEventModifiers(event.flags()); + timeStampSeconds = event.time_stamp().ToDoubleT(); + windowsKeyCode = event.key_code(); + nativeKeyCode = windowsKeyCode; + text[0] = event.GetCharacter(); + unmodifiedText[0] = event.GetUnmodifiedCharacter(); + setKeyIdentifierFromWindowsKeyCode(); + +#if defined(OS_WIN) + // |os_event| is a MSG struct, so we can copy it directly. + os_event = event.native_event(); +#elif defined(TOOLKIT_USES_GTK) + if (event.native_event()) { + os_event = + reinterpret_cast<GdkEventKey*>(gdk_event_copy(event.native_event())); + nativeKeyCode = os_event->keyval; + } else { + os_event = NULL; + } +#endif + +#if defined(OS_LINUX) + match_edit_command = false; +#endif +} + +NativeWebKeyboardEvent::NativeWebKeyboardEvent(uint16 character, + int flags, + double time_stamp_seconds, + FromViewsEvent) + : skip_in_browser(true) { + type = WebKit::WebInputEvent::Char; + modifiers = ViewsFlagsToWebInputEventModifiers(flags); + timeStampSeconds = time_stamp_seconds; + windowsKeyCode = character; + nativeKeyCode = character; + text[0] = character; + unmodifiedText[0] = character; + isSystemKey = (flags & ui::EF_ALT_DOWN) != 0; + +#if defined(OS_WIN) + memset(&os_event, 0, sizeof(os_event)); +#elif defined(TOOLKIT_USES_GTK) + os_event = NULL; +#endif + +#if defined(OS_LINUX) + match_edit_command = false; +#endif +} |