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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 static Position toPositionInDOMTree(const Position& position) | 73 static Position toPositionInDOMTree(const Position& position) |
74 { | 74 { |
75 return position; | 75 return position; |
76 } | 76 } |
77 | 77 |
78 template<typename Strategy> | 78 template<typename Strategy> |
79 StyledMarkupSerializer<Strategy>::StyledMarkupSerializer(EAbsoluteURLs shouldRes
olveURLs, EAnnotateForInterchange shouldAnnotate, const PositionType& start, con
st PositionType& end, Node* highestNodeToBeSerialized) | 79 StyledMarkupSerializer<Strategy>::StyledMarkupSerializer(EAbsoluteURLs shouldRes
olveURLs, EAnnotateForInterchange shouldAnnotate, const PositionType& start, con
st PositionType& end, Node* highestNodeToBeSerialized) |
80 : m_markupAccumulator(shouldResolveURLs, toTextOffset(start.parentAnchoredEq
uivalent()), toTextOffset(end.parentAnchoredEquivalent()), start.document(), sho
uldAnnotate, highestNodeToBeSerialized) | 80 : m_markupAccumulator(shouldResolveURLs, toTextOffset(start.parentAnchoredEq
uivalent()), toTextOffset(end.parentAnchoredEquivalent()), start.document(), sho
uldAnnotate, highestNodeToBeSerialized) |
81 , m_start(start) | 81 , m_start(start) |
82 , m_end(end) | 82 , m_end(end) |
| 83 , m_shouldAnnotate(shouldAnnotate) |
83 { | 84 { |
84 } | 85 } |
85 | 86 |
86 static bool needInterchangeNewlineAfter(const VisiblePosition& v) | 87 static bool needInterchangeNewlineAfter(const VisiblePosition& v) |
87 { | 88 { |
88 VisiblePosition next = v.next(); | 89 VisiblePosition next = v.next(); |
89 Node* upstreamNode = next.deepEquivalent().upstream().deprecatedNode(); | 90 Node* upstreamNode = next.deepEquivalent().upstream().deprecatedNode(); |
90 Node* downstreamNode = v.deepEquivalent().downstream().deprecatedNode(); | 91 Node* downstreamNode = v.deepEquivalent().downstream().deprecatedNode(); |
91 // Add an interchange newline if a paragraph break is selected and a br won'
t already be added to the markup to represent it. | 92 // Add an interchange newline if a paragraph break is selected and a br won'
t already be added to the markup to represent it. |
92 return isEndOfParagraph(v) && isStartOfParagraph(next) && !(isHTMLBRElement(
*upstreamNode) && upstreamNode == downstreamNode); | 93 return isEndOfParagraph(v) && isStartOfParagraph(next) && !(isHTMLBRElement(
*upstreamNode) && upstreamNode == downstreamNode); |
(...skipping 28 matching lines...) Expand all Loading... |
121 template<typename Strategy> | 122 template<typename Strategy> |
122 String StyledMarkupSerializer<Strategy>::createMarkup(bool convertBlocksToInline
s, Node* specialCommonAncestor) | 123 String StyledMarkupSerializer<Strategy>::createMarkup(bool convertBlocksToInline
s, Node* specialCommonAncestor) |
123 { | 124 { |
124 DEFINE_STATIC_LOCAL(const String, interchangeNewlineString, ("<br class=\""
AppleInterchangeNewline "\">")); | 125 DEFINE_STATIC_LOCAL(const String, interchangeNewlineString, ("<br class=\""
AppleInterchangeNewline "\">")); |
125 | 126 |
126 Node* pastEnd = m_end.nodeAsRangePastLastNode(); | 127 Node* pastEnd = m_end.nodeAsRangePastLastNode(); |
127 | 128 |
128 Node* firstNode = m_start.nodeAsRangeFirstNode(); | 129 Node* firstNode = m_start.nodeAsRangeFirstNode(); |
129 VisiblePosition visibleStart(toPositionInDOMTree(m_start), VP_DEFAULT_AFFINI
TY); | 130 VisiblePosition visibleStart(toPositionInDOMTree(m_start), VP_DEFAULT_AFFINI
TY); |
130 VisiblePosition visibleEnd(toPositionInDOMTree(m_end), VP_DEFAULT_AFFINITY); | 131 VisiblePosition visibleEnd(toPositionInDOMTree(m_end), VP_DEFAULT_AFFINITY); |
131 if (m_markupAccumulator.shouldAnnotateForInterchange() && needInterchangeNew
lineAfter(visibleStart)) { | 132 if (m_shouldAnnotate == AnnotateForInterchange && needInterchangeNewlineAfte
r(visibleStart)) { |
132 if (visibleStart == visibleEnd.previous()) | 133 if (visibleStart == visibleEnd.previous()) |
133 return interchangeNewlineString; | 134 return interchangeNewlineString; |
134 | 135 |
135 m_markupAccumulator.appendString(interchangeNewlineString); | 136 m_markupAccumulator.appendString(interchangeNewlineString); |
136 firstNode = visibleStart.next().deepEquivalent().deprecatedNode(); | 137 firstNode = visibleStart.next().deepEquivalent().deprecatedNode(); |
137 | 138 |
138 if (pastEnd && Strategy::PositionType::beforeNode(firstNode).compareTo(S
trategy::PositionType::beforeNode(pastEnd)) >= 0) { | 139 if (pastEnd && Strategy::PositionType::beforeNode(firstNode).compareTo(S
trategy::PositionType::beforeNode(pastEnd)) >= 0) { |
139 // This condition hits in editing/pasteboard/copy-display-none.html. | 140 // This condition hits in editing/pasteboard/copy-display-none.html. |
140 return interchangeNewlineString; | 141 return interchangeNewlineString; |
141 } | 142 } |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 // so that styles that affect the exterior of the node are not i
ncluded. | 181 // so that styles that affect the exterior of the node are not i
ncluded. |
181 wrapWithNode(*ancestor, convertBlocksToInlines, StyledMarkupAccu
mulator::DoesNotFullySelectNode); | 182 wrapWithNode(*ancestor, convertBlocksToInlines, StyledMarkupAccu
mulator::DoesNotFullySelectNode); |
182 } | 183 } |
183 | 184 |
184 if (ancestor == specialCommonAncestor) | 185 if (ancestor == specialCommonAncestor) |
185 break; | 186 break; |
186 } | 187 } |
187 } | 188 } |
188 | 189 |
189 // FIXME: The interchange newline should be placed in the block that it's in
, not after all of the content, unconditionally. | 190 // FIXME: The interchange newline should be placed in the block that it's in
, not after all of the content, unconditionally. |
190 if (m_markupAccumulator.shouldAnnotateForInterchange() && needInterchangeNew
lineAt(visibleEnd)) | 191 if (m_shouldAnnotate == AnnotateForInterchange && needInterchangeNewlineAt(v
isibleEnd)) |
191 m_markupAccumulator.appendString(interchangeNewlineString); | 192 m_markupAccumulator.appendString(interchangeNewlineString); |
192 | 193 |
193 return takeResults(); | 194 return takeResults(); |
194 } | 195 } |
195 | 196 |
196 template<typename Strategy> | 197 template<typename Strategy> |
197 void StyledMarkupSerializer<Strategy>::wrapWithNode(ContainerNode& node, bool co
nvertBlocksToInlines, typename StyledMarkupAccumulator::RangeFullySelectsNode ra
ngeFullySelectsNode) | 198 void StyledMarkupSerializer<Strategy>::wrapWithNode(ContainerNode& node, bool co
nvertBlocksToInlines, typename StyledMarkupAccumulator::RangeFullySelectsNode ra
ngeFullySelectsNode) |
198 { | 199 { |
199 StringBuilder markup; | 200 StringBuilder markup; |
200 if (node.isElementNode()) | 201 if (node.isElementNode()) |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 template<typename Strategy> | 234 template<typename Strategy> |
234 Node* StyledMarkupSerializer<Strategy>::serializeNodes(Node* startNode, Node* pa
stEnd) | 235 Node* StyledMarkupSerializer<Strategy>::serializeNodes(Node* startNode, Node* pa
stEnd) |
235 { | 236 { |
236 if (!m_markupAccumulator.highestNodeToBeSerialized()) { | 237 if (!m_markupAccumulator.highestNodeToBeSerialized()) { |
237 Node* lastClosed = traverseNodesForSerialization(startNode, pastEnd, DoN
otEmitString); | 238 Node* lastClosed = traverseNodesForSerialization(startNode, pastEnd, DoN
otEmitString); |
238 m_markupAccumulator.setHighestNodeToBeSerialized(lastClosed); | 239 m_markupAccumulator.setHighestNodeToBeSerialized(lastClosed); |
239 } | 240 } |
240 | 241 |
241 Node* highestNodeToBeSerialized = m_markupAccumulator.highestNodeToBeSeriali
zed(); | 242 Node* highestNodeToBeSerialized = m_markupAccumulator.highestNodeToBeSeriali
zed(); |
242 if (highestNodeToBeSerialized && Strategy::parent(*highestNodeToBeSerialized
)) { | 243 if (highestNodeToBeSerialized && Strategy::parent(*highestNodeToBeSerialized
)) { |
243 RefPtrWillBeRawPtr<EditingStyle> wrappingStyle = EditingStyle::wrappingS
tyleForSerialization(Strategy::parent(*highestNodeToBeSerialized), m_markupAccum
ulator.shouldAnnotate()); | 244 bool shouldAnnotate = m_shouldAnnotate == AnnotateForInterchange || m_sh
ouldAnnotate == AnnotateForNavigationTransition; |
244 if (m_markupAccumulator.shouldAnnotateForNavigationTransition()) { | 245 RefPtrWillBeRawPtr<EditingStyle> wrappingStyle = EditingStyle::wrappingS
tyleForSerialization(Strategy::parent(*highestNodeToBeSerialized), shouldAnnotat
e); |
| 246 if (m_shouldAnnotate == AnnotateForNavigationTransition) { |
245 wrappingStyle->style()->removeProperty(CSSPropertyBackgroundColor); | 247 wrappingStyle->style()->removeProperty(CSSPropertyBackgroundColor); |
246 wrappingStyle->style()->removeProperty(CSSPropertyBackgroundImage); | 248 wrappingStyle->style()->removeProperty(CSSPropertyBackgroundImage); |
247 } | 249 } |
248 m_markupAccumulator.setWrappingStyle(wrappingStyle.release()); | 250 m_markupAccumulator.setWrappingStyle(wrappingStyle.release()); |
249 } | 251 } |
250 return traverseNodesForSerialization(startNode, pastEnd, EmitString); | 252 return traverseNodesForSerialization(startNode, pastEnd, EmitString); |
251 } | 253 } |
252 | 254 |
253 template<typename Strategy> | 255 template<typename Strategy> |
254 Node* StyledMarkupSerializer<Strategy>::traverseNodesForSerialization(Node* star
tNode, Node* pastEnd, NodeTraversalMode traversalMode) | 256 Node* StyledMarkupSerializer<Strategy>::traverseNodesForSerialization(Node* star
tNode, Node* pastEnd, NodeTraversalMode traversalMode) |
(...skipping 12 matching lines...) Expand all Loading... |
267 break; | 269 break; |
268 | 270 |
269 next = Strategy::next(*n); | 271 next = Strategy::next(*n); |
270 bool openedTag = false; | 272 bool openedTag = false; |
271 | 273 |
272 if (isBlock(n) && canHaveChildrenForEditing(n) && next == pastEnd) { | 274 if (isBlock(n) && canHaveChildrenForEditing(n) && next == pastEnd) { |
273 // Don't write out empty block containers that aren't fully selected
. | 275 // Don't write out empty block containers that aren't fully selected
. |
274 continue; | 276 continue; |
275 } | 277 } |
276 | 278 |
277 if (!n->layoutObject() && !enclosingElementWithTag(firstPositionInOrBefo
reNode(n), selectTag) && !m_markupAccumulator.shouldAnnotateForNavigationTransit
ion()) { | 279 if (!n->layoutObject() && !enclosingElementWithTag(firstPositionInOrBefo
reNode(n), selectTag) && m_shouldAnnotate != AnnotateForNavigationTransition) { |
278 next = Strategy::nextSkippingChildren(*n); | 280 next = Strategy::nextSkippingChildren(*n); |
279 // Don't skip over pastEnd. | 281 // Don't skip over pastEnd. |
280 if (pastEnd && Strategy::isDescendantOf(*pastEnd, *n)) | 282 if (pastEnd && Strategy::isDescendantOf(*pastEnd, *n)) |
281 next = pastEnd; | 283 next = pastEnd; |
282 } else { | 284 } else { |
283 // Add the node to the markup if we're not skipping the descendants | 285 // Add the node to the markup if we're not skipping the descendants |
284 if (shouldEmit) | 286 if (shouldEmit) |
285 m_markupAccumulator.appendStartTag(*n); | 287 m_markupAccumulator.appendStartTag(*n); |
286 | 288 |
287 // If node has no children, close the tag now. | 289 // If node has no children, close the tag now. |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 } | 332 } |
331 } | 333 } |
332 } | 334 } |
333 | 335 |
334 return lastClosed; | 336 return lastClosed; |
335 } | 337 } |
336 | 338 |
337 template class StyledMarkupSerializer<EditingStrategy>; | 339 template class StyledMarkupSerializer<EditingStrategy>; |
338 | 340 |
339 } // namespace blink | 341 } // namespace blink |
OLD | NEW |