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@apple.com | 36744d6 | 2009-01-25 20:23:04 +0000 | [diff] [blame] | 4 | * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 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 |
ddkilzer | c8eccec | 2007-09-26 02:29:57 +0000 | [diff] [blame] | 18 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 19 | * Boston, MA 02110-1301, USA. |
eseidel | 3a6d132 | 2006-01-09 03:14:50 +0000 | [diff] [blame] | 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 | |
mitz@apple.com | fb8da4e | 2008-02-19 21:13:19 +0000 | [diff] [blame] | 40 | virtual const char* renderName() const; |
eseidel | 3a6d132 | 2006-01-09 03:14:50 +0000 | [diff] [blame] | 41 | |
mitz@apple.com | fb8da4e | 2008-02-19 21:13:19 +0000 | [diff] [blame] | 42 | virtual bool isTextFragment() const; |
| 43 | virtual bool isWordBreak() const; |
weinig | 695d48b | 2006-12-16 23:36:48 +0000 | [diff] [blame] | 44 | |
darin | 42563ac5 | 2007-01-22 17:28:57 +0000 | [diff] [blame] | 45 | virtual PassRefPtr<StringImpl> originalText() const; |
weinig | 695d48b | 2006-12-16 23:36:48 +0000 | [diff] [blame] | 46 | |
weinig | 0a635f0 | 2006-11-01 21:49:13 +0000 | [diff] [blame] | 47 | void extractTextBox(InlineTextBox*); |
| 48 | void attachTextBox(InlineTextBox*); |
| 49 | void removeTextBox(InlineTextBox*); |
darin | 42563ac5 | 2007-01-22 17:28:57 +0000 | [diff] [blame] | 50 | |
eseidel | 3a6d132 | 2006-01-09 03:14:50 +0000 | [diff] [blame] | 51 | virtual void destroy(); |
weinig | 695d48b | 2006-12-16 23:36:48 +0000 | [diff] [blame] | 52 | |
darin | 42563ac5 | 2007-01-22 17:28:57 +0000 | [diff] [blame] | 53 | StringImpl* text() const { return m_text.get(); } |
eseidel | 3a6d132 | 2006-01-09 03:14:50 +0000 | [diff] [blame] | 54 | |
hyatt@apple.com | c92b735 | 2009-02-12 01:35:08 +0000 | [diff] [blame] | 55 | InlineTextBox* createInlineTextBox(); |
| 56 | void dirtyLineBoxes(bool fullLayout); |
eseidel | 3a6d132 | 2006-01-09 03:14:50 +0000 | [diff] [blame] | 57 | |
bdakin | da6e103 | 2007-07-13 23:07:15 +0000 | [diff] [blame] | 58 | virtual void absoluteRects(Vector<IntRect>&, int tx, int ty, bool topLevel = true); |
hyatt@apple.com | 8afdf17 | 2009-02-03 22:14:08 +0000 | [diff] [blame] | 59 | virtual void absoluteRectsForRange(Vector<IntRect>&, unsigned startOffset = 0, unsigned endOffset = UINT_MAX, bool useSelectionHeight = false); |
eseidel | 3a6d132 | 2006-01-09 03:14:50 +0000 | [diff] [blame] | 60 | |
simon.fraser@apple.com | aacf70e | 2008-11-12 23:43:52 +0000 | [diff] [blame] | 61 | virtual void absoluteQuads(Vector<FloatQuad>&, bool topLevel = true); |
hyatt@apple.com | 8afdf17 | 2009-02-03 22:14:08 +0000 | [diff] [blame] | 62 | virtual void absoluteQuadsForRange(Vector<FloatQuad>&, unsigned startOffset = 0, unsigned endOffset = UINT_MAX, bool useSelectionHeight = false); |
simon.fraser@apple.com | aacf70e | 2008-11-12 23:43:52 +0000 | [diff] [blame] | 63 | |
levin@chromium.org | d3ac7e6 | 2009-03-02 00:41:53 +0000 | [diff] [blame] | 64 | virtual VisiblePosition positionForPoint(const IntPoint&); |
eseidel | 3a6d132 | 2006-01-09 03:14:50 +0000 | [diff] [blame] | 65 | |
darin | 42563ac5 | 2007-01-22 17:28:57 +0000 | [diff] [blame] | 66 | const UChar* characters() const { return m_text->characters(); } |
| 67 | unsigned textLength() const { return m_text->length(); } // non virtual implementation of length() |
hyatt@apple.com | 6a551ad | 2009-02-11 22:43:12 +0000 | [diff] [blame] | 68 | void positionLineBox(InlineBox*); |
eseidel | 3a6d132 | 2006-01-09 03:14:50 +0000 | [diff] [blame] | 69 | |
mitz@apple.com | aa6ce3d | 2009-04-10 01:00:20 +0000 | [diff] [blame^] | 70 | 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; |
eseidel | 3a6d132 | 2006-01-09 03:14:50 +0000 | [diff] [blame] | 72 | |
timothy@apple.com | c59ad19 | 2008-06-20 19:26:31 +0000 | [diff] [blame] | 73 | virtual int lineHeight(bool firstLine, bool isRootLineBox = false) const; |
eseidel | 3a6d132 | 2006-01-09 03:14:50 +0000 | [diff] [blame] | 74 | |
hyatt | 818bb12 | 2007-04-25 19:10:24 +0000 | [diff] [blame] | 75 | virtual int minPrefWidth() const; |
| 76 | virtual int maxPrefWidth() const; |
eseidel | 3a6d132 | 2006-01-09 03:14:50 +0000 | [diff] [blame] | 77 | |
darin | 7e7c8e4 | 2007-04-25 01:14:03 +0000 | [diff] [blame] | 78 | 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); |
weinig | 0a635f0 | 2006-11-01 21:49:13 +0000 | [diff] [blame] | 84 | |
hyatt@apple.com | 651c2e8 | 2009-01-23 22:17:26 +0000 | [diff] [blame] | 85 | IntRect linesBoundingBox() const; |
hyatt@apple.com | d885df7 | 2009-01-22 02:31:52 +0000 | [diff] [blame] | 86 | |
| 87 | int firstRunX() const; |
| 88 | int firstRunY() const; |
eseidel | 3a6d132 | 2006-01-09 03:14:50 +0000 | [diff] [blame] | 89 | |
darin | ec37548 | 2007-01-06 01:36:24 +0000 | [diff] [blame] | 90 | void setText(PassRefPtr<StringImpl>, bool force = false); |
| 91 | void setTextWithOffset(PassRefPtr<StringImpl>, unsigned offset, unsigned len, bool force = false); |
eseidel | 3a6d132 | 2006-01-09 03:14:50 +0000 | [diff] [blame] | 92 | |
| 93 | virtual bool canBeSelectionLeaf() const { return true; } |
eseidel | 3a6d132 | 2006-01-09 03:14:50 +0000 | [diff] [blame] | 94 | virtual void setSelectionState(SelectionState s); |
hyatt@apple.com | 80ab6e9 | 2009-02-05 17:24:00 +0000 | [diff] [blame] | 95 | virtual IntRect selectionRectForRepaint(RenderBoxModelObject* repaintContainer, bool clipToVisibleContent = true); |
simon.fraser@apple.com | 2b2b6ce | 2008-12-06 19:58:44 +0000 | [diff] [blame] | 96 | virtual IntRect localCaretRect(InlineBox*, int caretOffset, int* extraWidthToEndOfLine = 0); |
eseidel | 3a6d132 | 2006-01-09 03:14:50 +0000 | [diff] [blame] | 97 | |
darin | 947a31b | 2006-02-24 03:08:41 +0000 | [diff] [blame] | 98 | virtual int marginLeft() const { return style()->marginLeft().calcMinValue(0); } |
| 99 | virtual int marginRight() const { return style()->marginRight().calcMinValue(0); } |
eseidel | 3a6d132 | 2006-01-09 03:14:50 +0000 | [diff] [blame] | 100 | |
hyatt@apple.com | 80ab6e9 | 2009-02-05 17:24:00 +0000 | [diff] [blame] | 101 | virtual IntRect clippedOverflowRectForRepaint(RenderBoxModelObject* repaintContainer); |
eseidel | 3a6d132 | 2006-01-09 03:14:50 +0000 | [diff] [blame] | 102 | |
eseidel | 3a6d132 | 2006-01-09 03:14:50 +0000 | [diff] [blame] | 103 | InlineTextBox* firstTextBox() const { return m_firstTextBox; } |
| 104 | InlineTextBox* lastTextBox() const { return m_lastTextBox; } |
weinig | 0a635f0 | 2006-11-01 21:49:13 +0000 | [diff] [blame] | 105 | |
eseidel | 3a6d132 | 2006-01-09 03:14:50 +0000 | [diff] [blame] | 106 | virtual int caretMinOffset() const; |
| 107 | virtual int caretMaxOffset() const; |
| 108 | virtual unsigned caretMaxRenderedOffset() const; |
| 109 | |
darin | 38ae534 | 2006-07-25 04:39:25 +0000 | [diff] [blame] | 110 | virtual int previousOffset(int current) const; |
ap@webkit.org | 73ecea1 | 2009-02-06 07:53:20 +0000 | [diff] [blame] | 111 | virtual int previousOffsetForBackwardDeletion(int current) const; |
darin | 38ae534 | 2006-07-25 04:39:25 +0000 | [diff] [blame] | 112 | virtual int nextOffset(int current) const; |
weinig | 695d48b | 2006-12-16 23:36:48 +0000 | [diff] [blame] | 113 | |
darin | 38ae534 | 2006-07-25 04:39:25 +0000 | [diff] [blame] | 114 | bool containsReversedText() const { return m_containsReversedText; } |
weinig | 695d48b | 2006-12-16 23:36:48 +0000 | [diff] [blame] | 115 | |
weinig | 0a635f0 | 2006-11-01 21:49:13 +0000 | [diff] [blame] | 116 | InlineTextBox* findNextInlineTextBox(int offset, int& pos) const; |
eseidel | 3a6d132 | 2006-01-09 03:14:50 +0000 | [diff] [blame] | 117 | |
mitz@apple.com | cdb7b04 | 2007-12-01 16:28:57 +0000 | [diff] [blame] | 118 | bool allowTabs() const { return !style()->collapseWhiteSpace(); } |
antti | abdc591 | 2007-03-30 09:59:57 +0000 | [diff] [blame] | 119 | |
darin | 5ae6f47 | 2007-08-06 19:51:38 +0000 | [diff] [blame] | 120 | void checkConsistency() const; |
| 121 | |
hyatt@apple.com | c92b735 | 2009-02-12 01:35:08 +0000 | [diff] [blame] | 122 | virtual void calcPrefWidths(int leadWidth); |
| 123 | |
weinig | 0a635f0 | 2006-11-01 21:49:13 +0000 | [diff] [blame] | 124 | protected: |
weinig@apple.com | 1a57c82 | 2009-02-04 22:27:50 +0000 | [diff] [blame] | 125 | virtual void styleWillChange(StyleDifference, const RenderStyle*) { } |
| 126 | virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle); |
simon.fraser@apple.com | a89b8cd | 2008-10-10 03:15:31 +0000 | [diff] [blame] | 127 | |
darin | 48ef06c | 2007-05-29 19:39:14 +0000 | [diff] [blame] | 128 | virtual void setTextInternal(PassRefPtr<StringImpl>); |
bdash | 85a00f9 | 2007-07-07 02:37:27 +0000 | [diff] [blame] | 129 | virtual UChar previousCharacter(); |
hyatt@apple.com | c92b735 | 2009-02-12 01:35:08 +0000 | [diff] [blame] | 130 | |
| 131 | virtual InlineTextBox* createTextBox(); // Subclassed by SVG. |
darin | ec37548 | 2007-01-06 01:36:24 +0000 | [diff] [blame] | 132 | |
| 133 | private: |
mitz@apple.com | aa6ce3d | 2009-04-10 01:00:20 +0000 | [diff] [blame^] | 134 | void calcPrefWidths(int leadWidth, HashSet<const SimpleFontData*>& fallbackFonts); |
| 135 | |
darin | 42563ac5 | 2007-01-22 17:28:57 +0000 | [diff] [blame] | 136 | // 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(); } |
darin | ec37548 | 2007-01-06 01:36:24 +0000 | [diff] [blame] | 140 | |
darin@apple.com | 98a7ac6 | 2009-01-05 17:26:53 +0000 | [diff] [blame] | 141 | 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 | |
darin | 42563ac5 | 2007-01-22 17:28:57 +0000 | [diff] [blame] | 145 | void deleteTextBoxes(); |
| 146 | bool containsOnlyWhitespace(unsigned from, unsigned len) const; |
mitz@apple.com | aa6ce3d | 2009-04-10 01:00:20 +0000 | [diff] [blame^] | 147 | int widthFromCache(const Font&, int start, int len, int xPos, HashSet<const SimpleFontData*>* fallbackFonts) 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 | |
eseidel | 3a6d132 | 2006-01-09 03:14:50 +0000 | [diff] [blame] | 160 | 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) |
eseidel | 3a6d132 | 2006-01-09 03:14:50 +0000 | [diff] [blame] | 165 | 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; |
darin | 42563ac5 | 2007-01-22 17:28:57 +0000 | [diff] [blame] | 170 | bool m_isAllASCII : 1; |
mitz@apple.com | aa6ce3d | 2009-04-10 01:00:20 +0000 | [diff] [blame^] | 171 | mutable bool m_knownNotToUseFallbackFonts : 1; |
eseidel | 3a6d132 | 2006-01-09 03:14:50 +0000 | [diff] [blame] | 172 | }; |
| 173 | |
darin@apple.com | 36744d6 | 2009-01-25 20:23:04 +0000 | [diff] [blame] | 174 | inline RenderText* toRenderText(RenderObject* o) |
| 175 | { |
| 176 | ASSERT(!o || o->isText()); |
| 177 | return static_cast<RenderText*>(o); |
| 178 | } |
| 179 | |
| 180 | inline const RenderText* toRenderText(const RenderObject* o) |
| 181 | { |
| 182 | ASSERT(!o || o->isText()); |
| 183 | return static_cast<const RenderText*>(o); |
| 184 | } |
| 185 | |
weinig@apple.com | 7c50a3b | 2009-01-30 19:55:45 +0000 | [diff] [blame] | 186 | // This will catch anyone doing an unnecessary cast. |
| 187 | void toRenderText(const RenderText*); |
| 188 | |
darin | 5ae6f47 | 2007-08-06 19:51:38 +0000 | [diff] [blame] | 189 | #ifdef NDEBUG |
darin | 08c4f74 | 2007-08-06 20:53:07 +0000 | [diff] [blame] | 190 | inline void RenderText::checkConsistency() const |
darin | 5ae6f47 | 2007-08-06 19:51:38 +0000 | [diff] [blame] | 191 | { |
| 192 | } |
| 193 | #endif |
| 194 | |
weinig | 0a635f0 | 2006-11-01 21:49:13 +0000 | [diff] [blame] | 195 | } // namespace WebCore |
eseidel | 3a6d132 | 2006-01-09 03:14:50 +0000 | [diff] [blame] | 196 | |
weinig | 0a635f0 | 2006-11-01 21:49:13 +0000 | [diff] [blame] | 197 | #endif // RenderText_h |