OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2010 Apple Inc. All rights reserved. | 2 * Copyright (C) 2010 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 { | 121 { |
122 return state == DefinitelyProcessingNewUserGesture || state == DefinitelyPro
cessingUserGesture; | 122 return state == DefinitelyProcessingNewUserGesture || state == DefinitelyPro
cessingUserGesture; |
123 } | 123 } |
124 | 124 |
125 } // namespace | 125 } // namespace |
126 | 126 |
127 ProcessingUserGestureState UserGestureIndicator::s_state = DefinitelyNotProcessi
ngUserGesture; | 127 ProcessingUserGestureState UserGestureIndicator::s_state = DefinitelyNotProcessi
ngUserGesture; |
128 UserGestureIndicator* UserGestureIndicator::s_topmostIndicator = 0; | 128 UserGestureIndicator* UserGestureIndicator::s_topmostIndicator = 0; |
129 bool UserGestureIndicator::s_processedUserGestureSinceLoad = false; | 129 bool UserGestureIndicator::s_processedUserGestureSinceLoad = false; |
130 | 130 |
131 UserGestureIndicator::UserGestureIndicator(ProcessingUserGestureState state) | 131 UserGestureIndicator::UserGestureIndicator(ProcessingUserGestureState state, Use
rGestureUtilizedCallback* usageCallback) |
132 : m_previousState(DefinitelyNotProcessingUserGesture) | 132 : m_previousState(DefinitelyNotProcessingUserGesture) |
| 133 , m_usageCallback(usageCallback) |
133 { | 134 { |
134 // Silently ignore UserGestureIndicators on non-main threads. | 135 // Silently ignore UserGestureIndicators on non-main threads. |
135 if (!isMainThread()) | 136 if (!isMainThread()) |
136 return; | 137 return; |
137 | 138 |
138 m_previousState = s_state; | 139 m_previousState = s_state; |
139 | 140 |
140 // We overwrite s_state only if the caller is definite about the gesture sta
te. | 141 // We overwrite s_state only if the caller is definite about the gesture sta
te. |
141 if (isDefinite(state)) { | 142 if (isDefinite(state)) { |
142 if (!s_topmostIndicator) { | 143 if (!s_topmostIndicator) { |
143 s_topmostIndicator = this; | 144 s_topmostIndicator = this; |
144 m_token = GestureToken::create(); | 145 m_token = GestureToken::create(); |
145 } else { | 146 } else { |
146 m_token = currentToken(); | 147 m_token = currentToken(); |
147 } | 148 } |
148 s_state = state; | 149 s_state = state; |
149 } | 150 } |
150 | 151 |
151 if (state == DefinitelyProcessingNewUserGesture) { | 152 if (state == DefinitelyProcessingNewUserGesture) { |
152 static_cast<GestureToken*>(m_token.get())->addGesture(); | 153 static_cast<GestureToken*>(m_token.get())->addGesture(); |
153 s_processedUserGestureSinceLoad = true; | 154 s_processedUserGestureSinceLoad = true; |
154 } else if (state == DefinitelyProcessingUserGesture && s_topmostIndicator ==
this) { | 155 } else if (state == DefinitelyProcessingUserGesture && s_topmostIndicator ==
this) { |
155 static_cast<GestureToken*>(m_token.get())->addGesture(); | 156 static_cast<GestureToken*>(m_token.get())->addGesture(); |
156 s_processedUserGestureSinceLoad = true; | 157 s_processedUserGestureSinceLoad = true; |
157 } | 158 } |
158 ASSERT(isDefinite(s_state)); | 159 ASSERT(isDefinite(s_state)); |
159 } | 160 } |
160 | 161 |
161 UserGestureIndicator::UserGestureIndicator(PassRefPtr<UserGestureToken> token) | 162 UserGestureIndicator::UserGestureIndicator(PassRefPtr<UserGestureToken> token, U
serGestureUtilizedCallback* usageCallback) |
162 : m_previousState(DefinitelyNotProcessingUserGesture) | 163 : m_previousState(DefinitelyNotProcessingUserGesture) |
| 164 , m_usageCallback(usageCallback) |
163 { | 165 { |
164 // Silently ignore UserGestureIndicators on non-main threads. | 166 // Silently ignore UserGestureIndicators on non-main threads. |
165 if (!isMainThread()) | 167 if (!isMainThread()) |
166 return; | 168 return; |
167 | 169 |
168 m_previousState = s_state; | 170 m_previousState = s_state; |
169 | 171 |
170 if (token) { | 172 if (token) { |
171 static_cast<GestureToken*>(token.get())->resetTimestamp(); | 173 static_cast<GestureToken*>(token.get())->resetTimestamp(); |
172 if (!s_topmostIndicator) { | 174 if (!s_topmostIndicator) { |
(...skipping 16 matching lines...) Expand all Loading... |
189 { | 191 { |
190 if (!isMainThread()) | 192 if (!isMainThread()) |
191 return; | 193 return; |
192 s_state = m_previousState; | 194 s_state = m_previousState; |
193 if (s_topmostIndicator == this) | 195 if (s_topmostIndicator == this) |
194 s_topmostIndicator = nullptr; | 196 s_topmostIndicator = nullptr; |
195 ASSERT(isDefinite(s_state)); | 197 ASSERT(isDefinite(s_state)); |
196 } | 198 } |
197 | 199 |
198 // static | 200 // static |
| 201 bool UserGestureIndicator::utilizeUserGesture() |
| 202 { |
| 203 if (UserGestureIndicator::processingUserGesture()) { |
| 204 if (s_topmostIndicator->m_usageCallback) { |
| 205 s_topmostIndicator->m_usageCallback->userGestureUtilized(); |
| 206 s_topmostIndicator->m_usageCallback = nullptr; |
| 207 } |
| 208 return true; |
| 209 } |
| 210 return false; |
| 211 } |
| 212 |
199 bool UserGestureIndicator::processingUserGesture() | 213 bool UserGestureIndicator::processingUserGesture() |
200 { | 214 { |
201 if (auto* token = currentToken()) { | 215 if (auto* token = currentToken()) { |
202 ASSERT(isMainThread()); | 216 ASSERT(isMainThread()); |
203 return isDefiniteUserGesture(s_state) && static_cast<GestureToken*>(toke
n)->hasGestures(); | 217 return isDefiniteUserGesture(s_state) && static_cast<GestureToken*>(toke
n)->hasGestures(); |
204 } | 218 } |
205 | 219 |
206 return false; | 220 return false; |
207 } | 221 } |
208 | 222 |
209 // static | 223 // static |
210 bool UserGestureIndicator::consumeUserGesture() | 224 bool UserGestureIndicator::consumeUserGesture() |
211 { | 225 { |
212 if (auto* token = currentToken()) { | 226 if (auto* token = currentToken()) { |
213 ASSERT(isMainThread()); | 227 ASSERT(isMainThread()); |
214 return static_cast<GestureToken*>(token)->consumeGesture(); | 228 if (static_cast<GestureToken*>(token)->consumeGesture()) { |
| 229 if (s_topmostIndicator->m_usageCallback) { |
| 230 s_topmostIndicator->m_usageCallback->userGestureUtilized(); |
| 231 s_topmostIndicator->m_usageCallback = nullptr; |
| 232 } |
| 233 return true; |
| 234 } |
215 } | 235 } |
216 | |
217 return false; | 236 return false; |
218 } | 237 } |
219 | 238 |
220 // static | 239 // static |
221 UserGestureToken* UserGestureIndicator::currentToken() | 240 UserGestureToken* UserGestureIndicator::currentToken() |
222 { | 241 { |
223 if (!isMainThread() || !s_topmostIndicator) | 242 if (!isMainThread() || !s_topmostIndicator) |
224 return nullptr; | 243 return nullptr; |
225 return s_topmostIndicator->m_token.get(); | 244 return s_topmostIndicator->m_token.get(); |
226 } | 245 } |
227 | 246 |
228 // static | 247 // static |
229 void UserGestureIndicator::clearProcessedUserGestureSinceLoad() | 248 void UserGestureIndicator::clearProcessedUserGestureSinceLoad() |
230 { | 249 { |
231 if (isMainThread()) | 250 if (isMainThread()) |
232 s_processedUserGestureSinceLoad = false; | 251 s_processedUserGestureSinceLoad = false; |
233 } | 252 } |
234 | 253 |
235 // static | 254 // static |
236 bool UserGestureIndicator::processedUserGestureSinceLoad() | 255 bool UserGestureIndicator::processedUserGestureSinceLoad() |
237 { | 256 { |
238 if (!isMainThread()) | 257 if (!isMainThread()) |
239 return false; | 258 return false; |
240 return s_processedUserGestureSinceLoad; | 259 return s_processedUserGestureSinceLoad; |
241 } | 260 } |
242 | 261 |
243 } // namespace blink | 262 } // namespace blink |
OLD | NEW |