OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2005, 2006 Apple Computer, Inc. All rights reserved. | 2 * Copyright (C) 2005, 2006 Apple Computer, Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 if (!isEndOfBlock(endingSelection().visibleStart())) | 113 if (!isEndOfBlock(endingSelection().visibleStart())) |
114 return false; | 114 return false; |
115 | 115 |
116 return enclosingBlock->hasTagName(h1Tag) || | 116 return enclosingBlock->hasTagName(h1Tag) || |
117 enclosingBlock->hasTagName(h2Tag) || | 117 enclosingBlock->hasTagName(h2Tag) || |
118 enclosingBlock->hasTagName(h3Tag) || | 118 enclosingBlock->hasTagName(h3Tag) || |
119 enclosingBlock->hasTagName(h4Tag) || | 119 enclosingBlock->hasTagName(h4Tag) || |
120 enclosingBlock->hasTagName(h5Tag); | 120 enclosingBlock->hasTagName(h5Tag); |
121 } | 121 } |
122 | 122 |
123 void InsertParagraphSeparatorCommand::getAncestorsInsideBlock(const Node* insert
ionNode, Element* outerBlock, Vector<Element*>& ancestors) | 123 void InsertParagraphSeparatorCommand::getAncestorsInsideBlock(const Node* insert
ionNode, Element* outerBlock, Vector<RefPtr<Element> >& ancestors) |
124 { | 124 { |
125 ancestors.clear(); | 125 ancestors.clear(); |
126 | 126 |
127 // Build up list of ancestors elements between the insertion node and the ou
ter block. | 127 // Build up list of ancestors elements between the insertion node and the ou
ter block. |
128 if (insertionNode != outerBlock) { | 128 if (insertionNode != outerBlock) { |
129 for (Element* n = insertionNode->parentElement(); n && n != outerBlock;
n = n->parentElement()) | 129 for (Element* n = insertionNode->parentElement(); n && n != outerBlock;
n = n->parentElement()) |
130 ancestors.append(n); | 130 ancestors.append(n); |
131 } | 131 } |
132 } | 132 } |
133 | 133 |
134 PassRefPtr<Element> InsertParagraphSeparatorCommand::cloneHierarchyUnderNewBlock
(const Vector<Element*>& ancestors, PassRefPtr<Element> blockToInsert) | 134 PassRefPtr<Element> InsertParagraphSeparatorCommand::cloneHierarchyUnderNewBlock
(const Vector<RefPtr<Element> >& ancestors, PassRefPtr<Element> blockToInsert) |
135 { | 135 { |
136 // Make clones of ancestors in between the start node and the start block. | 136 // Make clones of ancestors in between the start node and the start block. |
137 RefPtr<Element> parent = blockToInsert; | 137 RefPtr<Element> parent = blockToInsert; |
138 for (size_t i = ancestors.size(); i != 0; --i) { | 138 for (size_t i = ancestors.size(); i != 0; --i) { |
139 RefPtr<Element> child = ancestors[i - 1]->cloneElementWithoutChildren(); | 139 RefPtr<Element> child = ancestors[i - 1]->cloneElementWithoutChildren(); |
140 // It should always be okay to remove id from the cloned elements, since
the originals are not deleted. | 140 // It should always be okay to remove id from the cloned elements, since
the originals are not deleted. |
141 child->removeAttribute(idAttr); | 141 child->removeAttribute(idAttr); |
142 appendNode(child, parent); | 142 appendNode(child, parent); |
143 parent = child.release(); | 143 parent = child.release(); |
144 } | 144 } |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 // Most of the time we want to stay at the nesting level of the star
tBlock (e.g., when nesting within lists). However, | 233 // Most of the time we want to stay at the nesting level of the star
tBlock (e.g., when nesting within lists). However, |
234 // for div nodes, this can result in nested div tags that are hard t
o break out of. | 234 // for div nodes, this can result in nested div tags that are hard t
o break out of. |
235 Element* siblingNode = startBlock.get(); | 235 Element* siblingNode = startBlock.get(); |
236 if (blockToInsert->hasTagName(divTag)) | 236 if (blockToInsert->hasTagName(divTag)) |
237 siblingNode = highestVisuallyEquivalentDivBelowRoot(startBlock.g
et()); | 237 siblingNode = highestVisuallyEquivalentDivBelowRoot(startBlock.g
et()); |
238 insertNodeAfter(blockToInsert, siblingNode); | 238 insertNodeAfter(blockToInsert, siblingNode); |
239 } | 239 } |
240 | 240 |
241 // Recreate the same structure in the new paragraph. | 241 // Recreate the same structure in the new paragraph. |
242 | 242 |
243 Vector<Element*> ancestors; | 243 Vector<RefPtr<Element> > ancestors; |
244 getAncestorsInsideBlock(positionOutsideTabSpan(insertionPosition).deprec
atedNode(), startBlock.get(), ancestors); | 244 getAncestorsInsideBlock(positionOutsideTabSpan(insertionPosition).deprec
atedNode(), startBlock.get(), ancestors); |
245 RefPtr<Element> parent = cloneHierarchyUnderNewBlock(ancestors, blockToI
nsert); | 245 RefPtr<Element> parent = cloneHierarchyUnderNewBlock(ancestors, blockToI
nsert); |
246 | 246 |
247 appendBlockPlaceholder(parent); | 247 appendBlockPlaceholder(parent); |
248 | 248 |
249 setEndingSelection(VisibleSelection(firstPositionInNode(parent.get()), D
OWNSTREAM, endingSelection().isDirectional())); | 249 setEndingSelection(VisibleSelection(firstPositionInNode(parent.get()), D
OWNSTREAM, endingSelection().isDirectional())); |
250 return; | 250 return; |
251 } | 251 } |
252 | 252 |
253 | 253 |
(...skipping 18 matching lines...) Expand all Loading... |
272 } else | 272 } else |
273 refNode = insertionPosition.deprecatedNode(); | 273 refNode = insertionPosition.deprecatedNode(); |
274 | 274 |
275 // find ending selection position easily before inserting the paragraph | 275 // find ending selection position easily before inserting the paragraph |
276 insertionPosition = insertionPosition.downstream(); | 276 insertionPosition = insertionPosition.downstream(); |
277 | 277 |
278 insertNodeBefore(blockToInsert, refNode); | 278 insertNodeBefore(blockToInsert, refNode); |
279 | 279 |
280 // Recreate the same structure in the new paragraph. | 280 // Recreate the same structure in the new paragraph. |
281 | 281 |
282 Vector<Element*> ancestors; | 282 Vector<RefPtr<Element> > ancestors; |
283 getAncestorsInsideBlock(positionAvoidingSpecialElementBoundary(positionO
utsideTabSpan(insertionPosition)).deprecatedNode(), startBlock.get(), ancestors)
; | 283 getAncestorsInsideBlock(positionAvoidingSpecialElementBoundary(positionO
utsideTabSpan(insertionPosition)).deprecatedNode(), startBlock.get(), ancestors)
; |
284 | 284 |
285 appendBlockPlaceholder(cloneHierarchyUnderNewBlock(ancestors, blockToIns
ert)); | 285 appendBlockPlaceholder(cloneHierarchyUnderNewBlock(ancestors, blockToIns
ert)); |
286 | 286 |
287 // In this case, we need to set the new ending selection. | 287 // In this case, we need to set the new ending selection. |
288 setEndingSelection(VisibleSelection(insertionPosition, DOWNSTREAM, endin
gSelection().isDirectional())); | 288 setEndingSelection(VisibleSelection(insertionPosition, DOWNSTREAM, endin
gSelection().isDirectional())); |
289 return; | 289 return; |
290 } | 290 } |
291 | 291 |
292 //--------------------------------------------------------------------- | 292 //--------------------------------------------------------------------- |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 if (positionAfterSplit.deprecatedNode()->isTextNode()) | 390 if (positionAfterSplit.deprecatedNode()->isTextNode()) |
391 insertTextIntoNode(toText(positionAfterSplit.containerNode()), 0
, nonBreakingSpaceString()); | 391 insertTextIntoNode(toText(positionAfterSplit.containerNode()), 0
, nonBreakingSpaceString()); |
392 } | 392 } |
393 } | 393 } |
394 | 394 |
395 setEndingSelection(VisibleSelection(firstPositionInNode(blockToInsert.get())
, DOWNSTREAM, endingSelection().isDirectional())); | 395 setEndingSelection(VisibleSelection(firstPositionInNode(blockToInsert.get())
, DOWNSTREAM, endingSelection().isDirectional())); |
396 applyStyleAfterInsertion(startBlock.get()); | 396 applyStyleAfterInsertion(startBlock.get()); |
397 } | 397 } |
398 | 398 |
399 } // namespace WebCore | 399 } // namespace WebCore |
OLD | NEW |