| 1 | /* |
|---|
| 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. |
|---|
| 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., 51 Franklin Street, Fifth Floor, |
|---|
| 19 | * Boston, MA 02110-1301, USA. |
|---|
| 20 | * |
|---|
| 21 | */ |
|---|
| 22 | |
|---|
| 23 | #ifndef RenderText_h |
|---|
| 24 | #define RenderText_h |
|---|
| 25 | |
|---|
| 26 | #include "RenderObject.h" |
|---|
| 27 | |
|---|
| 28 | namespace WebCore { |
|---|
| 29 | |
|---|
| 30 | class InlineTextBox; |
|---|
| 31 | class StringImpl; |
|---|
| 32 | |
|---|
| 33 | class RenderText : public RenderObject { |
|---|
| 34 | public: |
|---|
| 35 | RenderText(Node*, PassRefPtr<StringImpl>); |
|---|
| 36 | #ifndef NDEBUG |
|---|
| 37 | virtual ~RenderText(); |
|---|
| 38 | #endif |
|---|
| 39 | |
|---|
| 40 | virtual const char* renderName() const; |
|---|
| 41 | |
|---|
| 42 | virtual bool isTextFragment() const; |
|---|
| 43 | virtual bool isWordBreak() const; |
|---|
| 44 | |
|---|
| 45 | virtual PassRefPtr<StringImpl> originalText() const; |
|---|
| 46 | |
|---|
| 47 | void extractTextBox(InlineTextBox*); |
|---|
| 48 | void attachTextBox(InlineTextBox*); |
|---|
| 49 | void removeTextBox(InlineTextBox*); |
|---|
| 50 | |
|---|
| 51 | virtual void destroy(); |
|---|
| 52 | |
|---|
| 53 | StringImpl* text() const { return m_text.get(); } |
|---|
| 54 | |
|---|
| 55 | InlineTextBox* createInlineTextBox(); |
|---|
| 56 | void dirtyLineBoxes(bool fullLayout); |
|---|
| 57 | |
|---|
| 58 | virtual void absoluteRects(Vector<IntRect>&, int tx, int ty); |
|---|
| 59 | void absoluteRectsForRange(Vector<IntRect>&, unsigned startOffset = 0, unsigned endOffset = UINT_MAX, bool useSelectionHeight = false); |
|---|
| 60 | |
|---|
| 61 | virtual void absoluteQuads(Vector<FloatQuad>&); |
|---|
| 62 | void absoluteQuadsForRange(Vector<FloatQuad>&, unsigned startOffset = 0, unsigned endOffset = UINT_MAX, bool useSelectionHeight = false); |
|---|
| 63 | |
|---|
| 64 | virtual VisiblePosition positionForPoint(const IntPoint&); |
|---|
| 65 | |
|---|
| 66 | const UChar* characters() const { return m_text->characters(); } |
|---|
| 67 | unsigned textLength() const { return m_text->length(); } // non virtual implementation of length() |
|---|
| 68 | void positionLineBox(InlineBox*); |
|---|
| 69 | |
|---|
| 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; |
|---|
| 72 | |
|---|
| 73 | virtual int lineHeight(bool firstLine, bool isRootLineBox = false) const; |
|---|
| 74 | |
|---|
| 75 | virtual int minPrefWidth() const; |
|---|
| 76 | virtual int maxPrefWidth() const; |
|---|
| 77 | |
|---|
| 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); |
|---|
| 84 | |
|---|
| 85 | IntRect linesBoundingBox() const; |
|---|
| 86 | |
|---|
| 87 | IntPoint firstRunOrigin() const; |
|---|
| 88 | int firstRunX() const; |
|---|
| 89 | int firstRunY() const; |
|---|
| 90 | |
|---|
| 91 | void setText(PassRefPtr<StringImpl>, bool force = false); |
|---|
| 92 | void setTextWithOffset(PassRefPtr<StringImpl>, unsigned offset, unsigned len, bool force = false); |
|---|
| 93 | |
|---|
| 94 | virtual bool canBeSelectionLeaf() const { return true; } |
|---|
| 95 | virtual void setSelectionState(SelectionState s); |
|---|
| 96 | virtual IntRect selectionRectForRepaint(RenderBoxModelObject* repaintContainer, bool clipToVisibleContent = true); |
|---|
| 97 | virtual IntRect localCaretRect(InlineBox*, int caretOffset, int* extraWidthToEndOfLine = 0); |
|---|
| 98 | |
|---|
| 99 | virtual int marginLeft() const { return style()->marginLeft().calcMinValue(0); } |
|---|
| 100 | virtual int marginRight() const { return style()->marginRight().calcMinValue(0); } |
|---|
| 101 | |
|---|
| 102 | virtual IntRect clippedOverflowRectForRepaint(RenderBoxModelObject* repaintContainer); |
|---|
| 103 | |
|---|
| 104 | InlineTextBox* firstTextBox() const { return m_firstTextBox; } |
|---|
| 105 | InlineTextBox* lastTextBox() const { return m_lastTextBox; } |
|---|
| 106 | |
|---|
| 107 | virtual int caretMinOffset() const; |
|---|
| 108 | virtual int caretMaxOffset() const; |
|---|
| 109 | virtual unsigned caretMaxRenderedOffset() const; |
|---|
| 110 | |
|---|
| 111 | virtual int previousOffset(int current) const; |
|---|
| 112 | virtual int previousOffsetForBackwardDeletion(int current) const; |
|---|
| 113 | virtual int nextOffset(int current) const; |
|---|
| 114 | |
|---|
| 115 | bool containsReversedText() const { return m_containsReversedText; } |
|---|
| 116 | |
|---|
| 117 | InlineTextBox* findNextInlineTextBox(int offset, int& pos) const; |
|---|
| 118 | |
|---|
| 119 | bool allowTabs() const { return !style()->collapseWhiteSpace(); } |
|---|
| 120 | |
|---|
| 121 | void checkConsistency() const; |
|---|
| 122 | |
|---|
| 123 | virtual void calcPrefWidths(int leadWidth); |
|---|
| 124 | |
|---|
| 125 | protected: |
|---|
| 126 | virtual void styleWillChange(StyleDifference, const RenderStyle*) { } |
|---|
| 127 | virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle); |
|---|
| 128 | |
|---|
| 129 | virtual void setTextInternal(PassRefPtr<StringImpl>); |
|---|
| 130 | virtual UChar previousCharacter(); |
|---|
| 131 | |
|---|
| 132 | virtual InlineTextBox* createTextBox(); // Subclassed by SVG. |
|---|
| 133 | |
|---|
| 134 | private: |
|---|
| 135 | void calcPrefWidths(int leadWidth, HashSet<const SimpleFontData*>& fallbackFonts); |
|---|
| 136 | |
|---|
| 137 | // Make length() private so that callers that have a RenderText* |
|---|
| 138 | // will use the more efficient textLength() instead, while |
|---|
| 139 | // callers with a RenderObject* can continue to use length(). |
|---|
| 140 | virtual unsigned length() const { return textLength(); } |
|---|
| 141 | |
|---|
| 142 | virtual void paint(PaintInfo&, int, int) { ASSERT_NOT_REACHED(); } |
|---|
| 143 | virtual void layout() { ASSERT_NOT_REACHED(); } |
|---|
| 144 | virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, int, int, int, int, HitTestAction) { ASSERT_NOT_REACHED(); return false; } |
|---|
| 145 | |
|---|
| 146 | void deleteTextBoxes(); |
|---|
| 147 | bool containsOnlyWhitespace(unsigned from, unsigned len) const; |
|---|
| 148 | int widthFromCache(const Font&, int start, int len, int xPos, HashSet<const SimpleFontData*>* fallbackFonts) const; |
|---|
| 149 | bool isAllASCII() const { return m_isAllASCII; } |
|---|
| 150 | |
|---|
| 151 | int m_minWidth; // here to minimize padding in 64-bit. |
|---|
| 152 | |
|---|
| 153 | RefPtr<StringImpl> m_text; |
|---|
| 154 | |
|---|
| 155 | InlineTextBox* m_firstTextBox; |
|---|
| 156 | InlineTextBox* m_lastTextBox; |
|---|
| 157 | |
|---|
| 158 | int m_maxWidth; |
|---|
| 159 | int m_beginMinWidth; |
|---|
| 160 | int m_endMinWidth; |
|---|
| 161 | |
|---|
| 162 | bool m_hasBreakableChar : 1; // Whether or not we can be broken into multiple lines. |
|---|
| 163 | bool m_hasBreak : 1; // Whether or not we have a hard break (e.g., <pre> with '\n'). |
|---|
| 164 | bool m_hasTab : 1; // Whether or not we have a variable width tab character (e.g., <pre> with '\t'). |
|---|
| 165 | bool m_hasBeginWS : 1; // Whether or not we begin with WS (only true if we aren't pre) |
|---|
| 166 | bool m_hasEndWS : 1; // Whether or not we end with WS (only true if we aren't pre) |
|---|
| 167 | bool m_linesDirty : 1; // This bit indicates that the text run has already dirtied specific |
|---|
| 168 | // line boxes, and this hint will enable layoutInlineChildren to avoid |
|---|
| 169 | // just dirtying everything when character data is modified (e.g., appended/inserted |
|---|
| 170 | // or removed). |
|---|
| 171 | bool m_containsReversedText : 1; |
|---|
| 172 | bool m_isAllASCII : 1; |
|---|
| 173 | mutable bool m_knownNotToUseFallbackFonts : 1; |
|---|
| 174 | }; |
|---|
| 175 | |
|---|
| 176 | inline RenderText* toRenderText(RenderObject* object) |
|---|
| 177 | { |
|---|
| 178 | ASSERT(!object || object->isText()); |
|---|
| 179 | return static_cast<RenderText*>(object); |
|---|
| 180 | } |
|---|
| 181 | |
|---|
| 182 | inline const RenderText* toRenderText(const RenderObject* object) |
|---|
| 183 | { |
|---|
| 184 | ASSERT(!object || object->isText()); |
|---|
| 185 | return static_cast<const RenderText*>(object); |
|---|
| 186 | } |
|---|
| 187 | |
|---|
| 188 | // This will catch anyone doing an unnecessary cast. |
|---|
| 189 | void toRenderText(const RenderText*); |
|---|
| 190 | |
|---|
| 191 | #ifdef NDEBUG |
|---|
| 192 | inline void RenderText::checkConsistency() const |
|---|
| 193 | { |
|---|
| 194 | } |
|---|
| 195 | #endif |
|---|
| 196 | |
|---|
| 197 | } // namespace WebCore |
|---|
| 198 | |
|---|
| 199 | #endif // RenderText_h |
|---|