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

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

Issue 1177323005: Move StyledMarkupAccumulator::shouldApplyWrappingStyle to its serializer (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: yosin'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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 template<typename Strategy> 117 template<typename Strategy>
118 String StyledMarkupSerializer<Strategy>::createMarkup() 118 String StyledMarkupSerializer<Strategy>::createMarkup()
119 { 119 {
120 StyledMarkupAccumulator markupAccumulator(m_shouldResolveURLs, toTextOffset( m_start.parentAnchoredEquivalent()), toTextOffset(m_end.parentAnchoredEquivalent ()), m_start.document(), m_shouldAnnotate, m_highestNodeToBeSerialized.get()); 120 StyledMarkupAccumulator markupAccumulator(m_shouldResolveURLs, toTextOffset( m_start.parentAnchoredEquivalent()), toTextOffset(m_end.parentAnchoredEquivalent ()), m_start.document(), m_shouldAnnotate, m_highestNodeToBeSerialized.get());
121 121
122 Node* pastEnd = m_end.nodeAsRangePastLastNode(); 122 Node* pastEnd = m_end.nodeAsRangePastLastNode();
123 123
124 Node* firstNode = m_start.nodeAsRangeFirstNode(); 124 Node* firstNode = m_start.nodeAsRangeFirstNode();
125 VisiblePosition visibleStart(toPositionInDOMTree(m_start), VP_DEFAULT_AFFINI TY); 125 VisiblePosition visibleStart(toPositionInDOMTree(m_start), VP_DEFAULT_AFFINI TY);
126 VisiblePosition visibleEnd(toPositionInDOMTree(m_end), VP_DEFAULT_AFFINITY); 126 VisiblePosition visibleEnd(toPositionInDOMTree(m_end), VP_DEFAULT_AFFINITY);
127 if (m_shouldAnnotate == AnnotateForInterchange && needInterchangeNewlineAfte r(visibleStart)) { 127 if (shouldAnnotate() && needInterchangeNewlineAfter(visibleStart)) {
128 markupAccumulator.appendInterchangeNewline(); 128 markupAccumulator.appendInterchangeNewline();
129 if (visibleStart == visibleEnd.previous()) 129 if (visibleStart == visibleEnd.previous())
130 return markupAccumulator.takeResults(); 130 return markupAccumulator.takeResults();
131 131
132 firstNode = visibleStart.next().deepEquivalent().deprecatedNode(); 132 firstNode = visibleStart.next().deepEquivalent().deprecatedNode();
133 133
134 if (pastEnd && Strategy::PositionType::beforeNode(firstNode).compareTo(S trategy::PositionType::beforeNode(pastEnd)) >= 0) { 134 if (pastEnd && Strategy::PositionType::beforeNode(firstNode).compareTo(S trategy::PositionType::beforeNode(pastEnd)) >= 0) {
135 // This condition hits in editing/pasteboard/copy-display-none.html. 135 // This condition hits in editing/pasteboard/copy-display-none.html.
136 return markupAccumulator.takeResults(); 136 return markupAccumulator.takeResults();
137 } 137 }
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 style->style()->removeProperty(CSSPropertyFloat); 181 style->style()->removeProperty(CSSPropertyFloat);
182 wrapWithNode(markupAccumulator, *ancestor, style); 182 wrapWithNode(markupAccumulator, *ancestor, style);
183 } 183 }
184 184
185 if (ancestor == m_highestNodeToBeSerialized) 185 if (ancestor == m_highestNodeToBeSerialized)
186 break; 186 break;
187 } 187 }
188 } 188 }
189 189
190 // FIXME: The interchange newline should be placed in the block that it's in , not after all of the content, unconditionally. 190 // FIXME: The interchange newline should be placed in the block that it's in , not after all of the content, unconditionally.
191 if (m_shouldAnnotate == AnnotateForInterchange && needInterchangeNewlineAt(v isibleEnd)) 191 if (shouldAnnotate() && needInterchangeNewlineAt(visibleEnd))
192 markupAccumulator.appendInterchangeNewline(); 192 markupAccumulator.appendInterchangeNewline();
193 193
194 return markupAccumulator.takeResults(); 194 return markupAccumulator.takeResults();
195 } 195 }
196 196
197 template<typename Strategy> 197 template<typename Strategy>
198 Node* StyledMarkupSerializer<Strategy>::serializeNodes(Node* startNode, Node* pa stEnd, StyledMarkupAccumulator* markupAccumulator) 198 Node* StyledMarkupSerializer<Strategy>::serializeNodes(Node* startNode, Node* pa stEnd, StyledMarkupAccumulator* markupAccumulator)
199 { 199 {
200 if (!markupAccumulator->highestNodeToBeSerialized()) { 200 if (!markupAccumulator->highestNodeToBeSerialized()) {
201 Node* lastClosed = traverseNodesForSerialization(startNode, pastEnd, nul lptr); 201 Node* lastClosed = traverseNodesForSerialization(startNode, pastEnd, nul lptr);
202 markupAccumulator->setHighestNodeToBeSerialized(lastClosed); 202 markupAccumulator->setHighestNodeToBeSerialized(lastClosed);
203 } 203 }
204 204
205 Node* highestNodeToBeSerialized = markupAccumulator->highestNodeToBeSerializ ed(); 205 Node* highestNodeToBeSerialized = markupAccumulator->highestNodeToBeSerializ ed();
206 if (highestNodeToBeSerialized && Strategy::parent(*highestNodeToBeSerialized )) { 206 if (highestNodeToBeSerialized && Strategy::parent(*highestNodeToBeSerialized )) {
207 bool shouldAnnotate = m_shouldAnnotate == AnnotateForInterchange; 207 RefPtrWillBeRawPtr<EditingStyle> wrappingStyle = EditingStyle::wrappingS tyleForSerialization(Strategy::parent(*highestNodeToBeSerialized), shouldAnnotat e());
208 RefPtrWillBeRawPtr<EditingStyle> wrappingStyle = EditingStyle::wrappingS tyleForSerialization(Strategy::parent(*highestNodeToBeSerialized), shouldAnnotat e);
209 markupAccumulator->setWrappingStyle(wrappingStyle.release()); 208 markupAccumulator->setWrappingStyle(wrappingStyle.release());
210 } 209 }
211 return traverseNodesForSerialization(startNode, pastEnd, markupAccumulator); 210 return traverseNodesForSerialization(startNode, pastEnd, markupAccumulator);
212 } 211 }
213 212
214 template<typename Strategy> 213 template<typename Strategy>
215 Node* StyledMarkupSerializer<Strategy>::traverseNodesForSerialization(Node* star tNode, Node* pastEnd, StyledMarkupAccumulator* markupAccumulator) 214 Node* StyledMarkupSerializer<Strategy>::traverseNodesForSerialization(Node* star tNode, Node* pastEnd, StyledMarkupAccumulator* markupAccumulator)
216 { 215 {
217 WillBeHeapVector<RawPtrWillBeMember<ContainerNode>> ancestorsToClose; 216 WillBeHeapVector<RawPtrWillBeMember<ContainerNode>> ancestorsToClose;
218 Node* next; 217 Node* next;
(...skipping 15 matching lines...) Expand all
234 } 233 }
235 234
236 if (!n->layoutObject() && !enclosingElementWithTag(firstPositionInOrBefo reNode(n), selectTag)) { 235 if (!n->layoutObject() && !enclosingElementWithTag(firstPositionInOrBefo reNode(n), selectTag)) {
237 next = Strategy::nextSkippingChildren(*n); 236 next = Strategy::nextSkippingChildren(*n);
238 // Don't skip over pastEnd. 237 // Don't skip over pastEnd.
239 if (pastEnd && Strategy::isDescendantOf(*pastEnd, *n)) 238 if (pastEnd && Strategy::isDescendantOf(*pastEnd, *n))
240 next = pastEnd; 239 next = pastEnd;
241 } else { 240 } else {
242 // Add the node to the markup if we're not skipping the descendants 241 // Add the node to the markup if we're not skipping the descendants
243 if (markupAccumulator) 242 if (markupAccumulator)
244 markupAccumulator->appendStartTag(*n); 243 appendStartMarkup(*markupAccumulator, *n);
245 244
246 // If node has no children, close the tag now. 245 // If node has no children, close the tag now.
247 if (Strategy::hasChildren(*n)) { 246 if (Strategy::hasChildren(*n)) {
248 ancestorsToClose.append(toContainerNode(n)); 247 ancestorsToClose.append(toContainerNode(n));
249 continue; 248 continue;
250 } 249 }
251 if (markupAccumulator && n->isElementNode()) 250 if (markupAccumulator && n->isElementNode())
252 markupAccumulator->appendEndTag(toElement(*n)); 251 markupAccumulator->appendEndTag(toElement(*n));
253 lastClosed = n; 252 lastClosed = n;
254 } 253 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 } 293 }
295 294
296 return lastClosed; 295 return lastClosed;
297 } 296 }
298 297
299 template<typename Strategy> 298 template<typename Strategy>
300 bool StyledMarkupSerializer<Strategy>::needsInlineStyle(const Element& element) 299 bool StyledMarkupSerializer<Strategy>::needsInlineStyle(const Element& element)
301 { 300 {
302 if (!element.isHTMLElement()) 301 if (!element.isHTMLElement())
303 return false; 302 return false;
304 if (m_shouldAnnotate == AnnotateForInterchange) 303 if (shouldAnnotate())
305 return true; 304 return true;
306 return convertBlocksToInlines() && isBlock(&element); 305 return convertBlocksToInlines() && isBlock(&element);
307 } 306 }
308 307
309 template<typename Strategy> 308 template<typename Strategy>
310 void StyledMarkupSerializer<Strategy>::wrapWithNode(StyledMarkupAccumulator& acc umulator, ContainerNode& node, PassRefPtrWillBeRawPtr<EditingStyle> style) 309 void StyledMarkupSerializer<Strategy>::wrapWithNode(StyledMarkupAccumulator& acc umulator, ContainerNode& node, PassRefPtrWillBeRawPtr<EditingStyle> style)
311 { 310 {
312 StringBuilder markup; 311 StringBuilder markup;
313 if (node.isDocumentNode()) { 312 if (node.isDocumentNode()) {
314 MarkupFormatter::appendXMLDeclaration(markup, toDocument(node)); 313 MarkupFormatter::appendXMLDeclaration(markup, toDocument(node));
315 accumulator.pushMarkup(markup.toString()); 314 accumulator.pushMarkup(markup.toString());
316 return; 315 return;
317 } 316 }
318 if (!node.isElementNode()) 317 if (!node.isElementNode())
319 return; 318 return;
320 Element& element = toElement(node); 319 Element& element = toElement(node);
321 if (accumulator.shouldApplyWrappingStyle(element) || needsInlineStyle(elemen t)) 320 if (shouldApplyWrappingStyle(accumulator, element) || needsInlineStyle(eleme nt))
322 accumulator.appendElementWithInlineStyle(markup, element, style); 321 accumulator.appendElementWithInlineStyle(markup, element, style);
323 else 322 else
324 accumulator.appendElement(markup, element); 323 accumulator.appendElement(markup, element);
325 accumulator.pushMarkup(markup.toString()); 324 accumulator.pushMarkup(markup.toString());
326 accumulator.appendEndTag(toElement(node)); 325 accumulator.appendEndTag(toElement(node));
327 } 326 }
328 327
329 template<typename Strategy> 328 template<typename Strategy>
330 RefPtrWillBeRawPtr<EditingStyle> StyledMarkupSerializer<Strategy>::createInlineS tyleIfNeeded(StyledMarkupAccumulator& accumulator, Node& node) 329 RefPtrWillBeRawPtr<EditingStyle> StyledMarkupSerializer<Strategy>::createInlineS tyleIfNeeded(StyledMarkupAccumulator& accumulator, Node& node)
331 { 330 {
332 if (!node.isElementNode()) 331 if (!node.isElementNode())
333 return nullptr; 332 return nullptr;
334 RefPtrWillBeRawPtr<EditingStyle> inlineStyle = accumulator.createInlineStyle (toElement(node)); 333 RefPtrWillBeRawPtr<EditingStyle> inlineStyle = accumulator.createInlineStyle (toElement(node));
335 if (convertBlocksToInlines() && isBlock(&node)) 334 if (convertBlocksToInlines() && isBlock(&node))
336 inlineStyle->forceInline(); 335 inlineStyle->forceInline();
337 return inlineStyle; 336 return inlineStyle;
338 } 337 }
339 338
339 template<typename Strategy>
340 void StyledMarkupSerializer<Strategy>::appendStartMarkup(StyledMarkupAccumulator & accumulator, Node& node)
341 {
342 switch (node.nodeType()) {
343 case Node::TEXT_NODE: {
344 Text& text = toText(node);
345 if (text.parentElement() && text.parentElement()->tagQName() == textarea Tag) {
346 accumulator.appendText(text);
347 return;
348 }
349 RefPtrWillBeRawPtr<EditingStyle> style = nullptr;
yosin_UTC9 2015/06/16 08:23:56 s/style/inlineStyle/
hajimehoshi 2015/06/16 08:58:17 Done.
350 if (shouldApplyWrappingStyle(accumulator, text)) {
351 style = accumulator.wrappingStyle()->copy();
352 // FIXME: <rdar://problem/5371536> Style rules that match pasted con tent can change it's appearance
353 // Make sure spans are inline style in paste side e.g. span { displa y: block }.
354 style->forceInline();
355 // FIXME: Should this be included in forceInline?
356 style->style()->setProperty(CSSPropertyFloat, CSSValueNone);
357 }
358 accumulator.appendTextWithInlineStyle(text, style);
359 break;
360 } case Node::ELEMENT_NODE: {
361 Element& element = toElement(node);
362 RefPtrWillBeRawPtr<EditingStyle> style = accumulator.createInlineStyle(e lement);
363 if ((element.isHTMLElement() && shouldAnnotate()) || shouldApplyWrapping Style(accumulator, element)) {
364 accumulator.appendElementWithInlineStyle(element, style);
365 return;
366 }
367 accumulator.appendElement(element);
368 break;
369 }
370 default:
371 accumulator.appendStartMarkup(node);
372 break;
373 }
374 }
375
376 template<typename Strategy>
377 bool StyledMarkupSerializer<Strategy>::shouldApplyWrappingStyle(StyledMarkupAccu mulator& accumulator, const Node& node) const
yosin_UTC9 2015/06/16 08:23:56 |const StyledMarkupAccumulator&|
hajimehoshi 2015/06/16 08:58:17 Done.
378 {
379 return accumulator.highestNodeToBeSerialized() && Strategy::parent(*accumula tor.highestNodeToBeSerialized()) == Strategy::parent(node)
380 && accumulator.wrappingStyle() && accumulator.wrappingStyle()->style();
381 }
382
340 template class StyledMarkupSerializer<EditingStrategy>; 383 template class StyledMarkupSerializer<EditingStrategy>;
341 384
342 } // namespace blink 385 } // namespace blink
OLDNEW
« Source/core/editing/StyledMarkupSerializer.h ('K') | « Source/core/editing/StyledMarkupSerializer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698