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.
31 #ifndef DocumentLifecycle_h
32 #define DocumentLifecycle_h
34 #include "wtf/Assertions.h"
35 #include "wtf/Noncopyable.h"
39 class DocumentLifecycle {
40 WTF_MAKE_NONCOPYABLE(DocumentLifecycle);
46 // When the document is active, it traverses these states.
62 PaintInvalidationClean,
64 // Once the document starts shuting down, we cannot return
65 // to the style/layout/rendering states.
72 WTF_MAKE_NONCOPYABLE(Scope);
74 Scope(DocumentLifecycle&, State finalState);
77 void setFinalState(State finalState) { m_finalState = finalState; }
80 DocumentLifecycle& m_lifecycle;
84 class DeprecatedTransition {
85 WTF_MAKE_NONCOPYABLE(DeprecatedTransition);
87 DeprecatedTransition(State from, State to);
88 ~DeprecatedTransition();
90 State from() const { return m_from; }
91 State to() const { return m_to; }
94 DeprecatedTransition* m_previous;
100 WTF_MAKE_NONCOPYABLE(DetachScope);
102 explicit DetachScope(DocumentLifecycle& documentLifecycle)
103 : m_documentLifecycle(documentLifecycle)
105 m_documentLifecycle.incrementDetachCount();
110 m_documentLifecycle.decrementDetachCount();
114 DocumentLifecycle& m_documentLifecycle;
118 ~DocumentLifecycle();
120 bool isActive() const { return m_state > Inactive && m_state < Stopping; }
121 State state() const { return m_state; }
123 bool stateAllowsTreeMutations() const;
124 bool stateAllowsRenderTreeMutations() const;
125 bool stateAllowsDetach() const;
127 void advanceTo(State);
128 void ensureStateAtMost(State);
130 void incrementDetachCount() { m_detachCount++; }
131 void decrementDetachCount()
133 ASSERT(m_detachCount > 0);
139 bool canAdvanceTo(State) const;
140 bool canRewindTo(State) const;
147 inline bool DocumentLifecycle::stateAllowsTreeMutations() const
149 // FIXME: We should not allow mutations in InPreLayout or AfterPerformLayout either,
150 // but we need to fix MediaList listeners and plugins first.
151 return m_state != InStyleRecalc
152 && m_state != InPerformLayout
153 && m_state != InCompositingUpdate;
156 inline bool DocumentLifecycle::stateAllowsRenderTreeMutations() const
158 return m_detachCount || m_state == InStyleRecalc;
161 inline bool DocumentLifecycle::stateAllowsDetach() const
163 return m_state == VisualUpdatePending
164 || m_state == InStyleRecalc
165 || m_state == StyleClean
166 || m_state == InPreLayout
167 || m_state == LayoutClean
168 || m_state == CompositingClean
169 || m_state == PaintInvalidationClean
170 || m_state == Stopping;