Changeset 137233 in webkit


Ignore:
Timestamp:
Dec 10, 2012 5:42:16 PM (11 years ago)
Author:
morrita@google.com
Message:

[Shadow DOM][Refactoring] HTMLContentElement,HTMLShadowElement::m_registeredWithShadowRoot should be moved to InsertionPoint
https://bugs.webkit.org/show_bug.cgi?id=104516

Reviewed by Dimitri Glazkov.

This change pulls duplicated code in removedFrom() and
insertedInto() of both both HTMLShadowElement and
HTMLContentElement to their super class InsertionPoint.

This is a part of effor that encapsulate node distribution algorithm to
ContentDistributor and its family.

No new tests, no behavior change.

  • dom/ShadowRoot.cpp:

(WebCore::ShadowRoot::registerInsertionPoint): Added.
(WebCore::ShadowRoot::unregisterInsertionPoint): Added.

  • dom/ShadowRoot.h:

(ShadowRoot):

  • html/shadow/ContentDistributor.cpp:

(WebCore::ShadowRootContentDistributionData::regiterInsertionPoint): Generalized two methods for <content> and <shadow>.
(WebCore):
(WebCore::ShadowRootContentDistributionData::unregisterInsertionPoint): Ditto.

  • html/shadow/ContentDistributor.h:

(ShadowRootContentDistributionData):

  • html/shadow/HTMLContentElement.cpp:

(WebCore::HTMLContentElement::HTMLContentElement):

  • html/shadow/HTMLContentElement.h:
  • html/shadow/HTMLShadowElement.cpp:

(WebCore::HTMLShadowElement::HTMLShadowElement):

  • html/shadow/HTMLShadowElement.h:
  • html/shadow/InsertionPoint.cpp:

(WebCore::InsertionPoint::InsertionPoint):
(WebCore::InsertionPoint::insertedInto): Pulled up from subclasses
(WebCore::InsertionPoint::removedFrom): Pulled up from subclasses

  • html/shadow/InsertionPoint.h:

(InsertionPoint):

