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