| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2005 Apple Computer, Inc. All rights reserved. | 2 * Copyright (C) 2005 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 15 matching lines...) Expand all Loading... |
| 26 #include "config.h" | 26 #include "config.h" |
| 27 #include "core/editing/BreakBlockquoteCommand.h" | 27 #include "core/editing/BreakBlockquoteCommand.h" |
| 28 | 28 |
| 29 #include "core/HTMLNames.h" | 29 #include "core/HTMLNames.h" |
| 30 #include "core/dom/NodeTraversal.h" | 30 #include "core/dom/NodeTraversal.h" |
| 31 #include "core/dom/Text.h" | 31 #include "core/dom/Text.h" |
| 32 #include "core/editing/VisiblePosition.h" | 32 #include "core/editing/VisiblePosition.h" |
| 33 #include "core/editing/htmlediting.h" | 33 #include "core/editing/htmlediting.h" |
| 34 #include "core/html/HTMLBRElement.h" | 34 #include "core/html/HTMLBRElement.h" |
| 35 #include "core/html/HTMLElement.h" | 35 #include "core/html/HTMLElement.h" |
| 36 #include "core/html/HTMLQuoteElement.h" |
| 36 #include "core/rendering/RenderListItem.h" | 37 #include "core/rendering/RenderListItem.h" |
| 37 | 38 |
| 38 namespace blink { | 39 namespace blink { |
| 39 | 40 |
| 40 using namespace HTMLNames; | 41 using namespace HTMLNames; |
| 41 | 42 |
| 42 BreakBlockquoteCommand::BreakBlockquoteCommand(Document& document) | 43 BreakBlockquoteCommand::BreakBlockquoteCommand(Document& document) |
| 43 : CompositeEditCommand(document) | 44 : CompositeEditCommand(document) |
| 44 { | 45 { |
| 45 } | 46 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 61 if (endingSelection().isNone()) | 62 if (endingSelection().isNone()) |
| 62 return; | 63 return; |
| 63 | 64 |
| 64 VisiblePosition visiblePos = endingSelection().visibleStart(); | 65 VisiblePosition visiblePos = endingSelection().visibleStart(); |
| 65 | 66 |
| 66 // pos is a position equivalent to the caret. We use downstream() so that p
os will | 67 // pos is a position equivalent to the caret. We use downstream() so that p
os will |
| 67 // be in the first node that we need to move (there are a few exceptions to
this, see below). | 68 // be in the first node that we need to move (there are a few exceptions to
this, see below). |
| 68 Position pos = endingSelection().start().downstream(); | 69 Position pos = endingSelection().start().downstream(); |
| 69 | 70 |
| 70 // Find the top-most blockquote from the start. | 71 // Find the top-most blockquote from the start. |
| 71 Node* topBlockquote = highestEnclosingNodeOfType(pos, isMailBlockquote); | 72 HTMLQuoteElement* topBlockquote = toHTMLQuoteElement(highestEnclosingNodeOfT
ype(pos, isMailHTMLBlockquoteElement)); |
| 72 if (!topBlockquote || !topBlockquote->parentNode() || !topBlockquote->isElem
entNode()) | 73 if (!topBlockquote || !topBlockquote->parentNode()) |
| 73 return; | 74 return; |
| 74 | 75 |
| 75 RefPtrWillBeRawPtr<HTMLBRElement> breakElement = createBreakElement(document
()); | 76 RefPtrWillBeRawPtr<HTMLBRElement> breakElement = createBreakElement(document
()); |
| 76 | 77 |
| 77 bool isLastVisPosInNode = isLastVisiblePositionInNode(visiblePos, topBlockqu
ote); | 78 bool isLastVisPosInNode = isLastVisiblePositionInNode(visiblePos, topBlockqu
ote); |
| 78 | 79 |
| 79 // If the position is at the beginning of the top quoted content, we don't n
eed to break the quote. | 80 // If the position is at the beginning of the top quoted content, we don't n
eed to break the quote. |
| 80 // Instead, insert the break before the blockquote, unless the position is a
s the end of the the quoted content. | 81 // Instead, insert the break before the blockquote, unless the position is a
s the end of the the quoted content. |
| 81 if (isFirstVisiblePositionInNode(visiblePos, topBlockquote) && !isLastVisPos
InNode) { | 82 if (isFirstVisiblePositionInNode(visiblePos, topBlockquote) && !isLastVisPos
InNode) { |
| 82 insertNodeBefore(breakElement.get(), topBlockquote); | 83 insertNodeBefore(breakElement.get(), topBlockquote); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 94 rebalanceWhitespace(); | 95 rebalanceWhitespace(); |
| 95 return; | 96 return; |
| 96 } | 97 } |
| 97 | 98 |
| 98 // Don't move a line break just after the caret. Doing so would create an e
xtra, empty paragraph | 99 // Don't move a line break just after the caret. Doing so would create an e
xtra, empty paragraph |
| 99 // in the new blockquote. | 100 // in the new blockquote. |
| 100 if (lineBreakExistsAtVisiblePosition(visiblePos)) | 101 if (lineBreakExistsAtVisiblePosition(visiblePos)) |
| 101 pos = pos.next(); | 102 pos = pos.next(); |
| 102 | 103 |
| 103 // Adjust the position so we don't split at the beginning of a quote. | 104 // Adjust the position so we don't split at the beginning of a quote. |
| 104 while (isFirstVisiblePositionInNode(VisiblePosition(pos), enclosingNodeOfTyp
e(pos, isMailBlockquote))) | 105 while (isFirstVisiblePositionInNode(VisiblePosition(pos), enclosingNodeOfTyp
e(pos, isMailHTMLBlockquoteElement))) |
| 105 pos = pos.previous(); | 106 pos = pos.previous(); |
| 106 | 107 |
| 107 // startNode is the first node that we need to move to the new blockquote. | 108 // startNode is the first node that we need to move to the new blockquote. |
| 108 Node* startNode = pos.deprecatedNode(); | 109 Node* startNode = pos.deprecatedNode(); |
| 109 ASSERT(startNode); | 110 ASSERT(startNode); |
| 110 | 111 |
| 111 // Split at pos if in the middle of a text node. | 112 // Split at pos if in the middle of a text node. |
| 112 if (startNode->isTextNode()) { | 113 if (startNode->isTextNode()) { |
| 113 Text* textNode = toText(startNode); | 114 Text* textNode = toText(startNode); |
| 114 if ((unsigned)pos.deprecatedEditingOffset() >= textNode->length()) { | 115 if ((unsigned)pos.deprecatedEditingOffset() >= textNode->length()) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 127 setEndingSelection(VisibleSelection(VisiblePosition(firstPositionInOrBef
oreNode(startNode)), endingSelection().isDirectional())); | 128 setEndingSelection(VisibleSelection(VisiblePosition(firstPositionInOrBef
oreNode(startNode)), endingSelection().isDirectional())); |
| 128 return; | 129 return; |
| 129 } | 130 } |
| 130 | 131 |
| 131 // Build up list of ancestors in between the start node and the top blockquo
te. | 132 // Build up list of ancestors in between the start node and the top blockquo
te. |
| 132 WillBeHeapVector<RefPtrWillBeMember<Element> > ancestors; | 133 WillBeHeapVector<RefPtrWillBeMember<Element> > ancestors; |
| 133 for (Element* node = startNode->parentElement(); node && node != topBlockquo
te; node = node->parentElement()) | 134 for (Element* node = startNode->parentElement(); node && node != topBlockquo
te; node = node->parentElement()) |
| 134 ancestors.append(node); | 135 ancestors.append(node); |
| 135 | 136 |
| 136 // Insert a clone of the top blockquote after the break. | 137 // Insert a clone of the top blockquote after the break. |
| 137 RefPtrWillBeRawPtr<Element> clonedBlockquote = toElement(topBlockquote)->clo
neElementWithoutChildren(); | 138 RefPtrWillBeRawPtr<Element> clonedBlockquote = topBlockquote->cloneElementWi
thoutChildren(); |
| 138 insertNodeAfter(clonedBlockquote.get(), breakElement.get()); | 139 insertNodeAfter(clonedBlockquote.get(), breakElement.get()); |
| 139 | 140 |
| 140 // Clone startNode's ancestors into the cloned blockquote. | 141 // Clone startNode's ancestors into the cloned blockquote. |
| 141 // On exiting this loop, clonedAncestor is the lowest ancestor | 142 // On exiting this loop, clonedAncestor is the lowest ancestor |
| 142 // that was cloned (i.e. the clone of either ancestors.last() | 143 // that was cloned (i.e. the clone of either ancestors.last() |
| 143 // or clonedBlockquote if ancestors is empty). | 144 // or clonedBlockquote if ancestors is empty). |
| 144 RefPtrWillBeRawPtr<Element> clonedAncestor = clonedBlockquote; | 145 RefPtrWillBeRawPtr<Element> clonedAncestor = clonedBlockquote; |
| 145 for (size_t i = ancestors.size(); i != 0; --i) { | 146 for (size_t i = ancestors.size(); i != 0; --i) { |
| 146 RefPtrWillBeRawPtr<Element> clonedChild = ancestors[i - 1]->cloneElement
WithoutChildren(); | 147 RefPtrWillBeRawPtr<Element> clonedChild = ancestors[i - 1]->cloneElement
WithoutChildren(); |
| 147 // Preserve list item numbering in cloned lists. | 148 // Preserve list item numbering in cloned lists. |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 | 182 |
| 182 // Make sure the cloned block quote renders. | 183 // Make sure the cloned block quote renders. |
| 183 addBlockPlaceholderIfNeeded(clonedBlockquote.get()); | 184 addBlockPlaceholderIfNeeded(clonedBlockquote.get()); |
| 184 | 185 |
| 185 // Put the selection right before the break. | 186 // Put the selection right before the break. |
| 186 setEndingSelection(VisibleSelection(positionBeforeNode(breakElement.get()),
DOWNSTREAM, endingSelection().isDirectional())); | 187 setEndingSelection(VisibleSelection(positionBeforeNode(breakElement.get()),
DOWNSTREAM, endingSelection().isDirectional())); |
| 187 rebalanceWhitespace(); | 188 rebalanceWhitespace(); |
| 188 } | 189 } |
| 189 | 190 |
| 190 } // namespace blink | 191 } // namespace blink |
| OLD | NEW |