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

Side by Side Diff: third_party/WebKit/Source/core/layout/LayoutBlock.cpp

Issue 1651703002: More explicit LayoutUnit conversions (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@evenMoarConstructors
Patch Set: Traits vs Properties vs Pandas Created 4 years, 10 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 | « no previous file | third_party/WebKit/Source/core/layout/LayoutBlockFlowLine.cpp » ('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) 2007 David Smith (catfish.man@gmail.com) 4 * (C) 2007 David Smith (catfish.man@gmail.com)
5 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved. 5 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved.
6 * Copyright (C) Research In Motion Limited 2010. All rights reserved. 6 * Copyright (C) Research In Motion Limited 2010. All rights reserved.
7 * 7 *
8 * This library is free software; you can redistribute it and/or 8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public 9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either 10 * License as published by the Free Software Foundation; either
(...skipping 1921 matching lines...) Expand 10 before | Expand all | Expand 10 after
1932 1932
1933 int scrollbarWidth = intrinsicScrollbarLogicalWidth(); 1933 int scrollbarWidth = intrinsicScrollbarLogicalWidth();
1934 maxLogicalWidth += scrollbarWidth; 1934 maxLogicalWidth += scrollbarWidth;
1935 minLogicalWidth += scrollbarWidth; 1935 minLogicalWidth += scrollbarWidth;
1936 } 1936 }
1937 1937
1938 void LayoutBlock::computePreferredLogicalWidths() 1938 void LayoutBlock::computePreferredLogicalWidths()
1939 { 1939 {
1940 ASSERT(preferredLogicalWidthsDirty()); 1940 ASSERT(preferredLogicalWidthsDirty());
1941 1941
1942 m_minPreferredLogicalWidth = 0; 1942 m_minPreferredLogicalWidth = LayoutUnit();
1943 m_maxPreferredLogicalWidth = 0; 1943 m_maxPreferredLogicalWidth = LayoutUnit();
1944 1944
1945 // FIXME: The isFixed() calls here should probably be checking for isSpecifi ed since you 1945 // FIXME: The isFixed() calls here should probably be checking for isSpecifi ed since you
1946 // should be able to use percentage, calc or viewport relative values for wi dth. 1946 // should be able to use percentage, calc or viewport relative values for wi dth.
1947 const ComputedStyle& styleToUse = styleRef(); 1947 const ComputedStyle& styleToUse = styleRef();
1948 if (!isTableCell() && styleToUse.logicalWidth().isFixed() && styleToUse.logi calWidth().value() >= 0 1948 if (!isTableCell() && styleToUse.logicalWidth().isFixed() && styleToUse.logi calWidth().value() >= 0
1949 && !(isDeprecatedFlexItem() && !styleToUse.logicalWidth().intValue())) 1949 && !(isDeprecatedFlexItem() && !styleToUse.logicalWidth().intValue()))
1950 m_minPreferredLogicalWidth = m_maxPreferredLogicalWidth = adjustContentB oxLogicalWidthForBoxSizing(styleToUse.logicalWidth().value()); 1950 m_minPreferredLogicalWidth = m_maxPreferredLogicalWidth = adjustContentB oxLogicalWidthForBoxSizing(styleToUse.logicalWidth().value());
1951 else 1951 else
1952 computeIntrinsicLogicalWidths(m_minPreferredLogicalWidth, m_maxPreferred LogicalWidth); 1952 computeIntrinsicLogicalWidths(m_minPreferredLogicalWidth, m_maxPreferred LogicalWidth);
1953 1953
1954 if (styleToUse.logicalMinWidth().isFixed() && styleToUse.logicalMinWidth().v alue() > 0) { 1954 if (styleToUse.logicalMinWidth().isFixed() && styleToUse.logicalMinWidth().v alue() > 0) {
1955 m_maxPreferredLogicalWidth = std::max(m_maxPreferredLogicalWidth, adjust ContentBoxLogicalWidthForBoxSizing(styleToUse.logicalMinWidth().value())); 1955 m_maxPreferredLogicalWidth = std::max(m_maxPreferredLogicalWidth, adjust ContentBoxLogicalWidthForBoxSizing(styleToUse.logicalMinWidth().value()));
1956 m_minPreferredLogicalWidth = std::max(m_minPreferredLogicalWidth, adjust ContentBoxLogicalWidthForBoxSizing(styleToUse.logicalMinWidth().value())); 1956 m_minPreferredLogicalWidth = std::max(m_minPreferredLogicalWidth, adjust ContentBoxLogicalWidthForBoxSizing(styleToUse.logicalMinWidth().value()));
1957 } 1957 }
1958 1958
1959 if (styleToUse.logicalMaxWidth().isFixed()) { 1959 if (styleToUse.logicalMaxWidth().isFixed()) {
1960 m_maxPreferredLogicalWidth = std::min(m_maxPreferredLogicalWidth, adjust ContentBoxLogicalWidthForBoxSizing(styleToUse.logicalMaxWidth().value())); 1960 m_maxPreferredLogicalWidth = std::min(m_maxPreferredLogicalWidth, adjust ContentBoxLogicalWidthForBoxSizing(styleToUse.logicalMaxWidth().value()));
1961 m_minPreferredLogicalWidth = std::min(m_minPreferredLogicalWidth, adjust ContentBoxLogicalWidthForBoxSizing(styleToUse.logicalMaxWidth().value())); 1961 m_minPreferredLogicalWidth = std::min(m_minPreferredLogicalWidth, adjust ContentBoxLogicalWidthForBoxSizing(styleToUse.logicalMaxWidth().value()));
1962 } 1962 }
1963 1963
1964 // Table layout uses integers, ceil the preferred widths to ensure that they can contain the contents. 1964 // Table layout uses integers, ceil the preferred widths to ensure that they can contain the contents.
1965 if (isTableCell()) { 1965 if (isTableCell()) {
1966 m_minPreferredLogicalWidth = m_minPreferredLogicalWidth.ceil(); 1966 m_minPreferredLogicalWidth = LayoutUnit(m_minPreferredLogicalWidth.ceil( ));
1967 m_maxPreferredLogicalWidth = m_maxPreferredLogicalWidth.ceil(); 1967 m_maxPreferredLogicalWidth = LayoutUnit(m_maxPreferredLogicalWidth.ceil( ));
1968 } 1968 }
1969 1969
1970 LayoutUnit borderAndPadding = borderAndPaddingLogicalWidth(); 1970 LayoutUnit borderAndPadding = borderAndPaddingLogicalWidth();
1971 m_minPreferredLogicalWidth += borderAndPadding; 1971 m_minPreferredLogicalWidth += borderAndPadding;
1972 m_maxPreferredLogicalWidth += borderAndPadding; 1972 m_maxPreferredLogicalWidth += borderAndPadding;
1973 1973
1974 clearPreferredLogicalWidthsDirty(); 1974 clearPreferredLogicalWidthsDirty();
1975 } 1975 }
1976 1976
1977 void LayoutBlock::computeBlockPreferredLogicalWidths(LayoutUnit& minLogicalWidth , LayoutUnit& maxLogicalWidth) const 1977 void LayoutBlock::computeBlockPreferredLogicalWidths(LayoutUnit& minLogicalWidth , LayoutUnit& maxLogicalWidth) const
(...skipping 10 matching lines...) Expand all
1988 if (child->isOutOfFlowPositioned() || child->isColumnSpanAll()) { 1988 if (child->isOutOfFlowPositioned() || child->isColumnSpanAll()) {
1989 child = child->nextSibling(); 1989 child = child->nextSibling();
1990 continue; 1990 continue;
1991 } 1991 }
1992 1992
1993 RefPtr<ComputedStyle> childStyle = child->mutableStyle(); 1993 RefPtr<ComputedStyle> childStyle = child->mutableStyle();
1994 if (child->isFloating() || (child->isBox() && toLayoutBox(child)->avoids Floats())) { 1994 if (child->isFloating() || (child->isBox() && toLayoutBox(child)->avoids Floats())) {
1995 LayoutUnit floatTotalWidth = floatLeftWidth + floatRightWidth; 1995 LayoutUnit floatTotalWidth = floatLeftWidth + floatRightWidth;
1996 if (childStyle->clear() & CLEFT) { 1996 if (childStyle->clear() & CLEFT) {
1997 maxLogicalWidth = std::max(floatTotalWidth, maxLogicalWidth); 1997 maxLogicalWidth = std::max(floatTotalWidth, maxLogicalWidth);
1998 floatLeftWidth = 0; 1998 floatLeftWidth = LayoutUnit();
1999 } 1999 }
2000 if (childStyle->clear() & CRIGHT) { 2000 if (childStyle->clear() & CRIGHT) {
2001 maxLogicalWidth = std::max(floatTotalWidth, maxLogicalWidth); 2001 maxLogicalWidth = std::max(floatTotalWidth, maxLogicalWidth);
2002 floatRightWidth = 0; 2002 floatRightWidth = LayoutUnit();
2003 } 2003 }
2004 } 2004 }
2005 2005
2006 // A margin basically has three types: fixed, percentage, and auto (vari able). 2006 // A margin basically has three types: fixed, percentage, and auto (vari able).
2007 // Auto and percentage margins simply become 0 when computing min/max wi dth. 2007 // Auto and percentage margins simply become 0 when computing min/max wi dth.
2008 // Fixed margins can be added in as is. 2008 // Fixed margins can be added in as is.
2009 Length startMarginLength = childStyle->marginStartUsing(&styleToUse); 2009 Length startMarginLength = childStyle->marginStartUsing(&styleToUse);
2010 Length endMarginLength = childStyle->marginEndUsing(&styleToUse); 2010 Length endMarginLength = childStyle->marginEndUsing(&styleToUse);
2011 LayoutUnit margin; 2011 LayoutUnit margin;
2012 LayoutUnit marginStart; 2012 LayoutUnit marginStart;
(...skipping 24 matching lines...) Expand all
2037 bool ltr = containingBlock ? containingBlock->style()->isLeftToR ightDirection() : styleToUse.isLeftToRightDirection(); 2037 bool ltr = containingBlock ? containingBlock->style()->isLeftToR ightDirection() : styleToUse.isLeftToRightDirection();
2038 LayoutUnit marginLogicalLeft = ltr ? marginStart : marginEnd; 2038 LayoutUnit marginLogicalLeft = ltr ? marginStart : marginEnd;
2039 LayoutUnit marginLogicalRight = ltr ? marginEnd : marginStart; 2039 LayoutUnit marginLogicalRight = ltr ? marginEnd : marginStart;
2040 LayoutUnit maxLeft = marginLogicalLeft > 0 ? std::max(floatLeftW idth, marginLogicalLeft) : floatLeftWidth + marginLogicalLeft; 2040 LayoutUnit maxLeft = marginLogicalLeft > 0 ? std::max(floatLeftW idth, marginLogicalLeft) : floatLeftWidth + marginLogicalLeft;
2041 LayoutUnit maxRight = marginLogicalRight > 0 ? std::max(floatRig htWidth, marginLogicalRight) : floatRightWidth + marginLogicalRight; 2041 LayoutUnit maxRight = marginLogicalRight > 0 ? std::max(floatRig htWidth, marginLogicalRight) : floatRightWidth + marginLogicalRight;
2042 w = childMaxPreferredLogicalWidth + maxLeft + maxRight; 2042 w = childMaxPreferredLogicalWidth + maxLeft + maxRight;
2043 w = std::max(w, floatLeftWidth + floatRightWidth); 2043 w = std::max(w, floatLeftWidth + floatRightWidth);
2044 } else { 2044 } else {
2045 maxLogicalWidth = std::max(floatLeftWidth + floatRightWidth, max LogicalWidth); 2045 maxLogicalWidth = std::max(floatLeftWidth + floatRightWidth, max LogicalWidth);
2046 } 2046 }
2047 floatLeftWidth = floatRightWidth = 0; 2047 floatLeftWidth = floatRightWidth = LayoutUnit();
2048 } 2048 }
2049 2049
2050 if (child->isFloating()) { 2050 if (child->isFloating()) {
2051 if (childStyle->floating() == LeftFloat) 2051 if (childStyle->floating() == LeftFloat)
2052 floatLeftWidth += w; 2052 floatLeftWidth += w;
2053 else 2053 else
2054 floatRightWidth += w; 2054 floatRightWidth += w;
2055 } else { 2055 } else {
2056 maxLogicalWidth = std::max(w, maxLogicalWidth); 2056 maxLogicalWidth = std::max(w, maxLogicalWidth);
2057 } 2057 }
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
2113 LayoutUnit LayoutBlock::lineHeight(bool firstLine, LineDirectionMode direction, LinePositionMode linePositionMode) const 2113 LayoutUnit LayoutBlock::lineHeight(bool firstLine, LineDirectionMode direction, LinePositionMode linePositionMode) const
2114 { 2114 {
2115 // Inline blocks are replaced elements. Otherwise, just pass off to 2115 // Inline blocks are replaced elements. Otherwise, just pass off to
2116 // the base class. If we're being queried as though we're the root line 2116 // the base class. If we're being queried as though we're the root line
2117 // box, then the fact that we're an inline-block is irrelevant, and we behav e 2117 // box, then the fact that we're an inline-block is irrelevant, and we behav e
2118 // just like a block. 2118 // just like a block.
2119 if (isAtomicInlineLevel() && linePositionMode == PositionOnContainingLine) 2119 if (isAtomicInlineLevel() && linePositionMode == PositionOnContainingLine)
2120 return LayoutBox::lineHeight(firstLine, direction, linePositionMode); 2120 return LayoutBox::lineHeight(firstLine, direction, linePositionMode);
2121 2121
2122 const ComputedStyle& style = styleRef(firstLine && document().styleEngine(). usesFirstLineRules()); 2122 const ComputedStyle& style = styleRef(firstLine && document().styleEngine(). usesFirstLineRules());
2123 return style.computedLineHeight(); 2123 return LayoutUnit(style.computedLineHeight());
2124 } 2124 }
2125 2125
2126 int LayoutBlock::beforeMarginInLineDirection(LineDirectionMode direction) const 2126 int LayoutBlock::beforeMarginInLineDirection(LineDirectionMode direction) const
2127 { 2127 {
2128 return direction == HorizontalLine ? marginTop() : marginRight(); 2128 return direction == HorizontalLine ? marginTop() : marginRight();
2129 } 2129 }
2130 2130
2131 int LayoutBlock::baselinePosition(FontBaseline baselineType, bool firstLine, Lin eDirectionMode direction, LinePositionMode linePositionMode) const 2131 int LayoutBlock::baselinePosition(FontBaseline baselineType, bool firstLine, Lin eDirectionMode direction, LinePositionMode linePositionMode) const
2132 { 2132 {
2133 // Inline blocks are replaced elements. Otherwise, just pass off to 2133 // Inline blocks are replaced elements. Otherwise, just pass off to
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
2505 // FIXME: This check really isn't accurate. 2505 // FIXME: This check really isn't accurate.
2506 bool nextInlineHasLineBox = inlineElementContinuation->firstLineBox(); 2506 bool nextInlineHasLineBox = inlineElementContinuation->firstLineBox();
2507 // FIXME: This is wrong. The principal layoutObject may not be the conti nuation preceding this block. 2507 // FIXME: This is wrong. The principal layoutObject may not be the conti nuation preceding this block.
2508 // FIXME: This is wrong for vertical writing-modes. 2508 // FIXME: This is wrong for vertical writing-modes.
2509 // https://bugs.webkit.org/show_bug.cgi?id=46781 2509 // https://bugs.webkit.org/show_bug.cgi?id=46781
2510 bool prevInlineHasLineBox = toLayoutInline(inlineElementContinuation->no de()->layoutObject())->firstLineBox(); 2510 bool prevInlineHasLineBox = toLayoutInline(inlineElementContinuation->no de()->layoutObject())->firstLineBox();
2511 LayoutUnit topMargin = prevInlineHasLineBox ? collapsedMarginBefore() : LayoutUnit(); 2511 LayoutUnit topMargin = prevInlineHasLineBox ? collapsedMarginBefore() : LayoutUnit();
2512 LayoutUnit bottomMargin = nextInlineHasLineBox ? collapsedMarginAfter() : LayoutUnit(); 2512 LayoutUnit bottomMargin = nextInlineHasLineBox ? collapsedMarginAfter() : LayoutUnit();
2513 if (topMargin || bottomMargin) { 2513 if (topMargin || bottomMargin) {
2514 LayoutRect rect(additionalOffset, size()); 2514 LayoutRect rect(additionalOffset, size());
2515 rect.expandEdges(topMargin, 0, bottomMargin, 0); 2515 rect.expandEdges(topMargin, LayoutUnit(), bottomMargin, LayoutUnit() );
2516 rects.append(rect); 2516 rects.append(rect);
2517 } 2517 }
2518 } else if (!isAnonymous()) { // For anonymous blocks, the children add outli ne rects. 2518 } else if (!isAnonymous()) { // For anonymous blocks, the children add outli ne rects.
2519 rects.append(LayoutRect(additionalOffset, size())); 2519 rects.append(LayoutRect(additionalOffset, size()));
2520 } 2520 }
2521 2521
2522 if (includeBlockOverflows == IncludeBlockVisualOverflow && !hasOverflowClip( ) && !hasControlClip()) { 2522 if (includeBlockOverflows == IncludeBlockVisualOverflow && !hasOverflowClip( ) && !hasControlClip()) {
2523 for (RootInlineBox* curr = firstRootBox(); curr; curr = curr->nextRootBo x()) { 2523 for (RootInlineBox* curr = firstRootBox(); curr; curr = curr->nextRootBo x()) {
2524 LayoutUnit top = std::max<LayoutUnit>(curr->lineTop(), curr->top()); 2524 LayoutUnit top = std::max<LayoutUnit>(curr->lineTop(), curr->top());
2525 LayoutUnit bottom = std::min<LayoutUnit>(curr->lineBottom(), curr->t op() + curr->height()); 2525 LayoutUnit bottom = std::min<LayoutUnit>(curr->lineBottom(), curr->t op() + curr->height());
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
2858 void LayoutBlock::showLineTreeAndMark(const InlineBox* markedBox1, const char* m arkedLabel1, const InlineBox* markedBox2, const char* markedLabel2, const Layout Object* obj) const 2858 void LayoutBlock::showLineTreeAndMark(const InlineBox* markedBox1, const char* m arkedLabel1, const InlineBox* markedBox2, const char* markedLabel2, const Layout Object* obj) const
2859 { 2859 {
2860 showLayoutObject(); 2860 showLayoutObject();
2861 for (const RootInlineBox* root = firstRootBox(); root; root = root->nextRoot Box()) 2861 for (const RootInlineBox* root = firstRootBox(); root; root = root->nextRoot Box())
2862 root->showLineTreeAndMark(markedBox1, markedLabel1, markedBox2, markedLa bel2, obj, 1); 2862 root->showLineTreeAndMark(markedBox1, markedLabel1, markedBox2, markedLa bel2, obj, 1);
2863 } 2863 }
2864 2864
2865 #endif 2865 #endif
2866 2866
2867 } // namespace blink 2867 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/layout/LayoutBlockFlowLine.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698