| 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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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(Element* original
EnclosingBlock) | 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 |
| 101 if (!m_style) | 102 if (!m_style) |
| 102 return; | 103 return; |
| 103 | 104 |
| 104 m_style->prepareToApplyAt(endingSelection().start()); | 105 m_style->prepareToApplyAt(endingSelection().start()); |
| 105 if (!m_style->isEmpty()) | 106 if (!m_style->isEmpty()) |
| 106 applyStyle(m_style.get()); | 107 applyStyle(m_style.get()); |
| 107 } | 108 } |
| 108 | 109 |
| 109 bool InsertParagraphSeparatorCommand::shouldUseDefaultParagraphElement(Element*
enclosingBlock) const | 110 bool InsertParagraphSeparatorCommand::shouldUseDefaultParagraphElement(Element*
enclosingBlock) const |
| 110 { | 111 { |
| 111 if (m_mustUseDefaultParagraphElement) | 112 if (m_mustUseDefaultParagraphElement) |
| 112 return true; | 113 return true; |
| 113 | 114 |
| 114 // Assumes that if there was a range selection, it was already deleted. | 115 // Assumes that if there was a range selection, it was already deleted. |
| 115 if (!isEndOfBlock(endingSelection().visibleStart())) | 116 if (!isEndOfBlock(endingSelection().visibleStart())) |
| 116 return false; | 117 return false; |
| 117 | 118 |
| 118 return enclosingBlock->hasTagName(h1Tag) || | 119 return enclosingBlock->hasTagName(h1Tag) |
| 119 enclosingBlock->hasTagName(h2Tag) || | 120 || enclosingBlock->hasTagName(h2Tag) |
| 120 enclosingBlock->hasTagName(h3Tag) || | 121 || enclosingBlock->hasTagName(h3Tag) |
| 121 enclosingBlock->hasTagName(h4Tag) || | 122 || enclosingBlock->hasTagName(h4Tag) |
| 122 enclosingBlock->hasTagName(h5Tag); | 123 || enclosingBlock->hasTagName(h5Tag); |
| 123 } | 124 } |
| 124 | 125 |
| 125 void InsertParagraphSeparatorCommand::getAncestorsInsideBlock(const Node* insert
ionNode, Element* outerBlock, WillBeHeapVector<RefPtrWillBeMember<Element>>& anc
estors) | 126 void InsertParagraphSeparatorCommand::getAncestorsInsideBlock(const Node* insert
ionNode, Element* outerBlock, WillBeHeapVector<RefPtrWillBeMember<Element>>& anc
estors) |
| 126 { | 127 { |
| 127 ancestors.clear(); | 128 ancestors.clear(); |
| 128 | 129 |
| 129 // Build up list of ancestors elements between the insertion node and the ou
ter block. | 130 // Build up list of ancestors elements between the insertion node and the ou
ter block. |
| 130 if (insertionNode != outerBlock) { | 131 if (insertionNode != outerBlock) { |
| 131 for (Element* n = insertionNode->parentElement(); n && n != outerBlock;
n = n->parentElement()) | 132 for (Element* n = insertionNode->parentElement(); n && n != outerBlock;
n = n->parentElement()) |
| 132 ancestors.append(n); | 133 ancestors.append(n); |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 | 388 |
| 388 // If the paragraph separator was inserted at the end of a paragraph, an emp
ty line must be | 389 // If the paragraph separator was inserted at the end of a paragraph, an emp
ty line must be |
| 389 // created. All of the nodes, starting at visiblePos, are about to be added
to the new paragraph | 390 // created. All of the nodes, starting at visiblePos, are about to be added
to the new paragraph |
| 390 // element. If the first node to be inserted won't be one that will hold an
empty line open, add a br. | 391 // element. If the first node to be inserted won't be one that will hold an
empty line open, add a br. |
| 391 if (isEndOfParagraph(visiblePos) && !lineBreakExistsAtVisiblePosition(visibl
ePos)) | 392 if (isEndOfParagraph(visiblePos) && !lineBreakExistsAtVisiblePosition(visibl
ePos)) |
| 392 appendNode(createBreakElement(document()).get(), blockToInsert.get()); | 393 appendNode(createBreakElement(document()).get(), blockToInsert.get()); |
| 393 | 394 |
| 394 // Move the start node and the siblings of the start node. | 395 // Move the start node and the siblings of the start node. |
| 395 if (VisiblePosition(insertionPosition).deepEquivalent() != VisiblePosition(p
ositionBeforeNode(blockToInsert.get())).deepEquivalent()) { | 396 if (VisiblePosition(insertionPosition).deepEquivalent() != VisiblePosition(p
ositionBeforeNode(blockToInsert.get())).deepEquivalent()) { |
| 396 Node* n; | 397 Node* n; |
| 397 if (insertionPosition.computeContainerNode() == startBlock) | 398 if (insertionPosition.computeContainerNode() == startBlock) { |
| 398 n = insertionPosition.computeNodeAfterPosition(); | 399 n = insertionPosition.computeNodeAfterPosition(); |
| 399 else { | 400 } else { |
| 400 Node* splitTo = insertionPosition.computeContainerNode(); | 401 Node* splitTo = insertionPosition.computeContainerNode(); |
| 401 if (splitTo->isTextNode() && insertionPosition.offsetInContainerNode
() >= caretMaxOffset(splitTo)) | 402 if (splitTo->isTextNode() && insertionPosition.offsetInContainerNode
() >= caretMaxOffset(splitTo)) |
| 402 splitTo = NodeTraversal::next(*splitTo, startBlock.get()); | 403 splitTo = NodeTraversal::next(*splitTo, startBlock.get()); |
| 403 ASSERT(splitTo); | 404 ASSERT(splitTo); |
| 404 splitTreeToNode(splitTo, startBlock.get()); | 405 splitTreeToNode(splitTo, startBlock.get()); |
| 405 | 406 |
| 406 for (n = startBlock->firstChild(); n; n = n->nextSibling()) { | 407 for (n = startBlock->firstChild(); n; n = n->nextSibling()) { |
| 407 VisiblePosition beforeNodePosition(positionBeforeNode(n)); | 408 VisiblePosition beforeNodePosition(positionBeforeNode(n)); |
| 408 if (!beforeNodePosition.isNull() && comparePositions(VisiblePosi
tion(insertionPosition), beforeNodePosition) <= 0) | 409 if (!beforeNodePosition.isNull() && comparePositions(VisiblePosi
tion(insertionPosition), beforeNodePosition) <= 0) |
| 409 break; | 410 break; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 430 } | 431 } |
| 431 | 432 |
| 432 DEFINE_TRACE(InsertParagraphSeparatorCommand) | 433 DEFINE_TRACE(InsertParagraphSeparatorCommand) |
| 433 { | 434 { |
| 434 visitor->trace(m_style); | 435 visitor->trace(m_style); |
| 435 CompositeEditCommand::trace(visitor); | 436 CompositeEditCommand::trace(visitor); |
| 436 } | 437 } |
| 437 | 438 |
| 438 | 439 |
| 439 } // namespace blink | 440 } // namespace blink |
| OLD | NEW |