Home | History | Annotate | Download | only in paint
      1 // Copyright 2014 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef BackgroundImageGeometry_h
      6 #define BackgroundImageGeometry_h
      7 
      8 #include "platform/geometry/IntPoint.h"
      9 #include "platform/geometry/IntRect.h"
     10 #include "platform/geometry/IntSize.h"
     11 
     12 namespace blink {
     13 
     14 class BackgroundImageGeometry {
     15 public:
     16     BackgroundImageGeometry()
     17         : m_hasNonLocalGeometry(false)
     18     { }
     19 
     20     IntPoint destOrigin() const { return m_destOrigin; }
     21     void setDestOrigin(const IntPoint& destOrigin)
     22     {
     23         m_destOrigin = destOrigin;
     24     }
     25 
     26     IntRect destRect() const { return m_destRect; }
     27     void setDestRect(const IntRect& destRect)
     28     {
     29         m_destRect = destRect;
     30     }
     31 
     32     // Returns the phase relative to the destination rectangle.
     33     IntPoint relativePhase() const;
     34 
     35     IntPoint phase() const { return m_phase; }
     36     void setPhase(const IntPoint& phase)
     37     {
     38         m_phase = phase;
     39     }
     40 
     41     IntSize tileSize() const { return m_tileSize; }
     42     void setTileSize(const IntSize& tileSize)
     43     {
     44         m_tileSize = tileSize;
     45     }
     46 
     47     // Space-size represents extra width and height that may be added to
     48     // the image if used as a pattern with repeat: space
     49     IntSize spaceSize() const { return m_repeatSpacing; }
     50     void setSpaceSize(const IntSize& repeatSpacing)
     51     {
     52         m_repeatSpacing = repeatSpacing;
     53     }
     54 
     55     void setPhaseX(int x) { m_phase.setX(x); }
     56     void setPhaseY(int y) { m_phase.setY(y); }
     57 
     58     void setNoRepeatX(int xOffset);
     59     void setNoRepeatY(int yOffset);
     60 
     61     void useFixedAttachment(const IntPoint& attachmentPoint);
     62 
     63     void clip(const IntRect&);
     64 
     65     void setHasNonLocalGeometry(bool hasNonLocalGeometry = true) { m_hasNonLocalGeometry = hasNonLocalGeometry; }
     66     bool hasNonLocalGeometry() const { return m_hasNonLocalGeometry; }
     67 
     68 private:
     69     IntRect m_destRect;
     70     IntPoint m_destOrigin;
     71     IntPoint m_phase;
     72     IntSize m_tileSize;
     73     IntSize m_repeatSpacing;
     74     bool m_hasNonLocalGeometry; // Has background-attachment: fixed. Implies that we can't always cheaply compute destRect.
     75 };
     76 
     77 #endif // BackgroundImageGeometry_h
     78 
     79 } // namespace blink
     80