OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 // Defines a simple integer rectangle class. The containment semantics | 5 // Defines a simple integer rectangle class. The containment semantics |
6 // are array-like; that is, the coordinate (x, y) is considered to be | 6 // are array-like; that is, the coordinate (x, y) is considered to be |
7 // contained by the rectangle, but the coordinate (x + width, y) is not. | 7 // contained by the rectangle, but the coordinate (x + width, y) is not. |
8 // The class will happily let you create malformed rectangles (that is, | 8 // The class will happily let you create malformed rectangles (that is, |
9 // rectangles with negative width and/or height), but there will be assertions | 9 // rectangles with negative width and/or height), but there will be assertions |
10 // in the operations (such as Contains()) to complain in this case. | 10 // in the operations (such as Contains()) to complain in this case. |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 // Fits as much of the receiving rectangle into the supplied rectangle as | 157 // Fits as much of the receiving rectangle into the supplied rectangle as |
158 // possible, returning the result. For example, if the receiver had | 158 // possible, returning the result. For example, if the receiver had |
159 // a x-location of 2 and a width of 4, and the supplied rectangle had | 159 // a x-location of 2 and a width of 4, and the supplied rectangle had |
160 // an x-location of 0 with a width of 5, the returned rectangle would have | 160 // an x-location of 0 with a width of 5, the returned rectangle would have |
161 // an x-location of 1 with a width of 4. | 161 // an x-location of 1 with a width of 4. |
162 Rect AdjustToFit(const Rect& rect) const; | 162 Rect AdjustToFit(const Rect& rect) const; |
163 | 163 |
164 // Returns the center of this rectangle. | 164 // Returns the center of this rectangle. |
165 Point CenterPoint() const; | 165 Point CenterPoint() const; |
166 | 166 |
| 167 // Return a rectangle that has the same center point but with a size capped |
| 168 // at given |size|. |
| 169 Rect Center(const gfx::Size& size) const; |
| 170 |
167 // Returns true if this rectangle shares an entire edge (i.e., same width or | 171 // Returns true if this rectangle shares an entire edge (i.e., same width or |
168 // same height) with the given rectangle, and the rectangles do not overlap. | 172 // same height) with the given rectangle, and the rectangles do not overlap. |
169 bool SharesEdgeWith(const gfx::Rect& rect) const; | 173 bool SharesEdgeWith(const gfx::Rect& rect) const; |
170 | 174 |
171 private: | 175 private: |
172 gfx::Point origin_; | 176 gfx::Point origin_; |
173 gfx::Size size_; | 177 gfx::Size size_; |
174 }; | 178 }; |
175 | 179 |
176 std::ostream& operator<<(std::ostream& out, const gfx::Rect& r); | 180 std::ostream& operator<<(std::ostream& out, const gfx::Rect& r); |
177 | 181 |
178 } // namespace gfx | 182 } // namespace gfx |
179 | 183 |
180 #endif // GFX_RECT_H_ | 184 #endif // GFX_RECT_H_ |
OLD | NEW |