]> git.saurik.com Git - iphone-api.git/blob - WebCore/RenderText.h
Adding the WebCore headers (for Cydget).
[iphone-api.git] / WebCore / RenderText.h
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 #include "SelectionRect.h"
28 #include "Timer.h"
29
30 namespace WebCore {
31
32 class InlineTextBox;
33 class StringImpl;
34
35 class RenderText : public RenderObject {
36 public:
37 RenderText(Node*, PassRefPtr<StringImpl>);
38 #ifndef NDEBUG
39 virtual ~RenderText();
40 #endif
41
42 virtual const char* renderName() const;
43
44 virtual bool isTextFragment() const;
45 virtual bool isWordBreak() const;
46
47 virtual PassRefPtr<StringImpl> originalText() const;
48
49 void extractTextBox(InlineTextBox*);
50 void attachTextBox(InlineTextBox*);
51 void removeTextBox(InlineTextBox*);
52
53 virtual void destroy();
54
55 StringImpl* text() const { return m_text.get(); }
56
57 virtual InlineBox* createInlineBox(bool makePlaceHolderBox, bool isRootLineBox, bool isOnlyRun = false);
58 virtual InlineTextBox* createInlineTextBox();
59 virtual void dirtyLineBoxes(bool fullLayout, bool isRootInlineBox = false);
60
61 virtual void absoluteRects(Vector<IntRect>&, int tx, int ty, bool topLevel = true);
62 virtual void addLineBoxRects(Vector<IntRect>&, unsigned startOffset = 0, unsigned endOffset = UINT_MAX, bool useSelectionHeight = false);
63 virtual void collectSelectionRects(Vector<SelectionRect>&, unsigned startOffset = 0, unsigned endOffset = UINT_MAX);
64
65 virtual void absoluteQuads(Vector<FloatQuad>&, bool topLevel = true);
66 virtual void collectAbsoluteLineBoxQuads(Vector<FloatQuad>&, unsigned startOffset = 0, unsigned endOffset = UINT_MAX, bool useSelectionHeight = false);
67
68 virtual VisiblePosition positionForCoordinates(int x, int y);
69
70 const UChar* characters() const { return m_text->characters(); }
71 unsigned textLength() const { return m_text->length(); } // non virtual implementation of length()
72 virtual void position(InlineBox*);
73
74 virtual unsigned width(unsigned from, unsigned len, const Font&, int xPos) const;
75 virtual unsigned width(unsigned from, unsigned len, int xPos, bool firstLine = false) const;
76
77 virtual int lineHeight(bool firstLine, bool isRootLineBox = false) const;
78
79 virtual int minPrefWidth() const;
80 virtual int maxPrefWidth() const;
81
82 void trimmedPrefWidths(int leadWidth,
83 int& beginMinW, bool& beginWS,
84 int& endMinW, bool& endWS,
85 bool& hasBreakableChar, bool& hasBreak,
86 int& beginMaxW, int& endMaxW,
87 int& minW, int& maxW, bool& stripFrontSpaces);
88
89 IntRect linesBoundingBox() const;
90
91 int firstRunX() const;
92 int firstRunY() const;
93
94 virtual int verticalPositionHint(bool firstLine) const;
95
96 void setText(PassRefPtr<StringImpl>, bool force = false);
97 void setTextWithOffset(PassRefPtr<StringImpl>, unsigned offset, unsigned len, bool force = false);
98
99 virtual bool canBeSelectionLeaf() const { return true; }
100 virtual SelectionState selectionState() const { return static_cast<SelectionState>(m_selectionState); }
101 virtual void setSelectionState(SelectionState s);
102 virtual IntRect selectionRectForRepaint(RenderBox* repaintContainer, bool clipToVisibleContent = true);
103 virtual IntRect localCaretRect(InlineBox*, int caretOffset, int* extraWidthToEndOfLine = 0);
104
105 virtual int marginLeft() const { return style()->marginLeft().calcMinValue(0); }
106 virtual int marginRight() const { return style()->marginRight().calcMinValue(0); }
107
108 virtual IntRect clippedOverflowRectForRepaint(RenderBox* repaintContainer);
109
110 InlineTextBox* firstTextBox() const { return m_firstTextBox; }
111 InlineTextBox* lastTextBox() const { return m_lastTextBox; }
112
113 virtual int caretMinOffset() const;
114 virtual int caretMaxOffset() const;
115 virtual unsigned caretMaxRenderedOffset() const;
116
117 virtual int previousOffset(int current) const;
118 virtual int nextOffset(int current) const;
119
120 bool containsReversedText() const { return m_containsReversedText; }
121
122 bool isSecure() { return style()->textSecurity() != TSNONE; }
123 void momentarilyRevealLastCharacter();
124 void secureLastCharacter();
125 void secureLastCharacter(Timer<RenderText> * aTimer);
126
127 InlineTextBox* findNextInlineTextBox(int offset, int& pos) const;
128
129 bool allowTabs() const { return !style()->collapseWhiteSpace(); }
130
131 void checkConsistency() const;
132
133 float candidateComputedTextSize() const { return m_candidateComputedTextSize; }
134 void setCandidateComputedTextSize(float s) { m_candidateComputedTextSize = s; }
135
136 protected:
137 virtual void styleWillChange(StyleDifference, const RenderStyle*) { }
138 virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle);
139
140 virtual void setTextInternal(PassRefPtr<StringImpl>);
141 virtual void calcPrefWidths(int leadWidth);
142 virtual UChar previousCharacter();
143
144 private:
145 // Make length() private so that callers that have a RenderText*
146 // will use the more efficient textLength() instead, while
147 // callers with a RenderObject* can continue to use length().
148 virtual unsigned length() const { return textLength(); }
149
150 virtual void paint(PaintInfo&, int, int) { ASSERT_NOT_REACHED(); }
151 virtual void layout() { ASSERT_NOT_REACHED(); }
152 virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, int, int, int, int, HitTestAction) { ASSERT_NOT_REACHED(); return false; }
153
154 void deleteTextBoxes();
155 bool containsOnlyWhitespace(unsigned from, unsigned len) const;
156 int widthFromCache(const Font&, int start, int len, int xPos) const;
157 bool isAllASCII() const { return m_isAllASCII; }
158
159 RefPtr<StringImpl> m_text;
160
161 InlineTextBox* m_firstTextBox;
162 InlineTextBox* m_lastTextBox;
163
164 int m_minWidth;
165 int m_maxWidth;
166 int m_beginMinWidth;
167 int m_endMinWidth;
168
169 unsigned m_selectionState : 3; // enums on Windows are signed, so this needs to be unsigned to prevent it turning negative.
170 bool m_hasBreakableChar : 1; // Whether or not we can be broken into multiple lines.
171 bool m_hasBreak : 1; // Whether or not we have a hard break (e.g., <pre> with '\n').
172 bool m_hasTab : 1; // Whether or not we have a variable width tab character (e.g., <pre> with '\t').
173 bool m_hasBeginWS : 1; // Whether or not we begin with WS (only true if we aren't pre)
174 bool m_hasEndWS : 1; // Whether or not we end with WS (only true if we aren't pre)
175 bool m_linesDirty : 1; // This bit indicates that the text run has already dirtied specific
176 // line boxes, and this hint will enable layoutInlineChildren to avoid
177 // just dirtying everything when character data is modified (e.g., appended/inserted
178 // or removed).
179 bool m_containsReversedText : 1;
180 bool m_isAllASCII : 1;
181
182 bool m_shouldSecureLastCharacter : 1;
183 bool m_hasSecureLastCharacterTimer : 1;
184 // FIXME: This should probably be part of the text sizing structures in Document instead. That would save some memory.
185 float m_candidateComputedTextSize;
186 };
187
188 inline RenderText* toRenderText(RenderObject* o)
189 {
190 ASSERT(!o || o->isText());
191 return static_cast<RenderText*>(o);
192 }
193
194 inline const RenderText* toRenderText(const RenderObject* o)
195 {
196 ASSERT(!o || o->isText());
197 return static_cast<const RenderText*>(o);
198 }
199
200 #ifdef NDEBUG
201 inline void RenderText::checkConsistency() const
202 {
203 }
204 #endif
205
206 } // namespace WebCore
207
208 #endif // RenderText_h