Changeset 141313 in webkit


Ignore:
Timestamp:
Jan 30, 2013 2:30:54 PM (11 years ago)
Author:
esprehn@chromium.org
Message:

Clean up interface to ShadowRoot
https://bugs.webkit.org/show_bug.cgi?id=108300

Reviewed by Dimitri Glazkov.

Lots of general clean up to ShadowRoot removing unused headers and forward
declarations, moving short inline methods into the class definition so it's
easier to understand what methods do what, and replacing macros with methods
with inline methods.

No new tests, just refactoring.

  • dom/ElementShadow.cpp:

(WebCore::ElementShadow::addShadowRoot):
(WebCore::ElementShadow::removeAllShadowRoots):

  • dom/ShadowRoot.cpp:

(WebCore::ShadowRoot::ShadowRoot):
(WebCore::ShadowRoot::setInnerHTML): Use isOrphan instead of macro.
(WebCore::ShadowRoot::setApplyAuthorStyles): Use isOrphan instead of macro.
(WebCore::ShadowRoot::setResetStyleInheritance): Use isOrphan instead of macro.
(WebCore::ShadowRoot::childrenChanged): Use isOrphan instead of macro.

  • dom/ShadowRoot.h:

(WebCore::ShadowRoot::setHost): Removed.
(WebCore::ShadowRoot::host):
(WebCore::ShadowRoot::owner):
(ShadowRoot):
(WebCore::ShadowRoot::isOrphan): Replacement of GuardOrphanShadowRoot macro.

