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 
5 #ifndef ASH_ACCESSIBILITY_ACCESSIBILITY_HIGHLIGHT_CONTROLLER_H_
6 #define ASH_ACCESSIBILITY_ACCESSIBILITY_HIGHLIGHT_CONTROLLER_H_
7 
8 #include "ash/ash_export.h"
9 #include "base/macros.h"
10 #include "ui/aura/client/cursor_client_observer.h"
11 #include "ui/base/ime/input_method_observer.h"
12 #include "ui/events/event_handler.h"
13 #include "ui/gfx/geometry/point.h"
14 #include "ui/gfx/geometry/rect.h"
15 
16 namespace ui {
17 class KeyEvent;
18 class InputMethod;
19 class MouseEvent;
20 class TextInputClient;
21 }  // namespace ui
22 
23 namespace ash {
24 
25 // Controls visual highlights that Chrome OS can draw around the focused object,
26 // the cursor, and the text caret for accessibility.
27 class ASH_EXPORT AccessibilityHighlightController
28     : public ui::EventHandler,
29       public ui::InputMethodObserver,
30       public aura::client::CursorClientObserver {
31  public:
32   AccessibilityHighlightController();
33   ~AccessibilityHighlightController() override;
34 
35   void HighlightFocus(bool focus);
36   void HighlightCursor(bool cursor);
37   void HighlightCaret(bool caret);
38   void SetFocusHighlightRect(const gfx::Rect& bounds_in_screen);
39 
40   // Updates the visual highlight position for the text input caret. Removes
41   // the highlight if the caret is not visible.
42   void SetCaretBounds(const gfx::Rect& caret_bounds_in_screen);
43 
44   // ui::EventHandler:
45   void OnMouseEvent(ui::MouseEvent* event) override;
46   void OnKeyEvent(ui::KeyEvent* event) override;
47 
48   // ui::InputMethodObserver:
OnFocus()49   void OnFocus() override {}
OnBlur()50   void OnBlur() override {}
OnInputMethodDestroyed(const ui::InputMethod * input_method)51   void OnInputMethodDestroyed(const ui::InputMethod* input_method) override {}
OnShowVirtualKeyboardIfEnabled()52   void OnShowVirtualKeyboardIfEnabled() override {}
53   void OnTextInputStateChanged(const ui::TextInputClient* client) override;
54   void OnCaretBoundsChanged(const ui::TextInputClient* client) override;
55 
56   // aura::client::CursorClientObserver:
57   void OnCursorVisibilityChanged(bool is_visible) override;
58 
59  private:
60   bool IsCursorVisible();
61   bool IsCaretVisible(const gfx::Rect& caret_bounds_in_screen);
62   void UpdateFocusAndCaretHighlights();
63   void UpdateCursorHighlight();
64 
65   bool focus_ = false;
66   gfx::Rect focus_rect_;
67 
68   bool cursor_ = false;
69   gfx::Point cursor_point_;
70 
71   bool caret_ = false;
72   bool caret_visible_ = false;
73   gfx::Point caret_point_;
74 
75   DISALLOW_COPY_AND_ASSIGN(AccessibilityHighlightController);
76 };
77 
78 }  // namespace ash
79 
80 #endif  // ASH_ACCESSIBILITY_ACCESSIBILITY_HIGHLIGHT_CONTROLLER_H_
81