Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(330)

Side by Side Diff: third_party/WebKit/Source/core/editing/commands/ReplaceSelectionCommand.cpp

Issue 2405223002: Ensure valid input for CompositeEditCommand::moveParagraph[s] (Closed)
Patch Set: Remove the dirty hacks Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/core/editing/commands/InsertListCommand.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 1507 matching lines...) Expand 10 before | Expand all | Expand 10 after
1518 lastPositionInOrAfterNode(insertedNodes.lastLeafInserted()); 1518 lastPositionInOrAfterNode(insertedNodes.lastLeafInserted());
1519 1519
1520 // Determine whether or not we should merge the end of inserted content with 1520 // Determine whether or not we should merge the end of inserted content with
1521 // what's after it before we do the start merge so that the start merge 1521 // what's after it before we do the start merge so that the start merge
1522 // doesn't effect our decision. 1522 // doesn't effect our decision.
1523 m_shouldMergeEnd = shouldMergeEnd(selectionEndWasEndOfParagraph); 1523 m_shouldMergeEnd = shouldMergeEnd(selectionEndWasEndOfParagraph);
1524 1524
1525 if (shouldMergeStart(selectionStartWasStartOfParagraph, 1525 if (shouldMergeStart(selectionStartWasStartOfParagraph,
1526 fragment.hasInterchangeNewlineAtStart(), 1526 fragment.hasInterchangeNewlineAtStart(),
1527 startIsInsideMailBlockquote)) { 1527 startIsInsideMailBlockquote)) {
1528 // TODO(xiaochengh): Stop storing VisiblePositions through mutations.
1529 VisiblePosition startOfParagraphToMove = positionAtStartOfInsertedContent(); 1528 VisiblePosition startOfParagraphToMove = positionAtStartOfInsertedContent();
1530 VisiblePosition destination = previousPositionOf(startOfParagraphToMove); 1529 VisiblePosition destination = previousPositionOf(startOfParagraphToMove);
1530
1531 // Helpers for making the VisiblePositions valid again after DOM changes.
1532 PositionWithAffinity startOfParagraphToMovePosition =
1533 startOfParagraphToMove.toPositionWithAffinity();
1534 PositionWithAffinity destinationPosition =
1535 destination.toPositionWithAffinity();
1536
1531 // We need to handle the case where we need to merge the end 1537 // We need to handle the case where we need to merge the end
1532 // but our destination node is inside an inline that is the last in the 1538 // but our destination node is inside an inline that is the last in the
1533 // block. 1539 // block.
1534 // We insert a placeholder before the newly inserted content to avoid being 1540 // We insert a placeholder before the newly inserted content to avoid being
1535 // merged into the inline. 1541 // merged into the inline.
1536 Node* destinationNode = destination.deepEquivalent().anchorNode(); 1542 Node* destinationNode = destination.deepEquivalent().anchorNode();
1537 if (m_shouldMergeEnd && 1543 if (m_shouldMergeEnd &&
1538 destinationNode != enclosingInline(destinationNode) && 1544 destinationNode != enclosingInline(destinationNode) &&
1539 enclosingInline(destinationNode)->nextSibling()) { 1545 enclosingInline(destinationNode)->nextSibling()) {
1540 insertNodeBefore(HTMLBRElement::create(document()), refNode, 1546 insertNodeBefore(HTMLBRElement::create(document()), refNode,
1541 editingState); 1547 editingState);
1542 if (editingState->isAborted()) 1548 if (editingState->isAborted())
1543 return; 1549 return;
1544 } 1550 }
1545 1551
1546 // Merging the the first paragraph of inserted content with the content that 1552 // Merging the the first paragraph of inserted content with the content that
1547 // came before the selection that was pasted into would also move content 1553 // came before the selection that was pasted into would also move content
1548 // after the selection that was pasted into if: only one paragraph was being 1554 // after the selection that was pasted into if: only one paragraph was being
1549 // pasted, and it was not wrapped in a block, the selection that was pasted 1555 // pasted, and it was not wrapped in a block, the selection that was pasted
1550 // into ended at the end of a block and the next paragraph didn't start at 1556 // into ended at the end of a block and the next paragraph didn't start at
1551 // the start of a block. 1557 // the start of a block.
1552 // Insert a line break just after the inserted content to separate it from 1558 // Insert a line break just after the inserted content to separate it from
1553 // what comes after and prevent that from happening. 1559 // what comes after and prevent that from happening.
1554 VisiblePosition endOfInsertedContent = positionAtEndOfInsertedContent(); 1560 VisiblePosition endOfInsertedContent = positionAtEndOfInsertedContent();
1555 if (startOfParagraph(endOfInsertedContent).deepEquivalent() == 1561 if (startOfParagraph(endOfInsertedContent).deepEquivalent() ==
1556 startOfParagraphToMove.deepEquivalent()) { 1562 startOfParagraphToMovePosition.position()) {
1557 insertNodeAt(HTMLBRElement::create(document()), 1563 insertNodeAt(HTMLBRElement::create(document()),
1558 endOfInsertedContent.deepEquivalent(), editingState); 1564 endOfInsertedContent.deepEquivalent(), editingState);
1559 if (editingState->isAborted()) 1565 if (editingState->isAborted())
1560 return; 1566 return;
1561 // Mutation events (bug 22634) triggered by inserting the <br> might have 1567 // Mutation events (bug 22634) triggered by inserting the <br> might have
1562 // removed the content we're about to move 1568 // removed the content we're about to move
1563 if (!startOfParagraphToMove.deepEquivalent().isConnected()) 1569 if (!startOfParagraphToMovePosition.position().isConnected())
1564 return; 1570 return;
1565 } 1571 }
1566 1572
1567 document().updateStyleAndLayoutIgnorePendingStylesheets(); 1573 document().updateStyleAndLayoutIgnorePendingStylesheets();
1568 1574
1575 // Making the two VisiblePositions valid again.
1576 startOfParagraphToMove =
1577 createVisiblePosition(startOfParagraphToMovePosition);
1578 destination = createVisiblePosition(destinationPosition);
1579
1569 // FIXME: Maintain positions for the start and end of inserted content 1580 // FIXME: Maintain positions for the start and end of inserted content
1570 // instead of keeping nodes. The nodes are only ever used to create 1581 // instead of keeping nodes. The nodes are only ever used to create
1571 // positions where inserted content starts/ends. 1582 // positions where inserted content starts/ends.
1572 moveParagraph(startOfParagraphToMove, 1583 moveParagraph(startOfParagraphToMove,
1573 endOfParagraph(createVisiblePosition( 1584 endOfParagraph(startOfParagraphToMove), destination,
1574 startOfParagraphToMove.toPositionWithAffinity())), 1585 editingState);
1575 destination, editingState);
1576 if (editingState->isAborted()) 1586 if (editingState->isAborted())
1577 return; 1587 return;
1578 1588
1579 document().updateStyleAndLayoutIgnorePendingStylesheets(); 1589 document().updateStyleAndLayoutIgnorePendingStylesheets();
1580 m_startOfInsertedContent = mostForwardCaretPosition( 1590 m_startOfInsertedContent = mostForwardCaretPosition(
1581 endingSelection().visibleStart().deepEquivalent()); 1591 endingSelection().visibleStart().deepEquivalent());
1582 if (m_endOfInsertedContent.isOrphan()) { 1592 if (m_endOfInsertedContent.isOrphan()) {
1583 m_endOfInsertedContent = mostBackwardCaretPosition( 1593 m_endOfInsertedContent = mostBackwardCaretPosition(
1584 endingSelection().visibleEnd().deepEquivalent()); 1594 endingSelection().visibleEnd().deepEquivalent());
1585 } 1595 }
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after
2065 visitor->trace(m_startOfInsertedContent); 2075 visitor->trace(m_startOfInsertedContent);
2066 visitor->trace(m_endOfInsertedContent); 2076 visitor->trace(m_endOfInsertedContent);
2067 visitor->trace(m_insertionStyle); 2077 visitor->trace(m_insertionStyle);
2068 visitor->trace(m_documentFragment); 2078 visitor->trace(m_documentFragment);
2069 visitor->trace(m_startOfInsertedRange); 2079 visitor->trace(m_startOfInsertedRange);
2070 visitor->trace(m_endOfInsertedRange); 2080 visitor->trace(m_endOfInsertedRange);
2071 CompositeEditCommand::trace(visitor); 2081 CompositeEditCommand::trace(visitor);
2072 } 2082 }
2073 2083
2074 } // namespace blink 2084 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/editing/commands/InsertListCommand.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698