Changeset 256451 in webkit
- Timestamp:
- Feb 12, 2020 10:40:24 AM (4 years ago)
- Location:
- trunk
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r256450 r256451 1 2020-02-12 Megan Gardner <megan_gardner@apple.com> 2 3 Fix highlight text decorations to work with all decoration types and colors 4 https://bugs.webkit.org/show_bug.cgi?id=207601 5 6 Reviewed by Dean Jackson. 7 8 * http/wpt/css/css-highlight-api/highlight-text-decorations-expected.html: 9 * http/wpt/css/css-highlight-api/highlight-text-decorations.html: 10 1 11 2020-02-12 Per Arne Vollan <pvollan@apple.com> 2 12 -
trunk/LayoutTests/http/wpt/css/css-highlight-api/highlight-text-decorations-expected.html
r256360 r256451 8 8 .style1 { 9 9 text-decoration: underline; 10 text-decoration-color: red; 11 color: blue; 12 } 13 .style2 { 14 text-decoration: line-through; 15 text-decoration-color: violet; 16 text-decoration-style: double; 17 } 18 .style3 { 19 text-decoration: overline; 20 text-decoration-color: orange; 21 text-decoration-style: dotted; 10 22 } 11 23 /* FIXME: There is a discrepency for how the underlines are displayed at the end of the line, leading to a pixel different in this text. Find a real fix, but in the meantime, obscure the offending pixel <rdar://problem/59327965> https://bugs.webkit.org/show_bug.cgi?id=207512*/ 12 24 .obscurer1 { 13 25 position: absolute; 14 top: 35px;15 left: 100px;26 top: 25px; 27 left: 95px; 16 28 width: 10px; 17 29 height: 10px; … … 29 41 </head> 30 42 <body> 31 O<span class="style1">n</span>e t<span class="style 1">w</span>o th<span class="style1">ree</span>43 O<span class="style1">n</span>e t<span class="style2">w</span>o th<span class="style3">ree</span> 32 44 <div class='obscurer1'></div> 33 45 <div class='obscurer2'></div> -
trunk/LayoutTests/http/wpt/css/css-highlight-api/highlight-text-decorations.html
r256360 r256451 13 13 ::highlight(example-highlight1) { 14 14 text-decoration: underline; 15 text-decoration-color: red; 16 color: blue; 17 } 18 ::highlight(example-highlight2) { 19 text-decoration: line-through; 20 text-decoration-color: violet; 21 text-decoration-style: double; 22 } 23 ::highlight(example-highlight3) { 24 text-decoration: overline; 25 text-decoration-color: orange; 26 text-decoration-style: dotted; 15 27 } 16 28 /* FIXME: There is a discrepency for how the underlines are displayed at the end of the line, leading to a pixel different in this text. Find a real fix, but in the meantime, obscure the offending pixel https://bugs.webkit.org/show_bug.cgi?id=207512 <rdar://problem/59327965> */ 17 29 .obscurer1 { 18 30 position: absolute; 19 top: 35px;20 left: 100px;31 top: 25px; 32 left: 95px; 21 33 width: 10px; 22 34 height: 10px; … … 37 49 <div class='obscurer1'></div> 38 50 <div class='obscurer2'></div> 51 39 52 <script> 40 53 let textElement = document.getElementById('text1'); 41 54 let highlightRangeGroup1 = new HighlightRangeGroup(new StaticRange({startContainer: textElement.childNodes[0], startOffset: 1, endContainer: textElement.childNodes[0], endOffset: 2})); 42 highlightRangeGroup1.add(new StaticRange({startContainer: textElement.childNodes[0], startOffset: 5, endContainer: textElement.childNodes[0], endOffset: 6}));43 highlightRangeGroup1.add(new StaticRange({startContainer: textElement.childNodes[0], startOffset: 10, endContainer: textElement.childNodes[0], endOffset: 13}));55 let highlightRangeGroup2 = new HighlightRangeGroup(new StaticRange({startContainer: textElement.childNodes[0], startOffset: 5, endContainer: textElement.childNodes[0], endOffset: 6})); 56 let highlightRangeGroup3 = new HighlightRangeGroup(new StaticRange({startContainer: textElement.childNodes[0], startOffset: 10, endContainer: textElement.childNodes[0], endOffset: 13})); 44 57 45 58 CSS.highlights.set("example-highlight1", highlightRangeGroup1); 59 CSS.highlights.set("example-highlight2", highlightRangeGroup2); 60 CSS.highlights.set("example-highlight3", highlightRangeGroup3); 46 61 </script> 47 62 </body> -
trunk/Source/WebCore/ChangeLog
r256447 r256451 1 2020-02-12 Megan Gardner <megan_gardner@apple.com> 2 3 Fix highlight text decorations to work with all decoration types and colors 4 https://bugs.webkit.org/show_bug.cgi?id=207601 5 6 Reviewed by Dean Jackson. 7 8 MarkedText styles were incorrectly setting styles, and colors were being 9 calculated incorrectly. 10 11 Extended http/wpt/css/css-highlight-api/highlight-text-decorations.html. 12 13 * rendering/InlineTextBox.cpp: 14 (WebCore::InlineTextBox::resolveStyleForMarkedText): 15 Correctly pass information about text decorations to MarkedTexts styles. 16 17 * rendering/TextDecorationPainter.cpp: 18 (WebCore::collectStylesForRenderer): 19 (WebCore::TextDecorationPainter::decorationColor): 20 (WebCore::decorationColor): Deleted. 21 Expose decorationColor calculator for use in InlineTextBox. 22 * rendering/TextDecorationPainter.h: 23 1 24 2020-02-12 Chris Dumez <cdumez@apple.com> 2 25 -
trunk/Source/WebCore/rendering/InlineTextBox.cpp
r256360 r256451 827 827 style.textStyles.strokeColor = renderStyle->computedStrokeColor(); 828 828 829 auto color = renderStyle->visitedDependentColorWithColorFilter(CSSPropertyWebkitTextFillColor);829 auto color = TextDecorationPainter::decorationColor(*renderStyle.get()); 830 830 auto decorationStyle = renderStyle->textDecorationStyle(); 831 831 auto decorations = renderStyle->textDecorationsInEffect(); 832 832 833 if (decorations.contains Any({ TextDecoration::Underline, TextDecoration::Overline, TextDecoration::LineThrough })) {833 if (decorations.contains(TextDecoration::Underline)) { 834 834 style.textDecorationStyles.underlineColor = color; 835 835 style.textDecorationStyles.underlineStyle = decorationStyle; 836 } 837 if (decorations.contains(TextDecoration::Overline)) { 838 style.textDecorationStyles.overlineColor = color; 839 style.textDecorationStyles.overlineStyle = decorationStyle; 840 } 841 if (decorations.contains(TextDecoration::LineThrough)) { 842 style.textDecorationStyles.linethroughColor = color; 843 style.textDecorationStyles.linethroughStyle = decorationStyle; 836 844 } 837 845 } -
trunk/Source/WebCore/rendering/TextDecorationPainter.cpp
r256360 r256451 317 317 } 318 318 319 static Color decorationColor(const RenderStyle& style) 319 static void collectStylesForRenderer(TextDecorationPainter::Styles& result, const RenderObject& renderer, OptionSet<TextDecoration> remainingDecorations, bool firstLineStyle, PseudoId pseudoId) 320 { 321 auto extractDecorations = [&] (const RenderStyle& style, OptionSet<TextDecoration> decorations) { 322 auto color = TextDecorationPainter::decorationColor(style); 323 auto decorationStyle = style.textDecorationStyle(); 324 325 if (decorations.contains(TextDecoration::Underline)) { 326 remainingDecorations.remove(TextDecoration::Underline); 327 result.underlineColor = color; 328 result.underlineStyle = decorationStyle; 329 } 330 if (decorations.contains(TextDecoration::Overline)) { 331 remainingDecorations.remove(TextDecoration::Overline); 332 result.overlineColor = color; 333 result.overlineStyle = decorationStyle; 334 } 335 if (decorations.contains(TextDecoration::LineThrough)) { 336 remainingDecorations.remove(TextDecoration::LineThrough); 337 result.linethroughColor = color; 338 result.linethroughStyle = decorationStyle; 339 } 340 341 }; 342 343 auto styleForRenderer = [&] (const RenderObject& renderer) -> const RenderStyle& { 344 if (pseudoId != PseudoId::None && renderer.style().hasPseudoStyle(pseudoId)) { 345 if (is<RenderText>(renderer)) 346 return *downcast<RenderText>(renderer).getCachedPseudoStyle(pseudoId); 347 return *downcast<RenderElement>(renderer).getCachedPseudoStyle(pseudoId); 348 } 349 return firstLineStyle ? renderer.firstLineStyle() : renderer.style(); 350 }; 351 352 auto* current = &renderer; 353 do { 354 const auto& style = styleForRenderer(*current); 355 extractDecorations(style, style.textDecoration()); 356 357 if (current->isRubyText()) 358 return; 359 360 current = current->parent(); 361 if (current && current->isAnonymousBlock() && downcast<RenderBlock>(*current).continuation()) 362 current = downcast<RenderBlock>(*current).continuation(); 363 364 if (remainingDecorations.isEmpty()) 365 break; 366 367 } while (current && !is<HTMLAnchorElement>(current->node()) && !is<HTMLFontElement>(current->node())); 368 369 // If we bailed out, use the element we bailed out at (typically a <font> or <a> element). 370 if (!remainingDecorations.isEmpty() && current) 371 extractDecorations(styleForRenderer(*current), remainingDecorations); 372 } 373 374 Color TextDecorationPainter::decorationColor(const RenderStyle& style) 320 375 { 321 376 // Check for text decoration color first. 322 Colorresult = style.visitedDependentColorWithColorFilter(CSSPropertyTextDecorationColor);377 auto result = style.visitedDependentColorWithColorFilter(CSSPropertyTextDecorationColor); 323 378 if (result.isValid()) 324 379 return result; … … 331 386 332 387 return style.visitedDependentColorWithColorFilter(CSSPropertyWebkitTextFillColor); 333 }334 335 static void collectStylesForRenderer(TextDecorationPainter::Styles& result, const RenderObject& renderer, OptionSet<TextDecoration> remainingDecorations, bool firstLineStyle, PseudoId pseudoId)336 {337 auto extractDecorations = [&] (const RenderStyle& style, OptionSet<TextDecoration> decorations) {338 auto color = decorationColor(style);339 auto decorationStyle = style.textDecorationStyle();340 341 if (decorations.contains(TextDecoration::Underline)) {342 remainingDecorations.remove(TextDecoration::Underline);343 result.underlineColor = color;344 result.underlineStyle = decorationStyle;345 }346 if (decorations.contains(TextDecoration::Overline)) {347 remainingDecorations.remove(TextDecoration::Overline);348 result.overlineColor = color;349 result.overlineStyle = decorationStyle;350 }351 if (decorations.contains(TextDecoration::LineThrough)) {352 remainingDecorations.remove(TextDecoration::LineThrough);353 result.linethroughColor = color;354 result.linethroughStyle = decorationStyle;355 }356 357 };358 359 auto styleForRenderer = [&] (const RenderObject& renderer) -> const RenderStyle& {360 if (pseudoId != PseudoId::None && renderer.style().hasPseudoStyle(pseudoId)) {361 if (is<RenderText>(renderer))362 return *downcast<RenderText>(renderer).getCachedPseudoStyle(pseudoId);363 return *downcast<RenderElement>(renderer).getCachedPseudoStyle(pseudoId);364 }365 return firstLineStyle ? renderer.firstLineStyle() : renderer.style();366 };367 368 auto* current = &renderer;369 do {370 const auto& style = styleForRenderer(*current);371 extractDecorations(style, style.textDecoration());372 373 if (current->isRubyText())374 return;375 376 current = current->parent();377 if (current && current->isAnonymousBlock() && downcast<RenderBlock>(*current).continuation())378 current = downcast<RenderBlock>(*current).continuation();379 380 if (remainingDecorations.isEmpty())381 break;382 383 } while (current && !is<HTMLAnchorElement>(current->node()) && !is<HTMLFontElement>(current->node()));384 385 // If we bailed out, use the element we bailed out at (typically a <font> or <a> element).386 if (!remainingDecorations.isEmpty() && current)387 extractDecorations(styleForRenderer(*current), remainingDecorations);388 388 } 389 389 -
trunk/Source/WebCore/rendering/TextDecorationPainter.h
r256360 r256451 65 65 TextDecorationStyle linethroughStyle; 66 66 }; 67 static Color decorationColor(const RenderStyle&); 67 68 static OptionSet<TextDecoration> textDecorationsInEffectForStyle(const Styles&); 68 69 static Styles stylesForRenderer(const RenderObject&, OptionSet<TextDecoration> requestedDecorations, bool firstLineStyle = false, PseudoId = PseudoId::None);
Note: See TracChangeset
for help on using the changeset viewer.