Bug 1408305 - Use Servo to parse IntersectionObserver rootMargin values. r=xidorn draft
authorCameron McCormack <cam@mcc.id.au>
Mon, 16 Oct 2017 18:02:16 +0800
changeset 681334 8b1204df875e93b2a1d7dbfe0f11a98296ea1334
parent 681333 f5075e887f8c9f8d6b5dad10283da494a5b9b997
child 681335 32218b9784d8f47b0541629b90b30b12831c1b2c
push id84788
push userbmo:cam@mcc.id.au
push dateTue, 17 Oct 2017 04:58:36 +0000
reviewersxidorn
bugs1408305
milestone58.0a1
Bug 1408305 - Use Servo to parse IntersectionObserver rootMargin values. r=xidorn MozReview-Commit-ID: 4CIXP73kcf2
dom/base/DOMIntersectionObserver.cpp
layout/style/ServoBindingList.h
layout/style/ServoBindings.toml
layout/style/ServoCSSParser.cpp
layout/style/ServoCSSParser.h
--- a/dom/base/DOMIntersectionObserver.cpp
+++ b/dom/base/DOMIntersectionObserver.cpp
@@ -5,16 +5,17 @@
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "DOMIntersectionObserver.h"
 #include "nsCSSParser.h"
 #include "nsCSSPropertyID.h"
 #include "nsIFrame.h"
 #include "nsContentUtils.h"
 #include "nsLayoutUtils.h"
+#include "mozilla/ServoCSSParser.h"
 
 namespace mozilla {
 namespace dom {
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(DOMIntersectionObserverEntry)
   NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
   NS_INTERFACE_MAP_ENTRY(nsISupports)
 NS_INTERFACE_MAP_END
@@ -111,16 +112,21 @@ DOMIntersectionObserver::Constructor(con
   }
 
   return observer.forget();
 }
 
 bool
 DOMIntersectionObserver::SetRootMargin(const nsAString& aString)
 {
+  if (mDocument && mDocument->IsStyledByServo()) {
+    return ServoCSSParser::ParseIntersectionObserverRootMargin(aString,
+                                                               &mRootMargin);
+  }
+
   // By not passing a CSS Loader object we make sure we don't parse in quirks
   // mode so that pixel/percent and unit-less values will be differentiated.
   nsCSSParser parser(nullptr);
   nsCSSValue value;
   if (!parser.ParseMarginString(aString, nullptr, 0, value, true)) {
     return false;
   }
 
--- a/layout/style/ServoBindingList.h
+++ b/layout/style/ServoBindingList.h
@@ -684,15 +684,18 @@ SERVO_BINDING_FUNC(Servo_CloneArcStringD
 
 // CSS parsing utility functions.
 SERVO_BINDING_FUNC(Servo_IsValidCSSColor, bool, const nsAString* value);
 SERVO_BINDING_FUNC(Servo_ComputeColor, bool,
                    RawServoStyleSetBorrowedOrNull set,
                    nscolor current_color,
                    const nsAString* value,
                    nscolor* result_color);
+SERVO_BINDING_FUNC(Servo_ParseIntersectionObserverRootMargin, bool,
+                   const nsAString* value,
+                   nsCSSRect* result);
 
 // AddRef / Release functions
 #define SERVO_ARC_TYPE(name_, type_)                                \
   SERVO_BINDING_FUNC(Servo_##name_##_AddRef, void, type_##Borrowed) \
   SERVO_BINDING_FUNC(Servo_##name_##_Release, void, type_##Borrowed)
 #include "mozilla/ServoArcTypeList.h"
 #undef SERVO_ARC_TYPE
--- a/layout/style/ServoBindings.toml
+++ b/layout/style/ServoBindings.toml
@@ -444,16 +444,17 @@ structs-types = [
     "StyleShapeSource",
     "StyleTransition",
     "gfxFontFeatureValueSet",
     "nsCSSCounterStyleRule",
     "nsCSSFontFaceRule",
     "nsCSSKeyword",
     "nsCSSPropertyID",
     "nsCSSPropertyIDSet",
+    "nsCSSRect",
     "nsCSSShadowArray",
     "nsCSSUnit",
     "nsCSSValue",
     "nsCSSValueSharedList",
     "nsChangeHint",
     "nsCursorImage",
     "nsFont",
     "nsAtom",
--- a/layout/style/ServoCSSParser.cpp
+++ b/layout/style/ServoCSSParser.cpp
@@ -20,8 +20,15 @@ ServoCSSParser::IsValidCSSColor(const ns
 ServoCSSParser::ComputeColor(ServoStyleSet* aStyleSet,
                              nscolor aCurrentColor,
                              const nsAString& aValue,
                              nscolor* aResultColor)
 {
   return Servo_ComputeColor(aStyleSet ? aStyleSet->RawSet() : nullptr,
                             aCurrentColor, &aValue, aResultColor);
 }
+
+/* static */ bool
+ServoCSSParser::ParseIntersectionObserverRootMargin(const nsAString& aValue,
+                                                    nsCSSRect* aResult)
+{
+  return Servo_ParseIntersectionObserverRootMargin(&aValue, aResult);
+}
--- a/layout/style/ServoCSSParser.h
+++ b/layout/style/ServoCSSParser.h
@@ -33,13 +33,24 @@ public:
    * @param aValue The CSS <color> value.
    * @param aResultColor The resulting computed color value.
    * @return Whether aValue was successfully parsed and aResultColor was set.
    */
   static bool ComputeColor(ServoStyleSet* aStyleSet,
                            nscolor aCurrentColor,
                            const nsAString& aValue,
                            nscolor* aResultColor);
+
+  /**
+   * Parses a IntersectionObserver's initialization dictionary's rootMargin
+   * property.
+   *
+   * @param aValue The rootMargin value.
+   * @param aResult The nsCSSRect object to write the result into.
+   * @return Whether the value was successfully parsed.
+   */
+  static bool ParseIntersectionObserverRootMargin(const nsAString& aValue,
+                                                  nsCSSRect* aResult);
 };
 
 } // namespace mozilla
 
 #endif // mozilla_ServoCSSParser_h