Changeset 155565 in webkit


Ignore:
Timestamp:
Sep 11, 2013 2:29:37 PM (11 years ago)
Author:
zoltan@webkit.org
Message:

Move LineWidth out of RenderBlockLineLayout
https://bugs.webkit.org/show_bug.cgi?id=121107

Reviewed by David Hyatt.

Move LineWidth class and related code into LineWidth.{h,cpp}.

No new tests, no behavior change.

  • CMakeLists.txt:
  • GNUmakefile.list.am:
  • Target.pri:
  • WebCore.vcxproj/WebCore.vcxproj:
  • WebCore.xcodeproj/project.pbxproj:
  • rendering/LineWidth.cpp: Added.

(WebCore::LineWidth::applyOverhang):
(WebCore::LineWidth::fitBelowFloats):

  • rendering/LineWidth.h: Added.

(WebCore::logicalHeightForLine):
(WebCore::LineWidth::LineWidth):
(WebCore::LineWidth::fitsOnLine):
(WebCore::LineWidth::fitsOnLineIncludingExtraWidth):
(WebCore::LineWidth::fitsOnLineExcludingTrailingWhitespace):
(WebCore::LineWidth::currentWidth):
(WebCore::LineWidth::uncommittedWidth):
(WebCore::LineWidth::committedWidth):
(WebCore::LineWidth::availableWidth):
(WebCore::LineWidth::addUncommittedWidth):
(WebCore::LineWidth::commit):
(WebCore::LineWidth::setTrailingWhitespaceWidth):
(WebCore::LineWidth::shouldIndentText):
(WebCore::LineWidth::computeAvailableWidthFromLeftAndRight):
(WebCore::LineWidth::fitsOnLineExcludingTrailingCollapsedWhitespace):
(WebCore::LineWidth::updateAvailableWidth):
(WebCore::LineWidth::shrinkAvailableWidthForNewFloatIfNeeded):

  • rendering/RenderBlockLineLayout.cpp:
