Bug 1309752: Add a method to physicalize longhands. r?heycam
MozReview-Commit-ID: 1eutEoeqQwk
--- a/layout/style/nsCSSProps.h
+++ b/layout/style/nsCSSProps.h
@@ -24,16 +24,25 @@
#include "mozilla/EnumTypeTraits.h"
#include "mozilla/Preferences.h"
#include "nsXULAppAPI.h"
// Length of the "--" prefix on custom names (such as custom property names,
// and, in the future, custom media query names).
#define CSS_CUSTOM_NAME_PREFIX_LENGTH 2
+namespace mozilla {
+class ComputedStyle;
+}
+
+extern "C" {
+ nsCSSPropertyID Servo_ResolveLogicalProperty(nsCSSPropertyID,
+ const mozilla::ComputedStyle*);
+}
+
struct nsCSSKTableEntry
{
// nsCSSKTableEntry objects can be initialized either with an int16_t value
// or a value of an enumeration type that can fit within an int16_t.
constexpr nsCSSKTableEntry(nsCSSKeyword aKeyword, int16_t aValue)
: mKeyword(aKeyword)
, mValue(aValue)
@@ -81,17 +90,18 @@ public:
static nsCSSPropertyID LookupPropertyByIDLName(
const nsACString& aPropertyIDLName,
EnabledState aEnabled);
// Returns whether aProperty is a custom property name, i.e. begins with
// "--". This assumes that the CSS Variables pref has been enabled.
static bool IsCustomPropertyName(const nsAString& aProperty);
- static inline bool IsShorthand(nsCSSPropertyID aProperty) {
+ static bool IsShorthand(nsCSSPropertyID aProperty)
+ {
MOZ_ASSERT(0 <= aProperty && aProperty < eCSSProperty_COUNT,
"out of range");
return (aProperty >= eCSSProperty_COUNT_no_shorthands);
}
// Same but for @font-face descriptors
static nsCSSFontDesc LookupFontDesc(const nsAString& aProperty);
@@ -134,32 +144,41 @@ public:
"aValue must be an enum that fits within KTableEntry::mValue");
return ValueToKeyword(static_cast<int16_t>(aValue), aTable);
}
private:
static const Flags kFlagsTable[eCSSProperty_COUNT];
public:
- static inline bool PropHasFlags(nsCSSPropertyID aProperty, Flags aFlags)
+ static bool PropHasFlags(nsCSSPropertyID aProperty, Flags aFlags)
{
MOZ_ASSERT(0 <= aProperty && aProperty < eCSSProperty_COUNT,
"out of range");
return (nsCSSProps::kFlagsTable[aProperty] & aFlags) == aFlags;
}
+ static nsCSSPropertyID Physicalize(nsCSSPropertyID aProperty,
+ const mozilla::ComputedStyle& aStyle)
+ {
+ if (PropHasFlags(aProperty, Flags::IsLogical)) {
+ return Servo_ResolveLogicalProperty(aProperty, &aStyle);
+ }
+ return aProperty;
+ }
+
private:
// A table for shorthand properties. The appropriate index is the
// property ID minus eCSSProperty_COUNT_no_shorthands.
- static const nsCSSPropertyID *const
+ static const nsCSSPropertyID* const
kSubpropertyTable[eCSSProperty_COUNT - eCSSProperty_COUNT_no_shorthands];
public:
- static inline
- const nsCSSPropertyID * SubpropertyEntryFor(nsCSSPropertyID aProperty) {
+ static const nsCSSPropertyID* SubpropertyEntryFor(nsCSSPropertyID aProperty)
+ {
MOZ_ASSERT(eCSSProperty_COUNT_no_shorthands <= aProperty &&
aProperty < eCSSProperty_COUNT,
"out of range");
return nsCSSProps::kSubpropertyTable[aProperty -
eCSSProperty_COUNT_no_shorthands];
}
private: