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

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

Issue 24360004: Use shrink-to-fit for width for Button, input, select, textarea, and legend treat width value of 'a… (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fixed review comments Created 7 years, 2 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
« no previous file with comments | « Source/core/rendering/RenderBox.h ('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) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2005 Allan Sandfeld Jensen (kde@carewolf.com) 4 * (C) 2005 Allan Sandfeld Jensen (kde@carewolf.com)
5 * (C) 2005, 2006 Samuel Weinig (sam.weinig@gmail.com) 5 * (C) 2005, 2006 Samuel Weinig (sam.weinig@gmail.com)
6 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserv ed. 6 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserv ed.
7 * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved. 7 * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved.
8 * 8 *
9 * This library is free software; you can redistribute it and/or 9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public 10 * modify it under the terms of the GNU Library General Public
(...skipping 2329 matching lines...) Expand 10 before | Expand all | Expand 10 after
2340 // that don't stretch their kids lay out their children at their intrinsic w idths. 2340 // that don't stretch their kids lay out their children at their intrinsic w idths.
2341 // FIXME: Think about block-flow here. 2341 // FIXME: Think about block-flow here.
2342 // https://bugs.webkit.org/show_bug.cgi?id=46473 2342 // https://bugs.webkit.org/show_bug.cgi?id=46473
2343 if (parent()->isDeprecatedFlexibleBox() && (parent()->style()->boxOrient() = = HORIZONTAL || parent()->style()->boxAlign() != BSTRETCH)) 2343 if (parent()->isDeprecatedFlexibleBox() && (parent()->style()->boxOrient() = = HORIZONTAL || parent()->style()->boxAlign() != BSTRETCH))
2344 return true; 2344 return true;
2345 2345
2346 // Button, input, select, textarea, and legend treat width value of 'auto' a s 'intrinsic' unless it's in a 2346 // Button, input, select, textarea, and legend treat width value of 'auto' a s 'intrinsic' unless it's in a
2347 // stretching column flexbox. 2347 // stretching column flexbox.
2348 // FIXME: Think about block-flow here. 2348 // FIXME: Think about block-flow here.
2349 // https://bugs.webkit.org/show_bug.cgi?id=46473 2349 // https://bugs.webkit.org/show_bug.cgi?id=46473
2350 if (logicalWidth.type() == Auto && !isStretchingColumnFlexItem(this) && node () && (node()->hasTagName(inputTag) 2350 if (logicalWidth.type() == Auto && !isStretchingColumnFlexItem(this) && auto WidthShouldFitContent())
2351 || node()->hasTagName(selectTag) || node()->hasTagName(buttonTag) || isH TMLTextAreaElement(node()) || node()->hasTagName(legendTag)))
2352 return true; 2351 return true;
2353 2352
2354 if (isHorizontalWritingMode() != containingBlock()->isHorizontalWritingMode( )) 2353 if (isHorizontalWritingMode() != containingBlock()->isHorizontalWritingMode( ))
2355 return true; 2354 return true;
2356 2355
2357 return false; 2356 return false;
2358 } 2357 }
2359 2358
2359 bool RenderBox::autoWidthShouldFitContent() const
2360 {
2361 if (node() && (node()->hasTagName(inputTag) || node()->hasTagName(selectTag) || node()->hasTagName(buttonTag)
2362 || isHTMLTextAreaElement(node()) || node()->hasTagName(legendTag)))
2363 return true;
2364
2365 return false;
2366 }
2367
2360 void RenderBox::computeInlineDirectionMargins(RenderBlock* containingBlock, Layo utUnit containerWidth, LayoutUnit childWidth, LayoutUnit& marginStart, LayoutUni t& marginEnd) const 2368 void RenderBox::computeInlineDirectionMargins(RenderBlock* containingBlock, Layo utUnit containerWidth, LayoutUnit childWidth, LayoutUnit& marginStart, LayoutUni t& marginEnd) const
2361 { 2369 {
2362 const RenderStyle* containingBlockStyle = containingBlock->style(); 2370 const RenderStyle* containingBlockStyle = containingBlock->style();
2363 Length marginStartLength = style()->marginStartUsing(containingBlockStyle); 2371 Length marginStartLength = style()->marginStartUsing(containingBlockStyle);
2364 Length marginEndLength = style()->marginEndUsing(containingBlockStyle); 2372 Length marginEndLength = style()->marginEndUsing(containingBlockStyle);
2365 RenderView* renderView = view(); 2373 RenderView* renderView = view();
2366 2374
2367 if (isFloating() || isInline()) { 2375 if (isFloating() || isInline()) {
2368 // Inline blocks/tables and floats don't have their margins increased. 2376 // Inline blocks/tables and floats don't have their margins increased.
2369 marginStart = minimumValueForLength(marginStartLength, containerWidth, r enderView); 2377 marginStart = minimumValueForLength(marginStartLength, containerWidth, r enderView);
(...skipping 948 matching lines...) Expand 10 before | Expand all | Expand 10 after
3318 { 3326 {
3319 // Deal with differing writing modes here. Our offset needs to be in the co ntaining block's coordinate space. If the containing block is flipped 3327 // Deal with differing writing modes here. Our offset needs to be in the co ntaining block's coordinate space. If the containing block is flipped
3320 // along this axis, then we need to flip the coordinate. This can only happ en if the containing block is both a flipped mode and perpendicular to us. 3328 // along this axis, then we need to flip the coordinate. This can only happ en if the containing block is both a flipped mode and perpendicular to us.
3321 if (containerBlock->isHorizontalWritingMode() != child->isHorizontalWritingM ode() && containerBlock->style()->isFlippedBlocksWritingMode()) { 3329 if (containerBlock->isHorizontalWritingMode() != child->isHorizontalWritingM ode() && containerBlock->style()->isFlippedBlocksWritingMode()) {
3322 logicalLeftPos = containerLogicalWidth - logicalWidthValue - logicalLeft Pos; 3330 logicalLeftPos = containerLogicalWidth - logicalWidthValue - logicalLeft Pos;
3323 logicalLeftPos += (child->isHorizontalWritingMode() ? containerBlock->bo rderRight() : containerBlock->borderBottom()); 3331 logicalLeftPos += (child->isHorizontalWritingMode() ? containerBlock->bo rderRight() : containerBlock->borderBottom());
3324 } else 3332 } else
3325 logicalLeftPos += (child->isHorizontalWritingMode() ? containerBlock->bo rderLeft() : containerBlock->borderTop()); 3333 logicalLeftPos += (child->isHorizontalWritingMode() ? containerBlock->bo rderLeft() : containerBlock->borderTop());
3326 } 3334 }
3327 3335
3336 void RenderBox::shrinkToFitWidth(const LayoutUnit availableSpace, const LayoutUn it logicalLeftValue, const LayoutUnit bordersPlusPadding, LogicalExtentComputedV alues& computedValues) const
3337 {
3338 // FIXME: would it be better to have shrink-to-fit in one step?
3339 LayoutUnit preferredWidth = maxPreferredLogicalWidth() - bordersPlusPadding;
3340 LayoutUnit preferredMinWidth = minPreferredLogicalWidth() - bordersPlusPaddi ng;
3341 LayoutUnit availableWidth = availableSpace - logicalLeftValue;
3342 computedValues.m_extent = min(max(preferredMinWidth, availableWidth), prefer redWidth);
3343 }
3344
3328 void RenderBox::computePositionedLogicalWidthUsing(Length logicalWidth, const Re nderBoxModelObject* containerBlock, TextDirection containerDirection, 3345 void RenderBox::computePositionedLogicalWidthUsing(Length logicalWidth, const Re nderBoxModelObject* containerBlock, TextDirection containerDirection,
3329 LayoutUnit containerLogicalWi dth, LayoutUnit bordersPlusPadding, 3346 LayoutUnit containerLogicalWi dth, LayoutUnit bordersPlusPadding,
3330 Length logicalLeft, Length lo gicalRight, Length marginLogicalLeft, Length marginLogicalRight, 3347 Length logicalLeft, Length lo gicalRight, Length marginLogicalLeft, Length marginLogicalRight,
3331 LogicalExtentComputedValues& computedValues) const 3348 LogicalExtentComputedValues& computedValues) const
3332 { 3349 {
3333 if (logicalWidth.isIntrinsic()) 3350 if (logicalWidth.isIntrinsic())
3334 logicalWidth = Length(computeIntrinsicLogicalWidthUsing(logicalWidth, co ntainerLogicalWidth, bordersPlusPadding) - bordersPlusPadding, Fixed); 3351 logicalWidth = Length(computeIntrinsicLogicalWidthUsing(logicalWidth, co ntainerLogicalWidth, bordersPlusPadding) - bordersPlusPadding, Fixed);
3335 3352
3336 // 'left' and 'right' cannot both be 'auto' because one would of been 3353 // 'left' and 'right' cannot both be 'auto' because one would of been
3337 // converted to the static position already 3354 // converted to the static position already
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
3460 // FIXME: would it be better to have shrink-to-fit in one step? 3477 // FIXME: would it be better to have shrink-to-fit in one step?
3461 LayoutUnit preferredWidth = maxPreferredLogicalWidth() - bordersPlus Padding; 3478 LayoutUnit preferredWidth = maxPreferredLogicalWidth() - bordersPlus Padding;
3462 LayoutUnit preferredMinWidth = minPreferredLogicalWidth() - bordersP lusPadding; 3479 LayoutUnit preferredMinWidth = minPreferredLogicalWidth() - bordersP lusPadding;
3463 LayoutUnit availableWidth = availableSpace - logicalRightValue; 3480 LayoutUnit availableWidth = availableSpace - logicalRightValue;
3464 computedValues.m_extent = min(max(preferredMinWidth, availableWidth) , preferredWidth); 3481 computedValues.m_extent = min(max(preferredMinWidth, availableWidth) , preferredWidth);
3465 logicalLeftValue = availableSpace - (computedValues.m_extent + logic alRightValue); 3482 logicalLeftValue = availableSpace - (computedValues.m_extent + logic alRightValue);
3466 } else if (!logicalLeftIsAuto && logicalWidthIsAuto && logicalRightIsAut o) { 3483 } else if (!logicalLeftIsAuto && logicalWidthIsAuto && logicalRightIsAut o) {
3467 // RULE 3: (use shrink-to-fit for width, and no need solve of right) 3484 // RULE 3: (use shrink-to-fit for width, and no need solve of right)
3468 logicalLeftValue = valueForLength(logicalLeft, containerLogicalWidth , renderView); 3485 logicalLeftValue = valueForLength(logicalLeft, containerLogicalWidth , renderView);
3469 3486
3470 // FIXME: would it be better to have shrink-to-fit in one step? 3487 shrinkToFitWidth(availableSpace, logicalLeftValue, bordersPlusPaddin g, computedValues);
3471 LayoutUnit preferredWidth = maxPreferredLogicalWidth() - bordersPlus Padding;
3472 LayoutUnit preferredMinWidth = minPreferredLogicalWidth() - bordersP lusPadding;
3473 LayoutUnit availableWidth = availableSpace - logicalLeftValue;
3474 computedValues.m_extent = min(max(preferredMinWidth, availableWidth) , preferredWidth);
3475 } else if (logicalLeftIsAuto && !logicalWidthIsAuto && !logicalRightIsAu to) { 3488 } else if (logicalLeftIsAuto && !logicalWidthIsAuto && !logicalRightIsAu to) {
3476 // RULE 4: (solve for left) 3489 // RULE 4: (solve for left)
3477 computedValues.m_extent = adjustContentBoxLogicalWidthForBoxSizing(v alueForLength(logicalWidth, containerLogicalWidth, renderView)); 3490 computedValues.m_extent = adjustContentBoxLogicalWidthForBoxSizing(v alueForLength(logicalWidth, containerLogicalWidth, renderView));
3478 logicalLeftValue = availableSpace - (computedValues.m_extent + value ForLength(logicalRight, containerLogicalWidth, renderView)); 3491 logicalLeftValue = availableSpace - (computedValues.m_extent + value ForLength(logicalRight, containerLogicalWidth, renderView));
3479 } else if (!logicalLeftIsAuto && logicalWidthIsAuto && !logicalRightIsAu to) { 3492 } else if (!logicalLeftIsAuto && logicalWidthIsAuto && !logicalRightIsAu to) {
3480 // RULE 5: (solve for width) 3493 // RULE 5: (solve for width)
3481 logicalLeftValue = valueForLength(logicalLeft, containerLogicalWidth , renderView); 3494 logicalLeftValue = valueForLength(logicalLeft, containerLogicalWidth , renderView);
3482 computedValues.m_extent = availableSpace - (logicalLeftValue + value ForLength(logicalRight, containerLogicalWidth, renderView)); 3495 if (autoWidthShouldFitContent())
3496 shrinkToFitWidth(availableSpace, logicalLeftValue, bordersPlusPa dding, computedValues);
3497 else
3498 computedValues.m_extent = availableSpace - (logicalLeftValue + v alueForLength(logicalRight, containerLogicalWidth, renderView));
3483 } else if (!logicalLeftIsAuto && !logicalWidthIsAuto && logicalRightIsAu to) { 3499 } else if (!logicalLeftIsAuto && !logicalWidthIsAuto && logicalRightIsAu to) {
3484 // RULE 6: (no need solve for right) 3500 // RULE 6: (no need solve for right)
3485 logicalLeftValue = valueForLength(logicalLeft, containerLogicalWidth , renderView); 3501 logicalLeftValue = valueForLength(logicalLeft, containerLogicalWidth , renderView);
3486 computedValues.m_extent = adjustContentBoxLogicalWidthForBoxSizing(v alueForLength(logicalWidth, containerLogicalWidth, renderView)); 3502 computedValues.m_extent = adjustContentBoxLogicalWidthForBoxSizing(v alueForLength(logicalWidth, containerLogicalWidth, renderView));
3487 } 3503 }
3488 } 3504 }
3489 3505
3490 // Use computed values to calculate the horizontal position. 3506 // Use computed values to calculate the horizontal position.
3491 3507
3492 // FIXME: This hack is needed to calculate the logical left position for a 'rtl' relatively 3508 // FIXME: This hack is needed to calculate the logical left position for a 'rtl' relatively
(...skipping 1290 matching lines...) Expand 10 before | Expand all | Expand 10 after
4783 return 0; 4799 return 0;
4784 4800
4785 if (!layoutState && !flowThreadContainingBlock()) 4801 if (!layoutState && !flowThreadContainingBlock())
4786 return 0; 4802 return 0;
4787 4803
4788 RenderBlock* containerBlock = containingBlock(); 4804 RenderBlock* containerBlock = containingBlock();
4789 return containerBlock->offsetFromLogicalTopOfFirstPage() + logicalTop(); 4805 return containerBlock->offsetFromLogicalTopOfFirstPage() + logicalTop();
4790 } 4806 }
4791 4807
4792 } // namespace WebCore 4808 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/rendering/RenderBox.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698