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 21 #ifndef RootInlineBox_h 22 #define RootInlineBox_h 23 24 #include "BidiContext.h" 25 #include "InlineFlowBox.h" 26 27 namespace WebCore { 28 29 class EllipsisBox; 30 class HitTestResult; 31 32 struct BidiStatus; 33 struct GapRects; 34 35 class RootInlineBox : public InlineFlowBox { 36 public: 37 RootInlineBox(RenderBlock* block); 38 39 virtual void destroy(RenderArena*); 40 41 virtual bool isRootInlineBox() const { return true; } 42 43 void detachEllipsisBox(RenderArena*); 44 45 RootInlineBox* nextRootBox() const { return static_cast<RootInlineBox*>(m_nextLineBox); } 46 RootInlineBox* prevRootBox() const { return static_cast<RootInlineBox*>(m_prevLineBox); } 47 48 virtual void adjustPosition(float dx, float dy); 49 50 int lineTop() const { return m_lineTop; } 51 int lineBottom() const { return m_lineBottom; } 52 53 int paginationStrut() const { return m_paginationStrut; } 54 void setPaginationStrut(int s) { m_paginationStrut = s; } 55 56 int selectionTop() const; 57 int selectionBottom() const; 58 int selectionHeight() const { return max(0, selectionBottom() - selectionTop()); } 59 60 int alignBoxesInBlockDirection(int heightOfBlock, GlyphOverflowAndFallbackFontsMap&, VerticalPositionCache&); 61 void setLineTopBottomPositions(int top, int bottom); 62 63 virtual RenderLineBoxList* rendererLineBoxes() const; 64 65 RenderObject* lineBreakObj() const { return m_lineBreakObj; } 66 BidiStatus lineBreakBidiStatus() const; 67 void setLineBreakInfo(RenderObject*, unsigned breakPos, const BidiStatus&); 68 69 unsigned lineBreakPos() const { return m_lineBreakPos; } 70 void setLineBreakPos(unsigned p) { m_lineBreakPos = p; } 71 72 int blockLogicalHeight() const { return m_blockLogicalHeight; } 73 void setBlockLogicalHeight(int h) { m_blockLogicalHeight = h; } 74 75 bool endsWithBreak() const { return m_endsWithBreak; } 76 void setEndsWithBreak(bool b) { m_endsWithBreak = b; } 77 78 void childRemoved(InlineBox* box); 79 80 bool lineCanAccommodateEllipsis(bool ltr, int blockEdge, int lineBoxEdge, int ellipsisWidth); 81 void placeEllipsis(const AtomicString& ellipsisStr, bool ltr, float blockLeftEdge, float blockRightEdge, float ellipsisWidth, InlineBox* markupBox = 0); 82 virtual float placeEllipsisBox(bool ltr, float blockLeftEdge, float blockRightEdge, float ellipsisWidth, bool& foundBox); 83 84 EllipsisBox* ellipsisBox() const; 85 86 void paintEllipsisBox(PaintInfo&, int tx, int ty, int lineTop, int lineBottom) const; 87 88 virtual void clearTruncation(); 89 90 virtual int baselinePosition(FontBaseline baselineType) const { return boxModelObject()->baselinePosition(baselineType, m_firstLine, isHorizontal() ? HorizontalLine : VerticalLine, PositionOfInteriorLineBoxes); } 91 virtual int lineHeight() const { return boxModelObject()->lineHeight(m_firstLine, isHorizontal() ? HorizontalLine : VerticalLine, PositionOfInteriorLineBoxes); } 92 93 #if PLATFORM(MAC) 94 void addHighlightOverflow(); 95 void paintCustomHighlight(PaintInfo&, int tx, int ty, const AtomicString& highlightType); 96 #endif 97 98 virtual void paint(PaintInfo&, int tx, int ty, int lineTop, int lineBottom); 99 virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, int x, int y, int tx, int ty, int lineTop, int lineBottom); 100 101 bool hasSelectedChildren() const { return m_hasSelectedChildrenOrCanHaveLeadingExpansion; } 102 void setHasSelectedChildren(bool hasSelectedChildren) { m_hasSelectedChildrenOrCanHaveLeadingExpansion = hasSelectedChildren; } 103 104 virtual RenderObject::SelectionState selectionState(); 105 InlineBox* firstSelectedBox(); 106 InlineBox* lastSelectedBox(); 107 108 GapRects lineSelectionGap(RenderBlock* rootBlock, const IntPoint& rootBlockPhysicalPosition, const IntSize& offsetFromRootBlock, int selTop, int selHeight, const PaintInfo*); 109 110 RenderBlock* block() const; 111 112 InlineBox* closestLeafChildForLogicalLeftPosition(int, bool onlyEditableLeaves = false); 113 114 void appendFloat(RenderBox* floatingBox) 115 { 116 ASSERT(!isDirty()); 117 if (m_floats) 118 m_floats->append(floatingBox); 119 else 120 m_floats= adoptPtr(new Vector<RenderBox*>(1, floatingBox)); 121 } 122 123 Vector<RenderBox*>* floatsPtr() { ASSERT(!isDirty()); return m_floats.get(); } 124 125 virtual void extractLineBoxFromRenderObject(); 126 virtual void attachLineBoxToRenderObject(); 127 virtual void removeLineBoxFromRenderObject(); 128 129 FontBaseline baselineType() const { return static_cast<FontBaseline>(m_baselineType); } 130 131 bool hasAnnotationsBefore() const { return m_hasAnnotationsBefore; } 132 bool hasAnnotationsAfter() const { return m_hasAnnotationsAfter; } 133 134 IntRect paddedLayoutOverflowRect(int endPadding) const; 135 136 void ascentAndDescentForBox(InlineBox*, GlyphOverflowAndFallbackFontsMap&, int& ascent, int& descent, bool& affectsAscent, bool& affectsDescent) const; 137 int verticalPositionForBox(InlineBox*, VerticalPositionCache&); 138 bool includeLeadingForBox(InlineBox*) const; 139 bool includeFontForBox(InlineBox*) const; 140 bool includeGlyphsForBox(InlineBox*) const; 141 bool includeMarginForBox(InlineBox*) const; 142 bool fitsToGlyphs() const; 143 bool includesRootLineBoxFontOrLeading() const; 144 145 int logicalTopVisualOverflow() const 146 { 147 return InlineFlowBox::logicalTopVisualOverflow(lineTop()); 148 } 149 int logicalBottomVisualOverflow() const 150 { 151 return InlineFlowBox::logicalBottomVisualOverflow(lineBottom()); 152 } 153 int logicalTopLayoutOverflow() const 154 { 155 return InlineFlowBox::logicalTopLayoutOverflow(lineTop()); 156 } 157 int logicalBottomLayoutOverflow() const 158 { 159 return InlineFlowBox::logicalBottomLayoutOverflow(lineBottom()); 160 } 161 162 Node* getLogicalStartBoxWithNode(InlineBox*&) const; 163 Node* getLogicalEndBoxWithNode(InlineBox*&) const; 164 private: 165 bool hasEllipsisBox() const { return m_hasEllipsisBoxOrHyphen; } 166 void setHasEllipsisBox(bool hasEllipsisBox) { m_hasEllipsisBoxOrHyphen = hasEllipsisBox; } 167 168 int beforeAnnotationsAdjustment() const; 169 170 // Where this line ended. The exact object and the position within that object are stored so that 171 // we can create an InlineIterator beginning just after the end of this line. 172 RenderObject* m_lineBreakObj; 173 unsigned m_lineBreakPos; 174 RefPtr<BidiContext> m_lineBreakContext; 175 176 int m_lineTop; 177 int m_lineBottom; 178 179 int m_paginationStrut; 180 181 // Floats hanging off the line are pushed into this vector during layout. It is only 182 // good for as long as the line has not been marked dirty. 183 OwnPtr<Vector<RenderBox*> > m_floats; 184 185 // The logical height of the block at the end of this line. This is where the next line starts. 186 int m_blockLogicalHeight; 187 188 // Whether or not this line uses alphabetic or ideographic baselines by default. 189 unsigned m_baselineType : 1; // FontBaseline 190 191 // If the line contains any ruby runs, then this will be true. 192 bool m_hasAnnotationsBefore : 1; 193 bool m_hasAnnotationsAfter : 1; 194 195 WTF::Unicode::Direction m_lineBreakBidiStatusEor : 5; 196 WTF::Unicode::Direction m_lineBreakBidiStatusLastStrong : 5; 197 WTF::Unicode::Direction m_lineBreakBidiStatusLast : 5; 198 }; 199 200 inline void RootInlineBox::setLineTopBottomPositions(int top, int bottom) 201 { 202 m_lineTop = top; 203 m_lineBottom = bottom; 204 } 205 206 } // namespace WebCore 207 208 #endif // RootInlineBox_h 209