Do more math in terms of FloatSizes and FloatPoints
authorsimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 20 Sep 2017 06:13:54 +0000 (06:13 +0000)
committersimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 20 Sep 2017 06:13:54 +0000 (06:13 +0000)
https://bugs.webkit.org/show_bug.cgi?id=177217

Reviewed by Zalan Bujtas.
Source/WebCore:

Add operator/(const FloatSize&, const FloatSize&), GraphicsContext::translate(const FloatPoint&),
FloatRect.scale(FloatSize) and AffineTransform::translate(const FloatSize&)
and use them in lots of places to do math in terms of points and sizes.

* html/canvas/CanvasRenderingContext2D.cpp:
(WebCore::CanvasRenderingContext2D::drawImage):
(WebCore::CanvasRenderingContext2D::fullCanvasCompositedDrawImage):
(WebCore::CanvasRenderingContext2D::drawTextInternal):
* page/mac/TextIndicatorWindow.mm:
(-[WebTextIndicatorView initWithFrame:textIndicator:margin:offset:]):
* platform/Theme.cpp:
(WebCore::Theme::drawNamedImage const):
* platform/graphics/CrossfadeGeneratedImage.cpp:
(WebCore::drawCrossfadeSubimage):
(WebCore::CrossfadeGeneratedImage::draw):
* platform/graphics/FloatRect.h:
(WebCore::FloatRect::center const):
(WebCore::FloatRect::scale):
* platform/graphics/FloatSize.h:
(WebCore::operator/):
* platform/graphics/GradientImage.cpp:
(WebCore::GradientImage::draw):
* platform/graphics/GraphicsContext.cpp:
(WebCore::GraphicsContext::scaleFactorForDrawing const):
* platform/graphics/GraphicsContext.h:
(WebCore::GraphicsContext::translate):
* platform/graphics/Image.cpp:
(WebCore::Image::drawTiled):
* platform/graphics/ImageBuffer.cpp:
(WebCore::ImageBuffer::clampedSize):
(WebCore::ImageBuffer::createCompatibleBuffer):
* platform/graphics/LayoutSize.h:
* platform/graphics/NamedImageGeneratedImage.cpp:
(WebCore::NamedImageGeneratedImage::draw):
* platform/graphics/Path.cpp:
(WebCore::Path::addRoundedRect):
* platform/graphics/cg/ImageBufferCG.cpp:
(WebCore::ImageBuffer::createCompatibleBuffer):
* platform/graphics/cg/PDFDocumentImage.cpp:
(WebCore::transformContextForPainting):
(WebCore::applyRotationForPainting):
(WebCore::PDFDocumentImage::drawPDFPage):
* platform/graphics/filters/FETile.cpp:
(WebCore::FETile::platformApplySoftware):
* platform/graphics/transforms/AffineTransform.cpp:
(WebCore::AffineTransform::translate):
(WebCore::makeMapBetweenRects):
* platform/graphics/transforms/AffineTransform.h:
* platform/mac/ScrollbarThemeMac.mm:
(WebCore::ScrollbarThemeMac::paint):
* platform/mac/ThemeMac.mm:
(WebCore::paintToggleButton):
(WebCore::paintButton):
(WebCore::paintStepper):
* rendering/FilterEffectRenderer.cpp:
(WebCore::FilterEffectRendererHelper::beginFilterEffect):
* rendering/RenderBoxModelObject.cpp:
(WebCore::RenderBoxModelObject::paintMaskForTextFillBox):
(WebCore::RenderBoxModelObject::paintBoxShadow):
* rendering/RenderEmbeddedObject.cpp:
(WebCore::RenderEmbeddedObject::getReplacementTextGeometry const):
* rendering/RenderLayer.cpp:
(WebCore::RenderLayer::calculateClipRects const):
* rendering/RenderLayerBacking.cpp:
(WebCore::RenderLayerBacking::paintContents):
* rendering/RenderLayerCompositor.cpp:
(WebCore::paintScrollbar):
(WebCore::RenderLayerCompositor::paintContents):
* rendering/RenderMediaControls.cpp:
(WebCore::getUnzoomedRectAndAdjustCurrentContext):
* rendering/RenderThemeMac.mm:
(WebCore::RenderThemeMac::paintMenuList):
(WebCore::RenderThemeMac::paintSliderThumb):
(WebCore::RenderThemeMac::paintSearchField):
(WebCore::RenderThemeMac::paintSearchFieldCancelButton):
(WebCore::RenderThemeMac::paintSearchFieldResultsButton):
(WebCore::RenderThemeMac::paintImageControlsButton):
* rendering/svg/RenderSVGForeignObject.cpp:
(WebCore::RenderSVGForeignObject::RenderSVGForeignObject):
(WebCore::RenderSVGForeignObject::localToParentTransform const):
* rendering/svg/RenderSVGForeignObject.h:
* rendering/svg/RenderSVGResourceClipper.cpp:
(WebCore::RenderSVGResourceClipper::pathOnlyClipping):
(WebCore::RenderSVGResourceClipper::drawContentIntoMaskImage):
(WebCore::RenderSVGResourceClipper::hitTestClipContent):
(WebCore::RenderSVGResourceClipper::resourceBoundingBox):
* rendering/svg/RenderSVGResourceGradient.cpp:
(WebCore::clipToTextMask):
(WebCore::RenderSVGResourceGradient::applyResource):
* rendering/svg/RenderSVGResourceMarker.cpp:
(WebCore::RenderSVGResourceMarker::markerTransformation const):
(WebCore::RenderSVGResourceMarker::markerContentTransformation const):
* rendering/svg/RenderSVGResourceMasker.cpp:
(WebCore::RenderSVGResourceMasker::drawContentIntoMaskImage):
(WebCore::RenderSVGResourceMasker::resourceBoundingBox):
* rendering/svg/RenderSVGResourcePattern.cpp:
(WebCore::RenderSVGResourcePattern::buildPattern):
(WebCore::RenderSVGResourcePattern::createTileImage const):
* rendering/svg/RenderSVGTransformableContainer.cpp:
(WebCore::RenderSVGTransformableContainer::calculateLocalTransform):
* rendering/svg/SVGRenderingContext.cpp:
(WebCore::SVGRenderingContext::createImageBuffer):
(WebCore::SVGRenderingContext::bufferForeground):
* svg/SVGAnimateMotionElement.cpp:
(WebCore::SVGAnimateMotionElement::buildTransformForProgress):
* svg/SVGSVGElement.cpp:
(WebCore::SVGSVGElement::localCoordinateSpaceTransform const):
* svg/graphics/SVGImage.cpp:
(WebCore::SVGImage::draw):

Source/WebKit:

Add operator/(const FloatSize&, const FloatSize&), GraphicsContext::translate(const FloatPoint&),
FloatRect.scale(FloatSize) and AffineTransform::translate(const FloatSize&)
and use them in lots of places to do math in terms of points and sizes.

* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _didCommitLayerTree:]):
* UIProcess/ios/DragDropInteractionState.mm:
(WebKit::createTargetedDragPreview):
* WebProcess/InjectedBundle/DOM/InjectedBundleNodeHandle.cpp:
(WebKit::imageForRect):
* WebProcess/InjectedBundle/DOM/InjectedBundleRangeHandle.cpp:
(WebKit::InjectedBundleRangeHandle::renderedImage):
* WebProcess/WebPage/WebPage.cpp:
(WebKit::paintSnapshotAtSize):
(WebKit::WebPage::snapshotNode):

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

