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

Unified Diff: Source/core/style/ComputedStyle.cpp

Issue 1328283005: Add support for multiple text decorations with same line positioning (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Review feedback Created 5 years, 3 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
Index: Source/core/style/ComputedStyle.cpp
diff --git a/Source/core/style/ComputedStyle.cpp b/Source/core/style/ComputedStyle.cpp
index 739ff8076e479bc25c6e072a6b41be9b39e1e3b5..351d60bedc37db26887455d409567824a205fff2 100644
--- a/Source/core/style/ComputedStyle.cpp
+++ b/Source/core/style/ComputedStyle.cpp
@@ -742,7 +742,7 @@ void ComputedStyle::updatePropertySpecificDifferences(const ComputedStyle& other
if (!diff.needsPaintInvalidation()) {
if (inherited->color != other.inherited->color
|| inherited->visitedLinkColor != other.inherited->visitedLinkColor
- || inherited_flags.m_textUnderline != other.inherited_flags.m_textUnderline
+ || inherited_flags.m_hasSimpleUnderline != other.inherited_flags.m_hasSimpleUnderline
|| visual->textDecoration != other.visual->textDecoration) {
diff.setTextOrColorChanged();
} else if (rareNonInheritedData.get() != other.rareNonInheritedData.get()
@@ -1245,24 +1245,31 @@ FontStretch ComputedStyle::fontStretch() const { return fontDescription().stretc
TextDecoration ComputedStyle::textDecorationsInEffect() const
{
+ if (!inherited_flags.m_hasSimpleUnderline && !rareInheritedData->appliedTextDecorations)
+ return TextDecorationNone;
+ if (inherited_flags.m_hasSimpleUnderline)
+ return TextDecorationUnderline;
+
int decorations = 0;
const Vector<AppliedTextDecoration>& applied = appliedTextDecorations();
for (size_t i = 0; i < applied.size(); ++i)
- decorations |= applied[i].line();
+ decorations |= applied[i].lines();
return static_cast<TextDecoration>(decorations);
}
const Vector<AppliedTextDecoration>& ComputedStyle::appliedTextDecorations() const
{
- if (!inherited_flags.m_textUnderline && !rareInheritedData->appliedTextDecorations) {
+ if (!inherited_flags.m_hasSimpleUnderline && !rareInheritedData->appliedTextDecorations) {
DEFINE_STATIC_LOCAL(Vector<AppliedTextDecoration>, empty, ());
return empty;
}
- if (inherited_flags.m_textUnderline) {
- DEFINE_STATIC_LOCAL(Vector<AppliedTextDecoration>, underline, (1, AppliedTextDecoration(TextDecorationUnderline)));
+ if (inherited_flags.m_hasSimpleUnderline) {
+ DEFINE_STATIC_LOCAL(Vector<AppliedTextDecoration>, underline, (1, AppliedTextDecoration(TextDecorationUnderline, TextDecorationStyleSolid, Color::transparent, true)));
+ // Since we only have one of these in memory, just update the color before returning.
+ underline.at(0).applyPropagatedColor(visitedDependentSimpleUnderlineColor());
return underline;
}
@@ -1370,43 +1377,64 @@ void ComputedStyle::addAppliedTextDecoration(const AppliedTextDecoration& decora
else if (!list->hasOneRef())
list = list->copy();
- if (inherited_flags.m_textUnderline) {
- inherited_flags.m_textUnderline = false;
- list->append(AppliedTextDecoration(TextDecorationUnderline));
- }
-
list->append(decoration);
}
-void ComputedStyle::applyTextDecorations()
+void ComputedStyle::updateAppliedTextDecoration(size_t index, Color newColor)
{
- if (textDecoration() == TextDecorationNone)
+ RefPtr<AppliedTextDecorationList>& list = rareInheritedData.access()->appliedTextDecorations;
+
+ if (!list)
+ list = AppliedTextDecorationList::create();
+ else if (!list->hasOneRef())
+ list = list->copy();
+
+ list->at(index).applyPropagatedColor(newColor);
+}
+
+void ComputedStyle::applyTextDecorations(bool overrideExistingColors)
+{
+ if (textDecoration() == TextDecorationNone && !inherited_flags.m_hasSimpleUnderline && !rareInheritedData->appliedTextDecorations)
return;
- TextDecorationStyle style = textDecorationStyle();
- StyleColor styleColor = decorationColorIncludingFallback(insideLink() == InsideVisitedLink);
+ // If we have a propagated color, update any other affected decorations.
+ if (overrideExistingColors && inherited_flags.m_hasSimpleUnderline) {
+ setSimpleUnderlineColor(colorIncludingFallback(CSSPropertyTextDecorationColor, false));
+ setSimpleUnderlineVisitedColor(colorIncludingFallback(CSSPropertyTextDecorationColor, true));
+ } else if (overrideExistingColors && rareInheritedData->appliedTextDecorations) {
+ for (size_t i = 0; i < rareInheritedData->appliedTextDecorations->size(); ++i) {
+ AppliedTextDecoration& decoration = rareInheritedData->appliedTextDecorations->at(i);
+ if (decoration.isAffectedByPropagatedColors())
+ updateAppliedTextDecoration(i, visitedDependentColor(CSSPropertyTextDecorationColor));
+ }
+ }
- int decorations = textDecoration();
+ TextDecoration decorationLines = textDecoration();
+ TextDecorationStyle decorationStyle = textDecorationStyle();
+ StyleColor decorationColor = decorationColorIncludingFallback(insideLink() == InsideVisitedLink);
- if (decorations & TextDecorationUnderline) {
- // To save memory, we don't use AppliedTextDecoration objects in the
- // common case of a single simple underline.
- AppliedTextDecoration underline(TextDecorationUnderline, style, styleColor);
+ // To save memory, we don't use AppliedTextDecoration objects in the common case of a single simple underline.
+ if (!rareInheritedData->appliedTextDecorations && !inherited_flags.m_hasSimpleUnderline
+ && decorationLines == TextDecorationUnderline && decorationStyle == TextDecorationStyleSolid && decorationColor.isCurrentColor()) {
+ inherited_flags.m_hasSimpleUnderline = true;
+ setSimpleUnderlineColor(colorIncludingFallback(CSSPropertyTextDecorationColor, false));
+ setSimpleUnderlineVisitedColor(colorIncludingFallback(CSSPropertyTextDecorationColor, true));
+ return;
+ }
- if (!rareInheritedData->appliedTextDecorations && underline.isSimpleUnderline())
- inherited_flags.m_textUnderline = true;
- else
- addAppliedTextDecoration(underline);
+ // Clear the existing optimization if we have it.
+ if (inherited_flags.m_hasSimpleUnderline) {
+ inherited_flags.m_hasSimpleUnderline = false;
+ addAppliedTextDecoration(AppliedTextDecoration(TextDecorationUnderline, TextDecorationStyleSolid, visitedDependentSimpleUnderlineColor(), true));
}
- if (decorations & TextDecorationOverline)
- addAppliedTextDecoration(AppliedTextDecoration(TextDecorationOverline, style, styleColor));
- if (decorations & TextDecorationLineThrough)
- addAppliedTextDecoration(AppliedTextDecoration(TextDecorationLineThrough, style, styleColor));
+
+ Color currentTextDecorationColor = visitedDependentColor(CSSPropertyTextDecorationColor);
+ addAppliedTextDecoration(AppliedTextDecoration(decorationLines, decorationStyle, decorationColor.resolve(currentTextDecorationColor), decorationColor.isCurrentColor()));
}
void ComputedStyle::clearAppliedTextDecorations()
{
- inherited_flags.m_textUnderline = false;
+ inherited_flags.m_hasSimpleUnderline = false;
if (rareInheritedData->appliedTextDecorations)
rareInheritedData.access()->appliedTextDecorations = nullptr;

Powered by Google App Engine
This is Rietveld 408576698