RootInlineBox.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. /*
  2. * Copyright (C) 2003, 2006, 2007, 2008 Apple Inc. All rights reserved.
  3. *
  4. * This library is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Library General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2 of the License, or (at your option) any later version.
  8. *
  9. * This library is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Library General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Library General Public License
  15. * along with this library; see the file COPYING.LIB. If not, write to
  16. * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  17. * Boston, MA 02110-1301, USA.
  18. *
  19. */
  20. #ifndef RootInlineBox_h
  21. #define RootInlineBox_h
  22. #include "BidiContext.h"
  23. #include "InlineFlowBox.h"
  24. namespace WebCore {
  25. class EllipsisBox;
  26. class HitTestResult;
  27. class LogicalSelectionOffsetCaches;
  28. class RenderRegion;
  29. struct BidiStatus;
  30. struct GapRects;
  31. class RootInlineBox : public InlineFlowBox {
  32. public:
  33. explicit RootInlineBox(RenderBlock*);
  34. virtual void destroy(RenderArena*) FINAL;
  35. virtual bool isRootInlineBox() const FINAL { return true; }
  36. void detachEllipsisBox(RenderArena*);
  37. RootInlineBox* nextRootBox() const { return static_cast<RootInlineBox*>(m_nextLineBox); }
  38. RootInlineBox* prevRootBox() const { return static_cast<RootInlineBox*>(m_prevLineBox); }
  39. virtual void adjustPosition(float dx, float dy) FINAL;
  40. LayoutUnit lineTop() const { return m_lineTop; }
  41. LayoutUnit lineBottom() const { return m_lineBottom; }
  42. LayoutUnit lineTopWithLeading() const { return m_lineTopWithLeading; }
  43. LayoutUnit lineBottomWithLeading() const { return m_lineBottomWithLeading; }
  44. LayoutUnit paginationStrut() const { return m_fragmentationData ? m_fragmentationData->m_paginationStrut : LayoutUnit(0); }
  45. void setPaginationStrut(LayoutUnit strut) { ensureLineFragmentationData()->m_paginationStrut = strut; }
  46. bool isFirstAfterPageBreak() const { return m_fragmentationData ? m_fragmentationData->m_isFirstAfterPageBreak : false; }
  47. void setIsFirstAfterPageBreak(bool isFirstAfterPageBreak) { ensureLineFragmentationData()->m_isFirstAfterPageBreak = isFirstAfterPageBreak; }
  48. LayoutUnit paginatedLineWidth() const { return m_fragmentationData ? m_fragmentationData->m_paginatedLineWidth : LayoutUnit(0); }
  49. void setPaginatedLineWidth(LayoutUnit width) { ensureLineFragmentationData()->m_paginatedLineWidth = width; }
  50. RenderRegion* containingRegion() const;
  51. void setContainingRegion(RenderRegion*);
  52. LayoutUnit selectionTop() const;
  53. LayoutUnit selectionBottom() const;
  54. LayoutUnit selectionHeight() const { return max<LayoutUnit>(0, selectionBottom() - selectionTop()); }
  55. LayoutUnit selectionTopAdjustedForPrecedingBlock() const;
  56. LayoutUnit selectionHeightAdjustedForPrecedingBlock() const { return max<LayoutUnit>(0, selectionBottom() - selectionTopAdjustedForPrecedingBlock()); }
  57. int blockDirectionPointInLine() const;
  58. LayoutUnit alignBoxesInBlockDirection(LayoutUnit heightOfBlock, GlyphOverflowAndFallbackFontsMap&, VerticalPositionCache&);
  59. void setLineTopBottomPositions(LayoutUnit top, LayoutUnit bottom, LayoutUnit topWithLeading, LayoutUnit bottomWithLeading)
  60. {
  61. m_lineTop = top;
  62. m_lineBottom = bottom;
  63. m_lineTopWithLeading = topWithLeading;
  64. m_lineBottomWithLeading = bottomWithLeading;
  65. }
  66. virtual RenderLineBoxList* rendererLineBoxes() const FINAL;
  67. RenderObject* lineBreakObj() const { return m_lineBreakObj; }
  68. BidiStatus lineBreakBidiStatus() const;
  69. void setLineBreakInfo(RenderObject*, unsigned breakPos, const BidiStatus&);
  70. unsigned lineBreakPos() const { return m_lineBreakPos; }
  71. void setLineBreakPos(unsigned p) { m_lineBreakPos = p; }
  72. using InlineBox::endsWithBreak;
  73. using InlineBox::setEndsWithBreak;
  74. void childRemoved(InlineBox* box);
  75. bool lineCanAccommodateEllipsis(bool ltr, int blockEdge, int lineBoxEdge, int ellipsisWidth);
  76. // Return the truncatedWidth, the width of the truncated text + ellipsis.
  77. float placeEllipsis(const AtomicString& ellipsisStr, bool ltr, float blockLeftEdge, float blockRightEdge, float ellipsisWidth, InlineBox* markupBox = 0);
  78. // Return the position of the EllipsisBox or -1.
  79. virtual float placeEllipsisBox(bool ltr, float blockLeftEdge, float blockRightEdge, float ellipsisWidth, float &truncatedWidth, bool& foundBox) OVERRIDE FINAL;
  80. using InlineBox::hasEllipsisBox;
  81. EllipsisBox* ellipsisBox() const;
  82. void paintEllipsisBox(PaintInfo&, const LayoutPoint&, LayoutUnit lineTop, LayoutUnit lineBottom) const;
  83. virtual void clearTruncation() OVERRIDE FINAL;
  84. bool isHyphenated() const;
  85. virtual int baselinePosition(FontBaseline baselineType) const FINAL;
  86. virtual LayoutUnit lineHeight() const FINAL;
  87. #if PLATFORM(MAC)
  88. void addHighlightOverflow();
  89. void paintCustomHighlight(PaintInfo&, const LayoutPoint&, const AtomicString& highlightType);
  90. #endif
  91. virtual void paint(PaintInfo&, const LayoutPoint&, LayoutUnit lineTop, LayoutUnit lineBottom);
  92. virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, LayoutUnit lineTop, LayoutUnit lineBottom) OVERRIDE FINAL;
  93. using InlineBox::hasSelectedChildren;
  94. using InlineBox::setHasSelectedChildren;
  95. virtual RenderObject::SelectionState selectionState() FINAL;
  96. InlineBox* firstSelectedBox();
  97. InlineBox* lastSelectedBox();
  98. GapRects lineSelectionGap(RenderBlock* rootBlock, const LayoutPoint& rootBlockPhysicalPosition, const LayoutSize& offsetFromRootBlock,
  99. LayoutUnit selTop, LayoutUnit selHeight, const LogicalSelectionOffsetCaches&, const PaintInfo*);
  100. RenderBlock* block() const;
  101. InlineBox* closestLeafChildForPoint(const IntPoint&, bool onlyEditableLeaves);
  102. InlineBox* closestLeafChildForLogicalLeftPosition(int, bool onlyEditableLeaves = false);
  103. void appendFloat(RenderBox* floatingBox)
  104. {
  105. ASSERT(!isDirty());
  106. if (m_floats)
  107. m_floats->append(floatingBox);
  108. else
  109. m_floats= adoptPtr(new Vector<RenderBox*>(1, floatingBox));
  110. }
  111. Vector<RenderBox*>* floatsPtr() { ASSERT(!isDirty()); return m_floats.get(); }
  112. virtual void extractLineBoxFromRenderObject() FINAL;
  113. virtual void attachLineBoxToRenderObject() FINAL;
  114. virtual void removeLineBoxFromRenderObject() FINAL;
  115. FontBaseline baselineType() const { return static_cast<FontBaseline>(m_baselineType); }
  116. bool hasAnnotationsBefore() const { return m_hasAnnotationsBefore; }
  117. bool hasAnnotationsAfter() const { return m_hasAnnotationsAfter; }
  118. LayoutRect paddedLayoutOverflowRect(LayoutUnit endPadding) const;
  119. void ascentAndDescentForBox(InlineBox*, GlyphOverflowAndFallbackFontsMap&, int& ascent, int& descent, bool& affectsAscent, bool& affectsDescent) const;
  120. LayoutUnit verticalPositionForBox(InlineBox*, VerticalPositionCache&);
  121. bool includeLeadingForBox(InlineBox*) const;
  122. bool includeFontForBox(InlineBox*) const;
  123. bool includeGlyphsForBox(InlineBox*) const;
  124. bool includeMarginForBox(InlineBox*) const;
  125. bool fitsToGlyphs() const;
  126. bool includesRootLineBoxFontOrLeading() const;
  127. LayoutUnit logicalTopVisualOverflow() const
  128. {
  129. return InlineFlowBox::logicalTopVisualOverflow(lineTop());
  130. }
  131. LayoutUnit logicalBottomVisualOverflow() const
  132. {
  133. return InlineFlowBox::logicalBottomVisualOverflow(lineBottom());
  134. }
  135. LayoutUnit logicalTopLayoutOverflow() const
  136. {
  137. return InlineFlowBox::logicalTopLayoutOverflow(lineTop());
  138. }
  139. LayoutUnit logicalBottomLayoutOverflow() const
  140. {
  141. return InlineFlowBox::logicalBottomLayoutOverflow(lineBottom());
  142. }
  143. #if ENABLE(CSS3_TEXT)
  144. // Used to calculate the underline offset for TextUnderlinePositionUnder.
  145. float maxLogicalTop() const;
  146. #endif // CSS3_TEXT
  147. Node* getLogicalStartBoxWithNode(InlineBox*&) const;
  148. Node* getLogicalEndBoxWithNode(InlineBox*&) const;
  149. #ifndef NDEBUG
  150. virtual const char* boxName() const;
  151. #endif
  152. private:
  153. LayoutUnit lineSnapAdjustment(LayoutUnit delta = 0) const;
  154. LayoutUnit beforeAnnotationsAdjustment() const;
  155. struct LineFragmentationData;
  156. LineFragmentationData* ensureLineFragmentationData()
  157. {
  158. if (!m_fragmentationData)
  159. m_fragmentationData = adoptPtr(new LineFragmentationData());
  160. return m_fragmentationData.get();
  161. }
  162. // This folds into the padding at the end of InlineFlowBox on 64-bit.
  163. unsigned m_lineBreakPos;
  164. // Where this line ended. The exact object and the position within that object are stored so that
  165. // we can create an InlineIterator beginning just after the end of this line.
  166. RenderObject* m_lineBreakObj;
  167. RefPtr<BidiContext> m_lineBreakContext;
  168. LayoutUnit m_lineTop;
  169. LayoutUnit m_lineBottom;
  170. LayoutUnit m_lineTopWithLeading;
  171. LayoutUnit m_lineBottomWithLeading;
  172. struct LineFragmentationData {
  173. WTF_MAKE_NONCOPYABLE(LineFragmentationData); WTF_MAKE_FAST_ALLOCATED;
  174. public:
  175. LineFragmentationData()
  176. : m_containingRegion(0)
  177. , m_paginationStrut(0)
  178. , m_paginatedLineWidth(0)
  179. , m_isFirstAfterPageBreak(false)
  180. {
  181. }
  182. // It should not be assumed the |containingRegion| is always valid.
  183. // It can also be 0 if the flow has no region chain.
  184. RenderRegion* m_containingRegion;
  185. LayoutUnit m_paginationStrut;
  186. LayoutUnit m_paginatedLineWidth;
  187. bool m_isFirstAfterPageBreak;
  188. };
  189. OwnPtr<LineFragmentationData> m_fragmentationData;
  190. // Floats hanging off the line are pushed into this vector during layout. It is only
  191. // good for as long as the line has not been marked dirty.
  192. OwnPtr<Vector<RenderBox*> > m_floats;
  193. };
  194. } // namespace WebCore
  195. #endif // RootInlineBox_h