2
* Copyright (C) 2010 Google, Inc. All Rights Reserved.
3
* Copyright (C) 2011 Apple Inc. All rights reserved.
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions
8
* 1. Redistributions of source code must retain the above copyright
9
* notice, this list of conditions and the following disclaimer.
10
* 2. Redistributions in binary form must reproduce the above copyright
11
* notice, this list of conditions and the following disclaimer in the
12
* documentation and/or other materials provided with the distribution.
14
* THIS SOFTWARE IS PROVIDED BY GOOGLE INC. ``AS IS'' AND ANY
15
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GOOGLE INC. OR
18
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
#ifndef HTMLElementStack_h
28
#define HTMLElementStack_h
30
#include "HTMLNames.h"
31
#include "HTMLStackItem.h"
32
#include <wtf/Forward.h>
33
#include <wtf/Noncopyable.h>
34
#include <wtf/OwnPtr.h>
35
#include <wtf/PassOwnPtr.h>
36
#include <wtf/RefPtr.h>
41
class DocumentFragment;
45
// NOTE: The HTML5 spec uses a backwards (grows downward) stack. We're using
46
// more standard (grows upwards) stack terminology here.
47
class HTMLElementStack {
48
WTF_MAKE_NONCOPYABLE(HTMLElementStack); WTF_MAKE_FAST_ALLOCATED;
54
WTF_MAKE_NONCOPYABLE(ElementRecord); WTF_MAKE_FAST_ALLOCATED;
56
~ElementRecord(); // Public for ~PassOwnPtr()
58
Element* element() const { return m_item->element(); }
59
ContainerNode* node() const { return m_item->node(); }
60
PassRefPtr<HTMLStackItem> stackItem() const { return m_item; }
61
void replaceElement(PassRefPtr<HTMLStackItem>);
63
bool isAbove(ElementRecord*) const;
65
ElementRecord* next() const { return m_next.get(); }
67
friend class HTMLElementStack;
69
ElementRecord(PassRefPtr<HTMLStackItem>, PassOwnPtr<ElementRecord>);
71
PassOwnPtr<ElementRecord> releaseNext() { return m_next.release(); }
72
void setNext(PassOwnPtr<ElementRecord> next) { m_next = next; }
74
RefPtr<HTMLStackItem> m_item;
75
OwnPtr<ElementRecord> m_next;
78
unsigned stackDepth() const { return m_stackDepth; }
80
// Inlining this function is a (small) performance win on the parsing
84
ASSERT(m_top->element());
85
return m_top->element();
88
ContainerNode* topNode() const
90
ASSERT(m_top->node());
94
HTMLStackItem* topStackItem() const
96
ASSERT(m_top->stackItem());
97
return m_top->stackItem().get();
100
HTMLStackItem* oneBelowTop() const;
101
ElementRecord* topRecord() const;
102
ElementRecord* find(Element*) const;
103
ElementRecord* furthestBlockForFormattingElement(Element*) const;
104
ElementRecord* topmost(const AtomicString& tagName) const;
106
void insertAbove(PassRefPtr<HTMLStackItem>, ElementRecord*);
108
void push(PassRefPtr<HTMLStackItem>);
109
void pushRootNode(PassRefPtr<HTMLStackItem>);
110
void pushHTMLHtmlElement(PassRefPtr<HTMLStackItem>);
111
void pushHTMLHeadElement(PassRefPtr<HTMLStackItem>);
112
void pushHTMLBodyElement(PassRefPtr<HTMLStackItem>);
115
void popUntil(const AtomicString& tagName);
116
void popUntil(Element*);
117
void popUntilPopped(const AtomicString& tagName);
118
void popUntilPopped(Element*);
119
void popUntilNumberedHeaderElementPopped();
120
void popUntilTableScopeMarker(); // "clear the stack back to a table context" in the spec.
121
void popUntilTableBodyScopeMarker(); // "clear the stack back to a table body context" in the spec.
122
void popUntilTableRowScopeMarker(); // "clear the stack back to a table row context" in the spec.
123
void popUntilForeignContentScopeMarker();
124
void popHTMLHeadElement();
125
void popHTMLBodyElement();
128
static bool isMathMLTextIntegrationPoint(HTMLStackItem*);
129
static bool isHTMLIntegrationPoint(HTMLStackItem*);
131
void remove(Element*);
132
void removeHTMLHeadElement(Element*);
134
bool contains(Element*) const;
135
bool contains(const AtomicString& tagName) const;
137
bool inScope(Element*) const;
138
bool inScope(const AtomicString& tagName) const;
139
bool inScope(const QualifiedName&) const;
140
bool inListItemScope(const AtomicString& tagName) const;
141
bool inListItemScope(const QualifiedName&) const;
142
bool inTableScope(const AtomicString& tagName) const;
143
bool inTableScope(const QualifiedName&) const;
144
bool inButtonScope(const AtomicString& tagName) const;
145
bool inButtonScope(const QualifiedName&) const;
146
bool inSelectScope(const AtomicString& tagName) const;
147
bool inSelectScope(const QualifiedName&) const;
149
bool hasNumberedHeaderElementInScope() const;
151
bool hasOnlyOneElement() const;
152
bool secondElementIsHTMLBodyElement() const;
154
Element* htmlElement() const;
155
Element* headElement() const;
156
Element* bodyElement() const;
158
ContainerNode* rootNode() const;
165
void pushCommon(PassRefPtr<HTMLStackItem>);
166
void pushRootNodeCommon(PassRefPtr<HTMLStackItem>);
168
void removeNonTopCommon(Element*);
170
OwnPtr<ElementRecord> m_top;
172
// We remember the root node, <head> and <body> as they are pushed. Their
173
// ElementRecords keep them alive. The root node is never popped.
174
// FIXME: We don't currently require type-specific information about
175
// these elements so we haven't yet bothered to plumb the types all the
176
// way down through createElement, etc.
177
ContainerNode* m_rootNode;
178
Element* m_headElement;
179
Element* m_bodyElement;
180
unsigned m_stackDepth;
183
} // namespace WebCore
185
#endif // HTMLElementStack_h