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

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

Issue 436603003: Make Element::attributes() less error-prone and simplify call sites (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Keep synchronizeAllAttributes() in hasAttributes() 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2005, 2006, 2008, 2009 Apple Inc. All rights reserved. 2 * Copyright (C) 2005, 2006, 2008, 2009 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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 69
70 const HTMLSpanElement& span = toHTMLSpanElement(*node); 70 const HTMLSpanElement& span = toHTMLSpanElement(*node);
71 if (span.getAttribute(classAttr) != styleSpanClassString()) 71 if (span.getAttribute(classAttr) != styleSpanClassString())
72 return false; 72 return false;
73 UseCounter::count(span.document(), UseCounter::EditingAppleStyleSpanClass); 73 UseCounter::count(span.document(), UseCounter::EditingAppleStyleSpanClass);
74 return true; 74 return true;
75 } 75 }
76 76
77 static bool hasNoAttributeOrOnlyStyleAttribute(const HTMLElement* element, Shoul dStyleAttributeBeEmpty shouldStyleAttributeBeEmpty) 77 static bool hasNoAttributeOrOnlyStyleAttribute(const HTMLElement* element, Shoul dStyleAttributeBeEmpty shouldStyleAttributeBeEmpty)
78 { 78 {
79 if (!element->hasAttributes()) 79 AttributeCollection attributes = element->attributes();
80 if (attributes.isEmpty())
80 return true; 81 return true;
81 82
82 unsigned matchedAttributes = 0; 83 unsigned matchedAttributes = 0;
83 if (element->getAttribute(classAttr) == styleSpanClassString()) 84 if (element->getAttribute(classAttr) == styleSpanClassString())
84 matchedAttributes++; 85 matchedAttributes++;
85 if (element->hasAttribute(styleAttr) && (shouldStyleAttributeBeEmpty == Allo wNonEmptyStyleAttribute 86 if (element->hasAttribute(styleAttr) && (shouldStyleAttributeBeEmpty == Allo wNonEmptyStyleAttribute
86 || !element->inlineStyle() || element->inlineStyle()->isEmpty())) 87 || !element->inlineStyle() || element->inlineStyle()->isEmpty()))
87 matchedAttributes++; 88 matchedAttributes++;
88 89
89 ASSERT(matchedAttributes <= element->attributes().size()); 90 ASSERT(matchedAttributes <= attributes.size());
90 return matchedAttributes == element->attributes().size(); 91 return matchedAttributes == attributes.size();
91 } 92 }
92 93
93 bool isStyleSpanOrSpanWithOnlyStyleAttribute(const Element* element) 94 bool isStyleSpanOrSpanWithOnlyStyleAttribute(const Element* element)
94 { 95 {
95 if (!isHTMLSpanElement(element)) 96 if (!isHTMLSpanElement(element))
96 return false; 97 return false;
97 return hasNoAttributeOrOnlyStyleAttribute(toHTMLSpanElement(element), AllowN onEmptyStyleAttribute); 98 return hasNoAttributeOrOnlyStyleAttribute(toHTMLSpanElement(element), AllowN onEmptyStyleAttribute);
98 } 99 }
99 100
100 static inline bool isSpanWithoutAttributesOrUnstyledStyleSpan(const Node* node) 101 static inline bool isSpanWithoutAttributesOrUnstyledStyleSpan(const Node* node)
(...skipping 1470 matching lines...) Expand 10 before | Expand all | Expand 10 after
1571 void ApplyStyleCommand::trace(Visitor* visitor) 1572 void ApplyStyleCommand::trace(Visitor* visitor)
1572 { 1573 {
1573 visitor->trace(m_style); 1574 visitor->trace(m_style);
1574 visitor->trace(m_start); 1575 visitor->trace(m_start);
1575 visitor->trace(m_end); 1576 visitor->trace(m_end);
1576 visitor->trace(m_styledInlineElement); 1577 visitor->trace(m_styledInlineElement);
1577 CompositeEditCommand::trace(visitor); 1578 CompositeEditCommand::trace(visitor);
1578 } 1579 }
1579 1580
1580 } 1581 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698