diff options
-rw-r--r-- | content/browser/renderer_host/native_web_keyboard_event_android.cc | 73 | ||||
-rw-r--r-- | content/content_browser.gypi | 1 | ||||
-rw-r--r-- | content/public/browser/native_web_keyboard_event.h | 17 | ||||
-rw-r--r-- | ui/gfx/native_widget_types.h | 8 |
4 files changed, 97 insertions, 2 deletions
diff --git a/content/browser/renderer_host/native_web_keyboard_event_android.cc b/content/browser/renderer_host/native_web_keyboard_event_android.cc new file mode 100644 index 0000000..2dfb7f2 --- /dev/null +++ b/content/browser/renderer_host/native_web_keyboard_event_android.cc @@ -0,0 +1,73 @@ +// Copyright (c) 2012 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/public/browser/native_web_keyboard_event.h" + +#include "base/android/jni_android.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/android/WebInputEventFactory.h" +#include "ui/gfx/native_widget_types.h" + +using WebKit::WebInputEventFactory; + +namespace { + +jobject NewGlobalRefForKeyEvent(jobject key_event) { + if (key_event == NULL) return NULL; + return base::android::AttachCurrentThread()->NewGlobalRef(key_event); +} + +void DeleteGlobalRefForKeyEvent(jobject key_event) { + if (key_event != NULL) + base::android::AttachCurrentThread()->DeleteGlobalRef(key_event); +} + +} + +NativeWebKeyboardEvent::NativeWebKeyboardEvent() + : os_event(NULL), + skip_in_browser(false) { +} + +NativeWebKeyboardEvent::NativeWebKeyboardEvent( + WebKit::WebInputEvent::Type type, + int modifiers, double time_secs, int keycode, int unicode_character, + bool is_system_key) + : WebKeyboardEvent(WebInputEventFactory::keyboardEvent( + type, modifiers, time_secs, keycode, unicode_character, + is_system_key)) { + os_event = NULL; + skip_in_browser = false; +} + +NativeWebKeyboardEvent::NativeWebKeyboardEvent( + jobject android_key_event, WebKit::WebInputEvent::Type type, + int modifiers, double time_secs, int keycode, int unicode_character, + bool is_system_key) + : WebKeyboardEvent(WebInputEventFactory::keyboardEvent( + type, modifiers, time_secs, keycode, unicode_character, + is_system_key)) { + os_event = NewGlobalRefForKeyEvent(android_key_event); + skip_in_browser = false; +} + +NativeWebKeyboardEvent::NativeWebKeyboardEvent( + const NativeWebKeyboardEvent& other) + : WebKeyboardEvent(other), + os_event(NewGlobalRefForKeyEvent(other.os_event)), + skip_in_browser(other.skip_in_browser) { +} + +NativeWebKeyboardEvent& NativeWebKeyboardEvent::operator=( + const NativeWebKeyboardEvent& other) { + WebKeyboardEvent::operator=(other); + + os_event = NewGlobalRefForKeyEvent(other.os_event); + skip_in_browser = other.skip_in_browser; + + return *this; +} + +NativeWebKeyboardEvent::~NativeWebKeyboardEvent() { + DeleteGlobalRefForKeyEvent(os_event); +} diff --git a/content/content_browser.gypi b/content/content_browser.gypi index 49e46af..fa2aa26 100644 --- a/content/content_browser.gypi +++ b/content/content_browser.gypi @@ -497,6 +497,7 @@ 'browser/renderer_host/media/video_capture_host.h', 'browser/renderer_host/media/video_capture_manager.cc', 'browser/renderer_host/media/video_capture_manager.h', + 'browser/renderer_host/native_web_keyboard_event_android.cc', 'browser/renderer_host/native_web_keyboard_event_aura.cc', 'browser/renderer_host/native_web_keyboard_event_gtk.cc', 'browser/renderer_host/native_web_keyboard_event_mac.mm', diff --git a/content/public/browser/native_web_keyboard_event.h b/content/public/browser/native_web_keyboard_event.h index 41926d3..4cb2c67 100644 --- a/content/public/browser/native_web_keyboard_event.h +++ b/content/public/browser/native_web_keyboard_event.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -35,6 +35,21 @@ struct CONTENT_EXPORT NativeWebKeyboardEvent : NativeWebKeyboardEvent(wchar_t character, int state, double time_stamp_seconds); +#elif defined(OS_ANDROID) + NativeWebKeyboardEvent(WebKit::WebInputEvent::Type type, + int modifiers, + double time_secs, + int keycode, + int unicode_character, + bool is_system_key); + // Takes ownership of android_key_event. + NativeWebKeyboardEvent(jobject android_key_event, + WebKit::WebInputEvent::Type type, + int modifiers, + double time_secs, + int keycode, + int unicode_character, + bool is_system_key); #endif NativeWebKeyboardEvent(const NativeWebKeyboardEvent& event); diff --git a/ui/gfx/native_widget_types.h b/ui/gfx/native_widget_types.h index 81a59a2..debd83e 100644 --- a/ui/gfx/native_widget_types.h +++ b/ui/gfx/native_widget_types.h @@ -6,6 +6,12 @@ #define UI_GFX_NATIVE_WIDGET_TYPES_H_ #pragma once +#include "build/build_config.h" + +#if defined(OS_ANDROID) +#include <jni.h> +#endif + #include "base/basictypes.h" #include "ui/base/ui_export.h" @@ -130,7 +136,7 @@ typedef void* NativeCursor; typedef ChromeView* NativeView; typedef ChromeView* NativeWindow; typedef void* NativeRegion; -typedef void* NativeEvent; +typedef jobject NativeEvent; #endif #if defined(OS_WIN) |