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

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

Issue 778723002: Refactor CSSGradientValue (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Remove m_colorIsDerivedFromElement Created 6 years 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 | « Source/core/css/CSSGradientValue.h ('k') | Source/core/css/resolver/ElementStyleResources.cpp » ('j') | 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 03479afd02eb0e92a6ebc72ca90a9c46f6c6817d..1b048ece7a40da7a84ca5a1f9ac8af8b4cc35168 100644
--- a/Source/core/css/CSSGradientValue.cpp
+++ b/Source/core/css/CSSGradientValue.cpp
@@ -114,38 +114,7 @@ public:
{ }
};
-PassRefPtrWillBeRawPtr<CSSGradientValue> CSSGradientValue::gradientWithStylesResolved(const TextLinkColors& textLinkColors, Color currentColor)
-{
- bool derived = false;
- for (auto& stop : m_stops) {
- if (!stop.isHint() && stop.m_color->colorIsDerivedFromElement()) {
- stop.m_colorIsDerivedFromElement = true;
- derived = true;
- break;
- }
- }
-
- RefPtrWillBeRawPtr<CSSGradientValue> result = nullptr;
- if (!derived)
- result = this;
- else if (isLinearGradientValue())
- result = toCSSLinearGradientValue(this)->clone();
- else if (isRadialGradientValue())
- result = toCSSRadialGradientValue(this)->clone();
- else {
- ASSERT_NOT_REACHED();
- return nullptr;
- }
-
- for (auto& stop : result->m_stops) {
- if (!stop.isHint())
- stop.m_resolvedColor = textLinkColors.colorFromPrimitiveValue(stop.m_color.get(), currentColor);
- }
-
- return result.release();
-}
-
-static void replaceColorHintsWithColorStops(WillBeHeapVector<GradientStop>& stops, const WillBeHeapVector<CSSGradientColorStop, 2>& cssGradientStops)
+void replaceColorHintsWithColorStops(WillBeHeapVector<GradientStop>& stops, const WillBeHeapVector<CSSGradientColorStop, 2>& cssGradientStops)
{
// This algorithm will replace each color interpolation hint with 9 regular
// color stops. The color values for the new color stops will be calculated
@@ -233,6 +202,11 @@ static void replaceColorHintsWithColorStops(WillBeHeapVector<GradientStop>& stop
}
}
+static Color resolveStopColor(CSSPrimitiveValue* stopColor, const RenderObject& object)
+{
+ return object.document().textLinkColors().colorFromPrimitiveValue(stopColor, object.resolveColor(CSSPropertyColor));
+}
+
void CSSGradientValue::addStops(Gradient* gradient, const CSSToLengthConversionData& conversionData, float maxLengthForRepeat, const RenderObject& object)
{
if (m_gradientType == CSSDeprecatedLinearGradient || m_gradientType == CSSDeprecatedRadialGradient) {
@@ -247,7 +221,7 @@ void CSSGradientValue::addStops(Gradient* gradient, const CSSToLengthConversionD
else
offset = stop.m_position->getFloatValue(CSSPrimitiveValue::CSS_NUMBER);
- gradient->addColorStop(offset, stop.m_resolvedColor);
+ gradient->addColorStop(offset, resolveStopColor(stop.m_color.get(), object));
}
return;
@@ -275,7 +249,7 @@ void CSSGradientValue::addStops(Gradient* gradient, const CSSToLengthConversionD
if (stop.isHint())
hasHints = true;
else
- stops[i].color = object.document().textLinkColors().colorFromPrimitiveValue(stop.m_color.get(), object.style()->visitedDependentColor(CSSPropertyColor));
+ stops[i].color = resolveStopColor(stop.m_color.get(), object);
if (stop.m_position) {
if (stop.m_position->isPercentage())
@@ -559,7 +533,7 @@ bool CSSGradientValue::isCacheable() const
for (size_t i = 0; i < m_stops.size(); ++i) {
const CSSGradientColorStop& stop = m_stops[i];
- if (stop.m_colorIsDerivedFromElement)
+ if (!stop.isHint() && stop.m_color->colorIsDerivedFromElement())
return false;
if (!stop.m_position)
@@ -572,10 +546,11 @@ bool CSSGradientValue::isCacheable() const
return true;
}
-bool CSSGradientValue::knownToBeOpaque(const RenderObject*) const
+bool CSSGradientValue::knownToBeOpaque(const RenderObject* object) const
{
+ ASSERT(object);
for (auto& stop : m_stops) {
- if (!stop.isHint() && stop.m_resolvedColor.hasAlpha())
+ if (!stop.isHint() && resolveStopColor(stop.m_color.get(), *object).hasAlpha())
return false;
}
return true;
« no previous file with comments | « Source/core/css/CSSGradientValue.h ('k') | Source/core/css/resolver/ElementStyleResources.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698