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

Unified Diff: Source/core/rendering/RenderReplaced.cpp

Issue 26390004: Rework SVG sizing (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fix mishap during rebase in svg.css Created 6 years, 8 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/rendering/RenderReplaced.cpp
diff --git a/Source/core/rendering/RenderReplaced.cpp b/Source/core/rendering/RenderReplaced.cpp
index cebffbb9151b8cdbd3f59b11c09a0833f9f74846..353f974bcd0a68e8ae1361e7457ee17ef4d388dc 100644
--- a/Source/core/rendering/RenderReplaced.cpp
+++ b/Source/core/rendering/RenderReplaced.cpp
@@ -271,28 +271,21 @@ static inline bool rendererHasAspectRatio(const RenderObject* renderer)
return renderer->isImage() || renderer->isCanvas() || renderer->isVideo();
}
-void RenderReplaced::computeAspectRatioInformationForRenderBox(RenderBox* contentRenderer, FloatSize& constrainedSize, double& intrinsicRatio, bool& isPercentageIntrinsicSize) const
+void RenderReplaced::computeAspectRatioInformationForRenderBox(RenderBox* contentRenderer, FloatSize& constrainedSize, double& intrinsicRatio) const
{
FloatSize intrinsicSize;
if (contentRenderer) {
- contentRenderer->computeIntrinsicRatioInformation(intrinsicSize, intrinsicRatio, isPercentageIntrinsicSize);
- if (intrinsicRatio)
- ASSERT(!isPercentageIntrinsicSize);
+ contentRenderer->computeIntrinsicRatioInformation(intrinsicSize, intrinsicRatio);
// Handle zoom & vertical writing modes here, as the embedded document doesn't know about them.
- if (!isPercentageIntrinsicSize) {
- intrinsicSize.scale(style()->effectiveZoom());
- if (isRenderImage())
- intrinsicSize.scale(toRenderImage(this)->imageDevicePixelRatio());
- }
-
- if (rendererHasAspectRatio(this) && isPercentageIntrinsicSize)
- intrinsicRatio = 1;
+ intrinsicSize.scale(style()->effectiveZoom());
+ if (isRenderImage())
+ intrinsicSize.scale(toRenderImage(this)->imageDevicePixelRatio());
// Update our intrinsic size to match what the content renderer has computed, so that when we
// constrain the size below, the correct intrinsic size will be obtained for comparison against
// min and max widths.
- if (intrinsicRatio && !isPercentageIntrinsicSize && !intrinsicSize.isEmpty())
+ if (intrinsicRatio && !intrinsicSize.isEmpty())
m_intrinsicSize = LayoutSize(intrinsicSize);
if (!isHorizontalWritingMode()) {
@@ -301,12 +294,9 @@ void RenderReplaced::computeAspectRatioInformationForRenderBox(RenderBox* conten
intrinsicSize = intrinsicSize.transposedSize();
}
} else {
- computeIntrinsicRatioInformation(intrinsicSize, intrinsicRatio, isPercentageIntrinsicSize);
- if (intrinsicRatio) {
- ASSERT(!isPercentageIntrinsicSize);
- if (!intrinsicSize.isEmpty())
- m_intrinsicSize = LayoutSize(isHorizontalWritingMode() ? intrinsicSize : intrinsicSize.transposedSize());
- }
+ computeIntrinsicRatioInformation(intrinsicSize, intrinsicRatio);
+ if (intrinsicRatio && !intrinsicSize.isEmpty())
+ m_intrinsicSize = LayoutSize(isHorizontalWritingMode() ? intrinsicSize : intrinsicSize.transposedSize());
}
// Now constrain the intrinsic size along each axis according to minimum and maximum width/heights along the
@@ -316,7 +306,7 @@ void RenderReplaced::computeAspectRatioInformationForRenderBox(RenderBox* conten
// FIXME: In the long term, it might be better to just return this code more to the way it used to be before this
// function was added, since all it has done is make the code more unclear.
constrainedSize = intrinsicSize;
- if (intrinsicRatio && !isPercentageIntrinsicSize && !intrinsicSize.isEmpty() && style()->logicalWidth().isAuto() && style()->logicalHeight().isAuto()) {
+ if (intrinsicRatio && !intrinsicSize.isEmpty() && style()->logicalWidth().isAuto() && style()->logicalHeight().isAuto()) {
// We can't multiply or divide by 'intrinsicRatio' here, it breaks tests, like fast/images/zoomed-img-size.html, which
// can only be fixed once subpixel precision is available for things like intrinsicWidth/Height - which include zoom!
constrainedSize.setWidth(RenderBox::computeReplacedLogicalHeight() * intrinsicSize.width() / intrinsicSize.height());
@@ -364,11 +354,10 @@ LayoutRect RenderReplaced::replacedContentRect(const LayoutSize* overriddenIntri
return finalRect;
}
-void RenderReplaced::computeIntrinsicRatioInformation(FloatSize& intrinsicSize, double& intrinsicRatio, bool& isPercentageIntrinsicSize) const
+void RenderReplaced::computeIntrinsicRatioInformation(FloatSize& intrinsicSize, double& intrinsicRatio) const
{
// If there's an embeddedContentBox() of a remote, referenced document available, this code-path should never be used.
ASSERT(!embeddedContentBox());
- isPercentageIntrinsicSize = false;
intrinsicSize = FloatSize(intrinsicLogicalWidth().toFloat(), intrinsicLogicalHeight().toFloat());
// Figure out if we need to compute an intrinsic ratio.
@@ -386,25 +375,24 @@ LayoutUnit RenderReplaced::computeReplacedLogicalWidth(ShouldComputePreferred sh
RenderBox* contentRenderer = embeddedContentBox();
// 10.3.2 Inline, replaced elements: http://www.w3.org/TR/CSS21/visudet.html#inline-replaced-width
- bool isPercentageIntrinsicSize = false;
double intrinsicRatio = 0;
FloatSize constrainedSize;
- computeAspectRatioInformationForRenderBox(contentRenderer, constrainedSize, intrinsicRatio, isPercentageIntrinsicSize);
+ computeAspectRatioInformationForRenderBox(contentRenderer, constrainedSize, intrinsicRatio);
if (style()->logicalWidth().isAuto()) {
- bool heightIsAuto = style()->logicalHeight().isAuto();
- bool hasIntrinsicWidth = !isPercentageIntrinsicSize && constrainedSize.width() > 0;
+ bool computedHeightIsAuto = hasAutoHeightOrContainingBlockWithAutoHeight();
+ bool hasIntrinsicWidth = constrainedSize.width() > 0;
// If 'height' and 'width' both have computed values of 'auto' and the element also has an intrinsic width, then that intrinsic width is the used value of 'width'.
- if (heightIsAuto && hasIntrinsicWidth)
+ if (computedHeightIsAuto && hasIntrinsicWidth)
return computeReplacedLogicalWidthRespectingMinMaxWidth(constrainedSize.width(), shouldComputePreferred);
- bool hasIntrinsicHeight = !isPercentageIntrinsicSize && constrainedSize.height() > 0;
- if (intrinsicRatio || isPercentageIntrinsicSize) {
+ bool hasIntrinsicHeight = constrainedSize.height() > 0;
+ if (intrinsicRatio) {
// If 'height' and 'width' both have computed values of 'auto' and the element has no intrinsic width, but does have an intrinsic height and intrinsic ratio;
// or if 'width' has a computed value of 'auto', 'height' has some other computed value, and the element does have an intrinsic ratio; then the used value
// of 'width' is: (used height) * (intrinsic ratio)
- if (intrinsicRatio && ((heightIsAuto && !hasIntrinsicWidth && hasIntrinsicHeight) || !heightIsAuto)) {
+ if (intrinsicRatio && ((computedHeightIsAuto && !hasIntrinsicWidth && hasIntrinsicHeight) || !computedHeightIsAuto)) {
LayoutUnit logicalHeight = computeReplacedLogicalHeight();
return computeReplacedLogicalWidthRespectingMinMaxWidth(roundToInt(round(logicalHeight * intrinsicRatio)), shouldComputePreferred);
}
@@ -412,7 +400,7 @@ LayoutUnit RenderReplaced::computeReplacedLogicalWidth(ShouldComputePreferred sh
// If 'height' and 'width' both have computed values of 'auto' and the element has an intrinsic ratio but no intrinsic height or width, then the used value of
// 'width' is undefined in CSS 2.1. However, it is suggested that, if the containing block's width does not itself depend on the replaced element's width, then
// the used value of 'width' is calculated from the constraint equation used for block-level, non-replaced elements in normal flow.
- if (heightIsAuto && !hasIntrinsicWidth && !hasIntrinsicHeight) {
+ if (computedHeightIsAuto && !hasIntrinsicWidth && !hasIntrinsicHeight) {
// The aforementioned 'constraint equation' used for block-level, non-replaced elements in normal flow:
// 'margin-left' + 'border-left-width' + 'padding-left' + 'width' + 'padding-right' + 'border-right-width' + 'margin-right' = width of containing block
LayoutUnit logicalWidth;
@@ -434,8 +422,6 @@ LayoutUnit RenderReplaced::computeReplacedLogicalWidth(ShouldComputePreferred sh
LayoutUnit marginStart = minimumValueForLength(style()->marginStart(), logicalWidth);
LayoutUnit marginEnd = minimumValueForLength(style()->marginEnd(), logicalWidth);
logicalWidth = max<LayoutUnit>(0, logicalWidth - (marginStart + marginEnd + (width() - clientWidth())));
- if (isPercentageIntrinsicSize)
- logicalWidth = logicalWidth * constrainedSize.width() / 100;
return computeReplacedLogicalWidthRespectingMinMaxWidth(logicalWidth, shouldComputePreferred);
}
}
@@ -463,13 +449,12 @@ LayoutUnit RenderReplaced::computeReplacedLogicalHeight() const
RenderBox* contentRenderer = embeddedContentBox();
// 10.6.2 Inline, replaced elements: http://www.w3.org/TR/CSS21/visudet.html#inline-replaced-height
- bool isPercentageIntrinsicSize = false;
double intrinsicRatio = 0;
FloatSize constrainedSize;
- computeAspectRatioInformationForRenderBox(contentRenderer, constrainedSize, intrinsicRatio, isPercentageIntrinsicSize);
+ computeAspectRatioInformationForRenderBox(contentRenderer, constrainedSize, intrinsicRatio);
bool widthIsAuto = style()->logicalWidth().isAuto();
- bool hasIntrinsicHeight = !isPercentageIntrinsicSize && constrainedSize.height() > 0;
+ bool hasIntrinsicHeight = constrainedSize.height() > 0;
// If 'height' and 'width' both have computed values of 'auto' and the element also has an intrinsic height, then that intrinsic height is the used value of 'height'.
if (widthIsAuto && hasIntrinsicHeight)
@@ -506,7 +491,7 @@ void RenderReplaced::computePreferredLogicalWidths()
m_minPreferredLogicalWidth = m_maxPreferredLogicalWidth = computeReplacedLogicalWidth(ComputePreferred);
RenderStyle* styleToUse = style();
- if (styleToUse->logicalWidth().isPercent() || styleToUse->logicalMaxWidth().isPercent() || hasRelativeIntrinsicLogicalWidth())
+ if (styleToUse->logicalWidth().isPercent() || styleToUse->logicalMaxWidth().isPercent())
m_minPreferredLogicalWidth = 0;
if (styleToUse->logicalMinWidth().isFixed() && styleToUse->logicalMinWidth().value() > 0) {

Powered by Google App Engine
This is Rietveld 408576698