Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(170)

Side by Side Diff: third_party/WebKit/Source/platform/UserGestureIndicator.cpp

Issue 1799253002: Stricter user gestures for touch - measure and warn (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 116
117 static bool isDefinite(ProcessingUserGestureState state) 117 static bool isDefinite(ProcessingUserGestureState state)
118 { 118 {
119 return state == DefinitelyProcessingNewUserGesture || state == DefinitelyPro cessingUserGesture || state == DefinitelyNotProcessingUserGesture; 119 return state == DefinitelyProcessingNewUserGesture || state == DefinitelyPro cessingUserGesture || state == DefinitelyNotProcessingUserGesture;
120 } 120 }
121 121
122 ProcessingUserGestureState UserGestureIndicator::s_state = DefinitelyNotProcessi ngUserGesture; 122 ProcessingUserGestureState UserGestureIndicator::s_state = DefinitelyNotProcessi ngUserGesture;
123 UserGestureIndicator* UserGestureIndicator::s_topmostIndicator = 0; 123 UserGestureIndicator* UserGestureIndicator::s_topmostIndicator = 0;
124 bool UserGestureIndicator::s_processedUserGestureSinceLoad = false; 124 bool UserGestureIndicator::s_processedUserGestureSinceLoad = false;
125 125
126 UserGestureIndicator::UserGestureIndicator(ProcessingUserGestureState state) 126 UserGestureIndicator::UserGestureIndicator(ProcessingUserGestureState state, Use rGestureUsedCallback* usageCallback)
127 : m_previousState(DefinitelyNotProcessingUserGesture) 127 : m_previousState(DefinitelyNotProcessingUserGesture)
128 , m_usageCallback(usageCallback)
128 { 129 {
129 // Silently ignore UserGestureIndicators on non-main threads. 130 // Silently ignore UserGestureIndicators on non-main threads.
130 if (!isMainThread()) 131 if (!isMainThread())
131 return; 132 return;
132 133
133 m_previousState = s_state; 134 m_previousState = s_state;
134 135
135 // We overwrite s_state only if the caller is definite about the gesture sta te. 136 // We overwrite s_state only if the caller is definite about the gesture sta te.
136 if (isDefinite(state)) { 137 if (isDefinite(state)) {
137 if (!s_topmostIndicator) { 138 if (!s_topmostIndicator) {
138 s_topmostIndicator = this; 139 s_topmostIndicator = this;
139 m_token = GestureToken::create(); 140 m_token = GestureToken::create();
140 } else { 141 } else {
141 m_token = s_topmostIndicator->currentToken(); 142 m_token = s_topmostIndicator->currentToken();
142 } 143 }
143 s_state = state; 144 s_state = state;
144 } 145 }
145 146
146 if (state == DefinitelyProcessingNewUserGesture) { 147 if (state == DefinitelyProcessingNewUserGesture) {
147 static_cast<GestureToken*>(m_token.get())->addGesture(); 148 static_cast<GestureToken*>(m_token.get())->addGesture();
148 s_processedUserGestureSinceLoad = true; 149 s_processedUserGestureSinceLoad = true;
149 } else if (state == DefinitelyProcessingUserGesture && s_topmostIndicator == this) { 150 } else if (state == DefinitelyProcessingUserGesture && s_topmostIndicator == this) {
150 static_cast<GestureToken*>(m_token.get())->addGesture(); 151 static_cast<GestureToken*>(m_token.get())->addGesture();
151 s_processedUserGestureSinceLoad = true; 152 s_processedUserGestureSinceLoad = true;
152 } 153 }
153 ASSERT(isDefinite(s_state)); 154 ASSERT(isDefinite(s_state));
154 } 155 }
155 156
156 UserGestureIndicator::UserGestureIndicator(PassRefPtr<UserGestureToken> token) 157 UserGestureIndicator::UserGestureIndicator(PassRefPtr<UserGestureToken> token, U serGestureUsedCallback* usageCallback)
157 : m_previousState(DefinitelyNotProcessingUserGesture) 158 : m_previousState(DefinitelyNotProcessingUserGesture)
159 , m_usageCallback(usageCallback)
158 { 160 {
159 // Silently ignore UserGestureIndicators on non-main threads. 161 // Silently ignore UserGestureIndicators on non-main threads.
160 if (!isMainThread()) 162 if (!isMainThread())
161 return; 163 return;
162 164
163 m_previousState = s_state; 165 m_previousState = s_state;
164 166
165 if (token) { 167 if (token) {
166 static_cast<GestureToken*>(token.get())->resetTimestamp(); 168 static_cast<GestureToken*>(token.get())->resetTimestamp();
167 if (!s_topmostIndicator) { 169 if (!s_topmostIndicator) {
(...skipping 17 matching lines...) Expand all
185 if (!isMainThread()) 187 if (!isMainThread())
186 return; 188 return;
187 s_state = m_previousState; 189 s_state = m_previousState;
188 if (s_topmostIndicator == this) 190 if (s_topmostIndicator == this)
189 s_topmostIndicator = 0; 191 s_topmostIndicator = 0;
190 ASSERT(isDefinite(s_state)); 192 ASSERT(isDefinite(s_state));
191 } 193 }
192 194
193 bool UserGestureIndicator::processingUserGesture() 195 bool UserGestureIndicator::processingUserGesture()
194 { 196 {
197 if (UserGestureIndicator::processingUserGestureUntracked()) {
198 if (s_topmostIndicator->m_usageCallback) {
199 s_topmostIndicator->m_usageCallback->userGestureUsed();
200 s_topmostIndicator->m_usageCallback = nullptr;
201 }
202 return true;
203 }
204 return false;
205 }
206
207 bool UserGestureIndicator::processingUserGestureUntracked()
208 {
195 if (!isMainThread()) 209 if (!isMainThread())
196 return false; 210 return false;
197 return s_topmostIndicator && static_cast<GestureToken*>(s_topmostIndicator-> currentToken())->hasGestures() && (s_state == DefinitelyProcessingNewUserGesture || s_state == DefinitelyProcessingUserGesture); 211 return s_topmostIndicator && static_cast<GestureToken*>(s_topmostIndicator-> currentToken())->hasGestures() && (s_state == DefinitelyProcessingNewUserGesture || s_state == DefinitelyProcessingUserGesture);
198 } 212 }
199 213
200 bool UserGestureIndicator::consumeUserGesture() 214 bool UserGestureIndicator::consumeUserGesture()
201 { 215 {
202 if (!isMainThread() || !s_topmostIndicator) 216 if (!isMainThread() || !s_topmostIndicator)
203 return false; 217 return false;
204 return static_cast<GestureToken*>(s_topmostIndicator->currentToken())->consu meGesture(); 218 if (static_cast<GestureToken*>(s_topmostIndicator->currentToken())->consumeG esture()) {
219 if (s_topmostIndicator->m_usageCallback) {
220 s_topmostIndicator->m_usageCallback->userGestureUsed();
221 s_topmostIndicator->m_usageCallback = nullptr;
222 }
223 return true;
224 }
225 return false;
205 } 226 }
206 227
207 UserGestureToken* UserGestureIndicator::currentToken() 228 UserGestureToken* UserGestureIndicator::currentToken()
208 { 229 {
209 if (!isMainThread() || !s_topmostIndicator) 230 if (!isMainThread() || !s_topmostIndicator)
210 return 0; 231 return 0;
211 return s_topmostIndicator->m_token.get(); 232 return s_topmostIndicator->m_token.get();
212 } 233 }
213 234
214 void UserGestureIndicator::clearProcessedUserGestureSinceLoad() 235 void UserGestureIndicator::clearProcessedUserGestureSinceLoad()
215 { 236 {
216 if (isMainThread()) 237 if (isMainThread())
217 s_processedUserGestureSinceLoad = false; 238 s_processedUserGestureSinceLoad = false;
218 } 239 }
219 240
220 bool UserGestureIndicator::processedUserGestureSinceLoad() 241 bool UserGestureIndicator::processedUserGestureSinceLoad()
221 { 242 {
222 if (!isMainThread()) 243 if (!isMainThread())
223 return false; 244 return false;
224 return s_processedUserGestureSinceLoad; 245 return s_processedUserGestureSinceLoad;
225 } 246 }
226 247
227 } // namespace blink 248 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698