Title: [159671] trunk
Revision
159671
Author
[email protected]
Date
2013-11-21 19:17:15 -0800 (Thu, 21 Nov 2013)

Log Message

Web Inspector: [CSS Shapes] Refactor highlighting code to decrease Shapes API surface
https://bugs.webkit.org/show_bug.cgi?id=124737

Reviewed by Timothy Hatcher.

Source/WebCore:

Add a virtual method to Shapes, buildPath, that can be used to build the
path (in the Shape coordinate system) for display in the Inspector. This allows us
to remove methods such as type(), polygon(), and logicalRx/Ry() which exposed the
inner workings of the Shapes classes. Also covers the addition of the BoxShape type.

Refactoring, existing test is inspector-protocol/model/highlight-shape-outside.html.

* inspector/InspectorOverlay.cpp:
(WebCore::appendPathCommandAndPoints): Points need to be translated from shape space
to renderer space using ShapeInfo.
(WebCore::buildObjectForShapeOutside): Add the ShapeOutsideInfo to the path info struct.
* rendering/shapes/BoxShape.cpp:
(WebCore::BoxShape::buildPath): Build the path for a BoxShape.
* rendering/shapes/BoxShape.h:
* rendering/shapes/PolygonShape.cpp:
(WebCore::PolygonShape::buildPath): Build the path for a PolygonShape.
* rendering/shapes/PolygonShape.h:
* rendering/shapes/RasterShape.h:
* rendering/shapes/RectangleShape.cpp:
(WebCore::RectangleShape::buildPath): Build the path for a RectangleShape.
* rendering/shapes/RectangleShape.h:
* rendering/shapes/Shape.h:

LayoutTests:

The shapes paths are now drawn in shape-coordinate space before being translated to
renderer space. With different writing modes, shapes may have their coordinates
translated. For example, a rectangle specified as four points [top left, top right,
bottom right, bottom left] in vertical-lr space would appear as [top left, bottom left,
bottom right, top right] in horizontal-tb space. Adjusting the previous tests, and
adding a test for the new box value.

* inspector-protocol/model/highlight-shape-outside-expected.txt:
* inspector-protocol/model/highlight-shape-outside.html:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (159670 => 159671)


--- trunk/LayoutTests/ChangeLog	2013-11-22 03:12:13 UTC (rev 159670)
+++ trunk/LayoutTests/ChangeLog	2013-11-22 03:17:15 UTC (rev 159671)
@@ -1,3 +1,20 @@
+2013-11-21  Bear Travis  <[email protected]>
+
+        Web Inspector: [CSS Shapes] Refactor highlighting code to decrease Shapes API surface
+        https://bugs.webkit.org/show_bug.cgi?id=124737
+
+        Reviewed by Timothy Hatcher.
+
+        The shapes paths are now drawn in shape-coordinate space before being translated to
+        renderer space. With different writing modes, shapes may have their coordinates
+        translated. For example, a rectangle specified as four points [top left, top right,
+        bottom right, bottom left] in vertical-lr space would appear as [top left, bottom left,
+        bottom right, top right] in horizontal-tb space. Adjusting the previous tests, and
+        adding a test for the new box value.
+
+        * inspector-protocol/model/highlight-shape-outside-expected.txt:
+        * inspector-protocol/model/highlight-shape-outside.html:
+
 2013-11-21  Sun-woo Nam  <[email protected]>
 
         [EFL] Layout tests with editing need to be rebaselined.

Modified: trunk/LayoutTests/inspector-protocol/model/highlight-shape-outside-expected.txt (159670 => 159671)


