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

Unified 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 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 4b10abcb39f8d0ee3cb0fed86f596222c00ed9ad..ee6fc29bb2189d87e9d1104b3620cc38650092e1 100644
--- a/Source/core/editing/StyledMarkupSerializer.cpp
+++ b/Source/core/editing/StyledMarkupSerializer.cpp
@@ -124,7 +124,7 @@ String StyledMarkupSerializer<Strategy>::createMarkup()
Node* firstNode = m_start.nodeAsRangeFirstNode();
VisiblePosition visibleStart(toPositionInDOMTree(m_start), VP_DEFAULT_AFFINITY);
VisiblePosition visibleEnd(toPositionInDOMTree(m_end), VP_DEFAULT_AFFINITY);
- if (m_shouldAnnotate == AnnotateForInterchange && needInterchangeNewlineAfter(visibleStart)) {
+ if (shouldAnnotate() && needInterchangeNewlineAfter(visibleStart)) {
markupAccumulator.appendInterchangeNewline();
if (visibleStart == visibleEnd.previous())
return markupAccumulator.takeResults();
@@ -188,7 +188,7 @@ String StyledMarkupSerializer<Strategy>::createMarkup()
}
// FIXME: The interchange newline should be placed in the block that it's in, not after all of the content, unconditionally.
- if (m_shouldAnnotate == AnnotateForInterchange && needInterchangeNewlineAt(visibleEnd))
+ if (shouldAnnotate() && needInterchangeNewlineAt(visibleEnd))
markupAccumulator.appendInterchangeNewline();
return markupAccumulator.takeResults();
@@ -204,8 +204,7 @@ Node* StyledMarkupSerializer<Strategy>::serializeNodes(Node* startNode, Node* pa
Node* highestNodeToBeSerialized = markupAccumulator->highestNodeToBeSerialized();
if (highestNodeToBeSerialized && Strategy::parent(*highestNodeToBeSerialized)) {
- bool shouldAnnotate = m_shouldAnnotate == AnnotateForInterchange;
- RefPtrWillBeRawPtr<EditingStyle> wrappingStyle = EditingStyle::wrappingStyleForSerialization(Strategy::parent(*highestNodeToBeSerialized), shouldAnnotate);
+ RefPtrWillBeRawPtr<EditingStyle> wrappingStyle = EditingStyle::wrappingStyleForSerialization(Strategy::parent(*highestNodeToBeSerialized), shouldAnnotate());
markupAccumulator->setWrappingStyle(wrappingStyle.release());
}
return traverseNodesForSerialization(startNode, pastEnd, markupAccumulator);
@@ -241,7 +240,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);
+ appendStartMarkup(*markupAccumulator, *n);
// If node has no children, close the tag now.
if (Strategy::hasChildren(*n)) {
@@ -301,7 +300,7 @@ bool StyledMarkupSerializer<Strategy>::needsInlineStyle(const Element& element)
{
if (!element.isHTMLElement())
return false;
- if (m_shouldAnnotate == AnnotateForInterchange)
+ if (shouldAnnotate())
return true;
return convertBlocksToInlines() && isBlock(&element);
}
@@ -318,7 +317,7 @@ void StyledMarkupSerializer<Strategy>::wrapWithNode(StyledMarkupAccumulator& acc
if (!node.isElementNode())
return;
Element& element = toElement(node);
- if (accumulator.shouldApplyWrappingStyle(element) || needsInlineStyle(element))
+ if (shouldApplyWrappingStyle(accumulator, element) || needsInlineStyle(element))
accumulator.appendElementWithInlineStyle(markup, element, style);
else
accumulator.appendElement(markup, element);
@@ -337,6 +336,50 @@ RefPtrWillBeRawPtr<EditingStyle> StyledMarkupSerializer<Strategy>::createInlineS
return inlineStyle;
}
+template<typename Strategy>
+void StyledMarkupSerializer<Strategy>::appendStartMarkup(StyledMarkupAccumulator& accumulator, Node& node)
+{
+ switch (node.nodeType()) {
+ case Node::TEXT_NODE: {
+ Text& text = toText(node);
+ if (text.parentElement() && text.parentElement()->tagQName() == textareaTag) {
+ accumulator.appendText(text);
+ return;
+ }
+ RefPtrWillBeRawPtr<EditingStyle> style = nullptr;
yosin_UTC9 2015/06/16 08:23:56 s/style/inlineStyle/
hajimehoshi 2015/06/16 08:58:17 Done.
+ if (shouldApplyWrappingStyle(accumulator, text)) {
+ style = accumulator.wrappingStyle()->copy();
+ // FIXME: <rdar://problem/5371536> Style rules that match pasted content can change it's appearance
+ // Make sure spans are inline style in paste side e.g. span { display: block }.
+ style->forceInline();
+ // FIXME: Should this be included in forceInline?
+ style->style()->setProperty(CSSPropertyFloat, CSSValueNone);
+ }
+ accumulator.appendTextWithInlineStyle(text, style);
+ break;
+ } case Node::ELEMENT_NODE: {
+ Element& element = toElement(node);
+ RefPtrWillBeRawPtr<EditingStyle> style = accumulator.createInlineStyle(element);
+ if ((element.isHTMLElement() && shouldAnnotate()) || shouldApplyWrappingStyle(accumulator, element)) {
+ accumulator.appendElementWithInlineStyle(element, style);
+ return;
+ }
+ accumulator.appendElement(element);
+ break;
+ }
+ default:
+ accumulator.appendStartMarkup(node);
+ break;
+ }
+}
+
+template<typename Strategy>
+bool StyledMarkupSerializer<Strategy>::shouldApplyWrappingStyle(StyledMarkupAccumulator& accumulator, const Node& node) const
yosin_UTC9 2015/06/16 08:23:56 |const StyledMarkupAccumulator&|
hajimehoshi 2015/06/16 08:58:17 Done.
+{
+ return accumulator.highestNodeToBeSerialized() && Strategy::parent(*accumulator.highestNodeToBeSerialized()) == Strategy::parent(node)
+ && accumulator.wrappingStyle() && accumulator.wrappingStyle()->style();
+}
+
template class StyledMarkupSerializer<EditingStrategy>;
} // namespace blink
« 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