diff options
author | danakj@chromium.org <danakj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-10-23 16:51:47 +0000 |
---|---|---|
committer | danakj@chromium.org <danakj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-10-23 16:51:47 +0000 |
commit | d40305001bfd61bef7e118c8580895f68d36b163 (patch) | |
tree | 05a4a731233c5cb3deb56306019231e22d474deb /ui/gfx/rect_base.h | |
parent | ea75f30985b5b24627bed4c613a1ef403235aa02 (diff) | |
download | chromium_src-d40305001bfd61bef7e118c8580895f68d36b163.zip chromium_src-d40305001bfd61bef7e118c8580895f68d36b163.tar.gz chromium_src-d40305001bfd61bef7e118c8580895f68d36b163.tar.bz2 |
Make gfx::Rect class operations consistently mutate the class they are called on.
Currently some methods mutate the class, and some return a new value, requiring
API users to know what kind of method they are calling each time, and making
inconsistent code. For example:
gfx::Rect rect;
rect.Inset(1, 1, 1, 1);
rect = rect.Intersect(other_rect);
rect.Offset(1, 1);
Instead of:
gfx::Rect rect;
rect.Inset(1, 1, 1, 1);
rect.Intersect(other_rect);
rect.Offset(1, 1);
We could go either way - making the class immutable or all methods return a new
instance - but I believe it is better to instead make all methods mutate the
class. This allows for shorter lines of code by avoiding having to repeat the
object's name twice in order to change it.
This patch changes gfx::Rect classes and all the callsites that uses these
methods. It should make no change in behaviour, so no new tests added.
R=sky
BUG=147395
Review URL: https://codereview.chromium.org/11110004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@163579 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/gfx/rect_base.h')
-rw-r--r-- | ui/gfx/rect_base.h | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/ui/gfx/rect_base.h b/ui/gfx/rect_base.h index 08c9121..a9ddda4 100644 --- a/ui/gfx/rect_base.h +++ b/ui/gfx/rect_base.h @@ -100,31 +100,31 @@ class UI_EXPORT RectBase { bool Intersects(const Class& rect) const; // Computes the intersection of this rectangle with the given rectangle. - Class Intersect(const Class& rect) const WARN_UNUSED_RESULT; + void Intersect(const Class& rect); // Computes the union of this rectangle with the given rectangle. The union // is the smallest rectangle containing both rectangles. - Class Union(const Class& rect) const WARN_UNUSED_RESULT; + void Union(const Class& rect); // Computes the rectangle resulting from subtracting |rect| from |this|. If // |rect| does not intersect completely in either the x- or y-direction, then - // |*this| is returned. If |rect| contains |this|, then an empty Rect is - // returned. - Class Subtract(const Class& rect) const WARN_UNUSED_RESULT; + // |*this| does not change. If |rect| contains |this|, then an empty Rect is + // the result. + void Subtract(const Class& rect); // Fits as much of the receiving rectangle into the supplied rectangle as - // possible, returning the result. For example, if the receiver had + // possible, becoming the result. For example, if the receiver had // a x-location of 2 and a width of 4, and the supplied rectangle had // an x-location of 0 with a width of 5, the returned rectangle would have // an x-location of 1 with a width of 4. - Class AdjustToFit(const Class& rect) const WARN_UNUSED_RESULT; + void AdjustToFit(const Class& rect); // Returns the center of this rectangle. PointClass CenterPoint() const; - // Return a rectangle that has the same center point but with a size capped + // Becomes a rectangle that has the same center point but with a size capped // at given |size|. - Class Center(const SizeClass& size) const WARN_UNUSED_RESULT; + void ClampToCenteredSize(const SizeClass& size); // Splits |this| in two halves, |left_half| and |right_half|. void SplitVertically(Class* left_half, Class* right_half) const; |