keyboard_controller_impl.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. // Copyright 2018 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. #ifndef ASH_KEYBOARD_KEYBOARD_CONTROLLER_IMPL_H_
  5. #define ASH_KEYBOARD_KEYBOARD_CONTROLLER_IMPL_H_
  6. #include <memory>
  7. #include <set>
  8. #include <vector>
  9. #include "ash/ash_export.h"
  10. #include "ash/keyboard/ui/keyboard_layout_delegate.h"
  11. #include "ash/keyboard/ui/keyboard_ui_controller.h"
  12. #include "ash/public/cpp/keyboard/keyboard_controller.h"
  13. #include "ash/public/cpp/keyboard/keyboard_controller_observer.h"
  14. #include "ash/public/cpp/session/session_observer.h"
  15. class PrefChangeRegistrar;
  16. class PrefRegistrySimple;
  17. class PrefService;
  18. namespace gfx {
  19. class Rect;
  20. }
  21. namespace keyboard {
  22. class KeyboardUIController;
  23. class KeyboardUIFactory;
  24. } // namespace keyboard
  25. namespace ash {
  26. class SessionControllerImpl;
  27. class VirtualKeyboardController;
  28. struct KeyRepeatSettings;
  29. // Contains and observes a keyboard::KeyboardUIController instance. Ash specific
  30. // behavior, including implementing the public interface, is implemented in this
  31. // class.
  32. class ASH_EXPORT KeyboardControllerImpl
  33. : public KeyboardController,
  34. public keyboard::KeyboardLayoutDelegate,
  35. public KeyboardControllerObserver,
  36. public SessionObserver {
  37. public:
  38. // |session_controller| is expected to outlive KeyboardControllerImpl.
  39. explicit KeyboardControllerImpl(SessionControllerImpl* session_controller);
  40. KeyboardControllerImpl(const KeyboardControllerImpl&) = delete;
  41. KeyboardControllerImpl& operator=(const KeyboardControllerImpl&) = delete;
  42. ~KeyboardControllerImpl() override;
  43. static void RegisterProfilePrefs(PrefRegistrySimple* registry);
  44. // Create or destroy the virtual keyboard. Called from Shell. TODO(stevenjb):
  45. // Fix dependencies so that the virtual keyboard can be created with the
  46. // keyboard controller.
  47. void CreateVirtualKeyboard(
  48. std::unique_ptr<keyboard::KeyboardUIFactory> keyboard_ui_factory);
  49. void DestroyVirtualKeyboard();
  50. // Forwards events to observers.
  51. void SendOnKeyboardVisibleBoundsChanged(const gfx::Rect& screen_bounds);
  52. void SendOnKeyboardUIDestroyed();
  53. // ash::KeyboardController:
  54. keyboard::KeyboardConfig GetKeyboardConfig() override;
  55. void SetKeyboardConfig(
  56. const keyboard::KeyboardConfig& keyboard_config) override;
  57. bool IsKeyboardEnabled() override;
  58. void SetEnableFlag(keyboard::KeyboardEnableFlag flag) override;
  59. void ClearEnableFlag(keyboard::KeyboardEnableFlag flag) override;
  60. const std::set<keyboard::KeyboardEnableFlag>& GetEnableFlags() override;
  61. void ReloadKeyboardIfNeeded() override;
  62. void RebuildKeyboardIfEnabled() override;
  63. bool IsKeyboardVisible() override;
  64. void ShowKeyboard() override;
  65. void HideKeyboard(HideReason reason) override;
  66. void SetContainerType(keyboard::ContainerType container_type,
  67. const gfx::Rect& target_bounds,
  68. SetContainerTypeCallback callback) override;
  69. void SetKeyboardLocked(bool locked) override;
  70. void SetOccludedBounds(const std::vector<gfx::Rect>& bounds) override;
  71. void SetHitTestBounds(const std::vector<gfx::Rect>& bounds) override;
  72. bool SetAreaToRemainOnScreen(const gfx::Rect& bounds) override;
  73. void SetDraggableArea(const gfx::Rect& bounds) override;
  74. bool SetWindowBoundsInScreen(const gfx::Rect& bounds_in_screen) override;
  75. void SetKeyboardConfigFromPref(bool enabled) override;
  76. bool ShouldOverscroll() override;
  77. void AddObserver(KeyboardControllerObserver* observer) override;
  78. void RemoveObserver(KeyboardControllerObserver* observer) override;
  79. KeyRepeatSettings GetKeyRepeatSettings() override;
  80. bool AreTopRowKeysFunctionKeys() override;
  81. // keyboard::KeyboardLayoutDelegate:
  82. aura::Window* GetContainerForDefaultDisplay() override;
  83. aura::Window* GetContainerForDisplay(
  84. const display::Display& display) override;
  85. void TransferGestureEventToShelf(const ui::GestureEvent& e) override;
  86. // SessionObserver:
  87. void OnSessionStateChanged(session_manager::SessionState state) override;
  88. void OnSigninScreenPrefServiceInitialized(PrefService* prefs) override;
  89. void OnActiveUserPrefServiceChanged(PrefService* prefs) override;
  90. keyboard::KeyboardUIController* keyboard_ui_controller() {
  91. return keyboard_ui_controller_.get();
  92. }
  93. VirtualKeyboardController* virtual_keyboard_controller() {
  94. return virtual_keyboard_controller_.get();
  95. }
  96. // Called whenever a root window is closing.
  97. // If the root window contains the virtual keyboard window, deactivates
  98. // the keyboard so that its window doesn't get destroyed as well.
  99. void OnRootWindowClosing(aura::Window* root_window);
  100. private:
  101. // KeyboardControllerObserver:
  102. void OnKeyboardConfigChanged(const keyboard::KeyboardConfig& config) override;
  103. void OnKeyRepeatSettingsChanged(const KeyRepeatSettings& settings) override;
  104. void OnKeyboardVisibilityChanged(bool is_visible) override;
  105. void OnKeyboardVisibleBoundsChanged(const gfx::Rect& screen_bounds) override;
  106. void OnKeyboardOccludedBoundsChanged(const gfx::Rect& screen_bounds) override;
  107. void OnKeyboardEnableFlagsChanged(
  108. const std::set<keyboard::KeyboardEnableFlag>& flags) override;
  109. void OnKeyboardEnabledChanged(bool is_enabled) override;
  110. void ObservePrefs(PrefService* prefs);
  111. void SendKeyRepeatUpdate();
  112. void SendKeyboardConfigUpdate();
  113. void SetEnableFlagFromCommandLine();
  114. std::unique_ptr<PrefChangeRegistrar> pref_change_registrar_;
  115. SessionControllerImpl* session_controller_; // unowned
  116. std::unique_ptr<keyboard::KeyboardUIController> keyboard_ui_controller_;
  117. std::unique_ptr<VirtualKeyboardController> virtual_keyboard_controller_;
  118. base::ObserverList<KeyboardControllerObserver>::Unchecked observers_;
  119. // This flag controls if the keyboard config is set from the policy settings.
  120. // Note: the flag value cannot be changed from 'true' to 'false' because
  121. // original config is not stored.
  122. bool keyboard_config_from_pref_enabled_ = false;
  123. };
  124. } // namespace ash
  125. #endif // ASH_KEYBOARD_KEYBOARD_CONTROLLER_IMPL_H_