mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-27 12:50:09 +00:00
Bug 978398 - Rename custom element callbacks from enteredView/leftView to attached/detached. r=mrbkap
This commit is contained in:
parent
41fe2d4584
commit
181b287ab2
@ -2004,8 +2004,8 @@ public:
|
||||
|
||||
enum ElementCallbackType {
|
||||
eCreated,
|
||||
eEnteredView,
|
||||
eLeftView,
|
||||
eAttached,
|
||||
eDetached,
|
||||
eAttributeChanged
|
||||
};
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -331,11 +331,11 @@ CustomElementCallback::Call()
|
||||
static_cast<LifecycleCreatedCallback *>(mCallback.get())->Call(mThisObject, rv);
|
||||
mOwnerData->mElementIsBeingCreated = false;
|
||||
break;
|
||||
case nsIDocument::eEnteredView:
|
||||
static_cast<LifecycleEnteredViewCallback *>(mCallback.get())->Call(mThisObject, rv);
|
||||
case nsIDocument::eAttached:
|
||||
static_cast<LifecycleAttachedCallback *>(mCallback.get())->Call(mThisObject, rv);
|
||||
break;
|
||||
case nsIDocument::eLeftView:
|
||||
static_cast<LifecycleLeftViewCallback *>(mCallback.get())->Call(mThisObject, rv);
|
||||
case nsIDocument::eDetached:
|
||||
static_cast<LifecycleDetachedCallback *>(mCallback.get())->Call(mThisObject, rv);
|
||||
break;
|
||||
case nsIDocument::eAttributeChanged:
|
||||
static_cast<LifecycleAttributeChangedCallback *>(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -313,7 +313,7 @@ private:
|
||||
// The this value to use for invocation of the callback.
|
||||
nsRefPtr<mozilla::dom::Element> mThisObject;
|
||||
nsRefPtr<mozilla::dom::CallbackFunction> 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.
|
||||
|
@ -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);
|
||||
|
@ -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 });
|
||||
|
@ -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;
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user