OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "core/layout/ColumnBalancer.h" | 5 #include "core/layout/ColumnBalancer.h" |
6 | 6 |
7 #include "core/layout/LayoutMultiColumnFlowThread.h" | 7 #include "core/layout/LayoutMultiColumnFlowThread.h" |
8 #include "core/layout/LayoutMultiColumnSet.h" | 8 #include "core/layout/LayoutMultiColumnSet.h" |
9 #include "core/layout/api/LineLayoutBlockFlow.h" | 9 #include "core/layout/api/LineLayoutBlockFlow.h" |
10 | 10 |
11 namespace blink { | 11 namespace blink { |
12 | 12 |
13 ColumnBalancer::ColumnBalancer(const LayoutMultiColumnSet& columnSet, | 13 ColumnBalancer::ColumnBalancer(const LayoutMultiColumnSet& columnSet, |
14 LayoutUnit logicalTopInFlowThread, | 14 LayoutUnit logicalTopInFlowThread, |
15 LayoutUnit logicalBottomInFlowThread) | 15 LayoutUnit logicalBottomInFlowThread) |
16 : m_columnSet(columnSet), | 16 : m_columnSet(columnSet), |
17 m_logicalTopInFlowThread(logicalTopInFlowThread), | 17 m_logicalTopInFlowThread(logicalTopInFlowThread), |
18 m_logicalBottomInFlowThread(logicalBottomInFlowThread) {} | 18 m_logicalBottomInFlowThread(logicalBottomInFlowThread) {} |
19 | 19 |
20 void ColumnBalancer::traverse() { | 20 void ColumnBalancer::traverse() { |
21 traverseSubtree(*columnSet().flowThread()); | 21 traverseSubtree(*columnSet().flowThread()); |
22 ASSERT(!flowThreadOffset()); | 22 ASSERT(!flowThreadOffset()); |
23 } | 23 } |
24 | 24 |
25 void ColumnBalancer::traverseSubtree(const LayoutBox& box) { | 25 void ColumnBalancer::traverseSubtree(const LayoutBox& box) { |
26 if (box.childrenInline() && box.isLayoutBlockFlow()) { | 26 if (box.childrenInline() && box.isLayoutBlockFlow()) { |
27 // Look for breaks between lines. | 27 // Look for breaks between lines. |
28 for (const RootInlineBox* line = toLayoutBlockFlow(box).firstRootBox(); | 28 traverseLines(toLayoutBlockFlow(box)); |
29 line; line = line->nextRootBox()) { | |
30 LayoutUnit lineTopInFlowThread = | |
31 m_flowThreadOffset + line->lineTopWithLeading(); | |
32 if (lineTopInFlowThread < logicalTopInFlowThread()) | |
33 continue; | |
34 if (lineTopInFlowThread >= logicalBottomInFlowThread()) | |
35 break; | |
36 examineLine(*line); | |
37 } | |
38 } | 29 } |
39 | 30 |
| 31 // Look for breaks between and inside block-level children. Even if this is a |
| 32 // block flow with inline children, there may be interesting floats to examine |
| 33 // here. |
| 34 traverseChildren(box); |
| 35 } |
| 36 |
| 37 void ColumnBalancer::traverseLines(const LayoutBlockFlow& blockFlow) { |
| 38 for (const RootInlineBox* line = blockFlow.firstRootBox(); line; |
| 39 line = line->nextRootBox()) { |
| 40 LayoutUnit lineTopInFlowThread = |
| 41 m_flowThreadOffset + line->lineTopWithLeading(); |
| 42 if (lineTopInFlowThread < logicalTopInFlowThread()) |
| 43 continue; |
| 44 if (lineTopInFlowThread >= logicalBottomInFlowThread()) |
| 45 break; |
| 46 examineLine(*line); |
| 47 } |
| 48 } |
| 49 |
| 50 void ColumnBalancer::traverseChildren(const LayoutObject& object) { |
| 51 // The break-after value from the previous in-flow block-level object to be |
| 52 // joined with the break-before value of the next in-flow block-level sibling. |
| 53 EBreak previousBreakAfterValue = BreakAuto; |
| 54 |
40 const LayoutFlowThread* flowThread = columnSet().flowThread(); | 55 const LayoutFlowThread* flowThread = columnSet().flowThread(); |
41 bool isHorizontalWritingMode = flowThread->isHorizontalWritingMode(); | 56 bool isHorizontalWritingMode = flowThread->isHorizontalWritingMode(); |
42 | 57 |
43 // The break-after value from the previous in-flow block-level object to be | 58 for (const LayoutObject* child = object.slowFirstChild(); child; |
44 // joined with the break-before value of the next in-flow block-level sibling. | 59 child = child->nextSibling()) { |
45 EBreak previousBreakAfterValue = BreakAuto; | 60 if (!child->isBox()) { |
| 61 // Keep traversing inside inlines. There may be floats there. |
| 62 if (child->isLayoutInline()) |
| 63 traverseChildren(*child); |
| 64 continue; |
| 65 } |
46 | 66 |
47 // Look for breaks between and inside block-level children. Even if this is a | |
48 // block flow with inline children, there may be interesting floats to examine | |
49 // here. | |
50 for (const LayoutObject* child = box.slowFirstChild(); child; | |
51 child = child->nextSibling()) { | |
52 if (!child->isBox() || child->isInline()) | |
53 continue; | |
54 const LayoutBox& childBox = toLayoutBox(*child); | 67 const LayoutBox& childBox = toLayoutBox(*child); |
55 LayoutRect overflowRect = childBox.layoutOverflowRect(); | 68 LayoutRect overflowRect = childBox.layoutOverflowRect(); |
56 LayoutUnit childLogicalBottomWithOverflow = | 69 LayoutUnit childLogicalBottomWithOverflow = |
57 childBox.logicalTop() + | 70 childBox.logicalTop() + |
58 (isHorizontalWritingMode ? overflowRect.maxY() : overflowRect.maxX()); | 71 (isHorizontalWritingMode ? overflowRect.maxY() : overflowRect.maxX()); |
59 if (m_flowThreadOffset + childLogicalBottomWithOverflow <= | 72 if (m_flowThreadOffset + childLogicalBottomWithOverflow <= |
60 logicalTopInFlowThread()) { | 73 logicalTopInFlowThread()) { |
61 // This child is fully above the flow thread portion we're examining. | 74 // This child is fully above the flow thread portion we're examining. |
62 continue; | 75 continue; |
63 } | 76 } |
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
404 if (group.columnLogicalTopForOffset(lineTopInFlowThread) != | 417 if (group.columnLogicalTopForOffset(lineTopInFlowThread) != |
405 group.columnLogicalTopForOffset(lineBottomWithOverflow)) { | 418 group.columnLogicalTopForOffset(lineBottomWithOverflow)) { |
406 LayoutUnit shortage = | 419 LayoutUnit shortage = |
407 lineBottomWithOverflow - | 420 lineBottomWithOverflow - |
408 group.columnLogicalTopForOffset(lineBottomWithOverflow); | 421 group.columnLogicalTopForOffset(lineBottomWithOverflow); |
409 recordSpaceShortage(shortage); | 422 recordSpaceShortage(shortage); |
410 } | 423 } |
411 } | 424 } |
412 | 425 |
413 } // namespace blink | 426 } // namespace blink |
OLD | NEW |