Commit 02e9ec58 authored by davve@opera.com's avatar davve@opera.com

Refactor code for calculating background image geometry

Extract BoxPainter::calculateBackgroundImageGeometry implementation
and related functions to the BackgroundImageGeometry class. This
enables shrinking the API surface of BackgroundImageGeometry and eases
further code health improvements.

BUG=521481

Review URL: https://codereview.chromium.org/1300103003

git-svn-id: svn://svn.chromium.org/blink/trunk@200850 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent a0a9b9e8
...@@ -1185,7 +1185,7 @@ bool LayoutBox::getBackgroundPaintedExtent(LayoutRect& paintedExtent) ...@@ -1185,7 +1185,7 @@ bool LayoutBox::getBackgroundPaintedExtent(LayoutRect& paintedExtent)
BackgroundImageGeometry geometry; BackgroundImageGeometry geometry;
// TODO(jchaffraix): This function should be rethought as it's called during and outside // TODO(jchaffraix): This function should be rethought as it's called during and outside
// of the paint phase. Potentially returning different results at different phases. // of the paint phase. Potentially returning different results at different phases.
BoxPainter::calculateBackgroundImageGeometry(*this, 0, GlobalPaintNormalPhase, style()->backgroundLayers(), backgroundRect, geometry); geometry.calculate(*this, nullptr, GlobalPaintNormalPhase, style()->backgroundLayers(), backgroundRect);
if (geometry.hasNonLocalGeometry()) if (geometry.hasNonLocalGeometry())
return false; return false;
paintedExtent = LayoutRect(geometry.destRect()); paintedExtent = LayoutRect(geometry.destRect());
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#ifndef BackgroundImageGeometry_h #ifndef BackgroundImageGeometry_h
#define BackgroundImageGeometry_h #define BackgroundImageGeometry_h
#include "core/paint/PaintPhase.h"
#include "platform/geometry/IntPoint.h" #include "platform/geometry/IntPoint.h"
#include "platform/geometry/IntRect.h" #include "platform/geometry/IntRect.h"
#include "platform/geometry/IntSize.h" #include "platform/geometry/IntSize.h"
...@@ -12,6 +13,11 @@ ...@@ -12,6 +13,11 @@
namespace blink { namespace blink {
class FillLayer;
class LayoutBoxModelObject;
class LayoutObject;
class LayoutRect;
class BackgroundImageGeometry { class BackgroundImageGeometry {
STACK_ALLOCATED(); STACK_ALLOCATED();
public: public:
...@@ -19,51 +25,38 @@ public: ...@@ -19,51 +25,38 @@ public:
: m_hasNonLocalGeometry(false) : m_hasNonLocalGeometry(false)
{ } { }
IntRect destRect() const { return m_destRect; } void calculate(const LayoutBoxModelObject&, const LayoutBoxModelObject* paintContainer,
void setDestRect(const IntRect& destRect) const GlobalPaintFlags, const FillLayer&, const LayoutRect& paintRect,
{ LayoutObject* backgroundObject = nullptr);
m_destRect = destRect;
}
IntPoint phase() const { return m_phase; }
void setPhase(const IntPoint& phase)
{
m_phase = phase;
}
IntRect destRect() const { return m_destRect; }
IntSize tileSize() const { return m_tileSize; } IntSize tileSize() const { return m_tileSize; }
void setTileSize(const IntSize& tileSize) IntPoint phase() const { return m_phase; }
{
m_tileSize = tileSize;
}
// Space-size represents extra width and height that may be added to // Space-size represents extra width and height that may be added to
// the image if used as a pattern with repeat: space // the image if used as a pattern with background-repeat: space.
IntSize spaceSize() const { return m_repeatSpacing; } IntSize spaceSize() const { return m_repeatSpacing; }
void setSpaceSize(const IntSize& repeatSpacing) // Has background-attachment: fixed. Implies that we can't always cheaply compute destRect.
{ bool hasNonLocalGeometry() const { return m_hasNonLocalGeometry; }
m_repeatSpacing = repeatSpacing;
}
private:
void setDestRect(const IntRect& destRect) { m_destRect = destRect; }
void setPhase(const IntPoint& phase) { m_phase = phase; }
void setTileSize(const IntSize& tileSize) { m_tileSize = tileSize; }
void setSpaceSize(const IntSize& repeatSpacing) { m_repeatSpacing = repeatSpacing; }
void setPhaseX(int x) { m_phase.setX(x); } void setPhaseX(int x) { m_phase.setX(x); }
void setPhaseY(int y) { m_phase.setY(y); } void setPhaseY(int y) { m_phase.setY(y); }
void setNoRepeatX(int xOffset); void setNoRepeatX(int xOffset);
void setNoRepeatY(int yOffset); void setNoRepeatY(int yOffset);
void useFixedAttachment(const IntPoint& attachmentPoint); void useFixedAttachment(const IntPoint& attachmentPoint);
void clip(const IntRect&); void clip(const IntRect&);
void setHasNonLocalGeometry() { m_hasNonLocalGeometry = true; } void setHasNonLocalGeometry() { m_hasNonLocalGeometry = true; }
bool hasNonLocalGeometry() const { return m_hasNonLocalGeometry; }
private:
IntRect m_destRect; IntRect m_destRect;
IntPoint m_phase; IntPoint m_phase;
IntSize m_tileSize; IntSize m_tileSize;
IntSize m_repeatSpacing; IntSize m_repeatSpacing;
bool m_hasNonLocalGeometry; // Has background-attachment: fixed. Implies that we can't always cheaply compute destRect. bool m_hasNonLocalGeometry;
}; };
} // namespace blink } // namespace blink
......
...@@ -36,7 +36,6 @@ public: ...@@ -36,7 +36,6 @@ public:
void paintMaskImages(const PaintInfo&, const LayoutRect&); void paintMaskImages(const PaintInfo&, const LayoutRect&);
void paintBoxDecorationBackgroundWithRect(const PaintInfo&, const LayoutPoint&, const LayoutRect&); void paintBoxDecorationBackgroundWithRect(const PaintInfo&, const LayoutPoint&, const LayoutRect&);
static void paintFillLayerExtended(LayoutBoxModelObject&, const PaintInfo&, const Color&, const FillLayer&, const LayoutRect&, BackgroundBleedAvoidance, InlineFlowBox* = nullptr, const LayoutSize& = LayoutSize(), SkXfermode::Mode = SkXfermode::kSrcOver_Mode, LayoutObject* backgroundObject = nullptr); static void paintFillLayerExtended(LayoutBoxModelObject&, const PaintInfo&, const Color&, const FillLayer&, const LayoutRect&, BackgroundBleedAvoidance, InlineFlowBox* = nullptr, const LayoutSize& = LayoutSize(), SkXfermode::Mode = SkXfermode::kSrcOver_Mode, LayoutObject* backgroundObject = nullptr);
static void calculateBackgroundImageGeometry(const LayoutBoxModelObject&, const LayoutBoxModelObject* paintContainer, const GlobalPaintFlags, const FillLayer&, const LayoutRect& paintRect, BackgroundImageGeometry&, LayoutObject* backgroundObject = nullptr);
static InterpolationQuality chooseInterpolationQuality(LayoutObject&, GraphicsContext*, Image*, const void*, const LayoutSize&); static InterpolationQuality chooseInterpolationQuality(LayoutObject&, GraphicsContext*, Image*, const void*, const LayoutSize&);
static bool paintNinePieceImage(LayoutBoxModelObject&, GraphicsContext*, const LayoutRect&, const ComputedStyle&, const NinePieceImage&, SkXfermode::Mode = SkXfermode::kSrcOver_Mode); static bool paintNinePieceImage(LayoutBoxModelObject&, GraphicsContext*, const LayoutRect&, const ComputedStyle&, const NinePieceImage&, SkXfermode::Mode = SkXfermode::kSrcOver_Mode);
static void paintBorder(LayoutBoxModelObject&, const PaintInfo&, const LayoutRect&, const ComputedStyle&, BackgroundBleedAvoidance = BackgroundBleedNone, bool includeLogicalLeftEdge = true, bool includeLogicalRightEdge = true); static void paintBorder(LayoutBoxModelObject&, const PaintInfo&, const LayoutRect&, const ComputedStyle&, BackgroundBleedAvoidance = BackgroundBleedNone, bool includeLogicalLeftEdge = true, bool includeLogicalRightEdge = true);
...@@ -52,8 +51,6 @@ private: ...@@ -52,8 +51,6 @@ private:
static FloatRoundedRect getBackgroundRoundedRect(LayoutObject&, const LayoutRect&, InlineFlowBox*, LayoutUnit inlineBoxWidth, LayoutUnit inlineBoxHeight, static FloatRoundedRect getBackgroundRoundedRect(LayoutObject&, const LayoutRect&, InlineFlowBox*, LayoutUnit inlineBoxWidth, LayoutUnit inlineBoxHeight,
bool includeLogicalLeftEdge, bool includeLogicalRightEdge); bool includeLogicalLeftEdge, bool includeLogicalRightEdge);
static void applyBoxShadowForBackground(GraphicsContext*, LayoutObject&); static void applyBoxShadowForBackground(GraphicsContext*, LayoutObject&);
static bool fixedBackgroundPaintsInLocalCoordinates(const LayoutObject&, const GlobalPaintFlags);
static IntSize calculateFillTileSize(const LayoutBoxModelObject&, const FillLayer&, const IntSize& scaledPositioningAreaSize);
LayoutRect boundsForDrawingRecorder(const LayoutPoint& paintOffset); LayoutRect boundsForDrawingRecorder(const LayoutPoint& paintOffset);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment