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 aura { 18 class WindowTreeHost; 19 } 20 21 class GURL; 22 23 namespace keyboard { 24 25 // Enumeration of swipe directions. 26 enum CursorMoveDirection { 27 kCursorMoveRight = 0x01, 28 kCursorMoveLeft = 0x02, 29 kCursorMoveUp = 0x04, 30 kCursorMoveDown = 0x08 31 }; 32 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, 38 KEYBOARD_CONTROL_MAX, 39 }; 40 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, 46 }; 47 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, 53 }; 54 55 // Gets the default keyboard bounds from |window_bounds|. 56 KEYBOARD_EXPORT gfx::Rect DefaultKeyboardBoundsFromWindowBounds( 57 const gfx::Rect& window_bounds); 58 59 // Gets the caculated keyboard bounds from |window_bounds|. The keyboard height 60 // is specified by |keyboard_height|. 61 KEYBOARD_EXPORT gfx::Rect KeyboardBoundsFromWindowBounds( 62 const gfx::Rect& window_bounds, int keyboard_height); 63 64 // Sets the state of the a11y onscreen keyboard. 65 KEYBOARD_EXPORT void SetAccessibilityKeyboardEnabled(bool enabled); 66 67 // Gets the state of the a11y onscreen keyboard. 68 KEYBOARD_EXPORT bool GetAccessibilityKeyboardEnabled(); 69 70 // Sets the state of the touch onscreen keyboard. 71 KEYBOARD_EXPORT void SetTouchKeyboardEnabled(bool enabled); 72 73 // Gets the state of the touch onscreen keyboard. 74 KEYBOARD_EXPORT bool GetTouchKeyboardEnabled(); 75 76 // Gets the default keyboard layout. 77 KEYBOARD_EXPORT std::string GetKeyboardLayout(); 78 79 // Returns true if the virtual keyboard is enabled. 80 KEYBOARD_EXPORT bool IsKeyboardEnabled(); 81 82 // Returns true if the keyboard usability test is enabled. 83 KEYBOARD_EXPORT bool IsKeyboardUsabilityExperimentEnabled(); 84 85 // Returns true if keyboard overscroll mode is enabled. 86 KEYBOARD_EXPORT bool IsKeyboardOverscrollEnabled(); 87 88 // Sets temporary keyboard overscroll override. 89 KEYBOARD_EXPORT void SetKeyboardOverscrollOverride( 90 KeyboardOverscrolOverride override); 91 92 // Sets policy override on whether to show the keyboard. 93 KEYBOARD_EXPORT void SetKeyboardShowOverride(KeyboardShowOverride override); 94 95 // Returns true if an IME extension can specify a custom input view for the 96 // virtual keyboard window. 97 KEYBOARD_EXPORT bool IsInputViewEnabled(); 98 99 // Returns true if experimental features are enabled for IME input-views. 100 KEYBOARD_EXPORT bool IsExperimentalInputViewEnabled(); 101 102 // Insert |text| into the active TextInputClient associated with |root_window|, 103 // if there is one. Returns true if |text| was successfully inserted. Note 104 // that this may convert |text| into ui::KeyEvents for injection in some 105 // special circumstances (i.e. VKEY_RETURN, VKEY_BACK). 106 KEYBOARD_EXPORT bool InsertText(const base::string16& text, 107 aura::Window* root_window); 108 109 // Move cursor when swipe on the virtualkeyboard. Returns true if cursor was 110 // successfully moved according to |swipe_direction|. 111 KEYBOARD_EXPORT bool MoveCursor(int swipe_direction, 112 int modifier_flags, 113 aura::WindowTreeHost* host); 114 115 // Sends a fabricated key event, where |type| is the event type, |key_value| 116 // is the unicode value of the character, |key_code| is the legacy key code 117 // value, |key_name| is the name of the key as defined in the DOM3 key event 118 // specification, and |modifier| indicates if any modifier keys are being 119 // virtually pressed. The event is dispatched to the active TextInputClient 120 // associated with |root_window|. The type may be "keydown" or "keyup". 121 KEYBOARD_EXPORT bool SendKeyEvent(std::string type, 122 int key_value, 123 int key_code, 124 std::string key_name, 125 int modifiers, 126 aura::WindowTreeHost* host); 127 128 // Marks that the keyboard load has started. This is used to measure the time it 129 // takes to fully load the keyboard. This should be called before 130 // MarkKeyboardLoadFinished. 131 KEYBOARD_EXPORT const void MarkKeyboardLoadStarted(); 132 133 // Marks that the keyboard load has ended. This finishes measuring that the 134 // keyboard is loaded. 135 KEYBOARD_EXPORT const void MarkKeyboardLoadFinished(); 136 137 // Get the list of keyboard resources. |size| is populated with the number of 138 // resources in the returned array. 139 KEYBOARD_EXPORT const GritResourceMap* GetKeyboardExtensionResources( 140 size_t* size); 141 142 // Sets the override content url. 143 // This is used by for input view for extension IMEs. 144 KEYBOARD_EXPORT void SetOverrideContentUrl(const GURL& url); 145 146 // Gets the override content url. 147 KEYBOARD_EXPORT const GURL& GetOverrideContentUrl(); 148 149 // Logs the keyboard control event as a UMA stat. 150 void LogKeyboardControlEvent(KeyboardControlEvent event); 151 152 } // namespace keyboard 153 154 #endif // UI_KEYBOARD_KEYBOARD_UTIL_H_ 155