Home | History | Annotate | Download | only in rendering
      1 /*
      2  * Copyright (C) 2007 Apple Inc.  All rights reserved.
      3  *
      4  * Redistribution and use in source and binary forms, with or without
      5  * modification, are permitted provided that the following conditions
      6  * are met:
      7  * 1. Redistributions of source code must retain the above copyright
      8  *    notice, this list of conditions and the following disclaimer.
      9  * 2. Redistributions in binary form must reproduce the above copyright
     10  *    notice, this list of conditions and the following disclaimer in the
     11  *    documentation and/or other materials provided with the distribution.
     12  *
     13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
     14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
     17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
     20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
     21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     24  */
     25 
     26 #ifndef LayoutState_h
     27 #define LayoutState_h
     28 
     29 #include "core/rendering/ColumnInfo.h"
     30 #include "platform/geometry/LayoutRect.h"
     31 #include "wtf/HashMap.h"
     32 #include "wtf/Noncopyable.h"
     33 
     34 namespace WebCore {
     35 
     36 class ForceHorriblySlowRectMapping;
     37 class RenderBox;
     38 class RenderObject;
     39 class RenderView;
     40 
     41 class LayoutState {
     42     WTF_MAKE_NONCOPYABLE(LayoutState);
     43 public:
     44     // Constructor for root LayoutState created by RenderView
     45     LayoutState(LayoutUnit pageLogicalHeight, bool pageLogicalHeightChanged, RenderView&);
     46     // Constructor for sub-tree Layout and RenderTableSections
     47     explicit LayoutState(RenderObject& root);
     48 
     49     LayoutState(RenderBox&, const LayoutSize& offset, LayoutUnit pageLogicalHeight = 0, bool pageHeightLogicalChanged = false, ColumnInfo* = 0);
     50 
     51     ~LayoutState();
     52 
     53     void clearPaginationInformation();
     54     bool isPaginatingColumns() const { return m_columnInfo; }
     55     bool isPaginated() const { return m_isPaginated; }
     56     bool isClipped() const { return m_clipped; }
     57 
     58     // The page logical offset is the object's offset from the top of the page in the page progression
     59     // direction (so an x-offset in vertical text and a y-offset for horizontal text).
     60     LayoutUnit pageLogicalOffset(const RenderBox&, const LayoutUnit& childLogicalOffset) const;
     61 
     62     void addForcedColumnBreak(const RenderBox&, const LayoutUnit& childLogicalOffset);
     63 
     64     void addLayoutDelta(const LayoutSize& delta)
     65     {
     66         m_layoutDelta += delta;
     67 #if ASSERT_ENABLED
     68             m_layoutDeltaXSaturated |= m_layoutDelta.width() == LayoutUnit::max() || m_layoutDelta.width() == LayoutUnit::min();
     69             m_layoutDeltaYSaturated |= m_layoutDelta.height() == LayoutUnit::max() || m_layoutDelta.height() == LayoutUnit::min();
     70 #endif
     71     }
     72 
     73     void setColumnInfo(ColumnInfo* columnInfo) { m_columnInfo = columnInfo; }
     74 
     75     const LayoutSize& layoutOffset() const { return m_layoutOffset; }
     76     const LayoutSize& layoutDelta() const { return m_layoutDelta; }
     77     const LayoutSize& pageOffset() const { return m_pageOffset; }
     78     LayoutUnit pageLogicalHeight() const { return m_pageLogicalHeight; }
     79     bool pageLogicalHeightChanged() const { return m_pageLogicalHeightChanged; }
     80 
     81     LayoutState* next() const { return m_next; }
     82 
     83     bool needsBlockDirectionLocationSetBeforeLayout() const { return m_isPaginated && m_pageLogicalHeight; }
     84 
     85     ColumnInfo* columnInfo() const { return m_columnInfo; }
     86 
     87     bool cachedOffsetsEnabled() const { return m_cachedOffsetsEnabled; }
     88 
     89     const LayoutRect& clipRect() const
     90     {
     91         ASSERT(m_cachedOffsetsEnabled);
     92         return m_clipRect;
     93     }
     94     const LayoutSize& paintOffset() const
     95     {
     96         ASSERT(m_cachedOffsetsEnabled);
     97         return m_paintOffset;
     98     }
     99 
    100 
    101     RenderObject& renderer() const { return m_renderer; }
    102 
    103 #if ASSERT_ENABLED
    104     bool layoutDeltaXSaturated() const { return m_layoutDeltaXSaturated; }
    105     bool layoutDeltaYSaturated() const { return m_layoutDeltaYSaturated; }
    106 #endif
    107 
    108 private:
    109     friend class ForceHorriblySlowRectMapping;
    110 
    111     // Do not add anything apart from bitfields until after m_columnInfo. See https://bugs.webkit.org/show_bug.cgi?id=100173
    112     bool m_clipped:1;
    113     bool m_isPaginated:1;
    114     // If our page height has changed, this will force all blocks to relayout.
    115     bool m_pageLogicalHeightChanged:1;
    116 
    117     bool m_cachedOffsetsEnabled:1;
    118 #if ASSERT_ENABLED
    119     bool m_layoutDeltaXSaturated:1;
    120     bool m_layoutDeltaYSaturated:1;
    121 #endif
    122     // If the enclosing pagination model is a column model, then this will store column information for easy retrieval/manipulation.
    123     ColumnInfo* m_columnInfo;
    124     LayoutState* m_next;
    125 
    126     // FIXME: Distinguish between the layout clip rect and the paint clip rect which may be larger,
    127     // e.g., because of composited scrolling.
    128     LayoutRect m_clipRect;
    129 
    130     // x/y offset from container. Includes relative positioning and scroll offsets.
    131     LayoutSize m_paintOffset;
    132     // x/y offset from container. Does not include relative positioning or scroll offsets.
    133     LayoutSize m_layoutOffset;
    134     // Transient offset from the final position of the object
    135     // used to ensure that repaints happen in the correct place.
    136     // This is a total delta accumulated from the root.
    137     LayoutSize m_layoutDelta;
    138 
    139     // The current page height for the pagination model that encloses us.
    140     LayoutUnit m_pageLogicalHeight;
    141     // The offset of the start of the first page in the nearest enclosing pagination model.
    142     LayoutSize m_pageOffset;
    143 
    144     RenderObject& m_renderer;
    145 };
    146 
    147 } // namespace WebCore
    148 
    149 #endif // LayoutState_h
    150