blob: 71e55949382fbe98f92990c45bb7c25f782ea5c5 [file] [log] [blame]
eseidel3a6d1322006-01-09 03:14:50 +00001/*
eseidel3a6d1322006-01-09 03:14:50 +00002 * (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 2000 Dirk Mueller (mueller@kde.org)
darin@apple.com36744d62009-01-25 20:23:04 +00004 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
eseidel3a6d1322006-01-09 03:14:50 +00005 *
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
ddkilzerc8eccec2007-09-26 02:29:57 +000018 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
eseidel3a6d1322006-01-09 03:14:50 +000020 *
21 */
22
darinb53ebdc2006-07-09 15:10:21 +000023#ifndef RenderText_h
24#define RenderText_h
eseidel3a6d1322006-01-09 03:14:50 +000025
darinb9481ed2006-03-20 02:57:59 +000026#include "RenderObject.h"
eseidel3a6d1322006-01-09 03:14:50 +000027
darin9d0a6282006-03-01 07:49:33 +000028namespace WebCore {
eseidel3a6d1322006-01-09 03:14:50 +000029
darinfb4d9372006-04-22 05:31:57 +000030class InlineTextBox;
darin9d0a6282006-03-01 07:49:33 +000031class StringImpl;
eseidel3a6d1322006-01-09 03:14:50 +000032
darin9d0a6282006-03-01 07:49:33 +000033class RenderText : public RenderObject {
eseidel3a6d1322006-01-09 03:14:50 +000034public:
darin42563ac52007-01-22 17:28:57 +000035 RenderText(Node*, PassRefPtr<StringImpl>);
darin5ae6f472007-08-06 19:51:38 +000036#ifndef NDEBUG
37 virtual ~RenderText();
38#endif
eseidel3a6d1322006-01-09 03:14:50 +000039
mitz@apple.comfb8da4e2008-02-19 21:13:19 +000040 virtual const char* renderName() const;
eseidel3a6d1322006-01-09 03:14:50 +000041
mitz@apple.comfb8da4e2008-02-19 21:13:19 +000042 virtual bool isTextFragment() const;
43 virtual bool isWordBreak() const;
weinig695d48b2006-12-16 23:36:48 +000044
darin42563ac52007-01-22 17:28:57 +000045 virtual PassRefPtr<StringImpl> originalText() const;
weinig695d48b2006-12-16 23:36:48 +000046
weinig0a635f02006-11-01 21:49:13 +000047 void extractTextBox(InlineTextBox*);
48 void attachTextBox(InlineTextBox*);
49 void removeTextBox(InlineTextBox*);
darin42563ac52007-01-22 17:28:57 +000050
eseidel3a6d1322006-01-09 03:14:50 +000051 virtual void destroy();
weinig695d48b2006-12-16 23:36:48 +000052
darin42563ac52007-01-22 17:28:57 +000053 StringImpl* text() const { return m_text.get(); }
eseidel3a6d1322006-01-09 03:14:50 +000054
hyatt@apple.comc92b7352009-02-12 01:35:08 +000055 InlineTextBox* createInlineTextBox();
56 void dirtyLineBoxes(bool fullLayout);
eseidel3a6d1322006-01-09 03:14:50 +000057
bdakinda6e1032007-07-13 23:07:15 +000058 virtual void absoluteRects(Vector<IntRect>&, int tx, int ty, bool topLevel = true);
hyatt@apple.com8afdf172009-02-03 22:14:08 +000059 virtual void absoluteRectsForRange(Vector<IntRect>&, unsigned startOffset = 0, unsigned endOffset = UINT_MAX, bool useSelectionHeight = false);
eseidel3a6d1322006-01-09 03:14:50 +000060
simon.fraser@apple.comaacf70e2008-11-12 23:43:52 +000061 virtual void absoluteQuads(Vector<FloatQuad>&, bool topLevel = true);
hyatt@apple.com8afdf172009-02-03 22:14:08 +000062 virtual void absoluteQuadsForRange(Vector<FloatQuad>&, unsigned startOffset = 0, unsigned endOffset = UINT_MAX, bool useSelectionHeight = false);
simon.fraser@apple.comaacf70e2008-11-12 23:43:52 +000063
levin@chromium.orgd3ac7e62009-03-02 00:41:53 +000064 virtual VisiblePosition positionForPoint(const IntPoint&);
eseidel3a6d1322006-01-09 03:14:50 +000065
darin42563ac52007-01-22 17:28:57 +000066 const UChar* characters() const { return m_text->characters(); }
67 unsigned textLength() const { return m_text->length(); } // non virtual implementation of length()
hyatt@apple.com6a551ad2009-02-11 22:43:12 +000068 void positionLineBox(InlineBox*);
eseidel3a6d1322006-01-09 03:14:50 +000069
mitz@apple.comaa6ce3d2009-04-10 01:00:20 +000070 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;
eseidel3a6d1322006-01-09 03:14:50 +000072
timothy@apple.comc59ad192008-06-20 19:26:31 +000073 virtual int lineHeight(bool firstLine, bool isRootLineBox = false) const;
eseidel3a6d1322006-01-09 03:14:50 +000074
hyatt818bb122007-04-25 19:10:24 +000075 virtual int minPrefWidth() const;
76 virtual int maxPrefWidth() const;
eseidel3a6d1322006-01-09 03:14:50 +000077
darin7e7c8e42007-04-25 01:14:03 +000078 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);
weinig0a635f02006-11-01 21:49:13 +000084
hyatt@apple.com651c2e82009-01-23 22:17:26 +000085 IntRect linesBoundingBox() const;
hyatt@apple.comd885df72009-01-22 02:31:52 +000086
87 int firstRunX() const;
88 int firstRunY() const;
eseidel3a6d1322006-01-09 03:14:50 +000089
darinec375482007-01-06 01:36:24 +000090 void setText(PassRefPtr<StringImpl>, bool force = false);
91 void setTextWithOffset(PassRefPtr<StringImpl>, unsigned offset, unsigned len, bool force = false);
eseidel3a6d1322006-01-09 03:14:50 +000092
93 virtual bool canBeSelectionLeaf() const { return true; }
eseidel3a6d1322006-01-09 03:14:50 +000094 virtual void setSelectionState(SelectionState s);
hyatt@apple.com80ab6e92009-02-05 17:24:00 +000095 virtual IntRect selectionRectForRepaint(RenderBoxModelObject* repaintContainer, bool clipToVisibleContent = true);
simon.fraser@apple.com2b2b6ce2008-12-06 19:58:44 +000096 virtual IntRect localCaretRect(InlineBox*, int caretOffset, int* extraWidthToEndOfLine = 0);
eseidel3a6d1322006-01-09 03:14:50 +000097
darin947a31b2006-02-24 03:08:41 +000098 virtual int marginLeft() const { return style()->marginLeft().calcMinValue(0); }
99 virtual int marginRight() const { return style()->marginRight().calcMinValue(0); }
eseidel3a6d1322006-01-09 03:14:50 +0000100
hyatt@apple.com80ab6e92009-02-05 17:24:00 +0000101 virtual IntRect clippedOverflowRectForRepaint(RenderBoxModelObject* repaintContainer);
eseidel3a6d1322006-01-09 03:14:50 +0000102
eseidel3a6d1322006-01-09 03:14:50 +0000103 InlineTextBox* firstTextBox() const { return m_firstTextBox; }
104 InlineTextBox* lastTextBox() const { return m_lastTextBox; }
weinig0a635f02006-11-01 21:49:13 +0000105
eseidel3a6d1322006-01-09 03:14:50 +0000106 virtual int caretMinOffset() const;
107 virtual int caretMaxOffset() const;
108 virtual unsigned caretMaxRenderedOffset() const;
109
darin38ae5342006-07-25 04:39:25 +0000110 virtual int previousOffset(int current) const;
ap@webkit.org73ecea12009-02-06 07:53:20 +0000111 virtual int previousOffsetForBackwardDeletion(int current) const;
darin38ae5342006-07-25 04:39:25 +0000112 virtual int nextOffset(int current) const;
weinig695d48b2006-12-16 23:36:48 +0000113
darin38ae5342006-07-25 04:39:25 +0000114 bool containsReversedText() const { return m_containsReversedText; }
weinig695d48b2006-12-16 23:36:48 +0000115
weinig0a635f02006-11-01 21:49:13 +0000116 InlineTextBox* findNextInlineTextBox(int offset, int& pos) const;
eseidel3a6d1322006-01-09 03:14:50 +0000117
mitz@apple.comcdb7b042007-12-01 16:28:57 +0000118 bool allowTabs() const { return !style()->collapseWhiteSpace(); }
anttiabdc5912007-03-30 09:59:57 +0000119
darin5ae6f472007-08-06 19:51:38 +0000120 void checkConsistency() const;
121
hyatt@apple.comc92b7352009-02-12 01:35:08 +0000122 virtual void calcPrefWidths(int leadWidth);
123
weinig0a635f02006-11-01 21:49:13 +0000124protected:
weinig@apple.com1a57c822009-02-04 22:27:50 +0000125 virtual void styleWillChange(StyleDifference, const RenderStyle*) { }
126 virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle);
simon.fraser@apple.coma89b8cd2008-10-10 03:15:31 +0000127
darin48ef06c2007-05-29 19:39:14 +0000128 virtual void setTextInternal(PassRefPtr<StringImpl>);
bdash85a00f92007-07-07 02:37:27 +0000129 virtual UChar previousCharacter();
hyatt@apple.comc92b7352009-02-12 01:35:08 +0000130
131 virtual InlineTextBox* createTextBox(); // Subclassed by SVG.
darinec375482007-01-06 01:36:24 +0000132
133private:
mitz@apple.comaa6ce3d2009-04-10 01:00:20 +0000134 void calcPrefWidths(int leadWidth, HashSet<const SimpleFontData*>& fallbackFonts);
135
darin42563ac52007-01-22 17:28:57 +0000136 // Make length() private so that callers that have a RenderText*
137 // will use the more efficient textLength() instead, while
138 // callers with a RenderObject* can continue to use length().
139 virtual unsigned length() const { return textLength(); }
darinec375482007-01-06 01:36:24 +0000140
darin@apple.com98a7ac62009-01-05 17:26:53 +0000141 virtual void paint(PaintInfo&, int, int) { ASSERT_NOT_REACHED(); }
142 virtual void layout() { ASSERT_NOT_REACHED(); }
143 virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, int, int, int, int, HitTestAction) { ASSERT_NOT_REACHED(); return false; }
144
darin42563ac52007-01-22 17:28:57 +0000145 void deleteTextBoxes();
146 bool containsOnlyWhitespace(unsigned from, unsigned len) const;
mitz@apple.comaa6ce3d2009-04-10 01:00:20 +0000147 int widthFromCache(const Font&, int start, int len, int xPos, HashSet<const SimpleFontData*>* fallbackFonts) const;
darin42563ac52007-01-22 17:28:57 +0000148 bool isAllASCII() const { return m_isAllASCII; }
149
150 RefPtr<StringImpl> m_text;
weinig0a635f02006-11-01 21:49:13 +0000151
eseidel3a6d1322006-01-09 03:14:50 +0000152 InlineTextBox* m_firstTextBox;
153 InlineTextBox* m_lastTextBox;
weinig0a635f02006-11-01 21:49:13 +0000154
eseidel3a6d1322006-01-09 03:14:50 +0000155 int m_minWidth;
156 int m_maxWidth;
157 int m_beginMinWidth;
158 int m_endMinWidth;
weinig0a635f02006-11-01 21:49:13 +0000159
eseidel3a6d1322006-01-09 03:14:50 +0000160 bool m_hasBreakableChar : 1; // Whether or not we can be broken into multiple lines.
161 bool m_hasBreak : 1; // Whether or not we have a hard break (e.g., <pre> with '\n').
162 bool m_hasTab : 1; // Whether or not we have a variable width tab character (e.g., <pre> with '\t').
163 bool m_hasBeginWS : 1; // Whether or not we begin with WS (only true if we aren't pre)
164 bool m_hasEndWS : 1; // Whether or not we end with WS (only true if we aren't pre)
eseidel3a6d1322006-01-09 03:14:50 +0000165 bool m_linesDirty : 1; // This bit indicates that the text run has already dirtied specific
166 // line boxes, and this hint will enable layoutInlineChildren to avoid
167 // just dirtying everything when character data is modified (e.g., appended/inserted
168 // or removed).
169 bool m_containsReversedText : 1;
darin42563ac52007-01-22 17:28:57 +0000170 bool m_isAllASCII : 1;
mitz@apple.comaa6ce3d2009-04-10 01:00:20 +0000171 mutable bool m_knownNotToUseFallbackFonts : 1;
eseidel3a6d1322006-01-09 03:14:50 +0000172};
173
darin@apple.com36744d62009-01-25 20:23:04 +0000174inline RenderText* toRenderText(RenderObject* o)
175{
176 ASSERT(!o || o->isText());
177 return static_cast<RenderText*>(o);
178}
179
180inline const RenderText* toRenderText(const RenderObject* o)
181{
182 ASSERT(!o || o->isText());
183 return static_cast<const RenderText*>(o);
184}
185
weinig@apple.com7c50a3b2009-01-30 19:55:45 +0000186// This will catch anyone doing an unnecessary cast.
187void toRenderText(const RenderText*);
188
darin5ae6f472007-08-06 19:51:38 +0000189#ifdef NDEBUG
darin08c4f742007-08-06 20:53:07 +0000190inline void RenderText::checkConsistency() const
darin5ae6f472007-08-06 19:51:38 +0000191{
192}
193#endif
194
weinig0a635f02006-11-01 21:49:13 +0000195} // namespace WebCore
eseidel3a6d1322006-01-09 03:14:50 +0000196
weinig0a635f02006-11-01 21:49:13 +0000197#endif // RenderText_h