Changeset 102100 in webkit


Ignore:
Timestamp:
Dec 5, 2011 11:37:07 PM (12 years ago)
Author:
commit-queue@webkit.org
Message:

[MutationObservers] Support 'attributes' mutation records for element.removeAttribute
https://bugs.webkit.org/show_bug.cgi?id=73880

Patch by Rafael Weinstein <rafaelw@chromium.org> on 2011-12-05
Reviewed by Ojan Vafai.

Source/WebCore:

  • dom/Element.cpp:

(WebCore::enqueueAttributesMutationRecord):
(WebCore::Element::removeAttribute):

LayoutTests:

  • fast/mutation/observe-attributes-expected.txt:
  • fast/mutation/observe-attributes.html:
Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r102089 r102100  
     12011-12-05  Rafael Weinstein  <rafaelw@chromium.org>
     2
     3        [MutationObservers] Support 'attributes' mutation records for element.removeAttribute
     4        https://bugs.webkit.org/show_bug.cgi?id=73880
     5
     6        Reviewed by Ojan Vafai.
     7
     8        * fast/mutation/observe-attributes-expected.txt:
     9        * fast/mutation/observe-attributes.html:
     10
    1112011-12-05  Florin Malita  <fmalita@google.com>
    212
  • trunk/LayoutTests/fast/mutation/observe-attributes-expected.txt

    r101101 r102100  
    66Testing basic aspects of attribute observation.
    77...can attribute changes be observed at all
    8 PASS mutations.length is 1
     8PASS mutations.length is 2
    99PASS mutations[0].type is "attributes"
    1010PASS mutations[0].attributeName is "foo"
    1111PASS mutations[0].attributeNamespace is null
     12PASS mutations[1].type is "attributes"
     13PASS mutations[1].attributeName is "bar"
     14PASS mutations[1].attributeNamespace is null
    1215...observer.disconnect() should prevent further delivery of mutations.
    1316PASS mutations is null
     
    6063
    6164Testing basic oldValue delivery.
    62 PASS mutations.length is 2
     65PASS mutations.length is 3
    6366PASS mutations[0].type is "attributes"
    6467PASS mutations[0].attributeName is "foo"
     
    6770PASS mutations[1].attributeName is "foo"
    6871PASS mutations[1].oldValue is "bar"
     72PASS mutations[2].type is "attributes"
     73PASS mutations[2].attributeName is "bar"
     74PASS mutations[2].oldValue is "boo"
    6975
    7076Testing that oldValue is delivered as requested (or not).
  • trunk/LayoutTests/fast/mutation/observe-attributes.html

    r101101 r102100  
    2323        mutations = null;
    2424        div = document.createElement('div');
     25        div.setAttribute('bar', 'foo');
     26
    2527        observer = new WebKitMutationObserver(function(m) {
    2628            mutations = m;
     
    2931        observer.observe(div, { attributes: true, characterData: true });
    3032        div.setAttribute('foo', 'bar');
     33        div.removeAttribute('bar');
    3134        setTimeout(checkDisconnectAndMutate, 0);
    3235    }
     
    3538        debug('...can attribute changes be observed at all');
    3639
    37         shouldBe('mutations.length', '1');
     40        shouldBe('mutations.length', '2');
    3841        shouldBe('mutations[0].type', '"attributes"');
    3942        shouldBe('mutations[0].attributeName', '"foo"');
    4043        shouldBe('mutations[0].attributeNamespace', 'null');
     44        shouldBe('mutations[1].type', '"attributes"');
     45        shouldBe('mutations[1].attributeName', '"bar"');
     46        shouldBe('mutations[1].attributeNamespace', 'null');
    4147
    4248        mutations = null;
     
    304310        mutations = null;
    305311        div = document.createElement('div');
     312        div.setAttribute('bar', 'boo');
     313       
    306314        observer = new WebKitMutationObserver(function(mutations) {
    307315            window.mutations = mutations;
     
    310318        div.setAttribute('foo', 'bar');
    311319        div.setAttribute('foo', 'baz');
    312         setTimeout(finish, 0);
    313     }
    314 
    315     function finish() {
    316         shouldBe('mutations.length', '2');
     320        div.removeAttribute('bar');
     321        div.removeAttribute('non-existant');
     322        setTimeout(finish, 0);
     323    }
     324
     325    function finish() {
     326        shouldBe('mutations.length', '3');
    317327        shouldBe('mutations[0].type', '"attributes"');
    318328        shouldBe('mutations[0].attributeName', '"foo"');
     
    321331        shouldBe('mutations[1].attributeName', '"foo"');
    322332        shouldBe('mutations[1].oldValue', '"bar"');
     333        shouldBe('mutations[2].type', '"attributes"');
     334        shouldBe('mutations[2].attributeName', '"bar"');
     335        shouldBe('mutations[2].oldValue', '"boo"');
    323336        observer.disconnect();
    324337        debug('');
  • trunk/Source/WebCore/ChangeLog

    r102098 r102100  
     12011-12-05  Rafael Weinstein  <rafaelw@chromium.org>
     2
     3        [MutationObservers] Support 'attributes' mutation records for element.removeAttribute
     4        https://bugs.webkit.org/show_bug.cgi?id=73880
     5
     6        Reviewed by Ojan Vafai.
     7
     8        * dom/Element.cpp:
     9        (WebCore::enqueueAttributesMutationRecord):
     10        (WebCore::Element::removeAttribute):
     11
    1122011-12-05  Dana Jansens  <danakj@chromium.org>
    213
  • trunk/Source/WebCore/dom/Element.cpp

    r101855 r102100  
    181181}
    182182
     183#if ENABLE(MUTATION_OBSERVERS)
     184static void enqueueAttributesMutationRecord(Element* target, const QualifiedName& attributeName, const AtomicString& oldValue)
     185{
     186    OwnPtr<MutationObserverInterestGroup> mutationRecipients = MutationObserverInterestGroup::createForAttributesMutation(target, attributeName);
     187    mutationRecipients->enqueueMutationRecord(MutationRecord::createAttributes(target, attributeName, oldValue));
     188}
     189#endif
     190
    183191void Element::removeAttribute(const QualifiedName& name, ExceptionCode& ec)
    184192{
    185193    if (m_attributeMap) {
    186194        ec = 0;
    187         m_attributeMap->removeNamedItem(name, ec);
     195        RefPtr<Node> attrNode = m_attributeMap->removeNamedItem(name, ec);
    188196        if (ec == NOT_FOUND_ERR)
    189197            ec = 0;
     198#if ENABLE(MUTATION_OBSERVERS)
     199        else
     200            enqueueAttributesMutationRecord(this, name, attrNode->nodeValue());
     201#endif
    190202    }
    191203}
     
    616628    return getAttribute(QualifiedName(nullAtom, localName, namespaceURI));
    617629}
    618 
    619 #if ENABLE(MUTATION_OBSERVERS)
    620 static void enqueueAttributesMutationRecord(Element* target, const QualifiedName& attributeName, const AtomicString& oldValue)
    621 {
    622     OwnPtr<MutationObserverInterestGroup> mutationRecipients = MutationObserverInterestGroup::createForAttributesMutation(target, attributeName);
    623     mutationRecipients->enqueueMutationRecord(MutationRecord::createAttributes(target, attributeName, oldValue));
    624 }
    625 #endif
    626630
    627631void Element::setAttribute(const AtomicString& name, const AtomicString& value, ExceptionCode& ec)
     
    15431547    if (m_attributeMap) {
    15441548        ec = 0;
    1545         m_attributeMap->removeNamedItem(localName, ec);
     1549        RefPtr<Node> attrNode = m_attributeMap->removeNamedItem(localName, ec);
    15461550        if (ec == NOT_FOUND_ERR)
    15471551            ec = 0;
     1552#if ENABLE(MUTATION_OBSERVERS)
     1553        else
     1554            enqueueAttributesMutationRecord(this, QualifiedName(nullAtom, localName, nullAtom), attrNode->nodeValue());
     1555#endif
    15481556    }
    15491557   
Note: See TracChangeset for help on using the changeset viewer.