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

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: Fixed unit test bug Created 7 years 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
« no previous file with comments | « Source/platform/UserGestureIndicator.h ('k') | Source/web/WebUserGestureIndicator.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
37 // User gestures timeout in 1 second. 38 // User gestures timeout in 1 second.
38 const double userGestureTimeout = 1.0; 39 const double userGestureTimeout = 1.0;
39 40
40 // For out of process tokens we allow a 10 second delay. 41 // For out of process tokens we allow a 10 second delay.
41 const double userGestureOutOfProcessTimeout = 10.0; 42 const double userGestureOutOfProcessTimeout = 10.0;
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 106
106 } 107 }
107 108
108 static bool isDefinite(ProcessingUserGestureState state) 109 static bool isDefinite(ProcessingUserGestureState state)
109 { 110 {
110 return state == DefinitelyProcessingNewUserGesture || state == DefinitelyPro cessingUserGesture || state == DefinitelyNotProcessingUserGesture; 111 return state == DefinitelyProcessingNewUserGesture || state == DefinitelyPro cessingUserGesture || state == DefinitelyNotProcessingUserGesture;
111 } 112 }
112 113
113 ProcessingUserGestureState UserGestureIndicator::s_state = DefinitelyNotProcessi ngUserGesture; 114 ProcessingUserGestureState UserGestureIndicator::s_state = DefinitelyNotProcessi ngUserGesture;
114 UserGestureIndicator* UserGestureIndicator::s_topmostIndicator = 0; 115 UserGestureIndicator* UserGestureIndicator::s_topmostIndicator = 0;
116 UserGestureHandler* UserGestureIndicator::s_handler = 0;
115 117
116 UserGestureIndicator::UserGestureIndicator(ProcessingUserGestureState state) 118 UserGestureIndicator::UserGestureIndicator(ProcessingUserGestureState state)
117 : m_previousState(s_state) 119 : m_previousState(s_state)
118 { 120 {
119 // Silently ignore UserGestureIndicators on non-main threads. 121 // Silently ignore UserGestureIndicators on non-main threads.
120 if (!isMainThread()) 122 if (!isMainThread())
121 return; 123 return;
122 124
123 // We overwrite s_state only if the caller is definite about the gesture sta te. 125 // We overwrite s_state only if the caller is definite about the gesture sta te.
124 if (isDefinite(state)) { 126 if (isDefinite(state)) {
125 if (!s_topmostIndicator) { 127 if (!s_topmostIndicator) {
126 s_topmostIndicator = this; 128 s_topmostIndicator = this;
127 m_token = GestureToken::create(); 129 m_token = GestureToken::create();
128 } else { 130 } else {
129 m_token = s_topmostIndicator->currentToken(); 131 m_token = s_topmostIndicator->currentToken();
130 } 132 }
131 s_state = state; 133 s_state = state;
132 } 134 }
133 135
134 if (state == DefinitelyProcessingNewUserGesture) 136 bool shouldNotifyHandler = false;
137 if (state == DefinitelyProcessingNewUserGesture) {
135 static_cast<GestureToken*>(m_token.get())->addGesture(); 138 static_cast<GestureToken*>(m_token.get())->addGesture();
136 else if (state == DefinitelyProcessingUserGesture && s_topmostIndicator == t his) 139 shouldNotifyHandler = true;
140 } else if (state == DefinitelyProcessingUserGesture && s_topmostIndicator == this) {
137 static_cast<GestureToken*>(m_token.get())->addGesture(); 141 static_cast<GestureToken*>(m_token.get())->addGesture();
142 shouldNotifyHandler = true;
143 }
144
145 if (shouldNotifyHandler && s_handler)
146 s_handler->onGesture();
138 ASSERT(isDefinite(s_state)); 147 ASSERT(isDefinite(s_state));
139 } 148 }
140 149
141 UserGestureIndicator::UserGestureIndicator(PassRefPtr<UserGestureToken> token) 150 UserGestureIndicator::UserGestureIndicator(PassRefPtr<UserGestureToken> token)
142 : m_previousState(s_state) 151 : m_previousState(s_state)
143 { 152 {
144 // Silently ignore UserGestureIndicators on non-main threads. 153 // Silently ignore UserGestureIndicators on non-main threads.
145 if (!isMainThread()) 154 if (!isMainThread())
146 return; 155 return;
147 156
148 if (token) { 157 if (token) {
149 static_cast<GestureToken*>(token.get())->resetTimestamp(); 158 static_cast<GestureToken*>(token.get())->resetTimestamp();
150 if (!s_topmostIndicator) { 159 if (!s_topmostIndicator) {
151 s_topmostIndicator = this; 160 s_topmostIndicator = this;
152 m_token = token; 161 m_token = token;
153 } else { 162 } else {
154 m_token = s_topmostIndicator->currentToken(); 163 m_token = s_topmostIndicator->currentToken();
155 if (static_cast<GestureToken*>(token.get())->hasGestures()) { 164 if (static_cast<GestureToken*>(token.get())->hasGestures()) {
156 static_cast<GestureToken*>(m_token.get())->addGesture(); 165 static_cast<GestureToken*>(m_token.get())->addGesture();
157 static_cast<GestureToken*>(token.get())->consumeGesture(); 166 static_cast<GestureToken*>(token.get())->consumeGesture();
158 } 167 }
159 } 168 }
160 s_state = DefinitelyProcessingUserGesture; 169 s_state = DefinitelyProcessingUserGesture;
170
171 if (s_handler)
172 s_handler->onGesture();
161 } 173 }
162 174
163 ASSERT(isDefinite(s_state)); 175 ASSERT(isDefinite(s_state));
164 } 176 }
165 177
166 UserGestureIndicator::~UserGestureIndicator() 178 UserGestureIndicator::~UserGestureIndicator()
167 { 179 {
168 if (!isMainThread()) 180 if (!isMainThread())
169 return; 181 return;
170 s_state = m_previousState; 182 s_state = m_previousState;
(...skipping 16 matching lines...) Expand all
187 return static_cast<GestureToken*>(s_topmostIndicator->currentToken())->consu meGesture(); 199 return static_cast<GestureToken*>(s_topmostIndicator->currentToken())->consu meGesture();
188 } 200 }
189 201
190 UserGestureToken* UserGestureIndicator::currentToken() 202 UserGestureToken* UserGestureIndicator::currentToken()
191 { 203 {
192 if (!isMainThread() || !s_topmostIndicator) 204 if (!isMainThread() || !s_topmostIndicator)
193 return 0; 205 return 0;
194 return s_topmostIndicator->m_token.get(); 206 return s_topmostIndicator->m_token.get();
195 } 207 }
196 208
209 void UserGestureIndicator::setHandler(UserGestureHandler* handler)
210 {
211 s_handler = handler;
212 }
213
197 UserGestureIndicatorDisabler::UserGestureIndicatorDisabler() 214 UserGestureIndicatorDisabler::UserGestureIndicatorDisabler()
198 : m_savedState(UserGestureIndicator::s_state) 215 : m_savedState(UserGestureIndicator::s_state)
199 , m_savedIndicator(UserGestureIndicator::s_topmostIndicator) 216 , m_savedIndicator(UserGestureIndicator::s_topmostIndicator)
200 { 217 {
201 RELEASE_ASSERT(isMainThread()); 218 RELEASE_ASSERT(isMainThread());
202 UserGestureIndicator::s_state = DefinitelyNotProcessingUserGesture; 219 UserGestureIndicator::s_state = DefinitelyNotProcessingUserGesture;
203 UserGestureIndicator::s_topmostIndicator = 0; 220 UserGestureIndicator::s_topmostIndicator = 0;
204 } 221 }
205 222
206 UserGestureIndicatorDisabler::~UserGestureIndicatorDisabler() 223 UserGestureIndicatorDisabler::~UserGestureIndicatorDisabler()
207 { 224 {
208 RELEASE_ASSERT(isMainThread()); 225 RELEASE_ASSERT(isMainThread());
209 UserGestureIndicator::s_state = m_savedState; 226 UserGestureIndicator::s_state = m_savedState;
210 UserGestureIndicator::s_topmostIndicator = m_savedIndicator; 227 UserGestureIndicator::s_topmostIndicator = m_savedIndicator;
211 } 228 }
212 229
213 } 230 }
OLDNEW
« no previous file with comments | « Source/platform/UserGestureIndicator.h ('k') | Source/web/WebUserGestureIndicator.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698