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