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) |
36 { | 37 { |
37 } | 38 } |
38 | 39 |
39 RenderTextFragment::RenderTextFragment(Node* node, StringImpl* str) | 40 RenderTextFragment::RenderTextFragment(Node* node, StringImpl* str) |
40 : RenderText(node, str) | 41 : RenderText(node, str) |
41 , m_start(0) | 42 , m_start(0) |
42 , m_end(str ? str->length() : 0) | 43 , m_end(str ? str->length() : 0) |
43 , m_contentString(str) | 44 , m_contentString(str) |
44 , m_firstLetter(0) | 45 , m_firstLetter(0) |
| 46 , m_allowFragmentReset(true) |
45 { | 47 { |
46 } | 48 } |
47 | 49 |
48 RenderTextFragment::~RenderTextFragment() | 50 RenderTextFragment::~RenderTextFragment() |
49 { | 51 { |
50 } | 52 } |
51 | 53 |
52 PassRefPtr<StringImpl> RenderTextFragment::originalText() const | 54 PassRefPtr<StringImpl> RenderTextFragment::originalText() const |
53 { | 55 { |
54 Node* e = node(); | 56 Node* e = node(); |
55 RefPtr<StringImpl> result = ((e && e->isTextNode()) ? static_cast<Text*>(e)-
>dataImpl() : contentString()); | 57 RefPtr<StringImpl> result = ((e && e->isTextNode()) ? static_cast<Text*>(e)-
>dataImpl() : contentString()); |
56 if (!result) | 58 if (!result) |
57 return 0; | 59 return 0; |
58 return result->substring(start(), end()); | 60 return result->substring(start(), end()); |
59 } | 61 } |
60 | 62 |
61 void RenderTextFragment::styleDidChange(StyleDifference diff, const RenderStyle*
oldStyle) | 63 void RenderTextFragment::styleDidChange(StyleDifference diff, const RenderStyle*
oldStyle) |
62 { | 64 { |
| 65 m_allowFragmentReset = false; |
63 RenderText::styleDidChange(diff, oldStyle); | 66 RenderText::styleDidChange(diff, oldStyle); |
| 67 m_allowFragmentReset = true; |
64 | 68 |
65 if (RenderBlock* block = blockForAccompanyingFirstLetter()) { | 69 if (RenderBlock* block = blockForAccompanyingFirstLetter()) { |
66 block->style()->removeCachedPseudoStyle(FIRST_LETTER); | 70 block->style()->removeCachedPseudoStyle(FIRST_LETTER); |
67 block->updateFirstLetter(); | 71 block->updateFirstLetter(); |
68 } | 72 } |
69 } | 73 } |
70 | 74 |
71 void RenderTextFragment::willBeDestroyed() | 75 void RenderTextFragment::willBeDestroyed() |
72 { | 76 { |
73 if (m_firstLetter) | 77 if (m_firstLetter) |
74 m_firstLetter->destroy(); | 78 m_firstLetter->destroy(); |
75 RenderText::willBeDestroyed(); | 79 RenderText::willBeDestroyed(); |
76 } | 80 } |
77 | 81 |
78 void RenderTextFragment::setTextInternal(PassRefPtr<StringImpl> text) | 82 void RenderTextFragment::setTextInternal(PassRefPtr<StringImpl> text) |
79 { | 83 { |
80 RenderText::setTextInternal(text); | 84 RenderText::setTextInternal(text); |
81 if (m_firstLetter) { | 85 |
82 ASSERT(!m_contentString); | 86 if (m_allowFragmentReset) { |
83 m_firstLetter->destroy(); | |
84 m_firstLetter = 0; | |
85 m_start = 0; | 87 m_start = 0; |
86 m_end = textLength(); | 88 m_end = textLength(); |
87 if (Node* t = node()) { | 89 if (m_firstLetter) { |
88 ASSERT(!t->renderer()); | 90 ASSERT(!m_contentString); |
89 t->setRenderer(this); | 91 m_firstLetter->destroy(); |
| 92 m_firstLetter = 0; |
| 93 if (Node* t = node()) { |
| 94 ASSERT(!t->renderer()); |
| 95 t->setRenderer(this); |
| 96 } |
90 } | 97 } |
91 } | 98 } |
92 } | 99 } |
93 | 100 |
94 UChar RenderTextFragment::previousCharacter() const | 101 UChar RenderTextFragment::previousCharacter() const |
95 { | 102 { |
96 if (start()) { | 103 if (start()) { |
97 Node* e = node(); | 104 Node* e = node(); |
98 StringImpl* original = ((e && e->isTextNode()) ? static_cast<Text*>(e)-
>dataImpl() : contentString()); | 105 StringImpl* original = ((e && e->isTextNode()) ? static_cast<Text*>(e)-
>dataImpl() : contentString()); |
99 if (original && start() <= original->length()) | 106 if (original && start() <= original->length()) |
100 return (*original)[start() - 1]; | 107 return (*original)[start() - 1]; |
101 } | 108 } |
102 | 109 |
103 return RenderText::previousCharacter(); | 110 return RenderText::previousCharacter(); |
104 } | 111 } |
105 | 112 |
106 RenderBlock* RenderTextFragment::blockForAccompanyingFirstLetter() const | 113 RenderBlock* RenderTextFragment::blockForAccompanyingFirstLetter() const |
107 { | 114 { |
108 if (!m_firstLetter) | 115 if (!m_firstLetter) |
109 return 0; | 116 return 0; |
110 for (RenderObject* block = m_firstLetter->parent(); block; block = block->pa
rent()) { | 117 for (RenderObject* block = m_firstLetter->parent(); block; block = block->pa
rent()) { |
111 if (block->style()->hasPseudoStyle(FIRST_LETTER) && block->canHaveChildr
en() && block->isRenderBlock()) | 118 if (block->style()->hasPseudoStyle(FIRST_LETTER) && block->canHaveChildr
en() && block->isRenderBlock()) |
112 return toRenderBlock(block); | 119 return toRenderBlock(block); |
113 } | 120 } |
114 return 0; | 121 return 0; |
115 } | 122 } |
116 | 123 |
117 } // namespace WebCore | 124 } // namespace WebCore |
OLD | NEW |