Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1386)

Unified Diff: Source/core/platform/graphics/LayoutSize.h

Issue 22482004: Add support for the object-fit CSS property. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Code review Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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;
};

Powered by Google App Engine
This is Rietveld 408576698