1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/public/browser/native_web_keyboard_event.h"
7 #include "base/android/jni_android.h"
8 #include "content/browser/renderer_host/input/web_input_event_builders_android.h"
9 #include "ui/gfx/native_widget_types.h"
13 jobject
NewGlobalRefForKeyEvent(jobject key_event
) {
14 if (key_event
== NULL
) return NULL
;
15 return base::android::AttachCurrentThread()->NewGlobalRef(key_event
);
18 void DeleteGlobalRefForKeyEvent(jobject key_event
) {
19 if (key_event
!= NULL
)
20 base::android::AttachCurrentThread()->DeleteGlobalRef(key_event
);
27 NativeWebKeyboardEvent::NativeWebKeyboardEvent()
29 skip_in_browser(false) {
32 NativeWebKeyboardEvent::NativeWebKeyboardEvent(
33 blink::WebInputEvent::Type type
,
34 int modifiers
, double time_secs
, int keycode
, int unicode_character
,
36 : WebKeyboardEvent(WebKeyboardEventBuilder::Build(
37 type
, modifiers
, time_secs
, keycode
, unicode_character
,
40 skip_in_browser
= false;
43 NativeWebKeyboardEvent::NativeWebKeyboardEvent(
44 jobject android_key_event
, blink::WebInputEvent::Type type
,
45 int modifiers
, double time_secs
, int keycode
, int unicode_character
,
47 : WebKeyboardEvent(WebKeyboardEventBuilder::Build(
48 type
, modifiers
, time_secs
, keycode
, unicode_character
,
50 os_event
= NewGlobalRefForKeyEvent(android_key_event
);
51 skip_in_browser
= false;
54 NativeWebKeyboardEvent::NativeWebKeyboardEvent(
55 const NativeWebKeyboardEvent
& other
)
56 : WebKeyboardEvent(other
),
57 os_event(NewGlobalRefForKeyEvent(other
.os_event
)),
58 skip_in_browser(other
.skip_in_browser
) {
61 NativeWebKeyboardEvent
& NativeWebKeyboardEvent::operator=(
62 const NativeWebKeyboardEvent
& other
) {
63 WebKeyboardEvent::operator=(other
);
65 os_event
= NewGlobalRefForKeyEvent(other
.os_event
);
66 skip_in_browser
= other
.skip_in_browser
;
71 NativeWebKeyboardEvent::~NativeWebKeyboardEvent() {
72 DeleteGlobalRefForKeyEvent(os_event
);
75 } // namespace content