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 // Gets the caculated keyboard bounds from |root_bounds|. The keyboard height
56 // is specified by |keyboard_height|. This should be only called when keyboard
57 // is in FULL_WDITH mode.
58 KEYBOARD_EXPORT
gfx::Rect
FullWidthKeyboardBoundsFromRootBounds(
59 const gfx::Rect
& root_bounds
, int keyboard_height
);
61 // Sets the state of the a11y onscreen keyboard.
62 KEYBOARD_EXPORT
void SetAccessibilityKeyboardEnabled(bool enabled
);
64 // Gets the state of the a11y onscreen keyboard.
65 KEYBOARD_EXPORT
bool GetAccessibilityKeyboardEnabled();
67 // Sets the state of the touch onscreen keyboard.
68 KEYBOARD_EXPORT
void SetTouchKeyboardEnabled(bool enabled
);
70 // Gets the state of the touch onscreen keyboard.
71 KEYBOARD_EXPORT
bool GetTouchKeyboardEnabled();
73 // Gets the default keyboard layout.
74 KEYBOARD_EXPORT
std::string
GetKeyboardLayout();
76 // Returns true if the virtual keyboard is enabled.
77 KEYBOARD_EXPORT
bool IsKeyboardEnabled();
79 // Returns true if smart deployment of the virtual keyboard is enabled.
80 KEYBOARD_EXPORT
bool IsSmartDeployEnabled();
82 // Returns true if keyboard overscroll mode is enabled.
83 KEYBOARD_EXPORT
bool IsKeyboardOverscrollEnabled();
85 // Sets temporary keyboard overscroll override.
86 KEYBOARD_EXPORT
void SetKeyboardOverscrollOverride(
87 KeyboardOverscrolOverride override
);
89 // Sets policy override on whether to show the keyboard.
90 KEYBOARD_EXPORT
void SetKeyboardShowOverride(KeyboardShowOverride override
);
92 // Returns true if an IME extension can specify a custom input view for the
93 // virtual keyboard window.
94 KEYBOARD_EXPORT
bool IsInputViewEnabled();
96 // Returns true if experimental features are enabled for IME input-views.
97 KEYBOARD_EXPORT
bool IsExperimentalInputViewEnabled();
99 // Returns true if floating virtual keyboard feature is enabled.
100 KEYBOARD_EXPORT
bool IsFloatingVirtualKeyboardEnabled();
102 // Returns true if gesture typing option is enabled for virtual keyboard.
103 KEYBOARD_EXPORT
bool IsGestureTypingEnabled();
105 // Returns true if gesture editing option is enabled for virtual keyboard.
106 KEYBOARD_EXPORT
bool IsGestureEditingEnabled();
108 // Returns true if material design is enabled for the keyboard.
109 KEYBOARD_EXPORT
bool IsMaterialDesignEnabled();
111 // Returns true if voice input is enabled for the keyboard.
112 KEYBOARD_EXPORT
bool IsVoiceInputEnabled();
114 // Insert |text| into the active TextInputClient if there is one. Returns true
115 // if |text| was successfully inserted.
116 KEYBOARD_EXPORT
bool InsertText(const base::string16
& text
);
118 // Move cursor when swipe on the virtualkeyboard. Returns true if cursor was
119 // successfully moved according to |swipe_direction|.
120 KEYBOARD_EXPORT
bool MoveCursor(int swipe_direction
,
122 aura::WindowTreeHost
* host
);
124 // Sends a fabricated key event, where |type| is the event type, |key_value|
125 // is the unicode value of the character, |key_code| is the legacy key code
126 // value, |key_name| is the name of the key as defined in the DOM3 key event
127 // specification, and |modifier| indicates if any modifier keys are being
128 // virtually pressed. The event is dispatched to the active TextInputClient
129 // associated with |root_window|. The type may be "keydown" or "keyup".
130 KEYBOARD_EXPORT
bool SendKeyEvent(std::string type
,
133 std::string key_name
,
135 aura::WindowTreeHost
* host
);
137 // Marks that the keyboard load has started. This is used to measure the time it
138 // takes to fully load the keyboard. This should be called before
139 // MarkKeyboardLoadFinished.
140 KEYBOARD_EXPORT
void MarkKeyboardLoadStarted();
142 // Marks that the keyboard load has ended. This finishes measuring that the
143 // keyboard is loaded.
144 KEYBOARD_EXPORT
void MarkKeyboardLoadFinished();
146 // Get the list of keyboard resources. |size| is populated with the number of
147 // resources in the returned array.
148 KEYBOARD_EXPORT
const GritResourceMap
* GetKeyboardExtensionResources(
151 // Sets the override content url.
152 // This is used by for input view for extension IMEs.
153 KEYBOARD_EXPORT
void SetOverrideContentUrl(const GURL
& url
);
155 // Gets the override content url.
156 KEYBOARD_EXPORT
const GURL
& GetOverrideContentUrl();
158 // Logs the keyboard control event as a UMA stat.
159 void LogKeyboardControlEvent(KeyboardControlEvent event
);
161 } // namespace keyboard
163 #endif // UI_KEYBOARD_KEYBOARD_UTIL_H_