OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2010 Google, Inc. All Rights Reserved. | 2 * Copyright (C) 2010 Google, Inc. All Rights Reserved. |
3 * Copyright (C) 2011 Apple Inc. All rights reserved. | 3 * Copyright (C) 2011 Apple Inc. All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 RefPtr<Node> child; | 56 RefPtr<Node> child; |
57 bool selfClosing; | 57 bool selfClosing; |
58 }; | 58 }; |
59 | 59 |
60 } // namespace blink | 60 } // namespace blink |
61 | 61 |
62 WTF_ALLOW_MOVE_INIT_AND_COMPARE_WITH_MEM_FUNCTIONS(blink::HTMLConstructionSiteTa
sk); | 62 WTF_ALLOW_MOVE_INIT_AND_COMPARE_WITH_MEM_FUNCTIONS(blink::HTMLConstructionSiteTa
sk); |
63 | 63 |
64 namespace blink { | 64 namespace blink { |
65 | 65 |
66 // Note: These are intentionally ordered so that when we concatonate | |
67 // strings and whitespaces the resulting whitespace is ws = min(ws1, ws2). | |
68 enum WhitespaceMode { | |
69 WhitespaceUnknown, | |
70 NotAllWhitespace, | |
71 AllWhitespace, | |
72 }; | |
73 | |
74 class AtomicHTMLToken; | 66 class AtomicHTMLToken; |
75 class Document; | 67 class Document; |
76 class Element; | 68 class Element; |
77 | 69 |
78 class HTMLConstructionSite final { | 70 class HTMLConstructionSite final { |
79 WTF_MAKE_NONCOPYABLE(HTMLConstructionSite); | 71 WTF_MAKE_NONCOPYABLE(HTMLConstructionSite); |
80 DISALLOW_ALLOCATION(); | 72 DISALLOW_ALLOCATION(); |
81 public: | 73 public: |
82 explicit HTMLConstructionSite(Document*); | 74 explicit HTMLConstructionSite(Document*); |
83 explicit HTMLConstructionSite(DocumentFragment*); | 75 explicit HTMLConstructionSite(DocumentFragment*); |
(...skipping 22 matching lines...) Expand all Loading... |
106 { | 98 { |
107 return !m_pendingText.isEmpty() || !m_taskQueue.isEmpty(); | 99 return !m_pendingText.isEmpty() || !m_taskQueue.isEmpty(); |
108 } | 100 } |
109 | 101 |
110 void processEndOfFile(); | 102 void processEndOfFile(); |
111 void finishedParsing(); | 103 void finishedParsing(); |
112 | 104 |
113 void insertHTMLElement(AtomicHTMLToken*); | 105 void insertHTMLElement(AtomicHTMLToken*); |
114 void insertSelfClosingHTMLElement(AtomicHTMLToken*); | 106 void insertSelfClosingHTMLElement(AtomicHTMLToken*); |
115 void insertScriptElement(AtomicHTMLToken*); | 107 void insertScriptElement(AtomicHTMLToken*); |
116 void insertTextNode(const String&, WhitespaceMode = WhitespaceUnknown); | 108 void insertTextNode(const String&); |
117 | 109 |
118 bool isEmpty() const { return !m_openElements.stackDepth(); } | 110 bool isEmpty() const { return !m_openElements.stackDepth(); } |
119 Element* currentElement() const { return m_openElements.top(); } | 111 Element* currentElement() const { return m_openElements.top(); } |
120 ContainerNode* currentNode() const { return m_openElements.topNode(); } | 112 ContainerNode* currentNode() const { return m_openElements.topNode(); } |
121 Document& ownerDocumentForCurrentNode(); | 113 Document& ownerDocumentForCurrentNode(); |
122 HTMLElementStack* openElements() const { return &m_openElements; } | 114 HTMLElementStack* openElements() const { return &m_openElements; } |
123 | 115 |
124 private: | 116 private: |
125 // In the common case, this queue will have only one task because most | 117 // In the common case, this queue will have only one task because most |
126 // tokens produce only one DOM mutation. | 118 // tokens produce only one DOM mutation. |
(...skipping 14 matching lines...) Expand all Loading... |
141 RawPtr<ContainerNode> m_attachmentRoot; | 133 RawPtr<ContainerNode> m_attachmentRoot; |
142 | 134 |
143 mutable HTMLElementStack m_openElements; | 135 mutable HTMLElementStack m_openElements; |
144 | 136 |
145 TaskQueue m_taskQueue; | 137 TaskQueue m_taskQueue; |
146 | 138 |
147 class PendingText { | 139 class PendingText { |
148 DISALLOW_ALLOCATION(); | 140 DISALLOW_ALLOCATION(); |
149 public: | 141 public: |
150 PendingText() | 142 PendingText() |
151 : whitespaceMode(WhitespaceUnknown) | |
152 { | 143 { |
153 } | 144 } |
154 | 145 |
155 void append(PassRefPtr<ContainerNode> newParent, const String& newString
, WhitespaceMode newWhitespaceMode) | 146 void append(PassRefPtr<ContainerNode> newParent, const String& newString
) |
156 { | 147 { |
157 ASSERT(!parent || parent == newParent); | 148 ASSERT(!parent || parent == newParent); |
158 parent = newParent; | 149 parent = newParent; |
159 stringBuilder.append(newString); | 150 stringBuilder.append(newString); |
160 whitespaceMode = std::min(whitespaceMode, newWhitespaceMode); | |
161 } | 151 } |
162 | 152 |
163 void swap(PendingText& other) | 153 void swap(PendingText& other) |
164 { | 154 { |
165 std::swap(whitespaceMode, other.whitespaceMode); | |
166 parent.swap(other.parent); | 155 parent.swap(other.parent); |
167 stringBuilder.swap(other.stringBuilder); | 156 stringBuilder.swap(other.stringBuilder); |
168 } | 157 } |
169 | 158 |
170 void discard() | 159 void discard() |
171 { | 160 { |
172 PendingText discardedText; | 161 PendingText discardedText; |
173 swap(discardedText); | 162 swap(discardedText); |
174 } | 163 } |
175 | 164 |
176 bool isEmpty() | 165 bool isEmpty() |
177 { | 166 { |
178 // When the stringbuilder is empty, the parent and whitespace should
also be "empty". | 167 // When the stringbuilder is empty, the parent should also be "empty
". |
179 ASSERT(stringBuilder.isEmpty() == !parent); | 168 ASSERT(stringBuilder.isEmpty() == !parent); |
180 ASSERT(!stringBuilder.isEmpty() || !nextChild); | 169 ASSERT(!stringBuilder.isEmpty() || !nextChild); |
181 ASSERT(!stringBuilder.isEmpty() || (whitespaceMode == WhitespaceUnkn
own)); | |
182 return stringBuilder.isEmpty(); | 170 return stringBuilder.isEmpty(); |
183 } | 171 } |
184 | 172 |
185 RefPtr<ContainerNode> parent; | 173 RefPtr<ContainerNode> parent; |
186 RefPtr<Node> nextChild; | 174 RefPtr<Node> nextChild; |
187 StringBuilder stringBuilder; | 175 StringBuilder stringBuilder; |
188 WhitespaceMode whitespaceMode; | |
189 }; | 176 }; |
190 | 177 |
191 PendingText m_pendingText; | 178 PendingText m_pendingText; |
192 }; | 179 }; |
193 | 180 |
194 } // namespace blink | 181 } // namespace blink |
195 | 182 |
196 #endif // SKY_ENGINE_CORE_HTML_PARSER_HTMLCONSTRUCTIONSITE_H_ | 183 #endif // SKY_ENGINE_CORE_HTML_PARSER_HTMLCONSTRUCTIONSITE_H_ |
OLD | NEW |