| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserv
ed. | 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserv
ed. |
| 3 * Copyright (C) 2008, 2009, 2010, 2011 Google Inc. All rights reserved. | 3 * Copyright (C) 2008, 2009, 2010, 2011 Google Inc. All rights reserved. |
| 4 * Copyright (C) 2011 Igalia S.L. | 4 * Copyright (C) 2011 Igalia S.L. |
| 5 * Copyright (C) 2011 Motorola Mobility. All rights reserved. | 5 * Copyright (C) 2011 Motorola Mobility. All rights reserved. |
| 6 * | 6 * |
| 7 * Redistribution and use in source and binary forms, with or without | 7 * Redistribution and use in source and binary forms, with or without |
| 8 * modification, are permitted provided that the following conditions | 8 * modification, are permitted provided that the following conditions |
| 9 * are met: | 9 * are met: |
| 10 * 1. Redistributions of source code must retain the above copyright | 10 * 1. Redistributions of source code must retain the above copyright |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 | 130 |
| 131 if (wrappingSpan) | 131 if (wrappingSpan) |
| 132 out.append("</span>"); | 132 out.append("</span>"); |
| 133 } | 133 } |
| 134 | 134 |
| 135 void StyledMarkupAccumulator::appendElement(StringBuilder& out, Element& element
) | 135 void StyledMarkupAccumulator::appendElement(StringBuilder& out, Element& element
) |
| 136 { | 136 { |
| 137 appendElement(out, element, false, DoesFullySelectNode); | 137 appendElement(out, element, false, DoesFullySelectNode); |
| 138 } | 138 } |
| 139 | 139 |
| 140 RefPtrWillBeRawPtr<EditingStyle> StyledMarkupAccumulator::createInlineStyle(Elem
ent& element, bool addDisplayInline, StyledMarkupAccumulator::RangeFullySelectsN
ode rangeFullySelectsNode) |
| 141 { |
| 142 const bool shouldAnnotateOrForceInline = element.isHTMLElement() && (shouldA
nnotate() || addDisplayInline); |
| 143 |
| 144 RefPtrWillBeRawPtr<EditingStyle> inlineStyle = nullptr; |
| 145 |
| 146 if (shouldApplyWrappingStyle(element)) { |
| 147 inlineStyle = m_wrappingStyle->copy(); |
| 148 inlineStyle->removePropertiesInElementDefaultStyle(&element); |
| 149 inlineStyle->removeStyleConflictingWithStyleOfElement(&element); |
| 150 } else { |
| 151 inlineStyle = EditingStyle::create(); |
| 152 } |
| 153 |
| 154 if (element.isStyledElement() && element.inlineStyle()) |
| 155 inlineStyle->overrideWithStyle(element.inlineStyle()); |
| 156 |
| 157 if (!shouldAnnotateOrForceInline) |
| 158 return inlineStyle; |
| 159 |
| 160 if (shouldAnnotate()) |
| 161 inlineStyle->mergeStyleFromRulesForSerialization(&toHTMLElement(element)
); |
| 162 |
| 163 if (addDisplayInline) |
| 164 inlineStyle->forceInline(); |
| 165 |
| 166 // If the node is not fully selected by the range, then we don't want to kee
p styles that affect its relationship to the nodes around it |
| 167 // only the ones that affect it and the nodes within it. |
| 168 if (rangeFullySelectsNode == DoesNotFullySelectNode && inlineStyle->style()) |
| 169 inlineStyle->style()->removeProperty(CSSPropertyFloat); |
| 170 return inlineStyle; |
| 171 } |
| 172 |
| 140 void StyledMarkupAccumulator::appendElement(StringBuilder& out, Element& element
, bool addDisplayInline, StyledMarkupAccumulator::RangeFullySelectsNode rangeFul
lySelectsNode) | 173 void StyledMarkupAccumulator::appendElement(StringBuilder& out, Element& element
, bool addDisplayInline, StyledMarkupAccumulator::RangeFullySelectsNode rangeFul
lySelectsNode) |
| 141 { | 174 { |
| 142 const bool documentIsHTML = element.document().isHTMLDocument(); | 175 const bool documentIsHTML = element.document().isHTMLDocument(); |
| 143 m_formatter.appendOpenTag(out, element, 0); | 176 m_formatter.appendOpenTag(out, element, 0); |
| 144 | 177 |
| 145 const bool shouldAnnotateOrForceInline = element.isHTMLElement() && (shouldA
nnotate() || addDisplayInline); | 178 const bool shouldOverrideStyleAttr = (element.isHTMLElement() && (shouldAnno
tate() || addDisplayInline)) || shouldApplyWrappingStyle(element); |
| 146 const bool shouldOverrideStyleAttr = shouldAnnotateOrForceInline || shouldAp
plyWrappingStyle(element); | |
| 147 | 179 |
| 148 AttributeCollection attributes = element.attributes(); | 180 AttributeCollection attributes = element.attributes(); |
| 149 for (const auto& attribute : attributes) { | 181 for (const auto& attribute : attributes) { |
| 150 // We'll handle the style attribute separately, below. | 182 // We'll handle the style attribute separately, below. |
| 151 if (attribute.name() == styleAttr && shouldOverrideStyleAttr) | 183 if (attribute.name() == styleAttr && shouldOverrideStyleAttr) |
| 152 continue; | 184 continue; |
| 153 m_formatter.appendAttribute(out, element, attribute, nullptr); | 185 m_formatter.appendAttribute(out, element, attribute, nullptr); |
| 154 } | 186 } |
| 155 | 187 |
| 156 if (shouldOverrideStyleAttr) { | 188 if (shouldOverrideStyleAttr) { |
| 157 RefPtrWillBeRawPtr<EditingStyle> newInlineStyle = nullptr; | 189 RefPtrWillBeRawPtr<EditingStyle> inlineStyle = createInlineStyle(element
, addDisplayInline, rangeFullySelectsNode); |
| 158 | 190 if (!inlineStyle->isEmpty()) { |
| 159 if (shouldApplyWrappingStyle(element)) { | |
| 160 newInlineStyle = m_wrappingStyle->copy(); | |
| 161 newInlineStyle->removePropertiesInElementDefaultStyle(&element); | |
| 162 newInlineStyle->removeStyleConflictingWithStyleOfElement(&element); | |
| 163 } else { | |
| 164 newInlineStyle = EditingStyle::create(); | |
| 165 } | |
| 166 | |
| 167 if (element.isStyledElement() && element.inlineStyle()) | |
| 168 newInlineStyle->overrideWithStyle(element.inlineStyle()); | |
| 169 | |
| 170 if (shouldAnnotateOrForceInline) { | |
| 171 if (shouldAnnotate()) | |
| 172 newInlineStyle->mergeStyleFromRulesForSerialization(&toHTMLEleme
nt(element)); | |
| 173 | |
| 174 if (addDisplayInline) | |
| 175 newInlineStyle->forceInline(); | |
| 176 | |
| 177 // If the node is not fully selected by the range, then we don't wan
t to keep styles that affect its relationship to the nodes around it | |
| 178 // only the ones that affect it and the nodes within it. | |
| 179 if (rangeFullySelectsNode == DoesNotFullySelectNode && newInlineStyl
e->style()) | |
| 180 newInlineStyle->style()->removeProperty(CSSPropertyFloat); | |
| 181 } | |
| 182 | |
| 183 if (!newInlineStyle->isEmpty()) { | |
| 184 out.appendLiteral(" style=\""); | 191 out.appendLiteral(" style=\""); |
| 185 MarkupFormatter::appendAttributeValue(out, newInlineStyle->style()->
asText(), documentIsHTML); | 192 MarkupFormatter::appendAttributeValue(out, inlineStyle->style()->asT
ext(), documentIsHTML); |
| 186 out.append('\"'); | 193 out.append('\"'); |
| 187 } | 194 } |
| 188 } | 195 } |
| 189 | 196 |
| 190 m_formatter.appendCloseTag(out, element); | 197 m_formatter.appendCloseTag(out, element); |
| 191 } | 198 } |
| 192 | 199 |
| 193 void StyledMarkupAccumulator::wrapWithStyleNode(StylePropertySet* style) | 200 void StyledMarkupAccumulator::wrapWithStyleNode(StylePropertySet* style) |
| 194 { | 201 { |
| 195 // wrappingStyleForSerialization should have removed -webkit-text-decoration
s-in-effect | 202 // wrappingStyleForSerialization should have removed -webkit-text-decoration
s-in-effect |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 { | 261 { |
| 255 return m_shouldAnnotate == AnnotateForInterchange; | 262 return m_shouldAnnotate == AnnotateForInterchange; |
| 256 } | 263 } |
| 257 | 264 |
| 258 void StyledMarkupAccumulator::pushMarkup(const String& str) | 265 void StyledMarkupAccumulator::pushMarkup(const String& str) |
| 259 { | 266 { |
| 260 m_reversedPrecedingMarkup.append(str); | 267 m_reversedPrecedingMarkup.append(str); |
| 261 } | 268 } |
| 262 | 269 |
| 263 } // namespace blink | 270 } // namespace blink |
| OLD | NEW |