Skip to content
Permalink
Browse files
[CSS Shapes] Refactor getExcludedIntervals since only one LineSegment…
… is ever returned

https://bugs.webkit.org/show_bug.cgi?id=135757

Reviewed by Zoltan Horvath.

The interface for getExcludedIntervals was designed when shape-inside
was still a thing, and it was possible for a line in a shape to have
multiple segments. shape-outside can only have one segment per line,
so this refactors the code to simplify and reflect that reality.

No new test, no behavior change.

* rendering/shapes/BoxShape.cpp:
(WebCore::BoxShape::getExcludedInterval):
(WebCore::BoxShape::getExcludedIntervals): Deleted.
* rendering/shapes/BoxShape.h:
* rendering/shapes/PolygonShape.cpp:
(WebCore::PolygonShape::getExcludedInterval):
(WebCore::PolygonShape::getExcludedIntervals): Deleted.
* rendering/shapes/PolygonShape.h:
* rendering/shapes/RasterShape.cpp:
(WebCore::RasterShape::getExcludedInterval):
(WebCore::RasterShape::getExcludedIntervals): Deleted.
* rendering/shapes/RasterShape.h:
* rendering/shapes/RectangleShape.cpp:
(WebCore::RectangleShape::getExcludedInterval):
(WebCore::RectangleShape::getExcludedIntervals): Deleted.
* rendering/shapes/RectangleShape.h:
* rendering/shapes/Shape.h:
(WebCore::LineSegment::LineSegment):
* rendering/shapes/ShapeOutsideInfo.cpp:
(WebCore::ShapeOutsideInfo::logicalLeftOffset):
(WebCore::ShapeOutsideInfo::updateDeltasForContainingBlockLine):
(WebCore::ShapeOutsideInfo::computeSegmentsForLine): Deleted.
* rendering/shapes/ShapeOutsideInfo.h:


Canonical link: https://commits.webkit.org/153644@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@172357 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
bemjb committed Aug 8, 2014
1 parent 8aa5e2a commit 2aa918f96149997078d911a99012567829532cba
Showing 12 changed files with 90 additions and 63 deletions.
@@ -1,3 +1,41 @@
2014-08-08 Bem Jones-Bey <bjonesbe@adobe.com>

[CSS Shapes] Refactor getExcludedIntervals since only one LineSegment is ever returned
https://bugs.webkit.org/show_bug.cgi?id=135757

Reviewed by Zoltan Horvath.

The interface for getExcludedIntervals was designed when shape-inside
was still a thing, and it was possible for a line in a shape to have
multiple segments. shape-outside can only have one segment per line,
so this refactors the code to simplify and reflect that reality.

No new test, no behavior change.

* rendering/shapes/BoxShape.cpp:
(WebCore::BoxShape::getExcludedInterval):
(WebCore::BoxShape::getExcludedIntervals): Deleted.
* rendering/shapes/BoxShape.h:
* rendering/shapes/PolygonShape.cpp:
(WebCore::PolygonShape::getExcludedInterval):
(WebCore::PolygonShape::getExcludedIntervals): Deleted.
* rendering/shapes/PolygonShape.h:
* rendering/shapes/RasterShape.cpp:
(WebCore::RasterShape::getExcludedInterval):
(WebCore::RasterShape::getExcludedIntervals): Deleted.
* rendering/shapes/RasterShape.h:
* rendering/shapes/RectangleShape.cpp:
(WebCore::RectangleShape::getExcludedInterval):
(WebCore::RectangleShape::getExcludedIntervals): Deleted.
* rendering/shapes/RectangleShape.h:
* rendering/shapes/Shape.h:
(WebCore::LineSegment::LineSegment):
* rendering/shapes/ShapeOutsideInfo.cpp:
(WebCore::ShapeOutsideInfo::logicalLeftOffset):
(WebCore::ShapeOutsideInfo::updateDeltasForContainingBlockLine):
(WebCore::ShapeOutsideInfo::computeSegmentsForLine): Deleted.
* rendering/shapes/ShapeOutsideInfo.h:

2014-08-08 Brian J. Burg <burg@cs.washington.edu>

Web Inspector: add debugging flag to InspectorTest for unbuffered logging to stderr
@@ -12,7 +12,7 @@
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials
* provided with the distribution.
*
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
@@ -112,28 +112,24 @@ FloatRoundedRect BoxShape::shapeMarginBounds() const
return marginBounds;
}

