sticky_keys_overlay.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // Copyright 2014 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_ACCESSIBILITY_STICKY_KEYS_STICKY_KEYS_OVERLAY_H_
  5. #define ASH_ACCESSIBILITY_STICKY_KEYS_STICKY_KEYS_OVERLAY_H_
  6. #include <memory>
  7. #include "ash/accessibility/sticky_keys/sticky_keys_state.h"
  8. #include "ash/ash_export.h"
  9. #include "ui/compositor/layer_animation_observer.h"
  10. #include "ui/events/event_constants.h"
  11. #include "ui/gfx/geometry/size.h"
  12. namespace gfx {
  13. class Rect;
  14. }
  15. namespace views {
  16. class Widget;
  17. }
  18. namespace ash {
  19. class StickyKeysOverlayView;
  20. // Controls the overlay UI for sticky keys, an accessibility feature allowing
  21. // use of modifier keys without holding them down. This overlay will appear as
  22. // a transparent window on the top left of the screen, showing the state of
  23. // each sticky key modifier.
  24. class ASH_EXPORT StickyKeysOverlay : public ui::ImplicitAnimationObserver {
  25. public:
  26. StickyKeysOverlay();
  27. ~StickyKeysOverlay() override;
  28. // Shows or hides the overlay.
  29. void Show(bool visible);
  30. void UpdateBoundsIfVisible();
  31. void SetModifierVisible(ui::EventFlags modifier, bool visible);
  32. bool GetModifierVisible(ui::EventFlags modifier);
  33. // Updates the overlay with the current state of a sticky key modifier.
  34. void SetModifierKeyState(ui::EventFlags modifier, StickyKeyState state);
  35. // Get the current state of the sticky key modifier in the overlay.
  36. StickyKeyState GetModifierKeyState(ui::EventFlags modifier);
  37. // Returns true if the overlay is currently visible. If the overlay is
  38. // animating, the returned value is the target of the animation.
  39. bool is_visible() { return is_visible_; }
  40. // Returns the underlying views::Widget for testing purposes. The returned
  41. // widget is owned by StickyKeysOverlay.
  42. views::Widget* GetWidgetForTesting();
  43. private:
  44. // Returns the current bounds of the overlay, which is based on visibility.
  45. gfx::Rect CalculateOverlayBounds();
  46. // ui::ImplicitAnimationObserver:
  47. void OnImplicitAnimationsCompleted() override;
  48. bool is_visible_ = false;
  49. std::unique_ptr<views::Widget> overlay_widget_;
  50. StickyKeysOverlayView* overlay_view_; // owned by |overlay_widget_|.
  51. gfx::Size widget_size_;
  52. };
  53. } // namespace ash
  54. #endif // ASH_ACCESSIBILITY_STICKY_KEYS_STICKY_KEYS_OVERLAY_H_