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

Unified Diff: third_party/WebKit/Source/core/layout/LayoutBoxModelObject.cpp

Issue 1756763004: Merge image sizing algorithms (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix unused variable 'styleImage' in release Created 4 years, 9 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: third_party/WebKit/Source/core/layout/LayoutBoxModelObject.cpp
diff --git a/third_party/WebKit/Source/core/layout/LayoutBoxModelObject.cpp b/third_party/WebKit/Source/core/layout/LayoutBoxModelObject.cpp
index f7c413e7cff1ac79a732417b472a9ca2b54c3dc1..cc61a1398d413478ea9209a2efc7dbd7cc9cd433 100644
--- a/third_party/WebKit/Source/core/layout/LayoutBoxModelObject.cpp
+++ b/third_party/WebKit/Source/core/layout/LayoutBoxModelObject.cpp
@@ -690,93 +690,6 @@ LayoutUnit LayoutBoxModelObject::computedCSSPadding(const Length& padding) const
return minimumValueForLength(padding, w);
}
-static inline LayoutUnit resolveWidthForRatio(LayoutUnit height, const FloatSize& intrinsicRatio)
-{
- return LayoutUnit(height * intrinsicRatio.width() / intrinsicRatio.height());
-}
-
-static inline LayoutUnit resolveHeightForRatio(LayoutUnit width, const FloatSize& intrinsicRatio)
-{
- return LayoutUnit(width * intrinsicRatio.height() / intrinsicRatio.width());
-}
-
-static inline LayoutSize resolveAgainstIntrinsicWidthOrHeightAndRatio(const LayoutSize& size, const FloatSize& intrinsicRatio, LayoutUnit useWidth, LayoutUnit useHeight)
-{
- if (intrinsicRatio.isEmpty()) {
- if (useWidth)
- return LayoutSize(useWidth, size.height());
- return LayoutSize(size.width(), useHeight);
- }
-
- if (useWidth)
- return LayoutSize(useWidth, resolveHeightForRatio(useWidth, intrinsicRatio));
- return LayoutSize(resolveWidthForRatio(useHeight, intrinsicRatio), useHeight);
-}
-
-static inline LayoutSize resolveAgainstIntrinsicRatio(const LayoutSize& size, const FloatSize& intrinsicRatio)
-{
- // Two possible solutions: (size.width(), solutionHeight) or (solutionWidth, size.height())
- // "... must be assumed to be the largest dimensions..." = easiest answer: the rect with the largest surface area.
-
- LayoutUnit solutionWidth = resolveWidthForRatio(size.height(), intrinsicRatio);
- LayoutUnit solutionHeight = resolveHeightForRatio(size.width(), intrinsicRatio);
- if (solutionWidth <= size.width()) {
- if (solutionHeight <= size.height()) {
- // If both solutions fit, choose the one covering the larger area.
- LayoutUnit areaOne = solutionWidth * size.height();
- LayoutUnit areaTwo = size.width() * solutionHeight;
- if (areaOne < areaTwo)
- return LayoutSize(size.width(), solutionHeight);
- return LayoutSize(solutionWidth, size.height());
- }
-
- // Only the first solution fits.
- return LayoutSize(solutionWidth, size.height());
- }
-
- // Only the second solution fits, assert that.
- ASSERT(solutionHeight <= size.height());
- return LayoutSize(size.width(), solutionHeight);
-}
-
-LayoutSize LayoutBoxModelObject::calculateImageIntrinsicDimensions(StyleImage* image, const LayoutSize& positioningAreaSize, ScaleByEffectiveZoomOrNot shouldScaleOrNot) const
-{
- // A generated image without a fixed size, will always return the container size as intrinsic size.
- if (image->isGeneratedImage() && image->usesImageContainerSize())
- return positioningAreaSize;
-
- FloatSize intrinsicSize;
- FloatSize intrinsicRatio;
- image->computeIntrinsicDimensions(this, intrinsicSize, intrinsicRatio);
-
- LayoutSize resolvedSize(intrinsicSize);
- LayoutSize minimumSize(resolvedSize.width() > LayoutUnit() ? LayoutUnit(1) : LayoutUnit(),
- resolvedSize.height() > LayoutUnit() ? LayoutUnit(1) : LayoutUnit());
- if (shouldScaleOrNot == ScaleByEffectiveZoom)
- resolvedSize.scale(style()->effectiveZoom());
- resolvedSize.clampToMinimumSize(minimumSize);
-
- if (!resolvedSize.isEmpty())
- return resolvedSize;
-
- // If the image has one of either an intrinsic width or an intrinsic height:
- // * and an intrinsic aspect ratio, then the missing dimension is calculated from the given dimension and the ratio.
- // * and no intrinsic aspect ratio, then the missing dimension is assumed to be the size of the rectangle that
- // establishes the coordinate system for the 'background-position' property.
- if (resolvedSize.width() > LayoutUnit() || resolvedSize.height() > LayoutUnit())
- return resolveAgainstIntrinsicWidthOrHeightAndRatio(positioningAreaSize, intrinsicRatio, resolvedSize.width(), resolvedSize.height());
-
- // If the image has no intrinsic dimensions and has an intrinsic ratio the dimensions must be assumed to be the
- // largest dimensions at that ratio such that neither dimension exceeds the dimensions of the rectangle that
- // establishes the coordinate system for the 'background-position' property.
- if (!intrinsicRatio.isEmpty())
- return resolveAgainstIntrinsicRatio(positioningAreaSize, intrinsicRatio);
-
- // If the image has no intrinsic ratio either, then the dimensions must be assumed to be the rectangle that
- // establishes the coordinate system for the 'background-position' property.
- return positioningAreaSize;
-}
-
bool LayoutBoxModelObject::boxShadowShouldBeAppliedToBackground(BackgroundBleedAvoidance bleedAvoidance, const InlineFlowBox* inlineFlowBox) const
{
if (bleedAvoidance != BackgroundBleedNone)

Powered by Google App Engine
This is Rietveld 408576698