Changeset 98163 in webkit


Ignore:
Timestamp:
Oct 21, 2011 3:52:29 PM (13 years ago)
Author:
adamk@chromium.org
Message:

[MutationObservers] Implement basic subtree observation
https://bugs.webkit.org/show_bug.cgi?id=70436

Reviewed by Ryosuke Niwa.

Source/WebCore:

Note that this patch only implements "basic" subtree semantics,
not the fully robust semantics described in
http://lists.w3.org/Archives/Public/public-webapps/2011JulSep/1622.html.
Most importantly, this change does not handle the case where mutations
occur in a temporarily detached subtree.

The plan is to implement those semantics in a followup to avoid
blocking other parts of the MutationObserver spec that rely on
the existence of subtree observation but not its specific
implementation.

Test: fast/mutation/observe-subtree.html

  • dom/Node.cpp:

(WebCore::addMatchingObservers): Static helper method for registeredMutationObserversOfType().
(WebCore::Node::registeredMutationObserversOfType): Walk up the tree looking for observers.

  • dom/NodeRareData.h:

(WebCore::MutationObserverEntry::hasAllOptions): A stricter, renamed from matches().

LayoutTests:

  • fast/mutation/observe-subtree-expected.txt: Added.
  • fast/mutation/observe-subtree.html: Added.
Location:
trunk
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r98154 r98163  
     12011-10-21  Adam Klein  <adamk@chromium.org>
     2
     3        [MutationObservers] Implement basic subtree observation
     4        https://bugs.webkit.org/show_bug.cgi?id=70436
     5
     6        Reviewed by Ryosuke Niwa.
     7
     8        * fast/mutation/observe-subtree-expected.txt: Added.
     9        * fast/mutation/observe-subtree.html: Added.
     10
    1112011-10-21  Joshua Bell  <jsbell@chromium.org>
    212
  • trunk/Source/WebCore/ChangeLog

    r98154 r98163  
     12011-10-21  Adam Klein  <adamk@chromium.org>
     2
     3        [MutationObservers] Implement basic subtree observation
     4        https://bugs.webkit.org/show_bug.cgi?id=70436
     5
     6        Reviewed by Ryosuke Niwa.
     7
     8        Note that this patch only implements "basic" subtree semantics,
     9        not the fully robust semantics described in
     10        http://lists.w3.org/Archives/Public/public-webapps/2011JulSep/1622.html.
     11        Most importantly, this change does not handle the case where mutations
     12        occur in a temporarily detached subtree.
     13
     14        The plan is to implement those semantics in a followup to avoid
     15        blocking other parts of the MutationObserver spec that rely on
     16        the existence of subtree observation but not its specific
     17        implementation.
     18
     19        Test: fast/mutation/observe-subtree.html
     20
     21        * dom/Node.cpp:
     22        (WebCore::addMatchingObservers): Static helper method for registeredMutationObserversOfType().
     23        (WebCore::Node::registeredMutationObserversOfType): Walk up the tree looking for observers.
     24        * dom/NodeRareData.h:
     25        (WebCore::MutationObserverEntry::hasAllOptions): A stricter, renamed from matches().
     26
    1272011-10-21  Joshua Bell  <jsbell@chromium.org>
    228
  • trunk/Source/WebCore/dom/Node.cpp

    r98146 r98163  
    26992699}
    27002700
     2701static void addMatchingObservers(HashSet<WebKitMutationObserver*>& observerSet, Vector<MutationObserverEntry>* observerEntries, MutationObserverOptions options)
     2702{
     2703    if (!observerEntries)
     2704        return;
     2705
     2706    const size_t size = observerEntries->size();
     2707    for (size_t i = 0; i < size; ++i) {
     2708        MutationObserverEntry& entry = observerEntries->at(i);
     2709        if (entry.hasAllOptions(options))
     2710            observerSet.add(entry.observer.get());
     2711    }
     2712}
     2713
    27012714void Node::registeredMutationObserversOfType(Vector<WebKitMutationObserver*>& observers, WebKitMutationObserver::MutationType type)
    27022715{
    2703     Vector<MutationObserverEntry>* observerEntries = mutationObserverEntries();
    2704     if (!observerEntries || observerEntries->isEmpty())
    2705         return;
    2706 
    2707     for (size_t i = 0; i < observerEntries->size(); ++i) {
    2708         if ((*observerEntries)[i].matches(type))
    2709             observers.append((*observerEntries)[i].observer.get());
    2710     }
     2716    HashSet<WebKitMutationObserver*> observerSet;
     2717    addMatchingObservers(observerSet, mutationObserverEntries(), type);
     2718    for (Node* node = parentNode(); node; node = node->parentNode())
     2719        addMatchingObservers(observerSet, node->mutationObserverEntries(), type | WebKitMutationObserver::Subtree);
     2720
     2721    // FIXME: this method should output a HashSet instead of a Vector.
     2722    if (!observerSet.isEmpty())
     2723        copyToVector(observerSet, observers);
    27112724}
    27122725
  • trunk/Source/WebCore/dom/NodeRareData.h

    r97714 r98163  
    102102    }
    103103
    104     bool matches(MutationObserverOptions options) const
     104    bool hasAllOptions(MutationObserverOptions options) const
    105105    {
    106         return this->options & options;
     106        return (this->options & options) == options;
    107107    }
    108108
     
    110110    MutationObserverOptions options;
    111111};
    112 
    113112#endif // ENABLE(MUTATION_OBSERVERS)
    114113
Note: See TracChangeset for help on using the changeset viewer.