| 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 DEFINE_STATIC_LOCAL(const String, divClose, ("</div>")); | 44 DEFINE_STATIC_LOCAL(const String, divClose, ("</div>")); |
| 45 DEFINE_STATIC_LOCAL(const String, styleSpanClose, ("</span>")); | 45 DEFINE_STATIC_LOCAL(const String, styleSpanClose, ("</span>")); |
| 46 return isBlock ? divClose : styleSpanClose; | 46 return isBlock ? divClose : styleSpanClose; |
| 47 } | 47 } |
| 48 | 48 |
| 49 } // namespace | 49 } // namespace |
| 50 | 50 |
| 51 using namespace HTMLNames; | 51 using namespace HTMLNames; |
| 52 | 52 |
| 53 StyledMarkupAccumulator::StyledMarkupAccumulator(EAbsoluteURLs shouldResolveURLs
, const TextOffset& start, const TextOffset& end, const PassRefPtrWillBeRawPtr<D
ocument> document, EAnnotateForInterchange shouldAnnotate, Node* highestNodeToBe
Serialized, ConvertBlocksToInlines convertBlocksToInlines) | 53 StyledMarkupAccumulator::StyledMarkupAccumulator(EAbsoluteURLs shouldResolveURLs
, const TextOffset& start, const TextOffset& end, const PassRefPtrWillBeRawPtr<D
ocument> document, EAnnotateForInterchange shouldAnnotate, Node* highestNodeToBe
Serialized, ConvertBlocksToInlines convertBlocksToInlines) |
| 54 : m_accumulator(shouldResolveURLs) | 54 : m_formatter(shouldResolveURLs) |
| 55 , m_start(start) | 55 , m_start(start) |
| 56 , m_end(end) | 56 , m_end(end) |
| 57 , m_document(document) | 57 , m_document(document) |
| 58 , m_shouldAnnotate(shouldAnnotate) | 58 , m_shouldAnnotate(shouldAnnotate) |
| 59 , m_convertBlocksToInlines(convertBlocksToInlines) | 59 , m_convertBlocksToInlines(convertBlocksToInlines) |
| 60 , m_highestNodeToBeSerialized(highestNodeToBeSerialized) | 60 , m_highestNodeToBeSerialized(highestNodeToBeSerialized) |
| 61 { | 61 { |
| 62 } | 62 } |
| 63 | 63 |
| 64 void StyledMarkupAccumulator::appendString(const String& str) | 64 void StyledMarkupAccumulator::appendString(const String& str) |
| 65 { | 65 { |
| 66 m_accumulator.appendString(str); | 66 m_result.append(str); |
| 67 } | 67 } |
| 68 | 68 |
| 69 void StyledMarkupAccumulator::appendStartTag(Node& node) | 69 void StyledMarkupAccumulator::appendStartTag(Node& node) |
| 70 { | 70 { |
| 71 StringBuilder out; | 71 appendStartMarkup(m_result, node); |
| 72 appendStartMarkup(out, node); | |
| 73 appendString(out.toString()); | |
| 74 } | 72 } |
| 75 | 73 |
| 76 void StyledMarkupAccumulator::appendEndTag(const Element& element) | 74 void StyledMarkupAccumulator::appendEndTag(const Element& element) |
| 77 { | 75 { |
| 78 StringBuilder out; | 76 appendEndMarkup(m_result, element); |
| 79 appendEndMarkup(out, element); | |
| 80 appendString(out.toString()); | |
| 81 } | 77 } |
| 82 | 78 |
| 83 void StyledMarkupAccumulator::appendStartMarkup(StringBuilder& result, Node& nod
e) | 79 void StyledMarkupAccumulator::appendStartMarkup(StringBuilder& result, Node& nod
e) |
| 84 { | 80 { |
| 85 switch (node.nodeType()) { | 81 switch (node.nodeType()) { |
| 86 case Node::TEXT_NODE: | 82 case Node::TEXT_NODE: |
| 87 appendText(result, toText(node)); | 83 appendText(result, toText(node)); |
| 88 break; | 84 break; |
| 89 case Node::ELEMENT_NODE: | 85 case Node::ELEMENT_NODE: |
| 90 appendElement(result, toElement(node)); | 86 appendElement(result, toElement(node)); |
| 91 break; | 87 break; |
| 92 default: | 88 default: |
| 93 m_accumulator.appendStartMarkup(result, node, nullptr); | 89 m_formatter.appendStartMarkup(result, node, nullptr); |
| 94 break; | 90 break; |
| 95 } | 91 } |
| 96 } | 92 } |
| 97 | 93 |
| 98 void StyledMarkupAccumulator::appendEndMarkup(StringBuilder& result, const Eleme
nt& element) | 94 void StyledMarkupAccumulator::appendEndMarkup(StringBuilder& result, const Eleme
nt& element) |
| 99 { | 95 { |
| 100 m_accumulator.appendEndMarkup(result, element); | 96 m_formatter.appendEndMarkup(result, element); |
| 101 } | 97 } |
| 102 | 98 |
| 103 void StyledMarkupAccumulator::appendText(StringBuilder& out, Text& text) | 99 void StyledMarkupAccumulator::appendText(StringBuilder& out, Text& text) |
| 104 { | 100 { |
| 105 const bool parentIsTextarea = text.parentElement() && text.parentElement()->
tagQName() == textareaTag; | 101 const bool parentIsTextarea = text.parentElement() && text.parentElement()->
tagQName() == textareaTag; |
| 106 const bool wrappingSpan = shouldApplyWrappingStyle(text) && !parentIsTextare
a; | 102 const bool wrappingSpan = shouldApplyWrappingStyle(text) && !parentIsTextare
a; |
| 107 if (wrappingSpan) { | 103 if (wrappingSpan) { |
| 108 RefPtrWillBeRawPtr<EditingStyle> wrappingStyle = m_wrappingStyle->copy()
; | 104 RefPtrWillBeRawPtr<EditingStyle> wrappingStyle = m_wrappingStyle->copy()
; |
| 109 // FIXME: <rdar://problem/5371536> Style rules that match pasted content
can change it's appearance | 105 // FIXME: <rdar://problem/5371536> Style rules that match pasted content
can change it's appearance |
| 110 // Make sure spans are inline style in paste side e.g. span { display: b
lock }. | 106 // Make sure spans are inline style in paste side e.g. span { display: b
lock }. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 122 if (m_end.isNotNull()) { | 118 if (m_end.isNotNull()) { |
| 123 if (text == m_end.text()) | 119 if (text == m_end.text()) |
| 124 length = m_end.offset(); | 120 length = m_end.offset(); |
| 125 } | 121 } |
| 126 if (m_start.isNotNull()) { | 122 if (m_start.isNotNull()) { |
| 127 if (text == m_start.text()) { | 123 if (text == m_start.text()) { |
| 128 start = m_start.offset(); | 124 start = m_start.offset(); |
| 129 length -= start; | 125 length -= start; |
| 130 } | 126 } |
| 131 } | 127 } |
| 132 MarkupFormatter::appendCharactersReplacingEntities(out, str, start, leng
th, m_accumulator.entityMaskForText(text)); | 128 MarkupFormatter::appendCharactersReplacingEntities(out, str, start, leng
th, m_formatter.entityMaskForText(text)); |
| 133 } else { | 129 } else { |
| 134 const bool useRenderedText = !enclosingElementWithTag(firstPositionInNod
e(&text), selectTag); | 130 const bool useRenderedText = !enclosingElementWithTag(firstPositionInNod
e(&text), selectTag); |
| 135 String content = useRenderedText ? renderedText(text) : stringValueForRa
nge(text); | 131 String content = useRenderedText ? renderedText(text) : stringValueForRa
nge(text); |
| 136 StringBuilder buffer; | 132 StringBuilder buffer; |
| 137 MarkupFormatter::appendCharactersReplacingEntities(buffer, content, 0, c
ontent.length(), EntityMaskInPCDATA); | 133 MarkupFormatter::appendCharactersReplacingEntities(buffer, content, 0, c
ontent.length(), EntityMaskInPCDATA); |
| 138 out.append(convertHTMLTextToInterchangeFormat(buffer.toString(), text)); | 134 out.append(convertHTMLTextToInterchangeFormat(buffer.toString(), text)); |
| 139 } | 135 } |
| 140 | 136 |
| 141 if (wrappingSpan) | 137 if (wrappingSpan) |
| 142 out.append(styleNodeCloseTag(false)); | 138 out.append(styleNodeCloseTag(false)); |
| 143 } | 139 } |
| 144 | 140 |
| 145 void StyledMarkupAccumulator::appendElement(StringBuilder& out, Element& element
) | 141 void StyledMarkupAccumulator::appendElement(StringBuilder& out, Element& element
) |
| 146 { | 142 { |
| 147 appendElement(out, element, false, DoesFullySelectNode); | 143 appendElement(out, element, false, DoesFullySelectNode); |
| 148 } | 144 } |
| 149 | 145 |
| 150 void StyledMarkupAccumulator::appendElement(StringBuilder& out, Element& element
, bool addDisplayInline, StyledMarkupAccumulator::RangeFullySelectsNode rangeFul
lySelectsNode) | 146 void StyledMarkupAccumulator::appendElement(StringBuilder& out, Element& element
, bool addDisplayInline, StyledMarkupAccumulator::RangeFullySelectsNode rangeFul
lySelectsNode) |
| 151 { | 147 { |
| 152 const bool documentIsHTML = element.document().isHTMLDocument(); | 148 const bool documentIsHTML = element.document().isHTMLDocument(); |
| 153 m_accumulator.appendOpenTag(out, element, 0); | 149 m_formatter.appendOpenTag(out, element, 0); |
| 154 | 150 |
| 155 const bool shouldAnnotateOrForceInline = element.isHTMLElement() && (shouldA
nnotate() || addDisplayInline); | 151 const bool shouldAnnotateOrForceInline = element.isHTMLElement() && (shouldA
nnotate() || addDisplayInline); |
| 156 const bool shouldOverrideStyleAttr = shouldAnnotateOrForceInline || shouldAp
plyWrappingStyle(element); | 152 const bool shouldOverrideStyleAttr = shouldAnnotateOrForceInline || shouldAp
plyWrappingStyle(element); |
| 157 | 153 |
| 158 AttributeCollection attributes = element.attributes(); | 154 AttributeCollection attributes = element.attributes(); |
| 159 for (const auto& attribute : attributes) { | 155 for (const auto& attribute : attributes) { |
| 160 // We'll handle the style attribute separately, below. | 156 // We'll handle the style attribute separately, below. |
| 161 if (attribute.name() == styleAttr && shouldOverrideStyleAttr) | 157 if (attribute.name() == styleAttr && shouldOverrideStyleAttr) |
| 162 continue; | 158 continue; |
| 163 m_accumulator.appendAttribute(out, element, attribute, nullptr); | 159 m_formatter.appendAttribute(out, element, attribute, nullptr); |
| 164 } | 160 } |
| 165 | 161 |
| 166 if (shouldOverrideStyleAttr) { | 162 if (shouldOverrideStyleAttr) { |
| 167 RefPtrWillBeRawPtr<EditingStyle> newInlineStyle = nullptr; | 163 RefPtrWillBeRawPtr<EditingStyle> newInlineStyle = nullptr; |
| 168 | 164 |
| 169 if (shouldApplyWrappingStyle(element)) { | 165 if (shouldApplyWrappingStyle(element)) { |
| 170 newInlineStyle = m_wrappingStyle->copy(); | 166 newInlineStyle = m_wrappingStyle->copy(); |
| 171 newInlineStyle->removePropertiesInElementDefaultStyle(&element); | 167 newInlineStyle->removePropertiesInElementDefaultStyle(&element); |
| 172 newInlineStyle->removeStyleConflictingWithStyleOfElement(&element); | 168 newInlineStyle->removeStyleConflictingWithStyleOfElement(&element); |
| 173 } else { | 169 } else { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 190 newInlineStyle->style()->removeProperty(CSSPropertyFloat); | 186 newInlineStyle->style()->removeProperty(CSSPropertyFloat); |
| 191 } | 187 } |
| 192 | 188 |
| 193 if (!newInlineStyle->isEmpty()) { | 189 if (!newInlineStyle->isEmpty()) { |
| 194 out.appendLiteral(" style=\""); | 190 out.appendLiteral(" style=\""); |
| 195 MarkupFormatter::appendAttributeValue(out, newInlineStyle->style()->
asText(), documentIsHTML); | 191 MarkupFormatter::appendAttributeValue(out, newInlineStyle->style()->
asText(), documentIsHTML); |
| 196 out.append('\"'); | 192 out.append('\"'); |
| 197 } | 193 } |
| 198 } | 194 } |
| 199 | 195 |
| 200 m_accumulator.appendCloseTag(out, element); | 196 m_formatter.appendCloseTag(out, element); |
| 201 } | 197 } |
| 202 | 198 |
| 203 void StyledMarkupAccumulator::appendStyleNodeOpenTag(StringBuilder& out, StylePr
opertySet* style, bool isBlock) | 199 void StyledMarkupAccumulator::appendStyleNodeOpenTag(StringBuilder& out, StylePr
opertySet* style, bool isBlock) |
| 204 { | 200 { |
| 205 // wrappingStyleForSerialization should have removed -webkit-text-decoration
s-in-effect | 201 // wrappingStyleForSerialization should have removed -webkit-text-decoration
s-in-effect |
| 206 ASSERT(propertyMissingOrEqualToNone(style, CSSPropertyWebkitTextDecorationsI
nEffect)); | 202 ASSERT(propertyMissingOrEqualToNone(style, CSSPropertyWebkitTextDecorationsI
nEffect)); |
| 207 if (isBlock) | 203 if (isBlock) |
| 208 out.appendLiteral("<div style=\""); | 204 out.appendLiteral("<div style=\""); |
| 209 else | 205 else |
| 210 out.appendLiteral("<span style=\""); | 206 out.appendLiteral("<span style=\""); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 229 { | 225 { |
| 230 StringBuilder openTag; | 226 StringBuilder openTag; |
| 231 appendStyleNodeOpenTag(openTag, style, isBlock); | 227 appendStyleNodeOpenTag(openTag, style, isBlock); |
| 232 m_reversedPrecedingMarkup.append(openTag.toString()); | 228 m_reversedPrecedingMarkup.append(openTag.toString()); |
| 233 appendString(styleNodeCloseTag(isBlock)); | 229 appendString(styleNodeCloseTag(isBlock)); |
| 234 } | 230 } |
| 235 | 231 |
| 236 String StyledMarkupAccumulator::takeResults() | 232 String StyledMarkupAccumulator::takeResults() |
| 237 { | 233 { |
| 238 StringBuilder result; | 234 StringBuilder result; |
| 239 result.reserveCapacity(MarkupFormatter::totalLength(m_reversedPrecedingMarku
p) + m_accumulator.length()); | 235 result.reserveCapacity(MarkupFormatter::totalLength(m_reversedPrecedingMarku
p) + m_result.length()); |
| 240 | 236 |
| 241 for (size_t i = m_reversedPrecedingMarkup.size(); i > 0; --i) | 237 for (size_t i = m_reversedPrecedingMarkup.size(); i > 0; --i) |
| 242 result.append(m_reversedPrecedingMarkup[i - 1]); | 238 result.append(m_reversedPrecedingMarkup[i - 1]); |
| 243 | 239 |
| 244 m_accumulator.concatenateMarkup(result); | 240 result.append(m_result); |
| 245 | 241 |
| 246 // We remove '\0' characters because they are not visibly rendered to the us
er. | 242 // We remove '\0' characters because they are not visibly rendered to the us
er. |
| 247 return result.toString().replace(0, ""); | 243 return result.toString().replace(0, ""); |
| 248 } | 244 } |
| 249 | 245 |
| 250 String StyledMarkupAccumulator::renderedText(Text& textNode) | 246 String StyledMarkupAccumulator::renderedText(Text& textNode) |
| 251 { | 247 { |
| 252 int startOffset = 0; | 248 int startOffset = 0; |
| 253 int endOffset = textNode.length(); | 249 int endOffset = textNode.length(); |
| 254 if (m_start.text() == textNode) | 250 if (m_start.text() == textNode) |
| (...skipping 22 matching lines...) Expand all Loading... |
| 277 return m_highestNodeToBeSerialized && m_highestNodeToBeSerialized->parentNod
e() == node.parentNode() | 273 return m_highestNodeToBeSerialized && m_highestNodeToBeSerialized->parentNod
e() == node.parentNode() |
| 278 && m_wrappingStyle && m_wrappingStyle->style(); | 274 && m_wrappingStyle && m_wrappingStyle->style(); |
| 279 } | 275 } |
| 280 | 276 |
| 281 bool StyledMarkupAccumulator::shouldAnnotate() const | 277 bool StyledMarkupAccumulator::shouldAnnotate() const |
| 282 { | 278 { |
| 283 return m_shouldAnnotate == AnnotateForInterchange; | 279 return m_shouldAnnotate == AnnotateForInterchange; |
| 284 } | 280 } |
| 285 | 281 |
| 286 } // namespace blink | 282 } // namespace blink |
| OLD | NEW |