Separate out outline-style: auto user-agent appearance from Mac animated focus ring...
authordbates@webkit.org <dbates@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 11 Feb 2019 19:00:08 +0000 (19:00 +0000)
committerdbates@webkit.org <dbates@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 11 Feb 2019 19:00:08 +0000 (19:00 +0000)
https://bugs.webkit.org/show_bug.cgi?id=193591

Reviewed by Simon Fraser.

Untangle the Mac-specific concept of animated focus ring drawing from the concepts of using
the fancy shrink-wrapped focus ring appearance and using the platform focus ring color when
outline-style: auto.

No functionality changed. So, no new tests.

* platform/graphics/GraphicsContext.h:
* platform/graphics/cocoa/GraphicsContextCocoa.mm:
(WebCore::drawFocusRing):
(WebCore::drawFocusRingToContextAtTime):
Change some macro guards.

* rendering/RenderElement.cpp:
(WebCore::usePlatformFocusRingColorForOutlineStyleAuto): Added.
(WebCore::useShrinkWrappedFocusRingForOutlineStyleAuto): Added.
(WebCore::drawFocusRing): Added.
(WebCore::RenderElement::paintFocusRing): Write in terms of drawFocusRing().

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@241271 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/GraphicsContext.h
Source/WebCore/platform/graphics/cocoa/GraphicsContextCocoa.mm
Source/WebCore/rendering/RenderElement.cpp

index 06439ba..e9fd440 100644 (file)
@@ -1,3 +1,28 @@
+2019-02-11  Daniel Bates  <dabates@apple.com>
+
+        Separate out outline-style: auto user-agent appearance from Mac animated focus ring drawing
+        https://bugs.webkit.org/show_bug.cgi?id=193591
+
+        Reviewed by Simon Fraser.
+
+        Untangle the Mac-specific concept of animated focus ring drawing from the concepts of using
+        the fancy shrink-wrapped focus ring appearance and using the platform focus ring color when
+        outline-style: auto.
+
+        No functionality changed. So, no new tests.
+
+        * platform/graphics/GraphicsContext.h:
+        * platform/graphics/cocoa/GraphicsContextCocoa.mm:
+        (WebCore::drawFocusRing):
+        (WebCore::drawFocusRingToContextAtTime):
+        Change some macro guards.
+
+        * rendering/RenderElement.cpp:
+        (WebCore::usePlatformFocusRingColorForOutlineStyleAuto): Added.
+        (WebCore::useShrinkWrappedFocusRingForOutlineStyleAuto): Added.
+        (WebCore::drawFocusRing): Added.
+        (WebCore::RenderElement::paintFocusRing): Write in terms of drawFocusRing().
+
 2019-02-11  Truitt Savell  <tsavell@apple.com>
 
         Unreviewed, rolling out r241229.
index 816caea..1c366d5 100644 (file)
@@ -446,9 +446,7 @@ public:
 
     void drawFocusRing(const Vector<FloatRect>&, float width, float offset, const Color&);
     void drawFocusRing(const Path&, float width, float offset, const Color&);
-
-    // FIXME: The following functions should only be compiled for Mac. See <https://bugs.webkit.org/show_bug.cgi?id=193591>.
-#if PLATFORM(COCOA)
+#if PLATFORM(MAC)
     void drawFocusRing(const Path&, double timeOffset, bool& needsRedraw, const Color&);
     void drawFocusRing(const Vector<FloatRect>&, double timeOffset, bool& needsRedraw, const Color&);
 #endif
index 702d6c5..eab564b 100644 (file)
@@ -95,7 +95,7 @@ static bool drawFocusRingAtTime(CGContextRef context, NSTimeInterval timeOffset,
     return needsRepaint;
 }
 
-static void drawFocusRing(CGContextRef context, const Color& color)
+inline static void drawFocusRing(CGContextRef context, const Color& color)
 {
     drawFocusRingAtTime(context, std::numeric_limits<double>::max(), color);
 }
@@ -107,14 +107,6 @@ static void drawFocusRingToContext(CGContextRef context, CGPathRef focusRingPath
     drawFocusRing(context, color);
 }
 
-static bool drawFocusRingToContextAtTime(CGContextRef context, CGPathRef focusRingPath, double timeOffset, const Color& color)
-{
-    UNUSED_PARAM(timeOffset);
-    CGContextBeginPath(context);
-    CGContextAddPath(context, focusRingPath);
-    return drawFocusRingAtTime(context, std::numeric_limits<double>::max(), color);
-}
-
 #endif // ENABLE(FULL_KEYBOARD_ACCESS)
 
 void GraphicsContext::drawFocusRing(const Path& path, float width, float offset, const Color& color)
@@ -137,8 +129,15 @@ void GraphicsContext::drawFocusRing(const Path& path, float width, float offset,
 #endif
 }
 
