1 | /* |
2 | * Copyright (C) 2012 Apple Inc. All rights reserved. |
3 | * |
4 | * Redistribution and use in source and binary forms, with or without |
5 | * modification, are permitted provided that the following conditions |
6 | * are met: |
7 | * 1. Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. |
9 | * 2. Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. |
12 | * |
13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
18 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
19 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
20 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
21 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
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. |
24 | */ |
25 | |
26 | #pragma once |
27 | |
28 | #include "RenderFragmentedFlow.h" |
29 | #include <wtf/HashMap.h> |
30 | |
31 | namespace WebCore { |
32 | |
33 | class RenderMultiColumnSet; |
34 | class RenderMultiColumnSpannerPlaceholder; |
35 | |
36 | class RenderMultiColumnFlow final : public RenderFragmentedFlow { |
37 | WTF_MAKE_ISO_ALLOCATED(RenderMultiColumnFlow); |
38 | public: |
39 | RenderMultiColumnFlow(Document&, RenderStyle&&); |
40 | ~RenderMultiColumnFlow(); |
41 | |
42 | RenderBlockFlow* multiColumnBlockFlow() const { return downcast<RenderBlockFlow>(parent()); } |
43 | |
44 | RenderMultiColumnSet* firstMultiColumnSet() const; |
45 | RenderMultiColumnSet* lastMultiColumnSet() const; |
46 | RenderBox* firstColumnSetOrSpanner() const; |
47 | bool hasColumnSpanner() const { return !m_spannerMap->isEmpty(); } |
48 | static RenderBox* nextColumnSetOrSpannerSiblingOf(const RenderBox*); |
49 | static RenderBox* previousColumnSetOrSpannerSiblingOf(const RenderBox*); |
50 | |
51 | RenderMultiColumnSpannerPlaceholder* findColumnSpannerPlaceholder(RenderBox* spanner) const { return m_spannerMap->get(spanner).get(); } |
52 | |
53 | void layout() override; |
54 | |
55 | unsigned columnCount() const { return m_columnCount; } |
56 | LayoutUnit columnWidth() const { return m_columnWidth; } |
57 | LayoutUnit columnHeightAvailable() const { return m_columnHeightAvailable; } |
58 | void setColumnHeightAvailable(LayoutUnit available) { m_columnHeightAvailable = available; } |
59 | bool inBalancingPass() const { return m_inBalancingPass; } |
60 | void setInBalancingPass(bool balancing) { m_inBalancingPass = balancing; } |
61 | bool needsHeightsRecalculation() const { return m_needsHeightsRecalculation; } |
62 | void setNeedsHeightsRecalculation(bool recalculate) { m_needsHeightsRecalculation = recalculate; } |
63 | |
64 | bool shouldRelayoutForPagination() const { return !m_inBalancingPass && m_needsHeightsRecalculation; } |
65 | |
66 | void setColumnCountAndWidth(unsigned count, LayoutUnit width) |
67 | { |
68 | m_columnCount = count; |
69 | m_columnWidth = width; |
70 | } |
71 | |
72 | bool progressionIsInline() const { return m_progressionIsInline; } |
73 | void setProgressionIsInline(bool progressionIsInline) { m_progressionIsInline = progressionIsInline; } |
74 | |
75 | bool progressionIsReversed() const { return m_progressionIsReversed; } |
76 | void setProgressionIsReversed(bool reversed) { m_progressionIsReversed = reversed; } |
77 | |
78 | RenderFragmentContainer* mapFromFlowToFragment(TransformState&) const override; |
79 | |
80 | // This method takes a logical offset and returns a physical translation that can be applied to map |
81 | // a physical point (corresponding to the logical offset) into the fragment's physical coordinate space. |
82 | LayoutSize physicalTranslationOffsetFromFlowToFragment(const RenderFragmentContainer*, const LayoutUnit) const; |
83 | |
84 | // The point is physical, and the result is a physical location within the fragment. |
85 | RenderFragmentContainer* physicalTranslationFromFlowToFragment(LayoutPoint&) const; |
86 | |
87 | // This method is the inverse of the previous method and goes from fragment to flow. |
88 | LayoutSize physicalTranslationFromFragmentToFlow(const RenderMultiColumnSet*, const LayoutPoint&) const; |
89 | |
90 | bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction) override; |
91 | |
92 | void mapAbsoluteToLocalPoint(MapCoordinatesFlags, TransformState&) const override; |
93 | LayoutSize offsetFromContainer(RenderElement&, const LayoutPoint&, bool* offsetDependsOnPoint = nullptr) const override; |
94 | |
95 | // FIXME: Eventually as column and fragment flow threads start nesting, this will end up changing. |
96 | bool shouldCheckColumnBreaks() const override; |
97 | |
98 | typedef HashMap<RenderBox*, WeakPtr<RenderMultiColumnSpannerPlaceholder>> SpannerMap; |
99 | SpannerMap& spannerMap() { return *m_spannerMap; } |
100 | |
101 | private: |
102 | bool isRenderMultiColumnFlow() const override { return true; } |
103 | const char* renderName() const override; |
104 | void addFragmentToThread(RenderFragmentContainer*) override; |
105 | void willBeRemovedFromTree() override; |
106 | void fragmentedFlowDescendantBoxLaidOut(RenderBox*) override; |
107 | LogicalExtentComputedValues computeLogicalHeight(LayoutUnit logicalHeight, LayoutUnit logicalTop) const override; |
108 | LayoutUnit initialLogicalWidth() const override; |
109 | void setPageBreak(const RenderBlock*, LayoutUnit offset, LayoutUnit spaceShortage) override; |
110 | void updateMinimumPageHeight(const RenderBlock*, LayoutUnit offset, LayoutUnit minHeight) override; |
111 | RenderFragmentContainer* fragmentAtBlockOffset(const RenderBox*, LayoutUnit, bool extendLastFragment = false) const override; |
112 | void setFragmentRangeForBox(const RenderBox&, RenderFragmentContainer*, RenderFragmentContainer*) override; |
113 | bool addForcedFragmentBreak(const RenderBlock*, LayoutUnit, RenderBox* breakChild, bool isBefore, LayoutUnit* offsetBreakAdjustment = 0) override; |
114 | bool isPageLogicalHeightKnown() const override; |
115 | |
116 | private: |
117 | std::unique_ptr<SpannerMap> m_spannerMap; |
118 | |
119 | // The last set we worked on. It's not to be used as the "current set". The concept of a |
120 | // "current set" is difficult, since layout may jump back and forth in the tree, due to wrong |
121 | // top location estimates (due to e.g. margin collapsing), and possibly for other reasons. |
122 | RenderMultiColumnSet* m_lastSetWorkedOn; |
123 | |
124 | unsigned m_columnCount; // The default column count/width that are based off our containing block width. These values represent only the default, |
125 | LayoutUnit m_columnWidth; // A multi-column block that is split across variable width pages or fragments will have different column counts and widths in each. These values will be cached (eventually) for multi-column blocks. |
126 | |
127 | LayoutUnit m_columnHeightAvailable; // Total height available to columns, or 0 if auto. |
128 | bool m_inLayout; // Set while we're laying out the flow thread, during which colum set heights are unknown. |
129 | bool m_inBalancingPass; // Guard to avoid re-entering column balancing. |
130 | bool m_needsHeightsRecalculation; |
131 | |
132 | bool m_progressionIsInline; |
133 | bool m_progressionIsReversed; |
134 | }; |
135 | |
136 | } // namespace WebCore |
137 | |
138 | SPECIALIZE_TYPE_TRAITS_RENDER_OBJECT(RenderMultiColumnFlow, isRenderMultiColumnFlow()) |
139 | |