| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * (C) 1999 Lars Knoll (knoll@kde.org) | |
| 3 * (C) 2000 Dirk Mueller (mueller@kde.org) | |
| 4 * Copyright (C) 2004-2009, 2013 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 "core/dom/Text.h" | |
| 27 #include "core/layout/LayoutObject.h" | |
| 28 #include "core/layout/line/FloatToLayoutUnit.h" | |
| 29 #include "platform/LengthFunctions.h" | |
| 30 #include "platform/text/TextPath.h" | |
| 31 #include "wtf/Forward.h" | |
| 32 #include "wtf/PassRefPtr.h" | |
| 33 | |
| 34 namespace blink { | |
| 35 | |
| 36 class AbstractInlineTextBox; | |
| 37 class InlineTextBox; | |
| 38 | |
| 39 class RenderText : public LayoutObject { | |
| 40 public: | |
| 41 // FIXME: If the node argument is not a Text node or the string argument is | |
| 42 // not the content of the Text node, updating text-transform property | |
| 43 // doesn't re-transform the string. | |
| 44 RenderText(Node*, PassRefPtr<StringImpl>); | |
| 45 #if ENABLE(ASSERT) | |
| 46 virtual ~RenderText(); | |
| 47 #endif | |
| 48 | |
| 49 virtual const char* renderName() const override; | |
| 50 | |
| 51 virtual bool isTextFragment() const; | |
| 52 virtual bool isWordBreak() const; | |
| 53 | |
| 54 virtual PassRefPtr<StringImpl> originalText() const; | |
| 55 | |
| 56 void extractTextBox(InlineTextBox*); | |
| 57 void attachTextBox(InlineTextBox*); | |
| 58 void removeTextBox(InlineTextBox*); | |
| 59 | |
| 60 const String& text() const { return m_text; } | |
| 61 virtual unsigned textStartOffset() const { return 0; } | |
| 62 String plainText() const; | |
| 63 | |
| 64 InlineTextBox* createInlineTextBox(int start, unsigned short length); | |
| 65 void dirtyOrDeleteLineBoxesIfNeeded(bool fullLayout); | |
| 66 void dirtyLineBoxes(); | |
| 67 | |
| 68 virtual void absoluteRects(Vector<IntRect>&, const LayoutPoint& accumulatedO
ffset) const override final; | |
| 69 void absoluteRectsForRange(Vector<IntRect>&, unsigned startOffset = 0, unsig
ned endOffset = INT_MAX, bool useSelectionHeight = false, bool* wasFixed = 0); | |
| 70 | |
| 71 virtual void absoluteQuads(Vector<FloatQuad>&, bool* wasFixed) const overrid
e final; | |
| 72 void absoluteQuadsForRange(Vector<FloatQuad>&, unsigned startOffset = 0, uns
igned endOffset = INT_MAX, bool useSelectionHeight = false, bool* wasFixed = 0); | |
| 73 | |
| 74 enum ClippingOption { NoClipping, ClipToEllipsis }; | |
| 75 void absoluteQuads(Vector<FloatQuad>&, bool* wasFixed = 0, ClippingOption =
NoClipping) const; | |
| 76 | |
| 77 virtual PositionWithAffinity positionForPoint(const LayoutPoint&) override; | |
| 78 | |
| 79 bool is8Bit() const { return m_text.is8Bit(); } | |
| 80 const LChar* characters8() const { return m_text.impl()->characters8(); } | |
| 81 const UChar* characters16() const { return m_text.impl()->characters16(); } | |
| 82 bool hasEmptyText() const { return m_text.isEmpty(); } | |
| 83 UChar characterAt(unsigned) const; | |
| 84 UChar uncheckedCharacterAt(unsigned) const; | |
| 85 UChar operator[](unsigned i) const { return uncheckedCharacterAt(i); } | |
| 86 unsigned textLength() const { return m_text.length(); } // non virtual imple
mentation of length() | |
| 87 void positionLineBox(InlineBox*); | |
| 88 | |
| 89 virtual float width(unsigned from, unsigned len, const Font&, float xPos, Te
xtDirection, HashSet<const SimpleFontData*>* fallbackFonts = 0, GlyphOverflow* =
0) const; | |
| 90 virtual float width(unsigned from, unsigned len, float xPos, TextDirection,
bool firstLine = false, HashSet<const SimpleFontData*>* fallbackFonts = 0, Glyph
Overflow* = 0) const; | |
| 91 | |
| 92 float minLogicalWidth() const; | |
| 93 float maxLogicalWidth() const; | |
| 94 | |
| 95 void trimmedPrefWidths(FloatWillBeLayoutUnit leadWidth, | |
| 96 FloatWillBeLayoutUnit& firstLineMinWidth, bool& hasBreakableStart, | |
| 97 FloatWillBeLayoutUnit& lastLineMinWidth, bool& hasBreakableEnd, | |
| 98 bool& hasBreakableChar, bool& hasBreak, | |
| 99 FloatWillBeLayoutUnit& firstLineMaxWidth, FloatWillBeLayoutUnit& lastLin
eMaxWidth, | |
| 100 FloatWillBeLayoutUnit& minWidth, FloatWillBeLayoutUnit& maxWidth, bool&
stripFrontSpaces, | |
| 101 TextDirection); | |
| 102 | |
| 103 virtual IntRect linesBoundingBox() const; | |
| 104 LayoutRect linesVisualOverflowBoundingBox() const; | |
| 105 | |
| 106 FloatPoint firstRunOrigin() const; | |
| 107 float firstRunX() const; | |
| 108 float firstRunY() const; | |
| 109 | |
| 110 virtual void setText(PassRefPtr<StringImpl>, bool force = false); | |
| 111 void setTextWithOffset(PassRefPtr<StringImpl>, unsigned offset, unsigned len
, bool force = false); | |
| 112 | |
| 113 virtual void transformText(); | |
| 114 | |
| 115 virtual bool canBeSelectionLeaf() const override { return true; } | |
| 116 virtual void setSelectionState(SelectionState) override final; | |
| 117 virtual LayoutRect selectionRectForPaintInvalidation(const LayoutBoxModelObj
ect* paintInvalidationContainer) const override; | |
| 118 virtual LayoutRect localCaretRect(InlineBox*, int caretOffset, LayoutUnit* e
xtraWidthToEndOfLine = 0) override; | |
| 119 | |
| 120 InlineTextBox* firstTextBox() const { return m_firstTextBox; } | |
| 121 InlineTextBox* lastTextBox() const { return m_lastTextBox; } | |
| 122 | |
| 123 virtual int caretMinOffset() const override; | |
| 124 virtual int caretMaxOffset() const override; | |
| 125 unsigned renderedTextLength() const; | |
| 126 | |
| 127 virtual int previousOffset(int current) const override final; | |
| 128 virtual int previousOffsetForBackwardDeletion(int current) const override fi
nal; | |
| 129 virtual int nextOffset(int current) const override final; | |
| 130 | |
| 131 bool containsReversedText() const { return m_containsReversedText; } | |
| 132 | |
| 133 bool isSecure() const { return style()->textSecurity() != TSNONE; } | |
| 134 void momentarilyRevealLastTypedCharacter(unsigned lastTypedCharacterOffset); | |
| 135 | |
| 136 bool isAllCollapsibleWhitespace() const; | |
| 137 | |
| 138 bool canUseSimpleFontCodePath() const { return m_canUseSimpleFontCodePath; } | |
| 139 | |
| 140 void removeAndDestroyTextBoxes(); | |
| 141 | |
| 142 PassRefPtr<AbstractInlineTextBox> firstAbstractInlineTextBox(); | |
| 143 | |
| 144 protected: | |
| 145 virtual void willBeDestroyed() override; | |
| 146 | |
| 147 virtual void styleWillChange(StyleDifference, const LayoutStyle&) override f
inal { } | |
| 148 virtual void styleDidChange(StyleDifference, const LayoutStyle* oldStyle) ov
erride; | |
| 149 | |
| 150 virtual void setTextInternal(PassRefPtr<StringImpl>); | |
| 151 virtual UChar previousCharacter() const; | |
| 152 | |
| 153 virtual void addLayerHitTestRects(LayerHitTestRects&, const Layer* currentLa
yer, const LayoutPoint& layerOffset, const LayoutRect& containerRect) const over
ride; | |
| 154 | |
| 155 virtual InlineTextBox* createTextBox(int start, unsigned short length); // S
ubclassed by SVG. | |
| 156 | |
| 157 virtual void invalidateDisplayItemClients(DisplayItemList*) const override; | |
| 158 | |
| 159 private: | |
| 160 void computePreferredLogicalWidths(float leadWidth); | |
| 161 void computePreferredLogicalWidths(float leadWidth, HashSet<const SimpleFont
Data*>& fallbackFonts, GlyphOverflow&); | |
| 162 | |
| 163 bool computeCanUseSimpleFontCodePath() const; | |
| 164 | |
| 165 // Make length() private so that callers that have a RenderText* | |
| 166 // will use the more efficient textLength() instead, while | |
| 167 // callers with a LayoutObject* can continue to use length(). | |
| 168 virtual unsigned length() const override final { return textLength(); } | |
| 169 | |
| 170 virtual void paint(const PaintInfo&, const LayoutPoint&) override final { AS
SERT_NOT_REACHED(); } | |
| 171 virtual void layout() override final { ASSERT_NOT_REACHED(); } | |
| 172 virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTes
tLocation&, const LayoutPoint&, HitTestAction) override final { ASSERT_NOT_REACH
ED(); return false; } | |
| 173 | |
| 174 void deleteTextBoxes(); | |
| 175 bool containsOnlyWhitespace(unsigned from, unsigned len) const; | |
| 176 float widthFromCache(const Font&, int start, int len, float xPos, TextDirect
ion, HashSet<const SimpleFontData*>* fallbackFonts, GlyphOverflow*) const; | |
| 177 bool isAllASCII() const { return m_isAllASCII; } | |
| 178 | |
| 179 void secureText(UChar mask); | |
| 180 | |
| 181 bool isText() const = delete; // This will catch anyone doing an unnecessary
check. | |
| 182 | |
| 183 virtual LayoutRect clippedOverflowRectForPaintInvalidation(const LayoutBoxMo
delObject* paintInvalidationContainer, const PaintInvalidationState* = 0) const
override; | |
| 184 | |
| 185 void checkConsistency() const; | |
| 186 | |
| 187 // We put the bitfield first to minimize padding on 64-bit. | |
| 188 bool m_hasBreakableChar : 1; // Whether or not we can be broken into multipl
e lines. | |
| 189 bool m_hasBreak : 1; // Whether or not we have a hard break (e.g., <pre> wit
h '\n'). | |
| 190 bool m_hasTab : 1; // Whether or not we have a variable width tab character
(e.g., <pre> with '\t'). | |
| 191 bool m_hasBreakableStart : 1; | |
| 192 bool m_hasBreakableEnd : 1; | |
| 193 bool m_hasEndWhiteSpace : 1; | |
| 194 bool m_linesDirty : 1; // This bit indicates that the text run has already d
irtied specific | |
| 195 // line boxes, and this hint will enable layoutInline
Children to avoid | |
| 196 // just dirtying everything when character data is mo
dified (e.g., appended/inserted | |
| 197 // or removed). | |
| 198 bool m_containsReversedText : 1; | |
| 199 bool m_isAllASCII : 1; | |
| 200 bool m_canUseSimpleFontCodePath : 1; | |
| 201 mutable bool m_knownToHaveNoOverflowAndNoFallbackFonts : 1; | |
| 202 | |
| 203 float m_minWidth; | |
| 204 float m_maxWidth; | |
| 205 float m_firstLineMinWidth; | |
| 206 float m_lastLineLineMinWidth; | |
| 207 | |
| 208 String m_text; | |
| 209 | |
| 210 InlineTextBox* m_firstTextBox; | |
| 211 InlineTextBox* m_lastTextBox; | |
| 212 }; | |
| 213 | |
| 214 inline UChar RenderText::uncheckedCharacterAt(unsigned i) const | |
| 215 { | |
| 216 ASSERT_WITH_SECURITY_IMPLICATION(i < textLength()); | |
| 217 return is8Bit() ? characters8()[i] : characters16()[i]; | |
| 218 } | |
| 219 | |
| 220 inline UChar RenderText::characterAt(unsigned i) const | |
| 221 { | |
| 222 if (i >= textLength()) | |
| 223 return 0; | |
| 224 | |
| 225 return uncheckedCharacterAt(i); | |
| 226 } | |
| 227 | |
| 228 DEFINE_LAYOUT_OBJECT_TYPE_CASTS(RenderText, isText()); | |
| 229 | |
| 230 #if !ENABLE(ASSERT) | |
| 231 inline void RenderText::checkConsistency() const | |
| 232 { | |
| 233 } | |
| 234 #endif | |
| 235 | |
| 236 inline RenderText* Text::renderer() const | |
| 237 { | |
| 238 return toRenderText(CharacterData::renderer()); | |
| 239 } | |
| 240 | |
| 241 void applyTextTransform(const LayoutStyle*, String&, UChar); | |
| 242 | |
| 243 } // namespace blink | |
| 244 | |
| 245 #endif // RenderText_h | |
| OLD | NEW |