Esempio n. 1
0
LayoutUnit LayoutReplaced::computeReplacedLogicalHeight(
    LayoutUnit estimatedUsedWidth) const {
    // 10.5 Content height: the 'height' property:
    // http://www.w3.org/TR/CSS21/visudet.html#propdef-height
    if (hasReplacedLogicalHeight())
        return computeReplacedLogicalHeightRespectingMinMaxHeight(
                   computeReplacedLogicalHeightUsing(MainOrPreferredSize,
                           style()->logicalHeight()));

    LayoutReplaced* contentLayoutObject = embeddedReplacedContent();

    // 10.6.2 Inline, replaced elements:
    // http://www.w3.org/TR/CSS21/visudet.html#inline-replaced-height
    IntrinsicSizingInfo intrinsicSizingInfo;
    computeIntrinsicSizingInfoForReplacedContent(contentLayoutObject,
            intrinsicSizingInfo);
    FloatSize constrainedSize =
        constrainIntrinsicSizeToMinMax(intrinsicSizingInfo);

    bool widthIsAuto = style()->logicalWidth().isAuto();

    // 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 && intrinsicSizingInfo.hasHeight)
        return computeReplacedLogicalHeightRespectingMinMaxHeight(
                   LayoutUnit(constrainedSize.height()));

    // Otherwise, if 'height' has a computed value of 'auto', and the element has
    // an intrinsic ratio then the used value of 'height' is:
    // (used width) / (intrinsic ratio)
    if (!intrinsicSizingInfo.aspectRatio.isEmpty()) {
        LayoutUnit usedWidth =
            estimatedUsedWidth ? estimatedUsedWidth : availableLogicalWidth();
        return computeReplacedLogicalHeightRespectingMinMaxHeight(
                   resolveHeightForRatio(usedWidth, intrinsicSizingInfo.aspectRatio));
    }

    // Otherwise, if 'height' has a computed value of 'auto', and the element has
    // an intrinsic height, then that intrinsic height is the used value of
    // 'height'.
    if (intrinsicSizingInfo.hasHeight)
        return computeReplacedLogicalHeightRespectingMinMaxHeight(
                   LayoutUnit(constrainedSize.height()));

    // Otherwise, if 'height' has a computed value of 'auto', but none of the
    // conditions above are met, then the used value of 'height' must be set to
    // the height of the largest rectangle that has a 2:1 ratio, has a height not
    // greater than 150px, and has a width not greater than the device width.
    return computeReplacedLogicalHeightRespectingMinMaxHeight(
               intrinsicLogicalHeight());
}
Esempio n. 2
0
void LayoutReplaced::computeIntrinsicSizingInfo(
    IntrinsicSizingInfo& intrinsicSizingInfo) const {
    // If there's an embeddedReplacedContent() of a remote, referenced document
    // available, this code-path should never be used.
    ASSERT(!embeddedReplacedContent());
    intrinsicSizingInfo.size = FloatSize(intrinsicLogicalWidth().toFloat(),
                                         intrinsicLogicalHeight().toFloat());

    // Figure out if we need to compute an intrinsic ratio.
    if (intrinsicSizingInfo.size.isEmpty() || !layoutObjectHasAspectRatio(this))
        return;

    intrinsicSizingInfo.aspectRatio = intrinsicSizingInfo.size;
}
bool LayoutPart::needsPreferredWidthsRecalculation() const
{
    if (LayoutReplaced::needsPreferredWidthsRecalculation())
        return true;
    return embeddedReplacedContent();
}
Esempio n. 4
0
LayoutUnit LayoutReplaced::computeReplacedLogicalWidth(
    ShouldComputePreferred shouldComputePreferred) const {
    if (style()->logicalWidth().isSpecified() ||
            style()->logicalWidth().isIntrinsic())
        return computeReplacedLogicalWidthRespectingMinMaxWidth(
                   computeReplacedLogicalWidthUsing(MainOrPreferredSize,
                           style()->logicalWidth()),
                   shouldComputePreferred);

    LayoutReplaced* contentLayoutObject = embeddedReplacedContent();

    // 10.3.2 Inline, replaced elements:
    // http://www.w3.org/TR/CSS21/visudet.html#inline-replaced-width
    IntrinsicSizingInfo intrinsicSizingInfo;
    computeIntrinsicSizingInfoForReplacedContent(contentLayoutObject,
            intrinsicSizingInfo);
    FloatSize constrainedSize =
        constrainIntrinsicSizeToMinMax(intrinsicSizingInfo);

    if (style()->logicalWidth().isAuto()) {
        bool computedHeightIsAuto = style()->logicalHeight().isAuto();

        // 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 (computedHeightIsAuto && intrinsicSizingInfo.hasWidth)
            return computeReplacedLogicalWidthRespectingMinMaxWidth(
                       LayoutUnit(constrainedSize.width()), shouldComputePreferred);

        if (!intrinsicSizingInfo.aspectRatio.isEmpty()) {
            // 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 ((computedHeightIsAuto && !intrinsicSizingInfo.hasWidth &&
                    intrinsicSizingInfo.hasHeight) ||
                    !computedHeightIsAuto) {
                LayoutUnit estimatedUsedWidth =
                    intrinsicSizingInfo.hasWidth
                    ? LayoutUnit(constrainedSize.width())
                    : computeConstrainedLogicalWidth(shouldComputePreferred);
                LayoutUnit logicalHeight =
                    computeReplacedLogicalHeight(estimatedUsedWidth);
                return computeReplacedLogicalWidthRespectingMinMaxWidth(
                           resolveWidthForRatio(logicalHeight,
                                                intrinsicSizingInfo.aspectRatio),
                           shouldComputePreferred);
            }

            // 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 (computedHeightIsAuto && !intrinsicSizingInfo.hasWidth &&
                    !intrinsicSizingInfo.hasHeight)
                return computeConstrainedLogicalWidth(shouldComputePreferred);
        }

        // Otherwise, if 'width' has a computed value of 'auto', and the element has
        // an intrinsic width, then that intrinsic width is the used value of
        // 'width'.
        if (intrinsicSizingInfo.hasWidth)
            return computeReplacedLogicalWidthRespectingMinMaxWidth(
                       LayoutUnit(constrainedSize.width()), shouldComputePreferred);

        // Otherwise, if 'width' has a computed value of 'auto', but none of the
        // conditions above are met, then the used value of 'width' becomes 300px.
        // If 300px is too wide to fit the device, UAs should use the width of the
        // largest rectangle that has a 2:1 ratio and fits the device instead.
        // Note: We fall through and instead return intrinsicLogicalWidth() here -
        // to preserve existing WebKit behavior, which might or might not be
        // correct, or desired.
        // Changing this to return cDefaultWidth, will affect lots of test results.
        // Eg. some tests assume that a blank <img> tag (which implies
        // width/height=auto) has no intrinsic size, which is wrong per CSS 2.1, but
        // matches our behavior since a long time.
    }

    return computeReplacedLogicalWidthRespectingMinMaxWidth(
               intrinsicLogicalWidth(), shouldComputePreferred);
}