Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(597)

Side by Side Diff: Source/core/rendering/RenderTable.cpp

Issue 14141004: Fix table sizing when 'max-width' is used (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Updated the test to use Ahem for consistency across platforms Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « LayoutTests/fast/table/html-table-width-max-width-constrained-expected.txt ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 Apple Inc. All r ights reserved. 7 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All r ights 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 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 LayoutUnit availableContentLogicalWidth = max<LayoutUnit>(0, containerWi dthInInlineDirection - marginTotal); 265 LayoutUnit availableContentLogicalWidth = max<LayoutUnit>(0, containerWi dthInInlineDirection - marginTotal);
266 if (shrinkToAvoidFloats() && cb->containsFloats() && !hasPerpendicularCo ntainingBlock) { 266 if (shrinkToAvoidFloats() && cb->containsFloats() && !hasPerpendicularCo ntainingBlock) {
267 // FIXME: Work with regions someday. 267 // FIXME: Work with regions someday.
268 availableContentLogicalWidth = shrinkLogicalWidthToAvoidFloats(margi nStart, marginEnd, cb, 0, 0); 268 availableContentLogicalWidth = shrinkLogicalWidthToAvoidFloats(margi nStart, marginEnd, cb, 0, 0);
269 } 269 }
270 270
271 // Ensure we aren't bigger than our available width. 271 // Ensure we aren't bigger than our available width.
272 setLogicalWidth(min<int>(availableContentLogicalWidth, maxPreferredLogic alWidth())); 272 setLogicalWidth(min<int>(availableContentLogicalWidth, maxPreferredLogic alWidth()));
273 } 273 }
274 274
275 // Ensure we aren't smaller than our min preferred width.
276 setLogicalWidth(max<int>(logicalWidth(), minPreferredLogicalWidth()));
277
278
279 // Ensure we aren't bigger than our max-width style. 275 // Ensure we aren't bigger than our max-width style.
280 Length styleMaxLogicalWidth = style()->logicalMaxWidth(); 276 Length styleMaxLogicalWidth = style()->logicalMaxWidth();
281 if ((styleMaxLogicalWidth.isSpecified() && !styleMaxLogicalWidth.isNegative( )) || styleMaxLogicalWidth.isIntrinsic()) { 277 if ((styleMaxLogicalWidth.isSpecified() && !styleMaxLogicalWidth.isNegative( )) || styleMaxLogicalWidth.isIntrinsic()) {
282 LayoutUnit computedMaxLogicalWidth = convertStyleLogicalWidthToComputedW idth(styleMaxLogicalWidth, availableLogicalWidth); 278 LayoutUnit computedMaxLogicalWidth = convertStyleLogicalWidthToComputedW idth(styleMaxLogicalWidth, availableLogicalWidth);
283 setLogicalWidth(min<int>(logicalWidth(), computedMaxLogicalWidth)); 279 setLogicalWidth(min<int>(logicalWidth(), computedMaxLogicalWidth));
284 } 280 }
285 281
286 // Ensure we aren't smaller than our min-width style. 282 // Ensure we aren't smaller than our min preferred width. This MUST be done after 'max-width' as
283 // we ignore it if it means we wouldn't accomodate our content.
284 setLogicalWidth(max<int>(logicalWidth(), minPreferredLogicalWidth()));
285
286 // Ensure we aren't smaller than our min-width style.
287 Length styleMinLogicalWidth = style()->logicalMinWidth(); 287 Length styleMinLogicalWidth = style()->logicalMinWidth();
288 if ((styleMinLogicalWidth.isSpecified() && !styleMinLogicalWidth.isNegative( )) || styleMinLogicalWidth.isIntrinsic()) { 288 if ((styleMinLogicalWidth.isSpecified() && !styleMinLogicalWidth.isNegative( )) || styleMinLogicalWidth.isIntrinsic()) {
289 LayoutUnit computedMinLogicalWidth = convertStyleLogicalWidthToComputedW idth(styleMinLogicalWidth, availableLogicalWidth); 289 LayoutUnit computedMinLogicalWidth = convertStyleLogicalWidthToComputedW idth(styleMinLogicalWidth, availableLogicalWidth);
290 setLogicalWidth(max<int>(logicalWidth(), computedMinLogicalWidth)); 290 setLogicalWidth(max<int>(logicalWidth(), computedMinLogicalWidth));
291 } 291 }
292 292
293 // Finally, with our true width determined, compute our margins for real. 293 // Finally, with our true width determined, compute our margins for real.
294 setMarginStart(0); 294 setMarginStart(0);
295 setMarginEnd(0); 295 setMarginEnd(0);
296 if (!hasPerpendicularContainingBlock) { 296 if (!hasPerpendicularContainingBlock) {
297 LayoutUnit containerLogicalWidthForAutoMargins = availableLogicalWidth; 297 LayoutUnit containerLogicalWidthForAutoMargins = availableLogicalWidth;
298 if (avoidsFloats() && cb->containsFloats()) 298 if (avoidsFloats() && cb->containsFloats())
299 containerLogicalWidthForAutoMargins = containingBlockAvailableLineWi dthInRegion(0, 0); // FIXME: Work with regions someday. 299 containerLogicalWidthForAutoMargins = containingBlockAvailableLineWi dthInRegion(0, 0); // FIXME: Work with regions someday.
300 ComputedMarginValues marginValues; 300 ComputedMarginValues marginValues;
301 bool hasInvertedDirection = cb->style()->isLeftToRightDirection() == st yle()->isLeftToRightDirection(); 301 bool hasInvertedDirection = cb->style()->isLeftToRightDirection() == st yle()->isLeftToRightDirection();
302 computeInlineDirectionMargins(cb, containerLogicalWidthForAutoMargins, l ogicalWidth(), 302 computeInlineDirectionMargins(cb, containerLogicalWidthForAutoMargins, l ogicalWidth(),
303 hasInvertedDirection ? marginValues.m_start : marginValues.m_end, 303 hasInvertedDirection ? marginValues.m_start : marginValues.m_end,
304 hasInvertedDirection ? marginValues.m_end : marginValues.m_start); 304 hasInvertedDirection ? marginValues.m_end : marginValues.m_start);
305 setMarginStart(marginValues.m_start); 305 setMarginStart(marginValues.m_start);
306 setMarginEnd(marginValues.m_end); 306 setMarginEnd(marginValues.m_end);
307 } else { 307 } else {
308 setMarginStart(minimumValueForLength(style()->marginStart(), availableLo gicalWidth, renderView)); 308 setMarginStart(minimumValueForLength(style()->marginStart(), availableLo gicalWidth, renderView));
309 setMarginEnd(minimumValueForLength(style()->marginEnd(), availableLogica lWidth, renderView)); 309 setMarginEnd(minimumValueForLength(style()->marginEnd(), availableLogica lWidth, renderView));
310 } 310 }
311
312 // We should NEVER shrink the table below the min-content logical width, or else the table can't accomodate
313 // its own content which doesn't match CSS nor what authors expect.
314 ASSERT(logicalWidth() >= minPreferredLogicalWidth());
311 } 315 }
312 316
313 // This method takes a RenderStyle's logical width, min-width, or max-width leng th and computes its actual value. 317 // This method takes a RenderStyle's logical width, min-width, or max-width leng th and computes its actual value.
314 LayoutUnit RenderTable::convertStyleLogicalWidthToComputedWidth(const Length& st yleLogicalWidth, LayoutUnit availableWidth) 318 LayoutUnit RenderTable::convertStyleLogicalWidthToComputedWidth(const Length& st yleLogicalWidth, LayoutUnit availableWidth)
315 { 319 {
316 if (styleLogicalWidth.isIntrinsic()) 320 if (styleLogicalWidth.isIntrinsic())
317 return computeIntrinsicLogicalWidthUsing(styleLogicalWidth, availableWid th, bordersPaddingAndSpacingInRowDirection()); 321 return computeIntrinsicLogicalWidthUsing(styleLogicalWidth, availableWid th, bordersPaddingAndSpacingInRowDirection());
318 322
319 // HTML tables' width styles already include borders and paddings, but CSS t ables' width styles do not. 323 // HTML tables' width styles already include borders and paddings, but CSS t ables' width styles do not.
320 LayoutUnit borders = 0; 324 LayoutUnit borders = 0;
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after
761 765
762 RenderStyle* styleToUse = style(); 766 RenderStyle* styleToUse = style();
763 // FIXME: This should probably be checking for isSpecified since you should be able to use percentage, calc or viewport relative values for min-width. 767 // FIXME: This should probably be checking for isSpecified since you should be able to use percentage, calc or viewport relative values for min-width.
764 if (styleToUse->logicalMinWidth().isFixed() && styleToUse->logicalMinWidth() .value() > 0) { 768 if (styleToUse->logicalMinWidth().isFixed() && styleToUse->logicalMinWidth() .value() > 0) {
765 m_maxPreferredLogicalWidth = std::max(m_maxPreferredLogicalWidth, adjust ContentBoxLogicalWidthForBoxSizing(styleToUse->logicalMinWidth().value())); 769 m_maxPreferredLogicalWidth = std::max(m_maxPreferredLogicalWidth, adjust ContentBoxLogicalWidthForBoxSizing(styleToUse->logicalMinWidth().value()));
766 m_minPreferredLogicalWidth = std::max(m_minPreferredLogicalWidth, adjust ContentBoxLogicalWidthForBoxSizing(styleToUse->logicalMinWidth().value())); 770 m_minPreferredLogicalWidth = std::max(m_minPreferredLogicalWidth, adjust ContentBoxLogicalWidthForBoxSizing(styleToUse->logicalMinWidth().value()));
767 } 771 }
768 772
769 // FIXME: This should probably be checking for isSpecified since you should be able to use percentage, calc or viewport relative values for maxWidth. 773 // FIXME: This should probably be checking for isSpecified since you should be able to use percentage, calc or viewport relative values for maxWidth.
770 if (styleToUse->logicalMaxWidth().isFixed()) { 774 if (styleToUse->logicalMaxWidth().isFixed()) {
775 // We don't constrain m_minPreferredLogicalWidth as the table should be at least the size of its min-content, regardless of 'max-width'.
771 m_maxPreferredLogicalWidth = std::min(m_maxPreferredLogicalWidth, adjust ContentBoxLogicalWidthForBoxSizing(styleToUse->logicalMaxWidth().value())); 776 m_maxPreferredLogicalWidth = std::min(m_maxPreferredLogicalWidth, adjust ContentBoxLogicalWidthForBoxSizing(styleToUse->logicalMaxWidth().value()));
772 m_minPreferredLogicalWidth = std::min(m_minPreferredLogicalWidth, adjust ContentBoxLogicalWidthForBoxSizing(styleToUse->logicalMaxWidth().value())); 777 m_maxPreferredLogicalWidth = std::max(m_minPreferredLogicalWidth, m_maxP referredLogicalWidth);
773 } 778 }
774 779
775 // FIXME: We should be adding borderAndPaddingLogicalWidth here, but m_table Layout->computePreferredLogicalWidths already does, 780 // FIXME: We should be adding borderAndPaddingLogicalWidth here, but m_table Layout->computePreferredLogicalWidths already does,
776 // so a bunch of tests break doing this naively. 781 // so a bunch of tests break doing this naively.
777 setPreferredLogicalWidthsDirty(false); 782 setPreferredLogicalWidthsDirty(false);
778 } 783 }
779 784
780 RenderTableSection* RenderTable::topNonEmptySection() const 785 RenderTableSection* RenderTable::topNonEmptySection() const
781 { 786 {
782 RenderTableSection* section = topSection(); 787 RenderTableSection* section = topSection();
(...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after
1428 const BorderValue& RenderTable::tableEndBorderAdjoiningCell(const RenderTableCel l* cell) const 1433 const BorderValue& RenderTable::tableEndBorderAdjoiningCell(const RenderTableCel l* cell) const
1429 { 1434 {
1430 ASSERT(cell->isFirstOrLastCellInRow()); 1435 ASSERT(cell->isFirstOrLastCellInRow());
1431 if (hasSameDirectionAs(cell->row())) 1436 if (hasSameDirectionAs(cell->row()))
1432 return style()->borderEnd(); 1437 return style()->borderEnd();
1433 1438
1434 return style()->borderStart(); 1439 return style()->borderStart();
1435 } 1440 }
1436 1441
1437 } 1442 }
OLDNEW
« no previous file with comments | « LayoutTests/fast/table/html-table-width-max-width-constrained-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698