48 files changed:
Source/WebCore/ChangeLog
Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp
Source/WebCore/page/mac/TextIndicatorWindow.mm
Source/WebCore/platform/Theme.cpp
Source/WebCore/platform/graphics/CrossfadeGeneratedImage.cpp
Source/WebCore/platform/graphics/FloatRect.h
Source/WebCore/platform/graphics/FloatSize.h
Source/WebCore/platform/graphics/GradientImage.cpp
Source/WebCore/platform/graphics/GraphicsContext.cpp
Source/WebCore/platform/graphics/GraphicsContext.h
Source/WebCore/platform/graphics/Image.cpp
Source/WebCore/platform/graphics/ImageBuffer.cpp
Source/WebCore/platform/graphics/LayoutSize.h
Source/WebCore/platform/graphics/NamedImageGeneratedImage.cpp
Source/WebCore/platform/graphics/Path.cpp
Source/WebCore/platform/graphics/cg/ImageBufferCG.cpp
Source/WebCore/platform/graphics/cg/PDFDocumentImage.cpp
Source/WebCore/platform/graphics/filters/FETile.cpp
Source/WebCore/platform/graphics/transforms/AffineTransform.cpp
Source/WebCore/platform/graphics/transforms/AffineTransform.h
Source/WebCore/platform/mac/ScrollbarThemeMac.mm
Source/WebCore/platform/mac/ThemeMac.mm
Source/WebCore/rendering/FilterEffectRenderer.cpp
Source/WebCore/rendering/RenderBoxModelObject.cpp
Source/WebCore/rendering/RenderEmbeddedObject.cpp
Source/WebCore/rendering/RenderLayer.cpp
Source/WebCore/rendering/RenderLayerBacking.cpp
Source/WebCore/rendering/RenderLayerCompositor.cpp
Source/WebCore/rendering/RenderMediaControls.cpp
Source/WebCore/rendering/RenderThemeMac.mm
Source/WebCore/rendering/svg/RenderSVGForeignObject.cpp
Source/WebCore/rendering/svg/RenderSVGForeignObject.h
Source/WebCore/rendering/svg/RenderSVGResourceClipper.cpp
Source/WebCore/rendering/svg/RenderSVGResourceGradient.cpp
Source/WebCore/rendering/svg/RenderSVGResourceMarker.cpp
Source/WebCore/rendering/svg/RenderSVGResourceMasker.cpp
Source/WebCore/rendering/svg/RenderSVGResourcePattern.cpp
Source/WebCore/rendering/svg/RenderSVGTransformableContainer.cpp
Source/WebCore/rendering/svg/SVGRenderingContext.cpp
Source/WebCore/svg/SVGAnimateMotionElement.cpp
Source/WebCore/svg/SVGSVGElement.cpp
Source/WebCore/svg/graphics/SVGImage.cpp
Source/WebKit/ChangeLog
Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm
Source/WebKit/UIProcess/ios/DragDropInteractionState.mm
Source/WebKit/WebProcess/InjectedBundle/DOM/InjectedBundleNodeHandle.cpp
Source/WebKit/WebProcess/InjectedBundle/DOM/InjectedBundleRangeHandle.cpp
Source/WebKit/WebProcess/WebPage/WebPage.cpp

index 01bc200..7e9f0e5 100644 (file)
@@ -1,3 +1,120 @@
+2017-09-19  Simon Fraser  <simon.fraser@apple.com>
+
+        Do more math in terms of FloatSizes and FloatPoints
+        https://bugs.webkit.org/show_bug.cgi?id=177217
+
+        Reviewed by Zalan Bujtas.
+        
+        Add operator/(const FloatSize&, const FloatSize&), GraphicsContext::translate(const FloatPoint&),
+        FloatRect.scale(FloatSize) and AffineTransform::translate(const FloatSize&)
+        and use them in lots of places to do math in terms of points and sizes.
+
+        * html/canvas/CanvasRenderingContext2D.cpp:
+        (WebCore::CanvasRenderingContext2D::drawImage):
+        (WebCore::CanvasRenderingContext2D::fullCanvasCompositedDrawImage):
+        (WebCore::CanvasRenderingContext2D::drawTextInternal):
+        * page/mac/TextIndicatorWindow.mm:
+        (-[WebTextIndicatorView initWithFrame:textIndicator:margin:offset:]):
+        * platform/Theme.cpp:
+        (WebCore::Theme::drawNamedImage const):
+        * platform/graphics/CrossfadeGeneratedImage.cpp:
+        (WebCore::drawCrossfadeSubimage):
+        (WebCore::CrossfadeGeneratedImage::draw):
+        * platform/graphics/FloatRect.h:
+        (WebCore::FloatRect::center const):
+        (WebCore::FloatRect::scale):
+        * platform/graphics/FloatSize.h:
+        (WebCore::operator/):
+        * platform/graphics/GradientImage.cpp:
+        (WebCore::GradientImage::draw):
+        * platform/graphics/GraphicsContext.cpp:
+        (WebCore::GraphicsContext::scaleFactorForDrawing const):
+        * platform/graphics/GraphicsContext.h:
+        (WebCore::GraphicsContext::translate):
+        * platform/graphics/Image.cpp:
+        (WebCore::Image::drawTiled):
+        * platform/graphics/ImageBuffer.cpp:
+        (WebCore::ImageBuffer::clampedSize):
+        (WebCore::ImageBuffer::createCompatibleBuffer):
+        * platform/graphics/LayoutSize.h:
+        * platform/graphics/NamedImageGeneratedImage.cpp:
+        (WebCore::NamedImageGeneratedImage::draw):
+        * platform/graphics/Path.cpp:
+        (WebCore::Path::addRoundedRect):
+        * platform/graphics/cg/ImageBufferCG.cpp:
+        (WebCore::ImageBuffer::createCompatibleBuffer):
+        * platform/graphics/cg/PDFDocumentImage.cpp:
+        (WebCore::transformContextForPainting):
+        (WebCore::applyRotationForPainting):
+        (WebCore::PDFDocumentImage::drawPDFPage):
+        * platform/graphics/filters/FETile.cpp:
+        (WebCore::FETile::platformApplySoftware):
+        * platform/graphics/transforms/AffineTransform.cpp:
+        (WebCore::AffineTransform::translate):
+        (WebCore::makeMapBetweenRects):
+        * platform/graphics/transforms/AffineTransform.h:
+        * platform/mac/ScrollbarThemeMac.mm:
+        (WebCore::ScrollbarThemeMac::paint):
+        * platform/mac/ThemeMac.mm:
+        (WebCore::paintToggleButton):
+        (WebCore::paintButton):
+        (WebCore::paintStepper):
+        * rendering/FilterEffectRenderer.cpp:
+        (WebCore::FilterEffectRendererHelper::beginFilterEffect):
+        * rendering/RenderBoxModelObject.cpp:
+        (WebCore::RenderBoxModelObject::paintMaskForTextFillBox):
+        (WebCore::RenderBoxModelObject::paintBoxShadow):
+        * rendering/RenderEmbeddedObject.cpp:
+        (WebCore::RenderEmbeddedObject::getReplacementTextGeometry const):
+        * rendering/RenderLayer.cpp:
+        (WebCore::RenderLayer::calculateClipRects const):
+        * rendering/RenderLayerBacking.cpp:
+        (WebCore::RenderLayerBacking::paintContents):
+        * rendering/RenderLayerCompositor.cpp:
+        (WebCore::paintScrollbar):
+        (WebCore::RenderLayerCompositor::paintContents):
+        * rendering/RenderMediaControls.cpp:
+        (WebCore::getUnzoomedRectAndAdjustCurrentContext):
+        * rendering/RenderThemeMac.mm:
+        (WebCore::RenderThemeMac::paintMenuList):
+        (WebCore::RenderThemeMac::paintSliderThumb):
+        (WebCore::RenderThemeMac::paintSearchField):
+        (WebCore::RenderThemeMac::paintSearchFieldCancelButton):
+        (WebCore::RenderThemeMac::paintSearchFieldResultsButton):
+        (WebCore::RenderThemeMac::paintImageControlsButton):
+        * rendering/svg/RenderSVGForeignObject.cpp:
+        (WebCore::RenderSVGForeignObject::RenderSVGForeignObject):
+        (WebCore::RenderSVGForeignObject::localToParentTransform const):
+        * rendering/svg/RenderSVGForeignObject.h:
+        * rendering/svg/RenderSVGResourceClipper.cpp:
+        (WebCore::RenderSVGResourceClipper::pathOnlyClipping):
+        (WebCore::RenderSVGResourceClipper::drawContentIntoMaskImage):
+        (WebCore::RenderSVGResourceClipper::hitTestClipContent):
+        (WebCore::RenderSVGResourceClipper::resourceBoundingBox):
+        * rendering/svg/RenderSVGResourceGradient.cpp:
+        (WebCore::clipToTextMask):
+        (WebCore::RenderSVGResourceGradient::applyResource):
+        * rendering/svg/RenderSVGResourceMarker.cpp:
+        (WebCore::RenderSVGResourceMarker::markerTransformation const):
+        (WebCore::RenderSVGResourceMarker::markerContentTransformation const):
+        * rendering/svg/RenderSVGResourceMasker.cpp:
+        (WebCore::RenderSVGResourceMasker::drawContentIntoMaskImage):
+        (WebCore::RenderSVGResourceMasker::resourceBoundingBox):
+        * rendering/svg/RenderSVGResourcePattern.cpp:
+        (WebCore::RenderSVGResourcePattern::buildPattern):
+        (WebCore::RenderSVGResourcePattern::createTileImage const):
+        * rendering/svg/RenderSVGTransformableContainer.cpp:
+        (WebCore::RenderSVGTransformableContainer::calculateLocalTransform):
+        * rendering/svg/SVGRenderingContext.cpp:
+        (WebCore::SVGRenderingContext::createImageBuffer):
+        (WebCore::SVGRenderingContext::bufferForeground):
+        * svg/SVGAnimateMotionElement.cpp:
+        (WebCore::SVGAnimateMotionElement::buildTransformForProgress):
+        * svg/SVGSVGElement.cpp:
+        (WebCore::SVGSVGElement::localCoordinateSpaceTransform const):
+        * svg/graphics/SVGImage.cpp:
+        (WebCore::SVGImage::draw):
+
 2017-09-19  Chris Dumez  <cdumez@apple.com>
 
         IDBRequest and IDBTransaction error properties should be DOMExceptions
