| 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 1159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1170 | 1170 |
| 1171 | 1171 |
| 1172 // There are bugs in deletion when it removes a fully selected table/list. | 1172 // There are bugs in deletion when it removes a fully selected table/list. |
| 1173 // It expands and removes the entire table/list, but will let content | 1173 // It expands and removes the entire table/list, but will let content |
| 1174 // before and after the table/list collapse onto one line. | 1174 // before and after the table/list collapse onto one line. |
| 1175 // Deleting a paragraph will leave a placeholder. Remove it (and prune | 1175 // Deleting a paragraph will leave a placeholder. Remove it (and prune |
| 1176 // empty or unrendered parents). | 1176 // empty or unrendered parents). |
| 1177 | 1177 |
| 1178 void CompositeEditCommand::cleanupAfterDeletion(EditingState* editingState, Visi
blePosition destination) | 1178 void CompositeEditCommand::cleanupAfterDeletion(EditingState* editingState, Visi
blePosition destination) |
| 1179 { | 1179 { |
| 1180 VisiblePosition caretAfterDelete = endingSelection().visibleStart(); | 1180 VisiblePosition caretAfterDelete = endingSelection().visibleStartDeprecated(
); |
| 1181 Node* destinationNode = destination.deepEquivalent().anchorNode(); | 1181 Node* destinationNode = destination.deepEquivalent().anchorNode(); |
| 1182 if (caretAfterDelete.deepEquivalent() != destination.deepEquivalent() && isS
tartOfParagraphDeprecated(caretAfterDelete) && isEndOfParagraphDeprecated(caretA
fterDelete)) { | 1182 if (caretAfterDelete.deepEquivalent() != destination.deepEquivalent() && isS
tartOfParagraphDeprecated(caretAfterDelete) && isEndOfParagraphDeprecated(caretA
fterDelete)) { |
| 1183 // Note: We want the rightmost candidate. | 1183 // Note: We want the rightmost candidate. |
| 1184 Position position = mostForwardCaretPosition(caretAfterDelete.deepEquiva
lent()); | 1184 Position position = mostForwardCaretPosition(caretAfterDelete.deepEquiva
lent()); |
| 1185 Node* node = position.anchorNode(); | 1185 Node* node = position.anchorNode(); |
| 1186 | 1186 |
| 1187 // Bail if we'd remove an ancestor of our destination. | 1187 // Bail if we'd remove an ancestor of our destination. |
| 1188 if (destinationNode && destinationNode->isDescendantOf(node)) | 1188 if (destinationNode && destinationNode->isDescendantOf(node)) |
| 1189 return; | 1189 return; |
| 1190 | 1190 |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1285 void CompositeEditCommand::moveParagraphs(const VisiblePosition& startOfParagrap
hToMove, const VisiblePosition& endOfParagraphToMove, const VisiblePosition& des
tination, EditingState* editingState, ShouldPreserveSelection shouldPreserveSele
ction, ShouldPreserveStyle shouldPreserveStyle, Node* constrainingAncestor) | 1285 void CompositeEditCommand::moveParagraphs(const VisiblePosition& startOfParagrap
hToMove, const VisiblePosition& endOfParagraphToMove, const VisiblePosition& des
tination, EditingState* editingState, ShouldPreserveSelection shouldPreserveSele
ction, ShouldPreserveStyle shouldPreserveStyle, Node* constrainingAncestor) |
| 1286 { | 1286 { |
| 1287 if (startOfParagraphToMove.deepEquivalent() == destination.deepEquivalent()
|| startOfParagraphToMove.isNull()) | 1287 if (startOfParagraphToMove.deepEquivalent() == destination.deepEquivalent()
|| startOfParagraphToMove.isNull()) |
| 1288 return; | 1288 return; |
| 1289 | 1289 |
| 1290 int startIndex = -1; | 1290 int startIndex = -1; |
| 1291 int endIndex = -1; | 1291 int endIndex = -1; |
| 1292 int destinationIndex = -1; | 1292 int destinationIndex = -1; |
| 1293 bool originalIsDirectional = endingSelection().isDirectional(); | 1293 bool originalIsDirectional = endingSelection().isDirectional(); |
| 1294 if (shouldPreserveSelection == PreserveSelection && !endingSelection().isNon
e()) { | 1294 if (shouldPreserveSelection == PreserveSelection && !endingSelection().isNon
e()) { |
| 1295 VisiblePosition visibleStart = endingSelection().visibleStart(); | 1295 VisiblePosition visibleStart = endingSelection().visibleStartDeprecated(
); |
| 1296 VisiblePosition visibleEnd = endingSelection().visibleEnd(); | 1296 VisiblePosition visibleEnd = endingSelection().visibleEndDeprecated(); |
| 1297 | 1297 |
| 1298 bool startAfterParagraph = comparePositions(visibleStart, endOfParagraph
ToMove) > 0; | 1298 bool startAfterParagraph = comparePositions(visibleStart, endOfParagraph
ToMove) > 0; |
| 1299 bool endBeforeParagraph = comparePositions(visibleEnd, startOfParagraphT
oMove) < 0; | 1299 bool endBeforeParagraph = comparePositions(visibleEnd, startOfParagraphT
oMove) < 0; |
| 1300 | 1300 |
| 1301 if (!startAfterParagraph && !endBeforeParagraph) { | 1301 if (!startAfterParagraph && !endBeforeParagraph) { |
| 1302 bool startInParagraph = comparePositions(visibleStart, startOfParagr
aphToMove) >= 0; | 1302 bool startInParagraph = comparePositions(visibleStart, startOfParagr
aphToMove) >= 0; |
| 1303 bool endInParagraph = comparePositions(visibleEnd, endOfParagraphToM
ove) <= 0; | 1303 bool endInParagraph = comparePositions(visibleEnd, endOfParagraphToM
ove) <= 0; |
| 1304 | 1304 |
| 1305 // TextIterator::rangeLength requires clean layout. | 1305 // TextIterator::rangeLength requires clean layout. |
| 1306 document().updateStyleAndLayoutIgnorePendingStylesheets(); | 1306 document().updateStyleAndLayoutIgnorePendingStylesheets(); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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); |
| 1387 if (editingState->isAborted()) | 1387 if (editingState->isAborted()) |
| 1388 return; | 1388 return; |
| 1389 | 1389 |
| 1390 document().frame()->spellChecker().markMisspellingsAndBadGrammarForMovingPar
agraphs(endingSelection()); | 1390 document().frame()->spellChecker().markMisspellingsAndBadGrammarForMovingPar
agraphs(endingSelection()); |
| 1391 | 1391 |
| 1392 // If the selection is in an empty paragraph, restore styles from the old em
pty paragraph to the new empty paragraph. | 1392 // If the selection is in an empty paragraph, restore styles from the old em
pty paragraph to the new empty paragraph. |
| 1393 bool selectionIsEmptyParagraph = endingSelection().isCaret() && isStartOfPar
agraphDeprecated(endingSelection().visibleStart()) && isEndOfParagraphDeprecated
(endingSelection().visibleStart()); | 1393 bool selectionIsEmptyParagraph = endingSelection().isCaret() && isStartOfPar
agraphDeprecated(endingSelection().visibleStartDeprecated()) && isEndOfParagraph
Deprecated(endingSelection().visibleStartDeprecated()); |
| 1394 if (styleInEmptyParagraph && selectionIsEmptyParagraph) { | 1394 if (styleInEmptyParagraph && selectionIsEmptyParagraph) { |
| 1395 applyStyle(styleInEmptyParagraph, editingState); | 1395 applyStyle(styleInEmptyParagraph, editingState); |
| 1396 if (editingState->isAborted()) | 1396 if (editingState->isAborted()) |
| 1397 return; | 1397 return; |
| 1398 } | 1398 } |
| 1399 | 1399 |
| 1400 if (shouldPreserveSelection == DoNotPreserveSelection || startIndex == -1) | 1400 if (shouldPreserveSelection == DoNotPreserveSelection || startIndex == -1) |
| 1401 return; | 1401 return; |
| 1402 Element* documentElement = document().documentElement(); | 1402 Element* documentElement = document().documentElement(); |
| 1403 if (!documentElement) | 1403 if (!documentElement) |
| (...skipping 12 matching lines...) Expand all Loading... |
| 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(VisibleSelection(startRange.startPosition(), endRange.sta
rtPosition(), 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().visibleStart(
)); | 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()); |
| 1431 style->mergeTypingStyle(&document()); | 1431 style->mergeTypingStyle(&document()); |
| 1432 | 1432 |
| 1433 ContainerNode* listNode = emptyListItem->parentNode(); | 1433 ContainerNode* listNode = emptyListItem->parentNode(); |
| 1434 // FIXME: Can't we do something better when the immediate parent wasn't a li
st node? | 1434 // FIXME: Can't we do something better when the immediate parent wasn't a li
st node? |
| 1435 if (!listNode | 1435 if (!listNode |
| 1436 || (!isHTMLUListElement(*listNode) && !isHTMLOListElement(*listNode)) | 1436 || (!isHTMLUListElement(*listNode) && !isHTMLOListElement(*listNode)) |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1502 return true; | 1502 return true; |
| 1503 } | 1503 } |
| 1504 | 1504 |
| 1505 // If the caret is in an empty quoted paragraph, and either there is nothing bef
ore that | 1505 // If the caret is in an empty quoted paragraph, and either there is nothing bef
ore that |
| 1506 // paragraph, or what is before is unquoted, and the user presses delete, unquot
e that paragraph. | 1506 // paragraph, or what is before is unquoted, and the user presses delete, unquot
e that paragraph. |
| 1507 bool CompositeEditCommand::breakOutOfEmptyMailBlockquotedParagraph(EditingState*
editingState) | 1507 bool CompositeEditCommand::breakOutOfEmptyMailBlockquotedParagraph(EditingState*
editingState) |
| 1508 { | 1508 { |
| 1509 if (!endingSelection().isCaret()) | 1509 if (!endingSelection().isCaret()) |
| 1510 return false; | 1510 return false; |
| 1511 | 1511 |
| 1512 VisiblePosition caret = endingSelection().visibleStart(); | 1512 VisiblePosition caret = endingSelection().visibleStartDeprecated(); |
| 1513 HTMLQuoteElement* highestBlockquote = toHTMLQuoteElement(highestEnclosingNod
eOfType(caret.deepEquivalent(), &isMailHTMLBlockquoteElement)); | 1513 HTMLQuoteElement* highestBlockquote = toHTMLQuoteElement(highestEnclosingNod
eOfType(caret.deepEquivalent(), &isMailHTMLBlockquoteElement)); |
| 1514 if (!highestBlockquote) | 1514 if (!highestBlockquote) |
| 1515 return false; | 1515 return false; |
| 1516 | 1516 |
| 1517 if (!isStartOfParagraphDeprecated(caret) || !isEndOfParagraphDeprecated(care
t)) | 1517 if (!isStartOfParagraphDeprecated(caret) || !isEndOfParagraphDeprecated(care
t)) |
| 1518 return false; | 1518 return false; |
| 1519 | 1519 |
| 1520 VisiblePosition previous = previousPositionOf(caret, CannotCrossEditingBound
ary); | 1520 VisiblePosition previous = previousPositionOf(caret, CannotCrossEditingBound
ary); |
| 1521 // Only move forward if there's nothing before the caret, or if there's unqu
oted content before it. | 1521 // Only move forward if there's nothing before the caret, or if there's unqu
oted content before it. |
| 1522 if (enclosingNodeOfType(previous.deepEquivalent(), &isMailHTMLBlockquoteElem
ent)) | 1522 if (enclosingNodeOfType(previous.deepEquivalent(), &isMailHTMLBlockquoteElem
ent)) |
| (...skipping 137 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 |