Chromium Code Reviews| Index: third_party/WebKit/Source/core/style/ComputedStyle.cpp |
| diff --git a/third_party/WebKit/Source/core/style/ComputedStyle.cpp b/third_party/WebKit/Source/core/style/ComputedStyle.cpp |
| index 3852f28062f1f9c3cbc46d26e638ce95829b3e2b..835d098507d4078eb35a9f6b96a665e867f824ae 100644 |
| --- a/third_party/WebKit/Source/core/style/ComputedStyle.cpp |
| +++ b/third_party/WebKit/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.setTextDecorationOrColorChanged(); |
| } 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, visitedDependentColor(CSSPropertyTextDecorationColor)))); |
| + // Since we only have one of these in memory, just update the color before returning. |
| + underline.at(0).setColor(visitedDependentColor(CSSPropertyTextDecorationColor)); |
| return underline; |
| } |
| @@ -1370,43 +1377,61 @@ 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::updateAppliedTextDecorations(Color propagatedColor) |
| +{ |
| + RefPtr<AppliedTextDecorationList>& list = rareInheritedData.access()->appliedTextDecorations; |
| + |
| + ASSERT(list); |
| + if (!list->hasOneRef()) |
| + list = list->copy(); |
| + |
| + for (size_t i = 0; i < rareInheritedData->appliedTextDecorations->size(); ++i) |
| + list->at(i).setColor(propagatedColor); |
| +} |
| + |
| +void ComputedStyle::applyTextDecorations(const ComputedStyle& parentStyle, bool overrideExistingColors) |
|
Timothy Loh
2015/10/01 01:51:43
just pass in the parent style's decoration color
sashab
2015/10/02 02:45:42
Done.
|
| { |
| - if (textDecoration() == TextDecorationNone) |
| + if (textDecoration() == TextDecorationNone && !inherited_flags.m_hasSimpleUnderline && !rareInheritedData->appliedTextDecorations) |
| return; |
| - TextDecorationStyle style = textDecorationStyle(); |
| - StyleColor styleColor = decorationColorIncludingFallback(insideLink() == InsideVisitedLink); |
| + // If there are any color changes, stop using m_hasSimpleUnderline. |
| + Color parentDecorationColor = parentStyle.visitedDependentColor(CSSPropertyTextDecorationColor); |
| + if (inherited_flags.m_hasSimpleUnderline && visitedDependentColor(CSSPropertyTextDecorationColor) != parentDecorationColor) { |
|
Timothy Loh
2015/10/01 01:51:43
can we not copy-paste visitedDependentColor(CSSPro
sashab
2015/10/02 02:45:42
Done.
|
| + inherited_flags.m_hasSimpleUnderline = false; |
| + addAppliedTextDecoration(AppliedTextDecoration(TextDecorationUnderline, TextDecorationStyleSolid, parentDecorationColor)); |
| + } |
| - int decorations = textDecoration(); |
| + // If we have a propagated color, update any other affected decorations. |
| + if (overrideExistingColors && rareInheritedData->appliedTextDecorations) |
| + updateAppliedTextDecorations(visitedDependentColor(CSSPropertyTextDecorationColor)); |
| - 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); |
| + TextDecoration decorationLines = textDecoration(); |
| + TextDecorationStyle decorationStyle = textDecorationStyle(); |
| + StyleColor decorationColor = decorationColorIncludingFallback(insideLink() == InsideVisitedLink); |
| - if (!rareInheritedData->appliedTextDecorations && underline.isSimpleUnderline()) |
| - inherited_flags.m_textUnderline = true; |
| - else |
| - addAppliedTextDecoration(underline); |
| + // 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; |
| + return; |
| + } |
| + |
| + // Clear the existing optimization if we have it. |
|
Timothy Loh
2015/10/01 01:51:43
The logic here is a bit complicated, can we just o
sashab
2015/10/02 02:45:42
Simplified it a bit.
|
| + if (inherited_flags.m_hasSimpleUnderline) { |
| + inherited_flags.m_hasSimpleUnderline = false; |
| + addAppliedTextDecoration(AppliedTextDecoration(TextDecorationUnderline, TextDecorationStyleSolid, visitedDependentColor(CSSPropertyTextDecorationColor))); |
| } |
| - if (decorations & TextDecorationOverline) |
| - addAppliedTextDecoration(AppliedTextDecoration(TextDecorationOverline, style, styleColor)); |
| - if (decorations & TextDecorationLineThrough) |
| - addAppliedTextDecoration(AppliedTextDecoration(TextDecorationLineThrough, style, styleColor)); |
| + |
| + Color resolvedDecorationColor = decorationColor.resolve(visitedDependentColor(CSSPropertyTextDecorationColor)); |
| + addAppliedTextDecoration(AppliedTextDecoration(decorationLines, decorationStyle, resolvedDecorationColor)); |
| } |
| void ComputedStyle::clearAppliedTextDecorations() |
| { |
| - inherited_flags.m_textUnderline = false; |
| + inherited_flags.m_hasSimpleUnderline = false; |
| if (rareInheritedData->appliedTextDecorations) |
| rareInheritedData.access()->appliedTextDecorations = nullptr; |