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

Side by Side Diff: third_party/WebKit/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: Rebase again Created 5 years, 2 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Antti Koivisto (koivisto@kde.org) 2 * Copyright (C) 1999 Antti Koivisto (koivisto@kde.org)
3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved. 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved.
4 * Copyright (C) 2011 Adobe Systems Incorporated. All rights reserved. 4 * Copyright (C) 2011 Adobe Systems Incorporated. All rights reserved.
5 * 5 *
6 * This library is free software; you can redistribute it and/or 6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public 7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either 8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version. 9 * version 2 of the License, or (at your option) any later version.
10 * 10 *
(...skipping 724 matching lines...) Expand 10 before | Expand all | Expand 10 after
735 if (rareNonInheritedData->m_filter != other.rareNonInheritedData->m_filt er) 735 if (rareNonInheritedData->m_filter != other.rareNonInheritedData->m_filt er)
736 diff.setFilterChanged(); 736 diff.setFilterChanged();
737 737
738 if (rareNonInheritedData->m_backdropFilter != other.rareNonInheritedData ->m_backdropFilter) 738 if (rareNonInheritedData->m_backdropFilter != other.rareNonInheritedData ->m_backdropFilter)
739 diff.setBackdropFilterChanged(); 739 diff.setBackdropFilterChanged();
740 } 740 }
741 741
742 if (!diff.needsPaintInvalidation()) { 742 if (!diff.needsPaintInvalidation()) {
743 if (inherited->color != other.inherited->color 743 if (inherited->color != other.inherited->color
744 || inherited->visitedLinkColor != other.inherited->visitedLinkColor 744 || inherited->visitedLinkColor != other.inherited->visitedLinkColor
745 || inherited_flags.m_textUnderline != other.inherited_flags.m_textUn derline 745 || inherited_flags.m_hasSimpleUnderline != other.inherited_flags.m_h asSimpleUnderline
746 || visual->textDecoration != other.visual->textDecoration) { 746 || visual->textDecoration != other.visual->textDecoration) {
747 diff.setTextDecorationOrColorChanged(); 747 diff.setTextDecorationOrColorChanged();
748 } else if (rareNonInheritedData.get() != other.rareNonInheritedData.get( ) 748 } else if (rareNonInheritedData.get() != other.rareNonInheritedData.get( )
749 && (rareNonInheritedData->m_textDecorationStyle != other.rareNonInhe ritedData->m_textDecorationStyle 749 && (rareNonInheritedData->m_textDecorationStyle != other.rareNonInhe ritedData->m_textDecorationStyle
750 || rareNonInheritedData->m_textDecorationColor != other.rareNonI nheritedData->m_textDecorationColor 750 || rareNonInheritedData->m_textDecorationColor != other.rareNonI nheritedData->m_textDecorationColor
751 || rareNonInheritedData->m_visitedLinkTextDecorationColor != oth er.rareNonInheritedData->m_visitedLinkTextDecorationColor)) { 751 || rareNonInheritedData->m_visitedLinkTextDecorationColor != oth er.rareNonInheritedData->m_visitedLinkTextDecorationColor)) {
752 diff.setTextDecorationOrColorChanged(); 752 diff.setTextDecorationOrColorChanged();
753 } else if (rareInheritedData.get() != other.rareInheritedData.get() 753 } else if (rareInheritedData.get() != other.rareInheritedData.get()
754 && (rareInheritedData->textFillColor() != other.rareInheritedData->t extFillColor() 754 && (rareInheritedData->textFillColor() != other.rareInheritedData->t extFillColor()
755 || rareInheritedData->textStrokeColor() != other.rareInheritedDa ta->textStrokeColor() 755 || rareInheritedData->textStrokeColor() != other.rareInheritedDa ta->textStrokeColor()
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after
1238 float ComputedStyle::specifiedFontSize() const { return fontDescription().specif iedSize(); } 1238 float ComputedStyle::specifiedFontSize() const { return fontDescription().specif iedSize(); }
1239 float ComputedStyle::computedFontSize() const { return fontDescription().compute dSize(); } 1239 float ComputedStyle::computedFontSize() const { return fontDescription().compute dSize(); }
1240 int ComputedStyle::fontSize() const { return fontDescription().computedPixelSize (); } 1240 int ComputedStyle::fontSize() const { return fontDescription().computedPixelSize (); }
1241 float ComputedStyle::fontSizeAdjust() const { return fontDescription().sizeAdjus t(); } 1241 float ComputedStyle::fontSizeAdjust() const { return fontDescription().sizeAdjus t(); }
1242 bool ComputedStyle::hasFontSizeAdjust() const { return fontDescription().hasSize Adjust(); } 1242 bool ComputedStyle::hasFontSizeAdjust() const { return fontDescription().hasSize Adjust(); }
1243 FontWeight ComputedStyle::fontWeight() const { return fontDescription().weight() ; } 1243 FontWeight ComputedStyle::fontWeight() const { return fontDescription().weight() ; }
1244 FontStretch ComputedStyle::fontStretch() const { return fontDescription().stretc h(); } 1244 FontStretch ComputedStyle::fontStretch() const { return fontDescription().stretc h(); }
1245 1245
1246 TextDecoration ComputedStyle::textDecorationsInEffect() const 1246 TextDecoration ComputedStyle::textDecorationsInEffect() const
1247 { 1247 {
1248 if (!inherited_flags.m_hasSimpleUnderline && !rareInheritedData->appliedText Decorations)
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
1249 return TextDecorationNone;
1250 if (inherited_flags.m_hasSimpleUnderline)
1251 return TextDecorationUnderline;
1252
1248 int decorations = 0; 1253 int decorations = 0;
1249 1254
1250 const Vector<AppliedTextDecoration>& applied = appliedTextDecorations(); 1255 const Vector<AppliedTextDecoration>& applied = appliedTextDecorations();
1251 1256
1252 for (size_t i = 0; i < applied.size(); ++i) 1257 for (size_t i = 0; i < applied.size(); ++i)
1253 decorations |= applied[i].line(); 1258 decorations |= applied[i].lines();
1254 1259
1255 return static_cast<TextDecoration>(decorations); 1260 return static_cast<TextDecoration>(decorations);
1256 } 1261 }
1257 1262
1258 const Vector<AppliedTextDecoration>& ComputedStyle::appliedTextDecorations() con st 1263 const Vector<AppliedTextDecoration>& ComputedStyle::appliedTextDecorations() con st
1259 { 1264 {
1260 if (!inherited_flags.m_textUnderline && !rareInheritedData->appliedTextDecor ations) { 1265 if (!inherited_flags.m_hasSimpleUnderline && !rareInheritedData->appliedText Decorations) {
1261 DEFINE_STATIC_LOCAL(Vector<AppliedTextDecoration>, empty, ()); 1266 DEFINE_STATIC_LOCAL(Vector<AppliedTextDecoration>, empty, ());
1262 return empty; 1267 return empty;
1263 } 1268 }
1264 if (inherited_flags.m_textUnderline) { 1269 if (inherited_flags.m_hasSimpleUnderline) {
1265 DEFINE_STATIC_LOCAL(Vector<AppliedTextDecoration>, underline, (1, Applie dTextDecoration(TextDecorationUnderline))); 1270 DEFINE_STATIC_LOCAL(Vector<AppliedTextDecoration>, underline, (1, Applie dTextDecoration(TextDecorationUnderline, TextDecorationStyleSolid, visitedDepend entColor(CSSPropertyTextDecorationColor))));
1271 // Since we only have one of these in memory, just update the color befo re returning.
1272 underline.at(0).setColor(visitedDependentColor(CSSPropertyTextDecoration Color));
1266 return underline; 1273 return underline;
1267 } 1274 }
1268 1275
1269 return rareInheritedData->appliedTextDecorations->vector(); 1276 return rareInheritedData->appliedTextDecorations->vector();
1270 } 1277 }
1271 1278
1272 float ComputedStyle::wordSpacing() const { return fontDescription().wordSpacing( ); } 1279 float ComputedStyle::wordSpacing() const { return fontDescription().wordSpacing( ); }
1273 float ComputedStyle::letterSpacing() const { return fontDescription().letterSpac ing(); } 1280 float ComputedStyle::letterSpacing() const { return fontDescription().letterSpac ing(); }
1274 1281
1275 bool ComputedStyle::setFontDescription(const FontDescription& v) 1282 bool ComputedStyle::setFontDescription(const FontDescription& v)
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
1363 1370
1364 void ComputedStyle::addAppliedTextDecoration(const AppliedTextDecoration& decora tion) 1371 void ComputedStyle::addAppliedTextDecoration(const AppliedTextDecoration& decora tion)
1365 { 1372 {
1366 RefPtr<AppliedTextDecorationList>& list = rareInheritedData.access()->applie dTextDecorations; 1373 RefPtr<AppliedTextDecorationList>& list = rareInheritedData.access()->applie dTextDecorations;
1367 1374
1368 if (!list) 1375 if (!list)
1369 list = AppliedTextDecorationList::create(); 1376 list = AppliedTextDecorationList::create();
1370 else if (!list->hasOneRef()) 1377 else if (!list->hasOneRef())
1371 list = list->copy(); 1378 list = list->copy();
1372 1379
1373 if (inherited_flags.m_textUnderline) {
1374 inherited_flags.m_textUnderline = false;
1375 list->append(AppliedTextDecoration(TextDecorationUnderline));
1376 }
1377
1378 list->append(decoration); 1380 list->append(decoration);
1379 } 1381 }
1380 1382
1381 void ComputedStyle::applyTextDecorations() 1383 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
1382 { 1384 {
1385 RefPtr<AppliedTextDecorationList>& list = rareInheritedData.access()->applie dTextDecorations;
1386
1387 ASSERT(list);
1388 if (!list->hasOneRef())
1389 list = list->copy();
1390
1391 for (size_t i = 0; i < rareInheritedData->appliedTextDecorations->size(); ++ i)
1392 list->at(i).setColor(propagatedColor);
1393 }
1394
1395 void ComputedStyle::applyTextDecorations(const Color& parentTextDecorationColor, bool overrideExistingColors)
1396 {
1397 // 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!
1398 if (textDecoration() == TextDecorationNone && !inherited_flags.m_hasSimpleUn derline && !rareInheritedData->appliedTextDecorations)
1399 return;
1400
1401 // If there are any color changes or decorations set by this element, stop u sing m_hasSimpleUnderline.
1402 Color currentTextDecorationColor = visitedDependentColor(CSSPropertyTextDeco rationColor);
1403 if (inherited_flags.m_hasSimpleUnderline && (textDecoration() != TextDecorat ionNone || currentTextDecorationColor != parentTextDecorationColor)) {
1404 inherited_flags.m_hasSimpleUnderline = false;
1405 addAppliedTextDecoration(AppliedTextDecoration(TextDecorationUnderline, TextDecorationStyleSolid, parentTextDecorationColor));
1406 }
1407
1408 // 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!
1409 if (overrideExistingColors && rareInheritedData->appliedTextDecorations)
1410 updateAppliedTextDecorations(currentTextDecorationColor);
1411
1383 if (textDecoration() == TextDecorationNone) 1412 if (textDecoration() == TextDecorationNone)
1384 return; 1413 return;
1414 ASSERT(!inherited_flags.m_hasSimpleUnderline);
1385 1415
1386 TextDecorationStyle style = textDecorationStyle(); 1416 // To save memory, we don't use AppliedTextDecoration objects in the common case of a single simple underline.
1387 StyleColor styleColor = decorationColorIncludingFallback(insideLink() == Ins ideVisitedLink); 1417 TextDecoration decorationLines = textDecoration();
1418 TextDecorationStyle decorationStyle = textDecorationStyle();
1419 StyleColor decorationColor = decorationColorIncludingFallback(insideLink() = = InsideVisitedLink);
1420 bool isSimpleUnderline = decorationLines == TextDecorationUnderline && decor ationStyle == TextDecorationStyleSolid && decorationColor.isCurrentColor();
1421 if (!rareInheritedData->appliedTextDecorations && !inherited_flags.m_hasSimp leUnderline && isSimpleUnderline) {
1422 inherited_flags.m_hasSimpleUnderline = true;
1423 return;
1424 }
1388 1425
1389 int decorations = textDecoration(); 1426 Color resolvedDecorationColor = decorationColor.resolve(currentTextDecoratio nColor);
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.
1390 1427 addAppliedTextDecoration(AppliedTextDecoration(decorationLines, decorationSt yle, resolvedDecorationColor));
1391 if (decorations & TextDecorationUnderline) {
1392 // To save memory, we don't use AppliedTextDecoration objects in the
1393 // common case of a single simple underline.
1394 AppliedTextDecoration underline(TextDecorationUnderline, style, styleCol or);
1395
1396 if (!rareInheritedData->appliedTextDecorations && underline.isSimpleUnde rline())
1397 inherited_flags.m_textUnderline = true;
1398 else
1399 addAppliedTextDecoration(underline);
1400 }
1401 if (decorations & TextDecorationOverline)
1402 addAppliedTextDecoration(AppliedTextDecoration(TextDecorationOverline, s tyle, styleColor));
1403 if (decorations & TextDecorationLineThrough)
1404 addAppliedTextDecoration(AppliedTextDecoration(TextDecorationLineThrough , style, styleColor));
1405 } 1428 }
1406 1429
1407 void ComputedStyle::clearAppliedTextDecorations() 1430 void ComputedStyle::clearAppliedTextDecorations()
1408 { 1431 {
1409 inherited_flags.m_textUnderline = false; 1432 inherited_flags.m_hasSimpleUnderline = false;
1410 1433
1411 if (rareInheritedData->appliedTextDecorations) 1434 if (rareInheritedData->appliedTextDecorations)
1412 rareInheritedData.access()->appliedTextDecorations = nullptr; 1435 rareInheritedData.access()->appliedTextDecorations = nullptr;
1413 } 1436 }
1414 1437
1415 void ComputedStyle::clearMultiCol() 1438 void ComputedStyle::clearMultiCol()
1416 { 1439 {
1417 rareNonInheritedData.access()->m_multiCol = nullptr; 1440 rareNonInheritedData.access()->m_multiCol = nullptr;
1418 rareNonInheritedData.access()->m_multiCol.init(); 1441 rareNonInheritedData.access()->m_multiCol.init();
1419 } 1442 }
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after
1798 } 1821 }
1799 1822
1800 void ComputedStyle::copyChildDependentFlagsFrom(const ComputedStyle& other) 1823 void ComputedStyle::copyChildDependentFlagsFrom(const ComputedStyle& other)
1801 { 1824 {
1802 setEmptyState(other.emptyState()); 1825 setEmptyState(other.emptyState());
1803 if (other.hasExplicitlyInheritedProperties()) 1826 if (other.hasExplicitlyInheritedProperties())
1804 setHasExplicitlyInheritedProperties(); 1827 setHasExplicitlyInheritedProperties();
1805 } 1828 }
1806 1829
1807 } // namespace blink 1830 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698