| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 1997 Martin Jones (mjones@kde.org) | 2 * Copyright (C) 1997 Martin Jones (mjones@kde.org) |
| 3 * (C) 1997 Torben Weis (weis@kde.org) | 3 * (C) 1997 Torben Weis (weis@kde.org) |
| 4 * (C) 1998 Waldo Bastian (bastian@kde.org) | 4 * (C) 1998 Waldo Bastian (bastian@kde.org) |
| 5 * (C) 1999 Lars Knoll (knoll@kde.org) | 5 * (C) 1999 Lars Knoll (knoll@kde.org) |
| 6 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 6 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
| 7 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2013 Apple Inc.
All rights reserved. | 7 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2013 Apple Inc.
All rights reserved. |
| 8 * Copyright (C) 2006 Alexey Proskuryakov (ap@nypop.com) | 8 * Copyright (C) 2006 Alexey Proskuryakov (ap@nypop.com) |
| 9 * | 9 * |
| 10 * This library is free software; you can redistribute it and/or | 10 * This library is free software; you can redistribute it and/or |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 LayoutUnit marginStart = minimumValueForLength(style()->marginStart(), a
vailableLogicalWidth); | 279 LayoutUnit marginStart = minimumValueForLength(style()->marginStart(), a
vailableLogicalWidth); |
| 280 LayoutUnit marginEnd = minimumValueForLength(style()->marginEnd(), avail
ableLogicalWidth); | 280 LayoutUnit marginEnd = minimumValueForLength(style()->marginEnd(), avail
ableLogicalWidth); |
| 281 LayoutUnit marginTotal = marginStart + marginEnd; | 281 LayoutUnit marginTotal = marginStart + marginEnd; |
| 282 | 282 |
| 283 // Subtract out our margins to get the available content width. | 283 // Subtract out our margins to get the available content width. |
| 284 LayoutUnit availableContentLogicalWidth = (containerWidthInInlineDirecti
on - marginTotal).clampNegativeToZero(); | 284 LayoutUnit availableContentLogicalWidth = (containerWidthInInlineDirecti
on - marginTotal).clampNegativeToZero(); |
| 285 if (shrinkToAvoidFloats() && cb->isLayoutBlockFlow() && toLayoutBlockFlo
w(cb)->containsFloats() && !hasPerpendicularContainingBlock) | 285 if (shrinkToAvoidFloats() && cb->isLayoutBlockFlow() && toLayoutBlockFlo
w(cb)->containsFloats() && !hasPerpendicularContainingBlock) |
| 286 availableContentLogicalWidth = shrinkLogicalWidthToAvoidFloats(margi
nStart, marginEnd, toLayoutBlockFlow(cb)); | 286 availableContentLogicalWidth = shrinkLogicalWidthToAvoidFloats(margi
nStart, marginEnd, toLayoutBlockFlow(cb)); |
| 287 | 287 |
| 288 // Ensure we aren't bigger than our available width. | 288 // Ensure we aren't bigger than our available width. |
| 289 setLogicalWidth(std::min<int>(availableContentLogicalWidth, maxPreferred
LogicalWidth())); | 289 setLogicalWidth(LayoutUnit(std::min(availableContentLogicalWidth, maxPre
ferredLogicalWidth()).floor())); |
| 290 } | 290 } |
| 291 | 291 |
| 292 // Ensure we aren't bigger than our max-width style. | 292 // Ensure we aren't bigger than our max-width style. |
| 293 Length styleMaxLogicalWidth = style()->logicalMaxWidth(); | 293 Length styleMaxLogicalWidth = style()->logicalMaxWidth(); |
| 294 if ((styleMaxLogicalWidth.isSpecified() && !styleMaxLogicalWidth.isNegative(
)) || styleMaxLogicalWidth.isIntrinsic()) { | 294 if ((styleMaxLogicalWidth.isSpecified() && !styleMaxLogicalWidth.isNegative(
)) || styleMaxLogicalWidth.isIntrinsic()) { |
| 295 LayoutUnit computedMaxLogicalWidth = convertStyleLogicalWidthToComputedW
idth(styleMaxLogicalWidth, availableLogicalWidth); | 295 LayoutUnit computedMaxLogicalWidth = convertStyleLogicalWidthToComputedW
idth(styleMaxLogicalWidth, availableLogicalWidth); |
| 296 setLogicalWidth(std::min<int>(logicalWidth(), computedMaxLogicalWidth)); | 296 setLogicalWidth(LayoutUnit(std::min(logicalWidth(), computedMaxLogicalWi
dth).floor())); |
| 297 } | 297 } |
| 298 | 298 |
| 299 // Ensure we aren't smaller than our min preferred width. This MUST be done
after 'max-width' as | 299 // Ensure we aren't smaller than our min preferred width. This MUST be done
after 'max-width' as |
| 300 // we ignore it if it means we wouldn't accommodate our content. | 300 // we ignore it if it means we wouldn't accommodate our content. |
| 301 setLogicalWidth(std::max<int>(logicalWidth(), minPreferredLogicalWidth())); | 301 setLogicalWidth(std::max<int>(logicalWidth(), minPreferredLogicalWidth())); |
| 302 | 302 |
| 303 // Ensure we aren't smaller than our min-width style. | 303 // Ensure we aren't smaller than our min-width style. |
| 304 Length styleMinLogicalWidth = style()->logicalMinWidth(); | 304 Length styleMinLogicalWidth = style()->logicalMinWidth(); |
| 305 if ((styleMinLogicalWidth.isSpecified() && !styleMinLogicalWidth.isNegative(
)) || styleMinLogicalWidth.isIntrinsic()) { | 305 if ((styleMinLogicalWidth.isSpecified() && !styleMinLogicalWidth.isNegative(
)) || styleMinLogicalWidth.isIntrinsic()) { |
| 306 LayoutUnit computedMinLogicalWidth = convertStyleLogicalWidthToComputedW
idth(styleMinLogicalWidth, availableLogicalWidth); | 306 LayoutUnit computedMinLogicalWidth = convertStyleLogicalWidthToComputedW
idth(styleMinLogicalWidth, availableLogicalWidth); |
| 307 setLogicalWidth(std::max<int>(logicalWidth(), computedMinLogicalWidth)); | 307 setLogicalWidth(LayoutUnit(std::max(logicalWidth(), computedMinLogicalWi
dth).floor())); |
| 308 } | 308 } |
| 309 | 309 |
| 310 // Finally, with our true width determined, compute our margins for real. | 310 // Finally, with our true width determined, compute our margins for real. |
| 311 ComputedMarginValues marginValues; | 311 ComputedMarginValues marginValues; |
| 312 computeMarginsForDirection(InlineDirection, cb, availableLogicalWidth, logic
alWidth(), marginValues.m_start, marginValues.m_end, style()->marginStart(), sty
le()->marginEnd()); | 312 computeMarginsForDirection(InlineDirection, cb, availableLogicalWidth, logic
alWidth(), marginValues.m_start, marginValues.m_end, style()->marginStart(), sty
le()->marginEnd()); |
| 313 setMarginStart(marginValues.m_start); | 313 setMarginStart(marginValues.m_start); |
| 314 setMarginEnd(marginValues.m_end); | 314 setMarginEnd(marginValues.m_end); |
| 315 | 315 |
| 316 // We should NEVER shrink the table below the min-content logical width, or
else the table can't accommodate | 316 // We should NEVER shrink the table below the min-content logical width, or
else the table can't accommodate |
| 317 // its own content which doesn't match CSS nor what authors expect. | 317 // its own content which doesn't match CSS nor what authors expect. |
| 318 // FIXME: When we convert to sub-pixel layout for tables we can remove the i
nt conversion | 318 // FIXME: When we convert to sub-pixel layout for tables we can remove the i
nt conversion |
| 319 // https://code.google.com/p/chromium/issues/detail?id=241198 | 319 // https://code.google.com/p/chromium/issues/detail?id=241198 |
| 320 ASSERT(logicalWidth().toInt() >= minPreferredLogicalWidth().toInt()); | 320 ASSERT(logicalWidth().floor() >= minPreferredLogicalWidth().floor()); |
| 321 } | 321 } |
| 322 | 322 |
| 323 // This method takes a ComputedStyle's logical width, min-width, or max-width le
ngth and computes its actual value. | 323 // This method takes a ComputedStyle's logical width, min-width, or max-width le
ngth and computes its actual value. |
| 324 LayoutUnit LayoutTable::convertStyleLogicalWidthToComputedWidth(const Length& st
yleLogicalWidth, LayoutUnit availableWidth) | 324 LayoutUnit LayoutTable::convertStyleLogicalWidthToComputedWidth(const Length& st
yleLogicalWidth, LayoutUnit availableWidth) |
| 325 { | 325 { |
| 326 if (styleLogicalWidth.isIntrinsic()) | 326 if (styleLogicalWidth.isIntrinsic()) |
| 327 return computeIntrinsicLogicalWidthUsing(styleLogicalWidth, availableWid
th, bordersPaddingAndSpacingInRowDirection()); | 327 return computeIntrinsicLogicalWidthUsing(styleLogicalWidth, availableWid
th, bordersPaddingAndSpacingInRowDirection()); |
| 328 | 328 |
| 329 // HTML tables' width styles already include borders and paddings, but CSS t
ables' width styles do not. | 329 // HTML tables' width styles already include borders and paddings, but CSS t
ables' width styles do not. |
| 330 LayoutUnit borders; | 330 LayoutUnit borders; |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 429 | 429 |
| 430 // If any table section moved vertically, we will just issue paint invalidat
ions for everything from that | 430 // If any table section moved vertically, we will just issue paint invalidat
ions for everything from that |
| 431 // section down (it is quite unlikely that any of the following sections | 431 // section down (it is quite unlikely that any of the following sections |
| 432 // did not shift). | 432 // did not shift). |
| 433 bool sectionMoved = false; | 433 bool sectionMoved = false; |
| 434 { | 434 { |
| 435 LayoutState state(*this, locationOffset()); | 435 LayoutState state(*this, locationOffset()); |
| 436 LayoutUnit oldLogicalWidth = logicalWidth(); | 436 LayoutUnit oldLogicalWidth = logicalWidth(); |
| 437 LayoutUnit oldLogicalHeight = logicalHeight(); | 437 LayoutUnit oldLogicalHeight = logicalHeight(); |
| 438 | 438 |
| 439 setLogicalHeight(0); | 439 setLogicalHeight(LayoutUnit()); |
| 440 updateLogicalWidth(); | 440 updateLogicalWidth(); |
| 441 | 441 |
| 442 if (logicalWidth() != oldLogicalWidth) { | 442 if (logicalWidth() != oldLogicalWidth) { |
| 443 for (unsigned i = 0; i < m_captions.size(); i++) | 443 for (unsigned i = 0; i < m_captions.size(); i++) |
| 444 layouter.setNeedsLayout(m_captions[i], LayoutInvalidationReason:
:TableChanged); | 444 layouter.setNeedsLayout(m_captions[i], LayoutInvalidationReason:
:TableChanged); |
| 445 } | 445 } |
| 446 // FIXME: The optimisation below doesn't work since the internal table | 446 // FIXME: The optimisation below doesn't work since the internal table |
| 447 // layout could have changed. We need to add a flag to the table | 447 // layout could have changed. We need to add a flag to the table |
| 448 // layout that tells us if something has changed in the min max | 448 // layout that tells us if something has changed in the min max |
| 449 // calculations to do it correctly. | 449 // calculations to do it correctly. |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 517 | 517 |
| 518 for (LayoutTableSection* section = topSection(); section; section = sect
ionBelow(section)) | 518 for (LayoutTableSection* section = topSection(); section; section = sect
ionBelow(section)) |
| 519 section->layoutRows(); | 519 section->layoutRows(); |
| 520 | 520 |
| 521 if (!topSection() && computedLogicalHeight > totalSectionLogicalHeight &
& !document().inQuirksMode()) { | 521 if (!topSection() && computedLogicalHeight > totalSectionLogicalHeight &
& !document().inQuirksMode()) { |
| 522 // Completely empty tables (with no sections or anything) should at
least honor specified height | 522 // Completely empty tables (with no sections or anything) should at
least honor specified height |
| 523 // in strict mode. | 523 // in strict mode. |
| 524 setLogicalHeight(logicalHeight() + computedLogicalHeight); | 524 setLogicalHeight(logicalHeight() + computedLogicalHeight); |
| 525 } | 525 } |
| 526 | 526 |
| 527 LayoutUnit sectionLogicalLeft = style()->isLeftToRightDirection() ? bord
erStart() : borderEnd(); | 527 LayoutUnit sectionLogicalLeft = LayoutUnit(style()->isLeftToRightDirecti
on() ? borderStart() : borderEnd()); |
| 528 if (!collapsing) | 528 if (!collapsing) |
| 529 sectionLogicalLeft += style()->isLeftToRightDirection() ? paddingSta
rt() : paddingEnd(); | 529 sectionLogicalLeft += style()->isLeftToRightDirection() ? paddingSta
rt() : paddingEnd(); |
| 530 | 530 |
| 531 // position the table sections | 531 // position the table sections |
| 532 LayoutTableSection* section = topSection(); | 532 LayoutTableSection* section = topSection(); |
| 533 while (section) { | 533 while (section) { |
| 534 if (!sectionMoved && section->logicalTop() != logicalHeight()) | 534 if (!sectionMoved && section->logicalTop() != logicalHeight()) |
| 535 sectionMoved = true; | 535 sectionMoved = true; |
| 536 section->setLogicalLocation(LayoutPoint(sectionLogicalLeft, logicalH
eight())); | 536 section->setLogicalLocation(LayoutPoint(sectionLogicalLeft, logicalH
eight())); |
| 537 | 537 |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 647 } | 647 } |
| 648 | 648 |
| 649 void LayoutTable::subtractCaptionRect(LayoutRect& rect) const | 649 void LayoutTable::subtractCaptionRect(LayoutRect& rect) const |
| 650 { | 650 { |
| 651 for (unsigned i = 0; i < m_captions.size(); i++) { | 651 for (unsigned i = 0; i < m_captions.size(); i++) { |
| 652 LayoutUnit captionLogicalHeight = m_captions[i]->logicalHeight() + m_cap
tions[i]->marginBefore() + m_captions[i]->marginAfter(); | 652 LayoutUnit captionLogicalHeight = m_captions[i]->logicalHeight() + m_cap
tions[i]->marginBefore() + m_captions[i]->marginAfter(); |
| 653 bool captionIsBefore = (m_captions[i]->style()->captionSide() != CAPBOTT
OM) ^ style()->isFlippedBlocksWritingMode(); | 653 bool captionIsBefore = (m_captions[i]->style()->captionSide() != CAPBOTT
OM) ^ style()->isFlippedBlocksWritingMode(); |
| 654 if (style()->isHorizontalWritingMode()) { | 654 if (style()->isHorizontalWritingMode()) { |
| 655 rect.setHeight(rect.height() - captionLogicalHeight); | 655 rect.setHeight(rect.height() - captionLogicalHeight); |
| 656 if (captionIsBefore) | 656 if (captionIsBefore) |
| 657 rect.move(0, captionLogicalHeight); | 657 rect.move(LayoutUnit(), captionLogicalHeight); |
| 658 } else { | 658 } else { |
| 659 rect.setWidth(rect.width() - captionLogicalHeight); | 659 rect.setWidth(rect.width() - captionLogicalHeight); |
| 660 if (captionIsBefore) | 660 if (captionIsBefore) |
| 661 rect.move(captionLogicalHeight, 0); | 661 rect.move(captionLogicalHeight, LayoutUnit()); |
| 662 } | 662 } |
| 663 } | 663 } |
| 664 } | 664 } |
| 665 | 665 |
| 666 void LayoutTable::paintBoxDecorationBackground(const PaintInfo& paintInfo, const
LayoutPoint& paintOffset) const | 666 void LayoutTable::paintBoxDecorationBackground(const PaintInfo& paintInfo, const
LayoutPoint& paintOffset) const |
| 667 { | 667 { |
| 668 TablePainter(*this).paintBoxDecorationBackground(paintInfo, paintOffset); | 668 TablePainter(*this).paintBoxDecorationBackground(paintInfo, paintOffset); |
| 669 } | 669 } |
| 670 | 670 |
| 671 void LayoutTable::paintMask(const PaintInfo& paintInfo, const LayoutPoint& paint
Offset) const | 671 void LayoutTable::paintMask(const PaintInfo& paintInfo, const LayoutPoint& paint
Offset) const |
| (...skipping 783 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1455 | 1455 |
| 1456 LayoutUnit LayoutTable::paddingRight() const | 1456 LayoutUnit LayoutTable::paddingRight() const |
| 1457 { | 1457 { |
| 1458 if (collapseBorders()) | 1458 if (collapseBorders()) |
| 1459 return LayoutUnit(); | 1459 return LayoutUnit(); |
| 1460 | 1460 |
| 1461 return LayoutBlock::paddingRight(); | 1461 return LayoutBlock::paddingRight(); |
| 1462 } | 1462 } |
| 1463 | 1463 |
| 1464 } // namespace blink | 1464 } // namespace blink |
| OLD | NEW |