-// FIXME: The following functions should only be compiled for Mac. See <https://bugs.webkit.org/show_bug.cgi?id=193591>.
-#if ENABLE(FULL_KEYBOARD_ACCESS)
+#if PLATFORM(MAC)
+
+static bool drawFocusRingToContextAtTime(CGContextRef context, CGPathRef focusRingPath, double timeOffset, const Color& color)
+{
+    UNUSED_PARAM(timeOffset);
+    CGContextBeginPath(context);
+    CGContextAddPath(context, focusRingPath);
+    return drawFocusRingAtTime(context, std::numeric_limits<double>::max(), color);
+}
 
 void GraphicsContext::drawFocusRing(const Path& path, double timeOffset, bool& needsRedraw, const Color& color)
 {
@@ -166,7 +165,7 @@ void GraphicsContext::drawFocusRing(const Vector<FloatRect>& rects, double timeO
     needsRedraw = drawFocusRingToContextAtTime(platformContext(), focusRingPath.get(), timeOffset, color);
 }
 
-#endif
+#endif // PLATFORM(MAC)
 
 void GraphicsContext::drawFocusRing(const Vector<FloatRect>& rects, float width, float offset, const Color& color)
 {
index 2f2f3c1..96d4a3c 100644 (file)
@@ -1809,6 +1809,51 @@ void RenderElement::drawLineForBoxSide(GraphicsContext& graphicsContext, const F
     }
 }
 
+static bool usePlatformFocusRingColorForOutlineStyleAuto()
+{
+#if PLATFORM(COCOA)
+    return true;
+#else
+    return false;
+#endif
+}
+
+static bool useShrinkWrappedFocusRingForOutlineStyleAuto()
+{
+#if PLATFORM(COCOA)
+    return true;
+#else
+    return false;
+#endif
+}
+
+static bool drawFocusRing(GraphicsContext& context, Page& page, const Path& path, const RenderStyle& style, Color focusRingColor)
+{
+    bool needsRepaint = false;
+#if PLATFORM(MAC)
+    context.drawFocusRing(path, page.focusController().timeSinceFocusWasSet().seconds(), needsRepaint, focusRingColor);
+    UNUSED_PARAM(style);
+#else
+    context.drawFocusRing(path, style.outlineWidth(), style.outlineOffset(), focusRingColor);
+    UNUSED_PARAM(page);
+#endif
+    return needsRepaint;
+}
+
+static bool drawFocusRing(GraphicsContext& context, Page& page, Vector<FloatRect> rects, const RenderStyle& style, Color focusRingColor)
+{
+    bool needsRepaint = false;
+#if PLATFORM(MAC)
+    context.drawFocusRing(rects, page.focusController().timeSinceFocusWasSet().seconds(), needsRepaint, focusRingColor);
+    UNUSED_PARAM(style);
+#else
+    context.drawFocusRing(rects, style.outlineWidth(), style.outlineOffset(), focusRingColor);
+    UNUSED_PARAM(page);
+#endif
+    return needsRepaint;
+}
+
+
 void RenderElement::paintFocusRing(PaintInfo& paintInfo, const RenderStyle& style, const Vector<LayoutRect>& focusRingRects)
 {
     ASSERT(style.outlineStyleIsAuto() == OutlineIsAuto::On);
@@ -1819,24 +1864,20 @@ void RenderElement::paintFocusRing(PaintInfo& paintInfo, const RenderStyle& styl
         rect.inflate(outlineOffset);
         pixelSnappedFocusRingRects.append(snapRectToDevicePixels(rect, deviceScaleFactor));
     }
-    // FIXME: The following code should only be compiled for Mac. See <https://bugs.webkit.org/show_bug.cgi?id=193591>.
-#if ENABLE(FULL_KEYBOARD_ACCESS)
+    Color focusRingColor = usePlatformFocusRingColorForOutlineStyleAuto() ? RenderTheme::singleton().focusRingColor(styleColorOptions()) : style.visitedDependentColorWithColorFilter(CSSPropertyOutlineColor);
     bool needsRepaint;
-    if (style.hasBorderRadius()) {
+    if (useShrinkWrappedFocusRingForOutlineStyleAuto() && style.hasBorderRadius()) {
         Path path = PathUtilities::pathWithShrinkWrappedRectsForOutline(pixelSnappedFocusRingRects, style.border(), outlineOffset, style.direction(), style.writingMode(),
             document().deviceScaleFactor());
         if (path.isEmpty()) {
             for (auto rect : pixelSnappedFocusRingRects)
                 path.addRect(rect);
         }
-        paintInfo.context().drawFocusRing(path, page().focusController().timeSinceFocusWasSet().seconds(), needsRepaint, RenderTheme::singleton().focusRingColor(styleColorOptions()));
+        needsRepaint = drawFocusRing(paintInfo.context(), page(), path, style, focusRingColor);
     } else
-        paintInfo.context().drawFocusRing(pixelSnappedFocusRingRects, page().focusController().timeSinceFocusWasSet().seconds(), needsRepaint, RenderTheme::singleton().focusRingColor(styleColorOptions()));
+        needsRepaint = drawFocusRing(paintInfo.context(), page(), pixelSnappedFocusRingRects, style, focusRingColor);
     if (needsRepaint)
         page().focusController().setFocusedElementNeedsRepaint();
-#else
-    paintInfo.context().drawFocusRing(pixelSnappedFocusRingRects, style.outlineWidth(), style.outlineOffset(), style.visitedDependentColorWithColorFilter(CSSPropertyOutlineColor));
-#endif
 }
 
 void RenderElement::paintOutline(PaintInfo& paintInfo, const LayoutRect& paintRect)