15c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)/*
25c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Copyright (C) 2007 Apple Inc.  All rights reserved.
35c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *
45c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Redistribution and use in source and binary forms, with or without
55c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * modification, are permitted provided that the following conditions
65c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * are met:
75c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * 1. Redistributions of source code must retain the above copyright
85c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *    notice, this list of conditions and the following disclaimer.
95c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * 2. Redistributions in binary form must reproduce the above copyright
105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *    notice, this list of conditions and the following disclaimer in the
115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *    documentation and/or other materials provided with the distribution.
125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *
135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2302772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) */
255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
265c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#ifndef LayoutState_h
275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#define LayoutState_h
285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2953e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/rendering/ColumnInfo.h"
301e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)#include "platform/geometry/LayoutRect.h"
3102772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch#include "wtf/HashMap.h"
3202772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch#include "wtf/Noncopyable.h"
335c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
345c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)namespace WebCore {
355c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
3651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)class RenderBlockFlow;
375c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)class RenderBox;
385c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)class RenderObject;
395c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)class RenderFlowThread;
40591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdochclass ShapeInsideInfo;
415c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
425c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)class LayoutState {
435c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    WTF_MAKE_NONCOPYABLE(LayoutState);
445c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)public:
455c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    LayoutState()
465c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        : m_clipped(false)
475c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        , m_isPaginated(false)
485c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        , m_pageLogicalHeightChanged(false)
4953e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#if !ASSERT_DISABLED
505c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        , m_layoutDeltaXSaturated(false)
515c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        , m_layoutDeltaYSaturated(false)
525c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#endif
535c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        , m_columnInfo(0)
545c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        , m_lineGrid(0)
555c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        , m_next(0)
56591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch        , m_shapeInsideInfo(0)
575c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        , m_pageLogicalHeight(0)
585c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#ifndef NDEBUG
595c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        , m_renderer(0)
605c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#endif
615c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    {
625c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
635c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
645c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    LayoutState(LayoutState*, RenderBox*, const LayoutSize& offset, LayoutUnit pageHeight, bool pageHeightChanged, ColumnInfo*);
655c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    LayoutState(RenderObject*);
665c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
67f5e4ad553afbc08dd2e729bb77e937a9a94d5827Torne (Richard Coles)    // LayoutState is allocated out of the rendering partition.
68f5e4ad553afbc08dd2e729bb77e937a9a94d5827Torne (Richard Coles)    void* operator new(size_t);
69f5e4ad553afbc08dd2e729bb77e937a9a94d5827Torne (Richard Coles)    void operator delete(void*);
705c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
715c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    void clearPaginationInformation();
725c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    bool isPaginatingColumns() const { return m_columnInfo && m_columnInfo->paginationUnit() == ColumnInfo::Column; }
735c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    bool isPaginated() const { return m_isPaginated; }
7402772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch
755c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // The page logical offset is the object's offset from the top of the page in the page progression
765c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // direction (so an x-offset in vertical text and a y-offset for horizontal text).
775c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    LayoutUnit pageLogicalOffset(RenderBox*, LayoutUnit childLogicalOffset) const;
785c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
795c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    void addForcedColumnBreak(RenderBox*, LayoutUnit childLogicalOffset);
8002772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch
815c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    LayoutUnit pageLogicalHeight() const { return m_pageLogicalHeight; }
825c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    bool pageLogicalHeightChanged() const { return m_pageLogicalHeightChanged; }
835c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
8451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    RenderBlockFlow* lineGrid() const { return m_lineGrid; }
855c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    LayoutSize lineGridOffset() const { return m_lineGridOffset; }
865c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    LayoutSize lineGridPaginationOrigin() const { return m_lineGridPaginationOrigin; }
875c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
885c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    LayoutSize layoutOffset() const { return m_layoutOffset; }
895c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
905c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    bool needsBlockDirectionLocationSetBeforeLayout() const { return m_lineGrid || (m_isPaginated && m_pageLogicalHeight); }
915c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
92591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch    ShapeInsideInfo* shapeInsideInfo() const { return m_shapeInsideInfo; }
938abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)
948abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)#ifndef NDEBUG
958abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)    RenderObject* renderer() const { return m_renderer; }
968abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)#endif
975c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)private:
985c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    void propagateLineGridInfo(RenderBox*);
9951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    void establishLineGrid(RenderBlockFlow*);
1005c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1015c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    void computeLineGridPaginationOrigin(RenderBox*);
1025c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1035c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)public:
1045c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // Do not add anything apart from bitfields until after m_columnInfo. See https://bugs.webkit.org/show_bug.cgi?id=100173
1055c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    bool m_clipped:1;
1065c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    bool m_isPaginated:1;
1075c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // If our page height has changed, this will force all blocks to relayout.
1085c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    bool m_pageLogicalHeightChanged:1;
10953e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#if !ASSERT_DISABLED
1105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    bool m_layoutDeltaXSaturated:1;
1115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    bool m_layoutDeltaYSaturated:1;
1125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#endif
1135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // If the enclosing pagination model is a column model, then this will store column information for easy retrieval/manipulation.
1145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    ColumnInfo* m_columnInfo;
1155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // The current line grid that we're snapping to and the offset of the start of the grid.
11651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    RenderBlockFlow* m_lineGrid;
1175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    LayoutState* m_next;
118591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch    ShapeInsideInfo* m_shapeInsideInfo;
1195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
120926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    // FIXME: Distinguish between the layout clip rect and the paint clip rect which may be larger,
121926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    // e.g., because of composited scrolling.
1225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    LayoutRect m_clipRect;
12302772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch
1245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // x/y offset from container. Includes relative positioning and scroll offsets.
1255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    LayoutSize m_paintOffset;
1265c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // x/y offset from container. Does not include relative positioning or scroll offsets.
1275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    LayoutSize m_layoutOffset;
1285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // Transient offset from the final position of the object
1295c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // used to ensure that repaints happen in the correct place.
13002772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch    // This is a total delta accumulated from the root.
1315c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    LayoutSize m_layoutDelta;
1325c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1335c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // The current page height for the pagination model that encloses us.
1345c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    LayoutUnit m_pageLogicalHeight;
1355c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // The offset of the start of the first page in the nearest enclosing pagination model.
1365c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    LayoutSize m_pageOffset;
1375c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    LayoutSize m_lineGridOffset;
1385c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    LayoutSize m_lineGridPaginationOrigin;
1395c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1405c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#ifndef NDEBUG
1415c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    RenderObject* m_renderer;
1425c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#endif
1435c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)};
1445c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1455c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)} // namespace WebCore
1465c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1475c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#endif // LayoutState_h
148