OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2006, 2010 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2010 Apple 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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 // margin/padding, but not others. We should make the gap painting more con
sistent and | 122 // margin/padding, but not others. We should make the gap painting more con
sistent and |
123 // then use a left margin/padding rule here. | 123 // then use a left margin/padding rule here. |
124 if (visibleEnd != visibleStart && isStartOfParagraph(visibleEnd, CanSkipOver
EditingBoundary)) { | 124 if (visibleEnd != visibleStart && isStartOfParagraph(visibleEnd, CanSkipOver
EditingBoundary)) { |
125 setEndingSelection(VisibleSelection(visibleStart, visibleEnd.previous(Ca
nnotCrossEditingBoundary), endingSelection().isDirectional())); | 125 setEndingSelection(VisibleSelection(visibleStart, visibleEnd.previous(Ca
nnotCrossEditingBoundary), endingSelection().isDirectional())); |
126 if (!endingSelection().rootEditableElement()) | 126 if (!endingSelection().rootEditableElement()) |
127 return; | 127 return; |
128 } | 128 } |
129 | 129 |
130 const QualifiedName& listTag = (m_type == OrderedList) ? olTag : ulTag; | 130 const QualifiedName& listTag = (m_type == OrderedList) ? olTag : ulTag; |
131 if (endingSelection().isRange()) { | 131 if (endingSelection().isRange()) { |
| 132 bool forceListCreation = false; |
132 VisibleSelection selection = selectionForParagraphIteration(endingSelect
ion()); | 133 VisibleSelection selection = selectionForParagraphIteration(endingSelect
ion()); |
133 ASSERT(selection.isRange()); | 134 ASSERT(selection.isRange()); |
134 VisiblePosition startOfSelection = selection.visibleStart(); | 135 VisiblePosition startOfSelection = selection.visibleStart(); |
135 VisiblePosition endOfSelection = selection.visibleEnd(); | 136 VisiblePosition endOfSelection = selection.visibleEnd(); |
136 VisiblePosition startOfLastParagraph = startOfParagraph(endOfSelection,
CanSkipOverEditingBoundary); | 137 VisiblePosition startOfLastParagraph = startOfParagraph(endOfSelection,
CanSkipOverEditingBoundary); |
137 | 138 |
| 139 RefPtrWillBeRawPtr<Range> currentSelection = endingSelection().firstRang
e(); |
| 140 RefPtrWillBeRawPtr<ContainerNode> scopeForStartOfSelection = nullptr; |
| 141 RefPtrWillBeRawPtr<ContainerNode> scopeForEndOfSelection = nullptr; |
| 142 // FIXME: This is an inefficient way to keep selection alive because |
| 143 // indexForVisiblePosition walks from the beginning of the document to t
he |
| 144 // endOfSelection everytime this code is executed. But not using index i
s hard |
| 145 // because there are so many ways we can los eselection inside doApplyFo
rSingleParagraph. |
| 146 int indexForStartOfSelection = indexForVisiblePosition(startOfSelection,
scopeForStartOfSelection); |
| 147 int indexForEndOfSelection = indexForVisiblePosition(endOfSelection, sco
peForEndOfSelection); |
| 148 |
138 if (startOfParagraph(startOfSelection, CanSkipOverEditingBoundary) != st
artOfLastParagraph) { | 149 if (startOfParagraph(startOfSelection, CanSkipOverEditingBoundary) != st
artOfLastParagraph) { |
139 RefPtrWillBeRawPtr<ContainerNode> scope = nullptr; | 150 forceListCreation = !selectionHasListOfType(selection, listTag); |
140 int indexForEndOfSelection = indexForVisiblePosition(endOfSelection,
scope); | |
141 bool forceCreateList = !selectionHasListOfType(selection, listTag); | |
142 | 151 |
143 RefPtrWillBeRawPtr<Range> currentSelection = endingSelection().first
Range(); | |
144 VisiblePosition startOfCurrentParagraph = startOfSelection; | 152 VisiblePosition startOfCurrentParagraph = startOfSelection; |
145 while (startOfCurrentParagraph.isNotNull() && !inSameParagraph(start
OfCurrentParagraph, startOfLastParagraph, CanCrossEditingBoundary)) { | 153 while (startOfCurrentParagraph.isNotNull() && !inSameParagraph(start
OfCurrentParagraph, startOfLastParagraph, CanCrossEditingBoundary)) { |
146 // doApply() may operate on and remove the last paragraph of the
selection from the document | 154 // doApply() may operate on and remove the last paragraph of the
selection from the document |
147 // if it's in the same list item as startOfCurrentParagraph. Re
turn early to avoid an | 155 // if it's in the same list item as startOfCurrentParagraph. Re
turn early to avoid an |
148 // infinite loop and because there is no more work to be done. | 156 // infinite loop and because there is no more work to be done. |
149 // FIXME(<rdar://problem/5983974>): The endingSelection() may be
incorrect here. Compute | 157 // FIXME(<rdar://problem/5983974>): The endingSelection() may be
incorrect here. Compute |
150 // the new location of endOfSelection and use it as the end of t
he new selection. | 158 // the new location of endOfSelection and use it as the end of t
he new selection. |
151 if (!startOfLastParagraph.deepEquivalent().inDocument()) | 159 if (!startOfLastParagraph.deepEquivalent().inDocument()) |
152 return; | 160 return; |
153 setEndingSelection(startOfCurrentParagraph); | 161 setEndingSelection(startOfCurrentParagraph); |
154 | 162 |
155 // Save and restore endOfSelection and startOfLastParagraph when
necessary | 163 // Save and restore endOfSelection and startOfLastParagraph when
necessary |
156 // since moveParagraph and movePragraphWithClones can remove nod
es. | 164 // since moveParagraph and movePragraphWithClones can remove nod
es. |
157 // FIXME: This is an inefficient way to keep selection alive bec
ause indexForVisiblePosition walks from | 165 doApplyForSingleParagraph(forceListCreation, listTag, *currentSe
lection); |
158 // the beginning of the document to the endOfSelection everytime
this code is executed. | |
159 // But not using index is hard because there are so many ways we
can lose selection inside doApplyForSingleParagraph. | |
160 doApplyForSingleParagraph(forceCreateList, listTag, *currentSele
ction); | |
161 if (endOfSelection.isNull() || endOfSelection.isOrphan() || star
tOfLastParagraph.isNull() || startOfLastParagraph.isOrphan()) { | 166 if (endOfSelection.isNull() || endOfSelection.isOrphan() || star
tOfLastParagraph.isNull() || startOfLastParagraph.isOrphan()) { |
162 endOfSelection = visiblePositionForIndex(indexForEndOfSelect
ion, scope.get()); | 167 endOfSelection = visiblePositionForIndex(indexForEndOfSelect
ion, scopeForEndOfSelection.get()); |
163 // If endOfSelection is null, then some contents have been d
eleted from the document. | 168 // If endOfSelection is null, then some contents have been d
eleted from the document. |
164 // This should never happen and if it did, exit early immedi
ately because we've lost the loop invariant. | 169 // This should never happen and if it did, exit early immedi
ately because we've lost the loop invariant. |
165 ASSERT(endOfSelection.isNotNull()); | 170 ASSERT(endOfSelection.isNotNull()); |
166 if (endOfSelection.isNull()) | 171 if (endOfSelection.isNull()) |
167 return; | 172 return; |
168 startOfLastParagraph = startOfParagraph(endOfSelection, CanS
kipOverEditingBoundary); | 173 startOfLastParagraph = startOfParagraph(endOfSelection, CanS
kipOverEditingBoundary); |
169 } | 174 } |
170 | 175 |
171 // Fetch the start of the selection after moving the first parag
raph, | |
172 // because moving the paragraph will invalidate the original sta
rt. | |
173 // We'll use the new start to restore the original selection aft
er | |
174 // we modified all selected paragraphs. | |
175 if (startOfCurrentParagraph == startOfSelection) | |
176 startOfSelection = endingSelection().visibleStart(); | |
177 | |
178 startOfCurrentParagraph = startOfNextParagraph(endingSelection()
.visibleStart()); | 176 startOfCurrentParagraph = startOfNextParagraph(endingSelection()
.visibleStart()); |
179 } | 177 } |
180 setEndingSelection(endOfSelection); | 178 setEndingSelection(endOfSelection); |
181 doApplyForSingleParagraph(forceCreateList, listTag, *currentSelectio
n); | |
182 // Fetch the end of the selection, for the reason mentioned above. | |
183 if (endOfSelection.isNull() || endOfSelection.isOrphan()) { | |
184 endOfSelection = visiblePositionForIndex(indexForEndOfSelection,
scope.get()); | |
185 if (endOfSelection.isNull()) | |
186 return; | |
187 } | |
188 setEndingSelection(VisibleSelection(startOfSelection, endOfSelection
, endingSelection().isDirectional())); | |
189 return; | |
190 } | 179 } |
| 180 doApplyForSingleParagraph(forceListCreation, listTag, *currentSelection)
; |
| 181 // Fetch the end of the selection, for the reason mentioned above. |
| 182 if (endOfSelection.isNull() || endOfSelection.isOrphan()) { |
| 183 endOfSelection = visiblePositionForIndex(indexForEndOfSelection, sco
peForEndOfSelection.get()); |
| 184 if (endOfSelection.isNull()) |
| 185 return; |
| 186 } |
| 187 if (startOfSelection.isNull() || startOfSelection.isOrphan()) { |
| 188 startOfSelection = visiblePositionForIndex(indexForStartOfSelection,
scopeForStartOfSelection.get()); |
| 189 if (startOfSelection.isNull()) |
| 190 return; |
| 191 } |
| 192 setEndingSelection(VisibleSelection(startOfSelection, endOfSelection, en
dingSelection().isDirectional())); |
| 193 return; |
191 } | 194 } |
192 | 195 |
193 ASSERT(endingSelection().firstRange()); | 196 ASSERT(endingSelection().firstRange()); |
194 doApplyForSingleParagraph(false, listTag, *endingSelection().firstRange()); | 197 doApplyForSingleParagraph(false, listTag, *endingSelection().firstRange()); |
195 } | 198 } |
196 | 199 |
197 void InsertListCommand::doApplyForSingleParagraph(bool forceCreateList, const Qu
alifiedName& listTag, Range& currentSelection) | 200 void InsertListCommand::doApplyForSingleParagraph(bool forceCreateList, const Qu
alifiedName& listTag, Range& currentSelection) |
198 { | 201 { |
199 // FIXME: This will produce unexpected results for a selection that starts j
ust before a | 202 // FIXME: This will produce unexpected results for a selection that starts j
ust before a |
200 // table and ends inside the first cell, selectionForParagraphIteration shou
ld probably | 203 // table and ends inside the first cell, selectionForParagraphIteration shou
ld probably |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
405 return listElement; | 408 return listElement; |
406 } | 409 } |
407 | 410 |
408 void InsertListCommand::trace(Visitor* visitor) | 411 void InsertListCommand::trace(Visitor* visitor) |
409 { | 412 { |
410 visitor->trace(m_listElement); | 413 visitor->trace(m_listElement); |
411 CompositeEditCommand::trace(visitor); | 414 CompositeEditCommand::trace(visitor); |
412 } | 415 } |
413 | 416 |
414 } | 417 } |
OLD | NEW |