| 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 // We don't want to return a root node (if it happens to be a div, e.g., in
a document fragment) because there are no | 54 // We don't want to return a root node (if it happens to be a div, e.g., in
a document fragment) because there are no |
| 55 // siblings for us to append to. | 55 // siblings for us to append to. |
| 56 while (!curBlock->nextSibling() && isHTMLDivElement(*curBlock->parentElement
()) && curBlock->parentElement()->parentElement()) { | 56 while (!curBlock->nextSibling() && isHTMLDivElement(*curBlock->parentElement
()) && curBlock->parentElement()->parentElement()) { |
| 57 if (curBlock->parentElement()->hasAttributes()) | 57 if (curBlock->parentElement()->hasAttributes()) |
| 58 break; | 58 break; |
| 59 curBlock = curBlock->parentElement(); | 59 curBlock = curBlock->parentElement(); |
| 60 } | 60 } |
| 61 return curBlock; | 61 return curBlock; |
| 62 } | 62 } |
| 63 | 63 |
| 64 InsertParagraphSeparatorCommand::InsertParagraphSeparatorCommand(Document& docum
ent, bool mustUseDefaultParagraphElement, bool pasteBlockqutoeIntoUnquotedArea) | 64 InsertParagraphSeparatorCommand::InsertParagraphSeparatorCommand(Document& docum
ent, bool mustUseDefaultParagraphElement, bool pasteBlockquoteIntoUnquotedArea) |
| 65 : CompositeEditCommand(document) | 65 : CompositeEditCommand(document) |
| 66 , m_mustUseDefaultParagraphElement(mustUseDefaultParagraphElement) | 66 , m_mustUseDefaultParagraphElement(mustUseDefaultParagraphElement) |
| 67 , m_pasteBlockqutoeIntoUnquotedArea(pasteBlockqutoeIntoUnquotedArea) | 67 , m_pasteBlockquoteIntoUnquotedArea(pasteBlockquoteIntoUnquotedArea) |
| 68 { | 68 { |
| 69 } | 69 } |
| 70 | 70 |
| 71 bool InsertParagraphSeparatorCommand::preservesTypingStyle() const | 71 bool InsertParagraphSeparatorCommand::preservesTypingStyle() const |
| 72 { | 72 { |
| 73 return true; | 73 return true; |
| 74 } | 74 } |
| 75 | 75 |
| 76 void InsertParagraphSeparatorCommand::calculateStyleBeforeInsertion(const Positi
on &pos) | 76 void InsertParagraphSeparatorCommand::calculateStyleBeforeInsertion(const Positi
on &pos) |
| 77 { | 77 { |
| 78 // It is only important to set a style to apply later if we're at the bounda
ries of | 78 // It is only important to set a style to apply later if we're at the bounda
ries of |
| 79 // a paragraph. Otherwise, content that is moved as part of the work of the
command | 79 // a paragraph. Otherwise, content that is moved as part of the work of the
command |
| 80 // will lend their styles to the new paragraph without any extra work needed
. | 80 // will lend their styles to the new paragraph without any extra work needed
. |
| 81 VisiblePosition visiblePos(pos, VP_DEFAULT_AFFINITY); | 81 VisiblePosition visiblePos(pos, VP_DEFAULT_AFFINITY); |
| 82 if (!isStartOfParagraph(visiblePos) && !isEndOfParagraph(visiblePos)) | 82 if (!isStartOfParagraph(visiblePos) && !isEndOfParagraph(visiblePos)) |
| 83 return; | 83 return; |
| 84 | 84 |
| 85 ASSERT(pos.isNotNull()); | 85 ASSERT(pos.isNotNull()); |
| 86 m_style = EditingStyle::create(pos); | 86 m_style = EditingStyle::create(pos); |
| 87 m_style->mergeTypingStyle(pos.document()); | 87 m_style->mergeTypingStyle(pos.document()); |
| 88 } | 88 } |
| 89 | 89 |
| 90 void InsertParagraphSeparatorCommand::applyStyleAfterInsertion(Node* originalEnc
losingBlock) | 90 void InsertParagraphSeparatorCommand::applyStyleAfterInsertion(Element* original
EnclosingBlock) |
| 91 { | 91 { |
| 92 // Not only do we break out of header tags, but we also do not preserve the
typing style, | 92 // Not only do we break out of header tags, but we also do not preserve the
typing style, |
| 93 // in order to match other browsers. | 93 // in order to match other browsers. |
| 94 if (originalEnclosingBlock->hasTagName(h1Tag) || | 94 if (originalEnclosingBlock->hasTagName(h1Tag) || |
| 95 originalEnclosingBlock->hasTagName(h2Tag) || | 95 originalEnclosingBlock->hasTagName(h2Tag) || |
| 96 originalEnclosingBlock->hasTagName(h3Tag) || | 96 originalEnclosingBlock->hasTagName(h3Tag) || |
| 97 originalEnclosingBlock->hasTagName(h4Tag) || | 97 originalEnclosingBlock->hasTagName(h4Tag) || |
| 98 originalEnclosingBlock->hasTagName(h5Tag)) | 98 originalEnclosingBlock->hasTagName(h5Tag)) |
| 99 return; | 99 return; |
| 100 | 100 |
| 101 if (!m_style) | 101 if (!m_style) |
| 102 return; | 102 return; |
| 103 | 103 |
| 104 m_style->prepareToApplyAt(endingSelection().start()); | 104 m_style->prepareToApplyAt(endingSelection().start()); |
| 105 if (!m_style->isEmpty()) | 105 if (!m_style->isEmpty()) |
| 106 applyStyle(m_style.get()); | 106 applyStyle(m_style.get()); |
| 107 } | 107 } |
| 108 | 108 |
| 109 bool InsertParagraphSeparatorCommand::shouldUseDefaultParagraphElement(Node* enc
losingBlock) const | 109 bool InsertParagraphSeparatorCommand::shouldUseDefaultParagraphElement(Element*
enclosingBlock) const |
| 110 { | 110 { |
| 111 if (m_mustUseDefaultParagraphElement) | 111 if (m_mustUseDefaultParagraphElement) |
| 112 return true; | 112 return true; |
| 113 | 113 |
| 114 // Assumes that if there was a range selection, it was already deleted. | 114 // Assumes that if there was a range selection, it was already deleted. |
| 115 if (!isEndOfBlock(endingSelection().visibleStart())) | 115 if (!isEndOfBlock(endingSelection().visibleStart())) |
| 116 return false; | 116 return false; |
| 117 | 117 |
| 118 return enclosingBlock->hasTagName(h1Tag) || | 118 return enclosingBlock->hasTagName(h1Tag) || |
| 119 enclosingBlock->hasTagName(h2Tag) || | 119 enclosingBlock->hasTagName(h2Tag) || |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 if (endingSelection().isRange()) { | 161 if (endingSelection().isRange()) { |
| 162 calculateStyleBeforeInsertion(insertionPosition); | 162 calculateStyleBeforeInsertion(insertionPosition); |
| 163 deleteSelection(false, true); | 163 deleteSelection(false, true); |
| 164 insertionPosition = endingSelection().start(); | 164 insertionPosition = endingSelection().start(); |
| 165 affinity = endingSelection().affinity(); | 165 affinity = endingSelection().affinity(); |
| 166 } | 166 } |
| 167 | 167 |
| 168 // FIXME: The parentAnchoredEquivalent conversion needs to be moved into enc
losingBlock. | 168 // FIXME: The parentAnchoredEquivalent conversion needs to be moved into enc
losingBlock. |
| 169 RefPtrWillBeRawPtr<Element> startBlock = enclosingBlock(insertionPosition.pa
rentAnchoredEquivalent().containerNode()); | 169 RefPtrWillBeRawPtr<Element> startBlock = enclosingBlock(insertionPosition.pa
rentAnchoredEquivalent().containerNode()); |
| 170 Node* listChildNode = enclosingListChild(insertionPosition.parentAnchoredEqu
ivalent().containerNode()); | 170 Node* listChildNode = enclosingListChild(insertionPosition.parentAnchoredEqu
ivalent().containerNode()); |
| 171 RefPtrWillBeRawPtr<Element> listChild = listChildNode && listChildNode->isHT
MLElement() ? toHTMLElement(listChildNode) : 0; | 171 RefPtrWillBeRawPtr<HTMLElement> listChild = listChildNode && listChildNode->
isHTMLElement() ? toHTMLElement(listChildNode) : 0; |
| 172 Position canonicalPos = VisiblePosition(insertionPosition).deepEquivalent(); | 172 Position canonicalPos = VisiblePosition(insertionPosition).deepEquivalent(); |
| 173 if (!startBlock | 173 if (!startBlock |
| 174 || !startBlock->nonShadowBoundaryParentNode() | 174 || !startBlock->nonShadowBoundaryParentNode() |
| 175 || isTableCell(startBlock.get()) | 175 || isTableCell(startBlock.get()) |
| 176 || isHTMLFormElement(*startBlock) | 176 || isHTMLFormElement(*startBlock) |
| 177 // 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 // 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 |
| 178 || (!canonicalPos.isNull() && isRenderedTable(canonicalPos.deprecatedNod
e())) | 178 || (!canonicalPos.isNull() && isRenderedTable(canonicalPos.deprecatedNod
e())) |
| 179 || (!canonicalPos.isNull() && isHTMLHRElement(*canonicalPos.deprecatedNo
de()))) { | 179 || (!canonicalPos.isNull() && isHTMLHRElement(*canonicalPos.deprecatedNo
de()))) { |
| 180 applyCommandToComposite(InsertLineBreakCommand::create(document())); | 180 applyCommandToComposite(InsertLineBreakCommand::create(document())); |
| 181 return; | 181 return; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 } | 215 } |
| 216 | 216 |
| 217 //--------------------------------------------------------------------- | 217 //--------------------------------------------------------------------- |
| 218 // Handle case when position is in the last visible position in its block, | 218 // Handle case when position is in the last visible position in its block, |
| 219 // including when the block is empty. | 219 // including when the block is empty. |
| 220 if (isLastInBlock) { | 220 if (isLastInBlock) { |
| 221 if (nestNewBlock) { | 221 if (nestNewBlock) { |
| 222 if (isFirstInBlock && !lineBreakExistsAtVisiblePosition(visiblePos))
{ | 222 if (isFirstInBlock && !lineBreakExistsAtVisiblePosition(visiblePos))
{ |
| 223 // The block is empty. Create an empty block to | 223 // The block is empty. Create an empty block to |
| 224 // represent the paragraph that we're leaving. | 224 // represent the paragraph that we're leaving. |
| 225 RefPtrWillBeRawPtr<Element> extraBlock = createDefaultParagraphE
lement(document()); | 225 RefPtrWillBeRawPtr<HTMLElement> extraBlock = createDefaultParagr
aphElement(document()); |
| 226 appendNode(extraBlock, startBlock); | 226 appendNode(extraBlock, startBlock); |
| 227 appendBlockPlaceholder(extraBlock); | 227 appendBlockPlaceholder(extraBlock); |
| 228 } | 228 } |
| 229 appendNode(blockToInsert, startBlock); | 229 appendNode(blockToInsert, startBlock); |
| 230 } else { | 230 } else { |
| 231 // 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 | 231 // 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 |
| 232 // into an unquoted area. We then don't want the newline within the
blockquote or else it will also be quoted. | 232 // into an unquoted area. We then don't want the newline within the
blockquote or else it will also be quoted. |
| 233 if (m_pasteBlockqutoeIntoUnquotedArea) { | 233 if (m_pasteBlockquoteIntoUnquotedArea) { |
| 234 if (HTMLQuoteElement* highestBlockquote = toHTMLQuoteElement(hig
hestEnclosingNodeOfType(canonicalPos, &isMailHTMLBlockquoteElement))) | 234 if (HTMLQuoteElement* highestBlockquote = toHTMLQuoteElement(hig
hestEnclosingNodeOfType(canonicalPos, &isMailHTMLBlockquoteElement))) |
| 235 startBlock = highestBlockquote; | 235 startBlock = highestBlockquote; |
| 236 } | 236 } |
| 237 | 237 |
| 238 if (listChild && listChild != startBlock) { | 238 if (listChild && listChild != startBlock) { |
| 239 RefPtrWillBeRawPtr<Element> listChildToInsert = listChild->clone
ElementWithoutChildren(); | 239 RefPtrWillBeRawPtr<Element> listChildToInsert = listChild->clone
ElementWithoutChildren(); |
| 240 appendNode(blockToInsert, listChildToInsert.get()); | 240 appendNode(blockToInsert, listChildToInsert.get()); |
| 241 insertNodeAfter(listChildToInsert.get(), listChild); | 241 insertNodeAfter(listChildToInsert.get(), listChild); |
| 242 } else { | 242 } else { |
| 243 // Most of the time we want to stay at the nesting level of the
startBlock (e.g., when nesting within lists). However, | 243 // Most of the time we want to stay at the nesting level of the
startBlock (e.g., when nesting within lists). However, |
| 244 // for div nodes, this can result in nested div tags that are ha
rd to break out of. | 244 // for div nodes, this can result in nested div tags that are ha
rd to break out of. |
| 245 Element* siblingNode = startBlock.get(); | 245 Element* siblingElement = startBlock.get(); |
| 246 if (isHTMLDivElement(*blockToInsert)) | 246 if (isHTMLDivElement(*blockToInsert)) |
| 247 siblingNode = highestVisuallyEquivalentDivBelowRoot(startBlo
ck.get()); | 247 siblingElement = highestVisuallyEquivalentDivBelowRoot(start
Block.get()); |
| 248 insertNodeAfter(blockToInsert, siblingNode); | 248 insertNodeAfter(blockToInsert, siblingElement); |
| 249 } | 249 } |
| 250 } | 250 } |
| 251 | 251 |
| 252 // Recreate the same structure in the new paragraph. | 252 // Recreate the same structure in the new paragraph. |
| 253 | 253 |
| 254 WillBeHeapVector<RefPtrWillBeMember<Element> > ancestors; | 254 WillBeHeapVector<RefPtrWillBeMember<Element> > ancestors; |
| 255 getAncestorsInsideBlock(positionOutsideTabSpan(insertionPosition).deprec
atedNode(), startBlock.get(), ancestors); | 255 getAncestorsInsideBlock(positionOutsideTabSpan(insertionPosition).deprec
atedNode(), startBlock.get(), ancestors); |
| 256 RefPtrWillBeRawPtr<Element> parent = cloneHierarchyUnderNewBlock(ancesto
rs, blockToInsert); | 256 RefPtrWillBeRawPtr<Element> parent = cloneHierarchyUnderNewBlock(ancesto
rs, blockToInsert); |
| 257 | 257 |
| 258 appendBlockPlaceholder(parent); | 258 appendBlockPlaceholder(parent); |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 429 } | 429 } |
| 430 | 430 |
| 431 void InsertParagraphSeparatorCommand::trace(Visitor *visitor) | 431 void InsertParagraphSeparatorCommand::trace(Visitor *visitor) |
| 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 |