| 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 | 56 |
| 57 void StyledMarkupAccumulator::appendEndTag(const Element& element) | 57 void StyledMarkupAccumulator::appendEndTag(const Element& element) |
| 58 { | 58 { |
| 59 appendEndMarkup(m_result, element); | 59 appendEndMarkup(m_result, element); |
| 60 } | 60 } |
| 61 | 61 |
| 62 void StyledMarkupAccumulator::appendStartMarkup(StringBuilder& result, Node& nod
e) | 62 void StyledMarkupAccumulator::appendStartMarkup(StringBuilder& result, Node& nod
e) |
| 63 { | 63 { |
| 64 switch (node.nodeType()) { | 64 switch (node.nodeType()) { |
| 65 case Node::TEXT_NODE: | 65 case Node::TEXT_NODE: |
| 66 appendText(result, toText(node)); | 66 appendText(toText(node)); |
| 67 break; | 67 break; |
| 68 case Node::ELEMENT_NODE: | 68 case Node::ELEMENT_NODE: { |
| 69 appendElement(result, toElement(node)); | 69 Element& element = toElement(node); |
| 70 RefPtrWillBeRawPtr<EditingStyle> style = createInlineStyle(element, fals
e); |
| 71 appendElement(element, style); |
| 70 break; | 72 break; |
| 73 } |
| 71 default: | 74 default: |
| 72 m_formatter.appendStartMarkup(result, node, nullptr); | 75 m_formatter.appendStartMarkup(result, node, nullptr); |
| 73 break; | 76 break; |
| 74 } | 77 } |
| 75 } | 78 } |
| 76 | 79 |
| 77 void StyledMarkupAccumulator::appendEndMarkup(StringBuilder& result, const Eleme
nt& element) | 80 void StyledMarkupAccumulator::appendEndMarkup(StringBuilder& result, const Eleme
nt& element) |
| 78 { | 81 { |
| 79 m_formatter.appendEndMarkup(result, element); | 82 m_formatter.appendEndMarkup(result, element); |
| 80 } | 83 } |
| 81 | 84 |
| 85 void StyledMarkupAccumulator::appendText(Text& text) |
| 86 { |
| 87 appendText(m_result, text); |
| 88 } |
| 89 |
| 82 void StyledMarkupAccumulator::appendText(StringBuilder& out, Text& text) | 90 void StyledMarkupAccumulator::appendText(StringBuilder& out, Text& text) |
| 83 { | 91 { |
| 84 const bool parentIsTextarea = text.parentElement() && text.parentElement()->
tagQName() == textareaTag; | 92 const bool parentIsTextarea = text.parentElement() && text.parentElement()->
tagQName() == textareaTag; |
| 85 const bool wrappingSpan = shouldApplyWrappingStyle(text) && !parentIsTextare
a; | 93 const bool wrappingSpan = shouldApplyWrappingStyle(text) && !parentIsTextare
a; |
| 86 if (wrappingSpan) { | 94 if (wrappingSpan) { |
| 87 RefPtrWillBeRawPtr<EditingStyle> wrappingStyle = m_wrappingStyle->copy()
; | 95 RefPtrWillBeRawPtr<EditingStyle> wrappingStyle = m_wrappingStyle->copy()
; |
| 88 // FIXME: <rdar://problem/5371536> Style rules that match pasted content
can change it's appearance | 96 // FIXME: <rdar://problem/5371536> Style rules that match pasted content
can change it's appearance |
| 89 // Make sure spans are inline style in paste side e.g. span { display: b
lock }. | 97 // Make sure spans are inline style in paste side e.g. span { display: b
lock }. |
| 90 wrappingStyle->forceInline(); | 98 wrappingStyle->forceInline(); |
| 91 // FIXME: Should this be included in forceInline? | 99 // FIXME: Should this be included in forceInline? |
| (...skipping 28 matching lines...) Expand all Loading... |
| 120 String content = useRenderedText ? renderedText(text) : stringValueForRa
nge(text); | 128 String content = useRenderedText ? renderedText(text) : stringValueForRa
nge(text); |
| 121 StringBuilder buffer; | 129 StringBuilder buffer; |
| 122 MarkupFormatter::appendCharactersReplacingEntities(buffer, content, 0, c
ontent.length(), EntityMaskInPCDATA); | 130 MarkupFormatter::appendCharactersReplacingEntities(buffer, content, 0, c
ontent.length(), EntityMaskInPCDATA); |
| 123 out.append(convertHTMLTextToInterchangeFormat(buffer.toString(), text)); | 131 out.append(convertHTMLTextToInterchangeFormat(buffer.toString(), text)); |
| 124 } | 132 } |
| 125 | 133 |
| 126 if (wrappingSpan) | 134 if (wrappingSpan) |
| 127 out.append("</span>"); | 135 out.append("</span>"); |
| 128 } | 136 } |
| 129 | 137 |
| 130 void StyledMarkupAccumulator::appendElement(StringBuilder& out, Element& element
) | 138 void StyledMarkupAccumulator::appendElement(Element& element, PassRefPtrWillBeRa
wPtr<EditingStyle> style) |
| 131 { | 139 { |
| 132 appendElement(out, element, false, DoesFullySelectNode); | 140 appendElement(m_result, element, false, style); |
| 133 } | 141 } |
| 134 | 142 |
| 135 RefPtrWillBeRawPtr<EditingStyle> StyledMarkupAccumulator::createInlineStyle(Elem
ent& element, bool addDisplayInline, StyledMarkupAccumulator::RangeFullySelectsN
ode rangeFullySelectsNode) | 143 RefPtrWillBeRawPtr<EditingStyle> StyledMarkupAccumulator::createInlineStyle(Elem
ent& element, bool addDisplayInline) |
| 136 { | 144 { |
| 137 const bool shouldAnnotateOrForceInline = element.isHTMLElement() && (shouldA
nnotate() || addDisplayInline); | 145 const bool shouldAnnotateOrForceInline = element.isHTMLElement() && (shouldA
nnotate() || addDisplayInline); |
| 138 | 146 |
| 139 RefPtrWillBeRawPtr<EditingStyle> inlineStyle = nullptr; | 147 RefPtrWillBeRawPtr<EditingStyle> inlineStyle = nullptr; |
| 140 | 148 |
| 141 if (shouldApplyWrappingStyle(element)) { | 149 if (shouldApplyWrappingStyle(element)) { |
| 142 inlineStyle = m_wrappingStyle->copy(); | 150 inlineStyle = m_wrappingStyle->copy(); |
| 143 inlineStyle->removePropertiesInElementDefaultStyle(&element); | 151 inlineStyle->removePropertiesInElementDefaultStyle(&element); |
| 144 inlineStyle->removeStyleConflictingWithStyleOfElement(&element); | 152 inlineStyle->removeStyleConflictingWithStyleOfElement(&element); |
| 145 } else { | 153 } else { |
| 146 inlineStyle = EditingStyle::create(); | 154 inlineStyle = EditingStyle::create(); |
| 147 } | 155 } |
| 148 | 156 |
| 149 if (element.isStyledElement() && element.inlineStyle()) | 157 if (element.isStyledElement() && element.inlineStyle()) |
| 150 inlineStyle->overrideWithStyle(element.inlineStyle()); | 158 inlineStyle->overrideWithStyle(element.inlineStyle()); |
| 151 | 159 |
| 152 if (!shouldAnnotateOrForceInline) | 160 if (!shouldAnnotateOrForceInline) |
| 153 return inlineStyle; | 161 return inlineStyle; |
| 154 | 162 |
| 155 if (shouldAnnotate()) | 163 if (shouldAnnotate()) |
| 156 inlineStyle->mergeStyleFromRulesForSerialization(&toHTMLElement(element)
); | 164 inlineStyle->mergeStyleFromRulesForSerialization(&toHTMLElement(element)
); |
| 157 | 165 |
| 158 if (addDisplayInline) | 166 if (addDisplayInline) |
| 159 inlineStyle->forceInline(); | 167 inlineStyle->forceInline(); |
| 160 | 168 |
| 161 // 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 | |
| 162 // only the ones that affect it and the nodes within it. | |
| 163 if (rangeFullySelectsNode == DoesNotFullySelectNode && inlineStyle->style()) | |
| 164 inlineStyle->style()->removeProperty(CSSPropertyFloat); | |
| 165 return inlineStyle; | 169 return inlineStyle; |
| 166 } | 170 } |
| 167 | 171 |
| 168 void StyledMarkupAccumulator::appendElement(StringBuilder& out, Element& element
, bool addDisplayInline, StyledMarkupAccumulator::RangeFullySelectsNode rangeFul
lySelectsNode) | 172 void StyledMarkupAccumulator::appendElement(StringBuilder& out, Element& element
, bool addDisplayInline, PassRefPtrWillBeRawPtr<EditingStyle> style) |
| 169 { | 173 { |
| 170 const bool documentIsHTML = element.document().isHTMLDocument(); | 174 const bool documentIsHTML = element.document().isHTMLDocument(); |
| 171 m_formatter.appendOpenTag(out, element, 0); | 175 m_formatter.appendOpenTag(out, element, nullptr); |
| 172 | 176 |
| 173 const bool shouldOverrideStyleAttr = (element.isHTMLElement() && (shouldAnno
tate() || addDisplayInline)) || shouldApplyWrappingStyle(element); | 177 const bool shouldOverrideStyleAttr = (element.isHTMLElement() && (shouldAnno
tate() || addDisplayInline)) || shouldApplyWrappingStyle(element); |
| 174 | 178 |
| 175 AttributeCollection attributes = element.attributes(); | 179 AttributeCollection attributes = element.attributes(); |
| 176 for (const auto& attribute : attributes) { | 180 for (const auto& attribute : attributes) { |
| 177 // We'll handle the style attribute separately, below. | 181 // We'll handle the style attribute separately, below. |
| 178 if (attribute.name() == styleAttr && shouldOverrideStyleAttr) | 182 if (attribute.name() == styleAttr && shouldOverrideStyleAttr) |
| 179 continue; | 183 continue; |
| 180 m_formatter.appendAttribute(out, element, attribute, nullptr); | 184 m_formatter.appendAttribute(out, element, attribute, nullptr); |
| 181 } | 185 } |
| 182 | 186 |
| 183 if (shouldOverrideStyleAttr) { | 187 if (shouldOverrideStyleAttr) { |
| 184 RefPtrWillBeRawPtr<EditingStyle> inlineStyle = createInlineStyle(element
, addDisplayInline, rangeFullySelectsNode); | 188 if (style && !style->isEmpty()) { |
| 185 if (!inlineStyle->isEmpty()) { | |
| 186 out.appendLiteral(" style=\""); | 189 out.appendLiteral(" style=\""); |
| 187 MarkupFormatter::appendAttributeValue(out, inlineStyle->style()->asT
ext(), documentIsHTML); | 190 MarkupFormatter::appendAttributeValue(out, style->style()->asText(),
documentIsHTML); |
| 188 out.append('\"'); | 191 out.append('\"'); |
| 189 } | 192 } |
| 190 } | 193 } |
| 191 | 194 |
| 192 m_formatter.appendCloseTag(out, element); | 195 m_formatter.appendCloseTag(out, element); |
| 193 } | 196 } |
| 194 | 197 |
| 195 void StyledMarkupAccumulator::wrapWithStyleNode(StylePropertySet* style) | 198 void StyledMarkupAccumulator::wrapWithStyleNode(StylePropertySet* style) |
| 196 { | 199 { |
| 197 // wrappingStyleForSerialization should have removed -webkit-text-decoration
s-in-effect | 200 // wrappingStyleForSerialization should have removed -webkit-text-decoration
s-in-effect |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 m_reversedPrecedingMarkup.append(str); | 265 m_reversedPrecedingMarkup.append(str); |
| 263 } | 266 } |
| 264 | 267 |
| 265 void StyledMarkupAccumulator::appendInterchangeNewline() | 268 void StyledMarkupAccumulator::appendInterchangeNewline() |
| 266 { | 269 { |
| 267 DEFINE_STATIC_LOCAL(const String, interchangeNewlineString, ("<br class=\""
AppleInterchangeNewline "\">")); | 270 DEFINE_STATIC_LOCAL(const String, interchangeNewlineString, ("<br class=\""
AppleInterchangeNewline "\">")); |
| 268 m_result.append(interchangeNewlineString); | 271 m_result.append(interchangeNewlineString); |
| 269 } | 272 } |
| 270 | 273 |
| 271 } // namespace blink | 274 } // namespace blink |
| OLD | NEW |