| 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_handler.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) {} |  | 
| 38 |  | 
| 39   // Toggles spoken feedback. |  | 
| 40   virtual void ToggleSpokenFeedback() {} |  | 
| 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::EventHandler { |  | 
| 46  public: |  | 
| 47   TouchAccessibilityEnabler(aura::Window* root_window, |  | 
| 48                             ui::TouchAccessibilityEnablerDelegate* delegate); |  | 
| 49   ~TouchAccessibilityEnabler() override; |  | 
| 50 |  | 
| 51   bool IsInNoFingersDownForTesting() { return state_ == NO_FINGERS_DOWN; } |  | 
| 52   bool IsInOneFingerDownForTesting() { return state_ == ONE_FINGER_DOWN; } |  | 
| 53   bool IsInTwoFingersDownForTesting() { return state_ == TWO_FINGERS_DOWN; } |  | 
| 54   bool IsInWaitForNoFingersForTesting() { |  | 
| 55     return state_ == WAIT_FOR_NO_FINGERS; |  | 
| 56   } |  | 
| 57   void TriggerOnTimerForTesting() { OnTimer(); } |  | 
| 58 |  | 
| 59   void HandleTouchEvent(const ui::TouchEvent& event); |  | 
| 60 |  | 
| 61  private: |  | 
| 62   // Overridden from ui::EventHandler |  | 
| 63   void OnTouchEvent(ui::TouchEvent* event) override; |  | 
| 64 |  | 
| 65   void StartTimer(); |  | 
| 66   void CancelTimer(); |  | 
| 67   void OnTimer(); |  | 
| 68 |  | 
| 69   // Returns the current time of the tick clock. |  | 
| 70   base::TimeTicks Now(); |  | 
| 71 |  | 
| 72   enum State { |  | 
| 73     // No fingers are down. |  | 
| 74     NO_FINGERS_DOWN, |  | 
| 75 |  | 
| 76     // One finger is down and it's possible this could be a two-finger-hold. |  | 
| 77     ONE_FINGER_DOWN, |  | 
| 78 |  | 
| 79     // Two fingers are down and stationary and we will trigger enabling |  | 
| 80     // spoken feedback after a delay. |  | 
| 81     TWO_FINGERS_DOWN, |  | 
| 82 |  | 
| 83     // This is the "reject" state when we get anything other than two fingers |  | 
| 84     // held down and stationary. Stay in this state until all fingers are |  | 
| 85     // removed. |  | 
| 86     WAIT_FOR_NO_FINGERS |  | 
| 87   }; |  | 
| 88 |  | 
| 89   aura::Window* root_window_; |  | 
| 90 |  | 
| 91   // Called when we detect a long-press of two fingers. Not owned. |  | 
| 92   ui::TouchAccessibilityEnablerDelegate* delegate_; |  | 
| 93 |  | 
| 94   // The current state. |  | 
| 95   State state_; |  | 
| 96 |  | 
| 97   // The time when we entered the two finger state. |  | 
| 98   base::TimeTicks two_finger_start_time_; |  | 
| 99 |  | 
| 100   // Map of touch ids to their initial locations. |  | 
| 101   std::map<int, gfx::PointF> touch_locations_; |  | 
| 102 |  | 
| 103   // A timer that triggers repeatedly while two fingers are held down. |  | 
| 104   base::RepeatingTimer timer_; |  | 
| 105 |  | 
| 106   // A default gesture detector config, so we can share the same |  | 
| 107   // timeout and pixel slop constants. |  | 
| 108   ui::GestureDetector::Config gesture_detector_config_; |  | 
| 109 |  | 
| 110   // When touch_accessibility_enabler gets time relative to real time during |  | 
| 111   // testing, this clock is set to the simulated clock and used. |  | 
| 112   base::TickClock* tick_clock_; |  | 
| 113 |  | 
| 114   DISALLOW_COPY_AND_ASSIGN(TouchAccessibilityEnabler); |  | 
| 115 }; |  | 
| 116 |  | 
| 117 }  // namespace ui |  | 
| 118 |  | 
| 119 #endif  // UI_CHROMEOS_TOUCH_ACCESSIBILITY_ENABLER_H_ |  | 
| OLD | NEW | 
|---|