| 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 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 // All of the content in the current block after visiblePos is | 312 // All of the content in the current block after visiblePos is |
| 313 // about to be wrapped in a new paragraph element. Add a br before | 313 // about to be wrapped in a new paragraph element. Add a br before |
| 314 // it if visiblePos is at the start of a paragraph so that the | 314 // it if visiblePos is at the start of a paragraph so that the |
| 315 // content will move down a line. | 315 // content will move down a line. |
| 316 if (isStartOfParagraph(visiblePos)) { | 316 if (isStartOfParagraph(visiblePos)) { |
| 317 RefPtrWillBeRawPtr<HTMLBRElement> br = createBreakElement(document()); | 317 RefPtrWillBeRawPtr<HTMLBRElement> br = createBreakElement(document()); |
| 318 insertNodeAt(br.get(), insertionPosition); | 318 insertNodeAt(br.get(), insertionPosition); |
| 319 insertionPosition = positionInParentAfterNode(*br); | 319 insertionPosition = positionInParentAfterNode(*br); |
| 320 // If the insertion point is a break element, there is nothing else | 320 // If the insertion point is a break element, there is nothing else |
| 321 // we need to do. | 321 // we need to do. |
| 322 if (visiblePos.deepEquivalent().anchorNode()->renderer()->isBR()) { | 322 if (visiblePos.deepEquivalent().anchorNode()->layoutObject()->isBR()) { |
| 323 setEndingSelection(VisibleSelection(insertionPosition, DOWNSTREAM, e
ndingSelection().isDirectional())); | 323 setEndingSelection(VisibleSelection(insertionPosition, DOWNSTREAM, e
ndingSelection().isDirectional())); |
| 324 return; | 324 return; |
| 325 } | 325 } |
| 326 } | 326 } |
| 327 | 327 |
| 328 // Move downstream. Typing style code will take care of carrying along the | 328 // Move downstream. Typing style code will take care of carrying along the |
| 329 // style of the upstream position. | 329 // style of the upstream position. |
| 330 insertionPosition = insertionPosition.downstream(); | 330 insertionPosition = insertionPosition.downstream(); |
| 331 | 331 |
| 332 // At this point, the insertionPosition's node could be a container, and we
want to make sure we include | 332 // At this point, the insertionPosition's node could be a container, and we
want to make sure we include |
| (...skipping 10 matching lines...) Expand all Loading... |
| 343 insertionPosition = insertionPosition.upstream(); | 343 insertionPosition = insertionPosition.upstream(); |
| 344 } | 344 } |
| 345 | 345 |
| 346 // Make sure we do not cause a rendered space to become unrendered. | 346 // Make sure we do not cause a rendered space to become unrendered. |
| 347 // FIXME: We need the affinity for pos, but pos.downstream() does not give i
t | 347 // FIXME: We need the affinity for pos, but pos.downstream() does not give i
t |
| 348 Position leadingWhitespace = leadingWhitespacePosition(insertionPosition, VP
_DEFAULT_AFFINITY); | 348 Position leadingWhitespace = leadingWhitespacePosition(insertionPosition, VP
_DEFAULT_AFFINITY); |
| 349 // FIXME: leadingWhitespacePosition is returning the position before preserv
ed newlines for positions | 349 // FIXME: leadingWhitespacePosition is returning the position before preserv
ed newlines for positions |
| 350 // after the preserved newline, causing the newline to be turned into a nbsp
. | 350 // after the preserved newline, causing the newline to be turned into a nbsp
. |
| 351 if (leadingWhitespace.isNotNull() && leadingWhitespace.deprecatedNode()->isT
extNode()) { | 351 if (leadingWhitespace.isNotNull() && leadingWhitespace.deprecatedNode()->isT
extNode()) { |
| 352 Text* textNode = toText(leadingWhitespace.deprecatedNode()); | 352 Text* textNode = toText(leadingWhitespace.deprecatedNode()); |
| 353 ASSERT(!textNode->renderer() || textNode->renderer()->style()->collapseW
hiteSpace()); | 353 ASSERT(!textNode->layoutObject() || textNode->layoutObject()->style()->c
ollapseWhiteSpace()); |
| 354 replaceTextInNodePreservingMarkers(textNode, leadingWhitespace.deprecate
dEditingOffset(), 1, nonBreakingSpaceString()); | 354 replaceTextInNodePreservingMarkers(textNode, leadingWhitespace.deprecate
dEditingOffset(), 1, nonBreakingSpaceString()); |
| 355 } | 355 } |
| 356 | 356 |
| 357 // Split at pos if in the middle of a text node. | 357 // Split at pos if in the middle of a text node. |
| 358 Position positionAfterSplit; | 358 Position positionAfterSplit; |
| 359 if (insertionPosition.anchorType() == Position::PositionIsOffsetInAnchor &&
insertionPosition.containerNode()->isTextNode()) { | 359 if (insertionPosition.anchorType() == Position::PositionIsOffsetInAnchor &&
insertionPosition.containerNode()->isTextNode()) { |
| 360 RefPtrWillBeRawPtr<Text> textNode = toText(insertionPosition.containerNo
de()); | 360 RefPtrWillBeRawPtr<Text> textNode = toText(insertionPosition.containerNo
de()); |
| 361 bool atEnd = static_cast<unsigned>(insertionPosition.offsetInContainerNo
de()) >= textNode->length(); | 361 bool atEnd = static_cast<unsigned>(insertionPosition.offsetInContainerNo
de()) >= textNode->length(); |
| 362 if (insertionPosition.deprecatedEditingOffset() > 0 && !atEnd) { | 362 if (insertionPosition.deprecatedEditingOffset() > 0 && !atEnd) { |
| 363 splitTextNode(textNode, insertionPosition.offsetInContainerNode()); | 363 splitTextNode(textNode, insertionPosition.offsetInContainerNode()); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 410 } | 410 } |
| 411 | 411 |
| 412 moveRemainingSiblingsToNewParent(n, blockToInsert.get(), blockToInsert); | 412 moveRemainingSiblingsToNewParent(n, blockToInsert.get(), blockToInsert); |
| 413 } | 413 } |
| 414 | 414 |
| 415 // Handle whitespace that occurs after the split | 415 // Handle whitespace that occurs after the split |
| 416 if (positionAfterSplit.isNotNull()) { | 416 if (positionAfterSplit.isNotNull()) { |
| 417 document().updateLayoutIgnorePendingStylesheets(); | 417 document().updateLayoutIgnorePendingStylesheets(); |
| 418 if (!positionAfterSplit.isRenderedCharacter()) { | 418 if (!positionAfterSplit.isRenderedCharacter()) { |
| 419 // Clear out all whitespace and insert one non-breaking space | 419 // Clear out all whitespace and insert one non-breaking space |
| 420 ASSERT(!positionAfterSplit.containerNode()->renderer() || positionAf
terSplit.containerNode()->renderer()->style()->collapseWhiteSpace()); | 420 ASSERT(!positionAfterSplit.containerNode()->layoutObject() || positi
onAfterSplit.containerNode()->layoutObject()->style()->collapseWhiteSpace()); |
| 421 deleteInsignificantTextDownstream(positionAfterSplit); | 421 deleteInsignificantTextDownstream(positionAfterSplit); |
| 422 if (positionAfterSplit.deprecatedNode()->isTextNode()) | 422 if (positionAfterSplit.deprecatedNode()->isTextNode()) |
| 423 insertTextIntoNode(toText(positionAfterSplit.containerNode()), 0
, nonBreakingSpaceString()); | 423 insertTextIntoNode(toText(positionAfterSplit.containerNode()), 0
, nonBreakingSpaceString()); |
| 424 } | 424 } |
| 425 } | 425 } |
| 426 | 426 |
| 427 setEndingSelection(VisibleSelection(firstPositionInNode(blockToInsert.get())
, DOWNSTREAM, endingSelection().isDirectional())); | 427 setEndingSelection(VisibleSelection(firstPositionInNode(blockToInsert.get())
, DOWNSTREAM, endingSelection().isDirectional())); |
| 428 applyStyleAfterInsertion(startBlock.get()); | 428 applyStyleAfterInsertion(startBlock.get()); |
| 429 } | 429 } |
| 430 | 430 |
| 431 DEFINE_TRACE(InsertParagraphSeparatorCommand) | 431 DEFINE_TRACE(InsertParagraphSeparatorCommand) |
| 432 { | 432 { |
| 433 visitor->trace(m_style); | 433 visitor->trace(m_style); |
| 434 CompositeEditCommand::trace(visitor); | 434 CompositeEditCommand::trace(visitor); |
| 435 } | 435 } |
| 436 | 436 |
| 437 | 437 |
| 438 } // namespace blink | 438 } // namespace blink |
| OLD | NEW |