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 == DefinitelyProcessingUserGesture || state == DefinitelyNotPro
cessingUserGesture; | 62 return state == DefinitelyProcessingNewUserGesture || state == DefinitelyNot
ProcessingUserGesture; |
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 == DefinitelyProcessingUserGesture) | 81 if (state == DefinitelyProcessingNewUserGesture) |
82 static_cast<GestureToken*>(m_token.get())->addGesture(); | 82 static_cast<GestureToken*>(m_token.get())->addGesture(); |
83 ASSERT(isDefinite(s_state)); | 83 ASSERT(isDefinite(s_state)); |
84 } | 84 } |
85 | 85 |
86 UserGestureIndicator::UserGestureIndicator(PassRefPtr<UserGestureIndicator::Toke
n> token) | 86 UserGestureIndicator::UserGestureIndicator(PassRefPtr<UserGestureIndicator::Toke
n> token) |
87 : m_previousState(s_state) | 87 : m_previousState(s_state) |
88 { | 88 { |
89 if (token && static_cast<GestureToken*>(token.get())->hasGestures()) { | 89 if (token && static_cast<GestureToken*>(token.get())->hasGestures()) { |
90 if (!s_topmostIndicator) { | 90 if (!s_topmostIndicator) { |
91 s_topmostIndicator = this; | 91 s_topmostIndicator = this; |
92 m_token = token; | 92 m_token = token; |
93 } else { | 93 } else { |
94 m_token = s_topmostIndicator->currentToken(); | 94 m_token = s_topmostIndicator->currentToken(); |
95 static_cast<GestureToken*>(m_token.get())->addGesture(); | 95 static_cast<GestureToken*>(m_token.get())->addGesture(); |
96 static_cast<GestureToken*>(token.get())->consumeGesture(); | 96 static_cast<GestureToken*>(token.get())->consumeGesture(); |
97 } | 97 } |
98 s_state = DefinitelyProcessingUserGesture; | 98 s_state = DefinitelyProcessingNewUserGesture; |
99 } | 99 } |
100 | 100 |
101 ASSERT(isDefinite(s_state)); | 101 ASSERT(isDefinite(s_state)); |
102 } | 102 } |
103 | 103 |
104 UserGestureIndicator::~UserGestureIndicator() | 104 UserGestureIndicator::~UserGestureIndicator() |
105 { | 105 { |
106 s_state = m_previousState; | 106 s_state = m_previousState; |
107 if (s_topmostIndicator == this) | 107 if (s_topmostIndicator == this) |
108 s_topmostIndicator = 0; | 108 s_topmostIndicator = 0; |
109 ASSERT(isDefinite(s_state)); | 109 ASSERT(isDefinite(s_state)); |
110 } | 110 } |
111 | 111 |
112 bool UserGestureIndicator::processingUserGesture() | 112 bool UserGestureIndicator::processingUserGesture() |
113 { | 113 { |
114 return s_topmostIndicator && static_cast<GestureToken*>(s_topmostIndicator->
currentToken())->hasGestures() && s_state == DefinitelyProcessingUserGesture; | 114 return s_topmostIndicator && static_cast<GestureToken*>(s_topmostIndicator->
currentToken())->hasGestures() && s_state == DefinitelyProcessingNewUserGesture; |
115 } | 115 } |
116 | 116 |
117 bool UserGestureIndicator::consumeUserGesture() | 117 bool UserGestureIndicator::consumeUserGesture() |
118 { | 118 { |
119 if (!s_topmostIndicator) | 119 if (!s_topmostIndicator) |
120 return false; | 120 return false; |
121 return static_cast<GestureToken*>(s_topmostIndicator->currentToken())->consu
meGesture(); | 121 return static_cast<GestureToken*>(s_topmostIndicator->currentToken())->consu
meGesture(); |
122 } | 122 } |
123 | 123 |
124 UserGestureIndicator::Token* UserGestureIndicator::currentToken() | 124 UserGestureIndicator::Token* UserGestureIndicator::currentToken() |
125 { | 125 { |
126 if (!s_topmostIndicator) | 126 if (!s_topmostIndicator) |
127 return 0; | 127 return 0; |
128 return s_topmostIndicator->m_token.get(); | 128 return s_topmostIndicator->m_token.get(); |
129 } | 129 } |
130 | 130 |
131 } | 131 } |
OLD | NEW |