RenderRegion.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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. #ifndef RenderRegion_h
  30. #define RenderRegion_h
  31. #include "RenderBlock.h"
  32. #include "StyleInheritedData.h"
  33. namespace WebCore {
  34. struct LayerFragment;
  35. typedef Vector<LayerFragment, 1> LayerFragments;
  36. class RenderBox;
  37. class RenderBoxRegionInfo;
  38. class RenderFlowThread;
  39. class RenderNamedFlowThread;
  40. class RenderRegion : public RenderBlock {
  41. public:
  42. explicit RenderRegion(Element*, RenderFlowThread*);
  43. virtual bool isRenderRegion() const { return true; }
  44. virtual bool hitTestContents(const HitTestRequest&, HitTestResult&, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction) OVERRIDE;
  45. virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle);
  46. void setFlowThreadPortionRect(const LayoutRect& rect) { m_flowThreadPortionRect = rect; }
  47. LayoutRect flowThreadPortionRect() const { return m_flowThreadPortionRect; }
  48. LayoutRect flowThreadPortionOverflowRect() const;
  49. void attachRegion();
  50. void detachRegion();
  51. RenderNamedFlowThread* parentNamedFlowThread() const { return m_parentNamedFlowThread; }
  52. RenderFlowThread* flowThread() const { return m_flowThread; }
  53. // Valid regions do not create circular dependencies with other flows.
  54. bool isValid() const { return m_isValid; }
  55. void setIsValid(bool valid) { m_isValid = valid; }
  56. bool hasCustomRegionStyle() const { return m_hasCustomRegionStyle; }
  57. void setHasCustomRegionStyle(bool hasCustomRegionStyle) { m_hasCustomRegionStyle = hasCustomRegionStyle; }
  58. RenderBoxRegionInfo* renderBoxRegionInfo(const RenderBox*) const;
  59. RenderBoxRegionInfo* setRenderBoxRegionInfo(const RenderBox*, LayoutUnit logicalLeftInset, LayoutUnit logicalRightInset,
  60. bool containingBlockChainIsInset);
  61. PassOwnPtr<RenderBoxRegionInfo> takeRenderBoxRegionInfo(const RenderBox*);
  62. void removeRenderBoxRegionInfo(const RenderBox*);
  63. void deleteAllRenderBoxRegionInfo();
  64. bool isFirstRegion() const;
  65. bool isLastRegion() const;
  66. void clearObjectStyleInRegion(const RenderObject*);
  67. enum RegionState {
  68. RegionUndefined,
  69. RegionEmpty,
  70. RegionFit,
  71. RegionOverset
  72. };
  73. RegionState regionState() const { return isValid() ? m_regionState : RegionUndefined; }
  74. void setRegionState(RegionState regionState) { m_regionState = regionState; }
  75. // These methods represent the width and height of a "page" and for a RenderRegion they are just the
  76. // content width and content height of a region. For RenderRegionSets, however, they will be the width and
  77. // height of a single column or page in the set.
  78. virtual LayoutUnit pageLogicalWidth() const;
  79. virtual LayoutUnit pageLogicalHeight() const;
  80. LayoutUnit maxPageLogicalHeight() const;
  81. LayoutUnit logicalTopOfFlowThreadContentRect(const LayoutRect&) const;
  82. LayoutUnit logicalBottomOfFlowThreadContentRect(const LayoutRect&) const;
  83. LayoutUnit logicalTopForFlowThreadContent() const { return logicalTopOfFlowThreadContentRect(flowThreadPortionRect()); };
  84. LayoutUnit logicalBottomForFlowThreadContent() const { return logicalBottomOfFlowThreadContentRect(flowThreadPortionRect()); };
  85. void getRanges(Vector<RefPtr<Range> >&) const;
  86. // This method represents the logical height of the entire flow thread portion used by the region or set.
  87. // For RenderRegions it matches logicalPaginationHeight(), but for sets it is the height of all the pages
  88. // or columns added together.
  89. virtual LayoutUnit logicalHeightOfAllFlowThreadContent() const;
  90. bool hasAutoLogicalHeight() const { return m_hasAutoLogicalHeight; }
  91. virtual void updateLogicalHeight() OVERRIDE;
  92. // The top of the nearest page inside the region. For RenderRegions, 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. virtual void expandToEncompassFlowThreadContentsIfNeeded() { };
  97. // Whether or not this region is a set.
  98. virtual bool isRenderRegionSet() const { return false; }
  99. virtual void repaintFlowThreadContent(const LayoutRect& repaintRect, bool immediate) const;
  100. virtual void collectLayerFragments(LayerFragments&, const LayoutRect&, const LayoutRect&) { }
  101. protected:
  102. void setRegionObjectsRegionStyle();
  103. void restoreRegionObjectsOriginalStyle();
  104. virtual void computePreferredLogicalWidths() OVERRIDE;
  105. virtual void computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth) const OVERRIDE;
  106. LayoutRect overflowRectForFlowThreadPortion(const LayoutRect& flowThreadPortionRect, bool isFirstPortion, bool isLastPortion) const;
  107. void repaintFlowThreadContentRectangle(const LayoutRect& repaintRect, bool immediate, const LayoutRect& flowThreadPortionRect,
  108. const LayoutRect& flowThreadPortionOverflowRect, const LayoutPoint& regionLocation) const;
  109. virtual bool shouldHaveAutoLogicalHeight() const;
  110. private:
  111. virtual const char* renderName() const { return "RenderRegion"; }
  112. virtual bool canHaveChildren() const OVERRIDE { return false; }
  113. virtual bool canHaveGeneratedChildren() const OVERRIDE { return true; }
  114. virtual void insertedIntoTree() OVERRIDE;
  115. virtual void willBeRemovedFromTree() OVERRIDE;
  116. virtual void layoutBlock(bool relayoutChildren, LayoutUnit pageLogicalHeight = 0) OVERRIDE;
  117. virtual void paintObject(PaintInfo&, const LayoutPoint&) OVERRIDE;
  118. virtual void installFlowThread();
  119. PassRefPtr<RenderStyle> computeStyleInRegion(const RenderObject*);
  120. void computeChildrenStyleInRegion(const RenderObject*);
  121. void setObjectStyleInRegion(RenderObject*, PassRefPtr<RenderStyle>, bool objectRegionStyleCached);
  122. void checkRegionStyle();
  123. void updateRegionHasAutoLogicalHeightFlag();
  124. void incrementAutoLogicalHeightCount();
  125. void decrementAutoLogicalHeightCount();
  126. protected:
  127. RenderFlowThread* m_flowThread;
  128. private:
  129. // If this RenderRegion is displayed as part of another named flow,
  130. // we need to create a dependency tree, so that layout of the
  131. // regions is always done before the regions themselves.
  132. RenderNamedFlowThread* m_parentNamedFlowThread;
  133. LayoutRect m_flowThreadPortionRect;
  134. // This map holds unique information about a block that is split across regions.
  135. // A RenderBoxRegionInfo* tells us about any layout information for a RenderBox that
  136. // is unique to the region. For now it just holds logical width information for RenderBlocks, but eventually
  137. // it will also hold a custom style for any box (for region styling).
  138. typedef HashMap<const RenderBox*, OwnPtr<RenderBoxRegionInfo> > RenderBoxRegionInfoMap;
  139. RenderBoxRegionInfoMap m_renderBoxRegionInfo;
  140. struct ObjectRegionStyleInfo {
  141. // Used to store the original style of the object in region
  142. // so that the original style is properly restored after paint.
  143. // Also used to store computed style of the object in region between
  144. // region paintings, so that the style in region is computed only
  145. // when necessary.
  146. RefPtr<RenderStyle> style;
  147. // True if the computed style in region is cached.
  148. bool cached;
  149. };
  150. typedef HashMap<const RenderObject*, ObjectRegionStyleInfo > RenderObjectRegionStyleMap;
  151. RenderObjectRegionStyleMap m_renderObjectRegionStyle;
  152. bool m_isValid : 1;
  153. bool m_hasCustomRegionStyle : 1;
  154. bool m_hasAutoLogicalHeight : 1;
  155. RegionState m_regionState;
  156. };
  157. inline RenderRegion* toRenderRegion(RenderObject* object)
  158. {
  159. ASSERT_WITH_SECURITY_IMPLICATION(!object || object->isRenderRegion());
  160. return static_cast<RenderRegion*>(object);
  161. }
  162. inline const RenderRegion* toRenderRegion(const RenderObject* object)
  163. {
  164. ASSERT_WITH_SECURITY_IMPLICATION(!object || object->isRenderRegion());
  165. return static_cast<const RenderRegion*>(object);
  166. }
  167. // This will catch anyone doing an unnecessary cast.
  168. void toRenderRegion(const RenderRegion*);
  169. } // namespace WebCore
  170. #endif // RenderRegion_h