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