1 // Copyright (c) 2013 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 #ifndef UI_KEYBOARD_KEYBOARD_UTIL_H_
6 #define UI_KEYBOARD_KEYBOARD_UTIL_H_
10 #include "base/strings/string16.h"
11 // TODO(beng): replace with forward decl once RootWindow is renamed.
12 #include "ui/aura/window.h"
13 #include "ui/keyboard/keyboard_export.h"
15 struct GritResourceMap
;
25 // Enumeration of swipe directions.
26 enum CursorMoveDirection
{
27 kCursorMoveRight
= 0x01,
28 kCursorMoveLeft
= 0x02,
30 kCursorMoveDown
= 0x08
33 // An enumeration of different keyboard control events that should be logged.
34 enum KeyboardControlEvent
{
35 KEYBOARD_CONTROL_SHOW
= 0,
36 KEYBOARD_CONTROL_HIDE_AUTO
,
37 KEYBOARD_CONTROL_HIDE_USER
,
41 // An enumeration of keyboard overscroll override value.
42 enum KeyboardOverscrolOverride
{
43 KEYBOARD_OVERSCROLL_OVERRIDE_DISABLED
= 0,
44 KEYBOARD_OVERSCROLL_OVERRIDE_ENABLED
,
45 KEYBOARD_OVERSCROLL_OVERRIDE_NONE
,
48 // An enumeration of keyboard policy settings.
49 enum KeyboardShowOverride
{
50 KEYBOARD_SHOW_OVERRIDE_DISABLED
= 0,
51 KEYBOARD_SHOW_OVERRIDE_ENABLED
,
52 KEYBOARD_SHOW_OVERRIDE_NONE
,
55 // An enumeration of keyboard states.
57 // Default state. System decides whether to show the keyboard or not.
58 KEYBOARD_STATE_AUTO
= 0,
59 // Request virtual keyboard be deployed.
60 KEYBOARD_STATE_ENABLED
,
61 // Request virtual keyboard be suppressed.
62 KEYBOARD_STATE_DISABLED
,
65 // Gets the calculated keyboard bounds from |root_bounds|. The keyboard height
66 // is specified by |keyboard_height|. This should be only called when keyboard
67 // is in FULL_WDITH mode.
68 KEYBOARD_EXPORT
gfx::Rect
FullWidthKeyboardBoundsFromRootBounds(
69 const gfx::Rect
& root_bounds
, int keyboard_height
);
71 // Sets the state of the a11y onscreen keyboard.
72 KEYBOARD_EXPORT
void SetAccessibilityKeyboardEnabled(bool enabled
);
74 // Gets the state of the a11y onscreen keyboard.
75 KEYBOARD_EXPORT
bool GetAccessibilityKeyboardEnabled();
77 // Sets the state of the hotrod onscreen keyboard.
78 KEYBOARD_EXPORT
void SetHotrodKeyboardEnabled(bool enabled
);
80 // Gets the state of the hotrod onscreen keyboard.
81 KEYBOARD_EXPORT
bool GetHotrodKeyboardEnabled();
83 // Sets the state of the touch onscreen keyboard.
84 KEYBOARD_EXPORT
void SetTouchKeyboardEnabled(bool enabled
);
86 // Gets the state of the touch onscreen keyboard.
87 KEYBOARD_EXPORT
bool GetTouchKeyboardEnabled();
89 // Sets the requested state of the keyboard.
90 KEYBOARD_EXPORT
void SetRequestedKeyboardState(KeyboardState state
);
92 // Gets the requested state of the keyboard.
93 KEYBOARD_EXPORT
int GetRequestedKeyboardState();
95 // Gets the default keyboard layout.
96 KEYBOARD_EXPORT
std::string
GetKeyboardLayout();
98 // Returns true if the virtual keyboard is enabled.
99 KEYBOARD_EXPORT
bool IsKeyboardEnabled();
101 // Returns true if smart deployment of the virtual keyboard is enabled.
102 KEYBOARD_EXPORT
bool IsSmartDeployEnabled();
104 // Returns true if keyboard overscroll mode is enabled.
105 KEYBOARD_EXPORT
bool IsKeyboardOverscrollEnabled();
107 // Sets temporary keyboard overscroll override.
108 KEYBOARD_EXPORT
void SetKeyboardOverscrollOverride(
109 KeyboardOverscrolOverride override
);
111 // Sets policy override on whether to show the keyboard.
112 KEYBOARD_EXPORT
void SetKeyboardShowOverride(KeyboardShowOverride override
);
114 // Returns true if an IME extension can specify a custom input view for the
115 // virtual keyboard window.
116 KEYBOARD_EXPORT
bool IsInputViewEnabled();
118 // Returns true if experimental features are enabled for IME input-views.
119 KEYBOARD_EXPORT
bool IsExperimentalInputViewEnabled();
121 // Returns true if floating virtual keyboard feature is enabled.
122 KEYBOARD_EXPORT
bool IsFloatingVirtualKeyboardEnabled();
124 // Returns true if gesture typing option is enabled for virtual keyboard.
125 KEYBOARD_EXPORT
bool IsGestureTypingEnabled();
127 // Returns true if gesture editing option is enabled for virtual keyboard.
128 KEYBOARD_EXPORT
bool IsGestureEditingEnabled();
130 // Returns true if voice input is enabled for the keyboard.
131 KEYBOARD_EXPORT
bool IsVoiceInputEnabled();
133 // Insert |text| into the active TextInputClient if there is one. Returns true
134 // if |text| was successfully inserted.
135 KEYBOARD_EXPORT
bool InsertText(const base::string16
& text
);
137 // Move cursor when swipe on the virtualkeyboard. Returns true if cursor was
138 // successfully moved according to |swipe_direction|.
139 KEYBOARD_EXPORT
bool MoveCursor(int swipe_direction
,
141 aura::WindowTreeHost
* host
);
143 // Sends a fabricated key event, where |type| is the event type, |key_value|
144 // is the unicode value of the character, |key_code| is the legacy key code
145 // value, |key_name| is the name of the key as defined in the DOM3 key event
146 // specification, and |modifier| indicates if any modifier keys are being
147 // virtually pressed. The event is dispatched to the active TextInputClient
148 // associated with |root_window|. The type may be "keydown" or "keyup".
149 KEYBOARD_EXPORT
bool SendKeyEvent(std::string type
,
152 std::string key_name
,
154 aura::WindowTreeHost
* host
);
156 // Marks that the keyboard load has started. This is used to measure the time it
157 // takes to fully load the keyboard. This should be called before
158 // MarkKeyboardLoadFinished.
159 KEYBOARD_EXPORT
void MarkKeyboardLoadStarted();
161 // Marks that the keyboard load has ended. This finishes measuring that the
162 // keyboard is loaded.
163 KEYBOARD_EXPORT
void MarkKeyboardLoadFinished();
165 // Get the list of keyboard resources. |size| is populated with the number of
166 // resources in the returned array.
167 KEYBOARD_EXPORT
const GritResourceMap
* GetKeyboardExtensionResources(
170 // Sets the override content url.
171 // This is used by for input view for extension IMEs.
172 KEYBOARD_EXPORT
void SetOverrideContentUrl(const GURL
& url
);
174 // Gets the override content url.
175 KEYBOARD_EXPORT
const GURL
& GetOverrideContentUrl();
177 // Logs the keyboard control event as a UMA stat.
178 void LogKeyboardControlEvent(KeyboardControlEvent event
);
180 } // namespace keyboard
182 #endif // UI_KEYBOARD_KEYBOARD_UTIL_H_