Chromium Code Reviews| 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/PseudoElement.h" | |
| 26 #include "core/dom/Text.h" | 27 #include "core/dom/Text.h" |
| 27 #include "core/rendering/HitTestResult.h" | 28 #include "core/rendering/HitTestResult.h" |
| 28 #include "core/rendering/RenderBlock.h" | 29 #include "core/rendering/RenderBlock.h" |
| 29 | 30 |
| 30 namespace blink { | 31 namespace blink { |
| 31 | 32 |
| 32 RenderTextFragment::RenderTextFragment(Node* node, StringImpl* str, int startOff set, int length) | 33 RenderTextFragment::RenderTextFragment(Node* node, StringImpl* str, int startOff set, int length) |
| 33 : RenderText(node, str ? str->substring(startOffset, length) : PassRefPtr<St ringImpl>(nullptr)) | 34 : RenderText(node, str ? str->substring(startOffset, length) : PassRefPtr<St ringImpl>(nullptr)) |
| 34 , m_start(startOffset) | 35 , m_start(startOffset) |
| 35 , m_end(length) | 36 , m_end(length) |
| 36 , m_firstLetter(nullptr) | |
| 37 { | 37 { |
| 38 } | 38 } |
| 39 | 39 |
| 40 RenderTextFragment::RenderTextFragment(Node* node, StringImpl* str) | 40 RenderTextFragment::RenderTextFragment(Node* node, StringImpl* str) |
| 41 : RenderText(node, str) | 41 : RenderText(node, str) |
| 42 , m_start(0) | 42 , m_start(0) |
| 43 , m_end(str ? str->length() : 0) | 43 , m_end(str ? str->length() : 0) |
| 44 , m_contentString(str) | 44 , m_contentString(str) |
| 45 , m_firstLetter(nullptr) | |
| 46 { | 45 { |
| 47 } | 46 } |
| 48 | 47 |
| 49 RenderTextFragment::~RenderTextFragment() | 48 RenderTextFragment::~RenderTextFragment() |
| 50 { | 49 { |
| 51 } | 50 } |
| 52 | 51 |
| 53 void RenderTextFragment::trace(Visitor* visitor) | 52 PassRefPtr<StringImpl> RenderTextFragment::completeText() const |
| 54 { | 53 { |
| 55 visitor->trace(m_firstLetter); | 54 Text* e = associatedTextNode(); |
|
esprehn
2014/09/30 09:00:31
text =, no single letter variables.
dsinclair
2014/09/30 21:46:34
Done.
| |
| 56 RenderText::trace(visitor); | 55 return e ? e->dataImpl() : contentString(); |
| 57 } | |
| 58 | |
| 59 RenderText* RenderTextFragment::firstRenderTextInFirstLetter() const | |
| 60 { | |
| 61 for (RenderObject* current = m_firstLetter; current; current = current->next InPreOrder(m_firstLetter)) { | |
| 62 if (current->isText()) | |
| 63 return toRenderText(current); | |
| 64 } | |
| 65 return 0; | |
| 66 } | 56 } |
| 67 | 57 |
| 68 PassRefPtr<StringImpl> RenderTextFragment::originalText() const | 58 PassRefPtr<StringImpl> RenderTextFragment::originalText() const |
| 69 { | 59 { |
| 70 Node* e = node(); | 60 RefPtr<StringImpl> result = completeText(); |
| 71 RefPtr<StringImpl> result = ((e && e->isTextNode()) ? toText(e)->dataImpl() : contentString()); | |
| 72 if (!result) | 61 if (!result) |
| 73 return nullptr; | 62 return nullptr; |
| 74 return result->substring(start(), end()); | 63 return result->substring(start(), end()); |
| 75 } | 64 } |
| 76 | 65 |
| 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 | |
| 94 void RenderTextFragment::setText(PassRefPtr<StringImpl> text, bool force) | 66 void RenderTextFragment::setText(PassRefPtr<StringImpl> text, bool force) |
| 95 { | 67 { |
| 96 RenderText::setText(text, force); | 68 RenderText::setText(text, force); |
| 97 | 69 |
| 98 m_start = 0; | 70 m_start = 0; |
| 99 m_end = textLength(); | 71 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; | |
| 104 | 72 |
| 105 ASSERT(!m_contentString); | 73 // If we're the remaining text from a first letter then we have to tell the |
| 106 m_firstLetter->destroy(); | 74 // first letter pseudo element to reattach itself so it can re-calculate the |
| 107 m_firstLetter = nullptr; | 75 // correct first-letter settings. |
| 108 if (Node* t = node()) { | 76 if (RenderObject* previous = previousSibling()) { |
|
esprehn
2014/09/30 09:00:31
This feels sketchy, we can't keep an explicit RefP
dsinclair
2014/09/30 21:46:34
I can do that, if it's preferred, I was more afrai
| |
| 109 ASSERT(!t->renderer()); | 77 if (!previous->isPseudoElement() || !previous->node()->isFirstLetterPseu doElement()) |
| 110 t->setRenderer(this); | 78 return; |
| 111 } | 79 |
| 80 previous->node()->parentElement()->setNeedsStyleRecalc(SubtreeStyleChang e); | |
|
esprehn
2014/09/30 09:00:31
This is really bad, you're causing a subtree recal
dsinclair
2014/09/30 21:46:34
Changed to LocalStyleChange. I had to add a second
| |
| 81 | |
| 82 // FIXME:: Will this get cleaned up properly? OR am I leaking here? | |
| 83 previous->node()->detach(); | |
| 112 } | 84 } |
| 113 } | 85 } |
| 114 | 86 |
| 115 void RenderTextFragment::transformText() | 87 void RenderTextFragment::transformText() |
| 116 { | 88 { |
| 117 // Don't reset first-letter here because we are only transforming the trunca ted fragment. | |
| 118 if (RefPtr<StringImpl> textToTransform = originalText()) | 89 if (RefPtr<StringImpl> textToTransform = originalText()) |
| 119 RenderText::setText(textToTransform.release(), true); | 90 RenderText::setText(textToTransform.release(), true); |
| 120 } | 91 } |
| 121 | 92 |
| 122 UChar RenderTextFragment::previousCharacter() const | 93 UChar RenderTextFragment::previousCharacter() const |
| 123 { | 94 { |
| 124 if (start()) { | 95 if (start()) { |
| 125 Node* e = node(); | 96 StringImpl* original = completeText().get(); |
| 126 StringImpl* original = ((e && e->isTextNode()) ? toText(e)->dataImpl() : contentString()); | |
| 127 if (original && start() <= original->length()) | 97 if (original && start() <= original->length()) |
| 128 return (*original)[start() - 1]; | 98 return (*original)[start() - 1]; |
| 129 } | 99 } |
| 130 | 100 |
| 131 return RenderText::previousCharacter(); | 101 return RenderText::previousCharacter(); |
| 132 } | 102 } |
| 133 | 103 |
| 134 RenderBlock* RenderTextFragment::blockForAccompanyingFirstLetter() const | |
| 135 { | |
| 136 if (!m_firstLetter) | |
| 137 return 0; | |
| 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 } | |
| 144 | |
| 145 void RenderTextFragment::updateHitTestResult(HitTestResult& result, const Layout Point& point) | 104 void RenderTextFragment::updateHitTestResult(HitTestResult& result, const Layout Point& point) |
| 146 { | 105 { |
| 147 if (result.innerNode()) | 106 if (result.innerNode()) |
| 148 return; | 107 return; |
| 149 | 108 |
| 150 RenderObject::updateHitTestResult(result, point); | 109 RenderObject::updateHitTestResult(result, point); |
| 151 if (m_firstLetter || !node()) | 110 if (!node()) |
| 152 return; | |
| 153 RenderObject* nodeRenderer = node()->renderer(); | |
| 154 if (!nodeRenderer || !nodeRenderer->isText() || !toRenderText(nodeRenderer)- >isTextFragment()) | |
| 155 return; | 111 return; |
| 156 | 112 |
| 157 if (isDescendantOf(toRenderTextFragment(nodeRenderer)->m_firstLetter)) | 113 // FIXME(dsinclair): First letter? |
| 158 result.setIsFirstLetter(true); | |
| 159 } | 114 } |
| 160 | 115 |
| 116 // If this is the renderer for a first-letter pseudoNode then we have to look | |
| 117 // at the node for the remaining text to find our content. | |
| 118 Text* RenderTextFragment::associatedTextNode() const | |
| 119 { | |
| 120 Node* e = node(); | |
|
esprehn
2014/09/30 09:00:31
node = this->node(); Not sure what e is, but no si
dsinclair
2014/09/30 21:46:34
Done.
| |
| 121 if (!e) | |
| 122 return nullptr; | |
| 123 | |
| 124 if (e->isFirstLetterPseudoElement()) { | |
| 125 Element* pseudo = toElement(e); | |
| 126 RenderObject* nextRenderer = pseudo->firstLetterTextRenderer(); | |
| 127 if (!nextRenderer) | |
| 128 return nullptr; | |
| 129 e = nextRenderer->node(); | |
| 130 } | |
| 131 return (e && e->isTextNode()) ? toText(e) : nullptr; | |
|
esprehn
2014/09/30 09:00:31
This code seems overly cautious, how can firstLett
dsinclair
2014/09/30 21:46:34
I believe I broke that invariant (if it is invaria
| |
| 132 } | |
| 133 | |
| 134 | |
| 161 } // namespace blink | 135 } // namespace blink |
| OLD | NEW |