| 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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 // the non-const-ness of styleFromMatchedRulesForElement. | 112 // the non-const-ness of styleFromMatchedRulesForElement. |
| 113 style->mergeStyleFromRules(const_cast<HTMLElement*>(element)); | 113 style->mergeStyleFromRules(const_cast<HTMLElement*>(element)); |
| 114 return style.release(); | 114 return style.release(); |
| 115 } | 115 } |
| 116 | 116 |
| 117 template<typename Strategy> | 117 template<typename Strategy> |
| 118 String StyledMarkupSerializer<Strategy>::createMarkup() | 118 String StyledMarkupSerializer<Strategy>::createMarkup() |
| 119 { | 119 { |
| 120 DEFINE_STATIC_LOCAL(const String, interchangeNewlineString, ("<br class=\""
AppleInterchangeNewline "\">")); | 120 DEFINE_STATIC_LOCAL(const String, interchangeNewlineString, ("<br class=\""
AppleInterchangeNewline "\">")); |
| 121 | 121 |
| 122 StyledMarkupAccumulator markupAccumulator(m_shouldResolveURLs, toTextOffset(
m_start.parentAnchoredEquivalent()), toTextOffset(m_end.parentAnchoredEquivalent
()), m_start.document(), m_shouldAnnotate, m_highestNodeToBeSerialized.get(), m_
convertBlocksToInlines); | 122 StyledMarkupAccumulator markupAccumulator(m_shouldResolveURLs, toTextOffset(
m_start.parentAnchoredEquivalent()), toTextOffset(m_end.parentAnchoredEquivalent
()), m_start.document(), m_shouldAnnotate, m_highestNodeToBeSerialized.get()); |
| 123 | 123 |
| 124 Node* pastEnd = m_end.nodeAsRangePastLastNode(); | 124 Node* pastEnd = m_end.nodeAsRangePastLastNode(); |
| 125 | 125 |
| 126 Node* firstNode = m_start.nodeAsRangeFirstNode(); | 126 Node* firstNode = m_start.nodeAsRangeFirstNode(); |
| 127 VisiblePosition visibleStart(toPositionInDOMTree(m_start), VP_DEFAULT_AFFINI
TY); | 127 VisiblePosition visibleStart(toPositionInDOMTree(m_start), VP_DEFAULT_AFFINI
TY); |
| 128 VisiblePosition visibleEnd(toPositionInDOMTree(m_end), VP_DEFAULT_AFFINITY); | 128 VisiblePosition visibleEnd(toPositionInDOMTree(m_end), VP_DEFAULT_AFFINITY); |
| 129 if (m_shouldAnnotate == AnnotateForInterchange && needInterchangeNewlineAfte
r(visibleStart)) { | 129 if (m_shouldAnnotate == AnnotateForInterchange && needInterchangeNewlineAfte
r(visibleStart)) { |
| 130 if (visibleStart == visibleEnd.previous()) | 130 if (visibleStart == visibleEnd.previous()) |
| 131 return interchangeNewlineString; | 131 return interchangeNewlineString; |
| 132 | 132 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 147 ASSERT(commonAncestor); | 147 ASSERT(commonAncestor); |
| 148 HTMLBodyElement* body = toHTMLBodyElement(enclosingElementWithTag(firstP
ositionInNode(commonAncestor), bodyTag)); | 148 HTMLBodyElement* body = toHTMLBodyElement(enclosingElementWithTag(firstP
ositionInNode(commonAncestor), bodyTag)); |
| 149 HTMLBodyElement* fullySelectedRoot = nullptr; | 149 HTMLBodyElement* fullySelectedRoot = nullptr; |
| 150 // FIXME: Do this for all fully selected blocks, not just the body. | 150 // FIXME: Do this for all fully selected blocks, not just the body. |
| 151 if (body && areSameRanges(body, m_start, m_end)) | 151 if (body && areSameRanges(body, m_start, m_end)) |
| 152 fullySelectedRoot = body; | 152 fullySelectedRoot = body; |
| 153 | 153 |
| 154 // Also include all of the ancestors of lastClosed up to this special an
cestor. | 154 // Also include all of the ancestors of lastClosed up to this special an
cestor. |
| 155 // FIXME: What is ancestor? | 155 // FIXME: What is ancestor? |
| 156 for (ContainerNode* ancestor = Strategy::parent(*lastClosed); ancestor;
ancestor = Strategy::parent(*ancestor)) { | 156 for (ContainerNode* ancestor = Strategy::parent(*lastClosed); ancestor;
ancestor = Strategy::parent(*ancestor)) { |
| 157 if (ancestor == fullySelectedRoot && !markupAccumulator.convertBlock
sToInlines()) { | 157 if (ancestor == fullySelectedRoot && !convertBlocksToInlines()) { |
| 158 RefPtrWillBeRawPtr<EditingStyle> fullySelectedRootStyle = styleF
romMatchedRulesAndInlineDecl(fullySelectedRoot); | 158 RefPtrWillBeRawPtr<EditingStyle> fullySelectedRootStyle = styleF
romMatchedRulesAndInlineDecl(fullySelectedRoot); |
| 159 | 159 |
| 160 // Bring the background attribute over, but not as an attribute
because a background attribute on a div | 160 // Bring the background attribute over, but not as an attribute
because a background attribute on a div |
| 161 // appears to have no effect. | 161 // appears to have no effect. |
| 162 if ((!fullySelectedRootStyle || !fullySelectedRootStyle->style()
|| !fullySelectedRootStyle->style()->getPropertyCSSValue(CSSPropertyBackgroundI
mage)) | 162 if ((!fullySelectedRootStyle || !fullySelectedRootStyle->style()
|| !fullySelectedRootStyle->style()->getPropertyCSSValue(CSSPropertyBackgroundI
mage)) |
| 163 && fullySelectedRoot->hasAttribute(backgroundAttr)) | 163 && fullySelectedRoot->hasAttribute(backgroundAttr)) |
| 164 fullySelectedRootStyle->style()->setProperty(CSSPropertyBack
groundImage, "url('" + fullySelectedRoot->getAttribute(backgroundAttr) + "')"); | 164 fullySelectedRootStyle->style()->setProperty(CSSPropertyBack
groundImage, "url('" + fullySelectedRoot->getAttribute(backgroundAttr) + "')"); |
| 165 | 165 |
| 166 if (fullySelectedRootStyle->style()) { | 166 if (fullySelectedRootStyle->style()) { |
| 167 // Reset the CSS properties to avoid an assertion error in a
ddStyleMarkup(). | 167 // Reset the CSS properties to avoid an assertion error in a
ddStyleMarkup(). |
| 168 // This assertion is caused at least when we select all text
of a <body> element whose | 168 // This assertion is caused at least when we select all text
of a <body> element whose |
| 169 // 'text-decoration' property is "inherit", and copy it. | 169 // 'text-decoration' property is "inherit", and copy it. |
| 170 if (!propertyMissingOrEqualToNone(fullySelectedRootStyle->st
yle(), CSSPropertyTextDecoration)) | 170 if (!propertyMissingOrEqualToNone(fullySelectedRootStyle->st
yle(), CSSPropertyTextDecoration)) |
| 171 fullySelectedRootStyle->style()->setProperty(CSSProperty
TextDecoration, CSSValueNone); | 171 fullySelectedRootStyle->style()->setProperty(CSSProperty
TextDecoration, CSSValueNone); |
| 172 if (!propertyMissingOrEqualToNone(fullySelectedRootStyle->st
yle(), CSSPropertyWebkitTextDecorationsInEffect)) | 172 if (!propertyMissingOrEqualToNone(fullySelectedRootStyle->st
yle(), CSSPropertyWebkitTextDecorationsInEffect)) |
| 173 fullySelectedRootStyle->style()->setProperty(CSSProperty
WebkitTextDecorationsInEffect, CSSValueNone); | 173 fullySelectedRootStyle->style()->setProperty(CSSProperty
WebkitTextDecorationsInEffect, CSSValueNone); |
| 174 markupAccumulator.wrapWithStyleNode(fullySelectedRootStyle->
style()); | 174 markupAccumulator.wrapWithStyleNode(fullySelectedRootStyle->
style()); |
| 175 } | 175 } |
| 176 } else { | 176 } else { |
| 177 // Since this node and all the other ancestors are not in the se
lection we want to set RangeFullySelectsNode to DoesNotFullySelectNode | 177 // Since this node and all the other ancestors are not in the se
lection we want to set RangeFullySelectsNode to DoesNotFullySelectNode |
| 178 // so that styles that affect the exterior of the node are not i
ncluded. | 178 // so that styles that affect the exterior of the node are not i
ncluded. |
| 179 markupAccumulator.wrapWithNode(*ancestor, StyledMarkupAccumulato
r::DoesNotFullySelectNode); | 179 wrapWithNode(markupAccumulator, *ancestor, StyledMarkupAccumulat
or::DoesNotFullySelectNode); |
| 180 } | 180 } |
| 181 | 181 |
| 182 if (ancestor == m_highestNodeToBeSerialized) | 182 if (ancestor == m_highestNodeToBeSerialized) |
| 183 break; | 183 break; |
| 184 } | 184 } |
| 185 } | 185 } |
| 186 | 186 |
| 187 // FIXME: The interchange newline should be placed in the block that it's in
, not after all of the content, unconditionally. | 187 // FIXME: The interchange newline should be placed in the block that it's in
, not after all of the content, unconditionally. |
| 188 if (m_shouldAnnotate == AnnotateForInterchange && needInterchangeNewlineAt(v
isibleEnd)) | 188 if (m_shouldAnnotate == AnnotateForInterchange && needInterchangeNewlineAt(v
isibleEnd)) |
| 189 markupAccumulator.appendString(interchangeNewlineString); | 189 markupAccumulator.appendString(interchangeNewlineString); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 ASSERT(n); | 276 ASSERT(n); |
| 277 Node* lastAncestorClosedOrSelf = Strategy::isDescendantOf(*n, *lastClose
d) ? lastClosed : n; | 277 Node* lastAncestorClosedOrSelf = Strategy::isDescendantOf(*n, *lastClose
d) ? lastClosed : n; |
| 278 for (ContainerNode* parent = Strategy::parent(*lastAncestorClosedOrSelf)
; parent && parent != nextParent; parent = Strategy::parent(*parent)) { | 278 for (ContainerNode* parent = Strategy::parent(*lastAncestorClosedOrSelf)
; parent && parent != nextParent; parent = Strategy::parent(*parent)) { |
| 279 // All ancestors that aren't in the ancestorsToClose list should eit
her be a) unrendered: | 279 // All ancestors that aren't in the ancestorsToClose list should eit
her be a) unrendered: |
| 280 if (!parent->layoutObject()) | 280 if (!parent->layoutObject()) |
| 281 continue; | 281 continue; |
| 282 // or b) ancestors that we never encountered during a pre-order trav
ersal starting at startNode: | 282 // or b) ancestors that we never encountered during a pre-order trav
ersal starting at startNode: |
| 283 ASSERT(startNode); | 283 ASSERT(startNode); |
| 284 ASSERT(Strategy::isDescendantOf(*startNode, *parent)); | 284 ASSERT(Strategy::isDescendantOf(*startNode, *parent)); |
| 285 if (markupAccumulator) | 285 if (markupAccumulator) |
| 286 markupAccumulator->wrapWithNode(*parent); | 286 wrapWithNode(*markupAccumulator, *parent, StyledMarkupAccumulato
r::DoesFullySelectNode); |
| 287 lastClosed = parent; | 287 lastClosed = parent; |
| 288 } | 288 } |
| 289 } | 289 } |
| 290 | 290 |
| 291 return lastClosed; | 291 return lastClosed; |
| 292 } | 292 } |
| 293 | 293 |
| 294 template<typename Strategy> |
| 295 void StyledMarkupSerializer<Strategy>::wrapWithNode(StyledMarkupAccumulator& acc
umulator, ContainerNode& node, StyledMarkupAccumulator::RangeFullySelectsNode ra
ngeFullySelectsNode) |
| 296 { |
| 297 StringBuilder markup; |
| 298 if (node.isElementNode()) |
| 299 accumulator.appendElement(markup, toElement(node), convertBlocksToInline
s() && isBlock(&node), rangeFullySelectsNode); |
| 300 else |
| 301 accumulator.appendStartMarkup(markup, node); |
| 302 accumulator.pushMarkup(markup.toString()); |
| 303 if (!node.isElementNode()) |
| 304 return; |
| 305 accumulator.appendEndTag(toElement(node)); |
| 306 } |
| 307 |
| 294 template class StyledMarkupSerializer<EditingStrategy>; | 308 template class StyledMarkupSerializer<EditingStrategy>; |
| 295 | 309 |
| 296 } // namespace blink | 310 } // namespace blink |
| OLD | NEW |