index 9e0df80..c25a022 100644 (file)
@@ -1651,9 +1651,9 @@ ExceptionOr<void> CanvasRenderingContext2D::drawImage(HTMLVideoElement& video, c
 
     GraphicsContextStateSaver stateSaver(*c);
     c->clip(dstRect);
-    c->translate(dstRect.x(), dstRect.y());
+    c->translate(dstRect.location());
     c->scale(FloatSize(dstRect.width() / srcRect.width(), dstRect.height() / srcRect.height()));
-    c->translate(-srcRect.x(), -srcRect.y());
+    c->translate(-srcRect.location());
     video.paintCurrentFrameInContext(*c, FloatRect(FloatPoint(), size(video)));
     stateSaver.restore();
     didDraw(dstRect);
@@ -1778,8 +1778,8 @@ template<class T> void CanvasRenderingContext2D::fullCanvasCompositedDrawImage(T
     adjustedDest.setLocation(FloatPoint(0, 0));
     AffineTransform effectiveTransform = c->getCTM();
     IntRect transformedAdjustedRect = enclosingIntRect(effectiveTransform.mapRect(adjustedDest));
-    buffer->context().translate(-transformedAdjustedRect.location().x(), -transformedAdjustedRect.location().y());
-    buffer->context().translate(croppedOffset.width(), croppedOffset.height());
+    buffer->context().translate(-transformedAdjustedRect.location());
+    buffer->context().translate(croppedOffset);
     buffer->context().concatCTM(effectiveTransform);
     drawImageToContext(image, buffer->context(), adjustedDest, src, CompositeSourceOver);
 
@@ -2642,12 +2642,12 @@ void CanvasRenderingContext2D::drawTextInternal(const String& text, float x, flo
         maskImageContext.setTextDrawingMode(fill ? TextModeFill : TextModeStroke);
 
         if (useMaxWidth) {
-            maskImageContext.translate(location.x() - maskRect.x(), location.y() - maskRect.y());
+            maskImageContext.translate(location - maskRect.location());
             // We draw when fontWidth is 0 so compositing operations (eg, a "copy" op) still work.
             maskImageContext.scale(FloatSize((fontWidth > 0 ? (width / fontWidth) : 0), 1));
             fontProxy.drawBidiText(maskImageContext, textRun, FloatPoint(0, 0), FontCascade::UseFallbackIfFontNotReady);
         } else {
-            maskImageContext.translate(-maskRect.x(), -maskRect.y());
+            maskImageContext.translate(-maskRect.location());
             fontProxy.drawBidiText(maskImageContext, textRun, location, FontCascade::UseFallbackIfFontNotReady);
         }
 
@@ -2663,7 +2663,7 @@ void CanvasRenderingContext2D::drawTextInternal(const String& text, float x, flo
 
     GraphicsContextStateSaver stateSaver(*c);
     if (useMaxWidth) {
-        c->translate(location.x(), location.y());
+        c->translate(location);
         // We draw when fontWidth is 0 so compositing operations (eg, a "copy" op) still work.
         c->scale(FloatSize((fontWidth > 0 ? (width / fontWidth) : 0), 1));
         location = FloatPoint();
index 945dab0..cd1a56e 100644 (file)
@@ -183,7 +183,7 @@ static bool indicatorWantsManualAnimation(const TextIndicator& indicator)
 
         Path translatedPath;
         AffineTransform transform;
-        transform.translate(-pathBoundingRect.x(), -pathBoundingRect.y());
+        transform.translate(-pathBoundingRect.location());
         translatedPath.addPath(path, transform);
 
         FloatRect offsetTextRect = pathBoundingRect;
index 7e4d373..8229f1c 100644 (file)
@@ -108,7 +108,7 @@ void Theme::drawNamedImage(const String& name, GraphicsContext& context, const F
 
     // Draw a generic Wireless Playback icon.
 
-    context.scale(FloatSize(rect.size().width() / 100, rect.size().height() / 100));
+    context.scale(rect.size() / 100);
     context.translate(8, 1);
 
     Path outline;
index 036274e..ec856c8 100644 (file)
@@ -61,7 +61,7 @@ static void drawCrossfadeSubimage(GraphicsContext& context, Image& image, Compos
         context.setAlpha(opacity);
 
     if (targetSize != imageSize)
-        context.scale(FloatSize(targetSize.width() / imageSize.width(), targetSize.height() / imageSize.height()));
+        context.scale(targetSize / imageSize);
 
     context.drawImage(image, IntPoint(), ImagePaintingOptions(drawImageOperation));
 
@@ -91,10 +91,10 @@ ImageDrawResult CrossfadeGeneratedImage::draw(GraphicsContext& context, const Fl
     GraphicsContextStateSaver stateSaver(context);
     context.setCompositeOperation(compositeOp, blendMode);
     context.clip(dstRect);
-    context.translate(dstRect.x(), dstRect.y());
+    context.translate(dstRect.location());
     if (dstRect.size() != srcRect.size())
-        context.scale(FloatSize(dstRect.width() / srcRect.width(), dstRect.height() / srcRect.height()));
-    context.translate(-srcRect.x(), -srcRect.y());
+        context.scale(dstRect.size() / srcRect.size());
+    context.translate(-srcRect.location());
     
     drawCrossfade(context);
     return ImageDrawResult::DidDraw;
index 3745e1f..e55f17b 100644 (file)
@@ -98,7 +98,7 @@ public:
     bool isZero() const { return m_size.isZero(); }
     bool isExpressibleAsIntRect() const;
 
-    FloatPoint center() const { return FloatPoint(x() + width() / 2, y() + height() / 2); }
+    FloatPoint center() const { return location() + size() / 2; }
 
     void move(const FloatSize& delta) { m_location += delta; } 
     void moveBy(const FloatPoint& delta) { m_location.move(delta.x(), delta.y()); }
@@ -166,6 +166,7 @@ public:
     void inflate(float d) { inflateX(d); inflateY(d); }
     void scale(float s) { scale(s, s); }
     WEBCORE_EXPORT void scale(float sx, float sy);
+    void scale(FloatSize size) { scale(size.width(), size.height()); }
 
     FloatRect transposedRect() const { return FloatRect(m_location.transposedPoint(), m_size.transposedSize()); }
 
index 831719e..1c3d7f1 100644 (file)
@@ -202,6 +202,11 @@ inline FloatSize operator*(const FloatSize& a, const FloatSize& b)
     return FloatSize(a.width() * b.width(), a.height() * b.height());
 }
 
+inline FloatSize operator/(const FloatSize& a, const FloatSize& b)
+{
+    return FloatSize(a.width() / b.width(), a.height() / b.height());
+}
+
 inline FloatSize operator/(const FloatSize& a, float b)
 {
     return FloatSize(a.width() / b, a.height() / b);
index ec8deef..760db66 100644 (file)
@@ -46,10 +46,10 @@ ImageDrawResult GradientImage::draw(GraphicsContext& destContext, const FloatRec
     GraphicsContextStateSaver stateSaver(destContext);
     destContext.setCompositeOperation(compositeOp, blendMode);
     destContext.clip(destRect);
-    destContext.translate(destRect.x(), destRect.y());
+    destContext.translate(destRect.location());
     if (destRect.size() != srcRect.size())
-        destContext.scale(FloatSize(destRect.width() / srcRect.width(), destRect.height() / srcRect.height()));
-    destContext.translate(-srcRect.x(), -srcRect.y());
+        destContext.scale(destRect.size() / srcRect.size());
+    destContext.translate(-srcRect.location());
     destContext.fillRect(FloatRect(FloatPoint(), size()), m_gradient.get());
     return ImageDrawResult::DidDraw;
 }
index 98f8a03..9587e67 100644 (file)
@@ -1040,7 +1040,7 @@ FloatSize GraphicsContext::scaleFactorForDrawing(const FloatRect& destRect, cons
 {
     AffineTransform transform = getCTM(GraphicsContext::DefinitelyIncludeDeviceScale);
     auto transformedDestRect = transform.mapRect(destRect);
-    return { static_cast<float>(transformedDestRect.width() / srcRect.width()), static_cast<float>(transformedDestRect.height() / srcRect.height()) };
+    return transformedDestRect.size() / srcRect.size();
 }
 
 void GraphicsContext::fillEllipse(const FloatRect& ellipse)
index b8244a9..4d3fbe7 100644 (file)
@@ -476,6 +476,7 @@ public:
     WEBCORE_EXPORT void scale(const FloatSize&);
     void rotate(float angleInRadians);
     void translate(const FloatSize& size) { translate(size.width(), size.height()); }
+    void translate(const FloatPoint& p) { translate(p.x(), p.y()); }
     WEBCORE_EXPORT void translate(float x, float y);
 
     void setURLForRect(const URL&, const FloatRect&);
index b9df285..0feb2d2 100644 (file)
@@ -125,11 +125,10 @@ ImageDrawResult Image::drawTiled(GraphicsContext& ctxt, const FloatRect& destRec
     if (hasRelativeHeight())
         intrinsicTileSize.setHeight(scaledTileSize.height());
 
-    FloatSize scale(scaledTileSize.width() / intrinsicTileSize.width(),
-                    scaledTileSize.height() / intrinsicTileSize.height());
+    FloatSize scale(scaledTileSize / intrinsicTileSize);
 
     FloatRect oneTileRect;
-    FloatSize actualTileSize(scaledTileSize.width() + spacing.width(), scaledTileSize.height() + spacing.height());
+    FloatSize actualTileSize = scaledTileSize + spacing;
     oneTileRect.setX(destRect.x() + fmodf(fmodf(-srcPoint.x(), actualTileSize.width()) - actualTileSize.width(), actualTileSize.width()));
     oneTileRect.setY(destRect.y() + fmodf(fmodf(-srcPoint.y(), actualTileSize.height()) - actualTileSize.height(), actualTileSize.height()));
     oneTileRect.setSize(scaledTileSize);
index ea2dd5d..7db548b 100644 (file)
@@ -90,7 +90,7 @@ FloatSize ImageBuffer::clampedSize(const FloatSize& size, FloatSize& scale)
         return size;
 
     FloatSize clampedSize = ImageBuffer::clampedSize(size);
-    scale = FloatSize(clampedSize.width() / size.width(), clampedSize.height() / size.height());
+    scale = clampedSize / size;
     ASSERT(!sizeNeedsClamping(clampedSize));
     ASSERT(!sizeNeedsClamping(size, scale));
     return clampedSize;
@@ -211,7 +211,7 @@ std::unique_ptr<ImageBuffer> ImageBuffer::createCompatibleBuffer(const FloatSize
         return nullptr;
 
     // Set up a corresponding scale factor on the graphics context.
-    buffer->context().scale(FloatSize(scaledSize.width() / size.width(), scaledSize.height() / size.height()));
+    buffer->context().scale(scaledSize / size);
     return buffer;
 }
 
index 64d2d90..2ae03b6 100644 (file)
@@ -136,7 +136,8 @@ public:
     }
 
 private:
-    LayoutUnit m_width, m_height;
+    LayoutUnit m_width;
+    LayoutUnit m_height;
 };
 
 inline LayoutSize& operator+=(LayoutSize& a, const LayoutSize& b)
index 8b3d4b8..9be2eda 100644 (file)
@@ -46,10 +46,10 @@ ImageDrawResult NamedImageGeneratedImage::draw(GraphicsContext& context, const F
     GraphicsContextStateSaver stateSaver(context);
     context.setCompositeOperation(compositeOp, blendMode);
     context.clip(dstRect);
-    context.translate(dstRect.x(), dstRect.y());
+    context.translate(dstRect.location());
     if (dstRect.size() != srcRect.size())
         context.scale(FloatSize(dstRect.width() / srcRect.width(), dstRect.height() / srcRect.height()));
-    context.translate(-srcRect.x(), -srcRect.y());
+    context.translate(-srcRect.location());
 
     Theme::singleton().drawNamedImage(m_name, context, dstRect);
     return ImageDrawResult::DidDraw;
index 454bc53..29692aa 100644 (file)
@@ -81,7 +81,7 @@ void Path::addRoundedRect(const FloatRect& rect, const FloatSize& roundingRadii,
         return;
 
     FloatSize radius(roundingRadii);
-    FloatSize halfSize(rect.width() / 2, rect.height() / 2);
+    FloatSize halfSize = rect.size() / 2;
 
     // Apply the SVG corner radius constraints, per the rect section of the SVG shapes spec: if
     // one of rx,ry is negative, then the other corner radius value is used. If both values are
index d24c10f..1461e28 100644 (file)
@@ -108,7 +108,7 @@ std::unique_ptr<ImageBuffer> ImageBuffer::createCompatibleBuffer(const FloatSize
         return nullptr;
 
     // Set up a corresponding scale factor on the graphics context.
-    buffer->context().scale(FloatSize(scaledSize.width() / size.width(), scaledSize.height() / size.height()));
+    buffer->context().scale(scaledSize / size);
     return buffer;
 }
 
index 2429b4b..ec84f6f 100644 (file)
@@ -153,7 +153,7 @@ static void transformContextForPainting(GraphicsContext& context, const FloatRec
     // drawPDFPage() relies on drawing the whole PDF into a context starting at (0, 0). We need
     // to transform the destination context such that srcRect of the source context will be drawn
     // in dstRect of destination context.
-    context.translate(dstRect.x() - srcRect.x(), dstRect.y() - srcRect.y());
+    context.translate(dstRect.location() - srcRect.location());
     context.scale(FloatSize(hScale, -vScale));
     context.translate(0, -srcRect.height());
 }
@@ -334,7 +334,7 @@ static void applyRotationForPainting(GraphicsContext& context, FloatSize size, i
     if (rotationDegrees == 90)
         context.translate(0, size.height());
     else if (rotationDegrees == 180)
-        context.translate(size.width(), size.height());
+        context.translate(size);
     else if (rotationDegrees == 270)
         context.translate(size.width(), 0);
 
@@ -345,7 +345,7 @@ void PDFDocumentImage::drawPDFPage(GraphicsContext& context)
 {
     applyRotationForPainting(context, size(), m_rotationDegrees);
 
-    context.translate(-m_cropBox.x(), -m_cropBox.y());
+    context.translate(-m_cropBox.location());
 
 #if USE(DIRECT2D)
     notImplemented();
index 963f1a5..b4bd68f 100644 (file)
@@ -79,7 +79,7 @@ void FETile::platformApplySoftware()
     auto pattern = Pattern::create(tileImageCopy.releaseNonNull(), true, true);
 
     AffineTransform patternTransform;
-    patternTransform.translate(inMaxEffectLocation.x() - maxEffectLocation.x(), inMaxEffectLocation.y() - maxEffectLocation.y());
+    patternTransform.translate(inMaxEffectLocation - maxEffectLocation);
     pattern.get().setPatternSpaceTransform(patternTransform);
     GraphicsContext& filterContext = resultImage->context();
     filterContext.setFillPattern(WTFMove(pattern));
index 6f95646..eebf228 100644 (file)
@@ -202,6 +202,11 @@ AffineTransform& AffineTransform::translate(const FloatPoint& t)
     return translate(t.x(), t.y());
 }
 
+AffineTransform& AffineTransform::translate(const FloatSize& t)
+{
+    return translate(t.width(), t.height());
+}
+
 AffineTransform& AffineTransform::rotateFromVector(double x, double y)
 {
     return rotate(rad2deg(atan2(y, x)));
@@ -249,7 +254,7 @@ AffineTransform makeMapBetweenRects(const FloatRect& source, const FloatRect& de
 {
     AffineTransform transform;
     transform.translate(dest.x() - source.x(), dest.y() - source.y());
-    transform.scale(dest.width() / source.width(), dest.height() / source.height());
+    transform.scale(dest.size() / source.size());
     return transform;
 }
 
index 68bb525..4f034b0 100644 (file)
@@ -112,12 +112,13 @@ public:
     WEBCORE_EXPORT AffineTransform& multiply(const AffineTransform& other);
     WEBCORE_EXPORT AffineTransform& scale(double);
     AffineTransform& scale(double sx, double sy); 
-    WEBCORE_EXPORT AffineTransform& scaleNonUniform(double sx, double sy);
+    WEBCORE_EXPORT AffineTransform& scaleNonUniform(double sx, double sy); // Same as scale(sx, sy).
     WEBCORE_EXPORT AffineTransform& scale(const FloatSize&);
     WEBCORE_EXPORT AffineTransform& rotate(double);
     AffineTransform& rotateFromVector(double x, double y);
     WEBCORE_EXPORT AffineTransform& translate(double tx, double ty);
     WEBCORE_EXPORT AffineTransform& translate(const FloatPoint&);
+    WEBCORE_EXPORT AffineTransform& translate(const FloatSize&);
     WEBCORE_EXPORT AffineTransform& shear(double sx, double sy);
     WEBCORE_EXPORT AffineTransform& flipX();
     WEBCORE_EXPORT AffineTransform& flipY();
index 072e2b4..712c449 100644 (file)
@@ -554,7 +554,7 @@ bool ScrollbarThemeMac::paint(Scrollbar& scrollbar, GraphicsContext& context, co
     
     GraphicsContextStateSaver stateSaver(context);
     context.clip(damageRect);
-    context.translate(scrollbar.frameRect().x(), scrollbar.frameRect().y());
+    context.translate(scrollbar.frameRect().location());
     LocalCurrentGraphicsContext localContext(context);
     scrollerImpPaint(scrollbarMap()->get(&scrollbar).get(), scrollbar.enabled());
 
index 5cde548..eee528f 100644 (file)
@@ -415,9 +415,9 @@ static void paintToggleButton(ControlPart buttonType, ControlStates& controlStat
     if (zoomFactor != 1.0f) {
         inflatedRect.setWidth(inflatedRect.width() / zoomFactor);
         inflatedRect.setHeight(inflatedRect.height() / zoomFactor);
-        context.translate(inflatedRect.x(), inflatedRect.y());
+        context.translate(inflatedRect.location());
         context.scale(zoomFactor);
-        context.translate(-inflatedRect.x(), -inflatedRect.y());
+        context.translate(-inflatedRect.location());
     }
 
     LocalCurrentGraphicsContext localContext(context);
@@ -429,7 +429,7 @@ static void paintToggleButton(ControlPart buttonType, ControlStates& controlStat
     bool isCellFocused = controlStates.states() & ControlStates::FocusState;
 
     if ([toggleButtonCell _stateAnimationRunning]) {
-        context.translate(inflatedRect.x(), inflatedRect.y());
+        context.translate(inflatedRect.location());
         context.scale(FloatSize(1, -1));
         context.translate(0, -inflatedRect.height());
 
@@ -540,9 +540,9 @@ static void paintButton(ControlPart part, ControlStates& controlStates, Graphics
         if (zoomFactor != 1.0f) {
             inflatedRect.setWidth(inflatedRect.width() / zoomFactor);
             inflatedRect.setHeight(inflatedRect.height() / zoomFactor);
-            context.translate(inflatedRect.x(), inflatedRect.y());
+            context.translate(inflatedRect.location());
             context.scale(zoomFactor);
-            context.translate(-inflatedRect.x(), -inflatedRect.y());
+            context.translate(-inflatedRect.location());
         }
     }
     
@@ -611,9 +611,9 @@ static void paintStepper(ControlStates& states, GraphicsContext& context, const
     if (zoomFactor != 1.0f) {
         rect.setWidth(rect.width() / zoomFactor);
         rect.setHeight(rect.height() / zoomFactor);
-        context.translate(rect.x(), rect.y());
+        context.translate(rect.location());
         context.scale(zoomFactor);
-        context.translate(-rect.x(), -rect.y());
+        context.translate(-rect.location());
     }
     CGRect bounds(rect);
     CGRect backgroundBounds;
index e5bf04d..13e4fa2 100644 (file)
@@ -439,7 +439,7 @@ bool FilterEffectRendererHelper::beginFilterEffect()
 
     // Translate the context so that the contents of the layer is captured in the offscreen memory buffer.
     sourceGraphicsContext->save();
-    sourceGraphicsContext->translate(-m_paintOffset.x(), -m_paintOffset.y());
+    sourceGraphicsContext->translate(-m_paintOffset);
     sourceGraphicsContext->clearRect(m_repaintRect);
     sourceGraphicsContext->clip(m_repaintRect);
 
index 464a363..ec216fb 100644 (file)
@@ -685,7 +685,7 @@ InterpolationQuality RenderBoxModelObject::chooseInterpolationQuality(GraphicsCo
 void RenderBoxModelObject::paintMaskForTextFillBox(ImageBuffer* maskImage, const IntRect& maskRect, InlineFlowBox* box, const LayoutRect& scrolledPaintRect)
 {
     GraphicsContext& maskImageContext = maskImage->context();
-    maskImageContext.translate(-maskRect.x(), -maskRect.y());
+    maskImageContext.translate(-maskRect.location());
 
     // Now add the text to the clip. We do this by painting using a special paint phase that signals to
     // InlineTextBoxes that they should just add their contents to the clip.
@@ -2437,7 +2437,7 @@ void RenderBoxModelObject::paintBoxShadow(const PaintInfo& info, const LayoutRec
                 context.clip(pixelSnappedBorderRect.rect());
 
             IntSize extraOffset(2 * roundToInt(paintRect.width()) + std::max(0, shadowOffset.width()) + shadowPaintingExtent - 2 * shadowSpread + 1, 0);
-            context.translate(extraOffset.width(), extraOffset.height());
+            context.translate(extraOffset);
             shadowOffset -= extraOffset;
 
             if (shadow->isWebkitBoxShadow())
index db38c73..7b316d0 100644 (file)
@@ -379,9 +379,7 @@ void RenderEmbeddedObject::getReplacementTextGeometry(const LayoutPoint& accumul
     textWidth = font.width(run);
 
     replacementTextRect.setSize(FloatSize(textWidth + replacementTextRoundedRectLeftTextMargin + (includesArrow ? replacementTextRoundedRectRightTextMarginWithArrow : replacementTextRoundedRectRightTextMargin), replacementTextRoundedRectHeight));
-    float x = (contentRect.size().width() / 2 - replacementTextRect.size().width() / 2) + contentRect.location().x();
-    float y = (contentRect.size().height() / 2 - replacementTextRect.size().height() / 2) + contentRect.location().y();
-    replacementTextRect.setLocation(FloatPoint(x, y));
+    replacementTextRect.setLocation(contentRect.location() + (contentRect.size() / 2 - replacementTextRect.size() / 2));
 
     indicatorRect = replacementTextRect;
 
index 2e47400..25139e9 100644 (file)
@@ -7115,7 +7115,7 @@ void RenderLayer::paintNamedFlowThreadInsideRegion(GraphicsContext& context, Ren
     LayoutSize moveOffset = region->flowThreadPortionLocation() - (paintOffset + regionContentBox.location()) + toLayoutSize(region->fragmentContainer().scrollPosition());
     FloatPoint adjustedPaintOffset = roundPointToDevicePixels(toLayoutPoint(moveOffset), renderer().document().deviceScaleFactor());
     context.save();
-    context.translate(-adjustedPaintOffset.x(), -adjustedPaintOffset.y());
+    context.translate(-adjustedPaintOffset);
 
     LayoutSize subpixelOffset = moveOffset - toLayoutSize(LayoutPoint(adjustedPaintOffset));
     paintDirtyRect.move(moveOffset);
index 8cb974e..0ef12c7 100644 (file)
@@ -2617,7 +2617,7 @@ void RenderLayerBacking::paintContents(const GraphicsLayer* graphicsLayer, Graph
     } else if (graphicsLayer == layerForScrollCorner()) {
         const LayoutRect& scrollCornerAndResizer = m_owningLayer.scrollCornerAndResizerRect();
         context.save();
-        context.translate(-scrollCornerAndResizer.x(), -scrollCornerAndResizer.y());
+        context.translate(-scrollCornerAndResizer.location());
         LayoutRect transformedClip = LayoutRect(clip);
         transformedClip.moveBy(scrollCornerAndResizer.location());
         m_owningLayer.paintScrollCorner(context, IntPoint(), snappedIntRect(transformedClip));
index 06e7100..73290c1 100644 (file)
@@ -2888,7 +2888,7 @@ void paintScrollbar(Scrollbar* scrollbar, GraphicsContext& context, const IntRec
 
     context.save();
     const IntRect& scrollbarRect = scrollbar->frameRect();
-    context.translate(-scrollbarRect.x(), -scrollbarRect.y());
+    context.translate(-scrollbarRect.location());
     IntRect transformedClip = clip;
     transformedClip.moveBy(scrollbarRect.location());
     scrollbar->paint(context, transformedClip);
@@ -2905,7 +2905,7 @@ void RenderLayerCompositor::paintContents(const GraphicsLayer* graphicsLayer, Gr
     else if (graphicsLayer == layerForScrollCorner()) {
         const IntRect& scrollCorner = m_renderView.frameView().scrollCornerRect();
         context.save();
-        context.translate(-scrollCorner.x(), -scrollCorner.y());
+        context.translate(-scrollCorner.location());
         IntRect transformedClip = pixelSnappedRectForIntegralPositionedItems;
         transformedClip.moveBy(scrollCorner.location());
         m_renderView.frameView().paintScrollCorner(context, transformedClip);
index 13cef16..3e8a762 100644 (file)
@@ -91,11 +91,10 @@ static FloatRect getUnzoomedRectAndAdjustCurrentContext(const RenderObject& o, c
     float zoomLevel = o.style().effectiveZoom();
     FloatRect unzoomedRect(originalRect);
     if (zoomLevel != 1.0f) {
-        unzoomedRect.setWidth(unzoomedRect.width() / zoomLevel);
-        unzoomedRect.setHeight(unzoomedRect.height() / zoomLevel);
-        paintInfo.context().translate(unzoomedRect.x(), unzoomedRect.y());
+        unzoomedRect.setSize(unzoomedRect.size() / zoomLevel);
+        paintInfo.context().translate(unzoomedRect.location());
         paintInfo.context().scale(zoomLevel);
-        paintInfo.context().translate(-unzoomedRect.x(), -unzoomedRect.y());
+        paintInfo.context().translate(-unzoomedRect.location());
     }
     return unzoomedRect;
 }
index f00c839..9287d40 100644 (file)
@@ -949,9 +949,9 @@ bool RenderThemeMac::paintMenuList(const RenderObject& renderer, const PaintInfo
     if (zoomLevel != 1.0f) {
         inflatedRect.setWidth(inflatedRect.width() / zoomLevel);
         inflatedRect.setHeight(inflatedRect.height() / zoomLevel);
-        paintInfo.context().translate(inflatedRect.x(), inflatedRect.y());
+        paintInfo.context().translate(inflatedRect.location());
         paintInfo.context().scale(zoomLevel);
-        paintInfo.context().translate(-inflatedRect.x(), -inflatedRect.y());
+        paintInfo.context().translate(-inflatedRect.location());
     }
 
     paintCellAndSetFocusedElementNeedsRepaintIfNecessary(popupButton, renderer, paintInfo, inflatedRect);
@@ -1583,11 +1583,10 @@ bool RenderThemeMac::paintSliderThumb(const RenderObject& o, const PaintInfo& pa
 
     FloatRect unzoomedRect = bounds;
     if (zoomLevel != 1.0f) {
-        unzoomedRect.setWidth(unzoomedRect.width() / zoomLevel);
-        unzoomedRect.setHeight(unzoomedRect.height() / zoomLevel);
-        paintInfo.context().translate(unzoomedRect.x(), unzoomedRect.y());
+        unzoomedRect.setSize(unzoomedRect.size() / zoomLevel);
+        paintInfo.context().translate(unzoomedRect.location());
         paintInfo.context().scale(zoomLevel);
-        paintInfo.context().translate(-unzoomedRect.x(), -unzoomedRect.y());
+        paintInfo.context().translate(-unzoomedRect.location());
     }
 
     bool shouldDrawCell = true;
@@ -1611,14 +1610,12 @@ bool RenderThemeMac::paintSearchField(const RenderObject& o, const PaintInfo& pa
 
     float zoomLevel = o.style().effectiveZoom();
 
-    IntRect unzoomedRect = r;
-
+    FloatRect unzoomedRect = r;
     if (zoomLevel != 1.0f) {
-        unzoomedRect.setWidth(unzoomedRect.width() / zoomLevel);
-        unzoomedRect.setHeight(unzoomedRect.height() / zoomLevel);
-        paintInfo.context().translate(unzoomedRect.x(), unzoomedRect.y());
+        unzoomedRect.setSize(unzoomedRect.size() / zoomLevel);
+        paintInfo.context().translate(unzoomedRect.location());
         paintInfo.context().scale(zoomLevel);
-        paintInfo.context().translate(-unzoomedRect.x(), -unzoomedRect.y());
+        paintInfo.context().translate(-unzoomedRect.location());
     }
 
     // Set the search button to nil before drawing.  Then reset it so we can draw it later.
@@ -1742,11 +1739,10 @@ bool RenderThemeMac::paintSearchFieldCancelButton(const RenderBox& box, const Pa
 
     FloatRect unzoomedRect(paintingPos, localBounds.size());
     if (zoomLevel != 1.0f) {
-        unzoomedRect.setWidth(unzoomedRect.width() / zoomLevel);
-        unzoomedRect.setHeight(unzoomedRect.height() / zoomLevel);
-        paintInfo.context().translate(unzoomedRect.x(), unzoomedRect.y());
+        unzoomedRect.setSize(unzoomedRect.size() / zoomLevel);
+        paintInfo.context().translate(unzoomedRect.location());
         paintInfo.context().scale(zoomLevel);
-        paintInfo.context().translate(-unzoomedRect.x(), -unzoomedRect.y());
+        paintInfo.context().translate(-unzoomedRect.location());
     }
     [[search cancelButtonCell] drawWithFrame:unzoomedRect inView:documentViewFor(box)];
     [[search cancelButtonCell] setControlView:nil];
@@ -1878,11 +1874,10 @@ bool RenderThemeMac::paintSearchFieldResultsButton(const RenderBox& box, const P
     
     FloatRect unzoomedRect(paintingPos, localBounds.size());
     if (zoomLevel != 1.0f) {
-        unzoomedRect.setWidth(unzoomedRect.width() / zoomLevel);
-        unzoomedRect.setHeight(unzoomedRect.height() / zoomLevel);
-        paintInfo.context().translate(unzoomedRect.x(), unzoomedRect.y());
+        unzoomedRect.setSize(unzoomedRect.size() / zoomLevel);
+        paintInfo.context().translate(unzoomedRect.location());
         paintInfo.context().scale(zoomLevel);
-        paintInfo.context().translate(-unzoomedRect.x(), -unzoomedRect.y());
+        paintInfo.context().translate(-unzoomedRect.location());
     }
 
     [[search searchButtonCell] drawWithFrame:unzoomedRect inView:documentViewFor(box)];
@@ -2114,7 +2109,7 @@ bool RenderThemeMac::paintImageControlsButton(const RenderObject& renderer, cons
     LocalCurrentGraphicsContext localContext(paintInfo.context());
     GraphicsContextStateSaver stateSaver(paintInfo.context());
 
-    paintInfo.context().translate(rect.x(), rect.y());
+    paintInfo.context().translate(rect.location());
 
     IntRect innerFrame(IntPoint(), rect.size());
     [cell drawWithFrame:innerFrame inView:documentViewFor(renderer)];
index b31f021..13a8178 100644 (file)
@@ -38,7 +38,6 @@ namespace WebCore {
 
 RenderSVGForeignObject::RenderSVGForeignObject(SVGForeignObjectElement& element, RenderStyle&& style)
     : RenderSVGBlock(element, WTFMove(style))
-    , m_needsTransformUpdate(true)
 {
 }
 
@@ -111,7 +110,7 @@ LayoutRect RenderSVGForeignObject::computeRectForRepaint(const LayoutRect& repai
 const AffineTransform& RenderSVGForeignObject::localToParentTransform() const
 {
     m_localToParentTransform = localTransform();
-    m_localToParentTransform.translate(m_viewport.x(), m_viewport.y());
+    m_localToParentTransform.translate(m_viewport.location());
     return m_localToParentTransform;
 }
 
index 1011353..3461d2c 100644 (file)
@@ -67,10 +67,10 @@ private:
     const AffineTransform& localToParentTransform() const override;
     AffineTransform localTransform() const override { return m_localTransform; }
 
-    bool m_needsTransformUpdate : 1;
-    FloatRect m_viewport;
     AffineTransform m_localTransform;
     mutable AffineTransform m_localToParentTransform;
+    FloatRect m_viewport;
+    bool m_needsTransformUpdate { true };
 };
 
 } // namespace WebCore
index 6a87511..a4fcd32 100644 (file)
@@ -112,8 +112,8 @@ bool RenderSVGResourceClipper::pathOnlyClipping(GraphicsContext& context, const
     // Only one visible shape/path was found. Directly continue clipping and transform the content to userspace if necessary.
     if (clipPathElement().clipPathUnits() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX) {
         AffineTransform transform;
-        transform.translate(objectBoundingBox.x(), objectBoundingBox.y());
-        transform.scaleNonUniform(objectBoundingBox.width(), objectBoundingBox.height());
+        transform.translate(objectBoundingBox.location());
+        transform.scale(objectBoundingBox.size());
         clipPath.transform(transform);
     }
 
@@ -182,8 +182,8 @@ bool RenderSVGResourceClipper::drawContentIntoMaskImage(const ClipperMaskImage&
 
     AffineTransform maskContentTransformation;
     if (clipPathElement().clipPathUnits() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX) {
-        maskContentTransformation.translate(objectBoundingBox.x(), objectBoundingBox.y());
-        maskContentTransformation.scaleNonUniform(objectBoundingBox.width(), objectBoundingBox.height());
+        maskContentTransformation.translate(objectBoundingBox.location());
+        maskContentTransformation.scale(objectBoundingBox.size());
         maskContext.concatCTM(maskContentTransformation);
     }
 
@@ -265,8 +265,8 @@ bool RenderSVGResourceClipper::hitTestClipContent(const FloatRect& objectBoundin
 
     if (clipPathElement().clipPathUnits() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX) {
         AffineTransform transform;
-        transform.translate(objectBoundingBox.x(), objectBoundingBox.y());
-        transform.scaleNonUniform(objectBoundingBox.width(), objectBoundingBox.height());
+        transform.translate(objectBoundingBox.location());
+        transform.scale(objectBoundingBox.size());
         point = transform.inverse().value_or(AffineTransform()).mapPoint(point);
     }
 
@@ -301,8 +301,8 @@ FloatRect RenderSVGResourceClipper::resourceBoundingBox(const RenderObject& obje
     if (clipPathElement().clipPathUnits() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX) {
         FloatRect objectBoundingBox = object.objectBoundingBox();
         AffineTransform transform;
-        transform.translate(objectBoundingBox.x(), objectBoundingBox.y());
-        transform.scaleNonUniform(objectBoundingBox.width(), objectBoundingBox.height());
+        transform.translate(objectBoundingBox.location());
+        transform.scale(objectBoundingBox.size());
         return transform.mapRect(m_clipBoundaries);
     }
 
index e55136d..198a0eb 100644 (file)
@@ -83,8 +83,8 @@ static inline AffineTransform clipToTextMask(GraphicsContext& context, std::uniq
     AffineTransform matrix;
     if (boundingBoxMode) {
         FloatRect maskBoundingBox = textRootBlock->objectBoundingBox();
-        matrix.translate(maskBoundingBox.x(), maskBoundingBox.y());
-        matrix.scaleNonUniform(maskBoundingBox.width(), maskBoundingBox.height());
+        matrix.translate(maskBoundingBox.location());
+        matrix.scale(maskBoundingBox.size());
     }
     matrix *= gradientTransform;
     return matrix;
@@ -132,8 +132,8 @@ bool RenderSVGResourceGradient::applyResource(RenderElement& renderer, const Ren
 #else
         if (gradientUnits() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX && !objectBoundingBox.isEmpty()) {
 #endif
-            gradientData->userspaceTransform.translate(objectBoundingBox.x(), objectBoundingBox.y());
-            gradientData->userspaceTransform.scaleNonUniform(objectBoundingBox.width(), objectBoundingBox.height());
+            gradientData->userspaceTransform.translate(objectBoundingBox.location());
+            gradientData->userspaceTransform.scale(objectBoundingBox.size());
         }
 
         AffineTransform gradientTransform;
index 75360ae..538e21c 100644 (file)
@@ -105,7 +105,7 @@ AffineTransform RenderSVGResourceMarker::markerTransformation(const FloatPoint&
     bool useStrokeWidth = markerElement().markerUnits() == SVGMarkerUnitsStrokeWidth;
 
     AffineTransform transform;
-    transform.translate(origin.x(), origin.y());
+    transform.translate(origin);
     transform.rotate(markerAngle == -1 ? autoAngle : markerAngle);
     transform = markerContentTransformation(transform, referencePoint(), useStrokeWidth ? strokeWidth : -1);
     return transform;
@@ -132,7 +132,7 @@ AffineTransform RenderSVGResourceMarker::markerContentTransformation(const Affin
     if (strokeWidth != -1)
         transformation.scaleNonUniform(strokeWidth, strokeWidth);
 
-    transformation.translate(-mappedOrigin.x(), -mappedOrigin.y());
+    transformation.translate(-mappedOrigin);
     return transformation;
 }
 
index aa960e2..bcd6bdf 100644 (file)
@@ -93,8 +93,8 @@ bool RenderSVGResourceMasker::drawContentIntoMaskImage(MaskerData* maskerData, C
     AffineTransform maskContentTransformation;
     if (maskElement().maskContentUnits() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX) {
         FloatRect objectBoundingBox = object->objectBoundingBox();
-        maskContentTransformation.translate(objectBoundingBox.x(), objectBoundingBox.y());
-        maskContentTransformation.scaleNonUniform(objectBoundingBox.width(), objectBoundingBox.height());
+        maskContentTransformation.translate(objectBoundingBox.location());
+        maskContentTransformation.scale(objectBoundingBox.size());
         maskImageContext.concatCTM(maskContentTransformation);
     }
 
@@ -152,8 +152,8 @@ FloatRect RenderSVGResourceMasker::resourceBoundingBox(const RenderObject& objec
     FloatRect maskRect = m_maskContentBoundaries;
     if (maskElement().maskContentUnits() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX) {
         AffineTransform transform;
-        transform.translate(objectBoundingBox.x(), objectBoundingBox.y());
-        transform.scaleNonUniform(objectBoundingBox.width(), objectBoundingBox.height());
+        transform.translate(objectBoundingBox.location());
+        transform.scale(objectBoundingBox.size());
         maskRect = transform.mapRect(maskRect);
     }
 
index d3a1e3c..980ee3e 100644 (file)
@@ -118,8 +118,8 @@ PatternData* RenderSVGResourcePattern::buildPattern(RenderElement& renderer, Opt
 
     // Compute pattern space transformation.
 
-    patternData->transform.translate(tileBoundaries.x(), tileBoundaries.y());
-    patternData->transform.scale(tileBoundaries.width() / tileImageSize.width(), tileBoundaries.height() / tileImageSize.height());
+    patternData->transform.translate(tileBoundaries.location());
+    patternData->transform.scale(tileBoundaries.size() / tileImageSize);
 
     AffineTransform patternTransform = m_attributes.patternTransform();
     if (!patternTransform.isIdentity())
@@ -258,8 +258,7 @@ std::unique_ptr<ImageBuffer> RenderSVGResourcePattern::createTileImage(const Pat
     GraphicsContext& tileImageContext = tileImage->context();
 
     // The image buffer represents the final rendered size, so the content has to be scaled (to avoid pixelation).
-    tileImageContext.scale(FloatSize(clampedAbsoluteTileBoundaries.width() / tileBoundaries.width(),
-                                      clampedAbsoluteTileBoundaries.height() / tileBoundaries.height()));
+    tileImageContext.scale(clampedAbsoluteTileBoundaries.size() / tileBoundaries.size());
 
     // Apply tile image transformations.
     if (!tileImageTransform.isIdentity())
index 0b08a17..449886d 100644 (file)
@@ -63,7 +63,7 @@ bool RenderSVGTransformableContainer::calculateLocalTransform()
         return false;
 
     m_localTransform = element.animatedLocalTransform();
-    m_localTransform.translate(m_lastTranslation.width(), m_lastTranslation.height());
+    m_localTransform.translate(m_lastTranslation);
     m_needsTransformUpdate = false;
     return true;
 }
index c9b0f5e..67aedb4 100644 (file)
@@ -272,7 +272,7 @@ std::unique_ptr<ImageBuffer> SVGRenderingContext::createImageBuffer(const FloatR
 std::unique_ptr<ImageBuffer> SVGRenderingContext::createImageBuffer(const FloatRect& targetRect, const FloatRect& clampedRect, ColorSpace colorSpace, RenderingMode renderingMode)
 {
     IntSize clampedSize = roundedIntSize(clampedRect.size());
-    IntSize unclampedSize = roundedIntSize(targetRect.size());
+    FloatSize unclampedSize = roundedIntSize(targetRect.size());
 
     // Don't create empty ImageBuffers.
     if (clampedSize.isEmpty())
@@ -285,7 +285,7 @@ std::unique_ptr<ImageBuffer> SVGRenderingContext::createImageBuffer(const FloatR
     GraphicsContext& imageContext = imageBuffer->context();
 
     // Compensate rounding effects, as the absolute target rect is using floating-point numbers and the image buffer size is integer.
-    imageContext.scale(FloatSize(unclampedSize.width() / targetRect.width(), unclampedSize.height() / targetRect.height()));
+    imageContext.scale(unclampedSize / targetRect.size());
 
     return imageBuffer;
 }
@@ -354,7 +354,7 @@ bool SVGRenderingContext::bufferForeground(std::unique_ptr<ImageBuffer>& imageBu
     if (!imageBuffer) {
         if ((imageBuffer = ImageBuffer::createCompatibleBuffer(expandedIntSize(boundingBox.size()), ColorSpaceSRGB, m_paintInfo->context()))) {
             GraphicsContext& bufferedRenderingContext = imageBuffer->context();
-            bufferedRenderingContext.translate(-boundingBox.x(), -boundingBox.y());
+            bufferedRenderingContext.translate(-boundingBox.location());
             PaintInfo bufferedInfo(*m_paintInfo);
             bufferedInfo.setContext(bufferedRenderingContext);
             downcast<RenderSVGImage>(*m_renderer).paintForeground(bufferedInfo);
index e808d79..29aa054 100644 (file)
@@ -221,7 +221,7 @@ void SVGAnimateMotionElement::buildTransformForProgress(AffineTransform* transfo
     FloatPoint position = traversalState.current();
     float angle = traversalState.normalAngle();
 
-    transform->translate(position.x(), position.y());
+    transform->translate(position);
     RotateMode rotateMode = this->rotateMode();
     if (rotateMode != RotateAuto && rotateMode != RotateAutoReverse)
         return;
index bfa9172..89879a9 100644 (file)
@@ -439,7 +439,7 @@ AffineTransform SVGSVGElement::localCoordinateSpaceTransform(SVGLocatable::CTMSc
             if (FrameView* view = document().view()) {
                 LayoutPoint scrollPosition = view->scrollPosition();
                 scrollPosition.scale(zoomFactor);
-                transform.translate(-scrollPosition.x(), -scrollPosition.y());
+                transform.translate(-scrollPosition);
             }
         }
     }
index 23ceae5..426e25e 100644 (file)
@@ -298,14 +298,14 @@ ImageDrawResult SVGImage::draw(GraphicsContext& context, const FloatRect& dstRec
         context.setCompositeOperation(CompositeSourceOver, BlendModeNormal);
     }
 
-    FloatSize scale(dstRect.width() / srcRect.width(), dstRect.height() / srcRect.height());
+    FloatSize scale(dstRect.size() / srcRect.size());
     
     // We can only draw the entire frame, clipped to the rect we want. So compute where the top left
     // of the image would be if we were drawing without clipping, and translate accordingly.
     FloatSize topLeftOffset(srcRect.location().x() * scale.width(), srcRect.location().y() * scale.height());
     FloatPoint destOffset = dstRect.location() - topLeftOffset;
 
-    context.translate(destOffset.x(), destOffset.y());
+    context.translate(destOffset);
     context.scale(scale);
 
     view->resize(containerSize());
index 58d0ae5..98afac5 100644 (file)
@@ -1,5 +1,28 @@
 2017-09-19  Simon Fraser  <simon.fraser@apple.com>
 
+        Do more math in terms of FloatSizes and FloatPoints
+        https://bugs.webkit.org/show_bug.cgi?id=177217
+
+        Reviewed by Zalan Bujtas.
+
+        Add operator/(const FloatSize&, const FloatSize&), GraphicsContext::translate(const FloatPoint&),
+        FloatRect.scale(FloatSize) and AffineTransform::translate(const FloatSize&)
+        and use them in lots of places to do math in terms of points and sizes.
+
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView _didCommitLayerTree:]):
+        * UIProcess/ios/DragDropInteractionState.mm:
+        (WebKit::createTargetedDragPreview):
+        * WebProcess/InjectedBundle/DOM/InjectedBundleNodeHandle.cpp:
+        (WebKit::imageForRect):
+        * WebProcess/InjectedBundle/DOM/InjectedBundleRangeHandle.cpp:
+        (WebKit::InjectedBundleRangeHandle::renderedImage):
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::paintSnapshotAtSize):
+        (WebKit::WebPage::snapshotNode):
+
+2017-09-19  Simon Fraser  <simon.fraser@apple.com>
+
         tiled-drawing/tiled-backing-in-window.html fails on Retina displays
         https://bugs.webkit.org/show_bug.cgi?id=177113
 
index f99d2f3..757257a 100644 (file)
@@ -1658,8 +1658,8 @@ static inline bool areEssentiallyEqualAsFloat(float a, float b)
 
             if (areEssentiallyEqualAsFloat(contentZoomScale(self), _scaleToRestore)) {
                 CGRect unobscuredRect = UIEdgeInsetsInsetRect(self.bounds, _obscuredInsets);
-                WebCore::FloatSize unobscuredContentSizeAtNewScale(unobscuredRect.size.width / _scaleToRestore, unobscuredRect.size.height / _scaleToRestore);
-                WebCore::FloatPoint topLeftInDocumentCoordinates(unobscuredCenterToRestore.x() - unobscuredContentSizeAtNewScale.width() / 2, unobscuredCenterToRestore.y() - unobscuredContentSizeAtNewScale.height() / 2);
+                WebCore::FloatSize unobscuredContentSizeAtNewScale = WebCore::FloatSize(unobscuredRect.size) / _scaleToRestore;
+                WebCore::FloatPoint topLeftInDocumentCoordinates = unobscuredCenterToRestore - unobscuredContentSizeAtNewScale / 2;
 
                 topLeftInDocumentCoordinates.scale(_scaleToRestore);
                 topLeftInDocumentCoordinates.moveBy(WebCore::FloatPoint(-_obscuredInsets.left, -_obscuredInsets.top));
index 5943f1e..64c8f06 100644 (file)
@@ -57,10 +57,9 @@ static UITargetedDragPreview *createTargetedDragPreview(UIImage *image, UIView *
     if (frameInContainerCoordinates.isEmpty())
         return nullptr;
 
-    float widthScalingRatio = frameInContainerCoordinates.width() / frameInRootViewCoordinates.width();
-    float heightScalingRatio = frameInContainerCoordinates.height() / frameInRootViewCoordinates.height();
+    FloatSize scalingRatio = frameInContainerCoordinates.size() / frameInRootViewCoordinates.size();
     for (auto rect : clippingRectsInFrameCoordinates) {
-        rect.scale(widthScalingRatio, heightScalingRatio);
+        rect.scale(scalingRatio);
         [clippingRectValuesInFrameCoordinates addObject:[NSValue valueWithCGRect:rect]];
     }
 
index 2da61c8..d90bd64 100644 (file)
@@ -163,7 +163,7 @@ static RefPtr<WebImage> imageForRect(FrameView* frameView, const IntRect& painti
     graphicsContext->clearRect(IntRect(IntPoint(), bitmapSize));
     graphicsContext->applyDeviceScaleFactor(deviceScaleFactor);
     graphicsContext->scale(bitmapScaleFactor);
-    graphicsContext->translate(-paintingRect.x(), -paintingRect.y());
+    graphicsContext->translate(-paintingRect.location());
 
     FrameView::SelectionInSnapshot shouldPaintSelection = FrameView::IncludeSelection;
     if (options & SnapshotOptionsExcludeSelectionHighlighting)
index d46c92d..7bd6a42 100644 (file)
@@ -140,7 +140,7 @@ RefPtr<WebImage> InjectedBundleRangeHandle::renderedImage(SnapshotOptions option
     paintRect.move(frameView->frameRect().x(), frameView->frameRect().y());
     paintRect.moveBy(-frameView->scrollPosition());
 
-    graphicsContext->translate(-paintRect.x(), -paintRect.y());
+    graphicsContext->translate(-paintRect.location());
 
     PaintBehavior oldPaintBehavior = frameView->paintBehavior();
     PaintBehavior paintBehavior = oldPaintBehavior | PaintBehaviorSelectionOnly | PaintBehaviorFlattenCompositingLayers | PaintBehaviorSnapshotting;
index 27ee723..0eabe65 100644 (file)
@@ -1969,7 +1969,7 @@ static void paintSnapshotAtSize(const IntRect& rect, const IntSize& bitmapSize,
     }
 
     graphicsContext.scale(scaleFactor);
-    graphicsContext.translate(-snapshotRect.x(), -snapshotRect.y());
+    graphicsContext.translate(-snapshotRect.location());
 
     FrameView::SelectionInSnapshot shouldPaintSelection = FrameView::IncludeSelection;
     if (options & SnapshotOptionsExcludeSelectionHighlighting)
@@ -2089,7 +2089,7 @@ RefPtr<WebImage> WebPage::snapshotNode(WebCore::Node& node, SnapshotOptions opti
     }
 
     graphicsContext->scale(scaleFactor);
-    graphicsContext->translate(-snapshotRect.x(), -snapshotRect.y());
+    graphicsContext->translate(-snapshotRect.location());
 
     Color savedBackgroundColor = frameView->baseBackgroundColor();
     frameView->setBaseBackgroundColor(Color::transparent);