--- trunk/LayoutTests/inspector-protocol/model/highlight-shape-outside-expected.txt	2013-11-22 03:12:13 UTC (rev 159670)
+++ trunk/LayoutTests/inspector-protocol/model/highlight-shape-outside-expected.txt	2013-11-22 03:17:15 UTC (rev 159671)
@@ -2,8 +2,9 @@
 PASS: Actual [M 50 50 L 100 50 L 100 100 L 50 100 Z] Expected [M 50 50 L 100 50 L 100 100 L 50 100 Z]
 PASS: Actual [M 75 75 L 175 75 L 175 125 L 75 125 L 75 75 Z] Expected [M 75 75 L 175 75 L 175 125 L 75 125 L 75 75 Z]
 PASS: Actual [M 50 50 L 150 50 L 150 100 L 50 100 L 50 50 Z] Expected [M 50 50 L 150 50 L 150 100 L 50 100 L 50 50 Z]
-PASS: Actual [M 50 50 L 150 50 L 150 100 L 50 100 L 50 50 Z] Expected [M 50 50 L 150 50 L 150 100 L 50 100 L 50 50 Z]
-PASS: Actual [M 50 50 L 150 50 L 150 100 L 50 100 L 50 50 Z] Expected [M 50 50 L 150 50 L 150 100 L 50 100 L 50 50 Z]
-PASS: Actual [M 75 75 L 175 75 L 175 125 L 75 125 L 75 75 Z] Expected [M 75 75 L 175 75 L 175 125 L 75 125 L 75 75 Z]
-PASS: Actual [M 50 50 L 150 50 L 150 100 L 50 100 L 50 50 Z] Expected [M 50 50 L 150 50 L 150 100 L 50 100 L 50 50 Z]
+PASS: Actual [M 50 50 L 50 100 L 150 100 L 150 50 L 50 50 Z] Expected [M 50 50 L 50 100 L 150 100 L 150 50 L 50 50 Z]
+PASS: Actual [M 150 50 L 150 100 L 50 100 L 50 50 L 150 50 Z] Expected [M 150 50 L 150 100 L 50 100 L 50 50 L 150 50 Z]
+PASS: Actual [M 175 75 L 175 125 L 75 125 L 75 75 L 175 75 Z] Expected [M 175 75 L 175 125 L 75 125 L 75 75 L 175 75 Z]
+PASS: Actual [M 150 50 L 150 100 L 50 100 L 50 50 L 150 50 Z] Expected [M 150 50 L 150 100 L 50 100 L 50 50 L 150 50 Z]
+PASS: Actual [M 25 25 L 125 25 L 125 125 L 25 125 L 25 25 Z] Expected [M 25 25 L 125 25 L 125 125 L 25 125 L 25 25 Z]
 

Modified: trunk/LayoutTests/inspector-protocol/model/highlight-shape-outside.html (159670 => 159671)


--- trunk/LayoutTests/inspector-protocol/model/highlight-shape-outside.html	2013-11-22 03:12:13 UTC (rev 159670)
+++ trunk/LayoutTests/inspector-protocol/model/highlight-shape-outside.html	2013-11-22 03:17:15 UTC (rev 159671)
@@ -30,6 +30,9 @@
 .polygon {
     -webkit-shape-outside: polygon(50px 50px, 100px 50px, 100px 100px, 50px 100px);
 }
+.content-box {
+    -webkit-shape-outside: content-box;
+}
 </style>
 <script type="text/_javascript_" src=""
 <script type="text/_javascript_" src=""
