• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2003, 2006, 2009 Apple Inc. All rights reserved.
3  * Copyright (C) 2010 Google Inc. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1.  Redistributions of source code must retain the above copyright
10  *     notice, this list of conditions and the following disclaimer.
11  * 2.  Redistributions in binary form must reproduce the above copyright
12  *     notice, this list of conditions and the following disclaimer in the
13  *     documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
16  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18  * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
19  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  */
26 
27 #ifndef RoundedIntRect_h
28 #define RoundedIntRect_h
29 
30 #include "IntRect.h"
31 
32 namespace WebCore {
33 
34 
35 class RoundedIntRect {
36 public:
37     class Radii {
38     public:
Radii()39         Radii() {}
Radii(const IntSize & topLeft,const IntSize & topRight,const IntSize & bottomLeft,const IntSize & bottomRight)40         Radii(const IntSize& topLeft, const IntSize& topRight, const IntSize& bottomLeft, const IntSize& bottomRight)
41             : m_topLeft(topLeft)
42             , m_topRight(topRight)
43             , m_bottomLeft(bottomLeft)
44             , m_bottomRight(bottomRight)
45         {
46         }
47 
setTopLeft(const IntSize & size)48         void setTopLeft(const IntSize& size) { m_topLeft = size; }
setTopRight(const IntSize & size)49         void setTopRight(const IntSize& size) { m_topRight = size; }
setBottomLeft(const IntSize & size)50         void setBottomLeft(const IntSize& size) { m_bottomLeft = size; }
setBottomRight(const IntSize & size)51         void setBottomRight(const IntSize& size) { m_bottomRight = size; }
topLeft()52         const IntSize& topLeft() const { return m_topLeft; }
topRight()53         const IntSize& topRight() const { return m_topRight; }
bottomLeft()54         const IntSize& bottomLeft() const { return m_bottomLeft; }
bottomRight()55         const IntSize& bottomRight() const { return m_bottomRight; }
56 
57         bool isZero() const;
58 
59         void includeLogicalEdges(const Radii& edges, bool isHorizontal, bool includeLogicalLeftEdge, bool includeLogicalRightEdge);
60         void excludeLogicalEdges(bool isHorizontal, bool excludeLogicalLeftEdge, bool excludeLogicalRightEdge);
61 
62         void scale(float factor);
63         void expand(int topWidth, int bottomWidth, int leftWidth, int rightWidth);
expand(int size)64         void expand(int size) { expand(size, size, size, size); }
shrink(int topWidth,int bottomWidth,int leftWidth,int rightWidth)65         void shrink(int topWidth, int bottomWidth, int leftWidth, int rightWidth) { expand(-topWidth, -bottomWidth, -leftWidth, -rightWidth); }
shrink(int size)66         void shrink(int size) { shrink(size, size, size, size); }
67 
68     private:
69         IntSize m_topLeft;
70         IntSize m_topRight;
71         IntSize m_bottomLeft;
72         IntSize m_bottomRight;
73     };
74 
75     explicit RoundedIntRect(const IntRect&, const Radii& = Radii());
76     RoundedIntRect(int x, int y, int width, int height);
77     RoundedIntRect(const IntRect&, const IntSize& topLeft, const IntSize& topRight, const IntSize& bottomLeft, const IntSize& bottomRight);
78 
rect()79     const IntRect& rect() const { return m_rect; }
radii()80     const Radii& radii() const { return m_radii; }
isRounded()81     bool isRounded() const { return !m_radii.isZero(); }
isEmpty()82     bool isEmpty() const { return m_rect.isEmpty(); }
83 
setRect(const IntRect & rect)84     void setRect(const IntRect& rect) { m_rect = rect; }
setRadii(const Radii & radii)85     void setRadii(const Radii& radii) { m_radii = radii; }
86 
move(const IntSize & size)87     void move(const IntSize& size) { m_rect.move(size); }
inflate(int size)88     void inflate(int size) { m_rect.inflate(size);  }
inflateWithRadii(int size)89     void inflateWithRadii(int size) { m_rect.inflate(size); m_radii.expand(size); }
expandRadii(int size)90     void expandRadii(int size) { m_radii.expand(size); }
shrinkRadii(int size)91     void shrinkRadii(int size) { m_radii.shrink(size); }
92 
93     void includeLogicalEdges(const Radii& edges, bool isHorizontal, bool includeLogicalLeftEdge, bool includeLogicalRightEdge);
94     void excludeLogicalEdges(bool isHorizontal, bool excludeLogicalLeftEdge, bool excludeLogicalRightEdge);
95 
96     bool isRenderable() const;
97 
98 private:
99     IntRect m_rect;
100     Radii m_radii;
101 };
102 
103 inline bool operator==(const RoundedIntRect::Radii& a, const RoundedIntRect::Radii& b)
104 {
105     return a.topLeft() == b.topLeft() && a.topRight() == b.topRight() && a.bottomLeft() == b.bottomLeft() && a.bottomRight() == b.bottomRight();
106 }
107 
108 inline bool operator==(const RoundedIntRect& a, const RoundedIntRect& b)
109 {
110     return a.rect() == b.rect() && a.radii() == b.radii();
111 }
112 
113 
114 } // namespace WebCore
115 
116 #endif // RoundedIntRect_h
117