OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 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_BASE_WIN_OSK_DISPLAY_MANAGER_H_ | |
6 #define UI_BASE_WIN_OSK_DISPLAY_MANAGER_H_ | |
7 | |
8 #include "base/memory/singleton.h" | |
9 #include "base/memory/weak_ptr.h" | |
10 #include "base/observer_list.h" | |
11 #include "base/strings/string16.h" | |
12 #include "ui/base/ui_base_export.h" | |
13 #include "ui/gfx/geometry/rect.h" | |
14 | |
15 namespace ui { | |
16 | |
17 // Implemented by classes who wish to get notified about the on screen keyboard | |
18 // becoming visible/hidden. | |
19 class UI_BASE_EXPORT OnScreenKeyboardObserver { | |
sky
2016/05/19 16:05:26
nit: move to own header.
ananta
2016/05/19 19:33:38
Done.
| |
20 public: | |
21 virtual ~OnScreenKeyboardObserver() {} | |
22 | |
23 // The |keyboard_rect| parameter contains the bounds of the keyboard in DIPs. | |
24 virtual void OnKeyboardVisible(const gfx::Rect& keyboard_rect_in_dips) {} | |
25 virtual void OnKeyboardHidden(const gfx::Rect& keyboard_rect_in_dips) {} | |
26 }; | |
27 | |
28 // This class provides functionality to detect when the on screen keyboard | |
29 // is displayed and move the main window up if it is obscured by the keyboard. | |
30 class UI_BASE_EXPORT OnScreenKeyboardDetector { | |
31 public: | |
32 OnScreenKeyboardDetector(); | |
33 ~OnScreenKeyboardDetector(); | |
34 | |
35 // Schedules a delayed task which detects if the on screen keyboard was | |
36 // displayed. | |
37 void DetectKeyboard(HWND main_window); | |
38 | |
39 // Dismisses the on screen keyboard. | |
40 bool DismissKeyboard(); | |
41 | |
42 // Add/Remove keyboard observers. | |
43 // Please note that this class does not track the |observer| destruction. It | |
44 // is upto the classes which set up these observers to remove them when they | |
45 // are destroyed. | |
46 void AddObserver(OnScreenKeyboardObserver* observer); | |
47 void RemoveObserver(OnScreenKeyboardObserver* observer); | |
48 | |
49 private: | |
50 // Executes as a task and detects if the on screen keyboard is displayed. | |
51 // The |check_for_activation| parameter controls whether the function detects | |
52 // whether the keyboard wad displayed or hidden. | |
53 // Once the OSK is detected, this task runs periodically for the duration for | |
54 // which the OSK is visible. | |
55 void CheckOSKState(bool check_for_activation); | |
56 | |
57 // Notifies observers that the keyboard was displayed. | |
58 // A recurring task CheckOSKState() is started to detect when the OSK | |
59 // disappears. | |
60 void HandleKeyboardVisible(); | |
61 | |
62 // Notifies observers that the keyboard was hidden. | |
63 // The observer list is cleared out after this notification. | |
64 void HandleKeyboardHidden(); | |
65 | |
66 // Removes all observers from the list. | |
67 void ClearObservers(); | |
68 | |
69 // The main window which displays the on screen keyboard. | |
70 HWND main_window_; | |
71 | |
72 // Tracks if the keyboard was displayed. | |
73 bool osk_visible_notification_received_; | |
74 | |
75 // The keyboard dimensions in DIPs. | |
76 gfx::Rect osk_rect_dip_; | |
77 | |
78 base::ObserverList<OnScreenKeyboardObserver, false> observers_; | |
79 | |
80 // Should be the last member in the class. Helps ensure that tasks spawned | |
81 // by this class instance are canceled when it is destroyed. | |
82 base::WeakPtrFactory<OnScreenKeyboardDetector> keyboard_detector_factory_; | |
83 | |
84 DISALLOW_COPY_AND_ASSIGN(OnScreenKeyboardDetector); | |
85 }; | |
86 | |
87 // This class provides functionality to display the on screen keyboard on | |
88 // Windows 8+. It optionally notifies observers that the OSK is displayed, | |
89 // hidden, etc. | |
90 class UI_BASE_EXPORT OnScreenKeyboardDisplayManager { | |
sky
2016/05/19 16:05:26
Why do we need two classes for managing keyboards?
ananta
2016/05/19 19:33:38
Done.
| |
91 public: | |
92 static OnScreenKeyboardDisplayManager* GetInstance(); | |
93 | |
94 ~OnScreenKeyboardDisplayManager(); | |
95 | |
96 // Functions to display and dismiss the keyboard. | |
97 // The |observer| parameters allow the caller to optionally set up | |
98 // notification observers for detecting when the keyboard is displayed | |
99 // hidden etc. | |
100 bool DisplayVirtualKeyboard(OnScreenKeyboardObserver* observer); | |
101 bool DismissVirtualKeyboard(); | |
102 | |
103 private: | |
104 OnScreenKeyboardDisplayManager(); | |
105 | |
106 friend struct base::DefaultSingletonTraits<OnScreenKeyboardDisplayManager>; | |
107 | |
108 std::unique_ptr<OnScreenKeyboardDetector> keyboard_detector_; | |
109 | |
110 // The location of TabTip.exe. | |
111 base::string16 osk_path_; | |
112 | |
113 DISALLOW_COPY_AND_ASSIGN(OnScreenKeyboardDisplayManager); | |
114 }; | |
115 | |
116 // Displays the on screen keyboard on Windows 8 and above. Returns true on | |
117 // success. | |
118 UI_BASE_EXPORT bool DisplayVirtualKeyboard(); | |
119 | |
120 // Dismisses the on screen keyboard if it is being displayed on Windows 8 and. | |
121 // above. Returns true on success. | |
122 UI_BASE_EXPORT bool DismissVirtualKeyboard(); | |
123 | |
124 } // namespace ui | |
125 | |
126 #endif // UI_BASE_WIN_OSK_DISPLAY_MANAGER_H_ | |
OLD | NEW |