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