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;
19 // Enumeration of swipe directions.
20 enum CursorMoveDirection {
21 kCursorMoveRight = 0x01,
22 kCursorMoveLeft = 0x02,
24 kCursorMoveDown = 0x08
27 // An enumeration of different keyboard control events that should be logged.
28 enum KeyboardControlEvent {
29 KEYBOARD_CONTROL_SHOW = 0,
30 KEYBOARD_CONTROL_HIDE_AUTO,
31 KEYBOARD_CONTROL_HIDE_USER,
35 // Returns true if the virtual keyboard is enabled.
36 KEYBOARD_EXPORT bool IsKeyboardEnabled();
38 // Insert |text| into the active TextInputClient associated with |root_window|,
39 // if there is one. Returns true if |text| was successfully inserted. Note
40 // that this may convert |text| into ui::KeyEvents for injection in some
41 // special circumstances (i.e. VKEY_RETURN, VKEY_BACK).
42 KEYBOARD_EXPORT bool InsertText(const base::string16& text,
43 aura::Window* root_window);
45 // Move cursor when swipe on the virtualkeyboard. Returns true if cursor was
46 // successfully moved according to |swipe_direction|.
47 KEYBOARD_EXPORT bool MoveCursor(int swipe_direction,
49 aura::WindowEventDispatcher* dispatcher);
51 // Sends a fabricated key event, where |type| is the event type, |key_value|
52 // is the unicode value of the character, |key_code| is the legacy key code
53 // value, and |modifier| indicates if any modifier keys are being virtually
54 // pressed. The event is dispatched to the active TextInputClient associated
55 // with |root_window|. The type may be "keydown" or "keyup".
56 KEYBOARD_EXPORT bool SendKeyEvent(std::string type,
60 aura::WindowEventDispatcher* dispatcher);
62 // Marks that the keyboard load has started. This is used to measure the time it
63 // takes to fully load the keyboard. This should be called before
64 // MarkKeyboardLoadFinished.
65 KEYBOARD_EXPORT const void MarkKeyboardLoadStarted();
67 // Marks that the keyboard load has ended. This finishes measuring that the
68 // keyboard is loaded.
69 KEYBOARD_EXPORT const void MarkKeyboardLoadFinished();
71 // Get the list of keyboard resources. |size| is populated with the number of
72 // resources in the returned array.
73 KEYBOARD_EXPORT const GritResourceMap* GetKeyboardExtensionResources(
76 // Logs the keyboard control event as a UMA stat.
77 void LogKeyboardControlEvent(KeyboardControlEvent event);
79 } // namespace keyboard
81 #endif // UI_KEYBOARD_KEYBOARD_UTIL_H_