OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012 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 CC_STUBS_REGION_H_ | |
6 #define CC_STUBS_REGION_H_ | |
7 | |
8 #if INSIDE_WEBKIT_BUILD | |
9 #include "Source/WebCore/platform/graphics/Region.h" | |
10 #else | |
11 #include "third_party/WebKit/Source/WebCore/platform/graphics/Region.h" | |
12 #endif | |
13 #include "base/logging.h" | |
14 #include "ui/gfx/rect.h" | |
15 | |
16 namespace cc { | |
17 | |
18 class Region : public WebCore::Region { | |
19 public: | |
20 Region() { } | |
21 | |
22 Region(const WebCore::Region& region) | |
23 : WebCore::Region(region) | |
24 { | |
25 } | |
26 | |
27 Region(const gfx::Rect& rect) | |
28 : WebCore::Region(WebCore::IntRect(rect.x(), rect.y(), rect.width(), rec
t.height())) | |
29 { | |
30 } | |
31 | |
32 bool IsEmpty() const { return isEmpty(); } | |
33 | |
34 bool Contains(const gfx::Point& point) const { return contains(WebCore::IntP
oint(point.x(), point.y())); } | |
35 bool Contains(const gfx::Rect& rect) const { return contains(WebCore::IntRec
t(rect.x(), rect.y(), rect.width(), rect.height())); } | |
36 void Subtract(const gfx::Rect& rect) { subtract(WebCore::IntRect(rect.x(), r
ect.y(), rect.width(), rect.height())); } | |
37 void Subtract(const Region& region) { subtract(region); } | |
38 void Union(const gfx::Rect& rect) { unite(WebCore::IntRect(rect.x(), rect.y(
), rect.width(), rect.height())); } | |
39 void Union(const Region& region) { unite(region); } | |
40 void Intersect(const gfx::Rect& rect) { intersect(WebCore::IntRect(rect.x(),
rect.y(), rect.width(), rect.height())); } | |
41 void Intersect(const Region& region) { intersect(region); } | |
42 | |
43 gfx::Rect bounds() const | |
44 { | |
45 WebCore::IntRect bounds = WebCore::Region::bounds(); | |
46 return gfx::Rect(bounds.x(), bounds.y(), bounds.width(), bounds.height()
); | |
47 } | |
48 | |
49 class Iterator { | |
50 public: | |
51 Iterator(const Region& region); | |
52 ~Iterator(); | |
53 | |
54 gfx::Rect rect() const { | |
55 DCHECK(has_rect()); | |
56 if (!has_rect()) | |
57 return gfx::Rect(); | |
58 return gfx::Rect(m_rects[m_pos].x(), m_rects[m_pos].y(), m_rects[m_p
os].width(), m_rects[m_pos].height()); | |
59 } | |
60 | |
61 void next() { ++m_pos; } | |
62 bool has_rect() const { return m_pos < m_rects.size(); } | |
63 | |
64 // It is expensive to construct the iterator just to get this size. Only | |
65 // do this for testing. | |
66 size_t size() const { return m_rects.size(); } | |
67 private: | |
68 size_t m_pos; | |
69 Vector<WebCore::IntRect> m_rects; | |
70 }; | |
71 | |
72 private: | |
73 bool isEmpty() const { return WebCore::Region::isEmpty(); } | |
74 bool contains(const WebCore::IntPoint& point) const { return WebCore::Region
::contains(point); } | |
75 bool contains(const WebCore::IntRect& rect) const { return WebCore::Region::
contains(rect); } | |
76 void subtract(const WebCore::IntRect& rect) { return WebCore::Region::subtra
ct(rect); } | |
77 void subtract(const Region& region) { return WebCore::Region::subtract(regio
n); } | |
78 void unite(const WebCore::IntRect& rect) { return WebCore::Region::unite(rec
t); } | |
79 void unite(const Region& region) { return WebCore::Region::unite(region); } | |
80 void intersect(const WebCore::IntRect& rect) { return WebCore::Region::inter
sect(rect); } | |
81 void intersect(const Region& region) { return WebCore::Region::intersect(reg
ion); } | |
82 Vector<WebCore::IntRect> rects() const { return WebCore::Region::rects(); } | |
83 }; | |
84 | |
85 inline Region subtract(const Region& region, const gfx::Rect& rect) { return Web
Core::intersect(region, WebCore::IntRect(rect.x(), rect.y(), rect.width(), rect.
height())); } | |
86 inline Region intersect(const Region& region, const gfx::Rect& rect) { return We
bCore::intersect(region, WebCore::IntRect(rect.x(), rect.y(), rect.width(), rect
.height())); } | |
87 | |
88 inline Region::Iterator::Iterator(const Region& region) | |
89 : m_pos(0) | |
90 , m_rects(region.rects()) | |
91 { | |
92 } | |
93 | |
94 inline Region::Iterator::~Iterator() { } | |
95 | |
96 } | |
97 | |
98 #endif // CC_STUBS_REGION_H_ | |
OLD | NEW |