mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-03-01 22:07:41 +00:00
Bug 1479450: Implement nsCSSProps::LookupProperty using Rust. r=xidorn
Always assume allowed-for-all-content. There are a couple callers which weren't doing that: * A unit test -> removed. * ComputeAnimationDistance: Used for testing (in transitions_per_property), and for the animation inspector. The animation inspector shouldn't show non-enabled properties. The transitions_per_property test already relies on getComputedStyle stuff which only uses eForAllContent. * GetCSSImageURLs: I added this API for the context menu page and such. It doesn't rely on non-enabled-everywhere properties, it was only using eInChrome because it was a ChromeOnly API, but it doesn't really need this. Differential Revision: https://phabricator.services.mozilla.com/D2514 MozReview-Commit-ID: 4VOi5Su3Bos
This commit is contained in:
parent
1ad081c136
commit
2996813963
dom
editor/libeditor
layout
inspector
style
servo
@ -2707,10 +2707,8 @@ nsDOMWindowUtils::ComputeAnimationDistance(Element* aElement,
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aElement);
|
||||
|
||||
nsCSSPropertyID property =
|
||||
nsCSSProps::LookupProperty(aProperty, CSSEnabledState::eIgnoreEnabledState);
|
||||
if (property == eCSSProperty_UNKNOWN ||
|
||||
nsCSSProps::IsShorthand(property)) {
|
||||
nsCSSPropertyID property = nsCSSProps::LookupProperty(aProperty);
|
||||
if (property == eCSSProperty_UNKNOWN || nsCSSProps::IsShorthand(property)) {
|
||||
return NS_ERROR_ILLEGAL_VALUE;
|
||||
}
|
||||
|
||||
@ -2737,8 +2735,7 @@ nsDOMWindowUtils::GetUnanimatedComputedStyle(Element* aElement,
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
|
||||
nsCSSPropertyID propertyID =
|
||||
nsCSSProps::LookupProperty(aProperty, CSSEnabledState::eForAllContent);
|
||||
nsCSSPropertyID propertyID = nsCSSProps::LookupProperty(aProperty);
|
||||
if (propertyID == eCSSProperty_UNKNOWN ||
|
||||
nsCSSProps::IsShorthand(propertyID)) {
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
|
@ -155,8 +155,7 @@ nsSMILCompositor::GetCSSPropertyToAnimate() const
|
||||
}
|
||||
|
||||
nsCSSPropertyID propID =
|
||||
nsCSSProps::LookupProperty(nsDependentAtomString(mKey.mAttributeName),
|
||||
CSSEnabledState::eForAllContent);
|
||||
nsCSSProps::LookupProperty(nsDependentAtomString(mKey.mAttributeName));
|
||||
|
||||
if (!nsSMILCSSProperty::IsPropertyAnimatable(propID)) {
|
||||
return eCSSProperty_UNKNOWN;
|
||||
|
@ -1192,8 +1192,7 @@ MappedAttrParser::ParseMappedAttrValue(nsAtom* aMappedAttrName,
|
||||
|
||||
// Get the nsCSSPropertyID ID for our mapped attribute.
|
||||
nsCSSPropertyID propertyID =
|
||||
nsCSSProps::LookupProperty(nsDependentAtomString(aMappedAttrName),
|
||||
CSSEnabledState::eForAllContent);
|
||||
nsCSSProps::LookupProperty(nsDependentAtomString(aMappedAttrName));
|
||||
if (propertyID != eCSSProperty_UNKNOWN) {
|
||||
bool changed = false; // outparam for ParseProperty.
|
||||
NS_ConvertUTF16toUTF8 value(aMappedAttrValue);
|
||||
|
@ -538,8 +538,7 @@ CSSEditUtils::GetCSSInlinePropertyBase(nsINode* aNode,
|
||||
}
|
||||
|
||||
nsCSSPropertyID prop =
|
||||
nsCSSProps::LookupProperty(nsDependentAtomString(aProperty),
|
||||
CSSEnabledState::eForAllContent);
|
||||
nsCSSProps::LookupProperty(nsDependentAtomString(aProperty));
|
||||
MOZ_ASSERT(prop != eCSSProperty_UNKNOWN);
|
||||
|
||||
decl->GetPropertyValueByID(prop, aValue);
|
||||
|
@ -418,8 +418,7 @@ InspectorUtils::GetSubpropertiesForCSSProperty(GlobalObject& aGlobal,
|
||||
nsTArray<nsString>& aResult,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
nsCSSPropertyID propertyID =
|
||||
nsCSSProps::LookupProperty(aProperty, CSSEnabledState::eForAllContent);
|
||||
nsCSSPropertyID propertyID = nsCSSProps::LookupProperty(aProperty);
|
||||
|
||||
if (propertyID == eCSSProperty_UNKNOWN) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
|
@ -889,6 +889,9 @@ SERVO_BINDING_FUNC(Servo_ResolveLogicalProperty,
|
||||
nsCSSPropertyID,
|
||||
nsCSSPropertyID,
|
||||
ComputedStyleBorrowed);
|
||||
SERVO_BINDING_FUNC(Servo_Property_LookupEnabledForAllContent,
|
||||
nsCSSPropertyID,
|
||||
const nsACString* name);
|
||||
SERVO_BINDING_FUNC(Servo_Property_IsShorthand, bool,
|
||||
const nsACString* name, bool* found);
|
||||
SERVO_BINDING_FUNC(Servo_Property_IsInherited, bool,
|
||||
|
@ -162,40 +162,6 @@ nsCSSProps::IsCustomPropertyName(const nsAString& aProperty)
|
||||
StringBeginsWith(aProperty, NS_LITERAL_STRING("--"));
|
||||
}
|
||||
|
||||
nsCSSPropertyID
|
||||
nsCSSProps::LookupProperty(const nsAString& aProperty, EnabledState aEnabled)
|
||||
{
|
||||
if (IsCustomPropertyName(aProperty)) {
|
||||
return eCSSPropertyExtra_variable;
|
||||
}
|
||||
|
||||
// This is faster than converting and calling
|
||||
// LookupProperty(nsACString&). The table will do its own
|
||||
// converting and avoid a PromiseFlatCString() call.
|
||||
MOZ_ASSERT(gPropertyTable, "no lookup table, needs addref");
|
||||
nsCSSPropertyID res = nsCSSPropertyID(gPropertyTable->Lookup(aProperty));
|
||||
if (MOZ_LIKELY(res < eCSSProperty_COUNT)) {
|
||||
if (res != eCSSProperty_UNKNOWN && !IsEnabled(res, aEnabled)) {
|
||||
res = eCSSProperty_UNKNOWN;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
MOZ_ASSERT(eCSSAliasCount != 0,
|
||||
"'res' must be an alias at this point so we better have some!");
|
||||
// We intentionally don't support CSSEnabledState::eInUASheets or
|
||||
// CSSEnabledState::eInChrome for aliases yet because it's unlikely
|
||||
// there will be a need for it.
|
||||
if (IsEnabled(res) || aEnabled == CSSEnabledState::eIgnoreEnabledState) {
|
||||
res = gAliases[res - eCSSProperty_COUNT];
|
||||
MOZ_ASSERT(0 <= res && res < eCSSProperty_COUNT,
|
||||
"aliases must not point to other aliases");
|
||||
if (IsEnabled(res) || aEnabled == CSSEnabledState::eIgnoreEnabledState) {
|
||||
return res;
|
||||
}
|
||||
}
|
||||
return eCSSProperty_UNKNOWN;
|
||||
}
|
||||
|
||||
nsCSSPropertyID
|
||||
nsCSSProps::LookupPropertyByIDLName(const nsACString& aPropertyIDLName,
|
||||
EnabledState aEnabled)
|
||||
|
@ -14,7 +14,7 @@
|
||||
|
||||
#include <limits>
|
||||
#include <type_traits>
|
||||
#include "nsStringFwd.h"
|
||||
#include "nsString.h"
|
||||
#include "nsCSSPropertyID.h"
|
||||
#include "nsStyleStructFwd.h"
|
||||
#include "nsCSSKeywords.h"
|
||||
@ -36,6 +36,7 @@ class ComputedStyle;
|
||||
extern "C" {
|
||||
nsCSSPropertyID Servo_ResolveLogicalProperty(nsCSSPropertyID,
|
||||
const mozilla::ComputedStyle*);
|
||||
nsCSSPropertyID Servo_Property_LookupEnabledForAllContent(const nsACString*);
|
||||
}
|
||||
|
||||
struct nsCSSKTableEntry
|
||||
@ -80,8 +81,20 @@ public:
|
||||
// Looks up the property with name aProperty and returns its corresponding
|
||||
// nsCSSPropertyID value. If aProperty is the name of a custom property,
|
||||
// then eCSSPropertyExtra_variable will be returned.
|
||||
static nsCSSPropertyID LookupProperty(const nsAString& aProperty,
|
||||
EnabledState aEnabled);
|
||||
//
|
||||
// This only returns properties enabled for all content, and resolves aliases
|
||||
// to return the aliased property.
|
||||
static nsCSSPropertyID LookupProperty(const nsACString& aProperty)
|
||||
{
|
||||
return Servo_Property_LookupEnabledForAllContent(&aProperty);
|
||||
}
|
||||
|
||||
static nsCSSPropertyID LookupProperty(const nsAString& aProperty)
|
||||
{
|
||||
NS_ConvertUTF16toUTF8 utf8(aProperty);
|
||||
return LookupProperty(utf8);
|
||||
}
|
||||
|
||||
// As above, but looked up using a property's IDL name.
|
||||
// eCSSPropertyExtra_variable won't be returned from these methods.
|
||||
static nsCSSPropertyID LookupPropertyByIDLName(
|
||||
|
@ -437,8 +437,7 @@ nsComputedDOMStyle::GetPropertyValue(const nsAString& aPropertyName,
|
||||
{
|
||||
aReturn.Truncate();
|
||||
|
||||
nsCSSPropertyID prop =
|
||||
nsCSSProps::LookupProperty(aPropertyName, CSSEnabledState::eForAllContent);
|
||||
nsCSSPropertyID prop = nsCSSProps::LookupProperty(aPropertyName);
|
||||
|
||||
const ComputedStyleMap::Entry* entry = nullptr;
|
||||
if (prop != eCSSPropertyExtra_variable) {
|
||||
@ -719,7 +718,7 @@ CollectImageURLsForProperty(nsCSSPropertyID aProp,
|
||||
nsTArray<nsString>& aURLs)
|
||||
{
|
||||
if (nsCSSProps::IsShorthand(aProp)) {
|
||||
CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(p, aProp, CSSEnabledState::eInChrome) {
|
||||
CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(p, aProp, CSSEnabledState::eForAllContent) {
|
||||
CollectImageURLsForProperty(*p, aStyle, aURLs);
|
||||
}
|
||||
return;
|
||||
@ -761,8 +760,7 @@ nsComputedDOMStyle::GetCSSImageURLs(const nsAString& aPropertyName,
|
||||
nsTArray<nsString>& aImageURLs,
|
||||
mozilla::ErrorResult& aRv)
|
||||
{
|
||||
nsCSSPropertyID prop =
|
||||
nsCSSProps::LookupProperty(aPropertyName, CSSEnabledState::eInChrome);
|
||||
nsCSSPropertyID prop = nsCSSProps::LookupProperty(aPropertyName);
|
||||
if (prop == eCSSProperty_UNKNOWN) {
|
||||
aRv.Throw(NS_ERROR_DOM_SYNTAX_ERR);
|
||||
return;
|
||||
|
@ -209,8 +209,7 @@ nsDOMCSSDeclaration::SetProperty(const nsAString& aPropertyName,
|
||||
}
|
||||
|
||||
// In the common (and fast) cases we can use the property id
|
||||
nsCSSPropertyID propID =
|
||||
nsCSSProps::LookupProperty(aPropertyName, CSSEnabledState::eForAllContent);
|
||||
nsCSSPropertyID propID = nsCSSProps::LookupProperty(aPropertyName);
|
||||
if (propID == eCSSProperty_UNKNOWN) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -21,71 +21,6 @@ static const char* const kJunkNames[] = {
|
||||
"#@$&@#*@*$@$#"
|
||||
};
|
||||
|
||||
static bool
|
||||
TestProps()
|
||||
{
|
||||
bool success = true;
|
||||
nsCSSPropertyID id;
|
||||
nsCSSPropertyID index;
|
||||
|
||||
// Everything appears to assert if we don't do this first...
|
||||
nsCSSProps::AddRefTable();
|
||||
|
||||
// First make sure we can find all of the tags that are supposed to
|
||||
// be in the table. Futz with the case to make sure any case will
|
||||
// work
|
||||
extern const char* const kCSSRawProperties[];
|
||||
const char*const* et = &kCSSRawProperties[0];
|
||||
const char*const* end = &kCSSRawProperties[eCSSProperty_COUNT];
|
||||
index = eCSSProperty_UNKNOWN;
|
||||
while (et < end) {
|
||||
char tagName[100];
|
||||
PL_strcpy(tagName, *et);
|
||||
index = nsCSSPropertyID(int32_t(index) + 1);
|
||||
|
||||
id = nsCSSProps::LookupProperty(nsCString(tagName),
|
||||
CSSEnabledState::eIgnoreEnabledState);
|
||||
if (id == eCSSProperty_UNKNOWN) {
|
||||
printf("bug: can't find '%s'\n", tagName);
|
||||
success = false;
|
||||
}
|
||||
if (id != index) {
|
||||
printf("bug: name='%s' id=%d index=%d\n", tagName, id, index);
|
||||
success = false;
|
||||
}
|
||||
|
||||
// fiddle with the case to make sure we can still find it
|
||||
if (('a' <= tagName[0]) && (tagName[0] <= 'z')) {
|
||||
tagName[0] = tagName[0] - 32;
|
||||
}
|
||||
id = nsCSSProps::LookupProperty(NS_ConvertASCIItoUTF16(tagName),
|
||||
CSSEnabledState::eIgnoreEnabledState);
|
||||
if (id < 0) {
|
||||
printf("bug: can't find '%s'\n", tagName);
|
||||
success = false;
|
||||
}
|
||||
if (index != id) {
|
||||
printf("bug: name='%s' id=%d index=%d\n", tagName, id, index);
|
||||
success = false;
|
||||
}
|
||||
et++;
|
||||
}
|
||||
|
||||
// Now make sure we don't find some garbage
|
||||
for (int i = 0; i < (int) (sizeof(kJunkNames) / sizeof(const char*)); i++) {
|
||||
const char* const tag = kJunkNames[i];
|
||||
id = nsCSSProps::LookupProperty(nsAutoCString(tag),
|
||||
CSSEnabledState::eIgnoreEnabledState);
|
||||
if (id >= 0) {
|
||||
printf("bug: found '%s'\n", tag ? tag : "(null)");
|
||||
success = false;
|
||||
}
|
||||
}
|
||||
|
||||
nsCSSProps::ReleaseTable();
|
||||
return success;
|
||||
}
|
||||
|
||||
bool
|
||||
TestKeywords()
|
||||
{
|
||||
|
@ -1870,6 +1870,18 @@ impl PropertyId {
|
||||
id.enabled_for_all_content()
|
||||
}
|
||||
|
||||
/// Converts this PropertyId in nsCSSPropertyID, resolving aliases to the
|
||||
/// resolved property, and returning eCSSPropertyExtra_variable for custom
|
||||
/// properties.
|
||||
#[cfg(feature = "gecko")]
|
||||
#[inline]
|
||||
pub fn to_nscsspropertyid_resolving_aliases(&self) -> nsCSSPropertyID {
|
||||
match self.non_custom_non_alias_id() {
|
||||
Some(id) => id.to_nscsspropertyid(),
|
||||
None => nsCSSPropertyID::eCSSPropertyExtra_variable,
|
||||
}
|
||||
}
|
||||
|
||||
fn allowed_in(&self, context: &ParserContext) -> bool {
|
||||
let id = match self.non_custom_id() {
|
||||
// Custom properties are allowed everywhere
|
||||
|
@ -925,6 +925,17 @@ pub extern "C" fn Servo_ResolveLogicalProperty(
|
||||
longhand.to_physical(style.writing_mode).to_nscsspropertyid()
|
||||
}
|
||||
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn Servo_Property_LookupEnabledForAllContent(
|
||||
prop: *const nsACString,
|
||||
) -> nsCSSPropertyID {
|
||||
match PropertyId::parse_enabled_for_all_content((*prop).as_str_unchecked()) {
|
||||
Ok(p) => p.to_nscsspropertyid_resolving_aliases(),
|
||||
Err(..) => nsCSSPropertyID::eCSSProperty_UNKNOWN,
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! parse_enabled_property_name {
|
||||
($prop_name:ident, $found:ident, $default:expr) => {{
|
||||
let prop_name = $prop_name.as_ref().unwrap().as_str_unchecked();
|
||||
|
Loading…
x
Reference in New Issue
Block a user