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

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

Issue 198453003: Use new is*Element() helper functions more in HTML code (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase 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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 // http://www.whatwg.org/specs/web-apps/current-work/multipage/parsing.html#form atting 130 // http://www.whatwg.org/specs/web-apps/current-work/multipage/parsing.html#form atting
131 static bool isFormattingTag(const AtomicString& tagName) 131 static bool isFormattingTag(const AtomicString& tagName)
132 { 132 {
133 return tagName == aTag || isNonAnchorFormattingTag(tagName); 133 return tagName == aTag || isNonAnchorFormattingTag(tagName);
134 } 134 }
135 135
136 static HTMLFormElement* closestFormAncestor(Element* element) 136 static HTMLFormElement* closestFormAncestor(Element* element)
137 { 137 {
138 ASSERT(isMainThread()); 138 ASSERT(isMainThread());
139 while (element) { 139 while (element) {
140 if (element->hasTagName(formTag)) 140 if (isHTMLFormElement(*element))
141 return toHTMLFormElement(element); 141 return toHTMLFormElement(element);
142 ContainerNode* parent = element->parentNode(); 142 ContainerNode* parent = element->parentNode();
143 if (!parent || !parent->isElementNode()) 143 if (!parent || !parent->isElementNode())
144 return 0; 144 return 0;
145 element = toElement(parent); 145 element = toElement(parent);
146 } 146 }
147 return 0; 147 return 0;
148 } 148 }
149 149
150 class HTMLTreeBuilder::CharacterTokenBuffer { 150 class HTMLTreeBuilder::CharacterTokenBuffer {
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 ASSERT(isMainThread()); 304 ASSERT(isMainThread());
305 // FIXME: This assertion will become invalid if <http://webkit.org/b/60316> is fixed. 305 // FIXME: This assertion will become invalid if <http://webkit.org/b/60316> is fixed.
306 ASSERT(contextElement); 306 ASSERT(contextElement);
307 if (contextElement) { 307 if (contextElement) {
308 // Steps 4.2-4.6 of the HTML5 Fragment Case parsing algorithm: 308 // 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 309 // 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") 310 // 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. 311 // and instead use the DocumentFragment as a root node.
312 m_tree.openElements()->pushRootNode(HTMLStackItem::create(fragment, HTML StackItem::ItemForDocumentFragmentNode)); 312 m_tree.openElements()->pushRootNode(HTMLStackItem::create(fragment, HTML StackItem::ItemForDocumentFragmentNode));
313 313
314 if (contextElement->hasTagName(templateTag)) 314 if (isHTMLTemplateElement(*contextElement))
315 m_templateInsertionModes.append(TemplateContentsMode); 315 m_templateInsertionModes.append(TemplateContentsMode);
316 316
317 resetInsertionModeAppropriately(); 317 resetInsertionModeAppropriately();
318 m_tree.setForm(closestFormAncestor(contextElement)); 318 m_tree.setForm(closestFormAncestor(contextElement));
319 } 319 }
320 } 320 }
321 321
322 HTMLTreeBuilder::~HTMLTreeBuilder() 322 HTMLTreeBuilder::~HTMLTreeBuilder()
323 { 323 {
324 } 324 }
(...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after
905 m_tree.activeFormattingElements()->appendMarker(); 905 m_tree.activeFormattingElements()->appendMarker();
906 m_tree.insertHTMLElement(token); 906 m_tree.insertHTMLElement(token);
907 m_templateInsertionModes.append(TemplateContentsMode); 907 m_templateInsertionModes.append(TemplateContentsMode);
908 setInsertionMode(TemplateContentsMode); 908 setInsertionMode(TemplateContentsMode);
909 } 909 }
910 910
911 bool HTMLTreeBuilder::processTemplateEndTag(AtomicHTMLToken* token) 911 bool HTMLTreeBuilder::processTemplateEndTag(AtomicHTMLToken* token)
912 { 912 {
913 ASSERT(token->name() == templateTag.localName()); 913 ASSERT(token->name() == templateTag.localName());
914 if (!m_tree.openElements()->hasTemplateInHTMLScope()) { 914 if (!m_tree.openElements()->hasTemplateInHTMLScope()) {
915 ASSERT(m_templateInsertionModes.isEmpty() || (m_templateInsertionModes.s ize() == 1 && m_fragmentContext.contextElement()->hasTagName(templateTag))); 915 ASSERT(m_templateInsertionModes.isEmpty() || (m_templateInsertionModes.s ize() == 1 && isHTMLTemplateElement(m_fragmentContext.contextElement())));
916 parseError(token); 916 parseError(token);
917 return false; 917 return false;
918 } 918 }
919 m_tree.generateImpliedEndTags(); 919 m_tree.generateImpliedEndTags();
920 if (!m_tree.currentStackItem()->hasTagName(templateTag)) 920 if (!m_tree.currentStackItem()->hasTagName(templateTag))
921 parseError(token); 921 parseError(token);
922 m_tree.openElements()->popUntilPopped(templateTag); 922 m_tree.openElements()->popUntilPopped(templateTag);
923 m_tree.activeFormattingElements()->clearToLastMarker(); 923 m_tree.activeFormattingElements()->clearToLastMarker();
924 m_templateInsertionModes.removeLast(); 924 m_templateInsertionModes.removeLast();
925 resetInsertionModeAppropriately(); 925 resetInsertionModeAppropriately();
926 return true; 926 return true;
927 } 927 }
928 928
929 bool HTMLTreeBuilder::processEndOfFileForInTemplateContents(AtomicHTMLToken* tok en) 929 bool HTMLTreeBuilder::processEndOfFileForInTemplateContents(AtomicHTMLToken* tok en)
930 { 930 {
931 AtomicHTMLToken endTemplate(HTMLToken::EndTag, templateTag.localName()); 931 AtomicHTMLToken endTemplate(HTMLToken::EndTag, templateTag.localName());
932 if (!processTemplateEndTag(&endTemplate)) 932 if (!processTemplateEndTag(&endTemplate))
933 return false; 933 return false;
934 934
935 processEndOfFile(token); 935 processEndOfFile(token);
936 return true; 936 return true;
937 } 937 }
938 938
939 bool HTMLTreeBuilder::processColgroupEndTagForInColumnGroup() 939 bool HTMLTreeBuilder::processColgroupEndTagForInColumnGroup()
940 { 940 {
941 if (m_tree.currentIsRootNode() || m_tree.currentNode()->hasTagName(templateT ag)) { 941 if (m_tree.currentIsRootNode() || isHTMLTemplateElement(*m_tree.currentNode( ))) {
942 ASSERT(isParsingFragmentOrTemplateContents()); 942 ASSERT(isParsingFragmentOrTemplateContents());
943 // FIXME: parse error 943 // FIXME: parse error
944 return false; 944 return false;
945 } 945 }
946 m_tree.openElements()->pop(); 946 m_tree.openElements()->pop();
947 setInsertionMode(InTableMode); 947 setInsertionMode(InTableMode);
948 return true; 948 return true;
949 } 949 }
950 950
951 // http://www.whatwg.org/specs/web-apps/current-work/#adjusted-current-node 951 // http://www.whatwg.org/specs/web-apps/current-work/#adjusted-current-node
(...skipping 1496 matching lines...) Expand 10 before | Expand all | Expand 10 after
2448 return; 2448 return;
2449 case AfterFramesetMode: 2449 case AfterFramesetMode:
2450 case AfterAfterFramesetMode: 2450 case AfterAfterFramesetMode:
2451 ASSERT(insertionMode() == AfterFramesetMode || insertionMode() == AfterA fterFramesetMode); 2451 ASSERT(insertionMode() == AfterFramesetMode || insertionMode() == AfterA fterFramesetMode);
2452 break; 2452 break;
2453 case InColumnGroupMode: 2453 case InColumnGroupMode:
2454 if (m_tree.currentIsRootNode()) { 2454 if (m_tree.currentIsRootNode()) {
2455 ASSERT(isParsingFragment()); 2455 ASSERT(isParsingFragment());
2456 return; // FIXME: Should we break here instead of returning? 2456 return; // FIXME: Should we break here instead of returning?
2457 } 2457 }
2458 ASSERT(m_tree.currentNode()->hasTagName(colgroupTag) || m_tree.currentNo de()->hasTagName(templateTag)); 2458 ASSERT(m_tree.currentNode()->hasTagName(colgroupTag) || isHTMLTemplateEl ement(m_tree.currentNode()));
2459 processColgroupEndTagForInColumnGroup(); 2459 processColgroupEndTagForInColumnGroup();
2460 // Fall through 2460 // Fall through
2461 case InFramesetMode: 2461 case InFramesetMode:
2462 case InTableMode: 2462 case InTableMode:
2463 case InTableBodyMode: 2463 case InTableBodyMode:
2464 case InSelectInTableMode: 2464 case InSelectInTableMode:
2465 case InSelectMode: 2465 case InSelectMode:
2466 ASSERT(insertionMode() == InSelectMode || insertionMode() == InSelectInT ableMode || insertionMode() == InTableMode || insertionMode() == InFramesetMode || insertionMode() == InTableBodyMode || insertionMode() == InColumnGroupMode); 2466 ASSERT(insertionMode() == InSelectMode || insertionMode() == InSelectInT ableMode || insertionMode() == InTableMode || insertionMode() == InFramesetMode || insertionMode() == InTableBodyMode || insertionMode() == InColumnGroupMode);
2467 if (m_tree.currentNode() != m_tree.openElements()->rootNode()) 2467 if (m_tree.currentNode() != m_tree.openElements()->rootNode())
2468 parseError(token); 2468 parseError(token);
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
2789 ASSERT(m_isAttached); 2789 ASSERT(m_isAttached);
2790 // Warning, this may detach the parser. Do not do anything else after this. 2790 // Warning, this may detach the parser. Do not do anything else after this.
2791 m_tree.finishedParsing(); 2791 m_tree.finishedParsing();
2792 } 2792 }
2793 2793
2794 void HTMLTreeBuilder::parseError(AtomicHTMLToken*) 2794 void HTMLTreeBuilder::parseError(AtomicHTMLToken*)
2795 { 2795 {
2796 } 2796 }
2797 2797
2798 } // namespace WebCore 2798 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698