Skip to content

Commit

Permalink
Bug 1771150 - Make fullscreen modal. r=smaug
Browse files Browse the repository at this point in the history
  • Loading branch information
emilio committed Jun 27, 2022
1 parent 4fdd211 commit 016a64f
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 24 deletions.
28 changes: 11 additions & 17 deletions dom/base/Document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14574,7 +14574,7 @@ bool Document::PopFullscreenElement(UpdateViewport aUpdateViewport) {
}

MOZ_ASSERT(removedElement->State().HasState(ElementState::FULLSCREEN));
removedElement->RemoveStates(ElementState::FULLSCREEN);
removedElement->RemoveStates(ElementState::FULLSCREEN | ElementState::MODAL);
NotifyFullScreenChangedForMediaElement(*removedElement);
// Reset iframe fullscreen flag.
if (auto* iframe = HTMLIFrameElement::FromNode(removedElement)) {
Expand All @@ -14587,23 +14587,18 @@ bool Document::PopFullscreenElement(UpdateViewport aUpdateViewport) {
}

void Document::SetFullscreenElement(Element& aElement) {
aElement.AddStates(ElementState::FULLSCREEN);
ElementState statesToAdd = ElementState::FULLSCREEN;
if (StaticPrefs::dom_fullscreen_modal()) {
statesToAdd |= ElementState::MODAL;
}
aElement.AddStates(statesToAdd);
TopLayerPush(aElement);
NotifyFullScreenChangedForMediaElement(aElement);
UpdateViewportScrollbarOverrideForFullscreen(this);
}

static ElementState TopLayerModalStates() {
ElementState modalStates = ElementState::MODAL_DIALOG;
if (StaticPrefs::dom_fullscreen_modal()) {
modalStates |= ElementState::FULLSCREEN;
}
return modalStates;
}

void Document::TopLayerPush(Element& aElement) {
const bool modal =
aElement.State().HasAtLeastOneOfStates(TopLayerModalStates());
const bool modal = aElement.State().HasState(ElementState::MODAL);

auto predictFunc = [&aElement](Element* element) {
return element == &aElement;
Expand Down Expand Up @@ -14640,7 +14635,7 @@ void Document::TopLayerPush(Element& aElement) {
}

void Document::AddModalDialog(HTMLDialogElement& aDialogElement) {
aDialogElement.AddStates(ElementState::MODAL_DIALOG);
aDialogElement.AddStates(ElementState::MODAL);
TopLayerPush(aDialogElement);
}

Expand All @@ -14650,7 +14645,7 @@ void Document::RemoveModalDialog(HTMLDialogElement& aDialogElement) {
};
DebugOnly<Element*> removedElement = TopLayerPop(predicate);
MOZ_ASSERT(removedElement == &aDialogElement);
aDialogElement.RemoveStates(ElementState::MODAL_DIALOG);
aDialogElement.RemoveStates(ElementState::MODAL);
}

Element* Document::TopLayerPop(FunctionRef<bool(Element*)> aPredicate) {
Expand Down Expand Up @@ -14691,15 +14686,14 @@ Element* Document::TopLayerPop(FunctionRef<bool(Element*)> aPredicate) {
return nullptr;
}

const ElementState modalStates = TopLayerModalStates();
const bool modal = removedElement->State().HasAtLeastOneOfStates(modalStates);
const bool modal = removedElement->State().HasState(ElementState::MODAL);

if (modal) {
removedElement->RemoveStates(ElementState::TOPMOST_MODAL);
bool foundExistingModalElement = false;
for (const nsWeakPtr& weakPtr : Reversed(mTopLayer)) {
nsCOMPtr<Element> element(do_QueryReferent(weakPtr));
if (element && element->State().HasAtLeastOneOfStates(modalStates)) {
if (element && element->State().HasState(ElementState::MODAL)) {
element->AddStates(ElementState::TOPMOST_MODAL);
foundExistingModalElement = true;
break;
Expand Down
8 changes: 4 additions & 4 deletions dom/base/rust/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ bitflags! {
const AUTOFILL = 1u64 << 40;
/// Non-standard & undocumented.
const AUTOFILL_PREVIEW = 1u64 << 41;
/// State that dialog element is modal, for centered alignment
/// <https://html.spec.whatwg.org/multipage/#centered-alignment>
const MODAL_DIALOG = 1u64 << 42;
/// State for modal elements:
/// <https://drafts.csswg.org/selectors-4/#modal-state>
const MODAL = 1u64 << 42;
/// <https://html.spec.whatwg.org/multipage/#inert-subtrees>
const INERT = 1u64 << 43;
/// State for the topmost modal element in top layer
Expand Down Expand Up @@ -164,7 +164,7 @@ bitflags! {
Self::FULLSCREEN.bits |
Self::HOVER.bits |
Self::URLTARGET.bits |
Self::MODAL_DIALOG.bits |
Self::MODAL.bits |
Self::INERT.bits |
Self::TOPMOST_MODAL.bits |
Self::REVEALED.bits;
Expand Down
3 changes: 3 additions & 0 deletions dom/base/test/test_fullscreen_modal.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@

clickButton(/* expectEvent = */ !modal);

ok(document.fullscreenElement.matches(":fullscreen"), "Fullscreen element matches :fullscreen");
is(document.fullscreenElement.matches(":modal"), modal, "Fullscreen element matches :modal");

await document.exitFullscreen();
clickButton(/* expectEvent = */ true);
}
Expand Down
2 changes: 1 addition & 1 deletion dom/html/HTMLDialogElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ void HTMLDialogElement::Show() {
}

bool HTMLDialogElement::IsInTopLayer() const {
return State().HasState(ElementState::MODAL_DIALOG);
return State().HasState(ElementState::MODAL);
}

void HTMLDialogElement::AddToTopLayerIfNeeded() {
Expand Down
2 changes: 1 addition & 1 deletion modules/libpref/init/StaticPrefList.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2384,7 +2384,7 @@
# This matches other browsers but historically not Gecko.
- name: dom.fullscreen.modal
type: bool
value: false
value: true
mirror: always

# Whether the Gamepad API is enabled
Expand Down
2 changes: 1 addition & 1 deletion servo/components/style/gecko/non_ts_pseudo_class_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ macro_rules! apply_non_ts_list {
("-moz-devtools-highlighted", MozDevtoolsHighlighted, DEVTOOLS_HIGHLIGHTED, PSEUDO_CLASS_ENABLED_IN_UA_SHEETS),
("-moz-styleeditor-transitioning", MozStyleeditorTransitioning, STYLEEDITOR_TRANSITIONING, PSEUDO_CLASS_ENABLED_IN_UA_SHEETS),
("fullscreen", Fullscreen, FULLSCREEN, _),
("modal", Modal, MODAL_DIALOG, _),
("modal", Modal, MODAL, _),
("-moz-topmost-modal", MozTopmostModal, TOPMOST_MODAL, PSEUDO_CLASS_ENABLED_IN_UA_SHEETS),
("-moz-broken", MozBroken, BROKEN, _),
("-moz-loading", MozLoading, LOADING, _),
Expand Down

0 comments on commit 016a64f

Please sign in to comment.