| 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 { | 52 { |
| 53 } | 53 } |
| 54 | 54 |
| 55 size_t m_consumableGestures; | 55 size_t m_consumableGestures; |
| 56 }; | 56 }; |
| 57 | 57 |
| 58 } | 58 } |
| 59 | 59 |
| 60 static bool isDefinite(ProcessingUserGestureState state) | 60 static bool isDefinite(ProcessingUserGestureState state) |
| 61 { | 61 { |
| 62 return state == DefinitelyProcessingNewUserGesture || state == DefinitelyNot
ProcessingUserGesture; | 62 return state == DefinitelyProcessingNewUserGesture || state == DefinitelyPro
cessingUserGesture || state == DefinitelyNotProcessingUserGesture; |
| 63 } | 63 } |
| 64 | 64 |
| 65 ProcessingUserGestureState UserGestureIndicator::s_state = DefinitelyNotProcessi
ngUserGesture; | 65 ProcessingUserGestureState UserGestureIndicator::s_state = DefinitelyNotProcessi
ngUserGesture; |
| 66 UserGestureIndicator* UserGestureIndicator::s_topmostIndicator = 0; | 66 UserGestureIndicator* UserGestureIndicator::s_topmostIndicator = 0; |
| 67 | 67 |
| 68 UserGestureIndicator::UserGestureIndicator(ProcessingUserGestureState state) | 68 UserGestureIndicator::UserGestureIndicator(ProcessingUserGestureState state) |
| 69 : m_previousState(s_state) | 69 : m_previousState(s_state) |
| 70 { | 70 { |
| 71 // We overwrite s_state only if the caller is definite about the gesture sta
te. | 71 // We overwrite s_state only if the caller is definite about the gesture sta
te. |
| 72 if (isDefinite(state)) { | 72 if (isDefinite(state)) { |
| 73 if (!s_topmostIndicator) { | 73 if (!s_topmostIndicator) { |
| 74 s_topmostIndicator = this; | 74 s_topmostIndicator = this; |
| 75 m_token = GestureToken::create(); | 75 m_token = GestureToken::create(); |
| 76 } else | 76 } else |
| 77 m_token = s_topmostIndicator->currentToken(); | 77 m_token = s_topmostIndicator->currentToken(); |
| 78 s_state = state; | 78 s_state = state; |
| 79 } | 79 } |
| 80 | 80 |
| 81 if (state == DefinitelyProcessingNewUserGesture) | 81 if (state == DefinitelyProcessingNewUserGesture) |
| 82 static_cast<GestureToken*>(m_token.get())->addGesture(); | 82 static_cast<GestureToken*>(m_token.get())->addGesture(); |
| 83 else if (state == DefinitelyProcessingUserGesture && s_topmostIndicator == t
his) |
| 84 static_cast<GestureToken*>(m_token.get())->addGesture(); |
| 83 ASSERT(isDefinite(s_state)); | 85 ASSERT(isDefinite(s_state)); |
| 84 } | 86 } |
| 85 | 87 |
| 86 UserGestureIndicator::UserGestureIndicator(PassRefPtr<UserGestureIndicator::Toke
n> token) | 88 UserGestureIndicator::UserGestureIndicator(PassRefPtr<UserGestureIndicator::Toke
n> token) |
| 87 : m_previousState(s_state) | 89 : m_previousState(s_state) |
| 88 { | 90 { |
| 89 if (token && static_cast<GestureToken*>(token.get())->hasGestures()) { | 91 if (token && static_cast<GestureToken*>(token.get())->hasGestures()) { |
| 90 if (!s_topmostIndicator) { | 92 if (!s_topmostIndicator) { |
| 91 s_topmostIndicator = this; | 93 s_topmostIndicator = this; |
| 92 m_token = token; | 94 m_token = token; |
| 93 } else { | 95 } else { |
| 94 m_token = s_topmostIndicator->currentToken(); | 96 m_token = s_topmostIndicator->currentToken(); |
| 95 static_cast<GestureToken*>(m_token.get())->addGesture(); | 97 static_cast<GestureToken*>(m_token.get())->addGesture(); |
| 96 static_cast<GestureToken*>(token.get())->consumeGesture(); | 98 static_cast<GestureToken*>(token.get())->consumeGesture(); |
| 97 } | 99 } |
| 98 s_state = DefinitelyProcessingNewUserGesture; | 100 s_state = DefinitelyProcessingUserGesture; |
| 99 } | 101 } |
| 100 | 102 |
| 101 ASSERT(isDefinite(s_state)); | 103 ASSERT(isDefinite(s_state)); |
| 102 } | 104 } |
| 103 | 105 |
| 104 UserGestureIndicator::~UserGestureIndicator() | 106 UserGestureIndicator::~UserGestureIndicator() |
| 105 { | 107 { |
| 106 s_state = m_previousState; | 108 s_state = m_previousState; |
| 107 if (s_topmostIndicator == this) | 109 if (s_topmostIndicator == this) |
| 108 s_topmostIndicator = 0; | 110 s_topmostIndicator = 0; |
| 109 ASSERT(isDefinite(s_state)); | 111 ASSERT(isDefinite(s_state)); |
| 110 } | 112 } |
| 111 | 113 |
| 112 bool UserGestureIndicator::processingUserGesture() | 114 bool UserGestureIndicator::processingUserGesture() |
| 113 { | 115 { |
| 114 return s_topmostIndicator && static_cast<GestureToken*>(s_topmostIndicator->
currentToken())->hasGestures() && s_state == DefinitelyProcessingNewUserGesture; | 116 return s_topmostIndicator && static_cast<GestureToken*>(s_topmostIndicator->
currentToken())->hasGestures() && (s_state == DefinitelyProcessingNewUserGesture
|| s_state == DefinitelyProcessingUserGesture); |
| 115 } | 117 } |
| 116 | 118 |
| 117 bool UserGestureIndicator::consumeUserGesture() | 119 bool UserGestureIndicator::consumeUserGesture() |
| 118 { | 120 { |
| 119 if (!s_topmostIndicator) | 121 if (!s_topmostIndicator) |
| 120 return false; | 122 return false; |
| 121 return static_cast<GestureToken*>(s_topmostIndicator->currentToken())->consu
meGesture(); | 123 return static_cast<GestureToken*>(s_topmostIndicator->currentToken())->consu
meGesture(); |
| 122 } | 124 } |
| 123 | 125 |
| 124 UserGestureIndicator::Token* UserGestureIndicator::currentToken() | 126 UserGestureIndicator::Token* UserGestureIndicator::currentToken() |
| 125 { | 127 { |
| 126 if (!s_topmostIndicator) | 128 if (!s_topmostIndicator) |
| 127 return 0; | 129 return 0; |
| 128 return s_topmostIndicator->m_token.get(); | 130 return s_topmostIndicator->m_token.get(); |
| 129 } | 131 } |
| 130 | 132 |
| 131 } | 133 } |
| OLD | NEW |