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..aa7170984e149cb1e912ef4ba696c554d5778b76 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) |
|
Timothy Loh
2015/10/12 00:11:16
can we move this if statement below the other one
sashab
2015/10/12 23:11:01
Yeahhh.. It's a bit weird because applideTextDecor
|
| + 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,59 @@ 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) |
|
Timothy Loh
2015/10/12 00:11:16
"update" is really vague. How about overrideTextDe
sashab
2015/10/12 23:11:01
Hey, good one. Yup, this name is an artifact from
|
| { |
| - if (textDecoration() == TextDecorationNone) |
| - return; |
| + 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); |
| +} |
| - TextDecorationStyle style = textDecorationStyle(); |
| - StyleColor styleColor = decorationColorIncludingFallback(insideLink() == InsideVisitedLink); |
| +void ComputedStyle::applyTextDecorations(const Color& parentTextDecorationColor, bool overrideExistingColors) |
| +{ |
| + // If we have no decorations, return early. |
|
Timothy Loh
2015/10/12 00:11:16
This comment doesn't add value.
sashab
2015/10/12 23:11:02
Removed!
|
| + if (textDecoration() == TextDecorationNone && !inherited_flags.m_hasSimpleUnderline && !rareInheritedData->appliedTextDecorations) |
| + return; |
| - int decorations = textDecoration(); |
| + // If there are any color changes or decorations set by this element, stop using m_hasSimpleUnderline. |
| + Color currentTextDecorationColor = visitedDependentColor(CSSPropertyTextDecorationColor); |
| + if (inherited_flags.m_hasSimpleUnderline && (textDecoration() != TextDecorationNone || currentTextDecorationColor != parentTextDecorationColor)) { |
| + inherited_flags.m_hasSimpleUnderline = false; |
| + addAppliedTextDecoration(AppliedTextDecoration(TextDecorationUnderline, TextDecorationStyleSolid, parentTextDecorationColor)); |
| + } |
| - 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); |
| + // If we have a propagated color, update any other affected decorations. |
|
Timothy Loh
2015/10/12 00:11:16
Don't think this comment helps (or makes sense)
sashab
2015/10/12 23:11:01
Yup, 'propagated' doesn't belong here. Removed!
|
| + if (overrideExistingColors && rareInheritedData->appliedTextDecorations) |
| + updateAppliedTextDecorations(currentTextDecorationColor); |
| - if (!rareInheritedData->appliedTextDecorations && underline.isSimpleUnderline()) |
| - inherited_flags.m_textUnderline = true; |
| - else |
| - addAppliedTextDecoration(underline); |
| + if (textDecoration() == TextDecorationNone) |
| + return; |
| + ASSERT(!inherited_flags.m_hasSimpleUnderline); |
| + |
| + // To save memory, we don't use AppliedTextDecoration objects in the common case of a single simple underline. |
| + TextDecoration decorationLines = textDecoration(); |
| + TextDecorationStyle decorationStyle = textDecorationStyle(); |
| + StyleColor decorationColor = decorationColorIncludingFallback(insideLink() == InsideVisitedLink); |
| + bool isSimpleUnderline = decorationLines == TextDecorationUnderline && decorationStyle == TextDecorationStyleSolid && decorationColor.isCurrentColor(); |
| + if (!rareInheritedData->appliedTextDecorations && !inherited_flags.m_hasSimpleUnderline && isSimpleUnderline) { |
| + inherited_flags.m_hasSimpleUnderline = true; |
| + return; |
| } |
| - if (decorations & TextDecorationOverline) |
| - addAppliedTextDecoration(AppliedTextDecoration(TextDecorationOverline, style, styleColor)); |
| - if (decorations & TextDecorationLineThrough) |
| - addAppliedTextDecoration(AppliedTextDecoration(TextDecorationLineThrough, style, styleColor)); |
| + |
| + Color resolvedDecorationColor = decorationColor.resolve(currentTextDecorationColor); |
|
Timothy Loh
2015/10/12 00:11:16
isn't this exactly the same as currentTextDecorati
sashab
2015/10/12 23:11:02
Oh yeah, you're right :) Done.
|
| + 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; |