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.
4 
5 #ifndef CONTENT_PUBLIC_BROWSER_NATIVE_WEB_KEYBOARD_EVENT_H_
6 #define CONTENT_PUBLIC_BROWSER_NATIVE_WEB_KEYBOARD_EVENT_H_
7 
8 #include "base/compiler_specific.h"
9 #include "base/strings/string16.h"
10 #include "base/time/time.h"
11 #include "build/build_config.h"
12 #include "content/common/content_export.h"
13 #include "third_party/blink/public/common/input/web_keyboard_event.h"
14 #include "ui/gfx/native_widget_types.h"
15 
16 #if defined(OS_ANDROID)
17 #include "base/android/scoped_java_ref.h"
18 #endif
19 
20 namespace ui {
21 class KeyEvent;
22 }
23 
24 namespace content {
25 
26 // Owns a platform specific event; used to pass own and pass event through
27 // platform independent code.
28 struct CONTENT_EXPORT NativeWebKeyboardEvent : public blink::WebKeyboardEvent {
29   NativeWebKeyboardEvent(blink::WebInputEvent::Type type,
30                          int modifiers,
31                          base::TimeTicks timestamp);
32 
33   // Creates a native web keyboard event from a WebKeyboardEvent. The |os_event|
34   // member may be a synthetic event, and possibly incomplete.
35   NativeWebKeyboardEvent(const blink::WebKeyboardEvent& web_event,
36                          gfx::NativeView native_view);
37 
38   explicit NativeWebKeyboardEvent(gfx::NativeEvent native_event);
39 #if defined(OS_ANDROID)
40   // Holds a global ref to android_key_event (allowed to be null).
41   NativeWebKeyboardEvent(
42       JNIEnv* env,
43       const base::android::JavaRef<jobject>& android_key_event,
44       blink::WebInputEvent::Type type,
45       int modifiers,
46       base::TimeTicks timestamp,
47       int keycode,
48       int scancode,
49       int unicode_character,
50       bool is_system_key);
51 #else
52   explicit NativeWebKeyboardEvent(const ui::KeyEvent& key_event);
53 #if defined(USE_AURA)
54   // Create a legacy keypress event specified by |character|.
55   NativeWebKeyboardEvent(const ui::KeyEvent& key_event, base::char16 character);
56 #endif
57 #endif
58 
59 #if defined(OS_MACOSX)
60   // TODO(bokan): Temporarily added to debug https://crbug.com/1039833. This is
61   // used to allow collecting Event.Latency.OS_NO_VALIDATION only in contexts
62   // where the key event will be sent to the renderer.  The purpose is to avoid
63   // recording it for reinjected events after the renderer has already
64   // processed the event.
65   static NativeWebKeyboardEvent CreateForRenderer(
66       gfx::NativeEvent native_event);
67   NativeWebKeyboardEvent(gfx::NativeEvent native_event, bool record_debug_uma);
68 #endif
69 
70   NativeWebKeyboardEvent(const NativeWebKeyboardEvent& event);
71   ~NativeWebKeyboardEvent() override;
72 
73   NativeWebKeyboardEvent& operator=(const NativeWebKeyboardEvent& event);
74 
75   gfx::NativeEvent os_event;
76 
77   // True if the browser should ignore this event if it's not handled by the
78   // renderer. This happens for RawKeyDown events that are created while IME is
79   // active and is necessary to prevent backspace from doing "history back" if
80   // it is hit in ime mode.
81   // Currently, it's only used by Linux and Mac ports.
82   bool skip_in_browser;
83 };
84 
85 }  // namespace content
86 
87 #endif  // CONTENT_PUBLIC_BROWSER_NATIVE_WEB_KEYBOARD_EVENT_H_
88