| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "content/public/browser/native_web_keyboard_event.h" | 5 #include "content/public/browser/native_web_keyboard_event.h" |
| 6 | 6 |
| 7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
| 8 #include "content/browser/renderer_host/input/web_input_event_builders_android.h
" | 8 #include "content/browser/renderer_host/input/web_input_event_builders_android.h
" |
| 9 #include "ui/gfx/native_widget_types.h" | 9 #include "ui/gfx/native_widget_types.h" |
| 10 | 10 |
| 11 namespace { | 11 namespace { |
| 12 | 12 |
| 13 jobject NewGlobalRefForKeyEvent(jobject key_event) { | 13 jobject NewGlobalRefForKeyEvent(jobject key_event) { |
| 14 if (key_event == nullptr) return nullptr; | 14 if (key_event == nullptr) return nullptr; |
| 15 return base::android::AttachCurrentThread()->NewGlobalRef(key_event); | 15 return base::android::AttachCurrentThread()->NewGlobalRef(key_event); |
| 16 } | 16 } |
| 17 | 17 |
| 18 void DeleteGlobalRefForKeyEvent(jobject key_event) { | 18 void DeleteGlobalRefForKeyEvent(jobject key_event) { |
| 19 if (key_event != nullptr) | 19 if (key_event != nullptr) |
| 20 base::android::AttachCurrentThread()->DeleteGlobalRef(key_event); | 20 base::android::AttachCurrentThread()->DeleteGlobalRef(key_event); |
| 21 } | 21 } |
| 22 | 22 |
| 23 } | 23 } |
| 24 | 24 |
| 25 namespace content { | 25 namespace content { |
| 26 | 26 |
| 27 NativeWebKeyboardEvent::NativeWebKeyboardEvent() | 27 NativeWebKeyboardEvent::NativeWebKeyboardEvent() |
| 28 : os_event(nullptr), | 28 : os_event(nullptr), |
| 29 skip_in_browser(false) { | 29 skip_in_browser(false), |
| 30 is_synthetic(false) { |
| 30 } | 31 } |
| 31 | 32 |
| 32 NativeWebKeyboardEvent::NativeWebKeyboardEvent( | 33 NativeWebKeyboardEvent::NativeWebKeyboardEvent( |
| 33 JNIEnv* env, | 34 JNIEnv* env, |
| 34 const base::android::JavaRef<jobject>& android_key_event, | 35 const base::android::JavaRef<jobject>& android_key_event, |
| 35 blink::WebInputEvent::Type type, | 36 blink::WebInputEvent::Type type, |
| 36 int modifiers, | 37 int modifiers, |
| 37 double time_secs, | 38 double time_secs, |
| 38 int keycode, | 39 int keycode, |
| 39 int scancode, | 40 int scancode, |
| 40 int unicode_character, | 41 int unicode_character, |
| 41 bool is_system_key) | 42 bool is_system_key) |
| 42 : WebKeyboardEvent(WebKeyboardEventBuilder::Build(env, | 43 : WebKeyboardEvent(WebKeyboardEventBuilder::Build(env, |
| 43 android_key_event, | 44 android_key_event, |
| 44 type, | 45 type, |
| 45 modifiers, | 46 modifiers, |
| 46 time_secs, | 47 time_secs, |
| 47 keycode, | 48 keycode, |
| 48 scancode, | 49 scancode, |
| 49 unicode_character, | 50 unicode_character, |
| 50 is_system_key)), | 51 is_system_key)), |
| 51 os_event(nullptr), | 52 os_event(nullptr), |
| 52 skip_in_browser(false) { | 53 skip_in_browser(false), |
| 54 is_synthetic(false) { |
| 53 if (!android_key_event.is_null()) | 55 if (!android_key_event.is_null()) |
| 54 os_event = NewGlobalRefForKeyEvent(android_key_event.obj()); | 56 os_event = NewGlobalRefForKeyEvent(android_key_event.obj()); |
| 55 } | 57 } |
| 56 | 58 |
| 57 NativeWebKeyboardEvent::NativeWebKeyboardEvent( | 59 NativeWebKeyboardEvent::NativeWebKeyboardEvent( |
| 58 const NativeWebKeyboardEvent& other) | 60 const NativeWebKeyboardEvent& other) |
| 59 : WebKeyboardEvent(other), | 61 : WebKeyboardEvent(other), |
| 60 os_event(NewGlobalRefForKeyEvent(other.os_event)), | 62 os_event(NewGlobalRefForKeyEvent(other.os_event)), |
| 61 skip_in_browser(other.skip_in_browser) { | 63 skip_in_browser(other.skip_in_browser), |
| 64 is_synthetic(other.is_synthetic) { |
| 62 } | 65 } |
| 63 | 66 |
| 64 NativeWebKeyboardEvent& NativeWebKeyboardEvent::operator=( | 67 NativeWebKeyboardEvent& NativeWebKeyboardEvent::operator=( |
| 65 const NativeWebKeyboardEvent& other) { | 68 const NativeWebKeyboardEvent& other) { |
| 66 WebKeyboardEvent::operator=(other); | 69 WebKeyboardEvent::operator=(other); |
| 67 | 70 |
| 68 os_event = NewGlobalRefForKeyEvent(other.os_event); | 71 os_event = NewGlobalRefForKeyEvent(other.os_event); |
| 69 skip_in_browser = other.skip_in_browser; | 72 skip_in_browser = other.skip_in_browser; |
| 73 is_synthetic = other.is_synthetic; |
| 70 | 74 |
| 71 return *this; | 75 return *this; |
| 72 } | 76 } |
| 73 | 77 |
| 74 NativeWebKeyboardEvent::~NativeWebKeyboardEvent() { | 78 NativeWebKeyboardEvent::~NativeWebKeyboardEvent() { |
| 75 DeleteGlobalRefForKeyEvent(os_event); | 79 DeleteGlobalRefForKeyEvent(os_event); |
| 76 } | 80 } |
| 77 | 81 |
| 78 } // namespace content | 82 } // namespace content |
| OLD | NEW |