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

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

Issue 288263002: [New Multicolumn] Rebalance properly when child content changes. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: code review Created 6 years, 7 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 // coordinates to visual ones. It is in charge of both positioning columns corre ctly relatively to 45 // coordinates to visual ones. It is in charge of both positioning columns corre ctly relatively to
46 // the parent multicol container, and to calculate the correct translation for e ach column's 46 // the parent multicol container, and to calculate the correct translation for e ach column's
47 // contents, and to paint any rules between them. RenderMultiColumnSet objects a re used for 47 // contents, and to paint any rules between them. RenderMultiColumnSet objects a re used for
48 // painting, hit testing, and any other type of operation that requires mapping from flow thread 48 // painting, hit testing, and any other type of operation that requires mapping from flow thread
49 // coordinates to visual coordinates. 49 // coordinates to visual coordinates.
50 // 50 //
51 // Column spans result in the creation of new column sets, since a spanning rend erer has to be 51 // Column spans result in the creation of new column sets, since a spanning rend erer has to be
52 // placed in between the column sets that come before and after the span. 52 // placed in between the column sets that come before and after the span.
53 class RenderMultiColumnSet FINAL : public RenderRegion { 53 class RenderMultiColumnSet FINAL : public RenderRegion {
54 public: 54 public:
55 enum BalancedHeightCalculation { GuessFromFlowThreadPortion, StretchBySpaceS hortage };
56
55 static RenderMultiColumnSet* createAnonymous(RenderFlowThread*, RenderStyle* parentStyle); 57 static RenderMultiColumnSet* createAnonymous(RenderFlowThread*, RenderStyle* parentStyle);
56 58
57 virtual bool isRenderMultiColumnSet() const OVERRIDE { return true; } 59 virtual bool isRenderMultiColumnSet() const OVERRIDE { return true; }
58 60
59 RenderBlockFlow* multiColumnBlockFlow() const { return toRenderBlockFlow(par ent()); } 61 RenderBlockFlow* multiColumnBlockFlow() const { return toRenderBlockFlow(par ent()); }
60 RenderMultiColumnFlowThread* multiColumnFlowThread() const 62 RenderMultiColumnFlowThread* multiColumnFlowThread() const
61 { 63 {
62 ASSERT_WITH_SECURITY_IMPLICATION(!flowThread() || flowThread()->isRender MultiColumnFlowThread()); 64 ASSERT_WITH_SECURITY_IMPLICATION(!flowThread() || flowThread()->isRender MultiColumnFlowThread());
63 return static_cast<RenderMultiColumnFlowThread*>(flowThread()); 65 return static_cast<RenderMultiColumnFlowThread*>(flowThread());
64 } 66 }
65 67
66 RenderMultiColumnSet* nextSiblingMultiColumnSet() const; 68 RenderMultiColumnSet* nextSiblingMultiColumnSet() const;
69 RenderMultiColumnSet* previousSiblingMultiColumnSet() const;
67 70
68 LayoutUnit logicalTopInFlowThread() const { return isHorizontalWritingMode() ? flowThreadPortionRect().y() : flowThreadPortionRect().x(); } 71 LayoutUnit logicalTopInFlowThread() const { return isHorizontalWritingMode() ? flowThreadPortionRect().y() : flowThreadPortionRect().x(); }
69 LayoutUnit logicalBottomInFlowThread() const { return isHorizontalWritingMod e() ? flowThreadPortionRect().maxY() : flowThreadPortionRect().maxX(); } 72 LayoutUnit logicalBottomInFlowThread() const { return isHorizontalWritingMod e() ? flowThreadPortionRect().maxY() : flowThreadPortionRect().maxX(); }
70 73
71 LayoutUnit logicalHeightInFlowThread() const { return isHorizontalWritingMod e() ? flowThreadPortionRect().height() : flowThreadPortionRect().width(); } 74 LayoutUnit logicalHeightInFlowThread() const { return isHorizontalWritingMod e() ? flowThreadPortionRect().height() : flowThreadPortionRect().width(); }
72 75
73 unsigned computedColumnCount() const { return m_computedColumnCount; } 76 unsigned computedColumnCount() const { return m_computedColumnCount; }
74 LayoutUnit computedColumnWidth() const { return m_computedColumnWidth; } 77 LayoutUnit computedColumnWidth() const { return m_computedColumnWidth; }
75 LayoutUnit computedColumnHeight() const { return m_computedColumnHeight; } 78 LayoutUnit computedColumnHeight() const { return m_computedColumnHeight; }
76 79
(...skipping 11 matching lines...) Expand all
88 91
89 void updateMinimumColumnHeight(LayoutUnit height) { m_minimumColumnHeight = std::max(height, m_minimumColumnHeight); } 92 void updateMinimumColumnHeight(LayoutUnit height) { m_minimumColumnHeight = std::max(height, m_minimumColumnHeight); }
90 LayoutUnit minimumColumnHeight() const { return m_minimumColumnHeight; } 93 LayoutUnit minimumColumnHeight() const { return m_minimumColumnHeight; }
91 94
92 // Add a content run, specified by its end position. A content run is append ed at every 95 // Add a content run, specified by its end position. A content run is append ed at every
93 // forced/explicit break and at the end of the column set. The content runs are used to 96 // forced/explicit break and at the end of the column set. The content runs are used to
94 // determine where implicit/soft breaks will occur, in order to calculate an initial column 97 // determine where implicit/soft breaks will occur, in order to calculate an initial column
95 // height. 98 // height.
96 void addContentRun(LayoutUnit endOffsetFromFirstPage); 99 void addContentRun(LayoutUnit endOffsetFromFirstPage);
97 100
98 // (Re-)calculate the column height if it's auto. If 'initial' is set, guess an initial column 101 // (Re-)calculate the column height if it's auto.
99 // height; otherwise, stretch the column height a tad. Return true if column height changed and 102 bool recalculateColumnHeight(BalancedHeightCalculation);
100 // another layout pass is required.
101 bool recalculateColumnHeight(bool initial);
102 103
103 // Record space shortage (the amount of space that would have been enough to prevent some 104 // Record space shortage (the amount of space that would have been enough to prevent some
104 // element from being moved to the next column) at a column break. The small est amount of space 105 // element from being moved to the next column) at a column break. The small est amount of space
105 // shortage we find is the amount with which we will stretch the column heig ht, if it turns out 106 // shortage we find is the amount with which we will stretch the column heig ht, if it turns out
106 // after layout that the columns weren't tall enough. 107 // after layout that the columns weren't tall enough.
107 void recordSpaceShortage(LayoutUnit spaceShortage); 108 void recordSpaceShortage(LayoutUnit spaceShortage);
108 109
109 virtual void updateLogicalWidth() OVERRIDE; 110 // Reset previously calculated column height. Will mark for layout if needed .
110 111 void resetColumnHeight();
111 void prepareForLayout();
112 112
113 // Expand this set's flow thread portion rectangle to contain all trailing f low thread 113 // Expand this set's flow thread portion rectangle to contain all trailing f low thread
114 // overflow. Only to be called on the last set. 114 // overflow. Only to be called on the last set.
115 void expandToEncompassFlowThreadContentsIfNeeded(); 115 void expandToEncompassFlowThreadContentsIfNeeded();
116 116
117 private: 117 private:
118 RenderMultiColumnSet(RenderFlowThread*); 118 RenderMultiColumnSet(RenderFlowThread*);
119 119
120 virtual void layout() OVERRIDE;
121 virtual void computeLogicalHeight(LayoutUnit logicalHeight, LayoutUnit logic alTop, LogicalExtentComputedValues&) const OVERRIDE; 120 virtual void computeLogicalHeight(LayoutUnit logicalHeight, LayoutUnit logic alTop, LogicalExtentComputedValues&) const OVERRIDE;
122 121
123 virtual void paintObject(PaintInfo&, const LayoutPoint& paintOffset) OVERRID E; 122 virtual void paintObject(PaintInfo&, const LayoutPoint& paintOffset) OVERRID E;
124 123
125 virtual LayoutUnit pageLogicalWidth() const OVERRIDE { return m_computedColu mnWidth; } 124 virtual LayoutUnit pageLogicalWidth() const OVERRIDE { return m_computedColu mnWidth; }
126 virtual LayoutUnit pageLogicalHeight() const OVERRIDE { return m_computedCol umnHeight; } 125 virtual LayoutUnit pageLogicalHeight() const OVERRIDE { return m_computedCol umnHeight; }
127 126
128 virtual LayoutUnit pageLogicalTopForOffset(LayoutUnit offset) const OVERRIDE ; 127 virtual LayoutUnit pageLogicalTopForOffset(LayoutUnit offset) const OVERRIDE ;
129 128
130 virtual LayoutUnit logicalHeightOfAllFlowThreadContent() const OVERRIDE { re turn logicalHeightInFlowThread(); } 129 virtual LayoutUnit logicalHeightOfAllFlowThreadContent() const OVERRIDE { re turn logicalHeightInFlowThread(); }
131 130
132 virtual void repaintFlowThreadContent(const LayoutRect& repaintRect) const O VERRIDE; 131 virtual void repaintFlowThreadContent(const LayoutRect& repaintRect) const O VERRIDE;
133 132
134 virtual void collectLayerFragments(LayerFragments&, const LayoutRect& layerB oundingBox, const LayoutRect& dirtyRect) OVERRIDE; 133 virtual void collectLayerFragments(LayerFragments&, const LayoutRect& layerB oundingBox, const LayoutRect& dirtyRect) OVERRIDE;
135 134
135 virtual void addOverflowFromChildren() OVERRIDE;
136
136 virtual const char* renderName() const OVERRIDE; 137 virtual const char* renderName() const OVERRIDE;
137 138
138 void paintColumnRules(PaintInfo&, const LayoutPoint& paintOffset); 139 void paintColumnRules(PaintInfo&, const LayoutPoint& paintOffset);
139 140
141 LayoutUnit calculateMaxColumnHeight() const;
140 LayoutUnit columnGap() const; 142 LayoutUnit columnGap() const;
141 LayoutRect columnRectAt(unsigned index) const; 143 LayoutRect columnRectAt(unsigned index) const;
142 unsigned columnCount() const; 144 unsigned columnCount() const;
143 145
144 LayoutRect flowThreadPortionRectAt(unsigned index) const; 146 LayoutRect flowThreadPortionRectAt(unsigned index) const;
145 LayoutRect flowThreadPortionOverflowRect(const LayoutRect& flowThreadPortion , unsigned index, unsigned colCount, LayoutUnit colGap) const; 147 LayoutRect flowThreadPortionOverflowRect(const LayoutRect& flowThreadPortion , unsigned index, unsigned colCount, LayoutUnit colGap) const;
146 148
147 enum ColumnIndexCalculationMode { 149 enum ColumnIndexCalculationMode {
148 ClampToExistingColumns, // Stay within the range of already existing col umns. 150 ClampToExistingColumns, // Stay within the range of already existing col umns.
149 AssumeNewColumns // Allow column indices outside the range of already ex isting columns. 151 AssumeNewColumns // Allow column indices outside the range of already ex isting columns.
150 }; 152 };
151 unsigned columnIndexAtOffset(LayoutUnit, ColumnIndexCalculationMode = ClampT oExistingColumns) const; 153 unsigned columnIndexAtOffset(LayoutUnit, ColumnIndexCalculationMode = ClampT oExistingColumns) const;
152 154
153 void setAndConstrainColumnHeight(LayoutUnit); 155 void setAndConstrainColumnHeight(LayoutUnit);
154 156
155 // Return the index of the content run with the currently tallest columns, t aking all implicit 157 // Return the index of the content run with the currently tallest columns, t aking all implicit
156 // breaks assumed so far into account. 158 // breaks assumed so far into account.
157 unsigned findRunWithTallestColumns() const; 159 unsigned findRunWithTallestColumns() const;
158 160
159 // Given the current list of content runs, make assumptions about where we n eed to insert 161 // Given the current list of content runs, make assumptions about where we n eed to insert
160 // implicit breaks (if there's room for any at all; depending on the number of explicit breaks), 162 // implicit breaks (if there's room for any at all; depending on the number of explicit breaks),
161 // and store the results. This is needed in order to balance the columns. 163 // and store the results. This is needed in order to balance the columns.
162 void distributeImplicitBreaks(); 164 void distributeImplicitBreaks();
163 165
164 LayoutUnit calculateColumnHeight(bool initial) const; 166 LayoutUnit calculateColumnHeight(BalancedHeightCalculation) const;
165 167
166 unsigned m_computedColumnCount; // Used column count (the resulting 'N' from the pseudo-algorithm in the multicol spec) 168 unsigned m_computedColumnCount; // Used column count (the resulting 'N' from the pseudo-algorithm in the multicol spec)
167 LayoutUnit m_computedColumnWidth; // Used column width (the resulting 'W' fr om the pseudo-algorithm in the multicol spec) 169 LayoutUnit m_computedColumnWidth; // Used column width (the resulting 'W' fr om the pseudo-algorithm in the multicol spec)
168 LayoutUnit m_computedColumnHeight; 170 LayoutUnit m_computedColumnHeight;
169 171
170 // The following variables are used when balancing the column set. 172 // The following variables are used when balancing the column set.
171 LayoutUnit m_maxColumnHeight; // Maximum column height allowed. 173 LayoutUnit m_maxColumnHeight; // Maximum column height allowed.
172 LayoutUnit m_minSpaceShortage; // The smallest amout of space shortage that caused a column break. 174 LayoutUnit m_minSpaceShortage; // The smallest amout of space shortage that caused a column break.
173 LayoutUnit m_minimumColumnHeight; 175 LayoutUnit m_minimumColumnHeight;
174 176
(...skipping 24 matching lines...) Expand all
199 }; 201 };
200 Vector<ContentRun, 1> m_contentRuns; 202 Vector<ContentRun, 1> m_contentRuns;
201 }; 203 };
202 204
203 DEFINE_RENDER_OBJECT_TYPE_CASTS(RenderMultiColumnSet, isRenderMultiColumnSet()); 205 DEFINE_RENDER_OBJECT_TYPE_CASTS(RenderMultiColumnSet, isRenderMultiColumnSet());
204 206
205 } // namespace WebCore 207 } // namespace WebCore
206 208
207 #endif // RenderMultiColumnSet_h 209 #endif // RenderMultiColumnSet_h
208 210
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