| 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 24 matching lines...) Expand all Loading... |
| 35 const double userGestureTimeout = 1.0; | 35 const double userGestureTimeout = 1.0; |
| 36 | 36 |
| 37 // For out of process tokens we allow a 10 second delay. | 37 // For out of process tokens we allow a 10 second delay. |
| 38 const double userGestureOutOfProcessTimeout = 10.0; | 38 const double userGestureOutOfProcessTimeout = 10.0; |
| 39 | 39 |
| 40 UserGestureToken::UserGestureToken(Status status) | 40 UserGestureToken::UserGestureToken(Status status) |
| 41 : m_consumableGestures(0), | 41 : m_consumableGestures(0), |
| 42 m_timestamp(WTF::currentTime()), | 42 m_timestamp(WTF::currentTime()), |
| 43 m_timeoutPolicy(Default), | 43 m_timeoutPolicy(Default), |
| 44 m_usageCallback(nullptr) { | 44 m_usageCallback(nullptr) { |
| 45 if (status == NewGesture || !UserGestureIndicator::currentToken()) | 45 if (status == NewGesture || !UserGestureIndicator::currentTokenThreadSafe()) |
| 46 m_consumableGestures++; | 46 m_consumableGestures++; |
| 47 } | 47 } |
| 48 | 48 |
| 49 bool UserGestureToken::hasGestures() const { | 49 bool UserGestureToken::hasGestures() const { |
| 50 return m_consumableGestures && !hasTimedOut(); | 50 return m_consumableGestures && !hasTimedOut(); |
| 51 } | 51 } |
| 52 | 52 |
| 53 void UserGestureToken::transferGestureTo(UserGestureToken* other) { | 53 void UserGestureToken::transferGestureTo(UserGestureToken* other) { |
| 54 if (!hasGestures()) | 54 if (!hasGestures()) |
| 55 return; | 55 return; |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 // static | 144 // static |
| 145 bool UserGestureIndicator::utilizeUserGesture() { | 145 bool UserGestureIndicator::utilizeUserGesture() { |
| 146 if (UserGestureIndicator::processingUserGesture()) { | 146 if (UserGestureIndicator::processingUserGesture()) { |
| 147 s_rootToken->userGestureUtilized(); | 147 s_rootToken->userGestureUtilized(); |
| 148 return true; | 148 return true; |
| 149 } | 149 } |
| 150 return false; | 150 return false; |
| 151 } | 151 } |
| 152 | 152 |
| 153 bool UserGestureIndicator::processingUserGesture() { | 153 bool UserGestureIndicator::processingUserGesture() { |
| 154 if (auto* token = currentToken()) { | 154 if (auto* token = currentToken()) |
| 155 ASSERT(isMainThread()); | |
| 156 return token->hasGestures(); | 155 return token->hasGestures(); |
| 157 } | 156 return false; |
| 157 } |
| 158 | 158 |
| 159 return false; | 159 bool UserGestureIndicator::processingUserGestureThreadSafe() { |
| 160 return isMainThread() && processingUserGesture(); |
| 160 } | 161 } |
| 161 | 162 |
| 162 // static | 163 // static |
| 163 bool UserGestureIndicator::consumeUserGesture() { | 164 bool UserGestureIndicator::consumeUserGesture() { |
| 164 if (auto* token = currentToken()) { | 165 if (auto* token = currentToken()) { |
| 165 ASSERT(isMainThread()); | |
| 166 if (token->consumeGesture()) { | 166 if (token->consumeGesture()) { |
| 167 token->userGestureUtilized(); | 167 token->userGestureUtilized(); |
| 168 return true; | 168 return true; |
| 169 } | 169 } |
| 170 } | 170 } |
| 171 return false; | 171 return false; |
| 172 } | 172 } |
| 173 | 173 |
| 174 // static | 174 bool UserGestureIndicator::consumeUserGestureThreadSafe() { |
| 175 return isMainThread() && consumeUserGesture(); |
| 176 } |
| 177 |
| 175 UserGestureToken* UserGestureIndicator::currentToken() { | 178 UserGestureToken* UserGestureIndicator::currentToken() { |
| 176 if (!isMainThread() || !s_rootToken) | 179 DCHECK(isMainThread()); |
| 177 return nullptr; | |
| 178 return s_rootToken; | 180 return s_rootToken; |
| 179 } | 181 } |
| 180 | 182 |
| 183 UserGestureToken* UserGestureIndicator::currentTokenThreadSafe() { |
| 184 return isMainThread() ? currentToken() : nullptr; |
| 185 } |
| 186 |
| 181 } // namespace blink | 187 } // namespace blink |
| OLD | NEW |