Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(233)

Side by Side Diff: Source/core/rendering/RenderMultiColumnSet.h

Issue 143383002: Region based multicol: support explicit column breaks (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Code review. Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Apple Inc. All rights reserved. 2 * Copyright (C) 2012 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 10 matching lines...) Expand all
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 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. 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */ 24 */
25 25
26 26
27 #ifndef RenderMultiColumnSet_h 27 #ifndef RenderMultiColumnSet_h
28 #define RenderMultiColumnSet_h 28 #define RenderMultiColumnSet_h
29 29
30 #include "core/rendering/RenderRegionSet.h" 30 #include "core/rendering/RenderRegionSet.h"
31 #include "wtf/Vector.h"
31 32
32 namespace WebCore { 33 namespace WebCore {
33 34
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 // 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 // object, we significantly reduce the number of unique RenderObjects required t o represent columns.
36 // 37 //
37 // A simple multi-column block will have exactly one RenderMultiColumnSet child. A simple paginated multi-column block will have three 38 // 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 // 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 // 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 // as well).
(...skipping 14 matching lines...) Expand all
55 { 56 {
56 m_computedColumnWidth = width; 57 m_computedColumnWidth = width;
57 m_computedColumnCount = count; 58 m_computedColumnCount = count;
58 } 59 }
59 60
60 LayoutUnit heightAdjustedForSetOffset(LayoutUnit height) const; 61 LayoutUnit heightAdjustedForSetOffset(LayoutUnit height) const;
61 62
62 void updateMinimumColumnHeight(LayoutUnit height) { m_minimumColumnHeight = std::max(height, m_minimumColumnHeight); } 63 void updateMinimumColumnHeight(LayoutUnit height) { m_minimumColumnHeight = std::max(height, m_minimumColumnHeight); }
63 LayoutUnit minimumColumnHeight() const { return m_minimumColumnHeight; } 64 LayoutUnit minimumColumnHeight() const { return m_minimumColumnHeight; }
64 65
65 unsigned forcedBreaksCount() const { return m_forcedBreaksCount; } 66 unsigned forcedBreaksCount() const { return m_contentRuns.size(); }
66 LayoutUnit forcedBreakOffset() const { return m_forcedBreakOffset; } 67 void clearForcedBreaks();
67 LayoutUnit maximumDistanceBetweenForcedBreaks() const { return m_maximumDist anceBetweenForcedBreaks; } 68 void addForcedBreak(LayoutUnit offsetFromFirstPage);
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 69
85 // Calculate the column height when contents are supposed to be balanced. If 'initial' is set, 70 // (Re-)calculate the column height when contents are supposed to be balance d. If 'initial' is
86 // guess an initial column height; otherwise, stretch the column height a ta d. Return true if 71 // set, guess an initial column height; otherwise, stretch the column height a tad. Return true
87 // column height changed and another layout pass is required. 72 // if column height changed and another layout pass is required.
88 bool calculateBalancedHeight(bool initial); 73 bool recalculateBalancedHeight(bool initial);
89 74
90 // Record space shortage (the amount of space that would have been enough to prevent some 75 // 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 76 // 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 77 // 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. 78 // after layout that the columns weren't tall enough.
94 void recordSpaceShortage(LayoutUnit spaceShortage); 79 void recordSpaceShortage(LayoutUnit spaceShortage);
95 80
96 virtual void updateLogicalWidth() OVERRIDE; 81 virtual void updateLogicalWidth() OVERRIDE;
97 82
98 void prepareForLayout(); 83 void prepareForLayout();
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 LayoutRect flowThreadPortionOverflowRect(const LayoutRect& flowThreadPortion , unsigned index, unsigned colCount, LayoutUnit colGap) const; 117 LayoutRect flowThreadPortionOverflowRect(const LayoutRect& flowThreadPortion , unsigned index, unsigned colCount, LayoutUnit colGap) const;
133 118
134 enum ColumnIndexCalculationMode { 119 enum ColumnIndexCalculationMode {
135 ClampToExistingColumns, // Stay within the range of already existing col umns. 120 ClampToExistingColumns, // Stay within the range of already existing col umns.
136 AssumeNewColumns // Allow column indices outside the range of already ex isting columns. 121 AssumeNewColumns // Allow column indices outside the range of already ex isting columns.
137 }; 122 };
138 unsigned columnIndexAtOffset(LayoutUnit, ColumnIndexCalculationMode = ClampT oExistingColumns) const; 123 unsigned columnIndexAtOffset(LayoutUnit, ColumnIndexCalculationMode = ClampT oExistingColumns) const;
139 124
140 void setAndConstrainColumnHeight(LayoutUnit); 125 void setAndConstrainColumnHeight(LayoutUnit);
141 126
142 unsigned m_computedColumnCount; 127 // Return the index of the content run with the currently tallest columns, t aking all implicit
143 LayoutUnit m_computedColumnWidth; 128 // breaks assumed so far into account.
129 unsigned findRunWithTallestColumns() const;
130
131 // Given the current list of content runs, make assumptions about where we n eed to insert
132 // implicit breaks (if there's room for any at all; depending on the number of explicit breaks),
133 // and store the results. This is needed in order to balance the columns.
134 void distributeImplicitBreaks();
135
136 LayoutUnit calculateBalancedHeight(bool initial) const;
137
138 unsigned m_computedColumnCount; // Used column count (the resulting 'N' from the pseudo-algorithm in the multicol spec)
139 LayoutUnit m_computedColumnWidth; // Used column width (the resulting 'W' fr om the pseudo-algorithm in the multicol spec)
144 LayoutUnit m_computedColumnHeight; 140 LayoutUnit m_computedColumnHeight;
145 141
146 // The following variables are used when balancing the column set. 142 // The following variables are used when balancing the column set.
147 LayoutUnit m_maxColumnHeight; // Maximum column height allowed. 143 LayoutUnit m_maxColumnHeight; // Maximum column height allowed.
148 LayoutUnit m_minSpaceShortage; // The smallest amout of space shortage that caused a column break. 144 LayoutUnit m_minSpaceShortage; // The smallest amout of space shortage that caused a column break.
149 LayoutUnit m_minimumColumnHeight; 145 LayoutUnit m_minimumColumnHeight;
150 unsigned m_forcedBreaksCount; // FIXME: We will ultimately need to cache mor e information to balance around forced breaks properly. 146
151 LayoutUnit m_maximumDistanceBetweenForcedBreaks; 147 // A run of content without explicit (forced) breaks; i.e. a flow thread por tion between two
152 LayoutUnit m_forcedBreakOffset; 148 // explicit breaks, between flow thread start and an explicit break, between an explicit break
149 // and flow thread end, or, in cases when there are no explicit breaks at al l: between flow flow
150 // thread start and flow thread end. We need to know where the explicit brea ks are, in order to
151 // figure out where the implicit breaks will end up, so that we get the colu mns properly
152 // balanced. A content run starts out as representing one single column, and will represent one
153 // additional column for each implicit break "inserted" there.
154 class ContentRun {
155 public:
156 ContentRun(LayoutUnit breakOffset)
157 : m_breakOffset(breakOffset)
158 , m_assumedImplicitBreaks(0) { }
159
160 unsigned assumedImplicitBreaks() const { return m_assumedImplicitBreaks; }
161 void assumeAnotherImplicitBreak() { m_assumedImplicitBreaks++; }
162 LayoutUnit breakOffset() const { return m_breakOffset; }
163
164 // Return the column height that this content run would require, conside ring the implicit
165 // breaks assumed so far.
166 LayoutUnit columnLogicalHeight(LayoutUnit startOffset) const { return ce ilf(float(m_breakOffset - startOffset) / float(m_assumedImplicitBreaks + 1)); }
167
168 private:
169 LayoutUnit m_breakOffset; // Flow thread offset where this run ends.
170 unsigned m_assumedImplicitBreaks; // Number of implicit breaks in this r un assumed so far.
171 };
172 Vector<ContentRun, 1> m_contentRuns;
153 }; 173 };
154 174
155 DEFINE_RENDER_OBJECT_TYPE_CASTS(RenderMultiColumnSet, isRenderMultiColumnSet()); 175 DEFINE_RENDER_OBJECT_TYPE_CASTS(RenderMultiColumnSet, isRenderMultiColumnSet());
156 176
157 } // namespace WebCore 177 } // namespace WebCore
158 178
159 #endif // RenderMultiColumnSet_h 179 #endif // RenderMultiColumnSet_h
160 180
OLDNEW
« no previous file with comments | « Source/core/rendering/RenderMultiColumnFlowThread.cpp ('k') | Source/core/rendering/RenderMultiColumnSet.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698