@@ -54,19 +57,23 @@
     },
     {
         'selector' : '.rectangle.vertical-lr',
-        'path' : ['M', 50, 50, 'L', 150, 50, 'L', 150, 100, 'L', 50, 100, 'L', 50, 50, 'Z']
+        'path' : ['M', 50, 50, 'L', 50, 100, 'L', 150, 100, 'L', 150, 50, 'L', 50, 50, 'Z']
     },
     {
         'selector' : '.rectangle.vertical-rl',
-        'path' : ['M', 50, 50, 'L', 150, 50, 'L', 150, 100, 'L', 50, 100, 'L', 50, 50, 'Z']
+        'path' : ['M', 150, 50, 'L', 150, 100, 'L', 50, 100, 'L', 50, 50, 'L', 150, 50, 'Z']
     },
     {
         'selector' : '.rectangle.padded.vertical-rl',
-        'path' : ['M', 75, 75, 'L', 175, 75, 'L', 175, 125, 'L', 75, 125, 'L', 75, 75, 'Z']
+        'path' : ['M', 175, 75, 'L', 175, 125, 'L', 75, 125, 'L', 75, 75, 'L', 175, 75, 'Z']
     },
     {
         'selector' : '.rectangle.padded.vertical-rl.border-box',
-        'path' : ['M', 50, 50, 'L', 150, 50, 'L', 150, 100, 'L', 50, 100, 'L', 50, 50, 'Z']
+        'path' : ['M', 150, 50, 'L', 150, 100, 'L', 50, 100, 'L', 50, 50, 'L', 150, 50, 'Z']
+    },
+    {
+        'selector' : '.content-box.padded',
+        'path' : ['M', 25, 25, 'L', 125, 25, 'L', 125, 125, 'L', 25, 125, 'L', 25, 25, 'Z']
     }
     ];
 
@@ -99,5 +106,6 @@
     <div class='shape rectangle vertical-rl'></div>
     <div class='shape padded rectangle vertical-rl'></div>
     <div class='shape padded rectangle vertical-rl border-box'></div>
+    <div class='shape padded content-box'></div>
 </body>
 </html>

Modified: trunk/Source/WebCore/ChangeLog (159670 => 159671)


--- trunk/Source/WebCore/ChangeLog	2013-11-22 03:12:13 UTC (rev 159670)
+++ trunk/Source/WebCore/ChangeLog	2013-11-22 03:17:15 UTC (rev 159671)
@@ -1,3 +1,33 @@
+2013-11-21  Bear Travis  <[email protected]>
+
+        Web Inspector: [CSS Shapes] Refactor highlighting code to decrease Shapes API surface
+        https://bugs.webkit.org/show_bug.cgi?id=124737
+
+        Reviewed by Timothy Hatcher.
+
+        Add a virtual method to Shapes, buildPath, that can be used to build the
+        path (in the Shape coordinate system) for display in the Inspector. This allows us
+        to remove methods such as type(), polygon(), and logicalRx/Ry() which exposed the
+        inner workings of the Shapes classes. Also covers the addition of the BoxShape type.
+
+        Refactoring, existing test is inspector-protocol/model/highlight-shape-outside.html.
+
+        * inspector/InspectorOverlay.cpp:
+        (WebCore::appendPathCommandAndPoints): Points need to be translated from shape space
+        to renderer space using ShapeInfo.
+        (WebCore::buildObjectForShapeOutside): Add the ShapeOutsideInfo to the path info struct.
+        * rendering/shapes/BoxShape.cpp:
+        (WebCore::BoxShape::buildPath): Build the path for a BoxShape.
+        * rendering/shapes/BoxShape.h:
+        * rendering/shapes/PolygonShape.cpp:
+        (WebCore::PolygonShape::buildPath): Build the path for a PolygonShape.
+        * rendering/shapes/PolygonShape.h:
+        * rendering/shapes/RasterShape.h:
+        * rendering/shapes/RectangleShape.cpp:
+        (WebCore::RectangleShape::buildPath): Build the path for a RectangleShape.
+        * rendering/shapes/RectangleShape.h:
+        * rendering/shapes/Shape.h:
+
 2013-11-21  Mark Rowe  <[email protected]>
 
         <https://webkit.org/b/124702> Stop overriding VALID_ARCHS.

Modified: trunk/Source/WebCore/inspector/InspectorOverlay.cpp (159670 => 159671)


--- trunk/Source/WebCore/inspector/InspectorOverlay.cpp	2013-11-22 03:12:13 UTC (rev 159670)
+++ trunk/Source/WebCore/inspector/InspectorOverlay.cpp	2013-11-22 03:17:15 UTC (rev 159671)
@@ -548,6 +548,7 @@
     FrameView* view;
     InspectorArray* array;
     RenderObject* renderer;
