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

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

Issue 298253009: Add iterator object to iterate efficiently over an Element's attributes (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase Created 6 years, 6 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/MarkupAccumulator.cpp ('k') | Source/core/html/HTMLEmbedElement.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) 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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 105
106 static void completeURLs(DocumentFragment& fragment, const String& baseURL) 106 static void completeURLs(DocumentFragment& fragment, const String& baseURL)
107 { 107 {
108 WillBeHeapVector<AttributeChange> changes; 108 WillBeHeapVector<AttributeChange> changes;
109 109
110 KURL parsedBaseURL(ParsedURLString, baseURL); 110 KURL parsedBaseURL(ParsedURLString, baseURL);
111 111
112 for (Element* element = ElementTraversal::firstWithin(fragment); element; el ement = ElementTraversal::next(*element, &fragment)) { 112 for (Element* element = ElementTraversal::firstWithin(fragment); element; el ement = ElementTraversal::next(*element, &fragment)) {
113 if (!element->hasAttributes()) 113 if (!element->hasAttributes())
114 continue; 114 continue;
115 unsigned length = element->attributeCount(); 115 AttributeIteratorAccessor attributes = element->attributesIterator();
116 for (unsigned i = 0; i < length; i++) { 116 AttributeConstIterator end = attributes.end();
117 const Attribute& attribute = element->attributeItem(i); 117 for (AttributeConstIterator it = attributes.begin(); it != end; ++it) {
118 if (element->isURLAttribute(attribute) && !attribute.value().isEmpty ()) 118 if (element->isURLAttribute(**it) && !it->value().isEmpty())
119 changes.append(AttributeChange(element, attribute.name(), KURL(p arsedBaseURL, attribute.value()).string())); 119 changes.append(AttributeChange(element, it->name(), KURL(parsedB aseURL, it->value()).string()));
120 } 120 }
121 } 121 }
122 122
123 size_t numChanges = changes.size(); 123 size_t numChanges = changes.size();
124 for (size_t i = 0; i < numChanges; ++i) 124 for (size_t i = 0; i < numChanges; ++i)
125 changes[i].apply(); 125 changes[i].apply();
126 } 126 }
127 127
128 class StyledMarkupAccumulator FINAL : public MarkupAccumulator { 128 class StyledMarkupAccumulator FINAL : public MarkupAccumulator {
129 public: 129 public:
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 if (node == range->startContainer()) 281 if (node == range->startContainer())
282 str.remove(0, range->startOffset()); 282 str.remove(0, range->startOffset());
283 return str; 283 return str;
284 } 284 }
285 285
286 void StyledMarkupAccumulator::appendElement(StringBuilder& out, Element& element , bool addDisplayInline, RangeFullySelectsNode rangeFullySelectsNode) 286 void StyledMarkupAccumulator::appendElement(StringBuilder& out, Element& element , bool addDisplayInline, RangeFullySelectsNode rangeFullySelectsNode)
287 { 287 {
288 const bool documentIsHTML = element.document().isHTMLDocument(); 288 const bool documentIsHTML = element.document().isHTMLDocument();
289 appendOpenTag(out, element, 0); 289 appendOpenTag(out, element, 0);
290 290
291 const unsigned length = element.hasAttributes() ? element.attributeCount() : 0;
292 const bool shouldAnnotateOrForceInline = element.isHTMLElement() && (shouldA nnotate() || addDisplayInline); 291 const bool shouldAnnotateOrForceInline = element.isHTMLElement() && (shouldA nnotate() || addDisplayInline);
293 const bool shouldOverrideStyleAttr = shouldAnnotateOrForceInline || shouldAp plyWrappingStyle(element); 292 const bool shouldOverrideStyleAttr = shouldAnnotateOrForceInline || shouldAp plyWrappingStyle(element);
294 for (unsigned i = 0; i < length; ++i) { 293
295 const Attribute& attribute = element.attributeItem(i); 294 if (element.hasAttributes()) {
296 // We'll handle the style attribute separately, below. 295 AttributeIteratorAccessor attributes = element.attributesIterator();
297 if (attribute.name() == styleAttr && shouldOverrideStyleAttr) 296 AttributeConstIterator end = attributes.end();
298 continue; 297 for (AttributeConstIterator it = attributes.begin(); it != end; ++it) {
299 appendAttribute(out, element, attribute, 0); 298 // We'll handle the style attribute separately, below.
299 if (it->name() == styleAttr && shouldOverrideStyleAttr)
300 continue;
301 appendAttribute(out, element, **it, 0);
302 }
300 } 303 }
301 304
302 if (shouldOverrideStyleAttr) { 305 if (shouldOverrideStyleAttr) {
303 RefPtrWillBeRawPtr<EditingStyle> newInlineStyle = nullptr; 306 RefPtrWillBeRawPtr<EditingStyle> newInlineStyle = nullptr;
304 307
305 if (shouldApplyWrappingStyle(element)) { 308 if (shouldApplyWrappingStyle(element)) {
306 newInlineStyle = m_wrappingStyle->copy(); 309 newInlineStyle = m_wrappingStyle->copy();
307 newInlineStyle->removePropertiesInElementDefaultStyle(&element); 310 newInlineStyle->removePropertiesInElementDefaultStyle(&element);
308 newInlineStyle->removeStyleConflictingWithStyleOfNode(&element); 311 newInlineStyle->removeStyleConflictingWithStyleOfNode(&element);
309 } else 312 } else
(...skipping 766 matching lines...) Expand 10 before | Expand all | Expand 10 after
1076 return; 1079 return;
1077 1080
1078 RefPtrWillBeRawPtr<Text> textNode = toText(node.get()); 1081 RefPtrWillBeRawPtr<Text> textNode = toText(node.get());
1079 RefPtrWillBeRawPtr<Text> textNext = toText(next); 1082 RefPtrWillBeRawPtr<Text> textNext = toText(next);
1080 textNode->appendData(textNext->data()); 1083 textNode->appendData(textNext->data());
1081 if (textNext->parentNode()) // Might have been removed by mutation event. 1084 if (textNext->parentNode()) // Might have been removed by mutation event.
1082 textNext->remove(exceptionState); 1085 textNext->remove(exceptionState);
1083 } 1086 }
1084 1087
1085 } 1088 }
OLDNEW
« no previous file with comments | « Source/core/editing/MarkupAccumulator.cpp ('k') | Source/core/html/HTMLEmbedElement.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698