blob: 818c7c30b5c032a57191e707dd10090a50182ca3 [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)
darinb5a0e3d2007-01-10 00:08:18 +00004 * Copyright (C) 2004, 2005, 2006, 2007 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
18 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
20 *
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
weinig0a635f02006-11-01 21:49:13 +000040 virtual const char* renderName() const { return "RenderText"; }
eseidel3a6d1322006-01-09 03:14:50 +000041
weinig695d48b2006-12-16 23:36:48 +000042 virtual bool isTextFragment() const { return false; }
43
darin42563ac52007-01-22 17:28:57 +000044 virtual PassRefPtr<StringImpl> originalText() const;
weinig695d48b2006-12-16 23:36:48 +000045
weinig0a635f02006-11-01 21:49:13 +000046 virtual void setStyle(RenderStyle*);
eseidel3a6d1322006-01-09 03:14:50 +000047
weinig0a635f02006-11-01 21:49:13 +000048 void extractTextBox(InlineTextBox*);
49 void attachTextBox(InlineTextBox*);
50 void removeTextBox(InlineTextBox*);
darin42563ac52007-01-22 17:28:57 +000051
eseidel3a6d1322006-01-09 03:14:50 +000052 virtual void destroy();
weinig695d48b2006-12-16 23:36:48 +000053
darin42563ac52007-01-22 17:28:57 +000054 StringImpl* text() const { return m_text.get(); }
eseidel3a6d1322006-01-09 03:14:50 +000055
darin42563ac52007-01-22 17:28:57 +000056 virtual InlineBox* createInlineBox(bool makePlaceHolderBox, bool isRootLineBox, bool isOnlyRun = false);
rwlbuis09f49fb2007-01-26 09:03:43 +000057 virtual InlineTextBox* createInlineTextBox();
eseidel3a6d1322006-01-09 03:14:50 +000058 virtual void dirtyLineBoxes(bool fullLayout, bool isRootInlineBox = false);
eseidel3a6d1322006-01-09 03:14:50 +000059
weinig695d48b2006-12-16 23:36:48 +000060 virtual void paint(PaintInfo&, int tx, int ty) { ASSERT_NOT_REACHED(); }
61 virtual void layout() { ASSERT_NOT_REACHED(); }
62
63 virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, int, int, int, int, HitTestAction) { ASSERT_NOT_REACHED(); return false; }
eseidel3a6d1322006-01-09 03:14:50 +000064
bdakinda6e1032007-07-13 23:07:15 +000065 virtual void absoluteRects(Vector<IntRect>&, int tx, int ty, bool topLevel = true);
sullivan4ea5e412007-07-06 03:49:50 +000066 virtual void addLineBoxRects(Vector<IntRect>&, unsigned startOffset = 0, unsigned endOffset = UINT_MAX, bool useSelectionHeight = false);
eseidel3a6d1322006-01-09 03:14:50 +000067
68 virtual VisiblePosition positionForCoordinates(int x, int y);
69
darin42563ac52007-01-22 17:28:57 +000070 const UChar* characters() const { return m_text->characters(); }
71 unsigned textLength() const { return m_text->length(); } // non virtual implementation of length()
adele80407612006-07-28 05:13:24 +000072 virtual void position(InlineBox*);
eseidel3a6d1322006-01-09 03:14:50 +000073
darin42563ac52007-01-22 17:28:57 +000074 virtual unsigned width(unsigned from, unsigned len, const Font&, int xPos) const;
weinig695d48b2006-12-16 23:36:48 +000075 virtual unsigned width(unsigned from, unsigned len, int xPos, bool firstLine = false) const;
eseidel3a6d1322006-01-09 03:14:50 +000076 virtual int width() const;
77 virtual int height() const;
78
hyattef0a9392006-03-05 05:51:37 +000079 virtual short lineHeight(bool firstLine, bool isRootLineBox = false) const;
eseidel3a6d1322006-01-09 03:14:50 +000080
hyatt818bb122007-04-25 19:10:24 +000081 virtual int minPrefWidth() const;
82 virtual int maxPrefWidth() const;
eseidel3a6d1322006-01-09 03:14:50 +000083
darin7e7c8e42007-04-25 01:14:03 +000084 void trimmedPrefWidths(int leadWidth,
85 int& beginMinW, bool& beginWS,
86 int& endMinW, bool& endWS,
87 bool& hasBreakableChar, bool& hasBreak,
88 int& beginMaxW, int& endMaxW,
89 int& minW, int& maxW, bool& stripFrontSpaces);
weinig0a635f02006-11-01 21:49:13 +000090
eseidel3a6d1322006-01-09 03:14:50 +000091 // returns the minimum x position of all runs relative to the parent.
92 // defaults to 0.
93 int minXPos() const;
94
95 virtual int xPos() const;
96 virtual int yPos() const;
97
weinig0a635f02006-11-01 21:49:13 +000098 virtual short verticalPositionHint(bool firstLine) const;
eseidel3a6d1322006-01-09 03:14:50 +000099
darinec375482007-01-06 01:36:24 +0000100 void setText(PassRefPtr<StringImpl>, bool force = false);
101 void setTextWithOffset(PassRefPtr<StringImpl>, unsigned offset, unsigned len, bool force = false);
eseidel3a6d1322006-01-09 03:14:50 +0000102
103 virtual bool canBeSelectionLeaf() const { return true; }
darinbc19ccb2007-01-09 14:36:16 +0000104 virtual SelectionState selectionState() const { return static_cast<SelectionState>(m_selectionState); }
eseidel3a6d1322006-01-09 03:14:50 +0000105 virtual void setSelectionState(SelectionState s);
adeleeaa00552007-05-11 00:26:12 +0000106 virtual IntRect selectionRect(bool clipToVisibleContent = true);
weinig0a635f02006-11-01 21:49:13 +0000107 virtual IntRect caretRect(int offset, EAffinity, int* extraWidthToEndOfLine = 0);
eseidel3a6d1322006-01-09 03:14:50 +0000108
darin947a31b2006-02-24 03:08:41 +0000109 virtual int marginLeft() const { return style()->marginLeft().calcMinValue(0); }
110 virtual int marginRight() const { return style()->marginRight().calcMinValue(0); }
eseidel3a6d1322006-01-09 03:14:50 +0000111
bdashef45ac02007-03-07 03:35:03 +0000112 virtual IntRect absoluteClippedOverflowRect();
eseidel3a6d1322006-01-09 03:14:50 +0000113
eseidel3a6d1322006-01-09 03:14:50 +0000114 InlineTextBox* firstTextBox() const { return m_firstTextBox; }
115 InlineTextBox* lastTextBox() const { return m_lastTextBox; }
weinig0a635f02006-11-01 21:49:13 +0000116
117 virtual InlineBox* inlineBox(int offset, EAffinity = UPSTREAM);
eseidel3a6d1322006-01-09 03:14:50 +0000118
eseidel3a6d1322006-01-09 03:14:50 +0000119 virtual int caretMinOffset() const;
120 virtual int caretMaxOffset() const;
121 virtual unsigned caretMaxRenderedOffset() const;
122
darin38ae5342006-07-25 04:39:25 +0000123 virtual int previousOffset(int current) const;
124 virtual int nextOffset(int current) const;
weinig695d48b2006-12-16 23:36:48 +0000125
darin38ae5342006-07-25 04:39:25 +0000126 bool containsReversedText() const { return m_containsReversedText; }
weinig695d48b2006-12-16 23:36:48 +0000127
weinig0a635f02006-11-01 21:49:13 +0000128 InlineTextBox* findNextInlineTextBox(int offset, int& pos) const;
eseidel3a6d1322006-01-09 03:14:50 +0000129
anttiabdc5912007-03-30 09:59:57 +0000130 int allowTabs() const { return !style()->collapseWhiteSpace(); }
131
darin5ae6f472007-08-06 19:51:38 +0000132 void checkConsistency() const;
133
weinig0a635f02006-11-01 21:49:13 +0000134protected:
darin48ef06c2007-05-29 19:39:14 +0000135 virtual void setTextInternal(PassRefPtr<StringImpl>);
hyatt818bb122007-04-25 19:10:24 +0000136 virtual void calcPrefWidths(int leadWidth);
bdash85a00f92007-07-07 02:37:27 +0000137 virtual UChar previousCharacter();
darinec375482007-01-06 01:36:24 +0000138
139private:
darin42563ac52007-01-22 17:28:57 +0000140 // Make length() private so that callers that have a RenderText*
141 // will use the more efficient textLength() instead, while
142 // callers with a RenderObject* can continue to use length().
143 virtual unsigned length() const { return textLength(); }
darinec375482007-01-06 01:36:24 +0000144
darin42563ac52007-01-22 17:28:57 +0000145 void deleteTextBoxes();
146 bool containsOnlyWhitespace(unsigned from, unsigned len) const;
anttiabdc5912007-03-30 09:59:57 +0000147 int widthFromCache(const Font&, int start, int len, int xPos) 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
darinbc19ccb2007-01-09 14:36:16 +0000160 unsigned m_selectionState : 3; // enums on Windows are signed, so this needs to be unsigned to prevent it turning negative.
eseidel3a6d1322006-01-09 03:14:50 +0000161 bool m_hasBreakableChar : 1; // Whether or not we can be broken into multiple lines.
162 bool m_hasBreak : 1; // Whether or not we have a hard break (e.g., <pre> with '\n').
163 bool m_hasTab : 1; // Whether or not we have a variable width tab character (e.g., <pre> with '\t').
164 bool m_hasBeginWS : 1; // Whether or not we begin with WS (only true if we aren't pre)
165 bool m_hasEndWS : 1; // Whether or not we end with WS (only true if we aren't pre)
eseidel3a6d1322006-01-09 03:14:50 +0000166 bool m_linesDirty : 1; // This bit indicates that the text run has already dirtied specific
167 // line boxes, and this hint will enable layoutInlineChildren to avoid
168 // just dirtying everything when character data is modified (e.g., appended/inserted
169 // or removed).
170 bool m_containsReversedText : 1;
darin42563ac52007-01-22 17:28:57 +0000171 bool m_isAllASCII : 1;
eseidel3a6d1322006-01-09 03:14:50 +0000172};
173
darin5ae6f472007-08-06 19:51:38 +0000174#ifdef NDEBUG
darin08c4f742007-08-06 20:53:07 +0000175inline void RenderText::checkConsistency() const
darin5ae6f472007-08-06 19:51:38 +0000176{
177}
178#endif
179
weinig0a635f02006-11-01 21:49:13 +0000180} // namespace WebCore
eseidel3a6d1322006-01-09 03:14:50 +0000181
weinig0a635f02006-11-01 21:49:13 +0000182#endif // RenderText_h