+    const ShapeOutsideInfo* shapeOutsideInfo;
 };
 
 static void appendPathCommandAndPoints(PathApplyInfo* info, const String& command, const FloatPoint points[], unsigned length)
@@ -555,7 +556,8 @@
     FloatPoint point;
     info->array->pushString(command);
     for (unsigned i = 0; i < length; i++) {
-        point = localPointToRoot(info->renderer, info->rootView, info->view, points[i]);
+        point = info->shapeOutsideInfo->shapeToRendererPoint(points[i]);
+        point = localPointToRoot(info->renderer, info->rootView, info->view, point);
         info->array->pushNumber(point.x());
         info->array->pushNumber(point.y());
     }
@@ -602,40 +604,8 @@
     shapeObject->setArray("bounds", buildArrayForQuad(shapeQuad));
 
     Path path;
-    switch (shapeOutsideInfo->computedShape()->type()) {
-    case Shape::RoundedRectangleType: {
-        const RectangleShape* shape = static_cast<const RectangleShape*>(shapeOutsideInfo->computedShape());
-        FloatSize radii(shape->logicalRx(), shape->logicalRy());
-        radii = shapeOutsideInfo->shapeToRendererSize(radii);
-        path.addRoundedRect(shapeBounds, radii, Path::PreferBezierRoundedRect);
-        break;
-    }
+    shapeOutsideInfo->computedShape()->buildPath(path);
 
-    case Shape::PolygonType: {
-        const PolygonShape* shape = static_cast<const PolygonShape*>(shapeOutsideInfo->computedShape());
-        const FloatPolygon& polygon = shape->polygon();
-        FloatPoint vertex;
-
-        if (polygon.numberOfVertices()) {
-            vertex = shapeOutsideInfo->shapeToRendererPoint(polygon.vertexAt(0));
-            path.moveTo(vertex);
-        }
-
-        for (size_t i = 1; i < polygon.numberOfVertices(); i++) {
-            FloatPoint vertex = shapeOutsideInfo->shapeToRendererPoint(polygon.vertexAt(i));
-            path.addLineTo(vertex);
-        }
-
-        if (polygon.numberOfVertices())
-            path.closeSubpath();
-        break;
-    }
-
-    case Shape::RasterType:
-        // FIXME: Bug 124080 - RasterShapes are not yet supported and only display their shape bounds
-        break;
-    }
-
     if (path.length()) {
         RefPtr<InspectorArray> shapePath = InspectorArray::create();
         PathApplyInfo info;
@@ -643,6 +613,7 @@
         info.view = containingFrame->view();
         info.array = shapePath.get();
         info.renderer = renderer;
+        info.shapeOutsideInfo = shapeOutsideInfo;
 
         path.apply(&info, &appendPathSegment);
 

Modified: trunk/Source/WebCore/rendering/shapes/BoxShape.cpp (159670 => 159671)


--- trunk/Source/WebCore/rendering/shapes/BoxShape.cpp	2013-11-22 03:12:13 UTC (rev 159670)
+++ trunk/Source/WebCore/rendering/shapes/BoxShape.cpp	2013-11-22 03:17:15 UTC (rev 159671)
@@ -108,4 +108,11 @@
     return true;
 }
 
+void BoxShape::buildPath(Path& path) const
+{
+    const FloatRect& rect = m_bounds.rect();
+    const FloatRoundedRect::Radii& radii = m_bounds.radii();
+    path.addRoundedRect(rect, radii.topLeft(), radii.topRight(), radii.bottomLeft(), radii.bottomRight(), Path::PreferBezierRoundedRect);
+}
+
 } // namespace WebCore

Modified: trunk/Source/WebCore/rendering/shapes/BoxShape.h (159670 => 159671)


