Implement parsing for CSS will-change
[WebKit-https.git] / Source / WebCore / css / StyleBuilderCustom.h
index 2eb1aa0..1cf5a82 100644 (file)
@@ -48,6 +48,7 @@
 #include "StyleFontSizeFunctions.h"
 #include "StyleGeneratedImage.h"
 #include "StyleResolver.h"
+#include "WillChangeData.h"
 
 namespace WebCore {
 
@@ -133,6 +134,7 @@ public:
     static void applyInitialWebkitScrollSnapPointsY(StyleResolver&);
     static void applyInheritWebkitScrollSnapPointsY(StyleResolver&);
 #endif
+    static void applyValueWillChange(StyleResolver&, CSSValue&);
 
 private:
     static void resetEffectiveZoom(StyleResolver&);
@@ -1717,6 +1719,37 @@ inline void StyleBuilderCustom::applyInheritWebkitScrollSnapPointsY(StyleResolve
 }
 #endif
 
+inline void StyleBuilderCustom::applyValueWillChange(StyleResolver& styleResolver, CSSValue& value)
+{
+    if (is<CSSPrimitiveValue>(value)) {
+        ASSERT(downcast<CSSPrimitiveValue>(value).getValueID() == CSSValueAuto);
+        styleResolver.style()->setWillChange(nullptr);
+        return;
+    }
+
+    Ref<WillChangeData> willChange = WillChangeData::create();
+    for (auto& item : downcast<CSSValueList>(value)) {
+        if (!is<CSSPrimitiveValue>(item.get()))
+            continue;
+
+        const auto& primitiveValue = downcast<CSSPrimitiveValue>(item.get());
+        switch (primitiveValue.getValueID()) {
+        case CSSValueScrollPosition:
+            willChange->addFeature(WillChangeData::Feature::ScrollPosition);
+            break;
+        case CSSValueContents:
+            willChange->addFeature(WillChangeData::Feature::Contents);
+            break;
+        default:
+            if (primitiveValue.isPropertyID())
+                willChange->addFeature(WillChangeData::Feature::Property, primitiveValue.getPropertyID());
+            break;
+        }
+    }
+
+    styleResolver.style()->setWillChange(WTF::move(willChange));
+}
+
 } // namespace WebCore
 
 #endif // StyleBuilderCustom_h