Location:
trunk/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r141306 r141313  
     12013-01-30  Elliott Sprehn  <esprehn@chromium.org>
     2
     3        Clean up interface to ShadowRoot
     4        https://bugs.webkit.org/show_bug.cgi?id=108300
     5
     6        Reviewed by Dimitri Glazkov.
     7
     8        Lots of general clean up to ShadowRoot removing unused headers and forward
     9        declarations, moving short inline methods into the class definition so it's
     10        easier to understand what methods do what, and replacing macros with methods
     11        with inline methods.
     12
     13        No new tests, just refactoring.
     14
     15        * dom/ElementShadow.cpp:
     16        (WebCore::ElementShadow::addShadowRoot):
     17        (WebCore::ElementShadow::removeAllShadowRoots):
     18        * dom/ShadowRoot.cpp:
     19        (WebCore::ShadowRoot::ShadowRoot):
     20        (WebCore::ShadowRoot::setInnerHTML): Use isOrphan instead of macro.
     21        (WebCore::ShadowRoot::setApplyAuthorStyles): Use isOrphan instead of macro.
     22        (WebCore::ShadowRoot::setResetStyleInheritance): Use isOrphan instead of macro.
     23        (WebCore::ShadowRoot::childrenChanged): Use isOrphan instead of macro.
     24        * dom/ShadowRoot.h:
     25        (WebCore::ShadowRoot::setHost): Removed.
     26        (WebCore::ShadowRoot::host):
     27        (WebCore::ShadowRoot::owner):
     28        (ShadowRoot):
     29        (WebCore::ShadowRoot::isOrphan): Replacement of GuardOrphanShadowRoot macro.
     30
    1312013-01-30  Ryosuke Niwa  <rniwa@webkit.org>
    232
  • trunk/Source/WebCore/dom/ElementShadow.cpp

    r141292 r141313  
    3737    RefPtr<ShadowRoot> shadowRoot = ShadowRoot::create(shadowHost->document(), type);
    3838
    39     shadowRoot->setHost(shadowHost);
     39    shadowRoot->setParentOrHostNode(shadowHost);
     40    shadowRoot->setParentTreeScope(shadowHost->treeScope());
    4041    m_shadowRoots.push(shadowRoot.get());
    4142    m_distributor.didShadowBoundaryChange(shadowHost);
     
    6970
    7071        m_shadowRoots.removeHead();
    71         oldRoot->setHost(0);
     72        oldRoot->setParentOrHostNode(0);
    7273        oldRoot->setParentTreeScope(shadowHost->document());
    7374        oldRoot->setPrev(0);
  • trunk/Source/WebCore/dom/ShadowRoot.cpp

    r141218 r141313  
    2929
    3030#include "ContentDistributor.h"
    31 #include "DOMSelection.h"
    32 #include "DOMWindow.h"
    33 #include "Document.h"
    34 #include "DocumentFragment.h"
    35 #include "Element.h"
    3631#include "ElementShadow.h"
    37 #include "HTMLContentElement.h"
    38 #include "HTMLInputElement.h"
    39 #include "HTMLNames.h"
    40 #include "HTMLTextAreaElement.h"
    4132#include "HistogramSupport.h"
    4233#include "InsertionPoint.h"
    43 #include "NodeRareData.h"
    4434#include "RuntimeEnabledFeatures.h"
    45 #include "SVGNames.h"
    4635#include "StyleResolver.h"
    4736#include "Text.h"
    4837#include "markup.h"
    49 
    50 // FIXME: This shouldn't happen. https://bugs.webkit.org/show_bug.cgi?id=88834
    51 #define GuardOrphanShadowRoot(rejectStatement) \
    52     if (!this->host()) {                       \
    53         rejectStatement;                       \
    54         return;                                \
    55     }
    5638
    5739namespace WebCore {
     
    6749    ShadowRootUsageOriginWeb = 0,
    6850    ShadowRootUsageOriginNotWeb,
    69     ShadowRootUsageOriginTypes
     51    ShadowRootUsageOriginMax
    7052};
    71 
    72 static inline ShadowRootUsageOriginType determineUsageType(Document* document)
    73 {
    74     // Enables only on CHROMIUM since this cost won't worth paying for platforms which don't collect this metrics.
    75 #if PLATFORM(CHROMIUM)
    76     return document->url().string().startsWith("http") ? ShadowRootUsageOriginWeb : ShadowRootUsageOriginNotWeb;
    77 #else
    78     UNUSED_PARAM(document);
    79     return ShadowRootUsageOriginWeb;
    80 #endif
    81 }
    8253
    8354ShadowRoot::ShadowRoot(Document* document, ShadowRootType type)
     
    9566    setTreeScope(this);
    9667
    97     if (type == ShadowRoot::AuthorShadowRoot)
    98         HistogramSupport::histogramEnumeration("WebCore.ShadowRoot.constructor", determineUsageType(document), ShadowRootUsageOriginTypes);
     68#if PLATFORM(CHROMIUM)
     69    if (type == ShadowRoot::AuthorShadowRoot) {
     70        ShadowRootUsageOriginType usageType = document->url().protocolIsInHTTPFamily() ? ShadowRootUsageOriginWeb : ShadowRootUsageOriginNotWeb;
     71        HistogramSupport::histogramEnumeration("WebCore.ShadowRoot.constructor", usageType, ShadowRootUsageOriginMax);
     72    }
     73#endif
    9974}
    10075
     
    11590}
    11691
    117 PassRefPtr<Node> ShadowRoot::cloneNode(bool)
    118 {
    119     // ShadowRoot should not be arbitrarily cloned.
    120     return 0;
    121 }
    122 
    12392PassRefPtr<Node> ShadowRoot::cloneNode(bool, ExceptionCode& ec)
    12493{
     
    134103void ShadowRoot::setInnerHTML(const String& markup, ExceptionCode& ec)
    135104{
    136     GuardOrphanShadowRoot(ec = INVALID_ACCESS_ERR);
     105    if (isOrphan()) {
     106        ec = INVALID_ACCESS_ERR;
     107        return;
     108    }
    137109
    138110    if (RefPtr<DocumentFragment> fragment = createFragmentForInnerOuterHTML(markup, host(), AllowScriptingContent, ec))
     
    175147}
    176148
    177 ElementShadow* ShadowRoot::owner() const
    178 {
    179     if (host())
    180         return host()->shadow();
    181     return 0;
    182 }
    183 
    184 bool ShadowRoot::applyAuthorStyles() const
    185 {
    186     return m_applyAuthorStyles;
    187 }
    188 
    189149void ShadowRoot::setApplyAuthorStyles(bool value)
    190150{
    191     GuardOrphanShadowRoot({ });
     151    if (isOrphan())
     152        return;
    192153
    193154    if (m_applyAuthorStyles != value) {
     
    197158}
    198159
    199 bool ShadowRoot::resetStyleInheritance() const
    200 {
    201     return m_resetStyleInheritance;
    202 }
    203 
    204160void ShadowRoot::setResetStyleInheritance(bool value)
    205161{
    206     GuardOrphanShadowRoot({ });
     162    if (isOrphan())
     163        return;
    207164
    208165    if (value != m_resetStyleInheritance) {
     
    259216void ShadowRoot::childrenChanged(bool changedByParser, Node* beforeChange, Node* afterChange, int childCountDelta)
    260217{
    261     GuardOrphanShadowRoot({ });
     218    if (isOrphan())
     219        return;
    262220
    263221    ContainerNode::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta);
  • trunk/Source/WebCore/dom/ShadowRoot.h

    r141218 r141313  
    3838namespace WebCore {
    3939
    40 class Document;
    41 class DOMSelection;
    4240class ElementShadow;
    43 class InsertionPoint;
    4441class ScopeContentDistribution;
    4542
     
    6360    void recalcStyle(StyleChange);
    6461
    65     virtual bool applyAuthorStyles() const OVERRIDE;
     62    virtual bool applyAuthorStyles() const OVERRIDE { return m_applyAuthorStyles; }
    6663    void setApplyAuthorStyles(bool);
    67     virtual bool resetStyleInheritance() const OVERRIDE;
     64    virtual bool resetStyleInheritance() const OVERRIDE { return m_resetStyleInheritance; }
    6865    void setResetStyleInheritance(bool);
    6966
    70     Element* host() const;
    71     void setHost(Element*);
    72     ElementShadow* owner() const;
     67    Element* host() const { return toElement(parentOrHostNode()); }
     68    ElementShadow* owner() const { return host() ? host()->shadow() : 0; }
    7369
    7470    String innerHTML() const;
     
    104100    ShadowRoot(Document*, ShadowRootType);
    105101    virtual ~ShadowRoot();
    106     virtual PassRefPtr<Node> cloneNode(bool deep);
    107     virtual bool childTypeAllowed(NodeType) const;
     102
     103    virtual bool childTypeAllowed(NodeType) const OVERRIDE;
    108104    virtual void childrenChanged(bool changedByParser, Node* beforeChange, Node* afterChange, int childCountDelta) OVERRIDE;
     105
     106    // ShadowRoots should never be cloned.
     107    virtual PassRefPtr<Node> cloneNode(bool) OVERRIDE { return 0; }
     108
     109    // FIXME: This shouldn't happen. https://bugs.webkit.org/show_bug.cgi?id=88834
     110    bool isOrphan() const { return !host(); }
    109111
    110112    ShadowRoot* m_prev;
     
    117119    unsigned m_registeredWithParentShadowRoot : 1;
    118120};
    119 
    120 inline Element* ShadowRoot::host() const
    121 {
    122     return toElement(parentOrHostNode());
    123 }
    124 
    125 inline void ShadowRoot::setHost(Element* host)
    126 {
    127     setParentOrHostNode(host);
    128     if (host)
    129         setParentTreeScope(host->treeScope());
    130 }
    131121
    132122inline Element* ShadowRoot::activeElement() const
Note: See TracChangeset for help on using the changeset viewer.