--- trunk/Source/WebCore/rendering/shapes/BoxShape.h	2013-11-22 03:12:13 UTC (rev 159670)
+++ trunk/Source/WebCore/rendering/shapes/BoxShape.h	2013-11-22 03:17:15 UTC (rev 159671)
@@ -45,8 +45,9 @@
     virtual void getExcludedIntervals(LayoutUnit logicalTop, LayoutUnit logicalHeight, SegmentList&) const OVERRIDE;
     virtual void getIncludedIntervals(LayoutUnit logicalTop, LayoutUnit logicalHeight, SegmentList&) const OVERRIDE;
     virtual bool firstIncludedIntervalLogicalTop(LayoutUnit minLogicalIntervalTop, const LayoutSize& minLogicalIntervalSize, LayoutUnit&) const OVERRIDE;
-    virtual ShapeType type() const OVERRIDE { return Shape::RoundedRectangleType; }
 
+    virtual void buildPath(Path&) const OVERRIDE;
+
 private:
     FloatRoundedRect m_bounds;
     FloatRoundedRect m_marginBounds;

Modified: trunk/Source/WebCore/rendering/shapes/PolygonShape.cpp (159670 => 159671)


--- trunk/Source/WebCore/rendering/shapes/PolygonShape.cpp	2013-11-22 03:12:13 UTC (rev 159670)
+++ trunk/Source/WebCore/rendering/shapes/PolygonShape.cpp	2013-11-22 03:17:15 UTC (rev 159671)
@@ -523,4 +523,19 @@
     return firstFitFound;
 }
 
+void PolygonShape::buildPath(Path& path) const
+{
+    FloatPoint vertex;
+
+    if (!m_polygon.numberOfVertices())
+        return;
+
+    path.moveTo(m_polygon.vertexAt(0));
+
+    for (size_t i = 1; i < m_polygon.numberOfVertices(); i++)
+        path.addLineTo(m_polygon.vertexAt(i));
+
+    path.closeSubpath();
+}
+
 } // namespace WebCore

Modified: trunk/Source/WebCore/rendering/shapes/PolygonShape.h (159670 => 159671)


--- trunk/Source/WebCore/rendering/shapes/PolygonShape.h	2013-11-22 03:12:13 UTC (rev 159670)
+++ trunk/Source/WebCore/rendering/shapes/PolygonShape.h	2013-11-22 03:17:15 UTC (rev 159671)
@@ -97,10 +97,8 @@
     virtual void getIncludedIntervals(LayoutUnit logicalTop, LayoutUnit logicalHeight, SegmentList&) const OVERRIDE;
     virtual bool firstIncludedIntervalLogicalTop(LayoutUnit minLogicalIntervalTop, const LayoutSize& minLogicalIntervalSize, LayoutUnit&) const OVERRIDE;
 
-    virtual ShapeType type() const OVERRIDE { return Shape::PolygonType; }
+    virtual void buildPath(Path&) const OVERRIDE;
 
-    const FloatPolygon& polygon() const { return m_polygon; }
-
 private:
     const FloatPolygon& shapeMarginBounds() const;
     const FloatPolygon& shapePaddingBounds() const;

Modified: trunk/Source/WebCore/rendering/shapes/RasterShape.h (159670 => 159671)


--- trunk/Source/WebCore/rendering/shapes/RasterShape.h	2013-11-22 03:12:13 UTC (rev 159670)
+++ trunk/Source/WebCore/rendering/shapes/RasterShape.h	2013-11-22 03:17:15 UTC (rev 159671)
@@ -101,7 +101,8 @@
     virtual void getIncludedIntervals(LayoutUnit logicalTop, LayoutUnit logicalHeight, SegmentList&) const OVERRIDE;
     virtual bool firstIncludedIntervalLogicalTop(LayoutUnit minLogicalIntervalTop, const LayoutSize& minLogicalIntervalSize, LayoutUnit&) const OVERRIDE;
 
-    virtual ShapeType type() const OVERRIDE { return Shape::RasterType; }
+    // FIXME: Bug 124080 - RasterShapes are not yet supported and only display their shape bounds
+    virtual void buildPath(Path& path) const OVERRIDE { UNUSED_PARAM(path); }
 
 private:
     const RasterShapeIntervals& marginIntervals() const;

