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

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

Issue 67473002: Have ElementTraversal / NodeTraversal's next() methods take a reference (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebase on master Created 7 years, 1 month 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 | « Source/core/editing/htmlediting.cpp ('k') | Source/core/html/FormAssociatedElement.h » ('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) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserv ed. 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserv ed.
3 * Copyright (C) 2008, 2009, 2010, 2011 Google Inc. All rights reserved. 3 * Copyright (C) 2008, 2009, 2010, 2011 Google Inc. All rights reserved.
4 * Copyright (C) 2011 Igalia S.L. 4 * Copyright (C) 2011 Igalia S.L.
5 * Copyright (C) 2011 Motorola Mobility. All rights reserved. 5 * Copyright (C) 2011 Motorola Mobility. All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 QualifiedName m_name; 92 QualifiedName m_name;
93 String m_value; 93 String m_value;
94 }; 94 };
95 95
96 static void completeURLs(DocumentFragment* fragment, const String& baseURL) 96 static void completeURLs(DocumentFragment* fragment, const String& baseURL)
97 { 97 {
98 Vector<AttributeChange> changes; 98 Vector<AttributeChange> changes;
99 99
100 KURL parsedBaseURL(ParsedURLString, baseURL); 100 KURL parsedBaseURL(ParsedURLString, baseURL);
101 101
102 for (Element* element = ElementTraversal::firstWithin(fragment); element; el ement = ElementTraversal::next(element, fragment)) { 102 for (Element* element = ElementTraversal::firstWithin(fragment); element; el ement = ElementTraversal::next(*element, fragment)) {
103 if (!element->hasAttributes()) 103 if (!element->hasAttributes())
104 continue; 104 continue;
105 unsigned length = element->attributeCount(); 105 unsigned length = element->attributeCount();
106 for (unsigned i = 0; i < length; i++) { 106 for (unsigned i = 0; i < length; i++) {
107 const Attribute* attribute = element->attributeItem(i); 107 const Attribute* attribute = element->attributeItem(i);
108 if (element->isURLAttribute(*attribute) && !attribute->value().isEmp ty()) 108 if (element->isURLAttribute(*attribute) && !attribute->value().isEmp ty())
109 changes.append(AttributeChange(element, attribute->name(), KURL( parsedBaseURL, attribute->value()).string())); 109 changes.append(AttributeChange(element, attribute->name(), KURL( parsedBaseURL, attribute->value()).string()));
110 } 110 }
111 } 111 }
112 112
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 Node* lastClosed = 0; 348 Node* lastClosed = 0;
349 for (Node* n = startNode; n != pastEnd; n = next) { 349 for (Node* n = startNode; n != pastEnd; n = next) {
350 // According to <rdar://problem/5730668>, it is possible for n to blow 350 // According to <rdar://problem/5730668>, it is possible for n to blow
351 // past pastEnd and become null here. This shouldn't be possible. 351 // past pastEnd and become null here. This shouldn't be possible.
352 // This null check will prevent crashes (but create too much markup) 352 // This null check will prevent crashes (but create too much markup)
353 // and the ASSERT will hopefully lead us to understanding the problem. 353 // and the ASSERT will hopefully lead us to understanding the problem.
354 ASSERT(n); 354 ASSERT(n);
355 if (!n) 355 if (!n)
356 break; 356 break;
357 357
358 next = NodeTraversal::next(n); 358 next = NodeTraversal::next(*n);
359 bool openedTag = false; 359 bool openedTag = false;
360 360
361 if (isBlock(n) && canHaveChildrenForEditing(n) && next == pastEnd) 361 if (isBlock(n) && canHaveChildrenForEditing(n) && next == pastEnd)
362 // Don't write out empty block containers that aren't fully selected . 362 // Don't write out empty block containers that aren't fully selected .
363 continue; 363 continue;
364 364
365 if (!n->renderer() && !enclosingNodeWithTag(firstPositionInOrBeforeNode( n), selectTag)) { 365 if (!n->renderer() && !enclosingNodeWithTag(firstPositionInOrBeforeNode( n), selectTag)) {
366 next = NodeTraversal::nextSkippingChildren(n); 366 next = NodeTraversal::nextSkippingChildren(n);
367 // Don't skip over pastEnd. 367 // Don't skip over pastEnd.
368 if (pastEnd && pastEnd->isDescendantOf(n)) 368 if (pastEnd && pastEnd->isDescendantOf(n))
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
650 if (!baseURL.isEmpty() && baseURL != blankURL() && baseURL != document.baseU RL()) 650 if (!baseURL.isEmpty() && baseURL != blankURL() && baseURL != document.baseU RL())
651 completeURLs(fragment.get(), baseURL); 651 completeURLs(fragment.get(), baseURL);
652 652
653 return fragment.release(); 653 return fragment.release();
654 } 654 }
655 655
656 static const char fragmentMarkerTag[] = "webkit-fragment-marker"; 656 static const char fragmentMarkerTag[] = "webkit-fragment-marker";
657 657
658 static bool findNodesSurroundingContext(Document* document, RefPtr<Node>& nodeBe foreContext, RefPtr<Node>& nodeAfterContext) 658 static bool findNodesSurroundingContext(Document* document, RefPtr<Node>& nodeBe foreContext, RefPtr<Node>& nodeAfterContext)
659 { 659 {
660 for (Node* node = document->firstChild(); node; node = NodeTraversal::next(n ode)) { 660 for (Node* node = document->firstChild(); node; node = NodeTraversal::next(* node)) {
661 if (node->nodeType() == Node::COMMENT_NODE && toCharacterData(node)->dat a() == fragmentMarkerTag) { 661 if (node->nodeType() == Node::COMMENT_NODE && toCharacterData(node)->dat a() == fragmentMarkerTag) {
662 if (!nodeBeforeContext) 662 if (!nodeBeforeContext)
663 nodeBeforeContext = node; 663 nodeBeforeContext = node;
664 else { 664 else {
665 nodeAfterContext = node; 665 nodeAfterContext = node;
666 return true; 666 return true;
667 } 667 }
668 } 668 }
669 } 669 }
670 return false; 670 return false;
671 } 671 }
672 672
673 static void trimFragment(DocumentFragment* fragment, Node* nodeBeforeContext, No de* nodeAfterContext) 673 static void trimFragment(DocumentFragment* fragment, Node* nodeBeforeContext, No de* nodeAfterContext)
674 { 674 {
675 RefPtr<Node> next; 675 RefPtr<Node> next;
676 for (RefPtr<Node> node = fragment->firstChild(); node; node = next) { 676 for (RefPtr<Node> node = fragment->firstChild(); node; node = next) {
677 if (nodeBeforeContext->isDescendantOf(node.get())) { 677 if (nodeBeforeContext->isDescendantOf(node.get())) {
678 next = NodeTraversal::next(node.get()); 678 next = NodeTraversal::next(*node);
679 continue; 679 continue;
680 } 680 }
681 next = NodeTraversal::nextSkippingChildren(node.get()); 681 next = NodeTraversal::nextSkippingChildren(node.get());
682 ASSERT(!node->contains(nodeAfterContext)); 682 ASSERT(!node->contains(nodeAfterContext));
683 node->parentNode()->removeChild(node.get(), ASSERT_NO_EXCEPTION); 683 node->parentNode()->removeChild(node.get(), ASSERT_NO_EXCEPTION);
684 if (nodeBeforeContext == node) 684 if (nodeBeforeContext == node)
685 break; 685 break;
686 } 686 }
687 687
688 ASSERT(nodeAfterContext->parentNode()); 688 ASSERT(nodeAfterContext->parentNode());
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after
1083 return; 1083 return;
1084 1084
1085 RefPtr<Text> textNode = toText(node.get()); 1085 RefPtr<Text> textNode = toText(node.get());
1086 RefPtr<Text> textNext = toText(next); 1086 RefPtr<Text> textNext = toText(next);
1087 textNode->appendData(textNext->data()); 1087 textNode->appendData(textNext->data());
1088 if (textNext->parentNode()) // Might have been removed by mutation event. 1088 if (textNext->parentNode()) // Might have been removed by mutation event.
1089 textNext->remove(es); 1089 textNext->remove(es);
1090 } 1090 }
1091 1091
1092 } 1092 }
OLDNEW
« no previous file with comments | « Source/core/editing/htmlediting.cpp ('k') | Source/core/html/FormAssociatedElement.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698