| 1 | /* |
| 2 | * Copyright (C) 2011 Adobe Systems Incorporated. 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 | * |
| 8 | * 1. Redistributions of source code must retain the above |
| 9 | * copyright notice, this list of conditions and the following |
| 10 | * disclaimer. |
| 11 | * 2. Redistributions in binary form must reproduce the above |
| 12 | * copyright notice, this list of conditions and the following |
| 13 | * disclaimer in the documentation and/or other materials |
| 14 | * provided with the distribution. |
| 15 | * |
| 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER “AS IS” AND ANY |
| 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 19 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE |
| 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, |
| 21 | * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 22 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 23 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR |
| 25 | * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF |
| 26 | * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 27 | * SUCH DAMAGE. |
| 28 | */ |
| 29 | |
| 30 | #pragma once |
| 31 | |
| 32 | #include "LayerFragment.h" |
| 33 | #include "RenderBlockFlow.h" |
| 34 | #include "VisiblePosition.h" |
| 35 | #include <memory> |
| 36 | |
| 37 | namespace WebCore { |
| 38 | |
| 39 | class Element; |
| 40 | class RenderBox; |
| 41 | class RenderBoxFragmentInfo; |
| 42 | class RenderFragmentedFlow; |
| 43 | |
| 44 | class RenderFragmentContainer : public RenderBlockFlow { |
| 45 | WTF_MAKE_ISO_ALLOCATED(RenderFragmentContainer); |
| 46 | public: |
| 47 | void styleDidChange(StyleDifference, const RenderStyle* oldStyle) override; |
| 48 | |
| 49 | void setFragmentedFlowPortionRect(const LayoutRect& rect) { m_fragmentedFlowPortionRect = rect; } |
| 50 | LayoutRect fragmentedFlowPortionRect() const { return m_fragmentedFlowPortionRect; } |
| 51 | LayoutRect fragmentedFlowPortionOverflowRect(); |
| 52 | |
| 53 | LayoutPoint fragmentedFlowPortionLocation() const; |
| 54 | |
| 55 | virtual void attachFragment(); |
| 56 | virtual void detachFragment(); |
| 57 | |
| 58 | RenderFragmentedFlow* fragmentedFlow() const { return m_fragmentedFlow; } |
| 59 | |
| 60 | // Valid fragments do not create circular dependencies with other flows. |
| 61 | bool isValid() const { return m_isValid; } |
| 62 | void setIsValid(bool valid) { m_isValid = valid; } |
| 63 | |
| 64 | RenderBoxFragmentInfo* renderBoxFragmentInfo(const RenderBox*) const; |
| 65 | RenderBoxFragmentInfo* setRenderBoxFragmentInfo(const RenderBox*, LayoutUnit logicalLeftInset, LayoutUnit logicalRightInset, |
| 66 | bool containingBlockChainIsInset); |
| 67 | std::unique_ptr<RenderBoxFragmentInfo> takeRenderBoxFragmentInfo(const RenderBox*); |
| 68 | void removeRenderBoxFragmentInfo(const RenderBox&); |
| 69 | |
| 70 | void deleteAllRenderBoxFragmentInfo(); |
| 71 | |
| 72 | bool isFirstFragment() const; |
| 73 | bool isLastFragment() const; |
| 74 | virtual bool shouldClipFragmentedFlowContent() const; |
| 75 | |
| 76 | // These methods represent the width and height of a "page" and for a RenderFragmentContainer they are just the |
| 77 | // content width and content height of a fragment. For RenderFragmentContainerSets, however, they will be the width and |
| 78 | // height of a single column or page in the set. |
| 79 | virtual LayoutUnit pageLogicalWidth() const; |
| 80 | virtual LayoutUnit pageLogicalHeight() const; |
| 81 | |
| 82 | LayoutUnit logicalTopOfFragmentedFlowContentRect(const LayoutRect&) const; |
| 83 | LayoutUnit logicalBottomOfFragmentedFlowContentRect(const LayoutRect&) const; |
| 84 | LayoutUnit logicalTopForFragmentedFlowContent() const { return logicalTopOfFragmentedFlowContentRect(fragmentedFlowPortionRect()); }; |
| 85 | LayoutUnit logicalBottomForFragmentedFlowContent() const { return logicalBottomOfFragmentedFlowContentRect(fragmentedFlowPortionRect()); }; |
| 86 | |
| 87 | // This method represents the logical height of the entire flow thread portion used by the fragment or set. |
| 88 | // For RenderFragmentContainers it matches logicalPaginationHeight(), but for sets it is the height of all the pages |
| 89 | // or columns added together. |
| 90 | virtual LayoutUnit logicalHeightOfAllFragmentedFlowContent() const; |
| 91 | |
| 92 | // The top of the nearest page inside the fragment. For RenderFragmentContainers, this is just the logical top of the |
| 93 | // flow thread portion we contain. For sets, we have to figure out the top of the nearest column or |
| 94 | // page. |
| 95 | virtual LayoutUnit pageLogicalTopForOffset(LayoutUnit offset) const; |
| 96 | |
| 97 | // Whether or not this fragment is a set. |
| 98 | virtual bool isRenderFragmentContainerSet() const { return false; } |
| 99 | |
| 100 | virtual void repaintFragmentedFlowContent(const LayoutRect& repaintRect); |
| 101 | |
| 102 | virtual void collectLayerFragments(LayerFragments&, const LayoutRect&, const LayoutRect&) { } |
| 103 | |
| 104 | virtual void adjustFragmentBoundsFromFragmentedFlowPortionRect(LayoutRect& fragmentBounds) const; |
| 105 | |
| 106 | void addLayoutOverflowForBox(const RenderBox*, const LayoutRect&); |
| 107 | void addVisualOverflowForBox(const RenderBox*, const LayoutRect&); |
| 108 | LayoutRect layoutOverflowRectForBox(const RenderBox*); |
| 109 | LayoutRect visualOverflowRectForBox(const RenderBoxModelObject&); |
| 110 | LayoutRect layoutOverflowRectForBoxForPropagation(const RenderBox*); |
| 111 | LayoutRect visualOverflowRectForBoxForPropagation(const RenderBoxModelObject&); |
| 112 | |
| 113 | LayoutRect rectFlowPortionForBox(const RenderBox*, const LayoutRect&) const; |
| 114 | |
| 115 | void setFragmentObjectsFragmentStyle(); |
| 116 | void restoreFragmentObjectsOriginalStyle(); |
| 117 | |
| 118 | bool canHaveChildren() const override { return false; } |
| 119 | bool canHaveGeneratedChildren() const override { return true; } |
| 120 | VisiblePosition positionForPoint(const LayoutPoint&, const RenderFragmentContainer*) override; |
| 121 | |
| 122 | virtual void absoluteQuadsForBoxInFragment(Vector<FloatQuad>&, bool*, const RenderBox*, float, float) { } |
| 123 | |
| 124 | String debugString() const; |
| 125 | |
| 126 | protected: |
| 127 | RenderFragmentContainer(Element&, RenderStyle&&, RenderFragmentedFlow*); |
| 128 | RenderFragmentContainer(Document&, RenderStyle&&, RenderFragmentedFlow*); |
| 129 | |
| 130 | void ensureOverflowForBox(const RenderBox*, RefPtr<RenderOverflow>&, bool); |
| 131 | |
| 132 | void computePreferredLogicalWidths() override; |
| 133 | void computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth) const override; |
| 134 | |
| 135 | enum OverflowType { |
| 136 | LayoutOverflow = 0, |
| 137 | VisualOverflow |
| 138 | }; |
| 139 | |
| 140 | LayoutRect overflowRectForFragmentedFlowPortion(const LayoutRect& fragmentedFlowPortionRect, bool isFirstPortion, bool isLastPortion, OverflowType); |
| 141 | void repaintFragmentedFlowContentRectangle(const LayoutRect& repaintRect, const LayoutRect& fragmentedFlowPortionRect, const LayoutPoint& fragmentLocation, const LayoutRect* fragmentedFlowPortionClipRect = 0); |
| 142 | |
| 143 | void computeOverflowFromFragmentedFlow(); |
| 144 | |
| 145 | private: |
| 146 | bool isRenderFragmentContainer() const final { return true; } |
| 147 | const char* renderName() const override { return "RenderFragmentContainer" ; } |
| 148 | |
| 149 | void insertedIntoTree() override; |
| 150 | void willBeRemovedFromTree() override; |
| 151 | |
| 152 | virtual void installFragmentedFlow(); |
| 153 | |
| 154 | LayoutPoint mapFragmentPointIntoFragmentedFlowCoordinates(const LayoutPoint&); |
| 155 | |
| 156 | protected: |
| 157 | RenderFragmentedFlow* m_fragmentedFlow; |
| 158 | |
| 159 | private: |
| 160 | LayoutRect m_fragmentedFlowPortionRect; |
| 161 | |
| 162 | // This map holds unique information about a block that is split across fragments. |
| 163 | // A RenderBoxFragmentInfo* tells us about any layout information for a RenderBox that |
| 164 | // is unique to the fragment. For now it just holds logical width information for RenderBlocks, but eventually |
| 165 | // it will also hold a custom style for any box (for fragment styling). |
| 166 | typedef HashMap<const RenderBox*, std::unique_ptr<RenderBoxFragmentInfo>> RenderBoxFragmentInfoMap; |
| 167 | RenderBoxFragmentInfoMap m_renderBoxFragmentInfo; |
| 168 | |
| 169 | bool m_isValid : 1; |
| 170 | }; |
| 171 | |
| 172 | class CurrentRenderFragmentContainerMaintainer { |
| 173 | WTF_MAKE_NONCOPYABLE(CurrentRenderFragmentContainerMaintainer); |
| 174 | public: |
| 175 | CurrentRenderFragmentContainerMaintainer(RenderFragmentContainer&); |
| 176 | ~CurrentRenderFragmentContainerMaintainer(); |
| 177 | |
| 178 | RenderFragmentContainer& fragment() const { return m_fragment; } |
| 179 | private: |
| 180 | RenderFragmentContainer& m_fragment; |
| 181 | }; |
| 182 | |
| 183 | } // namespace WebCore |
| 184 | |
| 185 | SPECIALIZE_TYPE_TRAITS_RENDER_OBJECT(RenderFragmentContainer, isRenderFragmentContainer()) |
| 186 | |