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

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

Issue 1173223003: Refactoring: Remove addDisplayInline parameter of StyledMarkupAccumulator::appendElement (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: tkent's review Created 5 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 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 String content = useRenderedText ? renderedText(text) : stringValueForRa nge(text); 128 String content = useRenderedText ? renderedText(text) : stringValueForRa nge(text);
129 StringBuilder buffer; 129 StringBuilder buffer;
130 MarkupFormatter::appendCharactersReplacingEntities(buffer, content, 0, c ontent.length(), EntityMaskInPCDATA); 130 MarkupFormatter::appendCharactersReplacingEntities(buffer, content, 0, c ontent.length(), EntityMaskInPCDATA);
131 out.append(convertHTMLTextToInterchangeFormat(buffer.toString(), text)); 131 out.append(convertHTMLTextToInterchangeFormat(buffer.toString(), text));
132 } 132 }
133 133
134 if (wrappingSpan) 134 if (wrappingSpan)
135 out.append("</span>"); 135 out.append("</span>");
136 } 136 }
137 137
138 void StyledMarkupAccumulator::appendElement(Element& element, PassRefPtrWillBeRa wPtr<EditingStyle> style) 138 void StyledMarkupAccumulator::appendElement(const Element& element, PassRefPtrWi llBeRawPtr<EditingStyle> style)
139 { 139 {
140 appendElement(m_result, element, false, style); 140 if ((element.isHTMLElement() && shouldAnnotate()) || shouldApplyWrappingStyl e(element)) {
141 appendElementWithInlineStyle(m_result, element, style);
142 return;
143 }
144 appendElement(m_result, element);
141 } 145 }
142 146
143 RefPtrWillBeRawPtr<EditingStyle> StyledMarkupAccumulator::createInlineStyle(Elem ent& element) 147 RefPtrWillBeRawPtr<EditingStyle> StyledMarkupAccumulator::createInlineStyle(Elem ent& element)
144 { 148 {
145 RefPtrWillBeRawPtr<EditingStyle> inlineStyle = nullptr; 149 RefPtrWillBeRawPtr<EditingStyle> inlineStyle = nullptr;
146 150
147 if (shouldApplyWrappingStyle(element)) { 151 if (shouldApplyWrappingStyle(element)) {
148 inlineStyle = m_wrappingStyle->copy(); 152 inlineStyle = m_wrappingStyle->copy();
149 inlineStyle->removePropertiesInElementDefaultStyle(&element); 153 inlineStyle->removePropertiesInElementDefaultStyle(&element);
150 inlineStyle->removeStyleConflictingWithStyleOfElement(&element); 154 inlineStyle->removeStyleConflictingWithStyleOfElement(&element);
151 } else { 155 } else {
152 inlineStyle = EditingStyle::create(); 156 inlineStyle = EditingStyle::create();
153 } 157 }
154 158
155 if (element.isStyledElement() && element.inlineStyle()) 159 if (element.isStyledElement() && element.inlineStyle())
156 inlineStyle->overrideWithStyle(element.inlineStyle()); 160 inlineStyle->overrideWithStyle(element.inlineStyle());
157 161
158 if (element.isHTMLElement() && shouldAnnotate()) 162 if (element.isHTMLElement() && shouldAnnotate())
159 inlineStyle->mergeStyleFromRulesForSerialization(&toHTMLElement(element) ); 163 inlineStyle->mergeStyleFromRulesForSerialization(&toHTMLElement(element) );
160 164
161 return inlineStyle; 165 return inlineStyle;
162 } 166 }
163 167
164 void StyledMarkupAccumulator::appendElement(StringBuilder& out, Element& element , bool addDisplayInline, PassRefPtrWillBeRawPtr<EditingStyle> style) 168 void StyledMarkupAccumulator::appendElementWithInlineStyle(StringBuilder& out, c onst Element& element, PassRefPtrWillBeRawPtr<EditingStyle> style)
165 { 169 {
166 const bool documentIsHTML = element.document().isHTMLDocument(); 170 const bool documentIsHTML = element.document().isHTMLDocument();
167 m_formatter.appendOpenTag(out, element, nullptr); 171 m_formatter.appendOpenTag(out, element, nullptr);
168
169 const bool shouldOverrideStyleAttr = (element.isHTMLElement() && (shouldAnno tate() || addDisplayInline)) || shouldApplyWrappingStyle(element);
170
171 AttributeCollection attributes = element.attributes(); 172 AttributeCollection attributes = element.attributes();
172 for (const auto& attribute : attributes) { 173 for (const auto& attribute : attributes) {
173 // We'll handle the style attribute separately, below. 174 // We'll handle the style attribute separately, below.
174 if (attribute.name() == styleAttr && shouldOverrideStyleAttr) 175 if (attribute.name() == styleAttr)
175 continue; 176 continue;
176 m_formatter.appendAttribute(out, element, attribute, nullptr); 177 m_formatter.appendAttribute(out, element, attribute, nullptr);
177 } 178 }
178 179 if (style && !style->isEmpty()) {
179 if (shouldOverrideStyleAttr) { 180 out.appendLiteral(" style=\"");
180 if (style && !style->isEmpty()) { 181 MarkupFormatter::appendAttributeValue(out, style->style()->asText(), doc umentIsHTML);
181 out.appendLiteral(" style=\""); 182 out.append('\"');
182 MarkupFormatter::appendAttributeValue(out, style->style()->asText(), documentIsHTML);
183 out.append('\"');
184 }
185 } 183 }
186
187 m_formatter.appendCloseTag(out, element); 184 m_formatter.appendCloseTag(out, element);
188 } 185 }
189 186
187 void StyledMarkupAccumulator::appendElement(StringBuilder& out, const Element& e lement)
188 {
189 m_formatter.appendOpenTag(out, element, nullptr);
190 AttributeCollection attributes = element.attributes();
191 for (const auto& attribute : attributes)
192 m_formatter.appendAttribute(out, element, attribute, nullptr);
193 m_formatter.appendCloseTag(out, element);
194 }
195
190 void StyledMarkupAccumulator::wrapWithStyleNode(StylePropertySet* style) 196 void StyledMarkupAccumulator::wrapWithStyleNode(StylePropertySet* style)
191 { 197 {
192 // wrappingStyleForSerialization should have removed -webkit-text-decoration s-in-effect 198 // wrappingStyleForSerialization should have removed -webkit-text-decoration s-in-effect
193 ASSERT(propertyMissingOrEqualToNone(style, CSSPropertyWebkitTextDecorationsI nEffect)); 199 ASSERT(propertyMissingOrEqualToNone(style, CSSPropertyWebkitTextDecorationsI nEffect));
194 ASSERT(m_document); 200 ASSERT(m_document);
195 201
196 StringBuilder openTag; 202 StringBuilder openTag;
197 openTag.appendLiteral("<div style=\""); 203 openTag.appendLiteral("<div style=\"");
198 MarkupFormatter::appendAttributeValue(openTag, style->asText(), m_document-> isHTMLDocument()); 204 MarkupFormatter::appendAttributeValue(openTag, style->asText(), m_document-> isHTMLDocument());
199 openTag.appendLiteral("\">"); 205 openTag.appendLiteral("\">");
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 m_reversedPrecedingMarkup.append(str); 263 m_reversedPrecedingMarkup.append(str);
258 } 264 }
259 265
260 void StyledMarkupAccumulator::appendInterchangeNewline() 266 void StyledMarkupAccumulator::appendInterchangeNewline()
261 { 267 {
262 DEFINE_STATIC_LOCAL(const String, interchangeNewlineString, ("<br class=\"" AppleInterchangeNewline "\">")); 268 DEFINE_STATIC_LOCAL(const String, interchangeNewlineString, ("<br class=\"" AppleInterchangeNewline "\">"));
263 m_result.append(interchangeNewlineString); 269 m_result.append(interchangeNewlineString);
264 } 270 }
265 271
266 } // namespace blink 272 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/editing/StyledMarkupAccumulator.h ('k') | Source/core/editing/StyledMarkupSerializer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698