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.
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.
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.
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.
26 #include "RenderObject.h"
27 #include "SelectionRect.h"
35 class RenderText
: public RenderObject
{
37 RenderText(Node
*, PassRefPtr
<StringImpl
>);
39 virtual ~RenderText();
42 virtual const char* renderName() const;
44 virtual bool isTextFragment() const;
45 virtual bool isWordBreak() const;
47 virtual PassRefPtr
<StringImpl
> originalText() const;
49 void extractTextBox(InlineTextBox
*);
50 void attachTextBox(InlineTextBox
*);
51 void removeTextBox(InlineTextBox
*);
53 virtual void destroy();
55 StringImpl
* text() const { return m_text
.get(); }
57 virtual InlineBox
* createInlineBox(bool makePlaceHolderBox
, bool isRootLineBox
, bool isOnlyRun
= false);
58 virtual InlineTextBox
* createInlineTextBox();
59 virtual void dirtyLineBoxes(bool fullLayout
, bool isRootInlineBox
= false);
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
);
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);
68 virtual VisiblePosition
positionForCoordinates(int x
, int y
);
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
*);
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;
77 virtual int lineHeight(bool firstLine
, bool isRootLineBox
= false) const;
79 virtual int minPrefWidth() const;
80 virtual int maxPrefWidth() const;
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
);
89 IntRect
linesBoundingBox() const;
91 int firstRunX() const;
92 int firstRunY() const;
94 virtual int verticalPositionHint(bool firstLine
) const;
96 void setText(PassRefPtr
<StringImpl
>, bool force
= false);
97 void setTextWithOffset(PassRefPtr
<StringImpl
>, unsigned offset
, unsigned len
, bool force
= false);
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);
105 virtual int marginLeft() const { return style()->marginLeft().calcMinValue(0); }
106 virtual int marginRight() const { return style()->marginRight().calcMinValue(0); }
108 virtual IntRect
clippedOverflowRectForRepaint(RenderBox
* repaintContainer
);
110 InlineTextBox
* firstTextBox() const { return m_firstTextBox
; }
111 InlineTextBox
* lastTextBox() const { return m_lastTextBox
; }
113 virtual int caretMinOffset() const;
114 virtual int caretMaxOffset() const;
115 virtual unsigned caretMaxRenderedOffset() const;
117 virtual int previousOffset(int current
) const;
118 virtual int nextOffset(int current
) const;
120 bool containsReversedText() const { return m_containsReversedText
; }
122 bool isSecure() { return style()->textSecurity() != TSNONE
; }
123 void momentarilyRevealLastCharacter();
124 void secureLastCharacter();
125 void secureLastCharacter(Timer
<RenderText
> * aTimer
);
127 InlineTextBox
* findNextInlineTextBox(int offset
, int& pos
) const;
129 bool allowTabs() const { return !style()->collapseWhiteSpace(); }
131 void checkConsistency() const;
133 float candidateComputedTextSize() const { return m_candidateComputedTextSize
; }
134 void setCandidateComputedTextSize(float s
) { m_candidateComputedTextSize
= s
; }
137 virtual void styleWillChange(StyleDifference
, const RenderStyle
*) { }
138 virtual void styleDidChange(StyleDifference
, const RenderStyle
* oldStyle
);
140 virtual void setTextInternal(PassRefPtr
<StringImpl
>);
141 virtual void calcPrefWidths(int leadWidth
);
142 virtual UChar
previousCharacter();
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(); }
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; }
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
; }
159 RefPtr
<StringImpl
> m_text
;
161 InlineTextBox
* m_firstTextBox
;
162 InlineTextBox
* m_lastTextBox
;
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
179 bool m_containsReversedText
: 1;
180 bool m_isAllASCII
: 1;
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
;
188 inline RenderText
* toRenderText(RenderObject
* o
)
190 ASSERT(!o
|| o
->isText());
191 return static_cast<RenderText
*>(o
);
194 inline const RenderText
* toRenderText(const RenderObject
* o
)
196 ASSERT(!o
|| o
->isText());
197 return static_cast<const RenderText
*>(o
);
201 inline void RenderText::checkConsistency() const
206 } // namespace WebCore
208 #endif // RenderText_h