15c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)/*
25c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Copyright (C) 2012 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 COMPUTER, 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
235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) */
255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
265c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#ifndef RenderMultiColumnSet_h
285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#define RenderMultiColumnSet_h
295c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
30f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu#include "core/rendering/RenderMultiColumnFlowThread.h"
31323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles)#include "core/rendering/RenderRegion.h"
3209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)#include "wtf/Vector.h"
335c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
34c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)namespace blink {
355c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
36f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu// RenderMultiColumnSet represents a set of columns that all have the same width and height. By
37f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu// combining runs of same-size columns into a single object, we significantly reduce the number of
38f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu// unique RenderObjects required to represent columns.
395c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)//
40f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu// Column sets are inserted as anonymous children of the actual multicol container (i.e. the
41f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu// renderer whose style computes to non-auto column-count and/or column-width).
425c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)//
43f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu// Being a "region", a column set has no children on its own, but is merely used to slice a portion
44f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu// of the tall "single-column" flow thread into actual columns visually, to convert from flow thread
45f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu// coordinates to visual ones. It is in charge of both positioning columns correctly relatively to
46f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu// the parent multicol container, and to calculate the correct translation for each column's
47f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu// contents, and to paint any rules between them. RenderMultiColumnSet objects are used for
48f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu// painting, hit testing, and any other type of operation that requires mapping from flow thread
49f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu// coordinates to visual coordinates.
50f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu//
51f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu// Column spans result in the creation of new column sets, since a spanning renderer has to be
52f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu// placed in between the column sets that come before and after the span.
53323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles)class RenderMultiColumnSet FINAL : public RenderRegion {
545c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)public:
55d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)    enum BalancedHeightCalculation { GuessFromFlowThreadPortion, StretchBySpaceShortage };
56d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)
57f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu    static RenderMultiColumnSet* createAnonymous(RenderFlowThread*, RenderStyle* parentStyle);
58926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
595c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    virtual bool isRenderMultiColumnSet() const OVERRIDE { return true; }
605c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
61d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)    virtual LayoutUnit pageLogicalWidth() const OVERRIDE FINAL { return flowThread()->logicalWidth(); }
62d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)    virtual LayoutUnit pageLogicalHeight() const OVERRIDE FINAL { return m_columnHeight; }
63d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)
64d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    RenderBlockFlow* multiColumnBlockFlow() const { return toRenderBlockFlow(parent()); }
65f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu    RenderMultiColumnFlowThread* multiColumnFlowThread() const
66f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu    {
67f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu        ASSERT_WITH_SECURITY_IMPLICATION(!flowThread() || flowThread()->isRenderMultiColumnFlowThread());
68f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu        return static_cast<RenderMultiColumnFlowThread*>(flowThread());
69f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu    }
70f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu
71f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu    RenderMultiColumnSet* nextSiblingMultiColumnSet() const;
72d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)    RenderMultiColumnSet* previousSiblingMultiColumnSet() const;
73f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu
74d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)    LayoutUnit logicalTopInFlowThread() const { return isHorizontalWritingMode() ? flowThreadPortionRect().y() : flowThreadPortionRect().x(); }
75323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles)    LayoutUnit logicalBottomInFlowThread() const { return isHorizontalWritingMode() ? flowThreadPortionRect().maxY() : flowThreadPortionRect().maxX(); }
76323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles)
77d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)    LayoutUnit logicalHeightInFlowThread() const { return isHorizontalWritingMode() ? flowThreadPortionRect().height() : flowThreadPortionRect().width(); }
785c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
79d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)    // The used CSS value of column-count, i.e. how many columns there are room for without overflowing.
80d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)    unsigned usedColumnCount() const { return multiColumnFlowThread()->columnCount(); }
81591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch
82f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu    // Find the column that contains the given block offset, and return the translation needed to
83f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu    // get from flow thread coordinates to visual coordinates.
84f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu    LayoutSize flowThreadTranslationAtOffset(LayoutUnit) const;
85f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu
86591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch    LayoutUnit heightAdjustedForSetOffset(LayoutUnit height) const;
875c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
88926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    void updateMinimumColumnHeight(LayoutUnit height) { m_minimumColumnHeight = std::max(height, m_minimumColumnHeight); }
89926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    LayoutUnit minimumColumnHeight() const { return m_minimumColumnHeight; }
90926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
91d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)    // Add a content run, specified by its end position. A content run is appended at every
92d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)    // forced/explicit break and at the end of the column set. The content runs are used to
93d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)    // determine where implicit/soft breaks will occur, in order to calculate an initial column
94d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)    // height.
95d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)    void addContentRun(LayoutUnit endOffsetFromFirstPage);
96926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
97d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)    // (Re-)calculate the column height if it's auto.
98d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)    bool recalculateColumnHeight(BalancedHeightCalculation);
99591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch
100591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch    // Record space shortage (the amount of space that would have been enough to prevent some
101591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch    // element from being moved to the next column) at a column break. The smallest amount of space
102591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch    // shortage we find is the amount with which we will stretch the column height, if it turns out
103591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch    // after layout that the columns weren't tall enough.
104591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch    void recordSpaceShortage(LayoutUnit spaceShortage);
105926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
106d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)    // Reset previously calculated column height. Will mark for layout if needed.
107d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)    void resetColumnHeight();
108591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch
109323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles)    // Expand this set's flow thread portion rectangle to contain all trailing flow thread
110323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles)    // overflow. Only to be called on the last set.
111323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles)    void expandToEncompassFlowThreadContentsIfNeeded();
112323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles)
113197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    void attachRegion();
114197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    void detachRegion();
115926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
116197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    // This method represents the logical height of the entire flow thread portion used by the region or set.
117197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    // For RenderRegions it matches logicalPaginationHeight(), but for sets it is the height of all the pages
118197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    // or columns added together.
119197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    LayoutUnit logicalHeightOfAllFlowThreadContent() const { return logicalHeightInFlowThread(); }
1205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1219e12abdf8c3a23d52091ea54ebb6a04d327f9300Torne (Richard Coles)    void paintInvalidationForFlowThreadContent(const LayoutRect& paintInvalidationRect) const;
122197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch
123197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    // The top of the nearest page inside the region. For RenderRegions, this is just the logical top of the
124197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    // flow thread portion we contain. For sets, we have to figure out the top of the nearest column or
125197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    // page.
126197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    LayoutUnit pageLogicalTopForOffset(LayoutUnit offset) const;
1275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
128197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    void collectLayerFragments(LayerFragments&, const LayoutRect& layerBoundingBox, const LayoutRect& dirtyRect);
12902772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch
1307242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    LayoutUnit columnGap() const;
1317242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci
1327242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    // The "CSS actual" value of column-count. This includes overflowing columns, if any.
1337242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    unsigned actualColumnCount() const;
1347242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci
135197021e6b966cfb06891637935ef33fff06433d1Ben Murdochprivate:
136197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    RenderMultiColumnSet(RenderFlowThread*);
137926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
138197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    virtual void insertedIntoTree() OVERRIDE FINAL;
139197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    virtual void willBeRemovedFromTree() OVERRIDE FINAL;
1405c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
141197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    virtual void computeLogicalHeight(LayoutUnit logicalHeight, LayoutUnit logicalTop, LogicalExtentComputedValues&) const OVERRIDE;
142197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch
143197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    virtual void paintObject(PaintInfo&, const LayoutPoint& paintOffset) OVERRIDE;
144926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
145d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)    virtual void addOverflowFromChildren() OVERRIDE;
146d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)
14709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    virtual const char* renderName() const OVERRIDE;
14802772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch
149d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)    LayoutUnit calculateMaxColumnHeight() const;
1505c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    LayoutRect columnRectAt(unsigned index) const;
151d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)
1525c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1535c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    LayoutRect flowThreadPortionRectAt(unsigned index) const;
154926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    LayoutRect flowThreadPortionOverflowRect(const LayoutRect& flowThreadPortion, unsigned index, unsigned colCount, LayoutUnit colGap) const;
155591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch
156591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch    enum ColumnIndexCalculationMode {
157591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch        ClampToExistingColumns, // Stay within the range of already existing columns.
158591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch        AssumeNewColumns // Allow column indices outside the range of already existing columns.
159591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch    };
160591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch    unsigned columnIndexAtOffset(LayoutUnit, ColumnIndexCalculationMode = ClampToExistingColumns) const;
161591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch
162591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch    void setAndConstrainColumnHeight(LayoutUnit);
163591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch
16409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    // Return the index of the content run with the currently tallest columns, taking all implicit
16509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    // breaks assumed so far into account.
16609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    unsigned findRunWithTallestColumns() const;
16709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
16809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    // Given the current list of content runs, make assumptions about where we need to insert
16909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    // implicit breaks (if there's room for any at all; depending on the number of explicit breaks),
17009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    // and store the results. This is needed in order to balance the columns.
17109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    void distributeImplicitBreaks();
17209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
173d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)    LayoutUnit calculateColumnHeight(BalancedHeightCalculation) const;
17409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
175d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)    LayoutUnit m_columnHeight;
17602772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch
177926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    // The following variables are used when balancing the column set.
178591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch    LayoutUnit m_maxColumnHeight; // Maximum column height allowed.
179591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch    LayoutUnit m_minSpaceShortage; // The smallest amout of space shortage that caused a column break.
180926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    LayoutUnit m_minimumColumnHeight;
18109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
18209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    // A run of content without explicit (forced) breaks; i.e. a flow thread portion between two
18309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    // explicit breaks, between flow thread start and an explicit break, between an explicit break
184d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)    // and flow thread end, or, in cases when there are no explicit breaks at all: between flow
185d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)    // thread portion start and flow thread portion end. We need to know where the explicit breaks
186d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)    // are, in order to figure out where the implicit breaks will end up, so that we get the columns
187d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)    // properly balanced. A content run starts out as representing one single column, and will
188d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)    // represent one additional column for each implicit break "inserted" there.
18909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    class ContentRun {
19009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    public:
19109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        ContentRun(LayoutUnit breakOffset)
19209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)            : m_breakOffset(breakOffset)
19309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)            , m_assumedImplicitBreaks(0) { }
19409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
19509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        unsigned assumedImplicitBreaks() const { return m_assumedImplicitBreaks; }
19609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        void assumeAnotherImplicitBreak() { m_assumedImplicitBreaks++; }
19709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        LayoutUnit breakOffset() const { return m_breakOffset; }
19809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
19909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        // Return the column height that this content run would require, considering the implicit
20009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        // breaks assumed so far.
20143e7502580f146aa5b3db8267ba6dbb5c733a489Torne (Richard Coles)        LayoutUnit columnLogicalHeight(LayoutUnit startOffset) const { return ceilf((m_breakOffset - startOffset).toFloat() / float(m_assumedImplicitBreaks + 1)); }
20209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
20309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    private:
20409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        LayoutUnit m_breakOffset; // Flow thread offset where this run ends.
20509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        unsigned m_assumedImplicitBreaks; // Number of implicit breaks in this run assumed so far.
20609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    };
20709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    Vector<ContentRun, 1> m_contentRuns;
2085c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)};
2095c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
210bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)DEFINE_RENDER_OBJECT_TYPE_CASTS(RenderMultiColumnSet, isRenderMultiColumnSet());
211926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
212c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)} // namespace blink
2135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#endif // RenderMultiColumnSet_h
2155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
216