Bug 1823757 - add PopoverInvokerElement interface r=emilio

Differential Revision: https://phabricator.services.mozilla.com/D173180
This commit is contained in:
Alexander Surkov 2023-03-23 13:23:25 +00:00
parent 3591a80eeb
commit 50c3cdaa4f
7 changed files with 80 additions and 0 deletions

View File

@ -2749,6 +2749,15 @@ bool nsGenericHTMLFormControlElement::IsAutocapitalizeInheriting() const {
//---------------------------------------------------------------------- //----------------------------------------------------------------------
static const nsAttrValue::EnumTable kPopoverTargetActionTable[] = {
{"toggle", PopoverTargetAction::Toggle},
{"show", PopoverTargetAction::Show},
{"hide", PopoverTargetAction::Hide},
{nullptr, 0}};
static const nsAttrValue::EnumTable* kPopoverTargetActionDefault =
&kPopoverTargetActionTable[0];
nsGenericHTMLFormControlElementWithState:: nsGenericHTMLFormControlElementWithState::
nsGenericHTMLFormControlElementWithState( nsGenericHTMLFormControlElementWithState(
already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo, already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo,
@ -2760,6 +2769,33 @@ nsGenericHTMLFormControlElementWithState::
mStateKey.SetIsVoid(true); mStateKey.SetIsVoid(true);
} }
bool nsGenericHTMLFormControlElementWithState::ParseAttribute(
int32_t aNamespaceID, nsAtom* aAttribute, const nsAString& aValue,
nsIPrincipal* aMaybeScriptedPrincipal, nsAttrValue& aResult) {
if (aNamespaceID == kNameSpaceID_None &&
aAttribute == nsGkAtoms::popovertargetaction &&
StaticPrefs::dom_element_popover_enabled()) {
return aResult.ParseEnumValue(aValue, kPopoverTargetActionTable, false,
kPopoverTargetActionDefault);
}
return nsGenericHTMLFormControlElement::ParseAttribute(
aNamespaceID, aAttribute, aValue, aMaybeScriptedPrincipal, aResult);
}
mozilla::dom::Element*
nsGenericHTMLFormControlElementWithState::GetPopoverTargetElement() const {
// TODO: implement attr-associated element algorithm, see
// https://html.spec.whatwg.org/multipage/common-dom-interfaces.html#attr-associated-element
return nullptr;
}
void nsGenericHTMLFormControlElementWithState::SetPopoverTargetElement(
mozilla::dom::Element*) {
// TODO: implement attr-associated element algorithm, see setter steps at
// https://html.spec.whatwg.org/multipage/common-dom-interfaces.html#attr-associated-element
}
void nsGenericHTMLFormControlElementWithState::GenerateStateKey() { void nsGenericHTMLFormControlElementWithState::GenerateStateKey() {
// Keep the key if already computed // Keep the key if already computed
if (!mStateKey.IsVoid()) { if (!mStateKey.IsVoid()) {

View File

@ -1205,6 +1205,12 @@ class nsGenericHTMLFormControlElement : public nsGenericHTMLFormElement,
mozilla::dom::HTMLFieldSetElement* mFieldSet; mozilla::dom::HTMLFieldSetElement* mFieldSet;
}; };
enum class PopoverTargetAction : uint8_t {
Toggle,
Show,
Hide,
};
class nsGenericHTMLFormControlElementWithState class nsGenericHTMLFormControlElementWithState
: public nsGenericHTMLFormControlElement { : public nsGenericHTMLFormControlElement {
public: public:
@ -1212,6 +1218,22 @@ class nsGenericHTMLFormControlElementWithState
already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo, already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo,
mozilla::dom::FromParser aFromParser, FormControlType); mozilla::dom::FromParser aFromParser, FormControlType);
// nsIContent
bool ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute,
const nsAString& aValue,
nsIPrincipal* aMaybeScriptedPrincipal,
nsAttrValue& aResult) override;
// PopoverInvokerElement
mozilla::dom::Element* GetPopoverTargetElement() const;
void SetPopoverTargetElement(mozilla::dom::Element*);
void GetPopoverTargetAction(nsAString& aValue) const {
GetHTMLEnumAttr(nsGkAtoms::popovertargetaction, aValue);
}
void SetPopoverTargetAction(const nsAString& aValue) {
SetHTMLAttr(nsGkAtoms::popovertargetaction, aValue);
}
/** /**
* Get the presentation state for a piece of content, or create it if it does * Get the presentation state for a piece of content, or create it if it does
* not exist. Generally used by SaveState(). * not exist. Generally used by SaveState().

View File

@ -46,3 +46,5 @@ interface HTMLButtonElement : HTMLElement {
readonly attribute NodeList labels; readonly attribute NodeList labels;
}; };
HTMLButtonElement includes PopoverInvokerElement;

View File

@ -228,6 +228,8 @@ HTMLInputElement includes MozEditableElement;
HTMLInputElement includes MozImageLoadingContent; HTMLInputElement includes MozImageLoadingContent;
HTMLInputElement includes PopoverInvokerElement;
// https://wicg.github.io/entries-api/#idl-index // https://wicg.github.io/entries-api/#idl-index
partial interface HTMLInputElement { partial interface HTMLInputElement {
[Pref="dom.webkitBlink.filesystem.enabled", Frozen, Cached, Pure] [Pref="dom.webkitBlink.filesystem.enabled", Frozen, Cached, Pure]

View File

@ -0,0 +1,13 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*
* The origin of this IDL file is
* https://html.spec.whatwg.org/multipage/popover.html#popoverinvokerelement
*/
interface mixin PopoverInvokerElement {
[Pref="dom.element.popover.enabled", CEReactions] attribute Element? popoverTargetElement;
[Pref="dom.element.popover.enabled", CEReactions] attribute DOMString popoverTargetAction;
};

View File

@ -271,6 +271,9 @@ with Files("GeolocationPosition*"):
with Files("ProfileTimelineMarker.webidl"): with Files("ProfileTimelineMarker.webidl"):
BUG_COMPONENT = ("DevTools", "Performance Tools (Profiler/Timeline)") BUG_COMPONENT = ("DevTools", "Performance Tools (Profiler/Timeline)")
with Files("PopoverInvokerElement.webidl"):
BUG_COMPONENT = ("Core", "DOM: Core & HTML")
with Files("ProgressEvent.webidl"): with Files("ProgressEvent.webidl"):
BUG_COMPONENT = ("Core", "DOM: Events") BUG_COMPONENT = ("Core", "DOM: Events")
@ -792,6 +795,7 @@ WEBIDL_FILES = [
"Plugin.webidl", "Plugin.webidl",
"PluginArray.webidl", "PluginArray.webidl",
"PointerEvent.webidl", "PointerEvent.webidl",
"PopoverInvokerElement.webidl",
"ProcessingInstruction.webidl", "ProcessingInstruction.webidl",
"ProfileTimelineMarker.webidl", "ProfileTimelineMarker.webidl",
"Promise.webidl", "Promise.webidl",

View File

@ -1004,6 +1004,7 @@ STATIC_ATOMS = [
Atom("popover", "popover"), Atom("popover", "popover"),
Atom("popoverhidetarget", "popoverhidetarget"), Atom("popoverhidetarget", "popoverhidetarget"),
Atom("popovershowtarget", "popovershowtarget"), Atom("popovershowtarget", "popovershowtarget"),
Atom("popovertargetaction", "popovertargetaction"),
Atom("popovertoggletarget", "popovertoggletarget"), Atom("popovertoggletarget", "popovertoggletarget"),
Atom("popup", "popup"), Atom("popup", "popup"),
Atom("popupalign", "popupalign"), Atom("popupalign", "popupalign"),