~ubuntu-branches/ubuntu/raring/qtwebkit-source/raring-proposed

« back to all changes in this revision

Viewing changes to Source/WebCore/html/parser/HTMLElementStack.h

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-02-18 14:24:18 UTC
  • Revision ID: package-import@ubuntu.com-20130218142418-eon0jmjg3nj438uy
Tags: upstream-2.3
ImportĀ upstreamĀ versionĀ 2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2010 Google, Inc. All Rights Reserved.
 
3
 * Copyright (C) 2011 Apple Inc. All rights reserved.
 
4
 *
 
5
 * Redistribution and use in source and binary forms, with or without
 
6
 * modification, are permitted provided that the following conditions
 
7
 * are met:
 
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.
 
13
 *
 
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. 
 
25
 */
 
26
 
 
27
#ifndef HTMLElementStack_h
 
28
#define HTMLElementStack_h
 
29
 
 
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>
 
37
 
 
38
namespace WebCore {
 
39
 
 
40
class ContainerNode;
 
41
class DocumentFragment;
 
42
class Element;
 
43
class QualifiedName;
 
44
 
 
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;
 
49
public:
 
50
    HTMLElementStack();
 
51
    ~HTMLElementStack();
 
52
 
 
53
    class ElementRecord {
 
54
        WTF_MAKE_NONCOPYABLE(ElementRecord); WTF_MAKE_FAST_ALLOCATED;
 
55
    public:
 
56
        ~ElementRecord(); // Public for ~PassOwnPtr()
 
57
    
 
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>);
 
62
 
 
63
        bool isAbove(ElementRecord*) const;
 
64
 
 
65
        ElementRecord* next() const { return m_next.get(); }
 
66
    private:
 
67
        friend class HTMLElementStack;
 
68
 
 
69
        ElementRecord(PassRefPtr<HTMLStackItem>, PassOwnPtr<ElementRecord>);
 
70
 
 
71
        PassOwnPtr<ElementRecord> releaseNext() { return m_next.release(); }
 
72
        void setNext(PassOwnPtr<ElementRecord> next) { m_next = next; }
 
73
 
 
74
        RefPtr<HTMLStackItem> m_item;
 
75
        OwnPtr<ElementRecord> m_next;
 
76
    };
 
77
 
 
78
    unsigned stackDepth() const { return m_stackDepth; }
 
79
 
 
80
    // Inlining this function is a (small) performance win on the parsing
 
81
    // benchmark.
 
82
    Element* top() const
 
83
    {
 
84
        ASSERT(m_top->element());
 
85
        return m_top->element();
 
86
    }
 
87
 
 
88
    ContainerNode* topNode() const
 
89
    {
 
90
        ASSERT(m_top->node());
 
91
        return m_top->node();
 
92
    }
 
93
 
 
94
    HTMLStackItem* topStackItem() const
 
95
    {
 
96
        ASSERT(m_top->stackItem());
 
97
        return m_top->stackItem().get();
 
98
    }
 
99
 
 
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;
 
105
 
 
106
    void insertAbove(PassRefPtr<HTMLStackItem>, ElementRecord*);
 
107
 
 
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>);
 
113
 
 
114
    void pop();
 
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();
 
126
    void popAll();
 
127
 
 
128
    static bool isMathMLTextIntegrationPoint(HTMLStackItem*);
 
129
    static bool isHTMLIntegrationPoint(HTMLStackItem*);
 
130
 
 
131
    void remove(Element*);
 
132
    void removeHTMLHeadElement(Element*);
 
133
 
 
134
    bool contains(Element*) const;
 
135
    bool contains(const AtomicString& tagName) const;
 
136
 
 
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;
 
148
 
 
149
    bool hasNumberedHeaderElementInScope() const;
 
150
 
 
151
    bool hasOnlyOneElement() const;
 
152
    bool secondElementIsHTMLBodyElement() const;
 
153
 
 
154
    Element* htmlElement() const;
 
155
    Element* headElement() const;
 
156
    Element* bodyElement() const;
 
157
    
 
158
    ContainerNode* rootNode() const;
 
159
 
 
160
#ifndef NDEBUG
 
161
    void show();
 
162
#endif
 
163
 
 
164
private:
 
165
    void pushCommon(PassRefPtr<HTMLStackItem>);
 
166
    void pushRootNodeCommon(PassRefPtr<HTMLStackItem>);
 
167
    void popCommon();
 
168
    void removeNonTopCommon(Element*);
 
169
 
 
170
    OwnPtr<ElementRecord> m_top;
 
171
 
 
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;
 
181
};
 
182
    
 
183
} // namespace WebCore
 
184
 
 
185
#endif // HTMLElementStack_h