Skip to content
Permalink
Browse files
Subpixel layout: Cleanup snapSizeToPixel/snapSizeToDevicePixel.
https://bugs.webkit.org/show_bug.cgi?id=136264

Reviewed by Simon Fraser.

1. Align snapSizeToPixel()/snapSizeToDevicePixel() function names with the rest of snapping
functions. ->snappedIntSize()/snapSizeToDevicePixel().
2. Operate on LayoutSize/LayoutPoint instead of LayoutUnit/LayoutUnit to reflect functionality.

Covered by existing tests.

Source/WebCore:

* platform/LayoutUnit.h:
(WebCore::snapSizeToPixel): Deleted.
(WebCore::snapSizeToDevicePixel): Deleted.
* platform/graphics/LayoutPoint.h:
(WebCore::snappedIntSize):
(WebCore::snapSizeToDevicePixel):
(WebCore::pixelSnappedIntSize): Deleted.
* platform/graphics/LayoutRect.h:
(WebCore::LayoutRect::pixelSnappedSize):
(WebCore::LayoutRect::pixelSnappedWidth):
(WebCore::LayoutRect::pixelSnappedHeight):
(WebCore::pixelSnappedIntRect):
(WebCore::pixelSnappedIntRectFromEdges):
(WebCore::pixelSnappedForPainting):
(WebCore::directionalPixelSnappedForPainting):
* rendering/RenderBox.cpp:
(WebCore::RenderBox::pixelSnappedClientWidth):
(WebCore::RenderBox::pixelSnappedClientHeight):
(WebCore::RenderBox::pixelSnappedOffsetWidth):
(WebCore::RenderBox::pixelSnappedOffsetHeight):
(WebCore::RenderBox::scrollWidth):
(WebCore::RenderBox::scrollHeight):
* rendering/RenderBoxModelObject.cpp:
(WebCore::RenderBoxModelObject::pixelSnappedOffsetWidth):
(WebCore::RenderBoxModelObject::pixelSnappedOffsetHeight):
* rendering/RenderLayer.cpp:
(WebCore::RenderLayer::updateLayerPosition):
(WebCore::RenderLayer::scrollWidth):
(WebCore::RenderLayer::scrollHeight):
* rendering/RenderTreeAsText.cpp:
(WebCore::writeLayers):

Tools:

* TestWebKitAPI/Tests/WebCore/LayoutUnit.cpp:
(TestWebKitAPI::TEST): Deleted.

LayoutTests:

* cssom/subpixel-offsetleft-top-width-height-values-expected.txt:
* platform/mac/fast/css/vertical-text-overflow-ellipsis-text-align-center-expected.txt:


Canonical link: https://commits.webkit.org/154151@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@173049 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
alanbujtas committed Aug 28, 2014
1 parent abd2304 commit 6d12cb3386465d8b3d696f63e167ec38ece6673c
@@ -1,3 +1,19 @@
2014-08-27 Zalan Bujtas <zalan@apple.com>

Subpixel layout: Cleanup snapSizeToPixel/snapSizeToDevicePixel.
https://bugs.webkit.org/show_bug.cgi?id=136264

Reviewed by Simon Fraser.

1. Align snapSizeToPixel()/snapSizeToDevicePixel() function names with the rest of snapping
functions. ->snappedIntSize()/snapSizeToDevicePixel().
2. Operate on LayoutSize/LayoutPoint instead of LayoutUnit/LayoutUnit to reflect functionality.

Covered by existing tests.

* cssom/subpixel-offsetleft-top-width-height-values-expected.txt:
* platform/mac/fast/css/vertical-text-overflow-ellipsis-text-align-center-expected.txt:

2014-08-27 Daniel Bates <dabates@apple.com>

Scrollbar corner can be drawn outside containing frame

Large diffs are not rendered by default.

