OLD | NEW |
---|---|
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 Loading... | |
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 RenderMultiColumnFlowThread_h | 27 #ifndef RenderMultiColumnFlowThread_h |
28 #define RenderMultiColumnFlowThread_h | 28 #define RenderMultiColumnFlowThread_h |
29 | 29 |
30 #include "core/rendering/RenderFlowThread.h" | 30 #include "core/rendering/RenderFlowThread.h" |
31 #include "wtf/HashMap.h" | |
31 | 32 |
32 namespace blink { | 33 namespace blink { |
33 | 34 |
34 class RenderMultiColumnSet; | 35 class RenderMultiColumnSet; |
36 class RenderMultiColumnSpannerSet; | |
35 | 37 |
36 // Flow thread implementation for CSS multicol. This will be inserted as an anon ymous child block of | 38 // Flow thread implementation for CSS multicol. This will be inserted as an anon ymous child block of |
37 // the actual multicol container (i.e. the RenderBlockFlow whose style computes to non-auto | 39 // the actual multicol container (i.e. the RenderBlockFlow whose style computes to non-auto |
38 // column-count and/or column-width). RenderMultiColumnFlowThread is the heart o f the multicol | 40 // column-count and/or column-width). RenderMultiColumnFlowThread is the heart o f the multicol |
39 // implementation, and there is only one instance per multicol container. Child content of the | 41 // implementation, and there is only one instance per multicol container. Child content of the |
40 // multicol container is parented into the flow thread at the time of renderer i nsertion. | 42 // multicol container is parented into the flow thread at the time of renderer i nsertion. |
41 // | 43 // |
42 // Apart from this flow thread child, the multicol container will also have Rend erMultiColumnSet | 44 // Apart from this flow thread child, the multicol container will also have Rend erMultiColumnSet |
43 // "region" children, which are used to position the columns visually. The flow thread is in charge | 45 // "region" children, which are used to position the columns visually. The flow thread is in charge |
44 // of layout, and, after having calculated the column width, it lays out content as if everything | 46 // of layout, and, after having calculated the column width, it lays out content as if everything |
45 // were in one tall single column, except that there will typically be some amou nt of blank space | 47 // were in one tall single column, except that there will typically be some amou nt of blank space |
46 // (also known as pagination struts) at the offsets where the actual column boun daries are. This | 48 // (also known as pagination struts) at the offsets where the actual column boun daries are. This |
47 // way, content that needs to be preceded by a break will appear at the top of t he next | 49 // way, content that needs to be preceded by a break will appear at the top of t he next |
48 // column. Content needs to be preceded by a break when there's a forced break o r when the content | 50 // column. Content needs to be preceded by a break when there's a forced break o r when the content |
49 // is unbreakable and cannot fully fit in the same column as the preceding piece of | 51 // is unbreakable and cannot fully fit in the same column as the preceding piece of |
50 // content. Although a RenderMultiColumnFlowThread is laid out, it does not take up any space in its | 52 // content. Although a RenderMultiColumnFlowThread is laid out, it does not take up any space in its |
51 // container. It's the RenderMultiColumnSet objects that take up the necessary a mount of space, and | 53 // container. It's the RenderMultiColumnSet objects that take up the necessary a mount of space, and |
52 // make sure that the columns are painted and hit-tested correctly. | 54 // make sure that the columns are painted and hit-tested correctly. |
53 // | 55 // |
56 // If there is any column content inside the multicol container, we create a | |
57 // RenderMultiColumnSet. We only need to create multiple sets if there are spann ers | |
58 // (column-span:all) in the multicol container. When a spanner is inserted, cont ent preceding it | |
59 // gets its own set, and content succeeding it will get another set. The spanner itself will also | |
60 // get its own set (RenderMultiColumnSpannerSet). | |
61 // | |
54 // The width of the flow thread is the same as the column width. The width of a column set is the | 62 // The width of the flow thread is the same as the column width. The width of a column set is the |
55 // same as the content box width of the multicol container; in other words exact ly enough to hold | 63 // same as the content box width of the multicol container; in other words exact ly enough to hold |
56 // the number of columns to be used, stacked horizontally, plus column gaps betw een them. | 64 // the number of columns to be used, stacked horizontally, plus column gaps betw een them. |
57 // | 65 // |
58 // Since it's the first child of the multicol container, the flow thread is laid out first, albeit | 66 // Since it's the first child of the multicol container, the flow thread is laid out first, albeit |
59 // in a slightly special way, since it's not to take up any space in its ancesto rs. Afterwards, the | 67 // in a slightly special way, since it's not to take up any space in its ancesto rs. Afterwards, the |
60 // column sets are laid out. They get their height from the columns that they ho ld. In single | 68 // column sets are laid out. Column sets get their height from the columns that they hold. In single |
61 // column-row constrained height non-balancing cases this will simply be the sam e as the content | 69 // column-row constrained height non-balancing cases without spanners this will simply be the same |
62 // height of the multicol container itself. In most other cases we'll have to ca lculate optimal | 70 // as the content height of the multicol container itself. In most other cases w e'll have to |
63 // column heights ourselves, though. This process is referred to as column balan cing, and then we | 71 // calculate optimal column heights ourselves, though. This process is referred to as column |
64 // infer the column set height from the flow thread's height. | 72 // balancing, and then we infer the column set height from the height of the flo w thread portion |
73 // occupied by each set. | |
65 // | 74 // |
66 // More on column balancing: the columns' height is unknown in the first layout pass when | 75 // More on column balancing: the columns' height is unknown in the first layout pass when |
67 // balancing. This means that we cannot insert any implicit (soft / unforced) br eaks (and pagination | 76 // balancing. This means that we cannot insert any implicit (soft / unforced) br eaks (and pagination |
68 // struts) when laying out the contents of the flow thread. We'll just lay out e verything in tall | 77 // struts) when laying out the contents of the flow thread. We'll just lay out e verything in tall |
69 // single strip. After the initial flow thread layout pass we can determine a te ntative / minimal / | 78 // single strip. After the initial flow thread layout pass we can determine a te ntative / minimal / |
70 // initial column height. This is calculated by simply dividing the flow thread' s height by the | 79 // initial column height. This is calculated by simply dividing the flow thread' s height by the |
71 // number of specified columns. In the layout pass that follows, we can insert b reaks (and | 80 // number of specified columns. In the layout pass that follows, we can insert b reaks (and |
72 // pagination struts) at column boundaries, since we now have a column height. I t may very easily | 81 // pagination struts) at column boundaries, since we now have a column height. I t may very easily |
73 // turn out that the calculated height wasn't enough, though. We'll notice this at end of layout. If | 82 // turn out that the calculated height wasn't enough, though. We'll notice this at end of layout. If |
74 // we end up with too many columns (i.e. columns overflowing the multicol contai ner), it wasn't | 83 // we end up with too many columns (i.e. columns overflowing the multicol contai ner), it wasn't |
(...skipping 15 matching lines...) Expand all Loading... | |
90 | 99 |
91 static RenderMultiColumnFlowThread* createAnonymous(Document&, RenderStyle* parentStyle); | 100 static RenderMultiColumnFlowThread* createAnonymous(Document&, RenderStyle* parentStyle); |
92 | 101 |
93 virtual bool isRenderMultiColumnFlowThread() const override final { return t rue; } | 102 virtual bool isRenderMultiColumnFlowThread() const override final { return t rue; } |
94 | 103 |
95 RenderBlockFlow* multiColumnBlockFlow() const { return toRenderBlockFlow(par ent()); } | 104 RenderBlockFlow* multiColumnBlockFlow() const { return toRenderBlockFlow(par ent()); } |
96 | 105 |
97 RenderMultiColumnSet* firstMultiColumnSet() const; | 106 RenderMultiColumnSet* firstMultiColumnSet() const; |
98 RenderMultiColumnSet* lastMultiColumnSet() const; | 107 RenderMultiColumnSet* lastMultiColumnSet() const; |
99 | 108 |
100 virtual void addChild(RenderObject* newChild, RenderObject* beforeChild = 0) override; | 109 // Return the spanner set (if any) that contains the specified renderer. Thi s includes the |
110 // renderer for the element that actually establishes the spanner too. | |
111 RenderMultiColumnSpannerSet* containingColumnSpannerSet(const RenderObject* descendant) const; | |
101 | 112 |
102 // Populate the flow thread with what's currently its siblings. Called when a regular block | 113 // Populate the flow thread with what's currently its siblings. Called when a regular block |
103 // becomes a multicol container. | 114 // becomes a multicol container. |
104 void populate(); | 115 void populate(); |
105 | 116 |
106 // Empty the flow thread by moving everything to the parent. Remove all mult icol specific | 117 // Empty the flow thread by moving everything to the parent. Remove all mult icol specific |
107 // renderers. Then destroy the flow thread. Called when a multicol container becomes a regular | 118 // renderers. Then destroy the flow thread. Called when a multicol container becomes a regular |
108 // block. | 119 // block. |
109 void evacuateAndDestroy(); | 120 void evacuateAndDestroy(); |
110 | 121 |
(...skipping 13 matching lines...) Expand all Loading... | |
124 bool recalculateColumnHeights(); | 135 bool recalculateColumnHeights(); |
125 | 136 |
126 protected: | 137 protected: |
127 RenderMultiColumnFlowThread(); | 138 RenderMultiColumnFlowThread(); |
128 void setProgressionIsInline(bool isInline) { m_progressionIsInline = isInlin e; } | 139 void setProgressionIsInline(bool isInline) { m_progressionIsInline = isInlin e; } |
129 | 140 |
130 virtual void layout() override; | 141 virtual void layout() override; |
131 | 142 |
132 private: | 143 private: |
133 void calculateColumnCountAndWidth(LayoutUnit& width, unsigned& count) const; | 144 void calculateColumnCountAndWidth(LayoutUnit& width, unsigned& count) const; |
145 void createAndInsertMultiColumnSet(); | |
146 void createAndInsertSpannerSet(RenderBox* spanner); | |
147 virtual bool isDescendantValidColumnSpanner(RenderObject* descendant) const; | |
Julien - ping for review
2014/11/05 16:52:38
If we follow the correct English order, it should
mstensho (USE GERRIT)
2014/11/05 21:43:06
Done.
| |
134 | 148 |
135 virtual const char* renderName() const override; | 149 virtual const char* renderName() const override; |
136 virtual void addRegionToThread(RenderMultiColumnSet*) override; | 150 virtual void addRegionToThread(RenderMultiColumnSet*) override; |
137 virtual void willBeRemovedFromTree() override; | 151 virtual void willBeRemovedFromTree() override; |
152 virtual void flowThreadDescendantWasInserted(RenderObject*) override; | |
138 virtual void computeLogicalHeight(LayoutUnit logicalHeight, LayoutUnit logic alTop, LogicalExtentComputedValues&) const override; | 153 virtual void computeLogicalHeight(LayoutUnit logicalHeight, LayoutUnit logic alTop, LogicalExtentComputedValues&) const override; |
139 virtual void updateLogicalWidth() override; | 154 virtual void updateLogicalWidth() override; |
140 virtual void setPageBreak(LayoutUnit offset, LayoutUnit spaceShortage) overr ide; | 155 virtual void setPageBreak(LayoutUnit offset, LayoutUnit spaceShortage) overr ide; |
141 virtual void updateMinimumPageHeight(LayoutUnit offset, LayoutUnit minHeight ) override; | 156 virtual void updateMinimumPageHeight(LayoutUnit offset, LayoutUnit minHeight ) override; |
142 virtual RenderMultiColumnSet* columnSetAtBlockOffset(LayoutUnit) const overr ide; | 157 virtual RenderMultiColumnSet* columnSetAtBlockOffset(LayoutUnit) const overr ide; |
143 virtual bool addForcedRegionBreak(LayoutUnit, RenderObject* breakChild, bool isBefore, LayoutUnit* offsetBreakAdjustment = 0) override; | 158 virtual bool addForcedRegionBreak(LayoutUnit, RenderObject* breakChild, bool isBefore, LayoutUnit* offsetBreakAdjustment = 0) override; |
144 virtual bool isPageLogicalHeightKnown() const override; | 159 virtual bool isPageLogicalHeightKnown() const override; |
145 | 160 |
161 typedef HashMap<const RenderObject*, RenderMultiColumnSpannerSet*> SpannerMa p; | |
162 SpannerMap m_spannerMap; | |
163 | |
146 unsigned m_columnCount; // The used value of column-count | 164 unsigned m_columnCount; // The used value of column-count |
147 LayoutUnit m_columnHeightAvailable; // Total height available to columns, or 0 if auto. | 165 LayoutUnit m_columnHeightAvailable; // Total height available to columns, or 0 if auto. |
148 bool m_inBalancingPass; // Set when relayouting for column balancing. | 166 bool m_inBalancingPass; // Set when relayouting for column balancing. |
149 bool m_needsColumnHeightsRecalculation; // Set when we need to recalculate t he column set heights after layout. | 167 bool m_needsColumnHeightsRecalculation; // Set when we need to recalculate t he column set heights after layout. |
150 bool m_progressionIsInline; // Always true for regular multicol. False for p aged-y overflow. | 168 bool m_progressionIsInline; // Always true for regular multicol. False for p aged-y overflow. |
151 }; | 169 }; |
152 | 170 |
153 } // namespace blink | 171 } // namespace blink |
154 | 172 |
155 #endif // RenderMultiColumnFlowThread_h | 173 #endif // RenderMultiColumnFlowThread_h |
156 | 174 |
OLD | NEW |