Title: [224749] trunk/Source/WebCore
Revision
224749
Author
[email protected]
Date
2017-11-13 01:19:19 -0800 (Mon, 13 Nov 2017)

Log Message

[Cairo] Move focus ring drawing operations from GraphicsContextCairo to CairoOperations
https://bugs.webkit.org/show_bug.cgi?id=179603

Reviewed by Carlos Garcia Campos.

Move operations that perform focus ring drawing to the CairoOperations
file. This limits operations to only work with a PlatformContextCairo
object, along with other required parameters, and will help with future
work in this area.

The Cairo::State namespace is introduced, with the setStrokeStyle()
function placed there. The namespace will be used for operations that
only change an aspect of the Cairo state. More functions will be added
soon, and existing line and miter operations will likely move there as
well.

No new tests -- no change in behavior.

* platform/graphics/cairo/CairoOperations.cpp:
(WebCore::Cairo::adjustFocusRingColor):
(WebCore::Cairo::adjustFocusRingLineWidth):
(WebCore::Cairo::focusRingStrokeStyle):
(WebCore::Cairo::State::setStrokeStyle):
(WebCore::Cairo::drawFocusRing):
* platform/graphics/cairo/CairoOperations.h:
* platform/graphics/cairo/GraphicsContextCairo.cpp:
(WebCore::GraphicsContext::drawFocusRing):
(WebCore::GraphicsContext::setPlatformStrokeStyle):
(WebCore::adjustFocusRingColor): Deleted.
(WebCore::adjustFocusRingLineWidth): Deleted.
(WebCore::focusRingStrokeStyle): Deleted.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (224748 => 224749)


--- trunk/Source/WebCore/ChangeLog	2017-11-13 08:23:45 UTC (rev 224748)
+++ trunk/Source/WebCore/ChangeLog	2017-11-13 09:19:19 UTC (rev 224749)
@@ -1,3 +1,37 @@
+2017-11-13  Zan Dobersek  <[email protected]>
+
+        [Cairo] Move focus ring drawing operations from GraphicsContextCairo to CairoOperations
+        https://bugs.webkit.org/show_bug.cgi?id=179603
+
+        Reviewed by Carlos Garcia Campos.
+
+        Move operations that perform focus ring drawing to the CairoOperations
+        file. This limits operations to only work with a PlatformContextCairo
+        object, along with other required parameters, and will help with future
+        work in this area.
+
+        The Cairo::State namespace is introduced, with the setStrokeStyle()
+        function placed there. The namespace will be used for operations that
+        only change an aspect of the Cairo state. More functions will be added
+        soon, and existing line and miter operations will likely move there as
+        well.
+
+        No new tests -- no change in behavior.
+
+        * platform/graphics/cairo/CairoOperations.cpp:
+        (WebCore::Cairo::adjustFocusRingColor):
+        (WebCore::Cairo::adjustFocusRingLineWidth):
+        (WebCore::Cairo::focusRingStrokeStyle):
+        (WebCore::Cairo::State::setStrokeStyle):
+        (WebCore::Cairo::drawFocusRing):
+        * platform/graphics/cairo/CairoOperations.h:
+        * platform/graphics/cairo/GraphicsContextCairo.cpp:
+        (WebCore::GraphicsContext::drawFocusRing):
+        (WebCore::GraphicsContext::setPlatformStrokeStyle):
+        (WebCore::adjustFocusRingColor): Deleted.
+        (WebCore::adjustFocusRingLineWidth): Deleted.
+        (WebCore::focusRingStrokeStyle): Deleted.
+
 2017-11-13  Carlos Garcia Campos  <[email protected]>
 
         Unreviewed. Fix debug build with Touch Events enabled after r224740.

Modified: trunk/Source/WebCore/platform/graphics/cairo/CairoOperations.cpp (224748 => 224749)


--- trunk/Source/WebCore/platform/graphics/cairo/CairoOperations.cpp	2017-11-13 08:23:45 UTC (rev 224748)
+++ trunk/Source/WebCore/platform/graphics/cairo/CairoOperations.cpp	2017-11-13 09:19:19 UTC (rev 224749)
@@ -133,6 +133,64 @@
     cairo_restore(cr);
 }
 
