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

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

Issue 420053002: Use tighter typing in editing: DeleteSelectionCommand (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase Created 6 years, 4 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/DeleteSelectionCommand.h ('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 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 20 matching lines...) Expand all
31 #include "core/dom/Element.h" 31 #include "core/dom/Element.h"
32 #include "core/dom/NodeTraversal.h" 32 #include "core/dom/NodeTraversal.h"
33 #include "core/dom/Text.h" 33 #include "core/dom/Text.h"
34 #include "core/editing/EditingBoundary.h" 34 #include "core/editing/EditingBoundary.h"
35 #include "core/editing/Editor.h" 35 #include "core/editing/Editor.h"
36 #include "core/editing/VisibleUnits.h" 36 #include "core/editing/VisibleUnits.h"
37 #include "core/editing/htmlediting.h" 37 #include "core/editing/htmlediting.h"
38 #include "core/frame/LocalFrame.h" 38 #include "core/frame/LocalFrame.h"
39 #include "core/html/HTMLBRElement.h" 39 #include "core/html/HTMLBRElement.h"
40 #include "core/html/HTMLInputElement.h" 40 #include "core/html/HTMLInputElement.h"
41 #include "core/html/HTMLStyleElement.h"
42 #include "core/html/HTMLTableRowElement.h"
41 #include "core/rendering/RenderTableCell.h" 43 #include "core/rendering/RenderTableCell.h"
42 #include "core/rendering/RenderText.h" 44 #include "core/rendering/RenderText.h"
43 45
44 namespace blink { 46 namespace blink {
45 47
46 using namespace HTMLNames; 48 using namespace HTMLNames;
47 49
48 static bool isTableCellEmpty(Node* cell) 50 static bool isTableCellEmpty(Node* cell)
49 { 51 {
50 ASSERT(isTableCell(cell)); 52 ASSERT(isTableCell(cell));
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 end = lastEditablePositionBeforePositionInRoot(end, highestEditableRoot( start)); 173 end = lastEditablePositionBeforePositionInRoot(end, highestEditableRoot( start));
172 174
173 m_upstreamStart = start.upstream(); 175 m_upstreamStart = start.upstream();
174 m_downstreamStart = start.downstream(); 176 m_downstreamStart = start.downstream();
175 m_upstreamEnd = end.upstream(); 177 m_upstreamEnd = end.upstream();
176 m_downstreamEnd = end.downstream(); 178 m_downstreamEnd = end.downstream();
177 179
178 m_startRoot = editableRootForPosition(start); 180 m_startRoot = editableRootForPosition(start);
179 m_endRoot = editableRootForPosition(end); 181 m_endRoot = editableRootForPosition(end);
180 182
181 m_startTableRow = enclosingNodeOfType(start, &isHTMLTableRowElement); 183 m_startTableRow = toHTMLTableRowElement(enclosingNodeOfType(start, &isHTMLTa bleRowElement));
182 m_endTableRow = enclosingNodeOfType(end, &isHTMLTableRowElement); 184 m_endTableRow = toHTMLTableRowElement(enclosingNodeOfType(end, &isHTMLTableR owElement));
183 185
184 // Don't move content out of a table cell. 186 // Don't move content out of a table cell.
185 // If the cell is non-editable, enclosingNodeOfType won't return it by defau lt, so 187 // If the cell is non-editable, enclosingNodeOfType won't return it by defau lt, so
186 // tell that function that we don't care if it returns non-editable nodes. 188 // tell that function that we don't care if it returns non-editable nodes.
187 Node* startCell = enclosingNodeOfType(m_upstreamStart, &isTableCell, CanCros sEditingBoundary); 189 Node* startCell = enclosingNodeOfType(m_upstreamStart, &isTableCell, CanCros sEditingBoundary);
188 Node* endCell = enclosingNodeOfType(m_downstreamEnd, &isTableCell, CanCrossE ditingBoundary); 190 Node* endCell = enclosingNodeOfType(m_downstreamEnd, &isTableCell, CanCrossE ditingBoundary);
189 // FIXME: This isn't right. A borderless table with two rows and a single c olumn would appear as two paragraphs. 191 // FIXME: This isn't right. A borderless table with two rows and a single c olumn would appear as two paragraphs.
190 if (endCell && endCell != startCell) 192 if (endCell && endCell != startCell)
191 m_mergeBlocksAfterDelete = false; 193 m_mergeBlocksAfterDelete = false;
192 194
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 } 395 }
394 396
395 // FIXME: Update the endpoints of the range being deleted. 397 // FIXME: Update the endpoints of the range being deleted.
396 updatePositionForNodeRemoval(m_endingPosition, *node); 398 updatePositionForNodeRemoval(m_endingPosition, *node);
397 updatePositionForNodeRemoval(m_leadingWhitespace, *node); 399 updatePositionForNodeRemoval(m_leadingWhitespace, *node);
398 updatePositionForNodeRemoval(m_trailingWhitespace, *node); 400 updatePositionForNodeRemoval(m_trailingWhitespace, *node);
399 401
400 CompositeEditCommand::removeNode(node, shouldAssumeContentIsAlwaysEditable); 402 CompositeEditCommand::removeNode(node, shouldAssumeContentIsAlwaysEditable);
401 } 403 }
402 404
403 static void updatePositionForTextRemoval(Node* node, int offset, int count, Posi tion& position) 405 static void updatePositionForTextRemoval(Text* node, int offset, int count, Posi tion& position)
404 { 406 {
405 if (position.anchorType() != Position::PositionIsOffsetInAnchor || position. containerNode() != node) 407 if (position.anchorType() != Position::PositionIsOffsetInAnchor || position. containerNode() != node)
406 return; 408 return;
407 409
408 if (position.offsetInContainerNode() > offset + count) 410 if (position.offsetInContainerNode() > offset + count)
409 position.moveToOffset(position.offsetInContainerNode() - count); 411 position.moveToOffset(position.offsetInContainerNode() - count);
410 else if (position.offsetInContainerNode() > offset) 412 else if (position.offsetInContainerNode() > offset)
411 position.moveToOffset(offset); 413 position.moveToOffset(offset);
412 } 414 }
413 415
414 void DeleteSelectionCommand::deleteTextFromNode(PassRefPtrWillBeRawPtr<Text> nod e, unsigned offset, unsigned count) 416 void DeleteSelectionCommand::deleteTextFromNode(PassRefPtrWillBeRawPtr<Text> nod e, unsigned offset, unsigned count)
415 { 417 {
416 // FIXME: Update the endpoints of the range being deleted. 418 // FIXME: Update the endpoints of the range being deleted.
417 updatePositionForTextRemoval(node.get(), offset, count, m_endingPosition); 419 updatePositionForTextRemoval(node.get(), offset, count, m_endingPosition);
418 updatePositionForTextRemoval(node.get(), offset, count, m_leadingWhitespace) ; 420 updatePositionForTextRemoval(node.get(), offset, count, m_leadingWhitespace) ;
419 updatePositionForTextRemoval(node.get(), offset, count, m_trailingWhitespace ); 421 updatePositionForTextRemoval(node.get(), offset, count, m_trailingWhitespace );
420 updatePositionForTextRemoval(node.get(), offset, count, m_downstreamEnd); 422 updatePositionForTextRemoval(node.get(), offset, count, m_downstreamEnd);
421 423
422 CompositeEditCommand::deleteTextFromNode(node, offset, count); 424 CompositeEditCommand::deleteTextFromNode(node, offset, count);
423 } 425 }
424 426
425 void DeleteSelectionCommand::makeStylingElementsDirectChildrenOfEditableRootToPr eventStyleLoss() 427 void DeleteSelectionCommand::makeStylingElementsDirectChildrenOfEditableRootToPr eventStyleLoss()
426 { 428 {
427 RefPtrWillBeRawPtr<Range> range = m_selectionToDelete.toNormalizedRange(); 429 RefPtrWillBeRawPtr<Range> range = m_selectionToDelete.toNormalizedRange();
428 RefPtrWillBeRawPtr<Node> node = range->firstNode(); 430 RefPtrWillBeRawPtr<Node> node = range->firstNode();
429 while (node && node != range->pastLastNode()) { 431 while (node && node != range->pastLastNode()) {
430 RefPtrWillBeRawPtr<Node> nextNode = NodeTraversal::next(*node); 432 RefPtrWillBeRawPtr<Node> nextNode = NodeTraversal::next(*node);
431 if ((isHTMLStyleElement(*node) && !(toElement(node)->hasAttribute(scoped Attr))) || isHTMLLinkElement(*node)) { 433 if ((isHTMLStyleElement(*node) && !toHTMLStyleElement(node)->hasAttribut e(scopedAttr))
434 || isHTMLLinkElement(*node)) {
432 nextNode = NodeTraversal::nextSkippingChildren(*node); 435 nextNode = NodeTraversal::nextSkippingChildren(*node);
433 RefPtrWillBeRawPtr<ContainerNode> rootEditableElement = node->rootEd itableElement(); 436 RefPtrWillBeRawPtr<Element> rootEditableElement = node->rootEditable Element();
434 if (rootEditableElement.get()) { 437 if (rootEditableElement.get()) {
435 removeNode(node); 438 removeNode(node);
436 appendNode(node, rootEditableElement); 439 appendNode(node, rootEditableElement);
437 } 440 }
438 } 441 }
439 node = nextNode; 442 node = nextNode;
440 } 443 }
441 } 444 }
442 445
443 void DeleteSelectionCommand::handleGeneralDelete() 446 void DeleteSelectionCommand::handleGeneralDelete()
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
751 m_downstreamEnd.clear(); 754 m_downstreamEnd.clear();
752 m_endingPosition.clear(); 755 m_endingPosition.clear();
753 m_leadingWhitespace.clear(); 756 m_leadingWhitespace.clear();
754 m_trailingWhitespace.clear(); 757 m_trailingWhitespace.clear();
755 } 758 }
756 759
757 // This method removes div elements with no attributes that have only one child or no children at all. 760 // This method removes div elements with no attributes that have only one child or no children at all.
758 void DeleteSelectionCommand::removeRedundantBlocks() 761 void DeleteSelectionCommand::removeRedundantBlocks()
759 { 762 {
760 Node* node = m_endingPosition.containerNode(); 763 Node* node = m_endingPosition.containerNode();
761 Node* rootNode = node->rootEditableElement(); 764 Element* rootElement = node->rootEditableElement();
762 765
763 while (node != rootNode) { 766 while (node != rootElement) {
764 if (isRemovableBlock(node)) { 767 if (isRemovableBlock(node)) {
765 if (node == m_endingPosition.anchorNode()) 768 if (node == m_endingPosition.anchorNode())
766 updatePositionForNodeRemovalPreservingChildren(m_endingPosition, *node); 769 updatePositionForNodeRemovalPreservingChildren(m_endingPosition, *node);
767 770
768 CompositeEditCommand::removeNodePreservingChildren(node); 771 CompositeEditCommand::removeNodePreservingChildren(node);
769 node = m_endingPosition.anchorNode(); 772 node = m_endingPosition.anchorNode();
770 } else 773 } else
771 node = node->parentNode(); 774 node = node->parentNode();
772 } 775 }
773 } 776 }
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
886 visitor->trace(m_deleteIntoBlockquoteStyle); 889 visitor->trace(m_deleteIntoBlockquoteStyle);
887 visitor->trace(m_startRoot); 890 visitor->trace(m_startRoot);
888 visitor->trace(m_endRoot); 891 visitor->trace(m_endRoot);
889 visitor->trace(m_startTableRow); 892 visitor->trace(m_startTableRow);
890 visitor->trace(m_endTableRow); 893 visitor->trace(m_endTableRow);
891 visitor->trace(m_temporaryPlaceholder); 894 visitor->trace(m_temporaryPlaceholder);
892 CompositeEditCommand::trace(visitor); 895 CompositeEditCommand::trace(visitor);
893 } 896 }
894 897
895 } // namespace blink 898 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/editing/DeleteSelectionCommand.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698