Changeset 233814 in webkit
- Timestamp:
- Jul 13, 2018, 1:34:24 PM (8 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 19 edited
-
ChangeLog (modified) (1 diff)
-
platform/graphics/GraphicsContext.h (modified) (2 diffs)
-
platform/graphics/GraphicsContextImpl.h (modified) (1 diff)
-
platform/graphics/cairo/CairoOperations.cpp (modified) (2 diffs)
-
platform/graphics/cairo/CairoOperations.h (modified) (1 diff)
-
platform/graphics/cairo/GraphicsContextImplCairo.cpp (modified) (1 diff)
-
platform/graphics/cairo/GraphicsContextImplCairo.h (modified) (1 diff)
-
platform/graphics/cocoa/GraphicsContextCocoa.mm (modified) (4 diffs)
-
platform/graphics/displaylists/DisplayListItems.h (modified) (3 diffs)
-
platform/graphics/displaylists/DisplayListRecorder.cpp (modified) (1 diff)
-
platform/graphics/displaylists/DisplayListRecorder.h (modified) (1 diff)
-
platform/graphics/nicosia/cairo/NicosiaCairoOperationRecorder.cpp (modified) (1 diff)
-
platform/graphics/nicosia/cairo/NicosiaCairoOperationRecorder.h (modified) (1 diff)
-
platform/graphics/win/GraphicsContextCGWin.cpp (modified) (2 diffs)
-
rendering/InlineTextBox.cpp (modified) (2 diffs)
-
rendering/RenderTheme.cpp (modified) (1 diff)
-
rendering/RenderTheme.h (modified) (2 diffs)
-
rendering/RenderThemeMac.h (modified) (1 diff)
-
rendering/RenderThemeMac.mm (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r233805 r233814 1 2018-07-13 Antoine Quint <graouts@apple.com> 2 3 Dark Mode: document markers are difficult to see 4 https://bugs.webkit.org/show_bug.cgi?id=187632 5 <rdar://problem/41099719> 6 7 Reviewed by Simon Fraser. 8 9 We update the way we draw the document markers for macOS and use more constrasting colors in dark mode. 10 Paving the way for future improvements, we move the drawLineForDocumentMarker() method from GraphicsContext 11 to RenderTheme and implement a first version in RenderThemeMac. The circles used for the underline are now 12 drawn directly with Core Graphics and we no longer use an image resource. To allow both GraphicsContext 13 and RenderTheme to have different versions of the drawLineForDocumentMarker() method, the DocumentMarkerLineStyle 14 enum is now an "enum class". 15 16 No new test due to webkit.org/b/105616, webkit.org/b/187655 was raised to track the creation of new tests 17 when it becomes possible again. 18 19 * platform/graphics/GraphicsContext.h: 20 * platform/graphics/GraphicsContextImpl.h: 21 * platform/graphics/cairo/CairoOperations.cpp: 22 (WebCore::Cairo::drawLineForDocumentMarker): 23 * platform/graphics/cairo/CairoOperations.h: 24 * platform/graphics/cairo/GraphicsContextImplCairo.cpp: 25 (WebCore::GraphicsContextImplCairo::drawLineForDocumentMarker): 26 * platform/graphics/cairo/GraphicsContextImplCairo.h: 27 * platform/graphics/cocoa/GraphicsContextCocoa.mm: 28 (WebCore::GraphicsContext::drawLineForDocumentMarker): 29 * platform/graphics/displaylists/DisplayListItems.h: 30 (WebCore::DisplayList::DrawLineForDocumentMarker::create): 31 (WebCore::DisplayList::DrawLineForDocumentMarker::DrawLineForDocumentMarker): 32 * platform/graphics/displaylists/DisplayListRecorder.cpp: 33 (WebCore::DisplayList::Recorder::drawLineForDocumentMarker): 34 * platform/graphics/displaylists/DisplayListRecorder.h: 35 * platform/graphics/nicosia/cairo/NicosiaCairoOperationRecorder.cpp: 36 (Nicosia::CairoOperationRecorder::drawLineForDocumentMarker): 37 * platform/graphics/nicosia/cairo/NicosiaCairoOperationRecorder.h: 38 * platform/graphics/win/GraphicsContextCGWin.cpp: 39 (WebCore::GraphicsContext::drawLineForDocumentMarker): 40 * rendering/InlineTextBox.cpp: 41 (WebCore::InlineTextBox::paintPlatformDocumentMarker): Call drawLineForDocumentMarker() on the RenderTheme on 42 macOS and on GraphicsContext in all other cases. 43 * rendering/RenderTheme.cpp: 44 (WebCore::RenderTheme::drawLineForDocumentMarker): 45 * rendering/RenderTheme.h: 46 * rendering/RenderThemeMac.h: 47 * rendering/RenderThemeMac.mm: 48 (WebCore::colorForStyle): Provide different colors for light and dark modes. 49 (WebCore::RenderThemeMac::drawLineForDocumentMarker): A new macOS-specific version of drawLineForDocumentMarker() 50 where we paint circles using Core Graphics directly. 51 1 52 2018-07-13 Charlie Turner <cturner@igalia.com> 2 53 -
trunk/Source/WebCore/platform/graphics/GraphicsContext.h
r233315 r233814 110 110 }; 111 111 112 enum class DocumentMarkerLineStyle : uint8_t { 113 TextCheckingDictationPhraseWithAlternatives, 114 Spelling, 115 Grammar, 116 AutocorrectionReplacement, 117 DictationAlternatives 118 }; 119 112 120 namespace DisplayList { 113 121 class Recorder; … … 412 420 WEBCORE_EXPORT void drawLineForText(const FloatPoint&, float width, bool printing, bool doubleLines = false, StrokeStyle = SolidStroke); 413 421 void drawLinesForText(const FloatPoint&, const DashArray& widths, bool printing, bool doubleLines = false, StrokeStyle = SolidStroke); 414 enum DocumentMarkerLineStyle {415 #if PLATFORM(IOS)416 TextCheckingDictationPhraseWithAlternativesLineStyle,417 #endif418 DocumentMarkerSpellingLineStyle,419 DocumentMarkerGrammarLineStyle,420 DocumentMarkerAutocorrectionReplacementLineStyle,421 DocumentMarkerDictationAlternativesLineStyle422 };423 422 static void updateDocumentMarkerResources(); 424 423 void drawLineForDocumentMarker(const FloatPoint&, float width, DocumentMarkerLineStyle); -
trunk/Source/WebCore/platform/graphics/GraphicsContextImpl.h
r233078 r233814 80 80 virtual void drawLine(const FloatPoint&, const FloatPoint&) = 0; 81 81 virtual void drawLinesForText(const FloatPoint&, const DashArray& widths, bool printing, bool doubleLines, float strokeThickness) = 0; 82 virtual void drawLineForDocumentMarker(const FloatPoint&, float width, GraphicsContext::DocumentMarkerLineStyle) = 0;82 virtual void drawLineForDocumentMarker(const FloatPoint&, float width, DocumentMarkerLineStyle) = 0; 83 83 virtual void drawEllipse(const FloatRect&) = 0; 84 84 virtual void drawPath(const Path&) = 0; -
trunk/Source/WebCore/platform/graphics/cairo/CairoOperations.cpp
r233556 r233814 1050 1050 } 1051 1051 1052 void drawLineForDocumentMarker(PlatformContextCairo& platformContext, const FloatPoint& origin, float width, GraphicsContext::DocumentMarkerLineStyle style)1053 { 1054 if (style != GraphicsContext::DocumentMarkerSpellingLineStyle1055 && style != GraphicsContext::DocumentMarkerGrammarLineStyle)1052 void drawLineForDocumentMarker(PlatformContextCairo& platformContext, const FloatPoint& origin, float width, DocumentMarkerLineStyle style) 1053 { 1054 if (style != DocumentMarkerLineStyle::Spelling 1055 && style != DocumentMarkerLineStyle::Grammar) 1056 1056 return; 1057 1057 … … 1059 1059 cairo_save(cr); 1060 1060 1061 if (style == GraphicsContext::DocumentMarkerSpellingLineStyle)1061 if (style == DocumentMarkerLineStyle::Spelling) 1062 1062 cairo_set_source_rgb(cr, 1, 0, 0); 1063 else if (style == GraphicsContext::DocumentMarkerGrammarLineStyle)1063 else if (style == DocumentMarkerLineStyle::Grammar) 1064 1064 cairo_set_source_rgb(cr, 0, 1, 0); 1065 1065 -
trunk/Source/WebCore/platform/graphics/cairo/CairoOperations.h
r232246 r233814 146 146 void drawLine(PlatformContextCairo&, const FloatPoint&, const FloatPoint&, StrokeStyle, const Color&, float, bool); 147 147 void drawLinesForText(PlatformContextCairo&, const FloatPoint&, const DashArray&, bool, bool, const Color&, float); 148 void drawLineForDocumentMarker(PlatformContextCairo&, const FloatPoint&, float, GraphicsContext::DocumentMarkerLineStyle);148 void drawLineForDocumentMarker(PlatformContextCairo&, const FloatPoint&, float, DocumentMarkerLineStyle); 149 149 void drawEllipse(PlatformContextCairo&, const FloatRect&, const Color&, StrokeStyle, const Color&, float); 150 150 -
trunk/Source/WebCore/platform/graphics/cairo/GraphicsContextImplCairo.cpp
r233078 r233814 302 302 } 303 303 304 void GraphicsContextImplCairo::drawLineForDocumentMarker(const FloatPoint& origin, float width, GraphicsContext::DocumentMarkerLineStyle style)304 void GraphicsContextImplCairo::drawLineForDocumentMarker(const FloatPoint& origin, float width, DocumentMarkerLineStyle style) 305 305 { 306 306 Cairo::drawLineForDocumentMarker(m_platformContext, origin, width, style); -
trunk/Source/WebCore/platform/graphics/cairo/GraphicsContextImplCairo.h
r233078 r233814 81 81 void drawLine(const FloatPoint&, const FloatPoint&) override; 82 82 void drawLinesForText(const FloatPoint&, const DashArray&, bool, bool, float) override; 83 void drawLineForDocumentMarker(const FloatPoint&, float, GraphicsContext::DocumentMarkerLineStyle) override;83 void drawLineForDocumentMarker(const FloatPoint&, float, DocumentMarkerLineStyle) override; 84 84 void drawEllipse(const FloatRect&) override; 85 85 void drawPath(const Path&) override; -
trunk/Source/WebCore/platform/graphics/cocoa/GraphicsContextCocoa.mm
r233315 r233814 246 246 #endif 247 247 switch (style) { 248 case DocumentMarker SpellingLineStyle: {248 case DocumentMarkerLineStyle::Spelling: { 249 249 // Constants for spelling pattern color. 250 250 static bool usingDotForSpelling = false; … … 261 261 break; 262 262 } 263 case DocumentMarker GrammarLineStyle: {263 case DocumentMarkerLineStyle::Grammar: { 264 264 #if !PLATFORM(IOS) 265 265 // Constants for grammar pattern color. … … 278 278 #if PLATFORM(MAC) 279 279 // To support correction panel. 280 case DocumentMarker AutocorrectionReplacementLineStyle:281 case DocumentMarker DictationAlternativesLineStyle: {280 case DocumentMarkerLineStyle::AutocorrectionReplacement: 281 case DocumentMarkerLineStyle::DictationAlternatives: { 282 282 // Constants for spelling pattern color. 283 283 static bool usingDotForSpelling = false; … … 291 291 #endif 292 292 #if PLATFORM(IOS) 293 case TextCheckingDictationPhraseWithAlternativesLineStyle: {293 case DocumentMarkerLineStyle::TextCheckingDictationPhraseWithAlternatives: { 294 294 static bool usingDotForDictationPhraseWithAlternatives = false; 295 295 static CGPatternRef dictationPhraseWithAlternativesPattern = createDotPattern(usingDotForDictationPhraseWithAlternatives, "DictationPhraseWithAlternativesDot").leakRef(); -
trunk/Source/WebCore/platform/graphics/displaylists/DisplayListItems.h
r224312 r233814 831 831 class DrawLineForDocumentMarker : public DrawingItem { 832 832 public: 833 static Ref<DrawLineForDocumentMarker> create(const FloatPoint& point, float width, GraphicsContext::DocumentMarkerLineStyle style)833 static Ref<DrawLineForDocumentMarker> create(const FloatPoint& point, float width, DocumentMarkerLineStyle style) 834 834 { 835 835 return adoptRef(*new DrawLineForDocumentMarker(point, width, style)); … … 840 840 841 841 private: 842 DrawLineForDocumentMarker(const FloatPoint& point, float width, GraphicsContext::DocumentMarkerLineStyle style)842 DrawLineForDocumentMarker(const FloatPoint& point, float width, DocumentMarkerLineStyle style) 843 843 : DrawingItem(ItemType::DrawLineForDocumentMarker) 844 844 , m_point(point) … … 854 854 FloatPoint m_point; 855 855 float m_width; 856 GraphicsContext::DocumentMarkerLineStyle m_style;856 DocumentMarkerLineStyle m_style; 857 857 }; 858 858 -
trunk/Source/WebCore/platform/graphics/displaylists/DisplayListRecorder.cpp
r233078 r233814 237 237 } 238 238 239 void Recorder::drawLineForDocumentMarker(const FloatPoint& point, float width, GraphicsContext::DocumentMarkerLineStyle style)239 void Recorder::drawLineForDocumentMarker(const FloatPoint& point, float width, DocumentMarkerLineStyle style) 240 240 { 241 241 DrawingItem& newItem = downcast<DrawingItem>(appendItem(DrawLineForDocumentMarker::create(point, width, style))); -
trunk/Source/WebCore/platform/graphics/displaylists/DisplayListRecorder.h
r233078 r233814 99 99 void drawLine(const FloatPoint&, const FloatPoint&) override; 100 100 void drawLinesForText(const FloatPoint&, const DashArray& widths, bool printing, bool doubleLines, float strokeThickness) override; 101 void drawLineForDocumentMarker(const FloatPoint&, float width, GraphicsContext::DocumentMarkerLineStyle) override;101 void drawLineForDocumentMarker(const FloatPoint&, float width, DocumentMarkerLineStyle) override; 102 102 void drawEllipse(const FloatRect&) override; 103 103 void drawPath(const Path&) override; -
trunk/Source/WebCore/platform/graphics/nicosia/cairo/NicosiaCairoOperationRecorder.cpp
r233078 r233814 653 653 } 654 654 655 void CairoOperationRecorder::drawLineForDocumentMarker(const FloatPoint& origin, float width, GraphicsContext::DocumentMarkerLineStyle style)656 { 657 struct DrawLineForDocumentMarker final : PaintingOperation, OperationData<FloatPoint, float, GraphicsContext::DocumentMarkerLineStyle> {655 void CairoOperationRecorder::drawLineForDocumentMarker(const FloatPoint& origin, float width, DocumentMarkerLineStyle style) 656 { 657 struct DrawLineForDocumentMarker final : PaintingOperation, OperationData<FloatPoint, float, DocumentMarkerLineStyle> { 658 658 virtual ~DrawLineForDocumentMarker() = default; 659 659 -
trunk/Source/WebCore/platform/graphics/nicosia/cairo/NicosiaCairoOperationRecorder.h
r233078 r233814 74 74 void drawLine(const WebCore::FloatPoint&, const WebCore::FloatPoint&) override; 75 75 void drawLinesForText(const WebCore::FloatPoint&, const DashArray&, bool, bool, float) override; 76 void drawLineForDocumentMarker(const WebCore::FloatPoint&, float, WebCore:: GraphicsContext::DocumentMarkerLineStyle) override;76 void drawLineForDocumentMarker(const WebCore::FloatPoint&, float, WebCore::DocumentMarkerLineStyle) override; 77 77 void drawEllipse(const WebCore::FloatRect&) override; 78 78 void drawPath(const WebCore::Path&) override; -
trunk/Source/WebCore/platform/graphics/win/GraphicsContextCGWin.cpp
r227988 r233814 196 196 return; 197 197 198 if (style != DocumentMarker SpellingLineStyle && style != DocumentMarkerGrammarLineStyle)198 if (style != DocumentMarkerLineStyle::Spelling && style != DocumentMarkerLineStyle::Grammar) 199 199 return; 200 200 … … 219 219 CGContextSaveGState(context); 220 220 221 const Color& patternColor = style == DocumentMarker GrammarLineStyle? grammarPatternColor() : spellingPatternColor();221 const Color& patternColor = style == DocumentMarkerLineStyle::Grammar ? grammarPatternColor() : spellingPatternColor(); 222 222 setCGStrokeColor(context, patternColor); 223 223 -
trunk/Source/WebCore/rendering/InlineTextBox.cpp
r233704 r233814 690 690 switch (type) { 691 691 case MarkedText::SpellingError: 692 return GraphicsContext::DocumentMarkerSpellingLineStyle;692 return DocumentMarkerLineStyle::Spelling; 693 693 case MarkedText::GrammarError: 694 return GraphicsContext::DocumentMarkerGrammarLineStyle;694 return DocumentMarkerLineStyle::Grammar; 695 695 case MarkedText::Correction: 696 return GraphicsContext::DocumentMarkerAutocorrectionReplacementLineStyle;696 return DocumentMarkerLineStyle::AutocorrectionReplacement; 697 697 case MarkedText::DictationAlternatives: 698 return GraphicsContext::DocumentMarkerDictationAlternativesLineStyle;698 return DocumentMarkerLineStyle::DictationAlternatives; 699 699 #if PLATFORM(IOS) 700 700 case MarkedText::DictationPhraseWithAlternatives: 701 // FIXME: Rename TextCheckingDictationPhraseWithAlternativesLineStyleand remove the PLATFORM(IOS)-guard.702 return GraphicsContext::TextCheckingDictationPhraseWithAlternativesLineStyle;701 // FIXME: Rename DocumentMarkerLineStyle::TextCheckingDictationPhraseWithAlternatives and remove the PLATFORM(IOS)-guard. 702 return DocumentMarkerLineStyle::TextCheckingDictationPhraseWithAlternatives; 703 703 #endif 704 704 default: 705 705 ASSERT_NOT_REACHED(); 706 return GraphicsContext::DocumentMarkerSpellingLineStyle;706 return DocumentMarkerLineStyle::Spelling; 707 707 } 708 708 }; … … 725 725 underlineOffset = baseline + 2; 726 726 } 727 728 #if PLATFORM(MAC) 729 RenderTheme::singleton().drawLineForDocumentMarker(renderer(), context, FloatPoint(boxOrigin.x() + start, boxOrigin.y() + underlineOffset), width, lineStyleForMarkedTextType(markedText.type)); 730 #else 727 731 context.drawLineForDocumentMarker(FloatPoint(boxOrigin.x() + start, boxOrigin.y() + underlineOffset), width, lineStyleForMarkedTextType(markedText.type)); 732 #endif 728 733 } 729 734 -
trunk/Source/WebCore/rendering/RenderTheme.cpp
r233552 r233814 1413 1413 #endif 1414 1414 1415 void RenderTheme::drawLineForDocumentMarker(const RenderText&, GraphicsContext&, const FloatPoint&, float, DocumentMarkerLineStyle) 1416 { 1417 } 1418 1415 1419 } // namespace WebCore -
trunk/Source/WebCore/rendering/RenderTheme.h
r233670 r233814 23 23 #include "ColorHash.h" 24 24 #include "ControlStates.h" 25 #include "GraphicsContext.h" 25 26 #include "PaintInfo.h" 26 27 #include "PopupMenuStyle.h" … … 252 253 virtual void paintSystemPreviewBadge(Image&, const PaintInfo&, const FloatRect&); 253 254 #endif 255 256 virtual void drawLineForDocumentMarker(const RenderText&, GraphicsContext&, const FloatPoint& origin, float width, DocumentMarkerLineStyle); 254 257 255 258 protected: -
trunk/Source/WebCore/rendering/RenderThemeMac.h
r233532 r233814 169 169 #endif 170 170 171 void drawLineForDocumentMarker(const RenderText&, GraphicsContext&, const FloatPoint& origin, float width, DocumentMarkerLineStyle) final; 172 171 173 private: 172 174 String fileListNameForWidth(const FileList*, const FontCascade&, int width, bool multipleFilesAllowed) const final; -
trunk/Source/WebCore/rendering/RenderThemeMac.mm
r233670 r233814 26 26 #import "CSSValueKeywords.h" 27 27 #import "CSSValueList.h" 28 #import "Color.h" 28 29 #import "ColorMac.h" 29 30 #import "Document.h" … … 36 37 #import "FrameView.h" 37 38 #import "GeometryUtilities.h" 39 #import "GraphicsContext.h" 38 40 #import "GraphicsContextCG.h" 39 41 #import "HTMLAttachmentElement.h" … … 2777 2779 #endif // ENABLE(ATTACHMENT_ELEMENT) 2778 2780 2781 static CGColorRef colorForStyle(DocumentMarkerLineStyle style, bool useDarkMode) 2782 { 2783 switch (style) { 2784 // Red. 2785 case DocumentMarkerLineStyle::Spelling: 2786 return cachedCGColor(useDarkMode ? Color { 255, 140, 140, 217 } : Color { 255, 59, 48, 191 }); 2787 // Blue. 2788 case DocumentMarkerLineStyle::DictationAlternatives: 2789 case DocumentMarkerLineStyle::TextCheckingDictationPhraseWithAlternatives: 2790 case DocumentMarkerLineStyle::AutocorrectionReplacement: 2791 return cachedCGColor(useDarkMode ? Color { 40, 145, 255, 217 } : Color { 0, 122, 255, 191 }); 2792 // Green. 2793 case DocumentMarkerLineStyle::Grammar: 2794 return cachedCGColor(useDarkMode ? Color { 50, 215, 75, 217 } : Color { 25, 175, 50, 191 }); 2795 } 2796 } 2797 2798 void RenderThemeMac::drawLineForDocumentMarker(const RenderText& renderer, GraphicsContext& context, const FloatPoint& origin, float width, DocumentMarkerLineStyle style) 2799 { 2800 if (context.paintingDisabled()) 2801 return; 2802 2803 auto circleColor = colorForStyle(style, renderer.page().useSystemAppearance() && renderer.page().useDarkAppearance()); 2804 2805 // Center the underline and ensure we only draw entires dots. 2806 FloatPoint offsetPoint = origin; 2807 float widthMod = fmodf(width, cMisspellingLinePatternWidth); 2808 if (cMisspellingLinePatternWidth - widthMod > cMisspellingLinePatternGapWidth) { 2809 float gapIncludeWidth = 0; 2810 if (width > cMisspellingLinePatternWidth) 2811 gapIncludeWidth = cMisspellingLinePatternGapWidth; 2812 offsetPoint.move(floor((widthMod + gapIncludeWidth) / 2), 0); 2813 width -= widthMod; 2814 } 2815 2816 CGContextRef ctx = context.platformContext(); 2817 CGContextStateSaver stateSaver { ctx }; 2818 CGContextSetFillColorWithColor(ctx, circleColor); 2819 for (int x = 0; x < width; x += cMisspellingLinePatternWidth) 2820 CGContextAddEllipseInRect(ctx, CGRectMake(offsetPoint.x() + x, offsetPoint.y(), cMisspellingLineThickness, cMisspellingLineThickness)); 2821 CGContextSetCompositeOperation(ctx, kCGCompositeSover); 2822 CGContextFillPath(ctx); 2823 } 2824 2779 2825 } // namespace WebCore 2780 2826
Note:
See TracChangeset
for help on using the changeset viewer.