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 10 matching lines...) Expand all Loading... |
21 | 21 |
22 #include "config.h" | 22 #include "config.h" |
23 #include "core/dom/Text.h" | 23 #include "core/dom/Text.h" |
24 | 24 |
25 #include "bindings/core/v8/ExceptionState.h" | 25 #include "bindings/core/v8/ExceptionState.h" |
26 #include "bindings/core/v8/ExceptionStatePlaceholder.h" | 26 #include "bindings/core/v8/ExceptionStatePlaceholder.h" |
27 #include "core/SVGNames.h" | 27 #include "core/SVGNames.h" |
28 #include "core/css/resolver/StyleResolver.h" | 28 #include "core/css/resolver/StyleResolver.h" |
29 #include "core/dom/ExceptionCode.h" | 29 #include "core/dom/ExceptionCode.h" |
30 #include "core/dom/LayoutTreeBuilder.h" | 30 #include "core/dom/LayoutTreeBuilder.h" |
| 31 #include "core/dom/LayoutTreeBuilderTraversal.h" |
31 #include "core/dom/NodeComputedStyle.h" | 32 #include "core/dom/NodeComputedStyle.h" |
32 #include "core/dom/NodeRenderingTraversal.h" | |
33 #include "core/dom/NodeTraversal.h" | 33 #include "core/dom/NodeTraversal.h" |
34 #include "core/dom/shadow/ShadowRoot.h" | 34 #include "core/dom/shadow/ShadowRoot.h" |
35 #include "core/events/ScopedEventQueue.h" | 35 #include "core/events/ScopedEventQueue.h" |
36 #include "core/layout/LayoutText.h" | 36 #include "core/layout/LayoutText.h" |
37 #include "core/layout/LayoutTextCombine.h" | 37 #include "core/layout/LayoutTextCombine.h" |
38 #include "core/layout/svg/LayoutSVGInlineText.h" | 38 #include "core/layout/svg/LayoutSVGInlineText.h" |
39 #include "core/svg/SVGForeignObjectElement.h" | 39 #include "core/svg/SVGForeignObjectElement.h" |
40 #include "wtf/text/CString.h" | 40 #include "wtf/text/CString.h" |
41 #include "wtf/text/StringBuilder.h" | 41 #include "wtf/text/StringBuilder.h" |
42 | 42 |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 if (!canHaveWhitespaceChildren(parent)) | 309 if (!canHaveWhitespaceChildren(parent)) |
310 return false; | 310 return false; |
311 | 311 |
312 if (style.preserveNewline()) // pre/pre-wrap/pre-line always make renderers. | 312 if (style.preserveNewline()) // pre/pre-wrap/pre-line always make renderers. |
313 return true; | 313 return true; |
314 | 314 |
315 // childNeedsDistributionRecalc() here is rare, only happens JS calling surr
oundContents() etc. from DOMNodeInsertedIntoDocument etc. | 315 // childNeedsDistributionRecalc() here is rare, only happens JS calling surr
oundContents() etc. from DOMNodeInsertedIntoDocument etc. |
316 if (document().childNeedsDistributionRecalc()) | 316 if (document().childNeedsDistributionRecalc()) |
317 return true; | 317 return true; |
318 | 318 |
319 const LayoutObject* prev = NodeRenderingTraversal::previousSiblingRenderer(*
this); | 319 const LayoutObject* prev = LayoutTreeBuilderTraversal::previousSiblingRender
er(*this); |
320 if (prev && prev->isBR()) // <span><br/> <br/></span> | 320 if (prev && prev->isBR()) // <span><br/> <br/></span> |
321 return false; | 321 return false; |
322 | 322 |
323 if (parent.isLayoutInline()) { | 323 if (parent.isLayoutInline()) { |
324 // <span><div/> <div/></span> | 324 // <span><div/> <div/></span> |
325 if (prev && !prev->isInline()) | 325 if (prev && !prev->isInline()) |
326 return false; | 326 return false; |
327 } else { | 327 } else { |
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 == layoutObject() || NodeRenderingTraversal::nextSib
lingRenderer(*this) == first) | 338 if (!first || first == layoutObject() || LayoutTreeBuilderTraversal::nex
tSiblingRenderer(*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(const ComputedStyle& style) | 353 LayoutText* Text::createTextRenderer(const ComputedStyle& 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 = LayoutTreeBuilderTraversal::parent(*thi
s)) { |
367 if (LayoutObject* parentRenderer = renderingParent->layoutObject()) { | 367 if (LayoutObject* parentRenderer = renderingParent->layoutObject()) { |
368 if (textRendererIsNeeded(*parentRenderer->style(), *parentRenderer)) | 368 if (textRendererIsNeeded(*parentRenderer->style(), *parentRenderer)) |
369 LayoutTreeBuilderForText(*this, parentRenderer).createLayoutObje
ct(); | 369 LayoutTreeBuilderForText(*this, parentRenderer).createLayoutObje
ct(); |
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 layoutObjectIsNeeded = false; | 377 bool layoutObjectIsNeeded = false; |
378 ContainerNode* renderingParent = NodeRenderingTraversal::parent(*this); | 378 ContainerNode* renderingParent = LayoutTreeBuilderTraversal::parent(*this); |
379 if (renderingParent) { | 379 if (renderingParent) { |
380 if (LayoutObject* parentRenderer = renderingParent->layoutObject()) { | 380 if (LayoutObject* parentRenderer = renderingParent->layoutObject()) { |
381 if (textRendererIsNeeded(*parentRenderer->style(), *parentRenderer)) | 381 if (textRendererIsNeeded(*parentRenderer->style(), *parentRenderer)) |
382 layoutObjectIsNeeded = true; | 382 layoutObjectIsNeeded = true; |
383 } | 383 } |
384 } | 384 } |
385 | 385 |
386 if (layoutObjectIsNeeded == !!layoutObject()) | 386 if (layoutObjectIsNeeded == !!layoutObject()) |
387 return; | 387 return; |
388 | 388 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after 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 |