2 * Copyright (C) 2013 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include "core/dom/DocumentLifecycle.h"
34 #include "wtf/Assertions.h"
38 static DocumentLifecycle::DeprecatedTransition* s_deprecatedTransitionStack = 0;
40 DocumentLifecycle::Scope::Scope(DocumentLifecycle& lifecycle, State finalState)
41 : m_lifecycle(lifecycle)
42 , m_finalState(finalState)
46 DocumentLifecycle::Scope::~Scope()
48 m_lifecycle.advanceTo(m_finalState);
51 DocumentLifecycle::DeprecatedTransition::DeprecatedTransition(State from, State to)
52 : m_previous(s_deprecatedTransitionStack)
56 s_deprecatedTransitionStack = this;
59 DocumentLifecycle::DeprecatedTransition::~DeprecatedTransition()
61 s_deprecatedTransitionStack = m_previous;
64 DocumentLifecycle::DocumentLifecycle()
65 : m_state(Uninitialized)
69 DocumentLifecycle::~DocumentLifecycle()
75 bool DocumentLifecycle::canAdvanceTo(State state) const
77 // This transition is bogus, but we've whitelisted it anyway.
78 if (s_deprecatedTransitionStack && m_state == s_deprecatedTransitionStack->from() && state == s_deprecatedTransitionStack->to())
82 if (m_state == Disposed) {
83 // FIXME: We can dispose a document multiple times. This seems wrong.
84 // See https://code.google.com/p/chromium/issues/detail?id=301668.
85 return state == Disposed;
87 if (m_state == StyleClean) {
88 if (state == StyleRecalcPending)
90 // We can synchronously recalc style.
91 if (state == InStyleRecalc)
93 // We can synchronously perform layout.
94 if (state == InPreLayout)
96 if (state == InPerformLayout)
98 // We can redundant arrive in the style clean state.
99 if (state == StyleClean)
103 if (m_state == InPreLayout) {
104 if (state == InStyleRecalc)
106 if (state == StyleClean)
108 if (state == InPreLayout)
112 if (m_state == AfterPerformLayout) {
113 if (state == InPreLayout)
115 // If we're doing a partial layout, we won't actually end up cleaning
116 // out all the layout dirty bits. Instead, we'll return to StyleClean.
117 if (state == StyleClean)
121 if (m_state == LayoutClean) {
122 if (state == StyleRecalcPending)
124 // We can synchronously recalc style.
125 if (state == InStyleRecalc)
127 // We can synchronously perform layout.
128 if (state == InPreLayout)
130 if (state == InPerformLayout)
132 // We can redundant arrive in the layout clean state. This situation
133 // can happen when we call layout recursively and we unwind the stack.
134 if (state == LayoutClean)
136 if (state == StyleClean)
140 if (m_state == CompositingClean) {
141 if (state == StyleRecalcPending)
143 if (state == InStyleRecalc)
145 if (state == InPreLayout)
147 if (state == InCompositingUpdate)
156 void DocumentLifecycle::advanceTo(State state)
158 ASSERT(canAdvanceTo(state));