| 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 * |
| 11 * This library is distributed in the hope that it will be useful, | 11 * This library is distributed in the hope that it will be useful, |
| 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 * Library General Public License for more details. | 14 * Library General Public License for more details. |
| 15 * | 15 * |
| 16 * You should have received a copy of the GNU Library General Public License | 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 | 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, | 18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 19 * Boston, MA 02110-1301, USA. | 19 * Boston, MA 02110-1301, USA. |
| 20 * | 20 * |
| 21 */ | 21 */ |
| 22 | 22 |
| 23 #include "config.h" | 23 #include "config.h" |
| 24 #include "core/rendering/RenderTextFragment.h" | 24 #include "core/rendering/RenderTextFragment.h" |
| 25 | 25 |
| 26 #include "core/dom/FirstLetterPseudoElement.h" | |
| 27 #include "core/dom/PseudoElement.h" | |
| 28 #include "core/dom/StyleChangeReason.h" | |
| 29 #include "core/dom/Text.h" | 26 #include "core/dom/Text.h" |
| 30 #include "core/rendering/HitTestResult.h" | 27 #include "core/rendering/HitTestResult.h" |
| 31 #include "core/rendering/RenderBlock.h" | 28 #include "core/rendering/RenderBlock.h" |
| 32 | 29 |
| 33 namespace blink { | 30 namespace blink { |
| 34 | 31 |
| 35 RenderTextFragment::RenderTextFragment(Node* node, StringImpl* str, int startOff
set, int length) | 32 RenderTextFragment::RenderTextFragment(Node* node, StringImpl* str, int startOff
set, int length) |
| 36 : RenderText(node, str ? str->substring(startOffset, length) : PassRefPtr<St
ringImpl>(nullptr)) | 33 : RenderText(node, str ? str->substring(startOffset, length) : PassRefPtr<St
ringImpl>(nullptr)) |
| 37 , m_start(startOffset) | 34 , m_start(startOffset) |
| 38 , m_end(length) | 35 , m_end(length) |
| 39 , m_isRemainingTextRenderer(false) | 36 , m_firstLetter(nullptr) |
| 40 , m_firstLetterPseudoElement(nullptr) | |
| 41 { | 37 { |
| 42 } | 38 } |
| 43 | 39 |
| 44 RenderTextFragment::RenderTextFragment(Node* node, StringImpl* str) | 40 RenderTextFragment::RenderTextFragment(Node* node, StringImpl* str) |
| 45 : RenderText(node, str) | 41 : RenderText(node, str) |
| 46 , m_start(0) | 42 , m_start(0) |
| 47 , m_end(str ? str->length() : 0) | 43 , m_end(str ? str->length() : 0) |
| 48 , m_isRemainingTextRenderer(false) | |
| 49 , m_contentString(str) | 44 , m_contentString(str) |
| 50 , m_firstLetterPseudoElement(nullptr) | 45 , m_firstLetter(nullptr) |
| 51 { | 46 { |
| 52 } | 47 } |
| 53 | 48 |
| 54 RenderTextFragment::~RenderTextFragment() | 49 RenderTextFragment::~RenderTextFragment() |
| 55 { | 50 { |
| 56 ASSERT(!m_firstLetterPseudoElement); | |
| 57 } | |
| 58 | |
| 59 void RenderTextFragment::destroy() | |
| 60 { | |
| 61 if (m_isRemainingTextRenderer && m_firstLetterPseudoElement) | |
| 62 m_firstLetterPseudoElement->setRemainingTextRenderer(nullptr); | |
| 63 m_firstLetterPseudoElement = nullptr; | |
| 64 RenderText::destroy(); | |
| 65 } | 51 } |
| 66 | 52 |
| 67 void RenderTextFragment::trace(Visitor* visitor) | 53 void RenderTextFragment::trace(Visitor* visitor) |
| 68 { | 54 { |
| 69 visitor->trace(m_firstLetterPseudoElement); | 55 visitor->trace(m_firstLetter); |
| 70 RenderText::trace(visitor); | 56 RenderText::trace(visitor); |
| 71 } | 57 } |
| 72 | 58 |
| 73 PassRefPtr<StringImpl> RenderTextFragment::completeText() const | 59 RenderText* RenderTextFragment::firstRenderTextInFirstLetter() const |
| 74 { | 60 { |
| 75 Text* text = associatedTextNode(); | 61 for (RenderObject* current = m_firstLetter; current; current = current->next
InPreOrder(m_firstLetter)) { |
| 76 return text ? text->dataImpl() : contentString(); | 62 if (current->isText()) |
| 63 return toRenderText(current); |
| 64 } |
| 65 return 0; |
| 77 } | 66 } |
| 78 | 67 |
| 79 PassRefPtr<StringImpl> RenderTextFragment::originalText() const | 68 PassRefPtr<StringImpl> RenderTextFragment::originalText() const |
| 80 { | 69 { |
| 81 RefPtr<StringImpl> result = completeText(); | 70 Node* e = node(); |
| 71 RefPtr<StringImpl> result = ((e && e->isTextNode()) ? toText(e)->dataImpl()
: contentString()); |
| 82 if (!result) | 72 if (!result) |
| 83 return nullptr; | 73 return nullptr; |
| 84 return result->substring(start(), end()); | 74 return result->substring(start(), end()); |
| 85 } | 75 } |
| 86 | 76 |
| 77 void RenderTextFragment::styleDidChange(StyleDifference diff, const RenderStyle*
oldStyle) |
| 78 { |
| 79 RenderText::styleDidChange(diff, oldStyle); |
| 80 |
| 81 if (RenderBlock* block = blockForAccompanyingFirstLetter()) { |
| 82 block->style()->removeCachedPseudoStyle(FIRST_LETTER); |
| 83 block->updateFirstLetter(); |
| 84 } |
| 85 } |
| 86 |
| 87 void RenderTextFragment::willBeDestroyed() |
| 88 { |
| 89 if (m_firstLetter) |
| 90 m_firstLetter->destroy(); |
| 91 RenderText::willBeDestroyed(); |
| 92 } |
| 93 |
| 87 void RenderTextFragment::setText(PassRefPtr<StringImpl> text, bool force) | 94 void RenderTextFragment::setText(PassRefPtr<StringImpl> text, bool force) |
| 88 { | 95 { |
| 89 RenderText::setText(text, force); | 96 RenderText::setText(text, force); |
| 90 | 97 |
| 91 m_start = 0; | 98 m_start = 0; |
| 92 m_end = textLength(); | 99 m_end = textLength(); |
| 100 if (m_firstLetter) { |
| 101 // FIXME: We should not modify the structure of the render tree during |
| 102 // layout. crbug.com/370458 |
| 103 DeprecatedDisableModifyRenderTreeStructureAsserts disabler; |
| 93 | 104 |
| 94 // If we're the remaining text from a first letter then we have to tell the | 105 ASSERT(!m_contentString); |
| 95 // first letter pseudo element to reattach itself so it can re-calculate the | 106 m_firstLetter->destroy(); |
| 96 // correct first-letter settings. | 107 m_firstLetter = nullptr; |
| 97 if (RenderObject* previous = previousSibling()) { | 108 if (Node* t = node()) { |
| 98 if (!previous->isPseudoElement() || !previous->node()->isFirstLetterPseu
doElement()) | 109 ASSERT(!t->renderer()); |
| 99 return; | 110 t->setRenderer(this); |
| 100 | 111 } |
| 101 // Tell the first letter container node, and the first-letter node | |
| 102 // that their style may have changed. | |
| 103 // e.g. fast/css/first-letter-detach.html | |
| 104 toFirstLetterPseudoElement(previous->node())->setNeedsUpdate(); | |
| 105 } | 112 } |
| 106 } | 113 } |
| 107 | 114 |
| 108 void RenderTextFragment::transformText() | 115 void RenderTextFragment::transformText() |
| 109 { | 116 { |
| 110 // Note, we have to call RenderText::setText here because, if we use our | 117 // Don't reset first-letter here because we are only transforming the trunca
ted fragment. |
| 111 // version we will, potentially, screw up the first-letter settings where | |
| 112 // we only use portions of the string. | |
| 113 if (RefPtr<StringImpl> textToTransform = originalText()) | 118 if (RefPtr<StringImpl> textToTransform = originalText()) |
| 114 RenderText::setText(textToTransform.release(), true); | 119 RenderText::setText(textToTransform.release(), true); |
| 115 } | 120 } |
| 116 | 121 |
| 117 UChar RenderTextFragment::previousCharacter() const | 122 UChar RenderTextFragment::previousCharacter() const |
| 118 { | 123 { |
| 119 if (start()) { | 124 if (start()) { |
| 120 StringImpl* original = completeText().get(); | 125 Node* e = node(); |
| 126 StringImpl* original = ((e && e->isTextNode()) ? toText(e)->dataImpl() :
contentString()); |
| 121 if (original && start() <= original->length()) | 127 if (original && start() <= original->length()) |
| 122 return (*original)[start() - 1]; | 128 return (*original)[start() - 1]; |
| 123 } | 129 } |
| 124 | 130 |
| 125 return RenderText::previousCharacter(); | 131 return RenderText::previousCharacter(); |
| 126 } | 132 } |
| 127 | 133 |
| 128 // If this is the renderer for a first-letter pseudoNode then we have to look | 134 RenderBlock* RenderTextFragment::blockForAccompanyingFirstLetter() const |
| 129 // at the node for the remaining text to find our content. | |
| 130 Text* RenderTextFragment::associatedTextNode() const | |
| 131 { | 135 { |
| 132 Node* node = m_isRemainingTextRenderer ? this->node() : this->firstLetterPse
udoElement(); | 136 if (!m_firstLetter) |
| 133 if (!node) | 137 return 0; |
| 134 return nullptr; | 138 for (RenderObject* block = m_firstLetter->parent(); block; block = block->pa
rent()) { |
| 139 if (block->style()->hasPseudoStyle(FIRST_LETTER) && block->canHaveChildr
en() && block->isRenderBlock()) |
| 140 return toRenderBlock(block); |
| 141 } |
| 142 return 0; |
| 143 } |
| 135 | 144 |
| 136 if (node->isFirstLetterPseudoElement()) { | 145 void RenderTextFragment::updateHitTestResult(HitTestResult& result, const Layout
Point& point) |
| 137 FirstLetterPseudoElement* pseudo = toFirstLetterPseudoElement(node); | 146 { |
| 138 RenderObject* nextRenderer = FirstLetterPseudoElement::firstLetterTextRe
nderer(*pseudo); | 147 if (result.innerNode()) |
| 139 if (!nextRenderer) | 148 return; |
| 140 return nullptr; | 149 |
| 141 node = nextRenderer->node(); | 150 RenderObject::updateHitTestResult(result, point); |
| 142 } | 151 if (m_firstLetter || !node()) |
| 143 return (node && node->isTextNode()) ? toText(node) : nullptr; | 152 return; |
| 153 RenderObject* nodeRenderer = node()->renderer(); |
| 154 if (!nodeRenderer || !nodeRenderer->isText() || !toRenderText(nodeRenderer)-
>isTextFragment()) |
| 155 return; |
| 156 |
| 157 if (isDescendantOf(toRenderTextFragment(nodeRenderer)->m_firstLetter)) |
| 158 result.setIsFirstLetter(true); |
| 144 } | 159 } |
| 145 | 160 |
| 146 } // namespace blink | 161 } // namespace blink |
| OLD | NEW |