Bridge RenderBoxModelObject::calculateBackgroundImageGeometry parameters into a class
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 13 Jul 2011 13:45:24 +0000 (13:45 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 13 Jul 2011 13:45:24 +0000 (13:45 +0000)
https://bugs.webkit.org/show_bug.cgi?id=63987

Patch by Alexandru Chiculita <achicu@adobe.com> on 2011-07-13
Reviewed by Hajime Morita.

Change doesn't add new functionality. No test needed.

* rendering/RenderBox.cpp:
(WebCore::RenderBox::maskClipRect):
(WebCore::RenderBox::repaintLayerRectsForImage):
* rendering/RenderBoxModelObject.cpp:
(WebCore::RenderBoxModelObject::paintFillLayerExtended):
(WebCore::RenderBoxModelObject::BackgroundImageGeometry::setNoRepeatX):
(WebCore::RenderBoxModelObject::BackgroundImageGeometry::setNoRepeatY):
(WebCore::RenderBoxModelObject::BackgroundImageGeometry::useFixedAttachment):
(WebCore::RenderBoxModelObject::BackgroundImageGeometry::clip):
(WebCore::RenderBoxModelObject::BackgroundImageGeometry::relativePhase):
(WebCore::RenderBoxModelObject::calculateBackgroundImageGeometry):
* rendering/RenderBoxModelObject.h:
(WebCore::RenderBoxModelObject::BackgroundImageGeometry::destOrigin):
(WebCore::RenderBoxModelObject::BackgroundImageGeometry::setDestOrigin):
(WebCore::RenderBoxModelObject::BackgroundImageGeometry::destRect):
(WebCore::RenderBoxModelObject::BackgroundImageGeometry::setDestRect):
(WebCore::RenderBoxModelObject::BackgroundImageGeometry::phase):
(WebCore::RenderBoxModelObject::BackgroundImageGeometry::setPhase):
(WebCore::RenderBoxModelObject::BackgroundImageGeometry::tileSize):
(WebCore::RenderBoxModelObject::BackgroundImageGeometry::setTileSize):
(WebCore::RenderBoxModelObject::BackgroundImageGeometry::setPhaseX):
(WebCore::RenderBoxModelObject::BackgroundImageGeometry::setPhaseY):

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

Source/WebCore/ChangeLog
Source/WebCore/rendering/RenderBox.cpp
Source/WebCore/rendering/RenderBoxModelObject.cpp
Source/WebCore/rendering/RenderBoxModelObject.h

index 3c4760a..f9ee73b 100644 (file)
@@ -1,3 +1,35 @@
+2011-07-13  Alexandru Chiculita  <achicu@adobe.com>
+
+        Bridge RenderBoxModelObject::calculateBackgroundImageGeometry parameters into a class
+        https://bugs.webkit.org/show_bug.cgi?id=63987
+
+        Reviewed by Hajime Morita.
+
+        Change doesn't add new functionality. No test needed.
+
+        * rendering/RenderBox.cpp:
+        (WebCore::RenderBox::maskClipRect):
+        (WebCore::RenderBox::repaintLayerRectsForImage):
+        * rendering/RenderBoxModelObject.cpp:
+        (WebCore::RenderBoxModelObject::paintFillLayerExtended):
+        (WebCore::RenderBoxModelObject::BackgroundImageGeometry::setNoRepeatX):
+        (WebCore::RenderBoxModelObject::BackgroundImageGeometry::setNoRepeatY):
+        (WebCore::RenderBoxModelObject::BackgroundImageGeometry::useFixedAttachment):
+        (WebCore::RenderBoxModelObject::BackgroundImageGeometry::clip):
+        (WebCore::RenderBoxModelObject::BackgroundImageGeometry::relativePhase):
+        (WebCore::RenderBoxModelObject::calculateBackgroundImageGeometry):
+        * rendering/RenderBoxModelObject.h:
+        (WebCore::RenderBoxModelObject::BackgroundImageGeometry::destOrigin):
+        (WebCore::RenderBoxModelObject::BackgroundImageGeometry::setDestOrigin):
+        (WebCore::RenderBoxModelObject::BackgroundImageGeometry::destRect):
+        (WebCore::RenderBoxModelObject::BackgroundImageGeometry::setDestRect):
+        (WebCore::RenderBoxModelObject::BackgroundImageGeometry::phase):
+        (WebCore::RenderBoxModelObject::BackgroundImageGeometry::setPhase):
+        (WebCore::RenderBoxModelObject::BackgroundImageGeometry::tileSize):
+        (WebCore::RenderBoxModelObject::BackgroundImageGeometry::setTileSize):
+        (WebCore::RenderBoxModelObject::BackgroundImageGeometry::setPhaseX):
+        (WebCore::RenderBoxModelObject::BackgroundImageGeometry::setPhaseY):
+
 2011-07-13  MORITA Hajime  <morrita@google.com>
 
         Refactoring: Ignored ExceptionCode value should be less annoying.
index 088563c..9c075de 100644 (file)
@@ -969,11 +969,9 @@ IntRect RenderBox::maskClipRect()
     IntRect result;
     for (const FillLayer* maskLayer = style()->maskLayers(); maskLayer; maskLayer = maskLayer->next()) {
         if (maskLayer->image()) {
-            IntRect maskRect;
-            IntPoint phase;
-            IntSize tileSize;
-            calculateBackgroundImageGeometry(maskLayer, bbox, maskRect, phase, tileSize);
-            result.unite(maskRect);
+            BackgroundImageGeometry geometry;
+            calculateBackgroundImageGeometry(maskLayer, bbox, geometry);
+            result.unite(geometry.destRect());
         }
     }
     return result;
@@ -1063,12 +1061,10 @@ bool RenderBox::repaintLayerRectsForImage(WrappedImagePtr image, const FillLayer
                 }
             }
 
