From e3e29f278c6d0a26de2235d53f2b2ad328afd6f5 Mon Sep 17 00:00:00 2001 From: William Chen Date: Fri, 28 Feb 2014 17:45:31 -0800 Subject: [PATCH] Bug 978398 - Rename custom element callbacks from enteredView/leftView to attached/detached. r=mrbkap --- content/base/public/nsIDocument.h | 4 +- content/base/src/Element.cpp | 8 +- content/base/src/nsDocument.cpp | 36 +++---- content/base/src/nsDocument.h | 2 +- .../test_document_register_lifecycle.html | 94 +++++++++---------- .../test_document_register_stack.html | 34 +++---- dom/webidl/WebComponents.webidl | 8 +- 7 files changed, 93 insertions(+), 93 deletions(-) diff --git a/content/base/public/nsIDocument.h b/content/base/public/nsIDocument.h index ae5f193e8e9..f0409a8c721 100644 --- a/content/base/public/nsIDocument.h +++ b/content/base/public/nsIDocument.h @@ -2004,8 +2004,8 @@ public: enum ElementCallbackType { eCreated, - eEnteredView, - eLeftView, + eAttached, + eDetached, eAttributeChanged }; diff --git a/content/base/src/Element.cpp b/content/base/src/Element.cpp index d0d57d61e86..6f196b73341 100644 --- a/content/base/src/Element.cpp +++ b/content/base/src/Element.cpp @@ -1158,8 +1158,8 @@ Element::BindToTree(nsIDocument* aDocument, nsIContent* aParent, SetInDocument(); if (GetCustomElementData()) { - // Enqueue an enteredView callback for the custom element. - aDocument->EnqueueLifecycleCallback(nsIDocument::eEnteredView, this); + // Enqueue an attached callback for the custom element. + aDocument->EnqueueLifecycleCallback(nsIDocument::eAttached, this); } // Unset this flag since we now really are in a document. @@ -1321,8 +1321,8 @@ Element::UnbindFromTree(bool aDeep, bool aNullParent) document->ClearBoxObjectFor(this); if (GetCustomElementData()) { - // Enqueue a leftView callback for the custom element. - document->EnqueueLifecycleCallback(nsIDocument::eLeftView, this); + // Enqueue a detached callback for the custom element. + document->EnqueueLifecycleCallback(nsIDocument::eDetached, this); } } diff --git a/content/base/src/nsDocument.cpp b/content/base/src/nsDocument.cpp index 62b87010644..be3c5b020c6 100644 --- a/content/base/src/nsDocument.cpp +++ b/content/base/src/nsDocument.cpp @@ -331,11 +331,11 @@ CustomElementCallback::Call() static_cast(mCallback.get())->Call(mThisObject, rv); mOwnerData->mElementIsBeingCreated = false; break; - case nsIDocument::eEnteredView: - static_cast(mCallback.get())->Call(mThisObject, rv); + case nsIDocument::eAttached: + static_cast(mCallback.get())->Call(mThisObject, rv); break; - case nsIDocument::eLeftView: - static_cast(mCallback.get())->Call(mThisObject, rv); + case nsIDocument::eDetached: + static_cast(mCallback.get())->Call(mThisObject, rv); break; case nsIDocument::eAttributeChanged: static_cast(mCallback.get())->Call(mThisObject, @@ -1750,16 +1750,16 @@ CustomDefinitionsTraverse(CustomElementHashKey* aKey, cb->NoteXPCOMChild(aDefinition->mCallbacks->mCreatedCallback.Value()); } - if (callbacks->mEnteredViewCallback.WasPassed()) { + if (callbacks->mAttachedCallback.WasPassed()) { NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(*cb, - "mCustomDefinitions->mCallbacks->mEnteredViewCallback"); - cb->NoteXPCOMChild(aDefinition->mCallbacks->mEnteredViewCallback.Value()); + "mCustomDefinitions->mCallbacks->mAttachedCallback"); + cb->NoteXPCOMChild(aDefinition->mCallbacks->mAttachedCallback.Value()); } - if (callbacks->mLeftViewCallback.WasPassed()) { + if (callbacks->mDetachedCallback.WasPassed()) { NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(*cb, - "mCustomDefinitions->mCallbacks->mLeftViewCallback"); - cb->NoteXPCOMChild(aDefinition->mCallbacks->mLeftViewCallback.Value()); + "mCustomDefinitions->mCallbacks->mDetachedCallback"); + cb->NoteXPCOMChild(aDefinition->mCallbacks->mDetachedCallback.Value()); } return PL_DHASH_NEXT; @@ -5571,15 +5571,15 @@ nsDocument::EnqueueLifecycleCallback(nsIDocument::ElementCallbackType aType, } break; - case nsIDocument::eEnteredView: - if (definition->mCallbacks->mEnteredViewCallback.WasPassed()) { - func = definition->mCallbacks->mEnteredViewCallback.Value(); + case nsIDocument::eAttached: + if (definition->mCallbacks->mAttachedCallback.WasPassed()) { + func = definition->mCallbacks->mAttachedCallback.Value(); } break; - case nsIDocument::eLeftView: - if (definition->mCallbacks->mLeftViewCallback.WasPassed()) { - func = definition->mCallbacks->mLeftViewCallback.Value(); + case nsIDocument::eDetached: + if (definition->mCallbacks->mDetachedCallback.WasPassed()) { + func = definition->mCallbacks->mDetachedCallback.Value(); } break; @@ -5922,12 +5922,12 @@ nsDocument::RegisterElement(JSContext* aCx, const nsAString& aType, EnqueueLifecycleCallback(nsIDocument::eCreated, elem, nullptr, definition); if (elem->GetCurrentDoc()) { // Normally callbacks can not be enqueued until the created - // callback has been invoked, however, the entered view callback + // callback has been invoked, however, the attached callback // in element upgrade is an exception so pretend the created // callback has been invoked. elem->GetCustomElementData()->mCreatedCallbackInvoked = true; - EnqueueLifecycleCallback(nsIDocument::eEnteredView, elem, nullptr, definition); + EnqueueLifecycleCallback(nsIDocument::eAttached, elem, nullptr, definition); } } } diff --git a/content/base/src/nsDocument.h b/content/base/src/nsDocument.h index 068b27b0437..44260585f4b 100644 --- a/content/base/src/nsDocument.h +++ b/content/base/src/nsDocument.h @@ -313,7 +313,7 @@ private: // The this value to use for invocation of the callback. nsRefPtr mThisObject; nsRefPtr mCallback; - // The type of callback (eCreated, eEnteredView, etc.) + // The type of callback (eCreated, eAttached, etc.) nsIDocument::ElementCallbackType mType; // Arguments to be passed to the callback, // used by the attribute changed callback. diff --git a/dom/tests/mochitest/webcomponents/test_document_register_lifecycle.html b/dom/tests/mochitest/webcomponents/test_document_register_lifecycle.html index ea6895be566..a1826883ba1 100644 --- a/dom/tests/mochitest/webcomponents/test_document_register_lifecycle.html +++ b/dom/tests/mochitest/webcomponents/test_document_register_lifecycle.html @@ -24,8 +24,8 @@ function testRegisterUnresolved() { var helloElem = document.getElementById("hello"); var createdCallbackCalled = false; - var enteredViewCallbackCalled = false; - var leftViewCallbackCalled = false; + var attachedCallbackCalled = false; + var detachedCallbackCalled = false; var p = Object.create(HTMLElement.prototype); p.createdCallback = function() { @@ -35,17 +35,17 @@ function testRegisterUnresolved() { createdCallbackCalled = true; }; - p.enteredViewCallback = function() { - is(createdCallbackCalled, true, "Created callback should be called before enteredView"); - is(enteredViewCallbackCalled, false, "enteredView callback should only be called once in this test."); + p.attachedCallback = function() { + is(createdCallbackCalled, true, "Created callback should be called before attached"); + is(attachedCallbackCalled, false, "attached callback should only be called once in this test."); is(this, helloElem, "The 'this' value should be the custom element."); - enteredViewCallbackCalled = true; + attachedCallbackCalled = true; }; - p.leftViewCallback = function() { - is(enteredViewCallbackCalled, true, "enteredView callback should be called before leftView"); - is(leftViewCallbackCalled, false, "leftView callback should only be called once in this test."); - leftViewCallbackCalled = true; + p.detachedCallback = function() { + is(attachedCallbackCalled, true, "attached callback should be called before detached"); + is(detachedCallbackCalled, false, "detached callback should only be called once in this test."); + detachedCallbackCalled = true; is(this, helloElem, "The 'this' value should be the custom element."); runNextTest(); }; @@ -57,7 +57,7 @@ function testRegisterUnresolved() { document.registerElement("x-hello", { prototype: p }); is(createdCallbackCalled, true, "created callback should be called when control returns to script from user agent code"); - // Remove element from document to trigger leftView callback. + // Remove element from document to trigger detached callback. container.removeChild(helloElem); } @@ -67,8 +67,8 @@ function testRegisterUnresolvedExtended() { var buttonElem = document.getElementById("extbutton"); var createdCallbackCalled = false; - var enteredViewCallbackCalled = false; - var leftViewCallbackCalled = false; + var attachedCallbackCalled = false; + var detachedCallbackCalled = false; var p = Object.create(HTMLButtonElement.prototype); p.createdCallback = function() { @@ -78,17 +78,17 @@ function testRegisterUnresolvedExtended() { createdCallbackCalled = true; }; - p.enteredViewCallback = function() { - is(createdCallbackCalled, true, "Created callback should be called before enteredView"); - is(enteredViewCallbackCalled, false, "enteredView callback should only be called once in this test."); + p.attachedCallback = function() { + is(createdCallbackCalled, true, "Created callback should be called before attached"); + is(attachedCallbackCalled, false, "attached callback should only be called once in this test."); is(this, buttonElem, "The 'this' value should be the custom element."); - enteredViewCallbackCalled = true; + attachedCallbackCalled = true; }; - p.leftViewCallback = function() { - is(enteredViewCallbackCalled, true, "enteredView callback should be called before leftView"); - is(leftViewCallbackCalled, false, "leftView callback should only be called once in this test."); - leftViewCallbackCalled = true; + p.detachedCallback = function() { + is(attachedCallbackCalled, true, "attached callback should be called before detached"); + is(detachedCallbackCalled, false, "detached callback should only be called once in this test."); + detachedCallbackCalled = true; is(this, buttonElem, "The 'this' value should be the custom element."); runNextTest(); }; @@ -100,7 +100,7 @@ function testRegisterUnresolvedExtended() { document.registerElement("x-button", { prototype: p, extends: "button" }); is(createdCallbackCalled, true, "created callback should be called when control returns to script from user agent code"); - // Remove element from document to trigger leftView callback. + // Remove element from document to trigger detached callback. container.removeChild(buttonElem); } @@ -174,8 +174,8 @@ function testInnerHTMLExtendedUpgrade() { // register -> create element -> insert into document -> remove from document function testRegisterResolved() { var createdCallbackCalled = false; - var enteredViewCallbackCalled = false; - var leftViewCallbackCalled = false; + var attachedCallbackCalled = false; + var detachedCallbackCalled = false; var createdCallbackThis; @@ -186,18 +186,18 @@ function testRegisterResolved() { createdCallbackCalled = true; }; - p.enteredViewCallback = function() { - is(createdCallbackCalled, true, "created callback should be called before enteredView callback."); - is(enteredViewCallbackCalled, false, "enteredView callback should only be called on in this test."); + p.attachedCallback = function() { + is(createdCallbackCalled, true, "created callback should be called before attached callback."); + is(attachedCallbackCalled, false, "attached callback should only be called on in this test."); is(this, createdElement, "The 'this' value should be the custom element."); - enteredViewCallbackCalled = true; + attachedCallbackCalled = true; }; - p.leftViewCallback = function() { - is(enteredViewCallbackCalled, true, "enteredView callback should be called before leftView"); - is(leftViewCallbackCalled, false, "leftView callback should only be called once in this test."); + p.detachedCallback = function() { + is(attachedCallbackCalled, true, "attached callback should be called before detached"); + is(detachedCallbackCalled, false, "detached callback should only be called once in this test."); is(this, createdElement, "The 'this' value should be the custom element."); - leftViewCallbackCalled = true; + detachedCallbackCalled = true; runNextTest(); }; @@ -212,10 +212,10 @@ function testRegisterResolved() { is(createdCallbackThis, createdElement, "The 'this' value in the created callback should be the custom element."); is(createdElement.__proto__, p, "Prototype of custom element should be the registered prototype."); - // Insert element into document to trigger enteredView callback. + // Insert element into document to trigger attached callback. container.appendChild(createdElement); - // Remove element from document to trigger leftView callback. + // Remove element from document to trigger detached callback. container.removeChild(createdElement); } @@ -319,11 +319,11 @@ function testUpgradeCandidate() { function testNotInDocEnterLeave() { var p = Object.create(HTMLElement.prototype); - p.enteredView = function() { - ok(false, "enteredView should not be called when not entering the document."); + p.attached = function() { + ok(false, "attached should not be called when not entering the document."); }; - p.leftView = function() { + p.detached = function() { ok(false, "leaveView should not be called when not leaving the document."); }; @@ -343,19 +343,19 @@ function testNotInDocEnterLeave() { } function testEnterLeaveView() { - var enteredViewCallbackCalled = false; - var leftViewCallbackCalled = false; + var attachedCallbackCalled = false; + var detachedCallbackCalled = false; var p = Object.create(HTMLElement.prototype); - p.enteredViewCallback = function() { - is(enteredViewCallbackCalled, false, "enteredView callback should only be called on in this test."); - enteredViewCallbackCalled = true; + p.attachedCallback = function() { + is(attachedCallbackCalled, false, "attached callback should only be called on in this test."); + attachedCallbackCalled = true; }; - p.leftViewCallback = function() { - is(enteredViewCallbackCalled, true, "enteredView callback should be called before leftView"); - is(leftViewCallbackCalled, false, "leftView callback should only be called once in this test."); - leftViewCallbackCalled = true; + p.detachedCallback = function() { + is(attachedCallbackCalled, true, "attached callback should be called before detached"); + is(detachedCallbackCalled, false, "detached callback should only be called once in this test."); + detachedCallbackCalled = true; runNextTest(); }; @@ -363,7 +363,7 @@ function testEnterLeaveView() { document.registerElement("x-element-in-div", { prototype: p }); var customElement = document.createElement("x-element-in-div"); div.appendChild(customElement); - is(enteredViewCallbackCalled, false, "Appending a custom element to a node that is not in the document should not call the enteredView callback."); + is(attachedCallbackCalled, false, "Appending a custom element to a node that is not in the document should not call the attached callback."); container.appendChild(div); container.removeChild(div); diff --git a/dom/tests/mochitest/webcomponents/test_document_register_stack.html b/dom/tests/mochitest/webcomponents/test_document_register_stack.html index 23d78149697..34f1086549a 100644 --- a/dom/tests/mochitest/webcomponents/test_document_register_stack.html +++ b/dom/tests/mochitest/webcomponents/test_document_register_stack.html @@ -24,7 +24,7 @@ function testChangeAttributeInCreatedCallback() { var p = Object.create(HTMLElement.prototype); p.createdCallback = function() { - is(createdCallbackCalled, false, "Created callback should be called before enteredView callback."); + is(createdCallbackCalled, false, "Created callback should be called before attached callback."); createdCallbackCalled = true; is(attributeChangedCallbackCalled, false, "Attribute changed callback should not have been called prior to setting the attribute."); this.setAttribute("foo", "bar"); @@ -46,11 +46,11 @@ function testChangeAttributeInCreatedCallback() { function testChangeAttributeInEnteredViewCallback() { var p = Object.create(HTMLElement.prototype); var attributeChangedCallbackCalled = false; - var enteredViewCallbackCalled = false; + var attachedCallbackCalled = false; - p.enteredViewCallback = function() { - is(enteredViewCallbackCalled, false, "enteredView callback should be called only once in this test."); - enteredViewCallbackCalled = true; + p.attachedCallback = function() { + is(attachedCallbackCalled, false, "attached callback should be called only once in this test."); + attachedCallbackCalled = true; is(attributeChangedCallbackCalled, false, "Attribute changed callback should not be called before changing attribute."); this.setAttribute("foo", "bar"); is(attributeChangedCallbackCalled, true, "Transition from user-agent implementation to script should result in attribute changed callback being called."); @@ -58,7 +58,7 @@ function testChangeAttributeInEnteredViewCallback() { }; p.attributeChangedCallback = function() { - is(enteredViewCallbackCalled, true, "enteredView callback should have been called prior to attribute changed callback."); + is(attachedCallbackCalled, true, "attached callback should have been called prior to attribute changed callback."); is(attributeChangedCallbackCalled, false, "attributeChanged callback should only be called once in this tests."); attributeChangedCallbackCalled = true; }; @@ -72,24 +72,24 @@ function testChangeAttributeInEnteredViewCallback() { function testLeaveViewInEnteredViewCallback() { var p = Object.create(HTMLElement.prototype); - var enteredViewCallbackCalled = false; - var leftViewCallbackCalled = false; + var attachedCallbackCalled = false; + var detachedCallbackCalled = false; var container = document.getElementById("container"); - p.enteredViewCallback = function() { + p.attachedCallback = function() { is(this.parentNode, container, "Parent node should the container in which the node was appended."); - is(enteredViewCallbackCalled, false, "enteredView callback should be called only once in this test."); - enteredViewCallbackCalled = true; - is(leftViewCallbackCalled, false, "leftView callback should not be called prior to removing element from document."); + is(attachedCallbackCalled, false, "attached callback should be called only once in this test."); + attachedCallbackCalled = true; + is(detachedCallbackCalled, false, "detached callback should not be called prior to removing element from document."); container.removeChild(this); - is(leftViewCallbackCalled, true, "Transition from user-agent implementation to script should run left view callback."); + is(detachedCallbackCalled, true, "Transition from user-agent implementation to script should run left view callback."); runNextTest(); }; - p.leftViewCallback = function() { - is(leftViewCallbackCalled, false, "The left view callback should only be called once in this test."); - is(enteredViewCallbackCalled, true, "The entered view callback should be called prior to left view callback."); - leftViewCallbackCalled = true; + p.detachedCallback = function() { + is(detachedCallbackCalled, false, "The detached callback should only be called once in this test."); + is(attachedCallbackCalled, true, "The attached callback should be called prior to detached callback."); + detachedCallbackCalled = true; }; document.registerElement("x-three", { prototype: p }); diff --git a/dom/webidl/WebComponents.webidl b/dom/webidl/WebComponents.webidl index 9ed3c109099..3dfb960bc10 100644 --- a/dom/webidl/WebComponents.webidl +++ b/dom/webidl/WebComponents.webidl @@ -11,14 +11,14 @@ */ callback LifecycleCreatedCallback = void(); -callback LifecycleEnteredViewCallback = void(); -callback LifecycleLeftViewCallback = void(); +callback LifecycleAttachedCallback = void(); +callback LifecycleDetachedCallback = void(); callback LifecycleAttributeChangedCallback = void(DOMString attrName, DOMString? oldValue, DOMString? newValue); dictionary LifecycleCallbacks { LifecycleCreatedCallback? createdCallback; - LifecycleEnteredViewCallback? enteredViewCallback; - LifecycleLeftViewCallback? leftViewCallback; + LifecycleAttachedCallback? attachedCallback; + LifecycleDetachedCallback? detachedCallback; LifecycleAttributeChangedCallback? attributeChangedCallback; };