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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 | 59 |
60 if (endingSelection().isNone()) | 60 if (endingSelection().isNone()) |
61 return; | 61 return; |
62 | 62 |
63 VisiblePosition visiblePos = endingSelection().visibleStart(); | 63 VisiblePosition visiblePos = endingSelection().visibleStart(); |
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. | |
70 Node* topBlockquote = highestEnclosingNodeOfType(pos, isMailBlockquote); | |
71 if (!topBlockquote || !topBlockquote->parentNode() || !topBlockquote->isElem
entNode()) | |
72 return; | |
73 | |
74 RefPtr<Element> breakNode = createBreakElement(document()); | 69 RefPtr<Element> breakNode = createBreakElement(document()); |
75 | 70 |
76 bool isLastVisPosInNode = isLastVisiblePositionInNode(visiblePos, topBlockqu
ote); | 71 bool isLastVisPosInNode = isLastVisiblePositionInNode(visiblePos, topBlockqu
ote); |
77 | 72 |
78 // If the position is at the beginning of the top quoted content, we don't n
eed to break the quote. | 73 // 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. | 74 // 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) { | 75 if (isFirstVisiblePositionInNode(visiblePos, topBlockquote) && !isLastVisPos
InNode) { |
81 insertNodeBefore(breakNode.get(), topBlockquote); | 76 insertNodeBefore(breakNode.get(), topBlockquote); |
82 setEndingSelection(VisibleSelection(positionBeforeNode(breakNode.get()),
DOWNSTREAM, endingSelection().isDirectional())); | 77 setEndingSelection(VisibleSelection(positionBeforeNode(breakNode.get()),
DOWNSTREAM, endingSelection().isDirectional())); |
83 rebalanceWhitespace(); | 78 rebalanceWhitespace(); |
84 return; | 79 return; |
85 } | 80 } |
86 | 81 |
87 // Insert a break after the top blockquote. | 82 // Insert a break after the top blockquote. |
88 insertNodeAfter(breakNode.get(), topBlockquote); | 83 insertNodeAfter(breakNode.get(), topBlockquote); |
89 | 84 |
90 // If we're inserting the break at the end of the quoted content, we don't n
eed to break the quote. | 85 // If we're inserting the break at the end of the quoted content, we don't n
eed to break the quote. |
91 if (isLastVisPosInNode) { | 86 if (isLastVisPosInNode) { |
92 setEndingSelection(VisibleSelection(positionBeforeNode(breakNode.get()),
DOWNSTREAM, endingSelection().isDirectional())); | 87 setEndingSelection(VisibleSelection(positionBeforeNode(breakNode.get()),
DOWNSTREAM, endingSelection().isDirectional())); |
93 rebalanceWhitespace(); | 88 rebalanceWhitespace(); |
94 return; | 89 return; |
95 } | 90 } |
96 | 91 |
97 // Don't move a line break just after the caret. Doing so would create an e
xtra, empty paragraph | 92 // Don't move a line break just after the caret. Doing so would create an e
xtra, empty paragraph |
98 // in the new blockquote. | 93 // in the new blockquote. |
99 if (lineBreakExistsAtVisiblePosition(visiblePos)) | 94 if (lineBreakExistsAtVisiblePosition(visiblePos)) |
100 pos = pos.next(); | 95 pos = pos.next(); |
101 | 96 |
102 // Adjust the position so we don't split at the beginning of a quote. | |
103 while (isFirstVisiblePositionInNode(VisiblePosition(pos), enclosingNodeOfTyp
e(pos, isMailBlockquote))) | |
104 pos = pos.previous(); | |
105 | |
106 // startNode is the first node that we need to move to the new blockquote. | 97 // startNode is the first node that we need to move to the new blockquote. |
107 Node* startNode = pos.deprecatedNode(); | 98 Node* startNode = pos.deprecatedNode(); |
108 | 99 |
109 // Split at pos if in the middle of a text node. | 100 // Split at pos if in the middle of a text node. |
110 if (startNode->isTextNode()) { | 101 if (startNode->isTextNode()) { |
111 Text* textNode = toText(startNode); | 102 Text* textNode = toText(startNode); |
112 if ((unsigned)pos.deprecatedEditingOffset() >= textNode->length()) { | 103 if ((unsigned)pos.deprecatedEditingOffset() >= textNode->length()) { |
113 startNode = NodeTraversal::next(startNode); | 104 startNode = NodeTraversal::next(startNode); |
114 ASSERT(startNode); | 105 ASSERT(startNode); |
115 } else if (pos.deprecatedEditingOffset() > 0) | 106 } else if (pos.deprecatedEditingOffset() > 0) |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 | 170 |
180 // Make sure the cloned block quote renders. | 171 // Make sure the cloned block quote renders. |
181 addBlockPlaceholderIfNeeded(clonedBlockquote.get()); | 172 addBlockPlaceholderIfNeeded(clonedBlockquote.get()); |
182 | 173 |
183 // Put the selection right before the break. | 174 // Put the selection right before the break. |
184 setEndingSelection(VisibleSelection(positionBeforeNode(breakNode.get()), DOW
NSTREAM, endingSelection().isDirectional())); | 175 setEndingSelection(VisibleSelection(positionBeforeNode(breakNode.get()), DOW
NSTREAM, endingSelection().isDirectional())); |
185 rebalanceWhitespace(); | 176 rebalanceWhitespace(); |
186 } | 177 } |
187 | 178 |
188 } // namespace WebCore | 179 } // namespace WebCore |
OLD | NEW |