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. 4 5 #ifndef UI_KEYBOARD_KEYBOARD_UTIL_H_ 6 #define UI_KEYBOARD_KEYBOARD_UTIL_H_ 7 8 #include <string> 9 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" 14 15 struct GritResourceMap; 16 17 namespace keyboard { 18 19 // Enumeration of swipe directions. 20 enum CursorMoveDirection { 21 kCursorMoveRight = 0x01, 22 kCursorMoveLeft = 0x02, 23 kCursorMoveUp = 0x04, 24 kCursorMoveDown = 0x08 25 }; 26 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, 32 KEYBOARD_CONTROL_MAX, 33 }; 34 35 // Returns true if the virtual keyboard is enabled. 36 KEYBOARD_EXPORT bool IsKeyboardEnabled(); 37 38 // Returns true if the keyboard usability test is enabled. 39 KEYBOARD_EXPORT bool IsKeyboardUsabilityExperimentEnabled(); 40 41 // Insert |text| into the active TextInputClient associated with |root_window|, 42 // if there is one. Returns true if |text| was successfully inserted. Note 43 // that this may convert |text| into ui::KeyEvents for injection in some 44 // special circumstances (i.e. VKEY_RETURN, VKEY_BACK). 45 KEYBOARD_EXPORT bool InsertText(const base::string16& text, 46 aura::Window* root_window); 47 48 // Move cursor when swipe on the virtualkeyboard. Returns true if cursor was 49 // successfully moved according to |swipe_direction|. 50 KEYBOARD_EXPORT bool MoveCursor(int swipe_direction, 51 int modifier_flags, 52 aura::WindowEventDispatcher* dispatcher); 53 54 // Sends a fabricated key event, where |type| is the event type, |key_value| 55 // is the unicode value of the character, |key_code| is the legacy key code 56 // value, |key_name| is the name of the key as defined in the DOM3 key event 57 // specification, and |modifier| indicates if any modifier keys are being 58 // virtually pressed. The event is dispatched to the active TextInputClient 59 // associated with |root_window|. The type may be "keydown" or "keyup". 60 KEYBOARD_EXPORT bool SendKeyEvent(std::string type, 61 int key_value, 62 int key_code, 63 std::string key_name, 64 int modifiers, 65 aura::WindowEventDispatcher* dispatcher); 66 67 // Marks that the keyboard load has started. This is used to measure the time it 68 // takes to fully load the keyboard. This should be called before 69 // MarkKeyboardLoadFinished. 70 KEYBOARD_EXPORT const void MarkKeyboardLoadStarted(); 71 72 // Marks that the keyboard load has ended. This finishes measuring that the 73 // keyboard is loaded. 74 KEYBOARD_EXPORT const void MarkKeyboardLoadFinished(); 75 76 // Get the list of keyboard resources. |size| is populated with the number of 77 // resources in the returned array. 78 KEYBOARD_EXPORT const GritResourceMap* GetKeyboardExtensionResources( 79 size_t* size); 80 81 // Logs the keyboard control event as a UMA stat. 82 void LogKeyboardControlEvent(KeyboardControlEvent event); 83 84 } // namespace keyboard 85 86 #endif // UI_KEYBOARD_KEYBOARD_UTIL_H_ 87