Chromium Code Reviews| 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 ind exForVisiblePosition walks from | |
|
tkent
2014/06/27 05:04:57
nit: recommend to wrap comments in 80-columns.
arpitabahuguna
2014/06/27 06:15:30
Done.
| |
| 143 // the beginning of the document to the endOfSelection everytime this co de is executed. | |
| 144 // But not using index is hard because there are so many ways we can los eselection inside doApplyForSingleParagraph. | |
| 145 int indexForStartOfSelection = indexForVisiblePosition(startOfSelection, scopeForStartOfSelection); | |
| 146 int indexForEndOfSelection = indexForVisiblePosition(endOfSelection, sco peForEndOfSelection); | |
| 147 | |
| 138 if (startOfParagraph(startOfSelection, CanSkipOverEditingBoundary) != st artOfLastParagraph) { | 148 if (startOfParagraph(startOfSelection, CanSkipOverEditingBoundary) != st artOfLastParagraph) { |
| 139 RefPtrWillBeRawPtr<ContainerNode> scope = nullptr; | 149 forceListCreation = !selectionHasListOfType(selection, listTag); |
| 140 int indexForEndOfSelection = indexForVisiblePosition(endOfSelection, scope); | |
| 141 bool forceCreateList = !selectionHasListOfType(selection, listTag); | |
| 142 | 150 |
| 143 RefPtrWillBeRawPtr<Range> currentSelection = endingSelection().first Range(); | |
| 144 VisiblePosition startOfCurrentParagraph = startOfSelection; | 151 VisiblePosition startOfCurrentParagraph = startOfSelection; |
| 145 while (startOfCurrentParagraph.isNotNull() && !inSameParagraph(start OfCurrentParagraph, startOfLastParagraph, CanCrossEditingBoundary)) { | 152 while (startOfCurrentParagraph.isNotNull() && !inSameParagraph(start OfCurrentParagraph, startOfLastParagraph, CanCrossEditingBoundary)) { |
| 146 // doApply() may operate on and remove the last paragraph of the selection from the document | 153 // 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 | 154 // 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. | 155 // infinite loop and because there is no more work to be done. |
| 149 // FIXME(<rdar://problem/5983974>): The endingSelection() may be incorrect here. Compute | 156 // 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. | 157 // the new location of endOfSelection and use it as the end of t he new selection. |
| 151 if (!startOfLastParagraph.deepEquivalent().inDocument()) | 158 if (!startOfLastParagraph.deepEquivalent().inDocument()) |
| 152 return; | 159 return; |
| 153 setEndingSelection(startOfCurrentParagraph); | 160 setEndingSelection(startOfCurrentParagraph); |
| 154 | 161 |
| 155 // Save and restore endOfSelection and startOfLastParagraph when necessary | 162 // Save and restore endOfSelection and startOfLastParagraph when necessary |
| 156 // since moveParagraph and movePragraphWithClones can remove nod es. | 163 // since moveParagraph and movePragraphWithClones can remove nod es. |
| 157 // FIXME: This is an inefficient way to keep selection alive bec ause indexForVisiblePosition walks from | 164 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()) { | 165 if (endOfSelection.isNull() || endOfSelection.isOrphan() || star tOfLastParagraph.isNull() || startOfLastParagraph.isOrphan()) { |
| 162 endOfSelection = visiblePositionForIndex(indexForEndOfSelect ion, scope.get()); | 166 endOfSelection = visiblePositionForIndex(indexForEndOfSelect ion, scopeForEndOfSelection.get()); |
| 163 // If endOfSelection is null, then some contents have been d eleted from the document. | 167 // 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. | 168 // This should never happen and if it did, exit early immedi ately because we've lost the loop invariant. |
| 165 ASSERT(endOfSelection.isNotNull()); | 169 ASSERT(endOfSelection.isNotNull()); |
| 166 if (endOfSelection.isNull()) | 170 if (endOfSelection.isNull()) |
| 167 return; | 171 return; |
| 168 startOfLastParagraph = startOfParagraph(endOfSelection, CanS kipOverEditingBoundary); | 172 startOfLastParagraph = startOfParagraph(endOfSelection, CanS kipOverEditingBoundary); |
| 169 } | 173 } |
| 170 | 174 |
| 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()); | 175 startOfCurrentParagraph = startOfNextParagraph(endingSelection() .visibleStart()); |
| 179 } | 176 } |
| 180 setEndingSelection(endOfSelection); | 177 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 } | 178 } |
| 179 doApplyForSingleParagraph(forceListCreation, listTag, *currentSelection) ; | |
| 180 // Fetch the end of the selection, for the reason mentioned above. | |
| 181 if (endOfSelection.isNull() || endOfSelection.isOrphan()) { | |
| 182 endOfSelection = visiblePositionForIndex(indexForEndOfSelection, sco peForEndOfSelection.get()); | |
| 183 if (endOfSelection.isNull()) | |
| 184 return; | |
| 185 } | |
| 186 if (startOfSelection.isNull() || startOfSelection.isOrphan()) { | |
| 187 startOfSelection = visiblePositionForIndex(indexForStartOfSelection, scopeForStartOfSelection.get()); | |
| 188 if (startOfSelection.isNull()) | |
| 189 return; | |
| 190 } | |
| 191 setEndingSelection(VisibleSelection(startOfSelection, endOfSelection, en dingSelection().isDirectional())); | |
| 192 return; | |
| 191 } | 193 } |
| 192 | 194 |
| 193 ASSERT(endingSelection().firstRange()); | 195 ASSERT(endingSelection().firstRange()); |
| 194 doApplyForSingleParagraph(false, listTag, *endingSelection().firstRange()); | 196 doApplyForSingleParagraph(false, listTag, *endingSelection().firstRange()); |
| 195 } | 197 } |
| 196 | 198 |
| 197 void InsertListCommand::doApplyForSingleParagraph(bool forceCreateList, const Qu alifiedName& listTag, Range& currentSelection) | 199 void InsertListCommand::doApplyForSingleParagraph(bool forceCreateList, const Qu alifiedName& listTag, Range& currentSelection) |
| 198 { | 200 { |
| 199 // FIXME: This will produce unexpected results for a selection that starts j ust before a | 201 // 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 | 202 // 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; | 407 return listElement; |
| 406 } | 408 } |
| 407 | 409 |
| 408 void InsertListCommand::trace(Visitor* visitor) | 410 void InsertListCommand::trace(Visitor* visitor) |
| 409 { | 411 { |
| 410 visitor->trace(m_listElement); | 412 visitor->trace(m_listElement); |
| 411 CompositeEditCommand::trace(visitor); | 413 CompositeEditCommand::trace(visitor); |
| 412 } | 414 } |
| 413 | 415 |
| 414 } | 416 } |
| OLD | NEW |