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

Unified Diff: Source/core/editing/StyledMarkupAccumulator.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/StyledMarkupAccumulator.cpp
diff --git a/Source/core/editing/StyledMarkupAccumulator.cpp b/Source/core/editing/StyledMarkupAccumulator.cpp
index 66a58e71a528c78a881424db553b44f07b2f7889..d7bd22925d95cab46b6d190ed3e175afc8c80b33 100644
--- a/Source/core/editing/StyledMarkupAccumulator.cpp
+++ b/Source/core/editing/StyledMarkupAccumulator.cpp
@@ -61,11 +61,6 @@ StyledMarkupAccumulator::StyledMarkupAccumulator(EAbsoluteURLs shouldResolveURLs
{
}
-void StyledMarkupAccumulator::appendStartTag(Node& node)
-{
- appendStartMarkup(node);
-}
-
void StyledMarkupAccumulator::appendEndTag(const Element& element)
{
appendEndMarkup(m_result, element);
@@ -73,20 +68,7 @@ void StyledMarkupAccumulator::appendEndTag(const Element& element)
void StyledMarkupAccumulator::appendStartMarkup(Node& node)
{
- switch (node.nodeType()) {
- case Node::TEXT_NODE:
- appendText(toText(node));
- break;
- case Node::ELEMENT_NODE: {
- Element& element = toElement(node);
- RefPtrWillBeRawPtr<EditingStyle> style = createInlineStyle(element);
- appendElement(element, style);
- break;
- }
- default:
- m_formatter.appendStartMarkup(m_result, node, nullptr);
- break;
- }
+ m_formatter.appendStartMarkup(m_result, node, nullptr);
}
void StyledMarkupAccumulator::appendEndMarkup(StringBuilder& result, const Element& element)
@@ -96,64 +78,46 @@ void StyledMarkupAccumulator::appendEndMarkup(StringBuilder& result, const Eleme
void StyledMarkupAccumulator::appendText(Text& text)
{
- appendText(m_result, text);
+ const String& str = text.data();
+ unsigned length = str.length();
+ unsigned start = 0;
+ if (m_end.isNotNull()) {
+ if (text == m_end.text())
+ length = m_end.offset();
+ }
+ if (m_start.isNotNull()) {
+ if (text == m_start.text()) {
+ start = m_start.offset();
+ length -= start;
+ }
+ }
+ MarkupFormatter::appendCharactersReplacingEntities(m_result, str, start, length, m_formatter.entityMaskForText(text));
}
-void StyledMarkupAccumulator::appendText(StringBuilder& out, Text& text)
+void StyledMarkupAccumulator::appendTextWithInlineStyle(Text& text, PassRefPtrWillBeRawPtr<EditingStyle> style)
yosin_UTC9 2015/06/16 08:23:56 better to use |inlineStyle| rather than |style|.
hajimehoshi 2015/06/16 08:58:17 Done.
{
- const bool parentIsTextarea = text.parentElement() && text.parentElement()->tagQName() == textareaTag;
- const bool wrappingSpan = shouldApplyWrappingStyle(text) && !parentIsTextarea;
- if (wrappingSpan) {
- RefPtrWillBeRawPtr<EditingStyle> wrappingStyle = m_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 }.
- wrappingStyle->forceInline();
- // FIXME: Should this be included in forceInline?
- wrappingStyle->style()->setProperty(CSSPropertyFloat, CSSValueNone);
-
+ if (style) {
// wrappingStyleForSerialization should have removed -webkit-text-decorations-in-effect
- ASSERT(propertyMissingOrEqualToNone(wrappingStyle->style(), CSSPropertyWebkitTextDecorationsInEffect));
+ ASSERT(propertyMissingOrEqualToNone(style->style(), CSSPropertyWebkitTextDecorationsInEffect));
ASSERT(m_document);
- out.appendLiteral("<span style=\"");
- MarkupFormatter::appendAttributeValue(out, wrappingStyle->style()->asText(), m_document->isHTMLDocument());
- out.appendLiteral("\">");
+ m_result.appendLiteral("<span style=\"");
+ MarkupFormatter::appendAttributeValue(m_result, style->style()->asText(), m_document->isHTMLDocument());
+ m_result.appendLiteral("\">");
}
- if (!shouldAnnotate() || parentIsTextarea) {
- const String& str = text.data();
- unsigned length = str.length();
- unsigned start = 0;
- if (m_end.isNotNull()) {
- if (text == m_end.text())
- length = m_end.offset();
- }
- if (m_start.isNotNull()) {
- if (text == m_start.text()) {
- start = m_start.offset();
- length -= start;
- }
- }
- MarkupFormatter::appendCharactersReplacingEntities(out, str, start, length, m_formatter.entityMaskForText(text));
+ if (!shouldAnnotate()) {
+ appendText(text);
} else {
const bool useRenderedText = !enclosingElementWithTag(firstPositionInNode(&text), selectTag);
String content = useRenderedText ? renderedText(text) : stringValueForRange(text);
StringBuilder buffer;
MarkupFormatter::appendCharactersReplacingEntities(buffer, content, 0, content.length(), EntityMaskInPCDATA);
- out.append(convertHTMLTextToInterchangeFormat(buffer.toString(), text));
+ m_result.append(convertHTMLTextToInterchangeFormat(buffer.toString(), text));
}
- if (wrappingSpan)
- out.append("</span>");
-}
-
-void StyledMarkupAccumulator::appendElement(const Element& element, PassRefPtrWillBeRawPtr<EditingStyle> style)
-{
- if ((element.isHTMLElement() && shouldAnnotate()) || shouldApplyWrappingStyle(element)) {
- appendElementWithInlineStyle(m_result, element, style);
- return;
- }
- appendElement(m_result, element);
+ if (style)
+ m_result.append("</span>");
}
RefPtrWillBeRawPtr<EditingStyle> StyledMarkupAccumulator::createInlineStyle(Element& element)
@@ -177,6 +141,11 @@ RefPtrWillBeRawPtr<EditingStyle> StyledMarkupAccumulator::createInlineStyle(Elem
return inlineStyle;
}
+void StyledMarkupAccumulator::appendElementWithInlineStyle(const Element& element, PassRefPtrWillBeRawPtr<EditingStyle> style)
+{
+ appendElementWithInlineStyle(m_result, element, style);
+}
+
void StyledMarkupAccumulator::appendElementWithInlineStyle(StringBuilder& out, const Element& element, PassRefPtrWillBeRawPtr<EditingStyle> style)
{
const bool documentIsHTML = element.document().isHTMLDocument();
@@ -196,6 +165,11 @@ void StyledMarkupAccumulator::appendElementWithInlineStyle(StringBuilder& out, c
m_formatter.appendCloseTag(out, element);
}
+void StyledMarkupAccumulator::appendElement(const Element& element)
+{
+ appendElement(m_result, element);
+}
+
void StyledMarkupAccumulator::appendElement(StringBuilder& out, const Element& element)
{
m_formatter.appendOpenTag(out, element, nullptr);

Powered by Google App Engine
This is Rietveld 408576698