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

Side by Side Diff: Source/core/rendering/InlineTextBox.cpp

Issue 16337002: Revert "Revert "Implement CSS3TextDecorations runtime flag in favor of CSS3_TEXT"" (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 7 years, 6 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
« no previous file with comments | « Source/core/platform/graphics/GraphicsTypes.h ('k') | Source/core/rendering/RenderObject.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * (C) 1999 Lars Knoll (knoll@kde.org) 2 * (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 2000 Dirk Mueller (mueller@kde.org) 3 * (C) 2000 Dirk Mueller (mueller@kde.org)
4 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All r ights reserved. 4 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All r ights 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 919 matching lines...) Expand 10 before | Expand all | Expand 10 after
930 context->drawHighlightForText(font, constructTextRun(style, font), localOrig in, selHeight, c, style->colorSpace(), sPos, ePos); 930 context->drawHighlightForText(font, constructTextRun(style, font), localOrig in, selHeight, c, style->colorSpace(), sPos, ePos);
931 } 931 }
932 932
933 static StrokeStyle textDecorationStyleToStrokeStyle(TextDecorationStyle decorati onStyle) 933 static StrokeStyle textDecorationStyleToStrokeStyle(TextDecorationStyle decorati onStyle)
934 { 934 {
935 StrokeStyle strokeStyle = SolidStroke; 935 StrokeStyle strokeStyle = SolidStroke;
936 switch (decorationStyle) { 936 switch (decorationStyle) {
937 case TextDecorationStyleSolid: 937 case TextDecorationStyleSolid:
938 strokeStyle = SolidStroke; 938 strokeStyle = SolidStroke;
939 break; 939 break;
940 #if ENABLE(CSS3_TEXT)
941 case TextDecorationStyleDouble: 940 case TextDecorationStyleDouble:
942 strokeStyle = DoubleStroke; 941 strokeStyle = DoubleStroke;
943 break; 942 break;
944 case TextDecorationStyleDotted: 943 case TextDecorationStyleDotted:
945 strokeStyle = DottedStroke; 944 strokeStyle = DottedStroke;
946 break; 945 break;
947 case TextDecorationStyleDashed: 946 case TextDecorationStyleDashed:
948 strokeStyle = DashedStroke; 947 strokeStyle = DashedStroke;
949 break; 948 break;
950 case TextDecorationStyleWavy: 949 case TextDecorationStyleWavy:
951 strokeStyle = WavyStroke; 950 strokeStyle = WavyStroke;
952 break; 951 break;
953 #endif // CSS3_TEXT
954 } 952 }
955 953
956 return strokeStyle; 954 return strokeStyle;
957 } 955 }
958 956
959 #if ENABLE(CSS3_TEXT) 957 #if ENABLE(CSS3_TEXT)
960 static int computeUnderlineOffset(const TextUnderlinePosition underlinePosition, const FontMetrics& fontMetrics, const InlineTextBox* inlineTextBox, const int t extDecorationThickness) 958 static int computeUnderlineOffset(const TextUnderlinePosition underlinePosition, const FontMetrics& fontMetrics, const InlineTextBox* inlineTextBox, const int t extDecorationThickness)
961 { 959 {
962 // Compute the gap between the font and the underline. Use at least one 960 // Compute the gap between the font and the underline. Use at least one
963 // pixel gap, if underline is thick then use a bigger gap. 961 // pixel gap, if underline is thick then use a bigger gap.
(...skipping 12 matching lines...) Expand all
976 return inlineTextBox->logicalHeight() + gap + offset; 974 return inlineTextBox->logicalHeight() + gap + offset;
977 return inlineTextBox->logicalHeight() + gap; 975 return inlineTextBox->logicalHeight() + gap;
978 } 976 }
979 } 977 }
980 978
981 ASSERT_NOT_REACHED(); 979 ASSERT_NOT_REACHED();
982 return fontMetrics.ascent() + gap; 980 return fontMetrics.ascent() + gap;
983 } 981 }
984 #endif // CSS3_TEXT 982 #endif // CSS3_TEXT
985 983
986 #if ENABLE(CSS3_TEXT)
987 static void adjustStepToDecorationLength(float& step, float& controlPointDistanc e, float length) 984 static void adjustStepToDecorationLength(float& step, float& controlPointDistanc e, float length)
988 { 985 {
989 ASSERT(step > 0); 986 ASSERT(step > 0);
990 987
991 if (length <= 0) 988 if (length <= 0)
992 return; 989 return;
993 990
994 unsigned stepCount = static_cast<unsigned>(length / step); 991 unsigned stepCount = static_cast<unsigned>(length / step);
995 992
996 // Each Bezier curve starts at the same pixel that the previous one 993 // Each Bezier curve starts at the same pixel that the previous one
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
1098 controlPoint1.setX(x + step); 1095 controlPoint1.setX(x + step);
1099 controlPoint2.setX(x + step); 1096 controlPoint2.setX(x + step);
1100 x += 2 * step; 1097 x += 2 * step;
1101 path.addBezierCurveTo(controlPoint1, controlPoint2, FloatPoint(x, yA xis)); 1098 path.addBezierCurveTo(controlPoint1, controlPoint2, FloatPoint(x, yA xis));
1102 } 1099 }
1103 } 1100 }
1104 1101
1105 context->setShouldAntialias(true); 1102 context->setShouldAntialias(true);
1106 context->strokePath(path); 1103 context->strokePath(path);
1107 } 1104 }
1108 #endif // CSS3_TEXT
1109 1105
1110 void InlineTextBox::paintDecoration(GraphicsContext* context, const FloatPoint& boxOrigin, TextDecoration deco, TextDecorationStyle decorationStyle, const Shado wData* shadow) 1106 void InlineTextBox::paintDecoration(GraphicsContext* context, const FloatPoint& boxOrigin, TextDecoration deco, TextDecorationStyle decorationStyle, const Shado wData* shadow)
1111 { 1107 {
1112 GraphicsContextStateSaver stateSaver(*context); 1108 GraphicsContextStateSaver stateSaver(*context);
1113 1109
1114 // FIXME: We should improve this rule and not always just assume 1. 1110 // FIXME: We should improve this rule and not always just assume 1.
1115 const float textDecorationThickness = 1.f; 1111 const float textDecorationThickness = 1.f;
1116 1112
1117 if (m_truncation == cFullTruncation) 1113 if (m_truncation == cFullTruncation)
1118 return; 1114 return;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1166 // The last set of lines paints normally inside the clip. 1162 // The last set of lines paints normally inside the clip.
1167 localOrigin.move(0, -extraOffset); 1163 localOrigin.move(0, -extraOffset);
1168 extraOffset = 0; 1164 extraOffset = 0;
1169 } 1165 }
1170 int shadowX = isHorizontal() ? shadow->x() : shadow->y(); 1166 int shadowX = isHorizontal() ? shadow->x() : shadow->y();
1171 int shadowY = isHorizontal() ? shadow->y() : -shadow->x(); 1167 int shadowY = isHorizontal() ? shadow->y() : -shadow->x();
1172 context->setShadow(FloatSize(shadowX, shadowY - extraOffset), shadow ->blur(), shadow->color()); 1168 context->setShadow(FloatSize(shadowX, shadowY - extraOffset), shadow ->blur(), shadow->color());
1173 shadow = shadow->next(); 1169 shadow = shadow->next();
1174 } 1170 }
1175 1171
1176 #if ENABLE(CSS3_TEXT)
1177 // Offset between lines - always non-zero, so lines never cross each oth er. 1172 // Offset between lines - always non-zero, so lines never cross each oth er.
1178 float doubleOffset = textDecorationThickness + 1.f; 1173 float doubleOffset = textDecorationThickness + 1.f;
1179 #endif // CSS3_TEXT
1180 context->setStrokeStyle(textDecorationStyleToStrokeStyle(decorationStyle )); 1174 context->setStrokeStyle(textDecorationStyleToStrokeStyle(decorationStyle ));
1181 if (deco & TextDecorationUnderline) { 1175 if (deco & TextDecorationUnderline) {
1182 context->setStrokeColor(underline, colorSpace); 1176 context->setStrokeColor(underline, colorSpace);
1183 #if ENABLE(CSS3_TEXT) 1177 #if ENABLE(CSS3_TEXT)
1184 TextUnderlinePosition underlinePosition = styleToUse->textUnderlineP osition(); 1178 TextUnderlinePosition underlinePosition = styleToUse->textUnderlineP osition();
1185 const int underlineOffset = computeUnderlineOffset(underlinePosition , styleToUse->fontMetrics(), this, textDecorationThickness); 1179 const int underlineOffset = computeUnderlineOffset(underlinePosition , styleToUse->fontMetrics(), this, textDecorationThickness);
1180 #else
1181 const int underlineOffset = styleToUse->fontMetrics().ascent() + max <int>(1, ceilf(textDecorationThickness / 2.0));
1182 #endif // CSS3_TEXT
1186 1183
1187 switch (decorationStyle) { 1184 switch (decorationStyle) {
1188 case TextDecorationStyleWavy: { 1185 case TextDecorationStyleWavy: {
1189 FloatPoint start(localOrigin.x(), localOrigin.y() + underlineOff set + doubleOffset); 1186 FloatPoint start(localOrigin.x(), localOrigin.y() + underlineOff set + doubleOffset);
1190 FloatPoint end(localOrigin.x() + width, localOrigin.y() + underl ineOffset + doubleOffset); 1187 FloatPoint end(localOrigin.x() + width, localOrigin.y() + underl ineOffset + doubleOffset);
1191 strokeWavyTextDecoration(context, start, end, textDecorationThic kness); 1188 strokeWavyTextDecoration(context, start, end, textDecorationThic kness);
1192 break; 1189 break;
1193 } 1190 }
1194 default: 1191 default:
1195 context->drawLineForText(FloatPoint(localOrigin.x(), localOrigin .y() + underlineOffset), width, isPrinting); 1192 context->drawLineForText(FloatPoint(localOrigin.x(), localOrigin .y() + underlineOffset), width, isPrinting);
1196 1193
1197 if (decorationStyle == TextDecorationStyleDouble) 1194 if (decorationStyle == TextDecorationStyleDouble)
1198 context->drawLineForText(FloatPoint(localOrigin.x(), localOr igin.y() + underlineOffset + doubleOffset), width, isPrinting); 1195 context->drawLineForText(FloatPoint(localOrigin.x(), localOr igin.y() + underlineOffset + doubleOffset), width, isPrinting);
1199 } 1196 }
1200 #else
1201 // Leave one pixel of white between the baseline and the underline.
1202 context->drawLineForText(FloatPoint(localOrigin.x(), localOrigin.y() + baseline + 1), width, isPrinting);
1203 #endif // CSS3_TEXT
1204 } 1197 }
1205 if (deco & TextDecorationOverline) { 1198 if (deco & TextDecorationOverline) {
1206 context->setStrokeColor(overline, colorSpace); 1199 context->setStrokeColor(overline, colorSpace);
1207 #if ENABLE(CSS3_TEXT)
1208 switch (decorationStyle) { 1200 switch (decorationStyle) {
1209 case TextDecorationStyleWavy: { 1201 case TextDecorationStyleWavy: {
1210 FloatPoint start(localOrigin.x(), localOrigin.y() - doubleOffset ); 1202 FloatPoint start(localOrigin.x(), localOrigin.y() - doubleOffset );
1211 FloatPoint end(localOrigin.x() + width, localOrigin.y() - double Offset); 1203 FloatPoint end(localOrigin.x() + width, localOrigin.y() - double Offset);
1212 strokeWavyTextDecoration(context, start, end, textDecorationThic kness); 1204 strokeWavyTextDecoration(context, start, end, textDecorationThic kness);
1213 break; 1205 break;
1214 } 1206 }
1215 default: 1207 default:
1216 #endif // CSS3_TEXT
1217 context->drawLineForText(localOrigin, width, isPrinting); 1208 context->drawLineForText(localOrigin, width, isPrinting);
1218 #if ENABLE(CSS3_TEXT)
1219 if (decorationStyle == TextDecorationStyleDouble) 1209 if (decorationStyle == TextDecorationStyleDouble)
1220 context->drawLineForText(FloatPoint(localOrigin.x(), localOr igin.y() - doubleOffset), width, isPrinting); 1210 context->drawLineForText(FloatPoint(localOrigin.x(), localOr igin.y() - doubleOffset), width, isPrinting);
1221 } 1211 }
1222 #endif // CSS3_TEXT
1223 } 1212 }
1224 if (deco & TextDecorationLineThrough) { 1213 if (deco & TextDecorationLineThrough) {
1225 context->setStrokeColor(linethrough, colorSpace); 1214 context->setStrokeColor(linethrough, colorSpace);
1226 #if ENABLE(CSS3_TEXT)
1227 switch (decorationStyle) { 1215 switch (decorationStyle) {
1228 case TextDecorationStyleWavy: { 1216 case TextDecorationStyleWavy: {
1229 FloatPoint start(localOrigin.x(), localOrigin.y() + 2 * baseline / 3); 1217 FloatPoint start(localOrigin.x(), localOrigin.y() + 2 * baseline / 3);
1230 FloatPoint end(localOrigin.x() + width, localOrigin.y() + 2 * ba seline / 3); 1218 FloatPoint end(localOrigin.x() + width, localOrigin.y() + 2 * ba seline / 3);
1231 strokeWavyTextDecoration(context, start, end, textDecorationThic kness); 1219 strokeWavyTextDecoration(context, start, end, textDecorationThic kness);
1232 break; 1220 break;
1233 } 1221 }
1234 default: 1222 default:
1235 #endif // CSS3_TEXT
1236 context->drawLineForText(FloatPoint(localOrigin.x(), localOrigin .y() + 2 * baseline / 3), width, isPrinting); 1223 context->drawLineForText(FloatPoint(localOrigin.x(), localOrigin .y() + 2 * baseline / 3), width, isPrinting);
1237 #if ENABLE(CSS3_TEXT)
1238 if (decorationStyle == TextDecorationStyleDouble) 1224 if (decorationStyle == TextDecorationStyleDouble)
1239 context->drawLineForText(FloatPoint(localOrigin.x(), localOr igin.y() + doubleOffset + 2 * baseline / 3), width, isPrinting); 1225 context->drawLineForText(FloatPoint(localOrigin.x(), localOr igin.y() + doubleOffset + 2 * baseline / 3), width, isPrinting);
1240 } 1226 }
1241 #endif // CSS3_TEXT
1242 } 1227 }
1243 } while (shadow); 1228 } while (shadow);
1244 } 1229 }
1245 1230
1246 static GraphicsContext::DocumentMarkerLineStyle lineStyleForMarkerType(DocumentM arker::MarkerType markerType) 1231 static GraphicsContext::DocumentMarkerLineStyle lineStyleForMarkerType(DocumentM arker::MarkerType markerType)
1247 { 1232 {
1248 switch (markerType) { 1233 switch (markerType) {
1249 case DocumentMarker::Spelling: 1234 case DocumentMarker::Spelling:
1250 return GraphicsContext::DocumentMarkerSpellingLineStyle; 1235 return GraphicsContext::DocumentMarkerSpellingLineStyle;
1251 case DocumentMarker::Grammar: 1236 case DocumentMarker::Grammar:
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
1606 1591
1607 void InlineTextBox::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const 1592 void InlineTextBox::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const
1608 { 1593 {
1609 MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::Rendering); 1594 MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::Rendering);
1610 InlineBox::reportMemoryUsage(memoryObjectInfo); 1595 InlineBox::reportMemoryUsage(memoryObjectInfo);
1611 info.addMember(m_prevTextBox, "prevTextBox"); 1596 info.addMember(m_prevTextBox, "prevTextBox");
1612 info.addMember(m_nextTextBox, "nextTextBox"); 1597 info.addMember(m_nextTextBox, "nextTextBox");
1613 } 1598 }
1614 1599
1615 } // namespace WebCore 1600 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/platform/graphics/GraphicsTypes.h ('k') | Source/core/rendering/RenderObject.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698