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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 } | 99 } |
100 | 100 |
101 return true; | 101 return true; |
102 } | 102 } |
103 | 103 |
104 InsertListCommand::InsertListCommand(Document& document, Type type) | 104 InsertListCommand::InsertListCommand(Document& document, Type type) |
105 : CompositeEditCommand(document), m_type(type) | 105 : CompositeEditCommand(document), m_type(type) |
106 { | 106 { |
107 } | 107 } |
108 | 108 |
| 109 static bool inSameTreeAndOrdered(const VisiblePosition& shouldBeFormer, const Vi
siblePosition& shouldBeLater) |
| 110 { |
| 111 const Position formerPosition = shouldBeFormer.deepEquivalent(); |
| 112 const Position laterPosition = shouldBeLater.deepEquivalent(); |
| 113 return Position::commonAncestorTreeScope(formerPosition, laterPosition) && c
omparePositions(formerPosition, laterPosition) <= 0; |
| 114 } |
| 115 |
109 void InsertListCommand::doApply() | 116 void InsertListCommand::doApply() |
110 { | 117 { |
111 if (!endingSelection().isNonOrphanedCaretOrRange()) | 118 if (!endingSelection().isNonOrphanedCaretOrRange()) |
112 return; | 119 return; |
113 | 120 |
114 if (!endingSelection().rootEditableElement()) | 121 if (!endingSelection().rootEditableElement()) |
115 return; | 122 return; |
116 | 123 |
117 VisiblePosition visibleEnd = endingSelection().visibleEnd(); | 124 VisiblePosition visibleEnd = endingSelection().visibleEnd(); |
118 VisiblePosition visibleStart = endingSelection().visibleStart(); | 125 VisiblePosition visibleStart = endingSelection().visibleStart(); |
(...skipping 27 matching lines...) Expand all Loading... |
146 // indexForVisiblePosition walks from the beginning of the document to t
he | 153 // indexForVisiblePosition walks from the beginning of the document to t
he |
147 // endOfSelection everytime this code is executed. But not using index i
s hard | 154 // endOfSelection everytime this code is executed. But not using index i
s hard |
148 // because there are so many ways we can los eselection inside doApplyFo
rSingleParagraph. | 155 // because there are so many ways we can los eselection inside doApplyFo
rSingleParagraph. |
149 int indexForStartOfSelection = indexForVisiblePosition(startOfSelection,
scopeForStartOfSelection); | 156 int indexForStartOfSelection = indexForVisiblePosition(startOfSelection,
scopeForStartOfSelection); |
150 int indexForEndOfSelection = indexForVisiblePosition(endOfSelection, sco
peForEndOfSelection); | 157 int indexForEndOfSelection = indexForVisiblePosition(endOfSelection, sco
peForEndOfSelection); |
151 | 158 |
152 if (startOfParagraph(startOfSelection, CanSkipOverEditingBoundary).deepE
quivalent() != startOfLastParagraph.deepEquivalent()) { | 159 if (startOfParagraph(startOfSelection, CanSkipOverEditingBoundary).deepE
quivalent() != startOfLastParagraph.deepEquivalent()) { |
153 forceListCreation = !selectionHasListOfType(selection, listTag); | 160 forceListCreation = !selectionHasListOfType(selection, listTag); |
154 | 161 |
155 VisiblePosition startOfCurrentParagraph = startOfSelection; | 162 VisiblePosition startOfCurrentParagraph = startOfSelection; |
156 while (startOfCurrentParagraph.isNotNull() && !inSameParagraph(start
OfCurrentParagraph, startOfLastParagraph, CanCrossEditingBoundary)) { | 163 while (inSameTreeAndOrdered(startOfCurrentParagraph, startOfLastPara
graph) && !inSameParagraph(startOfCurrentParagraph, startOfLastParagraph, CanCro
ssEditingBoundary)) { |
157 // doApply() may operate on and remove the last paragraph of the
selection from the document | 164 // doApply() may operate on and remove the last paragraph of the
selection from the document |
158 // if it's in the same list item as startOfCurrentParagraph. Re
turn early to avoid an | 165 // if it's in the same list item as startOfCurrentParagraph. Re
turn early to avoid an |
159 // infinite loop and because there is no more work to be done. | 166 // infinite loop and because there is no more work to be done. |
160 // FIXME(<rdar://problem/5983974>): The endingSelection() may be
incorrect here. Compute | 167 // FIXME(<rdar://problem/5983974>): The endingSelection() may be
incorrect here. Compute |
161 // the new location of endOfSelection and use it as the end of t
he new selection. | 168 // the new location of endOfSelection and use it as the end of t
he new selection. |
162 if (!startOfLastParagraph.deepEquivalent().inDocument()) | 169 if (!startOfLastParagraph.deepEquivalent().inDocument()) |
163 return; | 170 return; |
164 setEndingSelection(startOfCurrentParagraph); | 171 setEndingSelection(startOfCurrentParagraph); |
165 | 172 |
166 // Save and restore endOfSelection and startOfLastParagraph when
necessary | 173 // Save and restore endOfSelection and startOfLastParagraph when
necessary |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 return listElement; | 427 return listElement; |
421 } | 428 } |
422 | 429 |
423 DEFINE_TRACE(InsertListCommand) | 430 DEFINE_TRACE(InsertListCommand) |
424 { | 431 { |
425 visitor->trace(m_listElement); | 432 visitor->trace(m_listElement); |
426 CompositeEditCommand::trace(visitor); | 433 CompositeEditCommand::trace(visitor); |
427 } | 434 } |
428 | 435 |
429 } | 436 } |
OLD | NEW |