Home | History | Annotate | Download | only in line
      1 /*
      2  * Copyright (C) 2000 Lars Knoll (knoll (at) kde.org)
      3  * Copyright (C) 2003, 2004, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All right reserved.
      4  * Copyright (C) 2010 Google Inc. All rights reserved.
      5  * Copyright (C) 2014 Adobe Systems Incorporated. All rights reserved.
      6  *
      7  * This library is free software; you can redistribute it and/or
      8  * modify it under the terms of the GNU Library General Public
      9  * License as published by the Free Software Foundation; either
     10  * version 2 of the License, or (at your option) any later version.
     11  *
     12  * This library is distributed in the hope that it will be useful,
     13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     15  * Library General Public License for more details.
     16  *
     17  * You should have received a copy of the GNU Library General Public License
     18  * along with this library; see the file COPYING.LIB.  If not, write to
     19  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
     20  * Boston, MA 02110-1301, USA.
     21  *
     22  */
     23 
     24 #ifndef LineLayoutState_h
     25 #define LineLayoutState_h
     26 
     27 #include "core/rendering/RenderBlockFlow.h"
     28 #include "platform/geometry/LayoutRect.h"
     29 
     30 namespace blink {
     31 
     32 // Like LayoutState for layout(), LineLayoutState keeps track of global information
     33 // during an entire linebox tree layout pass (aka layoutInlineChildren).
     34 class LineLayoutState {
     35 public:
     36     LineLayoutState(bool fullLayout, LayoutUnit& paintInvalidationLogicalTop, LayoutUnit& paintInvalidationLogicalBottom, RenderFlowThread* flowThread)
     37         : m_lastFloat(0)
     38         , m_endLine(0)
     39         , m_floatIndex(0)
     40         , m_endLineLogicalTop(0)
     41         , m_endLineMatched(false)
     42         , m_checkForFloatsFromLastLine(false)
     43         , m_hasInlineChild(false)
     44         , m_isFullLayout(fullLayout)
     45         , m_paintInvalidationLogicalTop(paintInvalidationLogicalTop)
     46         , m_paintInvalidationLogicalBottom(paintInvalidationLogicalBottom)
     47         , m_adjustedLogicalLineTop(0)
     48         , m_usesPaintInvalidationBounds(false)
     49         , m_flowThread(flowThread)
     50     { }
     51 
     52     void markForFullLayout() { m_isFullLayout = true; }
     53     bool isFullLayout() const { return m_isFullLayout; }
     54 
     55     bool usesPaintInvalidationBounds() const { return m_usesPaintInvalidationBounds; }
     56 
     57     void setPaintInvalidationRange(LayoutUnit logicalHeight)
     58     {
     59         m_usesPaintInvalidationBounds = true;
     60         m_paintInvalidationLogicalTop = m_paintInvalidationLogicalBottom = logicalHeight;
     61     }
     62 
     63     void updatePaintInvalidationRangeFromBox(RootInlineBox* box, LayoutUnit paginationDelta = 0)
     64     {
     65         m_usesPaintInvalidationBounds = true;
     66         m_paintInvalidationLogicalTop = std::min(m_paintInvalidationLogicalTop, box->logicalTopVisualOverflow() + std::min<LayoutUnit>(paginationDelta, 0));
     67         m_paintInvalidationLogicalBottom = std::max(m_paintInvalidationLogicalBottom, box->logicalBottomVisualOverflow() + std::max<LayoutUnit>(paginationDelta, 0));
     68     }
     69 
     70     bool endLineMatched() const { return m_endLineMatched; }
     71     void setEndLineMatched(bool endLineMatched) { m_endLineMatched = endLineMatched; }
     72 
     73     bool checkForFloatsFromLastLine() const { return m_checkForFloatsFromLastLine; }
     74     void setCheckForFloatsFromLastLine(bool check) { m_checkForFloatsFromLastLine = check; }
     75 
     76     bool hasInlineChild() const { return m_hasInlineChild; }
     77     void setHasInlineChild(bool hasInlineChild) { m_hasInlineChild = hasInlineChild; }
     78 
     79     LineInfo& lineInfo() { return m_lineInfo; }
     80     const LineInfo& lineInfo() const { return m_lineInfo; }
     81 
     82     LayoutUnit endLineLogicalTop() const { return m_endLineLogicalTop; }
     83     void setEndLineLogicalTop(LayoutUnit logicalTop) { m_endLineLogicalTop = logicalTop; }
     84 
     85     RootInlineBox* endLine() const { return m_endLine; }
     86     void setEndLine(RootInlineBox* line) { m_endLine = line; }
     87 
     88     FloatingObject* lastFloat() const { return m_lastFloat; }
     89     void setLastFloat(FloatingObject* lastFloat) { m_lastFloat = lastFloat; }
     90 
     91     Vector<RenderBlockFlow::FloatWithRect>& floats() { return m_floats; }
     92 
     93     unsigned floatIndex() const { return m_floatIndex; }
     94     void setFloatIndex(unsigned floatIndex) { m_floatIndex = floatIndex; }
     95 
     96     LayoutUnit adjustedLogicalLineTop() const { return m_adjustedLogicalLineTop; }
     97     void setAdjustedLogicalLineTop(LayoutUnit value) { m_adjustedLogicalLineTop = value; }
     98 
     99     RenderFlowThread* flowThread() const { return m_flowThread; }
    100     void setFlowThread(RenderFlowThread* thread) { m_flowThread = thread; }
    101 
    102 private:
    103     Vector<RenderBlockFlow::FloatWithRect> m_floats;
    104     FloatingObject* m_lastFloat;
    105     RootInlineBox* m_endLine;
    106     LineInfo m_lineInfo;
    107     unsigned m_floatIndex;
    108     LayoutUnit m_endLineLogicalTop;
    109     bool m_endLineMatched;
    110     bool m_checkForFloatsFromLastLine;
    111     // Used as a performance optimization to avoid doing a full paint invalidation when our floats
    112     // change but we don't have any inline children.
    113     bool m_hasInlineChild;
    114 
    115     bool m_isFullLayout;
    116 
    117     // FIXME: Should this be a range object instead of two ints?
    118     LayoutUnit& m_paintInvalidationLogicalTop;
    119     LayoutUnit& m_paintInvalidationLogicalBottom;
    120 
    121     LayoutUnit m_adjustedLogicalLineTop;
    122 
    123     bool m_usesPaintInvalidationBounds;
    124 
    125     RenderFlowThread* m_flowThread;
    126 };
    127 
    128 }
    129 
    130 #endif // LineLayoutState_h
    131