1 /* 2 * (C) 1999 Lars Knoll (knoll (at) kde.org) 3 * (C) 2000 Dirk Mueller (mueller (at) 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 #include <wtf/Forward.h> 28 29 namespace WebCore { 30 31 class InlineTextBox; 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.impl(); } 54 String textWithoutTranscoding() const; 55 56 InlineTextBox* createInlineTextBox(); 57 void dirtyLineBoxes(bool fullLayout); 58 59 virtual void absoluteRects(Vector<IntRect>&, int tx, int ty); 60 void absoluteRectsForRange(Vector<IntRect>&, unsigned startOffset = 0, unsigned endOffset = UINT_MAX, bool useSelectionHeight = false); 61 62 virtual void absoluteQuads(Vector<FloatQuad>&); 63 void absoluteQuadsForRange(Vector<FloatQuad>&, unsigned startOffset = 0, unsigned endOffset = UINT_MAX, bool useSelectionHeight = false); 64 65 enum ClippingOption { NoClipping, ClipToEllipsis }; 66 void absoluteQuads(Vector<FloatQuad>&, ClippingOption option = NoClipping); 67 68 virtual VisiblePosition positionForPoint(const IntPoint&); 69 70 const UChar* characters() const { return m_text.characters(); } 71 unsigned textLength() const { return m_text.length(); } // non virtual implementation of length() 72 void positionLineBox(InlineBox*); 73 74 virtual float width(unsigned from, unsigned len, const Font&, float xPos, HashSet<const SimpleFontData*>* fallbackFonts = 0, GlyphOverflow* = 0) const; 75 virtual float width(unsigned from, unsigned len, float xPos, bool firstLine = false, HashSet<const SimpleFontData*>* fallbackFonts = 0, GlyphOverflow* = 0) const; 76 77 float minLogicalWidth() const; 78 float maxLogicalWidth() const; 79 80 void trimmedPrefWidths(float leadWidth, 81 float& beginMinW, bool& beginWS, 82 float& endMinW, bool& endWS, 83 bool& hasBreakableChar, bool& hasBreak, 84 float& beginMaxW, float& endMaxW, 85 float& minW, float& maxW, bool& stripFrontSpaces); 86 87 virtual IntRect linesBoundingBox() const; 88 IntRect linesVisualOverflowBoundingBox() const; 89 90 FloatPoint firstRunOrigin() const; 91 float firstRunX() const; 92 float firstRunY() const; 93 94 void setText(PassRefPtr<StringImpl>, bool force = false); 95 void setTextWithOffset(PassRefPtr<StringImpl>, unsigned offset, unsigned len, bool force = false); 96 97 virtual bool canBeSelectionLeaf() const { return true; } 98 virtual void setSelectionState(SelectionState s); 99 virtual IntRect selectionRectForRepaint(RenderBoxModelObject* repaintContainer, bool clipToVisibleContent = true); 100 virtual IntRect localCaretRect(InlineBox*, int caretOffset, int* extraWidthToEndOfLine = 0); 101 102 virtual int marginLeft() const { return style()->marginLeft().calcMinValue(0); } 103 virtual int marginRight() const { return style()->marginRight().calcMinValue(0); } 104 105 virtual IntRect clippedOverflowRectForRepaint(RenderBoxModelObject* repaintContainer); 106 107 InlineTextBox* firstTextBox() const { return m_firstTextBox; } 108 InlineTextBox* lastTextBox() const { return m_lastTextBox; } 109 110 virtual int caretMinOffset() const; 111 virtual int caretMaxOffset() const; 112 virtual unsigned caretMaxRenderedOffset() const; 113 114 virtual int previousOffset(int current) const; 115 virtual int previousOffsetForBackwardDeletion(int current) const; 116 virtual int nextOffset(int current) const; 117 118 bool containsReversedText() const { return m_containsReversedText; } 119 120 InlineTextBox* findNextInlineTextBox(int offset, int& pos) const; 121 122 bool allowTabs() const { return !style()->collapseWhiteSpace(); } 123 124 void checkConsistency() const; 125 126 virtual void computePreferredLogicalWidths(float leadWidth); 127 bool isAllCollapsibleWhitespace(); 128 129 bool knownToHaveNoOverflowAndNoFallbackFonts() const { return m_knownToHaveNoOverflowAndNoFallbackFonts; } 130 131 void removeAndDestroyTextBoxes(); 132 133 protected: 134 virtual void styleWillChange(StyleDifference, const RenderStyle*) { } 135 virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle); 136 137 virtual void setTextInternal(PassRefPtr<StringImpl>); 138 virtual UChar previousCharacter() const; 139 140 virtual InlineTextBox* createTextBox(); // Subclassed by SVG. 141 142 private: 143 void computePreferredLogicalWidths(float leadWidth, HashSet<const SimpleFontData*>& fallbackFonts, GlyphOverflow&); 144 145 // Make length() private so that callers that have a RenderText* 146 // will use the more efficient textLength() instead, while 147 // callers with a RenderObject* can continue to use length(). 148 virtual unsigned length() const { return textLength(); } 149 150 virtual void paint(PaintInfo&, int, int) { ASSERT_NOT_REACHED(); } 151 virtual void layout() { ASSERT_NOT_REACHED(); } 152 virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, int, int, int, int, HitTestAction) { ASSERT_NOT_REACHED(); return false; } 153 154 void deleteTextBoxes(); 155 bool containsOnlyWhitespace(unsigned from, unsigned len) const; 156 float widthFromCache(const Font&, int start, int len, float xPos, HashSet<const SimpleFontData*>* fallbackFonts, GlyphOverflow*) const; 157 bool isAllASCII() const { return m_isAllASCII; } 158 void updateNeedsTranscoding(); 159 160 inline void transformText(String&) const; 161 162 float m_minWidth; // here to minimize padding in 64-bit. 163 164 String m_text; 165 166 InlineTextBox* m_firstTextBox; 167 InlineTextBox* m_lastTextBox; 168 169 float m_maxWidth; 170 float m_beginMinWidth; 171 float m_endMinWidth; 172 173 bool m_hasBreakableChar : 1; // Whether or not we can be broken into multiple lines. 174 bool m_hasBreak : 1; // Whether or not we have a hard break (e.g., <pre> with '\n'). 175 bool m_hasTab : 1; // Whether or not we have a variable width tab character (e.g., <pre> with '\t'). 176 bool m_hasBeginWS : 1; // Whether or not we begin with WS (only true if we aren't pre) 177 bool m_hasEndWS : 1; // Whether or not we end with WS (only true if we aren't pre) 178 bool m_linesDirty : 1; // This bit indicates that the text run has already dirtied specific 179 // line boxes, and this hint will enable layoutInlineChildren to avoid 180 // just dirtying everything when character data is modified (e.g., appended/inserted 181 // or removed). 182 bool m_containsReversedText : 1; 183 bool m_isAllASCII : 1; 184 mutable bool m_knownToHaveNoOverflowAndNoFallbackFonts : 1; 185 bool m_needsTranscoding : 1; 186 }; 187 188 inline RenderText* toRenderText(RenderObject* object) 189 { 190 ASSERT(!object || object->isText()); 191 return static_cast<RenderText*>(object); 192 } 193 194 inline const RenderText* toRenderText(const RenderObject* object) 195 { 196 ASSERT(!object || object->isText()); 197 return static_cast<const RenderText*>(object); 198 } 199 200 // This will catch anyone doing an unnecessary cast. 201 void toRenderText(const RenderText*); 202 203 #ifdef NDEBUG 204 inline void RenderText::checkConsistency() const 205 { 206 } 207 #endif 208 209 } // namespace WebCore 210 211 #endif // RenderText_h 212