Bug 1510848 - Do not unattach UA Widget Shadow Root if the element is already re-attached to the tree r=emilio,smaug
This patch moves all UA Widget calls to helper functions in Element.cpp. The helper function AttachAndSetUAShadowRoot sets the shadow root in a runnable, so that it is in the same order of NotifyUAWidget* runnables. Differential Revision: https://phabricator.services.mozilla.com/D13479
This commit is contained in:
@@ -4337,10 +4337,7 @@ nsresult HTMLInputElement::BindToTree(nsIDocument* aDocument,
|
||||
nsContentUtils::IsUAWidgetEnabled() && IsInComposedDoc()) {
|
||||
// Construct Shadow Root so web content can be hidden in the DOM.
|
||||
AttachAndSetUAShadowRoot();
|
||||
AsyncEventDispatcher* dispatcher =
|
||||
new AsyncEventDispatcher(this, NS_LITERAL_STRING("UAWidgetBindToTree"),
|
||||
CanBubble::eYes, ChromeOnlyDispatch::eYes);
|
||||
dispatcher->RunDOMEventWhenSafe();
|
||||
NotifyUAWidgetSetupOrChange();
|
||||
}
|
||||
|
||||
if (mType == NS_FORM_INPUT_PASSWORD) {
|
||||
@@ -4369,16 +4366,9 @@ void HTMLInputElement::UnbindFromTree(bool aDeep, bool aNullParent) {
|
||||
WillRemoveFromRadioGroup();
|
||||
}
|
||||
|
||||
if (GetShadowRoot() && IsInComposedDoc()) {
|
||||
nsContentUtils::AddScriptRunner(NS_NewRunnableFunction(
|
||||
"HTMLInputElement::UnbindFromTree::UAWidgetUnbindFromTree",
|
||||
[self = RefPtr<Element>(this)]() {
|
||||
nsContentUtils::DispatchChromeEvent(
|
||||
self->OwnerDoc(), self,
|
||||
NS_LITERAL_STRING("UAWidgetUnbindFromTree"), CanBubble::eYes,
|
||||
Cancelable::eNo);
|
||||
self->UnattachShadow();
|
||||
}));
|
||||
if ((mType == NS_FORM_INPUT_TIME || mType == NS_FORM_INPUT_DATE) &&
|
||||
nsContentUtils::IsUAWidgetEnabled() && IsInComposedDoc()) {
|
||||
NotifyUAWidgetTeardown();
|
||||
}
|
||||
|
||||
nsImageLoadingContent::UnbindFromTree(aDeep, aNullParent);
|
||||
@@ -4557,30 +4547,15 @@ void HTMLInputElement::HandleTypeChange(uint8_t aNewType, bool aNotify) {
|
||||
if (oldType == NS_FORM_INPUT_TIME || oldType == NS_FORM_INPUT_DATE) {
|
||||
if (mType != NS_FORM_INPUT_TIME && mType != NS_FORM_INPUT_DATE) {
|
||||
// Switch away from date/time type.
|
||||
RefPtr<Element> self = this;
|
||||
nsContentUtils::AddScriptRunner(NS_NewRunnableFunction(
|
||||
"HTMLInputElement::UnbindFromTree::UAWidgetUnbindFromTree",
|
||||
[self]() {
|
||||
nsContentUtils::DispatchChromeEvent(
|
||||
self->OwnerDoc(), self,
|
||||
NS_LITERAL_STRING("UAWidgetUnbindFromTree"), CanBubble::eYes,
|
||||
Cancelable::eNo);
|
||||
self->UnattachShadow();
|
||||
}));
|
||||
NotifyUAWidgetTeardown();
|
||||
} else {
|
||||
// Switch between date and time.
|
||||
AsyncEventDispatcher* dispatcher = new AsyncEventDispatcher(
|
||||
this, NS_LITERAL_STRING("UAWidgetAttributeChanged"),
|
||||
CanBubble::eYes, ChromeOnlyDispatch::eYes);
|
||||
dispatcher->RunDOMEventWhenSafe();
|
||||
NotifyUAWidgetSetupOrChange();
|
||||
}
|
||||
} else if (mType == NS_FORM_INPUT_TIME || mType == NS_FORM_INPUT_DATE) {
|
||||
// Switch to date/time type.
|
||||
AttachAndSetUAShadowRoot();
|
||||
AsyncEventDispatcher* dispatcher = new AsyncEventDispatcher(
|
||||
this, NS_LITERAL_STRING("UAWidgetBindToTree"), CanBubble::eYes,
|
||||
ChromeOnlyDispatch::eYes);
|
||||
dispatcher->RunDOMEventWhenSafe();
|
||||
NotifyUAWidgetSetupOrChange();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user