Chromium Code Reviews| Index: Source/core/platform/graphics/LayoutSize.h |
| diff --git a/Source/core/platform/graphics/LayoutSize.h b/Source/core/platform/graphics/LayoutSize.h |
| index 3bce732113d63b08f772bc32e6d75e8a8da6a34c..4821adb6bd5e7bc1af3c9901793dc38cd5b7bec3 100644 |
| --- a/Source/core/platform/graphics/LayoutSize.h |
| +++ b/Source/core/platform/graphics/LayoutSize.h |
| @@ -170,6 +170,24 @@ inline LayoutSize roundedLayoutSize(const FloatSize& s) |
| return LayoutSize(s); |
| } |
| +// Convert the specified scaled size to one that agrees with the specified aspect ratio |
| +// (expressed as a size, too). |
|
ojan
2013/08/08 02:36:55
Blink (and WebKit) style is to leave out "what" co
mstensho (USE GERRIT)
2013/08/08 07:26:42
Done.
|
| +enum AspectRatioFit { // How to set a size with the specified aspect ratio |
| + AspectRatioFitShrink, // Shrink in one dimension to gain aspect ratio |
| + AspectRatioFitGrow // Grow in one dimension to gain aspect ratio |
| +}; |
|
ojan
2013/08/08 02:36:55
Needs another line-break here.
mstensho (USE GERRIT)
2013/08/08 07:26:42
Done.
|
| +inline LayoutSize fitLayoutSizeToAspectRatio(const LayoutSize& scaledSize, const LayoutSize& aspectRatio, AspectRatioFit fit) |
|
ojan
2013/08/08 02:36:55
I think this method makes more sense as a member o
mstensho (USE GERRIT)
2013/08/08 07:26:42
Done.
|
| +{ |
| + // Set a new width or height to get to a size that honors the aspect ratio. If fit is |
| + // AspectRatioFitGrow, increase in the dimension that is scaled less. Otherwise, |
| + // decrease in the dimension that is scaled more. |
| + float heightScale = scaledSize.height().toFloat() / aspectRatio.height().toFloat(); |
| + float widthScale = scaledSize.width().toFloat() / aspectRatio.width().toFloat(); |
| + if ((widthScale > heightScale) != (fit == AspectRatioFitGrow)) |
| + return LayoutSize(scaledSize.height() * aspectRatio.width() / aspectRatio.height(), scaledSize.height()); |
| + return LayoutSize(scaledSize.width(), scaledSize.width() * aspectRatio.height() / aspectRatio.width()); |
| +} |
| + |
| } // namespace WebCore |
| #endif // LayoutSize_h |