Location:
trunk/Source/WebCore
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r137230 r137233  
     12012-12-10  Hajime Morrita  <morrita@google.com>
     2
     3        [Shadow DOM][Refactoring] HTMLContentElement,HTMLShadowElement::m_registeredWithShadowRoot should be moved to InsertionPoint
     4        https://bugs.webkit.org/show_bug.cgi?id=104516
     5
     6        Reviewed by Dimitri Glazkov.
     7
     8        This change pulls duplicated code in removedFrom() and
     9        insertedInto() of both both HTMLShadowElement and
     10        HTMLContentElement to their super class InsertionPoint.
     11
     12        This is a part of effor that encapsulate node distribution algorithm to
     13        ContentDistributor and its family.
     14
     15        No new tests, no behavior change.
     16
     17        * dom/ShadowRoot.cpp:
     18        (WebCore::ShadowRoot::registerInsertionPoint): Added.
     19        (WebCore::ShadowRoot::unregisterInsertionPoint): Added.
     20        * dom/ShadowRoot.h:
     21        (ShadowRoot):
     22        * html/shadow/ContentDistributor.cpp:
     23        (WebCore::ShadowRootContentDistributionData::regiterInsertionPoint): Generalized two methods for <content> and <shadow>.
     24        (WebCore):
     25        (WebCore::ShadowRootContentDistributionData::unregisterInsertionPoint): Ditto.
     26        * html/shadow/ContentDistributor.h:
     27        (ShadowRootContentDistributionData):
     28        * html/shadow/HTMLContentElement.cpp:
     29        (WebCore::HTMLContentElement::HTMLContentElement):
     30        * html/shadow/HTMLContentElement.h:
     31        * html/shadow/HTMLShadowElement.cpp:
     32        (WebCore::HTMLShadowElement::HTMLShadowElement):
     33        * html/shadow/HTMLShadowElement.h:
     34        * html/shadow/InsertionPoint.cpp:
     35        (WebCore::InsertionPoint::InsertionPoint):
     36        (WebCore::InsertionPoint::insertedInto): Pulled up from subclasses
     37        (WebCore::InsertionPoint::removedFrom): Pulled up from subclasses
     38        * html/shadow/InsertionPoint.h:
     39        (InsertionPoint):
     40
    1412012-12-10  Jon Lee  <jonlee@apple.com>
    242
  • trunk/Source/WebCore/dom/ShadowRoot.cpp

    r136924 r137233  
    359359}   
    360360
    361 void ShadowRoot::registerShadowElement()
    362 {
    363     ensureDistributionData()->incrementNumberOfShadowElementChildren();
    364 }
    365 
    366 void ShadowRoot::unregisterShadowElement()
    367 {
    368     distributionData()->decrementNumberOfShadowElementChildren();
     361void ShadowRoot::registerInsertionPoint(InsertionPoint* point)
     362{
     363    ensureDistributionData()->regiterInsertionPoint(this, point);
     364}
     365
     366void ShadowRoot::unregisterInsertionPoint(InsertionPoint* point)
     367{
     368    ensureDistributionData()->unregisterInsertionPoint(this, point);
    369369}
    370370
     
    375375
    376376    return distributionData()->hasShadowElementChildren();
    377 }
    378 
    379 void ShadowRoot::registerContentElement()
    380 {
    381     ensureDistributionData()->incrementNumberOfContentElementChildren();
    382 }
    383 
    384 void ShadowRoot::unregisterContentElement()
    385 {
    386     distributionData()->decrementNumberOfContentElementChildren();
    387377}
    388378
  • trunk/Source/WebCore/dom/ShadowRoot.h

    r136924 r137233  
    9292    void setAssignedTo(InsertionPoint*);
    9393
    94     void registerShadowElement();
    95     void unregisterShadowElement();
    9694    bool hasShadowInsertionPoint() const;
    97 
    98     void registerContentElement();
    99     void unregisterContentElement();
    10095    bool hasContentElement() const;
    10196
     97    void registerInsertionPoint(InsertionPoint*);
     98    void unregisterInsertionPoint(InsertionPoint*);
     99   
    102100    void registerElementShadow();
    103101    void unregisterElementShadow();
  • trunk/Source/WebCore/html/shadow/ContentDistributor.cpp

    r137221 r137233  
    111111}
    112112
     113void ShadowRootContentDistributionData::regiterInsertionPoint(ShadowRoot* scope, InsertionPoint* point)
     114{
     115    switch (point->insertionPointType()) {
     116    case InsertionPoint::ShadowInsertionPoint:
     117        ++m_numberOfShadowElementChildren;
     118        break;
     119    case InsertionPoint::ContentInsertionPoint:
     120        ++m_numberOfContentElementChildren;
     121        scope->owner()->setShouldCollectSelectFeatureSet();
     122        break;
     123    }
     124
     125    invalidateInsertionPointList();
     126}
     127
     128void ShadowRootContentDistributionData::unregisterInsertionPoint(ShadowRoot* scope, InsertionPoint* point)
     129{
     130    switch (point->insertionPointType()) {
     131    case InsertionPoint::ShadowInsertionPoint:
     132        ASSERT(m_numberOfShadowElementChildren > 0);
     133        --m_numberOfShadowElementChildren;
     134        break;
     135    case InsertionPoint::ContentInsertionPoint:
     136        ASSERT(m_numberOfContentElementChildren > 0);
     137        --m_numberOfContentElementChildren;
     138        if (scope->owner())
     139            scope->owner()->setShouldCollectSelectFeatureSet();
     140        break;
     141    }
     142
     143    invalidateInsertionPointList();
     144}
     145
     146
    113147ContentDistributor::ContentDistributor()
    114148    : m_validity(Undetermined)
  • trunk/Source/WebCore/html/shadow/ContentDistributor.h

    r137119 r137233  
    7878    void setInsertionPointAssignedTo(InsertionPoint* insertionPoint) { m_insertionPointAssignedTo = insertionPoint; }
    7979
    80     void incrementNumberOfShadowElementChildren() { ++m_numberOfShadowElementChildren; invalidateInsertionPointList(); }
    81     void decrementNumberOfShadowElementChildren() { ASSERT(m_numberOfShadowElementChildren > 0); --m_numberOfShadowElementChildren; invalidateInsertionPointList(); }
     80    void regiterInsertionPoint(ShadowRoot*, InsertionPoint*);
     81    void unregisterInsertionPoint(ShadowRoot*, InsertionPoint*);
    8282    bool hasShadowElementChildren() const { return m_numberOfShadowElementChildren > 0; }
    83 
    84     void incrementNumberOfContentElementChildren() { ++m_numberOfContentElementChildren; invalidateInsertionPointList(); }
    85     void decrementNumberOfContentElementChildren() { ASSERT(m_numberOfContentElementChildren > 0); --m_numberOfContentElementChildren; invalidateInsertionPointList(); }
    8683    bool hasContentElementChildren() const { return m_numberOfContentElementChildren > 0; }
    8784
  • trunk/Source/WebCore/html/shadow/HTMLContentElement.cpp

    r136924 r137233  
    6565HTMLContentElement::HTMLContentElement(const QualifiedName& name, Document* document)
    6666    : InsertionPoint(name, document)
    67     , m_registeredWithShadowRoot(false)
    6867    , m_shouldParseSelectorList(false)
    6968    , m_isValidSelector(true)
     
    109108    } else
    110109        InsertionPoint::parseAttribute(name, value);
    111 }
    112 
    113 Node::InsertionNotificationRequest HTMLContentElement::insertedInto(ContainerNode* insertionPoint)
    114 {
    115     InsertionPoint::insertedInto(insertionPoint);
    116 
    117     if (insertionPoint->inDocument() && isActive()) {
    118         ShadowRoot* root = containingShadowRoot();
    119         root->registerContentElement();
    120         root->owner()->setShouldCollectSelectFeatureSet();
    121         m_registeredWithShadowRoot = true;
    122     }
    123 
    124     return InsertionDone;
    125 }
    126 
    127 void HTMLContentElement::removedFrom(ContainerNode* insertionPoint)
    128 {
    129     if (insertionPoint->inDocument() && m_registeredWithShadowRoot) {
    130         ShadowRoot* root = containingShadowRoot();
    131         if (!root)
    132             root = insertionPoint->containingShadowRoot();
    133         if (root)
    134             root->unregisterContentElement();
    135         m_registeredWithShadowRoot = false;
    136 
    137         if (ElementShadow* elementShadow = root ? root->owner() : 0)
    138             elementShadow->setShouldCollectSelectFeatureSet();
    139     }
    140     InsertionPoint::removedFrom(insertionPoint);
    141110}
    142111
  • trunk/Source/WebCore/html/shadow/HTMLContentElement.h

    r135069 r137233  
    5050    virtual bool isSelectValid();
    5151    virtual const CSSSelectorList& selectorList();
     52    virtual Type insertionPointType() const OVERRIDE { return ContentInsertionPoint; }
    5253
    5354protected:
    5455    HTMLContentElement(const QualifiedName&, Document*);
    55 
    56     virtual InsertionNotificationRequest insertedInto(ContainerNode*) OVERRIDE;
    57     virtual void removedFrom(ContainerNode*) OVERRIDE;
    5856
    5957private:
     
    6159    void ensureSelectParsed();
    6260    bool validateSelect() const;
    63 
    64     bool m_registeredWithShadowRoot;
    6561
    6662    bool m_shouldParseSelectorList;
  • trunk/Source/WebCore/html/shadow/HTMLShadowElement.cpp

    r136924 r137233  
    4242inline HTMLShadowElement::HTMLShadowElement(const QualifiedName& tagName, Document* document)
    4343    : InsertionPoint(tagName, document)
    44     , m_registeredWithShadowRoot(false)
    4544{
    4645    ASSERT(hasTagName(HTMLNames::shadowTag));
     
    6160}
    6261
    63 Node::InsertionNotificationRequest HTMLShadowElement::insertedInto(ContainerNode* insertionPoint)
    64 {
    65     InsertionPoint::insertedInto(insertionPoint);
    66 
    67     if (insertionPoint->inDocument() && isActive()) {
    68         if (ShadowRoot* root = containingShadowRoot()) {
    69             root->registerShadowElement();
    70             m_registeredWithShadowRoot = true;
    71         }
    72     }
    73 
    74     return InsertionDone;
    75 }
    76 
    77 void HTMLShadowElement::removedFrom(ContainerNode* insertionPoint)
    78 {
    79     if (insertionPoint->inDocument() && m_registeredWithShadowRoot) {
    80         ShadowRoot* root = containingShadowRoot();
    81         if (!root)
    82             root = insertionPoint->containingShadowRoot();
    83         if (root)
    84             root->unregisterShadowElement();
    85         m_registeredWithShadowRoot = false;
    86     }
    87     InsertionPoint::removedFrom(insertionPoint);
    88 }
    89 
    9062const CSSSelectorList& HTMLShadowElement::emptySelectorList()
    9163{
  • trunk/Source/WebCore/html/shadow/HTMLShadowElement.h

    r133992 r137233  
    4646    virtual bool isSelectValid() OVERRIDE { return true; }
    4747    virtual const CSSSelectorList& selectorList() { return emptySelectorList(); }
    48 
    49 protected:
    50     virtual InsertionNotificationRequest insertedInto(ContainerNode*) OVERRIDE;
    51     virtual void removedFrom(ContainerNode*) OVERRIDE;
     48    virtual Type insertionPointType() const OVERRIDE { return ShadowInsertionPoint; }
    5249
    5350private:
  • trunk/Source/WebCore/html/shadow/InsertionPoint.cpp

    r137119 r137233  
    4444InsertionPoint::InsertionPoint(const QualifiedName& tagName, Document* document)
    4545    : HTMLElement(tagName, document, CreateInsertionPoint)
     46    , m_registeredWithShadowRoot(false)
    4647{
    4748}
     
    127128            root->owner()->setValidityUndetermined();
    128129            root->owner()->invalidateDistribution();
     130            if (isActive() && !m_registeredWithShadowRoot) {
     131                m_registeredWithShadowRoot = true;
     132                root->registerInsertionPoint(this);
     133            }
    129134        }
    130135    }
     
    141146
    142147        // host can be null when removedFrom() is called from ElementShadow destructor.
    143         if (root && root->host())
    144             root->owner()->invalidateDistribution();
     148        ElementShadow* rootOwner = root ? root->owner() : 0;
     149        if (rootOwner)
     150            rootOwner->invalidateDistribution();
    145151
    146152        // Since this insertion point is no longer visible from the shadow subtree, it need to clean itself up.
    147153        clearDistribution();
     154
     155        if (m_registeredWithShadowRoot) {
     156            m_registeredWithShadowRoot = false;
     157            if (root)
     158                root->unregisterInsertionPoint(this);
     159        }
    148160    }
    149161
  • trunk/Source/WebCore/html/shadow/InsertionPoint.h

    r137119 r137233  
    4444class InsertionPoint : public HTMLElement {
    4545public:
     46    enum Type {
     47        ShadowInsertionPoint,
     48        ContentInsertionPoint
     49    };
     50
    4651    virtual ~InsertionPoint();
    4752
     
    5762    virtual bool isSelectValid() = 0;
    5863    virtual const CSSSelectorList& selectorList() = 0;
     64    virtual Type insertionPointType() const = 0;
    5965
    6066    bool resetStyleInheritance() const;
     
    8692
    8793    ContentDistribution m_distribution;
     94    bool m_registeredWithShadowRoot;
    8895};
    8996
Note: See TracChangeset for help on using the changeset viewer.