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

Side by Side Diff: Source/core/rendering/style/RenderStyle.cpp

Issue 272443002: Store and propagate a list of applied text decorations. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 7 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
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 10 matching lines...) Expand all
21 */ 21 */
22 22
23 #include "config.h" 23 #include "config.h"
24 #include "core/rendering/style/RenderStyle.h" 24 #include "core/rendering/style/RenderStyle.h"
25 25
26 #include <algorithm> 26 #include <algorithm>
27 #include "RuntimeEnabledFeatures.h" 27 #include "RuntimeEnabledFeatures.h"
28 #include "core/css/resolver/StyleResolver.h" 28 #include "core/css/resolver/StyleResolver.h"
29 #include "core/rendering/RenderTheme.h" 29 #include "core/rendering/RenderTheme.h"
30 #include "core/rendering/TextAutosizer.h" 30 #include "core/rendering/TextAutosizer.h"
31 #include "core/rendering/style/AppliedTextDecoration.h"
31 #include "core/rendering/style/ContentData.h" 32 #include "core/rendering/style/ContentData.h"
32 #include "core/rendering/style/CursorList.h" 33 #include "core/rendering/style/CursorList.h"
33 #include "core/rendering/style/QuotesData.h" 34 #include "core/rendering/style/QuotesData.h"
34 #include "core/rendering/style/ShadowList.h" 35 #include "core/rendering/style/ShadowList.h"
35 #include "core/rendering/style/StyleImage.h" 36 #include "core/rendering/style/StyleImage.h"
36 #include "core/rendering/style/StyleInheritedData.h" 37 #include "core/rendering/style/StyleInheritedData.h"
37 #include "platform/LengthFunctions.h" 38 #include "platform/LengthFunctions.h"
38 #include "platform/fonts/Font.h" 39 #include "platform/fonts/Font.h"
39 #include "platform/fonts/FontSelector.h" 40 #include "platform/fonts/FontSelector.h"
40 #include "platform/geometry/FloatRoundedRect.h" 41 #include "platform/geometry/FloatRoundedRect.h"
(...skipping 640 matching lines...) Expand 10 before | Expand all | Expand 10 after
681 682
682 if (rareNonInheritedData->opacity != other.rareNonInheritedData->opacity ) 683 if (rareNonInheritedData->opacity != other.rareNonInheritedData->opacity )
683 changedContextSensitiveProperties |= ContextSensitivePropertyOpacity ; 684 changedContextSensitiveProperties |= ContextSensitivePropertyOpacity ;
684 685
685 if (rareNonInheritedData->m_filter != other.rareNonInheritedData->m_filt er) 686 if (rareNonInheritedData->m_filter != other.rareNonInheritedData->m_filt er)
686 changedContextSensitiveProperties |= ContextSensitivePropertyFilter; 687 changedContextSensitiveProperties |= ContextSensitivePropertyFilter;
687 } 688 }
688 689
689 if (!diff.needsRepaint()) { 690 if (!diff.needsRepaint()) {
690 if (inherited->color != other.inherited->color 691 if (inherited->color != other.inherited->color
691 || inherited_flags._text_decorations != other.inherited_flags._text_ decorations 692 || inherited_flags.m_textUnderline != other.inherited_flags.m_textUn derline
692 || visual->textDecoration != other.visual->textDecoration) { 693 || visual->textDecoration != other.visual->textDecoration) {
693 changedContextSensitiveProperties |= ContextSensitivePropertyTextOrC olor; 694 changedContextSensitiveProperties |= ContextSensitivePropertyTextOrC olor;
694 } else if (rareNonInheritedData.get() != other.rareNonInheritedData.get( )) { 695 } else if (rareNonInheritedData.get() != other.rareNonInheritedData.get( )) {
695 if (rareNonInheritedData->m_textDecorationStyle != other.rareNonInhe ritedData->m_textDecorationStyle 696 if (rareNonInheritedData->m_textDecorationStyle != other.rareNonInhe ritedData->m_textDecorationStyle
696 || rareNonInheritedData->m_textDecorationColor != other.rareNonI nheritedData->m_textDecorationColor) 697 || rareNonInheritedData->m_textDecorationColor != other.rareNonI nheritedData->m_textDecorationColor)
697 changedContextSensitiveProperties |= ContextSensitivePropertyTex tOrColor; 698 changedContextSensitiveProperties |= ContextSensitivePropertyTex tOrColor;
698 } else if (rareInheritedData.get() != other.rareInheritedData.get()) { 699 } else if (rareInheritedData.get() != other.rareInheritedData.get()) {
699 if (rareInheritedData->textFillColor() != other.rareInheritedData->t extFillColor() 700 if (rareInheritedData->textFillColor() != other.rareInheritedData->t extFillColor()
700 || rareInheritedData->textStrokeColor() != other.rareInheritedDa ta->textStrokeColor() 701 || rareInheritedData->textStrokeColor() != other.rareInheritedDa ta->textStrokeColor()
701 || rareInheritedData->textEmphasisColor() != other.rareInherited Data->textEmphasisColor() 702 || rareInheritedData->textEmphasisColor() != other.rareInherited Data->textEmphasisColor()
702 || rareInheritedData->textEmphasisFill != other.rareInheritedDat a->textEmphasisFill) 703 || rareInheritedData->textEmphasisFill != other.rareInheritedDat a->textEmphasisFill
704 || rareInheritedData->appliedTextDecorations != other.rareInheri tedData->appliedTextDecorations)
703 changedContextSensitiveProperties |= ContextSensitivePropertyTex tOrColor; 705 changedContextSensitiveProperties |= ContextSensitivePropertyTex tOrColor;
704 } 706 }
705 } 707 }
706 708
707 return changedContextSensitiveProperties; 709 return changedContextSensitiveProperties;
708 } 710 }
709 711
710 void RenderStyle::setClip(Length top, Length right, Length bottom, Length left) 712 void RenderStyle::setClip(Length top, Length right, Length bottom, Length left)
711 { 713 {
712 StyleVisualData* data = visual.access(); 714 StyleVisualData* data = visual.access();
(...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after
1197 } 1199 }
1198 1200
1199 const Font& RenderStyle::font() const { return inherited->font; } 1201 const Font& RenderStyle::font() const { return inherited->font; }
1200 const FontMetrics& RenderStyle::fontMetrics() const { return inherited->font.fon tMetrics(); } 1202 const FontMetrics& RenderStyle::fontMetrics() const { return inherited->font.fon tMetrics(); }
1201 const FontDescription& RenderStyle::fontDescription() const { return inherited-> font.fontDescription(); } 1203 const FontDescription& RenderStyle::fontDescription() const { return inherited-> font.fontDescription(); }
1202 float RenderStyle::specifiedFontSize() const { return fontDescription().specifie dSize(); } 1204 float RenderStyle::specifiedFontSize() const { return fontDescription().specifie dSize(); }
1203 float RenderStyle::computedFontSize() const { return fontDescription().computedS ize(); } 1205 float RenderStyle::computedFontSize() const { return fontDescription().computedS ize(); }
1204 int RenderStyle::fontSize() const { return fontDescription().computedPixelSize() ; } 1206 int RenderStyle::fontSize() const { return fontDescription().computedPixelSize() ; }
1205 FontWeight RenderStyle::fontWeight() const { return fontDescription().weight(); } 1207 FontWeight RenderStyle::fontWeight() const { return fontDescription().weight(); }
1206 1208
1209 TextDecoration RenderStyle::textDecorationsInEffect() const
1210 {
1211 int decorations = 0;
1212
1213 const Vector<AppliedTextDecoration>& applied = appliedTextDecorations();
1214
1215 for (size_t i = 0; i < applied.size(); ++i)
1216 decorations |= applied[i].line();
1217
1218 return static_cast<TextDecoration>(decorations);
1219 }
1220
1221 const Vector<AppliedTextDecoration>& RenderStyle::appliedTextDecorations() const
1222 {
1223 if (!inherited_flags.m_textUnderline && !rareInheritedData->appliedTextDecor ations) {
1224 DEFINE_STATIC_LOCAL(Vector<AppliedTextDecoration>, empty, ());
1225 return empty;
1226 }
Julien - ping for review 2014/05/06 23:29:30 I think we should just remove this artificial case
andersr 2014/05/07 11:17:53 We are not pretending that we have *a* text-decora
Julien - ping for review 2014/05/09 15:45:50 OK, I still think it's artificial and that we shou
1227 if (inherited_flags.m_textUnderline) {
1228 DEFINE_STATIC_LOCAL(Vector<AppliedTextDecoration>, underline, (1, Applie dTextDecoration(TextDecorationUnderline)));
1229 return underline;
1230 }
1231
1232 return rareInheritedData->appliedTextDecorations->vector();
1233 }
1234
1207 float RenderStyle::wordSpacing() const { return fontDescription().wordSpacing(); } 1235 float RenderStyle::wordSpacing() const { return fontDescription().wordSpacing(); }
1208 float RenderStyle::letterSpacing() const { return fontDescription().letterSpacin g(); } 1236 float RenderStyle::letterSpacing() const { return fontDescription().letterSpacin g(); }
1209 1237
1210 bool RenderStyle::setFontDescription(const FontDescription& v) 1238 bool RenderStyle::setFontDescription(const FontDescription& v)
1211 { 1239 {
1212 if (inherited->font.fontDescription() != v) { 1240 if (inherited->font.fontDescription() != v) {
1213 inherited.access()->font = Font(v); 1241 inherited.access()->font = Font(v);
1214 return true; 1242 return true;
1215 } 1243 }
1216 return false; 1244 return false;
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
1292 1320
1293 void RenderStyle::setFontWeight(FontWeight weight) 1321 void RenderStyle::setFontWeight(FontWeight weight)
1294 { 1322 {
1295 FontSelector* currentFontSelector = font().fontSelector(); 1323 FontSelector* currentFontSelector = font().fontSelector();
1296 FontDescription desc(fontDescription()); 1324 FontDescription desc(fontDescription());
1297 desc.setWeight(weight); 1325 desc.setWeight(weight);
1298 setFontDescription(desc); 1326 setFontDescription(desc);
1299 font().update(currentFontSelector); 1327 font().update(currentFontSelector);
1300 } 1328 }
1301 1329
1330 void RenderStyle::addAppliedTextDecoration(const AppliedTextDecoration& decorati on)
1331 {
1332 bool isSimpleUnderline = decoration.isSimple() && decoration.line() == TextD ecorationUnderline;
1333
1334 if (!rareInheritedData->appliedTextDecorations && isSimpleUnderline) {
1335 // To save memory, we don't use AppliedTextDecoration objects in the
1336 // common case of a single solid underline with the current color. Inste ad,
1337 // we set a bit to indicate that a solid underline must be drawn with th e
1338 // current color.
1339 inherited_flags.m_textUnderline = true;
1340 return;
1341 }
Julien - ping for review 2014/05/06 23:29:30 I still think this should be moved into the caller
andersr 2014/05/07 11:17:53 OK. In that case RenderStyle::addAppliedTextDecora
1342
1343 RefPtr<AppliedTextDecorationList>& list = rareInheritedData.access()->applie dTextDecorations;
1344
1345 if (!list)
1346 list = AppliedTextDecorationList::create();
1347 else if (!list->hasOneRef())
1348 list = list->copy();
Julien - ping for review 2014/05/06 23:29:30 I don't understand how you are saying that we can
andersr 2014/05/07 11:17:53 The worst case is not *an* applied text decoration
Julien - ping for review 2014/05/09 15:45:50 For people following at home, it turns out that we
1349
1350 if (inherited_flags.m_textUnderline) {
1351 inherited_flags.m_textUnderline = false;
1352 list->append(AppliedTextDecoration(TextDecorationUnderline, TextDecorati onStyleSolid, StyleColor::currentColor()));
1353 }
1354
1355 list->append(decoration);
1356 }
1357
1358 void RenderStyle::applyTextDecorations()
1359 {
1360 if (textDecoration() == TextDecorationNone)
1361 return;
1362
1363 TextDecorationStyle style = textDecorationStyle();
1364 StyleColor styleColor = visitedDependentDecorationStyleColor();
1365
1366 int decorations = textDecoration();
1367
1368 if (decorations & TextDecorationUnderline)
1369 addAppliedTextDecoration(AppliedTextDecoration(TextDecorationUnderline, style, styleColor));
1370 if (decorations & TextDecorationOverline)
1371 addAppliedTextDecoration(AppliedTextDecoration(TextDecorationOverline, s tyle, styleColor));
1372 if (decorations & TextDecorationLineThrough)
1373 addAppliedTextDecoration(AppliedTextDecoration(TextDecorationLineThrough , style, styleColor));
1374 }
1375
1376 void RenderStyle::clearAppliedTextDecorations()
1377 {
1378 inherited_flags.m_textUnderline = false;
1379
1380 if (rareInheritedData->appliedTextDecorations)
1381 rareInheritedData.access()->appliedTextDecorations = nullptr;
1382 }
1383
1302 void RenderStyle::getShadowExtent(const ShadowList* shadowList, LayoutUnit &top, LayoutUnit &right, LayoutUnit &bottom, LayoutUnit &left) const 1384 void RenderStyle::getShadowExtent(const ShadowList* shadowList, LayoutUnit &top, LayoutUnit &right, LayoutUnit &bottom, LayoutUnit &left) const
1303 { 1385 {
1304 top = 0; 1386 top = 0;
1305 right = 0; 1387 right = 0;
1306 bottom = 0; 1388 bottom = 0;
1307 left = 0; 1389 left = 0;
1308 1390
1309 size_t shadowCount = shadowList ? shadowList->shadows().size() : 0; 1391 size_t shadowCount = shadowList ? shadowList->shadows().size() : 0;
1310 for (size_t i = 0; i < shadowCount; ++i) { 1392 for (size_t i = 0; i < shadowCount; ++i) {
1311 const ShadowData& shadow = shadowList->shadows()[i]; 1393 const ShadowData& shadow = shadowList->shadows()[i];
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
1369 const ShadowData& shadow = shadowList->shadows()[i]; 1451 const ShadowData& shadow = shadowList->shadows()[i];
1370 if (shadow.style() == Inset) 1452 if (shadow.style() == Inset)
1371 continue; 1453 continue;
1372 float blurAndSpread = shadow.blur() + shadow.spread(); 1454 float blurAndSpread = shadow.blur() + shadow.spread();
1373 1455
1374 top = min<LayoutUnit>(top, shadow.y() - blurAndSpread); 1456 top = min<LayoutUnit>(top, shadow.y() - blurAndSpread);
1375 bottom = max<LayoutUnit>(bottom, shadow.y() + blurAndSpread); 1457 bottom = max<LayoutUnit>(bottom, shadow.y() + blurAndSpread);
1376 } 1458 }
1377 } 1459 }
1378 1460
1379 StyleColor RenderStyle::visitedDependentDecorationColor() const 1461 StyleColor RenderStyle::visitedDependentDecorationStyleColor() const
1380 { 1462 {
1381 // Text decoration color fallback is handled in RenderObject::decorationColo r. 1463 bool visitedLink = insideLink() == InsideVisitedLink;
Julien - ping for review 2014/05/06 23:29:30 Based on this comment, I think this part of the ch
andersr 2014/05/07 11:17:53 This is necessary for resolving the style recalcul
Julien - ping for review 2014/05/06 23:29:30 Coding style: Name-5. Precede boolean values with
andersr 2014/05/07 11:17:53 OK.
1382 return insideLink() == InsideVisitedLink ? visitedLinkTextDecorationColor() : textDecorationColor(); 1464
1465 StyleColor styleColor = visitedLink ? visitedLinkTextDecorationColor() : tex tDecorationColor();
1466
1467 if (!styleColor.isCurrentColor())
1468 return styleColor;
1469
1470 if (textStrokeWidth()) {
1471 // Prefer stroke color if possible but not if it's fully transparent.
1472 StyleColor textStrokeStyleColor = visitedLink ? visitedLinkTextStrokeCol or() : textStrokeColor();
1473 if (!textStrokeStyleColor.isCurrentColor() && textStrokeStyleColor.color ().alpha())
1474 return textStrokeStyleColor;
1475 }
1476
1477 return visitedLink ? visitedLinkTextFillColor() : textFillColor();
1478 }
1479
1480 Color RenderStyle::visitedDependentDecorationColor() const
1481 {
1482 bool visitedLink = insideLink() == InsideVisitedLink;
1483 return visitedDependentDecorationStyleColor().resolve(visitedLink ? visitedL inkColor() : color());
1383 } 1484 }
1384 1485
1385 Color RenderStyle::colorIncludingFallback(int colorProperty, bool visitedLink) c onst 1486 Color RenderStyle::colorIncludingFallback(int colorProperty, bool visitedLink) c onst
1386 { 1487 {
1387 StyleColor result(StyleColor::currentColor()); 1488 StyleColor result(StyleColor::currentColor());
1388 EBorderStyle borderStyle = BNONE; 1489 EBorderStyle borderStyle = BNONE;
1389 switch (colorProperty) { 1490 switch (colorProperty) {
1390 case CSSPropertyBackgroundColor: 1491 case CSSPropertyBackgroundColor:
1391 result = visitedLink ? visitedLinkBackgroundColor() : backgroundColor(); 1492 result = visitedLink ? visitedLinkBackgroundColor() : backgroundColor();
1392 break; 1493 break;
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
1672 // right 1773 // right
1673 radiiSum = radii.topRight().height() + radii.bottomRight().height(); 1774 radiiSum = radii.topRight().height() + radii.bottomRight().height();
1674 if (radiiSum > rect.height()) 1775 if (radiiSum > rect.height())
1675 factor = std::min(rect.height() / radiiSum, factor); 1776 factor = std::min(rect.height() / radiiSum, factor);
1676 1777
1677 ASSERT(factor <= 1); 1778 ASSERT(factor <= 1);
1678 return factor; 1779 return factor;
1679 } 1780 }
1680 1781
1681 } // namespace WebCore 1782 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698