| 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 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 LayoutUnit logicalRightValue; | 258 LayoutUnit logicalRightValue; |
| 259 | 259 |
| 260 if (marginLogicalLeft.isAuto() && marginLogicalRight.isAuto()) { | 260 if (marginLogicalLeft.isAuto() && marginLogicalRight.isAuto()) { |
| 261 // 'left' and 'right' cannot be 'auto' due to step 3 | 261 // 'left' and 'right' cannot be 'auto' due to step 3 |
| 262 ASSERT(!(logicalLeft.isAuto() && logicalRight.isAuto())); | 262 ASSERT(!(logicalLeft.isAuto() && logicalRight.isAuto())); |
| 263 | 263 |
| 264 logicalLeftValue = valueForLength(logicalLeft, containerLogicalWidth); | 264 logicalLeftValue = valueForLength(logicalLeft, containerLogicalWidth); |
| 265 logicalRightValue = valueForLength(logicalRight, containerLogicalWidth); | 265 logicalRightValue = valueForLength(logicalRight, containerLogicalWidth); |
| 266 | 266 |
| 267 LayoutUnit difference = availableSpace - (logicalLeftValue + logicalRigh
tValue); | 267 LayoutUnit difference = availableSpace - (logicalLeftValue + logicalRigh
tValue); |
| 268 if (difference > 0) { | 268 if (difference > LayoutUnit()) { |
| 269 marginLogicalLeftAlias = difference / 2; // split the difference | 269 marginLogicalLeftAlias = difference / 2; // split the difference |
| 270 marginLogicalRightAlias = difference - marginLogicalLeftAlias; // ac
count for odd valued differences | 270 marginLogicalRightAlias = difference - marginLogicalLeftAlias; // ac
count for odd valued differences |
| 271 } else { | 271 } else { |
| 272 // Use the containing block's direction rather than the parent block
's | 272 // Use the containing block's direction rather than the parent block
's |
| 273 // per CSS 2.1 reference test abspos-replaced-width-margin-000. | 273 // per CSS 2.1 reference test abspos-replaced-width-margin-000. |
| 274 if (containerDirection == LTR) { | 274 if (containerDirection == LTR) { |
| 275 marginLogicalLeftAlias = 0; | 275 marginLogicalLeftAlias = LayoutUnit(); |
| 276 marginLogicalRightAlias = difference; // will be negative | 276 marginLogicalRightAlias = difference; // will be negative |
| 277 } else { | 277 } else { |
| 278 marginLogicalLeftAlias = difference; // will be negative | 278 marginLogicalLeftAlias = difference; // will be negative |
| 279 marginLogicalRightAlias = 0; | 279 marginLogicalRightAlias = LayoutUnit(); |
| 280 } | 280 } |
| 281 } | 281 } |
| 282 | 282 |
| 283 /*-----------------------------------------------------------------------*\ | 283 /*-----------------------------------------------------------------------*\ |
| 284 * 5. If at this point there is an 'auto' left, solve the equation for | 284 * 5. If at this point there is an 'auto' left, solve the equation for |
| 285 * that value. | 285 * that value. |
| 286 \*-----------------------------------------------------------------------*/ | 286 \*-----------------------------------------------------------------------*/ |
| 287 } else if (logicalLeft.isAuto()) { | 287 } else if (logicalLeft.isAuto()) { |
| 288 marginLogicalLeftAlias = valueForLength(marginLogicalLeft, containerRela
tiveLogicalWidth); | 288 marginLogicalLeftAlias = valueForLength(marginLogicalLeft, containerRela
tiveLogicalWidth); |
| 289 marginLogicalRightAlias = valueForLength(marginLogicalRight, containerRe
lativeLogicalWidth); | 289 marginLogicalRightAlias = valueForLength(marginLogicalRight, containerRe
lativeLogicalWidth); |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 552 double intrinsicRatio = 0; | 552 double intrinsicRatio = 0; |
| 553 FloatSize constrainedSize; | 553 FloatSize constrainedSize; |
| 554 computeAspectRatioInformationForLayoutBox(contentLayoutObject, constrainedSi
ze, intrinsicRatio); | 554 computeAspectRatioInformationForLayoutBox(contentLayoutObject, constrainedSi
ze, intrinsicRatio); |
| 555 | 555 |
| 556 if (style()->logicalWidth().isAuto()) { | 556 if (style()->logicalWidth().isAuto()) { |
| 557 bool computedHeightIsAuto = hasAutoHeightOrContainingBlockWithAutoHeight
(); | 557 bool computedHeightIsAuto = hasAutoHeightOrContainingBlockWithAutoHeight
(); |
| 558 bool hasIntrinsicWidth = constrainedSize.width() > 0; | 558 bool hasIntrinsicWidth = constrainedSize.width() > 0; |
| 559 | 559 |
| 560 // 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'. | 560 // 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'. |
| 561 if (computedHeightIsAuto && hasIntrinsicWidth) | 561 if (computedHeightIsAuto && hasIntrinsicWidth) |
| 562 return computeReplacedLogicalWidthRespectingMinMaxWidth(constrainedS
ize.width(), shouldComputePreferred); | 562 return computeReplacedLogicalWidthRespectingMinMaxWidth(LayoutUnit(c
onstrainedSize.width()), shouldComputePreferred); |
| 563 | 563 |
| 564 bool hasIntrinsicHeight = constrainedSize.height() > 0; | 564 bool hasIntrinsicHeight = constrainedSize.height() > 0; |
| 565 if (intrinsicRatio) { | 565 if (intrinsicRatio) { |
| 566 // 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; | 566 // 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; |
| 567 // 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 | 567 // 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 |
| 568 // of 'width' is: (used height) * (intrinsic ratio) | 568 // of 'width' is: (used height) * (intrinsic ratio) |
| 569 if (intrinsicRatio && ((computedHeightIsAuto && !hasIntrinsicWidth &
& hasIntrinsicHeight) || !computedHeightIsAuto)) { | 569 if (intrinsicRatio && ((computedHeightIsAuto && !hasIntrinsicWidth &
& hasIntrinsicHeight) || !computedHeightIsAuto)) { |
| 570 LayoutUnit logicalHeight = computeReplacedLogicalHeight(); | 570 LayoutUnit logicalHeight = computeReplacedLogicalHeight(); |
| 571 return computeReplacedLogicalWidthRespectingMinMaxWidth(logicalH
eight * intrinsicRatio, shouldComputePreferred); | 571 return computeReplacedLogicalWidthRespectingMinMaxWidth(LayoutUn
it(logicalHeight * intrinsicRatio), shouldComputePreferred); |
| 572 } | 572 } |
| 573 | 573 |
| 574 // 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 | 574 // 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 |
| 575 // '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 | 575 // '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 |
| 576 // the used value of 'width' is calculated from the constraint equat
ion used for block-level, non-replaced elements in normal flow. | 576 // the used value of 'width' is calculated from the constraint equat
ion used for block-level, non-replaced elements in normal flow. |
| 577 if (computedHeightIsAuto && !hasIntrinsicWidth && !hasIntrinsicHeigh
t) { | 577 if (computedHeightIsAuto && !hasIntrinsicWidth && !hasIntrinsicHeigh
t) { |
| 578 if (shouldComputePreferred == ComputePreferred) | 578 if (shouldComputePreferred == ComputePreferred) |
| 579 return computeReplacedLogicalWidthRespectingMinMaxWidth(0, C
omputePreferred); | 579 return computeReplacedLogicalWidthRespectingMinMaxWidth(Layo
utUnit(), ComputePreferred); |
| 580 // The aforementioned 'constraint equation' used for block-level
, non-replaced elements in normal flow: | 580 // The aforementioned 'constraint equation' used for block-level
, non-replaced elements in normal flow: |
| 581 // 'margin-left' + 'border-left-width' + 'padding-left' + 'width
' + 'padding-right' + 'border-right-width' + 'margin-right' = width of containin
g block | 581 // 'margin-left' + 'border-left-width' + 'padding-left' + 'width
' + 'padding-right' + 'border-right-width' + 'margin-right' = width of containin
g block |
| 582 LayoutUnit logicalWidth = containingBlock()->availableLogicalWid
th(); | 582 LayoutUnit logicalWidth = containingBlock()->availableLogicalWid
th(); |
| 583 | 583 |
| 584 // This solves above equation for 'width' (== logicalWidth). | 584 // This solves above equation for 'width' (== logicalWidth). |
| 585 LayoutUnit marginStart = minimumValueForLength(style()->marginSt
art(), logicalWidth); | 585 LayoutUnit marginStart = minimumValueForLength(style()->marginSt
art(), logicalWidth); |
| 586 LayoutUnit marginEnd = minimumValueForLength(style()->marginEnd(
), logicalWidth); | 586 LayoutUnit marginEnd = minimumValueForLength(style()->marginEnd(
), logicalWidth); |
| 587 logicalWidth = (logicalWidth - (marginStart + marginEnd + (size(
).width() - clientWidth()))).clampNegativeToZero(); | 587 logicalWidth = (logicalWidth - (marginStart + marginEnd + (size(
).width() - clientWidth()))).clampNegativeToZero(); |
| 588 return computeReplacedLogicalWidthRespectingMinMaxWidth(logicalW
idth, shouldComputePreferred); | 588 return computeReplacedLogicalWidthRespectingMinMaxWidth(logicalW
idth, shouldComputePreferred); |
| 589 } | 589 } |
| 590 } | 590 } |
| 591 | 591 |
| 592 // 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'. | 592 // 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'. |
| 593 if (hasIntrinsicWidth) | 593 if (hasIntrinsicWidth) |
| 594 return computeReplacedLogicalWidthRespectingMinMaxWidth(constrainedS
ize.width(), shouldComputePreferred); | 594 return computeReplacedLogicalWidthRespectingMinMaxWidth(LayoutUnit(c
onstrainedSize.width()), shouldComputePreferred); |
| 595 | 595 |
| 596 // 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 | 596 // 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 |
| 597 // 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. | 597 // 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. |
| 598 // Note: We fall through and instead return intrinsicLogicalWidth() here
- to preserve existing WebKit behavior, which might or might not be correct, or
desired. | 598 // Note: We fall through and instead return intrinsicLogicalWidth() here
- to preserve existing WebKit behavior, which might or might not be correct, or
desired. |
| 599 // 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) | 599 // 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) |
| 600 // has no intrinsic size, which is wrong per CSS 2.1, but matches our be
havior since a long time. | 600 // has no intrinsic size, which is wrong per CSS 2.1, but matches our be
havior since a long time. |
| 601 } | 601 } |
| 602 | 602 |
| 603 return computeReplacedLogicalWidthRespectingMinMaxWidth(intrinsicLogicalWidt
h(), shouldComputePreferred); | 603 return computeReplacedLogicalWidthRespectingMinMaxWidth(intrinsicLogicalWidt
h(), shouldComputePreferred); |
| 604 } | 604 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 619 bool widthIsAuto = style()->logicalWidth().isAuto(); | 619 bool widthIsAuto = style()->logicalWidth().isAuto(); |
| 620 bool hasIntrinsicHeight = constrainedSize.height() > 0; | 620 bool hasIntrinsicHeight = constrainedSize.height() > 0; |
| 621 | 621 |
| 622 // 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'. | 622 // 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'. |
| 623 if (widthIsAuto && hasIntrinsicHeight) | 623 if (widthIsAuto && hasIntrinsicHeight) |
| 624 return computeReplacedLogicalHeightRespectingMinMaxHeight(constrainedSiz
e.height()); | 624 return computeReplacedLogicalHeightRespectingMinMaxHeight(constrainedSiz
e.height()); |
| 625 | 625 |
| 626 // Otherwise, if 'height' has a computed value of 'auto', and the element ha
s an intrinsic ratio then the used value of 'height' is: | 626 // Otherwise, if 'height' has a computed value of 'auto', and the element ha
s an intrinsic ratio then the used value of 'height' is: |
| 627 // (used width) / (intrinsic ratio) | 627 // (used width) / (intrinsic ratio) |
| 628 if (intrinsicRatio) | 628 if (intrinsicRatio) |
| 629 return computeReplacedLogicalHeightRespectingMinMaxHeight(availableLogic
alWidth() / intrinsicRatio); | 629 return computeReplacedLogicalHeightRespectingMinMaxHeight(LayoutUnit(ava
ilableLogicalWidth() / intrinsicRatio)); |
| 630 | 630 |
| 631 // 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'. | 631 // 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'. |
| 632 if (hasIntrinsicHeight) | 632 if (hasIntrinsicHeight) |
| 633 return computeReplacedLogicalHeightRespectingMinMaxHeight(constrainedSiz
e.height()); | 633 return computeReplacedLogicalHeightRespectingMinMaxHeight(LayoutUnit(con
strainedSize.height())); |
| 634 | 634 |
| 635 // 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 | 635 // 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 |
| 636 // 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. | 636 // 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. |
| 637 return computeReplacedLogicalHeightRespectingMinMaxHeight(intrinsicLogicalHe
ight()); | 637 return computeReplacedLogicalHeightRespectingMinMaxHeight(intrinsicLogicalHe
ight()); |
| 638 } | 638 } |
| 639 | 639 |
| 640 void LayoutReplaced::computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth,
LayoutUnit& maxLogicalWidth) const | 640 void LayoutReplaced::computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth,
LayoutUnit& maxLogicalWidth) const |
| 641 { | 641 { |
| 642 minLogicalWidth = maxLogicalWidth = intrinsicLogicalWidth(); | 642 minLogicalWidth = maxLogicalWidth = intrinsicLogicalWidth(); |
| 643 } | 643 } |
| 644 | 644 |
| 645 void LayoutReplaced::computePreferredLogicalWidths() | 645 void LayoutReplaced::computePreferredLogicalWidths() |
| 646 { | 646 { |
| 647 ASSERT(preferredLogicalWidthsDirty()); | 647 ASSERT(preferredLogicalWidthsDirty()); |
| 648 | 648 |
| 649 // We cannot resolve some logical width here (i.e. percent, fill-available o
r fit-content) | 649 // We cannot resolve some logical width here (i.e. percent, fill-available o
r fit-content) |
| 650 // as the available logical width may not be set on our containing block. | 650 // as the available logical width may not be set on our containing block. |
| 651 const Length& logicalWidth = style()->logicalWidth(); | 651 const Length& logicalWidth = style()->logicalWidth(); |
| 652 if (logicalWidth.hasPercent() || logicalWidth.isFillAvailable() || logicalWi
dth.isFitContent()) | 652 if (logicalWidth.hasPercent() || logicalWidth.isFillAvailable() || logicalWi
dth.isFitContent()) |
| 653 computeIntrinsicLogicalWidths(m_minPreferredLogicalWidth, m_maxPreferred
LogicalWidth); | 653 computeIntrinsicLogicalWidths(m_minPreferredLogicalWidth, m_maxPreferred
LogicalWidth); |
| 654 else | 654 else |
| 655 m_minPreferredLogicalWidth = m_maxPreferredLogicalWidth = computeReplace
dLogicalWidth(ComputePreferred); | 655 m_minPreferredLogicalWidth = m_maxPreferredLogicalWidth = computeReplace
dLogicalWidth(ComputePreferred); |
| 656 | 656 |
| 657 const ComputedStyle& styleToUse = styleRef(); | 657 const ComputedStyle& styleToUse = styleRef(); |
| 658 if (styleToUse.logicalWidth().hasPercent() || styleToUse.logicalMaxWidth().h
asPercent()) | 658 if (styleToUse.logicalWidth().hasPercent() || styleToUse.logicalMaxWidth().h
asPercent()) |
| 659 m_minPreferredLogicalWidth = 0; | 659 m_minPreferredLogicalWidth = LayoutUnit(); |
| 660 | 660 |
| 661 if (styleToUse.logicalMinWidth().isFixed() && styleToUse.logicalMinWidth().v
alue() > 0) { | 661 if (styleToUse.logicalMinWidth().isFixed() && styleToUse.logicalMinWidth().v
alue() > 0) { |
| 662 m_maxPreferredLogicalWidth = std::max(m_maxPreferredLogicalWidth, adjust
ContentBoxLogicalWidthForBoxSizing(styleToUse.logicalMinWidth().value())); | 662 m_maxPreferredLogicalWidth = std::max(m_maxPreferredLogicalWidth, adjust
ContentBoxLogicalWidthForBoxSizing(styleToUse.logicalMinWidth().value())); |
| 663 m_minPreferredLogicalWidth = std::max(m_minPreferredLogicalWidth, adjust
ContentBoxLogicalWidthForBoxSizing(styleToUse.logicalMinWidth().value())); | 663 m_minPreferredLogicalWidth = std::max(m_minPreferredLogicalWidth, adjust
ContentBoxLogicalWidthForBoxSizing(styleToUse.logicalMinWidth().value())); |
| 664 } | 664 } |
| 665 | 665 |
| 666 if (styleToUse.logicalMaxWidth().isFixed()) { | 666 if (styleToUse.logicalMaxWidth().isFixed()) { |
| 667 m_maxPreferredLogicalWidth = std::min(m_maxPreferredLogicalWidth, adjust
ContentBoxLogicalWidthForBoxSizing(styleToUse.logicalMaxWidth().value())); | 667 m_maxPreferredLogicalWidth = std::min(m_maxPreferredLogicalWidth, adjust
ContentBoxLogicalWidthForBoxSizing(styleToUse.logicalMaxWidth().value())); |
| 668 m_minPreferredLogicalWidth = std::min(m_minPreferredLogicalWidth, adjust
ContentBoxLogicalWidthForBoxSizing(styleToUse.logicalMaxWidth().value())); | 668 m_minPreferredLogicalWidth = std::min(m_minPreferredLogicalWidth, adjust
ContentBoxLogicalWidthForBoxSizing(styleToUse.logicalMaxWidth().value())); |
| 669 } | 669 } |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 745 // We only include the space below the baseline in our layer's cached paint
invalidation rect if the | 745 // We only include the space below the baseline in our layer's cached paint
invalidation rect if the |
| 746 // image is selected. Since the selection state has changed update the rect. | 746 // image is selected. Since the selection state has changed update the rect. |
| 747 if (hasLayer()) | 747 if (hasLayer()) |
| 748 setPreviousPaintInvalidationRect(boundsRectForPaintInvalidation(containe
rForPaintInvalidation())); | 748 setPreviousPaintInvalidationRect(boundsRectForPaintInvalidation(containe
rForPaintInvalidation())); |
| 749 | 749 |
| 750 if (canUpdateSelectionOnRootLineBoxes()) | 750 if (canUpdateSelectionOnRootLineBoxes()) |
| 751 inlineBoxWrapper()->root().setHasSelectedChildren(state != SelectionNone
); | 751 inlineBoxWrapper()->root().setHasSelectedChildren(state != SelectionNone
); |
| 752 } | 752 } |
| 753 | 753 |
| 754 } // namespace blink | 754 } // namespace blink |
| OLD | NEW |