Title: [169248] trunk
Revision
169248
Author
[email protected]
Date
2014-05-22 22:18:23 -0700 (Thu, 22 May 2014)

Log Message

Make viewport units work in CSS gradients
https://bugs.webkit.org/show_bug.cgi?id=133204
<rdar://problem/17012259>

Source/WebCore:

Reviewed by Tim Horton.

Make viewport percentage lengths work in gradients.

Test: fast/gradients/viewport-units-gradient.html

* css/CSSGradientValue.cpp:
(WebCore::CSSGradientValue::addStops):
(WebCore::CSSLinearGradientValue::createGradient):
(WebCore::CSSRadialGradientValue::createGradient):
* css/CSSGradientValue.h:

LayoutTests:

Reviewed by Tim Horton.

Make viewport percentage lengths work in gradients.

* fast/gradients/viewport-units-gradient-expected.html: Added.
* fast/gradients/viewport-units-gradient.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (169247 => 169248)


--- trunk/LayoutTests/ChangeLog	2014-05-23 04:34:32 UTC (rev 169247)
+++ trunk/LayoutTests/ChangeLog	2014-05-23 05:18:23 UTC (rev 169248)
@@ -1,3 +1,16 @@
+2014-05-22  Simon Fraser  <[email protected]>
+
+        Make viewport units work in CSS gradients
+        https://bugs.webkit.org/show_bug.cgi?id=133204
+        <rdar://problem/17012259>
+
+        Reviewed by Tim Horton.
+
+        Make viewport percentage lengths work in gradients.
+
+        * fast/gradients/viewport-units-gradient-expected.html: Added.
+        * fast/gradients/viewport-units-gradient.html: Added.
+
 2014-05-22  Ryosuke Niwa  <[email protected]>
 
         Can't type in status in facebook.com on iOS Safari because keyboard disappears

Added: trunk/LayoutTests/fast/gradients/viewport-units-gradient-expected.html (0 => 169248)


--- trunk/LayoutTests/fast/gradients/viewport-units-gradient-expected.html	                        (rev 0)
+++ trunk/LayoutTests/fast/gradients/viewport-units-gradient-expected.html	2014-05-23 05:18:23 UTC (rev 169248)
@@ -0,0 +1,18 @@
+<!DOCTYPE html>
+
+<html>
+<head>
+    <style>
+        html {
+            background-image: linear-gradient(white, white 300px, black 300px, black 600px);
+        }
+        
+        body {
+            height: 600px;
+        }
+    </style>
+</head>
+<body>
+
+</body>
+</html>

Added: trunk/LayoutTests/fast/gradients/viewport-units-gradient.html (0 => 169248)


--- trunk/LayoutTests/fast/gradients/viewport-units-gradient.html	                        (rev 0)
+++ trunk/LayoutTests/fast/gradients/viewport-units-gradient.html	2014-05-23 05:18:23 UTC (rev 169248)
@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+
+<html>
+<head>
+    <style>
+        html {
+            background-image: linear-gradient(white, white 50vh, black 50vh, black 100vh);
+        }
+        
+        body {
+            height: 600px;
+        }
+    </style>
+</head>
+<body>
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (169247 => 169248)


--- trunk/Source/WebCore/ChangeLog	2014-05-23 04:34:32 UTC (rev 169247)
+++ trunk/Source/WebCore/ChangeLog	2014-05-23 05:18:23 UTC (rev 169248)
@@ -1,3 +1,21 @@
+2014-05-22  Simon Fraser  <[email protected]>
+
+        Make viewport units work in CSS gradients
+        https://bugs.webkit.org/show_bug.cgi?id=133204
+        <rdar://problem/17012259>
+        
+        Reviewed by Tim Horton.
+        
+        Make viewport percentage lengths work in gradients.
+
+        Test: fast/gradients/viewport-units-gradient.html
+
+        * css/CSSGradientValue.cpp:
+        (WebCore::CSSGradientValue::addStops):
+        (WebCore::CSSLinearGradientValue::createGradient):
+        (WebCore::CSSRadialGradientValue::createGradient):
+        * css/CSSGradientValue.h:
+
 2014-05-22  Benjamin Poulain  <[email protected]>
 
         [iOS][WK2] Add support for minimal-ui viewports

