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

Unified Diff: Source/core/editing/StyledMarkupAccumulator.cpp

Issue 1175913002: Refactoring: Add StyledMarkupAccumulator::createInlineStyle from appendElement (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: 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
« no previous file with comments | « Source/core/editing/StyledMarkupAccumulator.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/editing/StyledMarkupAccumulator.cpp
diff --git a/Source/core/editing/StyledMarkupAccumulator.cpp b/Source/core/editing/StyledMarkupAccumulator.cpp
index f71a0b714b9d72c82bceda1d5c31c0733d10e329..883a12538833393917445b4828ba826c63a8a3a8 100644
--- a/Source/core/editing/StyledMarkupAccumulator.cpp
+++ b/Source/core/editing/StyledMarkupAccumulator.cpp
@@ -137,13 +137,45 @@ void StyledMarkupAccumulator::appendElement(StringBuilder& out, Element& element
appendElement(out, element, false, DoesFullySelectNode);
}
+RefPtrWillBeRawPtr<EditingStyle> StyledMarkupAccumulator::createInlineStyle(Element& element, bool addDisplayInline, StyledMarkupAccumulator::RangeFullySelectsNode rangeFullySelectsNode)
+{
+ const bool shouldAnnotateOrForceInline = element.isHTMLElement() && (shouldAnnotate() || addDisplayInline);
+
+ 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)
+ return inlineStyle;
+
+ if (shouldAnnotate())
+ inlineStyle->mergeStyleFromRulesForSerialization(&toHTMLElement(element));
+
+ if (addDisplayInline)
+ inlineStyle->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 && inlineStyle->style())
+ inlineStyle->style()->removeProperty(CSSPropertyFloat);
+ return inlineStyle;
+}
+
void StyledMarkupAccumulator::appendElement(StringBuilder& out, Element& element, bool addDisplayInline, StyledMarkupAccumulator::RangeFullySelectsNode rangeFullySelectsNode)
{
const bool documentIsHTML = element.document().isHTMLDocument();
m_formatter.appendOpenTag(out, element, 0);
- const bool shouldAnnotateOrForceInline = element.isHTMLElement() && (shouldAnnotate() || addDisplayInline);
- const bool shouldOverrideStyleAttr = shouldAnnotateOrForceInline || shouldApplyWrappingStyle(element);
+ const bool shouldOverrideStyleAttr = (element.isHTMLElement() && (shouldAnnotate() || addDisplayInline)) || shouldApplyWrappingStyle(element);
AttributeCollection attributes = element.attributes();
for (const auto& attribute : attributes) {
@@ -154,35 +186,10 @@ 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()) {
+ RefPtrWillBeRawPtr<EditingStyle> inlineStyle = createInlineStyle(element, addDisplayInline, rangeFullySelectsNode);
+ if (!inlineStyle->isEmpty()) {
out.appendLiteral(" style=\"");
- MarkupFormatter::appendAttributeValue(out, newInlineStyle->style()->asText(), documentIsHTML);
+ MarkupFormatter::appendAttributeValue(out, inlineStyle->style()->asText(), documentIsHTML);
out.append('\"');
}
}
« no previous file with comments | « Source/core/editing/StyledMarkupAccumulator.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698