Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(710)

Side by Side Diff: Source/core/html/parser/HTMLTreeBuilder.cpp

Issue 201293002: Add Traversal<*Element>::firstAncestor() API (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Slight clean up Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 17 matching lines...) Expand all
28 #include "core/html/parser/HTMLTreeBuilder.h" 28 #include "core/html/parser/HTMLTreeBuilder.h"
29 29
30 #include "HTMLNames.h" 30 #include "HTMLNames.h"
31 #include "MathMLNames.h" 31 #include "MathMLNames.h"
32 #include "SVGNames.h" 32 #include "SVGNames.h"
33 #include "XLinkNames.h" 33 #include "XLinkNames.h"
34 #include "XMLNSNames.h" 34 #include "XMLNSNames.h"
35 #include "XMLNames.h" 35 #include "XMLNames.h"
36 #include "bindings/v8/ExceptionStatePlaceholder.h" 36 #include "bindings/v8/ExceptionStatePlaceholder.h"
37 #include "core/dom/DocumentFragment.h" 37 #include "core/dom/DocumentFragment.h"
38 #include "core/dom/ElementTraversal.h"
38 #include "core/html/HTMLDocument.h" 39 #include "core/html/HTMLDocument.h"
39 #include "core/html/HTMLFormElement.h" 40 #include "core/html/HTMLFormElement.h"
40 #include "core/html/parser/AtomicHTMLToken.h" 41 #include "core/html/parser/AtomicHTMLToken.h"
41 #include "core/html/parser/HTMLDocumentParser.h" 42 #include "core/html/parser/HTMLDocumentParser.h"
42 #include "core/html/parser/HTMLParserIdioms.h" 43 #include "core/html/parser/HTMLParserIdioms.h"
43 #include "core/html/parser/HTMLStackItem.h" 44 #include "core/html/parser/HTMLStackItem.h"
44 #include "core/html/parser/HTMLToken.h" 45 #include "core/html/parser/HTMLToken.h"
45 #include "core/html/parser/HTMLTokenizer.h" 46 #include "core/html/parser/HTMLTokenizer.h"
46 #include "platform/NotImplemented.h" 47 #include "platform/NotImplemented.h"
47 #include "platform/text/PlatformLocale.h" 48 #include "platform/text/PlatformLocale.h"
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 return tagName == nobrTag 127 return tagName == nobrTag
127 || isNonAnchorNonNobrFormattingTag(tagName); 128 || isNonAnchorNonNobrFormattingTag(tagName);
128 } 129 }
129 130
130 // http://www.whatwg.org/specs/web-apps/current-work/multipage/parsing.html#form atting 131 // http://www.whatwg.org/specs/web-apps/current-work/multipage/parsing.html#form atting
131 static bool isFormattingTag(const AtomicString& tagName) 132 static bool isFormattingTag(const AtomicString& tagName)
132 { 133 {
133 return tagName == aTag || isNonAnchorFormattingTag(tagName); 134 return tagName == aTag || isNonAnchorFormattingTag(tagName);
134 } 135 }
135 136
136 static HTMLFormElement* closestFormAncestor(Element* element) 137 static HTMLFormElement* closestFormAncestor(Element& element)
137 { 138 {
138 ASSERT(isMainThread()); 139 ASSERT(isMainThread());
139 while (element) { 140 if (isHTMLFormElement(element))
140 if (isHTMLFormElement(*element)) 141 return &toHTMLFormElement(element);
141 return toHTMLFormElement(element); 142 return Traversal<HTMLFormElement>::firstAncestor(element);
142 ContainerNode* parent = element->parentNode();
143 if (!parent || !parent->isElementNode())
144 return 0;
145 element = toElement(parent);
146 }
147 return 0;
148 } 143 }
149 144
150 class HTMLTreeBuilder::CharacterTokenBuffer { 145 class HTMLTreeBuilder::CharacterTokenBuffer {
151 WTF_MAKE_NONCOPYABLE(CharacterTokenBuffer); 146 WTF_MAKE_NONCOPYABLE(CharacterTokenBuffer);
152 public: 147 public:
153 explicit CharacterTokenBuffer(AtomicHTMLToken* token) 148 explicit CharacterTokenBuffer(AtomicHTMLToken* token)
154 : m_characters(token->characters().impl()) 149 : m_characters(token->characters().impl())
155 , m_current(0) 150 , m_current(0)
156 , m_end(token->characters().length()) 151 , m_end(token->characters().length())
157 { 152 {
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 // Steps 4.2-4.6 of the HTML5 Fragment Case parsing algorithm: 303 // Steps 4.2-4.6 of the HTML5 Fragment Case parsing algorithm:
309 // http://www.whatwg.org/specs/web-apps/current-work/multipage/the-end.h tml#fragment-case 304 // http://www.whatwg.org/specs/web-apps/current-work/multipage/the-end.h tml#fragment-case
310 // For efficiency, we skip step 4.2 ("Let root be a new html element wit h no attributes") 305 // For efficiency, we skip step 4.2 ("Let root be a new html element wit h no attributes")
311 // and instead use the DocumentFragment as a root node. 306 // and instead use the DocumentFragment as a root node.
312 m_tree.openElements()->pushRootNode(HTMLStackItem::create(fragment, HTML StackItem::ItemForDocumentFragmentNode)); 307 m_tree.openElements()->pushRootNode(HTMLStackItem::create(fragment, HTML StackItem::ItemForDocumentFragmentNode));
313 308
314 if (isHTMLTemplateElement(*contextElement)) 309 if (isHTMLTemplateElement(*contextElement))
315 m_templateInsertionModes.append(TemplateContentsMode); 310 m_templateInsertionModes.append(TemplateContentsMode);
316 311
317 resetInsertionModeAppropriately(); 312 resetInsertionModeAppropriately();
318 m_tree.setForm(closestFormAncestor(contextElement)); 313 m_tree.setForm(closestFormAncestor(*contextElement));
319 } 314 }
320 } 315 }
321 316
322 HTMLTreeBuilder::~HTMLTreeBuilder() 317 HTMLTreeBuilder::~HTMLTreeBuilder()
323 { 318 {
324 } 319 }
325 320
326 void HTMLTreeBuilder::detach() 321 void HTMLTreeBuilder::detach()
327 { 322 {
328 #ifndef NDEBUG 323 #ifndef NDEBUG
(...skipping 2460 matching lines...) Expand 10 before | Expand all | Expand 10 after
2789 ASSERT(m_isAttached); 2784 ASSERT(m_isAttached);
2790 // Warning, this may detach the parser. Do not do anything else after this. 2785 // Warning, this may detach the parser. Do not do anything else after this.
2791 m_tree.finishedParsing(); 2786 m_tree.finishedParsing();
2792 } 2787 }
2793 2788
2794 void HTMLTreeBuilder::parseError(AtomicHTMLToken*) 2789 void HTMLTreeBuilder::parseError(AtomicHTMLToken*)
2795 { 2790 {
2796 } 2791 }
2797 2792
2798 } // namespace WebCore 2793 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698