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

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

Issue 426293002: Use tighter typing in editing: MarkupAccumulator (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: 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) 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 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 } 174 }
175 175
176 void StyledMarkupAccumulator::wrapWithNode(ContainerNode& node, bool convertBloc ksToInlines, RangeFullySelectsNode rangeFullySelectsNode) 176 void StyledMarkupAccumulator::wrapWithNode(ContainerNode& node, bool convertBloc ksToInlines, RangeFullySelectsNode rangeFullySelectsNode)
177 { 177 {
178 StringBuilder markup; 178 StringBuilder markup;
179 if (node.isElementNode()) 179 if (node.isElementNode())
180 appendElement(markup, toElement(node), convertBlocksToInlines && isBlock (&node), rangeFullySelectsNode); 180 appendElement(markup, toElement(node), convertBlocksToInlines && isBlock (&node), rangeFullySelectsNode);
181 else 181 else
182 appendStartMarkup(markup, node, 0); 182 appendStartMarkup(markup, node, 0);
183 m_reversedPrecedingMarkup.append(markup.toString()); 183 m_reversedPrecedingMarkup.append(markup.toString());
184 appendEndTag(node); 184 if (node.isElementNode())
185 appendEndTag(toElement(node));
185 if (m_nodes) 186 if (m_nodes)
186 m_nodes->append(&node); 187 m_nodes->append(&node);
187 } 188 }
188 189
189 void StyledMarkupAccumulator::wrapWithStyleNode(StylePropertySet* style, const D ocument& document, bool isBlock) 190 void StyledMarkupAccumulator::wrapWithStyleNode(StylePropertySet* style, const D ocument& document, bool isBlock)
190 { 191 {
191 StringBuilder openTag; 192 StringBuilder openTag;
192 appendStyleNodeOpenTag(openTag, style, document, isBlock); 193 appendStyleNodeOpenTag(openTag, style, document, isBlock);
193 m_reversedPrecedingMarkup.append(openTag.toString()); 194 m_reversedPrecedingMarkup.append(openTag.toString());
194 appendString(styleNodeCloseTag(isBlock)); 195 appendString(styleNodeCloseTag(isBlock));
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 } else { 396 } else {
396 // Add the node to the markup if we're not skipping the descendants 397 // Add the node to the markup if we're not skipping the descendants
397 if (shouldEmit) 398 if (shouldEmit)
398 appendStartTag(*n); 399 appendStartTag(*n);
399 400
400 // If node has no children, close the tag now. 401 // If node has no children, close the tag now.
401 if (n->isContainerNode() && toContainerNode(n)->hasChildren()) { 402 if (n->isContainerNode() && toContainerNode(n)->hasChildren()) {
402 openedTag = true; 403 openedTag = true;
403 ancestorsToClose.append(toContainerNode(n)); 404 ancestorsToClose.append(toContainerNode(n));
404 } else { 405 } else {
405 if (shouldEmit) 406 if (shouldEmit && n->isElementNode())
406 appendEndTag(*n); 407 appendEndTag(toElement(*n));
407 lastClosed = n; 408 lastClosed = n;
408 } 409 }
409 } 410 }
410 411
411 // If we didn't insert open tag and there's no more siblings or we're at the end of the traversal, take care of ancestors. 412 // If we didn't insert open tag and there's no more siblings or we're at the end of the traversal, take care of ancestors.
412 // FIXME: What happens if we just inserted open tag and reached the end? 413 // FIXME: What happens if we just inserted open tag and reached the end?
413 if (!openedTag && (!n->nextSibling() || next == pastEnd)) { 414 if (!openedTag && (!n->nextSibling() || next == pastEnd)) {
414 // Close up the ancestors. 415 // Close up the ancestors.
415 while (!ancestorsToClose.isEmpty()) { 416 while (!ancestorsToClose.isEmpty()) {
416 ContainerNode* ancestor = ancestorsToClose.last(); 417 ContainerNode* ancestor = ancestorsToClose.last();
417 ASSERT(ancestor); 418 ASSERT(ancestor);
418 if (next != pastEnd && next->isDescendantOf(ancestor)) 419 if (next != pastEnd && next->isDescendantOf(ancestor))
419 break; 420 break;
420 // Not at the end of the range, close ancestors up to sibling of next node. 421 // Not at the end of the range, close ancestors up to sibling of next node.
421 if (shouldEmit) 422 if (shouldEmit && ancestor->isElementNode())
422 appendEndTag(*ancestor); 423 appendEndTag(toElement(*ancestor));
423 lastClosed = ancestor; 424 lastClosed = ancestor;
424 ancestorsToClose.removeLast(); 425 ancestorsToClose.removeLast();
425 } 426 }
426 427
427 // Surround the currently accumulated markup with markup for ancesto rs we never opened as we leave the subtree(s) rooted at those ancestors. 428 // Surround the currently accumulated markup with markup for ancesto rs we never opened as we leave the subtree(s) rooted at those ancestors.
428 ContainerNode* nextParent = next ? next->parentNode() : 0; 429 ContainerNode* nextParent = next ? next->parentNode() : 0;
429 if (next != pastEnd && n != nextParent) { 430 if (next != pastEnd && n != nextParent) {
430 Node* lastAncestorClosedOrSelf = n->isDescendantOf(lastClosed) ? lastClosed : n; 431 Node* lastAncestorClosedOrSelf = n->isDescendantOf(lastClosed) ? lastClosed : n;
431 for (ContainerNode* parent = lastAncestorClosedOrSelf->parentNod e(); parent && parent != nextParent; parent = parent->parentNode()) { 432 for (ContainerNode* parent = lastAncestorClosedOrSelf->parentNod e(); parent && parent != nextParent; parent = parent->parentNode()) {
432 // All ancestors that aren't in the ancestorsToClose list sh ould either be a) unrendered: 433 // All ancestors that aren't in the ancestorsToClose list sh ould either be a) unrendered:
(...skipping 676 matching lines...) Expand 10 before | Expand all | Expand 10 after
1109 node->document().updateLayoutIgnorePendingStylesheets(); 1110 node->document().updateLayoutIgnorePendingStylesheets();
1110 1111
1111 StyledMarkupAccumulator accumulator(0, ResolveAllURLs, AnnotateForNavigation Transition, nullptr, 0); 1112 StyledMarkupAccumulator accumulator(0, ResolveAllURLs, AnnotateForNavigation Transition, nullptr, 0);
1112 accumulator.serializeNodes(node, NodeTraversal::nextSkippingChildren(*node)) ; 1113 accumulator.serializeNodes(node, NodeTraversal::nextSkippingChildren(*node)) ;
1113 1114
1114 static const char* documentMarkup = "<!DOCTYPE html><meta name=\"viewport\" content=\"width=device-width, user-scalable=0\">"; 1115 static const char* documentMarkup = "<!DOCTYPE html><meta name=\"viewport\" content=\"width=device-width, user-scalable=0\">";
1115 return documentMarkup + accumulator.takeResults(); 1116 return documentMarkup + accumulator.takeResults();
1116 } 1117 }
1117 1118
1118 } 1119 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698