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 // Gets the default keyboard bounds from |window_bounds|.
42 KEYBOARD_EXPORT
gfx::Rect
DefaultKeyboardBoundsFromWindowBounds(
43 const gfx::Rect
& window_bounds
);
45 // Gets the caculated keyboard bounds from |window_bounds|. The keyboard height
46 // is specified by |keyboard_height|.
47 KEYBOARD_EXPORT
gfx::Rect
KeyboardBoundsFromWindowBounds(
48 const gfx::Rect
& window_bounds
, int keyboard_height
);
50 // Sets the state of the a11y onscreen keyboard.
51 KEYBOARD_EXPORT
void SetAccessibilityKeyboardEnabled(bool enabled
);
53 // Gets the state of the a11y onscreen keyboard.
54 KEYBOARD_EXPORT
bool GetAccessibilityKeyboardEnabled();
56 // Sets the state of the touch onscreen keyboard.
57 KEYBOARD_EXPORT
void SetTouchKeyboardEnabled(bool enabled
);
59 // Gets the state of the touch onscreen keyboard.
60 KEYBOARD_EXPORT
bool GetTouchKeyboardEnabled();
62 // Gets the default keyboard layout.
63 KEYBOARD_EXPORT
std::string
GetKeyboardLayout();
65 // Returns true if the virtual keyboard is enabled.
66 KEYBOARD_EXPORT
bool IsKeyboardEnabled();
68 // Returns true if the keyboard usability test is enabled.
69 KEYBOARD_EXPORT
bool IsKeyboardUsabilityExperimentEnabled();
71 // Returns true if keyboard overscroll mode is enabled.
72 KEYBOARD_EXPORT
bool IsKeyboardOverscrollEnabled();
74 // Returns true if an IME extension can specify a custom input view for the
75 // virtual keyboard window.
76 KEYBOARD_EXPORT
bool IsInputViewEnabled();
78 // Insert |text| into the active TextInputClient associated with |root_window|,
79 // if there is one. Returns true if |text| was successfully inserted. Note
80 // that this may convert |text| into ui::KeyEvents for injection in some
81 // special circumstances (i.e. VKEY_RETURN, VKEY_BACK).
82 KEYBOARD_EXPORT
bool InsertText(const base::string16
& text
,
83 aura::Window
* root_window
);
85 // Move cursor when swipe on the virtualkeyboard. Returns true if cursor was
86 // successfully moved according to |swipe_direction|.
87 KEYBOARD_EXPORT
bool MoveCursor(int swipe_direction
,
89 aura::WindowTreeHost
* host
);
91 // Sends a fabricated key event, where |type| is the event type, |key_value|
92 // is the unicode value of the character, |key_code| is the legacy key code
93 // value, |key_name| is the name of the key as defined in the DOM3 key event
94 // specification, and |modifier| indicates if any modifier keys are being
95 // virtually pressed. The event is dispatched to the active TextInputClient
96 // associated with |root_window|. The type may be "keydown" or "keyup".
97 KEYBOARD_EXPORT
bool SendKeyEvent(std::string type
,
100 std::string key_name
,
102 aura::WindowTreeHost
* host
);
104 // Marks that the keyboard load has started. This is used to measure the time it
105 // takes to fully load the keyboard. This should be called before
106 // MarkKeyboardLoadFinished.
107 KEYBOARD_EXPORT
const void MarkKeyboardLoadStarted();
109 // Marks that the keyboard load has ended. This finishes measuring that the
110 // keyboard is loaded.
111 KEYBOARD_EXPORT
const void MarkKeyboardLoadFinished();
113 // Get the list of keyboard resources. |size| is populated with the number of
114 // resources in the returned array.
115 KEYBOARD_EXPORT
const GritResourceMap
* GetKeyboardExtensionResources(
118 // Sets the override content url.
119 // This is used by for input view for extension IMEs.
120 KEYBOARD_EXPORT
void SetOverrideContentUrl(const GURL
& url
);
122 // Gets the override content url.
123 KEYBOARD_EXPORT
const GURL
& GetOverrideContentUrl();
125 // Logs the keyboard control event as a UMA stat.
126 void LogKeyboardControlEvent(KeyboardControlEvent event
);
128 } // namespace keyboard
130 #endif // UI_KEYBOARD_KEYBOARD_UTIL_H_