• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "config.h"
24 #include "RenderTextFragment.h"
25 
26 #include "Text.h"
27 
28 namespace WebCore {
29 
RenderTextFragment(Node * node,StringImpl * str,int startOffset,int length)30 RenderTextFragment::RenderTextFragment(Node* node, StringImpl* str, int startOffset, int length)
31     : RenderText(node, str ? str->substring(startOffset, length) : 0)
32     , m_start(startOffset)
33     , m_end(length)
34     , m_firstLetter(0)
35 {
36 }
37 
RenderTextFragment(Node * node,StringImpl * str)38 RenderTextFragment::RenderTextFragment(Node* node, StringImpl* str)
39     : RenderText(node, str)
40     , m_start(0)
41     , m_end(str ? str->length() : 0)
42     , m_contentString(str)
43     , m_firstLetter(0)
44 {
45 }
46 
originalText() const47 PassRefPtr<StringImpl> RenderTextFragment::originalText() const
48 {
49     Node* e = node();
50     RefPtr<StringImpl> result = (e ? static_cast<Text*>(e)->string() : contentString());
51     if (result && (start() > 0 || start() < result->length()))
52         result = result->substring(start(), end());
53     return result.release();
54 }
55 
destroy()56 void RenderTextFragment::destroy()
57 {
58     if (m_firstLetter)
59         m_firstLetter->destroy();
60     RenderText::destroy();
61 }
62 
setTextInternal(PassRefPtr<StringImpl> text)63 void RenderTextFragment::setTextInternal(PassRefPtr<StringImpl> text)
64 {
65     RenderText::setTextInternal(text);
66     if (m_firstLetter) {
67         ASSERT(!m_contentString);
68         m_firstLetter->destroy();
69         m_firstLetter = 0;
70         m_start = 0;
71         m_end = textLength();
72     }
73 }
74 
previousCharacter()75 UChar RenderTextFragment::previousCharacter()
76 {
77     if (start()) {
78         Node* e = node();
79         StringImpl*  original = (e ? static_cast<Text*>(e)->string() : contentString());
80         if (original)
81             return (*original)[start() - 1];
82     }
83 
84     return RenderText::previousCharacter();
85 }
86 
87 } // namespace WebCore
88