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 virtual InlineBox* createInlineBox(bool makePlaceHolderBox, bool isRootLineBox, bool isOnlyRun = false);
56 virtual InlineTextBox* createInlineTextBox();
57 virtual void dirtyLineBoxes(bool fullLayout, bool isRootInlineBox = false);
58
59 virtual void absoluteRects(Vector<IntRect>&, int tx, int ty, bool topLevel = true);
60 virtual void addLineBoxRects(Vector<IntRect>&, unsigned startOffset = 0, unsigned endOffset = UINT_MAX, bool useSelectionHeight = false);
61
62 virtual void absoluteQuads(Vector<FloatQuad>&, bool topLevel = true);
63 virtual void collectAbsoluteLineBoxQuads(Vector<FloatQuad>&, unsigned startOffset = 0, unsigned endOffset = UINT_MAX, bool useSelectionHeight = false);
64
65 virtual VisiblePosition positionForCoordinates(int x, int y);
66
characters()67 const UChar* characters() const { return m_text->characters(); }
textLength()68 unsigned textLength() const { return m_text->length(); } // non virtual implementation of length()
69 virtual void position(InlineBox*);
70
71 virtual unsigned width(unsigned from, unsigned len, const Font&, int xPos) const;
72 virtual unsigned width(unsigned from, unsigned len, int xPos, bool firstLine = false) const;
73
74 virtual int lineHeight(bool firstLine, bool isRootLineBox = false) const;
75
76 virtual int minPrefWidth() const;
77 virtual int maxPrefWidth() const;
78
79 void trimmedPrefWidths(int leadWidth,
80 int& beginMinW, bool& beginWS,
81 int& endMinW, bool& endWS,
82 bool& hasBreakableChar, bool& hasBreak,
83 int& beginMaxW, int& endMaxW,
84 int& minW, int& maxW, bool& stripFrontSpaces);
85
86 IntRect linesBoundingBox() const;
87
88 int firstRunX() const;
89 int firstRunY() const;
90
91 virtual int verticalPositionHint(bool firstLine) const;
92
93 void setText(PassRefPtr<StringImpl>, bool force = false);
94 void setTextWithOffset(PassRefPtr<StringImpl>, unsigned offset, unsigned len, bool force = false);
95
canBeSelectionLeaf()96 virtual bool canBeSelectionLeaf() const { return true; }
selectionState()97 virtual SelectionState selectionState() const { return static_cast<SelectionState>(m_selectionState); }
98 virtual void setSelectionState(SelectionState s);
99 virtual IntRect selectionRect(bool clipToVisibleContent = true);
100 virtual IntRect localCaretRect(InlineBox*, int caretOffset, int* extraWidthToEndOfLine = 0);
101
marginLeft()102 virtual int marginLeft() const { return style()->marginLeft().calcMinValue(0); }
marginRight()103 virtual int marginRight() const { return style()->marginRight().calcMinValue(0); }
104
105 virtual IntRect clippedOverflowRectForRepaint(RenderBox* repaintContainer);
106
firstTextBox()107 InlineTextBox* firstTextBox() const { return m_firstTextBox; }
lastTextBox()108 InlineTextBox* lastTextBox() const { return m_lastTextBox; }
109
110 virtual int caretMinOffset() const;
111 virtual int caretMaxOffset() const;
112 virtual unsigned caretMaxRenderedOffset() const;
113
114 virtual int previousOffset(int current) const;
115 virtual int nextOffset(int current) const;
116
containsReversedText()117 bool containsReversedText() const { return m_containsReversedText; }
118
119 InlineTextBox* findNextInlineTextBox(int offset, int& pos) const;
120
allowTabs()121 bool allowTabs() const { return !style()->collapseWhiteSpace(); }
122
123 void checkConsistency() const;
124
125 protected:
styleWillChange(RenderStyle::Diff,const RenderStyle *)126 virtual void styleWillChange(RenderStyle::Diff, const RenderStyle*) { }
127 virtual void styleDidChange(RenderStyle::Diff, const RenderStyle* oldStyle);
128
129 virtual void setTextInternal(PassRefPtr<StringImpl>);
130 virtual void calcPrefWidths(int leadWidth);
131 virtual UChar previousCharacter();
132
133 private:
134 // Make length() private so that callers that have a RenderText*
135 // will use the more efficient textLength() instead, while
136 // callers with a RenderObject* can continue to use length().
length()137 virtual unsigned length() const { return textLength(); }
138
paint(PaintInfo &,int,int)139 virtual void paint(PaintInfo&, int, int) { ASSERT_NOT_REACHED(); }
layout()140 virtual void layout() { ASSERT_NOT_REACHED(); }
nodeAtPoint(const HitTestRequest &,HitTestResult &,int,int,int,int,HitTestAction)141 virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, int, int, int, int, HitTestAction) { ASSERT_NOT_REACHED(); return false; }
142
143 void deleteTextBoxes();
144 bool containsOnlyWhitespace(unsigned from, unsigned len) const;
145 int widthFromCache(const Font&, int start, int len, int xPos) const;
isAllASCII()146 bool isAllASCII() const { return m_isAllASCII; }
147
148 RefPtr<StringImpl> m_text;
149
150 InlineTextBox* m_firstTextBox;
151 InlineTextBox* m_lastTextBox;
152
153 int m_minWidth;
154 int m_maxWidth;
155 int m_beginMinWidth;
156 int m_endMinWidth;
157
158 unsigned m_selectionState : 3; // enums on Windows are signed, so this needs to be unsigned to prevent it turning negative.
159 bool m_hasBreakableChar : 1; // Whether or not we can be broken into multiple lines.
160 bool m_hasBreak : 1; // Whether or not we have a hard break (e.g., <pre> with '\n').
161 bool m_hasTab : 1; // Whether or not we have a variable width tab character (e.g., <pre> with '\t').
162 bool m_hasBeginWS : 1; // Whether or not we begin with WS (only true if we aren't pre)
163 bool m_hasEndWS : 1; // Whether or not we end with WS (only true if we aren't pre)
164 bool m_linesDirty : 1; // This bit indicates that the text run has already dirtied specific
165 // line boxes, and this hint will enable layoutInlineChildren to avoid
166 // just dirtying everything when character data is modified (e.g., appended/inserted
167 // or removed).
168 bool m_containsReversedText : 1;
169 bool m_isAllASCII : 1;
170 };
171
toRenderText(RenderObject * o)172 inline RenderText* toRenderText(RenderObject* o)
173 {
174 ASSERT(!o || o->isText());
175 return static_cast<RenderText*>(o);
176 }
177
toRenderText(const RenderObject * o)178 inline const RenderText* toRenderText(const RenderObject* o)
179 {
180 ASSERT(!o || o->isText());
181 return static_cast<const RenderText*>(o);
182 }
183
184 #ifdef NDEBUG
checkConsistency()185 inline void RenderText::checkConsistency() const
186 {
187 }
188 #endif
189
190 } // namespace WebCore
191
192 #endif // RenderText_h
193