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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 { | 57 { |
58 m_consumableGestures++; | 58 m_consumableGestures++; |
59 m_timestamp = WTF::currentTime(); | 59 m_timestamp = WTF::currentTime(); |
60 } | 60 } |
61 | 61 |
62 void resetTimestamp() | 62 void resetTimestamp() |
63 { | 63 { |
64 m_timestamp = WTF::currentTime(); | 64 m_timestamp = WTF::currentTime(); |
65 } | 65 } |
66 | 66 |
| 67 void setTimestamp(double timestamp) |
| 68 { |
| 69 m_timestamp = timestamp; |
| 70 } |
| 71 |
67 bool consumeGesture() | 72 bool consumeGesture() |
68 { | 73 { |
69 if (!m_consumableGestures) | 74 if (!m_consumableGestures) |
70 return false; | 75 return false; |
71 m_consumableGestures--; | 76 m_consumableGestures--; |
72 return true; | 77 return true; |
73 } | 78 } |
74 | 79 |
75 virtual void setOutOfProcess() OVERRIDE | 80 virtual void setOutOfProcess() OVERRIDE |
76 { | 81 { |
77 if (WTF::currentTime() - m_timestamp > userGestureTimeout) | 82 if (WTF::currentTime() - m_timestamp > userGestureTimeout) |
78 return; | 83 return; |
79 if (hasGestures()) | 84 if (hasGestures()) |
80 m_outOfProcess = true; | 85 m_outOfProcess = true; |
81 } | 86 } |
82 | 87 |
83 virtual void setJavascriptPrompt() OVERRIDE | 88 virtual void setJavascriptPrompt() OVERRIDE |
84 { | 89 { |
85 if (WTF::currentTime() - m_timestamp > userGestureTimeout) | 90 if (WTF::currentTime() - m_timestamp > userGestureTimeout) |
86 return; | 91 return; |
87 if (hasGestures()) | 92 if (hasGestures()) |
88 m_javascriptPrompt = true; | 93 m_javascriptPrompt = true; |
89 } | 94 } |
90 | 95 |
| 96 virtual double timestamp() const OVERRIDE |
| 97 { |
| 98 return m_timestamp; |
| 99 } |
| 100 |
91 private: | 101 private: |
92 GestureToken() | 102 GestureToken() |
93 : m_consumableGestures(0), | 103 : m_consumableGestures(0), |
94 m_timestamp(0), | 104 m_timestamp(0), |
95 m_outOfProcess(false), | 105 m_outOfProcess(false), |
96 m_javascriptPrompt(false) | 106 m_javascriptPrompt(false) |
97 { | 107 { |
98 } | 108 } |
99 | 109 |
100 size_t m_consumableGestures; | 110 size_t m_consumableGestures; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 static_cast<GestureToken*>(token.get())->consumeGesture(); | 170 static_cast<GestureToken*>(token.get())->consumeGesture(); |
161 } | 171 } |
162 } | 172 } |
163 s_state = DefinitelyProcessingUserGesture; | 173 s_state = DefinitelyProcessingUserGesture; |
164 s_processedUserGestureInPast = true; | 174 s_processedUserGestureInPast = true; |
165 } | 175 } |
166 | 176 |
167 ASSERT(isDefinite(s_state)); | 177 ASSERT(isDefinite(s_state)); |
168 } | 178 } |
169 | 179 |
| 180 UserGestureIndicator::UserGestureIndicator(double timestamp) |
| 181 : m_previousState(s_state) |
| 182 { |
| 183 // Silently ignore UserGestureIndicators on non-main threads. |
| 184 if (!isMainThread()) |
| 185 return; |
| 186 |
| 187 if (!s_topmostIndicator) { |
| 188 s_topmostIndicator = this; |
| 189 m_token = GestureToken::create(); |
| 190 } else { |
| 191 m_token = s_topmostIndicator->currentToken(); |
| 192 } |
| 193 s_state = DefinitelyProcessingUserGesture; |
| 194 |
| 195 static_cast<GestureToken*>(m_token.get())->addGesture(); |
| 196 static_cast<GestureToken*>(m_token.get())->setTimestamp(timestamp); |
| 197 ASSERT(isDefinite(s_state)); |
| 198 } |
| 199 |
170 UserGestureIndicator::~UserGestureIndicator() | 200 UserGestureIndicator::~UserGestureIndicator() |
171 { | 201 { |
172 if (!isMainThread()) | 202 if (!isMainThread()) |
173 return; | 203 return; |
174 s_state = m_previousState; | 204 s_state = m_previousState; |
175 if (s_topmostIndicator == this) | 205 if (s_topmostIndicator == this) |
176 s_topmostIndicator = 0; | 206 s_topmostIndicator = 0; |
177 ASSERT(isDefinite(s_state)); | 207 ASSERT(isDefinite(s_state)); |
178 } | 208 } |
179 | 209 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 } | 251 } |
222 | 252 |
223 UserGestureIndicatorDisabler::~UserGestureIndicatorDisabler() | 253 UserGestureIndicatorDisabler::~UserGestureIndicatorDisabler() |
224 { | 254 { |
225 RELEASE_ASSERT(isMainThread()); | 255 RELEASE_ASSERT(isMainThread()); |
226 UserGestureIndicator::s_state = m_savedState; | 256 UserGestureIndicator::s_state = m_savedState; |
227 UserGestureIndicator::s_topmostIndicator = m_savedIndicator; | 257 UserGestureIndicator::s_topmostIndicator = m_savedIndicator; |
228 } | 258 } |
229 | 259 |
230 } | 260 } |
OLD | NEW |