blob: 417300399e9f67e719e07a893c31d44d5cbbd6f0 [file] [log] [blame]
eseidel3a6d1322006-01-09 03:14:50 +00001/*
eseidel3a6d1322006-01-09 03:14:50 +00002 * (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 2000 Dirk Mueller (mueller@kde.org)
antti@apple.com61c4cde2013-10-13 11:05:33 +00004 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2013 Apple Inc. All rights reserved.
eseidel3a6d1322006-01-09 03:14:50 +00005 *
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
ddkilzerc8eccec2007-09-26 02:29:57 +000018 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
eseidel3a6d1322006-01-09 03:14:50 +000020 *
21 */
22
darinb53ebdc2006-07-09 15:10:21 +000023#ifndef RenderText_h
24#define RenderText_h
eseidel3a6d1322006-01-09 03:14:50 +000025
antti@apple.com1e9a3182013-09-27 02:02:27 +000026#include "RenderElement.h"
antti@apple.comb0b707f2013-10-12 17:41:13 +000027#include "RenderTextLineBoxes.h"
antti@apple.com940f5872013-10-24 20:31:11 +000028#include "SimpleLineLayout.h"
antti@apple.come9c90162013-10-13 16:00:10 +000029#include "Text.h"
barraclough@apple.comd218c2d2010-08-10 00:38:14 +000030#include <wtf/Forward.h>
eseidel3a6d1322006-01-09 03:14:50 +000031
darin9d0a6282006-03-01 07:49:33 +000032namespace WebCore {
eseidel3a6d1322006-01-09 03:14:50 +000033
darinfb4d9372006-04-22 05:31:57 +000034class InlineTextBox;
eseidel3a6d1322006-01-09 03:14:50 +000035
darin9d0a6282006-03-01 07:49:33 +000036class RenderText : public RenderObject {
eseidel3a6d1322006-01-09 03:14:50 +000037public:
akling@apple.com42e10632013-10-14 17:55:52 +000038 RenderText(Text&, const String&);
39 RenderText(Document&, const String&);
antti@apple.com4973e7c2013-12-07 00:33:42 +000040
darin5ae6f472007-08-06 19:51:38 +000041 virtual ~RenderText();
eseidel3a6d1322006-01-09 03:14:50 +000042
akling@apple.com81497072013-07-26 20:41:32 +000043 virtual const char* renderName() const OVERRIDE;
eseidel3a6d1322006-01-09 03:14:50 +000044
antti@apple.com1936a2b2013-09-19 10:37:49 +000045 Text* textNode() const;
46
mitz@apple.comfb8da4e2008-02-19 21:13:19 +000047 virtual bool isTextFragment() const;
weinig695d48b2006-12-16 23:36:48 +000048
akling@apple.com827be9c2013-10-29 02:58:43 +000049 RenderStyle& style() const;
50 RenderStyle& firstLineStyle() const;
antti@apple.com7aae1752013-09-24 12:22:10 +000051
antti@apple.com1936a2b2013-09-19 10:37:49 +000052 virtual String originalText() const;
weinig695d48b2006-12-16 23:36:48 +000053
antti@apple.comb0b707f2013-10-12 17:41:13 +000054 void extractTextBox(InlineTextBox& box) { m_lineBoxes.extract(box); }
55 void attachTextBox(InlineTextBox& box) { m_lineBoxes.attach(box); }
56 void removeTextBox(InlineTextBox& box) { m_lineBoxes.remove(box); }
darin42563ac52007-01-22 17:28:57 +000057
hamaji@chromium.org5e3b1e22010-03-16 07:39:28 +000058 StringImpl* text() const { return m_text.impl(); }
antti@apple.com7530ae12013-09-30 16:21:54 +000059 String textWithoutConvertingBackslashToYenSymbol() const;
eseidel3a6d1322006-01-09 03:14:50 +000060
antti@apple.comb0b707f2013-10-12 17:41:13 +000061 InlineTextBox* createInlineTextBox() { return m_lineBoxes.createAndAppendLineBox(*this); }
hyatt@apple.comc92b7352009-02-12 01:35:08 +000062 void dirtyLineBoxes(bool fullLayout);
eseidel3a6d1322006-01-09 03:14:50 +000063
akling@apple.com81497072013-07-26 20:41:32 +000064 virtual void absoluteRects(Vector<IntRect>&, const LayoutPoint& accumulatedOffset) const OVERRIDE FINAL;
antti@apple.com61c4cde2013-10-13 11:05:33 +000065 Vector<IntRect> absoluteRectsForRange(unsigned startOffset = 0, unsigned endOffset = UINT_MAX, bool useSelectionHeight = false, bool* wasFixed = nullptr) const;
dbates@webkit.org395fca72013-12-06 19:59:38 +000066#if PLATFORM(IOS)
67 virtual void collectSelectionRects(Vector<SelectionRect>&, unsigned startOffset = 0, unsigned endOffset = std::numeric_limits<unsigned>::max()) OVERRIDE;
68#endif
eseidel3a6d1322006-01-09 03:14:50 +000069
akling@apple.com81497072013-07-26 20:41:32 +000070 virtual void absoluteQuads(Vector<FloatQuad>&, bool* wasFixed) const OVERRIDE FINAL;
antti@apple.com61c4cde2013-10-13 11:05:33 +000071 Vector<FloatQuad> absoluteQuadsForRange(unsigned startOffset = 0, unsigned endOffset = UINT_MAX, bool useSelectionHeight = false, bool* wasFixed = nullptr) const;
simon.fraser@apple.comaacf70e2008-11-12 23:43:52 +000072
antti@apple.com61c4cde2013-10-13 11:05:33 +000073 Vector<FloatQuad> absoluteQuadsClippedToEllipsis() const;
cfleizach@apple.com59dc4352010-09-15 17:07:46 +000074
antti@apple.com1936a2b2013-09-19 10:37:49 +000075 virtual VisiblePosition positionForPoint(const LayoutPoint&) OVERRIDE;
eseidel3a6d1322006-01-09 03:14:50 +000076
akling@apple.com2c97bdc82013-02-10 13:44:02 +000077 bool is8Bit() const { return m_text.is8Bit(); }
78 const LChar* characters8() const { return m_text.impl()->characters8(); }
79 const UChar* characters16() const { return m_text.impl()->characters16(); }
darin@apple.comda57a4d2014-01-13 02:29:47 +000080 const UChar* characters() const { return deprecatedCharacters(); } // FIXME: Delete this.
81 const UChar* deprecatedCharacters() const { return m_text.deprecatedCharacters(); }
akling@apple.com2c97bdc82013-02-10 13:44:02 +000082 UChar characterAt(unsigned i) const { return is8Bit() ? characters8()[i] : characters16()[i]; }
msaboff@apple.com776c286c72012-10-15 16:56:29 +000083 UChar operator[](unsigned i) const { return characterAt(i); }
akling@apple.com61cebcb2013-10-15 18:17:56 +000084 unsigned textLength() const { return m_text.impl()->length(); } // non virtual implementation of length()
akling@apple.com27e7d142013-11-07 12:04:02 +000085 void positionLineBox(InlineTextBox&);
eseidel3a6d1322006-01-09 03:14:50 +000086
hyatt@apple.com0acc9352011-02-17 19:19:07 +000087 virtual float width(unsigned from, unsigned len, const Font&, float xPos, HashSet<const SimpleFontData*>* fallbackFonts = 0, GlyphOverflow* = 0) const;
88 virtual float width(unsigned from, unsigned len, float xPos, bool firstLine = false, HashSet<const SimpleFontData*>* fallbackFonts = 0, GlyphOverflow* = 0) const;
eseidel3a6d1322006-01-09 03:14:50 +000089
hyatt@apple.com0acc9352011-02-17 19:19:07 +000090 float minLogicalWidth() const;
91 float maxLogicalWidth() const;
eseidel3a6d1322006-01-09 03:14:50 +000092
hyatt@apple.com0acc9352011-02-17 19:19:07 +000093 void trimmedPrefWidths(float leadWidth,
94 float& beginMinW, bool& beginWS,
95 float& endMinW, bool& endWS,
darin7e7c8e42007-04-25 01:14:03 +000096 bool& hasBreakableChar, bool& hasBreak,
hyatt@apple.com0acc9352011-02-17 19:19:07 +000097 float& beginMaxW, float& endMaxW,
98 float& minW, float& maxW, bool& stripFrontSpaces);
weinig0a635f02006-11-01 21:49:13 +000099
leviw@chromium.org0e791352012-04-18 00:30:04 +0000100 virtual IntRect linesBoundingBox() const;
eae@chromium.orgd0606372011-11-02 22:53:39 +0000101 LayoutRect linesVisualOverflowBoundingBox() const;
hyatt@apple.comd885df72009-01-22 02:31:52 +0000102
hyatt@apple.com0acc9352011-02-17 19:19:07 +0000103 FloatPoint firstRunOrigin() const;
104 float firstRunX() const;
105 float firstRunY() const;
eseidel3a6d1322006-01-09 03:14:50 +0000106
antti@apple.com1936a2b2013-09-19 10:37:49 +0000107 virtual void setText(const String&, bool force = false);
108 void setTextWithOffset(const String&, unsigned offset, unsigned len, bool force = false);
eseidel3a6d1322006-01-09 03:14:50 +0000109
andersca@apple.com70c60582013-10-07 16:26:16 +0000110 virtual bool canBeSelectionLeaf() const OVERRIDE { return true; }
akling@apple.com81497072013-07-26 20:41:32 +0000111 virtual void setSelectionState(SelectionState s) OVERRIDE FINAL;
simon.fraser@apple.coma4825062012-11-08 05:15:10 +0000112 virtual LayoutRect selectionRectForRepaint(const RenderLayerModelObject* repaintContainer, bool clipToVisibleContent = true) OVERRIDE;
andersca@apple.com70c60582013-10-07 16:26:16 +0000113 virtual LayoutRect localCaretRect(InlineBox*, int caretOffset, LayoutUnit* extraWidthToEndOfLine = 0) OVERRIDE;
eseidel3a6d1322006-01-09 03:14:50 +0000114
akling@apple.com827be9c2013-10-29 02:58:43 +0000115 LayoutUnit marginLeft() const { return minimumValueForLength(style().marginLeft(), 0); }
116 LayoutUnit marginRight() const { return minimumValueForLength(style().marginRight(), 0); }
eseidel3a6d1322006-01-09 03:14:50 +0000117
akling@apple.com81497072013-07-26 20:41:32 +0000118 virtual LayoutRect clippedOverflowRectForRepaint(const RenderLayerModelObject* repaintContainer) const OVERRIDE FINAL;
eseidel3a6d1322006-01-09 03:14:50 +0000119
antti@apple.comb0b707f2013-10-12 17:41:13 +0000120 InlineTextBox* firstTextBox() const { return m_lineBoxes.first(); }
121 InlineTextBox* lastTextBox() const { return m_lineBoxes.last(); }
weinig0a635f02006-11-01 21:49:13 +0000122
andersca@apple.com70c60582013-10-07 16:26:16 +0000123 virtual int caretMinOffset() const OVERRIDE;
124 virtual int caretMaxOffset() const OVERRIDE;
antti@apple.comc42b4b92013-10-16 14:33:31 +0000125 unsigned countRenderedCharacterOffsetsUntil(unsigned) const;
126 bool containsRenderedCharacterOffset(unsigned) const;
antti@apple.comcbd63992013-10-16 12:24:57 +0000127 bool containsCaretOffset(unsigned) const;
antti@apple.com3218a1b2013-10-12 14:51:01 +0000128 bool hasRenderedText() const;
eseidel3a6d1322006-01-09 03:14:50 +0000129
akling@apple.com81497072013-07-26 20:41:32 +0000130 virtual int previousOffset(int current) const OVERRIDE FINAL;
131 virtual int previousOffsetForBackwardDeletion(int current) const OVERRIDE FINAL;
132 virtual int nextOffset(int current) const OVERRIDE FINAL;
weinig695d48b2006-12-16 23:36:48 +0000133
darin38ae5342006-07-25 04:39:25 +0000134 bool containsReversedText() const { return m_containsReversedText; }
weinig695d48b2006-12-16 23:36:48 +0000135
akling@apple.com827be9c2013-10-29 02:58:43 +0000136 bool isSecure() const { return style().textSecurity() != TSNONE; }
commit-queue@webkit.orgdbd63aa2011-08-23 23:31:44 +0000137 void momentarilyRevealLastTypedCharacter(unsigned lastTypedCharacterOffset);
138
antti@apple.comb0b707f2013-10-12 17:41:13 +0000139 InlineTextBox* findNextInlineTextBox(int offset, int& pos) const { return m_lineBoxes.findNext(offset, pos); }
eseidel3a6d1322006-01-09 03:14:50 +0000140
akling@apple.com2c422762013-05-17 15:26:30 +0000141 bool isAllCollapsibleWhitespace() const;
hyatt@apple.comc2fdbe12012-04-12 21:06:50 +0000142
143 bool canUseSimpleFontCodePath() const { return m_canUseSimpleFontCodePath; }
hyatt@apple.com14e332d2011-03-25 21:57:07 +0000144
hyatt@apple.coma61b8a32011-04-06 18:20:52 +0000145 void removeAndDestroyTextBoxes();
146
antti@apple.com1e9a3182013-09-27 02:02:27 +0000147 virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle);
148
akling@apple.comb5f24642013-11-06 04:47:12 +0000149 virtual std::unique_ptr<InlineTextBox> createTextBox(); // Subclassed by RenderSVGInlineText.
antti@apple.comb0b707f2013-10-12 17:41:13 +0000150
dbates@webkit.orgacb8f4f2013-09-11 02:39:05 +0000151#if ENABLE(IOS_TEXT_AUTOSIZING)
152 float candidateComputedTextSize() const { return m_candidateComputedTextSize; }
153 void setCandidateComputedTextSize(float s) { m_candidateComputedTextSize = s; }
154#endif
155
antti@apple.com940f5872013-10-24 20:31:11 +0000156 void ensureLineBoxes();
157 void deleteLineBoxesBeforeSimpleLineLayout();
antti@apple.comfea51992013-10-28 13:39:23 +0000158 const SimpleLineLayout::Layout* simpleLineLayout() const;
antti@apple.com940f5872013-10-24 20:31:11 +0000159
weinig0a635f02006-11-01 21:49:13 +0000160protected:
ojan@chromium.org082802b2013-01-15 20:44:25 +0000161 virtual void computePreferredLogicalWidths(float leadWidth);
antti@apple.com1936a2b2013-09-19 10:37:49 +0000162 virtual void willBeDestroyed() OVERRIDE;
simon.fraser@apple.com73cb0b32011-07-09 00:43:14 +0000163
antti@apple.com1936a2b2013-09-19 10:37:49 +0000164 virtual void setTextInternal(const String&);
hamaji@chromium.org359e1312010-04-20 23:51:45 +0000165 virtual UChar previousCharacter() const;
darinec375482007-01-06 01:36:24 +0000166
167private:
antti@apple.comda4d3162013-09-23 17:43:04 +0000168 virtual bool canHaveChildren() const OVERRIDE FINAL { return false; }
169
hyatt@apple.com0acc9352011-02-17 19:19:07 +0000170 void computePreferredLogicalWidths(float leadWidth, HashSet<const SimpleFontData*>& fallbackFonts, GlyphOverflow&);
mitz@apple.comaa6ce3d2009-04-10 01:00:20 +0000171
hyatt@apple.comc2fdbe12012-04-12 21:06:50 +0000172 bool computeCanUseSimpleFontCodePath() const;
173
darin42563ac52007-01-22 17:28:57 +0000174 // Make length() private so that callers that have a RenderText*
175 // will use the more efficient textLength() instead, while
176 // callers with a RenderObject* can continue to use length().
akling@apple.com81497072013-07-26 20:41:32 +0000177 virtual unsigned length() const OVERRIDE FINAL { return textLength(); }
darinec375482007-01-06 01:36:24 +0000178
akling@apple.com81497072013-07-26 20:41:32 +0000179 virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestLocation&, const LayoutPoint&, HitTestAction) OVERRIDE FINAL { ASSERT_NOT_REACHED(); return false; }
darin@apple.com98a7ac62009-01-05 17:26:53 +0000180
darin42563ac52007-01-22 17:28:57 +0000181 bool containsOnlyWhitespace(unsigned from, unsigned len) const;
akling@apple.com51b98e22013-10-15 11:45:03 +0000182 float widthFromCache(const Font&, int start, int len, float xPos, HashSet<const SimpleFontData*>* fallbackFonts, GlyphOverflow*, const RenderStyle&) const;
darin42563ac52007-01-22 17:28:57 +0000183 bool isAllASCII() const { return m_isAllASCII; }
antti@apple.com7530ae12013-09-30 16:21:54 +0000184 bool computeUseBackslashAsYenSymbol() const;
hamaji@chromium.org359e1312010-04-20 23:51:45 +0000185
commit-queue@webkit.orgdbd63aa2011-08-23 23:31:44 +0000186 void secureText(UChar mask);
darin42563ac52007-01-22 17:28:57 +0000187
antti@apple.com1936a2b2013-09-19 10:37:49 +0000188 void node() const WTF_DELETED_FUNCTION;
189
kling@webkit.orgdcf15f82012-04-25 08:18:52 +0000190 // We put the bitfield first to minimize padding on 64-bit.
eseidel3a6d1322006-01-09 03:14:50 +0000191 bool m_hasBreakableChar : 1; // Whether or not we can be broken into multiple lines.
192 bool m_hasBreak : 1; // Whether or not we have a hard break (e.g., <pre> with '\n').
193 bool m_hasTab : 1; // Whether or not we have a variable width tab character (e.g., <pre> with '\t').
194 bool m_hasBeginWS : 1; // Whether or not we begin with WS (only true if we aren't pre)
195 bool m_hasEndWS : 1; // Whether or not we end with WS (only true if we aren't pre)
eseidel3a6d1322006-01-09 03:14:50 +0000196 bool m_linesDirty : 1; // This bit indicates that the text run has already dirtied specific
197 // line boxes, and this hint will enable layoutInlineChildren to avoid
198 // just dirtying everything when character data is modified (e.g., appended/inserted
199 // or removed).
200 bool m_containsReversedText : 1;
darin42563ac52007-01-22 17:28:57 +0000201 bool m_isAllASCII : 1;
hyatt@apple.comc2fdbe12012-04-12 21:06:50 +0000202 bool m_canUseSimpleFontCodePath : 1;
enrica@apple.comb9050ed2010-04-07 17:01:52 +0000203 mutable bool m_knownToHaveNoOverflowAndNoFallbackFonts : 1;
antti@apple.com7530ae12013-09-30 16:21:54 +0000204 bool m_useBackslashAsYenSymbol : 1;
antti@apple.com4973e7c2013-12-07 00:33:42 +0000205 bool m_originalTextDiffersFromRendered : 1;
antti@apple.com940f5872013-10-24 20:31:11 +0000206
dbates@webkit.orgacb8f4f2013-09-11 02:39:05 +0000207#if ENABLE(IOS_TEXT_AUTOSIZING)
208 // FIXME: This should probably be part of the text sizing structures in Document instead. That would save some memory.
209 float m_candidateComputedTextSize;
210#endif
kling@webkit.orgdcf15f82012-04-25 08:18:52 +0000211 float m_minWidth;
212 float m_maxWidth;
213 float m_beginMinWidth;
214 float m_endMinWidth;
215
216 String m_text;
217
antti@apple.comb0b707f2013-10-12 17:41:13 +0000218 RenderTextLineBoxes m_lineBoxes;
eseidel3a6d1322006-01-09 03:14:50 +0000219};
220
akling@apple.com4f406ee2013-11-02 19:51:51 +0000221template <> inline bool isRendererOfType<const RenderText>(const RenderObject& renderer) { return renderer.isText(); }
gyuyoung.kim@samsung.comb0b17cd2013-10-24 01:30:20 +0000222RENDER_OBJECT_TYPE_CASTS(RenderText, isText())
weinig@apple.com7c50a3b2009-01-30 19:55:45 +0000223
akling@apple.com827be9c2013-10-29 02:58:43 +0000224inline RenderStyle& RenderText::style() const
antti@apple.com1e9a3182013-09-27 02:02:27 +0000225{
226 return parent()->style();
227}
228
akling@apple.com827be9c2013-10-29 02:58:43 +0000229inline RenderStyle& RenderText::firstLineStyle() const
antti@apple.comb0608f62013-09-28 18:30:16 +0000230{
231 return parent()->firstLineStyle();
232}
233
akling@apple.comd1024452013-10-29 05:18:24 +0000234void applyTextTransform(const RenderStyle&, String&, UChar);
commit-queue@webkit.org83ab3ea2011-10-07 23:29:50 +0000235
antti@apple.come9c90162013-10-13 16:00:10 +0000236inline RenderText* Text::renderer() const
237{
238 return toRenderText(Node::renderer());
239}
240
weinig0a635f02006-11-01 21:49:13 +0000241} // namespace WebCore
eseidel3a6d1322006-01-09 03:14:50 +0000242
weinig0a635f02006-11-01 21:49:13 +0000243#endif // RenderText_h