| 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 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 | 160 |
| 161 // Delete the current selection. | 161 // Delete the current selection. |
| 162 if (endingSelection().isRange()) { | 162 if (endingSelection().isRange()) { |
| 163 calculateStyleBeforeInsertion(insertionPosition); | 163 calculateStyleBeforeInsertion(insertionPosition); |
| 164 deleteSelection(false, true); | 164 deleteSelection(false, true); |
| 165 insertionPosition = endingSelection().start(); | 165 insertionPosition = endingSelection().start(); |
| 166 affinity = endingSelection().affinity(); | 166 affinity = endingSelection().affinity(); |
| 167 } | 167 } |
| 168 | 168 |
| 169 // FIXME: The parentAnchoredEquivalent conversion needs to be moved into enc
losingBlock. | 169 // FIXME: The parentAnchoredEquivalent conversion needs to be moved into enc
losingBlock. |
| 170 Handle<Element> startBlock = enclosingBlock(insertionPosition.parentAnchored
Equivalent().containerNode().handle().raw()); | 170 Handle<Element> startBlock = enclosingBlock(insertionPosition.parentAnchored
Equivalent().containerNode()); |
| 171 Position canonicalPos = VisiblePosition(insertionPosition).deepEquivalent(); | 171 Position canonicalPos = VisiblePosition(insertionPosition).deepEquivalent(); |
| 172 if (!startBlock | 172 if (!startBlock |
| 173 || !startBlock->nonShadowBoundaryParentNode() | 173 || !startBlock->nonShadowBoundaryParentNode() |
| 174 || isTableCell(startBlock.raw()) | 174 || isTableCell(startBlock) |
| 175 || startBlock->hasTagName(formTag) | 175 || startBlock->hasTagName(formTag) |
| 176 // FIXME: If the node is hidden, we don't have a canonical position so w
e will do the wrong thing for tables and <hr>. https://bugs.webkit.org/show_bug.
cgi?id=40342 | 176 // FIXME: If the node is hidden, we don't have a canonical position so w
e will do the wrong thing for tables and <hr>. https://bugs.webkit.org/show_bug.
cgi?id=40342 |
| 177 || (!canonicalPos.isNull() && canonicalPos.deprecatedNode()->renderer()
&& canonicalPos.deprecatedNode()->renderer()->isTable()) | 177 || (!canonicalPos.isNull() && canonicalPos.deprecatedNode()->renderer()
&& canonicalPos.deprecatedNode()->renderer()->isTable()) |
| 178 || (!canonicalPos.isNull() && canonicalPos.deprecatedNode()->hasTagName(
hrTag))) { | 178 || (!canonicalPos.isNull() && canonicalPos.deprecatedNode()->hasTagName(
hrTag))) { |
| 179 applyCommandToComposite(InsertLineBreakCommand::create(document())); | 179 applyCommandToComposite(InsertLineBreakCommand::create(document())); |
| 180 return; | 180 return; |
| 181 } | 181 } |
| 182 | 182 |
| 183 // Use the leftmost candidate. | 183 // Use the leftmost candidate. |
| 184 insertionPosition = insertionPosition.upstream(); | 184 insertionPosition = insertionPosition.upstream(); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 // represent the paragraph that we're leaving. | 222 // represent the paragraph that we're leaving. |
| 223 Handle<Element> extraBlock = createDefaultParagraphElement(docum
ent()); | 223 Handle<Element> extraBlock = createDefaultParagraphElement(docum
ent()); |
| 224 appendNode(extraBlock, startBlock); | 224 appendNode(extraBlock, startBlock); |
| 225 appendBlockPlaceholder(extraBlock); | 225 appendBlockPlaceholder(extraBlock); |
| 226 } | 226 } |
| 227 appendNode(blockToInsert, startBlock); | 227 appendNode(blockToInsert, startBlock); |
| 228 } else { | 228 } else { |
| 229 // 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 | 229 // 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 |
| 230 // into an unquoted area. We then don't want the newline within the
blockquote or else it will also be quoted. | 230 // into an unquoted area. We then don't want the newline within the
blockquote or else it will also be quoted. |
| 231 if (m_pasteBlockqutoeIntoUnquotedArea) { | 231 if (m_pasteBlockqutoeIntoUnquotedArea) { |
| 232 if (Node* highestBlockquote = highestEnclosingNodeOfType(canonic
alPos, &isMailBlockquote)) | 232 if (Handle<Node> highestBlockquote = highestEnclosingNodeOfType(
canonicalPos, &isMailBlockquote)) |
| 233 startBlock = adoptRawResult(toElement(highestBlockquote)); | 233 startBlock = toElement(highestBlockquote); |
| 234 } | 234 } |
| 235 | 235 |
| 236 // Most of the time we want to stay at the nesting level of the star
tBlock (e.g., when nesting within lists). However, | 236 // Most of the time we want to stay at the nesting level of the star
tBlock (e.g., when nesting within lists). However, |
| 237 // for div nodes, this can result in nested div tags that are hard t
o break out of. | 237 // for div nodes, this can result in nested div tags that are hard t
o break out of. |
| 238 Handle<Element> siblingNode = startBlock; | 238 Handle<Element> siblingNode = startBlock; |
| 239 if (blockToInsert->hasTagName(divTag)) | 239 if (blockToInsert->hasTagName(divTag)) |
| 240 siblingNode = highestVisuallyEquivalentDivBelowRoot(startBlock); | 240 siblingNode = highestVisuallyEquivalentDivBelowRoot(startBlock); |
| 241 insertNodeAfter(blockToInsert, siblingNode); | 241 insertNodeAfter(blockToInsert, siblingNode); |
| 242 } | 242 } |
| 243 | 243 |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 if (isEndOfParagraph(visiblePos) && !lineBreakExistsAtVisiblePosition(visibl
ePos)) | 362 if (isEndOfParagraph(visiblePos) && !lineBreakExistsAtVisiblePosition(visibl
ePos)) |
| 363 appendNode(createBreakElement(document()), blockToInsert); | 363 appendNode(createBreakElement(document()), blockToInsert); |
| 364 | 364 |
| 365 // Move the start node and the siblings of the start node. | 365 // Move the start node and the siblings of the start node. |
| 366 if (VisiblePosition(insertionPosition) != VisiblePosition(positionBeforeNode
(blockToInsert))) { | 366 if (VisiblePosition(insertionPosition) != VisiblePosition(positionBeforeNode
(blockToInsert))) { |
| 367 Handle<Node> n; | 367 Handle<Node> n; |
| 368 if (insertionPosition.containerNode() == startBlock) | 368 if (insertionPosition.containerNode() == startBlock) |
| 369 n = insertionPosition.computeNodeAfterPosition(); | 369 n = insertionPosition.computeNodeAfterPosition(); |
| 370 else { | 370 else { |
| 371 Handle<Node> splitTo = insertionPosition.containerNode(); | 371 Handle<Node> splitTo = insertionPosition.containerNode(); |
| 372 if (splitTo->isTextNode() && insertionPosition.offsetInContainerNode
() >= caretMaxOffset(splitTo.raw())) | 372 if (splitTo->isTextNode() && insertionPosition.offsetInContainerNode
() >= caretMaxOffset(splitTo)) |
| 373 splitTo = NodeTraversal::next(splitTo, startBlock); | 373 splitTo = NodeTraversal::next(splitTo, startBlock); |
| 374 ASSERT(splitTo); | 374 ASSERT(splitTo); |
| 375 splitTreeToNode(splitTo, startBlock); | 375 splitTreeToNode(splitTo, startBlock); |
| 376 | 376 |
| 377 for (n = startBlock->firstChild(); n; n = n->nextSibling()) { | 377 for (n = startBlock->firstChild(); n; n = n->nextSibling()) { |
| 378 HandleScope scope; | 378 HandleScope scope; |
| 379 VisiblePosition beforeNodePosition = positionBeforeNode(n); | 379 VisiblePosition beforeNodePosition = positionBeforeNode(n); |
| 380 if (!beforeNodePosition.isNull() && comparePositions(VisiblePosi
tion(insertionPosition), beforeNodePosition) <= 0) | 380 if (!beforeNodePosition.isNull() && comparePositions(VisiblePosi
tion(insertionPosition), beforeNodePosition) <= 0) |
| 381 break; | 381 break; |
| 382 } | 382 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 395 if (positionAfterSplit.deprecatedNode()->isTextNode()) | 395 if (positionAfterSplit.deprecatedNode()->isTextNode()) |
| 396 insertTextIntoNode(toText(positionAfterSplit.containerNode()), 0
, nonBreakingSpaceString()); | 396 insertTextIntoNode(toText(positionAfterSplit.containerNode()), 0
, nonBreakingSpaceString()); |
| 397 } | 397 } |
| 398 } | 398 } |
| 399 | 399 |
| 400 setEndingSelection(VisibleSelection(firstPositionInNode(blockToInsert), DOWN
STREAM, endingSelection().isDirectional())); | 400 setEndingSelection(VisibleSelection(firstPositionInNode(blockToInsert), DOWN
STREAM, endingSelection().isDirectional())); |
| 401 applyStyleAfterInsertion(startBlock.raw()); | 401 applyStyleAfterInsertion(startBlock.raw()); |
| 402 } | 402 } |
| 403 | 403 |
| 404 } // namespace WebCore | 404 } // namespace WebCore |
| OLD | NEW |