| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2005, 2006, 2007, 2008 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 1221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1232 | 1232 |
| 1233 // We upstream() the end and downstream() the start so that we don't include
collapsed whitespace in the move. | 1233 // We upstream() the end and downstream() the start so that we don't include
collapsed whitespace in the move. |
| 1234 // When we paste a fragment, spaces after the end and before the start are t
reated as though they were rendered. | 1234 // When we paste a fragment, spaces after the end and before the start are t
reated as though they were rendered. |
| 1235 Position start = mostForwardCaretPosition(startOfParagraphToMove.deepEquival
ent()); | 1235 Position start = mostForwardCaretPosition(startOfParagraphToMove.deepEquival
ent()); |
| 1236 Position end = startOfParagraphToMove.deepEquivalent() == endOfParagraphToMo
ve.deepEquivalent() ? start : mostBackwardCaretPosition(endOfParagraphToMove.dee
pEquivalent()); | 1236 Position end = startOfParagraphToMove.deepEquivalent() == endOfParagraphToMo
ve.deepEquivalent() ? start : mostBackwardCaretPosition(endOfParagraphToMove.dee
pEquivalent()); |
| 1237 if (comparePositions(start, end) > 0) | 1237 if (comparePositions(start, end) > 0) |
| 1238 end = start; | 1238 end = start; |
| 1239 | 1239 |
| 1240 cloneParagraphUnderNewElement(start, end, outerNode, blockElement, editingSt
ate); | 1240 cloneParagraphUnderNewElement(start, end, outerNode, blockElement, editingSt
ate); |
| 1241 | 1241 |
| 1242 setEndingSelection(VisibleSelection(start, end)); | 1242 setEndingSelection(createVisibleSelectionDeprecated(start, end)); |
| 1243 deleteSelection(editingState, false, false, false); | 1243 deleteSelection(editingState, false, false, false); |
| 1244 if (editingState->isAborted()) | 1244 if (editingState->isAborted()) |
| 1245 return; | 1245 return; |
| 1246 | 1246 |
| 1247 // There are bugs in deletion when it removes a fully selected table/list. | 1247 // There are bugs in deletion when it removes a fully selected table/list. |
| 1248 // It expands and removes the entire table/list, but will let content | 1248 // It expands and removes the entire table/list, but will let content |
| 1249 // before and after the table/list collapse onto one line. | 1249 // before and after the table/list collapse onto one line. |
| 1250 | 1250 |
| 1251 cleanupAfterDeletion(editingState); | 1251 cleanupAfterDeletion(editingState); |
| 1252 if (editingState->isAborted()) | 1252 if (editingState->isAborted()) |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1334 EditingStyle* styleInEmptyParagraph = nullptr; | 1334 EditingStyle* styleInEmptyParagraph = nullptr; |
| 1335 if (startOfParagraphToMove.deepEquivalent() == endOfParagraphToMove.deepEqui
valent() && shouldPreserveStyle == PreserveStyle) { | 1335 if (startOfParagraphToMove.deepEquivalent() == endOfParagraphToMove.deepEqui
valent() && shouldPreserveStyle == PreserveStyle) { |
| 1336 styleInEmptyParagraph = EditingStyle::create(startOfParagraphToMove.deep
Equivalent()); | 1336 styleInEmptyParagraph = EditingStyle::create(startOfParagraphToMove.deep
Equivalent()); |
| 1337 styleInEmptyParagraph->mergeTypingStyle(&document()); | 1337 styleInEmptyParagraph->mergeTypingStyle(&document()); |
| 1338 // The moved paragraph should assume the block style of the destination. | 1338 // The moved paragraph should assume the block style of the destination. |
| 1339 styleInEmptyParagraph->removeBlockProperties(); | 1339 styleInEmptyParagraph->removeBlockProperties(); |
| 1340 } | 1340 } |
| 1341 | 1341 |
| 1342 // FIXME (5098931): We should add a new insert action "WebViewInsertActionMo
ved" and call shouldInsertFragment here. | 1342 // FIXME (5098931): We should add a new insert action "WebViewInsertActionMo
ved" and call shouldInsertFragment here. |
| 1343 | 1343 |
| 1344 setEndingSelection(VisibleSelection(start, end)); | 1344 setEndingSelection(createVisibleSelectionDeprecated(start, end)); |
| 1345 document().frame()->spellChecker().clearMisspellingsAndBadGrammarForMovingPa
ragraphs(endingSelection()); | 1345 document().frame()->spellChecker().clearMisspellingsAndBadGrammarForMovingPa
ragraphs(endingSelection()); |
| 1346 deleteSelection(editingState, false, false, false); | 1346 deleteSelection(editingState, false, false, false); |
| 1347 if (editingState->isAborted()) | 1347 if (editingState->isAborted()) |
| 1348 return; | 1348 return; |
| 1349 | 1349 |
| 1350 DCHECK(destination.deepEquivalent().isConnected()) << destination; | 1350 DCHECK(destination.deepEquivalent().isConnected()) << destination; |
| 1351 cleanupAfterDeletion(editingState, destination); | 1351 cleanupAfterDeletion(editingState, destination); |
| 1352 if (editingState->isAborted()) | 1352 if (editingState->isAborted()) |
| 1353 return; | 1353 return; |
| 1354 DCHECK(destination.deepEquivalent().isConnected()) << destination; | 1354 DCHECK(destination.deepEquivalent().isConnected()) << destination; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1366 // FIXME: Trim text between beforeParagraph and afterParagraph if they a
ren't equal. | 1366 // FIXME: Trim text between beforeParagraph and afterParagraph if they a
ren't equal. |
| 1367 insertNodeAt(HTMLBRElement::create(document()), beforeParagraph.deepEqui
valent(), editingState); | 1367 insertNodeAt(HTMLBRElement::create(document()), beforeParagraph.deepEqui
valent(), editingState); |
| 1368 if (editingState->isAborted()) | 1368 if (editingState->isAborted()) |
| 1369 return; | 1369 return; |
| 1370 // Need an updateLayout here in case inserting the br has split a text n
ode. | 1370 // Need an updateLayout here in case inserting the br has split a text n
ode. |
| 1371 document().updateStyleAndLayoutIgnorePendingStylesheets(); | 1371 document().updateStyleAndLayoutIgnorePendingStylesheets(); |
| 1372 } | 1372 } |
| 1373 | 1373 |
| 1374 destinationIndex = TextIterator::rangeLength(Position::firstPositionInNode(d
ocument().documentElement()), destination.toParentAnchoredPosition(), true); | 1374 destinationIndex = TextIterator::rangeLength(Position::firstPositionInNode(d
ocument().documentElement()), destination.toParentAnchoredPosition(), true); |
| 1375 | 1375 |
| 1376 VisibleSelection destinationSelection(destination, originalIsDirectional); | 1376 VisibleSelection destinationSelection = createVisibleSelectionDeprecated(des
tination, originalIsDirectional); |
| 1377 if (endingSelection().isNone()) { | 1377 if (endingSelection().isNone()) { |
| 1378 // We abort executing command since |destination| becomes invisible. | 1378 // We abort executing command since |destination| becomes invisible. |
| 1379 editingState->abort(); | 1379 editingState->abort(); |
| 1380 return; | 1380 return; |
| 1381 } | 1381 } |
| 1382 setEndingSelection(destinationSelection); | 1382 setEndingSelection(destinationSelection); |
| 1383 ReplaceSelectionCommand::CommandOptions options = ReplaceSelectionCommand::S
electReplacement | ReplaceSelectionCommand::MovingParagraph; | 1383 ReplaceSelectionCommand::CommandOptions options = ReplaceSelectionCommand::S
electReplacement | ReplaceSelectionCommand::MovingParagraph; |
| 1384 if (shouldPreserveStyle == DoNotPreserveStyle) | 1384 if (shouldPreserveStyle == DoNotPreserveStyle) |
| 1385 options |= ReplaceSelectionCommand::MatchStyle; | 1385 options |= ReplaceSelectionCommand::MatchStyle; |
| 1386 applyCommandToComposite(ReplaceSelectionCommand::create(document(), fragment
, options), editingState); | 1386 applyCommandToComposite(ReplaceSelectionCommand::create(document(), fragment
, options), editingState); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1410 // instead of nbsps for some spaces that were rendered (11475), which causes | 1410 // instead of nbsps for some spaces that were rendered (11475), which causes |
| 1411 // spaces to be collapsed during the move operation. This results in a call | 1411 // spaces to be collapsed during the move operation. This results in a call |
| 1412 // to rangeFromLocationAndLength with a location past the end of the | 1412 // to rangeFromLocationAndLength with a location past the end of the |
| 1413 // document (which will return null). | 1413 // document (which will return null). |
| 1414 EphemeralRange startRange = PlainTextRange(destinationIndex + startIndex).cr
eateRangeForSelection(*documentElement); | 1414 EphemeralRange startRange = PlainTextRange(destinationIndex + startIndex).cr
eateRangeForSelection(*documentElement); |
| 1415 if (startRange.isNull()) | 1415 if (startRange.isNull()) |
| 1416 return; | 1416 return; |
| 1417 EphemeralRange endRange = PlainTextRange(destinationIndex + endIndex).create
RangeForSelection(*documentElement); | 1417 EphemeralRange endRange = PlainTextRange(destinationIndex + endIndex).create
RangeForSelection(*documentElement); |
| 1418 if (endRange.isNull()) | 1418 if (endRange.isNull()) |
| 1419 return; | 1419 return; |
| 1420 setEndingSelection(VisibleSelection(startRange.startPosition(), endRange.sta
rtPosition(), TextAffinity::Downstream, originalIsDirectional)); | 1420 setEndingSelection(createVisibleSelectionDeprecated(startRange.startPosition
(), endRange.startPosition(), TextAffinity::Downstream, originalIsDirectional)); |
| 1421 } | 1421 } |
| 1422 | 1422 |
| 1423 // FIXME: Send an appropriate shouldDeleteRange call. | 1423 // FIXME: Send an appropriate shouldDeleteRange call. |
| 1424 bool CompositeEditCommand::breakOutOfEmptyListItem(EditingState* editingState) | 1424 bool CompositeEditCommand::breakOutOfEmptyListItem(EditingState* editingState) |
| 1425 { | 1425 { |
| 1426 Node* emptyListItem = enclosingEmptyListItem(endingSelection().visibleStartD
eprecated()); | 1426 Node* emptyListItem = enclosingEmptyListItem(endingSelection().visibleStartD
eprecated()); |
| 1427 if (!emptyListItem) | 1427 if (!emptyListItem) |
| 1428 return false; | 1428 return false; |
| 1429 | 1429 |
| 1430 EditingStyle* style = EditingStyle::create(endingSelection().start()); | 1430 EditingStyle* style = EditingStyle::create(endingSelection().start()); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1483 if (editingState->isAborted()) | 1483 if (editingState->isAborted()) |
| 1484 return false; | 1484 return false; |
| 1485 removeNode(isListItem(previousListNode) || isHTMLListElement(previousLis
tNode) ? emptyListItem : listNode, editingState); | 1485 removeNode(isListItem(previousListNode) || isHTMLListElement(previousLis
tNode) ? emptyListItem : listNode, editingState); |
| 1486 if (editingState->isAborted()) | 1486 if (editingState->isAborted()) |
| 1487 return false; | 1487 return false; |
| 1488 } | 1488 } |
| 1489 | 1489 |
| 1490 appendBlockPlaceholder(newBlock, editingState); | 1490 appendBlockPlaceholder(newBlock, editingState); |
| 1491 if (editingState->isAborted()) | 1491 if (editingState->isAborted()) |
| 1492 return false; | 1492 return false; |
| 1493 setEndingSelection(VisibleSelection(Position::firstPositionInNode(newBlock),
TextAffinity::Downstream, endingSelection().isDirectional())); | 1493 setEndingSelection(createVisibleSelectionDeprecated(Position::firstPositionI
nNode(newBlock), TextAffinity::Downstream, endingSelection().isDirectional())); |
| 1494 | 1494 |
| 1495 style->prepareToApplyAt(endingSelection().start()); | 1495 style->prepareToApplyAt(endingSelection().start()); |
| 1496 if (!style->isEmpty()) { | 1496 if (!style->isEmpty()) { |
| 1497 applyStyle(style, editingState); | 1497 applyStyle(style, editingState); |
| 1498 if (editingState->isAborted()) | 1498 if (editingState->isAborted()) |
| 1499 return false; | 1499 return false; |
| 1500 } | 1500 } |
| 1501 | 1501 |
| 1502 return true; | 1502 return true; |
| 1503 } | 1503 } |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1529 if (editingState->isAborted()) | 1529 if (editingState->isAborted()) |
| 1530 return false; | 1530 return false; |
| 1531 VisiblePosition atBR = VisiblePosition::beforeNode(br); | 1531 VisiblePosition atBR = VisiblePosition::beforeNode(br); |
| 1532 // If the br we inserted collapsed, for example foo<br><blockquote>...</bloc
kquote>, insert | 1532 // If the br we inserted collapsed, for example foo<br><blockquote>...</bloc
kquote>, insert |
| 1533 // a second one. | 1533 // a second one. |
| 1534 if (!isStartOfParagraphDeprecated(atBR)) { | 1534 if (!isStartOfParagraphDeprecated(atBR)) { |
| 1535 insertNodeBefore(HTMLBRElement::create(document()), br, editingState); | 1535 insertNodeBefore(HTMLBRElement::create(document()), br, editingState); |
| 1536 if (editingState->isAborted()) | 1536 if (editingState->isAborted()) |
| 1537 return false; | 1537 return false; |
| 1538 } | 1538 } |
| 1539 setEndingSelection(VisibleSelection(atBR, endingSelection().isDirectional())
); | 1539 setEndingSelection(createVisibleSelectionDeprecated(atBR, endingSelection().
isDirectional())); |
| 1540 | 1540 |
| 1541 // If this is an empty paragraph there must be a line break here. | 1541 // If this is an empty paragraph there must be a line break here. |
| 1542 if (!lineBreakExistsAtVisiblePosition(caret)) | 1542 if (!lineBreakExistsAtVisiblePosition(caret)) |
| 1543 return false; | 1543 return false; |
| 1544 | 1544 |
| 1545 Position caretPos(mostForwardCaretPosition(caret.deepEquivalent())); | 1545 Position caretPos(mostForwardCaretPosition(caret.deepEquivalent())); |
| 1546 // A line break is either a br or a preserved newline. | 1546 // A line break is either a br or a preserved newline. |
| 1547 DCHECK(isHTMLBRElement(caretPos.anchorNode()) || (caretPos.anchorNode()->isT
extNode() && caretPos.anchorNode()->layoutObject()->style()->preserveNewline()))
<< caretPos; | 1547 DCHECK(isHTMLBRElement(caretPos.anchorNode()) || (caretPos.anchorNode()->isT
extNode() && caretPos.anchorNode()->layoutObject()->style()->preserveNewline()))
<< caretPos; |
| 1548 | 1548 |
| 1549 if (isHTMLBRElement(*caretPos.anchorNode())) { | 1549 if (isHTMLBRElement(*caretPos.anchorNode())) { |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1660 } | 1660 } |
| 1661 | 1661 |
| 1662 DEFINE_TRACE(CompositeEditCommand) | 1662 DEFINE_TRACE(CompositeEditCommand) |
| 1663 { | 1663 { |
| 1664 visitor->trace(m_commands); | 1664 visitor->trace(m_commands); |
| 1665 visitor->trace(m_composition); | 1665 visitor->trace(m_composition); |
| 1666 EditCommand::trace(visitor); | 1666 EditCommand::trace(visitor); |
| 1667 } | 1667 } |
| 1668 | 1668 |
| 1669 } // namespace blink | 1669 } // namespace blink |
| OLD | NEW |