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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
105 | 105 |
106 } | 106 } |
107 | 107 |
108 static bool isDefinite(ProcessingUserGestureState state) | 108 static bool isDefinite(ProcessingUserGestureState state) |
109 { | 109 { |
110 return state == DefinitelyProcessingNewUserGesture || state == DefinitelyPro cessingUserGesture || state == DefinitelyNotProcessingUserGesture; | 110 return state == DefinitelyProcessingNewUserGesture || state == DefinitelyPro cessingUserGesture || state == DefinitelyNotProcessingUserGesture; |
111 } | 111 } |
112 | 112 |
113 ProcessingUserGestureState UserGestureIndicator::s_state = DefinitelyNotProcessi ngUserGesture; | 113 ProcessingUserGestureState UserGestureIndicator::s_state = DefinitelyNotProcessi ngUserGesture; |
114 UserGestureIndicator* UserGestureIndicator::s_topmostIndicator = 0; | 114 UserGestureIndicator* UserGestureIndicator::s_topmostIndicator = 0; |
115 bool UserGestureIndicator::s_processedUserGestureInPast = false; | |
115 | 116 |
116 UserGestureIndicator::UserGestureIndicator(ProcessingUserGestureState state) | 117 UserGestureIndicator::UserGestureIndicator(ProcessingUserGestureState state) |
117 : m_previousState(s_state) | 118 : m_previousState(s_state) |
118 { | 119 { |
119 // Silently ignore UserGestureIndicators on non-main threads. | 120 // Silently ignore UserGestureIndicators on non-main threads. |
120 if (!isMainThread()) | 121 if (!isMainThread()) |
121 return; | 122 return; |
122 | 123 |
123 // We overwrite s_state only if the caller is definite about the gesture sta te. | 124 // We overwrite s_state only if the caller is definite about the gesture sta te. |
124 if (isDefinite(state)) { | 125 if (isDefinite(state)) { |
125 if (!s_topmostIndicator) { | 126 if (!s_topmostIndicator) { |
126 s_topmostIndicator = this; | 127 s_topmostIndicator = this; |
127 m_token = GestureToken::create(); | 128 m_token = GestureToken::create(); |
128 } else { | 129 } else { |
129 m_token = s_topmostIndicator->currentToken(); | 130 m_token = s_topmostIndicator->currentToken(); |
130 } | 131 } |
131 s_state = state; | 132 s_state = state; |
133 if (state == DefinitelyProcessingNewUserGesture || state == DefinitelyPr ocessingUserGesture) | |
134 s_processedUserGestureInPast = true; | |
jochen (gone - plz use gerrit)
2014/04/16 14:05:16
i think you only want to do this when we actually
vabr (Chromium)
2014/04/16 16:24:16
Done.
| |
132 } | 135 } |
133 | 136 |
134 if (state == DefinitelyProcessingNewUserGesture) | 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 else if (state == DefinitelyProcessingUserGesture && s_topmostIndicator == t his) |
137 static_cast<GestureToken*>(m_token.get())->addGesture(); | 140 static_cast<GestureToken*>(m_token.get())->addGesture(); |
138 ASSERT(isDefinite(s_state)); | 141 ASSERT(isDefinite(s_state)); |
139 } | 142 } |
140 | 143 |
141 UserGestureIndicator::UserGestureIndicator(PassRefPtr<UserGestureToken> token) | 144 UserGestureIndicator::UserGestureIndicator(PassRefPtr<UserGestureToken> token) |
142 : m_previousState(s_state) | 145 : m_previousState(s_state) |
143 { | 146 { |
144 // Silently ignore UserGestureIndicators on non-main threads. | 147 // Silently ignore UserGestureIndicators on non-main threads. |
145 if (!isMainThread()) | 148 if (!isMainThread()) |
146 return; | 149 return; |
147 | 150 |
148 if (token) { | 151 if (token) { |
149 static_cast<GestureToken*>(token.get())->resetTimestamp(); | 152 static_cast<GestureToken*>(token.get())->resetTimestamp(); |
150 if (!s_topmostIndicator) { | 153 if (!s_topmostIndicator) { |
151 s_topmostIndicator = this; | 154 s_topmostIndicator = this; |
152 m_token = token; | 155 m_token = token; |
153 } else { | 156 } else { |
154 m_token = s_topmostIndicator->currentToken(); | 157 m_token = s_topmostIndicator->currentToken(); |
155 if (static_cast<GestureToken*>(token.get())->hasGestures()) { | 158 if (static_cast<GestureToken*>(token.get())->hasGestures()) { |
156 static_cast<GestureToken*>(m_token.get())->addGesture(); | 159 static_cast<GestureToken*>(m_token.get())->addGesture(); |
157 static_cast<GestureToken*>(token.get())->consumeGesture(); | 160 static_cast<GestureToken*>(token.get())->consumeGesture(); |
158 } | 161 } |
159 } | 162 } |
160 s_state = DefinitelyProcessingUserGesture; | 163 s_state = DefinitelyProcessingUserGesture; |
164 s_processedUserGestureInPast = true; | |
161 } | 165 } |
162 | 166 |
163 ASSERT(isDefinite(s_state)); | 167 ASSERT(isDefinite(s_state)); |
164 } | 168 } |
165 | 169 |
166 UserGestureIndicator::~UserGestureIndicator() | 170 UserGestureIndicator::~UserGestureIndicator() |
167 { | 171 { |
168 if (!isMainThread()) | 172 if (!isMainThread()) |
169 return; | 173 return; |
170 s_state = m_previousState; | 174 s_state = m_previousState; |
(...skipping 16 matching lines...) Expand all Loading... | |
187 return static_cast<GestureToken*>(s_topmostIndicator->currentToken())->consu meGesture(); | 191 return static_cast<GestureToken*>(s_topmostIndicator->currentToken())->consu meGesture(); |
188 } | 192 } |
189 | 193 |
190 UserGestureToken* UserGestureIndicator::currentToken() | 194 UserGestureToken* UserGestureIndicator::currentToken() |
191 { | 195 { |
192 if (!isMainThread() || !s_topmostIndicator) | 196 if (!isMainThread() || !s_topmostIndicator) |
193 return 0; | 197 return 0; |
194 return s_topmostIndicator->m_token.get(); | 198 return s_topmostIndicator->m_token.get(); |
195 } | 199 } |
196 | 200 |
201 void UserGestureIndicator::clearProcessedUserGestureInPast() | |
202 { | |
203 if (isMainThread()) | |
204 s_processedUserGestureInPast = true; | |
jochen (gone - plz use gerrit)
2014/04/16 14:05:16
false?
vabr (Chromium)
2014/04/16 16:24:16
True! :)
(Thanks for catching this!)
| |
205 } | |
206 | |
207 bool UserGestureIndicator::processedUserGestureInPast() | |
208 { | |
209 if (!isMainThread()) | |
210 return false; | |
211 return s_processedUserGestureInPast; | |
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 } |
OLD | NEW |