Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2005, 2006, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2005, 2006, 2008 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2009, 2010, 2011 Google Inc. All rights reserved. | 3 * Copyright (C) 2009, 2010, 2011 Google Inc. All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 1451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1462 return true; | 1462 return true; |
| 1463 } | 1463 } |
| 1464 | 1464 |
| 1465 static bool isCharacterSmartReplaceExemptConsideringNonBreakingSpace(UChar32 cha racter, bool previousCharacter) | 1465 static bool isCharacterSmartReplaceExemptConsideringNonBreakingSpace(UChar32 cha racter, bool previousCharacter) |
| 1466 { | 1466 { |
| 1467 return isCharacterSmartReplaceExempt(character == noBreakSpaceCharacter ? ' ' : character, previousCharacter); | 1467 return isCharacterSmartReplaceExempt(character == noBreakSpaceCharacter ? ' ' : character, previousCharacter); |
| 1468 } | 1468 } |
| 1469 | 1469 |
| 1470 void ReplaceSelectionCommand::addSpacesForSmartReplace(EditingState* editingStat e) | 1470 void ReplaceSelectionCommand::addSpacesForSmartReplace(EditingState* editingStat e) |
| 1471 { | 1471 { |
| 1472 VisiblePosition startOfInsertedContent = positionAtStartOfInsertedContent(); | |
| 1473 VisiblePosition endOfInsertedContent = positionAtEndOfInsertedContent(); | 1472 VisiblePosition endOfInsertedContent = positionAtEndOfInsertedContent(); |
| 1474 | |
| 1475 Position endUpstream = mostBackwardCaretPosition(endOfInsertedContent.deepEq uivalent()); | 1473 Position endUpstream = mostBackwardCaretPosition(endOfInsertedContent.deepEq uivalent()); |
| 1476 Node* endNode = endUpstream.computeNodeBeforePosition(); | 1474 Node* endNode = endUpstream.computeNodeBeforePosition(); |
| 1477 int endOffset = endNode && endNode->isTextNode() ? toText(endNode)->length() : 0; | 1475 int endOffset = endNode && endNode->isTextNode() ? toText(endNode)->length() : 0; |
| 1478 if (endUpstream.isOffsetInAnchor()) { | 1476 if (endUpstream.isOffsetInAnchor()) { |
| 1479 endNode = endUpstream.computeContainerNode(); | 1477 endNode = endUpstream.computeContainerNode(); |
| 1480 endOffset = endUpstream.offsetInContainerNode(); | 1478 endOffset = endUpstream.offsetInContainerNode(); |
| 1481 } | 1479 } |
| 1482 | 1480 |
| 1483 bool needsTrailingSpace = !isEndOfParagraphDeprecated(endOfInsertedContent) && !isCharacterSmartReplaceExemptConsideringNonBreakingSpace(characterAfter(endO fInsertedContent), false); | 1481 bool needsTrailingSpace = !isEndOfParagraphDeprecated(endOfInsertedContent) && !isCharacterSmartReplaceExemptConsideringNonBreakingSpace(characterAfter(endO fInsertedContent), false); |
| 1484 if (needsTrailingSpace && endNode) { | 1482 if (needsTrailingSpace && endNode) { |
| 1485 bool collapseWhiteSpace = !endNode->layoutObject() || endNode->layoutObj ect()->style()->collapseWhiteSpace(); | 1483 bool collapseWhiteSpace = !endNode->layoutObject() || endNode->layoutObj ect()->style()->collapseWhiteSpace(); |
| 1486 if (endNode->isTextNode()) { | 1484 if (endNode->isTextNode()) { |
| 1487 insertTextIntoNode(toText(endNode), endOffset, collapseWhiteSpace ? nonBreakingSpaceString() : " "); | 1485 insertTextIntoNode(toText(endNode), endOffset, collapseWhiteSpace ? nonBreakingSpaceString() : " "); |
| 1488 if (m_endOfInsertedContent.computeContainerNode() == endNode) | 1486 if (m_endOfInsertedContent.computeContainerNode() == endNode) |
| 1489 m_endOfInsertedContent = Position(endNode, m_endOfInsertedConten t.offsetInContainerNode() + 1); | 1487 m_endOfInsertedContent = Position(endNode, m_endOfInsertedConten t.offsetInContainerNode() + 1); |
| 1490 } else { | 1488 } else { |
| 1491 Text* node = document().createEditingTextNode(collapseWhiteSpace ? n onBreakingSpaceString() : " "); | 1489 Text* node = document().createEditingTextNode(collapseWhiteSpace ? n onBreakingSpaceString() : " "); |
| 1492 insertNodeAfter(node, endNode, editingState); | 1490 insertNodeAfter(node, endNode, editingState); |
| 1493 if (editingState->isAborted()) | 1491 if (editingState->isAborted()) |
| 1494 return; | 1492 return; |
| 1495 updateNodesInserted(node); | 1493 updateNodesInserted(node); |
| 1496 } | 1494 } |
| 1497 } | 1495 } |
| 1498 | 1496 |
| 1499 document().updateStyleAndLayout(); | 1497 document().updateStyleAndLayout(); |
| 1500 | 1498 |
| 1499 VisiblePosition startOfInsertedContent = positionAtStartOfInsertedContent(); | |
|
yosin_UTC9
2016/09/27 08:30:53
This moving may change behavior due by DOM tree mo
Xiaocheng
2016/09/27 08:48:51
DCHECK has been added to make sure that |m_startOf
| |
| 1501 Position startDownstream = mostForwardCaretPosition(startOfInsertedContent.d eepEquivalent()); | 1500 Position startDownstream = mostForwardCaretPosition(startOfInsertedContent.d eepEquivalent()); |
| 1502 Node* startNode = startDownstream.computeNodeAfterPosition(); | 1501 Node* startNode = startDownstream.computeNodeAfterPosition(); |
| 1503 unsigned startOffset = 0; | 1502 unsigned startOffset = 0; |
| 1504 if (startDownstream.isOffsetInAnchor()) { | 1503 if (startDownstream.isOffsetInAnchor()) { |
| 1505 startNode = startDownstream.computeContainerNode(); | 1504 startNode = startDownstream.computeContainerNode(); |
| 1506 startOffset = startDownstream.offsetInContainerNode(); | 1505 startOffset = startDownstream.offsetInContainerNode(); |
| 1507 } | 1506 } |
| 1508 | 1507 |
| 1509 bool needsLeadingSpace = !isStartOfParagraphDeprecated(startOfInsertedConten t) && !isCharacterSmartReplaceExemptConsideringNonBreakingSpace(characterBefore( startOfInsertedContent), true); | 1508 bool needsLeadingSpace = !isStartOfParagraphDeprecated(startOfInsertedConten t) && !isCharacterSmartReplaceExemptConsideringNonBreakingSpace(characterBefore( startOfInsertedContent), true); |
| 1510 if (needsLeadingSpace && startNode) { | 1509 if (needsLeadingSpace && startNode) { |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1758 visitor->trace(m_startOfInsertedContent); | 1757 visitor->trace(m_startOfInsertedContent); |
| 1759 visitor->trace(m_endOfInsertedContent); | 1758 visitor->trace(m_endOfInsertedContent); |
| 1760 visitor->trace(m_insertionStyle); | 1759 visitor->trace(m_insertionStyle); |
| 1761 visitor->trace(m_documentFragment); | 1760 visitor->trace(m_documentFragment); |
| 1762 visitor->trace(m_startOfInsertedRange); | 1761 visitor->trace(m_startOfInsertedRange); |
| 1763 visitor->trace(m_endOfInsertedRange); | 1762 visitor->trace(m_endOfInsertedRange); |
| 1764 CompositeEditCommand::trace(visitor); | 1763 CompositeEditCommand::trace(visitor); |
| 1765 } | 1764 } |
| 1766 | 1765 |
| 1767 } // namespace blink | 1766 } // namespace blink |
| OLD | NEW |