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

Side by Side Diff: Source/core/editing/DeleteSelectionCommand.cpp

Issue 23450030: Introduce Position::inDocument() (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « Source/core/editing/CompositeEditCommand.cpp ('k') | Source/core/editing/Editor.cpp » ('j') | 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 Apple Computer, Inc. All rights reserved. 2 * Copyright (C) 2005 Apple Computer, 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 514 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 } else { 525 } else {
526 Node* n = node->lastDescendant(); 526 Node* n = node->lastDescendant();
527 if (m_downstreamEnd.deprecatedNode() == n && m_downstreamEnd.dep recatedEditingOffset() >= caretMaxOffset(n)) { 527 if (m_downstreamEnd.deprecatedNode() == n && m_downstreamEnd.dep recatedEditingOffset() >= caretMaxOffset(n)) {
528 removeNode(node.get()); 528 removeNode(node.get());
529 node = 0; 529 node = 0;
530 } else 530 } else
531 node = NodeTraversal::next(node.get()); 531 node = NodeTraversal::next(node.get());
532 } 532 }
533 } 533 }
534 534
535 if (m_downstreamEnd.deprecatedNode() != startNode && !m_upstreamStart.de precatedNode()->isDescendantOf(m_downstreamEnd.deprecatedNode()) && m_downstream End.anchorNode()->inDocument() && m_downstreamEnd.deprecatedEditingOffset() >= c aretMinOffset(m_downstreamEnd.deprecatedNode())) { 535 if (m_downstreamEnd.deprecatedNode() != startNode && !m_upstreamStart.de precatedNode()->isDescendantOf(m_downstreamEnd.deprecatedNode()) && m_downstream End.inDocument() && m_downstreamEnd.deprecatedEditingOffset() >= caretMinOffset( m_downstreamEnd.deprecatedNode())) {
536 if (m_downstreamEnd.atLastEditingPositionForNode() && !canHaveChildr enForEditing(m_downstreamEnd.deprecatedNode())) { 536 if (m_downstreamEnd.atLastEditingPositionForNode() && !canHaveChildr enForEditing(m_downstreamEnd.deprecatedNode())) {
537 // The node itself is fully selected, not just its contents. De lete it. 537 // The node itself is fully selected, not just its contents. De lete it.
538 removeNode(m_downstreamEnd.deprecatedNode()); 538 removeNode(m_downstreamEnd.deprecatedNode());
539 } else { 539 } else {
540 if (m_downstreamEnd.deprecatedNode()->isTextNode()) { 540 if (m_downstreamEnd.deprecatedNode()->isTextNode()) {
541 // in a text node that needs to be trimmed 541 // in a text node that needs to be trimmed
542 Text* text = toText(m_downstreamEnd.deprecatedNode()); 542 Text* text = toText(m_downstreamEnd.deprecatedNode());
543 if (m_downstreamEnd.deprecatedEditingOffset() > 0) { 543 if (m_downstreamEnd.deprecatedEditingOffset() > 0) {
544 deleteTextFromNode(text, 0, m_downstreamEnd.deprecatedEd itingOffset()); 544 deleteTextFromNode(text, 0, m_downstreamEnd.deprecatedEd itingOffset());
545 } 545 }
546 // Remove children of m_downstreamEnd.deprecatedNode() that come after m_upstreamStart. 546 // Remove children of m_downstreamEnd.deprecatedNode() that come after m_upstreamStart.
547 // Don't try to remove children if m_upstreamStart was inside m_ downstreamEnd.deprecatedNode() 547 // Don't try to remove children if m_upstreamStart was inside m_ downstreamEnd.deprecatedNode()
548 // and m_upstreamStart has been removed from the document, becau se then we don't 548 // and m_upstreamStart has been removed from the document, becau se then we don't
549 // know how many children to remove. 549 // know how many children to remove.
550 // FIXME: Make m_upstreamStart a position we update as we remove content, then we can 550 // FIXME: Make m_upstreamStart a position we update as we remove content, then we can
551 // always know which children to remove. 551 // always know which children to remove.
552 } else if (!(startNodeWasDescendantOfEndNode && !m_upstreamStart .anchorNode()->inDocument())) { 552 } else if (!(startNodeWasDescendantOfEndNode && !m_upstreamStart .inDocument())) {
553 int offset = 0; 553 int offset = 0;
554 if (m_upstreamStart.deprecatedNode()->isDescendantOf(m_downs treamEnd.deprecatedNode())) { 554 if (m_upstreamStart.deprecatedNode()->isDescendantOf(m_downs treamEnd.deprecatedNode())) {
555 Node* n = m_upstreamStart.deprecatedNode(); 555 Node* n = m_upstreamStart.deprecatedNode();
556 while (n && n->parentNode() != m_downstreamEnd.deprecate dNode()) 556 while (n && n->parentNode() != m_downstreamEnd.deprecate dNode())
557 n = n->parentNode(); 557 n = n->parentNode();
558 if (n) 558 if (n)
559 offset = n->nodeIndex() + 1; 559 offset = n->nodeIndex() + 1;
560 } 560 }
561 removeChildrenInRange(m_downstreamEnd.deprecatedNode(), offs et, m_downstreamEnd.deprecatedEditingOffset()); 561 removeChildrenInRange(m_downstreamEnd.deprecatedNode(), offs et, m_downstreamEnd.deprecatedEditingOffset());
562 m_downstreamEnd = createLegacyEditingPosition(m_downstreamEn d.deprecatedNode(), offset); 562 m_downstreamEnd = createLegacyEditingPosition(m_downstreamEn d.deprecatedNode(), offset);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
594 // a placeholder, but not in this case. 594 // a placeholder, but not in this case.
595 m_needPlaceholder = false; 595 m_needPlaceholder = false;
596 } 596 }
597 return; 597 return;
598 } 598 }
599 599
600 // It shouldn't have been asked to both try and merge content into the start block and prune it. 600 // It shouldn't have been asked to both try and merge content into the start block and prune it.
601 ASSERT(!m_pruneStartBlockIfNecessary); 601 ASSERT(!m_pruneStartBlockIfNecessary);
602 602
603 // FIXME: Deletion should adjust selection endpoints as it removes nodes so that we never get into this state (4099839). 603 // FIXME: Deletion should adjust selection endpoints as it removes nodes so that we never get into this state (4099839).
604 if (!m_downstreamEnd.anchorNode()->inDocument() || !m_upstreamStart.anchorNo de()->inDocument()) 604 if (!m_downstreamEnd.inDocument() || !m_upstreamStart.inDocument())
605 return; 605 return;
606 606
607 // FIXME: The deletion algorithm shouldn't let this happen. 607 // FIXME: The deletion algorithm shouldn't let this happen.
608 if (comparePositions(m_upstreamStart, m_downstreamEnd) > 0) 608 if (comparePositions(m_upstreamStart, m_downstreamEnd) > 0)
609 return; 609 return;
610 610
611 // There's nothing to merge. 611 // There's nothing to merge.
612 if (m_upstreamStart == m_downstreamEnd) 612 if (m_upstreamStart == m_downstreamEnd)
613 return; 613 return;
614 614
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
850 850
851 // Normally deletion doesn't preserve the typing style that was present before i t. For example, 851 // Normally deletion doesn't preserve the typing style that was present before i t. For example,
852 // type a character, Bold, then delete the character and start typing. The Bold typing style shouldn't 852 // type a character, Bold, then delete the character and start typing. The Bold typing style shouldn't
853 // stick around. Deletion should preserve a typing style that *it* sets, howeve r. 853 // stick around. Deletion should preserve a typing style that *it* sets, howeve r.
854 bool DeleteSelectionCommand::preservesTypingStyle() const 854 bool DeleteSelectionCommand::preservesTypingStyle() const
855 { 855 {
856 return m_typingStyle; 856 return m_typingStyle;
857 } 857 }
858 858
859 } // namespace WebCore 859 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/editing/CompositeEditCommand.cpp ('k') | Source/core/editing/Editor.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698