-            IntRect repaintRect;
-            IntPoint phase;
-            IntSize tileSize;
-            layerRenderer->calculateBackgroundImageGeometry(curLayer, rendererRect, repaintRect, phase, tileSize);
-            layerRenderer->repaintRectangle(repaintRect);
-            if (repaintRect == rendererRect)
+            BackgroundImageGeometry geometry;
+            layerRenderer->calculateBackgroundImageGeometry(curLayer, rendererRect, geometry);
+            layerRenderer->repaintRectangle(geometry.destRect());
+            if (geometry.destRect() == rendererRect)
                 return true;
         }
     }
index 068086d..19c5907 100644 (file)
@@ -763,20 +763,16 @@ void RenderBoxModelObject::paintFillLayerExtended(const PaintInfo& paintInfo, co
 
     // no progressive loading of the background image
     if (shouldPaintBackgroundImage) {
-        LayoutRect destRect;
-        LayoutPoint phase;
-        LayoutSize tileSize;
-
-        calculateBackgroundImageGeometry(bgLayer, scrolledPaintRect, destRect, phase, tileSize);
-        LayoutPoint destOrigin = destRect.location();
-        destRect.intersect(paintInfo.rect);
-        if (!destRect.isEmpty()) {
-            phase += destRect.location() - destOrigin;
+        BackgroundImageGeometry geometry;
+        calculateBackgroundImageGeometry(bgLayer, scrolledPaintRect, geometry);
+        geometry.clip(paintInfo.rect);
+        if (!geometry.destRect().isEmpty()) {
             CompositeOperator compositeOp = op == CompositeSourceOver ? bgLayer->composite() : op;
             RenderObject* clientForBackgroundImage = backgroundObject ? backgroundObject : this;
-            RefPtr<Image> image = bgImage->image(clientForBackgroundImage, tileSize);
-            bool useLowQualityScaling = shouldPaintAtLowQuality(context, image.get(), bgLayer, tileSize);
-            context->drawTiledImage(image.get(), style()->colorSpace(), destRect, phase, tileSize, compositeOp, useLowQualityScaling);
+            RefPtr<Image> image = bgImage->image(clientForBackgroundImage, geometry.tileSize());
+            bool useLowQualityScaling = shouldPaintAtLowQuality(context, image.get(), bgLayer, geometry.tileSize());
+            context->drawTiledImage(image.get(), style()->colorSpace(), geometry.destRect(), geometry.relativePhase(), geometry.tileSize(), 
+                compositeOp, useLowQualityScaling);
         }
     }
 }
@@ -842,8 +838,38 @@ IntSize RenderBoxModelObject::calculateFillTileSize(const FillLayer* fillLayer,
     return image->imageSize(this, style()->effectiveZoom());
 }
 
+void RenderBoxModelObject::BackgroundImageGeometry::setNoRepeatX(int xOffset)
+{
+    m_destRect.move(max(xOffset, 0), 0);
+    m_phase.setX(-min(xOffset, 0));
+    m_destRect.setWidth(m_tileSize.width() + min(xOffset, 0));
+}
+void RenderBoxModelObject::BackgroundImageGeometry::setNoRepeatY(int yOffset)
+{
+    m_destRect.move(0, max(yOffset, 0));
+    m_phase.setY(-min(yOffset, 0));
+    m_destRect.setHeight(m_tileSize.height() + min(yOffset, 0));
+}
+
+void RenderBoxModelObject::BackgroundImageGeometry::useFixedAttachment(const LayoutPoint& attachmentPoint)
+{
+    m_phase.move(max(attachmentPoint.x() - m_destRect.x(), 0), max(attachmentPoint.y() - m_destRect.y(), 0));
+}
+
+void RenderBoxModelObject::BackgroundImageGeometry::clip(const LayoutRect& clipRect)
+{
+    m_destRect.intersect(clipRect);
+}
+
+LayoutPoint RenderBoxModelObject::BackgroundImageGeometry::relativePhase() const
+{
+    LayoutPoint phase = m_phase;
+    phase += m_destRect.location() - m_destOrigin;
+    return phase;
+}
+
 void RenderBoxModelObject::calculateBackgroundImageGeometry(const FillLayer* fillLayer, const IntRect& paintRect, 
-                                                            IntRect& destRect, IntPoint& phase, IntSize& tileSize)
+                                                            BackgroundImageGeometry& geometry)
 {
     int left = 0;
     int top = 0;
@@ -864,7 +890,7 @@ void RenderBoxModelObject::calculateBackgroundImageGeometry(const FillLayer* fil
 #endif
 
     if (!fixedAttachment) {
-        destRect = paintRect;
+        geometry.setDestRect(paintRect);
 
         int right = 0;
         int bottom = 0;
@@ -892,37 +918,32 @@ void RenderBoxModelObject::calculateBackgroundImageGeometry(const FillLayer* fil
         } else
             positioningAreaSize = IntSize(paintRect.width() - left - right, paintRect.height() - top - bottom);
     } else {
-        destRect = viewRect();
-        positioningAreaSize = destRect.size();
+        geometry.setDestRect(viewRect());
+        positioningAreaSize = geometry.destRect().size();
     }
 
-    tileSize = calculateFillTileSize(fillLayer, positioningAreaSize);
+    geometry.setTileSize(calculateFillTileSize(fillLayer, positioningAreaSize));
 
     EFillRepeat backgroundRepeatX = fillLayer->repeatX();
     EFillRepeat backgroundRepeatY = fillLayer->repeatY();
 
-    int xPosition = fillLayer->xPosition().calcMinValue(positioningAreaSize.width() - tileSize.width(), true);
+    int xPosition = fillLayer->xPosition().calcMinValue(positioningAreaSize.width() - geometry.tileSize().width(), true);
     if (backgroundRepeatX == RepeatFill)
-        phase.setX(tileSize.width() ? tileSize.width() - (xPosition + left) % tileSize.width() : 0);
-    else {
-        destRect.move(max(xPosition + left, 0), 0);
-        phase.setX(-min(xPosition + left, 0));
-        destRect.setWidth(tileSize.width() + min(xPosition + left, 0));
-    }
+        geometry.setPhaseX(geometry.tileSize().width() ? geometry.tileSize().width() - (xPosition + left) % geometry.tileSize().width() : 0);
+    else
+        geometry.setNoRepeatX(xPosition + left);
 
-    int yPosition = fillLayer->yPosition().calcMinValue(positioningAreaSize.height() - tileSize.height(), true);
+    int yPosition = fillLayer->yPosition().calcMinValue(positioningAreaSize.height() - geometry.tileSize().height(), true);
     if (backgroundRepeatY == RepeatFill)
-        phase.setY(tileSize.height() ? tileSize.height() - (yPosition + top) % tileSize.height() : 0);
-    else {
-        destRect.move(0, max(yPosition + top, 0));
-        phase.setY(-min(yPosition + top, 0));
-        destRect.setHeight(tileSize.height() + min(yPosition + top, 0));
-    }
+        geometry.setPhaseY(geometry.tileSize().height() ? geometry.tileSize().height() - (yPosition + top) % geometry.tileSize().height() : 0);
+    else 
+        geometry.setNoRepeatY(yPosition + top);
 
     if (fixedAttachment)
-        phase.move(max(paintRect.x() - destRect.x(), 0), max(paintRect.y() - destRect.y(), 0));
+        geometry.useFixedAttachment(paintRect.location());
 
-    destRect.intersect(paintRect);
+    geometry.clip(paintRect);
+    geometry.setDestOrigin(geometry.destRect().location());
 }
 
 bool RenderBoxModelObject::paintNinePieceImage(GraphicsContext* graphicsContext, const IntRect& rect, const RenderStyle* style,
index c4a05b8..e612a1d 100644 (file)
@@ -135,7 +135,52 @@ public:
 protected:
     virtual void willBeDestroyed();
 
-    void calculateBackgroundImageGeometry(const FillLayer*, const IntRect& paintRect, IntRect& destRect, IntPoint& phase, IntSize& tileSize);
+    class BackgroundImageGeometry {
+    public:
+        LayoutPoint destOrigin() const { return m_destOrigin; }
+        void setDestOrigin(const LayoutPoint& destOrigin)
+        {
+            m_destOrigin = destOrigin;
+        }
+        
+        LayoutRect destRect() const { return m_destRect; }
+        void setDestRect(const LayoutRect& destRect)
+        {
+            m_destRect = destRect;
+        }
+
+        // Returns the phase relative to the destination rectangle.
+        LayoutPoint relativePhase() const;
+        
+        LayoutPoint phase() const { return m_phase; }   
+        void setPhase(const LayoutPoint& phase)
+        {
+            m_phase = phase;
+        }
+
+        LayoutSize tileSize() const { return m_tileSize; }    
+        void setTileSize(const LayoutSize& tileSize)
+        {
+            m_tileSize = tileSize;
+        }
+        
+        void setPhaseX(int x) { m_phase.setX(x); }
+        void setPhaseY(int y) { m_phase.setY(y); }
+        
+        void setNoRepeatX(int xOffset);
+        void setNoRepeatY(int yOffset);
+        
+        void useFixedAttachment(const LayoutPoint& attachmentPoint);
+        
+        void clip(const LayoutRect&);
+    private:
+        LayoutRect m_destRect;
+        LayoutPoint m_destOrigin;
+        LayoutPoint m_phase;
+        LayoutSize m_tileSize;
+    };
+
+    void calculateBackgroundImageGeometry(const FillLayer*, const IntRect& paintRect, BackgroundImageGeometry&);
     void getBorderEdgeInfo(class BorderEdge[], bool includeLogicalLeftEdge = true, bool includeLogicalRightEdge = true) const;
     bool borderObscuresBackgroundEdge(const FloatSize& contextScale) const;