Modified: trunk/Source/WebCore/css/CSSGradientValue.cpp (169247 => 169248)


--- trunk/Source/WebCore/css/CSSGradientValue.cpp	2014-05-23 04:34:32 UTC (rev 169247)
+++ trunk/Source/WebCore/css/CSSGradientValue.cpp	2014-05-23 05:18:23 UTC (rev 169248)
@@ -129,7 +129,7 @@
     return result.release();
 }
 
-void CSSGradientValue::addStops(Gradient* gradient, const CSSToLengthConversionData& conversionData, float maxLengthForRepeat)
+void CSSGradientValue::addStops(Gradient* gradient, RenderView* renderView, const CSSToLengthConversionData& conversionData, float maxLengthForRepeat)
 {
     if (m_gradientType == CSSDeprecatedLinearGradient || m_gradientType == CSSDeprecatedRadialGradient) {
         sortStopsIfNeeded();
@@ -171,18 +171,21 @@
         stops[i].color = stop.m_resolvedColor;
 
         if (stop.m_position) {
-            if (stop.m_position->isPercentage())
-                stops[i].offset = stop.m_position->getFloatValue(CSSPrimitiveValue::CSS_PERCENTAGE) / 100;
-            else if (stop.m_position->isLength() || stop.m_position->isCalculatedPercentageWithLength()) {
+            const CSSPrimitiveValue& positionValue = *stop.m_position;
+            if (positionValue.isPercentage())
+                stops[i].offset = positionValue.getFloatValue(CSSPrimitiveValue::CSS_PERCENTAGE) / 100;
+            else if (positionValue.isLength() || positionValue.isViewportPercentageLength() || positionValue.isCalculatedPercentageWithLength()) {
                 if (!computedGradientLength) {
                     FloatSize gradientSize(gradientStart - gradientEnd);
                     gradientLength = gradientSize.diagonalLength();
                 }
                 float length;
-                if (stop.m_position->isLength())
-                    length = stop.m_position->computeLength<float>(conversionData);
+                if (positionValue.isLength())
+                    length = positionValue.computeLength<float>(conversionData);
+                else if (positionValue.isViewportPercentageLength())
+                    length = valueForLength(positionValue.viewportPercentageLength(), 0, renderView);
                 else {
-                    Ref<CalculationValue> calculationValue { stop.m_position->cssCalcValue()->createCalculationValue(conversionData) };
+                    Ref<CalculationValue> calculationValue { positionValue.cssCalcValue()->createCalculationValue(conversionData) };
                     length = calculationValue->evaluate(gradientLength);
                 }
                 stops[i].offset = (gradientLength > 0) ? length / gradientLength : 0;
@@ -701,7 +704,7 @@
     RefPtr<Gradient> gradient = Gradient::create(firstPoint, secondPoint);
 
     // Now add the stops.
-    addStops(gradient.get(), conversionData, 1);
+    addStops(gradient.get(), &renderer->view(), conversionData, 1);
 
     return gradient.release();
 }
@@ -1115,7 +1118,7 @@
     }
 
     // Now add the stops.
-    addStops(gradient.get(), conversionData, maxExtent);
+    addStops(gradient.get(), &renderer->view(), conversionData, maxExtent);
 
     return gradient.release();
 }

Modified: trunk/Source/WebCore/css/CSSGradientValue.h (169247 => 169248)


--- trunk/Source/WebCore/css/CSSGradientValue.h	2014-05-23 04:34:32 UTC (rev 169247)
+++ trunk/Source/WebCore/css/CSSGradientValue.h	2014-05-23 05:18:23 UTC (rev 169248)
@@ -35,6 +35,7 @@
 
 class FloatPoint;
 class Gradient;
+class RenderView;
 
 enum CSSGradientType {
     CSSDeprecatedLinearGradient,
@@ -109,7 +110,7 @@
     {
     }
 
-    void addStops(Gradient*, const CSSToLengthConversionData&, float maxLengthForRepeat = 0);
+    void addStops(Gradient*, RenderView*, const CSSToLengthConversionData&, float maxLengthForRepeat = 0);
 
     // Resolve points/radii to front end values.
     FloatPoint computeEndPoint(CSSPrimitiveValue*, CSSPrimitiveValue*, const CSSToLengthConversionData&, const FloatSize&);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to