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

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

Issue 1181703003: Refactoring: Move StyledMarkupAccumulator::createInlineStyle to the serializer (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 StyledMarkupAccumulator::StyledMarkupAccumulator(EAbsoluteURLs shouldResolveURLs , const TextOffset& start, const TextOffset& end, const PassRefPtrWillBeRawPtr<D ocument> document, EAnnotateForInterchange shouldAnnotate, Node* highestNodeToBe Serialized) 54 StyledMarkupAccumulator::StyledMarkupAccumulator(EAbsoluteURLs shouldResolveURLs , const TextOffset& start, const TextOffset& end, const PassRefPtrWillBeRawPtr<D ocument> document, EAnnotateForInterchange shouldAnnotate, Node* highestNodeToBe Serialized)
55 : m_formatter(shouldResolveURLs) 55 : m_formatter(shouldResolveURLs)
56 , m_start(start) 56 , m_start(start)
57 , m_end(end) 57 , m_end(end)
58 , m_document(document) 58 , m_document(document)
59 , m_shouldAnnotate(shouldAnnotate) 59 , m_shouldAnnotate(shouldAnnotate)
60 , m_highestNodeToBeSerialized(highestNodeToBeSerialized) 60 , m_highestNodeToBeSerialized(highestNodeToBeSerialized)
61 { 61 {
62 } 62 }
63 63
64 void StyledMarkupAccumulator::appendStartTag(Node& node)
65 {
66 appendStartMarkup(node);
67 }
68
69 void StyledMarkupAccumulator::appendEndTag(const Element& element) 64 void StyledMarkupAccumulator::appendEndTag(const Element& element)
70 { 65 {
71 appendEndMarkup(m_result, element); 66 appendEndMarkup(m_result, element);
72 } 67 }
73 68
74 void StyledMarkupAccumulator::appendStartMarkup(Node& node) 69 void StyledMarkupAccumulator::appendStartMarkup(Node& node)
75 { 70 {
76 switch (node.nodeType()) { 71 m_formatter.appendStartMarkup(m_result, node, nullptr);
77 case Node::TEXT_NODE:
78 appendText(toText(node));
79 break;
80 case Node::ELEMENT_NODE: {
81 Element& element = toElement(node);
82 RefPtrWillBeRawPtr<EditingStyle> style = createInlineStyle(element);
83 appendElement(element, style);
84 break;
85 }
86 default:
87 m_formatter.appendStartMarkup(m_result, node, nullptr);
88 break;
89 }
90 } 72 }
91 73
92 void StyledMarkupAccumulator::appendEndMarkup(StringBuilder& result, const Eleme nt& element) 74 void StyledMarkupAccumulator::appendEndMarkup(StringBuilder& result, const Eleme nt& element)
93 { 75 {
94 m_formatter.appendEndMarkup(result, element); 76 m_formatter.appendEndMarkup(result, element);
95 } 77 }
96 78
97 void StyledMarkupAccumulator::appendText(Text& text) 79 void StyledMarkupAccumulator::appendText(Text& text)
98 { 80 {
99 if (text.parentElement() && text.parentElement()->tagQName() == textareaTag) { 81 if (text.parentElement() && text.parentElement()->tagQName() == textareaTag) {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 139
158 void StyledMarkupAccumulator::appendElement(const Element& element, PassRefPtrWi llBeRawPtr<EditingStyle> style) 140 void StyledMarkupAccumulator::appendElement(const Element& element, PassRefPtrWi llBeRawPtr<EditingStyle> style)
159 { 141 {
160 if ((element.isHTMLElement() && shouldAnnotate()) || shouldApplyWrappingStyl e(element)) { 142 if ((element.isHTMLElement() && shouldAnnotate()) || shouldApplyWrappingStyl e(element)) {
161 appendElementWithInlineStyle(m_result, element, style); 143 appendElementWithInlineStyle(m_result, element, style);
162 return; 144 return;
163 } 145 }
164 appendElement(m_result, element); 146 appendElement(m_result, element);
165 } 147 }
166 148
167 RefPtrWillBeRawPtr<EditingStyle> StyledMarkupAccumulator::createInlineStyle(Elem ent& element)
168 {
169 RefPtrWillBeRawPtr<EditingStyle> inlineStyle = nullptr;
170
171 if (shouldApplyWrappingStyle(element)) {
172 inlineStyle = m_wrappingStyle->copy();
173 inlineStyle->removePropertiesInElementDefaultStyle(&element);
174 inlineStyle->removeStyleConflictingWithStyleOfElement(&element);
175 } else {
176 inlineStyle = EditingStyle::create();
177 }
178
179 if (element.isStyledElement() && element.inlineStyle())
180 inlineStyle->overrideWithStyle(element.inlineStyle());
181
182 if (element.isHTMLElement() && shouldAnnotate())
183 inlineStyle->mergeStyleFromRulesForSerialization(&toHTMLElement(element) );
184
185 return inlineStyle;
186 }
187
188 void StyledMarkupAccumulator::appendElementWithInlineStyle(StringBuilder& out, c onst Element& element, PassRefPtrWillBeRawPtr<EditingStyle> style) 149 void StyledMarkupAccumulator::appendElementWithInlineStyle(StringBuilder& out, c onst Element& element, PassRefPtrWillBeRawPtr<EditingStyle> style)
189 { 150 {
190 const bool documentIsHTML = element.document().isHTMLDocument(); 151 const bool documentIsHTML = element.document().isHTMLDocument();
191 m_formatter.appendOpenTag(out, element, nullptr); 152 m_formatter.appendOpenTag(out, element, nullptr);
192 AttributeCollection attributes = element.attributes(); 153 AttributeCollection attributes = element.attributes();
193 for (const auto& attribute : attributes) { 154 for (const auto& attribute : attributes) {
194 // We'll handle the style attribute separately, below. 155 // We'll handle the style attribute separately, below.
195 if (attribute.name() == styleAttr) 156 if (attribute.name() == styleAttr)
196 continue; 157 continue;
197 m_formatter.appendAttribute(out, element, attribute, nullptr); 158 m_formatter.appendAttribute(out, element, attribute, nullptr);
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 m_reversedPrecedingMarkup.append(str); 244 m_reversedPrecedingMarkup.append(str);
284 } 245 }
285 246
286 void StyledMarkupAccumulator::appendInterchangeNewline() 247 void StyledMarkupAccumulator::appendInterchangeNewline()
287 { 248 {
288 DEFINE_STATIC_LOCAL(const String, interchangeNewlineString, ("<br class=\"" AppleInterchangeNewline "\">")); 249 DEFINE_STATIC_LOCAL(const String, interchangeNewlineString, ("<br class=\"" AppleInterchangeNewline "\">"));
289 m_result.append(interchangeNewlineString); 250 m_result.append(interchangeNewlineString);
290 } 251 }
291 252
292 } // namespace blink 253 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698