Bug 1309752: Add a method to physicalize longhands. r?heycam draft
authorEmilio Cobos Álvarez <emilio@crisal.io>
Fri, 06 Jul 2018 04:57:38 +0200
changeset 815641 19efac2b69ea32f475d77f76d0d4a1362fa1a75f
parent 815640 2ba47b6d669b72f1b9ad3ef8d66c2d26471a6673
child 815642 a8fcee647805fc363885125bb9e8e5be54c911e9
push id115591
push userbmo:emilio@crisal.io
push dateMon, 09 Jul 2018 16:15:39 +0000
reviewersheycam
bugs1309752
milestone63.0a1
Bug 1309752: Add a method to physicalize longhands. r?heycam MozReview-Commit-ID: 1eutEoeqQwk
layout/style/nsCSSProps.h
--- 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: