Changeset 126355 in webkit


Ignore:
Timestamp:
Aug 22, 2012 2:55:10 PM (12 years ago)
Author:
commit-queue@webkit.org
Message:

HTMLTreeBuilder::furthestBlockForFormattingElement should belong to HTMLElementStack
https://bugs.webkit.org/show_bug.cgi?id=93857

Patch by Kwang Yul Seo <skyul@company100.net> on 2012-08-22
Reviewed by Eric Seidel.

HTMLTreeBuilder::furthestBlockForFormattingElement should belong to
HTMLElementStack because it traverses the element stack and finds the
furthest block for the given formatting element.

Currently, it belongs to HTMLTreeBuilder just because
isSpecialNode(const HTMLStackItem*) function used by
furthestBlockForFormattingElement is internal to HTMLTreeBuilder.

Moved isSpecialNode to HTMLStackItem and changed
furthestBlockForFormattingElement to be a method of HTMLElementStack.

No behavior change. Just a refactoring.

  • html/parser/HTMLElementStack.cpp:

(WebCore):
(WebCore::HTMLElementStack::popUntilNumberedHeaderElementPopped):
(WebCore::HTMLElementStack::hasNumberedHeaderElementInScope):
(WebCore::HTMLElementStack::furthestBlockForFormattingElement):

  • html/parser/HTMLElementStack.h:

(HTMLElementStack):

  • html/parser/HTMLStackItem.h:

(WebCore::HTMLStackItem::isInHTMLNamespace):
(HTMLStackItem):
(WebCore::HTMLStackItem::isNumberedHeaderElement):
(WebCore::HTMLStackItem::isTableBodyContextElement):
(WebCore::HTMLStackItem::isSpecialNode):

  • html/parser/HTMLTreeBuilder.cpp:

(WebCore::HTMLTreeBuilder::constructTreeFromAtomicToken):
(WebCore::HTMLTreeBuilder::processCloseWhenNestedTag):
(WebCore::HTMLTreeBuilder::processStartTagForInBody):
(WebCore::HTMLTreeBuilder::processAnyOtherEndTagForInBody):
(WebCore::HTMLTreeBuilder::callTheAdoptionAgency):
(WebCore::HTMLTreeBuilder::shouldProcessTokenInForeignContent):
(WebCore::HTMLTreeBuilder::processTokenInForeignContent):

  • html/parser/HTMLTreeBuilder.h:
