virtual_keyboard_model.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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_SYSTEM_MODEL_VIRTUAL_KEYBOARD_MODEL_H_
  5. #define ASH_SYSTEM_MODEL_VIRTUAL_KEYBOARD_MODEL_H_
  6. #include "ash/ash_export.h"
  7. #include "ash/public/cpp/keyboard/arc/arc_input_method_bounds_tracker.h"
  8. #include "ash/public/cpp/keyboard/keyboard_controller_observer.h"
  9. #include "base/observer_list.h"
  10. namespace ash {
  11. // Model to store virtual keyboard visibility state.
  12. class ASH_EXPORT VirtualKeyboardModel
  13. : public ArcInputMethodBoundsTracker::Observer,
  14. public KeyboardControllerObserver {
  15. public:
  16. class Observer {
  17. public:
  18. virtual ~Observer() {}
  19. virtual void OnVirtualKeyboardVisibilityChanged() = 0;
  20. };
  21. VirtualKeyboardModel();
  22. VirtualKeyboardModel(const VirtualKeyboardModel&) = delete;
  23. VirtualKeyboardModel& operator=(const VirtualKeyboardModel&) = delete;
  24. ~VirtualKeyboardModel() override;
  25. void AddObserver(Observer* observer);
  26. void RemoveObserver(Observer* observer);
  27. // Start/stop observing ArcInputMethodBoundsTracker.
  28. void SetInputMethodBoundsTrackerObserver(
  29. ArcInputMethodBoundsTracker* input_method_bounds_tracker);
  30. void RemoveInputMethodBoundsTrackerObserver(
  31. ArcInputMethodBoundsTracker* input_method_bounds_tracker);
  32. // ArcInputMethodBoundsTracker::Observer:
  33. void OnArcInputMethodBoundsChanged(const gfx::Rect& bounds) override;
  34. // KeyboardControllerObserver:
  35. void OnKeyboardEnabledChanged(bool is_enabled) override;
  36. bool arc_keyboard_visible() const { return arc_keyboard_visible_; }
  37. const gfx::Rect& arc_keyboard_bounds() const { return arc_keyboard_bounds_; }
  38. private:
  39. // Sets `arc_keyboard_visible_` depending on last reported ARC input method
  40. // bounds and the keyboard controller state. Notifies observes of the
  41. // visibility change if the `arc_keyboard_visible_` value changed..
  42. void UpdateArcKeyboardVisibility();
  43. // Whether ARC IME keyboard is currently visible..
  44. bool arc_keyboard_visible_ = false;
  45. gfx::Rect arc_keyboard_bounds_;
  46. base::ObserverList<Observer>::Unchecked observers_;
  47. };
  48. } // namespace ash
  49. #endif // ASH_SYSTEM_MODEL_VIRTUAL_KEYBOARD_MODEL_H_