зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1637307 - Push/Pop dialog to top layer when needed r=smaug
This patch completes the top layer requirement for showModal() Spec: https://html.spec.whatwg.org/multipage/interactive-elements.html#dom-dialog-showmodal Differential Revision: https://phabricator.services.mozilla.com/D74922
This commit is contained in:
Родитель
093f9492b3
Коммит
ca6d5ba134
|
@ -13415,6 +13415,17 @@ Element* Document::GetTopLayerTop() {
|
||||||
return element;
|
return element;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Document::DoesTopLayerContain(const Element* aElement) const {
|
||||||
|
for (const nsWeakPtr& weakPtr : mTopLayer) {
|
||||||
|
nsCOMPtr<Element> element(do_QueryReferent(weakPtr));
|
||||||
|
if (element && element == aElement) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
Element* Document::GetUnretargetedFullScreenElement() {
|
Element* Document::GetUnretargetedFullScreenElement() {
|
||||||
for (const nsWeakPtr& weakPtr : Reversed(mTopLayer)) {
|
for (const nsWeakPtr& weakPtr : Reversed(mTopLayer)) {
|
||||||
nsCOMPtr<Element> element(do_QueryReferent(weakPtr));
|
nsCOMPtr<Element> element(do_QueryReferent(weakPtr));
|
||||||
|
|
|
@ -3405,6 +3405,9 @@ class Document : public nsINode,
|
||||||
// Not const because all the fullscreen goop is not const
|
// Not const because all the fullscreen goop is not const
|
||||||
bool FullscreenEnabled(CallerType aCallerType);
|
bool FullscreenEnabled(CallerType aCallerType);
|
||||||
Element* GetTopLayerTop();
|
Element* GetTopLayerTop();
|
||||||
|
|
||||||
|
bool DoesTopLayerContain(const Element* aElement) const;
|
||||||
|
|
||||||
// Return the fullscreen element in the top layer
|
// Return the fullscreen element in the top layer
|
||||||
Element* GetUnretargetedFullScreenElement();
|
Element* GetUnretargetedFullScreenElement();
|
||||||
bool Fullscreen() { return !!GetFullscreenElement(); }
|
bool Fullscreen() { return !!GetFullscreenElement(); }
|
||||||
|
|
|
@ -44,6 +44,13 @@ void HTMLDialogElement::Close(
|
||||||
ErrorResult ignored;
|
ErrorResult ignored;
|
||||||
SetOpen(false, ignored);
|
SetOpen(false, ignored);
|
||||||
ignored.SuppressException();
|
ignored.SuppressException();
|
||||||
|
|
||||||
|
Document* doc = OwnerDoc();
|
||||||
|
auto predictFunc = [self = RefPtr<HTMLDialogElement>(this)](
|
||||||
|
Element* element) { return element == self; };
|
||||||
|
|
||||||
|
doc->TopLayerPop(predictFunc);
|
||||||
|
|
||||||
RefPtr<AsyncEventDispatcher> eventDispatcher = new AsyncEventDispatcher(
|
RefPtr<AsyncEventDispatcher> eventDispatcher = new AsyncEventDispatcher(
|
||||||
this, NS_LITERAL_STRING("close"), CanBubble::eNo);
|
this, NS_LITERAL_STRING("close"), CanBubble::eNo);
|
||||||
eventDispatcher->PostDOMEvent();
|
eventDispatcher->PostDOMEvent();
|
||||||
|
@ -58,12 +65,32 @@ void HTMLDialogElement::Show() {
|
||||||
ignored.SuppressException();
|
ignored.SuppressException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool HTMLDialogElement::IsInTopLayer() const {
|
||||||
|
return OwnerDoc()->DoesTopLayerContain(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void HTMLDialogElement::UnbindFromTree(bool aNullParent) {
|
||||||
|
if (IsInTopLayer()) {
|
||||||
|
Document* doc = OwnerDoc();
|
||||||
|
auto predictFunc = [self = RefPtr<HTMLDialogElement>(this)](
|
||||||
|
Element* element) { return element == self; };
|
||||||
|
|
||||||
|
doc->TopLayerPop(predictFunc);
|
||||||
|
}
|
||||||
|
nsGenericHTMLElement::UnbindFromTree(aNullParent);
|
||||||
|
}
|
||||||
|
|
||||||
void HTMLDialogElement::ShowModal(ErrorResult& aError) {
|
void HTMLDialogElement::ShowModal(ErrorResult& aError) {
|
||||||
if (!IsInComposedDoc() || Open()) {
|
if (!IsInComposedDoc() || Open()) {
|
||||||
aError.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
aError.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Document* doc = OwnerDoc();
|
||||||
|
if (!IsInTopLayer()) {
|
||||||
|
doc->TopLayerPush(this);
|
||||||
|
}
|
||||||
|
|
||||||
SetOpen(true, aError);
|
SetOpen(true, aError);
|
||||||
aError.SuppressException();
|
aError.SuppressException();
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,10 +37,14 @@ class HTMLDialogElement final : public nsGenericHTMLElement {
|
||||||
mReturnValue = aReturnValue;
|
mReturnValue = aReturnValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual void UnbindFromTree(bool aNullParent = true) override;
|
||||||
|
|
||||||
void Close(const mozilla::dom::Optional<nsAString>& aReturnValue);
|
void Close(const mozilla::dom::Optional<nsAString>& aReturnValue);
|
||||||
void Show();
|
void Show();
|
||||||
void ShowModal(ErrorResult& aError);
|
void ShowModal(ErrorResult& aError);
|
||||||
|
|
||||||
|
bool IsInTopLayer() const;
|
||||||
|
|
||||||
nsString mReturnValue;
|
nsString mReturnValue;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
Загрузка…
Ссылка в новой задаче