- add sources.
[platform/framework/web/crosswalk.git] / src / ui / keyboard / keyboard_util.h
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 // 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);
44
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,
48                                 int modifier_flags,
49                                 aura::WindowEventDispatcher* dispatcher);
50
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,
57                                    int key_value,
58                                    int key_code,
59                                    int modifiers,
60                                    aura::WindowEventDispatcher* dispatcher);
61
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();
66
67 // Marks that the keyboard load has ended. This finishes measuring that the
68 // keyboard is loaded.
69 KEYBOARD_EXPORT const void MarkKeyboardLoadFinished();
70
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(
74     size_t* size);
75
76 // Logs the keyboard control event as a UMA stat.
77 void LogKeyboardControlEvent(KeyboardControlEvent event);
78
79 }  // namespace keyboard
80
81 #endif  // UI_KEYBOARD_KEYBOARD_UTIL_H_