Changeset 137233 in webkit
- Timestamp:
- Dec 10, 2012 5:42:16 PM (11 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r137230 r137233 1 2012-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 1 41 2012-12-10 Jon Lee <jonlee@apple.com> 2 42 -
trunk/Source/WebCore/dom/ShadowRoot.cpp
r136924 r137233 359 359 } 360 360 361 void ShadowRoot::register ShadowElement()362 { 363 ensureDistributionData()-> incrementNumberOfShadowElementChildren();364 } 365 366 void ShadowRoot::unregister ShadowElement()367 { 368 distributionData()->decrementNumberOfShadowElementChildren();361 void ShadowRoot::registerInsertionPoint(InsertionPoint* point) 362 { 363 ensureDistributionData()->regiterInsertionPoint(this, point); 364 } 365 366 void ShadowRoot::unregisterInsertionPoint(InsertionPoint* point) 367 { 368 ensureDistributionData()->unregisterInsertionPoint(this, point); 369 369 } 370 370 … … 375 375 376 376 return distributionData()->hasShadowElementChildren(); 377 }378 379 void ShadowRoot::registerContentElement()380 {381 ensureDistributionData()->incrementNumberOfContentElementChildren();382 }383 384 void ShadowRoot::unregisterContentElement()385 {386 distributionData()->decrementNumberOfContentElementChildren();387 377 } 388 378 -
trunk/Source/WebCore/dom/ShadowRoot.h
r136924 r137233 92 92 void setAssignedTo(InsertionPoint*); 93 93 94 void registerShadowElement();95 void unregisterShadowElement();96 94 bool hasShadowInsertionPoint() const; 97 98 void registerContentElement();99 void unregisterContentElement();100 95 bool hasContentElement() const; 101 96 97 void registerInsertionPoint(InsertionPoint*); 98 void unregisterInsertionPoint(InsertionPoint*); 99 102 100 void registerElementShadow(); 103 101 void unregisterElementShadow(); -
trunk/Source/WebCore/html/shadow/ContentDistributor.cpp
r137221 r137233 111 111 } 112 112 113 void 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 128 void 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 113 147 ContentDistributor::ContentDistributor() 114 148 : m_validity(Undetermined) -
trunk/Source/WebCore/html/shadow/ContentDistributor.h
r137119 r137233 78 78 void setInsertionPointAssignedTo(InsertionPoint* insertionPoint) { m_insertionPointAssignedTo = insertionPoint; } 79 79 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*); 82 82 bool hasShadowElementChildren() const { return m_numberOfShadowElementChildren > 0; } 83 84 void incrementNumberOfContentElementChildren() { ++m_numberOfContentElementChildren; invalidateInsertionPointList(); }85 void decrementNumberOfContentElementChildren() { ASSERT(m_numberOfContentElementChildren > 0); --m_numberOfContentElementChildren; invalidateInsertionPointList(); }86 83 bool hasContentElementChildren() const { return m_numberOfContentElementChildren > 0; } 87 84 -
trunk/Source/WebCore/html/shadow/HTMLContentElement.cpp
r136924 r137233 65 65 HTMLContentElement::HTMLContentElement(const QualifiedName& name, Document* document) 66 66 : InsertionPoint(name, document) 67 , m_registeredWithShadowRoot(false)68 67 , m_shouldParseSelectorList(false) 69 68 , m_isValidSelector(true) … … 109 108 } else 110 109 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);141 110 } 142 111 -
trunk/Source/WebCore/html/shadow/HTMLContentElement.h
r135069 r137233 50 50 virtual bool isSelectValid(); 51 51 virtual const CSSSelectorList& selectorList(); 52 virtual Type insertionPointType() const OVERRIDE { return ContentInsertionPoint; } 52 53 53 54 protected: 54 55 HTMLContentElement(const QualifiedName&, Document*); 55 56 virtual InsertionNotificationRequest insertedInto(ContainerNode*) OVERRIDE;57 virtual void removedFrom(ContainerNode*) OVERRIDE;58 56 59 57 private: … … 61 59 void ensureSelectParsed(); 62 60 bool validateSelect() const; 63 64 bool m_registeredWithShadowRoot;65 61 66 62 bool m_shouldParseSelectorList; -
trunk/Source/WebCore/html/shadow/HTMLShadowElement.cpp
r136924 r137233 42 42 inline HTMLShadowElement::HTMLShadowElement(const QualifiedName& tagName, Document* document) 43 43 : InsertionPoint(tagName, document) 44 , m_registeredWithShadowRoot(false)45 44 { 46 45 ASSERT(hasTagName(HTMLNames::shadowTag)); … … 61 60 } 62 61 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 90 62 const CSSSelectorList& HTMLShadowElement::emptySelectorList() 91 63 { -
trunk/Source/WebCore/html/shadow/HTMLShadowElement.h
r133992 r137233 46 46 virtual bool isSelectValid() OVERRIDE { return true; } 47 47 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; } 52 49 53 50 private: -
trunk/Source/WebCore/html/shadow/InsertionPoint.cpp
r137119 r137233 44 44 InsertionPoint::InsertionPoint(const QualifiedName& tagName, Document* document) 45 45 : HTMLElement(tagName, document, CreateInsertionPoint) 46 , m_registeredWithShadowRoot(false) 46 47 { 47 48 } … … 127 128 root->owner()->setValidityUndetermined(); 128 129 root->owner()->invalidateDistribution(); 130 if (isActive() && !m_registeredWithShadowRoot) { 131 m_registeredWithShadowRoot = true; 132 root->registerInsertionPoint(this); 133 } 129 134 } 130 135 } … … 141 146 142 147 // 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(); 145 151 146 152 // Since this insertion point is no longer visible from the shadow subtree, it need to clean itself up. 147 153 clearDistribution(); 154 155 if (m_registeredWithShadowRoot) { 156 m_registeredWithShadowRoot = false; 157 if (root) 158 root->unregisterInsertionPoint(this); 159 } 148 160 } 149 161 -
trunk/Source/WebCore/html/shadow/InsertionPoint.h
r137119 r137233 44 44 class InsertionPoint : public HTMLElement { 45 45 public: 46 enum Type { 47 ShadowInsertionPoint, 48 ContentInsertionPoint 49 }; 50 46 51 virtual ~InsertionPoint(); 47 52 … … 57 62 virtual bool isSelectValid() = 0; 58 63 virtual const CSSSelectorList& selectorList() = 0; 64 virtual Type insertionPointType() const = 0; 59 65 60 66 bool resetStyleInheritance() const; … … 86 92 87 93 ContentDistribution m_distribution; 94 bool m_registeredWithShadowRoot; 88 95 }; 89 96
Note: See TracChangeset
for help on using the changeset viewer.