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..3844e6b66ce78d33618f31c39d1d7a206595db9f 100644 |
--- a/Source/core/platform/graphics/LayoutSize.h |
+++ b/Source/core/platform/graphics/LayoutSize.h |
@@ -39,6 +39,11 @@ namespace WebCore { |
class LayoutPoint; |
+enum AspectRatioFit { |
+ AspectRatioFitShrink, |
+ AspectRatioFitGrow |
+}; |
+ |
class LayoutSize { |
public: |
LayoutSize() : m_width(0), m_height(0) { } |
@@ -112,6 +117,15 @@ public: |
return LayoutSize(m_height, m_width); |
} |
+ LayoutSize fitToAspectRatio(const LayoutSize& aspectRatio, AspectRatioFit fit) const |
+ { |
+ float heightScale = height().toFloat() / aspectRatio.height().toFloat(); |
+ float widthScale = width().toFloat() / aspectRatio.width().toFloat(); |
+ if ((widthScale > heightScale) != (fit == AspectRatioFitGrow)) |
+ return LayoutSize(height() * aspectRatio.width() / aspectRatio.height(), height()); |
+ return LayoutSize(width(), width() * aspectRatio.height() / aspectRatio.width()); |
+ } |
+ |
private: |
LayoutUnit m_width, m_height; |
}; |