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 |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 return; | 102 return; |
103 } | 103 } |
104 | 104 |
105 if (state_ == NO_FINGERS_DOWN && event.type() == ui::ET_TOUCH_PRESSED) { | 105 if (state_ == NO_FINGERS_DOWN && event.type() == ui::ET_TOUCH_PRESSED) { |
106 state_ = ONE_FINGER_DOWN; | 106 state_ = ONE_FINGER_DOWN; |
107 } else if (state_ == ONE_FINGER_DOWN && | 107 } else if (state_ == ONE_FINGER_DOWN && |
108 event.type() == ui::ET_TOUCH_PRESSED) { | 108 event.type() == ui::ET_TOUCH_PRESSED) { |
109 state_ = TWO_FINGERS_DOWN; | 109 state_ = TWO_FINGERS_DOWN; |
110 two_finger_start_time_ = Now(); | 110 two_finger_start_time_ = Now(); |
111 StartTimer(); | 111 StartTimer(); |
| 112 delegate_->OnTwoFingerTouchStart(); |
112 } | 113 } |
113 } | 114 } |
114 | 115 |
115 base::TimeTicks TouchAccessibilityEnabler::Now() { | 116 base::TimeTicks TouchAccessibilityEnabler::Now() { |
116 if (tick_clock_) { | 117 if (tick_clock_) { |
117 // This is the same as what EventTimeForNow() does, but here we do it | 118 // This is the same as what EventTimeForNow() does, but here we do it |
118 // with a clock that can be replaced with a simulated clock for tests. | 119 // with a clock that can be replaced with a simulated clock for tests. |
119 return tick_clock_->NowTicks(); | 120 return tick_clock_->NowTicks(); |
120 } | 121 } |
121 return ui::EventTimeForNow(); | 122 return ui::EventTimeForNow(); |
122 } | 123 } |
123 | 124 |
124 void TouchAccessibilityEnabler::StartTimer() { | 125 void TouchAccessibilityEnabler::StartTimer() { |
125 if (timer_.IsRunning()) | 126 if (timer_.IsRunning()) |
126 return; | 127 return; |
127 | 128 |
128 timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(kTimerDelayInMS), | 129 timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(kTimerDelayInMS), |
129 this, &ui::TouchAccessibilityEnabler::OnTimer); | 130 this, &ui::TouchAccessibilityEnabler::OnTimer); |
130 } | 131 } |
131 | 132 |
132 void TouchAccessibilityEnabler::CancelTimer() { | 133 void TouchAccessibilityEnabler::CancelTimer() { |
133 if (timer_.IsRunning()) | 134 if (timer_.IsRunning()) { |
134 timer_.Stop(); | 135 timer_.Stop(); |
| 136 delegate_->OnTwoFingerTouchStop(); |
| 137 } |
135 } | 138 } |
136 | 139 |
137 void TouchAccessibilityEnabler::OnTimer() { | 140 void TouchAccessibilityEnabler::OnTimer() { |
138 base::TimeTicks now = Now(); | 141 base::TimeTicks now = Now(); |
139 double tick_count_f = | 142 double tick_count_f = |
140 (now - two_finger_start_time_).InMillisecondsF() / kTimerDelayInMS; | 143 (now - two_finger_start_time_).InMillisecondsF() / kTimerDelayInMS; |
141 int tick_count = roundf(tick_count_f); | 144 int tick_count = roundf(tick_count_f); |
142 | 145 |
143 if (tick_count == kTimerTicksOfFirstSoundFeedback) { | 146 if (tick_count == kTimerTicksOfFirstSoundFeedback) { |
144 base::RecordAction( | 147 base::RecordAction( |
145 base::UserMetricsAction("Accessibility.TwoFingersHeldDown")); | 148 base::UserMetricsAction("Accessibility.TwoFingersHeldDown")); |
146 } | 149 } |
147 | 150 |
148 if (tick_count >= kTimerTicksOfFirstSoundFeedback && | 151 if (tick_count >= kTimerTicksOfFirstSoundFeedback && |
149 tick_count < kTimerTicksToToggleSpokenFeedback) { | 152 tick_count < kTimerTicksToToggleSpokenFeedback) { |
150 delegate_->PlaySpokenFeedbackToggleCountdown(tick_count); | 153 delegate_->PlaySpokenFeedbackToggleCountdown(tick_count); |
151 } | 154 } |
152 if (tick_count == kTimerTicksToToggleSpokenFeedback) { | 155 if (tick_count == kTimerTicksToToggleSpokenFeedback) { |
153 delegate_->ToggleSpokenFeedback(); | 156 delegate_->ToggleSpokenFeedback(); |
154 state_ = WAIT_FOR_NO_FINGERS; | 157 state_ = WAIT_FOR_NO_FINGERS; |
155 } | 158 } |
156 } | 159 } |
157 | 160 |
158 } // namespace ui | 161 } // namespace ui |
OLD | NEW |