| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
| 3 * Copyright (C) 2000 Dirk Mueller (mueller@kde.org) | 3 * Copyright (C) 2000 Dirk Mueller (mueller@kde.org) |
| 4 * Copyright (C) 2004, 2006, 2007 Apple Inc. All rights reserved. | 4 * Copyright (C) 2004, 2006, 2007 Apple Inc. All rights reserved. |
| 5 * Copyright (C) Research In Motion Limited 2011-2012. All rights reserved. | 5 * Copyright (C) Research In Motion Limited 2011-2012. All rights reserved. |
| 6 * | 6 * |
| 7 * This library is free software; you can redistribute it and/or | 7 * This library is free software; you can redistribute it and/or |
| 8 * modify it under the terms of the GNU Library General Public | 8 * modify it under the terms of the GNU Library General Public |
| 9 * License as published by the Free Software Foundation; either | 9 * License as published by the Free Software Foundation; either |
| 10 * version 2 of the License, or (at your option) any later version. | 10 * version 2 of the License, or (at your option) any later version. |
| (...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 544 static inline LayoutUnit resolveWidthForRatio(LayoutUnit height, const FloatSize
& aspectRatio) | 544 static inline LayoutUnit resolveWidthForRatio(LayoutUnit height, const FloatSize
& aspectRatio) |
| 545 { | 545 { |
| 546 return LayoutUnit(height * aspectRatio.width() / aspectRatio.height()); | 546 return LayoutUnit(height * aspectRatio.width() / aspectRatio.height()); |
| 547 } | 547 } |
| 548 | 548 |
| 549 static inline LayoutUnit resolveHeightForRatio(LayoutUnit width, const FloatSize
& aspectRatio) | 549 static inline LayoutUnit resolveHeightForRatio(LayoutUnit width, const FloatSize
& aspectRatio) |
| 550 { | 550 { |
| 551 return LayoutUnit(width * aspectRatio.height() / aspectRatio.width()); | 551 return LayoutUnit(width * aspectRatio.height() / aspectRatio.width()); |
| 552 } | 552 } |
| 553 | 553 |
| 554 LayoutUnit LayoutReplaced::computeConstrainedLogicalWidth(ShouldComputePreferred
shouldComputePreferred) const |
| 555 { |
| 556 if (shouldComputePreferred == ComputePreferred) |
| 557 return computeReplacedLogicalWidthRespectingMinMaxWidth(LayoutUnit(), Co
mputePreferred); |
| 558 // The aforementioned 'constraint equation' used for block-level, non-replac
ed elements in normal flow: |
| 559 // 'margin-left' + 'border-left-width' + 'padding-left' + 'width' + 'padding
-right' + 'border-right-width' + 'margin-right' = width of containing block |
| 560 LayoutUnit logicalWidth = containingBlock()->availableLogicalWidth(); |
| 561 |
| 562 // This solves above equation for 'width' (== logicalWidth). |
| 563 LayoutUnit marginStart = minimumValueForLength(style()->marginStart(), logic
alWidth); |
| 564 LayoutUnit marginEnd = minimumValueForLength(style()->marginEnd(), logicalWi
dth); |
| 565 logicalWidth = (logicalWidth - (marginStart + marginEnd + (size().width() -
clientWidth()))).clampNegativeToZero(); |
| 566 return computeReplacedLogicalWidthRespectingMinMaxWidth(logicalWidth, should
ComputePreferred); |
| 567 } |
| 568 |
| 554 LayoutUnit LayoutReplaced::computeReplacedLogicalWidth(ShouldComputePreferred sh
ouldComputePreferred) const | 569 LayoutUnit LayoutReplaced::computeReplacedLogicalWidth(ShouldComputePreferred sh
ouldComputePreferred) const |
| 555 { | 570 { |
| 556 if (style()->logicalWidth().isSpecified() || style()->logicalWidth().isIntri
nsic()) | 571 if (style()->logicalWidth().isSpecified() || style()->logicalWidth().isIntri
nsic()) |
| 557 return computeReplacedLogicalWidthRespectingMinMaxWidth(computeReplacedL
ogicalWidthUsing(MainOrPreferredSize, style()->logicalWidth()), shouldComputePre
ferred); | 572 return computeReplacedLogicalWidthRespectingMinMaxWidth(computeReplacedL
ogicalWidthUsing(MainOrPreferredSize, style()->logicalWidth()), shouldComputePre
ferred); |
| 558 | 573 |
| 559 LayoutReplaced* contentLayoutObject = embeddedReplacedContent(); | 574 LayoutReplaced* contentLayoutObject = embeddedReplacedContent(); |
| 560 | 575 |
| 561 // 10.3.2 Inline, replaced elements: http://www.w3.org/TR/CSS21/visudet.html
#inline-replaced-width | 576 // 10.3.2 Inline, replaced elements: http://www.w3.org/TR/CSS21/visudet.html
#inline-replaced-width |
| 562 IntrinsicSizingInfo intrinsicSizingInfo; | 577 IntrinsicSizingInfo intrinsicSizingInfo; |
| 563 computeIntrinsicSizingInfoForReplacedContent(contentLayoutObject, intrinsicS
izingInfo); | 578 computeIntrinsicSizingInfoForReplacedContent(contentLayoutObject, intrinsicS
izingInfo); |
| 564 FloatSize constrainedSize = constrainIntrinsicSizeToMinMax(intrinsicSizingIn
fo); | 579 FloatSize constrainedSize = constrainIntrinsicSizeToMinMax(intrinsicSizingIn
fo); |
| 565 | 580 |
| 566 if (style()->logicalWidth().isAuto()) { | 581 if (style()->logicalWidth().isAuto()) { |
| 567 bool computedHeightIsAuto = hasAutoHeightOrContainingBlockWithAutoHeight
(); | 582 bool computedHeightIsAuto = style()->logicalHeight().isAuto(); |
| 568 | 583 |
| 569 // If 'height' and 'width' both have computed values of 'auto' and the e
lement also has an intrinsic width, then that intrinsic width is the used value
of 'width'. | 584 // If 'height' and 'width' both have computed values of 'auto' and the e
lement also has an intrinsic width, then that intrinsic width is the used value
of 'width'. |
| 570 if (computedHeightIsAuto && intrinsicSizingInfo.hasWidth) | 585 if (computedHeightIsAuto && intrinsicSizingInfo.hasWidth) |
| 571 return computeReplacedLogicalWidthRespectingMinMaxWidth(LayoutUnit(c
onstrainedSize.width()), shouldComputePreferred); | 586 return computeReplacedLogicalWidthRespectingMinMaxWidth(LayoutUnit(c
onstrainedSize.width()), shouldComputePreferred); |
| 572 | 587 |
| 573 if (!intrinsicSizingInfo.aspectRatio.isEmpty()) { | 588 if (!intrinsicSizingInfo.aspectRatio.isEmpty()) { |
| 574 // If 'height' and 'width' both have computed values of 'auto' and t
he element has no intrinsic width, but does have an intrinsic height and intrins
ic ratio; | 589 // If 'height' and 'width' both have computed values of 'auto' and t
he element has no intrinsic width, but does have an intrinsic height and intrins
ic ratio; |
| 575 // or if 'width' has a computed value of 'auto', 'height' has some o
ther computed value, and the element does have an intrinsic ratio; then the used
value | 590 // or if 'width' has a computed value of 'auto', 'height' has some o
ther computed value, and the element does have an intrinsic ratio; then the used
value |
| 576 // of 'width' is: (used height) * (intrinsic ratio) | 591 // of 'width' is: (used height) * (intrinsic ratio) |
| 577 if ((computedHeightIsAuto && !intrinsicSizingInfo.hasWidth && intrin
sicSizingInfo.hasHeight) || !computedHeightIsAuto) { | 592 if ((computedHeightIsAuto && !intrinsicSizingInfo.hasWidth && intrin
sicSizingInfo.hasHeight) || !computedHeightIsAuto) { |
| 578 LayoutUnit logicalHeight = computeReplacedLogicalHeight(); | 593 LayoutUnit estimatedUsedWidth = intrinsicSizingInfo.hasWidth ? L
ayoutUnit(constrainedSize.width()) : computeConstrainedLogicalWidth(shouldComput
ePreferred); |
| 594 LayoutUnit logicalHeight = computeReplacedLogicalHeight(estimate
dUsedWidth); |
| 579 return computeReplacedLogicalWidthRespectingMinMaxWidth(resolveW
idthForRatio(logicalHeight, intrinsicSizingInfo.aspectRatio), shouldComputePrefe
rred); | 595 return computeReplacedLogicalWidthRespectingMinMaxWidth(resolveW
idthForRatio(logicalHeight, intrinsicSizingInfo.aspectRatio), shouldComputePrefe
rred); |
| 580 } | 596 } |
| 581 | 597 |
| 582 // If 'height' and 'width' both have computed values of 'auto' and t
he element has an intrinsic ratio but no intrinsic height or width, then the use
d value of | 598 // If 'height' and 'width' both have computed values of 'auto' and t
he element has an intrinsic ratio but no intrinsic height or width, then the use
d value of |
| 583 // 'width' is undefined in CSS 2.1. However, it is suggested that, i
f the containing block's width does not itself depend on the replaced element's
width, then | 599 // 'width' is undefined in CSS 2.1. However, it is suggested that, i
f the containing block's width does not itself depend on the replaced element's
width, then |
| 584 // the used value of 'width' is calculated from the constraint equat
ion used for block-level, non-replaced elements in normal flow. | 600 // the used value of 'width' is calculated from the constraint equat
ion used for block-level, non-replaced elements in normal flow. |
| 585 if (computedHeightIsAuto && !intrinsicSizingInfo.hasWidth && !intrin
sicSizingInfo.hasHeight) { | 601 if (computedHeightIsAuto && !intrinsicSizingInfo.hasWidth && !intrin
sicSizingInfo.hasHeight) |
| 586 if (shouldComputePreferred == ComputePreferred) | 602 return computeConstrainedLogicalWidth(shouldComputePreferred); |
| 587 return computeReplacedLogicalWidthRespectingMinMaxWidth(Layo
utUnit(), ComputePreferred); | |
| 588 // The aforementioned 'constraint equation' used for block-level
, non-replaced elements in normal flow: | |
| 589 // 'margin-left' + 'border-left-width' + 'padding-left' + 'width
' + 'padding-right' + 'border-right-width' + 'margin-right' = width of containin
g block | |
| 590 LayoutUnit logicalWidth = containingBlock()->availableLogicalWid
th(); | |
| 591 | |
| 592 // This solves above equation for 'width' (== logicalWidth). | |
| 593 LayoutUnit marginStart = minimumValueForLength(style()->marginSt
art(), logicalWidth); | |
| 594 LayoutUnit marginEnd = minimumValueForLength(style()->marginEnd(
), logicalWidth); | |
| 595 logicalWidth = (logicalWidth - (marginStart + marginEnd + (size(
).width() - clientWidth()))).clampNegativeToZero(); | |
| 596 return computeReplacedLogicalWidthRespectingMinMaxWidth(logicalW
idth, shouldComputePreferred); | |
| 597 } | |
| 598 } | 603 } |
| 599 | 604 |
| 600 // 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'. | 605 // 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'. |
| 601 if (intrinsicSizingInfo.hasWidth) | 606 if (intrinsicSizingInfo.hasWidth) |
| 602 return computeReplacedLogicalWidthRespectingMinMaxWidth(LayoutUnit(c
onstrainedSize.width()), shouldComputePreferred); | 607 return computeReplacedLogicalWidthRespectingMinMaxWidth(LayoutUnit(c
onstrainedSize.width()), shouldComputePreferred); |
| 603 | 608 |
| 604 // 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 300p
x is too | 609 // 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 300p
x is too |
| 605 // wide to fit the device, UAs should use the width of the largest recta
ngle that has a 2:1 ratio and fits the device instead. | 610 // wide to fit the device, UAs should use the width of the largest recta
ngle that has a 2:1 ratio and fits the device instead. |
| 606 // Note: We fall through and instead return intrinsicLogicalWidth() here
- to preserve existing WebKit behavior, which might or might not be correct, or
desired. | 611 // Note: We fall through and instead return intrinsicLogicalWidth() here
- to preserve existing WebKit behavior, which might or might not be correct, or
desired. |
| 607 // Changing this to return cDefaultWidth, will affect lots of test resul
ts. Eg. some tests assume that a blank <img> tag (which implies width/height=aut
o) | 612 // Changing this to return cDefaultWidth, will affect lots of test resul
ts. Eg. some tests assume that a blank <img> tag (which implies width/height=aut
o) |
| 608 // has no intrinsic size, which is wrong per CSS 2.1, but matches our be
havior since a long time. | 613 // has no intrinsic size, which is wrong per CSS 2.1, but matches our be
havior since a long time. |
| 609 } | 614 } |
| 610 | 615 |
| 611 return computeReplacedLogicalWidthRespectingMinMaxWidth(intrinsicLogicalWidt
h(), shouldComputePreferred); | 616 return computeReplacedLogicalWidthRespectingMinMaxWidth(intrinsicLogicalWidt
h(), shouldComputePreferred); |
| 612 } | 617 } |
| 613 | 618 |
| 614 LayoutUnit LayoutReplaced::computeReplacedLogicalHeight() const | 619 LayoutUnit LayoutReplaced::computeReplacedLogicalHeight(LayoutUnit estimatedUsed
Width) const |
| 615 { | 620 { |
| 616 // 10.5 Content height: the 'height' property: http://www.w3.org/TR/CSS21/vi
sudet.html#propdef-height | 621 // 10.5 Content height: the 'height' property: http://www.w3.org/TR/CSS21/vi
sudet.html#propdef-height |
| 617 if (hasReplacedLogicalHeight()) | 622 if (hasReplacedLogicalHeight()) |
| 618 return computeReplacedLogicalHeightRespectingMinMaxHeight(computeReplace
dLogicalHeightUsing(MainOrPreferredSize, style()->logicalHeight())); | 623 return computeReplacedLogicalHeightRespectingMinMaxHeight(computeReplace
dLogicalHeightUsing(MainOrPreferredSize, style()->logicalHeight())); |
| 619 | 624 |
| 620 LayoutReplaced* contentLayoutObject = embeddedReplacedContent(); | 625 LayoutReplaced* contentLayoutObject = embeddedReplacedContent(); |
| 621 | 626 |
| 622 // 10.6.2 Inline, replaced elements: http://www.w3.org/TR/CSS21/visudet.html
#inline-replaced-height | 627 // 10.6.2 Inline, replaced elements: http://www.w3.org/TR/CSS21/visudet.html
#inline-replaced-height |
| 623 IntrinsicSizingInfo intrinsicSizingInfo; | 628 IntrinsicSizingInfo intrinsicSizingInfo; |
| 624 computeIntrinsicSizingInfoForReplacedContent(contentLayoutObject, intrinsicS
izingInfo); | 629 computeIntrinsicSizingInfoForReplacedContent(contentLayoutObject, intrinsicS
izingInfo); |
| 625 FloatSize constrainedSize = constrainIntrinsicSizeToMinMax(intrinsicSizingIn
fo); | 630 FloatSize constrainedSize = constrainIntrinsicSizeToMinMax(intrinsicSizingIn
fo); |
| 626 | 631 |
| 627 bool widthIsAuto = style()->logicalWidth().isAuto(); | 632 bool widthIsAuto = style()->logicalWidth().isAuto(); |
| 628 | 633 |
| 629 // If 'height' and 'width' both have computed values of 'auto' and the eleme
nt also has an intrinsic height, then that intrinsic height is the used value of
'height'. | 634 // If 'height' and 'width' both have computed values of 'auto' and the eleme
nt also has an intrinsic height, then that intrinsic height is the used value of
'height'. |
| 630 if (widthIsAuto && intrinsicSizingInfo.hasHeight) | 635 if (widthIsAuto && intrinsicSizingInfo.hasHeight) |
| 631 return computeReplacedLogicalHeightRespectingMinMaxHeight(LayoutUnit(con
strainedSize.height())); | 636 return computeReplacedLogicalHeightRespectingMinMaxHeight(LayoutUnit(con
strainedSize.height())); |
| 632 | 637 |
| 633 // Otherwise, if 'height' has a computed value of 'auto', and the element ha
s an intrinsic ratio then the used value of 'height' is: | 638 // Otherwise, if 'height' has a computed value of 'auto', and the element ha
s an intrinsic ratio then the used value of 'height' is: |
| 634 // (used width) / (intrinsic ratio) | 639 // (used width) / (intrinsic ratio) |
| 635 if (!intrinsicSizingInfo.aspectRatio.isEmpty()) | 640 if (!intrinsicSizingInfo.aspectRatio.isEmpty()) { |
| 636 return computeReplacedLogicalHeightRespectingMinMaxHeight(resolveHeightF
orRatio(availableLogicalWidth(), intrinsicSizingInfo.aspectRatio)); | 641 LayoutUnit usedWidth = estimatedUsedWidth ? estimatedUsedWidth : availab
leLogicalWidth(); |
| 642 return computeReplacedLogicalHeightRespectingMinMaxHeight(resolveHeightF
orRatio(usedWidth, intrinsicSizingInfo.aspectRatio)); |
| 643 } |
| 637 | 644 |
| 638 // Otherwise, if 'height' has a computed value of 'auto', and the element ha
s an intrinsic height, then that intrinsic height is the used value of 'height'. | 645 // Otherwise, if 'height' has a computed value of 'auto', and the element ha
s an intrinsic height, then that intrinsic height is the used value of 'height'. |
| 639 if (intrinsicSizingInfo.hasHeight) | 646 if (intrinsicSizingInfo.hasHeight) |
| 640 return computeReplacedLogicalHeightRespectingMinMaxHeight(LayoutUnit(con
strainedSize.height())); | 647 return computeReplacedLogicalHeightRespectingMinMaxHeight(LayoutUnit(con
strainedSize.height())); |
| 641 | 648 |
| 642 // Otherwise, if 'height' has a computed value of 'auto', but none of the co
nditions above are met, then the used value of 'height' must be set to the heigh
t | 649 // Otherwise, if 'height' has a computed value of 'auto', but none of the co
nditions above are met, then the used value of 'height' must be set to the heigh
t |
| 643 // of the largest rectangle that has a 2:1 ratio, has a height not greater t
han 150px, and has a width not greater than the device width. | 650 // of the largest rectangle that has a 2:1 ratio, has a height not greater t
han 150px, and has a width not greater than the device width. |
| 644 return computeReplacedLogicalHeightRespectingMinMaxHeight(intrinsicLogicalHe
ight()); | 651 return computeReplacedLogicalHeightRespectingMinMaxHeight(intrinsicLogicalHe
ight()); |
| 645 } | 652 } |
| 646 | 653 |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 747 } | 754 } |
| 748 | 755 |
| 749 void LayoutReplaced::IntrinsicSizingInfo::transpose() | 756 void LayoutReplaced::IntrinsicSizingInfo::transpose() |
| 750 { | 757 { |
| 751 size = size.transposedSize(); | 758 size = size.transposedSize(); |
| 752 aspectRatio = aspectRatio.transposedSize(); | 759 aspectRatio = aspectRatio.transposedSize(); |
| 753 std::swap(hasWidth, hasHeight); | 760 std::swap(hasWidth, hasHeight); |
| 754 } | 761 } |
| 755 | 762 |
| 756 } // namespace blink | 763 } // namespace blink |
| OLD | NEW |