+static inline void adjustFocusRingColor(Color& color)
+{
+#if !PLATFORM(GTK)
+    // Force the alpha to 50%. This matches what the Mac does with outline rings.
+    color = Color(makeRGBA(color.red(), color.green(), color.blue(), 127));
+#else
+    UNUSED_PARAM(color);
+#endif
+}
+
+static inline void adjustFocusRingLineWidth(float& width)
+{
+#if PLATFORM(GTK)
+    width = 2;
+#else
+    UNUSED_PARAM(width);
+#endif
+}
+
+static inline StrokeStyle focusRingStrokeStyle()
+{
+#if PLATFORM(GTK)
+    return DottedStroke;
+#else
+    return SolidStroke;
+#endif
+}
+
+namespace State {
+
+void setStrokeStyle(PlatformContextCairo& platformContext, StrokeStyle strokeStyle)
+{
+    static const double dashPattern[] = { 5.0, 5.0 };
+    static const double dotPattern[] = { 1.0, 1.0 };
+
+    cairo_t* cr = platformContext.cr();
+    switch (strokeStyle) {
+    case NoStroke:
+        // FIXME: is it the right way to emulate NoStroke?
+        cairo_set_line_width(cr, 0);
+        break;
+    case SolidStroke:
+    case DoubleStroke:
+    case WavyStroke:
+        // FIXME: https://bugs.webkit.org/show_bug.cgi?id=94110 - Needs platform support.
+        cairo_set_dash(cr, 0, 0, 0);
+        break;
+    case DottedStroke:
+        cairo_set_dash(cr, dotPattern, 2, 0);
+        break;
+    case DashedStroke:
+        cairo_set_dash(cr, dashPattern, 2, 0);
+        break;
+    }
+}
+
+} // namespace State
+
 void setLineCap(PlatformContextCairo& platformContext, LineCap lineCap)
 {
     cairo_line_cap_t cairoCap;
@@ -289,6 +347,57 @@
     cairo_restore(cr);
 }
 
+void drawFocusRing(PlatformContextCairo& platformContext, const Path& path, float width, const Color& color)
+{
+    // FIXME: We should draw paths that describe a rectangle with rounded corners
+    // so as to be consistent with how we draw rectangular focus rings.
+    Color ringColor = color;
+    adjustFocusRingColor(ringColor);
+    adjustFocusRingLineWidth(width);
+
+    cairo_t* cr = platformContext.cr();
+    cairo_save(cr);
+
+    cairo_push_group(cr);
+    appendWebCorePathToCairoContext(cr, path);
+    setSourceRGBAFromColor(cr, ringColor);
+    cairo_set_line_width(cr, width);
+    Cairo::State::setStrokeStyle(platformContext, focusRingStrokeStyle());
+    cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
+    cairo_stroke_preserve(cr);
+
+    cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR);
+    cairo_set_fill_rule(cr, CAIRO_FILL_RULE_WINDING);
+    cairo_fill(cr);
+
+    cairo_pop_group_to_source(cr);
+    cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
+    cairo_paint(cr);
+
+    cairo_restore(cr);
+}
+
+void drawFocusRing(PlatformContextCairo& platformContext, const Vector<FloatRect>& rects, float width, const Color& color)
+{
+    Path path;
+#if PLATFORM(GTK)
+    for (const auto& rect : rects)
+        path.addRect(rect);
+#else
+    unsigned rectCount = rects.size();
+    int radius = (width - 1) / 2;
+    Path subPath;
+    for (unsigned i = 0; i < rectCount; ++i) {
+        if (i > 0)
+            subPath.clear();
+        subPath.addRoundedRect(rects[i], FloatSize(radius, radius));
+        path.addPath(subPath, AffineTransform());
+    }
+#endif
+
+    drawFocusRing(platformContext, path, width, color);
+}
+
 void save(PlatformContextCairo& platformContext)
 {
     platformContext.save();

Modified: trunk/Source/WebCore/platform/graphics/cairo/CairoOperations.h (224748 => 224749)


--- trunk/Source/WebCore/platform/graphics/cairo/CairoOperations.h	2017-11-13 08:23:45 UTC (rev 224748)
+++ trunk/Source/WebCore/platform/graphics/cairo/CairoOperations.h	2017-11-13 09:19:19 UTC (rev 224749)
@@ -35,6 +35,7 @@
 #if USE(CAIRO)
 
 #include "DashArray.h"
+#include "GraphicsContext.h"
 #include "GraphicsTypes.h"
 
 typedef struct _cairo_pattern cairo_pattern_t;
@@ -54,6 +55,10 @@
 
 namespace Cairo {
 
+namespace State {
+void setStrokeStyle(PlatformContextCairo&, StrokeStyle);
+}
+
 void setLineCap(PlatformContextCairo&, LineCap);
 void setLineDash(PlatformContextCairo&, const DashArray&, float);
 void setLineJoin(PlatformContextCairo&, LineJoin);
@@ -69,6 +74,9 @@
 void strokePath(PlatformContextCairo&, const Path&, const GraphicsContextState&, GraphicsContext&);
 void clearRect(PlatformContextCairo&, const FloatRect&);
 
+void drawFocusRing(PlatformContextCairo&, const Path&, float, const Color&);
+void drawFocusRing(PlatformContextCairo&, const Vector<FloatRect>&, float, const Color&);
+
 void save(PlatformContextCairo&);
 void restore(PlatformContextCairo&);
 

Modified: trunk/Source/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp (224748 => 224749)


--- trunk/Source/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp	2017-11-13 08:23:45 UTC (rev 224748)
+++ trunk/Source/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp	2017-11-13 09:19:19 UTC (rev 224749)
@@ -513,86 +513,32 @@
     return enclosingIntRect(FloatRect(x1, y1, x2 - x1, y2 - y1));
 }
 
-static inline void adjustFocusRingColor(Color& color)
+void GraphicsContext::drawFocusRing(const Path& path, float width, float offset, const Color& color)
 {
-#if !PLATFORM(GTK)
-    // Force the alpha to 50%.  This matches what the Mac does with outline rings.
-    color = Color(makeRGBA(color.red(), color.green(), color.blue(), 127));
-#else
-    UNUSED_PARAM(color);
-#endif
-}
-
-static inline void adjustFocusRingLineWidth(float& width)
-{
-#if PLATFORM(GTK)
-    width = 2;
-#else
-    UNUSED_PARAM(width);
-#endif
-}
-
-static inline StrokeStyle focusRingStrokeStyle()
-{
-#if PLATFORM(GTK)
-    return DottedStroke;
-#else
-    return SolidStroke;
-#endif
-}
-
-void GraphicsContext::drawFocusRing(const Path& path, float width, float /* offset */, const Color& color)
-{
     if (paintingDisabled())
         return;
 
-    // FIXME: We should draw paths that describe a rectangle with rounded corners
-    // so as to be consistent with how we draw rectangular focus rings.
-    Color ringColor = color;
-    adjustFocusRingColor(ringColor);
-    adjustFocusRingLineWidth(width);
+    if (m_impl) {
+        m_impl->drawFocusRing(path, width, offset, color);
+        return;
+    }
 
-    cairo_t* cr = platformContext()->cr();
-    cairo_save(cr);
-    cairo_push_group(cr);
-    appendWebCorePathToCairoContext(cr, path);
-    setSourceRGBAFromColor(cr, ringColor);
-    cairo_set_line_width(cr, width);
-    setPlatformStrokeStyle(focusRingStrokeStyle());
-    cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
-    cairo_stroke_preserve(cr);
-
-    cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR);
-    cairo_set_fill_rule(cr, CAIRO_FILL_RULE_WINDING);
-    cairo_fill(cr);
-
-    cairo_pop_group_to_source(cr);
-    cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
-    cairo_paint(cr);
-    cairo_restore(cr);
+    ASSERT(hasPlatformContext());
+    Cairo::drawFocusRing(*platformContext(), path, width, color);
 }
 
