Changeset 38227 in webkit


Ignore:
Timestamp:
Nov 7, 2008 11:17:08 AM (15 years ago)
Author:
Simon Fraser
Message:

2008-11-07 Simon Fraser <Simon Fraser>

Reviewed by Dan Bernstein

https://bugs.webkit.org/show_bug.cgi?id=22122

Use a stack-based object to simplify the pushLayoutState/popLayoutState
code. LayoutStateMaintainer either pushes in the constructor, or allows
an explicit push() later. Both cases require an explicit pop().

  • rendering/RenderBlock.cpp: (WebCore::RenderBlock::layoutBlock): (WebCore::RenderBlock::layoutOnlyPositionedObjects):
  • rendering/RenderContainer.cpp: (WebCore::RenderContainer::layout):
  • rendering/RenderFlexibleBox.cpp: (WebCore::RenderFlexibleBox::layoutBlock):
  • rendering/RenderTable.cpp: (WebCore::RenderTable::layout):
  • rendering/RenderTableRow.cpp: (WebCore::RenderTableRow::layout):
  • rendering/RenderTableSection.cpp: (WebCore::RenderTableSection::setCellWidths): (WebCore::RenderTableSection::calcRowHeight): (WebCore::RenderTableSection::layoutRows):
  • rendering/RenderView.h: (WebCore::LayoutStateMaintainer::LayoutStateMaintainer): (WebCore::LayoutStateMaintainer::~LayoutStateMaintainer): (WebCore::LayoutStateMaintainer::pop): (WebCore::LayoutStateMaintainer::push): (WebCore::LayoutStateMaintainer::didPush):
