Changeset 152290 in webkit


Ignore:
Timestamp:
Jul 2, 2013 6:48:16 AM (11 years ago)
Author:
kangil.han@samsung.com
Message:

is/toHTMLStyleElement should use Element* for its argument
https://bugs.webkit.org/show_bug.cgi?id=118286

Reviewed by Andreas Kling.

To reduce unnecessary call of isElementNode(), this patch replaces argument
of is/toHTMLStyleElement from Node* to Element*. Plus, use Element::hasTagName
in collectActiveStyleSheets function for minor code refactoring since
its cost is cheaper than Node::hasTagName.

  • css/CSSStyleSheet.cpp:

(WebCore::isAcceptableCSSStyleSheetParent):

  • css/StyleScopeResolver.cpp:

(WebCore::StyleScopeResolver::scopeFor):

  • dom/DocumentStyleSheetCollection.cpp:

(WebCore::DocumentStyleSheetCollection::collectActiveStyleSheets):

  • dom/Node.cpp:

(WebCore::Node::numberOfScopedHTMLStyleChildren):

  • html/HTMLStyleElement.h:

(WebCore::isHTMLStyleElement):
(WebCore::toHTMLStyleElement):

Location:
trunk/Source/WebCore
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r152286 r152290  
     12013-07-02  Kangil Han  <kangil.han@samsung.com>
     2
     3        is/toHTMLStyleElement should use Element* for its argument
     4        https://bugs.webkit.org/show_bug.cgi?id=118286
     5
     6        Reviewed by Andreas Kling.
     7
     8        To reduce unnecessary call of isElementNode(), this patch replaces argument
     9        of is/toHTMLStyleElement from Node* to Element*. Plus, use Element::hasTagName
     10        in collectActiveStyleSheets function for minor code refactoring since
     11        its cost is cheaper than Node::hasTagName.
     12
     13        * css/CSSStyleSheet.cpp:
     14        (WebCore::isAcceptableCSSStyleSheetParent):
     15        * css/StyleScopeResolver.cpp:
     16        (WebCore::StyleScopeResolver::scopeFor):
     17        * dom/DocumentStyleSheetCollection.cpp:
     18        (WebCore::DocumentStyleSheetCollection::collectActiveStyleSheets):
     19        * dom/Node.cpp:
     20        (WebCore::Node::numberOfScopedHTMLStyleChildren):
     21        * html/HTMLStyleElement.h:
     22        (WebCore::isHTMLStyleElement):
     23        (WebCore::toHTMLStyleElement):
     24
    1252013-07-02  Ryosuke Niwa  <rniwa@webkit.org>
    226
  • trunk/Source/WebCore/css/CSSStyleSheet.cpp

    r151911 r152290  
    6666        || parentNode->isDocumentNode()
    6767        || parentNode->hasTagName(HTMLNames::linkTag)
    68         || isHTMLStyleElement(parentNode)
     68        || (parentNode->isElementNode() && isHTMLStyleElement(toElement(parentNode)))
    6969#if ENABLE(SVG)
    7070        || parentNode->hasTagName(SVGNames::styleTag)
  • trunk/Source/WebCore/css/StyleScopeResolver.cpp

    r151911 r152290  
    6161        return 0;
    6262    Node* ownerNode = sheet->ownerNode();
    63     if (!ownerNode || !ownerNode->isHTMLElement() || !isHTMLStyleElement(ownerNode))
    64         return 0;
    65 
    66     HTMLStyleElement* styleElement = toHTMLStyleElement(ownerNode);
     63    if (!ownerNode || !ownerNode->isHTMLElement() || !isHTMLStyleElement(toElement(ownerNode)))
     64        return 0;
     65
     66    HTMLStyleElement* styleElement = toHTMLStyleElement(toElement(ownerNode));
    6767    if (!styleElement->scoped())
    6868        return styleElement->isInShadowTree() ? styleElement->containingShadowRoot() : 0;
  • trunk/Source/WebCore/dom/DocumentStyleSheetCollection.cpp

    r151911 r152290  
    300300            AtomicString title = e->getAttribute(titleAttr);
    301301            bool enabledViaScript = false;
    302             if (e->hasLocalName(linkTag)) {
     302            if (e->hasTagName(linkTag)) {
    303303                // <LINK> element
    304304                HTMLLinkElement* linkElement = static_cast<HTMLLinkElement*>(n);
     
    323323            // set of sheets that will be enabled.
    324324#if ENABLE(SVG)
    325             if (n->isSVGElement() && n->hasTagName(SVGNames::styleTag))
     325            if (e->hasTagName(SVGNames::styleTag))
    326326                sheet = static_cast<SVGStyleElement*>(n)->sheet();
    327327            else
    328328#endif
    329             if (e->hasLocalName(linkTag))
    330                 sheet = static_cast<HTMLLinkElement*>(n)->sheet();
    331             else
    332                 // <STYLE> element
    333                 sheet = toHTMLStyleElement(n)->sheet();
     329            {
     330                if (e->hasTagName(linkTag))
     331                    sheet = static_cast<HTMLLinkElement*>(n)->sheet();
     332                else
     333                    // <STYLE> element
     334                    sheet = toHTMLStyleElement(e)->sheet();
     335            }
    334336            // Check to see if this sheet belongs to a styleset
    335337            // (thus making it PREFERRED or ALTERNATE rather than
     
    343345                    // us as the preferred set. Otherwise, just ignore
    344346                    // this sheet.
    345                     if (e->hasLocalName(styleTag) || !rel.contains("alternate"))
     347                    if (e->hasTagName(styleTag) || !rel.contains("alternate"))
    346348                        m_preferredStylesheetSetName = m_selectedStylesheetSetName = title;
    347349                }
  • trunk/Source/WebCore/dom/Node.cpp

    r152203 r152290  
    25312531{
    25322532    size_t count = 0;
    2533     for (Node* child = firstChild(); child; child = child->nextSibling()) {
    2534         if (isHTMLStyleElement(child) && toHTMLStyleElement(child)->isRegisteredAsScoped())
     2533    for (Element* element = ElementTraversal::firstWithin(this); element; element = ElementTraversal::next(element, this)) {
     2534        if (isHTMLStyleElement(element) && toHTMLStyleElement(element)->isRegisteredAsScoped())
    25352535            count++;
    25362536    }
  • trunk/Source/WebCore/html/HTMLStyleElement.h

    r151911 r152290  
    9898};
    9999
    100 inline bool isHTMLStyleElement(Node* node)
     100inline bool isHTMLStyleElement(Element* element)
    101101{
    102     return node->hasTagName(HTMLNames::styleTag);
     102    return element->hasTagName(HTMLNames::styleTag);
    103103}
    104104
    105 inline HTMLStyleElement* toHTMLStyleElement(Node* node)
     105inline HTMLStyleElement* toHTMLStyleElement(Element* element)
    106106{
    107     ASSERT_WITH_SECURITY_IMPLICATION(!node || isHTMLStyleElement(node));
    108     return static_cast<HTMLStyleElement*>(node);
     107    ASSERT_WITH_SECURITY_IMPLICATION(!element || isHTMLStyleElement(element));
     108    return static_cast<HTMLStyleElement*>(element);
    109109}
    110110
Note: See TracChangeset for help on using the changeset viewer.