|
1 /* |
|
2 * Copyright (C) 2010 Google, Inc. All Rights Reserved. |
|
3 * |
|
4 * Redistribution and use in source and binary forms, with or without |
|
5 * modification, are permitted provided that the following conditions |
|
6 * are met: |
|
7 * 1. Redistributions of source code must retain the above copyright |
|
8 * notice, this list of conditions and the following disclaimer. |
|
9 * 2. Redistributions in binary form must reproduce the above copyright |
|
10 * notice, this list of conditions and the following disclaimer in the |
|
11 * documentation and/or other materials provided with the distribution. |
|
12 * |
|
13 * THIS SOFTWARE IS PROVIDED BY GOOGLE INC. ``AS IS'' AND ANY |
|
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
|
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GOOGLE INC. OR |
|
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
|
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
|
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
|
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
|
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
24 */ |
|
25 |
|
26 #ifndef HTMLElementStack_h |
|
27 #define HTMLElementStack_h |
|
28 |
|
29 #include <wtf/Noncopyable.h> |
|
30 #include <wtf/OwnPtr.h> |
|
31 #include <wtf/PassOwnPtr.h> |
|
32 #include <wtf/RefPtr.h> |
|
33 |
|
34 namespace WebCore { |
|
35 |
|
36 class AtomicString; |
|
37 class Element; |
|
38 class QualifiedName; |
|
39 |
|
40 // NOTE: The HTML5 spec uses a backwards (grows downward) stack. We're using |
|
41 // more standard (grows upwards) stack terminology here. |
|
42 class HTMLElementStack : public Noncopyable { |
|
43 public: |
|
44 HTMLElementStack(); |
|
45 ~HTMLElementStack(); |
|
46 |
|
47 class ElementRecord : public Noncopyable { |
|
48 public: |
|
49 ~ElementRecord(); // Public for ~PassOwnPtr() |
|
50 |
|
51 Element* element() const { return m_element.get(); } |
|
52 void replaceElement(PassRefPtr<Element>); |
|
53 |
|
54 bool isAbove(ElementRecord*) const; |
|
55 |
|
56 ElementRecord* next() const { return m_next.get(); } |
|
57 |
|
58 private: |
|
59 friend class HTMLElementStack; |
|
60 |
|
61 ElementRecord(PassRefPtr<Element>, PassOwnPtr<ElementRecord>); |
|
62 |
|
63 PassOwnPtr<ElementRecord> releaseNext() { return m_next.release(); } |
|
64 void setNext(PassOwnPtr<ElementRecord> next) { m_next = next; } |
|
65 |
|
66 RefPtr<Element> m_element; |
|
67 OwnPtr<ElementRecord> m_next; |
|
68 }; |
|
69 |
|
70 Element* top() const; |
|
71 Element* oneBelowTop() const; |
|
72 ElementRecord* topRecord() const; |
|
73 Element* bottom() const; |
|
74 ElementRecord* find(Element*) const; |
|
75 ElementRecord* topmost(const AtomicString& tagName) const; |
|
76 |
|
77 void insertAbove(PassRefPtr<Element>, ElementRecord*); |
|
78 |
|
79 void push(PassRefPtr<Element>); |
|
80 void pushHTMLHtmlElement(PassRefPtr<Element>); |
|
81 void pushHTMLHeadElement(PassRefPtr<Element>); |
|
82 void pushHTMLBodyElement(PassRefPtr<Element>); |
|
83 |
|
84 void pop(); |
|
85 void popUntil(const AtomicString& tagName); |
|
86 void popUntilElementWithNamespace(const AtomicString& namespaceURI); |
|
87 void popUntil(Element*); |
|
88 void popUntilPopped(const AtomicString& tagName); |
|
89 void popUntilPopped(Element*); |
|
90 void popUntilTableScopeMarker(); // "clear the stack back to a table context" in the spec. |
|
91 void popUntilTableBodyScopeMarker(); // "clear the stack back to a table body context" in the spec. |
|
92 void popUntilTableRowScopeMarker(); // "clear the stack back to a table row context" in the spec. |
|
93 void popHTMLHeadElement(); |
|
94 void popHTMLBodyElement(); |
|
95 void popAll(); |
|
96 |
|
97 void remove(Element*); |
|
98 void removeHTMLHeadElement(Element*); |
|
99 |
|
100 bool contains(Element*) const; |
|
101 bool contains(const AtomicString& tagName) const; |
|
102 |
|
103 bool inScope(Element*) const; |
|
104 bool inScope(const AtomicString& tagName) const; |
|
105 bool inScope(const QualifiedName&) const; |
|
106 bool inListItemScope(const AtomicString& tagName) const; |
|
107 bool inListItemScope(const QualifiedName&) const; |
|
108 bool inTableScope(const AtomicString& tagName) const; |
|
109 bool inTableScope(const QualifiedName&) const; |
|
110 bool inButtonScope(const AtomicString& tagName) const; |
|
111 bool inButtonScope(const QualifiedName&) const; |
|
112 |
|
113 bool hasOnlyHTMLElementsInScope() const; |
|
114 |
|
115 Element* htmlElement() const; |
|
116 Element* headElement() const; |
|
117 Element* bodyElement() const; |
|
118 |
|
119 #ifndef NDEBUG |
|
120 void show(); |
|
121 #endif |
|
122 |
|
123 private: |
|
124 void pushCommon(PassRefPtr<Element>); |
|
125 void popCommon(); |
|
126 void removeNonTopCommon(Element*); |
|
127 |
|
128 OwnPtr<ElementRecord> m_top; |
|
129 |
|
130 // We remember <html>, <head> and <body> as they are pushed. Their |
|
131 // ElementRecords keep them alive. <html> is never popped. |
|
132 // FIXME: We don't currently require type-specific information about |
|
133 // these elements so we haven't yet bothered to plumb the types all the |
|
134 // way down through createElement, etc. |
|
135 Element* m_htmlElement; |
|
136 Element* m_headElement; |
|
137 Element* m_bodyElement; |
|
138 }; |
|
139 |
|
140 } // namespace WebCore |
|
141 |
|
142 #endif // HTMLElementStack_h |