| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
| 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
| 4 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights
reserved. | 4 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 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 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 RefPtrWillBeRawPtr<Text> newText = cloneWithData(oldStr.substring(offset)); | 151 RefPtrWillBeRawPtr<Text> newText = cloneWithData(oldStr.substring(offset)); |
| 152 setDataWithoutUpdate(oldStr.substring(0, offset)); | 152 setDataWithoutUpdate(oldStr.substring(0, offset)); |
| 153 | 153 |
| 154 didModifyData(oldStr, CharacterData::UpdateFromNonParser); | 154 didModifyData(oldStr, CharacterData::UpdateFromNonParser); |
| 155 | 155 |
| 156 if (parentNode()) | 156 if (parentNode()) |
| 157 parentNode()->insertBefore(newText.get(), nextSibling(), exceptionState)
; | 157 parentNode()->insertBefore(newText.get(), nextSibling(), exceptionState)
; |
| 158 if (exceptionState.hadException()) | 158 if (exceptionState.hadException()) |
| 159 return nullptr; | 159 return nullptr; |
| 160 | 160 |
| 161 if (renderer()) | 161 if (layoutObject()) |
| 162 renderer()->setTextWithOffset(dataImpl(), 0, oldStr.length()); | 162 layoutObject()->setTextWithOffset(dataImpl(), 0, oldStr.length()); |
| 163 | 163 |
| 164 if (parentNode()) | 164 if (parentNode()) |
| 165 document().didSplitTextNode(*this); | 165 document().didSplitTextNode(*this); |
| 166 | 166 |
| 167 return newText.release(); | 167 return newText.release(); |
| 168 } | 168 } |
| 169 | 169 |
| 170 static const Text* earliestLogicallyAdjacentTextNode(const Text* t) | 170 static const Text* earliestLogicallyAdjacentTextNode(const Text* t) |
| 171 { | 171 { |
| 172 for (const Node* n = t->previousSibling(); n; n = n->previousSibling()) { | 172 for (const Node* n = t->previousSibling(); n; n = n->previousSibling()) { |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 if (parent.isLayoutBlock() && !parent.childrenInline() && (!prev || !pre
v->isInline())) | 328 if (parent.isLayoutBlock() && !parent.childrenInline() && (!prev || !pre
v->isInline())) |
| 329 return false; | 329 return false; |
| 330 | 330 |
| 331 // Avoiding creation of a Renderer for the text node is a non-essential
memory optimization. | 331 // Avoiding creation of a Renderer for the text node is a non-essential
memory optimization. |
| 332 // So to avoid blowing up on very wide DOMs, we limit the number of sibl
ings to visit. | 332 // So to avoid blowing up on very wide DOMs, we limit the number of sibl
ings to visit. |
| 333 unsigned maxSiblingsToVisit = 50; | 333 unsigned maxSiblingsToVisit = 50; |
| 334 | 334 |
| 335 LayoutObject* first = parent.slowFirstChild(); | 335 LayoutObject* first = parent.slowFirstChild(); |
| 336 while (first && first->isFloatingOrOutOfFlowPositioned() && maxSiblingsT
oVisit--) | 336 while (first && first->isFloatingOrOutOfFlowPositioned() && maxSiblingsT
oVisit--) |
| 337 first = first->nextSibling(); | 337 first = first->nextSibling(); |
| 338 if (!first || first == renderer() || NodeRenderingTraversal::nextSibling
Renderer(*this) == first) | 338 if (!first || first == layoutObject() || NodeRenderingTraversal::nextSib
lingRenderer(*this) == first) |
| 339 // Whitespace at the start of a block just goes away. Don't even | 339 // Whitespace at the start of a block just goes away. Don't even |
| 340 // make a render object for this text. | 340 // make a render object for this text. |
| 341 return false; | 341 return false; |
| 342 } | 342 } |
| 343 return true; | 343 return true; |
| 344 } | 344 } |
| 345 | 345 |
| 346 static bool isSVGText(Text* text) | 346 static bool isSVGText(Text* text) |
| 347 { | 347 { |
| 348 Node* parentOrShadowHostNode = text->parentOrShadowHostNode(); | 348 Node* parentOrShadowHostNode = text->parentOrShadowHostNode(); |
| 349 ASSERT(parentOrShadowHostNode); | 349 ASSERT(parentOrShadowHostNode); |
| 350 return parentOrShadowHostNode->isSVGElement() && !isSVGForeignObjectElement(
*parentOrShadowHostNode); | 350 return parentOrShadowHostNode->isSVGElement() && !isSVGForeignObjectElement(
*parentOrShadowHostNode); |
| 351 } | 351 } |
| 352 | 352 |
| 353 LayoutText* Text::createTextRenderer(LayoutStyle* style) | 353 LayoutText* Text::createTextRenderer(LayoutStyle* style) |
| 354 { | 354 { |
| 355 if (isSVGText(this)) | 355 if (isSVGText(this)) |
| 356 return new LayoutSVGInlineText(this, dataImpl()); | 356 return new LayoutSVGInlineText(this, dataImpl()); |
| 357 | 357 |
| 358 if (style->hasTextCombine()) | 358 if (style->hasTextCombine()) |
| 359 return new LayoutTextCombine(this, dataImpl()); | 359 return new LayoutTextCombine(this, dataImpl()); |
| 360 | 360 |
| 361 return new LayoutText(this, dataImpl()); | 361 return new LayoutText(this, dataImpl()); |
| 362 } | 362 } |
| 363 | 363 |
| 364 void Text::attach(const AttachContext& context) | 364 void Text::attach(const AttachContext& context) |
| 365 { | 365 { |
| 366 if (ContainerNode* renderingParent = NodeRenderingTraversal::parent(*this))
{ | 366 if (ContainerNode* renderingParent = NodeRenderingTraversal::parent(*this))
{ |
| 367 if (LayoutObject* parentRenderer = renderingParent->renderer()) { | 367 if (LayoutObject* parentRenderer = renderingParent->layoutObject()) { |
| 368 if (textRendererIsNeeded(*parentRenderer->style(), *parentRenderer)) | 368 if (textRendererIsNeeded(*parentRenderer->style(), *parentRenderer)) |
| 369 LayoutTreeBuilderForText(*this, parentRenderer).createRenderer()
; | 369 LayoutTreeBuilderForText(*this, parentRenderer).createRenderer()
; |
| 370 } | 370 } |
| 371 } | 371 } |
| 372 CharacterData::attach(context); | 372 CharacterData::attach(context); |
| 373 } | 373 } |
| 374 | 374 |
| 375 void Text::reattachIfNeeded(const AttachContext& context) | 375 void Text::reattachIfNeeded(const AttachContext& context) |
| 376 { | 376 { |
| 377 bool rendererIsNeeded = false; | 377 bool rendererIsNeeded = false; |
| 378 ContainerNode* renderingParent = NodeRenderingTraversal::parent(*this); | 378 ContainerNode* renderingParent = NodeRenderingTraversal::parent(*this); |
| 379 if (renderingParent) { | 379 if (renderingParent) { |
| 380 if (LayoutObject* parentRenderer = renderingParent->renderer()) { | 380 if (LayoutObject* parentRenderer = renderingParent->layoutObject()) { |
| 381 if (textRendererIsNeeded(*parentRenderer->style(), *parentRenderer)) | 381 if (textRendererIsNeeded(*parentRenderer->style(), *parentRenderer)) |
| 382 rendererIsNeeded = true; | 382 rendererIsNeeded = true; |
| 383 } | 383 } |
| 384 } | 384 } |
| 385 | 385 |
| 386 if (rendererIsNeeded == !!renderer()) | 386 if (rendererIsNeeded == !!layoutObject()) |
| 387 return; | 387 return; |
| 388 | 388 |
| 389 // The following is almost the same as Node::reattach() except that we creat
e renderer only if needed. | 389 // The following is almost the same as Node::reattach() except that we creat
e renderer only if needed. |
| 390 // Not calling reattach() to avoid repeated calls to Text::textRendererIsNee
ded(). | 390 // Not calling reattach() to avoid repeated calls to Text::textRendererIsNee
ded(). |
| 391 AttachContext reattachContext(context); | 391 AttachContext reattachContext(context); |
| 392 reattachContext.performingReattach = true; | 392 reattachContext.performingReattach = true; |
| 393 | 393 |
| 394 if (styleChangeType() < NeedsReattachStyleChange) | 394 if (styleChangeType() < NeedsReattachStyleChange) |
| 395 detach(reattachContext); | 395 detach(reattachContext); |
| 396 if (rendererIsNeeded) | 396 if (rendererIsNeeded) |
| 397 LayoutTreeBuilderForText(*this, renderingParent->renderer()).createRende
rer(); | 397 LayoutTreeBuilderForText(*this, renderingParent->layoutObject()).createR
enderer(); |
| 398 CharacterData::attach(reattachContext); | 398 CharacterData::attach(reattachContext); |
| 399 } | 399 } |
| 400 | 400 |
| 401 void Text::recalcTextStyle(StyleRecalcChange change, Text* nextTextSibling) | 401 void Text::recalcTextStyle(StyleRecalcChange change, Text* nextTextSibling) |
| 402 { | 402 { |
| 403 if (LayoutText* renderer = this->renderer()) { | 403 if (LayoutText* renderer = this->layoutObject()) { |
| 404 if (change != NoChange || needsStyleRecalc()) | 404 if (change != NoChange || needsStyleRecalc()) |
| 405 renderer->setStyle(document().ensureStyleResolver().styleForText(thi
s)); | 405 renderer->setStyle(document().ensureStyleResolver().styleForText(thi
s)); |
| 406 if (needsStyleRecalc()) | 406 if (needsStyleRecalc()) |
| 407 renderer->setText(dataImpl()); | 407 renderer->setText(dataImpl()); |
| 408 clearNeedsStyleRecalc(); | 408 clearNeedsStyleRecalc(); |
| 409 } else if (needsStyleRecalc() || needsWhitespaceRenderer()) { | 409 } else if (needsStyleRecalc() || needsWhitespaceRenderer()) { |
| 410 reattach(); | 410 reattach(); |
| 411 if (this->renderer()) | 411 if (this->layoutObject()) |
| 412 reattachWhitespaceSiblingsIfNeeded(nextTextSibling); | 412 reattachWhitespaceSiblingsIfNeeded(nextTextSibling); |
| 413 } | 413 } |
| 414 } | 414 } |
| 415 | 415 |
| 416 // If a whitespace node had no renderer and goes through a recalcStyle it may | 416 // If a whitespace node had no renderer and goes through a recalcStyle it may |
| 417 // need to create one if the parent style now has white-space: pre. | 417 // need to create one if the parent style now has white-space: pre. |
| 418 bool Text::needsWhitespaceRenderer() | 418 bool Text::needsWhitespaceRenderer() |
| 419 { | 419 { |
| 420 ASSERT(!renderer()); | 420 ASSERT(!layoutObject()); |
| 421 if (LayoutStyle* style = parentLayoutStyle()) | 421 if (LayoutStyle* style = parentLayoutStyle()) |
| 422 return style->preserveNewline(); | 422 return style->preserveNewline(); |
| 423 return false; | 423 return false; |
| 424 } | 424 } |
| 425 | 425 |
| 426 void Text::updateTextRenderer(unsigned offsetOfReplacedData, unsigned lengthOfRe
placedData, RecalcStyleBehavior recalcStyleBehavior) | 426 void Text::updateTextRenderer(unsigned offsetOfReplacedData, unsigned lengthOfRe
placedData, RecalcStyleBehavior recalcStyleBehavior) |
| 427 { | 427 { |
| 428 if (!inActiveDocument()) | 428 if (!inActiveDocument()) |
| 429 return; | 429 return; |
| 430 LayoutText* textRenderer = renderer(); | 430 LayoutText* textRenderer = layoutObject(); |
| 431 if (!textRenderer || !textRendererIsNeeded(*textRenderer->style(), *textRend
erer->parent())) { | 431 if (!textRenderer || !textRendererIsNeeded(*textRenderer->style(), *textRend
erer->parent())) { |
| 432 lazyReattachIfAttached(); | 432 lazyReattachIfAttached(); |
| 433 // FIXME: Editing should be updated so this is not neccesary. | 433 // FIXME: Editing should be updated so this is not neccesary. |
| 434 if (recalcStyleBehavior == DeprecatedRecalcStyleImmediatlelyForEditing) | 434 if (recalcStyleBehavior == DeprecatedRecalcStyleImmediatlelyForEditing) |
| 435 document().updateRenderTreeIfNeeded(); | 435 document().updateRenderTreeIfNeeded(); |
| 436 return; | 436 return; |
| 437 } | 437 } |
| 438 textRenderer->setTextWithOffset(dataImpl(), offsetOfReplacedData, lengthOfRe
placedData); | 438 textRenderer->setTextWithOffset(dataImpl(), offsetOfReplacedData, lengthOfRe
placedData); |
| 439 } | 439 } |
| 440 | 440 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 465 result.appendLiteral("; "); | 465 result.appendLiteral("; "); |
| 466 result.appendLiteral("value="); | 466 result.appendLiteral("value="); |
| 467 result.append(s); | 467 result.append(s); |
| 468 } | 468 } |
| 469 | 469 |
| 470 strncpy(buffer, result.toString().utf8().data(), length - 1); | 470 strncpy(buffer, result.toString().utf8().data(), length - 1); |
| 471 } | 471 } |
| 472 #endif | 472 #endif |
| 473 | 473 |
| 474 } // namespace blink | 474 } // namespace blink |
| OLD | NEW |