1 /*
2 * (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 2000 Dirk Mueller (mueller@kde.org)
4 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20 *
21 */
22
23 #ifndef RenderText_h
24 #define RenderText_h
25
26 #include "RenderObject.h"
27
28 namespace WebCore {
29
30 class InlineTextBox;
31 class StringImpl;
32
33 class RenderText : public RenderObject {
34 public:
35 RenderText(Node*, PassRefPtr<StringImpl>);
36 #ifndef NDEBUG
37 virtual ~RenderText();
38 #endif
39
40 virtual const char* renderName() const;
41
42 virtual bool isTextFragment() const;
43 virtual bool isWordBreak() const;
44
45 virtual PassRefPtr<StringImpl> originalText() const;
46
47 void extractTextBox(InlineTextBox*);
48 void attachTextBox(InlineTextBox*);
49 void removeTextBox(InlineTextBox*);
50
51 virtual void destroy();
52
text()53 StringImpl* text() const { return m_text.get(); }
54
55 InlineTextBox* createInlineTextBox();
56 void dirtyLineBoxes(bool fullLayout);
57
58 virtual void absoluteRects(Vector<IntRect>&, int tx, int ty);
59 void absoluteRectsForRange(Vector<IntRect>&, unsigned startOffset = 0, unsigned endOffset = UINT_MAX, bool useSelectionHeight = false);
60
61 virtual void absoluteQuads(Vector<FloatQuad>&);
62 void absoluteQuadsForRange(Vector<FloatQuad>&, unsigned startOffset = 0, unsigned endOffset = UINT_MAX, bool useSelectionHeight = false);
63
64 virtual VisiblePosition positionForPoint(const IntPoint&);
65
characters()66 const UChar* characters() const { return m_text->characters(); }
textLength()67 unsigned textLength() const { return m_text->length(); } // non virtual implementation of length()
68 void positionLineBox(InlineBox*);
69
70 virtual unsigned width(unsigned from, unsigned len, const Font&, int xPos, HashSet<const SimpleFontData*>* fallbackFonts = 0) const;
71 virtual unsigned width(unsigned from, unsigned len, int xPos, bool firstLine = false, HashSet<const SimpleFontData*>* fallbackFonts = 0) const;
72
73 virtual int lineHeight(bool firstLine, bool isRootLineBox = false) const;
74
75 virtual int minPrefWidth() const;
76 virtual int maxPrefWidth() const;
77
78 void trimmedPrefWidths(int leadWidth,
79 int& beginMinW, bool& beginWS,
80 int& endMinW, bool& endWS,
81 bool& hasBreakableChar, bool& hasBreak,
82 int& beginMaxW, int& endMaxW,
83 int& minW, int& maxW, bool& stripFrontSpaces);
84
85 IntRect linesBoundingBox() const;
86
87 IntPoint firstRunOrigin() const;
88 int firstRunX() const;
89 int firstRunY() const;
90
91 void setText(PassRefPtr<StringImpl>, bool force = false);
92 void setTextWithOffset(PassRefPtr<StringImpl>, unsigned offset, unsigned len, bool force = false);
93
canBeSelectionLeaf()94 virtual bool canBeSelectionLeaf() const { return true; }
95 virtual void setSelectionState(SelectionState s);
96 virtual IntRect selectionRectForRepaint(RenderBoxModelObject* repaintContainer, bool clipToVisibleContent = true);
97 virtual IntRect localCaretRect(InlineBox*, int caretOffset, int* extraWidthToEndOfLine = 0);
98
marginLeft()99 virtual int marginLeft() const { return style()->marginLeft().calcMinValue(0); }
marginRight()100 virtual int marginRight() const { return style()->marginRight().calcMinValue(0); }
101
102 virtual IntRect clippedOverflowRectForRepaint(RenderBoxModelObject* repaintContainer);
103
firstTextBox()104 InlineTextBox* firstTextBox() const { return m_firstTextBox; }
lastTextBox()105 InlineTextBox* lastTextBox() const { return m_lastTextBox; }
106
107 virtual int caretMinOffset() const;
108 virtual int caretMaxOffset() const;
109 virtual unsigned caretMaxRenderedOffset() const;
110
111 virtual int previousOffset(int current) const;
112 virtual int previousOffsetForBackwardDeletion(int current) const;
113 virtual int nextOffset(int current) const;
114
containsReversedText()115 bool containsReversedText() const { return m_containsReversedText; }
116
117 InlineTextBox* findNextInlineTextBox(int offset, int& pos) const;
118
allowTabs()119 bool allowTabs() const { return !style()->collapseWhiteSpace(); }
120
121 void checkConsistency() const;
122
123 virtual void calcPrefWidths(int leadWidth);
124 bool isAllCollapsibleWhitespace();
125
126 protected:
styleWillChange(StyleDifference,const RenderStyle *)127 virtual void styleWillChange(StyleDifference, const RenderStyle*) { }
128 virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle);
129
130 virtual void setTextInternal(PassRefPtr<StringImpl>);
131 virtual UChar previousCharacter();
132
133 virtual InlineTextBox* createTextBox(); // Subclassed by SVG.
134
135 private:
136 void calcPrefWidths(int leadWidth, HashSet<const SimpleFontData*>& fallbackFonts);
137
138 // Make length() private so that callers that have a RenderText*
139 // will use the more efficient textLength() instead, while
140 // callers with a RenderObject* can continue to use length().
length()141 virtual unsigned length() const { return textLength(); }
142
paint(PaintInfo &,int,int)143 virtual void paint(PaintInfo&, int, int) { ASSERT_NOT_REACHED(); }
layout()144 virtual void layout() { ASSERT_NOT_REACHED(); }
nodeAtPoint(const HitTestRequest &,HitTestResult &,int,int,int,int,HitTestAction)145 virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, int, int, int, int, HitTestAction) { ASSERT_NOT_REACHED(); return false; }
146
147 void deleteTextBoxes();
148 bool containsOnlyWhitespace(unsigned from, unsigned len) const;
149 int widthFromCache(const Font&, int start, int len, int xPos, HashSet<const SimpleFontData*>* fallbackFonts) const;
isAllASCII()150 bool isAllASCII() const { return m_isAllASCII; }
151
152 int m_minWidth; // here to minimize padding in 64-bit.
153
154 RefPtr<StringImpl> m_text;
155
156 InlineTextBox* m_firstTextBox;
157 InlineTextBox* m_lastTextBox;
158
159 int m_maxWidth;
160 int m_beginMinWidth;
161 int m_endMinWidth;
162
163 bool m_hasBreakableChar : 1; // Whether or not we can be broken into multiple lines.
164 bool m_hasBreak : 1; // Whether or not we have a hard break (e.g., <pre> with '\n').
165 bool m_hasTab : 1; // Whether or not we have a variable width tab character (e.g., <pre> with '\t').
166 bool m_hasBeginWS : 1; // Whether or not we begin with WS (only true if we aren't pre)
167 bool m_hasEndWS : 1; // Whether or not we end with WS (only true if we aren't pre)
168 bool m_linesDirty : 1; // This bit indicates that the text run has already dirtied specific
169 // line boxes, and this hint will enable layoutInlineChildren to avoid
170 // just dirtying everything when character data is modified (e.g., appended/inserted
171 // or removed).
172 bool m_containsReversedText : 1;
173 bool m_isAllASCII : 1;
174 mutable bool m_knownNotToUseFallbackFonts : 1;
175 };
176
toRenderText(RenderObject * object)177 inline RenderText* toRenderText(RenderObject* object)
178 {
179 ASSERT(!object || object->isText());
180 return static_cast<RenderText*>(object);
181 }
182
toRenderText(const RenderObject * object)183 inline const RenderText* toRenderText(const RenderObject* object)
184 {
185 ASSERT(!object || object->isText());
186 return static_cast<const RenderText*>(object);
187 }
188
189 // This will catch anyone doing an unnecessary cast.
190 void toRenderText(const RenderText*);
191
192 #ifdef NDEBUG
checkConsistency()193 inline void RenderText::checkConsistency() const
194 {
195 }
196 #endif
197
198 } // namespace WebCore
199
200 #endif // RenderText_h
201