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

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

Issue 2617783002: Migrate WTF::Vector::append() to ::push_back() [part 12 of N] (Closed)
Patch Set: rebase Created 3 years, 11 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, 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 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 command->doApply(editingState); 320 command->doApply(editingState);
321 if (!editingState->isAborted()) 321 if (!editingState->isAborted())
322 m_commands.push_back(command); 322 m_commands.push_back(command);
323 } 323 }
324 324
325 void CompositeEditCommand::appendCommandToComposite( 325 void CompositeEditCommand::appendCommandToComposite(
326 CompositeEditCommand* command) { 326 CompositeEditCommand* command) {
327 ensureComposition()->append(command->ensureComposition()); 327 ensureComposition()->append(command->ensureComposition());
328 command->m_composition = nullptr; 328 command->m_composition = nullptr;
329 command->setParent(this); 329 command->setParent(this);
330 m_commands.append(command); 330 m_commands.push_back(command);
331 } 331 }
332 332
333 void CompositeEditCommand::applyStyle(const EditingStyle* style, 333 void CompositeEditCommand::applyStyle(const EditingStyle* style,
334 EditingState* editingState) { 334 EditingState* editingState) {
335 applyCommandToComposite( 335 applyCommandToComposite(
336 ApplyStyleCommand::create(document(), style, InputEvent::InputType::None), 336 ApplyStyleCommand::create(document(), style, InputEvent::InputType::None),
337 editingState); 337 editingState);
338 } 338 }
339 339
340 void CompositeEditCommand::applyStyle(const EditingStyle* style, 340 void CompositeEditCommand::applyStyle(const EditingStyle* style,
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 editingState); 469 editingState);
470 } 470 }
471 471
472 void CompositeEditCommand::removeChildrenInRange(Node* node, 472 void CompositeEditCommand::removeChildrenInRange(Node* node,
473 unsigned from, 473 unsigned from,
474 unsigned to, 474 unsigned to,
475 EditingState* editingState) { 475 EditingState* editingState) {
476 HeapVector<Member<Node>> children; 476 HeapVector<Member<Node>> children;
477 Node* child = NodeTraversal::childAt(*node, from); 477 Node* child = NodeTraversal::childAt(*node, from);
478 for (unsigned i = from; child && i < to; i++, child = child->nextSibling()) 478 for (unsigned i = from; child && i < to; i++, child = child->nextSibling())
479 children.append(child); 479 children.push_back(child);
480 480
481 size_t size = children.size(); 481 size_t size = children.size();
482 for (size_t i = 0; i < size; ++i) { 482 for (size_t i = 0; i < size; ++i) {
483 removeNode(children[i].release(), editingState); 483 removeNode(children[i].release(), editingState);
484 if (editingState->isAborted()) 484 if (editingState->isAborted())
485 return; 485 return;
486 } 486 }
487 } 487 }
488 488
489 void CompositeEditCommand::removeNode( 489 void CompositeEditCommand::removeNode(
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
521 } 521 }
522 522
523 void CompositeEditCommand::moveRemainingSiblingsToNewParent( 523 void CompositeEditCommand::moveRemainingSiblingsToNewParent(
524 Node* node, 524 Node* node,
525 Node* pastLastNodeToMove, 525 Node* pastLastNodeToMove,
526 Element* newParent, 526 Element* newParent,
527 EditingState* editingState) { 527 EditingState* editingState) {
528 NodeVector nodesToRemove; 528 NodeVector nodesToRemove;
529 529
530 for (; node && node != pastLastNodeToMove; node = node->nextSibling()) 530 for (; node && node != pastLastNodeToMove; node = node->nextSibling())
531 nodesToRemove.append(node); 531 nodesToRemove.push_back(node);
532 532
533 for (unsigned i = 0; i < nodesToRemove.size(); i++) { 533 for (unsigned i = 0; i < nodesToRemove.size(); i++) {
534 removeNode(nodesToRemove[i], editingState); 534 removeNode(nodesToRemove[i], editingState);
535 if (editingState->isAborted()) 535 if (editingState->isAborted())
536 return; 536 return;
537 appendNode(nodesToRemove[i], newParent, editingState); 537 appendNode(nodesToRemove[i], newParent, editingState);
538 if (editingState->isAborted()) 538 if (editingState->isAborted())
539 return; 539 return;
540 } 540 }
541 } 541 }
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
670 } 670 }
671 671
672 static void copyMarkerTypesAndDescriptions( 672 static void copyMarkerTypesAndDescriptions(
673 const DocumentMarkerVector& markerPointers, 673 const DocumentMarkerVector& markerPointers,
674 Vector<DocumentMarker::MarkerType>& types, 674 Vector<DocumentMarker::MarkerType>& types,
675 Vector<String>& descriptions) { 675 Vector<String>& descriptions) {
676 size_t arraySize = markerPointers.size(); 676 size_t arraySize = markerPointers.size();
677 types.reserveCapacity(arraySize); 677 types.reserveCapacity(arraySize);
678 descriptions.reserveCapacity(arraySize); 678 descriptions.reserveCapacity(arraySize);
679 for (const auto& markerPointer : markerPointers) { 679 for (const auto& markerPointer : markerPointers) {
680 types.append(markerPointer->type()); 680 types.push_back(markerPointer->type());
681 descriptions.append(markerPointer->description()); 681 descriptions.push_back(markerPointer->description());
682 } 682 }
683 } 683 }
684 684
685 void CompositeEditCommand::replaceTextInNodePreservingMarkers( 685 void CompositeEditCommand::replaceTextInNodePreservingMarkers(
686 Text* node, 686 Text* node,
687 unsigned offset, 687 unsigned offset,
688 unsigned count, 688 unsigned count,
689 const String& replacementText) { 689 const String& replacementText) {
690 DocumentMarkerController& markerController = document().markers(); 690 DocumentMarkerController& markerController = document().markers();
691 Vector<DocumentMarker::MarkerType> types; 691 Vector<DocumentMarker::MarkerType> types;
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
966 966
967 LayoutText* textLayoutObject = textNode->layoutObject(); 967 LayoutText* textLayoutObject = textNode->layoutObject();
968 if (!textLayoutObject) 968 if (!textLayoutObject)
969 return; 969 return;
970 970
971 Vector<InlineTextBox*> sortedTextBoxes; 971 Vector<InlineTextBox*> sortedTextBoxes;
972 size_t sortedTextBoxesPosition = 0; 972 size_t sortedTextBoxesPosition = 0;
973 973
974 for (InlineTextBox* textBox = textLayoutObject->firstTextBox(); textBox; 974 for (InlineTextBox* textBox = textLayoutObject->firstTextBox(); textBox;
975 textBox = textBox->nextTextBox()) 975 textBox = textBox->nextTextBox())
976 sortedTextBoxes.append(textBox); 976 sortedTextBoxes.push_back(textBox);
977 977
978 // If there is mixed directionality text, the boxes can be out of order, 978 // If there is mixed directionality text, the boxes can be out of order,
979 // (like Arabic with embedded LTR), so sort them first. 979 // (like Arabic with embedded LTR), so sort them first.
980 if (textLayoutObject->containsReversedText()) 980 if (textLayoutObject->containsReversedText())
981 std::sort(sortedTextBoxes.begin(), sortedTextBoxes.end(), 981 std::sort(sortedTextBoxes.begin(), sortedTextBoxes.end(),
982 InlineTextBox::compareByStart); 982 InlineTextBox::compareByStart);
983 InlineTextBox* box = 983 InlineTextBox* box =
984 sortedTextBoxes.isEmpty() ? 0 : sortedTextBoxes[sortedTextBoxesPosition]; 984 sortedTextBoxes.isEmpty() ? 0 : sortedTextBoxes[sortedTextBoxesPosition];
985 985
986 if (!box) { 986 if (!box) {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
1046 const Position& end) { 1046 const Position& end) {
1047 if (start.isNull() || end.isNull()) 1047 if (start.isNull() || end.isNull())
1048 return; 1048 return;
1049 1049
1050 if (comparePositions(start, end) >= 0) 1050 if (comparePositions(start, end) >= 0)
1051 return; 1051 return;
1052 1052
1053 HeapVector<Member<Text>> nodes; 1053 HeapVector<Member<Text>> nodes;
1054 for (Node& node : NodeTraversal::startsAt(*start.anchorNode())) { 1054 for (Node& node : NodeTraversal::startsAt(*start.anchorNode())) {
1055 if (node.isTextNode()) 1055 if (node.isTextNode())
1056 nodes.append(toText(&node)); 1056 nodes.push_back(toText(&node));
1057 if (&node == end.anchorNode()) 1057 if (&node == end.anchorNode())
1058 break; 1058 break;
1059 } 1059 }
1060 1060
1061 for (const auto& node : nodes) { 1061 for (const auto& node : nodes) {
1062 Text* textNode = node; 1062 Text* textNode = node;
1063 int startOffset = textNode == start.anchorNode() 1063 int startOffset = textNode == start.anchorNode()
1064 ? start.computeOffsetInContainerNode() 1064 ? start.computeOffsetInContainerNode()
1065 : 0; 1065 : 0;
1066 int endOffset = textNode == end.anchorNode() 1066 int endOffset = textNode == end.anchorNode()
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
1297 1297
1298 if (start.anchorNode() != outerNode && lastNode->isElementNode() && 1298 if (start.anchorNode() != outerNode && lastNode->isElementNode() &&
1299 start.anchorNode()->isDescendantOf(outerNode)) { 1299 start.anchorNode()->isDescendantOf(outerNode)) {
1300 HeapVector<Member<Node>> ancestors; 1300 HeapVector<Member<Node>> ancestors;
1301 1301
1302 // Insert each node from innerNode to outerNode (excluded) in a list. 1302 // Insert each node from innerNode to outerNode (excluded) in a list.
1303 for (Node& runner : 1303 for (Node& runner :
1304 NodeTraversal::inclusiveAncestorsOf(*start.anchorNode())) { 1304 NodeTraversal::inclusiveAncestorsOf(*start.anchorNode())) {
1305 if (runner == outerNode) 1305 if (runner == outerNode)
1306 break; 1306 break;
1307 ancestors.append(runner); 1307 ancestors.push_back(runner);
1308 } 1308 }
1309 1309
1310 // Clone every node between start.anchorNode() and outerBlock. 1310 // Clone every node between start.anchorNode() and outerBlock.
1311 1311
1312 for (size_t i = ancestors.size(); i != 0; --i) { 1312 for (size_t i = ancestors.size(); i != 0; --i) {
1313 Node* item = ancestors[i - 1].get(); 1313 Node* item = ancestors[i - 1].get();
1314 Node* child = item->cloneNode(isDisplayInsideTable(item)); 1314 Node* child = item->cloneNode(isDisplayInsideTable(item));
1315 appendNode(child, toElement(lastNode), editingState); 1315 appendNode(child, toElement(lastNode), editingState);
1316 if (editingState->isAborted()) 1316 if (editingState->isAborted())
1317 return; 1317 return;
(...skipping 729 matching lines...) Expand 10 before | Expand all | Expand 10 after
2047 return node; 2047 return node;
2048 } 2048 }
2049 2049
2050 DEFINE_TRACE(CompositeEditCommand) { 2050 DEFINE_TRACE(CompositeEditCommand) {
2051 visitor->trace(m_commands); 2051 visitor->trace(m_commands);
2052 visitor->trace(m_composition); 2052 visitor->trace(m_composition);
2053 EditCommand::trace(visitor); 2053 EditCommand::trace(visitor);
2054 } 2054 }
2055 2055
2056 } // namespace blink 2056 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698