Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 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 UI_CHROMEOS_TOUCH_ACCESSIBILITY_ENABLER_H_ | |
| 6 #define UI_CHROMEOS_TOUCH_ACCESSIBILITY_ENABLER_H_ | |
| 7 | |
| 8 #include "base/macros.h" | |
| 9 #include "base/time/tick_clock.h" | |
| 10 #include "base/timer/timer.h" | |
| 11 #include "base/values.h" | |
| 12 #include "ui/chromeos/ui_chromeos_export.h" | |
| 13 #include "ui/events/event.h" | |
| 14 #include "ui/events/event_rewriter.h" | |
| 15 #include "ui/events/gesture_detection/gesture_detector.h" | |
| 16 | |
| 17 namespace aura { | |
| 18 class Window; | |
| 19 } | |
| 20 | |
| 21 namespace ui { | |
| 22 | |
| 23 class Event; | |
| 24 class EventHandler; | |
| 25 class TouchEvent; | |
| 26 | |
| 27 // A delegate to handle commands in response to detected accessibility gesture | |
| 28 // events. | |
| 29 class TouchAccessibilityEnablerDelegate { | |
| 30 public: | |
| 31 virtual ~TouchAccessibilityEnablerDelegate() {} | |
| 32 | |
| 33 // While the user holds down two fingers on a touch screen, which is the | |
| 34 // gesture to enable spoken feedback (if held down long enough), play a sound | |
| 35 // every "tick" (approximately every half-second) to warn the user something | |
| 36 // is about to happen. | |
| 37 virtual void PlaySpokenFeedbackToggleCountdown(int tick_count) = 0; | |
|
oshima
2016/11/08 18:14:43
optional: you may have empty impl for void functio
dmazzoni
2016/11/08 20:43:47
Done.
| |
| 38 | |
| 39 // Toggles spoken feedback. | |
| 40 virtual void ToggleSpokenFeedback() = 0; | |
| 41 }; | |
| 42 | |
| 43 // TouchAccessibilityEnabler triggers turning spoken feedback on or off | |
| 44 // by holding down two fingers on the touch screen for several seconds. | |
| 45 class UI_CHROMEOS_EXPORT TouchAccessibilityEnabler : public ui::EventRewriter { | |
| 46 public: | |
| 47 explicit TouchAccessibilityEnabler( | |
|
oshima
2016/11/08 18:14:43
nit: remove explicit
dmazzoni
2016/11/08 20:43:47
Done.
| |
| 48 aura::Window* root_window, | |
| 49 ui::TouchAccessibilityEnablerDelegate* delegate); | |
| 50 ~TouchAccessibilityEnabler() override; | |
| 51 | |
| 52 bool IsInNoFingersDownForTesting() { return state_ == NO_FINGERS_DOWN; } | |
| 53 bool IsInOneFingerDownForTesting() { return state_ == ONE_FINGER_DOWN; } | |
| 54 bool IsInTwoFingersDownForTesting() { return state_ == TWO_FINGERS_DOWN; } | |
| 55 bool IsInWaitForNoFingersForTesting() { | |
| 56 return state_ == WAIT_FOR_NO_FINGERS; | |
| 57 } | |
| 58 void TriggerOnTimerForTesting() { OnTimer(); } | |
| 59 | |
| 60 protected: | |
|
oshima
2016/11/08 18:14:43
is there subclass for this?
dmazzoni
2016/11/08 20:43:47
No, changed to private.
| |
| 61 // Overridden from ui::EventRewriter | |
| 62 ui::EventRewriteStatus RewriteEvent( | |
| 63 const ui::Event& event, | |
| 64 std::unique_ptr<ui::Event>* rewritten_event) override; | |
| 65 ui::EventRewriteStatus NextDispatchEvent( | |
| 66 const ui::Event& last_event, | |
| 67 std::unique_ptr<ui::Event>* new_event) override; | |
| 68 | |
| 69 void HandleTouchEvent(const ui::TouchEvent& event); | |
| 70 | |
| 71 void StartTimer(); | |
| 72 void CancelTimer(); | |
| 73 void OnTimer(); | |
| 74 | |
| 75 // Returns the current time of the tick clock. | |
| 76 base::TimeTicks Now(); | |
| 77 | |
| 78 enum State { | |
| 79 // No fingers are down. | |
| 80 NO_FINGERS_DOWN, | |
| 81 | |
| 82 // One finger is down and it's possible this could be a two-finger-hold. | |
| 83 ONE_FINGER_DOWN, | |
| 84 | |
| 85 // Two fingers are down and stationary and we will trigger enabling | |
| 86 // spoken feedback after a delay. | |
| 87 TWO_FINGERS_DOWN, | |
| 88 | |
| 89 // This is the "reject" state when we get anything other than two fingers | |
| 90 // held down and stationary. Stay in this state until all fingers are | |
| 91 // removed. | |
| 92 WAIT_FOR_NO_FINGERS | |
| 93 }; | |
| 94 | |
| 95 aura::Window* root_window_; | |
| 96 | |
| 97 // Called when we detect a long-press of two fingers. Not owned. | |
| 98 ui::TouchAccessibilityEnablerDelegate* delegate_; | |
| 99 | |
| 100 // The current state. | |
| 101 State state_; | |
| 102 | |
| 103 // The time when we entered the two finger state. | |
| 104 base::TimeTicks two_finger_start_time_; | |
| 105 | |
| 106 // A set of touch ids for fingers currently touching the screen. | |
| 107 std::vector<int> touch_ids_; | |
| 108 | |
| 109 // Map of touch ids to their initial locations. | |
| 110 std::map<int, gfx::PointF> touch_locations_; | |
| 111 | |
| 112 // A timer that triggers repeatedly while two fingers are held down. | |
| 113 base::RepeatingTimer timer_; | |
| 114 | |
| 115 // A default gesture detector config, so we can share the same | |
| 116 // timeout and pixel slop constants. | |
| 117 ui::GestureDetector::Config gesture_detector_config_; | |
| 118 | |
| 119 // When touch_accessibility_enabler gets time relative to real time during | |
| 120 // testing, this clock is set to the simulated clock and used. | |
| 121 base::TickClock* tick_clock_; | |
| 122 | |
| 123 DISALLOW_COPY_AND_ASSIGN(TouchAccessibilityEnabler); | |
| 124 }; | |
| 125 | |
| 126 } // namespace ui | |
| 127 | |
| 128 #endif // UI_CHROMEOS_TOUCH_ACCESSIBILITY_ENABLER_H_ | |
| OLD | NEW |