eseidel | 3a6d132 | 2006-01-09 03:14:50 +0000 | [diff] [blame] | 1 | /* |
eseidel | 3a6d132 | 2006-01-09 03:14:50 +0000 | [diff] [blame] | 2 | * (C) 1999 Lars Knoll (knoll@kde.org) |
| 3 | * (C) 2000 Dirk Mueller (mueller@kde.org) |
darin | b5a0e3d | 2007-01-10 00:08:18 +0000 | [diff] [blame] | 4 | * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved. |
eseidel | 3a6d132 | 2006-01-09 03:14:50 +0000 | [diff] [blame] | 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., 59 Temple Place - Suite 330, |
| 19 | * Boston, MA 02111-1307, USA. |
| 20 | * |
| 21 | */ |
| 22 | |
darin | b53ebdc | 2006-07-09 15:10:21 +0000 | [diff] [blame] | 23 | #ifndef RenderText_h |
| 24 | #define RenderText_h |
eseidel | 3a6d132 | 2006-01-09 03:14:50 +0000 | [diff] [blame] | 25 | |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 26 | #include "RenderObject.h" |
eseidel | 3a6d132 | 2006-01-09 03:14:50 +0000 | [diff] [blame] | 27 | |
darin | 9d0a628 | 2006-03-01 07:49:33 +0000 | [diff] [blame] | 28 | namespace WebCore { |
eseidel | 3a6d132 | 2006-01-09 03:14:50 +0000 | [diff] [blame] | 29 | |
darin | fb4d937 | 2006-04-22 05:31:57 +0000 | [diff] [blame] | 30 | class InlineTextBox; |
darin | 9d0a628 | 2006-03-01 07:49:33 +0000 | [diff] [blame] | 31 | class StringImpl; |
eseidel | 3a6d132 | 2006-01-09 03:14:50 +0000 | [diff] [blame] | 32 | |
darin | 9d0a628 | 2006-03-01 07:49:33 +0000 | [diff] [blame] | 33 | class RenderText : public RenderObject { |
eseidel | 3a6d132 | 2006-01-09 03:14:50 +0000 | [diff] [blame] | 34 | public: |
darin | 42563ac5 | 2007-01-22 17:28:57 +0000 | [diff] [blame] | 35 | RenderText(Node*, PassRefPtr<StringImpl>); |
darin | 5ae6f47 | 2007-08-06 19:51:38 +0000 | [diff] [blame] | 36 | #ifndef NDEBUG |
| 37 | virtual ~RenderText(); |
| 38 | #endif |
eseidel | 3a6d132 | 2006-01-09 03:14:50 +0000 | [diff] [blame] | 39 | |
weinig | 0a635f0 | 2006-11-01 21:49:13 +0000 | [diff] [blame] | 40 | virtual const char* renderName() const { return "RenderText"; } |
eseidel | 3a6d132 | 2006-01-09 03:14:50 +0000 | [diff] [blame] | 41 | |
weinig | 695d48b | 2006-12-16 23:36:48 +0000 | [diff] [blame] | 42 | virtual bool isTextFragment() const { return false; } |
| 43 | |
darin | 42563ac5 | 2007-01-22 17:28:57 +0000 | [diff] [blame] | 44 | virtual PassRefPtr<StringImpl> originalText() const; |
weinig | 695d48b | 2006-12-16 23:36:48 +0000 | [diff] [blame] | 45 | |
weinig | 0a635f0 | 2006-11-01 21:49:13 +0000 | [diff] [blame] | 46 | virtual void setStyle(RenderStyle*); |
eseidel | 3a6d132 | 2006-01-09 03:14:50 +0000 | [diff] [blame] | 47 | |
weinig | 0a635f0 | 2006-11-01 21:49:13 +0000 | [diff] [blame] | 48 | void extractTextBox(InlineTextBox*); |
| 49 | void attachTextBox(InlineTextBox*); |
| 50 | void removeTextBox(InlineTextBox*); |
darin | 42563ac5 | 2007-01-22 17:28:57 +0000 | [diff] [blame] | 51 | |
eseidel | 3a6d132 | 2006-01-09 03:14:50 +0000 | [diff] [blame] | 52 | virtual void destroy(); |
weinig | 695d48b | 2006-12-16 23:36:48 +0000 | [diff] [blame] | 53 | |
darin | 42563ac5 | 2007-01-22 17:28:57 +0000 | [diff] [blame] | 54 | StringImpl* text() const { return m_text.get(); } |
eseidel | 3a6d132 | 2006-01-09 03:14:50 +0000 | [diff] [blame] | 55 | |
darin | 42563ac5 | 2007-01-22 17:28:57 +0000 | [diff] [blame] | 56 | virtual InlineBox* createInlineBox(bool makePlaceHolderBox, bool isRootLineBox, bool isOnlyRun = false); |
rwlbuis | 09f49fb | 2007-01-26 09:03:43 +0000 | [diff] [blame] | 57 | virtual InlineTextBox* createInlineTextBox(); |
eseidel | 3a6d132 | 2006-01-09 03:14:50 +0000 | [diff] [blame] | 58 | virtual void dirtyLineBoxes(bool fullLayout, bool isRootInlineBox = false); |
eseidel | 3a6d132 | 2006-01-09 03:14:50 +0000 | [diff] [blame] | 59 | |
weinig | 695d48b | 2006-12-16 23:36:48 +0000 | [diff] [blame] | 60 | 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; } |
eseidel | 3a6d132 | 2006-01-09 03:14:50 +0000 | [diff] [blame] | 64 | |
bdakin | da6e103 | 2007-07-13 23:07:15 +0000 | [diff] [blame] | 65 | virtual void absoluteRects(Vector<IntRect>&, int tx, int ty, bool topLevel = true); |
sullivan | 4ea5e41 | 2007-07-06 03:49:50 +0000 | [diff] [blame] | 66 | virtual void addLineBoxRects(Vector<IntRect>&, unsigned startOffset = 0, unsigned endOffset = UINT_MAX, bool useSelectionHeight = false); |
eseidel | 3a6d132 | 2006-01-09 03:14:50 +0000 | [diff] [blame] | 67 | |
| 68 | virtual VisiblePosition positionForCoordinates(int x, int y); |
| 69 | |
darin | 42563ac5 | 2007-01-22 17:28:57 +0000 | [diff] [blame] | 70 | const UChar* characters() const { return m_text->characters(); } |
| 71 | unsigned textLength() const { return m_text->length(); } // non virtual implementation of length() |
adele | 8040761 | 2006-07-28 05:13:24 +0000 | [diff] [blame] | 72 | virtual void position(InlineBox*); |
eseidel | 3a6d132 | 2006-01-09 03:14:50 +0000 | [diff] [blame] | 73 | |
darin | 42563ac5 | 2007-01-22 17:28:57 +0000 | [diff] [blame] | 74 | virtual unsigned width(unsigned from, unsigned len, const Font&, int xPos) const; |
weinig | 695d48b | 2006-12-16 23:36:48 +0000 | [diff] [blame] | 75 | virtual unsigned width(unsigned from, unsigned len, int xPos, bool firstLine = false) const; |
eseidel | 3a6d132 | 2006-01-09 03:14:50 +0000 | [diff] [blame] | 76 | virtual int width() const; |
| 77 | virtual int height() const; |
| 78 | |
hyatt | ef0a939 | 2006-03-05 05:51:37 +0000 | [diff] [blame] | 79 | virtual short lineHeight(bool firstLine, bool isRootLineBox = false) const; |
eseidel | 3a6d132 | 2006-01-09 03:14:50 +0000 | [diff] [blame] | 80 | |
hyatt | 818bb12 | 2007-04-25 19:10:24 +0000 | [diff] [blame] | 81 | virtual int minPrefWidth() const; |
| 82 | virtual int maxPrefWidth() const; |
eseidel | 3a6d132 | 2006-01-09 03:14:50 +0000 | [diff] [blame] | 83 | |
darin | 7e7c8e4 | 2007-04-25 01:14:03 +0000 | [diff] [blame] | 84 | 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); |
weinig | 0a635f0 | 2006-11-01 21:49:13 +0000 | [diff] [blame] | 90 | |
eseidel | 3a6d132 | 2006-01-09 03:14:50 +0000 | [diff] [blame] | 91 | // 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 | |
weinig | 0a635f0 | 2006-11-01 21:49:13 +0000 | [diff] [blame] | 98 | virtual short verticalPositionHint(bool firstLine) const; |
eseidel | 3a6d132 | 2006-01-09 03:14:50 +0000 | [diff] [blame] | 99 | |
darin | ec37548 | 2007-01-06 01:36:24 +0000 | [diff] [blame] | 100 | void setText(PassRefPtr<StringImpl>, bool force = false); |
| 101 | void setTextWithOffset(PassRefPtr<StringImpl>, unsigned offset, unsigned len, bool force = false); |
eseidel | 3a6d132 | 2006-01-09 03:14:50 +0000 | [diff] [blame] | 102 | |
| 103 | virtual bool canBeSelectionLeaf() const { return true; } |
darin | bc19ccb | 2007-01-09 14:36:16 +0000 | [diff] [blame] | 104 | virtual SelectionState selectionState() const { return static_cast<SelectionState>(m_selectionState); } |
eseidel | 3a6d132 | 2006-01-09 03:14:50 +0000 | [diff] [blame] | 105 | virtual void setSelectionState(SelectionState s); |
adele | eaa0055 | 2007-05-11 00:26:12 +0000 | [diff] [blame] | 106 | virtual IntRect selectionRect(bool clipToVisibleContent = true); |
weinig | 0a635f0 | 2006-11-01 21:49:13 +0000 | [diff] [blame] | 107 | virtual IntRect caretRect(int offset, EAffinity, int* extraWidthToEndOfLine = 0); |
eseidel | 3a6d132 | 2006-01-09 03:14:50 +0000 | [diff] [blame] | 108 | |
darin | 947a31b | 2006-02-24 03:08:41 +0000 | [diff] [blame] | 109 | virtual int marginLeft() const { return style()->marginLeft().calcMinValue(0); } |
| 110 | virtual int marginRight() const { return style()->marginRight().calcMinValue(0); } |
eseidel | 3a6d132 | 2006-01-09 03:14:50 +0000 | [diff] [blame] | 111 | |
bdash | ef45ac0 | 2007-03-07 03:35:03 +0000 | [diff] [blame] | 112 | virtual IntRect absoluteClippedOverflowRect(); |
eseidel | 3a6d132 | 2006-01-09 03:14:50 +0000 | [diff] [blame] | 113 | |
eseidel | 3a6d132 | 2006-01-09 03:14:50 +0000 | [diff] [blame] | 114 | InlineTextBox* firstTextBox() const { return m_firstTextBox; } |
| 115 | InlineTextBox* lastTextBox() const { return m_lastTextBox; } |
weinig | 0a635f0 | 2006-11-01 21:49:13 +0000 | [diff] [blame] | 116 | |
| 117 | virtual InlineBox* inlineBox(int offset, EAffinity = UPSTREAM); |
eseidel | 3a6d132 | 2006-01-09 03:14:50 +0000 | [diff] [blame] | 118 | |
eseidel | 3a6d132 | 2006-01-09 03:14:50 +0000 | [diff] [blame] | 119 | virtual int caretMinOffset() const; |
| 120 | virtual int caretMaxOffset() const; |
| 121 | virtual unsigned caretMaxRenderedOffset() const; |
| 122 | |
darin | 38ae534 | 2006-07-25 04:39:25 +0000 | [diff] [blame] | 123 | virtual int previousOffset(int current) const; |
| 124 | virtual int nextOffset(int current) const; |
weinig | 695d48b | 2006-12-16 23:36:48 +0000 | [diff] [blame] | 125 | |
darin | 38ae534 | 2006-07-25 04:39:25 +0000 | [diff] [blame] | 126 | bool containsReversedText() const { return m_containsReversedText; } |
weinig | 695d48b | 2006-12-16 23:36:48 +0000 | [diff] [blame] | 127 | |
weinig | 0a635f0 | 2006-11-01 21:49:13 +0000 | [diff] [blame] | 128 | InlineTextBox* findNextInlineTextBox(int offset, int& pos) const; |
eseidel | 3a6d132 | 2006-01-09 03:14:50 +0000 | [diff] [blame] | 129 | |
antti | abdc591 | 2007-03-30 09:59:57 +0000 | [diff] [blame] | 130 | int allowTabs() const { return !style()->collapseWhiteSpace(); } |
| 131 | |
darin | 5ae6f47 | 2007-08-06 19:51:38 +0000 | [diff] [blame] | 132 | void checkConsistency() const; |
| 133 | |
weinig | 0a635f0 | 2006-11-01 21:49:13 +0000 | [diff] [blame] | 134 | protected: |
darin | 48ef06c | 2007-05-29 19:39:14 +0000 | [diff] [blame] | 135 | virtual void setTextInternal(PassRefPtr<StringImpl>); |
hyatt | 818bb12 | 2007-04-25 19:10:24 +0000 | [diff] [blame] | 136 | virtual void calcPrefWidths(int leadWidth); |
bdash | 85a00f9 | 2007-07-07 02:37:27 +0000 | [diff] [blame] | 137 | virtual UChar previousCharacter(); |
darin | ec37548 | 2007-01-06 01:36:24 +0000 | [diff] [blame] | 138 | |
| 139 | private: |
darin | 42563ac5 | 2007-01-22 17:28:57 +0000 | [diff] [blame] | 140 | // 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(); } |
darin | ec37548 | 2007-01-06 01:36:24 +0000 | [diff] [blame] | 144 | |
darin | 42563ac5 | 2007-01-22 17:28:57 +0000 | [diff] [blame] | 145 | void deleteTextBoxes(); |
| 146 | bool containsOnlyWhitespace(unsigned from, unsigned len) const; |
antti | abdc591 | 2007-03-30 09:59:57 +0000 | [diff] [blame] | 147 | int widthFromCache(const Font&, int start, int len, int xPos) const; |
darin | 42563ac5 | 2007-01-22 17:28:57 +0000 | [diff] [blame] | 148 | bool isAllASCII() const { return m_isAllASCII; } |
| 149 | |
| 150 | RefPtr<StringImpl> m_text; |
weinig | 0a635f0 | 2006-11-01 21:49:13 +0000 | [diff] [blame] | 151 | |
eseidel | 3a6d132 | 2006-01-09 03:14:50 +0000 | [diff] [blame] | 152 | InlineTextBox* m_firstTextBox; |
| 153 | InlineTextBox* m_lastTextBox; |
weinig | 0a635f0 | 2006-11-01 21:49:13 +0000 | [diff] [blame] | 154 | |
eseidel | 3a6d132 | 2006-01-09 03:14:50 +0000 | [diff] [blame] | 155 | int m_minWidth; |
| 156 | int m_maxWidth; |
| 157 | int m_beginMinWidth; |
| 158 | int m_endMinWidth; |
weinig | 0a635f0 | 2006-11-01 21:49:13 +0000 | [diff] [blame] | 159 | |
darin | bc19ccb | 2007-01-09 14:36:16 +0000 | [diff] [blame] | 160 | unsigned m_selectionState : 3; // enums on Windows are signed, so this needs to be unsigned to prevent it turning negative. |
eseidel | 3a6d132 | 2006-01-09 03:14:50 +0000 | [diff] [blame] | 161 | 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) |
eseidel | 3a6d132 | 2006-01-09 03:14:50 +0000 | [diff] [blame] | 166 | 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; |
darin | 42563ac5 | 2007-01-22 17:28:57 +0000 | [diff] [blame] | 171 | bool m_isAllASCII : 1; |
eseidel | 3a6d132 | 2006-01-09 03:14:50 +0000 | [diff] [blame] | 172 | }; |
| 173 | |
darin | 5ae6f47 | 2007-08-06 19:51:38 +0000 | [diff] [blame] | 174 | #ifdef NDEBUG |
darin | 08c4f74 | 2007-08-06 20:53:07 +0000 | [diff] [blame^] | 175 | inline void RenderText::checkConsistency() const |
darin | 5ae6f47 | 2007-08-06 19:51:38 +0000 | [diff] [blame] | 176 | { |
| 177 | } |
| 178 | #endif |
| 179 | |
weinig | 0a635f0 | 2006-11-01 21:49:13 +0000 | [diff] [blame] | 180 | } // namespace WebCore |
eseidel | 3a6d132 | 2006-01-09 03:14:50 +0000 | [diff] [blame] | 181 | |
weinig | 0a635f0 | 2006-11-01 21:49:13 +0000 | [diff] [blame] | 182 | #endif // RenderText_h |