| 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 size_t length = 0; | 44 size_t length = 0; |
| 45 for (const auto& string : strings) | 45 for (const auto& string : strings) |
| 46 length += string.length(); | 46 length += string.length(); |
| 47 return length; | 47 return length; |
| 48 } | 48 } |
| 49 | 49 |
| 50 } // namespace | 50 } // namespace |
| 51 | 51 |
| 52 using namespace HTMLNames; | 52 using namespace HTMLNames; |
| 53 | 53 |
| 54 StyledMarkupAccumulator::StyledMarkupAccumulator(EAbsoluteURLs shouldResolveURLs
, const TextOffset& start, const TextOffset& end, const PassRefPtrWillBeRawPtr<D
ocument> document, EAnnotateForInterchange shouldAnnotate, Node* highestNodeToBe
Serialized) | 54 StyledMarkupAccumulator::StyledMarkupAccumulator(EAbsoluteURLs shouldResolveURLs
, const TextOffset& start, const TextOffset& end, const PassRefPtrWillBeRawPtr<D
ocument> document, EAnnotateForInterchange shouldAnnotate) |
| 55 : m_formatter(shouldResolveURLs) | 55 : m_formatter(shouldResolveURLs) |
| 56 , m_start(start) | 56 , m_start(start) |
| 57 , m_end(end) | 57 , m_end(end) |
| 58 , m_document(document) | 58 , m_document(document) |
| 59 , m_shouldAnnotate(shouldAnnotate) | 59 , m_shouldAnnotate(shouldAnnotate) |
| 60 , m_highestNodeToBeSerialized(highestNodeToBeSerialized) | |
| 61 { | 60 { |
| 62 } | 61 } |
| 63 | 62 |
| 64 void StyledMarkupAccumulator::appendEndTag(const Element& element) | 63 void StyledMarkupAccumulator::appendEndTag(const Element& element) |
| 65 { | 64 { |
| 66 appendEndMarkup(m_result, element); | 65 appendEndMarkup(m_result, element); |
| 67 } | 66 } |
| 68 | 67 |
| 69 void StyledMarkupAccumulator::appendStartMarkup(Node& node) | 68 void StyledMarkupAccumulator::appendStartMarkup(Node& node) |
| 70 { | 69 { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 87 } | 86 } |
| 88 if (m_start.isNotNull()) { | 87 if (m_start.isNotNull()) { |
| 89 if (text == m_start.text()) { | 88 if (text == m_start.text()) { |
| 90 start = m_start.offset(); | 89 start = m_start.offset(); |
| 91 length -= start; | 90 length -= start; |
| 92 } | 91 } |
| 93 } | 92 } |
| 94 MarkupFormatter::appendCharactersReplacingEntities(m_result, str, start, len
gth, m_formatter.entityMaskForText(text)); | 93 MarkupFormatter::appendCharactersReplacingEntities(m_result, str, start, len
gth, m_formatter.entityMaskForText(text)); |
| 95 } | 94 } |
| 96 | 95 |
| 97 void StyledMarkupAccumulator::appendTextWithInlineStyle(Text& text) | 96 void StyledMarkupAccumulator::appendTextWithInlineStyle(Text& text, PassRefPtrWi
llBeRawPtr<EditingStyle> inlineStyle) |
| 98 { | 97 { |
| 99 const bool wrappingSpan = shouldApplyWrappingStyle(text); | 98 if (inlineStyle) { |
| 100 if (wrappingSpan) { | |
| 101 RefPtrWillBeRawPtr<EditingStyle> wrappingStyle = m_wrappingStyle->copy()
; | |
| 102 // FIXME: <rdar://problem/5371536> Style rules that match pasted content
can change it's appearance | |
| 103 // Make sure spans are inline style in paste side e.g. span { display: b
lock }. | |
| 104 wrappingStyle->forceInline(); | |
| 105 // FIXME: Should this be included in forceInline? | |
| 106 wrappingStyle->style()->setProperty(CSSPropertyFloat, CSSValueNone); | |
| 107 | |
| 108 // wrappingStyleForSerialization should have removed -webkit-text-decora
tions-in-effect | 99 // wrappingStyleForSerialization should have removed -webkit-text-decora
tions-in-effect |
| 109 ASSERT(propertyMissingOrEqualToNone(wrappingStyle->style(), CSSPropertyW
ebkitTextDecorationsInEffect)); | 100 ASSERT(propertyMissingOrEqualToNone(inlineStyle->style(), CSSPropertyWeb
kitTextDecorationsInEffect)); |
| 110 ASSERT(m_document); | 101 ASSERT(m_document); |
| 111 | 102 |
| 112 m_result.appendLiteral("<span style=\""); | 103 m_result.appendLiteral("<span style=\""); |
| 113 MarkupFormatter::appendAttributeValue(m_result, wrappingStyle->style()->
asText(), m_document->isHTMLDocument()); | 104 MarkupFormatter::appendAttributeValue(m_result, inlineStyle->style()->as
Text(), m_document->isHTMLDocument()); |
| 114 m_result.appendLiteral("\">"); | 105 m_result.appendLiteral("\">"); |
| 115 } | 106 } |
| 116 | |
| 117 if (!shouldAnnotate()) { | 107 if (!shouldAnnotate()) { |
| 118 appendText(text); | 108 appendText(text); |
| 119 } else { | 109 } else { |
| 120 const bool useRenderedText = !enclosingElementWithTag(firstPositionInNod
e(&text), selectTag); | 110 const bool useRenderedText = !enclosingElementWithTag(firstPositionInNod
e(&text), selectTag); |
| 121 String content = useRenderedText ? renderedText(text) : stringValueForRa
nge(text); | 111 String content = useRenderedText ? renderedText(text) : stringValueForRa
nge(text); |
| 122 StringBuilder buffer; | 112 StringBuilder buffer; |
| 123 MarkupFormatter::appendCharactersReplacingEntities(buffer, content, 0, c
ontent.length(), EntityMaskInPCDATA); | 113 MarkupFormatter::appendCharactersReplacingEntities(buffer, content, 0, c
ontent.length(), EntityMaskInPCDATA); |
| 124 m_result.append(convertHTMLTextToInterchangeFormat(buffer.toString(), te
xt)); | 114 m_result.append(convertHTMLTextToInterchangeFormat(buffer.toString(), te
xt)); |
| 125 } | 115 } |
| 126 | 116 if (inlineStyle) |
| 127 if (wrappingSpan) | |
| 128 m_result.append("</span>"); | 117 m_result.append("</span>"); |
| 129 } | 118 } |
| 130 | 119 |
| 131 void StyledMarkupAccumulator::appendElement(const Element& element, PassRefPtrWi
llBeRawPtr<EditingStyle> style) | 120 void StyledMarkupAccumulator::appendElementWithInlineStyle(const Element& elemen
t, PassRefPtrWillBeRawPtr<EditingStyle> style) |
| 132 { | 121 { |
| 133 if ((element.isHTMLElement() && shouldAnnotate()) || shouldApplyWrappingStyl
e(element)) { | 122 appendElementWithInlineStyle(m_result, element, style); |
| 134 appendElementWithInlineStyle(m_result, element, style); | |
| 135 return; | |
| 136 } | |
| 137 appendElement(m_result, element); | |
| 138 } | 123 } |
| 139 | 124 |
| 140 void StyledMarkupAccumulator::appendElementWithInlineStyle(StringBuilder& out, c
onst Element& element, PassRefPtrWillBeRawPtr<EditingStyle> style) | 125 void StyledMarkupAccumulator::appendElementWithInlineStyle(StringBuilder& out, c
onst Element& element, PassRefPtrWillBeRawPtr<EditingStyle> style) |
| 141 { | 126 { |
| 142 const bool documentIsHTML = element.document().isHTMLDocument(); | 127 const bool documentIsHTML = element.document().isHTMLDocument(); |
| 143 m_formatter.appendOpenTag(out, element, nullptr); | 128 m_formatter.appendOpenTag(out, element, nullptr); |
| 144 AttributeCollection attributes = element.attributes(); | 129 AttributeCollection attributes = element.attributes(); |
| 145 for (const auto& attribute : attributes) { | 130 for (const auto& attribute : attributes) { |
| 146 // We'll handle the style attribute separately, below. | 131 // We'll handle the style attribute separately, below. |
| 147 if (attribute.name() == styleAttr) | 132 if (attribute.name() == styleAttr) |
| 148 continue; | 133 continue; |
| 149 m_formatter.appendAttribute(out, element, attribute, nullptr); | 134 m_formatter.appendAttribute(out, element, attribute, nullptr); |
| 150 } | 135 } |
| 151 if (style && !style->isEmpty()) { | 136 if (style && !style->isEmpty()) { |
| 152 out.appendLiteral(" style=\""); | 137 out.appendLiteral(" style=\""); |
| 153 MarkupFormatter::appendAttributeValue(out, style->style()->asText(), doc
umentIsHTML); | 138 MarkupFormatter::appendAttributeValue(out, style->style()->asText(), doc
umentIsHTML); |
| 154 out.append('\"'); | 139 out.append('\"'); |
| 155 } | 140 } |
| 156 m_formatter.appendCloseTag(out, element); | 141 m_formatter.appendCloseTag(out, element); |
| 157 } | 142 } |
| 158 | 143 |
| 144 void StyledMarkupAccumulator::appendElement(const Element& element) |
| 145 { |
| 146 appendElement(m_result, element); |
| 147 } |
| 148 |
| 159 void StyledMarkupAccumulator::appendElement(StringBuilder& out, const Element& e
lement) | 149 void StyledMarkupAccumulator::appendElement(StringBuilder& out, const Element& e
lement) |
| 160 { | 150 { |
| 161 m_formatter.appendOpenTag(out, element, nullptr); | 151 m_formatter.appendOpenTag(out, element, nullptr); |
| 162 AttributeCollection attributes = element.attributes(); | 152 AttributeCollection attributes = element.attributes(); |
| 163 for (const auto& attribute : attributes) | 153 for (const auto& attribute : attributes) |
| 164 m_formatter.appendAttribute(out, element, attribute, nullptr); | 154 m_formatter.appendAttribute(out, element, attribute, nullptr); |
| 165 m_formatter.appendCloseTag(out, element); | 155 m_formatter.appendCloseTag(out, element); |
| 166 } | 156 } |
| 167 | 157 |
| 168 void StyledMarkupAccumulator::wrapWithStyleNode(StylePropertySet* style) | 158 void StyledMarkupAccumulator::wrapWithStyleNode(StylePropertySet* style) |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 return node.data(); | 201 return node.data(); |
| 212 | 202 |
| 213 String str = node.data(); | 203 String str = node.data(); |
| 214 if (m_start.text() == node) | 204 if (m_start.text() == node) |
| 215 str.truncate(m_end.offset()); | 205 str.truncate(m_end.offset()); |
| 216 if (m_end.text() == node) | 206 if (m_end.text() == node) |
| 217 str.remove(0, m_start.offset()); | 207 str.remove(0, m_start.offset()); |
| 218 return str; | 208 return str; |
| 219 } | 209 } |
| 220 | 210 |
| 221 bool StyledMarkupAccumulator::shouldApplyWrappingStyle(const Node& node) const | |
| 222 { | |
| 223 // TODO(hajimehoshi): Use Strategy | |
| 224 return m_highestNodeToBeSerialized && m_highestNodeToBeSerialized->parentNod
e() == node.parentNode() | |
| 225 && m_wrappingStyle && m_wrappingStyle->style(); | |
| 226 } | |
| 227 | |
| 228 bool StyledMarkupAccumulator::shouldAnnotate() const | 211 bool StyledMarkupAccumulator::shouldAnnotate() const |
| 229 { | 212 { |
| 230 return m_shouldAnnotate == AnnotateForInterchange; | 213 return m_shouldAnnotate == AnnotateForInterchange; |
| 231 } | 214 } |
| 232 | 215 |
| 233 void StyledMarkupAccumulator::pushMarkup(const String& str) | 216 void StyledMarkupAccumulator::pushMarkup(const String& str) |
| 234 { | 217 { |
| 235 m_reversedPrecedingMarkup.append(str); | 218 m_reversedPrecedingMarkup.append(str); |
| 236 } | 219 } |
| 237 | 220 |
| 238 void StyledMarkupAccumulator::appendInterchangeNewline() | 221 void StyledMarkupAccumulator::appendInterchangeNewline() |
| 239 { | 222 { |
| 240 DEFINE_STATIC_LOCAL(const String, interchangeNewlineString, ("<br class=\""
AppleInterchangeNewline "\">")); | 223 DEFINE_STATIC_LOCAL(const String, interchangeNewlineString, ("<br class=\""
AppleInterchangeNewline "\">")); |
| 241 m_result.append(interchangeNewlineString); | 224 m_result.append(interchangeNewlineString); |
| 242 } | 225 } |
| 243 | 226 |
| 244 } // namespace blink | 227 } // namespace blink |
| OLD | NEW |