@@ -27,7 +27,7 @@ layer at (0,0) size 785x2974
RenderBlock {H3} at (0,2595) size 769x23
RenderText {#text} at (0,0) size 509x22
text run at (0,0) width 509: "Right-To-Left containing replaced content blocking the ellipsis"
layer at (8,49) size 20x310 clip at (9,50) size 18x308 scrollHeight 719
layer at (8,49) size 20x310 clip at (9,50) size 18x308 scrollHeight 720
RenderBlock {DIV} at (0,40) size 20x311 [border: (1px solid #000000)]
RenderText {#text} at (1,1) size 18x720
text run at (1,1) width 719: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus vitae eros non libero faucibus sagittis sed ut eros."
@@ -52,7 +52,7 @@ layer at (8,790) size 31x310 clip at (9,791) size 29x308 scrollHeight 749
RenderImage {IMG} at (1,182) size 25x26
RenderText {#text} at (12,207) size 18x543
text run at (12,207) width 542: " consectetur adipiscing elit. Vivamus vitae eros non libero faucibus sagittis sed ut eros."
layer at (8,1161) size 31x310 clip at (9,1162) size 29x308 scrollHeight 744
layer at (8,1161) size 31x310 clip at (9,1162) size 29x308 scrollHeight 745
RenderBlock {DIV} at (0,1152) size 31x311 [border: (1px solid #000000)]
RenderText {#text} at (12,1) size 18x272
text run at (12,1) width 271: "Lorem ipsum dolor sit amet, consectetur ad"
@@ -1,3 +1,48 @@
2014-08-27 Zalan Bujtas <zalan@apple.com>

Subpixel layout: Cleanup snapSizeToPixel/snapSizeToDevicePixel.
https://bugs.webkit.org/show_bug.cgi?id=136264

Reviewed by Simon Fraser.

1. Align snapSizeToPixel()/snapSizeToDevicePixel() function names with the rest of snapping
functions. ->snappedIntSize()/snapSizeToDevicePixel().
2. Operate on LayoutSize/LayoutPoint instead of LayoutUnit/LayoutUnit to reflect functionality.

Covered by existing tests.

* platform/LayoutUnit.h:
(WebCore::snapSizeToPixel): Deleted.
(WebCore::snapSizeToDevicePixel): Deleted.
* platform/graphics/LayoutPoint.h:
(WebCore::snappedIntSize):
(WebCore::snapSizeToDevicePixel):
(WebCore::pixelSnappedIntSize): Deleted.
* platform/graphics/LayoutRect.h:
(WebCore::LayoutRect::pixelSnappedSize):
(WebCore::LayoutRect::pixelSnappedWidth):
(WebCore::LayoutRect::pixelSnappedHeight):
(WebCore::pixelSnappedIntRect):
(WebCore::pixelSnappedIntRectFromEdges):
(WebCore::pixelSnappedForPainting):
(WebCore::directionalPixelSnappedForPainting):
* rendering/RenderBox.cpp:
(WebCore::RenderBox::pixelSnappedClientWidth):
(WebCore::RenderBox::pixelSnappedClientHeight):
(WebCore::RenderBox::pixelSnappedOffsetWidth):
(WebCore::RenderBox::pixelSnappedOffsetHeight):
(WebCore::RenderBox::scrollWidth):
(WebCore::RenderBox::scrollHeight):
* rendering/RenderBoxModelObject.cpp:
(WebCore::RenderBoxModelObject::pixelSnappedOffsetWidth):
(WebCore::RenderBoxModelObject::pixelSnappedOffsetHeight):
* rendering/RenderLayer.cpp:
(WebCore::RenderLayer::updateLayerPosition):
(WebCore::RenderLayer::scrollWidth):
(WebCore::RenderLayer::scrollHeight):
* rendering/RenderTreeAsText.cpp:
(WebCore::writeLayers):

2014-08-27 Zalan Bujtas <zalan@apple.com>

Subpixel layout: Rename LayoutRect's device pixel snapping functions.
@@ -866,12 +866,6 @@ inline float& operator/=(float& a, const LayoutUnit& b)
return a;
}

inline int snapSizeToPixel(LayoutUnit size, LayoutUnit location)
{
LayoutUnit fraction = location.fraction();
return (fraction + size).round() - fraction.round();
}

inline int roundToInt(LayoutUnit value)
{
return value.round();
@@ -906,12 +900,6 @@ inline float ceilToDevicePixel(LayoutUnit value, float pixelSnappingFactor)
return ceilf((value.rawValue() * pixelSnappingFactor) / kEffectiveFixedPointDenominator) / pixelSnappingFactor;
}

inline float snapSizeToDevicePixel(LayoutUnit size, LayoutUnit location, float pixelSnappingFactor)
{
LayoutUnit fraction = location.fraction();
return roundToDevicePixel(fraction + size, pixelSnappingFactor) - roundToDevicePixel(fraction, pixelSnappingFactor);
}

inline LayoutUnit absoluteValue(const LayoutUnit& value)
{
return value.abs();
@@ -179,9 +179,14 @@ inline LayoutPoint ceiledLayoutPoint(const FloatPoint& p)
return LayoutPoint(LayoutUnit::fromFloatCeil(p.x()), LayoutUnit::fromFloatCeil(p.y()));
}

inline IntSize pixelSnappedIntSize(const LayoutSize& s, const LayoutPoint& p)
inline IntSize snappedIntSize(const LayoutSize& size, const LayoutPoint& location)
{
return IntSize(snapSizeToPixel(s.width(), p.x()), snapSizeToPixel(s.height(), p.y()));
auto snap = [] (LayoutUnit a, LayoutUnit b) {
LayoutUnit fraction = b.fraction();
return roundToInt(fraction + a) - roundToInt(fraction);
};

return IntSize(snap(size.width(), location.x()), snap(size.height(), location.y()));
}

inline FloatPoint roundPointToDevicePixels(const LayoutPoint& point, float pixelSnappingFactor, bool directionalRoundingToRight = true, bool directionalRoundingToBottom = true)
@@ -199,6 +204,16 @@ inline FloatPoint ceilPointToDevicePixels(const LayoutPoint& point, float pixelS
return FloatPoint(ceilToDevicePixel(point.x(), pixelSnappingFactor), ceilToDevicePixel(point.y(), pixelSnappingFactor));
}

inline FloatSize snapSizeToDevicePixel(const LayoutSize& size, const LayoutPoint& location, float pixelSnappingFactor)
{
auto snap = [&] (LayoutUnit a, LayoutUnit b) {
LayoutUnit fraction = b.fraction();
return roundToDevicePixel(fraction + a, pixelSnappingFactor) - roundToDevicePixel(fraction, pixelSnappingFactor);
};

return FloatSize(snap(size.width(), location.x()), snap(size.height(), location.y()));
}

} // namespace WebCore

#endif // LayoutPoint_h
@@ -56,7 +56,7 @@ class LayoutRect {
LayoutSize size() const { return m_size; }

IntPoint pixelSnappedLocation() const { return roundedIntPoint(m_location); }
IntSize pixelSnappedSize() const { return IntSize(snapSizeToPixel(m_size.width(), m_location.x()), snapSizeToPixel(m_size.height(), m_location.y())); }
IntSize pixelSnappedSize() const { return snappedIntSize(m_size, m_location); }

void setLocation(const LayoutPoint& location) { m_location = location; }
void setSize(const LayoutSize& size) { m_size = size; }
@@ -70,8 +70,8 @@ class LayoutRect {

int pixelSnappedX() const { return x().round(); }
int pixelSnappedY() const { return y().round(); }
int pixelSnappedWidth() const { return snapSizeToPixel(width(), x()); }
int pixelSnappedHeight() const { return snapSizeToPixel(height(), y()); }
int pixelSnappedWidth() const { return snappedIntSize(m_size, m_location).width(); }
int pixelSnappedHeight() const { return snappedIntSize(m_size, m_location).height(); }
int pixelSnappedMaxX() const { return (m_location.x() + m_size.width()).round(); }
int pixelSnappedMaxY() const { return (m_location.y() + m_size.height()).round(); }

@@ -206,30 +206,29 @@ WEBCORE_EXPORT LayoutRect enclosingLayoutRect(const FloatRect&);

inline IntRect snappedIntRect(const LayoutRect& rect)
{
return IntRect(roundedIntPoint(rect.location()), IntSize(snapSizeToPixel(rect.width(), rect.x()), snapSizeToPixel(rect.height(), rect.y())));
return IntRect(roundedIntPoint(rect.location()), snappedIntSize(rect.size(), rect.location()));
}

inline IntRect snappedIntRect(LayoutUnit left, LayoutUnit top, LayoutUnit width, LayoutUnit height)
{
return IntRect(left.round(), top.round(), snapSizeToPixel(width, left), snapSizeToPixel(height, top));
return IntRect(IntPoint(left.round(), top.round()), snappedIntSize(LayoutSize(width, height), LayoutPoint(left, top)));
}

inline IntRect snappedIntRectFromEdges(LayoutUnit left, LayoutUnit top, LayoutUnit right, LayoutUnit bottom)
{
return IntRect(left.round(), top.round(), snapSizeToPixel(right - left, left), snapSizeToPixel(bottom - top, top));
return IntRect(IntPoint(left.round(), top.round()), snappedIntSize(LayoutSize(right - left, bottom - top), LayoutPoint(left, top)));
}

inline IntRect snappedIntRect(LayoutPoint location, LayoutSize size)
{
return IntRect(roundedIntPoint(location), pixelSnappedIntSize(size, location));
return IntRect(roundedIntPoint(location), snappedIntSize(size, location));
}

FloatRect encloseRectToDevicePixels(const LayoutRect&, float pixelSnappingFactor);

inline FloatRect snapRectToDevicePixels(const LayoutRect& rect, float pixelSnappingFactor)
{
return FloatRect(roundToDevicePixel(rect.x(), pixelSnappingFactor), roundToDevicePixel(rect.y(), pixelSnappingFactor),
snapSizeToDevicePixel(rect.width(), rect.x(), pixelSnappingFactor), snapSizeToDevicePixel(rect.height(), rect.y(), pixelSnappingFactor));
return FloatRect(FloatPoint(roundToDevicePixel(rect.x(), pixelSnappingFactor), roundToDevicePixel(rect.y(), pixelSnappingFactor)), snapSizeToDevicePixel(rect.size(), rect.location(), pixelSnappingFactor));
}

inline FloatRect snapRectToDevicePixels(LayoutUnit x, LayoutUnit y, LayoutUnit width, LayoutUnit height, float pixelSnappingFactor)
@@ -242,9 +241,8 @@ inline FloatRect snapRectToDevicePixelsWithWritingDirection(const LayoutRect& re
{
if (!ltr) {
FloatPoint snappedTopRight = roundPointToDevicePixels(rect.maxXMinYCorner(), deviceScaleFactor, ltr);
float snappedWidth = snapSizeToDevicePixel(rect.width(), rect.maxX(), deviceScaleFactor);
float snappedHeight = snapSizeToDevicePixel(rect.height(), rect.y(), deviceScaleFactor);
return FloatRect(snappedTopRight.x() - snappedWidth, snappedTopRight.y(), snappedWidth, snappedHeight);
FloatSize snappedSize = snapSizeToDevicePixel(rect.size(), rect.maxXMinYCorner(), deviceScaleFactor);
return FloatRect(snappedTopRight.x() - snappedSize.width(), snappedTopRight.y(), snappedSize.width(), snappedSize.height());
}
return snapRectToDevicePixels(rect, deviceScaleFactor);
}
@@ -522,22 +522,26 @@ LayoutUnit RenderBox::clientHeight() const

int RenderBox::pixelSnappedClientWidth() const
{
return snapSizeToPixel(clientWidth(), x() + clientLeft());
// FIXME: This should use snappedIntSize() instead with absolute coordinates.
return roundToInt(clientWidth());
}

int RenderBox::pixelSnappedClientHeight() const
{
return snapSizeToPixel(clientHeight(), y() + clientTop());
// FIXME: This should use snappedIntSize() instead with absolute coordinates.
return roundToInt(clientHeight());
}

int RenderBox::pixelSnappedOffsetWidth() const
{
return snapSizeToPixel(offsetWidth(), x() + clientLeft());
// FIXME: This should use snappedIntSize() instead with absolute coordinates.
return roundToInt(offsetWidth());
}

int RenderBox::pixelSnappedOffsetHeight() const
{
return snapSizeToPixel(offsetHeight(), y() + clientTop());
// FIXME: This should use snappedIntSize() instead with absolute coordinates.
return roundToInt(offsetHeight());
}

int RenderBox::scrollWidth() const
@@ -546,8 +550,10 @@ int RenderBox::scrollWidth() const
return layer()->scrollWidth();
// For objects with visible overflow, this matches IE.
// FIXME: Need to work right with writing modes.
if (style().isLeftToRightDirection())
return snapSizeToPixel(std::max(clientWidth(), layoutOverflowRect().maxX() - borderLeft()), x() + clientLeft());
if (style().isLeftToRightDirection()) {
// FIXME: This should use snappedIntSize() instead with absolute coordinates.
return roundToInt(std::max(clientWidth(), layoutOverflowRect().maxX() - borderLeft()));
}
return clientWidth() - std::min<LayoutUnit>(0, layoutOverflowRect().x() - borderLeft());
}

@@ -557,7 +563,8 @@ int RenderBox::scrollHeight() const
return layer()->scrollHeight();
// For objects with visible overflow, this matches IE.
// FIXME: Need to work right with writing modes.
return snapSizeToPixel(std::max(clientHeight(), layoutOverflowRect().maxY() - borderTop()), y() + clientTop());
// FIXME: This should use snappedIntSize() instead with absolute coordinates.
return roundToInt(std::max(clientHeight(), layoutOverflowRect().maxY() - borderTop()));
}

int RenderBox::scrollLeft() const
@@ -494,12 +494,14 @@ LayoutUnit RenderBoxModelObject::offsetTop() const

int RenderBoxModelObject::pixelSnappedOffsetWidth() const
{
return snapSizeToPixel(offsetWidth(), offsetLeft());
// FIXME: This should use snappedIntSize() instead with absolute coordinates.
return roundToInt(offsetWidth());
}

int RenderBoxModelObject::pixelSnappedOffsetHeight() const
{
return snapSizeToPixel(offsetHeight(), offsetTop());
// FIXME: This should use snappedIntSize() instead with absolute coordinates.
return roundToInt(offsetHeight());
}

LayoutUnit RenderBoxModelObject::computedCSSPadding(const Length& padding) const
@@ -1226,7 +1226,7 @@ bool RenderLayer::updateLayerPosition()
localPoint += inlineBoundingBoxOffset;
} else if (RenderBox* box = renderBox()) {
// FIXME: Is snapping the size really needed here for the RenderBox case?
setSize(pixelSnappedIntSize(box->size(), box->location()));
setSize(snappedIntSize(box->size(), box->location()));
localPoint += box->topLeftLocationOffset();
}

@@ -3162,15 +3162,17 @@ int RenderLayer::scrollWidth() const
ASSERT(renderBox());
if (m_scrollDimensionsDirty)
const_cast<RenderLayer*>(this)->computeScrollDimensions();
return snapSizeToPixel(m_scrollSize.width(), renderBox()->clientLeft() + renderBox()->x());
// FIXME: This should use snappedIntSize() instead with absolute coordinates.
return roundToInt(m_scrollSize.width());
}

int RenderLayer::scrollHeight() const
{
ASSERT(renderBox());
if (m_scrollDimensionsDirty)
const_cast<RenderLayer*>(this)->computeScrollDimensions();
return snapSizeToPixel(m_scrollSize.height(), renderBox()->clientTop() + renderBox()->y());
// FIXME: This should use snappedIntSize() instead with absolute coordinates.
return roundToInt(m_scrollSize.height());
}

LayoutUnit RenderLayer::overflowTop() const
@@ -735,7 +735,7 @@ static void writeLayers(TextStream& ts, const RenderLayer* rootLayer, RenderLaye
if (rootLayer == l) {
paintDirtyRect.setWidth(std::max<LayoutUnit>(paintDirtyRect.width(), rootLayer->renderBox()->layoutOverflowRect().maxX()));
paintDirtyRect.setHeight(std::max<LayoutUnit>(paintDirtyRect.height(), rootLayer->renderBox()->layoutOverflowRect().maxY()));
l->setSize(l->size().expandedTo(pixelSnappedIntSize(maxLayoutOverflow(l->renderBox()), LayoutPoint(0, 0))));
l->setSize(l->size().expandedTo(snappedIntSize(maxLayoutOverflow(l->renderBox()), LayoutPoint(0, 0))));
}

// Calculate the clip rects we should use.
@@ -1,3 +1,19 @@
2014-08-27 Zalan Bujtas <zalan@apple.com>

Subpixel layout: Cleanup snapSizeToPixel/snapSizeToDevicePixel.
https://bugs.webkit.org/show_bug.cgi?id=136264

Reviewed by Simon Fraser.

1. Align snapSizeToPixel()/snapSizeToDevicePixel() function names with the rest of snapping
functions. ->snappedIntSize()/snapSizeToDevicePixel().
2. Operate on LayoutSize/LayoutPoint instead of LayoutUnit/LayoutUnit to reflect functionality.

Covered by existing tests.

* TestWebKitAPI/Tests/WebCore/LayoutUnit.cpp:
(TestWebKitAPI::TEST): Deleted.

2014-08-27 Alexey Proskuryakov <ap@apple.com>

EWS status link at build.webkit.org/dashboard is incorrect until EWS pop-up is opened
@@ -103,28 +103,6 @@ TEST(WebCoreLayoutUnit, LayoutUnitRounding)
ASSERT_EQ(LayoutUnit::fromFloatRound(1.51f).round(), 2);
}

TEST(WebCoreLayoutUnit, LayoutUnitSnapSizeToPixel)
{
ASSERT_EQ(snapSizeToPixel(LayoutUnit(1), LayoutUnit(0)), 1);
ASSERT_EQ(snapSizeToPixel(LayoutUnit(1), LayoutUnit(0.5)), 1);
ASSERT_EQ(snapSizeToPixel(LayoutUnit(1.5), LayoutUnit(0)), 2);
ASSERT_EQ(snapSizeToPixel(LayoutUnit(1.5), LayoutUnit(0.49)), 2);
ASSERT_EQ(snapSizeToPixel(LayoutUnit(1.5), LayoutUnit(0.5)), 1);
ASSERT_EQ(snapSizeToPixel(LayoutUnit(1.5), LayoutUnit(0.75)), 1);
ASSERT_EQ(snapSizeToPixel(LayoutUnit(1.5), LayoutUnit(0.99)), 1);
ASSERT_EQ(snapSizeToPixel(LayoutUnit(1.5), LayoutUnit(1)), 2);

ASSERT_EQ(snapSizeToPixel(LayoutUnit(0.5), LayoutUnit(1.5)), 0);
ASSERT_EQ(snapSizeToPixel(LayoutUnit(0.99), LayoutUnit(1.5)), 0);
ASSERT_EQ(snapSizeToPixel(LayoutUnit(1.0), LayoutUnit(1.5)), 1);
ASSERT_EQ(snapSizeToPixel(LayoutUnit(1.49), LayoutUnit(1.5)), 1);
ASSERT_EQ(snapSizeToPixel(LayoutUnit(1.5), LayoutUnit(1.5)), 1);

ASSERT_EQ(snapSizeToPixel(LayoutUnit(100.5), LayoutUnit(100)), 101);
ASSERT_EQ(snapSizeToPixel(LayoutUnit(intMaxForLayoutUnit), LayoutUnit(0.3)), intMaxForLayoutUnit);
ASSERT_EQ(snapSizeToPixel(LayoutUnit(intMinForLayoutUnit), LayoutUnit(-0.3)), intMinForLayoutUnit);
}

TEST(WebCoreLayoutUnit, LayoutUnitMultiplication)
{
ASSERT_EQ((LayoutUnit(1) * LayoutUnit(1)).toInt(), 1);

0 comments on commit 6d12cb3

Please sign in to comment.