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

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

Issue 82693006: Adding handlers for user gesture callbacks. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Removed removeHandler Created 7 years, 1 month 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 11 matching lines...) Expand all
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE. 23 * THE POSSIBILITY OF SUCH DAMAGE.
24 */ 24 */
25 25
26 #include "config.h" 26 #include "config.h"
27 #include "platform/UserGestureIndicator.h" 27 #include "platform/UserGestureIndicator.h"
28 28
29 #include "wtf/Assertions.h" 29 #include "wtf/Assertions.h"
30 #include "wtf/CurrentTime.h" 30 #include "wtf/CurrentTime.h"
31 #include "wtf/MainThread.h" 31 #include "wtf/MainThread.h"
32 #include "wtf/Vector.h"
32 33
33 namespace WebCore { 34 namespace WebCore {
34 35
35 namespace { 36 namespace {
36 37
38 static Vector<RefPtr<UserGestureHandler> >& handlers()
39 {
40 ASSERT(isMainThread());
41 DEFINE_STATIC_LOCAL(Vector<RefPtr<UserGestureHandler> >, userGestureHandlers , ());
42 return userGestureHandlers;
43 }
44
37 // User gestures timeout in 1 second. 45 // User gestures timeout in 1 second.
38 const double userGestureTimeout = 1.0; 46 const double userGestureTimeout = 1.0;
39 47
40 // For out of process tokens we allow a 10 second delay. 48 // For out of process tokens we allow a 10 second delay.
41 const double userGestureOutOfProcessTimeout = 10.0; 49 const double userGestureOutOfProcessTimeout = 10.0;
42 50
43 class GestureToken : public UserGestureToken { 51 class GestureToken : public UserGestureToken {
44 public: 52 public:
45 static PassRefPtr<UserGestureToken> create() { return adoptRef(new GestureTo ken); } 53 static PassRefPtr<UserGestureToken> create() { return adoptRef(new GestureTo ken); }
46 54
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 s_topmostIndicator = this; 159 s_topmostIndicator = this;
152 m_token = token; 160 m_token = token;
153 } else { 161 } else {
154 m_token = s_topmostIndicator->currentToken(); 162 m_token = s_topmostIndicator->currentToken();
155 if (static_cast<GestureToken*>(token.get())->hasGestures()) { 163 if (static_cast<GestureToken*>(token.get())->hasGestures()) {
156 static_cast<GestureToken*>(m_token.get())->addGesture(); 164 static_cast<GestureToken*>(m_token.get())->addGesture();
157 static_cast<GestureToken*>(token.get())->consumeGesture(); 165 static_cast<GestureToken*>(token.get())->consumeGesture();
158 } 166 }
159 } 167 }
160 s_state = DefinitelyProcessingUserGesture; 168 s_state = DefinitelyProcessingUserGesture;
169
170 while (handlers().size() > 0) {
171 handlers().last()->onGesture();
172 handlers().removeLast();
173 }
161 } 174 }
162 175
163 ASSERT(isDefinite(s_state)); 176 ASSERT(isDefinite(s_state));
164 } 177 }
165 178
166 UserGestureIndicator::~UserGestureIndicator() 179 UserGestureIndicator::~UserGestureIndicator()
167 { 180 {
168 if (!isMainThread()) 181 if (!isMainThread())
169 return; 182 return;
170 s_state = m_previousState; 183 s_state = m_previousState;
(...skipping 16 matching lines...) Expand all
187 return static_cast<GestureToken*>(s_topmostIndicator->currentToken())->consu meGesture(); 200 return static_cast<GestureToken*>(s_topmostIndicator->currentToken())->consu meGesture();
188 } 201 }
189 202
190 UserGestureToken* UserGestureIndicator::currentToken() 203 UserGestureToken* UserGestureIndicator::currentToken()
191 { 204 {
192 if (!isMainThread() || !s_topmostIndicator) 205 if (!isMainThread() || !s_topmostIndicator)
193 return 0; 206 return 0;
194 return s_topmostIndicator->m_token.get(); 207 return s_topmostIndicator->m_token.get();
195 } 208 }
196 209
210 void UserGestureIndicator::addHandler(PassRefPtr<UserGestureHandler> handler)
211 {
212 handlers().append(handler);
213 }
214
197 UserGestureIndicatorDisabler::UserGestureIndicatorDisabler() 215 UserGestureIndicatorDisabler::UserGestureIndicatorDisabler()
198 : m_savedState(UserGestureIndicator::s_state) 216 : m_savedState(UserGestureIndicator::s_state)
199 , m_savedIndicator(UserGestureIndicator::s_topmostIndicator) 217 , m_savedIndicator(UserGestureIndicator::s_topmostIndicator)
200 { 218 {
201 RELEASE_ASSERT(isMainThread()); 219 RELEASE_ASSERT(isMainThread());
202 UserGestureIndicator::s_state = DefinitelyNotProcessingUserGesture; 220 UserGestureIndicator::s_state = DefinitelyNotProcessingUserGesture;
203 UserGestureIndicator::s_topmostIndicator = 0; 221 UserGestureIndicator::s_topmostIndicator = 0;
204 } 222 }
205 223
206 UserGestureIndicatorDisabler::~UserGestureIndicatorDisabler() 224 UserGestureIndicatorDisabler::~UserGestureIndicatorDisabler()
207 { 225 {
208 RELEASE_ASSERT(isMainThread()); 226 RELEASE_ASSERT(isMainThread());
209 UserGestureIndicator::s_state = m_savedState; 227 UserGestureIndicator::s_state = m_savedState;
210 UserGestureIndicator::s_topmostIndicator = m_savedIndicator; 228 UserGestureIndicator::s_topmostIndicator = m_savedIndicator;
211 } 229 }
212 230
213 } 231 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698