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

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

Issue 1164253002: Refactoring: Remove boolean paramters from StyledMarkupAccumulator (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 19 matching lines...) Expand all
30 #include "core/editing/StyledMarkupAccumulator.h" 30 #include "core/editing/StyledMarkupAccumulator.h"
31 31
32 #include "core/css/StylePropertySet.h" 32 #include "core/css/StylePropertySet.h"
33 #include "core/dom/Text.h" 33 #include "core/dom/Text.h"
34 #include "core/editing/htmlediting.h" 34 #include "core/editing/htmlediting.h"
35 #include "core/editing/iterators/TextIterator.h" 35 #include "core/editing/iterators/TextIterator.h"
36 #include "wtf/text/StringBuilder.h" 36 #include "wtf/text/StringBuilder.h"
37 37
38 namespace blink { 38 namespace blink {
39 39
40 namespace { 40 namespace {
tkent 2015/06/08 07:49:56 Remove this namespace block.
hajimehoshi 2015/06/08 07:56:55 Done.
41 41
42 const String& styleNodeCloseTag(bool isBlock)
43 {
44 DEFINE_STATIC_LOCAL(const String, divClose, ("</div>"));
45 DEFINE_STATIC_LOCAL(const String, styleSpanClose, ("</span>"));
46 return isBlock ? divClose : styleSpanClose;
47 }
48
49 } // namespace 42 } // namespace
50 43
51 using namespace HTMLNames; 44 using namespace HTMLNames;
52 45
53 StyledMarkupAccumulator::StyledMarkupAccumulator(EAbsoluteURLs shouldResolveURLs , const TextOffset& start, const TextOffset& end, const PassRefPtrWillBeRawPtr<D ocument> document, EAnnotateForInterchange shouldAnnotate, Node* highestNodeToBe Serialized, ConvertBlocksToInlines convertBlocksToInlines) 46 StyledMarkupAccumulator::StyledMarkupAccumulator(EAbsoluteURLs shouldResolveURLs , const TextOffset& start, const TextOffset& end, const PassRefPtrWillBeRawPtr<D ocument> document, EAnnotateForInterchange shouldAnnotate, Node* highestNodeToBe Serialized, ConvertBlocksToInlines convertBlocksToInlines)
54 : m_formatter(shouldResolveURLs) 47 : m_formatter(shouldResolveURLs)
55 , m_start(start) 48 , m_start(start)
56 , m_end(end) 49 , m_end(end)
57 , m_document(document) 50 , m_document(document)
58 , m_shouldAnnotate(shouldAnnotate) 51 , m_shouldAnnotate(shouldAnnotate)
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 const bool parentIsTextarea = text.parentElement() && text.parentElement()-> tagQName() == textareaTag; 94 const bool parentIsTextarea = text.parentElement() && text.parentElement()-> tagQName() == textareaTag;
102 const bool wrappingSpan = shouldApplyWrappingStyle(text) && !parentIsTextare a; 95 const bool wrappingSpan = shouldApplyWrappingStyle(text) && !parentIsTextare a;
103 if (wrappingSpan) { 96 if (wrappingSpan) {
104 RefPtrWillBeRawPtr<EditingStyle> wrappingStyle = m_wrappingStyle->copy() ; 97 RefPtrWillBeRawPtr<EditingStyle> wrappingStyle = m_wrappingStyle->copy() ;
105 // FIXME: <rdar://problem/5371536> Style rules that match pasted content can change it's appearance 98 // FIXME: <rdar://problem/5371536> Style rules that match pasted content can change it's appearance
106 // Make sure spans are inline style in paste side e.g. span { display: b lock }. 99 // Make sure spans are inline style in paste side e.g. span { display: b lock }.
107 wrappingStyle->forceInline(); 100 wrappingStyle->forceInline();
108 // FIXME: Should this be included in forceInline? 101 // FIXME: Should this be included in forceInline?
109 wrappingStyle->style()->setProperty(CSSPropertyFloat, CSSValueNone); 102 wrappingStyle->style()->setProperty(CSSPropertyFloat, CSSValueNone);
110 103
111 appendStyleNodeOpenTag(out, wrappingStyle->style()); 104 out.appendLiteral("<span style=\"");
105 MarkupFormatter::appendAttributeValue(out, wrappingStyle->style()->asTex t(), m_document->isHTMLDocument());
106 out.appendLiteral("\">");
112 } 107 }
113 108
114 if (!shouldAnnotate() || parentIsTextarea) { 109 if (!shouldAnnotate() || parentIsTextarea) {
115 const String& str = text.data(); 110 const String& str = text.data();
116 unsigned length = str.length(); 111 unsigned length = str.length();
117 unsigned start = 0; 112 unsigned start = 0;
118 if (m_end.isNotNull()) { 113 if (m_end.isNotNull()) {
119 if (text == m_end.text()) 114 if (text == m_end.text())
120 length = m_end.offset(); 115 length = m_end.offset();
121 } 116 }
122 if (m_start.isNotNull()) { 117 if (m_start.isNotNull()) {
123 if (text == m_start.text()) { 118 if (text == m_start.text()) {
124 start = m_start.offset(); 119 start = m_start.offset();
125 length -= start; 120 length -= start;
126 } 121 }
127 } 122 }
128 MarkupFormatter::appendCharactersReplacingEntities(out, str, start, leng th, m_formatter.entityMaskForText(text)); 123 MarkupFormatter::appendCharactersReplacingEntities(out, str, start, leng th, m_formatter.entityMaskForText(text));
129 } else { 124 } else {
130 const bool useRenderedText = !enclosingElementWithTag(firstPositionInNod e(&text), selectTag); 125 const bool useRenderedText = !enclosingElementWithTag(firstPositionInNod e(&text), selectTag);
131 String content = useRenderedText ? renderedText(text) : stringValueForRa nge(text); 126 String content = useRenderedText ? renderedText(text) : stringValueForRa nge(text);
132 StringBuilder buffer; 127 StringBuilder buffer;
133 MarkupFormatter::appendCharactersReplacingEntities(buffer, content, 0, c ontent.length(), EntityMaskInPCDATA); 128 MarkupFormatter::appendCharactersReplacingEntities(buffer, content, 0, c ontent.length(), EntityMaskInPCDATA);
134 out.append(convertHTMLTextToInterchangeFormat(buffer.toString(), text)); 129 out.append(convertHTMLTextToInterchangeFormat(buffer.toString(), text));
135 } 130 }
136 131
137 if (wrappingSpan) 132 if (wrappingSpan)
138 out.append(styleNodeCloseTag(false)); 133 out.append("</span>");
139 } 134 }
140 135
141 void StyledMarkupAccumulator::appendElement(StringBuilder& out, Element& element ) 136 void StyledMarkupAccumulator::appendElement(StringBuilder& out, Element& element )
142 { 137 {
143 appendElement(out, element, false, DoesFullySelectNode); 138 appendElement(out, element, false, DoesFullySelectNode);
144 } 139 }
145 140
146 void StyledMarkupAccumulator::appendElement(StringBuilder& out, Element& element , bool addDisplayInline, StyledMarkupAccumulator::RangeFullySelectsNode rangeFul lySelectsNode) 141 void StyledMarkupAccumulator::appendElement(StringBuilder& out, Element& element , bool addDisplayInline, StyledMarkupAccumulator::RangeFullySelectsNode rangeFul lySelectsNode)
147 { 142 {
148 const bool documentIsHTML = element.document().isHTMLDocument(); 143 const bool documentIsHTML = element.document().isHTMLDocument();
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 if (!newInlineStyle->isEmpty()) { 184 if (!newInlineStyle->isEmpty()) {
190 out.appendLiteral(" style=\""); 185 out.appendLiteral(" style=\"");
191 MarkupFormatter::appendAttributeValue(out, newInlineStyle->style()-> asText(), documentIsHTML); 186 MarkupFormatter::appendAttributeValue(out, newInlineStyle->style()-> asText(), documentIsHTML);
192 out.append('\"'); 187 out.append('\"');
193 } 188 }
194 } 189 }
195 190
196 m_formatter.appendCloseTag(out, element); 191 m_formatter.appendCloseTag(out, element);
197 } 192 }
198 193
199 void StyledMarkupAccumulator::appendStyleNodeOpenTag(StringBuilder& out, StylePr opertySet* style, bool isBlock)
200 {
201 // wrappingStyleForSerialization should have removed -webkit-text-decoration s-in-effect
202 ASSERT(propertyMissingOrEqualToNone(style, CSSPropertyWebkitTextDecorationsI nEffect));
tkent 2015/06/08 07:49:56 The assertion is removed. Is it intentional?
hajimehoshi 2015/06/08 07:56:55 Oh, I forgot that. Copied.
203 if (isBlock)
204 out.appendLiteral("<div style=\"");
205 else
206 out.appendLiteral("<span style=\"");
207 ASSERT(m_document);
tkent 2015/06/08 07:49:56 Ditto.
hajimehoshi 2015/06/08 07:56:55 Done.
208 MarkupFormatter::appendAttributeValue(out, style->asText(), m_document->isHT MLDocument());
209 out.appendLiteral("\">");
210 }
211
212 void StyledMarkupAccumulator::wrapWithNode(ContainerNode& node, RangeFullySelect sNode rangeFullySelectsNode) 194 void StyledMarkupAccumulator::wrapWithNode(ContainerNode& node, RangeFullySelect sNode rangeFullySelectsNode)
213 { 195 {
214 StringBuilder markup; 196 StringBuilder markup;
215 if (node.isElementNode()) 197 if (node.isElementNode())
216 appendElement(markup, toElement(node), convertBlocksToInlines() && isBlo ck(&node), rangeFullySelectsNode); 198 appendElement(markup, toElement(node), convertBlocksToInlines() && isBlo ck(&node), rangeFullySelectsNode);
217 else 199 else
218 appendStartMarkup(markup, node); 200 appendStartMarkup(markup, node);
219 m_reversedPrecedingMarkup.append(markup.toString()); 201 m_reversedPrecedingMarkup.append(markup.toString());
220 if (node.isElementNode()) 202 if (node.isElementNode())
221 appendEndTag(toElement(node)); 203 appendEndTag(toElement(node));
222 } 204 }
223 205
224 void StyledMarkupAccumulator::wrapWithStyleNode(StylePropertySet* style, bool is Block) 206 void StyledMarkupAccumulator::wrapWithStyleNode(StylePropertySet* style)
225 { 207 {
226 StringBuilder openTag; 208 StringBuilder openTag;
227 appendStyleNodeOpenTag(openTag, style, isBlock); 209 openTag.appendLiteral("<div style=\"");
210 MarkupFormatter::appendAttributeValue(openTag, style->asText(), m_document-> isHTMLDocument());
211 openTag.appendLiteral("\">");
228 m_reversedPrecedingMarkup.append(openTag.toString()); 212 m_reversedPrecedingMarkup.append(openTag.toString());
229 appendString(styleNodeCloseTag(isBlock)); 213
214 appendString("</div>");
230 } 215 }
231 216
232 String StyledMarkupAccumulator::takeResults() 217 String StyledMarkupAccumulator::takeResults()
233 { 218 {
234 StringBuilder result; 219 StringBuilder result;
235 result.reserveCapacity(MarkupFormatter::totalLength(m_reversedPrecedingMarku p) + m_result.length()); 220 result.reserveCapacity(MarkupFormatter::totalLength(m_reversedPrecedingMarku p) + m_result.length());
236 221
237 for (size_t i = m_reversedPrecedingMarkup.size(); i > 0; --i) 222 for (size_t i = m_reversedPrecedingMarkup.size(); i > 0; --i)
238 result.append(m_reversedPrecedingMarkup[i - 1]); 223 result.append(m_reversedPrecedingMarkup[i - 1]);
239 224
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 return m_highestNodeToBeSerialized && m_highestNodeToBeSerialized->parentNod e() == node.parentNode() 258 return m_highestNodeToBeSerialized && m_highestNodeToBeSerialized->parentNod e() == node.parentNode()
274 && m_wrappingStyle && m_wrappingStyle->style(); 259 && m_wrappingStyle && m_wrappingStyle->style();
275 } 260 }
276 261
277 bool StyledMarkupAccumulator::shouldAnnotate() const 262 bool StyledMarkupAccumulator::shouldAnnotate() const
278 { 263 {
279 return m_shouldAnnotate == AnnotateForInterchange; 264 return m_shouldAnnotate == AnnotateForInterchange;
280 } 265 }
281 266
282 } // namespace blink 267 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/editing/StyledMarkupAccumulator.h ('k') | Source/core/editing/StyledMarkupSerializer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698