Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "core/layout/MultiColumnFragmentainerGroup.h" | |
| 6 | |
| 7 namespace blink { | |
| 8 | |
| 9 // A column balancer traverses the portion of the subtree of a flow thread that belongs to a given | |
| 10 // fragmentainer group, in order to collect certain data to be used for column b alancing. This is an | |
| 11 // abstract class that just walks the subtree and leaves it to subclasses to act ualy collect data. | |
| 12 class ColumnBalancer { | |
| 13 public: | |
| 14 ColumnBalancer(const MultiColumnFragmentainerGroup&); | |
|
leviw_travelin_and_unemployed
2015/10/08 09:49:29
Does any of this need to be public? It seems like
mstensho (USE GERRIT)
2015/10/08 10:38:05
Done.
| |
| 15 | |
| 16 const MultiColumnFragmentainerGroup& group() const { return m_group; } | |
| 17 | |
| 18 // Flow thread offset for the layout object that we're currently examining. | |
| 19 LayoutUnit flowThreadOffset() const { return m_flowThreadOffset; } | |
| 20 | |
| 21 // Return true if the specified offset is at the top of a column, as long as it's not the first | |
| 22 // column in the multicol container. | |
| 23 bool isFirstAfterBreak(LayoutUnit flowThreadOffset) const | |
| 24 { | |
| 25 if (flowThreadOffset != m_group.columnLogicalTopForOffset(flowThreadOffs et)) | |
| 26 return false; // Not at the top of a column. | |
| 27 // The first column in the first group isn't after any break. | |
| 28 return flowThreadOffset > m_group.logicalTopInFlowThread() || !m_group.i sFirstGroup(); | |
| 29 } | |
| 30 | |
| 31 // Examine and collect column balancing data from a layout box that has been found to intersect | |
| 32 // with this fragmentainer group. Does not recurse into children. flowThread Offset() will | |
| 33 // return the offset from |box| to the flow thread. Two hooks are provided h ere. The first one | |
| 34 // is called right after entering and before traversing the subtree of the b ox, and the second | |
| 35 // one right after having traversed the subtree. | |
| 36 virtual void examineBoxAfterEntering(const LayoutBox&) = 0; | |
| 37 virtual void examineBoxBeforeLeaving(const LayoutBox&) = 0; | |
| 38 | |
| 39 // Examine and collect column balancing data from a line that has been found to intersect with | |
| 40 // this fragmentainer group. Does not recurse into layout objects on that li ne. | |
| 41 virtual void examineLine(const RootInlineBox&) = 0; | |
| 42 | |
| 43 protected: | |
| 44 // Examine and collect column balancing data for everything in the fragmenta iner group. Will | |
| 45 // trigger calls to examineBoxAfterEntering(), examineBoxBeforeLeaving() and examineLine() for | |
| 46 // interesting boxes and lines. | |
| 47 void traverse(); | |
| 48 | |
| 49 private: | |
| 50 void traverseSubtree(const LayoutBox&); | |
| 51 | |
| 52 const MultiColumnFragmentainerGroup& m_group; | |
| 53 LayoutUnit m_flowThreadOffset; | |
| 54 }; | |
| 55 | |
| 56 // After an initial layout pass, we know the height of the contents of a flow th read. Based on | |
| 57 // this, we can estimate an initial minimal column height. This class will colle ct the necessary | |
| 58 // information from the layout objects to make this estimate. This estimate may be used to perform | |
| 59 // another layout iteration. If we after such a layout iteration cannot fit the contents with the | |
| 60 // given column height without creating overflowing columns, we will have to str etch the columns by | |
| 61 // some amount and lay out again. We may need to do this several times (but typi cally not more | |
| 62 // times than the number of columns that we have). The amount to stretch is prov ided by the sister | |
| 63 // of this class, named MinimumSpaceShortageFinder. | |
| 64 class InitialColumnHeightFinder final : public ColumnBalancer { | |
| 65 public: | |
| 66 static LayoutUnit initialMinimalBalancedHeight(const MultiColumnFragmentaine rGroup& group) | |
| 67 { | |
| 68 return InitialColumnHeightFinder(group).initialMinimalBalancedHeight(); | |
| 69 } | |
| 70 | |
| 71 private: | |
| 72 InitialColumnHeightFinder(const MultiColumnFragmentainerGroup&); | |
| 73 | |
| 74 LayoutUnit initialMinimalBalancedHeight() const; | |
| 75 | |
| 76 void examineBoxAfterEntering(const LayoutBox&); | |
|
leviw_travelin_and_unemployed
2015/10/08 09:49:29
mark these as overrides
mstensho (USE GERRIT)
2015/10/08 10:38:05
The entire class is final. Should I still mark the
| |
| 77 void examineBoxBeforeLeaving(const LayoutBox&); | |
| 78 void examineLine(const RootInlineBox&); | |
| 79 | |
| 80 // Add a content run, specified by its end position. A content run is append ed at every | |
| 81 // forced/explicit break and at the end of the column set. The content runs are used to | |
| 82 // determine where implicit/soft breaks will occur, in order to calculate an initial column | |
| 83 // height. | |
| 84 void addContentRun(LayoutUnit endOffsetInFlowThread); | |
| 85 | |
| 86 // Return the index of the content run with the currently tallest columns, t aking all implicit | |
| 87 // breaks assumed so far into account. | |
| 88 unsigned contentRunIndexWithTallestColumns() const; | |
| 89 | |
| 90 // Given the current list of content runs, make assumptions about where we n eed to insert | |
| 91 // implicit breaks (if there's room for any at all; depending on the number of explicit breaks), | |
| 92 // and store the results. This is needed in order to balance the columns. | |
| 93 void distributeImplicitBreaks(); | |
| 94 | |
| 95 // A run of content without explicit (forced) breaks; i.e. a flow thread por tion between two | |
| 96 // explicit breaks, between flow thread start and an explicit break, between an explicit break | |
| 97 // and flow thread end, or, in cases when there are no explicit breaks at al l: between flow | |
| 98 // thread portion start and flow thread portion end. We need to know where t he explicit breaks | |
| 99 // are, in order to figure out where the implicit breaks will end up, so tha t we get the columns | |
| 100 // properly balanced. A content run starts out as representing one single co lumn, and will | |
| 101 // represent one additional column for each implicit break "inserted" there. | |
| 102 class ContentRun { | |
| 103 public: | |
| 104 ContentRun(LayoutUnit breakOffset) | |
| 105 : m_breakOffset(breakOffset) | |
| 106 , m_assumedImplicitBreaks(0) { } | |
| 107 | |
| 108 unsigned assumedImplicitBreaks() const { return m_assumedImplicitBreaks; } | |
| 109 void assumeAnotherImplicitBreak() { m_assumedImplicitBreaks++; } | |
| 110 LayoutUnit breakOffset() const { return m_breakOffset; } | |
| 111 | |
| 112 // Return the column height that this content run would require, conside ring the implicit | |
| 113 // breaks assumed so far. | |
| 114 LayoutUnit columnLogicalHeight(LayoutUnit startOffset) const { return ce ilf((m_breakOffset - startOffset).toFloat() / float(m_assumedImplicitBreaks + 1) ); } | |
| 115 | |
| 116 private: | |
| 117 LayoutUnit m_breakOffset; // Flow thread offset where this run ends. | |
| 118 unsigned m_assumedImplicitBreaks; // Number of implicit breaks in this r un assumed so far. | |
| 119 }; | |
| 120 Vector<ContentRun, 50> m_contentRuns; | |
|
leviw_travelin_and_unemployed
2015/10/08 09:49:29
Where did you get this inline size from?
mstensho (USE GERRIT)
2015/10/08 10:38:05
I just typed something on my keyboard until it com
| |
| 121 }; | |
| 122 | |
| 123 // If we have previously used InitialColumnHeightFinder to estimate an initial c olumn height, and | |
| 124 // that didn't result in tall enough columns, we need subsequent layout passes w here we increase | |
| 125 // the column height by the minimum space shortage at column breaks. This class finds the minimum | |
| 126 // space shortage after having laid out with the current column height. | |
| 127 class MinimumSpaceShortageFinder final : public ColumnBalancer { | |
| 128 public: | |
| 129 MinimumSpaceShortageFinder(const MultiColumnFragmentainerGroup&); | |
| 130 | |
| 131 LayoutUnit minimumSpaceShortage() const { return m_minimumSpaceShortage; } | |
| 132 unsigned forcedBreaksCount() const { return m_forcedBreaksCount; } | |
| 133 | |
| 134 private: | |
| 135 void examineBoxAfterEntering(const LayoutBox&); | |
|
leviw_travelin_and_unemployed
2015/10/08 09:49:29
mark these as overrides
mstensho (USE GERRIT)
2015/10/08 10:38:05
See previous comment.
| |
| 136 void examineBoxBeforeLeaving(const LayoutBox&); | |
| 137 void examineLine(const RootInlineBox&); | |
| 138 | |
| 139 void recordSpaceShortage(LayoutUnit shortage) | |
| 140 { | |
| 141 // Only positive values are interesting (and allowed) here. Zero space s hortage may | |
| 142 // be reported when we're at the top of a column and the element has zer o | |
| 143 // height. | |
| 144 if (shortage > 0) | |
| 145 m_minimumSpaceShortage = std::min(m_minimumSpaceShortage, shortage); | |
| 146 } | |
| 147 | |
| 148 // The smallest amout of space shortage that caused a column break. | |
| 149 LayoutUnit m_minimumSpaceShortage; | |
| 150 | |
| 151 // Set when breaking before a block, and we're looking for the first unbreak able descendant, in | |
| 152 // order to report correct space shortage for that one. | |
| 153 LayoutUnit m_pendingStrut; | |
| 154 | |
| 155 unsigned m_forcedBreaksCount; | |
| 156 }; | |
| 157 | |
| 158 } // namespace blink | |
| OLD | NEW |