Modified: trunk/Source/WebCore/rendering/shapes/RectangleShape.cpp (159670 => 159671)


--- trunk/Source/WebCore/rendering/shapes/RectangleShape.cpp	2013-11-22 03:12:13 UTC (rev 159670)
+++ trunk/Source/WebCore/rendering/shapes/RectangleShape.cpp	2013-11-22 03:17:15 UTC (rev 159671)
@@ -228,4 +228,9 @@
     return false;
 }
 
+void RectangleShape::buildPath(Path& path) const
+{
+    path.addRoundedRect(m_bounds, FloatSize(m_bounds.rx(), m_bounds.ry()), Path::PreferBezierRoundedRect);
+}
+
 } // namespace WebCore

Modified: trunk/Source/WebCore/rendering/shapes/RectangleShape.h (159670 => 159671)


--- trunk/Source/WebCore/rendering/shapes/RectangleShape.h	2013-11-22 03:12:13 UTC (rev 159670)
+++ trunk/Source/WebCore/rendering/shapes/RectangleShape.h	2013-11-22 03:17:15 UTC (rev 159671)
@@ -56,11 +56,8 @@
     virtual void getIncludedIntervals(LayoutUnit logicalTop, LayoutUnit logicalHeight, SegmentList&) const OVERRIDE;
     virtual bool firstIncludedIntervalLogicalTop(LayoutUnit minLogicalIntervalTop, const LayoutSize& minLogicalIntervalSize, LayoutUnit&) const OVERRIDE;
 
-    LayoutUnit logicalRx() const { return m_bounds.rx(); }
-    LayoutUnit logicalRy() const { return m_bounds.ry(); }
+    virtual void buildPath(Path&) const OVERRIDE;
 
-    virtual ShapeType type() const OVERRIDE { return Shape::RoundedRectangleType; }
-
 private:
     class ShapeBounds : public FloatRect {
     public:

Modified: trunk/Source/WebCore/rendering/shapes/Shape.h (159670 => 159671)


--- trunk/Source/WebCore/rendering/shapes/Shape.h	2013-11-22 03:12:13 UTC (rev 159670)
+++ trunk/Source/WebCore/rendering/shapes/Shape.h	2013-11-22 03:17:15 UTC (rev 159671)
@@ -32,6 +32,7 @@
 
 #include "BasicShapes.h"
 #include "LayoutRect.h"
+#include "Path.h"
 #include "StyleImage.h"
 #include "WritingMode.h"
 #include <wtf/PassOwnPtr.h>
@@ -60,12 +61,6 @@
 
 class Shape {
 public:
-    enum ShapeType {
-        RoundedRectangleType,
-        PolygonType,
-        RasterType
-    };
-
     static PassOwnPtr<Shape> createShape(const BasicShape*, const LayoutSize& logicalBoxSize, WritingMode, Length margin, Length padding);
     static PassOwnPtr<Shape> createShape(const StyleImage*, float threshold, const LayoutSize& logicalBoxSize, WritingMode, Length margin, Length padding);
     static PassOwnPtr<Shape> createShape(const LayoutSize& logicalBoxSize, const LayoutSize& logicalRadii, WritingMode, Length margin, Length padding);
@@ -81,7 +76,7 @@
     bool lineOverlapsShapeMarginBounds(LayoutUnit lineTop, LayoutUnit lineHeight) const { return lineOverlapsBoundingBox(lineTop, lineHeight, shapeMarginLogicalBoundingBox()); }
     bool lineOverlapsShapePaddingBounds(LayoutUnit lineTop, LayoutUnit lineHeight) const { return lineOverlapsBoundingBox(lineTop, lineHeight, shapePaddingLogicalBoundingBox()); }
 
-    virtual ShapeType type() const = 0;
+    virtual void buildPath(Path&) const = 0;
 
 protected:
     float shapeMargin() const { return m_margin; }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to