1 /*
2 * Copyright (C) 2003, 2009, 2012 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26 #ifndef ClipRect_h
27 #define ClipRect_h
28
29 #include "platform/geometry/LayoutRect.h"
30
31 namespace blink {
32
33 class RenderLayer;
34 class HitTestLocation;
35
36 class ClipRect {
37 public:
ClipRect()38 ClipRect()
39 : m_hasRadius(false)
40 { }
41
ClipRect(const LayoutRect & rect)42 ClipRect(const LayoutRect& rect)
43 : m_rect(rect)
44 , m_hasRadius(false)
45 { }
46
rect()47 const LayoutRect& rect() const { return m_rect; }
setRect(const LayoutRect & rect)48 void setRect(const LayoutRect& rect) { m_rect = rect; }
49
hasRadius()50 bool hasRadius() const { return m_hasRadius; }
setHasRadius(bool hasRadius)51 void setHasRadius(bool hasRadius) { m_hasRadius = hasRadius; }
52
53 bool operator==(const ClipRect& other) const { return rect() == other.rect() && hasRadius() == other.hasRadius(); }
54 bool operator!=(const ClipRect& other) const { return rect() != other.rect() || hasRadius() != other.hasRadius(); }
55 bool operator!=(const LayoutRect& otherRect) const { return rect() != otherRect; }
56
intersect(const LayoutRect & other)57 void intersect(const LayoutRect& other) { m_rect.intersect(other); }
intersect(const ClipRect & other)58 void intersect(const ClipRect& other)
59 {
60 m_rect.intersect(other.rect());
61 if (other.hasRadius())
62 m_hasRadius = true;
63 }
move(LayoutUnit x,LayoutUnit y)64 void move(LayoutUnit x, LayoutUnit y) { m_rect.move(x, y); }
move(const LayoutSize & size)65 void move(const LayoutSize& size) { m_rect.move(size); }
moveBy(const LayoutPoint & point)66 void moveBy(const LayoutPoint& point) { m_rect.moveBy(point); }
67
isEmpty()68 bool isEmpty() const { return m_rect.isEmpty(); }
intersects(const LayoutRect & rect)69 bool intersects(const LayoutRect& rect) const { return m_rect.intersects(rect); }
70 bool intersects(const HitTestLocation&) const;
71
72 private:
73 LayoutRect m_rect;
74 bool m_hasRadius;
75 };
76
intersection(const ClipRect & a,const ClipRect & b)77 inline ClipRect intersection(const ClipRect& a, const ClipRect& b)
78 {
79 ClipRect c = a;
80 c.intersect(b);
81 return c;
82 }
83
84 } // namespace blink
85
86 #endif // ClipRect_h
87