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

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

Issue 2140733003: [Editing][CodeHealth] Make Node::rootEditableElement static (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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
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 351 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 if (nextChild && nextChild->parentNode() != node) 362 if (nextChild && nextChild->parentNode() != node)
363 return; 363 return;
364 child = nextChild; 364 child = nextChild;
365 } 365 }
366 366
367 // Don't remove editable regions that are inside non-editable ones, just clear them. 367 // Don't remove editable regions that are inside non-editable ones, just clear them.
368 return; 368 return;
369 } 369 }
370 } 370 }
371 371
372 if (isTableStructureNode(node) || node->isRootEditableElement()) { 372 if (isTableStructureNode(node) || isRootEditableElement(*node)) {
373 // Do not remove an element of table structure; remove its contents. 373 // Do not remove an element of table structure; remove its contents.
374 // Likewise for the root editable element. 374 // Likewise for the root editable element.
375 Node* child = node->firstChild(); 375 Node* child = node->firstChild();
376 while (child) { 376 while (child) {
377 Node* remove = child; 377 Node* remove = child;
378 child = child->nextSibling(); 378 child = child->nextSibling();
379 removeNode(remove, editingState, shouldAssumeContentIsAlwaysEditable ); 379 removeNode(remove, editingState, shouldAssumeContentIsAlwaysEditable );
380 if (editingState->isAborted()) 380 if (editingState->isAborted())
381 return; 381 return;
382 } 382 }
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 } 434 }
435 435
436 void DeleteSelectionCommand::makeStylingElementsDirectChildrenOfEditableRootToPr eventStyleLoss(EditingState* editingState) 436 void DeleteSelectionCommand::makeStylingElementsDirectChildrenOfEditableRootToPr eventStyleLoss(EditingState* editingState)
437 { 437 {
438 Range* range = createRange(m_selectionToDelete.toNormalizedEphemeralRange()) ; 438 Range* range = createRange(m_selectionToDelete.toNormalizedEphemeralRange()) ;
439 Node* node = range->firstNode(); 439 Node* node = range->firstNode();
440 while (node && node != range->pastLastNode()) { 440 while (node && node != range->pastLastNode()) {
441 Node* nextNode = NodeTraversal::next(*node); 441 Node* nextNode = NodeTraversal::next(*node);
442 if (isHTMLStyleElement(*node) || isHTMLLinkElement(*node)) { 442 if (isHTMLStyleElement(*node) || isHTMLLinkElement(*node)) {
443 nextNode = NodeTraversal::nextSkippingChildren(*node); 443 nextNode = NodeTraversal::nextSkippingChildren(*node);
444 Element* rootEditableElement = node->rootEditableElement(); 444 Element* element = rootEditableElement(*node);
445 if (rootEditableElement) { 445 if (element) {
446 removeNode(node, editingState); 446 removeNode(node, editingState);
447 if (editingState->isAborted()) 447 if (editingState->isAborted())
448 return; 448 return;
449 appendNode(node, rootEditableElement, editingState); 449 appendNode(node, element, editingState);
450 if (editingState->isAborted()) 450 if (editingState->isAborted())
451 return; 451 return;
452 } 452 }
453 } 453 }
454 node = nextNode; 454 node = nextNode;
455 } 455 }
456 } 456 }
457 457
458 void DeleteSelectionCommand::handleGeneralDelete(EditingState* editingState) 458 void DeleteSelectionCommand::handleGeneralDelete(EditingState* editingState)
459 { 459 {
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
802 m_downstreamEnd = Position(); 802 m_downstreamEnd = Position();
803 m_endingPosition = Position(); 803 m_endingPosition = Position();
804 m_leadingWhitespace = Position(); 804 m_leadingWhitespace = Position();
805 m_trailingWhitespace = Position(); 805 m_trailingWhitespace = Position();
806 } 806 }
807 807
808 // This method removes div elements with no attributes that have only one child or no children at all. 808 // This method removes div elements with no attributes that have only one child or no children at all.
809 void DeleteSelectionCommand::removeRedundantBlocks(EditingState* editingState) 809 void DeleteSelectionCommand::removeRedundantBlocks(EditingState* editingState)
810 { 810 {
811 Node* node = m_endingPosition.computeContainerNode(); 811 Node* node = m_endingPosition.computeContainerNode();
812 Element* rootElement = node->rootEditableElement(); 812 Element* rootElement = rootEditableElement(*node);
813 813
814 while (node != rootElement) { 814 while (node != rootElement) {
815 if (isRemovableBlock(node)) { 815 if (isRemovableBlock(node)) {
816 if (node == m_endingPosition.anchorNode()) 816 if (node == m_endingPosition.anchorNode())
817 updatePositionForNodeRemovalPreservingChildren(m_endingPosition, *node); 817 updatePositionForNodeRemovalPreservingChildren(m_endingPosition, *node);
818 818
819 CompositeEditCommand::removeNodePreservingChildren(node, editingStat e); 819 CompositeEditCommand::removeNodePreservingChildren(node, editingStat e);
820 if (editingState->isAborted()) 820 if (editingState->isAborted())
821 return; 821 return;
822 node = m_endingPosition.anchorNode(); 822 node = m_endingPosition.anchorNode();
(...skipping 10 matching lines...) Expand all
833 if (!m_hasSelectionToDelete) 833 if (!m_hasSelectionToDelete)
834 m_selectionToDelete = endingSelection(); 834 m_selectionToDelete = endingSelection();
835 835
836 if (!m_selectionToDelete.isNonOrphanedRange() || !m_selectionToDelete.isCont entEditable()) 836 if (!m_selectionToDelete.isNonOrphanedRange() || !m_selectionToDelete.isCont entEditable())
837 return; 837 return;
838 838
839 // save this to later make the selection with 839 // save this to later make the selection with
840 TextAffinity affinity = m_selectionToDelete.affinity(); 840 TextAffinity affinity = m_selectionToDelete.affinity();
841 841
842 Position downstreamEnd = mostForwardCaretPosition(m_selectionToDelete.end()) ; 842 Position downstreamEnd = mostForwardCaretPosition(m_selectionToDelete.end()) ;
843 bool rootWillStayOpenWithoutPlaceholder = downstreamEnd.computeContainerNode () == downstreamEnd.computeContainerNode()->rootEditableElement() 843 bool rootWillStayOpenWithoutPlaceholder = downstreamEnd.computeContainerNode () == rootEditableElement(*downstreamEnd.computeContainerNode())
844 || (downstreamEnd.computeContainerNode()->isTextNode() && downstreamEnd. computeContainerNode()->parentNode() == downstreamEnd.computeContainerNode()->ro otEditableElement()); 844 || (downstreamEnd.computeContainerNode()->isTextNode() && downstreamEnd. computeContainerNode()->parentNode() == rootEditableElement(*downstreamEnd.compu teContainerNode()));
845 bool lineBreakAtEndOfSelectionToDelete = lineBreakExistsAtVisiblePosition(m_ selectionToDelete.visibleEnd()); 845 bool lineBreakAtEndOfSelectionToDelete = lineBreakExistsAtVisiblePosition(m_ selectionToDelete.visibleEnd());
846 m_needPlaceholder = !rootWillStayOpenWithoutPlaceholder 846 m_needPlaceholder = !rootWillStayOpenWithoutPlaceholder
847 && isStartOfParagraph(m_selectionToDelete.visibleStart(), CanCrossEditin gBoundary) 847 && isStartOfParagraph(m_selectionToDelete.visibleStart(), CanCrossEditin gBoundary)
848 && isEndOfParagraph(m_selectionToDelete.visibleEnd(), CanCrossEditingBou ndary) 848 && isEndOfParagraph(m_selectionToDelete.visibleEnd(), CanCrossEditingBou ndary)
849 && !lineBreakAtEndOfSelectionToDelete; 849 && !lineBreakAtEndOfSelectionToDelete;
850 if (m_needPlaceholder) { 850 if (m_needPlaceholder) {
851 // Don't need a placeholder when deleting a selection that starts just 851 // Don't need a placeholder when deleting a selection that starts just
852 // before a table and ends inside it (we do need placeholders to hold 852 // before a table and ends inside it (we do need placeholders to hold
853 // open empty cells, but that's handled elsewhere). 853 // open empty cells, but that's handled elsewhere).
854 if (Element* table = tableElementJustAfter(m_selectionToDelete.visibleSt art())) { 854 if (Element* table = tableElementJustAfter(m_selectionToDelete.visibleSt art())) {
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
961 visitor->trace(m_deleteIntoBlockquoteStyle); 961 visitor->trace(m_deleteIntoBlockquoteStyle);
962 visitor->trace(m_startRoot); 962 visitor->trace(m_startRoot);
963 visitor->trace(m_endRoot); 963 visitor->trace(m_endRoot);
964 visitor->trace(m_startTableRow); 964 visitor->trace(m_startTableRow);
965 visitor->trace(m_endTableRow); 965 visitor->trace(m_endTableRow);
966 visitor->trace(m_temporaryPlaceholder); 966 visitor->trace(m_temporaryPlaceholder);
967 CompositeEditCommand::trace(visitor); 967 CompositeEditCommand::trace(visitor);
968 } 968 }
969 969
970 } // namespace blink 970 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698