| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google 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 are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 , m_detachCount(0) | 66 , m_detachCount(0) |
| 67 { | 67 { |
| 68 } | 68 } |
| 69 | 69 |
| 70 DocumentLifecycle::~DocumentLifecycle() | 70 DocumentLifecycle::~DocumentLifecycle() |
| 71 { | 71 { |
| 72 } | 72 } |
| 73 | 73 |
| 74 #if ENABLE(ASSERT) | 74 #if ENABLE(ASSERT) |
| 75 | 75 |
| 76 bool DocumentLifecycle::canAdvanceTo(State state) const | 76 bool DocumentLifecycle::canAdvanceTo(State nextState) const |
| 77 { | 77 { |
| 78 // We can stop from anywhere. | 78 // We can stop from anywhere. |
| 79 if (state == Stopping) | 79 if (nextState == Stopping) |
| 80 return true; | 80 return true; |
| 81 | 81 |
| 82 switch (m_state) { | 82 switch (m_state) { |
| 83 case Uninitialized: | 83 case Uninitialized: |
| 84 return state == Inactive; | 84 return nextState == Inactive; |
| 85 case Inactive: | 85 case Inactive: |
| 86 if (state == StyleClean) | 86 if (nextState == StyleClean) |
| 87 return true; | 87 return true; |
| 88 if (state == Disposed) | 88 if (nextState == Disposed) |
| 89 return true; | 89 return true; |
| 90 break; | 90 break; |
| 91 case VisualUpdatePending: | 91 case VisualUpdatePending: |
| 92 if (state == InPreLayout) | 92 if (nextState == InPreLayout) |
| 93 return true; | 93 return true; |
| 94 if (state == InStyleRecalc) | 94 if (nextState == InStyleRecalc) |
| 95 return true; | 95 return true; |
| 96 if (state == InPerformLayout) | 96 if (nextState == InPerformLayout) |
| 97 return true; | 97 return true; |
| 98 break; | 98 break; |
| 99 case InStyleRecalc: | 99 case InStyleRecalc: |
| 100 return state == StyleClean; | 100 return nextState == StyleClean; |
| 101 case StyleClean: | 101 case StyleClean: |
| 102 // We can synchronously recalc style. | 102 // We can synchronously recalc style. |
| 103 if (state == InStyleRecalc) | 103 if (nextState == InStyleRecalc) |
| 104 return true; | 104 return true; |
| 105 // We can notify layout objects that subtrees changed. | 105 // We can notify layout objects that subtrees changed. |
| 106 if (state == InLayoutSubtreeChange) | 106 if (nextState == InLayoutSubtreeChange) |
| 107 return true; | 107 return true; |
| 108 // We can synchronously perform layout. | 108 // We can synchronously perform layout. |
| 109 if (state == InPreLayout) | 109 if (nextState == InPreLayout) |
| 110 return true; | 110 return true; |
| 111 if (state == InPerformLayout) | 111 if (nextState == InPerformLayout) |
| 112 return true; | 112 return true; |
| 113 // We can redundant arrive in the style clean state. | 113 // We can redundant arrive in the style clean state. |
| 114 if (state == StyleClean) | 114 if (nextState == StyleClean) |
| 115 return true; | 115 return true; |
| 116 if (state == LayoutClean) | 116 if (nextState == LayoutClean) |
| 117 return true; | 117 return true; |
| 118 if (state == InCompositingUpdate) | 118 if (nextState == InCompositingUpdate) |
| 119 return true; | 119 return true; |
| 120 break; | 120 break; |
| 121 case InLayoutSubtreeChange: | 121 case InLayoutSubtreeChange: |
| 122 return state == LayoutSubtreeChangeClean; | 122 return nextState == LayoutSubtreeChangeClean; |
| 123 case LayoutSubtreeChangeClean: | 123 case LayoutSubtreeChangeClean: |
| 124 // We can synchronously recalc style. | 124 // We can synchronously recalc style. |
| 125 if (state == InStyleRecalc) | 125 if (nextState == InStyleRecalc) |
| 126 return true; | 126 return true; |
| 127 // We can synchronously perform layout. | 127 // We can synchronously perform layout. |
| 128 if (state == InPreLayout) | 128 if (nextState == InPreLayout) |
| 129 return true; | 129 return true; |
| 130 if (state == InPerformLayout) | 130 if (nextState == InPerformLayout) |
| 131 return true; | 131 return true; |
| 132 // Can move back to style clean. | 132 // Can move back to style clean. |
| 133 if (state == StyleClean) | 133 if (nextState == StyleClean) |
| 134 return true; | 134 return true; |
| 135 if (state == LayoutClean) | 135 if (nextState == LayoutClean) |
| 136 return true; | 136 return true; |
| 137 if (state == InCompositingUpdate) | 137 if (nextState == InCompositingUpdate) |
| 138 return true; | 138 return true; |
| 139 break; | 139 break; |
| 140 case InPreLayout: | 140 case InPreLayout: |
| 141 if (state == InStyleRecalc) | 141 if (nextState == InStyleRecalc) |
| 142 return true; | 142 return true; |
| 143 if (state == StyleClean) | 143 if (nextState == StyleClean) |
| 144 return true; | 144 return true; |
| 145 if (state == InPreLayout) | 145 if (nextState == InPreLayout) |
| 146 return true; | 146 return true; |
| 147 break; | 147 break; |
| 148 case InPerformLayout: | 148 case InPerformLayout: |
| 149 return state == AfterPerformLayout; | 149 return nextState == AfterPerformLayout; |
| 150 case AfterPerformLayout: | 150 case AfterPerformLayout: |
| 151 // We can synchronously recompute layout in AfterPerformLayout. | 151 // We can synchronously recompute layout in AfterPerformLayout. |
| 152 // FIXME: Ideally, we would unnest this recursion into a loop. | 152 // FIXME: Ideally, we would unnest this recursion into a loop. |
| 153 if (state == InPreLayout) | 153 if (nextState == InPreLayout) |
| 154 return true; | 154 return true; |
| 155 if (state == LayoutClean) | 155 if (nextState == LayoutClean) |
| 156 return true; | 156 return true; |
| 157 break; | 157 break; |
| 158 case LayoutClean: | 158 case LayoutClean: |
| 159 // We can synchronously recalc style. | 159 // We can synchronously recalc style. |
| 160 if (state == InStyleRecalc) | 160 if (nextState == InStyleRecalc) |
| 161 return true; | 161 return true; |
| 162 // We can synchronously perform layout. | 162 // We can synchronously perform layout. |
| 163 if (state == InPreLayout) | 163 if (nextState == InPreLayout) |
| 164 return true; | 164 return true; |
| 165 if (state == InPerformLayout) | 165 if (nextState == InPerformLayout) |
| 166 return true; | 166 return true; |
| 167 // We can redundant arrive in the layout clean state. This situation | 167 // We can redundant arrive in the layout clean state. This situation |
| 168 // can happen when we call layout recursively and we unwind the stack. | 168 // can happen when we call layout recursively and we unwind the stack. |
| 169 if (state == LayoutClean) | 169 if (nextState == LayoutClean) |
| 170 return true; | 170 return true; |
| 171 if (state == StyleClean) | 171 if (nextState == StyleClean) |
| 172 return true; | 172 return true; |
| 173 if (state == InCompositingUpdate) | 173 if (nextState == InCompositingUpdate) |
| 174 return true; | 174 return true; |
| 175 break; | 175 break; |
| 176 case InCompositingUpdate: | 176 case InCompositingUpdate: |
| 177 return state == CompositingClean; | 177 return nextState == CompositingClean; |
| 178 case CompositingClean: | 178 case CompositingClean: |
| 179 if (state == InStyleRecalc) | 179 if (nextState == InStyleRecalc) |
| 180 return true; | 180 return true; |
| 181 if (state == InPreLayout) | 181 if (nextState == InPreLayout) |
| 182 return true; | 182 return true; |
| 183 if (state == InCompositingUpdate) | 183 if (nextState == InCompositingUpdate) |
| 184 return true; | 184 return true; |
| 185 if (state == InPaintInvalidation) | 185 if (nextState == InPaintInvalidation) |
| 186 return true; | 186 return true; |
| 187 break; | 187 break; |
| 188 case InPaintInvalidation: | 188 case InPaintInvalidation: |
| 189 return state == PaintInvalidationClean; | 189 return nextState == PaintInvalidationClean; |
| 190 case PaintInvalidationClean: | 190 case PaintInvalidationClean: |
| 191 if (state == InStyleRecalc) | 191 if (nextState == InStyleRecalc) |
| 192 return true; | 192 return true; |
| 193 if (state == InPreLayout) | 193 if (nextState == InPreLayout) |
| 194 return true; | 194 return true; |
| 195 if (state == InCompositingUpdate) | 195 if (nextState == InCompositingUpdate) |
| 196 return true; | 196 return true; |
| 197 break; | 197 break; |
| 198 case Stopping: | 198 case Stopping: |
| 199 return state == Stopped; | 199 return nextState == Stopped; |
| 200 case Stopped: | 200 case Stopped: |
| 201 return state == Disposed; | 201 return nextState == Disposed; |
| 202 case Disposed: | 202 case Disposed: |
| 203 // FIXME: We can dispose a document multiple times. This seems wrong. | 203 // FIXME: We can dispose a document multiple times. This seems wrong. |
| 204 // See https://code.google.com/p/chromium/issues/detail?id=301668. | 204 // See https://code.google.com/p/chromium/issues/detail?id=301668. |
| 205 return state == Disposed; | 205 return nextState == Disposed; |
| 206 } | 206 } |
| 207 return false; | 207 return false; |
| 208 } | 208 } |
| 209 | 209 |
| 210 bool DocumentLifecycle::canRewindTo(State state) const | 210 bool DocumentLifecycle::canRewindTo(State nextState) const |
| 211 { | 211 { |
| 212 // This transition is bogus, but we've whitelisted it anyway. | 212 // This transition is bogus, but we've whitelisted it anyway. |
| 213 if (s_deprecatedTransitionStack && m_state == s_deprecatedTransitionStack->f
rom() && state == s_deprecatedTransitionStack->to()) | 213 if (s_deprecatedTransitionStack && m_state == s_deprecatedTransitionStack->f
rom() && nextState == s_deprecatedTransitionStack->to()) |
| 214 return true; | 214 return true; |
| 215 return m_state == StyleClean || m_state == LayoutSubtreeChangeClean || m_sta
te == AfterPerformLayout || m_state == LayoutClean || m_state == CompositingClea
n || m_state == PaintInvalidationClean; | 215 return m_state == StyleClean || m_state == LayoutSubtreeChangeClean || m_sta
te == AfterPerformLayout || m_state == LayoutClean || m_state == CompositingClea
n || m_state == PaintInvalidationClean; |
| 216 } | 216 } |
| 217 | 217 |
| 218 #endif | 218 #endif |
| 219 | 219 |
| 220 void DocumentLifecycle::advanceTo(State state) | 220 void DocumentLifecycle::advanceTo(State nextState) |
| 221 { | 221 { |
| 222 ASSERT(canAdvanceTo(state)); | 222 ASSERT(canAdvanceTo(nextState)); |
| 223 m_state = state; | 223 m_state = nextState; |
| 224 } | 224 } |
| 225 | 225 |
| 226 void DocumentLifecycle::ensureStateAtMost(State state) | 226 void DocumentLifecycle::ensureStateAtMost(State state) |
| 227 { | 227 { |
| 228 ASSERT(state == VisualUpdatePending || state == StyleClean || state == Layou
tClean); | 228 ASSERT(state == VisualUpdatePending || state == StyleClean || state == Layou
tClean); |
| 229 if (m_state <= state) | 229 if (m_state <= state) |
| 230 return; | 230 return; |
| 231 ASSERT(canRewindTo(state)); | 231 ASSERT(canRewindTo(state)); |
| 232 m_state = state; | 232 m_state = state; |
| 233 } | 233 } |
| 234 | 234 |
| 235 } | 235 } |
| OLD | NEW |