Chromium Code Reviews| 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 64 | 64 |
| 65 // pos is a position equivalent to the caret. We use downstream() so that p os will | 65 // pos is a position equivalent to the caret. We use downstream() so that p os will |
| 66 // be in the first node that we need to move (there are a few exceptions to this, see below). | 66 // be in the first node that we need to move (there are a few exceptions to this, see below). |
| 67 Position pos = endingSelection().start().downstream(); | 67 Position pos = endingSelection().start().downstream(); |
| 68 | 68 |
| 69 // Find the top-most blockquote from the start. | 69 // Find the top-most blockquote from the start. |
| 70 Node* topBlockquote = highestEnclosingNodeOfType(pos, isMailBlockquote); | 70 Node* topBlockquote = highestEnclosingNodeOfType(pos, isMailBlockquote); |
| 71 if (!topBlockquote || !topBlockquote->parentNode() || !topBlockquote->isElem entNode()) | 71 if (!topBlockquote || !topBlockquote->parentNode() || !topBlockquote->isElem entNode()) |
| 72 return; | 72 return; |
| 73 | 73 |
| 74 RefPtr<Element> breakNode = createBreakElement(document()); | 74 RefPtrWillBeRawPtr<Element> breakNode = createBreakElement(document()); |
| 75 | 75 |
| 76 bool isLastVisPosInNode = isLastVisiblePositionInNode(visiblePos, topBlockqu ote); | 76 bool isLastVisPosInNode = isLastVisiblePositionInNode(visiblePos, topBlockqu ote); |
| 77 | 77 |
| 78 // If the position is at the beginning of the top quoted content, we don't n eed to break the quote. | 78 // If the position is at the beginning of the top quoted content, we don't n eed to break the quote. |
| 79 // Instead, insert the break before the blockquote, unless the position is a s the end of the the quoted content. | 79 // Instead, insert the break before the blockquote, unless the position is a s the end of the the quoted content. |
| 80 if (isFirstVisiblePositionInNode(visiblePos, topBlockquote) && !isLastVisPos InNode) { | 80 if (isFirstVisiblePositionInNode(visiblePos, topBlockquote) && !isLastVisPos InNode) { |
| 81 insertNodeBefore(breakNode.get(), topBlockquote); | 81 insertNodeBefore(breakNode.get(), topBlockquote); |
| 82 setEndingSelection(VisibleSelection(positionBeforeNode(breakNode.get()), DOWNSTREAM, endingSelection().isDirectional())); | 82 setEndingSelection(VisibleSelection(positionBeforeNode(breakNode.get()), DOWNSTREAM, endingSelection().isDirectional())); |
| 83 rebalanceWhitespace(); | 83 rebalanceWhitespace(); |
| 84 return; | 84 return; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 121 ASSERT(startNode); | 121 ASSERT(startNode); |
| 122 } | 122 } |
| 123 | 123 |
| 124 // If there's nothing inside topBlockquote to move, we're finished. | 124 // If there's nothing inside topBlockquote to move, we're finished. |
| 125 if (!startNode->isDescendantOf(topBlockquote)) { | 125 if (!startNode->isDescendantOf(topBlockquote)) { |
| 126 setEndingSelection(VisibleSelection(VisiblePosition(firstPositionInOrBef oreNode(startNode)), endingSelection().isDirectional())); | 126 setEndingSelection(VisibleSelection(VisiblePosition(firstPositionInOrBef oreNode(startNode)), endingSelection().isDirectional())); |
| 127 return; | 127 return; |
| 128 } | 128 } |
| 129 | 129 |
| 130 // Build up list of ancestors in between the start node and the top blockquo te. | 130 // Build up list of ancestors in between the start node and the top blockquo te. |
| 131 Vector<RefPtr<Element> > ancestors; | 131 WillBeHeapVector<RefPtrWillBeMember<Element> > ancestors; |
| 132 for (Element* node = startNode->parentElement(); node && node != topBlockquo te; node = node->parentElement()) | 132 for (Element* node = startNode->parentElement(); node && node != topBlockquo te; node = node->parentElement()) |
| 133 ancestors.append(node); | 133 ancestors.append(node); |
| 134 | 134 |
| 135 // Insert a clone of the top blockquote after the break. | 135 // Insert a clone of the top blockquote after the break. |
| 136 RefPtr<Element> clonedBlockquote = toElement(topBlockquote)->cloneElementWit houtChildren(); | 136 RefPtrWillBeRawPtr<Element> clonedBlockquote = toElement(topBlockquote)->clo neElementWithoutChildren(); |
| 137 insertNodeAfter(clonedBlockquote.get(), breakNode.get()); | 137 insertNodeAfter(clonedBlockquote.get(), breakNode.get()); |
| 138 | 138 |
| 139 // Clone startNode's ancestors into the cloned blockquote. | 139 // Clone startNode's ancestors into the cloned blockquote. |
| 140 // On exiting this loop, clonedAncestor is the lowest ancestor | 140 // On exiting this loop, clonedAncestor is the lowest ancestor |
| 141 // that was cloned (i.e. the clone of either ancestors.last() | 141 // that was cloned (i.e. the clone of either ancestors.last() |
| 142 // or clonedBlockquote if ancestors is empty). | 142 // or clonedBlockquote if ancestors is empty). |
| 143 RefPtr<Element> clonedAncestor = clonedBlockquote; | 143 RefPtrWillBeRawPtr<Element> clonedAncestor = clonedBlockquote; |
| 144 for (size_t i = ancestors.size(); i != 0; --i) { | 144 for (size_t i = ancestors.size(); i != 0; --i) { |
| 145 RefPtr<Element> clonedChild = ancestors[i - 1]->cloneElementWithoutChild ren(); | 145 RefPtrWillBeRawPtr<Element> clonedChild = ancestors[i - 1]->cloneElement WithoutChildren(); |
| 146 // Preserve list item numbering in cloned lists. | 146 // Preserve list item numbering in cloned lists. |
| 147 if (isHTMLOListElement(*clonedChild)) { | 147 if (isHTMLOListElement(*clonedChild)) { |
| 148 Node* listChildNode = i > 1 ? ancestors[i - 2].get() : startNode; | 148 Node* listChildNode = i > 1 ? ancestors[i - 2].get() : startNode; |
| 149 // The first child of the cloned list might not be a list item eleme nt, | 149 // The first child of the cloned list might not be a list item eleme nt, |
| 150 // find the first one so that we know where to start numbering. | 150 // find the first one so that we know where to start numbering. |
| 151 while (listChildNode && !isHTMLLIElement(*listChildNode)) | 151 while (listChildNode && !isHTMLLIElement(*listChildNode)) |
| 152 listChildNode = listChildNode->nextSibling(); | 152 listChildNode = listChildNode->nextSibling(); |
| 153 if (listChildNode && listChildNode->renderer() && listChildNode->ren derer()->isListItem()) | 153 if (listChildNode && listChildNode->renderer() && listChildNode->ren derer()->isListItem()) |
| 154 setNodeAttribute(clonedChild, startAttr, AtomicString::number(to RenderListItem(listChildNode->renderer())->value())); | 154 setNodeAttribute(clonedChild, startAttr, AtomicString::number(to RenderListItem(listChildNode->renderer())->value())); |
| 155 } | 155 } |
| 156 | 156 |
| 157 appendNode(clonedChild.get(), clonedAncestor.get()); | 157 appendNode(clonedChild.get(), clonedAncestor.get()); |
| 158 clonedAncestor = clonedChild; | 158 clonedAncestor = clonedChild; |
| 159 } | 159 } |
| 160 | 160 |
| 161 moveRemainingSiblingsToNewParent(startNode, 0, clonedAncestor); | 161 moveRemainingSiblingsToNewParent(startNode, 0, clonedAncestor); |
| 162 | 162 |
| 163 if (!ancestors.isEmpty()) { | 163 if (!ancestors.isEmpty()) { |
| 164 // Split the tree up the ancestor chain until the topBlockquote | 164 // Split the tree up the ancestor chain until the topBlockquote |
| 165 // Throughout this loop, clonedParent is the clone of ancestor's parent. | 165 // Throughout this loop, clonedParent is the clone of ancestor's parent. |
| 166 // This is so we can clone ancestor's siblings and place the clones | 166 // This is so we can clone ancestor's siblings and place the clones |
| 167 // into the clone corresponding to the ancestor's parent. | 167 // into the clone corresponding to the ancestor's parent. |
| 168 RefPtr<Element> ancestor; | 168 RefPtrWillBeRawPtr<Element> ancestor; |
| 169 RefPtr<Element> clonedParent; | 169 RefPtrWillBeRawPtr<Element> clonedParent; |
|
haraken
2014/05/26 02:36:12
= nullptr;
sof
2014/05/28 08:31:35
Done.
| |
| 170 for (ancestor = ancestors.first(), clonedParent = clonedAncestor->parent Element(); | 170 for (ancestor = ancestors.first(), clonedParent = clonedAncestor->parent Element(); |
| 171 ancestor && ancestor != topBlockquote; | 171 ancestor && ancestor != topBlockquote; |
| 172 ancestor = ancestor->parentElement(), clonedParent = clonedParent-> parentElement()) | 172 ancestor = ancestor->parentElement(), clonedParent = clonedParent-> parentElement()) |
| 173 moveRemainingSiblingsToNewParent(ancestor->nextSibling(), 0, clonedP arent); | 173 moveRemainingSiblingsToNewParent(ancestor->nextSibling(), 0, clonedP arent); |
| 174 | 174 |
| 175 // If the startNode's original parent is now empty, remove it | 175 // If the startNode's original parent is now empty, remove it |
| 176 Node* originalParent = ancestors.first().get(); | 176 Node* originalParent = ancestors.first().get(); |
| 177 if (!originalParent->hasChildren()) | 177 if (!originalParent->hasChildren()) |
| 178 removeNode(originalParent); | 178 removeNode(originalParent); |
| 179 } | 179 } |
| 180 | 180 |
| 181 // Make sure the cloned block quote renders. | 181 // Make sure the cloned block quote renders. |
| 182 addBlockPlaceholderIfNeeded(clonedBlockquote.get()); | 182 addBlockPlaceholderIfNeeded(clonedBlockquote.get()); |
| 183 | 183 |
| 184 // Put the selection right before the break. | 184 // Put the selection right before the break. |
| 185 setEndingSelection(VisibleSelection(positionBeforeNode(breakNode.get()), DOW NSTREAM, endingSelection().isDirectional())); | 185 setEndingSelection(VisibleSelection(positionBeforeNode(breakNode.get()), DOW NSTREAM, endingSelection().isDirectional())); |
| 186 rebalanceWhitespace(); | 186 rebalanceWhitespace(); |
| 187 } | 187 } |
| 188 | 188 |
| 189 } // namespace WebCore | 189 } // namespace WebCore |
| OLD | NEW |