Index: ui/gfx/rect_base_impl.h |
diff --git a/ui/gfx/rect_base_impl.h b/ui/gfx/rect_base_impl.h |
index ab71f4278daf53f66034cb48ee1674449f0524ef..ad9fa8cf23f45a052aad5c93c8a4c0ad5e59e137 100644 |
--- a/ui/gfx/rect_base_impl.h |
+++ b/ui/gfx/rect_base_impl.h |
@@ -165,8 +165,13 @@ template<typename Class, |
typename SizeClass, |
typename InsetsClass, |
typename Type> |
-Class RectBase<Class, PointClass, SizeClass, InsetsClass, Type>::Intersect( |
- const Class& rect) const { |
+void RectBase<Class, PointClass, SizeClass, InsetsClass, Type>::Intersect( |
+ const Class& rect) { |
+ if (IsEmpty() || rect.IsEmpty()) { |
+ SetRect(0, 0, 0, 0); |
+ return; |
+ } |
+ |
Type rx = std::max(x(), rect.x()); |
Type ry = std::max(y(), rect.y()); |
Type rr = std::min(right(), rect.right()); |
@@ -175,7 +180,7 @@ Class RectBase<Class, PointClass, SizeClass, InsetsClass, Type>::Intersect( |
if (rx >= rr || ry >= rb) |
rx = ry = rr = rb = 0; // non-intersecting |
- return Class(rx, ry, rr - rx, rb - ry); |
+ SetRect(rx, ry, rr - rx, rb - ry); |
} |
template<typename Class, |
@@ -183,20 +188,22 @@ template<typename Class, |
typename SizeClass, |
typename InsetsClass, |
typename Type> |
-Class RectBase<Class, PointClass, SizeClass, InsetsClass, Type>::Union( |
- const Class& rect) const { |
+void RectBase<Class, PointClass, SizeClass, InsetsClass, Type>::Union( |
+ const Class& rect) { |
// special case empty rects... |
sky
2012/10/12 16:26:38
Remove this comment, it depends clarify anything.
danakj
2012/10/19 20:33:53
Done.
|
- if (IsEmpty()) |
- return rect; |
+ if (IsEmpty()) { |
+ SetRect(rect.x(), rect.y(), rect.width(), rect.height()); |
sky
2012/10/12 16:26:38
this = rect ?
danakj
2012/10/19 20:33:53
Done.
|
+ return; |
+ } |
if (rect.IsEmpty()) |
- return *static_cast<const Class*>(this); |
+ return; |
Type rx = std::min(x(), rect.x()); |
Type ry = std::min(y(), rect.y()); |
Type rr = std::max(right(), rect.right()); |
Type rb = std::max(bottom(), rect.bottom()); |
- return Class(rx, ry, rr - rx, rb - ry); |
+ SetRect(rx, ry, rr - rx, rb - ry); |
} |
template<typename Class, |
@@ -204,13 +211,15 @@ template<typename Class, |
typename SizeClass, |
typename InsetsClass, |
typename Type> |
-Class RectBase<Class, PointClass, SizeClass, InsetsClass, Type>::Subtract( |
- const Class& rect) const { |
+void RectBase<Class, PointClass, SizeClass, InsetsClass, Type>::Subtract( |
+ const Class& rect) { |
// boundary cases: |
if (!Intersects(rect)) |
- return *static_cast<const Class*>(this); |
- if (rect.Contains(*static_cast<const Class*>(this))) |
- return Class(); |
+ return; |
+ if (rect.Contains(*static_cast<const Class*>(this))) { |
+ SetRect(0, 0, 0, 0); |
+ return; |
+ } |
Type rx = x(); |
Type ry = y(); |
@@ -232,7 +241,7 @@ Class RectBase<Class, PointClass, SizeClass, InsetsClass, Type>::Subtract( |
rb = rect.y(); |
} |
} |
- return Class(rx, ry, rr - rx, rb - ry); |
+ SetRect(rx, ry, rr - rx, rb - ry); |
} |
template<typename Class, |
@@ -240,15 +249,15 @@ template<typename Class, |
typename SizeClass, |
typename InsetsClass, |
typename Type> |
-Class RectBase<Class, PointClass, SizeClass, InsetsClass, Type>::AdjustToFit( |
- const Class& rect) const { |
+void RectBase<Class, PointClass, SizeClass, InsetsClass, Type>::AdjustToFit( |
+ const Class& rect) { |
Type new_x = x(); |
Type new_y = y(); |
Type new_width = width(); |
Type new_height = height(); |
AdjustAlongAxis(rect.x(), rect.width(), &new_x, &new_width); |
AdjustAlongAxis(rect.y(), rect.height(), &new_y, &new_height); |
- return Class(new_x, new_y, new_width, new_height); |
+ SetRect(new_x, new_y, new_width, new_height); |
} |
template<typename Class, |
@@ -266,13 +275,13 @@ template<typename Class, |
typename SizeClass, |
typename InsetsClass, |
typename Type> |
-Class RectBase<Class, PointClass, SizeClass, InsetsClass, Type>::Center( |
- const SizeClass& size) const { |
+void RectBase<Class, PointClass, SizeClass, InsetsClass, Type>:: |
+ ClampToCenteredSize(const SizeClass& size) { |
Type new_width = std::min(width(), size.width()); |
Type new_height = std::min(height(), size.height()); |
Type new_x = x() + (width() - new_width) / 2; |
Type new_y = y() + (height() - new_height) / 2; |
- return Class(new_x, new_y, new_width, new_height); |
+ SetRect(new_x, new_y, new_width, new_height); |
} |
template<typename Class, |