| 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 m_formatter.appendStartMarkup(m_result, node, nullptr); |
| 77 case Node::TEXT_NODE: { | |
| 78 Text& text = toText(node); | |
| 79 if (text.parentElement() && text.parentElement()->tagQName() == textarea
Tag) { | |
| 80 appendText(text); | |
| 81 break; | |
| 82 } | |
| 83 appendTextWithInlineStyle(text); | |
| 84 break; | |
| 85 } | |
| 86 case Node::ELEMENT_NODE: { | |
| 87 Element& element = toElement(node); | |
| 88 RefPtrWillBeRawPtr<EditingStyle> style = createInlineStyle(element); | |
| 89 appendElement(element, style); | |
| 90 break; | |
| 91 } | |
| 92 default: | |
| 93 m_formatter.appendStartMarkup(m_result, node, nullptr); | |
| 94 break; | |
| 95 } | |
| 96 } | 72 } |
| 97 | 73 |
| 98 void StyledMarkupAccumulator::appendEndMarkup(StringBuilder& result, const Eleme
nt& element) | 74 void StyledMarkupAccumulator::appendEndMarkup(StringBuilder& result, const Eleme
nt& element) |
| 99 { | 75 { |
| 100 m_formatter.appendEndMarkup(result, element); | 76 m_formatter.appendEndMarkup(result, element); |
| 101 } | 77 } |
| 102 | 78 |
| 103 void StyledMarkupAccumulator::appendText(Text& text) | 79 void StyledMarkupAccumulator::appendText(Text& text) |
| 104 { | 80 { |
| 105 const String& str = text.data(); | 81 const String& str = text.data(); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 | 130 |
| 155 void StyledMarkupAccumulator::appendElement(const Element& element, PassRefPtrWi
llBeRawPtr<EditingStyle> style) | 131 void StyledMarkupAccumulator::appendElement(const Element& element, PassRefPtrWi
llBeRawPtr<EditingStyle> style) |
| 156 { | 132 { |
| 157 if ((element.isHTMLElement() && shouldAnnotate()) || shouldApplyWrappingStyl
e(element)) { | 133 if ((element.isHTMLElement() && shouldAnnotate()) || shouldApplyWrappingStyl
e(element)) { |
| 158 appendElementWithInlineStyle(m_result, element, style); | 134 appendElementWithInlineStyle(m_result, element, style); |
| 159 return; | 135 return; |
| 160 } | 136 } |
| 161 appendElement(m_result, element); | 137 appendElement(m_result, element); |
| 162 } | 138 } |
| 163 | 139 |
| 164 RefPtrWillBeRawPtr<EditingStyle> StyledMarkupAccumulator::createInlineStyle(Elem
ent& element) | |
| 165 { | |
| 166 RefPtrWillBeRawPtr<EditingStyle> inlineStyle = nullptr; | |
| 167 | |
| 168 if (shouldApplyWrappingStyle(element)) { | |
| 169 inlineStyle = m_wrappingStyle->copy(); | |
| 170 inlineStyle->removePropertiesInElementDefaultStyle(&element); | |
| 171 inlineStyle->removeStyleConflictingWithStyleOfElement(&element); | |
| 172 } else { | |
| 173 inlineStyle = EditingStyle::create(); | |
| 174 } | |
| 175 | |
| 176 if (element.isStyledElement() && element.inlineStyle()) | |
| 177 inlineStyle->overrideWithStyle(element.inlineStyle()); | |
| 178 | |
| 179 if (element.isHTMLElement() && shouldAnnotate()) | |
| 180 inlineStyle->mergeStyleFromRulesForSerialization(&toHTMLElement(element)
); | |
| 181 | |
| 182 return inlineStyle; | |
| 183 } | |
| 184 | |
| 185 void StyledMarkupAccumulator::appendElementWithInlineStyle(StringBuilder& out, c
onst Element& element, PassRefPtrWillBeRawPtr<EditingStyle> style) | 140 void StyledMarkupAccumulator::appendElementWithInlineStyle(StringBuilder& out, c
onst Element& element, PassRefPtrWillBeRawPtr<EditingStyle> style) |
| 186 { | 141 { |
| 187 const bool documentIsHTML = element.document().isHTMLDocument(); | 142 const bool documentIsHTML = element.document().isHTMLDocument(); |
| 188 m_formatter.appendOpenTag(out, element, nullptr); | 143 m_formatter.appendOpenTag(out, element, nullptr); |
| 189 AttributeCollection attributes = element.attributes(); | 144 AttributeCollection attributes = element.attributes(); |
| 190 for (const auto& attribute : attributes) { | 145 for (const auto& attribute : attributes) { |
| 191 // We'll handle the style attribute separately, below. | 146 // We'll handle the style attribute separately, below. |
| 192 if (attribute.name() == styleAttr) | 147 if (attribute.name() == styleAttr) |
| 193 continue; | 148 continue; |
| 194 m_formatter.appendAttribute(out, element, attribute, nullptr); | 149 m_formatter.appendAttribute(out, element, attribute, nullptr); |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 m_reversedPrecedingMarkup.append(str); | 235 m_reversedPrecedingMarkup.append(str); |
| 281 } | 236 } |
| 282 | 237 |
| 283 void StyledMarkupAccumulator::appendInterchangeNewline() | 238 void StyledMarkupAccumulator::appendInterchangeNewline() |
| 284 { | 239 { |
| 285 DEFINE_STATIC_LOCAL(const String, interchangeNewlineString, ("<br class=\""
AppleInterchangeNewline "\">")); | 240 DEFINE_STATIC_LOCAL(const String, interchangeNewlineString, ("<br class=\""
AppleInterchangeNewline "\">")); |
| 286 m_result.append(interchangeNewlineString); | 241 m_result.append(interchangeNewlineString); |
| 287 } | 242 } |
| 288 | 243 |
| 289 } // namespace blink | 244 } // namespace blink |
| OLD | NEW |