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
Родитель 3591a80eeb
Коммит 50c3cdaa4f
7 изменённых файлов: 80 добавлений и 0 удалений

Просмотреть файл

@ -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(
already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo,
@ -2760,6 +2769,33 @@ nsGenericHTMLFormControlElementWithState::
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() {
// Keep the key if already computed
if (!mStateKey.IsVoid()) {

Просмотреть файл

@ -1205,6 +1205,12 @@ class nsGenericHTMLFormControlElement : public nsGenericHTMLFormElement,
mozilla::dom::HTMLFieldSetElement* mFieldSet;
};
enum class PopoverTargetAction : uint8_t {
Toggle,
Show,
Hide,
};
class nsGenericHTMLFormControlElementWithState
: public nsGenericHTMLFormControlElement {
public:
@ -1212,6 +1218,22 @@ class nsGenericHTMLFormControlElementWithState
already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo,
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
* not exist. Generally used by SaveState().

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

@ -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;
};

Просмотреть файл

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

Просмотреть файл

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