| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 2012 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 COMPUTER, 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 | |
| 27 #ifndef RenderMultiColumnSet_h | |
| 28 #define RenderMultiColumnSet_h | |
| 29 | |
| 30 #include "core/rendering/RenderRegionSet.h" | |
| 31 | |
| 32 namespace WebCore { | |
| 33 | |
| 34 // RenderMultiColumnSet represents a set of columns that all have the same width
and height. By combining runs of same-size columns into a single | |
| 35 // object, we significantly reduce the number of unique RenderObjects required t
o represent columns. | |
| 36 // | |
| 37 // A simple multi-column block will have exactly one RenderMultiColumnSet child.
A simple paginated multi-column block will have three | |
| 38 // RenderMultiColumnSet children: one for the content at the bottom of the first
page (whose columns will have a shorter height), one | |
| 39 // for the 2nd to n-1 pages, and then one last column set that will hold the sho
rter columns on the final page (that may have to be balanced | |
| 40 // as well). | |
| 41 // | |
| 42 // Column spans result in the creation of new column sets as well, since a spann
ing region has to be placed in between the column sets that | |
| 43 // come before and after the span. | |
| 44 class RenderMultiColumnSet FINAL : public RenderRegionSet { | |
| 45 public: | |
| 46 static RenderMultiColumnSet* createAnonymous(RenderFlowThread*); | |
| 47 | |
| 48 virtual bool isRenderMultiColumnSet() const OVERRIDE { return true; } | |
| 49 | |
| 50 unsigned computedColumnCount() const { return m_computedColumnCount; } | |
| 51 LayoutUnit computedColumnWidth() const { return m_computedColumnWidth; } | |
| 52 LayoutUnit computedColumnHeight() const { return m_computedColumnHeight; } | |
| 53 | |
| 54 void setComputedColumnWidthAndCount(LayoutUnit width, unsigned count) | |
| 55 { | |
| 56 m_computedColumnWidth = width; | |
| 57 m_computedColumnCount = count; | |
| 58 } | |
| 59 | |
| 60 LayoutUnit heightAdjustedForSetOffset(LayoutUnit height) const; | |
| 61 | |
| 62 void updateMinimumColumnHeight(LayoutUnit height) { m_minimumColumnHeight =
std::max(height, m_minimumColumnHeight); } | |
| 63 LayoutUnit minimumColumnHeight() const { return m_minimumColumnHeight; } | |
| 64 | |
| 65 unsigned forcedBreaksCount() const { return m_forcedBreaksCount; } | |
| 66 LayoutUnit forcedBreakOffset() const { return m_forcedBreakOffset; } | |
| 67 LayoutUnit maximumDistanceBetweenForcedBreaks() const { return m_maximumDist
anceBetweenForcedBreaks; } | |
| 68 void clearForcedBreaks() | |
| 69 { | |
| 70 m_forcedBreaksCount = 0; | |
| 71 m_maximumDistanceBetweenForcedBreaks = 0; | |
| 72 m_forcedBreakOffset = 0; | |
| 73 } | |
| 74 void addForcedBreak(LayoutUnit offsetFromFirstPage) | |
| 75 { | |
| 76 ASSERT(!computedColumnHeight()); | |
| 77 LayoutUnit distanceFromLastBreak = offsetFromFirstPage - m_forcedBreakOf
fset; | |
| 78 if (!distanceFromLastBreak) | |
| 79 return; | |
| 80 m_forcedBreaksCount++; | |
| 81 m_maximumDistanceBetweenForcedBreaks = std::max(m_maximumDistanceBetween
ForcedBreaks, distanceFromLastBreak); | |
| 82 m_forcedBreakOffset = offsetFromFirstPage; | |
| 83 } | |
| 84 | |
| 85 // Calculate the column height when contents are supposed to be balanced. If
'initial' is set, | |
| 86 // guess an initial column height; otherwise, stretch the column height a ta
d. Return true if | |
| 87 // column height changed and another layout pass is required. | |
| 88 bool calculateBalancedHeight(bool initial); | |
| 89 | |
| 90 // Record space shortage (the amount of space that would have been enough to
prevent some | |
| 91 // element from being moved to the next column) at a column break. The small
est amount of space | |
| 92 // shortage we find is the amount with which we will stretch the column heig
ht, if it turns out | |
| 93 // after layout that the columns weren't tall enough. | |
| 94 void recordSpaceShortage(LayoutUnit spaceShortage); | |
| 95 | |
| 96 virtual void updateLogicalWidth() OVERRIDE; | |
| 97 | |
| 98 void prepareForLayout(); | |
| 99 | |
| 100 private: | |
| 101 RenderMultiColumnSet(RenderFlowThread*); | |
| 102 | |
| 103 virtual void computeLogicalHeight(LayoutUnit logicalHeight, LayoutUnit logic
alTop, LogicalExtentComputedValues&) const OVERRIDE; | |
| 104 | |
| 105 virtual void paintObject(PaintInfo&, const LayoutPoint& paintOffset) OVERRID
E; | |
| 106 | |
| 107 virtual LayoutUnit pageLogicalWidth() const OVERRIDE { return m_computedColu
mnWidth; } | |
| 108 virtual LayoutUnit pageLogicalHeight() const OVERRIDE { return m_computedCol
umnHeight; } | |
| 109 | |
| 110 virtual LayoutUnit pageLogicalTopForOffset(LayoutUnit offset) const OVERRIDE
; | |
| 111 | |
| 112 // FIXME: This will change once we have column sets constrained by enclosing
pages, etc. | |
| 113 virtual LayoutUnit logicalHeightOfAllFlowThreadContent() const OVERRIDE { re
turn m_computedColumnHeight; } | |
| 114 | |
| 115 // FIXME: For now we return false, but it's likely we will leverage the auto
height region code to do column | |
| 116 // balancing. That's why we have an override of this function that is distin
ct from RenderRegionSet's override. | |
| 117 virtual bool shouldHaveAutoLogicalHeight() const OVERRIDE { return false; } | |
| 118 | |
| 119 virtual void repaintFlowThreadContent(const LayoutRect& repaintRect) const O
VERRIDE; | |
| 120 | |
| 121 virtual void collectLayerFragments(LayerFragments&, const LayoutRect& layerB
oundingBox, const LayoutRect& dirtyRect) OVERRIDE; | |
| 122 | |
| 123 virtual const char* renderName() const OVERRIDE; | |
| 124 | |
| 125 void paintColumnRules(PaintInfo&, const LayoutPoint& paintOffset); | |
| 126 | |
| 127 LayoutUnit columnGap() const; | |
| 128 LayoutRect columnRectAt(unsigned index) const; | |
| 129 unsigned columnCount() const; | |
| 130 | |
| 131 LayoutRect flowThreadPortionRectAt(unsigned index) const; | |
| 132 LayoutRect flowThreadPortionOverflowRect(const LayoutRect& flowThreadPortion
, unsigned index, unsigned colCount, LayoutUnit colGap) const; | |
| 133 | |
| 134 enum ColumnIndexCalculationMode { | |
| 135 ClampToExistingColumns, // Stay within the range of already existing col
umns. | |
| 136 AssumeNewColumns // Allow column indices outside the range of already ex
isting columns. | |
| 137 }; | |
| 138 unsigned columnIndexAtOffset(LayoutUnit, ColumnIndexCalculationMode = ClampT
oExistingColumns) const; | |
| 139 | |
| 140 void setAndConstrainColumnHeight(LayoutUnit); | |
| 141 | |
| 142 unsigned m_computedColumnCount; | |
| 143 LayoutUnit m_computedColumnWidth; | |
| 144 LayoutUnit m_computedColumnHeight; | |
| 145 | |
| 146 // The following variables are used when balancing the column set. | |
| 147 LayoutUnit m_maxColumnHeight; // Maximum column height allowed. | |
| 148 LayoutUnit m_minSpaceShortage; // The smallest amout of space shortage that
caused a column break. | |
| 149 LayoutUnit m_minimumColumnHeight; | |
| 150 unsigned m_forcedBreaksCount; // FIXME: We will ultimately need to cache mor
e information to balance around forced breaks properly. | |
| 151 LayoutUnit m_maximumDistanceBetweenForcedBreaks; | |
| 152 LayoutUnit m_forcedBreakOffset; | |
| 153 }; | |
| 154 | |
| 155 DEFINE_RENDER_OBJECT_TYPE_CASTS(RenderMultiColumnSet, isRenderMultiColumnSet()); | |
| 156 | |
| 157 } // namespace WebCore | |
| 158 | |
| 159 #endif // RenderMultiColumnSet_h | |
| 160 | |
| OLD | NEW |