| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CC_STUBS_REGION_H_ | 5 #ifndef CC_STUBS_REGION_H_ |
| 6 #define CC_STUBS_REGION_H_ | 6 #define CC_STUBS_REGION_H_ |
| 7 | 7 |
| 8 #include "IntRect.h" | |
| 9 #if INSIDE_WEBKIT_BUILD | 8 #if INSIDE_WEBKIT_BUILD |
| 10 #include "Source/WebCore/platform/graphics/Region.h" | 9 #include "Source/WebCore/platform/graphics/Region.h" |
| 11 #else | 10 #else |
| 12 #include "third_party/WebKit/Source/WebCore/platform/graphics/Region.h" | 11 #include "third_party/WebKit/Source/WebCore/platform/graphics/Region.h" |
| 13 #endif | 12 #endif |
| 13 #include "base/logging.h" |
| 14 #include "ui/gfx/rect.h" | 14 #include "ui/gfx/rect.h" |
| 15 | 15 |
| 16 namespace cc { | 16 namespace cc { |
| 17 | 17 |
| 18 class Region : public WebCore::Region { | 18 class Region : public WebCore::Region { |
| 19 public: | 19 public: |
| 20 Region() { } | 20 Region() { } |
| 21 | 21 |
| 22 Region(const IntRect& rect) | |
| 23 : WebCore::Region(rect) | |
| 24 { | |
| 25 } | |
| 26 | |
| 27 Region(const WebCore::IntRect& rect) | |
| 28 : WebCore::Region(rect) | |
| 29 { | |
| 30 } | |
| 31 | |
| 32 Region(const WebCore::Region& region) | 22 Region(const WebCore::Region& region) |
| 33 : WebCore::Region(region) | 23 : WebCore::Region(region) |
| 34 { | 24 { |
| 35 } | 25 } |
| 36 | 26 |
| 37 Region(const gfx::Rect& rect) | 27 Region(const gfx::Rect& rect) |
| 38 : WebCore::Region(WebCore::IntRect(rect.x(), rect.y(), rect.width(), rec
t.height())) | 28 : WebCore::Region(WebCore::IntRect(rect.x(), rect.y(), rect.width(), rec
t.height())) |
| 39 { | 29 { |
| 40 } | 30 } |
| 41 | 31 |
| 42 bool IsEmpty() const { return isEmpty(); } | 32 bool IsEmpty() const { return isEmpty(); } |
| 43 | 33 |
| 44 bool Contains(const gfx::Point& point) const { return contains(cc::IntPoint(
point)); } | 34 bool Contains(const gfx::Point& point) const { return contains(WebCore::IntP
oint(point.x(), point.y())); } |
| 45 bool Contains(const gfx::Rect& rect) const { return contains(cc::IntRect(rec
t)); } | 35 bool Contains(const gfx::Rect& rect) const { return contains(WebCore::IntRec
t(rect.x(), rect.y(), rect.width(), rect.height())); } |
| 46 void Subtract(const gfx::Rect& rect) { subtract(cc::IntRect(rect)); } | 36 void Subtract(const gfx::Rect& rect) { subtract(WebCore::IntRect(rect.x(), r
ect.y(), rect.width(), rect.height())); } |
| 47 void Subtract(const Region& region) { subtract(region); } | 37 void Subtract(const Region& region) { subtract(region); } |
| 48 void Union(const gfx::Rect& rect) { unite(cc::IntRect(rect)); } | 38 void Union(const gfx::Rect& rect) { unite(WebCore::IntRect(rect.x(), rect.y(
), rect.width(), rect.height())); } |
| 49 void Union(const Region& region) { unite(region); } | 39 void Union(const Region& region) { unite(region); } |
| 50 void Intersect(const gfx::Rect& rect) { intersect(cc::IntRect(rect)); } | 40 void Intersect(const gfx::Rect& rect) { intersect(WebCore::IntRect(rect.x(),
rect.y(), rect.width(), rect.height())); } |
| 51 void Intersect(const Region& region) { intersect(region); } | 41 void Intersect(const Region& region) { intersect(region); } |
| 52 | 42 |
| 53 gfx::Rect bounds() const { return cc::IntRect(WebCore::Region::bounds()); } | 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 }; |
| 54 | 71 |
| 55 private: | 72 private: |
| 56 bool isEmpty() const { return WebCore::Region::isEmpty(); } | 73 bool isEmpty() const { return WebCore::Region::isEmpty(); } |
| 57 bool contains(const IntPoint& point) const { return WebCore::Region::contain
s(point); } | 74 bool contains(const WebCore::IntPoint& point) const { return WebCore::Region
::contains(point); } |
| 58 bool contains(const IntRect& rect) const { return WebCore::Region::contains(
rect); } | 75 bool contains(const WebCore::IntRect& rect) const { return WebCore::Region::
contains(rect); } |
| 59 void subtract(const IntRect& rect) { return WebCore::Region::subtract(rect);
} | 76 void subtract(const WebCore::IntRect& rect) { return WebCore::Region::subtra
ct(rect); } |
| 60 void subtract(const Region& region) { return WebCore::Region::subtract(regio
n); } | 77 void subtract(const Region& region) { return WebCore::Region::subtract(regio
n); } |
| 61 void unite(const IntRect& rect) { return WebCore::Region::unite(rect); } | 78 void unite(const WebCore::IntRect& rect) { return WebCore::Region::unite(rec
t); } |
| 62 void unite(const Region& region) { return WebCore::Region::unite(region); } | 79 void unite(const Region& region) { return WebCore::Region::unite(region); } |
| 63 void intersect(const IntRect& rect) { return WebCore::Region::intersect(rect
); } | 80 void intersect(const WebCore::IntRect& rect) { return WebCore::Region::inter
sect(rect); } |
| 64 void intersect(const Region& region) { return WebCore::Region::intersect(reg
ion); } | 81 void intersect(const Region& region) { return WebCore::Region::intersect(reg
ion); } |
| 82 Vector<WebCore::IntRect> rects() const { return WebCore::Region::rects(); } |
| 65 }; | 83 }; |
| 66 | 84 |
| 67 inline Region subtract(const Region& region, const gfx::Rect& rect) { return Web
Core::intersect(region, cc::IntRect(rect)); } | 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())); } |
| 68 inline Region intersect(const Region& region, const gfx::Rect& rect) { return We
bCore::intersect(region, cc::IntRect(rect)); } | 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() { } |
| 69 | 95 |
| 70 } | 96 } |
| 71 | 97 |
| 72 #endif // CC_STUBS_REGION_H_ | 98 #endif // CC_STUBS_REGION_H_ |
| OLD | NEW |