Location:
trunk/WebCore
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r38224 r38227  
     12008-11-07  Simon Fraser  <simon.fraser@apple.com>
     2
     3        Reviewed by Dan Bernstein
     4
     5        https://bugs.webkit.org/show_bug.cgi?id=22122
     6       
     7        Use a stack-based object to simplify the pushLayoutState/popLayoutState
     8        code. LayoutStateMaintainer either pushes in the constructor, or allows
     9        an explicit push() later. Both cases require an explicit pop().
     10
     11        * rendering/RenderBlock.cpp:
     12        (WebCore::RenderBlock::layoutBlock):
     13        (WebCore::RenderBlock::layoutOnlyPositionedObjects):
     14        * rendering/RenderContainer.cpp:
     15        (WebCore::RenderContainer::layout):
     16        * rendering/RenderFlexibleBox.cpp:
     17        (WebCore::RenderFlexibleBox::layoutBlock):
     18        * rendering/RenderTable.cpp:
     19        (WebCore::RenderTable::layout):
     20        * rendering/RenderTableRow.cpp:
     21        (WebCore::RenderTableRow::layout):
     22        * rendering/RenderTableSection.cpp:
     23        (WebCore::RenderTableSection::setCellWidths):
     24        (WebCore::RenderTableSection::calcRowHeight):
     25        (WebCore::RenderTableSection::layoutRows):
     26        * rendering/RenderView.h:
     27        (WebCore::LayoutStateMaintainer::LayoutStateMaintainer):
     28        (WebCore::LayoutStateMaintainer::~LayoutStateMaintainer):
     29        (WebCore::LayoutStateMaintainer::pop):
     30        (WebCore::LayoutStateMaintainer::push):
     31        (WebCore::LayoutStateMaintainer::didPush):
     32
    1332008-11-07  Tor Arne Vestbø  <tavestbo@trolltech.com>
    234
  • trunk/WebCore/rendering/RenderBlock.cpp

    r38207 r38227  
    593593    }
    594594
    595     bool hadColumns = m_hasColumns;
    596     if (!hadColumns && !hasReflection())
    597         view()->pushLayoutState(this, IntSize(xPos(), yPos()));
    598     else
    599         view()->disableLayoutState();
     595    LayoutStateMaintainer statePusher(view(), this, IntSize(xPos(), yPos()), !m_hasColumns && !hasReflection());
    600596
    601597    int oldWidth = m_width;
     
    726722    }
    727723
    728     if (!hadColumns && !hasReflection())
    729         view()->popLayoutState();
    730     else
    731         view()->enableLayoutState();
     724    statePusher.pop();
    732725
    733726    // Update our scroll information if we're overflow:auto/scroll/hidden now that we know if
     
    13951388        return false;
    13961389
    1397     if (!m_hasColumns)
    1398         view()->pushLayoutState(this, IntSize(xPos(), yPos()));
    1399     else
    1400         view()->disableLayoutState();
     1390    LayoutStateMaintainer statePusher(view(), this, IntSize(xPos(), yPos()), !m_hasColumns);
    14011391
    14021392    if (needsPositionedMovementLayout()) {
     
    14091399    layoutPositionedObjects(false);
    14101400
    1411     if (!m_hasColumns)
    1412         view()->popLayoutState();
    1413     else
    1414         view()->enableLayoutState();
     1401    statePusher.pop();
    14151402
    14161403    if (hasOverflowClip())
  • trunk/WebCore/rendering/RenderContainer.cpp

    r38098 r38227  
    521521    ASSERT(needsLayout());
    522522
    523     view()->pushLayoutState(this, IntSize(m_x, m_y));
     523    LayoutStateMaintainer statePusher(view(), this, IntSize(m_x, m_y));
    524524
    525525    RenderObject* child = m_firstChild;
     
    530530    }
    531531
    532     view()->popLayoutState();
     532    statePusher.pop();
    533533    setNeedsLayout(false);
    534534}
  • trunk/WebCore/rendering/RenderFlexibleBox.cpp

    r38207 r38227  
    220220    }
    221221
    222     if (!hasReflection())
    223         view()->pushLayoutState(this, IntSize(m_x, m_y));
    224     else
    225         view()->disableLayoutState();
     222    LayoutStateMaintainer statePusher(view(), this, IntSize(m_x, m_y), !hasReflection());
    226223
    227224    int previousWidth = m_width;
     
    309306    }
    310307
    311     if (!hasReflection())
    312         view()->popLayoutState();
    313     else
    314         view()->enableLayoutState();
     308    statePusher.pop();
    315309
    316310    // Update our scrollbars if we're overflow:auto/scroll/hidden now that we know if
  • trunk/WebCore/rendering/RenderTable.cpp

    r37637 r38227  
    266266    }
    267267   
    268     view()->pushLayoutState(this, IntSize(m_x, m_y));
     268    LayoutStateMaintainer statePusher(view(), this, IntSize(m_x, m_y));
    269269
    270270    m_height = 0;
     
    426426    }
    427427
    428     view()->popLayoutState();
     428    statePusher.pop();
    429429
    430430    bool didFullRepaint = true;
  • trunk/WebCore/rendering/RenderTableRow.cpp

    r37637 r38227  
    125125
    126126    // Table rows do not add translation.
    127     view()->pushLayoutState(this, IntSize());
     127    LayoutStateMaintainer statePusher(view(), this, IntSize());
    128128
    129129    for (RenderObject* child = firstChild(); child; child = child->nextSibling()) {
     
    149149    }
    150150
    151     view()->popLayoutState();
     151    statePusher.pop();
    152152    setNeedsLayout(false);
    153153}
  • trunk/WebCore/rendering/RenderTableSection.cpp

    r37637 r38227  
    258258{
    259259    Vector<int>& columnPos = table()->columnPositions();
    260     bool pushedLayoutState = false;
    261 
     260
     261    LayoutStateMaintainer statePusher(view());
     262   
    262263    for (int i = 0; i < m_gridRows; i++) {
    263264        Row& row = *m_grid[i].row;
     
    280281                cell->setNeedsLayout(true);
    281282                if (!table()->selfNeedsLayout() && cell->checkForRepaintDuringLayout()) {
    282                     if (!pushedLayoutState) {
     283                    if (!statePusher.didPush()) {
    283284                        // Technically, we should also push state for the row, but since
    284285                        // rows don't push a coordinate transform, that's not necessary.
    285                         view()->pushLayoutState(this, IntSize(m_x, m_y));
    286                         pushedLayoutState = true;
     286                        statePusher.push(this, IntSize(m_x, m_y));
    287287                    }
    288288                    cell->repaint();
     
    293293    }
    294294   
    295     if (pushedLayoutState)
    296         view()->popLayoutState();
     295    statePusher.pop();  // only pops if we pushed
    297296}
    298297
     
    302301
    303302    int spacing = table()->vBorderSpacing();
    304     bool pushedLayoutState = false;
     303
     304    LayoutStateMaintainer statePusher(view());
    305305
    306306    m_rowPos.resize(m_gridRows + 1);
     
    331331
    332332            if (cell->overrideSize() != -1) {
    333                 if (!pushedLayoutState) {
     333                if (!statePusher.didPush()) {
    334334                    // Technically, we should also push state for the row, but since
    335335                    // rows don't push a coordinate transform, that's not necessary.
    336                     view()->pushLayoutState(this, IntSize(m_x, m_y));
    337                     pushedLayoutState = true;
     336                    statePusher.push(this, IntSize(m_x, m_y));
    338337                }
    339338                cell->setOverrideSize(-1);
     
    374373    }
    375374
    376     if (pushedLayoutState)
    377         view()->popLayoutState();
     375    statePusher.pop();
    378376
    379377    return m_rowPos[m_gridRows];
     
    457455    int nEffCols = table()->numEffCols();
    458456
    459     view()->pushLayoutState(this, IntSize(m_x, m_y));
     457    LayoutStateMaintainer statePusher(view(), this, IntSize(m_x, m_y));
    460458
    461459    for (int r = 0; r < totalRows; r++) {
     
    576574    }
    577575
    578     view()->popLayoutState();
     576    statePusher.pop();
    579577
    580578    m_height = m_rowPos[totalRows];
  • trunk/WebCore/rendering/RenderView.h

    r38186 r38227  
    158158};
    159159
     160// Stack-based class to assist with LayoutState push/pop
     161class LayoutStateMaintainer : Noncopyable {
     162public:
     163    // ctor to push now
     164    LayoutStateMaintainer(RenderView* view, RenderBox* root, IntSize offset, bool shouldPush = true)
     165        : m_view(view)
     166        , m_shouldPushPop(shouldPush)
     167        , m_didStart(false)
     168        , m_didEnd(false)
     169    {
     170        push(root, offset);
     171    }
     172   
     173    // ctor to maybe push later
     174    LayoutStateMaintainer(RenderView* view)
     175        : m_view(view)
     176        , m_shouldPushPop(true)
     177        , m_didStart(false)
     178        , m_didEnd(false)
     179    {
     180    }
     181   
     182    ~LayoutStateMaintainer()
     183    {
     184        ASSERT(m_didStart == m_didEnd);   // if this fires, it means that someone did a push(), but forgot to pop().
     185    }
     186
     187    void pop()
     188    {
     189        if (m_didStart) {
     190            ASSERT(!m_didEnd);
     191            if (m_shouldPushPop)
     192                m_view->popLayoutState();
     193            else
     194                m_view->enableLayoutState();
     195            m_didEnd = true;
     196        }
     197    }
     198
     199    void push(RenderBox* root, IntSize offset)
     200    {
     201        ASSERT(!m_didStart);
     202        if (m_shouldPushPop)
     203            m_view->pushLayoutState(root, offset);
     204        else
     205            m_view->disableLayoutState();
     206        m_didStart = true;
     207    }
     208   
     209    bool didPush() const { return m_didStart; }
     210
     211private:
     212    RenderView* m_view;
     213    bool m_shouldPushPop : 1;   // true if we should push/pop, rather than disable/enable
     214    bool m_didStart : 1;        // true if we did a push or disable
     215    bool m_didEnd : 1;          // true if we popped or re-enabled
     216};
     217
    160218} // namespace WebCore
    161219
Note: See TracChangeset for help on using the changeset viewer.