Index: Source/core/editing/markup.cpp |
diff --git a/Source/core/editing/markup.cpp b/Source/core/editing/markup.cpp |
index f8441ca8e9a9787317c2875d3c3cf6d205c54da0..df3a96fb728f9a74043432a303d6cf60074c6b36 100644 |
--- a/Source/core/editing/markup.cpp |
+++ b/Source/core/editing/markup.cpp |
@@ -170,24 +170,6 @@ bool propertyMissingOrEqualToNone(StylePropertySet* style, CSSPropertyID propert |
return toCSSPrimitiveValue(value.get())->getValueID() == CSSValueNone; |
} |
-static bool needInterchangeNewlineAfter(const VisiblePosition& v) |
-{ |
- VisiblePosition next = v.next(); |
- Node* upstreamNode = next.deepEquivalent().upstream().deprecatedNode(); |
- Node* downstreamNode = v.deepEquivalent().downstream().deprecatedNode(); |
- // Add an interchange newline if a paragraph break is selected and a br won't already be added to the markup to represent it. |
- return isEndOfParagraph(v) && isStartOfParagraph(next) && !(isHTMLBRElement(*upstreamNode) && upstreamNode == downstreamNode); |
-} |
- |
-static PassRefPtrWillBeRawPtr<EditingStyle> styleFromMatchedRulesAndInlineDecl(const HTMLElement* element) |
-{ |
- RefPtrWillBeRawPtr<EditingStyle> style = EditingStyle::create(element->inlineStyle()); |
- // FIXME: Having to const_cast here is ugly, but it is quite a bit of work to untangle |
- // the non-const-ness of styleFromMatchedRulesForElement. |
- style->mergeStyleFromRules(const_cast<HTMLElement*>(element)); |
- return style.release(); |
-} |
- |
static bool isPresentationalHTMLElement(const Node* node) |
{ |
if (!node->isHTMLElement()) |
@@ -263,7 +245,6 @@ static String createMarkupInternal(const Position& startPosition, const Position |
ASSERT(startPosition.isNotNull()); |
ASSERT(endPosition.isNotNull()); |
ASSERT(startPosition.compareTo(endPosition) <= 0); |
- DEFINE_STATIC_LOCAL(const String, interchangeNewlineString, ("<br class=\"" AppleInterchangeNewline "\">")); |
bool collapsed = startPosition == endPosition; |
if (collapsed) |
@@ -275,69 +256,9 @@ static String createMarkupInternal(const Position& startPosition, const Position |
Document* document = startPosition.document(); |
document->updateLayoutIgnorePendingStylesheets(); |
- HTMLBodyElement* body = toHTMLBodyElement(enclosingElementWithTag(firstPositionInNode(commonAncestor), bodyTag)); |
- HTMLBodyElement* fullySelectedRoot = nullptr; |
- // FIXME: Do this for all fully selected blocks, not just the body. |
- if (body && areSameRanges(body, startPosition, endPosition)) |
- fullySelectedRoot = body; |
HTMLElement* specialCommonAncestor = highestAncestorToWrapMarkup(startPosition, endPosition, shouldAnnotate, constrainingAncestor); |
- StyledMarkupSerializer accumulator(shouldResolveURLs, shouldAnnotate, startPosition, endPosition, specialCommonAncestor); |
- Node* pastEnd = endPosition.nodeAsRangePastLastNode(); |
- |
- Node* startNode = startPosition.nodeAsRangeFirstNode(); |
- VisiblePosition visibleStart(startPosition, VP_DEFAULT_AFFINITY); |
- VisiblePosition visibleEnd(endPosition, VP_DEFAULT_AFFINITY); |
- if (shouldAnnotate == AnnotateForInterchange && needInterchangeNewlineAfter(visibleStart)) { |
- if (visibleStart == visibleEnd.previous()) |
- return interchangeNewlineString; |
- |
- accumulator.appendString(interchangeNewlineString); |
- startNode = visibleStart.next().deepEquivalent().deprecatedNode(); |
- |
- if (pastEnd && Range::compareBoundaryPoints(startNode, 0, pastEnd, 0, ASSERT_NO_EXCEPTION) >= 0) |
- return interchangeNewlineString; |
- } |
- |
- Node* lastClosed = accumulator.serializeNodes<EditingStrategy>(startNode, pastEnd); |
- |
- if (specialCommonAncestor && lastClosed) { |
- // Also include all of the ancestors of lastClosed up to this special ancestor. |
- for (ContainerNode* ancestor = lastClosed->parentNode(); ancestor; ancestor = ancestor->parentNode()) { |
- 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 |
- // appears to have no effect. |
- if ((!fullySelectedRootStyle || !fullySelectedRootStyle->style() || !fullySelectedRootStyle->style()->getPropertyCSSValue(CSSPropertyBackgroundImage)) |
- && fullySelectedRoot->hasAttribute(backgroundAttr)) |
- fullySelectedRootStyle->style()->setProperty(CSSPropertyBackgroundImage, "url('" + fullySelectedRoot->getAttribute(backgroundAttr) + "')"); |
- |
- if (fullySelectedRootStyle->style()) { |
- // Reset the CSS properties to avoid an assertion error in addStyleMarkup(). |
- // This assertion is caused at least when we select all text of a <body> element whose |
- // 'text-decoration' property is "inherit", and copy it. |
- if (!propertyMissingOrEqualToNone(fullySelectedRootStyle->style(), CSSPropertyTextDecoration)) |
- fullySelectedRootStyle->style()->setProperty(CSSPropertyTextDecoration, CSSValueNone); |
- if (!propertyMissingOrEqualToNone(fullySelectedRootStyle->style(), CSSPropertyWebkitTextDecorationsInEffect)) |
- fullySelectedRootStyle->style()->setProperty(CSSPropertyWebkitTextDecorationsInEffect, CSSValueNone); |
- accumulator.wrapWithStyleNode(fullySelectedRootStyle->style(), true); |
- } |
- } 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. |
- accumulator.wrapWithNode(*ancestor, convertBlocksToInlines, StyledMarkupAccumulator::DoesNotFullySelectNode); |
- } |
- |
- if (ancestor == specialCommonAncestor) |
- break; |
- } |
- } |
- |
- // FIXME: The interchange newline should be placed in the block that it's in, not after all of the content, unconditionally. |
- if (shouldAnnotate == AnnotateForInterchange && needInterchangeNewlineAfter(visibleEnd.previous())) |
- accumulator.appendString(interchangeNewlineString); |
- |
- return accumulator.takeResults(); |
+ StyledMarkupSerializer serializer(shouldResolveURLs, shouldAnnotate, startPosition, endPosition, specialCommonAncestor); |
+ return serializer.createMarkup(convertBlocksToInlines, specialCommonAncestor); |
} |
String createMarkup(const Range* range, EAnnotateForInterchange shouldAnnotate, bool convertBlocksToInlines, EAbsoluteURLs shouldResolveURLs, Node* constrainingAncestor) |