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

Unified Diff: Source/core/editing/StyledMarkupSerializer.cpp

Issue 1163673005: Refactoring: Remove StyledMarkupAccumulator::RangeFullySelectsNodes (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 side-by-side diff with in-line comments
Download patch
Index: Source/core/editing/StyledMarkupSerializer.cpp
diff --git a/Source/core/editing/StyledMarkupSerializer.cpp b/Source/core/editing/StyledMarkupSerializer.cpp
index ce77ecda8eb6538f9496158c167a5d5146390277..138070d01bc8882f2f09d82672f1b5e3e75e8900 100644
--- a/Source/core/editing/StyledMarkupSerializer.cpp
+++ b/Source/core/editing/StyledMarkupSerializer.cpp
@@ -119,7 +119,7 @@ String StyledMarkupSerializer<Strategy>::createMarkup()
{
DEFINE_STATIC_LOCAL(const String, interchangeNewlineString, ("<br class=\"" AppleInterchangeNewline "\">"));
- StyledMarkupAccumulator markupAccumulator(m_shouldResolveURLs, toTextOffset(m_start.parentAnchoredEquivalent()), toTextOffset(m_end.parentAnchoredEquivalent()), m_start.document(), m_shouldAnnotate, m_highestNodeToBeSerialized.get(), m_convertBlocksToInlines);
+ StyledMarkupAccumulator markupAccumulator(m_shouldResolveURLs, toTextOffset(m_start.parentAnchoredEquivalent()), toTextOffset(m_end.parentAnchoredEquivalent()), m_start.document(), m_shouldAnnotate, m_highestNodeToBeSerialized.get());
Node* pastEnd = m_end.nodeAsRangePastLastNode();
@@ -154,7 +154,7 @@ String StyledMarkupSerializer<Strategy>::createMarkup()
// Also include all of the ancestors of lastClosed up to this special ancestor.
// FIXME: What is ancestor?
for (ContainerNode* ancestor = Strategy::parent(*lastClosed); ancestor; ancestor = Strategy::parent(*ancestor)) {
- if (ancestor == fullySelectedRoot && !markupAccumulator.convertBlocksToInlines()) {
+ if (ancestor == fullySelectedRoot && !convertBlocksToInlines()) {
RefPtrWillBeRawPtr<EditingStyle> fullySelectedRootStyle = styleFromMatchedRulesAndInlineDecl(fullySelectedRoot);
// Bring the background attribute over, but not as an attribute because a background attribute on a div
@@ -174,9 +174,16 @@ String StyledMarkupSerializer<Strategy>::createMarkup()
markupAccumulator.wrapWithStyleNode(fullySelectedRootStyle->style());
}
} else {
- // Since this node and all the other ancestors are not in the selection we want to set RangeFullySelectsNode to DoesNotFullySelectNode
- // so that styles that affect the exterior of the node are not included.
- markupAccumulator.wrapWithNode(*ancestor, StyledMarkupAccumulator::DoesNotFullySelectNode);
+ RefPtrWillBeRawPtr<EditingStyle> style = nullptr;
+ if (ancestor->isElementNode())
+ style = markupAccumulator.createInlineStyle(toElement(*ancestor), convertBlocksToInlines() && isBlock(ancestor));
+ // Since this node and all the other ancestors are not in the selection we want
+ // styles that affect the exterior of the node not to be not included.
+ // If the node is not fully selected by the range, then we don't want to keep styles that affect its relationship to the nodes around it
+ // only the ones that affect it and the nodes within it.
+ if (style && style->style())
+ style->style()->removeProperty(CSSPropertyFloat);
+ wrapWithNode(markupAccumulator, *ancestor, style);
}
if (ancestor == m_highestNodeToBeSerialized)
@@ -238,7 +245,7 @@ Node* StyledMarkupSerializer<Strategy>::traverseNodesForSerialization(Node* star
} else {
// Add the node to the markup if we're not skipping the descendants
if (markupAccumulator)
- markupAccumulator->appendStartTag(*n);
+ appendStartTag(*markupAccumulator, *n);
// If node has no children, close the tag now.
if (Strategy::hasChildren(*n)) {
@@ -282,8 +289,12 @@ Node* StyledMarkupSerializer<Strategy>::traverseNodesForSerialization(Node* star
// or b) ancestors that we never encountered during a pre-order traversal starting at startNode:
ASSERT(startNode);
ASSERT(Strategy::isDescendantOf(*startNode, *parent));
- if (markupAccumulator)
- markupAccumulator->wrapWithNode(*parent);
+ if (markupAccumulator) {
+ RefPtrWillBeRawPtr<EditingStyle> style = nullptr;
+ if (parent->isElementNode())
+ style = markupAccumulator->createInlineStyle(toElement(*parent), convertBlocksToInlines() && isBlock(parent));
+ wrapWithNode(*markupAccumulator, *parent, style);
+ }
lastClosed = parent;
}
}
@@ -291,6 +302,38 @@ Node* StyledMarkupSerializer<Strategy>::traverseNodesForSerialization(Node* star
return lastClosed;
}
+template<typename Strategy>
+void StyledMarkupSerializer<Strategy>::appendStartTag(StyledMarkupAccumulator& accumulator, Node& node)
+{
+ switch (node.nodeType()) {
+ case Node::TEXT_NODE:
+ accumulator.appendText(toText(node));
yosin_UTC9 2015/06/09 01:18:11 I understand that StyledMarkupAccumlator still wor
+ break;
+ case Node::ELEMENT_NODE: {
+ Element& element = toElement(node);
+ RefPtrWillBeRawPtr<EditingStyle> style = accumulator.createInlineStyle(element, false);
+ accumulator.appendElement(element, false, style);
+ break;
+ }
+ default:
+ accumulator.appendStartTag(node);
+ break;
+ }
+}
+
+template<typename Strategy>
+void StyledMarkupSerializer<Strategy>::wrapWithNode(StyledMarkupAccumulator& accumulator, ContainerNode& node, PassRefPtrWillBeRawPtr<EditingStyle> style)
+{
+ StringBuilder markup;
+ if (node.isElementNode())
+ accumulator.appendElement(markup, toElement(node), convertBlocksToInlines() && isBlock(&node), style);
+ else
+ accumulator.appendStartMarkup(markup, node);
+ accumulator.pushMarkup(markup.toString());
+ if (node.isElementNode())
yosin_UTC9 2015/06/09 01:18:11 nit: early return is better.
+ accumulator.appendEndTag(toElement(node));
+}
+
template class StyledMarkupSerializer<EditingStrategy>;
} // namespace blink
« Source/core/editing/StyledMarkupAccumulator.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