Index: ui/base/win/osk_display_manager.h |
diff --git a/ui/base/win/osk_display_manager.h b/ui/base/win/osk_display_manager.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..c848bd31f163a1e8def4f4f5d1b98aceb790db1b |
--- /dev/null |
+++ b/ui/base/win/osk_display_manager.h |
@@ -0,0 +1,126 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef UI_BASE_WIN_OSK_DISPLAY_MANAGER_H_ |
+#define UI_BASE_WIN_OSK_DISPLAY_MANAGER_H_ |
+ |
+#include "base/memory/singleton.h" |
+#include "base/memory/weak_ptr.h" |
+#include "base/observer_list.h" |
+#include "base/strings/string16.h" |
+#include "ui/base/ui_base_export.h" |
+#include "ui/gfx/geometry/rect.h" |
+ |
+namespace ui { |
+ |
+// Implemented by classes who wish to get notified about the on screen keyboard |
+// becoming visible/hidden. |
+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.
|
+ public: |
+ virtual ~OnScreenKeyboardObserver() {} |
+ |
+ // The |keyboard_rect| parameter contains the bounds of the keyboard in DIPs. |
+ virtual void OnKeyboardVisible(const gfx::Rect& keyboard_rect_in_dips) {} |
+ virtual void OnKeyboardHidden(const gfx::Rect& keyboard_rect_in_dips) {} |
+}; |
+ |
+// This class provides functionality to detect when the on screen keyboard |
+// is displayed and move the main window up if it is obscured by the keyboard. |
+class UI_BASE_EXPORT OnScreenKeyboardDetector { |
+ public: |
+ OnScreenKeyboardDetector(); |
+ ~OnScreenKeyboardDetector(); |
+ |
+ // Schedules a delayed task which detects if the on screen keyboard was |
+ // displayed. |
+ void DetectKeyboard(HWND main_window); |
+ |
+ // Dismisses the on screen keyboard. |
+ bool DismissKeyboard(); |
+ |
+ // Add/Remove keyboard observers. |
+ // Please note that this class does not track the |observer| destruction. It |
+ // is upto the classes which set up these observers to remove them when they |
+ // are destroyed. |
+ void AddObserver(OnScreenKeyboardObserver* observer); |
+ void RemoveObserver(OnScreenKeyboardObserver* observer); |
+ |
+ private: |
+ // Executes as a task and detects if the on screen keyboard is displayed. |
+ // The |check_for_activation| parameter controls whether the function detects |
+ // whether the keyboard wad displayed or hidden. |
+ // Once the OSK is detected, this task runs periodically for the duration for |
+ // which the OSK is visible. |
+ void CheckOSKState(bool check_for_activation); |
+ |
+ // Notifies observers that the keyboard was displayed. |
+ // A recurring task CheckOSKState() is started to detect when the OSK |
+ // disappears. |
+ void HandleKeyboardVisible(); |
+ |
+ // Notifies observers that the keyboard was hidden. |
+ // The observer list is cleared out after this notification. |
+ void HandleKeyboardHidden(); |
+ |
+ // Removes all observers from the list. |
+ void ClearObservers(); |
+ |
+ // The main window which displays the on screen keyboard. |
+ HWND main_window_; |
+ |
+ // Tracks if the keyboard was displayed. |
+ bool osk_visible_notification_received_; |
+ |
+ // The keyboard dimensions in DIPs. |
+ gfx::Rect osk_rect_dip_; |
+ |
+ base::ObserverList<OnScreenKeyboardObserver, false> observers_; |
+ |
+ // Should be the last member in the class. Helps ensure that tasks spawned |
+ // by this class instance are canceled when it is destroyed. |
+ base::WeakPtrFactory<OnScreenKeyboardDetector> keyboard_detector_factory_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(OnScreenKeyboardDetector); |
+}; |
+ |
+// This class provides functionality to display the on screen keyboard on |
+// Windows 8+. It optionally notifies observers that the OSK is displayed, |
+// hidden, etc. |
+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.
|
+ public: |
+ static OnScreenKeyboardDisplayManager* GetInstance(); |
+ |
+ ~OnScreenKeyboardDisplayManager(); |
+ |
+ // Functions to display and dismiss the keyboard. |
+ // The |observer| parameters allow the caller to optionally set up |
+ // notification observers for detecting when the keyboard is displayed |
+ // hidden etc. |
+ bool DisplayVirtualKeyboard(OnScreenKeyboardObserver* observer); |
+ bool DismissVirtualKeyboard(); |
+ |
+ private: |
+ OnScreenKeyboardDisplayManager(); |
+ |
+ friend struct base::DefaultSingletonTraits<OnScreenKeyboardDisplayManager>; |
+ |
+ std::unique_ptr<OnScreenKeyboardDetector> keyboard_detector_; |
+ |
+ // The location of TabTip.exe. |
+ base::string16 osk_path_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(OnScreenKeyboardDisplayManager); |
+}; |
+ |
+// Displays the on screen keyboard on Windows 8 and above. Returns true on |
+// success. |
+UI_BASE_EXPORT bool DisplayVirtualKeyboard(); |
+ |
+// Dismisses the on screen keyboard if it is being displayed on Windows 8 and. |
+// above. Returns true on success. |
+UI_BASE_EXPORT bool DismissVirtualKeyboard(); |
+ |
+} // namespace ui |
+ |
+#endif // UI_BASE_WIN_OSK_DISPLAY_MANAGER_H_ |