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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 contentLayoutObject->computeIntrinsicSizingInfo(intrinsicSizingInfo); | 152 contentLayoutObject->computeIntrinsicSizingInfo(intrinsicSizingInfo); |
153 | 153 |
154 // Handle zoom & vertical writing modes here, as the embedded document d
oesn't know about them. | 154 // Handle zoom & vertical writing modes here, as the embedded document d
oesn't know about them. |
155 intrinsicSizingInfo.size.scale(style()->effectiveZoom()); | 155 intrinsicSizingInfo.size.scale(style()->effectiveZoom()); |
156 if (isLayoutImage()) | 156 if (isLayoutImage()) |
157 intrinsicSizingInfo.size.scale(toLayoutImage(this)->imageDevicePixel
Ratio()); | 157 intrinsicSizingInfo.size.scale(toLayoutImage(this)->imageDevicePixel
Ratio()); |
158 | 158 |
159 // Update our intrinsic size to match what the content layoutObject has
computed, so that when we | 159 // Update our intrinsic size to match what the content layoutObject has
computed, so that when we |
160 // constrain the size below, the correct intrinsic size will be obtained
for comparison against | 160 // constrain the size below, the correct intrinsic size will be obtained
for comparison against |
161 // min and max widths. | 161 // min and max widths. |
162 if (intrinsicSizingInfo.aspectRatio && !intrinsicSizingInfo.size.isEmpty
()) | 162 if (!intrinsicSizingInfo.aspectRatio.isEmpty() && !intrinsicSizingInfo.s
ize.isEmpty()) |
163 m_intrinsicSize = LayoutSize(intrinsicSizingInfo.size); | 163 m_intrinsicSize = LayoutSize(intrinsicSizingInfo.size); |
164 | 164 |
165 if (!isHorizontalWritingMode()) | 165 if (!isHorizontalWritingMode()) |
166 intrinsicSizingInfo.transpose(); | 166 intrinsicSizingInfo.transpose(); |
167 } else { | 167 } else { |
168 computeIntrinsicSizingInfo(intrinsicSizingInfo); | 168 computeIntrinsicSizingInfo(intrinsicSizingInfo); |
169 if (intrinsicSizingInfo.aspectRatio && !intrinsicSizingInfo.size.isEmpty
()) | 169 if (!intrinsicSizingInfo.aspectRatio.isEmpty() && !intrinsicSizingInfo.s
ize.isEmpty()) |
170 m_intrinsicSize = LayoutSize(isHorizontalWritingMode() ? intrinsicSi
zingInfo.size : intrinsicSizingInfo.size.transposedSize()); | 170 m_intrinsicSize = LayoutSize(isHorizontalWritingMode() ? intrinsicSi
zingInfo.size : intrinsicSizingInfo.size.transposedSize()); |
171 } | 171 } |
172 } | 172 } |
173 | 173 |
174 FloatSize LayoutReplaced::constrainIntrinsicSizeToMinMax(const IntrinsicSizingIn
fo& intrinsicSizingInfo) const | 174 FloatSize LayoutReplaced::constrainIntrinsicSizeToMinMax(const IntrinsicSizingIn
fo& intrinsicSizingInfo) const |
175 { | 175 { |
176 // Constrain the intrinsic size along each axis according to minimum and max
imum width/heights along the opposite | 176 // Constrain the intrinsic size along each axis according to minimum and max
imum width/heights along the opposite |
177 // axis. So for example a maximum width that shrinks our width will result i
n the height we compute here having | 177 // axis. So for example a maximum width that shrinks our width will result i
n the height we compute here having |
178 // to shrink in order to preserve the aspect ratio. Because we compute these
values independently along each | 178 // to shrink in order to preserve the aspect ratio. Because we compute these
values independently along each |
179 // axis, the final returned size may in fact not preserve the aspect ratio. | 179 // axis, the final returned size may in fact not preserve the aspect ratio. |
| 180 // TODO(davve): Investigate using only the intrinsic aspect ratio here. |
180 FloatSize constrainedSize = intrinsicSizingInfo.size; | 181 FloatSize constrainedSize = intrinsicSizingInfo.size; |
181 if (intrinsicSizingInfo.aspectRatio && !intrinsicSizingInfo.size.isEmpty() &
& style()->logicalWidth().isAuto() && style()->logicalHeight().isAuto()) { | 182 if (!intrinsicSizingInfo.aspectRatio.isEmpty() && !intrinsicSizingInfo.size.
isEmpty() && style()->logicalWidth().isAuto() && style()->logicalHeight().isAuto
()) { |
182 // We can't multiply or divide by 'intrinsicSizingInfo.aspectRatio' here
, it breaks tests, like fast/images/zoomed-img-size.html, which | 183 // We can't multiply or divide by 'intrinsicSizingInfo.aspectRatio' here
, it breaks tests, like fast/images/zoomed-img-size.html, which |
183 // can only be fixed once subpixel precision is available for things lik
e intrinsicWidth/Height - which include zoom! | 184 // can only be fixed once subpixel precision is available for things lik
e intrinsicWidth/Height - which include zoom! |
184 constrainedSize.setWidth(LayoutBox::computeReplacedLogicalHeight() * int
rinsicSizingInfo.size.width() / intrinsicSizingInfo.size.height()); | 185 constrainedSize.setWidth(LayoutBox::computeReplacedLogicalHeight() * int
rinsicSizingInfo.size.width() / intrinsicSizingInfo.size.height()); |
185 constrainedSize.setHeight(LayoutBox::computeReplacedLogicalWidth() * int
rinsicSizingInfo.size.height() / intrinsicSizingInfo.size.width()); | 186 constrainedSize.setHeight(LayoutBox::computeReplacedLogicalWidth() * int
rinsicSizingInfo.size.height() / intrinsicSizingInfo.size.width()); |
186 } | 187 } |
187 return constrainedSize; | 188 return constrainedSize; |
188 } | 189 } |
189 | 190 |
190 void LayoutReplaced::computePositionedLogicalWidth(LogicalExtentComputedValues&
computedValues) const | 191 void LayoutReplaced::computePositionedLogicalWidth(LogicalExtentComputedValues&
computedValues) const |
191 { | 192 { |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
530 void LayoutReplaced::computeIntrinsicSizingInfo(IntrinsicSizingInfo& intrinsicSi
zingInfo) const | 531 void LayoutReplaced::computeIntrinsicSizingInfo(IntrinsicSizingInfo& intrinsicSi
zingInfo) const |
531 { | 532 { |
532 // If there's an embeddedContentBox() of a remote, referenced document avail
able, this code-path should never be used. | 533 // If there's an embeddedContentBox() of a remote, referenced document avail
able, this code-path should never be used. |
533 ASSERT(!embeddedContentBox()); | 534 ASSERT(!embeddedContentBox()); |
534 intrinsicSizingInfo.size = FloatSize(intrinsicLogicalWidth().toFloat(), intr
insicLogicalHeight().toFloat()); | 535 intrinsicSizingInfo.size = FloatSize(intrinsicLogicalWidth().toFloat(), intr
insicLogicalHeight().toFloat()); |
535 | 536 |
536 // Figure out if we need to compute an intrinsic ratio. | 537 // Figure out if we need to compute an intrinsic ratio. |
537 if (intrinsicSizingInfo.size.isEmpty() || !layoutObjectHasAspectRatio(this)) | 538 if (intrinsicSizingInfo.size.isEmpty() || !layoutObjectHasAspectRatio(this)) |
538 return; | 539 return; |
539 | 540 |
540 intrinsicSizingInfo.aspectRatio = intrinsicSizingInfo.size.width() / intrins
icSizingInfo.size.height(); | 541 intrinsicSizingInfo.aspectRatio = intrinsicSizingInfo.size; |
| 542 } |
| 543 |
| 544 static inline LayoutUnit resolveWidthForRatio(LayoutUnit height, const FloatSize
& aspectRatio) |
| 545 { |
| 546 return LayoutUnit(height * aspectRatio.width() / aspectRatio.height()); |
| 547 } |
| 548 |
| 549 static inline LayoutUnit resolveHeightForRatio(LayoutUnit width, const FloatSize
& aspectRatio) |
| 550 { |
| 551 return LayoutUnit(width * aspectRatio.height() / aspectRatio.width()); |
541 } | 552 } |
542 | 553 |
543 LayoutUnit LayoutReplaced::computeReplacedLogicalWidth(ShouldComputePreferred sh
ouldComputePreferred) const | 554 LayoutUnit LayoutReplaced::computeReplacedLogicalWidth(ShouldComputePreferred sh
ouldComputePreferred) const |
544 { | 555 { |
545 if (style()->logicalWidth().isSpecified() || style()->logicalWidth().isIntri
nsic()) | 556 if (style()->logicalWidth().isSpecified() || style()->logicalWidth().isIntri
nsic()) |
546 return computeReplacedLogicalWidthRespectingMinMaxWidth(computeReplacedL
ogicalWidthUsing(MainOrPreferredSize, style()->logicalWidth()), shouldComputePre
ferred); | 557 return computeReplacedLogicalWidthRespectingMinMaxWidth(computeReplacedL
ogicalWidthUsing(MainOrPreferredSize, style()->logicalWidth()), shouldComputePre
ferred); |
547 | 558 |
548 LayoutBox* contentLayoutObject = embeddedContentBox(); | 559 LayoutBox* contentLayoutObject = embeddedContentBox(); |
549 | 560 |
550 // 10.3.2 Inline, replaced elements: http://www.w3.org/TR/CSS21/visudet.html
#inline-replaced-width | 561 // 10.3.2 Inline, replaced elements: http://www.w3.org/TR/CSS21/visudet.html
#inline-replaced-width |
551 IntrinsicSizingInfo intrinsicSizingInfo; | 562 IntrinsicSizingInfo intrinsicSizingInfo; |
552 computeIntrinsicSizingInfoForLayoutBox(contentLayoutObject, intrinsicSizingI
nfo); | 563 computeIntrinsicSizingInfoForLayoutBox(contentLayoutObject, intrinsicSizingI
nfo); |
553 FloatSize constrainedSize = constrainIntrinsicSizeToMinMax(intrinsicSizingIn
fo); | 564 FloatSize constrainedSize = constrainIntrinsicSizeToMinMax(intrinsicSizingIn
fo); |
554 | 565 |
555 if (style()->logicalWidth().isAuto()) { | 566 if (style()->logicalWidth().isAuto()) { |
556 bool computedHeightIsAuto = hasAutoHeightOrContainingBlockWithAutoHeight
(); | 567 bool computedHeightIsAuto = hasAutoHeightOrContainingBlockWithAutoHeight
(); |
557 | 568 |
558 // 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'. | 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'. |
559 if (computedHeightIsAuto && intrinsicSizingInfo.hasWidth) | 570 if (computedHeightIsAuto && intrinsicSizingInfo.hasWidth) |
560 return computeReplacedLogicalWidthRespectingMinMaxWidth(LayoutUnit(c
onstrainedSize.width()), shouldComputePreferred); | 571 return computeReplacedLogicalWidthRespectingMinMaxWidth(LayoutUnit(c
onstrainedSize.width()), shouldComputePreferred); |
561 | 572 |
562 if (intrinsicSizingInfo.aspectRatio) { | 573 if (!intrinsicSizingInfo.aspectRatio.isEmpty()) { |
563 // 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; | 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; |
564 // 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 | 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 |
565 // of 'width' is: (used height) * (intrinsic ratio) | 576 // of 'width' is: (used height) * (intrinsic ratio) |
566 if ((computedHeightIsAuto && !intrinsicSizingInfo.hasWidth && intrin
sicSizingInfo.hasHeight) || !computedHeightIsAuto) { | 577 if ((computedHeightIsAuto && !intrinsicSizingInfo.hasWidth && intrin
sicSizingInfo.hasHeight) || !computedHeightIsAuto) { |
567 LayoutUnit logicalHeight = computeReplacedLogicalHeight(); | 578 LayoutUnit logicalHeight = computeReplacedLogicalHeight(); |
568 return computeReplacedLogicalWidthRespectingMinMaxWidth(LayoutUn
it(logicalHeight * intrinsicSizingInfo.aspectRatio), shouldComputePreferred); | 579 return computeReplacedLogicalWidthRespectingMinMaxWidth(resolveW
idthForRatio(logicalHeight, intrinsicSizingInfo.aspectRatio), shouldComputePrefe
rred); |
569 } | 580 } |
570 | 581 |
571 // 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 | 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 |
572 // '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 | 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 |
573 // the used value of 'width' is calculated from the constraint equat
ion used for block-level, non-replaced elements in normal flow. | 584 // the used value of 'width' is calculated from the constraint equat
ion used for block-level, non-replaced elements in normal flow. |
574 if (computedHeightIsAuto && !intrinsicSizingInfo.hasWidth && !intrin
sicSizingInfo.hasHeight) { | 585 if (computedHeightIsAuto && !intrinsicSizingInfo.hasWidth && !intrin
sicSizingInfo.hasHeight) { |
575 if (shouldComputePreferred == ComputePreferred) | 586 if (shouldComputePreferred == ComputePreferred) |
576 return computeReplacedLogicalWidthRespectingMinMaxWidth(Layo
utUnit(), ComputePreferred); | 587 return computeReplacedLogicalWidthRespectingMinMaxWidth(Layo
utUnit(), ComputePreferred); |
577 // The aforementioned 'constraint equation' used for block-level
, non-replaced elements in normal flow: | 588 // The aforementioned 'constraint equation' used for block-level
, non-replaced elements in normal flow: |
578 // 'margin-left' + 'border-left-width' + 'padding-left' + 'width
' + 'padding-right' + 'border-right-width' + 'margin-right' = width of containin
g block | 589 // 'margin-left' + 'border-left-width' + 'padding-left' + 'width
' + 'padding-right' + 'border-right-width' + 'margin-right' = width of containin
g block |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
614 FloatSize constrainedSize = constrainIntrinsicSizeToMinMax(intrinsicSizingIn
fo); | 625 FloatSize constrainedSize = constrainIntrinsicSizeToMinMax(intrinsicSizingIn
fo); |
615 | 626 |
616 bool widthIsAuto = style()->logicalWidth().isAuto(); | 627 bool widthIsAuto = style()->logicalWidth().isAuto(); |
617 | 628 |
618 // 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'. | 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'. |
619 if (widthIsAuto && intrinsicSizingInfo.hasHeight) | 630 if (widthIsAuto && intrinsicSizingInfo.hasHeight) |
620 return computeReplacedLogicalHeightRespectingMinMaxHeight(constrainedSiz
e.height()); | 631 return computeReplacedLogicalHeightRespectingMinMaxHeight(constrainedSiz
e.height()); |
621 | 632 |
622 // Otherwise, if 'height' has a computed value of 'auto', and the element ha
s an intrinsic ratio then the used value of 'height' is: | 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: |
623 // (used width) / (intrinsic ratio) | 634 // (used width) / (intrinsic ratio) |
624 if (intrinsicSizingInfo.aspectRatio) | 635 if (!intrinsicSizingInfo.aspectRatio.isEmpty()) |
625 return computeReplacedLogicalHeightRespectingMinMaxHeight(LayoutUnit(ava
ilableLogicalWidth() / intrinsicSizingInfo.aspectRatio)); | 636 return computeReplacedLogicalHeightRespectingMinMaxHeight(resolveHeightF
orRatio(availableLogicalWidth(), intrinsicSizingInfo.aspectRatio)); |
626 | 637 |
627 // 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'. | 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'. |
628 if (intrinsicSizingInfo.hasHeight) | 639 if (intrinsicSizingInfo.hasHeight) |
629 return computeReplacedLogicalHeightRespectingMinMaxHeight(LayoutUnit(con
strainedSize.height())); | 640 return computeReplacedLogicalHeightRespectingMinMaxHeight(LayoutUnit(con
strainedSize.height())); |
630 | 641 |
631 // 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 | 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 |
632 // 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. | 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. |
633 return computeReplacedLogicalHeightRespectingMinMaxHeight(intrinsicLogicalHe
ight()); | 644 return computeReplacedLogicalHeightRespectingMinMaxHeight(intrinsicLogicalHe
ight()); |
634 } | 645 } |
635 | 646 |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
741 // We only include the space below the baseline in our layer's cached paint
invalidation rect if the | 752 // We only include the space below the baseline in our layer's cached paint
invalidation rect if the |
742 // image is selected. Since the selection state has changed update the rect. | 753 // image is selected. Since the selection state has changed update the rect. |
743 if (hasLayer()) | 754 if (hasLayer()) |
744 setPreviousPaintInvalidationRect(boundsRectForPaintInvalidation(containe
rForPaintInvalidation())); | 755 setPreviousPaintInvalidationRect(boundsRectForPaintInvalidation(containe
rForPaintInvalidation())); |
745 | 756 |
746 if (canUpdateSelectionOnRootLineBoxes()) | 757 if (canUpdateSelectionOnRootLineBoxes()) |
747 inlineBoxWrapper()->root().setHasSelectedChildren(state != SelectionNone
); | 758 inlineBoxWrapper()->root().setHasSelectedChildren(state != SelectionNone
); |
748 } | 759 } |
749 | 760 |
750 } // namespace blink | 761 } // namespace blink |
OLD | NEW |