OLD | NEW |
1 /* | 1 /* |
2 * (C) 1999 Lars Knoll (knoll@kde.org) | 2 * (C) 1999 Lars Knoll (knoll@kde.org) |
3 * (C) 2000 Dirk Mueller (mueller@kde.org) | 3 * (C) 2000 Dirk Mueller (mueller@kde.org) |
4 * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved. | 4 * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved. |
5 * | 5 * |
6 * This library is free software; you can redistribute it and/or | 6 * This library is free software; you can redistribute it and/or |
7 * modify it under the terms of the GNU Library General Public | 7 * modify it under the terms of the GNU Library General Public |
8 * License as published by the Free Software Foundation; either | 8 * License as published by the Free Software Foundation; either |
9 * version 2 of the License, or (at your option) any later version. | 9 * version 2 of the License, or (at your option) any later version. |
10 * | 10 * |
(...skipping 15 matching lines...) Expand all Loading... |
26 #include "RenderBlock.h" | 26 #include "RenderBlock.h" |
27 #include "Text.h" | 27 #include "Text.h" |
28 | 28 |
29 namespace WebCore { | 29 namespace WebCore { |
30 | 30 |
31 RenderTextFragment::RenderTextFragment(Node* node, StringImpl* str, int startOff
set, int length) | 31 RenderTextFragment::RenderTextFragment(Node* node, StringImpl* str, int startOff
set, int length) |
32 : RenderText(node, str ? str->substring(startOffset, length) : PassRefPtr<St
ringImpl>(0)) | 32 : RenderText(node, str ? str->substring(startOffset, length) : PassRefPtr<St
ringImpl>(0)) |
33 , m_start(startOffset) | 33 , m_start(startOffset) |
34 , m_end(length) | 34 , m_end(length) |
35 , m_firstLetter(0) | 35 , m_firstLetter(0) |
36 , m_allowFragmentReset(true) | |
37 { | 36 { |
38 } | 37 } |
39 | 38 |
40 RenderTextFragment::RenderTextFragment(Node* node, StringImpl* str) | 39 RenderTextFragment::RenderTextFragment(Node* node, StringImpl* str) |
41 : RenderText(node, str) | 40 : RenderText(node, str) |
42 , m_start(0) | 41 , m_start(0) |
43 , m_end(str ? str->length() : 0) | 42 , m_end(str ? str->length() : 0) |
44 , m_contentString(str) | 43 , m_contentString(str) |
45 , m_firstLetter(0) | 44 , m_firstLetter(0) |
46 , m_allowFragmentReset(true) | |
47 { | 45 { |
48 } | 46 } |
49 | 47 |
50 RenderTextFragment::~RenderTextFragment() | 48 RenderTextFragment::~RenderTextFragment() |
51 { | 49 { |
52 } | 50 } |
53 | 51 |
54 PassRefPtr<StringImpl> RenderTextFragment::originalText() const | 52 PassRefPtr<StringImpl> RenderTextFragment::originalText() const |
55 { | 53 { |
56 Node* e = node(); | 54 Node* e = node(); |
57 RefPtr<StringImpl> result = ((e && e->isTextNode()) ? static_cast<Text*>(e)-
>dataImpl() : contentString()); | 55 RefPtr<StringImpl> result = ((e && e->isTextNode()) ? static_cast<Text*>(e)-
>dataImpl() : contentString()); |
58 if (!result) | 56 if (!result) |
59 return 0; | 57 return 0; |
60 return result->substring(start(), end()); | 58 return result->substring(start(), end()); |
61 } | 59 } |
62 | 60 |
63 void RenderTextFragment::styleDidChange(StyleDifference diff, const RenderStyle*
oldStyle) | 61 void RenderTextFragment::styleDidChange(StyleDifference diff, const RenderStyle*
oldStyle) |
64 { | 62 { |
65 m_allowFragmentReset = false; | |
66 RenderText::styleDidChange(diff, oldStyle); | 63 RenderText::styleDidChange(diff, oldStyle); |
67 m_allowFragmentReset = true; | |
68 | 64 |
69 if (RenderBlock* block = blockForAccompanyingFirstLetter()) { | 65 if (RenderBlock* block = blockForAccompanyingFirstLetter()) { |
70 block->style()->removeCachedPseudoStyle(FIRST_LETTER); | 66 block->style()->removeCachedPseudoStyle(FIRST_LETTER); |
71 block->updateFirstLetter(); | 67 block->updateFirstLetter(); |
72 } | 68 } |
73 } | 69 } |
74 | 70 |
75 void RenderTextFragment::willBeDestroyed() | 71 void RenderTextFragment::willBeDestroyed() |
76 { | 72 { |
77 if (m_firstLetter) | 73 if (m_firstLetter) |
78 m_firstLetter->destroy(); | 74 m_firstLetter->destroy(); |
79 RenderText::willBeDestroyed(); | 75 RenderText::willBeDestroyed(); |
80 } | 76 } |
81 | 77 |
82 void RenderTextFragment::setTextInternal(PassRefPtr<StringImpl> text) | 78 void RenderTextFragment::setText(PassRefPtr<StringImpl> text, bool force) |
83 { | 79 { |
84 RenderText::setTextInternal(text); | 80 RenderText::setText(text, force); |
85 | 81 |
86 if (m_allowFragmentReset) { | 82 m_start = 0; |
87 m_start = 0; | 83 m_end = textLength(); |
88 m_end = textLength(); | 84 if (m_firstLetter) { |
89 if (m_firstLetter) { | 85 ASSERT(!m_contentString); |
90 ASSERT(!m_contentString); | 86 m_firstLetter->destroy(); |
91 m_firstLetter->destroy(); | 87 m_firstLetter = 0; |
92 m_firstLetter = 0; | 88 if (Node* t = node()) { |
93 if (Node* t = node()) { | 89 ASSERT(!t->renderer()); |
94 ASSERT(!t->renderer()); | 90 t->setRenderer(this); |
95 t->setRenderer(this); | |
96 } | |
97 } | 91 } |
98 } | 92 } |
99 } | 93 } |
100 | 94 |
| 95 void RenderTextFragment::transformText() |
| 96 { |
| 97 // Don't reset first-letter here because we are only transforming the trunca
ted fragment. |
| 98 if (RefPtr<StringImpl> textToTransform = originalText()) |
| 99 RenderText::setText(textToTransform.release(), true); |
| 100 } |
| 101 |
101 UChar RenderTextFragment::previousCharacter() const | 102 UChar RenderTextFragment::previousCharacter() const |
102 { | 103 { |
103 if (start()) { | 104 if (start()) { |
104 Node* e = node(); | 105 Node* e = node(); |
105 StringImpl* original = ((e && e->isTextNode()) ? static_cast<Text*>(e)-
>dataImpl() : contentString()); | 106 StringImpl* original = ((e && e->isTextNode()) ? static_cast<Text*>(e)-
>dataImpl() : contentString()); |
106 if (original && start() <= original->length()) | 107 if (original && start() <= original->length()) |
107 return (*original)[start() - 1]; | 108 return (*original)[start() - 1]; |
108 } | 109 } |
109 | 110 |
110 return RenderText::previousCharacter(); | 111 return RenderText::previousCharacter(); |
111 } | 112 } |
112 | 113 |
113 RenderBlock* RenderTextFragment::blockForAccompanyingFirstLetter() const | 114 RenderBlock* RenderTextFragment::blockForAccompanyingFirstLetter() const |
114 { | 115 { |
115 if (!m_firstLetter) | 116 if (!m_firstLetter) |
116 return 0; | 117 return 0; |
117 for (RenderObject* block = m_firstLetter->parent(); block; block = block->pa
rent()) { | 118 for (RenderObject* block = m_firstLetter->parent(); block; block = block->pa
rent()) { |
118 if (block->style()->hasPseudoStyle(FIRST_LETTER) && block->canHaveChildr
en() && block->isRenderBlock()) | 119 if (block->style()->hasPseudoStyle(FIRST_LETTER) && block->canHaveChildr
en() && block->isRenderBlock()) |
119 return toRenderBlock(block); | 120 return toRenderBlock(block); |
120 } | 121 } |
121 return 0; | 122 return 0; |
122 } | 123 } |
123 | 124 |
124 } // namespace WebCore | 125 } // namespace WebCore |
OLD | NEW |