void BoxShape::getExcludedIntervals(LayoutUnit logicalTop, LayoutUnit logicalHeight, SegmentList& result) const
LineSegment BoxShape::getExcludedInterval(LayoutUnit logicalTop, LayoutUnit logicalHeight) const
{
const FloatRoundedRect& marginBounds = shapeMarginBounds();
if (marginBounds.isEmpty() || !lineOverlapsShapeMarginBounds(logicalTop, logicalHeight))
return;
return LineSegment();

float y1 = logicalTop;
float y2 = logicalTop + logicalHeight;
const FloatRect& rect = marginBounds.rect();

if (!marginBounds.isRounded()) {
result.append(LineSegment(rect.x(), rect.maxX()));
return;
}
if (!marginBounds.isRounded())
return LineSegment(rect.x(), rect.maxX());

float topCornerMaxY = std::max<float>(marginBounds.topLeftCorner().maxY(), marginBounds.topRightCorner().maxY());
float bottomCornerMinY = std::min<float>(marginBounds.bottomLeftCorner().y(), marginBounds.bottomRightCorner().y());

if (topCornerMaxY <= bottomCornerMinY && y1 <= topCornerMaxY && y2 >= bottomCornerMinY) {
result.append(LineSegment(rect.x(), rect.maxX()));
return;
}
if (topCornerMaxY <= bottomCornerMinY && y1 <= topCornerMaxY && y2 >= bottomCornerMinY)
return LineSegment(rect.x(), rect.maxX());

float x1 = rect.maxX();
float x2 = rect.x();
@@ -157,7 +153,7 @@ void BoxShape::getExcludedIntervals(LayoutUnit logicalTop, LayoutUnit logicalHei
}

ASSERT(x2 >= x1);
result.append(LineSegment(x1, x2));
return LineSegment(x1, x2);
}

void BoxShape::buildDisplayPaths(DisplayPaths& paths) const
@@ -12,7 +12,7 @@
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials
* provided with the distribution.
*
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
@@ -49,7 +49,7 @@ class BoxShape : public Shape {

virtual LayoutRect shapeMarginLogicalBoundingBox() const override;
virtual bool isEmpty() const override { return m_bounds.isEmpty(); }
virtual void getExcludedIntervals(LayoutUnit logicalTop, LayoutUnit logicalHeight, SegmentList&) const override;
virtual LineSegment getExcludedInterval(LayoutUnit logicalTop, LayoutUnit logicalHeight) const override;

virtual void buildDisplayPaths(DisplayPaths&) const override;

@@ -12,7 +12,7 @@
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials
* provided with the distribution.
*
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
@@ -117,17 +117,17 @@ LayoutRect PolygonShape::shapeMarginLogicalBoundingBox() const
return LayoutRect(box);
}

void PolygonShape::getExcludedIntervals(LayoutUnit logicalTop, LayoutUnit logicalHeight, SegmentList& result) const
LineSegment PolygonShape::getExcludedInterval(LayoutUnit logicalTop, LayoutUnit logicalHeight) const
{
float y1 = logicalTop;
float y2 = logicalTop + logicalHeight;

if (m_polygon.isEmpty() || !m_polygon.boundingBox().overlapsYRange(y1 - shapeMargin(), y2 + shapeMargin()))
return;
return LineSegment();

Vector<const FloatPolygonEdge*> overlappingEdges;
if (!m_polygon.overlappingEdges(y1 - shapeMargin(), y2 + shapeMargin(), overlappingEdges))
return;
return LineSegment();

FloatShapeInterval excludedInterval;
for (unsigned i = 0; i < overlappingEdges.size(); i++) {
@@ -143,8 +143,10 @@ void PolygonShape::getExcludedIntervals(LayoutUnit logicalTop, LayoutUnit logica
}
}

if (!excludedInterval.isEmpty())
result.append(LineSegment(excludedInterval.x1(), excludedInterval.x2()));
if (excludedInterval.isEmpty())
return LineSegment();

return LineSegment(excludedInterval.x1(), excludedInterval.x2());
}

void PolygonShape::buildDisplayPaths(DisplayPaths& paths) const
@@ -12,7 +12,7 @@
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials
* provided with the distribution.
*
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
@@ -67,7 +67,7 @@ class PolygonShape : public Shape {

virtual LayoutRect shapeMarginLogicalBoundingBox() const override;
virtual bool isEmpty() const override { return m_polygon.isEmpty(); }
virtual void getExcludedIntervals(LayoutUnit logicalTop, LayoutUnit logicalHeight, SegmentList&) const override;
virtual LineSegment getExcludedInterval(LayoutUnit logicalTop, LayoutUnit logicalHeight) const override;

virtual void buildDisplayPaths(DisplayPaths&) const override;

@@ -12,7 +12,7 @@
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials
* provided with the distribution.
*
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
@@ -149,17 +149,17 @@ const RasterShapeIntervals& RasterShape::marginIntervals() const
return *m_marginIntervals;
}

