Bug 1828674: part 2) Set a popover's state to auto when the corresponding attribute value is the empty string. r=emilio
Differential Revision: https://phabricator.services.mozilla.com/D177764
This commit is contained in:
@@ -184,12 +184,20 @@ nsresult nsGenericHTMLElement::CopyInnerTo(Element* aDst) {
|
||||
static const nsAttrValue::EnumTable kDirTable[] = {
|
||||
{"ltr", eDir_LTR}, {"rtl", eDir_RTL}, {"auto", eDir_Auto}, {nullptr, 0}};
|
||||
|
||||
namespace {
|
||||
// See <https://html.spec.whatwg.org/#the-popover-attribute>.
|
||||
enum class PopoverAttributeKeyword : uint8_t { Auto, EmptyString, Manual };
|
||||
} // namespace
|
||||
|
||||
static const nsAttrValue::EnumTable kPopoverTable[] = {
|
||||
{"auto", PopoverState::Auto},
|
||||
{"manual", PopoverState::Manual},
|
||||
{"auto", PopoverAttributeKeyword::Auto},
|
||||
{"", PopoverAttributeKeyword::EmptyString},
|
||||
{"manual", PopoverAttributeKeyword::Manual},
|
||||
{nullptr, 0}};
|
||||
|
||||
static const nsAttrValue::EnumTable* kPopoverTableDefault = &kPopoverTable[1];
|
||||
// See <https://html.spec.whatwg.org/#the-popover-attribute>.
|
||||
static const nsAttrValue::EnumTable* kPopoverTableInvalidValueDefault =
|
||||
&kPopoverTable[2];
|
||||
|
||||
void nsGenericHTMLElement::AddToNameTable(nsAtom* aName) {
|
||||
MOZ_ASSERT(HasName(), "Node doesn't have name?");
|
||||
@@ -653,22 +661,40 @@ void nsGenericHTMLElement::BeforeSetAttr(int32_t aNamespaceID, nsAtom* aName,
|
||||
aNotify);
|
||||
}
|
||||
|
||||
namespace {
|
||||
constexpr PopoverState ToPopoverState(
|
||||
PopoverAttributeKeyword aPopoverAttributeKeyword) {
|
||||
// See <https://html.spec.whatwg.org/#the-popover-attribute>.
|
||||
switch (aPopoverAttributeKeyword) {
|
||||
case PopoverAttributeKeyword::Auto:
|
||||
return PopoverState::Auto;
|
||||
case PopoverAttributeKeyword::EmptyString:
|
||||
return PopoverState::Auto;
|
||||
case PopoverAttributeKeyword::Manual:
|
||||
return PopoverState::Manual;
|
||||
default: {
|
||||
MOZ_ASSERT_UNREACHABLE();
|
||||
return PopoverState::None;
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
void nsGenericHTMLElement::AfterSetPopoverAttr() {
|
||||
const nsAttrValue* newValue = GetParsedAttr(nsGkAtoms::popover);
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/popover.html#attr-popover
|
||||
PopoverState newState;
|
||||
if (newValue) {
|
||||
if (newValue->Type() == nsAttrValue::eEnum) {
|
||||
newState = static_cast<dom::PopoverState>(newValue->GetEnumValue());
|
||||
} else {
|
||||
// The invalid value default is the manual state
|
||||
newState = PopoverState::Manual;
|
||||
}
|
||||
MOZ_ASSERT(newValue->Type() == nsAttrValue::eEnum);
|
||||
const PopoverAttributeKeyword popoverAttributeKeyword =
|
||||
static_cast<PopoverAttributeKeyword>(newValue->GetEnumValue());
|
||||
newState = ToPopoverState(popoverAttributeKeyword);
|
||||
} else {
|
||||
// The missing value default is the no popover state.
|
||||
// The missing value default is the no popover state, see
|
||||
// <https://html.spec.whatwg.org/multipage/popover.html#attr-popover>.
|
||||
newState = PopoverState::None;
|
||||
}
|
||||
|
||||
PopoverState oldState = GetPopoverState();
|
||||
if (newState != oldState) {
|
||||
if (oldState != PopoverState::None) {
|
||||
@@ -957,7 +983,7 @@ bool nsGenericHTMLElement::ParseAttribute(int32_t aNamespaceID,
|
||||
if (aAttribute == nsGkAtoms::popover &&
|
||||
StaticPrefs::dom_element_popover_enabled()) {
|
||||
return aResult.ParseEnumValue(aValue, kPopoverTable, false,
|
||||
kPopoverTableDefault);
|
||||
kPopoverTableInvalidValueDefault);
|
||||
}
|
||||
|
||||
if (aAttribute == nsGkAtoms::tabindex) {
|
||||
|
||||
Reference in New Issue
Block a user