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