void RasterShape::getExcludedIntervals(LayoutUnit logicalTop, LayoutUnit logicalHeight, SegmentList& result) const
LineSegment RasterShape::getExcludedInterval(LayoutUnit logicalTop, LayoutUnit logicalHeight) const
{
const RasterShapeIntervals& intervals = marginIntervals();
if (intervals.isEmpty())
return;
return LineSegment();

int y1 = logicalTop;
int y2 = logicalTop + logicalHeight;
ASSERT(y2 >= y1);
if (y2 < intervals.bounds().y() || y1 >= intervals.bounds().maxY())
return;
return LineSegment();

y1 = std::max(y1, intervals.bounds().y());
y2 = std::min(y2, intervals.bounds().maxY());
@@ -172,7 +172,7 @@ void RasterShape::getExcludedIntervals(LayoutUnit logicalTop, LayoutUnit logical
excludedInterval.unite(intervals.intervalAt(y));
}

result.append(LineSegment(excludedInterval.x1(), excludedInterval.x2()));
return LineSegment(excludedInterval.x1(), excludedInterval.x2());
}

} // namespace WebCore
@@ -12,7 +12,7 @@
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials
* provided with the distribution.
*
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
@@ -61,7 +61,7 @@ class RasterShapeIntervals {
ASSERT(y + m_offset >= 0 && static_cast<unsigned>(y + m_offset) < m_intervals.size());
return m_intervals[y + m_offset];
}

std::unique_ptr<RasterShapeIntervals> computeShapeMarginIntervals(int shapeMargin) const;
void buildBoundsPath(Path&) const;

@@ -88,7 +88,7 @@ class RasterShape : public Shape {

virtual LayoutRect shapeMarginLogicalBoundingBox() const override { return static_cast<LayoutRect>(marginIntervals().bounds()); }
virtual bool isEmpty() const override { return m_intervals->isEmpty(); }
virtual void getExcludedIntervals(LayoutUnit logicalTop, LayoutUnit logicalHeight, SegmentList&) const override;
virtual LineSegment getExcludedInterval(LayoutUnit logicalTop, LayoutUnit logicalHeight) const override;

virtual void buildDisplayPaths(DisplayPaths& paths) const override
{
@@ -12,7 +12,7 @@
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials
* provided with the distribution.
*
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
@@ -53,17 +53,17 @@ FloatRect RectangleShape::shapeMarginBounds() const
return FloatRect(boundsX, boundsY, boundsWidth, boundsHeight);
}

void RectangleShape::getExcludedIntervals(LayoutUnit logicalTop, LayoutUnit logicalHeight, SegmentList& result) const
LineSegment RectangleShape::getExcludedInterval(LayoutUnit logicalTop, LayoutUnit logicalHeight) const
{
const FloatRect& bounds = shapeMarginBounds();
if (bounds.isEmpty())
return;
return LineSegment();

float y1 = logicalTop;
float y2 = logicalTop + logicalHeight;

if (y2 < bounds.y() || y1 >= bounds.maxY())
return;
return LineSegment();

float x1 = bounds.x();
float x2 = bounds.maxX();
@@ -85,7 +85,7 @@ void RectangleShape::getExcludedIntervals(LayoutUnit logicalTop, LayoutUnit logi
}
}

result.append(LineSegment(x1, x2));
return LineSegment(x1, x2);
}

void RectangleShape::buildDisplayPaths(DisplayPaths& paths) const
@@ -12,7 +12,7 @@
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials
* provided with the distribution.
*
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
@@ -49,7 +49,7 @@ class RectangleShape : public Shape {

virtual LayoutRect shapeMarginLogicalBoundingBox() const override { return static_cast<LayoutRect>(shapeMarginBounds()); }
virtual bool isEmpty() const override { return m_bounds.isEmpty(); }
virtual void getExcludedIntervals(LayoutUnit logicalTop, LayoutUnit logicalHeight, SegmentList&) const override;
virtual LineSegment getExcludedInterval(LayoutUnit logicalTop, LayoutUnit logicalHeight) const override;

virtual void buildDisplayPaths(DisplayPaths&) const override;

@@ -12,7 +12,7 @@
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials
* provided with the distribution.
*
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
@@ -37,23 +37,29 @@
namespace WebCore {

struct LineSegment {
LineSegment()
: logicalLeft(0)
, logicalRight(0)
, isValid(false)
{
}

LineSegment(float logicalLeft, float logicalRight)
: logicalLeft(logicalLeft)
, logicalRight(logicalRight)
, isValid(true)
{
}

float logicalLeft;
float logicalRight;
bool isValid;
};

class BasicShape;
class Image;
class RoundedRect;

typedef Vector<LineSegment> SegmentList;


// A representation of a BasicShape that enables layout code to determine how to break a line up into segments
// that will fit within or around a shape. The line is defined by a pair of logical Y coordinates and the
// computed segments are returned as pairs of logical X coordinates. The BasicShape itself is defined in
@@ -74,7 +80,7 @@ class Shape {

virtual LayoutRect shapeMarginLogicalBoundingBox() const = 0;
virtual bool isEmpty() const = 0;
virtual void getExcludedIntervals(LayoutUnit logicalTop, LayoutUnit logicalHeight, SegmentList&) const = 0;
virtual LineSegment getExcludedInterval(LayoutUnit logicalTop, LayoutUnit logicalHeight) const = 0;

bool lineOverlapsShapeMarginBounds(LayoutUnit lineTop, LayoutUnit lineHeight) const { return lineOverlapsBoundingBox(lineTop, lineHeight, shapeMarginLogicalBoundingBox()); }

0 comments on commit 2aa918f

Please sign in to comment.