Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2005, 2006, 2008, 2009 Apple Inc. All rights reserved. | 2 * Copyright (C) 2005, 2006, 2008, 2009 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 358 start = startPosition(); | 358 start = startPosition(); |
| 359 end = endPosition(); | 359 end = endPosition(); |
| 360 } | 360 } |
| 361 | 361 |
| 362 if (isValidCaretPositionInTextNode(end)) { | 362 if (isValidCaretPositionInTextNode(end)) { |
| 363 splitTextAtEnd(start, end); | 363 splitTextAtEnd(start, end); |
| 364 start = startPosition(); | 364 start = startPosition(); |
| 365 end = endPosition(); | 365 end = endPosition(); |
| 366 } | 366 } |
| 367 | 367 |
| 368 DCHECK(start.anchorNode()); | |
| 369 DCHECK(end.anchorNode()); | |
| 368 // Calculate loop end point. | 370 // Calculate loop end point. |
| 369 // If the end node is before the start node (can only happen if the end node is | 371 // If the end node is before the start node (can only happen if the end node is |
| 370 // an ancestor of the start node), we gather nodes up to the next sibling of the end node | 372 // an ancestor of the start node), we gather nodes up to the next sibling of the end node |
| 371 Node* beyondEnd; | 373 const Node* const beyondEnd = end.nodeAsRangePastLastNode(); |
| 372 DCHECK(start.anchorNode()); | |
| 373 DCHECK(end.anchorNode()); | |
| 374 if (start.anchorNode()->isDescendantOf(end.anchorNode())) | |
| 375 beyondEnd = NodeTraversal::nextSkippingChildren(*end.anchorNode()); | |
| 376 else | |
| 377 beyondEnd = NodeTraversal::next(*end.anchorNode()); | |
| 378 | |
| 379 start = mostBackwardCaretPosition(start); // Move upstream to ensure we do n ot add redundant spans. | 374 start = mostBackwardCaretPosition(start); // Move upstream to ensure we do n ot add redundant spans. |
| 380 Node* startNode = start.anchorNode(); | 375 Node* startNode = start.anchorNode(); |
| 381 DCHECK(startNode); | 376 DCHECK(startNode); |
| 382 | 377 |
| 383 // Make sure we're not already at the end or the next NodeTraversal::next() will traverse | 378 // Make sure we're not already at the end or the next NodeTraversal::next() will traverse |
| 384 // past it. | 379 // past it. |
| 385 if (startNode == beyondEnd) | 380 if (startNode == beyondEnd) |
| 386 return; | 381 return; |
| 387 | 382 |
| 388 if (startNode->isTextNode() && start.computeOffsetInContainerNode() >= caret MaxOffset(startNode)) { | 383 if (startNode->isTextNode() && start.computeOffsetInContainerNode() >= caret MaxOffset(startNode)) { |
| 389 // Move out of text node if range does not include its characters. | 384 // Move out of text node if range does not include its characters. |
| 390 startNode = NodeTraversal::next(*startNode); | 385 startNode = NodeTraversal::next(*startNode); |
| 391 if (!startNode) | 386 if (!startNode) |
| 392 return; | 387 return; |
| 393 } | 388 } |
| 394 | 389 |
| 395 // Store away font size before making any changes to the document. | 390 // Store away font size before making any changes to the document. |
| 396 // This ensures that changes to one node won't effect another. | 391 // This ensures that changes to one node won't effect another. |
| 397 HeapHashMap<Member<Node>, float> startingFontSizes; | 392 HeapHashMap<Member<Node>, float> startingFontSizes; |
| 398 for (Node* node = startNode; node != beyondEnd; node = NodeTraversal::next(* node)) { | 393 for (Node* node = startNode; node != beyondEnd; node = NodeTraversal::next(* node)) { |
| 399 DCHECK(node); | 394 DCHECK(node); |
| 400 startingFontSizes.set(node, computedFontSize(node)); | 395 startingFontSizes.set(node, computedFontSize(node)); |
| 401 } | 396 } |
| 402 | 397 |
| 403 // These spans were added by us. If empty after font size changes, they can be removed. | 398 // These spans were added by us. If empty after font size changes, they can be removed. |
| 404 HeapVector<Member<HTMLElement>> unstyledSpans; | 399 HeapVector<Member<HTMLElement>> unstyledSpans; |
| 405 | 400 |
| 406 Node* lastStyledNode = nullptr; | 401 Node* lastStyledNode = nullptr; |
| 407 for (Node* node = startNode; node != beyondEnd; node = NodeTraversal::next(* node)) { | 402 for (Node* node = startNode; node != beyondEnd; node = NodeTraversal::next(* node)) { |
|
yoichio
2016/07/05 05:50:57
This end condition looks very fragile.
Could you i
yosin_UTC9
2016/07/05 07:41:24
When |beyondEnd| is a wrong value, e.g. |beyondEnd
| |
| 408 DCHECK(node); | 403 DCHECK(node); |
| 409 HTMLElement* element = nullptr; | 404 HTMLElement* element = nullptr; |
| 410 if (node->isHTMLElement()) { | 405 if (node->isHTMLElement()) { |
| 411 // Only work on fully selected nodes. | 406 // Only work on fully selected nodes. |
| 412 if (!elementFullySelected(toHTMLElement(*node), start, end)) | 407 if (!elementFullySelected(toHTMLElement(*node), start, end)) |
| 413 continue; | 408 continue; |
| 414 element = toHTMLElement(node); | 409 element = toHTMLElement(node); |
| 415 } else if (node->isTextNode() && node->layoutObject() && node->parentNod e() != lastStyledNode) { | 410 } else if (node->isTextNode() && node->layoutObject() && node->parentNod e() != lastStyledNode) { |
| 416 // Last styled node was not parent node of this text node, but we wi sh to style this | 411 // Last styled node was not parent node of this text node, but we wi sh to style this |
| 417 // text node. To make this possible, add a style span to surround th is text node. | 412 // text node. To make this possible, add a style span to surround th is text node. |
| (...skipping 1313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1731 DEFINE_TRACE(ApplyStyleCommand) | 1726 DEFINE_TRACE(ApplyStyleCommand) |
| 1732 { | 1727 { |
| 1733 visitor->trace(m_style); | 1728 visitor->trace(m_style); |
| 1734 visitor->trace(m_start); | 1729 visitor->trace(m_start); |
| 1735 visitor->trace(m_end); | 1730 visitor->trace(m_end); |
| 1736 visitor->trace(m_styledInlineElement); | 1731 visitor->trace(m_styledInlineElement); |
| 1737 CompositeEditCommand::trace(visitor); | 1732 CompositeEditCommand::trace(visitor); |
| 1738 } | 1733 } |
| 1739 | 1734 |
| 1740 } // namespace blink | 1735 } // namespace blink |
| OLD | NEW |