| Index: Source/core/editing/StyledMarkupAccumulator.cpp
|
| diff --git a/Source/core/editing/StyledMarkupAccumulator.cpp b/Source/core/editing/StyledMarkupAccumulator.cpp
|
| index 5775f5c23354fd992678c9e8f27b204da0dd16cd..944a0c2d4ac6fae469157fe013774285632e3002 100644
|
| --- a/Source/core/editing/StyledMarkupAccumulator.cpp
|
| +++ b/Source/core/editing/StyledMarkupAccumulator.cpp
|
| @@ -39,13 +39,12 @@ namespace blink {
|
|
|
| using namespace HTMLNames;
|
|
|
| -StyledMarkupAccumulator::StyledMarkupAccumulator(EAbsoluteURLs shouldResolveURLs, const TextOffset& start, const TextOffset& end, const PassRefPtrWillBeRawPtr<Document> document, EAnnotateForInterchange shouldAnnotate, Node* highestNodeToBeSerialized, ConvertBlocksToInlines convertBlocksToInlines)
|
| +StyledMarkupAccumulator::StyledMarkupAccumulator(EAbsoluteURLs shouldResolveURLs, const TextOffset& start, const TextOffset& end, const PassRefPtrWillBeRawPtr<Document> document, EAnnotateForInterchange shouldAnnotate, Node* highestNodeToBeSerialized)
|
| : m_formatter(shouldResolveURLs)
|
| , m_start(start)
|
| , m_end(end)
|
| , m_document(document)
|
| , m_shouldAnnotate(shouldAnnotate)
|
| - , m_convertBlocksToInlines(convertBlocksToInlines)
|
| , m_highestNodeToBeSerialized(highestNodeToBeSerialized)
|
| {
|
| }
|
| @@ -67,17 +66,7 @@ void StyledMarkupAccumulator::appendEndTag(const Element& element)
|
|
|
| void StyledMarkupAccumulator::appendStartMarkup(StringBuilder& result, Node& node)
|
| {
|
| - switch (node.nodeType()) {
|
| - case Node::TEXT_NODE:
|
| - appendText(result, toText(node));
|
| - break;
|
| - case Node::ELEMENT_NODE:
|
| - appendElement(result, toElement(node));
|
| - break;
|
| - default:
|
| - m_formatter.appendStartMarkup(result, node, nullptr);
|
| - break;
|
| - }
|
| + m_formatter.appendStartMarkup(result, node, nullptr);
|
| }
|
|
|
| void StyledMarkupAccumulator::appendEndMarkup(StringBuilder& result, const Element& element)
|
| @@ -85,6 +74,11 @@ void StyledMarkupAccumulator::appendEndMarkup(StringBuilder& result, const Eleme
|
| m_formatter.appendEndMarkup(result, element);
|
| }
|
|
|
| +void StyledMarkupAccumulator::appendText(Text& text)
|
| +{
|
| + appendText(m_result, text);
|
| +}
|
| +
|
| void StyledMarkupAccumulator::appendText(StringBuilder& out, Text& text)
|
| {
|
| const bool parentIsTextarea = text.parentElement() && text.parentElement()->tagQName() == textareaTag;
|
| @@ -133,15 +127,47 @@ void StyledMarkupAccumulator::appendText(StringBuilder& out, Text& text)
|
| out.append("</span>");
|
| }
|
|
|
| -void StyledMarkupAccumulator::appendElement(StringBuilder& out, Element& element)
|
| +RefPtrWillBeMember<EditingStyle> StyledMarkupAccumulator::createInlineStyle(Element& element, bool addDisplayInline)
|
| +{
|
| + const bool shouldAnnotateOrForceInline = element.isHTMLElement() && (shouldAnnotate() || addDisplayInline);
|
| + const bool shouldOverrideStyleAttr = shouldAnnotateOrForceInline || shouldApplyWrappingStyle(element);
|
| +
|
| + if (!shouldOverrideStyleAttr)
|
| + return nullptr;
|
| +
|
| + RefPtrWillBeRawPtr<EditingStyle> inlineStyle = nullptr;
|
| +
|
| + if (shouldApplyWrappingStyle(element)) {
|
| + inlineStyle = m_wrappingStyle->copy();
|
| + inlineStyle->removePropertiesInElementDefaultStyle(&element);
|
| + inlineStyle->removeStyleConflictingWithStyleOfElement(&element);
|
| + } else {
|
| + inlineStyle = EditingStyle::create();
|
| + }
|
| +
|
| + if (element.isStyledElement() && element.inlineStyle())
|
| + inlineStyle->overrideWithStyle(element.inlineStyle());
|
| +
|
| + if (shouldAnnotateOrForceInline) {
|
| + if (shouldAnnotate())
|
| + inlineStyle->mergeStyleFromRulesForSerialization(&toHTMLElement(element));
|
| +
|
| + if (addDisplayInline)
|
| + inlineStyle->forceInline();
|
| + }
|
| +
|
| + return inlineStyle;
|
| +}
|
| +
|
| +void StyledMarkupAccumulator::appendElement(Element& element, bool addDisplayInline, PassRefPtrWillBeRawPtr<EditingStyle> style)
|
| {
|
| - appendElement(out, element, false, DoesFullySelectNode);
|
| + appendElement(m_result, element, addDisplayInline, style);
|
| }
|
|
|
| -void StyledMarkupAccumulator::appendElement(StringBuilder& out, Element& element, bool addDisplayInline, StyledMarkupAccumulator::RangeFullySelectsNode rangeFullySelectsNode)
|
| +void StyledMarkupAccumulator::appendElement(StringBuilder& out, Element& element, bool addDisplayInline, PassRefPtrWillBeRawPtr<EditingStyle> style)
|
| {
|
| const bool documentIsHTML = element.document().isHTMLDocument();
|
| - m_formatter.appendOpenTag(out, element, 0);
|
| + m_formatter.appendOpenTag(out, element, nullptr);
|
|
|
| const bool shouldAnnotateOrForceInline = element.isHTMLElement() && (shouldAnnotate() || addDisplayInline);
|
| const bool shouldOverrideStyleAttr = shouldAnnotateOrForceInline || shouldApplyWrappingStyle(element);
|
| @@ -155,35 +181,9 @@ void StyledMarkupAccumulator::appendElement(StringBuilder& out, Element& element
|
| }
|
|
|
| if (shouldOverrideStyleAttr) {
|
| - RefPtrWillBeRawPtr<EditingStyle> newInlineStyle = nullptr;
|
| -
|
| - if (shouldApplyWrappingStyle(element)) {
|
| - newInlineStyle = m_wrappingStyle->copy();
|
| - newInlineStyle->removePropertiesInElementDefaultStyle(&element);
|
| - newInlineStyle->removeStyleConflictingWithStyleOfElement(&element);
|
| - } else {
|
| - newInlineStyle = EditingStyle::create();
|
| - }
|
| -
|
| - if (element.isStyledElement() && element.inlineStyle())
|
| - newInlineStyle->overrideWithStyle(element.inlineStyle());
|
| -
|
| - if (shouldAnnotateOrForceInline) {
|
| - if (shouldAnnotate())
|
| - newInlineStyle->mergeStyleFromRulesForSerialization(&toHTMLElement(element));
|
| -
|
| - if (addDisplayInline)
|
| - newInlineStyle->forceInline();
|
| -
|
| - // 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 (rangeFullySelectsNode == DoesNotFullySelectNode && newInlineStyle->style())
|
| - newInlineStyle->style()->removeProperty(CSSPropertyFloat);
|
| - }
|
| -
|
| - if (!newInlineStyle->isEmpty()) {
|
| + if (style && !style->isEmpty()) {
|
| out.appendLiteral(" style=\"");
|
| - MarkupFormatter::appendAttributeValue(out, newInlineStyle->style()->asText(), documentIsHTML);
|
| + MarkupFormatter::appendAttributeValue(out, style->style()->asText(), documentIsHTML);
|
| out.append('\"');
|
| }
|
| }
|
| @@ -191,16 +191,9 @@ void StyledMarkupAccumulator::appendElement(StringBuilder& out, Element& element
|
| m_formatter.appendCloseTag(out, element);
|
| }
|
|
|
| -void StyledMarkupAccumulator::wrapWithNode(ContainerNode& node, RangeFullySelectsNode rangeFullySelectsNode)
|
| +void StyledMarkupAccumulator::pushMarkup(const String& str)
|
| {
|
| - StringBuilder markup;
|
| - if (node.isElementNode())
|
| - appendElement(markup, toElement(node), convertBlocksToInlines() && isBlock(&node), rangeFullySelectsNode);
|
| - else
|
| - appendStartMarkup(markup, node);
|
| - m_reversedPrecedingMarkup.append(markup.toString());
|
| - if (node.isElementNode())
|
| - appendEndTag(toElement(node));
|
| + m_reversedPrecedingMarkup.append(str);
|
| }
|
|
|
| void StyledMarkupAccumulator::wrapWithStyleNode(StylePropertySet* style)
|
|
|