Location:
trunk/Source/WebCore
Files:
2 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/CMakeLists.txt

    r155549 r155565  
    21102110    rendering/LayoutState.cpp
    21112111    rendering/LayoutRepainter.cpp
     2112    rendering/LineWidth.cpp
    21122113    rendering/PointerEventsHitRules.cpp
    21132114    rendering/RenderApplet.cpp
  • trunk/Source/WebCore/ChangeLog

    r155559 r155565  
     12013-09-11  Zoltan Horvath  <zoltan@webkit.org>
     2
     3        Move LineWidth out of RenderBlockLineLayout
     4        https://bugs.webkit.org/show_bug.cgi?id=121107
     5
     6        Reviewed by David Hyatt.
     7
     8        Move LineWidth class and related code into LineWidth.{h,cpp}.
     9
     10        No new tests, no behavior change.
     11
     12        * CMakeLists.txt:
     13        * GNUmakefile.list.am:
     14        * Target.pri:
     15        * WebCore.vcxproj/WebCore.vcxproj:
     16        * WebCore.xcodeproj/project.pbxproj:
     17        * rendering/LineWidth.cpp: Added.
     18        (WebCore::LineWidth::applyOverhang):
     19        (WebCore::LineWidth::fitBelowFloats):
     20        * rendering/LineWidth.h: Added.
     21        (WebCore::logicalHeightForLine):
     22        (WebCore::LineWidth::LineWidth):
     23        (WebCore::LineWidth::fitsOnLine):
     24        (WebCore::LineWidth::fitsOnLineIncludingExtraWidth):
     25        (WebCore::LineWidth::fitsOnLineExcludingTrailingWhitespace):
     26        (WebCore::LineWidth::currentWidth):
     27        (WebCore::LineWidth::uncommittedWidth):
     28        (WebCore::LineWidth::committedWidth):
     29        (WebCore::LineWidth::availableWidth):
     30        (WebCore::LineWidth::addUncommittedWidth):
     31        (WebCore::LineWidth::commit):
     32        (WebCore::LineWidth::setTrailingWhitespaceWidth):
     33        (WebCore::LineWidth::shouldIndentText):
     34        (WebCore::LineWidth::computeAvailableWidthFromLeftAndRight):
     35        (WebCore::LineWidth::fitsOnLineExcludingTrailingCollapsedWhitespace):
     36        (WebCore::LineWidth::updateAvailableWidth):
     37        (WebCore::LineWidth::shrinkAvailableWidthForNewFloatIfNeeded):
     38        * rendering/RenderBlockLineLayout.cpp:
     39
    1402013-09-11  Ryosuke Niwa  <rniwa@webkit.org>
    241
  • trunk/Source/WebCore/GNUmakefile.list.am

    r155549 r155565  
    43654365        Source/WebCore/rendering/LayoutRepainter.h \
    43664366        Source/WebCore/rendering/LayoutRepainter.cpp \
     4367        Source/WebCore/rendering/LineWidth.h \
     4368        Source/WebCore/rendering/LineWidth.cpp \
    43674369        Source/WebCore/rendering/OverlapTestRequestClient.h \
    43684370        Source/WebCore/rendering/Pagination.h \
  • trunk/Source/WebCore/Target.pri

    r155549 r155565  
    11511151    rendering/LayoutState.cpp \
    11521152    rendering/LayoutRepainter.cpp \
     1153    rendering/LineWidth.cpp \
    11531154    rendering/RenderApplet.cpp \
    11541155    rendering/RenderArena.cpp \
     
    24052406    rendering/LayoutRepainter.h \
    24062407    rendering/LayoutState.h \
     2408    rendering/LineWidth.h \
    24072409    rendering/LogicalSelectionOffsetCaches.h \
    24082410    rendering/mathml/RenderMathMLBlock.h \
  • trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj

    r155549 r155565  
    96359635      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Production|x64'">true</ExcludedFromBuild>
    96369636    </ClCompile>
     9637    <ClCompile Include="..\rendering\LineWidth.cpp" />
    96379638    <ClCompile Include="..\rendering\PointerEventsHitRules.cpp">
    96389639      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
     
    2000720008    <ClInclude Include="..\rendering\LayoutRepainter.h" />
    2000820009    <ClInclude Include="..\rendering\LayoutState.h" />
     20010    <ClInclude Include="..\rendering\LineWidth.h" />
    2000920011    <ClInclude Include="..\rendering\PaintInfo.h" />
    2001020012    <ClInclude Include="..\rendering\PaintPhase.h" />
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r155549 r155565  
    34213421                A07D3358152B632D001B6393 /* WebGLShaderPrecisionFormat.h in Headers */ = {isa = PBXBuildFile; fileRef = A07D3357152B632D001B6393 /* WebGLShaderPrecisionFormat.h */; };
    34223422                A08CF154152B77B3009C5775 /* WebGLShaderPrecisionFormat.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A08CF153152B77B3009C5775 /* WebGLShaderPrecisionFormat.cpp */; };
     3423                A0CB002417DF82660017896B /* LineWidth.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A0CB002317DF81AC0017896B /* LineWidth.cpp */; };
     3424                A0CB002517DF826C0017896B /* LineWidth.h in Headers */ = {isa = PBXBuildFile; fileRef = A0CB002117DE9CD00017896B /* LineWidth.h */; settings = {ATTRIBUTES = (); }; };
    34233425                A0EE0DF5144F825500F80B0D /* WebGLDebugRendererInfo.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A0EE0DF1144F825500F80B0D /* WebGLDebugRendererInfo.cpp */; };
    34243426                A0EE0DF6144F825500F80B0D /* WebGLDebugRendererInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = A0EE0DF2144F825500F80B0D /* WebGLDebugRendererInfo.h */; };
     
    1001610018                A07D3359152B633E001B6393 /* WebGLShaderPrecisionFormat.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = WebGLShaderPrecisionFormat.idl; path = canvas/WebGLShaderPrecisionFormat.idl; sourceTree = "<group>"; };
    1001710019                A08CF153152B77B3009C5775 /* WebGLShaderPrecisionFormat.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = WebGLShaderPrecisionFormat.cpp; path = canvas/WebGLShaderPrecisionFormat.cpp; sourceTree = "<group>"; };
     10020                A0CB002117DE9CD00017896B /* LineWidth.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LineWidth.h; sourceTree = "<group>"; };
     10021                A0CB002317DF81AC0017896B /* LineWidth.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LineWidth.cpp; sourceTree = "<group>"; };
    1001810022                A0EE0DEF144F823200F80B0D /* WebGLDebugShaders.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = WebGLDebugShaders.idl; path = canvas/WebGLDebugShaders.idl; sourceTree = "<group>"; };
    1001910023                A0EE0DF0144F824300F80B0D /* WebGLDebugRendererInfo.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = WebGLDebugRendererInfo.idl; path = canvas/WebGLDebugRendererInfo.idl; sourceTree = "<group>"; };
     
    2039220396                                2D9066040BE141D400956998 /* LayoutState.cpp */,
    2039320397                                2D9066050BE141D400956998 /* LayoutState.h */,
     20398                                A0CB002317DF81AC0017896B /* LineWidth.cpp */,
     20399                                A0CB002117DE9CD00017896B /* LineWidth.h */,
    2039420400                                9BA273F3172206BB0097CE47 /* LogicalSelectionOffsetCaches.h */,
    2039520401                                3774ABA30FA21EB400AD7DE9 /* OverlapTestRequestClient.h */,
     
    2456124567                                BE16C59517CFE17200852C04 /* InbandWebVTTTextTrack.h in Headers */,
    2456224568                                BC10D76817D8EE71005E2626 /* RenderBlockFlow.h in Headers */,
     24569                                A0CB002517DF826C0017896B /* LineWidth.h in Headers */,
    2456324570                        );
    2456424571                        runOnlyForDeploymentPostprocessing = 0;
     
    2758727594                                BE16C59417CFE17200852C04 /* InbandWebVTTTextTrack.cpp in Sources */,
    2758827595                                BC10D76717D8EE6E005E2626 /* RenderBlockFlow.cpp in Sources */,
     27596                                A0CB002417DF82660017896B /* LineWidth.cpp in Sources */,
    2758927597                        );
    2759027598                        runOnlyForDeploymentPostprocessing = 0;
  • trunk/Source/WebCore/rendering/RenderBlockLineLayout.cpp

    r155554 r155565  
    2929#include "InlineIterator.h"
    3030#include "InlineTextBox.h"
     31#include "LineWidth.h"
    3132#include "Logging.h"
    3233#include "RenderArena.h"
     
    6768const unsigned cMaxLineDepth = 200;
    6869
    69 static LayoutUnit logicalHeightForLine(const RenderBlock* block, bool isFirstLine, LayoutUnit replacedHeight = 0)
    70 {
    71     if (!block->document().inNoQuirksMode() && replacedHeight)
    72         return replacedHeight;
    73 
    74     if (!(block->style(isFirstLine)->lineBoxContain() & LineBoxContainBlock))
    75         return 0;
    76 
    77     return max<LayoutUnit>(replacedHeight, block->lineHeight(isFirstLine, block->isHorizontalWritingMode() ? HorizontalLine : VerticalLine, PositionOfInteriorLineBoxes));
    78 }
    79 
    8070#if ENABLE(CSS_SHAPES)
    8171ShapeInsideInfo* RenderBlock::layoutShapeInsideInfo() const
     
    9484}
    9585#endif
    96 
    97 enum IndentTextOrNot { DoNotIndentText, IndentText };
    98 
    99 class LineWidth {
    100 public:
    101     LineWidth(RenderBlock* block, bool isFirstLine, IndentTextOrNot shouldIndentText)
    102         : m_block(block)
    103         , m_uncommittedWidth(0)
    104         , m_committedWidth(0)
    105         , m_overhangWidth(0)
    106         , m_trailingWhitespaceWidth(0)
    107         , m_trailingCollapsedWhitespaceWidth(0)
    108         , m_left(0)
    109         , m_right(0)
    110         , m_availableWidth(0)
    111 #if ENABLE(CSS_SHAPES)
    112         , m_segment(0)
    113 #endif
    114         , m_isFirstLine(isFirstLine)
    115         , m_shouldIndentText(shouldIndentText)
    116     {
    117         ASSERT(block);
    118 #if ENABLE(CSS_SHAPES)
    119         if (ShapeInsideInfo* shapeInsideInfo = m_block->layoutShapeInsideInfo())
    120             m_segment = shapeInsideInfo->currentSegment();
    121 #endif
    122         updateAvailableWidth();
    123     }
    124     bool fitsOnLine(bool ignoringTrailingSpace = false)
    125     {
    126         return ignoringTrailingSpace ? fitsOnLineExcludingTrailingCollapsedWhitespace() : fitsOnLineIncludingExtraWidth(0);
    127     }
    128     bool fitsOnLineIncludingExtraWidth(float extra) const { return currentWidth() + extra <= m_availableWidth; }
    129     bool fitsOnLineExcludingTrailingWhitespace(float extra) const { return currentWidth() - m_trailingWhitespaceWidth + extra <= m_availableWidth; }
    130 
    131     float currentWidth() const { return m_committedWidth + m_uncommittedWidth; }
    132     // FIXME: We should eventually replace these three functions by ones that work on a higher abstraction.
    133     float uncommittedWidth() const { return m_uncommittedWidth; }
    134     float committedWidth() const { return m_committedWidth; }
    135     float availableWidth() const { return m_availableWidth; }
    136 
    137     void updateAvailableWidth(LayoutUnit minimumHeight = 0);
    138     void shrinkAvailableWidthForNewFloatIfNeeded(FloatingObject*);
    139     void addUncommittedWidth(float delta) { m_uncommittedWidth += delta; }
    140     void commit()
    141     {
    142         m_committedWidth += m_uncommittedWidth;
    143         m_uncommittedWidth = 0;
    144     }
    145     void applyOverhang(RenderRubyRun*, RenderObject* startRenderer, RenderObject* endRenderer);
    146     void fitBelowFloats();
    147     void setTrailingWhitespaceWidth(float collapsedWhitespace, float borderPaddingMargin = 0) { m_trailingCollapsedWhitespaceWidth = collapsedWhitespace; m_trailingWhitespaceWidth =  collapsedWhitespace + borderPaddingMargin; }
    148 
    149     bool shouldIndentText() const { return m_shouldIndentText == IndentText; }
    150 
    151 private:
    152     void computeAvailableWidthFromLeftAndRight()
    153     {
    154         m_availableWidth = max(0.0f, m_right - m_left) + m_overhangWidth;
    155     }
    156     bool fitsOnLineExcludingTrailingCollapsedWhitespace() const { return currentWidth() - m_trailingCollapsedWhitespaceWidth <= m_availableWidth; }
    157 
    158 private:
    159     RenderBlock* m_block;
    160     float m_uncommittedWidth;
    161     float m_committedWidth;
    162     float m_overhangWidth; // The amount by which |m_availableWidth| has been inflated to account for possible contraction due to ruby overhang.
    163     float m_trailingWhitespaceWidth;
    164     float m_trailingCollapsedWhitespaceWidth;
    165     float m_left;
    166     float m_right;
    167     float m_availableWidth;
    168 #if ENABLE(CSS_SHAPES)
    169     const LineSegment* m_segment;
    170 #endif
    171     bool m_isFirstLine;
    172     IndentTextOrNot m_shouldIndentText;
    173 };
    174 
    175 inline void LineWidth::updateAvailableWidth(LayoutUnit replacedHeight)
    176 {
    177     LayoutUnit height = m_block->logicalHeight();
    178     LayoutUnit logicalHeight = logicalHeightForLine(m_block, m_isFirstLine, replacedHeight);
    179     m_left = m_block->logicalLeftOffsetForLine(height, shouldIndentText(), logicalHeight);
    180     m_right = m_block->logicalRightOffsetForLine(height, shouldIndentText(), logicalHeight);
    181 
    182 #if ENABLE(CSS_SHAPES)
    183     if (m_segment) {
    184         m_left = max<float>(m_segment->logicalLeft, m_left);
    185         m_right = min<float>(m_segment->logicalRight, m_right);
    186     }
    187 #endif
    188 
    189     computeAvailableWidthFromLeftAndRight();
    190 }
    191 
    192 inline void LineWidth::shrinkAvailableWidthForNewFloatIfNeeded(FloatingObject* newFloat)
    193 {
    194     LayoutUnit height = m_block->logicalHeight();
    195     if (height < newFloat->logicalTop(m_block->isHorizontalWritingMode()) || height >= newFloat->logicalBottom(m_block->isHorizontalWritingMode()))
    196         return;
    197 
    198 #if ENABLE(CSS_SHAPES)
    199     // When floats with shape outside are stacked, the floats are positioned based on the margin box of the float,
    200     // not the shape's contour. Since we computed the width based on the shape contour when we added the float,
    201     // when we add a subsequent float on the same line, we need to undo the shape delta in order to position
    202     // based on the margin box. In order to do this, we need to walk back through the floating object list to find
    203     // the first previous float that is on the same side as our newFloat.
    204     ShapeOutsideInfo* previousShapeOutsideInfo = 0;
    205     const FloatingObjectSet& floatingObjectSet = m_block->m_floatingObjects->set();
    206     FloatingObjectSetIterator it = floatingObjectSet.end();
    207     FloatingObjectSetIterator begin = floatingObjectSet.begin();
    208     for (--it; it != begin; --it) {
    209         FloatingObject* previousFloat = *it;
    210         if (previousFloat != newFloat && previousFloat->type() == newFloat->type()) {
    211             previousShapeOutsideInfo = previousFloat->renderer()->shapeOutsideInfo();
    212             if (previousShapeOutsideInfo) {
    213                 previousShapeOutsideInfo->computeSegmentsForContainingBlockLine(m_block->logicalHeight(), previousFloat->logicalTop(m_block->isHorizontalWritingMode()), logicalHeightForLine(m_block, m_isFirstLine));
    214             }
    215             break;
    216         }
    217     }
    218 
    219     ShapeOutsideInfo* shapeOutsideInfo = newFloat->renderer()->shapeOutsideInfo();
    220     if (shapeOutsideInfo) {
    221         shapeOutsideInfo->computeSegmentsForContainingBlockLine(m_block->logicalHeight(), newFloat->logicalTop(m_block->isHorizontalWritingMode()), logicalHeightForLine(m_block, m_isFirstLine));
    222     }
    223 #endif
    224 
    225     if (newFloat->type() == FloatingObject::FloatLeft) {
    226         float newLeft = newFloat->logicalRight(m_block->isHorizontalWritingMode());
    227 #if ENABLE(CSS_SHAPES)
    228         if (previousShapeOutsideInfo)
    229             newLeft -= previousShapeOutsideInfo->rightSegmentMarginBoxDelta();
    230         if (shapeOutsideInfo)
    231             newLeft += shapeOutsideInfo->rightSegmentMarginBoxDelta();
    232 #endif
    233 
    234         if (shouldIndentText() && m_block->style()->isLeftToRightDirection())
    235             newLeft += floorToInt(m_block->textIndentOffset());
    236         m_left = max<float>(m_left, newLeft);
    237     } else {
    238         float newRight = newFloat->logicalLeft(m_block->isHorizontalWritingMode());
    239 #if ENABLE(CSS_SHAPES)
    240         if (previousShapeOutsideInfo)
    241             newRight -= previousShapeOutsideInfo->leftSegmentMarginBoxDelta();
    242         if (shapeOutsideInfo)
    243             newRight += shapeOutsideInfo->leftSegmentMarginBoxDelta();
    244 #endif
    245 
    246         if (shouldIndentText() && !m_block->style()->isLeftToRightDirection())
    247             newRight -= floorToInt(m_block->textIndentOffset());
    248         m_right = min<float>(m_right, newRight);
    249     }
    250 
    251     computeAvailableWidthFromLeftAndRight();
    252 }
    253 
    254 void LineWidth::applyOverhang(RenderRubyRun* rubyRun, RenderObject* startRenderer, RenderObject* endRenderer)
    255 {
    256     int startOverhang;
    257     int endOverhang;
    258     rubyRun->getOverhang(m_isFirstLine, startRenderer, endRenderer, startOverhang, endOverhang);
    259 
    260     startOverhang = min<int>(startOverhang, m_committedWidth);
    261     m_availableWidth += startOverhang;
    262 
    263     endOverhang = max(min<int>(endOverhang, m_availableWidth - currentWidth()), 0);
    264     m_availableWidth += endOverhang;
    265     m_overhangWidth += startOverhang + endOverhang;
    266 }
    267 
    268 void LineWidth::fitBelowFloats()
    269 {
    270     ASSERT(!m_committedWidth);
    271     ASSERT(!fitsOnLine());
    272 
    273     LayoutUnit floatLogicalBottom;
    274     LayoutUnit lastFloatLogicalBottom = m_block->logicalHeight();
    275     float newLineWidth = m_availableWidth;
    276     float newLineLeft = m_left;
    277     float newLineRight = m_right;
    278     while (true) {
    279         floatLogicalBottom = m_block->nextFloatLogicalBottomBelow(lastFloatLogicalBottom);
    280         if (floatLogicalBottom <= lastFloatLogicalBottom)
    281             break;
    282 
    283         newLineLeft = m_block->logicalLeftOffsetForLine(floatLogicalBottom, shouldIndentText());
    284         newLineRight = m_block->logicalRightOffsetForLine(floatLogicalBottom, shouldIndentText());
    285         newLineWidth = max(0.0f, newLineRight - newLineLeft);
    286         lastFloatLogicalBottom = floatLogicalBottom;
    287         if (newLineWidth >= m_uncommittedWidth)
    288             break;
    289     }
    290 
    291     if (newLineWidth > m_availableWidth) {
    292         m_block->setLogicalHeight(lastFloatLogicalBottom);
    293         m_availableWidth = newLineWidth + m_overhangWidth;
    294         m_left = newLineLeft;
    295         m_right = newLineRight;
    296     }
    297 }
    29886
    29987class LineInfo {
     
    29292717    LineMidpointState& lineMidpointState = resolver.midpointState();
    29302718
    2931     LineWidth width(m_block, lineInfo.isFirstLine(), requiresIndent(lineInfo.isFirstLine(), lineInfo.previousLineBrokeCleanly(), m_block->style()));
     2719    LineWidth width(*m_block, lineInfo.isFirstLine(), requiresIndent(lineInfo.isFirstLine(), lineInfo.previousLineBrokeCleanly(), m_block->style()));
    29322720
    29332721    skipLeadingWhitespace(resolver, lineInfo, lastFloatFromPreviousLine, width);
Note: See TracChangeset for help on using the changeset viewer.