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 27#ifndef RenderMultiColumnFlowThread_h 28#define RenderMultiColumnFlowThread_h 29 30#include "RenderFlowThread.h" 31 32#include <wtf/HashMap.h> 33 34namespace WebCore { 35 36class RenderMultiColumnSet; 37class RenderMultiColumnSpannerPlaceholder; 38 39class RenderMultiColumnFlowThread final : public RenderFlowThread { 40public: 41 RenderMultiColumnFlowThread(Document&, PassRef<RenderStyle>); 42 ~RenderMultiColumnFlowThread(); 43 44 virtual bool isRenderMultiColumnFlowThread() const override { return true; } 45 46 virtual void removeFlowChildInfo(RenderObject*) override; 47 48 RenderBlockFlow* multiColumnBlockFlow() const { return toRenderBlockFlow(parent()); } 49 50 RenderMultiColumnSet* firstMultiColumnSet() const; 51 RenderMultiColumnSet* lastMultiColumnSet() const; 52 RenderBox* firstColumnSetOrSpanner() const; 53 static RenderBox* nextColumnSetOrSpannerSiblingOf(const RenderBox*); 54 static RenderBox* previousColumnSetOrSpannerSiblingOf(const RenderBox*); 55 56 RenderMultiColumnSpannerPlaceholder* findColumnSpannerPlaceholder(RenderBox* spanner) const { return m_spannerMap.get(spanner); } 57 58 virtual void layout() override final; 59 60 // Find the set inside which the specified renderer would be rendered. 61 RenderMultiColumnSet* findSetRendering(RenderObject*) const; 62 63 // Populate the flow thread with what's currently its siblings. Called when a regular block 64 // becomes a multicol container. 65 void populate(); 66 67 // Empty the flow thread by moving everything to the parent. Remove all multicol specific 68 // renderers. Then destroy the flow thread. Called when a multicol container becomes a regular 69 // block. 70 void evacuateAndDestroy(); 71 72 unsigned columnCount() const { return m_columnCount; } 73 LayoutUnit columnWidth() const { return m_columnWidth; } 74 LayoutUnit columnHeightAvailable() const { return m_columnHeightAvailable; } 75 void setColumnHeightAvailable(LayoutUnit available) { m_columnHeightAvailable = available; } 76 bool inBalancingPass() const { return m_inBalancingPass; } 77 void setInBalancingPass(bool balancing) { m_inBalancingPass = balancing; } 78 bool needsHeightsRecalculation() const { return m_needsHeightsRecalculation; } 79 void setNeedsHeightsRecalculation(bool recalculate) { m_needsHeightsRecalculation = recalculate; } 80 81 bool shouldRelayoutForPagination() const { return !m_inBalancingPass && m_needsHeightsRecalculation; } 82 83 void setColumnCountAndWidth(unsigned count, LayoutUnit width) 84 { 85 m_columnCount = count; 86 m_columnWidth = width; 87 } 88 89 bool progressionIsInline() const { return m_progressionIsInline; } 90 void setProgressionIsInline(bool progressionIsInline) { m_progressionIsInline = progressionIsInline; } 91 92 bool progressionIsReversed() const { return m_progressionIsReversed; } 93 void setProgressionIsReversed(bool reversed) { m_progressionIsReversed = reversed; } 94 95 void computeLineGridPaginationOrigin(LayoutState&) const; 96 97 virtual RenderRegion* mapFromFlowToRegion(TransformState&) const override; 98 99 // This method takes a logical offset and returns a physical translation that can be applied to map 100 // a physical point (corresponding to the logical offset) into the region's physical coordinate space. 101 LayoutSize physicalTranslationOffsetFromFlowToRegion(const RenderRegion*, const LayoutUnit) const; 102 103 // The point is physical, and the result is a physical location within the region. 104 RenderRegion* physicalTranslationFromFlowToRegion(LayoutPoint&) const; 105 106 // This method is the inverse of the previous method and goes from region to flow. 107 LayoutSize physicalTranslationFromRegionToFlow(const RenderMultiColumnSet*, const LayoutPoint&) const; 108 109 virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction) override; 110 111 virtual void mapAbsoluteToLocalPoint(MapCoordinatesFlags, TransformState&) const override; 112 virtual LayoutSize offsetFromContainer(RenderObject*, const LayoutPoint&, bool* offsetDependsOnPoint = nullptr) const override; 113 114 // FIXME: Eventually as column and region flow threads start nesting, this will end up changing. 115 virtual bool shouldCheckColumnBreaks() const override; 116 117private: 118 virtual const char* renderName() const override; 119 virtual void addRegionToThread(RenderRegion*) override; 120 virtual void willBeRemovedFromTree() override; 121 virtual RenderObject* resolveMovedChild(RenderObject* child) const override; 122 virtual void flowThreadDescendantInserted(RenderObject*) override; 123 virtual void flowThreadRelativeWillBeRemoved(RenderObject*) override; 124 virtual void flowThreadDescendantBoxLaidOut(RenderBox*) override; 125 virtual void computeLogicalHeight(LayoutUnit logicalHeight, LayoutUnit logicalTop, LogicalExtentComputedValues&) const override; 126 virtual LayoutUnit initialLogicalWidth() const override; 127 virtual void autoGenerateRegionsToBlockOffset(LayoutUnit) override; 128 virtual void setPageBreak(const RenderBlock*, LayoutUnit offset, LayoutUnit spaceShortage) override; 129 virtual void updateMinimumPageHeight(const RenderBlock*, LayoutUnit offset, LayoutUnit minHeight) override; 130 virtual RenderRegion* regionAtBlockOffset(const RenderBox*, LayoutUnit, bool extendLastRegion = false, RegionAutoGenerationPolicy = AllowRegionAutoGeneration) override; 131 virtual void setRegionRangeForBox(const RenderBox*, RenderRegion*, RenderRegion*) override; 132 virtual bool addForcedRegionBreak(const RenderBlock*, LayoutUnit, RenderBox* breakChild, bool isBefore, LayoutUnit* offsetBreakAdjustment = 0) override; 133 virtual bool isPageLogicalHeightKnown() const override; 134 135private: 136 typedef HashMap<RenderBox*, RenderMultiColumnSpannerPlaceholder*> SpannerMap; 137 SpannerMap m_spannerMap; 138 139 // The last set we worked on. It's not to be used as the "current set". The concept of a 140 // "current set" is difficult, since layout may jump back and forth in the tree, due to wrong 141 // top location estimates (due to e.g. margin collapsing), and possibly for other reasons. 142 RenderMultiColumnSet* m_lastSetWorkedOn; 143 144 unsigned m_columnCount; // The default column count/width that are based off our containing block width. These values represent only the default, 145 LayoutUnit m_columnWidth; // A multi-column block that is split across variable width pages or regions will have different column counts and widths in each. 146 // These values will be cached (eventually) for multi-column blocks. 147 LayoutUnit m_columnHeightAvailable; // Total height available to columns, or 0 if auto. 148 bool m_inLayout; // Set while we're laying out the flow thread, during which colum set heights are unknown. 149 bool m_inBalancingPass; // Guard to avoid re-entering column balancing. 150 bool m_needsHeightsRecalculation; 151 152 bool m_progressionIsInline; 153 bool m_progressionIsReversed; 154 bool m_beingEvacuated; 155 156 static bool gShiftingSpanner; 157}; 158 159RENDER_OBJECT_TYPE_CASTS(RenderMultiColumnFlowThread, isRenderMultiColumnFlowThread()) 160 161} // namespace WebCore 162 163#endif // RenderMultiColumnFlowThread_h 164 165