-void GraphicsContext::drawFocusRing(const Vector<FloatRect>& rects, float width, float /* offset */, const Color& color)
+void GraphicsContext::drawFocusRing(const Vector<FloatRect>& rects, float width, float offset, const Color& color)
 {
     if (paintingDisabled())
         return;
 
-    Path path;
-#if PLATFORM(GTK)
-    for (const auto& rect : rects)
-        path.addRect(rect);
-#else
-    unsigned rectCount = rects.size();
-    int radius = (width - 1) / 2;
-    Path subPath;
-    for (unsigned i = 0; i < rectCount; ++i) {
-        if (i > 0)
-            subPath.clear();
-        subPath.addRoundedRect(rects[i], FloatSize(radius, radius));
-        path.addPath(subPath, AffineTransform());
+    if (m_impl) {
+        m_impl->drawFocusRing(rects, width, offset, color);
+        return;
     }
-#endif
-    drawFocusRing(path, width, 0, color);
+
+    ASSERT(hasPlatformContext());
+    Cairo::drawFocusRing(*platformContext(), rects, width, color);
 }
 
 void GraphicsContext::drawLineForText(const FloatPoint& origin, float width, bool printing, bool doubleUnderlines, StrokeStyle)
@@ -755,31 +701,11 @@
 
 void GraphicsContext::setPlatformStrokeStyle(StrokeStyle strokeStyle)
 {
-    static const double dashPattern[] = { 5.0, 5.0 };
-    static const double dotPattern[] = { 1.0, 1.0 };
-
     if (paintingDisabled())
         return;
 
     ASSERT(hasPlatformContext());
-
-    switch (strokeStyle) {
-    case NoStroke:
-        // FIXME: is it the right way to emulate NoStroke?
-        cairo_set_line_width(platformContext()->cr(), 0);
-        break;
-    case SolidStroke:
-    case DoubleStroke:
-    case WavyStroke: // FIXME: https://bugs.webkit.org/show_bug.cgi?id=94110 - Needs platform support.
-        cairo_set_dash(platformContext()->cr(), 0, 0, 0);
-        break;
-    case DottedStroke:
-        cairo_set_dash(platformContext()->cr(), dotPattern, 2, 0);
-        break;
-    case DashedStroke:
-        cairo_set_dash(platformContext()->cr(), dashPattern, 2, 0);
-        break;
-    }
+    Cairo::State::setStrokeStyle(*platformContext(), strokeStyle);
 }
 
 void GraphicsContext::setURLForRect(const URL&, const FloatRect&)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to