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