| OLD | NEW |
| (Empty) |
| 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 "core/rendering/RenderTextFragment.h" | |
| 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" | |
| 30 #include "core/layout/HitTestResult.h" | |
| 31 #include "core/layout/LayoutBlock.h" | |
| 32 | |
| 33 namespace blink { | |
| 34 | |
| 35 RenderTextFragment::RenderTextFragment(Node* node, StringImpl* str, int startOff
set, int length) | |
| 36 : RenderText(node, str ? str->substring(startOffset, length) : PassRefPtr<St
ringImpl>(nullptr)) | |
| 37 , m_start(startOffset) | |
| 38 , m_end(length) | |
| 39 , m_isRemainingTextRenderer(false) | |
| 40 , m_contentString(str) | |
| 41 , m_firstLetterPseudoElement(nullptr) | |
| 42 { | |
| 43 } | |
| 44 | |
| 45 RenderTextFragment::RenderTextFragment(Node* node, StringImpl* str) | |
| 46 : RenderText(node, str) | |
| 47 , m_start(0) | |
| 48 , m_end(str ? str->length() : 0) | |
| 49 , m_isRemainingTextRenderer(false) | |
| 50 , m_contentString(str) | |
| 51 , m_firstLetterPseudoElement(nullptr) | |
| 52 { | |
| 53 } | |
| 54 | |
| 55 RenderTextFragment::~RenderTextFragment() | |
| 56 { | |
| 57 ASSERT(!m_firstLetterPseudoElement); | |
| 58 } | |
| 59 | |
| 60 void RenderTextFragment::destroy() | |
| 61 { | |
| 62 if (m_isRemainingTextRenderer && m_firstLetterPseudoElement) | |
| 63 m_firstLetterPseudoElement->setRemainingTextRenderer(nullptr); | |
| 64 m_firstLetterPseudoElement = nullptr; | |
| 65 RenderText::destroy(); | |
| 66 } | |
| 67 | |
| 68 PassRefPtr<StringImpl> RenderTextFragment::completeText() const | |
| 69 { | |
| 70 Text* text = associatedTextNode(); | |
| 71 return text ? text->dataImpl() : contentString(); | |
| 72 } | |
| 73 | |
| 74 void RenderTextFragment::setContentString(StringImpl* str) | |
| 75 { | |
| 76 m_contentString = str; | |
| 77 setText(str); | |
| 78 } | |
| 79 | |
| 80 PassRefPtr<StringImpl> RenderTextFragment::originalText() const | |
| 81 { | |
| 82 RefPtr<StringImpl> result = completeText(); | |
| 83 if (!result) | |
| 84 return nullptr; | |
| 85 return result->substring(start(), end()); | |
| 86 } | |
| 87 | |
| 88 void RenderTextFragment::setText(PassRefPtr<StringImpl> text, bool force) | |
| 89 { | |
| 90 RenderText::setText(text, force); | |
| 91 | |
| 92 m_start = 0; | |
| 93 m_end = textLength(); | |
| 94 | |
| 95 // If we're the remaining text from a first letter then we have to tell the | |
| 96 // first letter pseudo element to reattach itself so it can re-calculate the | |
| 97 // correct first-letter settings. | |
| 98 if (LayoutObject* previous = previousSibling()) { | |
| 99 if (!previous->isPseudoElement() || !previous->node()->isFirstLetterPseu
doElement()) | |
| 100 return; | |
| 101 | |
| 102 // Tell the first letter container node, and the first-letter node | |
| 103 // that their text content changed. | |
| 104 toFirstLetterPseudoElement(previous->node())->updateTextFragments(); | |
| 105 } | |
| 106 } | |
| 107 | |
| 108 void RenderTextFragment::setTextFragment(PassRefPtr<StringImpl> text, unsigned s
tart, unsigned length) | |
| 109 { | |
| 110 RenderText::setText(text, false); | |
| 111 | |
| 112 m_start = start; | |
| 113 m_end = length; | |
| 114 } | |
| 115 | |
| 116 void RenderTextFragment::transformText() | |
| 117 { | |
| 118 // Note, we have to call RenderText::setText here because, if we use our | |
| 119 // version we will, potentially, screw up the first-letter settings where | |
| 120 // we only use portions of the string. | |
| 121 if (RefPtr<StringImpl> textToTransform = originalText()) | |
| 122 RenderText::setText(textToTransform.release(), true); | |
| 123 } | |
| 124 | |
| 125 UChar RenderTextFragment::previousCharacter() const | |
| 126 { | |
| 127 if (start()) { | |
| 128 StringImpl* original = completeText().get(); | |
| 129 if (original && start() <= original->length()) | |
| 130 return (*original)[start() - 1]; | |
| 131 } | |
| 132 | |
| 133 return RenderText::previousCharacter(); | |
| 134 } | |
| 135 | |
| 136 // If this is the renderer for a first-letter pseudoNode then we have to look | |
| 137 // at the node for the remaining text to find our content. | |
| 138 Text* RenderTextFragment::associatedTextNode() const | |
| 139 { | |
| 140 Node* node = this->firstLetterPseudoElement(); | |
| 141 if (m_isRemainingTextRenderer || !node) { | |
| 142 // If we don't have a node, then we aren't part of a first-letter pseudo | |
| 143 // element, so use the actual node. Likewise, if we have a node, but | |
| 144 // we're the remainingTextRenderer for a pseudo element use the real | |
| 145 // text node. | |
| 146 node = this->node(); | |
| 147 } | |
| 148 | |
| 149 if (!node) | |
| 150 return nullptr; | |
| 151 | |
| 152 if (node->isFirstLetterPseudoElement()) { | |
| 153 FirstLetterPseudoElement* pseudo = toFirstLetterPseudoElement(node); | |
| 154 LayoutObject* nextRenderer = FirstLetterPseudoElement::firstLetterTextRe
nderer(*pseudo); | |
| 155 if (!nextRenderer) | |
| 156 return nullptr; | |
| 157 node = nextRenderer->node(); | |
| 158 } | |
| 159 return (node && node->isTextNode()) ? toText(node) : nullptr; | |
| 160 } | |
| 161 | |
| 162 } // namespace blink | |
| OLD | NEW |