Bug 1963845 - Use Span for EnumTable. r=emilio,smaug
This patch makes the usage of `EnumTable`s safer by using `Span`s instead of relying on an empty element at the end. Also the name has been changed from `EnumTable` to `EnumTableEntry` to be more precise. Differential Revision: https://phabricator.services.mozilla.com/D247453
This commit is contained in:
committed by
jjaschke@mozilla.com
parent
6db653dc92
commit
b3debf824d
@@ -1125,10 +1125,10 @@ const DOMTokenListSupportedToken Element::sAnchorAndFormRelValues[] = {
|
||||
"noreferrer", "noopener", "opener", nullptr};
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/urls-and-fetching.html#lazy-loading-attribute
|
||||
static constexpr nsAttrValue::EnumTable kLoadingTable[] = {
|
||||
static constexpr nsAttrValue::EnumTableEntry kLoadingTable[] = {
|
||||
{"eager", Element::Loading::Eager},
|
||||
{"lazy", Element::Loading::Lazy},
|
||||
{nullptr, 0}};
|
||||
};
|
||||
|
||||
void Element::GetLoading(nsAString& aValue) const {
|
||||
GetEnumAttr(nsGkAtoms::loading, kLoadingTable[0].tag, aValue);
|
||||
@@ -1137,7 +1137,8 @@ void Element::GetLoading(nsAString& aValue) const {
|
||||
bool Element::ParseLoadingAttribute(const nsAString& aValue,
|
||||
nsAttrValue& aResult) {
|
||||
return aResult.ParseEnumValue(aValue, kLoadingTable,
|
||||
/* aCaseSensitive = */ false, kLoadingTable);
|
||||
/* aCaseSensitive = */ false,
|
||||
&kLoadingTable[0]);
|
||||
}
|
||||
|
||||
Element::Loading Element::LoadingState() const {
|
||||
@@ -1150,14 +1151,13 @@ Element::Loading Element::LoadingState() const {
|
||||
|
||||
namespace {
|
||||
// <https://html.spec.whatwg.org/multipage/urls-and-fetching.html#fetch-priority-attributes>.
|
||||
static constexpr nsAttrValue::EnumTable kFetchPriorityEnumTable[] = {
|
||||
static constexpr nsAttrValue::EnumTableEntry kFetchPriorityEnumTable[] = {
|
||||
{kFetchPriorityAttributeValueHigh, FetchPriority::High},
|
||||
{kFetchPriorityAttributeValueLow, FetchPriority::Low},
|
||||
{kFetchPriorityAttributeValueAuto, FetchPriority::Auto},
|
||||
{nullptr, 0}};
|
||||
{kFetchPriorityAttributeValueAuto, FetchPriority::Auto}};
|
||||
|
||||
// <https://html.spec.whatwg.org/multipage/urls-and-fetching.html#fetch-priority-attributes>.
|
||||
static const nsAttrValue::EnumTable*
|
||||
static constexpr const nsAttrValue::EnumTableEntry*
|
||||
kFetchPriorityEnumTableInvalidValueDefault = &kFetchPriorityEnumTable[2];
|
||||
} // namespace
|
||||
|
||||
@@ -3874,12 +3874,11 @@ bool Element::Matches(const nsACString& aSelector, ErrorResult& aResult) {
|
||||
return Servo_SelectorList_Matches(this, list);
|
||||
}
|
||||
|
||||
static const nsAttrValue::EnumTable kCORSAttributeTable[] = {
|
||||
static constexpr nsAttrValue::EnumTableEntry kCORSAttributeTable[] = {
|
||||
// Order matters here
|
||||
// See ParseCORSValue
|
||||
{"anonymous", CORS_ANONYMOUS},
|
||||
{"use-credentials", CORS_USE_CREDENTIALS},
|
||||
{nullptr, 0}};
|
||||
{"use-credentials", CORS_USE_CREDENTIALS}};
|
||||
|
||||
/* static */
|
||||
void Element::ParseCORSValue(const nsAString& aValue, nsAttrValue& aResult) {
|
||||
|
||||
@@ -239,7 +239,7 @@ void MiscContainer::Evict() {
|
||||
}
|
||||
}
|
||||
|
||||
nsTArray<const nsAttrValue::EnumTable*>* nsAttrValue::sEnumTableArray = nullptr;
|
||||
nsTArray<nsAttrValue::EnumTableSpan>* nsAttrValue::sEnumTableArray = nullptr;
|
||||
|
||||
nsAttrValue::nsAttrValue() : mBits(0) {}
|
||||
|
||||
@@ -262,7 +262,7 @@ nsAttrValue::~nsAttrValue() { ResetIfSet(); }
|
||||
/* static */
|
||||
void nsAttrValue::Init() {
|
||||
MOZ_ASSERT(!sEnumTableArray, "nsAttrValue already initialized");
|
||||
sEnumTableArray = new nsTArray<const EnumTable*>;
|
||||
sEnumTableArray = new nsTArray<EnumTableSpan>;
|
||||
}
|
||||
|
||||
/* static */
|
||||
@@ -791,19 +791,17 @@ void nsAttrValue::GetEnumString(nsAString& aResult, bool aRealTag) const {
|
||||
? static_cast<uint32_t>(GetIntInternal())
|
||||
: GetMiscContainer()->mValue.mEnumValue;
|
||||
int16_t val = allEnumBits >> NS_ATTRVALUE_ENUMTABLEINDEX_BITS;
|
||||
const EnumTable* table = sEnumTableArray->ElementAt(
|
||||
EnumTableSpan table = sEnumTableArray->ElementAt(
|
||||
allEnumBits & NS_ATTRVALUE_ENUMTABLEINDEX_MASK);
|
||||
|
||||
while (table->tag) {
|
||||
if (table->value == val) {
|
||||
aResult.AssignASCII(table->tag);
|
||||
for (const auto& entry : table) {
|
||||
if (entry.value == val) {
|
||||
aResult.AssignASCII(entry.tag);
|
||||
if (!aRealTag &&
|
||||
allEnumBits & NS_ATTRVALUE_ENUMTABLE_VALUE_NEEDS_TO_UPPER) {
|
||||
nsContentUtils::ASCIIToUpper(aResult);
|
||||
}
|
||||
return;
|
||||
}
|
||||
table++;
|
||||
}
|
||||
|
||||
MOZ_ASSERT_UNREACHABLE("couldn't find value in EnumTable");
|
||||
@@ -1528,8 +1526,19 @@ mozilla::StringBuffer* nsAttrValue::GetStoredStringBuffer() const {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int16_t nsAttrValue::GetEnumTableIndex(const EnumTable* aTable) {
|
||||
int16_t index = sEnumTableArray->IndexOf(aTable);
|
||||
/**
|
||||
* Compares two `EnumTableItem` spans by comparing their data pointer.
|
||||
*/
|
||||
struct EnumTablesHaveEqualContent {
|
||||
bool Equals(const nsAttrValue::EnumTableSpan& aSpan1,
|
||||
const nsAttrValue::EnumTableSpan& aSpan2) const {
|
||||
return aSpan1.Elements() == aSpan2.Elements();
|
||||
}
|
||||
};
|
||||
|
||||
int16_t nsAttrValue::GetEnumTableIndex(EnumTableSpan aTable) {
|
||||
int16_t index =
|
||||
sEnumTableArray->IndexOf(aTable, 0, EnumTablesHaveEqualContent());
|
||||
if (index < 0) {
|
||||
index = sEnumTableArray->Length();
|
||||
NS_ASSERTION(index <= NS_ATTRVALUE_ENUMTABLEINDEX_MAXVALUE,
|
||||
@@ -1540,47 +1549,43 @@ int16_t nsAttrValue::GetEnumTableIndex(const EnumTable* aTable) {
|
||||
return index;
|
||||
}
|
||||
|
||||
int32_t nsAttrValue::EnumTableEntryToValue(const EnumTable* aEnumTable,
|
||||
const EnumTable* aTableEntry) {
|
||||
int32_t nsAttrValue::EnumTableEntryToValue(EnumTableSpan aEnumTable,
|
||||
const EnumTableEntry& aTableEntry) {
|
||||
int16_t index = GetEnumTableIndex(aEnumTable);
|
||||
int32_t value =
|
||||
(aTableEntry->value << NS_ATTRVALUE_ENUMTABLEINDEX_BITS) + index;
|
||||
(aTableEntry.value << NS_ATTRVALUE_ENUMTABLEINDEX_BITS) + index;
|
||||
return value;
|
||||
}
|
||||
|
||||
bool nsAttrValue::ParseEnumValue(const nsAString& aValue,
|
||||
const EnumTable* aTable, bool aCaseSensitive,
|
||||
const EnumTable* aDefaultValue) {
|
||||
EnumTableSpan aTable,
|
||||
bool aCaseSensitive,
|
||||
const EnumTableEntry* aDefaultValue) {
|
||||
ResetIfSet();
|
||||
const EnumTable* tableEntry = aTable;
|
||||
|
||||
while (tableEntry->tag) {
|
||||
if (aCaseSensitive ? aValue.EqualsASCII(tableEntry->tag)
|
||||
: aValue.LowerCaseEqualsASCII(tableEntry->tag)) {
|
||||
for (const auto& tableEntry : aTable) {
|
||||
if (aCaseSensitive ? aValue.EqualsASCII(tableEntry.tag)
|
||||
: aValue.LowerCaseEqualsASCII(tableEntry.tag)) {
|
||||
int32_t value = EnumTableEntryToValue(aTable, tableEntry);
|
||||
|
||||
bool equals = aCaseSensitive || aValue.EqualsASCII(tableEntry->tag);
|
||||
bool equals = aCaseSensitive || aValue.EqualsASCII(tableEntry.tag);
|
||||
if (!equals) {
|
||||
nsAutoString tag;
|
||||
tag.AssignASCII(tableEntry->tag);
|
||||
tag.AssignASCII(tableEntry.tag);
|
||||
nsContentUtils::ASCIIToUpper(tag);
|
||||
if ((equals = tag.Equals(aValue))) {
|
||||
value |= NS_ATTRVALUE_ENUMTABLE_VALUE_NEEDS_TO_UPPER;
|
||||
}
|
||||
}
|
||||
SetIntValueAndType(value, eEnum, equals ? nullptr : &aValue);
|
||||
NS_ASSERTION(GetEnumValue() == tableEntry->value,
|
||||
NS_ASSERTION(GetEnumValue() == tableEntry.value,
|
||||
"failed to store enum properly");
|
||||
|
||||
return true;
|
||||
}
|
||||
tableEntry++;
|
||||
}
|
||||
|
||||
if (aDefaultValue) {
|
||||
MOZ_ASSERT(aTable <= aDefaultValue && aDefaultValue < tableEntry,
|
||||
"aDefaultValue not inside aTable?");
|
||||
SetIntValueAndType(EnumTableEntryToValue(aTable, aDefaultValue), eEnum,
|
||||
SetIntValueAndType(EnumTableEntryToValue(aTable, *aDefaultValue), eEnum,
|
||||
&aValue);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -314,22 +314,21 @@ class nsAttrValue {
|
||||
* Structure for a mapping from int (enum) values to strings. When you use
|
||||
* it you generally create an array of them.
|
||||
* Instantiate like this:
|
||||
* EnumTable myTable[] = {
|
||||
* EnumTableEntry myTable[] = {
|
||||
* { "string1", 1 },
|
||||
* { "string2", 2 },
|
||||
* { nullptr, 0 }
|
||||
* { "string2", 2 }
|
||||
* }
|
||||
*/
|
||||
struct EnumTable {
|
||||
struct EnumTableEntry {
|
||||
// EnumTable can be initialized either with an int16_t value
|
||||
// or a value of an enumeration type that can fit within an int16_t.
|
||||
|
||||
constexpr EnumTable(const char* aTag, int16_t aValue)
|
||||
constexpr EnumTableEntry(const char* aTag, int16_t aValue)
|
||||
: tag(aTag), value(aValue) {}
|
||||
|
||||
template <typename T,
|
||||
typename = typename std::enable_if<std::is_enum<T>::value>::type>
|
||||
constexpr EnumTable(const char* aTag, T aValue)
|
||||
constexpr EnumTableEntry(const char* aTag, T aValue)
|
||||
: tag(aTag), value(static_cast<int16_t>(aValue)) {
|
||||
static_assert(mozilla::EnumTypeFitsWithin<T, int16_t>::value,
|
||||
"aValue must be an enum that fits within int16_t");
|
||||
@@ -343,6 +342,7 @@ class nsAttrValue {
|
||||
int16_t value;
|
||||
};
|
||||
|
||||
using EnumTableSpan = mozilla::Span<const EnumTableEntry>;
|
||||
/**
|
||||
* Parse into an enum value.
|
||||
*
|
||||
@@ -354,9 +354,9 @@ class nsAttrValue {
|
||||
* cause aDefaultValue->value to be stored as the enumeration value.
|
||||
* @return whether the enum value was found or not
|
||||
*/
|
||||
bool ParseEnumValue(const nsAString& aValue, const EnumTable* aTable,
|
||||
bool ParseEnumValue(const nsAString& aValue, EnumTableSpan aTable,
|
||||
bool aCaseSensitive,
|
||||
const EnumTable* aDefaultValue = nullptr);
|
||||
const EnumTableEntry* aDefaultValue = nullptr);
|
||||
|
||||
/**
|
||||
* Parse a string into a dimension value. This is similar to
|
||||
@@ -512,7 +512,7 @@ class nsAttrValue {
|
||||
* @param aTable the EnumTable to get the index of.
|
||||
* @return the index of the EnumTable.
|
||||
*/
|
||||
int16_t GetEnumTableIndex(const EnumTable* aTable);
|
||||
int16_t GetEnumTableIndex(EnumTableSpan aTable);
|
||||
|
||||
inline void SetPtrValueAndType(void* aValue, ValueBaseType aType);
|
||||
void SetIntValueAndType(int32_t aValue, ValueType aType,
|
||||
@@ -541,8 +541,8 @@ class nsAttrValue {
|
||||
const nsAString& aValue) const;
|
||||
// Given an enum table and a particular entry in that table, return
|
||||
// the actual integer value we should store.
|
||||
int32_t EnumTableEntryToValue(const EnumTable* aEnumTable,
|
||||
const EnumTable* aTableEntry);
|
||||
int32_t EnumTableEntryToValue(EnumTableSpan aEnumTable,
|
||||
const EnumTableEntry& aTableEntry);
|
||||
|
||||
template <typename F>
|
||||
bool SubstringCheck(const nsAString& aValue,
|
||||
@@ -551,7 +551,7 @@ class nsAttrValue {
|
||||
static MiscContainer* AllocMiscContainer();
|
||||
static void DeallocMiscContainer(MiscContainer* aCont);
|
||||
|
||||
static nsTArray<const EnumTable*>* sEnumTableArray;
|
||||
static nsTArray<EnumTableSpan>* sEnumTableArray;
|
||||
|
||||
/**
|
||||
* Helper for ParseHTMLDimension and ParseNonzeroHTMLDimension.
|
||||
|
||||
@@ -572,62 +572,66 @@ enum AutocompleteCategory {
|
||||
#undef AUTOCOMPLETE_CATEGORY
|
||||
};
|
||||
|
||||
static const nsAttrValue::EnumTable kAutocompleteUnsupportedFieldNameTable[] = {
|
||||
static constexpr nsAttrValue::EnumTableEntry
|
||||
kAutocompleteUnsupportedFieldNameTable[]{
|
||||
#define AUTOCOMPLETE_UNSUPPORTED_FIELD_NAME(name_, value_) \
|
||||
{value_, eAutocompleteUnsupportedFieldName_##name_},
|
||||
#include "AutocompleteFieldList.h"
|
||||
#undef AUTOCOMPLETE_UNSUPPORTED_FIELD_NAME
|
||||
{nullptr, 0}};
|
||||
};
|
||||
|
||||
static const nsAttrValue::EnumTable kAutocompleteNoPersistFieldNameTable[] = {
|
||||
static constexpr nsAttrValue::EnumTableEntry
|
||||
kAutocompleteNoPersistFieldNameTable[] = {
|
||||
#define AUTOCOMPLETE_NO_PERSIST_FIELD_NAME(name_, value_) \
|
||||
{value_, eAutocompleteNoPersistFieldName_##name_},
|
||||
#include "AutocompleteFieldList.h"
|
||||
#undef AUTOCOMPLETE_NO_PERSIST_FIELD_NAME
|
||||
{nullptr, 0}};
|
||||
|
||||
static const nsAttrValue::EnumTable
|
||||
};
|
||||
static constexpr nsAttrValue::EnumTableEntry
|
||||
kAutocompleteUnsupportedContactFieldHintTable[] = {
|
||||
#define AUTOCOMPLETE_UNSUPPORTED_FIELD_CONTACT_HINT(name_, value_) \
|
||||
{value_, eAutocompleteUnsupportedFieldContactHint_##name_},
|
||||
#include "AutocompleteFieldList.h"
|
||||
#undef AUTOCOMPLETE_UNSUPPORTED_FIELD_CONTACT_HINT
|
||||
{nullptr, 0}};
|
||||
};
|
||||
|
||||
static const nsAttrValue::EnumTable kAutocompleteFieldNameTable[] = {
|
||||
static constexpr nsAttrValue::EnumTableEntry kAutocompleteFieldNameTable[] = {
|
||||
#define AUTOCOMPLETE_FIELD_NAME(name_, value_) \
|
||||
{value_, eAutocompleteFieldName_##name_},
|
||||
#include "AutocompleteFieldList.h"
|
||||
#undef AUTOCOMPLETE_FIELD_NAME
|
||||
{nullptr, 0}};
|
||||
};
|
||||
|
||||
static const nsAttrValue::EnumTable kAutocompleteContactFieldNameTable[] = {
|
||||
static constexpr nsAttrValue::EnumTableEntry
|
||||
kAutocompleteContactFieldNameTable[] = {
|
||||
#define AUTOCOMPLETE_CONTACT_FIELD_NAME(name_, value_) \
|
||||
{value_, eAutocompleteFieldName_##name_},
|
||||
#include "AutocompleteFieldList.h"
|
||||
#undef AUTOCOMPLETE_CONTACT_FIELD_NAME
|
||||
{nullptr, 0}};
|
||||
};
|
||||
|
||||
static const nsAttrValue::EnumTable kAutocompleteFieldHintTable[] = {
|
||||
static constexpr nsAttrValue::EnumTableEntry kAutocompleteFieldHintTable[] = {
|
||||
#define AUTOCOMPLETE_FIELD_HINT(name_, value_) \
|
||||
{value_, eAutocompleteFieldHint_##name_},
|
||||
#include "AutocompleteFieldList.h"
|
||||
#undef AUTOCOMPLETE_FIELD_HINT
|
||||
{nullptr, 0}};
|
||||
};
|
||||
|
||||
static const nsAttrValue::EnumTable kAutocompleteContactFieldHintTable[] = {
|
||||
static constexpr nsAttrValue::EnumTableEntry
|
||||
kAutocompleteContactFieldHintTable[] = {
|
||||
#define AUTOCOMPLETE_FIELD_CONTACT_HINT(name_, value_) \
|
||||
{value_, eAutocompleteFieldContactHint_##name_},
|
||||
#include "AutocompleteFieldList.h"
|
||||
#undef AUTOCOMPLETE_FIELD_CONTACT_HINT
|
||||
{nullptr, 0}};
|
||||
};
|
||||
|
||||
static const nsAttrValue::EnumTable kAutocompleteCredentialTypeTable[] = {
|
||||
static constexpr nsAttrValue::EnumTableEntry
|
||||
kAutocompleteCredentialTypeTable[] = {
|
||||
#define AUTOCOMPLETE_CREDENTIAL_TYPE(name_, value_) \
|
||||
{value_, eAutocompleteCredentialType_##name_},
|
||||
#include "AutocompleteFieldList.h"
|
||||
#undef AUTOCOMPLETE_CREDENTIAL_TYPE
|
||||
{nullptr, 0}};
|
||||
};
|
||||
|
||||
namespace {
|
||||
|
||||
|
||||
@@ -91,15 +91,6 @@ static void PrintReqURL(imgIRequest* req) {
|
||||
}
|
||||
#endif /* DEBUG_chb */
|
||||
|
||||
const nsAttrValue::EnumTable nsImageLoadingContent::kDecodingTable[] = {
|
||||
{"auto", nsImageLoadingContent::ImageDecodingType::Auto},
|
||||
{"async", nsImageLoadingContent::ImageDecodingType::Async},
|
||||
{"sync", nsImageLoadingContent::ImageDecodingType::Sync},
|
||||
{nullptr, 0}};
|
||||
|
||||
const nsAttrValue::EnumTable* nsImageLoadingContent::kDecodingTableDefault =
|
||||
&nsImageLoadingContent::kDecodingTable[0];
|
||||
|
||||
nsImageLoadingContent::nsImageLoadingContent()
|
||||
: mObserverList(nullptr),
|
||||
mOutstandingDecodePromises(0),
|
||||
|
||||
@@ -263,8 +263,13 @@ class nsImageLoadingContent : public nsIImageLoadingContent {
|
||||
Sync,
|
||||
};
|
||||
|
||||
static const nsAttrValue::EnumTable kDecodingTable[];
|
||||
static const nsAttrValue::EnumTable* kDecodingTableDefault;
|
||||
static constexpr nsAttrValue::EnumTableEntry kDecodingTable[] = {
|
||||
{"auto", nsImageLoadingContent::ImageDecodingType::Auto},
|
||||
{"async", nsImageLoadingContent::ImageDecodingType::Async},
|
||||
{"sync", nsImageLoadingContent::ImageDecodingType::Sync},
|
||||
};
|
||||
static constexpr const nsAttrValue::EnumTableEntry* kDecodingTableDefault =
|
||||
&nsImageLoadingContent::kDecodingTable[0];
|
||||
|
||||
private:
|
||||
/**
|
||||
|
||||
@@ -22,12 +22,12 @@ HTMLBRElement::~HTMLBRElement() = default;
|
||||
|
||||
NS_IMPL_ELEMENT_CLONE(HTMLBRElement)
|
||||
|
||||
static const nsAttrValue::EnumTable kClearTable[] = {
|
||||
static constexpr nsAttrValue::EnumTableEntry kClearTable[] = {
|
||||
{"left", StyleClear::Left},
|
||||
{"right", StyleClear::Right},
|
||||
{"all", StyleClear::Both},
|
||||
{"both", StyleClear::Both},
|
||||
{nullptr, 0}};
|
||||
};
|
||||
|
||||
bool HTMLBRElement::ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
|
||||
@@ -38,14 +38,15 @@ NS_IMPL_NS_NEW_HTML_ELEMENT_CHECK_PARSER(Button)
|
||||
|
||||
namespace mozilla::dom {
|
||||
|
||||
static const nsAttrValue::EnumTable kButtonTypeTable[] = {
|
||||
static constexpr nsAttrValue::EnumTableEntry kButtonTypeTable[] = {
|
||||
{"button", FormControlType::ButtonButton},
|
||||
{"reset", FormControlType::ButtonReset},
|
||||
{"submit", FormControlType::ButtonSubmit},
|
||||
{nullptr, 0}};
|
||||
};
|
||||
|
||||
// Default type is 'submit'.
|
||||
static const nsAttrValue::EnumTable* kButtonDefaultType = &kButtonTypeTable[2];
|
||||
static constexpr const nsAttrValue::EnumTableEntry* kButtonDefaultType =
|
||||
&kButtonTypeTable[2];
|
||||
|
||||
// Construction, destruction
|
||||
HTMLButtonElement::HTMLButtonElement(
|
||||
|
||||
@@ -19,17 +19,19 @@ NS_IMPL_NS_NEW_HTML_ELEMENT(Dialog)
|
||||
|
||||
namespace mozilla::dom {
|
||||
|
||||
static constexpr nsAttrValue::EnumTable kClosedbyTable[] = {
|
||||
static constexpr nsAttrValue::EnumTableEntry kClosedbyTable[] = {
|
||||
{"", HTMLDialogElement::ClosedBy::Auto},
|
||||
{"none", HTMLDialogElement::ClosedBy::None},
|
||||
{"any", HTMLDialogElement::ClosedBy::Any},
|
||||
{"closerequest", HTMLDialogElement::ClosedBy::CloseRequest},
|
||||
{nullptr, 0},
|
||||
};
|
||||
|
||||
static const nsAttrValue::EnumTable* kClosedbyAuto = &kClosedbyTable[0];
|
||||
static const nsAttrValue::EnumTable* kClosedbyDefault = &kClosedbyTable[1];
|
||||
static const nsAttrValue::EnumTable* kClosedbyModalDefault = &kClosedbyTable[3];
|
||||
static constexpr const nsAttrValue::EnumTableEntry* kClosedbyAuto =
|
||||
&kClosedbyTable[0];
|
||||
static constexpr const nsAttrValue::EnumTableEntry* kClosedbyDefault =
|
||||
&kClosedbyTable[1];
|
||||
static constexpr const nsAttrValue::EnumTableEntry* kClosedbyModalDefault =
|
||||
&kClosedbyTable[3];
|
||||
|
||||
HTMLDialogElement::~HTMLDialogElement() = default;
|
||||
|
||||
|
||||
@@ -95,12 +95,12 @@ namespace mozilla::dom {
|
||||
static const uint8_t NS_FORM_AUTOCOMPLETE_ON = 1;
|
||||
static const uint8_t NS_FORM_AUTOCOMPLETE_OFF = 0;
|
||||
|
||||
static const nsAttrValue::EnumTable kFormAutocompleteTable[] = {
|
||||
static constexpr nsAttrValue::EnumTableEntry kFormAutocompleteTable[] = {
|
||||
{"on", NS_FORM_AUTOCOMPLETE_ON},
|
||||
{"off", NS_FORM_AUTOCOMPLETE_OFF},
|
||||
{nullptr, 0}};
|
||||
};
|
||||
// Default autocomplete value is 'on'.
|
||||
static const nsAttrValue::EnumTable* kFormDefaultAutocomplete =
|
||||
static constexpr const nsAttrValue::EnumTableEntry* kFormDefaultAutocomplete =
|
||||
&kFormAutocompleteTable[0];
|
||||
|
||||
HTMLFormElement::HTMLFormElement(
|
||||
|
||||
@@ -14,23 +14,23 @@
|
||||
#define NS_FORM_ENCTYPE_MULTIPART 1
|
||||
#define NS_FORM_ENCTYPE_TEXTPLAIN 2
|
||||
|
||||
static const nsAttrValue::EnumTable kFormMethodTable[] = {
|
||||
static constexpr nsAttrValue::EnumTableEntry kFormMethodTable[] = {
|
||||
{"get", NS_FORM_METHOD_GET},
|
||||
{"post", NS_FORM_METHOD_POST},
|
||||
{"dialog", NS_FORM_METHOD_DIALOG},
|
||||
{nullptr, 0}};
|
||||
{"dialog", NS_FORM_METHOD_DIALOG}};
|
||||
|
||||
// Default method is 'get'.
|
||||
static const nsAttrValue::EnumTable* kFormDefaultMethod = &kFormMethodTable[0];
|
||||
static constexpr const nsAttrValue::EnumTableEntry* kFormDefaultMethod =
|
||||
&kFormMethodTable[0];
|
||||
|
||||
static const nsAttrValue::EnumTable kFormEnctypeTable[] = {
|
||||
static constexpr nsAttrValue::EnumTableEntry kFormEnctypeTable[] = {
|
||||
{"multipart/form-data", NS_FORM_ENCTYPE_MULTIPART},
|
||||
{"application/x-www-form-urlencoded", NS_FORM_ENCTYPE_URLENCODED},
|
||||
{"text/plain", NS_FORM_ENCTYPE_TEXTPLAIN},
|
||||
{nullptr, 0}};
|
||||
};
|
||||
|
||||
// Default method is 'application/x-www-form-urlencoded'.
|
||||
static const nsAttrValue::EnumTable* kFormDefaultEnctype =
|
||||
static constexpr const nsAttrValue::EnumTableEntry* kFormDefaultEnctype =
|
||||
&kFormEnctypeTable[1];
|
||||
|
||||
#endif // mozilla_dom_HTMLFormSubmissionConstants_h
|
||||
|
||||
@@ -27,11 +27,11 @@ bool HTMLHRElement::ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsIPrincipal* aMaybeScriptedPrincipal,
|
||||
nsAttrValue& aResult) {
|
||||
static const nsAttrValue::EnumTable kAlignTable[] = {
|
||||
static const nsAttrValue::EnumTableEntry kAlignTable[] = {
|
||||
{"left", StyleTextAlign::Left},
|
||||
{"right", StyleTextAlign::Right},
|
||||
{"center", StyleTextAlign::Center},
|
||||
{nullptr, 0}};
|
||||
};
|
||||
|
||||
if (aNamespaceID == kNameSpaceID_None) {
|
||||
if (aAttribute == nsGkAtoms::width) {
|
||||
|
||||
@@ -151,7 +151,7 @@ namespace mozilla::dom {
|
||||
static int32_t gSelectTextFieldOnFocus;
|
||||
UploadLastDir* HTMLInputElement::gUploadLastDir;
|
||||
|
||||
static const nsAttrValue::EnumTable kInputTypeTable[] = {
|
||||
static constexpr nsAttrValue::EnumTableEntry kInputTypeTable[] = {
|
||||
{"button", FormControlType::InputButton},
|
||||
{"checkbox", FormControlType::InputCheckbox},
|
||||
{"color", FormControlType::InputColor},
|
||||
@@ -176,19 +176,20 @@ static const nsAttrValue::EnumTable kInputTypeTable[] = {
|
||||
// "text" must be last for ParseAttribute to work right. If you add things
|
||||
// before it, please update kInputDefaultType.
|
||||
{"text", FormControlType::InputText},
|
||||
{nullptr, 0}};
|
||||
};
|
||||
|
||||
// Default type is 'text'.
|
||||
static const nsAttrValue::EnumTable* kInputDefaultType =
|
||||
&kInputTypeTable[std::size(kInputTypeTable) - 2];
|
||||
static constexpr const nsAttrValue::EnumTableEntry* kInputDefaultType =
|
||||
&kInputTypeTable[std::size(kInputTypeTable) - 1];
|
||||
|
||||
static const nsAttrValue::EnumTable kCaptureTable[] = {
|
||||
static constexpr nsAttrValue::EnumTableEntry kCaptureTable[] = {
|
||||
{"user", nsIFilePicker::captureUser},
|
||||
{"environment", nsIFilePicker::captureEnv},
|
||||
{"", nsIFilePicker::captureDefault},
|
||||
{nullptr, nsIFilePicker::captureNone}};
|
||||
};
|
||||
|
||||
static const nsAttrValue::EnumTable* kCaptureDefault = &kCaptureTable[2];
|
||||
static constexpr const nsAttrValue::EnumTableEntry* kCaptureDefault =
|
||||
&kCaptureTable[2];
|
||||
|
||||
using namespace blink;
|
||||
|
||||
@@ -5444,18 +5445,14 @@ bool HTMLInputElement::ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsIPrincipal* aMaybeScriptedPrincipal,
|
||||
nsAttrValue& aResult) {
|
||||
// We can't make these static_asserts because kInputDefaultType and
|
||||
// kInputTypeTable aren't constexpr.
|
||||
MOZ_ASSERT(
|
||||
static_assert(
|
||||
FormControlType(kInputDefaultType->value) == FormControlType::InputText,
|
||||
"Someone forgot to update kInputDefaultType when adding a new "
|
||||
"input type.");
|
||||
MOZ_ASSERT(kInputTypeTable[std::size(kInputTypeTable) - 1].tag == nullptr,
|
||||
"Last entry in the table must be the nullptr guard");
|
||||
MOZ_ASSERT(
|
||||
FormControlType(kInputTypeTable[std::size(kInputTypeTable) - 2].value) ==
|
||||
static_assert(
|
||||
FormControlType(kInputTypeTable[std::size(kInputTypeTable) - 1].value) ==
|
||||
FormControlType::InputText,
|
||||
"Next to last entry in the table must be the \"text\" entry");
|
||||
"Last entry in the table must be the \"text\" entry");
|
||||
|
||||
if (aNamespaceID == kNameSpaceID_None) {
|
||||
if (aAttribute == nsGkAtoms::type) {
|
||||
@@ -5465,7 +5462,8 @@ bool HTMLInputElement::ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute,
|
||||
// There's no public way to set an nsAttrValue to an enum value, but we
|
||||
// can just re-parse with a table that doesn't have any types other than
|
||||
// "text" in it.
|
||||
aResult.ParseEnumValue(aValue, kInputDefaultType, false,
|
||||
MOZ_ASSERT(&Span(kInputTypeTable).Last<1>()[0] == kInputDefaultType);
|
||||
aResult.ParseEnumValue(aValue, Span(kInputTypeTable).Last<1>(), false,
|
||||
kInputDefaultType);
|
||||
}
|
||||
|
||||
|
||||
@@ -20,18 +20,19 @@ HTMLLIElement::~HTMLLIElement() = default;
|
||||
NS_IMPL_ELEMENT_CLONE(HTMLLIElement)
|
||||
|
||||
// https://html.spec.whatwg.org/#lists
|
||||
const nsAttrValue::EnumTable HTMLLIElement::kULTypeTable[] = {
|
||||
const nsAttrValue::EnumTableEntry HTMLLIElement::kULTypeTable[] = {
|
||||
{"none", ListStyle::None},
|
||||
{"disc", ListStyle::Disc},
|
||||
{"circle", ListStyle::Circle},
|
||||
{"square", ListStyle::Square},
|
||||
{nullptr, 0}};
|
||||
};
|
||||
|
||||
// https://html.spec.whatwg.org/#lists
|
||||
const nsAttrValue::EnumTable HTMLLIElement::kOLTypeTable[] = {
|
||||
const nsAttrValue::EnumTableEntry HTMLLIElement::kOLTypeTable[] = {
|
||||
{"A", ListStyle::UpperAlpha}, {"a", ListStyle::LowerAlpha},
|
||||
{"I", ListStyle::UpperRoman}, {"i", ListStyle::LowerRoman},
|
||||
{"1", ListStyle::Decimal}, {nullptr, 0}};
|
||||
{"1", ListStyle::Decimal},
|
||||
};
|
||||
|
||||
bool HTMLLIElement::ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
|
||||
@@ -39,8 +39,8 @@ class HTMLLIElement final : public nsGenericHTMLElement {
|
||||
SetHTMLIntAttr(nsGkAtoms::value, aValue, rv);
|
||||
}
|
||||
|
||||
static const nsAttrValue::EnumTable kULTypeTable[];
|
||||
static const nsAttrValue::EnumTable kOLTypeTable[];
|
||||
static const nsAttrValue::EnumTableEntry kULTypeTable[4];
|
||||
static const nsAttrValue::EnumTableEntry kOLTypeTable[5];
|
||||
|
||||
protected:
|
||||
virtual ~HTMLLIElement();
|
||||
|
||||
@@ -33,11 +33,11 @@ bool HTMLLegendElement::ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute,
|
||||
nsIPrincipal* aMaybeScriptedPrincipal,
|
||||
nsAttrValue& aResult) {
|
||||
// this contains center, because IE4 does
|
||||
static const nsAttrValue::EnumTable kAlignTable[] = {
|
||||
static constexpr nsAttrValue::EnumTableEntry kAlignTable[] = {
|
||||
{"left", LegendAlignValue::Left},
|
||||
{"right", LegendAlignValue::Right},
|
||||
{"center", LegendAlignValue::Center},
|
||||
{nullptr, 0}};
|
||||
};
|
||||
|
||||
if (aAttribute == nsGkAtoms::align && aNamespaceID == kNameSpaceID_None) {
|
||||
return aResult.ParseEnumValue(aValue, kAlignTable, false);
|
||||
|
||||
@@ -22,17 +22,21 @@ HTMLMarqueeElement::~HTMLMarqueeElement() = default;
|
||||
|
||||
NS_IMPL_ELEMENT_CLONE(HTMLMarqueeElement)
|
||||
|
||||
static const nsAttrValue::EnumTable kBehaviorTable[] = {
|
||||
{"scroll", 1}, {"slide", 2}, {"alternate", 3}, {nullptr, 0}};
|
||||
static constexpr nsAttrValue::EnumTableEntry kBehaviorTable[] = {
|
||||
{"scroll", 1}, {"slide", 2}, {"alternate", 3}
|
||||
|
||||
};
|
||||
|
||||
// Default behavior value is "scroll".
|
||||
static const nsAttrValue::EnumTable* kDefaultBehavior = &kBehaviorTable[0];
|
||||
static constexpr const nsAttrValue::EnumTableEntry* kDefaultBehavior =
|
||||
&kBehaviorTable[0];
|
||||
|
||||
static const nsAttrValue::EnumTable kDirectionTable[] = {
|
||||
{"left", 1}, {"right", 2}, {"up", 3}, {"down", 4}, {nullptr, 0}};
|
||||
static constexpr nsAttrValue::EnumTableEntry kDirectionTable[] = {
|
||||
{"left", 1}, {"right", 2}, {"up", 3}, {"down", 4}};
|
||||
|
||||
// Default direction value is "left".
|
||||
static const nsAttrValue::EnumTable* kDefaultDirection = &kDirectionTable[0];
|
||||
static constexpr const nsAttrValue::EnumTableEntry* kDefaultDirection =
|
||||
&kDirectionTable[0];
|
||||
|
||||
JSObject* HTMLMarqueeElement::WrapNode(JSContext* aCx,
|
||||
JS::Handle<JSObject*> aGivenProto) {
|
||||
|
||||
@@ -4947,12 +4947,12 @@ bool HTMLMediaElement::ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute,
|
||||
nsIPrincipal* aMaybeScriptedPrincipal,
|
||||
nsAttrValue& aResult) {
|
||||
// Mappings from 'preload' attribute strings to an enumeration.
|
||||
static const nsAttrValue::EnumTable kPreloadTable[] = {
|
||||
static const nsAttrValue::EnumTableEntry kPreloadTable[] = {
|
||||
{"", HTMLMediaElement::PRELOAD_ATTR_EMPTY},
|
||||
{"none", HTMLMediaElement::PRELOAD_ATTR_NONE},
|
||||
{"metadata", HTMLMediaElement::PRELOAD_ATTR_METADATA},
|
||||
{"auto", HTMLMediaElement::PRELOAD_ATTR_AUTO},
|
||||
{nullptr, 0}};
|
||||
};
|
||||
|
||||
if (aNamespaceID == kNameSpaceID_None) {
|
||||
if (aAttribute == nsGkAtoms::crossorigin) {
|
||||
|
||||
@@ -24,10 +24,10 @@ JSObject* HTMLTableCaptionElement::WrapNode(JSContext* aCx,
|
||||
|
||||
NS_IMPL_ELEMENT_CLONE(HTMLTableCaptionElement)
|
||||
|
||||
static const nsAttrValue::EnumTable kCaptionAlignTable[] = {
|
||||
static constexpr nsAttrValue::EnumTableEntry kCaptionAlignTable[] = {
|
||||
{"top", StyleCaptionSide::Top},
|
||||
{"bottom", StyleCaptionSide::Bottom},
|
||||
{nullptr, 0}};
|
||||
};
|
||||
|
||||
bool HTMLTableCaptionElement::ParseAttribute(
|
||||
int32_t aNamespaceID, nsAtom* aAttribute, const nsAString& aValue,
|
||||
|
||||
@@ -101,12 +101,12 @@ void HTMLTableCellElement::GetAlign(DOMString& aValue) {
|
||||
}
|
||||
}
|
||||
|
||||
static const nsAttrValue::EnumTable kCellScopeTable[] = {
|
||||
static constexpr nsAttrValue::EnumTableEntry kCellScopeTable[] = {
|
||||
{"row", StyleCellScope::Row},
|
||||
{"col", StyleCellScope::Col},
|
||||
{"rowgroup", StyleCellScope::Rowgroup},
|
||||
{"colgroup", StyleCellScope::Colgroup},
|
||||
{nullptr, 0}};
|
||||
};
|
||||
|
||||
void HTMLTableCellElement::GetScope(DOMString& aScope) {
|
||||
GetEnumAttr(nsGkAtoms::scope, nullptr, aScope);
|
||||
|
||||
@@ -19,12 +19,10 @@ NS_IMPL_NS_NEW_HTML_ELEMENT(Template)
|
||||
|
||||
namespace mozilla::dom {
|
||||
|
||||
static constexpr nsAttrValue::EnumTable kShadowRootModeTable[] = {
|
||||
static constexpr nsAttrValue::EnumTableEntry kShadowRootModeTable[] = {
|
||||
{"open", ShadowRootMode::Open},
|
||||
{"closed", ShadowRootMode::Closed},
|
||||
{nullptr, {}}};
|
||||
|
||||
const nsAttrValue::EnumTable* kShadowRootModeDefault = &kShadowRootModeTable[2];
|
||||
};
|
||||
|
||||
HTMLTemplateElement::HTMLTemplateElement(
|
||||
already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo)
|
||||
|
||||
@@ -48,18 +48,18 @@ nsGenericHTMLElement* NS_NewHTMLTrackElement(
|
||||
namespace mozilla::dom {
|
||||
|
||||
// Map html attribute string values to TextTrackKind enums.
|
||||
static constexpr nsAttrValue::EnumTable kKindTable[] = {
|
||||
static constexpr nsAttrValue::EnumTableEntry kKindTable[] = {
|
||||
{"subtitles", static_cast<int16_t>(TextTrackKind::Subtitles)},
|
||||
{"captions", static_cast<int16_t>(TextTrackKind::Captions)},
|
||||
{"descriptions", static_cast<int16_t>(TextTrackKind::Descriptions)},
|
||||
{"chapters", static_cast<int16_t>(TextTrackKind::Chapters)},
|
||||
{"metadata", static_cast<int16_t>(TextTrackKind::Metadata)},
|
||||
{nullptr, 0}};
|
||||
};
|
||||
|
||||
// Invalid values are treated as "metadata" in ParseAttribute, but if no value
|
||||
// at all is specified, it's treated as "subtitles" in GetKind
|
||||
static constexpr const nsAttrValue::EnumTable* kKindTableInvalidValueDefault =
|
||||
&kKindTable[4];
|
||||
static constexpr const nsAttrValue::EnumTableEntry*
|
||||
kKindTableInvalidValueDefault = &kKindTable[4];
|
||||
|
||||
class WindowDestroyObserver final : public nsIObserver {
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
@@ -107,16 +107,12 @@ static const uint8_t NS_INPUTMODE_NUMERIC = 6;
|
||||
static const uint8_t NS_INPUTMODE_DECIMAL = 7;
|
||||
static const uint8_t NS_INPUTMODE_SEARCH = 8;
|
||||
|
||||
static constexpr nsAttrValue::EnumTable kInputmodeTable[] = {
|
||||
{"none", NS_INPUTMODE_NONE},
|
||||
{"text", NS_INPUTMODE_TEXT},
|
||||
{"tel", NS_INPUTMODE_TEL},
|
||||
{"url", NS_INPUTMODE_URL},
|
||||
{"email", NS_INPUTMODE_EMAIL},
|
||||
{"numeric", NS_INPUTMODE_NUMERIC},
|
||||
{"decimal", NS_INPUTMODE_DECIMAL},
|
||||
{"search", NS_INPUTMODE_SEARCH},
|
||||
{nullptr, 0}};
|
||||
static constexpr nsAttrValue::EnumTableEntry kInputmodeTable[] = {
|
||||
{"none", NS_INPUTMODE_NONE}, {"text", NS_INPUTMODE_TEXT},
|
||||
{"tel", NS_INPUTMODE_TEL}, {"url", NS_INPUTMODE_URL},
|
||||
{"email", NS_INPUTMODE_EMAIL}, {"numeric", NS_INPUTMODE_NUMERIC},
|
||||
{"decimal", NS_INPUTMODE_DECIMAL}, {"search", NS_INPUTMODE_SEARCH},
|
||||
};
|
||||
|
||||
static const uint8_t NS_ENTERKEYHINT_ENTER = 1;
|
||||
static const uint8_t NS_ENTERKEYHINT_DONE = 2;
|
||||
@@ -126,7 +122,7 @@ static const uint8_t NS_ENTERKEYHINT_PREVIOUS = 5;
|
||||
static const uint8_t NS_ENTERKEYHINT_SEARCH = 6;
|
||||
static const uint8_t NS_ENTERKEYHINT_SEND = 7;
|
||||
|
||||
static constexpr nsAttrValue::EnumTable kEnterKeyHintTable[] = {
|
||||
static constexpr nsAttrValue::EnumTableEntry kEnterKeyHintTable[] = {
|
||||
{"enter", NS_ENTERKEYHINT_ENTER},
|
||||
{"done", NS_ENTERKEYHINT_DONE},
|
||||
{"go", NS_ENTERKEYHINT_GO},
|
||||
@@ -134,14 +130,14 @@ static constexpr nsAttrValue::EnumTable kEnterKeyHintTable[] = {
|
||||
{"previous", NS_ENTERKEYHINT_PREVIOUS},
|
||||
{"search", NS_ENTERKEYHINT_SEARCH},
|
||||
{"send", NS_ENTERKEYHINT_SEND},
|
||||
{nullptr, 0}};
|
||||
};
|
||||
|
||||
static const uint8_t NS_AUTOCAPITALIZE_NONE = 1;
|
||||
static const uint8_t NS_AUTOCAPITALIZE_SENTENCES = 2;
|
||||
static const uint8_t NS_AUTOCAPITALIZE_WORDS = 3;
|
||||
static const uint8_t NS_AUTOCAPITALIZE_CHARACTERS = 4;
|
||||
|
||||
static constexpr nsAttrValue::EnumTable kAutocapitalizeTable[] = {
|
||||
static constexpr nsAttrValue::EnumTableEntry kAutocapitalizeTable[] = {
|
||||
{"none", NS_AUTOCAPITALIZE_NONE},
|
||||
{"sentences", NS_AUTOCAPITALIZE_SENTENCES},
|
||||
{"words", NS_AUTOCAPITALIZE_WORDS},
|
||||
@@ -149,9 +145,9 @@ static constexpr nsAttrValue::EnumTable kAutocapitalizeTable[] = {
|
||||
{"off", NS_AUTOCAPITALIZE_NONE},
|
||||
{"on", NS_AUTOCAPITALIZE_SENTENCES},
|
||||
{"", 0},
|
||||
{nullptr, 0}};
|
||||
};
|
||||
|
||||
static const nsAttrValue::EnumTable* kDefaultAutocapitalize =
|
||||
static constexpr const nsAttrValue::EnumTableEntry* kDefaultAutocapitalize =
|
||||
&kAutocapitalizeTable[1];
|
||||
|
||||
nsresult nsGenericHTMLElement::CopyInnerTo(Element* aDst) {
|
||||
@@ -171,11 +167,10 @@ nsresult nsGenericHTMLElement::CopyInnerTo(Element* aDst) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
static constexpr nsAttrValue::EnumTable kDirTable[] = {
|
||||
static constexpr nsAttrValue::EnumTableEntry kDirTable[] = {
|
||||
{"ltr", Directionality::Ltr},
|
||||
{"rtl", Directionality::Rtl},
|
||||
{"auto", Directionality::Auto},
|
||||
{nullptr, 0},
|
||||
};
|
||||
|
||||
namespace {
|
||||
@@ -186,14 +181,14 @@ static constexpr const char kPopoverAttributeValueAuto[] = "auto";
|
||||
static constexpr const char kPopoverAttributeValueEmptyString[] = "";
|
||||
static constexpr const char kPopoverAttributeValueManual[] = "manual";
|
||||
|
||||
static constexpr nsAttrValue::EnumTable kPopoverTable[] = {
|
||||
static constexpr nsAttrValue::EnumTableEntry kPopoverTable[] = {
|
||||
{kPopoverAttributeValueAuto, PopoverAttributeKeyword::Auto},
|
||||
{kPopoverAttributeValueEmptyString, PopoverAttributeKeyword::EmptyString},
|
||||
{kPopoverAttributeValueManual, PopoverAttributeKeyword::Manual},
|
||||
{nullptr, 0}};
|
||||
};
|
||||
|
||||
// See <https://html.spec.whatwg.org/#the-popover-attribute>.
|
||||
static const nsAttrValue::EnumTable* kPopoverTableInvalidValueDefault =
|
||||
static const nsAttrValue::EnumTableEntry* kPopoverTableInvalidValueDefault =
|
||||
&kPopoverTable[2];
|
||||
} // namespace
|
||||
|
||||
@@ -1253,23 +1248,23 @@ nsMapRuleToAttributesFunc nsGenericHTMLElement::GetAttributeMappingFunction()
|
||||
return &MapCommonAttributesInto;
|
||||
}
|
||||
|
||||
static constexpr nsAttrValue::EnumTable kDivAlignTable[] = {
|
||||
static constexpr nsAttrValue::EnumTableEntry kDivAlignTable[] = {
|
||||
{"left", StyleTextAlign::MozLeft},
|
||||
{"right", StyleTextAlign::MozRight},
|
||||
{"center", StyleTextAlign::MozCenter},
|
||||
{"middle", StyleTextAlign::MozCenter},
|
||||
{"justify", StyleTextAlign::Justify},
|
||||
{nullptr, 0}};
|
||||
};
|
||||
|
||||
static constexpr nsAttrValue::EnumTable kFrameborderTable[] = {
|
||||
static constexpr nsAttrValue::EnumTableEntry kFrameborderTable[] = {
|
||||
{"yes", FrameBorderProperty::Yes},
|
||||
{"no", FrameBorderProperty::No},
|
||||
{"1", FrameBorderProperty::One},
|
||||
{"0", FrameBorderProperty::Zero},
|
||||
{nullptr, 0}};
|
||||
};
|
||||
|
||||
// TODO(emilio): Nobody uses the parsed attribute here.
|
||||
static constexpr nsAttrValue::EnumTable kScrollingTable[] = {
|
||||
static constexpr nsAttrValue::EnumTableEntry kScrollingTable[] = {
|
||||
{"yes", ScrollingAttribute::Yes},
|
||||
{"no", ScrollingAttribute::No},
|
||||
{"on", ScrollingAttribute::On},
|
||||
@@ -1277,36 +1272,36 @@ static constexpr nsAttrValue::EnumTable kScrollingTable[] = {
|
||||
{"scroll", ScrollingAttribute::Scroll},
|
||||
{"noscroll", ScrollingAttribute::Noscroll},
|
||||
{"auto", ScrollingAttribute::Auto},
|
||||
{nullptr, 0}};
|
||||
};
|
||||
|
||||
static constexpr nsAttrValue::EnumTable kTableVAlignTable[] = {
|
||||
static constexpr nsAttrValue::EnumTableEntry kTableVAlignTable[] = {
|
||||
{"top", StyleVerticalAlignKeyword::Top},
|
||||
{"middle", StyleVerticalAlignKeyword::Middle},
|
||||
{"bottom", StyleVerticalAlignKeyword::Bottom},
|
||||
{"baseline", StyleVerticalAlignKeyword::Baseline},
|
||||
{nullptr, 0}};
|
||||
};
|
||||
|
||||
static constexpr nsAttrValue::EnumTableEntry kAlignTable[] = {
|
||||
{"left", StyleTextAlign::Left},
|
||||
{"right", StyleTextAlign::Right},
|
||||
|
||||
{"top", StyleVerticalAlignKeyword::Top},
|
||||
{"middle", StyleVerticalAlignKeyword::MozMiddleWithBaseline},
|
||||
|
||||
// Intentionally not bottom.
|
||||
{"bottom", StyleVerticalAlignKeyword::Baseline},
|
||||
|
||||
{"center", StyleVerticalAlignKeyword::MozMiddleWithBaseline},
|
||||
{"baseline", StyleVerticalAlignKeyword::Baseline},
|
||||
|
||||
{"texttop", StyleVerticalAlignKeyword::TextTop},
|
||||
{"absmiddle", StyleVerticalAlignKeyword::Middle},
|
||||
{"abscenter", StyleVerticalAlignKeyword::Middle},
|
||||
{"absbottom", StyleVerticalAlignKeyword::Bottom},
|
||||
};
|
||||
|
||||
bool nsGenericHTMLElement::ParseAlignValue(const nsAString& aString,
|
||||
nsAttrValue& aResult) {
|
||||
static constexpr nsAttrValue::EnumTable kAlignTable[] = {
|
||||
{"left", StyleTextAlign::Left},
|
||||
{"right", StyleTextAlign::Right},
|
||||
|
||||
{"top", StyleVerticalAlignKeyword::Top},
|
||||
{"middle", StyleVerticalAlignKeyword::MozMiddleWithBaseline},
|
||||
|
||||
// Intentionally not bottom.
|
||||
{"bottom", StyleVerticalAlignKeyword::Baseline},
|
||||
|
||||
{"center", StyleVerticalAlignKeyword::MozMiddleWithBaseline},
|
||||
{"baseline", StyleVerticalAlignKeyword::Baseline},
|
||||
|
||||
{"texttop", StyleVerticalAlignKeyword::TextTop},
|
||||
{"absmiddle", StyleVerticalAlignKeyword::Middle},
|
||||
{"abscenter", StyleVerticalAlignKeyword::Middle},
|
||||
{"absbottom", StyleVerticalAlignKeyword::Bottom},
|
||||
{nullptr, 0}};
|
||||
|
||||
static_assert(uint8_t(StyleTextAlign::Left) !=
|
||||
uint8_t(StyleVerticalAlignKeyword::Top) &&
|
||||
uint8_t(StyleTextAlign::Left) !=
|
||||
@@ -1338,12 +1333,12 @@ bool nsGenericHTMLElement::ParseAlignValue(const nsAString& aString,
|
||||
|
||||
//----------------------------------------
|
||||
|
||||
static constexpr nsAttrValue::EnumTable kTableHAlignTable[] = {
|
||||
static constexpr nsAttrValue::EnumTableEntry kTableHAlignTable[] = {
|
||||
{"left", StyleTextAlign::Left},
|
||||
{"right", StyleTextAlign::Right},
|
||||
{"center", StyleTextAlign::Center},
|
||||
{"justify", StyleTextAlign::Justify},
|
||||
{nullptr, 0}};
|
||||
};
|
||||
|
||||
bool nsGenericHTMLElement::ParseTableHAlignValue(const nsAString& aString,
|
||||
nsAttrValue& aResult) {
|
||||
@@ -1353,14 +1348,14 @@ bool nsGenericHTMLElement::ParseTableHAlignValue(const nsAString& aString,
|
||||
//----------------------------------------
|
||||
|
||||
// This table is used for td, th, tr, col, thead, tbody and tfoot.
|
||||
static constexpr nsAttrValue::EnumTable kTableCellHAlignTable[] = {
|
||||
static constexpr nsAttrValue::EnumTableEntry kTableCellHAlignTable[] = {
|
||||
{"left", StyleTextAlign::MozLeft},
|
||||
{"right", StyleTextAlign::MozRight},
|
||||
{"center", StyleTextAlign::MozCenter},
|
||||
{"justify", StyleTextAlign::Justify},
|
||||
{"middle", StyleTextAlign::MozCenter},
|
||||
{"absmiddle", StyleTextAlign::Center},
|
||||
{nullptr, 0}};
|
||||
};
|
||||
|
||||
bool nsGenericHTMLElement::ParseTableCellHAlignValue(const nsAString& aString,
|
||||
nsAttrValue& aResult) {
|
||||
@@ -1392,27 +1387,28 @@ bool nsGenericHTMLElement::ParseImageAttribute(nsAtom* aAttribute,
|
||||
return false;
|
||||
}
|
||||
|
||||
static constexpr nsAttrValue::EnumTableEntry kReferrerPolicyTable[] = {
|
||||
{GetEnumString(ReferrerPolicy::No_referrer).get(),
|
||||
static_cast<int16_t>(ReferrerPolicy::No_referrer)},
|
||||
{GetEnumString(ReferrerPolicy::Origin).get(),
|
||||
static_cast<int16_t>(ReferrerPolicy::Origin)},
|
||||
{GetEnumString(ReferrerPolicy::Origin_when_cross_origin).get(),
|
||||
static_cast<int16_t>(ReferrerPolicy::Origin_when_cross_origin)},
|
||||
{GetEnumString(ReferrerPolicy::No_referrer_when_downgrade).get(),
|
||||
static_cast<int16_t>(ReferrerPolicy::No_referrer_when_downgrade)},
|
||||
{GetEnumString(ReferrerPolicy::Unsafe_url).get(),
|
||||
static_cast<int16_t>(ReferrerPolicy::Unsafe_url)},
|
||||
{GetEnumString(ReferrerPolicy::Strict_origin).get(),
|
||||
static_cast<int16_t>(ReferrerPolicy::Strict_origin)},
|
||||
{GetEnumString(ReferrerPolicy::Same_origin).get(),
|
||||
static_cast<int16_t>(ReferrerPolicy::Same_origin)},
|
||||
{GetEnumString(ReferrerPolicy::Strict_origin_when_cross_origin).get(),
|
||||
static_cast<int16_t>(ReferrerPolicy::Strict_origin_when_cross_origin)},
|
||||
};
|
||||
|
||||
bool nsGenericHTMLElement::ParseReferrerAttribute(const nsAString& aString,
|
||||
nsAttrValue& aResult) {
|
||||
using mozilla::dom::ReferrerInfo;
|
||||
static constexpr nsAttrValue::EnumTable kReferrerPolicyTable[] = {
|
||||
{GetEnumString(ReferrerPolicy::No_referrer).get(),
|
||||
static_cast<int16_t>(ReferrerPolicy::No_referrer)},
|
||||
{GetEnumString(ReferrerPolicy::Origin).get(),
|
||||
static_cast<int16_t>(ReferrerPolicy::Origin)},
|
||||
{GetEnumString(ReferrerPolicy::Origin_when_cross_origin).get(),
|
||||
static_cast<int16_t>(ReferrerPolicy::Origin_when_cross_origin)},
|
||||
{GetEnumString(ReferrerPolicy::No_referrer_when_downgrade).get(),
|
||||
static_cast<int16_t>(ReferrerPolicy::No_referrer_when_downgrade)},
|
||||
{GetEnumString(ReferrerPolicy::Unsafe_url).get(),
|
||||
static_cast<int16_t>(ReferrerPolicy::Unsafe_url)},
|
||||
{GetEnumString(ReferrerPolicy::Strict_origin).get(),
|
||||
static_cast<int16_t>(ReferrerPolicy::Strict_origin)},
|
||||
{GetEnumString(ReferrerPolicy::Same_origin).get(),
|
||||
static_cast<int16_t>(ReferrerPolicy::Same_origin)},
|
||||
{GetEnumString(ReferrerPolicy::Strict_origin_when_cross_origin).get(),
|
||||
static_cast<int16_t>(ReferrerPolicy::Strict_origin_when_cross_origin)},
|
||||
{nullptr, ReferrerPolicy::_empty}};
|
||||
return aResult.ParseEnumValue(aString, kReferrerPolicyTable, false);
|
||||
}
|
||||
|
||||
@@ -2940,14 +2936,14 @@ void nsGenericHTMLFormControlElement::SetFormAutofillState(
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
static constexpr nsAttrValue::EnumTable kPopoverTargetActionTable[] = {
|
||||
static constexpr nsAttrValue::EnumTableEntry kPopoverTargetActionTable[] = {
|
||||
{"toggle", PopoverTargetAction::Toggle},
|
||||
{"show", PopoverTargetAction::Show},
|
||||
{"hide", PopoverTargetAction::Hide},
|
||||
{nullptr, 0}};
|
||||
};
|
||||
|
||||
static const nsAttrValue::EnumTable* kPopoverTargetActionDefault =
|
||||
&kPopoverTargetActionTable[0];
|
||||
static constexpr const nsAttrValue::EnumTableEntry*
|
||||
kPopoverTargetActionDefault = &kPopoverTargetActionTable[0];
|
||||
|
||||
nsGenericHTMLFormControlElementWithState::
|
||||
nsGenericHTMLFormControlElementWithState(
|
||||
|
||||
@@ -34,19 +34,6 @@ namespace mozilla {
|
||||
//----------------------------------------------------------------------
|
||||
// Static members
|
||||
|
||||
nsAttrValue::EnumTable SMILAnimationFunction::sAccumulateTable[] = {
|
||||
{"none", false}, {"sum", true}, {nullptr, 0}};
|
||||
|
||||
nsAttrValue::EnumTable SMILAnimationFunction::sAdditiveTable[] = {
|
||||
{"replace", false}, {"sum", true}, {nullptr, 0}};
|
||||
|
||||
nsAttrValue::EnumTable SMILAnimationFunction::sCalcModeTable[] = {
|
||||
{"linear", CALC_LINEAR},
|
||||
{"discrete", CALC_DISCRETE},
|
||||
{"paced", CALC_PACED},
|
||||
{"spline", CALC_SPLINE},
|
||||
{nullptr, 0}};
|
||||
|
||||
// Any negative number should be fine as a sentinel here,
|
||||
// because valid distances are non-negative.
|
||||
#define COMPUTE_DISTANCE_ERROR (-1)
|
||||
|
||||
@@ -399,9 +399,22 @@ class SMILAnimationFunction {
|
||||
// Members
|
||||
// -------
|
||||
|
||||
static nsAttrValue::EnumTable sAdditiveTable[];
|
||||
static nsAttrValue::EnumTable sCalcModeTable[];
|
||||
static nsAttrValue::EnumTable sAccumulateTable[];
|
||||
static constexpr nsAttrValue::EnumTableEntry sAdditiveTable[] = {
|
||||
{"replace", false},
|
||||
{"sum", true},
|
||||
};
|
||||
|
||||
static constexpr nsAttrValue::EnumTableEntry sAccumulateTable[] = {
|
||||
{"none", false},
|
||||
{"sum", true},
|
||||
};
|
||||
|
||||
static constexpr nsAttrValue::EnumTableEntry sCalcModeTable[] = {
|
||||
{"linear", CALC_LINEAR},
|
||||
{"discrete", CALC_DISCRETE},
|
||||
{"paced", CALC_PACED},
|
||||
{"spline", CALC_SPLINE},
|
||||
};
|
||||
|
||||
FallibleTArray<double> mKeyTimes;
|
||||
FallibleTArray<SMILKeySpline> mKeySplines;
|
||||
|
||||
@@ -192,15 +192,6 @@ void SMILTimedElement::RemoveInstanceTimes(InstanceTimeList& aArray,
|
||||
//----------------------------------------------------------------------
|
||||
// Static members
|
||||
|
||||
const nsAttrValue::EnumTable SMILTimedElement::sFillModeTable[] = {
|
||||
{"remove", FILL_REMOVE}, {"freeze", FILL_FREEZE}, {nullptr, 0}};
|
||||
|
||||
const nsAttrValue::EnumTable SMILTimedElement::sRestartModeTable[] = {
|
||||
{"always", RESTART_ALWAYS},
|
||||
{"whenNotActive", RESTART_WHENNOTACTIVE},
|
||||
{"never", RESTART_NEVER},
|
||||
{nullptr, 0}};
|
||||
|
||||
// The thresholds at which point we start filtering intervals and instance times
|
||||
// indiscriminately.
|
||||
// See FilterIntervals and FilterInstanceTimes.
|
||||
|
||||
@@ -567,7 +567,10 @@ class SMILTimedElement {
|
||||
|
||||
enum SMILFillMode : uint8_t { FILL_REMOVE, FILL_FREEZE };
|
||||
SMILFillMode mFillMode;
|
||||
static const nsAttrValue::EnumTable sFillModeTable[];
|
||||
static constexpr nsAttrValue::EnumTableEntry sFillModeTable[] = {
|
||||
{"remove", FILL_REMOVE},
|
||||
{"freeze", FILL_FREEZE},
|
||||
};
|
||||
|
||||
enum SMILRestartMode : uint8_t {
|
||||
RESTART_ALWAYS,
|
||||
@@ -575,7 +578,11 @@ class SMILTimedElement {
|
||||
RESTART_NEVER
|
||||
};
|
||||
SMILRestartMode mRestartMode;
|
||||
static const nsAttrValue::EnumTable sRestartModeTable[];
|
||||
static constexpr nsAttrValue::EnumTableEntry sRestartModeTable[] = {
|
||||
{"always", RESTART_ALWAYS},
|
||||
{"whenNotActive", RESTART_WHENNOTACTIVE},
|
||||
{"never", RESTART_NEVER},
|
||||
};
|
||||
|
||||
InstanceTimeList mBeginInstances;
|
||||
InstanceTimeList mEndInstances;
|
||||
|
||||
@@ -3872,18 +3872,13 @@ bool IsFontMimeType(const nsAString& aType) {
|
||||
return false;
|
||||
}
|
||||
|
||||
static const nsAttrValue::EnumTable kAsAttributeTable[] = {
|
||||
{"", DESTINATION_INVALID},
|
||||
{"audio", DESTINATION_AUDIO},
|
||||
{"font", DESTINATION_FONT},
|
||||
{"image", DESTINATION_IMAGE},
|
||||
{"script", DESTINATION_SCRIPT},
|
||||
{"style", DESTINATION_STYLE},
|
||||
{"track", DESTINATION_TRACK},
|
||||
{"video", DESTINATION_VIDEO},
|
||||
{"fetch", DESTINATION_FETCH},
|
||||
{"json", DESTINATION_JSON},
|
||||
{nullptr, 0}};
|
||||
static constexpr nsAttrValue::EnumTableEntry kAsAttributeTable[] = {
|
||||
{"", DESTINATION_INVALID}, {"audio", DESTINATION_AUDIO},
|
||||
{"font", DESTINATION_FONT}, {"image", DESTINATION_IMAGE},
|
||||
{"script", DESTINATION_SCRIPT}, {"style", DESTINATION_STYLE},
|
||||
{"track", DESTINATION_TRACK}, {"video", DESTINATION_VIDEO},
|
||||
{"fetch", DESTINATION_FETCH}, {"json", DESTINATION_JSON},
|
||||
};
|
||||
|
||||
void ParseAsValue(const nsAString& aValue, nsAttrValue& aResult) {
|
||||
DebugOnly<bool> success =
|
||||
|
||||
Reference in New Issue
Block a user