Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / rendering / RenderMultiColumnFlowThread.h
index a341db8..3e02d85 100644 (file)
 #define RenderMultiColumnFlowThread_h
 
 #include "core/rendering/RenderFlowThread.h"
+#include "wtf/HashMap.h"
 
-namespace WebCore {
+namespace blink {
 
 class RenderMultiColumnSet;
+class RenderMultiColumnSpannerSet;
 
 // Flow thread implementation for CSS multicol. This will be inserted as an anonymous child block of
 // the actual multicol container (i.e. the RenderBlockFlow whose style computes to non-auto
@@ -50,20 +52,63 @@ class RenderMultiColumnSet;
 // content. Although a RenderMultiColumnFlowThread is laid out, it does not take up any space in its
 // container. It's the RenderMultiColumnSet objects that take up the necessary amount of space, and
 // make sure that the columns are painted and hit-tested correctly.
-class RenderMultiColumnFlowThread FINAL : public RenderFlowThread {
+//
+// If there is any column content inside the multicol container, we create a
+// RenderMultiColumnSet. We only need to create multiple sets if there are spanners
+// (column-span:all) in the multicol container. When a spanner is inserted, content preceding it
+// gets its own set, and content succeeding it will get another set. The spanner itself will also
+// get its own set (RenderMultiColumnSpannerSet).
+//
+// The width of the flow thread is the same as the column width. The width of a column set is the
+// same as the content box width of the multicol container; in other words exactly enough to hold
+// the number of columns to be used, stacked horizontally, plus column gaps between them.
+//
+// Since it's the first child of the multicol container, the flow thread is laid out first, albeit
+// in a slightly special way, since it's not to take up any space in its ancestors. Afterwards, the
+// column sets are laid out. Column sets get their height from the columns that they hold. In single
+// column-row constrained height non-balancing cases without spanners this will simply be the same
+// as the content height of the multicol container itself. In most other cases we'll have to
+// calculate optimal column heights ourselves, though. This process is referred to as column
+// balancing, and then we infer the column set height from the height of the flow thread portion
+// occupied by each set.
+//
+// More on column balancing: the columns' height is unknown in the first layout pass when
+// balancing. This means that we cannot insert any implicit (soft / unforced) breaks (and pagination
+// struts) when laying out the contents of the flow thread. We'll just lay out everything in tall
+// single strip. After the initial flow thread layout pass we can determine a tentative / minimal /
+// initial column height. This is calculated by simply dividing the flow thread's height by the
+// number of specified columns. In the layout pass that follows, we can insert breaks (and
+// pagination struts) at column boundaries, since we now have a column height. It may very easily
+// turn out that the calculated height wasn't enough, though. We'll notice this at end of layout. If
+// we end up with too many columns (i.e. columns overflowing the multicol container), it wasn't
+// enough. In this case we need to increase the column heights. We'll increase them by the lowest
+// amount of space that could possibly affect where the breaks occur (see
+// RenderMultiColumnSet::recordSpaceShortage()). We'll relayout (to find new break points and the
+// new lowest amount of space increase that could affect where they occur, in case we need another
+// round) until we've reached an acceptable height (where everything fits perfectly in the number of
+// columns that we have specified). The rule of thumb is that we shouldn't have to perform more of
+// such iterations than the number of columns that we have.
+//
+// For each layout iteration done for column balancing, the flow thread will need a deep layout if
+// column heights changed in the previous pass, since column height changes may affect break points
+// and pagination struts anywhere in the tree, and currently no way exists to do this in a more
+// optimized manner.
+class RenderMultiColumnFlowThread : public RenderFlowThread {
 public:
     virtual ~RenderMultiColumnFlowThread();
 
     static RenderMultiColumnFlowThread* createAnonymous(Document&, RenderStyle* parentStyle);
 
-    virtual bool isRenderMultiColumnFlowThread() const OVERRIDE FINAL { return true; }
+    virtual bool isRenderMultiColumnFlowThread() const override final { return true; }
 
     RenderBlockFlow* multiColumnBlockFlow() const { return toRenderBlockFlow(parent()); }
 
     RenderMultiColumnSet* firstMultiColumnSet() const;
     RenderMultiColumnSet* lastMultiColumnSet() const;
 
-    virtual void addChild(RenderObject* newChild, RenderObject* beforeChild = 0) OVERRIDE;
+    // Return the spanner set (if any) that contains the specified renderer. This includes the
+    // renderer for the element that actually establishes the spanner too.
+    RenderMultiColumnSpannerSet* containingColumnSpannerSet(const RenderObject* descendant) const;
 
     // Populate the flow thread with what's currently its siblings. Called when a regular block
     // becomes a multicol container.
@@ -75,40 +120,55 @@ public:
     void evacuateAndDestroy();
 
     unsigned columnCount() const { return m_columnCount; }
-    LayoutUnit columnWidth() const { return m_columnWidth; }
     LayoutUnit columnHeightAvailable() const { return m_columnHeightAvailable; }
     void setColumnHeightAvailable(LayoutUnit available) { m_columnHeightAvailable = available; }
-    bool requiresBalancing() const { return !columnHeightAvailable() || multiColumnBlockFlow()->style()->columnFill() == ColumnFillBalance; }
+    virtual bool heightIsAuto() const { return !columnHeightAvailable() || multiColumnBlockFlow()->style()->columnFill() == ColumnFillBalance; }
+    bool progressionIsInline() const { return m_progressionIsInline; }
 
-    virtual LayoutSize columnOffset(const LayoutPoint&) const OVERRIDE FINAL;
+    virtual LayoutSize columnOffset(const LayoutPoint&) const override final;
+
+    // Do we need to set a new width and lay out?
+    virtual bool needsNewWidth() const;
 
     void layoutColumns(bool relayoutChildren, SubtreeLayoutScope&);
-    bool computeColumnCountAndWidth();
+
     bool recalculateColumnHeights();
 
-private:
+protected:
     RenderMultiColumnFlowThread();
+    void setProgressionIsInline(bool isInline) { m_progressionIsInline = isInline; }
 
-    virtual const char* renderName() const OVERRIDE;
-    virtual void addRegionToThread(RenderRegion*) OVERRIDE;
-    virtual void willBeRemovedFromTree() OVERRIDE;
-    virtual void computeLogicalHeight(LayoutUnit logicalHeight, LayoutUnit logicalTop, LogicalExtentComputedValues&) const OVERRIDE;
-    virtual void updateLogicalWidth() OVERRIDE FINAL;
-    virtual void layout() OVERRIDE FINAL;
-    virtual void setPageBreak(LayoutUnit offset, LayoutUnit spaceShortage) OVERRIDE;
-    virtual void updateMinimumPageHeight(LayoutUnit offset, LayoutUnit minHeight) OVERRIDE;
-    virtual RenderRegion* regionAtBlockOffset(LayoutUnit) const OVERRIDE;
-    virtual bool addForcedRegionBreak(LayoutUnit, RenderObject* breakChild, bool isBefore, LayoutUnit* offsetBreakAdjustment = 0) OVERRIDE;
-    virtual bool isPageLogicalHeightKnown() const OVERRIDE;
+    virtual void layout() override;
+
+private:
+    void calculateColumnCountAndWidth(LayoutUnit& width, unsigned& count) const;
+    void createAndInsertMultiColumnSet();
+    void createAndInsertSpannerSet(RenderBox* spanner);
+    virtual bool descendantIsValidColumnSpanner(RenderObject* descendant) const;
+
+    virtual const char* renderName() const override;
+    virtual void addRegionToThread(RenderMultiColumnSet*) override;
+    virtual void willBeRemovedFromTree() override;
+    virtual void flowThreadDescendantWasInserted(RenderObject*) override;
+    virtual void computeLogicalHeight(LayoutUnit logicalHeight, LayoutUnit logicalTop, LogicalExtentComputedValues&) const override;
+    virtual void updateLogicalWidth() override;
+    virtual void setPageBreak(LayoutUnit offset, LayoutUnit spaceShortage) override;
+    virtual void updateMinimumPageHeight(LayoutUnit offset, LayoutUnit minHeight) override;
+    virtual RenderMultiColumnSet* columnSetAtBlockOffset(LayoutUnit) const override;
+    virtual bool addForcedRegionBreak(LayoutUnit, RenderObject* breakChild, bool isBefore, LayoutUnit* offsetBreakAdjustment = 0) override;
+    virtual bool isPageLogicalHeightKnown() const override;
+
+    typedef HashMap<const RenderObject*, RenderMultiColumnSpannerSet*> SpannerMap;
+    SpannerMap m_spannerMap;
 
     unsigned m_columnCount; // The used value of column-count
-    LayoutUnit m_columnWidth; // The used value of column-width
     LayoutUnit m_columnHeightAvailable; // Total height available to columns, or 0 if auto.
     bool m_inBalancingPass; // Set when relayouting for column balancing.
     bool m_needsColumnHeightsRecalculation; // Set when we need to recalculate the column set heights after layout.
+    bool m_progressionIsInline; // Always true for regular multicol. False for paged-y overflow.
 };
 
-} // namespace WebCore
+} // namespace blink
 
 #endif // RenderMultiColumnFlowThread_h