| 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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 | 126 |
| 127 // Don't move a line break just after the caret. Doing so would create an e
xtra, empty paragraph | 127 // Don't move a line break just after the caret. Doing so would create an e
xtra, empty paragraph |
| 128 // in the new blockquote. | 128 // in the new blockquote. |
| 129 if (lineBreakExistsAtVisiblePosition(visiblePos)) { | 129 if (lineBreakExistsAtVisiblePosition(visiblePos)) { |
| 130 // TODO(yosin) We should use |PositionMoveType::Character| for | 130 // TODO(yosin) We should use |PositionMoveType::Character| for |
| 131 // |nextPositionOf()| to avoid editing middle of character. | 131 // |nextPositionOf()| to avoid editing middle of character. |
| 132 pos = nextPositionOf(pos, PositionMoveType::CodePoint); | 132 pos = nextPositionOf(pos, PositionMoveType::CodePoint); |
| 133 } | 133 } |
| 134 | 134 |
| 135 // Adjust the position so we don't split at the beginning of a quote. | 135 // Adjust the position so we don't split at the beginning of a quote. |
| 136 while (isFirstVisiblePositionInNode(VisiblePosition(pos), toHTMLQuoteElement
(enclosingNodeOfType(pos, isMailHTMLBlockquoteElement)))) { | 136 while (isFirstVisiblePositionInNode(createVisiblePosition(pos), toHTMLQuoteE
lement(enclosingNodeOfType(pos, isMailHTMLBlockquoteElement)))) { |
| 137 // TODO(yosin) We should use |PositionMoveType::Character| for | 137 // TODO(yosin) We should use |PositionMoveType::Character| for |
| 138 // |previousPositionOf()| to avoid editing middle character. | 138 // |previousPositionOf()| to avoid editing middle character. |
| 139 pos = previousPositionOf(pos, PositionMoveType::CodePoint); | 139 pos = previousPositionOf(pos, PositionMoveType::CodePoint); |
| 140 } | 140 } |
| 141 | 141 |
| 142 // startNode is the first node that we need to move to the new blockquote. | 142 // startNode is the first node that we need to move to the new blockquote. |
| 143 Node* startNode = pos.anchorNode(); | 143 Node* startNode = pos.anchorNode(); |
| 144 ASSERT(startNode); | 144 ASSERT(startNode); |
| 145 | 145 |
| 146 // Split at pos if in the middle of a text node. | 146 // Split at pos if in the middle of a text node. |
| 147 if (startNode->isTextNode()) { | 147 if (startNode->isTextNode()) { |
| 148 Text* textNode = toText(startNode); | 148 Text* textNode = toText(startNode); |
| 149 int textOffset = pos.computeOffsetInContainerNode(); | 149 int textOffset = pos.computeOffsetInContainerNode(); |
| 150 if ((unsigned)textOffset >= textNode->length()) { | 150 if ((unsigned)textOffset >= textNode->length()) { |
| 151 startNode = NodeTraversal::next(*startNode); | 151 startNode = NodeTraversal::next(*startNode); |
| 152 ASSERT(startNode); | 152 ASSERT(startNode); |
| 153 } else if (textOffset > 0) { | 153 } else if (textOffset > 0) { |
| 154 splitTextNode(textNode, textOffset); | 154 splitTextNode(textNode, textOffset); |
| 155 } | 155 } |
| 156 } else if (pos.computeEditingOffset() > 0) { | 156 } else if (pos.computeEditingOffset() > 0) { |
| 157 Node* childAtOffset = NodeTraversal::childAt(*startNode, pos.computeEdit
ingOffset()); | 157 Node* childAtOffset = NodeTraversal::childAt(*startNode, pos.computeEdit
ingOffset()); |
| 158 startNode = childAtOffset ? childAtOffset : NodeTraversal::next(*startNo
de); | 158 startNode = childAtOffset ? childAtOffset : NodeTraversal::next(*startNo
de); |
| 159 ASSERT(startNode); | 159 ASSERT(startNode); |
| 160 } | 160 } |
| 161 | 161 |
| 162 // If there's nothing inside topBlockquote to move, we're finished. | 162 // If there's nothing inside topBlockquote to move, we're finished. |
| 163 if (!startNode->isDescendantOf(topBlockquote)) { | 163 if (!startNode->isDescendantOf(topBlockquote)) { |
| 164 setEndingSelection(VisibleSelection(VisiblePosition(firstPositionInOrBef
oreNode(startNode)), endingSelection().isDirectional())); | 164 setEndingSelection(VisibleSelection(createVisiblePosition(firstPositionI
nOrBeforeNode(startNode)), endingSelection().isDirectional())); |
| 165 return; | 165 return; |
| 166 } | 166 } |
| 167 | 167 |
| 168 // Build up list of ancestors in between the start node and the top blockquo
te. | 168 // Build up list of ancestors in between the start node and the top blockquo
te. |
| 169 WillBeHeapVector<RefPtrWillBeMember<Element>> ancestors; | 169 WillBeHeapVector<RefPtrWillBeMember<Element>> ancestors; |
| 170 for (Element* node = startNode->parentElement(); node && node != topBlockquo
te; node = node->parentElement()) | 170 for (Element* node = startNode->parentElement(); node && node != topBlockquo
te; node = node->parentElement()) |
| 171 ancestors.append(node); | 171 ancestors.append(node); |
| 172 | 172 |
| 173 // Insert a clone of the top blockquote after the break. | 173 // Insert a clone of the top blockquote after the break. |
| 174 RefPtrWillBeRawPtr<Element> clonedBlockquote = topBlockquote->cloneElementWi
thoutChildren(); | 174 RefPtrWillBeRawPtr<Element> clonedBlockquote = topBlockquote->cloneElementWi
thoutChildren(); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 | 218 |
| 219 // Make sure the cloned block quote renders. | 219 // Make sure the cloned block quote renders. |
| 220 addBlockPlaceholderIfNeeded(clonedBlockquote.get()); | 220 addBlockPlaceholderIfNeeded(clonedBlockquote.get()); |
| 221 | 221 |
| 222 // Put the selection right before the break. | 222 // Put the selection right before the break. |
| 223 setEndingSelection(VisibleSelection(positionBeforeNode(breakElement.get()),
TextAffinity::Downstream, endingSelection().isDirectional())); | 223 setEndingSelection(VisibleSelection(positionBeforeNode(breakElement.get()),
TextAffinity::Downstream, endingSelection().isDirectional())); |
| 224 rebalanceWhitespace(); | 224 rebalanceWhitespace(); |
| 225 } | 225 } |
| 226 | 226 |
| 227 } // namespace blink | 227 } // namespace blink |
| OLD | NEW |