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/Text.h" | 26 #include "core/dom/Text.h" |
| 27 #include "core/editing/VisiblePosition.h" | |
| 28 #include "core/rendering/HitTestResult.h" | |
| 27 #include "core/rendering/RenderBlock.h" | 29 #include "core/rendering/RenderBlock.h" |
| 28 | 30 |
| 29 namespace WebCore { | 31 namespace WebCore { |
| 30 | 32 |
| 31 RenderTextFragment::RenderTextFragment(Node* node, StringImpl* str, int startOff set, int length) | 33 RenderTextFragment::RenderTextFragment(Node* node, StringImpl* str, int startOff set, int length) |
| 32 : RenderText(node, str ? str->substring(startOffset, length) : PassRefPtr<St ringImpl>(0)) | 34 : RenderText(node, str ? str->substring(startOffset, length) : PassRefPtr<St ringImpl>(0)) |
| 33 , m_start(startOffset) | 35 , m_start(startOffset) |
| 34 , m_end(length) | 36 , m_end(length) |
| 35 , m_firstLetter(0) | 37 , m_firstLetter(0) |
| 36 { | 38 { |
| 37 } | 39 } |
| 38 | 40 |
| 39 RenderTextFragment::RenderTextFragment(Node* node, StringImpl* str) | 41 RenderTextFragment::RenderTextFragment(Node* node, StringImpl* str) |
| 40 : RenderText(node, str) | 42 : RenderText(node, str) |
| 41 , m_start(0) | 43 , m_start(0) |
| 42 , m_end(str ? str->length() : 0) | 44 , m_end(str ? str->length() : 0) |
| 43 , m_contentString(str) | 45 , m_contentString(str) |
| 44 , m_firstLetter(0) | 46 , m_firstLetter(0) |
| 45 { | 47 { |
| 46 } | 48 } |
| 47 | 49 |
| 48 RenderTextFragment::~RenderTextFragment() | 50 RenderTextFragment::~RenderTextFragment() |
| 49 { | 51 { |
| 50 } | 52 } |
| 51 | 53 |
| 54 static RenderText* findRenderText(RenderObject* renderer) | |
| 55 { | |
| 56 if (renderer->isText()) | |
| 57 return toRenderText(renderer); | |
| 58 for (RenderObject* current = renderer->firstChild(); current; current = curr ent->nextSibling()) { | |
| 59 if (RenderText* found = findRenderText(current)) | |
|
tkent
2013/08/02 03:25:48
Using RenderObject::nextInPreOrder is preferable t
yosin_UTC9
2013/08/02 05:01:55
Done.
| |
| 60 return found; | |
| 61 } | |
| 62 return 0; | |
| 63 } | |
| 64 | |
| 65 RenderText* RenderTextFragment::firstRenderTextInFirstLetter() const | |
| 66 { | |
| 67 return m_firstLetter ? findRenderText(m_firstLetter) : 0; | |
| 68 } | |
| 69 | |
| 52 PassRefPtr<StringImpl> RenderTextFragment::originalText() const | 70 PassRefPtr<StringImpl> RenderTextFragment::originalText() const |
| 53 { | 71 { |
| 54 Node* e = node(); | 72 Node* e = node(); |
| 55 RefPtr<StringImpl> result = ((e && e->isTextNode()) ? toText(e)->dataImpl() : contentString()); | 73 RefPtr<StringImpl> result = ((e && e->isTextNode()) ? toText(e)->dataImpl() : contentString()); |
| 56 if (!result) | 74 if (!result) |
| 57 return 0; | 75 return 0; |
| 58 return result->substring(start(), end()); | 76 return result->substring(start(), end()); |
| 59 } | 77 } |
| 60 | 78 |
| 61 void RenderTextFragment::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle) | 79 void RenderTextFragment::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle) |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 115 { | 133 { |
| 116 if (!m_firstLetter) | 134 if (!m_firstLetter) |
| 117 return 0; | 135 return 0; |
| 118 for (RenderObject* block = m_firstLetter->parent(); block; block = block->pa rent()) { | 136 for (RenderObject* block = m_firstLetter->parent(); block; block = block->pa rent()) { |
| 119 if (block->style()->hasPseudoStyle(FIRST_LETTER) && block->canHaveChildr en() && block->isRenderBlock()) | 137 if (block->style()->hasPseudoStyle(FIRST_LETTER) && block->canHaveChildr en() && block->isRenderBlock()) |
| 120 return toRenderBlock(block); | 138 return toRenderBlock(block); |
| 121 } | 139 } |
| 122 return 0; | 140 return 0; |
| 123 } | 141 } |
| 124 | 142 |
| 143 void RenderTextFragment::updateHitTestResult(HitTestResult& result, const Layout Point& point) | |
| 144 { | |
| 145 if (result.innerNode()) | |
| 146 return; | |
| 147 | |
| 148 RenderObject::updateHitTestResult(result, point); | |
| 149 if (m_firstLetter || !node()) | |
| 150 return; | |
| 151 RenderObject* nodeRenderer = node()->renderer(); | |
| 152 if (!nodeRenderer || !nodeRenderer->isText() || !toRenderText(nodeRenderer)- >isTextFragment()) | |
| 153 return; | |
| 154 | |
| 155 if (isDescendantOf(toRenderTextFragment(nodeRenderer)->m_firstLetter)) | |
| 156 result.setIsFirstLetter(true); | |
| 157 } | |
| 158 | |
| 125 } // namespace WebCore | 159 } // namespace WebCore |
| OLD | NEW |