Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(131)

Unified Diff: Source/core/css/CSSGradientValue.cpp

Issue 356683005: Support radial-gradients with relative offsets (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « LayoutTests/fast/css/radial-gradient-position-with-relative-offset-expected.html ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/css/CSSGradientValue.cpp
diff --git a/Source/core/css/CSSGradientValue.cpp b/Source/core/css/CSSGradientValue.cpp
index 277162fd89ba49b8b354817c3e4bca249a68a349..454e55be078301da1d85b411f01f6af3544b826a 100644
--- a/Source/core/css/CSSGradientValue.cpp
+++ b/Source/core/css/CSSGradientValue.cpp
@@ -29,6 +29,7 @@
#include "core/CSSValueKeywords.h"
#include "core/css/CSSCalculationValue.h"
#include "core/css/CSSToLengthConversionData.h"
+#include "core/css/Pair.h"
#include "core/dom/NodeRenderStyle.h"
#include "core/dom/TextLinkColors.h"
#include "core/rendering/RenderObject.h"
@@ -387,12 +388,33 @@ void CSSGradientValue::addStops(Gradient* gradient, const CSSToLengthConversionD
gradient->addColorStop(stops[i].offset, stops[i].color);
}
+static float positionFromPairValue(CSSPrimitiveValue* value, int edgeDistance, const CSSToLengthConversionData& conversionData)
f(malita) 2014/06/26 20:33:43 I think we can fold this into the original method,
+{
+ if (value->isNumber())
+ return edgeDistance - (value->getFloatValue() * conversionData.zoom());
+ if (value->isPercentage())
+ return (100 - value->getFloatValue()) / 100.f * edgeDistance;
+ if (value->isCalculatedPercentageWithLength())
+ return edgeDistance - value->cssCalcValue()->toCalcValue(conversionData)->evaluate(edgeDistance);
+ return edgeDistance - value->computeLength<float>(conversionData);
+}
+
static float positionFromValue(CSSPrimitiveValue* value, const CSSToLengthConversionData& conversionData, const IntSize& size, bool isHorizontal)
f(malita) 2014/06/26 20:33:43 How about something like this instead: static flo
{
+ int edgeDistance = isHorizontal ? size.width() : size.height();
+ if (Pair* pair = value->getPairValue()) {
f(malita) 2014/06/26 20:33:42 We should probably add an inline comment describin
+ CSSValueID keyword = pair->first()->getValueID();
+ CSSPrimitiveValue* offsetValue = pair->second();
+
+ if (keyword == CSSValueRight || keyword == CSSValueBottom)
+ return positionFromPairValue(offsetValue, edgeDistance, conversionData);
+
+ value = offsetValue;
+ }
+
if (value->isNumber())
return value->getFloatValue() * conversionData.zoom();
- int edgeDistance = isHorizontal ? size.width() : size.height();
if (value->isPercentage())
return value->getFloatValue() / 100.f * edgeDistance;
« no previous file with comments | « LayoutTests/fast/css/radial-gradient-position-with-relative-offset-expected.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698