| 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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, Node* highestNodeToBe
Serialized) |
| 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) | 60 , m_highestNodeToBeSerialized(highestNodeToBeSerialized) |
| 61 { | 61 { |
| 62 } | 62 } |
| 63 | 63 |
| 64 void StyledMarkupAccumulator::appendStartTag(Node& node) | |
| 65 { | |
| 66 appendStartMarkup(node); | |
| 67 } | |
| 68 | |
| 69 void StyledMarkupAccumulator::appendEndTag(const Element& element) | 64 void StyledMarkupAccumulator::appendEndTag(const Element& element) |
| 70 { | 65 { |
| 71 appendEndMarkup(m_result, element); | 66 appendEndMarkup(m_result, element); |
| 72 } | 67 } |
| 73 | 68 |
| 74 void StyledMarkupAccumulator::appendStartMarkup(Node& node) | 69 void StyledMarkupAccumulator::appendStartMarkup(Node& node) |
| 75 { | 70 { |
| 76 switch (node.nodeType()) { | 71 switch (node.nodeType()) { |
| 77 case Node::TEXT_NODE: | |
| 78 appendText(toText(node)); | |
| 79 break; | |
| 80 case Node::ELEMENT_NODE: { | 72 case Node::ELEMENT_NODE: { |
| 81 Element& element = toElement(node); | 73 Element& element = toElement(node); |
| 82 RefPtrWillBeRawPtr<EditingStyle> style = createInlineStyle(element); | 74 RefPtrWillBeRawPtr<EditingStyle> style = createInlineStyle(element); |
| 83 appendElement(element, style); | 75 appendElement(element, style); |
| 84 break; | 76 break; |
| 85 } | 77 } |
| 86 default: | 78 default: |
| 87 m_formatter.appendStartMarkup(m_result, node, nullptr); | 79 m_formatter.appendStartMarkup(m_result, node, nullptr); |
| 88 break; | 80 break; |
| 89 } | 81 } |
| 90 } | 82 } |
| 91 | 83 |
| 92 void StyledMarkupAccumulator::appendEndMarkup(StringBuilder& result, const Eleme
nt& element) | 84 void StyledMarkupAccumulator::appendEndMarkup(StringBuilder& result, const Eleme
nt& element) |
| 93 { | 85 { |
| 94 m_formatter.appendEndMarkup(result, element); | 86 m_formatter.appendEndMarkup(result, element); |
| 95 } | 87 } |
| 96 | 88 |
| 97 void StyledMarkupAccumulator::appendText(Text& text) | 89 void StyledMarkupAccumulator::appendText(Text& text) |
| 98 { | 90 { |
| 99 appendText(m_result, text); | 91 const String& str = text.data(); |
| 92 unsigned length = str.length(); |
| 93 unsigned start = 0; |
| 94 if (m_end.isNotNull()) { |
| 95 if (text == m_end.text()) |
| 96 length = m_end.offset(); |
| 97 } |
| 98 if (m_start.isNotNull()) { |
| 99 if (text == m_start.text()) { |
| 100 start = m_start.offset(); |
| 101 length -= start; |
| 102 } |
| 103 } |
| 104 MarkupFormatter::appendCharactersReplacingEntities(m_result, str, start, len
gth, m_formatter.entityMaskForText(text)); |
| 100 } | 105 } |
| 101 | 106 |
| 102 void StyledMarkupAccumulator::appendText(StringBuilder& out, Text& text) | 107 void StyledMarkupAccumulator::appendTextWithWrappingStyle(Text& text) |
| 103 { | 108 { |
| 104 const bool parentIsTextarea = text.parentElement() && text.parentElement()->
tagQName() == textareaTag; | 109 const bool wrappingSpan = shouldApplyWrappingStyle(text); |
| 105 const bool wrappingSpan = shouldApplyWrappingStyle(text) && !parentIsTextare
a; | |
| 106 if (wrappingSpan) { | 110 if (wrappingSpan) { |
| 107 RefPtrWillBeRawPtr<EditingStyle> wrappingStyle = m_wrappingStyle->copy()
; | 111 RefPtrWillBeRawPtr<EditingStyle> wrappingStyle = m_wrappingStyle->copy()
; |
| 108 // FIXME: <rdar://problem/5371536> Style rules that match pasted content
can change it's appearance | 112 // FIXME: <rdar://problem/5371536> Style rules that match pasted content
can change it's appearance |
| 109 // Make sure spans are inline style in paste side e.g. span { display: b
lock }. | 113 // Make sure spans are inline style in paste side e.g. span { display: b
lock }. |
| 110 wrappingStyle->forceInline(); | 114 wrappingStyle->forceInline(); |
| 111 // FIXME: Should this be included in forceInline? | 115 // FIXME: Should this be included in forceInline? |
| 112 wrappingStyle->style()->setProperty(CSSPropertyFloat, CSSValueNone); | 116 wrappingStyle->style()->setProperty(CSSPropertyFloat, CSSValueNone); |
| 113 | 117 |
| 114 // wrappingStyleForSerialization should have removed -webkit-text-decora
tions-in-effect | 118 // wrappingStyleForSerialization should have removed -webkit-text-decora
tions-in-effect |
| 115 ASSERT(propertyMissingOrEqualToNone(wrappingStyle->style(), CSSPropertyW
ebkitTextDecorationsInEffect)); | 119 ASSERT(propertyMissingOrEqualToNone(wrappingStyle->style(), CSSPropertyW
ebkitTextDecorationsInEffect)); |
| 116 ASSERT(m_document); | 120 ASSERT(m_document); |
| 117 | 121 |
| 118 out.appendLiteral("<span style=\""); | 122 m_result.appendLiteral("<span style=\""); |
| 119 MarkupFormatter::appendAttributeValue(out, wrappingStyle->style()->asTex
t(), m_document->isHTMLDocument()); | 123 MarkupFormatter::appendAttributeValue(m_result, wrappingStyle->style()->
asText(), m_document->isHTMLDocument()); |
| 120 out.appendLiteral("\">"); | 124 m_result.appendLiteral("\">"); |
| 121 } | 125 } |
| 122 | 126 |
| 123 if (!shouldAnnotate() || parentIsTextarea) { | 127 if (!shouldAnnotate()) { |
| 124 const String& str = text.data(); | 128 appendText(text); |
| 125 unsigned length = str.length(); | |
| 126 unsigned start = 0; | |
| 127 if (m_end.isNotNull()) { | |
| 128 if (text == m_end.text()) | |
| 129 length = m_end.offset(); | |
| 130 } | |
| 131 if (m_start.isNotNull()) { | |
| 132 if (text == m_start.text()) { | |
| 133 start = m_start.offset(); | |
| 134 length -= start; | |
| 135 } | |
| 136 } | |
| 137 MarkupFormatter::appendCharactersReplacingEntities(out, str, start, leng
th, m_formatter.entityMaskForText(text)); | |
| 138 } else { | 129 } else { |
| 139 const bool useRenderedText = !enclosingElementWithTag(firstPositionInNod
e(&text), selectTag); | 130 const bool useRenderedText = !enclosingElementWithTag(firstPositionInNod
e(&text), selectTag); |
| 140 String content = useRenderedText ? renderedText(text) : stringValueForRa
nge(text); | 131 String content = useRenderedText ? renderedText(text) : stringValueForRa
nge(text); |
| 141 StringBuilder buffer; | 132 StringBuilder buffer; |
| 142 MarkupFormatter::appendCharactersReplacingEntities(buffer, content, 0, c
ontent.length(), EntityMaskInPCDATA); | 133 MarkupFormatter::appendCharactersReplacingEntities(buffer, content, 0, c
ontent.length(), EntityMaskInPCDATA); |
| 143 out.append(convertHTMLTextToInterchangeFormat(buffer.toString(), text)); | 134 m_result.append(convertHTMLTextToInterchangeFormat(buffer.toString(), te
xt)); |
| 144 } | 135 } |
| 145 | 136 |
| 146 if (wrappingSpan) | 137 if (wrappingSpan) |
| 147 out.append("</span>"); | 138 m_result.append("</span>"); |
| 148 } | 139 } |
| 149 | 140 |
| 150 void StyledMarkupAccumulator::appendElement(const Element& element, PassRefPtrWi
llBeRawPtr<EditingStyle> style) | 141 void StyledMarkupAccumulator::appendElement(const Element& element, PassRefPtrWi
llBeRawPtr<EditingStyle> style) |
| 151 { | 142 { |
| 152 if ((element.isHTMLElement() && shouldAnnotate()) || shouldApplyWrappingStyl
e(element)) { | 143 if ((element.isHTMLElement() && shouldAnnotate()) || shouldApplyWrappingStyl
e(element)) { |
| 153 appendElementWithInlineStyle(m_result, element, style); | 144 appendElementWithInlineStyle(m_result, element, style); |
| 154 return; | 145 return; |
| 155 } | 146 } |
| 156 appendElement(m_result, element); | 147 appendElement(m_result, element); |
| 157 } | 148 } |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 m_reversedPrecedingMarkup.append(str); | 266 m_reversedPrecedingMarkup.append(str); |
| 276 } | 267 } |
| 277 | 268 |
| 278 void StyledMarkupAccumulator::appendInterchangeNewline() | 269 void StyledMarkupAccumulator::appendInterchangeNewline() |
| 279 { | 270 { |
| 280 DEFINE_STATIC_LOCAL(const String, interchangeNewlineString, ("<br class=\""
AppleInterchangeNewline "\">")); | 271 DEFINE_STATIC_LOCAL(const String, interchangeNewlineString, ("<br class=\""
AppleInterchangeNewline "\">")); |
| 281 m_result.append(interchangeNewlineString); | 272 m_result.append(interchangeNewlineString); |
| 282 } | 273 } |
| 283 | 274 |
| 284 } // namespace blink | 275 } // namespace blink |
| OLD | NEW |