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 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 } | 368 } |
369 | 369 |
370 void HTMLTreeBuilder::constructTree(AtomicHTMLToken* token) | 370 void HTMLTreeBuilder::constructTree(AtomicHTMLToken* token) |
371 { | 371 { |
372 if (shouldProcessTokenInForeignContent(token)) | 372 if (shouldProcessTokenInForeignContent(token)) |
373 processTokenInForeignContent(token); | 373 processTokenInForeignContent(token); |
374 else | 374 else |
375 processToken(token); | 375 processToken(token); |
376 | 376 |
377 if (m_parser->tokenizer()) { | 377 if (m_parser->tokenizer()) { |
378 bool inForeignContent = false; | 378 bool inForeignContent = !m_tree.isEmpty() |
379 if (!m_tree.isEmpty()) { | 379 && !m_tree.currentStackItem()->isInHTMLNamespace() |
380 RefPtr<HTMLStackItem> adjustedCurrentNode = adjustedCurrentStackItem
(); | 380 && !HTMLElementStack::isHTMLIntegrationPoint(m_tree.currentStackItem
()) |
381 inForeignContent = !adjustedCurrentNode->isInHTMLNamespace() | 381 && !HTMLElementStack::isMathMLTextIntegrationPoint(m_tree.currentSta
ckItem()); |
382 && !HTMLElementStack::isHTMLIntegrationPoint(adjustedCurrentNode
.get()) | |
383 && !HTMLElementStack::isMathMLTextIntegrationPoint(adjustedCurre
ntNode.get()); | |
384 } | |
385 | 382 |
386 m_parser->tokenizer()->setForceNullCharacterReplacement(m_insertionMode
== TextMode || inForeignContent); | 383 m_parser->tokenizer()->setForceNullCharacterReplacement(m_insertionMode
== TextMode || inForeignContent); |
387 m_parser->tokenizer()->setShouldAllowCDATA(inForeignContent); | 384 m_parser->tokenizer()->setShouldAllowCDATA(inForeignContent); |
388 } | 385 } |
389 | 386 |
390 m_tree.executeQueuedTasks(); | 387 m_tree.executeQueuedTasks(); |
391 // We might be detached now. | 388 // We might be detached now. |
392 } | 389 } |
393 | 390 |
394 void HTMLTreeBuilder::processToken(AtomicHTMLToken* token) | 391 void HTMLTreeBuilder::processToken(AtomicHTMLToken* token) |
(...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
991 if (m_tree.currentIsRootNode() || m_tree.currentNode()->hasTagName(templateT
ag)) { | 988 if (m_tree.currentIsRootNode() || m_tree.currentNode()->hasTagName(templateT
ag)) { |
992 ASSERT(isParsingFragmentOrTemplateContents()); | 989 ASSERT(isParsingFragmentOrTemplateContents()); |
993 // FIXME: parse error | 990 // FIXME: parse error |
994 return false; | 991 return false; |
995 } | 992 } |
996 m_tree.openElements()->pop(); | 993 m_tree.openElements()->pop(); |
997 setInsertionMode(InTableMode); | 994 setInsertionMode(InTableMode); |
998 return true; | 995 return true; |
999 } | 996 } |
1000 | 997 |
1001 // http://www.whatwg.org/specs/web-apps/current-work/#adjusted-current-node | |
1002 PassRefPtr<HTMLStackItem> HTMLTreeBuilder::adjustedCurrentStackItem() const | |
1003 { | |
1004 ASSERT(!m_tree.isEmpty()); | |
1005 if (isParsingFragment() && m_tree.openElements()->hasOnlyOneElement()) | |
1006 return HTMLStackItem::create(m_fragmentContext.contextElement(), HTMLSta
ckItem::ItemForContextElement); | |
1007 | |
1008 return m_tree.currentStackItem(); | |
1009 } | |
1010 | |
1011 // http://www.whatwg.org/specs/web-apps/current-work/multipage/tokenization.html
#close-the-cell | 998 // http://www.whatwg.org/specs/web-apps/current-work/multipage/tokenization.html
#close-the-cell |
1012 void HTMLTreeBuilder::closeTheCell() | 999 void HTMLTreeBuilder::closeTheCell() |
1013 { | 1000 { |
1014 ASSERT(insertionMode() == InCellMode); | 1001 ASSERT(insertionMode() == InCellMode); |
1015 if (m_tree.openElements()->inTableScope(tdTag)) { | 1002 if (m_tree.openElements()->inTableScope(tdTag)) { |
1016 ASSERT(!m_tree.openElements()->inTableScope(thTag)); | 1003 ASSERT(!m_tree.openElements()->inTableScope(thTag)); |
1017 processFakeEndTag(tdTag); | 1004 processFakeEndTag(tdTag); |
1018 return; | 1005 return; |
1019 } | 1006 } |
1020 ASSERT(m_tree.openElements()->inTableScope(thTag)); | 1007 ASSERT(m_tree.openElements()->inTableScope(thTag)); |
(...skipping 1660 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2681 m_scriptToProcessStartPosition = position; | 2668 m_scriptToProcessStartPosition = position; |
2682 | 2669 |
2683 setInsertionMode(TextMode); | 2670 setInsertionMode(TextMode); |
2684 } | 2671 } |
2685 | 2672 |
2686 // http://www.whatwg.org/specs/web-apps/current-work/multipage/tree-construction
.html#tree-construction | 2673 // http://www.whatwg.org/specs/web-apps/current-work/multipage/tree-construction
.html#tree-construction |
2687 bool HTMLTreeBuilder::shouldProcessTokenInForeignContent(AtomicHTMLToken* token) | 2674 bool HTMLTreeBuilder::shouldProcessTokenInForeignContent(AtomicHTMLToken* token) |
2688 { | 2675 { |
2689 if (m_tree.isEmpty()) | 2676 if (m_tree.isEmpty()) |
2690 return false; | 2677 return false; |
2691 RefPtr<HTMLStackItem> adjustedCurrentNode = adjustedCurrentStackItem(); | 2678 HTMLStackItem* item = m_tree.currentStackItem(); |
2692 | 2679 if (item->isInHTMLNamespace()) |
2693 if (adjustedCurrentNode->isInHTMLNamespace()) | |
2694 return false; | 2680 return false; |
2695 if (HTMLElementStack::isMathMLTextIntegrationPoint(adjustedCurrentNode.get()
)) { | 2681 if (HTMLElementStack::isMathMLTextIntegrationPoint(item)) { |
2696 if (token->type() == HTMLToken::StartTag | 2682 if (token->type() == HTMLToken::StartTag |
2697 && token->name() != MathMLNames::mglyphTag | 2683 && token->name() != MathMLNames::mglyphTag |
2698 && token->name() != MathMLNames::malignmarkTag) | 2684 && token->name() != MathMLNames::malignmarkTag) |
2699 return false; | 2685 return false; |
2700 if (token->type() == HTMLToken::Character) | 2686 if (token->type() == HTMLToken::Character) |
2701 return false; | 2687 return false; |
2702 } | 2688 } |
2703 if (adjustedCurrentNode->hasTagName(MathMLNames::annotation_xmlTag) | 2689 if (item->hasTagName(MathMLNames::annotation_xmlTag) |
2704 && token->type() == HTMLToken::StartTag | 2690 && token->type() == HTMLToken::StartTag |
2705 && token->name() == SVGNames::svgTag) | 2691 && token->name() == SVGNames::svgTag) |
2706 return false; | 2692 return false; |
2707 if (HTMLElementStack::isHTMLIntegrationPoint(adjustedCurrentNode.get())) { | 2693 if (HTMLElementStack::isHTMLIntegrationPoint(item)) { |
2708 if (token->type() == HTMLToken::StartTag) | 2694 if (token->type() == HTMLToken::StartTag) |
2709 return false; | 2695 return false; |
2710 if (token->type() == HTMLToken::Character) | 2696 if (token->type() == HTMLToken::Character) |
2711 return false; | 2697 return false; |
2712 } | 2698 } |
2713 if (token->type() == HTMLToken::EndOfFile) | 2699 if (token->type() == HTMLToken::EndOfFile) |
2714 return false; | 2700 return false; |
2715 return true; | 2701 return true; |
2716 } | 2702 } |
2717 | 2703 |
2718 void HTMLTreeBuilder::processTokenInForeignContent(AtomicHTMLToken* token) | 2704 void HTMLTreeBuilder::processTokenInForeignContent(AtomicHTMLToken* token) |
2719 { | 2705 { |
2720 RefPtr<HTMLStackItem> adjustedCurrentNode = adjustedCurrentStackItem(); | |
2721 | |
2722 switch (token->type()) { | 2706 switch (token->type()) { |
2723 case HTMLToken::Uninitialized: | 2707 case HTMLToken::Uninitialized: |
2724 ASSERT_NOT_REACHED(); | 2708 ASSERT_NOT_REACHED(); |
2725 break; | 2709 break; |
2726 case HTMLToken::DOCTYPE: | 2710 case HTMLToken::DOCTYPE: |
2727 parseError(token); | 2711 parseError(token); |
2728 break; | 2712 break; |
2729 case HTMLToken::StartTag: { | 2713 case HTMLToken::StartTag: { |
2730 if (token->name() == bTag | 2714 if (token->name() == bTag |
2731 || token->name() == bigTag | 2715 || token->name() == bigTag |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2765 || token->name() == ttTag | 2749 || token->name() == ttTag |
2766 || token->name() == uTag | 2750 || token->name() == uTag |
2767 || token->name() == ulTag | 2751 || token->name() == ulTag |
2768 || token->name() == varTag | 2752 || token->name() == varTag |
2769 || (token->name() == fontTag && (token->getAttributeItem(colorAttr)
|| token->getAttributeItem(faceAttr) || token->getAttributeItem(sizeAttr)))) { | 2753 || (token->name() == fontTag && (token->getAttributeItem(colorAttr)
|| token->getAttributeItem(faceAttr) || token->getAttributeItem(sizeAttr)))) { |
2770 parseError(token); | 2754 parseError(token); |
2771 m_tree.openElements()->popUntilForeignContentScopeMarker(); | 2755 m_tree.openElements()->popUntilForeignContentScopeMarker(); |
2772 processStartTag(token); | 2756 processStartTag(token); |
2773 return; | 2757 return; |
2774 } | 2758 } |
2775 const AtomicString& currentNamespace = adjustedCurrentNode->namespaceURI
(); | 2759 const AtomicString& currentNamespace = m_tree.currentStackItem()->namesp
aceURI(); |
2776 if (currentNamespace == MathMLNames::mathmlNamespaceURI) | 2760 if (currentNamespace == MathMLNames::mathmlNamespaceURI) |
2777 adjustMathMLAttributes(token); | 2761 adjustMathMLAttributes(token); |
2778 if (currentNamespace == SVGNames::svgNamespaceURI) { | 2762 if (currentNamespace == SVGNames::svgNamespaceURI) { |
2779 adjustSVGTagNameCase(token); | 2763 adjustSVGTagNameCase(token); |
2780 adjustSVGAttributes(token); | 2764 adjustSVGAttributes(token); |
2781 } | 2765 } |
2782 adjustForeignAttributes(token); | 2766 adjustForeignAttributes(token); |
2783 m_tree.insertForeignElement(token, currentNamespace); | 2767 m_tree.insertForeignElement(token, currentNamespace); |
2784 break; | 2768 break; |
2785 } | 2769 } |
2786 case HTMLToken::EndTag: { | 2770 case HTMLToken::EndTag: { |
2787 if (adjustedCurrentNode->namespaceURI() == SVGNames::svgNamespaceURI) | 2771 if (m_tree.currentStackItem()->namespaceURI() == SVGNames::svgNamespaceU
RI) |
2788 adjustSVGTagNameCase(token); | 2772 adjustSVGTagNameCase(token); |
2789 | 2773 |
2790 if (token->name() == SVGNames::scriptTag && m_tree.currentStackItem()->h
asTagName(SVGNames::scriptTag)) { | 2774 if (token->name() == SVGNames::scriptTag && m_tree.currentStackItem()->h
asTagName(SVGNames::scriptTag)) { |
2791 if (scriptingContentIsAllowed(m_tree.parserContentPolicy())) | 2775 if (scriptingContentIsAllowed(m_tree.parserContentPolicy())) |
2792 m_scriptToProcess = m_tree.currentElement(); | 2776 m_scriptToProcess = m_tree.currentElement(); |
2793 m_tree.openElements()->pop(); | 2777 m_tree.openElements()->pop(); |
2794 return; | 2778 return; |
2795 } | 2779 } |
2796 if (!m_tree.currentStackItem()->isInHTMLNamespace()) { | 2780 if (!m_tree.currentStackItem()->isInHTMLNamespace()) { |
2797 // FIXME: This code just wants an Element* iterator, instead of an E
lementRecord* | 2781 // FIXME: This code just wants an Element* iterator, instead of an E
lementRecord* |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2838 ASSERT(m_isAttached); | 2822 ASSERT(m_isAttached); |
2839 // Warning, this may detach the parser. Do not do anything else after this. | 2823 // Warning, this may detach the parser. Do not do anything else after this. |
2840 m_tree.finishedParsing(); | 2824 m_tree.finishedParsing(); |
2841 } | 2825 } |
2842 | 2826 |
2843 void HTMLTreeBuilder::parseError(AtomicHTMLToken*) | 2827 void HTMLTreeBuilder::parseError(AtomicHTMLToken*) |
2844 { | 2828 { |
2845 } | 2829 } |
2846 | 2830 |
2847 } // namespace WebCore | 2831 } // namespace WebCore |
OLD | NEW |