Changeset 99593 in webkit
- Timestamp:
- Nov 8, 2011 10:29:54 AM (12 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r99590 r99593 1 2011-11-08 Adam Klein <adamk@chromium.org> 2 3 Only walk up the tree in search of MutationObservers if one has been added 4 https://bugs.webkit.org/show_bug.cgi?id=71499 5 6 Reviewed by Ojan Vafai. 7 8 Created a basic test showing that MutationObservers 9 are preserved when a Node switches documents. 10 11 * fast/mutation/cross-document-expected.txt: Added. 12 * fast/mutation/cross-document.html: Added. 13 1 14 2011-11-08 Ojan Vafai <ojan@chromium.org> 2 15 -
trunk/Source/WebCore/ChangeLog
r99592 r99593 1 2011-11-08 Adam Klein <adamk@chromium.org> 2 3 Only walk up the tree in search of MutationObservers if one has been added 4 https://bugs.webkit.org/show_bug.cgi?id=71499 5 6 Reviewed by Ojan Vafai. 7 8 Analogous to m_listenerTypes, added an m_subtreeMutationObserverTypes field 9 to Document that keeps track of which observer types have been added. 10 This allows us to avoid doing any extra work if MutationObservers are 11 not attached to a document. 12 13 This could be improved upon to keep a count of each type, as removing 14 an observer currently has no effect on m_subtreeMutationObserverTypes. 15 But that would require a more complex implementation: one counter per 16 mutation type. And it would be easier to get wrong: if the counter 17 gets out of sync with the actual state of the DOM, we could start 18 dropping mutation notifications. 19 20 Test: fast/mutation/cross-document.html 21 22 * dom/Document.h: 23 (WebCore::Document::hasSubtreeMutationObserverOfType): 24 (WebCore::Document::hasSubtreeMutationObserver): 25 (WebCore::Document::addSubtreeMutationObserverTypes): 26 * dom/MutationObserverRegistration.h: 27 (WebCore::MutationObserverRegistration::isSubtree): 28 (WebCore::MutationObserverRegistration::deliveryOptions): 29 (WebCore::MutationObserverRegistration::mutationTypes): 30 * dom/Node.cpp: 31 (WebCore::Node::didMoveToNewOwnerDocument): Update mutationObserverTypes when a Node is moved to a new document. 32 (WebCore::Node::getRegisteredMutationObserversOfType): Exit early if it's known that no observers of |type| are registered. 33 (WebCore::Node::notifyMutationObserversNodeWillDetach): Exit early if it's known no subtree observers of any type are registered. 34 * dom/WebKitMutationObserver.cpp: 35 (WebCore::WebKitMutationObserver::observe): Update mutationObserverTypes when an observation occurs. 36 * dom/WebKitMutationObserver.h: Add WebKitMutationObserver::AllMutationTypes to enum 37 1 38 2011-11-08 Andreas Kling <kling@webkit.org> 2 39 -
trunk/Source/WebCore/dom/Document.cpp
r99579 r99593 361 361 , m_compatibilityModeLocked(false) 362 362 , m_domTreeVersion(++s_globalTreeVersion) 363 #if ENABLE(MUTATION_OBSERVERS) 364 , m_subtreeMutationObserverTypes(0) 365 #endif 363 366 , m_styleSheets(StyleSheetList::create(this)) 364 367 , m_readyState(Complete) -
trunk/Source/WebCore/dom/Document.h
r98724 r99593 47 47 #include "TreeScope.h" 48 48 #include "ViewportArguments.h" 49 #include "WebKitMutationObserver.h" 49 50 #include <wtf/Deque.h> 50 51 #include <wtf/FixedArray.h> … … 777 778 void addListenerTypeIfNeeded(const AtomicString& eventType); 778 779 780 #if ENABLE(MUTATION_OBSERVERS) 781 bool hasSubtreeMutationObserverOfType(WebKitMutationObserver::MutationType type) const 782 { 783 return m_subtreeMutationObserverTypes & type; 784 } 785 bool hasSubtreeMutationObserver() const { return m_subtreeMutationObserverTypes; } 786 void addSubtreeMutationObserverTypes(MutationObserverOptions types) { m_subtreeMutationObserverTypes |= types; } 787 #endif 788 779 789 CSSStyleDeclaration* getOverrideStyle(Element*, const String& pseudoElt); 780 790 … … 1238 1248 1239 1249 unsigned short m_listenerTypes; 1250 1251 #if ENABLE(MUTATION_OBSERVERS) 1252 MutationObserverOptions m_subtreeMutationObserverTypes; 1253 #endif 1240 1254 1241 1255 RefPtr<StyleSheetList> m_styleSheets; // All of the stylesheets that are currently in effect for our media type and stylesheet set. -
trunk/Source/WebCore/dom/MutationObserverRegistration.h
r99338 r99593 54 54 55 55 bool shouldReceiveMutationFrom(Node*, WebKitMutationObserver::MutationType); 56 bool isSubtree() const { return m_options & WebKitMutationObserver::Subtree; } 56 57 57 58 WebKitMutationObserver* observer() { return m_observer.get(); } 58 MutationRecordDeliveryOptions deliveryOptions() { return m_options & (WebKitMutationObserver::AttributeOldValue | WebKitMutationObserver::CharacterDataOldValue); } 59 MutationRecordDeliveryOptions deliveryOptions() const { return m_options & (WebKitMutationObserver::AttributeOldValue | WebKitMutationObserver::CharacterDataOldValue); } 60 MutationObserverOptions mutationTypes() const { return m_options & WebKitMutationObserver::AllMutationTypes; } 59 61 60 62 private: -
trunk/Source/WebCore/dom/Node.cpp
r99338 r99593 2545 2545 ASSERT(!didMoveToNewOwnerDocumentWasCalled); 2546 2546 setDidMoveToNewOwnerDocumentWasCalled(true); 2547 2548 // FIXME: Event listener types for this node should be set on the new owner document here. 2549 2550 #if ENABLE(MUTATION_OBSERVERS) 2551 if (Vector<OwnPtr<MutationObserverRegistration> >* registry = mutationObserverRegistry()) { 2552 for (size_t i = 0; i < registry->size(); ++i) { 2553 if (registry->at(i)->isSubtree()) 2554 document()->addSubtreeMutationObserverTypes(registry->at(i)->mutationTypes()); 2555 } 2556 } 2557 2558 if (HashSet<MutationObserverRegistration*>* transientRegistry = transientMutationObserverRegistry()) { 2559 for (HashSet<MutationObserverRegistration*>::iterator iter = transientRegistry->begin(); iter != transientRegistry->end(); ++iter) { 2560 if ((*iter)->isSubtree()) 2561 document()->addSubtreeMutationObserverTypes((*iter)->mutationTypes()); 2562 } 2563 } 2564 #endif 2547 2565 } 2548 2566 … … 2735 2753 void Node::getRegisteredMutationObserversOfType(HashMap<WebKitMutationObserver*, MutationRecordDeliveryOptions>& observers, WebKitMutationObserver::MutationType type) 2736 2754 { 2737 for (Node* node = this; node; node = node->parentNode()) 2755 collectMatchingObserversForMutation(observers, this, type); 2756 2757 if (!document()->hasSubtreeMutationObserverOfType(type)) 2758 return; 2759 2760 for (Node* node = parentNode(); node; node = node->parentNode()) 2738 2761 collectMatchingObserversForMutation(observers, node, type); 2739 2762 } … … 2786 2809 void Node::notifyMutationObserversNodeWillDetach() 2787 2810 { 2811 if (!document()->hasSubtreeMutationObserver()) 2812 return; 2813 2788 2814 for (Node* node = parentNode(); node; node = node->parentNode()) { 2789 2815 if (Vector<OwnPtr<MutationObserverRegistration> >* registry = node->mutationObserverRegistry()) { -
trunk/Source/WebCore/dom/WebKitMutationObserver.cpp
r99338 r99593 35 35 #include "WebKitMutationObserver.h" 36 36 37 #include "Document.h" 37 38 #include "MutationCallback.h" 38 39 #include "MutationObserverRegistration.h" … … 62 63 MutationObserverRegistration* registration = node->registerMutationObserver(this); 63 64 registration->resetObservation(options); 65 66 if (registration->isSubtree()) 67 node->document()->addSubtreeMutationObserverTypes(registration->mutationTypes()); 64 68 } 65 69 -
trunk/Source/WebCore/dom/WebKitMutationObserver.h
r99338 r99593 56 56 ChildList = 1 << 0, 57 57 Attributes = 1 << 1, 58 CharacterData = 1 << 2 58 CharacterData = 1 << 2, 59 60 AllMutationTypes = ChildList | Attributes | CharacterData 59 61 }; 60 62
Note: See TracChangeset
for help on using the changeset viewer.