de9858c4862a0c0ffd4b4e93ff6645d3eb747f61
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / rendering / RenderTextFragment.h
1 /*
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.
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 RenderTextFragment_h
24 #define RenderTextFragment_h
25
26 #include "core/rendering/RenderText.h"
27
28 namespace WebCore {
29
30 // Used to represent a text substring of an element, e.g., for text runs that are split because of
31 // first letter and that must therefore have different styles (and positions in the render tree).
32 // We cache offsets so that text transformations can be applied in such a way that we can recover
33 // the original unaltered string from our corresponding DOM node.
34 class RenderTextFragment FINAL : public RenderText {
35 public:
36     RenderTextFragment(Node*, StringImpl*, int startOffset, int length);
37     RenderTextFragment(Node*, StringImpl*);
38     virtual ~RenderTextFragment();
39
40     virtual bool isTextFragment() const OVERRIDE { return true; }
41
42     virtual bool canBeSelectionLeaf() const OVERRIDE { return node() && node()->rendererIsEditable(); }
43
44     unsigned start() const { return m_start; }
45     unsigned end() const { return m_end; }
46     virtual unsigned textStartOffset() const OVERRIDE { return start(); }
47
48     RenderBoxModelObject* firstLetter() const { return m_firstLetter; }
49     void setFirstLetter(RenderBoxModelObject* firstLetter) { m_firstLetter = firstLetter; }
50     RenderText* firstRenderTextInFirstLetter() const;
51
52     StringImpl* contentString() const { return m_contentString.get(); }
53     virtual PassRefPtr<StringImpl> originalText() const OVERRIDE;
54
55     virtual void setText(PassRefPtr<StringImpl>, bool force = false) OVERRIDE;
56
57     virtual void transformText() OVERRIDE;
58
59 protected:
60     virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle) OVERRIDE;
61
62 private:
63     virtual void willBeDestroyed() OVERRIDE;
64
65     virtual UChar previousCharacter() const OVERRIDE;
66     RenderBlock* blockForAccompanyingFirstLetter() const;
67     virtual void updateHitTestResult(HitTestResult&, const LayoutPoint&) OVERRIDE;
68
69     unsigned m_start;
70     unsigned m_end;
71     RefPtr<StringImpl> m_contentString;
72     RenderBoxModelObject* m_firstLetter;
73 };
74
75 DEFINE_TYPE_CASTS(RenderTextFragment, RenderObject, object, toRenderText(object)->isTextFragment(), toRenderText(object).isTextFragment());
76
77 } // namespace WebCore
78
79 #endif // RenderTextFragment_h