Chromium Code Reviews| 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 |