From 362fdbde8cb06b270fdb20e3051bb2a5551a2a3c Mon Sep 17 00:00:00 2001 From: "dino@apple.com" Date: Fri, 21 Oct 2016 19:10:41 +0000 Subject: [PATCH] SVG should not paint selection within a mask https://bugs.webkit.org/show_bug.cgi?id=163772 Reviewed by Simon Fraser. Source/WebCore: When masking content, we shouldn't paint the text selection as we are rendering into the masking offscreen buffer. Test: svg/masking/mask-should-not-paint-selection.html * rendering/PaintPhase.h: Add a new behavior - PaintBehaviorSkipSelectionHighlight. * rendering/svg/SVGInlineTextBox.cpp: (WebCore::SVGInlineTextBox::paint): Don't update the selectionStyle if PaintBehaviorSkipSelectionHighlight is true. * rendering/svg/SVGRenderingContext.cpp: (WebCore::SVGRenderingContext::renderSubtreeToImageBuffer): Add PaintBehaviorSkipSelectionHighlight to the PaintInfo. LayoutTests: * svg/masking/mask-should-not-paint-selection-expected.html: Added. * svg/masking/mask-should-not-paint-selection.html: Added. git-svn-id: https://svn.webkit.org/repository/webkit/trunk@207692 268f45cc-cd09-0410-ab3c-d52691b4dbfc --- LayoutTests/ChangeLog | 11 +++++++++ .../mask-should-not-paint-selection-expected.html | 12 ++++++++++ .../masking/mask-should-not-paint-selection.html | 26 ++++++++++++++++++++++ Source/WebCore/ChangeLog | 22 ++++++++++++++++++ Source/WebCore/rendering/PaintPhase.h | 19 ++++++++-------- Source/WebCore/rendering/svg/SVGInlineTextBox.cpp | 3 ++- .../WebCore/rendering/svg/SVGRenderingContext.cpp | 4 +++- Source/WebCore/rendering/svg/SVGRootInlineBox.cpp | 3 ++- 8 files changed, 88 insertions(+), 12 deletions(-) create mode 100644 LayoutTests/svg/masking/mask-should-not-paint-selection-expected.html create mode 100644 LayoutTests/svg/masking/mask-should-not-paint-selection.html diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog index 336cd35..1b9ae57 100644 --- a/LayoutTests/ChangeLog +++ b/LayoutTests/ChangeLog @@ -1,3 +1,14 @@ +2016-10-20 Dean Jackson + + SVG should not paint selection within a mask + https://bugs.webkit.org/show_bug.cgi?id=163772 + + + Reviewed by Simon Fraser. + + * svg/masking/mask-should-not-paint-selection-expected.html: Added. + * svg/masking/mask-should-not-paint-selection.html: Added. + 2016-10-21 Zalan Bujtas Do not mutate the render tree while collecting selection repaint rects. diff --git a/LayoutTests/svg/masking/mask-should-not-paint-selection-expected.html b/LayoutTests/svg/masking/mask-should-not-paint-selection-expected.html new file mode 100644 index 0000000..db6bf2d --- /dev/null +++ b/LayoutTests/svg/masking/mask-should-not-paint-selection-expected.html @@ -0,0 +1,12 @@ + + + + + + + Text + + + + + diff --git a/LayoutTests/svg/masking/mask-should-not-paint-selection.html b/LayoutTests/svg/masking/mask-should-not-paint-selection.html new file mode 100644 index 0000000..44d8fde --- /dev/null +++ b/LayoutTests/svg/masking/mask-should-not-paint-selection.html @@ -0,0 +1,26 @@ + + + + + + + + + Text + + + + + diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog index dd87d22..3b3a31b 100644 --- a/Source/WebCore/ChangeLog +++ b/Source/WebCore/ChangeLog @@ -1,3 +1,25 @@ +2016-10-20 Dean Jackson + + SVG should not paint selection within a mask + https://bugs.webkit.org/show_bug.cgi?id=163772 + + + Reviewed by Simon Fraser. + + When masking content, we shouldn't paint the text + selection as we are rendering into the masking + offscreen buffer. + + Test: svg/masking/mask-should-not-paint-selection.html + + * rendering/PaintPhase.h: Add a new behavior - PaintBehaviorSkipSelectionHighlight. + * rendering/svg/SVGInlineTextBox.cpp: + (WebCore::SVGInlineTextBox::paint): Don't update the selectionStyle if + PaintBehaviorSkipSelectionHighlight is true. + * rendering/svg/SVGRenderingContext.cpp: + (WebCore::SVGRenderingContext::renderSubtreeToImageBuffer): Add PaintBehaviorSkipSelectionHighlight + to the PaintInfo. + 2016-10-21 Chris Dumez [Web IDL] MediaControlsHost has invalid operation overloads diff --git a/Source/WebCore/rendering/PaintPhase.h b/Source/WebCore/rendering/PaintPhase.h index d46fc4e..6e80330 100644 --- a/Source/WebCore/rendering/PaintPhase.h +++ b/Source/WebCore/rendering/PaintPhase.h @@ -54,15 +54,16 @@ enum PaintPhase { }; enum PaintBehaviorFlags { - PaintBehaviorNormal = 0, - PaintBehaviorSelectionOnly = 1 << 0, - PaintBehaviorForceBlackText = 1 << 1, - PaintBehaviorForceWhiteText = 1 << 2, - PaintBehaviorFlattenCompositingLayers = 1 << 3, - PaintBehaviorRenderingSVGMask = 1 << 4, - PaintBehaviorSkipRootBackground = 1 << 5, - PaintBehaviorRootBackgroundOnly = 1 << 6, - PaintBehaviorSelectionAndBackgroundsOnly = 1 << 7, + PaintBehaviorNormal = 0, + PaintBehaviorSelectionOnly = 1 << 0, + PaintBehaviorSkipSelectionHighlight = 1 << 1, + PaintBehaviorForceBlackText = 1 << 2, + PaintBehaviorForceWhiteText = 1 << 3, + PaintBehaviorFlattenCompositingLayers = 1 << 4, + PaintBehaviorRenderingSVGMask = 1 << 5, + PaintBehaviorSkipRootBackground = 1 << 6, + PaintBehaviorRootBackgroundOnly = 1 << 7, + PaintBehaviorSelectionAndBackgroundsOnly = 1 << 8, }; typedef unsigned PaintBehavior; diff --git a/Source/WebCore/rendering/svg/SVGInlineTextBox.cpp b/Source/WebCore/rendering/svg/SVGInlineTextBox.cpp index 689164a..0f80a0b 100644 --- a/Source/WebCore/rendering/svg/SVGInlineTextBox.cpp +++ b/Source/WebCore/rendering/svg/SVGInlineTextBox.cpp @@ -247,6 +247,7 @@ void SVGInlineTextBox::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffse auto& parentRenderer = parent()->renderer(); bool paintSelectedTextOnly = paintInfo.phase == PaintPhaseSelection; + bool shouldPaintSelectionHighlight = !(paintInfo.paintBehavior & PaintBehaviorSkipSelectionHighlight); bool hasSelection = !parentRenderer.document().printing() && selectionState() != RenderObject::SelectionNone; if (!hasSelection && paintSelectedTextOnly) return; @@ -262,7 +263,7 @@ void SVGInlineTextBox::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffse bool hasVisibleStroke = svgStyle.hasVisibleStroke(); const RenderStyle* selectionStyle = &style; - if (hasSelection) { + if (hasSelection && shouldPaintSelectionHighlight) { selectionStyle = parentRenderer.getCachedPseudoStyle(SELECTION); if (selectionStyle) { const SVGRenderStyle& svgSelectionStyle = selectionStyle->svgStyle(); diff --git a/Source/WebCore/rendering/svg/SVGRenderingContext.cpp b/Source/WebCore/rendering/svg/SVGRenderingContext.cpp index b27d501..4f35ed9 100644 --- a/Source/WebCore/rendering/svg/SVGRenderingContext.cpp +++ b/Source/WebCore/rendering/svg/SVGRenderingContext.cpp @@ -295,7 +295,9 @@ void SVGRenderingContext::renderSubtreeToImageBuffer(ImageBuffer* image, RenderE { ASSERT(image); - PaintInfo info(image->context(), LayoutRect::infiniteRect(), PaintPhaseForeground, PaintBehaviorNormal); + // Rendering into a buffer implies we're being used for masking, clipping, patterns or filters. In each of these + // cases we don't want to paint the selection. + PaintInfo info(image->context(), LayoutRect::infiniteRect(), PaintPhaseForeground, PaintBehaviorSkipSelectionHighlight); AffineTransform& contentTransformation = currentContentTransformation(); AffineTransform savedContentTransformation = contentTransformation; diff --git a/Source/WebCore/rendering/svg/SVGRootInlineBox.cpp b/Source/WebCore/rendering/svg/SVGRootInlineBox.cpp index be67d74..c6d23f5 100644 --- a/Source/WebCore/rendering/svg/SVGRootInlineBox.cpp +++ b/Source/WebCore/rendering/svg/SVGRootInlineBox.cpp @@ -53,9 +53,10 @@ void SVGRootInlineBox::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffse bool isPrinting = renderSVGText().document().printing(); bool hasSelection = !isPrinting && selectionState() != RenderObject::SelectionNone; + bool shouldPaintSelectionHighlight = !(paintInfo.paintBehavior & PaintBehaviorSkipSelectionHighlight); PaintInfo childPaintInfo(paintInfo); - if (hasSelection) { + if (hasSelection && shouldPaintSelectionHighlight) { for (InlineBox* child = firstChild(); child; child = child->nextOnLine()) { if (is(*child)) downcast(*child).paintSelectionBackground(childPaintInfo); -- 1.8.3.1