| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/chromeos/touch_accessibility_enabler.h" | 5 #include "ui/chromeos/touch_accessibility_enabler.h" |
| 6 | 6 |
| 7 #include <math.h> | 7 #include <math.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/metrics/user_metrics.h" |
| 12 #include "base/time/default_tick_clock.h" | 13 #include "base/time/default_tick_clock.h" |
| 13 #include "ui/aura/window.h" | 14 #include "ui/aura/window.h" |
| 14 #include "ui/aura/window_event_dispatcher.h" | 15 #include "ui/aura/window_event_dispatcher.h" |
| 15 #include "ui/aura/window_tree_host.h" | 16 #include "ui/aura/window_tree_host.h" |
| 16 #include "ui/events/event.h" | 17 #include "ui/events/event.h" |
| 17 #include "ui/events/event_processor.h" | 18 #include "ui/events/event_processor.h" |
| 18 #include "ui/events/event_utils.h" | 19 #include "ui/events/event_utils.h" |
| 19 | 20 |
| 20 namespace ui { | 21 namespace ui { |
| 21 | 22 |
| 22 namespace { | 23 namespace { |
| 23 | 24 |
| 24 // Delay between timer callbacks. Each one plays a tick sound. | 25 // Delay between timer callbacks. Each one plays a tick sound. |
| 25 constexpr int kTimerDelayInMS = 500; | 26 constexpr int kTimerDelayInMS = 500; |
| 26 | 27 |
| 28 // The number of ticks of the timer before the first sound is generated. |
| 29 constexpr int kTimerTicksOfFirstSoundFeedback = 6; |
| 30 |
| 27 // The number of ticks of the timer before toggling spoken feedback. | 31 // The number of ticks of the timer before toggling spoken feedback. |
| 28 constexpr int kTimerTicksToToggleSpokenFeedback = 7; | 32 constexpr int kTimerTicksToToggleSpokenFeedback = 10; |
| 29 | 33 |
| 30 } // namespace | 34 } // namespace |
| 31 | 35 |
| 32 TouchAccessibilityEnabler::TouchAccessibilityEnabler( | 36 TouchAccessibilityEnabler::TouchAccessibilityEnabler( |
| 33 aura::Window* root_window, | 37 aura::Window* root_window, |
| 34 TouchAccessibilityEnablerDelegate* delegate) | 38 TouchAccessibilityEnablerDelegate* delegate) |
| 35 : root_window_(root_window), | 39 : root_window_(root_window), |
| 36 delegate_(delegate), | 40 delegate_(delegate), |
| 37 state_(NO_FINGERS_DOWN), | 41 state_(NO_FINGERS_DOWN), |
| 38 tick_clock_(NULL) { | 42 tick_clock_(NULL) { |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 void TouchAccessibilityEnabler::CancelTimer() { | 132 void TouchAccessibilityEnabler::CancelTimer() { |
| 129 if (timer_.IsRunning()) | 133 if (timer_.IsRunning()) |
| 130 timer_.Stop(); | 134 timer_.Stop(); |
| 131 } | 135 } |
| 132 | 136 |
| 133 void TouchAccessibilityEnabler::OnTimer() { | 137 void TouchAccessibilityEnabler::OnTimer() { |
| 134 base::TimeTicks now = Now(); | 138 base::TimeTicks now = Now(); |
| 135 double tick_count_f = | 139 double tick_count_f = |
| 136 (now - two_finger_start_time_).InMillisecondsF() / kTimerDelayInMS; | 140 (now - two_finger_start_time_).InMillisecondsF() / kTimerDelayInMS; |
| 137 int tick_count = roundf(tick_count_f); | 141 int tick_count = roundf(tick_count_f); |
| 138 if (tick_count >= 1 && tick_count < kTimerTicksToToggleSpokenFeedback) { | 142 |
| 143 if (tick_count == kTimerTicksOfFirstSoundFeedback) { |
| 144 base::RecordAction( |
| 145 base::UserMetricsAction("Accessibility.TwoFingersHeldDown")); |
| 146 } |
| 147 |
| 148 if (tick_count >= kTimerTicksOfFirstSoundFeedback && |
| 149 tick_count < kTimerTicksToToggleSpokenFeedback) { |
| 139 delegate_->PlaySpokenFeedbackToggleCountdown(tick_count); | 150 delegate_->PlaySpokenFeedbackToggleCountdown(tick_count); |
| 140 } | 151 } |
| 141 if (tick_count == kTimerTicksToToggleSpokenFeedback) { | 152 if (tick_count == kTimerTicksToToggleSpokenFeedback) { |
| 142 delegate_->ToggleSpokenFeedback(); | 153 delegate_->ToggleSpokenFeedback(); |
| 143 state_ = WAIT_FOR_NO_FINGERS; | 154 state_ = WAIT_FOR_NO_FINGERS; |
| 144 } | 155 } |
| 145 } | 156 } |
| 146 | 157 |
| 147 } // namespace ui | 158 } // namespace ui |
| OLD | NEW |