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 // 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 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 x : static_cast<int>(std::floor(rect.right() * x_scale)); | 263 x : static_cast<int>(std::floor(rect.right() * x_scale)); |
264 int b = rect.height() == 0 ? | 264 int b = rect.height() == 0 ? |
265 y : static_cast<int>(std::floor(rect.bottom() * y_scale)); | 265 y : static_cast<int>(std::floor(rect.bottom() * y_scale)); |
266 return Rect(x, y, r - x, b - y); | 266 return Rect(x, y, r - x, b - y); |
267 } | 267 } |
268 | 268 |
269 inline Rect ScaleToEnclosedRect(const Rect& rect, float scale) { | 269 inline Rect ScaleToEnclosedRect(const Rect& rect, float scale) { |
270 return ScaleToEnclosedRect(rect, scale, scale); | 270 return ScaleToEnclosedRect(rect, scale, scale); |
271 } | 271 } |
272 | 272 |
| 273 // Will make the |p| fit inside |rect|, along the ledge that was closest to its |
| 274 // original position. |
| 275 GFX_EXPORT Point ConstrainToEnclosingRect(const Rect& rect, const Point& p); |
| 276 |
273 // This is declared here for use in gtest-based unit tests but is defined in | 277 // This is declared here for use in gtest-based unit tests but is defined in |
274 // the gfx_test_support target. Depend on that to use this in your unit test. | 278 // the gfx_test_support target. Depend on that to use this in your unit test. |
275 // This should not be used in production code - call ToString() instead. | 279 // This should not be used in production code - call ToString() instead. |
276 void PrintTo(const Rect& rect, ::std::ostream* os); | 280 void PrintTo(const Rect& rect, ::std::ostream* os); |
277 | 281 |
278 } // namespace gfx | 282 } // namespace gfx |
279 | 283 |
280 #endif // UI_GFX_GEOMETRY_RECT_H_ | 284 #endif // UI_GFX_GEOMETRY_RECT_H_ |
OLD | NEW |