Location:
trunk/Source/WebCore
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r126351 r126355  
     12012-08-22  Kwang Yul Seo  <skyul@company100.net>
     2
     3        HTMLTreeBuilder::furthestBlockForFormattingElement should belong to HTMLElementStack
     4        https://bugs.webkit.org/show_bug.cgi?id=93857
     5
     6        Reviewed by Eric Seidel.
     7
     8        HTMLTreeBuilder::furthestBlockForFormattingElement should belong to
     9        HTMLElementStack because it traverses the element stack and finds the
     10        furthest block for the given formatting element.
     11
     12        Currently, it belongs to HTMLTreeBuilder just because
     13        isSpecialNode(const HTMLStackItem*) function used by
     14        furthestBlockForFormattingElement is internal to HTMLTreeBuilder.
     15
     16        Moved isSpecialNode to HTMLStackItem and changed
     17        furthestBlockForFormattingElement to be a method of HTMLElementStack.
     18
     19        No behavior change. Just a refactoring.
     20
     21        * html/parser/HTMLElementStack.cpp:
     22        (WebCore):
     23        (WebCore::HTMLElementStack::popUntilNumberedHeaderElementPopped):
     24        (WebCore::HTMLElementStack::hasNumberedHeaderElementInScope):
     25        (WebCore::HTMLElementStack::furthestBlockForFormattingElement):
     26        * html/parser/HTMLElementStack.h:
     27        (HTMLElementStack):
     28        * html/parser/HTMLStackItem.h:
     29        (WebCore::HTMLStackItem::isInHTMLNamespace):
     30        (HTMLStackItem):
     31        (WebCore::HTMLStackItem::isNumberedHeaderElement):
     32        (WebCore::HTMLStackItem::isTableBodyContextElement):
     33        (WebCore::HTMLStackItem::isSpecialNode):
     34        * html/parser/HTMLTreeBuilder.cpp:
     35        (WebCore::HTMLTreeBuilder::constructTreeFromAtomicToken):
     36        (WebCore::HTMLTreeBuilder::processCloseWhenNestedTag):
     37        (WebCore::HTMLTreeBuilder::processStartTagForInBody):
     38        (WebCore::HTMLTreeBuilder::processAnyOtherEndTagForInBody):
     39        (WebCore::HTMLTreeBuilder::callTheAdoptionAgency):
     40        (WebCore::HTMLTreeBuilder::shouldProcessTokenInForeignContent):
     41        (WebCore::HTMLTreeBuilder::processTokenInForeignContent):
     42        * html/parser/HTMLTreeBuilder.h:
     43
    1442012-08-22  Alexandre Elias  <aelias@google.com>
    245
  • trunk/Source/WebCore/html/parser/HTMLElementStack.cpp

    r124379 r126355  
    3939using namespace HTMLNames;
    4040
    41 static inline bool isNumberedHeaderElement(HTMLStackItem* item)
    42 {
    43     return item->hasTagName(h1Tag)
    44         || item->hasTagName(h2Tag)
    45         || item->hasTagName(h3Tag)
    46         || item->hasTagName(h4Tag)
    47         || item->hasTagName(h5Tag)
    48         || item->hasTagName(h6Tag);
    49 }
    50    
    5141static inline bool isRootNode(HTMLStackItem* item)
    5242{
     
    10999    return HTMLElementStack::isMathMLTextIntegrationPoint(item)
    110100        || HTMLElementStack::isHTMLIntegrationPoint(item)
    111         || isInHTMLNamespace(item);
     101        || item->isInHTMLNamespace();
    112102}
    113103
     
    232222void HTMLElementStack::popUntilNumberedHeaderElementPopped()
    233223{
    234     while (!isNumberedHeaderElement(topStackItem()))
     224    while (!topStackItem()->isNumberedHeaderElement())
    235225        pop();
    236226    pop();
     
    461451    for (ElementRecord* record = m_top.get(); record; record = record->next()) {
    462452        HTMLStackItem* item = record->stackItem().get();
    463         if (isNumberedHeaderElement(item))
     453        if (item->isNumberedHeaderElement())
    464454            return true;
    465455        if (isScopeMarker(item))
     
    599589}
    600590
     591HTMLElementStack::ElementRecord* HTMLElementStack::furthestBlockForFormattingElement(Element* formattingElement) const
     592{
     593    ElementRecord* furthestBlock = 0;
     594    for (ElementRecord* pos = m_top.get(); pos; pos = pos->next()) {
     595        if (pos->element() == formattingElement)
     596            return furthestBlock;
     597        if (pos->stackItem()->isSpecialNode())
     598            furthestBlock = pos;
     599    }
     600    ASSERT_NOT_REACHED();
     601    return 0;
     602}
     603
    601604#ifndef NDEBUG
    602605
  • trunk/Source/WebCore/html/parser/HTMLElementStack.h

    r124277 r126355  
    102102    ElementRecord* topRecord() const;
    103103    ElementRecord* find(Element*) const;
     104    ElementRecord* furthestBlockForFormattingElement(Element*) const;
    104105    ElementRecord* topmost(const AtomicString& tagName) const;
    105106
     
    181182};
    182183   
    183 inline bool isInHTMLNamespace(const HTMLStackItem* item)
    184 {
    185     // A DocumentFragment takes the place of the document element when parsing
    186     // fragments and should be considered in the HTML namespace.
    187     return item->namespaceURI() == HTMLNames::xhtmlNamespaceURI
    188         || item->isDocumentFragmentNode(); // FIXME: Does this also apply to ShadowRoot?
    189 }
    190 
    191 
    192184} // namespace WebCore
    193185
  • trunk/Source/WebCore/html/parser/HTMLStackItem.h

    r124537 r126355  
    3030#include "HTMLNames.h"
    3131#include "HTMLToken.h"
     32#include "MathMLNames.h"
     33#include "SVGNames.h"
    3234
    3335#include <wtf/RefCounted.h>
     
    7880            || hasTagName(HTMLNames::theadTag)
    7981            || hasTagName(HTMLNames::trTag);
     82    }
     83
     84    bool isInHTMLNamespace() const
     85    {
     86        // A DocumentFragment takes the place of the document element when parsing
     87        // fragments and should be considered in the HTML namespace.
     88        return namespaceURI() == HTMLNames::xhtmlNamespaceURI
     89            || isDocumentFragmentNode(); // FIXME: Does this also apply to ShadowRoot?
     90    }
     91
     92    bool isNumberedHeaderElement() const
     93    {
     94        return hasTagName(HTMLNames::h1Tag)
     95            || hasTagName(HTMLNames::h2Tag)
     96            || hasTagName(HTMLNames::h3Tag)
     97            || hasTagName(HTMLNames::h4Tag)
     98            || hasTagName(HTMLNames::h5Tag)
     99            || hasTagName(HTMLNames::h6Tag);
     100    }
     101
     102    bool isTableBodyContextElement() const
     103    {
     104        return hasTagName(HTMLNames::tbodyTag)
     105            || hasTagName(HTMLNames::tfootTag)
     106            || hasTagName(HTMLNames::theadTag);
     107    }
     108
     109    // http://www.whatwg.org/specs/web-apps/current-work/multipage/parsing.html#special
     110    bool isSpecialNode() const
     111    {
     112        if (hasTagName(MathMLNames::miTag)
     113            || hasTagName(MathMLNames::moTag)
     114            || hasTagName(MathMLNames::mnTag)
     115            || hasTagName(MathMLNames::msTag)
     116            || hasTagName(MathMLNames::mtextTag)
     117            || hasTagName(MathMLNames::annotation_xmlTag)
     118            || hasTagName(SVGNames::foreignObjectTag)
     119            || hasTagName(SVGNames::descTag)
     120            || hasTagName(SVGNames::titleTag))
     121            return true;
     122        if (isDocumentFragmentNode())
     123            return true;
     124        if (!isInHTMLNamespace())
     125            return false;
     126        const AtomicString& tagName = localName();
     127        return tagName == HTMLNames::addressTag
     128            || tagName == HTMLNames::appletTag
     129            || tagName == HTMLNames::areaTag
     130            || tagName == HTMLNames::articleTag
     131            || tagName == HTMLNames::asideTag
     132            || tagName == HTMLNames::baseTag
     133            || tagName == HTMLNames::basefontTag
     134            || tagName == HTMLNames::bgsoundTag
     135            || tagName == HTMLNames::blockquoteTag
     136            || tagName == HTMLNames::bodyTag
     137            || tagName == HTMLNames::brTag
     138            || tagName == HTMLNames::buttonTag
     139            || tagName == HTMLNames::captionTag
     140            || tagName == HTMLNames::centerTag
     141            || tagName == HTMLNames::colTag
     142            || tagName == HTMLNames::colgroupTag
     143            || tagName == HTMLNames::commandTag
     144            || tagName == HTMLNames::ddTag
     145            || tagName == HTMLNames::detailsTag
     146            || tagName == HTMLNames::dirTag
     147            || tagName == HTMLNames::divTag
     148            || tagName == HTMLNames::dlTag
     149            || tagName == HTMLNames::dtTag
     150            || tagName == HTMLNames::embedTag
     151            || tagName == HTMLNames::fieldsetTag
     152            || tagName == HTMLNames::figcaptionTag
     153            || tagName == HTMLNames::figureTag
     154            || tagName == HTMLNames::footerTag
     155            || tagName == HTMLNames::formTag
     156            || tagName == HTMLNames::frameTag
     157            || tagName == HTMLNames::framesetTag
     158            || isNumberedHeaderElement()
     159            || tagName == HTMLNames::headTag
     160            || tagName == HTMLNames::headerTag
     161            || tagName == HTMLNames::hgroupTag
     162            || tagName == HTMLNames::hrTag
     163            || tagName == HTMLNames::htmlTag
     164            || tagName == HTMLNames::iframeTag
     165            || tagName == HTMLNames::imgTag
     166            || tagName == HTMLNames::inputTag
     167            || tagName == HTMLNames::isindexTag
     168            || tagName == HTMLNames::liTag
     169            || tagName == HTMLNames::linkTag
     170            || tagName == HTMLNames::listingTag
     171            || tagName == HTMLNames::marqueeTag
     172            || tagName == HTMLNames::menuTag
     173            || tagName == HTMLNames::metaTag
     174            || tagName == HTMLNames::navTag
     175            || tagName == HTMLNames::noembedTag
     176            || tagName == HTMLNames::noframesTag
     177            || tagName == HTMLNames::noscriptTag
     178            || tagName == HTMLNames::objectTag
     179            || tagName == HTMLNames::olTag
     180            || tagName == HTMLNames::pTag
     181            || tagName == HTMLNames::paramTag
     182            || tagName == HTMLNames::plaintextTag
     183            || tagName == HTMLNames::preTag
     184            || tagName == HTMLNames::scriptTag
     185            || tagName == HTMLNames::sectionTag
     186            || tagName == HTMLNames::selectTag
     187            || tagName == HTMLNames::styleTag
     188            || tagName == HTMLNames::summaryTag
     189            || tagName == HTMLNames::tableTag
     190            || isTableBodyContextElement()
     191            || tagName == HTMLNames::tdTag
     192            || tagName == HTMLNames::textareaTag
     193            || tagName == HTMLNames::thTag
     194            || tagName == HTMLNames::titleTag
     195            || tagName == HTMLNames::trTag
     196            || tagName == HTMLNames::ulTag
     197            || tagName == HTMLNames::wbrTag
     198            || tagName == HTMLNames::xmpTag;
    80199    }
    81200
  • trunk/Source/WebCore/html/parser/HTMLTreeBuilder.cpp

    r125846 r126355  
    111111}
    112112
    113 // http://www.whatwg.org/specs/web-apps/current-work/multipage/parsing.html#special
    114 static bool isSpecialNode(const HTMLStackItem* item)
    115 {
    116     if (item->hasTagName(MathMLNames::miTag)
    117         || item->hasTagName(MathMLNames::moTag)
    118         || item->hasTagName(MathMLNames::mnTag)
    119         || item->hasTagName(MathMLNames::msTag)
    120         || item->hasTagName(MathMLNames::mtextTag)
    121         || item->hasTagName(MathMLNames::annotation_xmlTag)
    122         || item->hasTagName(SVGNames::foreignObjectTag)
    123         || item->hasTagName(SVGNames::descTag)
    124         || item->hasTagName(SVGNames::titleTag))
    125         return true;
    126     if (item->isDocumentFragmentNode())
    127         return true;
    128     if (!isInHTMLNamespace(item))
    129         return false;
    130     const AtomicString& tagName = item->localName();
    131     return tagName == addressTag
    132         || tagName == appletTag
    133         || tagName == areaTag
    134         || tagName == articleTag
    135         || tagName == asideTag
    136         || tagName == baseTag
    137         || tagName == basefontTag
    138         || tagName == bgsoundTag
    139         || tagName == blockquoteTag
    140         || tagName == bodyTag
    141         || tagName == brTag
    142         || tagName == buttonTag
    143         || tagName == captionTag
    144         || tagName == centerTag
    145         || tagName == colTag
    146         || tagName == colgroupTag
    147         || tagName == commandTag
    148         || tagName == ddTag
    149         || tagName == detailsTag
    150         || tagName == dirTag
    151         || tagName == divTag
    152         || tagName == dlTag
    153         || tagName == dtTag
    154         || tagName == embedTag
    155         || tagName == fieldsetTag
    156         || tagName == figcaptionTag
    157         || tagName == figureTag
    158         || tagName == footerTag
    159         || tagName == formTag
    160         || tagName == frameTag
    161         || tagName == framesetTag
    162         || isNumberedHeaderTag(tagName)
    163         || tagName == headTag
    164         || tagName == headerTag
    165         || tagName == hgroupTag
    166         || tagName == hrTag
    167         || tagName == htmlTag
    168         || tagName == iframeTag
    169         || tagName == imgTag
    170         || tagName == inputTag
    171         || tagName == isindexTag
    172         || tagName == liTag
    173         || tagName == linkTag
    174         || tagName == listingTag
    175         || tagName == marqueeTag
    176         || tagName == menuTag
    177         || tagName == metaTag
    178         || tagName == navTag
    179         || tagName == noembedTag
    180         || tagName == noframesTag
    181         || tagName == noscriptTag
    182         || tagName == objectTag
    183         || tagName == olTag
    184         || tagName == pTag
    185         || tagName == paramTag
    186         || tagName == plaintextTag
    187         || tagName == preTag
    188         || tagName == scriptTag
    189         || tagName == sectionTag
    190         || tagName == selectTag
    191         || tagName == styleTag
    192         || tagName == summaryTag
    193         || tagName == tableTag
    194         || isTableBodyContextTag(tagName)
    195         || tagName == tdTag
    196         || tagName == textareaTag
    197         || tagName == thTag
    198         || tagName == titleTag
    199         || tagName == trTag
    200         || tagName == ulTag
    201         || tagName == wbrTag
    202         || tagName == xmpTag;
    203 }
    204 
    205113static bool isNonAnchorNonNobrFormattingTag(const AtomicString& tagName)
    206114{
     
    482390
    483391    bool inForeignContent = !m_tree.isEmpty()
    484         && !isInHTMLNamespace(m_tree.currentStackItem())
     392        && !m_tree.currentStackItem()->isInHTMLNamespace()
    485393        && !HTMLElementStack::isHTMLIntegrationPoint(m_tree.currentStackItem())
    486394        && !HTMLElementStack::isMathMLTextIntegrationPoint(m_tree.currentStackItem());
     
    641549            break;
    642550        }
    643         if (isSpecialNode(item.get()) && !item->hasTagName(addressTag) && !item->hasTagName(divTag) && !item->hasTagName(pTag))
     551        if (item->isSpecialNode() && !item->hasTagName(addressTag) && !item->hasTagName(divTag) && !item->hasTagName(pTag))
    644552            break;
    645553        nodeRecord = nodeRecord->next();
     
    817725    if (isNumberedHeaderTag(token->name())) {
    818726        processFakePEndTagIfPInButtonScope();
    819         if (isNumberedHeaderTag(m_tree.currentStackItem()->localName())) {
     727        if (m_tree.currentStackItem()->isNumberedHeaderElement()) {
    820728            parseError(token);
    821729            m_tree.openElements()->pop();
     
    14951403            return;
    14961404        }
    1497         if (isSpecialNode(item.get())) {
     1405        if (item->isSpecialNode()) {
    14981406            parseError(token);
    14991407            return;
     
    15011409        record = record->next();
    15021410    }
    1503 }
    1504 
    1505 // FIXME: This probably belongs on HTMLElementStack.
    1506 HTMLElementStack::ElementRecord* HTMLTreeBuilder::furthestBlockForFormattingElement(Element* formattingElement)
    1507 {
    1508     HTMLElementStack::ElementRecord* furthestBlock = 0;
    1509     HTMLElementStack::ElementRecord* record = m_tree.openElements()->topRecord();
    1510     for (; record; record = record->next()) {
    1511         if (record->element() == formattingElement)
    1512             return furthestBlock;
    1513         if (isSpecialNode(record->stackItem().get()))
    1514             furthestBlock = record;
    1515     }
    1516     ASSERT_NOT_REACHED();
    1517     return 0;
    15181411}
    15191412
     
    15451438            parseError(token);
    15461439        // 2.
    1547         HTMLElementStack::ElementRecord* furthestBlock = furthestBlockForFormattingElement(formattingElement);
     1440        HTMLElementStack::ElementRecord* furthestBlock = m_tree.openElements()->furthestBlockForFormattingElement(formattingElement);
    15481441        // 3.
    15491442        if (!furthestBlock) {
     
    26572550        return false;
    26582551    HTMLStackItem* item = m_tree.currentStackItem();
    2659     if (isInHTMLNamespace(item))
     2552    if (item->isInHTMLNamespace())
    26602553        return false;
    26612554    if (HTMLElementStack::isMathMLTextIntegrationPoint(item)) {
     
    27572650            return;
    27582651        }
    2759         if (!isInHTMLNamespace(m_tree.currentStackItem())) {
     2652        if (!m_tree.currentStackItem()->isInHTMLNamespace()) {
    27602653            // FIXME: This code just wants an Element* iterator, instead of an ElementRecord*
    27612654            HTMLElementStack::ElementRecord* nodeRecord = m_tree.openElements()->topRecord();
     
    27692662                nodeRecord = nodeRecord->next();
    27702663
    2771                 if (isInHTMLNamespace(nodeRecord->stackItem().get()))
     2664                if (nodeRecord->stackItem()->isInHTMLNamespace())
    27722665                    break;
    27732666            }
  • trunk/Source/WebCore/html/parser/HTMLTreeBuilder.h

    r123577 r126355  
    175175    Vector<Attribute> attributesForIsindexInput(AtomicHTMLToken*);
    176176
    177     HTMLElementStack::ElementRecord* furthestBlockForFormattingElement(Element*);
    178177    void callTheAdoptionAgency(AtomicHTMLToken*);
    179178
Note: See TracChangeset for help on using the changeset viewer.