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

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: 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
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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 93
94 static void completeURLs(DocumentFragment& fragment, const String& baseURL) 94 static void completeURLs(DocumentFragment& fragment, const String& baseURL)
95 { 95 {
96 Vector<AttributeChange> changes; 96 Vector<AttributeChange> changes;
97 97
98 KURL parsedBaseURL(ParsedURLString, baseURL); 98 KURL parsedBaseURL(ParsedURLString, baseURL);
99 99
100 for (Element* element = ElementTraversal::firstWithin(fragment); element; el ement = ElementTraversal::next(*element, &fragment)) { 100 for (Element* element = ElementTraversal::firstWithin(fragment); element; el ement = ElementTraversal::next(*element, &fragment)) {
101 if (!element->hasAttributes()) 101 if (!element->hasAttributes())
102 continue; 102 continue;
103 unsigned length = element->attributeCount(); 103 AttributeIteratorAccessor attributes = element->attributesIterator();
104 for (unsigned i = 0; i < length; i++) { 104 AttributeConstIterator end = attributes.end();
105 const Attribute& attribute = element->attributeItem(i); 105 for (AttributeConstIterator it = attributes.begin(); it != end; ++it) {
106 if (element->isURLAttribute(attribute) && !attribute.value().isEmpty ()) 106 if (element->isURLAttribute(**it) && !it->value().isEmpty())
107 changes.append(AttributeChange(element, attribute.name(), KURL(p arsedBaseURL, attribute.value()).string())); 107 changes.append(AttributeChange(element, it->name(), KURL(parsedB aseURL, it->value()).string()));
108 } 108 }
109 } 109 }
110 110
111 size_t numChanges = changes.size(); 111 size_t numChanges = changes.size();
112 for (size_t i = 0; i < numChanges; ++i) 112 for (size_t i = 0; i < numChanges; ++i)
113 changes[i].apply(); 113 changes[i].apply();
114 } 114 }
115 115
116 class StyledMarkupAccumulator FINAL : public MarkupAccumulator { 116 class StyledMarkupAccumulator FINAL : public MarkupAccumulator {
117 public: 117 public:
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 if (node == range->startContainer()) 270 if (node == range->startContainer())
271 str.remove(0, range->startOffset()); 271 str.remove(0, range->startOffset());
272 return str; 272 return str;
273 } 273 }
274 274
275 void StyledMarkupAccumulator::appendElement(StringBuilder& out, Element& element , bool addDisplayInline, RangeFullySelectsNode rangeFullySelectsNode) 275 void StyledMarkupAccumulator::appendElement(StringBuilder& out, Element& element , bool addDisplayInline, RangeFullySelectsNode rangeFullySelectsNode)
276 { 276 {
277 const bool documentIsHTML = element.document().isHTMLDocument(); 277 const bool documentIsHTML = element.document().isHTMLDocument();
278 appendOpenTag(out, element, 0); 278 appendOpenTag(out, element, 0);
279 279
280 const unsigned length = element.hasAttributes() ? element.attributeCount() : 0;
281 const bool shouldAnnotateOrForceInline = element.isHTMLElement() && (shouldA nnotate() || addDisplayInline); 280 const bool shouldAnnotateOrForceInline = element.isHTMLElement() && (shouldA nnotate() || addDisplayInline);
282 const bool shouldOverrideStyleAttr = shouldAnnotateOrForceInline || shouldAp plyWrappingStyle(element); 281 const bool shouldOverrideStyleAttr = shouldAnnotateOrForceInline || shouldAp plyWrappingStyle(element);
283 for (unsigned i = 0; i < length; ++i) { 282
284 const Attribute& attribute = element.attributeItem(i); 283 if (element.hasAttributes()) {
285 // We'll handle the style attribute separately, below. 284 AttributeIteratorAccessor attributes = element.attributesIterator();
286 if (attribute.name() == styleAttr && shouldOverrideStyleAttr) 285 AttributeConstIterator end = attributes.end();
287 continue; 286 for (AttributeConstIterator it = attributes.begin(); it != end; ++it) {
288 appendAttribute(out, element, attribute, 0); 287 // We'll handle the style attribute separately, below.
288 if (it->name() == styleAttr && shouldOverrideStyleAttr)
289 continue;
290 appendAttribute(out, element, **it, 0);
291 }
289 } 292 }
290 293
291 if (shouldOverrideStyleAttr) { 294 if (shouldOverrideStyleAttr) {
292 RefPtr<EditingStyle> newInlineStyle; 295 RefPtr<EditingStyle> newInlineStyle;
293 296
294 if (shouldApplyWrappingStyle(element)) { 297 if (shouldApplyWrappingStyle(element)) {
295 newInlineStyle = m_wrappingStyle->copy(); 298 newInlineStyle = m_wrappingStyle->copy();
296 newInlineStyle->removePropertiesInElementDefaultStyle(&element); 299 newInlineStyle->removePropertiesInElementDefaultStyle(&element);
297 newInlineStyle->removeStyleConflictingWithStyleOfNode(&element); 300 newInlineStyle->removeStyleConflictingWithStyleOfNode(&element);
298 } else 301 } else
(...skipping 766 matching lines...) Expand 10 before | Expand all | Expand 10 after
1065 return; 1068 return;
1066 1069
1067 RefPtrWillBeRawPtr<Text> textNode = toText(node.get()); 1070 RefPtrWillBeRawPtr<Text> textNode = toText(node.get());
1068 RefPtrWillBeRawPtr<Text> textNext = toText(next); 1071 RefPtrWillBeRawPtr<Text> textNext = toText(next);
1069 textNode->appendData(textNext->data()); 1072 textNode->appendData(textNext->data());
1070 if (textNext->parentNode()) // Might have been removed by mutation event. 1073 if (textNext->parentNode()) // Might have been removed by mutation event.
1071 textNext->remove(exceptionState); 1074 textNext->remove(exceptionState);
1072 } 1075 }
1073 1076
1074 } 1077 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698