Skip to content

Commit

Permalink
Backed out changeset adc083051939 (bug 1823359) for causing wpt failu…
Browse files Browse the repository at this point in the history
…res on popover-light-dismiss.html
  • Loading branch information
Norisz Fay committed Mar 23, 2023
1 parent 2b94f48 commit 33c7b8b
Show file tree
Hide file tree
Showing 15 changed files with 60 additions and 84 deletions.
20 changes: 3 additions & 17 deletions dom/base/Document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,6 @@
#include "mozilla/dom/StyleSheetApplicableStateChangeEventBinding.h"
#include "mozilla/dom/StyleSheetList.h"
#include "mozilla/dom/TimeoutManager.h"
#include "mozilla/dom/ToggleEvent.h"
#include "mozilla/dom/Touch.h"
#include "mozilla/dom/TouchEvent.h"
#include "mozilla/dom/TreeOrderedArrayInlines.h"
Expand Down Expand Up @@ -14896,38 +14895,25 @@ void Document::HideAllPopoversUntil(nsINode& aEndpoint,
}
}

// https://html.spec.whatwg.org/#dom-hidepopover
void Document::HidePopover(Element& aPopover, bool aFocusPreviousElement,
bool aFireEvents, ErrorResult& aRv) {
RefPtr<nsGenericHTMLElement> popoverHTMLEl =
nsGenericHTMLElement::FromNode(aPopover);
auto* popoverHTMLEl = nsGenericHTMLElement::FromNode(aPopover);
NS_ASSERTION(popoverHTMLEl, "Not a HTML element");

if (!popoverHTMLEl->CheckPopoverValidity(PopoverVisibilityState::Showing,
if (!popoverHTMLEl->CheckPopoverValidity(PopoverVisibilityState::Hidden,
aRv)) {
return;
}

// TODO: Run auto popover steps.
// Fire beforetoggle event and re-check popover validity.
if (aFireEvents) {
// Intentionally ignore the return value here as only on open event the
// cancelable attribute is initialized to true.
popoverHTMLEl->FireBeforeToggle(true);
if (!popoverHTMLEl->CheckPopoverValidity(PopoverVisibilityState::Showing,
aRv)) {
return;
}
}

// TODO: Fire beforetoggle event and re-check popover validity.
// TODO: Remove from Top Layer.

popoverHTMLEl->PopoverPseudoStateUpdate(false, true);
popoverHTMLEl->GetPopoverData()->SetPopoverVisibilityState(
PopoverVisibilityState::Hidden);

// TODO: Queue popover toggle event task.
// TODO: Handle element focus.
}

nsTArray<Element*> Document::AutoPopoverList() const {
Expand Down
1 change: 0 additions & 1 deletion dom/events/EventNameList.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@
#endif /* BEFOREUNLOAD_EVENT */

EVENT(abort, eImageAbort, EventNameType_All, eBasicEventClass)
EVENT(beforetoggle, eBeforeToggle, EventNameType_HTMLXUL, eBasicEventClass)
EVENT(bounce, eMarqueeBounce, EventNameType_HTMLMarqueeOnly, eBasicEventClass)
EVENT(canplay, eCanPlay, EventNameType_HTML, eBasicEventClass)
EVENT(canplaythrough, eCanPlayThrough, EventNameType_HTML, eBasicEventClass)
Expand Down
55 changes: 9 additions & 46 deletions dom/html/nsGenericHTMLElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@
#include "nsTextFragment.h"
#include "mozilla/dom/BindingUtils.h"
#include "mozilla/dom/MouseEventBinding.h"
#include "mozilla/dom/ToggleEvent.h"
#include "mozilla/dom/TouchEvent.h"
#include "mozilla/ErrorResult.h"
#include "nsHTMLDocument.h"
Expand Down Expand Up @@ -674,17 +673,14 @@ nsresult nsGenericHTMLElement::AfterSetAttr(
// The missing value default is the no popover state.
newState = PopoverState::None;
}
PopoverState oldState = GetPopoverState();
if (newState != oldState) {
if (oldState != PopoverState::None) {
HidePopoverInternal(/* aFireEvents = */ false, IgnoreErrors());
if (newState != GetPopoverState()) {
if (PopoverOpen()) {
HidePopover(IgnoreErrors());
}
if (newState != PopoverState::None) {
EnsurePopoverData().SetPopoverState(newState);
PopoverPseudoStateUpdate(false, true);
} else {
if (newState == PopoverState::None) {
ClearPopoverData();
RemoveStates(ElementState::OPEN | ElementState::CLOSED);
} else {
EnsurePopoverData().SetPopoverState(newState);
}
}
} else if (aName == nsGkAtoms::dir) {
Expand Down Expand Up @@ -3186,57 +3182,24 @@ void nsGenericHTMLElement::PopoverPseudoStateUpdate(bool aOpen, bool aNotify) {
ToggleStates(changedStates, aNotify);
}

bool nsGenericHTMLElement::FireBeforeToggle(bool aIsOpen) {
ToggleEventInit init;
init.mBubbles = false;
if (aIsOpen) {
init.mCancelable = false;
init.mOldState = u"open"_ns;
init.mNewState = u"closed"_ns;
} else {
init.mCancelable = true;
init.mOldState = u"closed"_ns;
init.mNewState = u"open"_ns;
}
RefPtr<ToggleEvent> event =
ToggleEvent::Constructor(this, u"beforetoggle"_ns, init);
event->SetTrusted(true);

EventDispatcher::DispatchDOMEvent(MOZ_KnownLive(ToSupports(this)), nullptr,
event, nullptr, nullptr);
return event->DefaultPrevented();
}

// https://html.spec.whatwg.org/#dom-showpopover
void nsGenericHTMLElement::ShowPopover(ErrorResult& aRv) {
if (!CheckPopoverValidity(PopoverVisibilityState::Hidden, aRv)) {
return;
}
// Fire beforetoggle event and re-check popover validity.
if (FireBeforeToggle(false)) {
return;
}
if (!CheckPopoverValidity(PopoverVisibilityState::Hidden, aRv)) {
return;
}
// TODO: Fire beforetoggle event and re-check popover validity.
// TODO: Run auto popover steps.
// TODO: Add to Top Layer.
GetPopoverData()->SetPopoverVisibilityState(PopoverVisibilityState::Showing);

PopoverPseudoStateUpdate(true, true);
GetPopoverData()->SetPopoverVisibilityState(PopoverVisibilityState::Showing);

// TODO: Handle popover focusing.
// TODO: Queue popover toggle event task.
}

// https://html.spec.whatwg.org/#dom-hidepopover
void nsGenericHTMLElement::HidePopover(ErrorResult& aRv) {
HidePopoverInternal(true, aRv);
}

void nsGenericHTMLElement::HidePopoverInternal(bool aFireEvents,
ErrorResult& aRv) {
OwnerDoc()->HidePopover(*this, true, aFireEvents, aRv);
OwnerDoc()->HidePopover(*this, true, true, aRv);
}

// https://html.spec.whatwg.org/multipage/popover.html#dom-togglepopover
Expand Down
6 changes: 1 addition & 5 deletions dom/html/nsGenericHTMLElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,7 @@ class nsGenericHTMLElement : public nsGenericHTMLElementBase {
bool PopoverOpen() const;
bool CheckPopoverValidity(mozilla::dom::PopoverVisibilityState aExpectedState,
ErrorResult& aRv);
/** Returns true if the event has been cancelled. */
MOZ_CAN_RUN_SCRIPT bool FireBeforeToggle(bool aIsOpen);
MOZ_CAN_RUN_SCRIPT void ShowPopover(ErrorResult& aRv);
MOZ_CAN_RUN_SCRIPT void HidePopoverInternal(bool aFireEvents,
ErrorResult& aRv);
void ShowPopover(ErrorResult& aRv);
MOZ_CAN_RUN_SCRIPT void HidePopover(ErrorResult& aRv);
MOZ_CAN_RUN_SCRIPT void TogglePopover(bool force, ErrorResult& aRv);

Expand Down
2 changes: 0 additions & 2 deletions dom/webidl/EventHandler.webidl
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ interface mixin GlobalEventHandlers {
attribute EventHandler onauxclick;
[Pref="dom.input_events.beforeinput.enabled"]
attribute EventHandler onbeforeinput;
[Pref="dom.element.popover.enabled"]
attribute EventHandler onbeforetoggle;
attribute EventHandler oncanplay;
attribute EventHandler oncanplaythrough;
attribute EventHandler onchange;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@
[Removing a visible popover=auto element from the document should close the popover]
expected: FAIL

[A showing popover=auto does not match :modal]
expected: FAIL

[Removing a visible popover=hint element from the document should close the popover]
expected: FAIL

Expand All @@ -72,6 +75,9 @@
[Removing a visible popover=manual element from the document should close the popover]
expected: FAIL

[A showing popover=manual does not match :modal]
expected: FAIL

[Changing the popover type in a "beforetoggle" event handler should throw an exception (during showPopover())]
expected: FAIL

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[popover-beforetoggle-opening-event.html]
[Ensure the `beforetoggle` event can be used to populate content before the popover renders]
expected: FAIL
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,3 @@

[Popover focus returns when popover is hidden by invoker]
expected: FAIL

[Circular reference tab navigation]
expected: FAIL
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
[popover-focus-child-dialog.html]
max-asserts: 2
expected:
if (os == "android") and fission: [ERROR, TIMEOUT]
ERROR
max-asserts: 2
[Popovers should not initially focus child popover elements.]
expected: NOTRUN
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
[Clicking inside a parent popover should close child popover]
expected: FAIL

[Clicking on invoking element, after using it for activation, shouldn't close its popover]
expected: FAIL

[Clicking on invoking element, after using it for activation, shouldn't close its popover (nested case)]
expected: FAIL

Expand Down Expand Up @@ -54,6 +57,12 @@
[An invoking element that was not used to invoke the popover can still be part of the ancestor chain]
expected: FAIL

[Scrolling within a popover should not close the popover]
expected: FAIL

[Moving focus back to the anchor element should not dismiss the popover]
expected: FAIL

[Ensure circular/convoluted ancestral relationships are functional]
expected: FAIL

Expand All @@ -68,6 +77,3 @@

[Light dismiss of mixed popover types including hints]
expected: FAIL

[Scrolling within a popover should not close the popover]
expected: FAIL
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[popover-not-keyboard-focusable.html]
[Popover should not be keyboard focusable]
expected: FAIL
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
[popover-shadow-dom.html]
[Popovers located inside shadow DOM can still be shown]
expected: FAIL

[anchor references do not cross shadow boundaries]
expected: FAIL

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,28 @@
[popover-top-layer-interactions.html]
expected: ERROR
[A Popover API should close a Popover API]
expected: FAIL

[A Modal Dialog should close a Popover API]
expected: FAIL
expected: NOTRUN

[A Fullscreen Element should close a Popover API]
expected: FAIL
expected: NOTRUN

[A Popover API should *not* close a Modal Dialog]
expected: NOTRUN

[A Popover API should *not* close a Fullscreen Element]
expected: NOTRUN

[A Fullscreen Element should *not* close a Fullscreen Element]
expected: FAIL
expected: NOTRUN

[A Modal Dialog should *not* close a Modal Dialog]
expected: NOTRUN

[A Fullscreen Element should *not* close a Modal Dialog]
expected: NOTRUN

[A Modal Dialog should *not* close a Fullscreen Element]
expected: NOTRUN
2 changes: 0 additions & 2 deletions widget/EventMessageList.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,6 @@ NS_EVENT_MESSAGE(eContextMenu)

NS_EVENT_MESSAGE(eCueChange)

NS_EVENT_MESSAGE(eBeforeToggle)

NS_EVENT_MESSAGE(eLoad)
NS_EVENT_MESSAGE(eUnload)
NS_EVENT_MESSAGE(eHashChange)
Expand Down
1 change: 0 additions & 1 deletion xpcom/ds/StaticAtoms.py
Original file line number Diff line number Diff line change
Expand Up @@ -1980,7 +1980,6 @@
Atom("onmozshowdropdown_sourcetouch", "onmozshowdropdown-sourcetouch"),
Atom("onprintPreviewUpdate", "onprintPreviewUpdate"),
Atom("onscrollend", "onscrollend"),
Atom("onbeforetoggle", "onbeforetoggle"),
# WebExtensions
Atom("moz_extension", "moz-extension"),
Atom("all_urlsPermission", "<all_urls>"),
Expand Down

0 comments on commit 33c7b8b

Please sign in to comment.