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; |
| 1493 // Make sure that |updateNodesInserted| does not change |
| 1494 // |m_startOfInsertedContent|. |
| 1495 DCHECK(m_startOfInsertedContent.isNotNull()); |
1495 updateNodesInserted(node); | 1496 updateNodesInserted(node); |
1496 } | 1497 } |
1497 } | 1498 } |
1498 | 1499 |
1499 document().updateStyleAndLayout(); | 1500 document().updateStyleAndLayout(); |
1500 | 1501 |
| 1502 VisiblePosition startOfInsertedContent = positionAtStartOfInsertedContent(); |
1501 Position startDownstream = mostForwardCaretPosition(startOfInsertedContent.d
eepEquivalent()); | 1503 Position startDownstream = mostForwardCaretPosition(startOfInsertedContent.d
eepEquivalent()); |
1502 Node* startNode = startDownstream.computeNodeAfterPosition(); | 1504 Node* startNode = startDownstream.computeNodeAfterPosition(); |
1503 unsigned startOffset = 0; | 1505 unsigned startOffset = 0; |
1504 if (startDownstream.isOffsetInAnchor()) { | 1506 if (startDownstream.isOffsetInAnchor()) { |
1505 startNode = startDownstream.computeContainerNode(); | 1507 startNode = startDownstream.computeContainerNode(); |
1506 startOffset = startDownstream.offsetInContainerNode(); | 1508 startOffset = startDownstream.offsetInContainerNode(); |
1507 } | 1509 } |
1508 | 1510 |
1509 bool needsLeadingSpace = !isStartOfParagraphDeprecated(startOfInsertedConten
t) && !isCharacterSmartReplaceExemptConsideringNonBreakingSpace(characterBefore(
startOfInsertedContent), true); | 1511 bool needsLeadingSpace = !isStartOfParagraphDeprecated(startOfInsertedConten
t) && !isCharacterSmartReplaceExemptConsideringNonBreakingSpace(characterBefore(
startOfInsertedContent), true); |
1510 if (needsLeadingSpace && startNode) { | 1512 if (needsLeadingSpace && startNode) { |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1758 visitor->trace(m_startOfInsertedContent); | 1760 visitor->trace(m_startOfInsertedContent); |
1759 visitor->trace(m_endOfInsertedContent); | 1761 visitor->trace(m_endOfInsertedContent); |
1760 visitor->trace(m_insertionStyle); | 1762 visitor->trace(m_insertionStyle); |
1761 visitor->trace(m_documentFragment); | 1763 visitor->trace(m_documentFragment); |
1762 visitor->trace(m_startOfInsertedRange); | 1764 visitor->trace(m_startOfInsertedRange); |
1763 visitor->trace(m_endOfInsertedRange); | 1765 visitor->trace(m_endOfInsertedRange); |
1764 CompositeEditCommand::trace(visitor); | 1766 CompositeEditCommand::trace(visitor); |
1765 } | 1767 } |
1766 | 1768 |
1767 } // namespace blink | 1769 } // namespace blink |
OLD | NEW |