2 * (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 2000 Dirk Mueller (mueller@kde.org)
4 * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved.
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.
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.
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.
23 #ifndef LayoutTextFragment_h
24 #define LayoutTextFragment_h
26 #include "core/layout/LayoutText.h"
30 class FirstLetterPseudoElement
;
32 // Used to represent a text substring of an element, e.g., for text runs that are split because of
33 // first letter and that must therefore have different styles (and positions in the layout tree).
34 // We cache offsets so that text transformations can be applied in such a way that we can recover
35 // the original unaltered string from our corresponding DOM node.
36 class LayoutTextFragment final
: public LayoutText
{
38 LayoutTextFragment(Node
*, StringImpl
*, int startOffset
, int length
);
39 LayoutTextFragment(Node
*, StringImpl
*);
40 ~LayoutTextFragment() override
;
42 bool isTextFragment() const override
{ return true; }
44 bool canBeSelectionLeaf() const override
{ return node() && node()->hasEditableStyle(); }
46 unsigned start() const { return m_start
; }
47 unsigned end() const { return m_end
; }
49 unsigned textStartOffset() const override
{ return start(); }
51 void setContentString(StringImpl
*);
52 StringImpl
* contentString() const { return m_contentString
.get(); }
53 // The complete text is all of the text in the associated DOM text node.
54 PassRefPtr
<StringImpl
> completeText() const;
55 // The fragment text is the text which will be used by this LayoutTextFragment. For
56 // things like first-letter this may differ from the completeText as we maybe using
57 // only a portion of the text nodes content.
59 PassRefPtr
<StringImpl
> originalText() const override
;
61 void setText(PassRefPtr
<StringImpl
>, bool force
= false) override
;
62 void setTextFragment(PassRefPtr
<StringImpl
>, unsigned start
, unsigned length
);
64 void transformText() override
;
66 // FIXME: Rename to LayoutTextFragment
67 const char* name() const override
{ return "LayoutTextFragment"; }
69 void setFirstLetterPseudoElement(FirstLetterPseudoElement
* element
) { m_firstLetterPseudoElement
= element
; }
70 FirstLetterPseudoElement
* firstLetterPseudoElement() const { return m_firstLetterPseudoElement
; }
72 void setIsRemainingTextLayoutObject(bool isRemainingText
) { m_isRemainingTextLayoutObject
= isRemainingText
; }
73 bool isRemainingTextLayoutObject() const { return m_isRemainingTextLayoutObject
; }
76 void willBeDestroyed() override
;
79 LayoutBlock
* blockForAccompanyingFirstLetter() const;
80 UChar
previousCharacter() const override
;
82 Text
* associatedTextNode() const;
83 void updateHitTestResult(HitTestResult
&, const LayoutPoint
&) override
;
87 bool m_isRemainingTextLayoutObject
;
88 RefPtr
<StringImpl
> m_contentString
;
89 // Reference back to FirstLetterPseudoElement; cleared by FirstLetterPseudoElement::detach() if
90 // it goes away first.
91 GC_PLUGIN_IGNORE("http://crbug.com/509911")
92 FirstLetterPseudoElement
* m_firstLetterPseudoElement
;
95 DEFINE_TYPE_CASTS(LayoutTextFragment
, LayoutObject
, object
, toLayoutText(object
)->isTextFragment(), toLayoutText(object
).isTextFragment());
99 #endif // LayoutTextFragment_h