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 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 //--------------------------------------------------------------------- | 194 //--------------------------------------------------------------------- |
195 // Prepare for more general cases. | 195 // Prepare for more general cases. |
196 | 196 |
197 bool isFirstInBlock = isStartOfBlock(visiblePos); | 197 bool isFirstInBlock = isStartOfBlock(visiblePos); |
198 bool isLastInBlock = isEndOfBlock(visiblePos); | 198 bool isLastInBlock = isEndOfBlock(visiblePos); |
199 bool nestNewBlock = false; | 199 bool nestNewBlock = false; |
200 | 200 |
201 // Create block to be inserted. | 201 // Create block to be inserted. |
202 RefPtr<Element> blockToInsert; | 202 RefPtr<Element> blockToInsert; |
203 if (startBlock->isRootEditableElement()) { | 203 if (startBlock->isRootEditableElement()) { |
204 blockToInsert = createDefaultParagraphElement(&document()); | 204 blockToInsert = createDefaultParagraphElement(document()); |
205 nestNewBlock = true; | 205 nestNewBlock = true; |
206 } else if (shouldUseDefaultParagraphElement(startBlock.get())) { | 206 } else if (shouldUseDefaultParagraphElement(startBlock.get())) { |
207 blockToInsert = createDefaultParagraphElement(&document()); | 207 blockToInsert = createDefaultParagraphElement(document()); |
208 } else { | 208 } else { |
209 blockToInsert = startBlock->cloneElementWithoutChildren(); | 209 blockToInsert = startBlock->cloneElementWithoutChildren(); |
210 } | 210 } |
211 | 211 |
212 //--------------------------------------------------------------------- | 212 //--------------------------------------------------------------------- |
213 // Handle case when position is in the last visible position in its block, | 213 // Handle case when position is in the last visible position in its block, |
214 // including when the block is empty. | 214 // including when the block is empty. |
215 if (isLastInBlock) { | 215 if (isLastInBlock) { |
216 if (nestNewBlock) { | 216 if (nestNewBlock) { |
217 if (isFirstInBlock && !lineBreakExistsAtVisiblePosition(visiblePos))
{ | 217 if (isFirstInBlock && !lineBreakExistsAtVisiblePosition(visiblePos))
{ |
218 // The block is empty. Create an empty block to | 218 // The block is empty. Create an empty block to |
219 // represent the paragraph that we're leaving. | 219 // represent the paragraph that we're leaving. |
220 RefPtr<Element> extraBlock = createDefaultParagraphElement(&docu
ment()); | 220 RefPtr<Element> extraBlock = createDefaultParagraphElement(docum
ent()); |
221 appendNode(extraBlock, startBlock); | 221 appendNode(extraBlock, startBlock); |
222 appendBlockPlaceholder(extraBlock); | 222 appendBlockPlaceholder(extraBlock); |
223 } | 223 } |
224 appendNode(blockToInsert, startBlock); | 224 appendNode(blockToInsert, startBlock); |
225 } else { | 225 } else { |
226 // We can get here if we pasted a copied portion of a blockquote wit
h a newline at the end and are trying to paste it | 226 // We can get here if we pasted a copied portion of a blockquote wit
h a newline at the end and are trying to paste it |
227 // into an unquoted area. We then don't want the newline within the
blockquote or else it will also be quoted. | 227 // into an unquoted area. We then don't want the newline within the
blockquote or else it will also be quoted. |
228 if (m_pasteBlockqutoeIntoUnquotedArea) { | 228 if (m_pasteBlockqutoeIntoUnquotedArea) { |
229 if (Node* highestBlockquote = highestEnclosingNodeOfType(canonic
alPos, &isMailBlockquote)) | 229 if (Node* highestBlockquote = highestEnclosingNodeOfType(canonic
alPos, &isMailBlockquote)) |
230 startBlock = toElement(highestBlockquote); | 230 startBlock = toElement(highestBlockquote); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 } | 290 } |
291 | 291 |
292 //--------------------------------------------------------------------- | 292 //--------------------------------------------------------------------- |
293 // Handle the (more complicated) general case, | 293 // Handle the (more complicated) general case, |
294 | 294 |
295 // All of the content in the current block after visiblePos is | 295 // All of the content in the current block after visiblePos is |
296 // about to be wrapped in a new paragraph element. Add a br before | 296 // about to be wrapped in a new paragraph element. Add a br before |
297 // it if visiblePos is at the start of a paragraph so that the | 297 // it if visiblePos is at the start of a paragraph so that the |
298 // content will move down a line. | 298 // content will move down a line. |
299 if (isStartOfParagraph(visiblePos)) { | 299 if (isStartOfParagraph(visiblePos)) { |
300 RefPtr<Element> br = createBreakElement(&document()); | 300 RefPtr<Element> br = createBreakElement(document()); |
301 insertNodeAt(br.get(), insertionPosition); | 301 insertNodeAt(br.get(), insertionPosition); |
302 insertionPosition = positionInParentAfterNode(br.get()); | 302 insertionPosition = positionInParentAfterNode(br.get()); |
303 // If the insertion point is a break element, there is nothing else | 303 // If the insertion point is a break element, there is nothing else |
304 // we need to do. | 304 // we need to do. |
305 if (visiblePos.deepEquivalent().anchorNode()->renderer()->isBR()) { | 305 if (visiblePos.deepEquivalent().anchorNode()->renderer()->isBR()) { |
306 setEndingSelection(VisibleSelection(insertionPosition, DOWNSTREAM, e
ndingSelection().isDirectional())); | 306 setEndingSelection(VisibleSelection(insertionPosition, DOWNSTREAM, e
ndingSelection().isDirectional())); |
307 return; | 307 return; |
308 } | 308 } |
309 } | 309 } |
310 | 310 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 appendNode(blockToInsert.get(), startBlock); | 359 appendNode(blockToInsert.get(), startBlock); |
360 else | 360 else |
361 insertNodeAfter(blockToInsert.get(), startBlock); | 361 insertNodeAfter(blockToInsert.get(), startBlock); |
362 | 362 |
363 document().updateLayoutIgnorePendingStylesheets(); | 363 document().updateLayoutIgnorePendingStylesheets(); |
364 | 364 |
365 // If the paragraph separator was inserted at the end of a paragraph, an emp
ty line must be | 365 // If the paragraph separator was inserted at the end of a paragraph, an emp
ty line must be |
366 // created. All of the nodes, starting at visiblePos, are about to be added
to the new paragraph | 366 // created. All of the nodes, starting at visiblePos, are about to be added
to the new paragraph |
367 // element. If the first node to be inserted won't be one that will hold an
empty line open, add a br. | 367 // element. If the first node to be inserted won't be one that will hold an
empty line open, add a br. |
368 if (isEndOfParagraph(visiblePos) && !lineBreakExistsAtVisiblePosition(visibl
ePos)) | 368 if (isEndOfParagraph(visiblePos) && !lineBreakExistsAtVisiblePosition(visibl
ePos)) |
369 appendNode(createBreakElement(&document()).get(), blockToInsert.get()); | 369 appendNode(createBreakElement(document()).get(), blockToInsert.get()); |
370 | 370 |
371 // Move the start node and the siblings of the start node. | 371 // Move the start node and the siblings of the start node. |
372 if (VisiblePosition(insertionPosition) != VisiblePosition(positionBeforeNode
(blockToInsert.get()))) { | 372 if (VisiblePosition(insertionPosition) != VisiblePosition(positionBeforeNode
(blockToInsert.get()))) { |
373 Node* n; | 373 Node* n; |
374 if (insertionPosition.containerNode() == startBlock) | 374 if (insertionPosition.containerNode() == startBlock) |
375 n = insertionPosition.computeNodeAfterPosition(); | 375 n = insertionPosition.computeNodeAfterPosition(); |
376 else { | 376 else { |
377 Node* splitTo = insertionPosition.containerNode(); | 377 Node* splitTo = insertionPosition.containerNode(); |
378 if (splitTo->isTextNode() && insertionPosition.offsetInContainerNode
() >= caretMaxOffset(splitTo)) | 378 if (splitTo->isTextNode() && insertionPosition.offsetInContainerNode
() >= caretMaxOffset(splitTo)) |
379 splitTo = NodeTraversal::next(splitTo, startBlock.get()); | 379 splitTo = NodeTraversal::next(splitTo, startBlock.get()); |
(...skipping 20 matching lines...) Expand all Loading... |
400 if (positionAfterSplit.deprecatedNode()->isTextNode()) | 400 if (positionAfterSplit.deprecatedNode()->isTextNode()) |
401 insertTextIntoNode(toText(positionAfterSplit.containerNode()), 0
, nonBreakingSpaceString()); | 401 insertTextIntoNode(toText(positionAfterSplit.containerNode()), 0
, nonBreakingSpaceString()); |
402 } | 402 } |
403 } | 403 } |
404 | 404 |
405 setEndingSelection(VisibleSelection(firstPositionInNode(blockToInsert.get())
, DOWNSTREAM, endingSelection().isDirectional())); | 405 setEndingSelection(VisibleSelection(firstPositionInNode(blockToInsert.get())
, DOWNSTREAM, endingSelection().isDirectional())); |
406 applyStyleAfterInsertion(startBlock.get()); | 406 applyStyleAfterInsertion(startBlock.get()); |
407 } | 407 } |
408 | 408 |
409 } // namespace WebCore | 409 } // namespace WebCore |
OLD | NEW |