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

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

Issue 305883002: Switch arguments to const Length references for performance (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 6 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 | « Source/core/rendering/RenderBox.h ('k') | Source/core/rendering/RenderBoxModelObject.h » ('j') | 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 2265 matching lines...) Expand 10 before | Expand all | Expand 10 after
2276 return fillAvailableMeasure(availableLogicalWidth, marginStart, marginEnd); 2276 return fillAvailableMeasure(availableLogicalWidth, marginStart, marginEnd);
2277 } 2277 }
2278 2278
2279 LayoutUnit RenderBox::fillAvailableMeasure(LayoutUnit availableLogicalWidth, Lay outUnit& marginStart, LayoutUnit& marginEnd) const 2279 LayoutUnit RenderBox::fillAvailableMeasure(LayoutUnit availableLogicalWidth, Lay outUnit& marginStart, LayoutUnit& marginEnd) const
2280 { 2280 {
2281 marginStart = minimumValueForLength(style()->marginStart(), availableLogical Width); 2281 marginStart = minimumValueForLength(style()->marginStart(), availableLogical Width);
2282 marginEnd = minimumValueForLength(style()->marginEnd(), availableLogicalWidt h); 2282 marginEnd = minimumValueForLength(style()->marginEnd(), availableLogicalWidt h);
2283 return availableLogicalWidth - marginStart - marginEnd; 2283 return availableLogicalWidth - marginStart - marginEnd;
2284 } 2284 }
2285 2285
2286 LayoutUnit RenderBox::computeIntrinsicLogicalWidthUsing(Length logicalWidthLengt h, LayoutUnit availableLogicalWidth, LayoutUnit borderAndPadding) const 2286 LayoutUnit RenderBox::computeIntrinsicLogicalWidthUsing(const Length& logicalWid thLength, LayoutUnit availableLogicalWidth, LayoutUnit borderAndPadding) const
2287 { 2287 {
2288 if (logicalWidthLength.type() == FillAvailable) 2288 if (logicalWidthLength.type() == FillAvailable)
2289 return fillAvailableMeasure(availableLogicalWidth); 2289 return fillAvailableMeasure(availableLogicalWidth);
2290 2290
2291 LayoutUnit minLogicalWidth = 0; 2291 LayoutUnit minLogicalWidth = 0;
2292 LayoutUnit maxLogicalWidth = 0; 2292 LayoutUnit maxLogicalWidth = 0;
2293 computeIntrinsicLogicalWidths(minLogicalWidth, maxLogicalWidth); 2293 computeIntrinsicLogicalWidths(minLogicalWidth, maxLogicalWidth);
2294 2294
2295 if (logicalWidthLength.type() == MinContent) 2295 if (logicalWidthLength.type() == MinContent)
2296 return minLogicalWidth + borderAndPadding; 2296 return minLogicalWidth + borderAndPadding;
2297 2297
2298 if (logicalWidthLength.type() == MaxContent) 2298 if (logicalWidthLength.type() == MaxContent)
2299 return maxLogicalWidth + borderAndPadding; 2299 return maxLogicalWidth + borderAndPadding;
2300 2300
2301 if (logicalWidthLength.type() == FitContent) { 2301 if (logicalWidthLength.type() == FitContent) {
2302 minLogicalWidth += borderAndPadding; 2302 minLogicalWidth += borderAndPadding;
2303 maxLogicalWidth += borderAndPadding; 2303 maxLogicalWidth += borderAndPadding;
2304 return max(minLogicalWidth, min(maxLogicalWidth, fillAvailableMeasure(av ailableLogicalWidth))); 2304 return max(minLogicalWidth, min(maxLogicalWidth, fillAvailableMeasure(av ailableLogicalWidth)));
2305 } 2305 }
2306 2306
2307 ASSERT_NOT_REACHED(); 2307 ASSERT_NOT_REACHED();
2308 return 0; 2308 return 0;
2309 } 2309 }
2310 2310
2311 LayoutUnit RenderBox::computeLogicalWidthUsing(SizeType widthType, Length logica lWidth, LayoutUnit availableLogicalWidth, const RenderBlock* cb) const 2311 LayoutUnit RenderBox::computeLogicalWidthUsing(SizeType widthType, const Length& logicalWidth, LayoutUnit availableLogicalWidth, const RenderBlock* cb) const
2312 { 2312 {
2313 if (!logicalWidth.isIntrinsicOrAuto()) { 2313 if (!logicalWidth.isIntrinsicOrAuto()) {
2314 // FIXME: If the containing block flow is perpendicular to our direction we need to use the available logical height instead. 2314 // FIXME: If the containing block flow is perpendicular to our direction we need to use the available logical height instead.
2315 return adjustBorderBoxLogicalWidthForBoxSizing(valueForLength(logicalWid th, availableLogicalWidth)); 2315 return adjustBorderBoxLogicalWidthForBoxSizing(valueForLength(logicalWid th, availableLogicalWidth));
2316 } 2316 }
2317 2317
2318 if (logicalWidth.isIntrinsic()) 2318 if (logicalWidth.isIntrinsic())
2319 return computeIntrinsicLogicalWidthUsing(logicalWidth, availableLogicalW idth, borderAndPaddingLogicalWidth()); 2319 return computeIntrinsicLogicalWidthUsing(logicalWidth, availableLogicalW idth, borderAndPaddingLogicalWidth());
2320 2320
2321 LayoutUnit marginStart = 0; 2321 LayoutUnit marginStart = 0;
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
2630 } 2630 }
2631 2631
2632 LayoutUnit RenderBox::computeContentLogicalHeight(const Length& height, LayoutUn it intrinsicContentHeight) const 2632 LayoutUnit RenderBox::computeContentLogicalHeight(const Length& height, LayoutUn it intrinsicContentHeight) const
2633 { 2633 {
2634 LayoutUnit heightIncludingScrollbar = computeContentAndScrollbarLogicalHeigh tUsing(height, intrinsicContentHeight); 2634 LayoutUnit heightIncludingScrollbar = computeContentAndScrollbarLogicalHeigh tUsing(height, intrinsicContentHeight);
2635 if (heightIncludingScrollbar == -1) 2635 if (heightIncludingScrollbar == -1)
2636 return -1; 2636 return -1;
2637 return std::max<LayoutUnit>(0, adjustContentBoxLogicalHeightForBoxSizing(hei ghtIncludingScrollbar) - scrollbarLogicalHeight()); 2637 return std::max<LayoutUnit>(0, adjustContentBoxLogicalHeightForBoxSizing(hei ghtIncludingScrollbar) - scrollbarLogicalHeight());
2638 } 2638 }
2639 2639
2640 LayoutUnit RenderBox::computeIntrinsicLogicalContentHeightUsing(Length logicalHe ightLength, LayoutUnit intrinsicContentHeight, LayoutUnit borderAndPadding) cons t 2640 LayoutUnit RenderBox::computeIntrinsicLogicalContentHeightUsing(const Length& lo gicalHeightLength, LayoutUnit intrinsicContentHeight, LayoutUnit borderAndPaddin g) const
2641 { 2641 {
2642 // FIXME(cbiesinger): The css-sizing spec is considering changing what min-c ontent/max-content should resolve to. 2642 // FIXME(cbiesinger): The css-sizing spec is considering changing what min-c ontent/max-content should resolve to.
2643 // If that happens, this code will have to change. 2643 // If that happens, this code will have to change.
2644 if (logicalHeightLength.isMinContent() || logicalHeightLength.isMaxContent() || logicalHeightLength.isFitContent()) { 2644 if (logicalHeightLength.isMinContent() || logicalHeightLength.isMaxContent() || logicalHeightLength.isFitContent()) {
2645 if (isReplaced()) 2645 if (isReplaced())
2646 return intrinsicSize().height(); 2646 return intrinsicSize().height();
2647 if (m_intrinsicContentLogicalHeight != -1) 2647 if (m_intrinsicContentLogicalHeight != -1)
2648 return m_intrinsicContentLogicalHeight; 2648 return m_intrinsicContentLogicalHeight;
2649 return intrinsicContentHeight; 2649 return intrinsicContentHeight;
2650 } 2650 }
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
2780 return computeReplacedLogicalWidthRespectingMinMaxWidth(computeReplacedLogic alWidthUsing(style()->logicalWidth()), shouldComputePreferred); 2780 return computeReplacedLogicalWidthRespectingMinMaxWidth(computeReplacedLogic alWidthUsing(style()->logicalWidth()), shouldComputePreferred);
2781 } 2781 }
2782 2782
2783 LayoutUnit RenderBox::computeReplacedLogicalWidthRespectingMinMaxWidth(LayoutUni t logicalWidth, ShouldComputePreferred shouldComputePreferred) const 2783 LayoutUnit RenderBox::computeReplacedLogicalWidthRespectingMinMaxWidth(LayoutUni t logicalWidth, ShouldComputePreferred shouldComputePreferred) const
2784 { 2784 {
2785 LayoutUnit minLogicalWidth = (shouldComputePreferred == ComputePreferred && style()->logicalMinWidth().isPercent()) || style()->logicalMinWidth().isUndefine d() ? logicalWidth : computeReplacedLogicalWidthUsing(style()->logicalMinWidth() ); 2785 LayoutUnit minLogicalWidth = (shouldComputePreferred == ComputePreferred && style()->logicalMinWidth().isPercent()) || style()->logicalMinWidth().isUndefine d() ? logicalWidth : computeReplacedLogicalWidthUsing(style()->logicalMinWidth() );
2786 LayoutUnit maxLogicalWidth = (shouldComputePreferred == ComputePreferred && style()->logicalMaxWidth().isPercent()) || style()->logicalMaxWidth().isUndefine d() ? logicalWidth : computeReplacedLogicalWidthUsing(style()->logicalMaxWidth() ); 2786 LayoutUnit maxLogicalWidth = (shouldComputePreferred == ComputePreferred && style()->logicalMaxWidth().isPercent()) || style()->logicalMaxWidth().isUndefine d() ? logicalWidth : computeReplacedLogicalWidthUsing(style()->logicalMaxWidth() );
2787 return max(minLogicalWidth, min(logicalWidth, maxLogicalWidth)); 2787 return max(minLogicalWidth, min(logicalWidth, maxLogicalWidth));
2788 } 2788 }
2789 2789
2790 LayoutUnit RenderBox::computeReplacedLogicalWidthUsing(Length logicalWidth) cons t 2790 LayoutUnit RenderBox::computeReplacedLogicalWidthUsing(const Length& logicalWidt h) const
2791 { 2791 {
2792 switch (logicalWidth.type()) { 2792 switch (logicalWidth.type()) {
2793 case Fixed: 2793 case Fixed:
2794 return adjustContentBoxLogicalWidthForBoxSizing(logicalWidth.value() ); 2794 return adjustContentBoxLogicalWidthForBoxSizing(logicalWidth.value() );
2795 case MinContent: 2795 case MinContent:
2796 case MaxContent: { 2796 case MaxContent: {
2797 // MinContent/MaxContent don't need the availableLogicalWidth argume nt. 2797 // MinContent/MaxContent don't need the availableLogicalWidth argume nt.
2798 LayoutUnit availableLogicalWidth = 0; 2798 LayoutUnit availableLogicalWidth = 0;
2799 return computeIntrinsicLogicalWidthUsing(logicalWidth, availableLogi calWidth, borderAndPaddingLogicalWidth()) - borderAndPaddingLogicalWidth(); 2799 return computeIntrinsicLogicalWidthUsing(logicalWidth, availableLogi calWidth, borderAndPaddingLogicalWidth()) - borderAndPaddingLogicalWidth();
2800 } 2800 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
2835 return computeReplacedLogicalHeightRespectingMinMaxHeight(computeReplacedLog icalHeightUsing(style()->logicalHeight())); 2835 return computeReplacedLogicalHeightRespectingMinMaxHeight(computeReplacedLog icalHeightUsing(style()->logicalHeight()));
2836 } 2836 }
2837 2837
2838 LayoutUnit RenderBox::computeReplacedLogicalHeightRespectingMinMaxHeight(LayoutU nit logicalHeight) const 2838 LayoutUnit RenderBox::computeReplacedLogicalHeightRespectingMinMaxHeight(LayoutU nit logicalHeight) const
2839 { 2839 {
2840 LayoutUnit minLogicalHeight = computeReplacedLogicalHeightUsing(style()->log icalMinHeight()); 2840 LayoutUnit minLogicalHeight = computeReplacedLogicalHeightUsing(style()->log icalMinHeight());
2841 LayoutUnit maxLogicalHeight = style()->logicalMaxHeight().isUndefined() ? lo gicalHeight : computeReplacedLogicalHeightUsing(style()->logicalMaxHeight()); 2841 LayoutUnit maxLogicalHeight = style()->logicalMaxHeight().isUndefined() ? lo gicalHeight : computeReplacedLogicalHeightUsing(style()->logicalMaxHeight());
2842 return max(minLogicalHeight, min(logicalHeight, maxLogicalHeight)); 2842 return max(minLogicalHeight, min(logicalHeight, maxLogicalHeight));
2843 } 2843 }
2844 2844
2845 LayoutUnit RenderBox::computeReplacedLogicalHeightUsing(Length logicalHeight) co nst 2845 LayoutUnit RenderBox::computeReplacedLogicalHeightUsing(const Length& logicalHei ght) const
2846 { 2846 {
2847 switch (logicalHeight.type()) { 2847 switch (logicalHeight.type()) {
2848 case Fixed: 2848 case Fixed:
2849 return adjustContentBoxLogicalHeightForBoxSizing(logicalHeight.value ()); 2849 return adjustContentBoxLogicalHeightForBoxSizing(logicalHeight.value ());
2850 case Percent: 2850 case Percent:
2851 case Calculated: 2851 case Calculated:
2852 { 2852 {
2853 RenderObject* cb = isOutOfFlowPositioned() ? container() : containin gBlock(); 2853 RenderObject* cb = isOutOfFlowPositioned() ? container() : containin gBlock();
2854 while (cb->isAnonymous()) 2854 while (cb->isAnonymous())
2855 cb = cb->containingBlock(); 2855 cb = cb->containingBlock();
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after
3238 { 3238 {
3239 // FIXME: would it be better to have shrink-to-fit in one step? 3239 // FIXME: would it be better to have shrink-to-fit in one step?
3240 LayoutUnit preferredWidth = maxPreferredLogicalWidth() - bordersPlusPadding; 3240 LayoutUnit preferredWidth = maxPreferredLogicalWidth() - bordersPlusPadding;
3241 LayoutUnit preferredMinWidth = minPreferredLogicalWidth() - bordersPlusPaddi ng; 3241 LayoutUnit preferredMinWidth = minPreferredLogicalWidth() - bordersPlusPaddi ng;
3242 LayoutUnit availableWidth = availableSpace - logicalLeftValue; 3242 LayoutUnit availableWidth = availableSpace - logicalLeftValue;
3243 computedValues.m_extent = min(max(preferredMinWidth, availableWidth), prefer redWidth); 3243 computedValues.m_extent = min(max(preferredMinWidth, availableWidth), prefer redWidth);
3244 } 3244 }
3245 3245
3246 void RenderBox::computePositionedLogicalWidthUsing(Length logicalWidth, const Re nderBoxModelObject* containerBlock, TextDirection containerDirection, 3246 void RenderBox::computePositionedLogicalWidthUsing(Length logicalWidth, const Re nderBoxModelObject* containerBlock, TextDirection containerDirection,
3247 LayoutUnit containerLogicalWi dth, LayoutUnit bordersPlusPadding, 3247 LayoutUnit containerLogicalWi dth, LayoutUnit bordersPlusPadding,
3248 Length logicalLeft, Length lo gicalRight, Length marginLogicalLeft, Length marginLogicalRight, 3248 const Length& logicalLeft, co nst Length& logicalRight, const Length& marginLogicalLeft,
3249 LogicalExtentComputedValues& computedValues) const 3249 const Length& marginLogicalRi ght, LogicalExtentComputedValues& computedValues) const
3250 { 3250 {
3251 if (logicalWidth.isIntrinsic()) 3251 if (logicalWidth.isIntrinsic())
3252 logicalWidth = Length(computeIntrinsicLogicalWidthUsing(logicalWidth, co ntainerLogicalWidth, bordersPlusPadding) - bordersPlusPadding, Fixed); 3252 logicalWidth = Length(computeIntrinsicLogicalWidthUsing(logicalWidth, co ntainerLogicalWidth, bordersPlusPadding) - bordersPlusPadding, Fixed);
3253 3253
3254 // 'left' and 'right' cannot both be 'auto' because one would of been 3254 // 'left' and 'right' cannot both be 'auto' because one would of been
3255 // converted to the static position already 3255 // converted to the static position already
3256 ASSERT(!(logicalLeft.isAuto() && logicalRight.isAuto())); 3256 ASSERT(!(logicalLeft.isAuto() && logicalRight.isAuto()));
3257 3257
3258 LayoutUnit logicalLeftValue = 0; 3258 LayoutUnit logicalLeftValue = 0;
3259 3259
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
3550 } else { 3550 } else {
3551 if (child->isHorizontalWritingMode()) 3551 if (child->isHorizontalWritingMode())
3552 logicalTopPos += containerBlock->borderTop(); 3552 logicalTopPos += containerBlock->borderTop();
3553 else 3553 else
3554 logicalTopPos += containerBlock->borderLeft(); 3554 logicalTopPos += containerBlock->borderLeft();
3555 } 3555 }
3556 } 3556 }
3557 3557
3558 void RenderBox::computePositionedLogicalHeightUsing(Length logicalHeightLength, const RenderBoxModelObject* containerBlock, 3558 void RenderBox::computePositionedLogicalHeightUsing(Length logicalHeightLength, const RenderBoxModelObject* containerBlock,
3559 LayoutUnit containerLogicalH eight, LayoutUnit bordersPlusPadding, LayoutUnit logicalHeight, 3559 LayoutUnit containerLogicalH eight, LayoutUnit bordersPlusPadding, LayoutUnit logicalHeight,
3560 Length logicalTop, Length lo gicalBottom, Length marginBefore, Length marginAfter, 3560 const Length& logicalTop, co nst Length& logicalBottom, const Length& marginBefore,
3561 LogicalExtentComputedValues& computedValues) const 3561 const Length& marginAfter, L ogicalExtentComputedValues& computedValues) const
3562 { 3562 {
3563 // 'top' and 'bottom' cannot both be 'auto' because 'top would of been 3563 // 'top' and 'bottom' cannot both be 'auto' because 'top would of been
3564 // converted to the static position in computePositionedLogicalHeight() 3564 // converted to the static position in computePositionedLogicalHeight()
3565 ASSERT(!(logicalTop.isAuto() && logicalBottom.isAuto())); 3565 ASSERT(!(logicalTop.isAuto() && logicalBottom.isAuto()));
3566 3566
3567 LayoutUnit logicalHeightValue; 3567 LayoutUnit logicalHeightValue;
3568 LayoutUnit contentLogicalHeight = logicalHeight - bordersPlusPadding; 3568 LayoutUnit contentLogicalHeight = logicalHeight - bordersPlusPadding;
3569 3569
3570 const LayoutUnit containerRelativeLogicalWidth = containingBlockLogicalWidth ForPositioned(containerBlock, false); 3570 const LayoutUnit containerRelativeLogicalWidth = containingBlockLogicalWidth ForPositioned(containerBlock, false);
3571 3571
(...skipping 1116 matching lines...) Expand 10 before | Expand all | Expand 10 after
4688 return 0; 4688 return 0;
4689 4689
4690 if (!layoutState && !flowThreadContainingBlock()) 4690 if (!layoutState && !flowThreadContainingBlock())
4691 return 0; 4691 return 0;
4692 4692
4693 RenderBlock* containerBlock = containingBlock(); 4693 RenderBlock* containerBlock = containingBlock();
4694 return containerBlock->offsetFromLogicalTopOfFirstPage() + logicalTop(); 4694 return containerBlock->offsetFromLogicalTopOfFirstPage() + logicalTop();
4695 } 4695 }
4696 4696
4697 } // namespace WebCore 4697 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/rendering/RenderBox.h ('k') | Source/core/rendering/RenderBoxModelObject.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698