| 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 |
| 11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
| 12 * | 12 * |
| 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY | 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY |
| 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR |
| 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 */ | 24 */ |
| 25 | 25 |
| 26 #include "config.h" | 26 #include "config.h" |
| 27 #include "core/editing/InsertListCommand.h" | 27 #include "core/editing/commands/InsertListCommand.h" |
| 28 | 28 |
| 29 #include "bindings/core/v8/ExceptionStatePlaceholder.h" | 29 #include "bindings/core/v8/ExceptionStatePlaceholder.h" |
| 30 #include "core/HTMLNames.h" | 30 #include "core/HTMLNames.h" |
| 31 #include "core/dom/Document.h" | 31 #include "core/dom/Document.h" |
| 32 #include "core/dom/Element.h" | 32 #include "core/dom/Element.h" |
| 33 #include "core/dom/ElementTraversal.h" | 33 #include "core/dom/ElementTraversal.h" |
| 34 #include "core/editing/EditingUtilities.h" | 34 #include "core/editing/EditingUtilities.h" |
| 35 #include "core/editing/VisibleUnits.h" | 35 #include "core/editing/VisibleUnits.h" |
| 36 #include "core/editing/iterators/TextIterator.h" | 36 #include "core/editing/iterators/TextIterator.h" |
| 37 #include "core/html/HTMLBRElement.h" | 37 #include "core/html/HTMLBRElement.h" |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 bool switchListType = false; | 211 bool switchListType = false; |
| 212 if (listChildNode) { | 212 if (listChildNode) { |
| 213 if (!listChildNode->parentNode()->hasEditableStyle()) | 213 if (!listChildNode->parentNode()->hasEditableStyle()) |
| 214 return false; | 214 return false; |
| 215 // Remove the list child. | 215 // Remove the list child. |
| 216 RefPtrWillBeRawPtr<HTMLElement> listElement = enclosingList(listChildNod
e); | 216 RefPtrWillBeRawPtr<HTMLElement> listElement = enclosingList(listChildNod
e); |
| 217 if (!listElement) { | 217 if (!listElement) { |
| 218 listElement = fixOrphanedListChild(listChildNode); | 218 listElement = fixOrphanedListChild(listChildNode); |
| 219 listElement = mergeWithNeighboringLists(listElement); | 219 listElement = mergeWithNeighboringLists(listElement); |
| 220 } | 220 } |
| 221 if (!listElement->hasTagName(listTag)) | 221 if (!listElement->hasTagName(listTag)) { |
| 222 // listChildNode will be removed from the list and a list of type m_
type will be created. | 222 // listChildNode will be removed from the list and a list of type m_
type will be created. |
| 223 switchListType = true; | 223 switchListType = true; |
| 224 } |
| 224 | 225 |
| 225 // If the list is of the desired type, and we are not removing the list,
then exit early. | 226 // If the list is of the desired type, and we are not removing the list,
then exit early. |
| 226 if (!switchListType && forceCreateList) | 227 if (!switchListType && forceCreateList) |
| 227 return true; | 228 return true; |
| 228 | 229 |
| 229 // If the entire list is selected, then convert the whole list. | 230 // If the entire list is selected, then convert the whole list. |
| 230 if (switchListType && isNodeVisiblyContainedWithin(*listElement, current
Selection)) { | 231 if (switchListType && isNodeVisiblyContainedWithin(*listElement, current
Selection)) { |
| 231 bool rangeStartIsInList = visiblePositionBeforeNode(*listElement).de
epEquivalent() == VisiblePosition(currentSelection.startPosition()).deepEquivale
nt(); | 232 bool rangeStartIsInList = visiblePositionBeforeNode(*listElement).de
epEquivalent() == VisiblePosition(currentSelection.startPosition()).deepEquivale
nt(); |
| 232 bool rangeEndIsInList = visiblePositionAfterNode(*listElement).deepE
quivalent() == VisiblePosition(currentSelection.endPosition()).deepEquivalent(); | 233 bool rangeEndIsInList = visiblePositionAfterNode(*listElement).deepE
quivalent() == VisiblePosition(currentSelection.endPosition()).deepEquivalent(); |
| 233 | 234 |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 | 356 |
| 356 // Check for adjoining lists. | 357 // Check for adjoining lists. |
| 357 RefPtrWillBeRawPtr<HTMLElement> listItemElement = createListItemElement(docu
ment()); | 358 RefPtrWillBeRawPtr<HTMLElement> listItemElement = createListItemElement(docu
ment()); |
| 358 RefPtrWillBeRawPtr<HTMLBRElement> placeholder = createBreakElement(document(
)); | 359 RefPtrWillBeRawPtr<HTMLBRElement> placeholder = createBreakElement(document(
)); |
| 359 appendNode(placeholder, listItemElement); | 360 appendNode(placeholder, listItemElement); |
| 360 | 361 |
| 361 // Place list item into adjoining lists. | 362 // Place list item into adjoining lists. |
| 362 HTMLElement* previousList = adjacentEnclosingList(start, start.previous(Cann
otCrossEditingBoundary), listTag); | 363 HTMLElement* previousList = adjacentEnclosingList(start, start.previous(Cann
otCrossEditingBoundary), listTag); |
| 363 HTMLElement* nextList = adjacentEnclosingList(start, end.next(CannotCrossEdi
tingBoundary), listTag); | 364 HTMLElement* nextList = adjacentEnclosingList(start, end.next(CannotCrossEdi
tingBoundary), listTag); |
| 364 RefPtrWillBeRawPtr<HTMLElement> listElement = nullptr; | 365 RefPtrWillBeRawPtr<HTMLElement> listElement = nullptr; |
| 365 if (previousList) | 366 if (previousList) { |
| 366 appendNode(listItemElement, previousList); | 367 appendNode(listItemElement, previousList); |
| 367 else if (nextList) | 368 } else if (nextList) { |
| 368 insertNodeAt(listItemElement, positionBeforeNode(nextList)); | 369 insertNodeAt(listItemElement, positionBeforeNode(nextList)); |
| 369 else { | 370 } else { |
| 370 // Create the list. | 371 // Create the list. |
| 371 listElement = createHTMLElement(document(), listTag); | 372 listElement = createHTMLElement(document(), listTag); |
| 372 appendNode(listItemElement, listElement); | 373 appendNode(listItemElement, listElement); |
| 373 | 374 |
| 374 if (start.deepEquivalent() == end.deepEquivalent() && isBlock(start.deep
Equivalent().anchorNode())) { | 375 if (start.deepEquivalent() == end.deepEquivalent() && isBlock(start.deep
Equivalent().anchorNode())) { |
| 375 // Inserting the list into an empty paragraph that isn't held open | 376 // Inserting the list into an empty paragraph that isn't held open |
| 376 // by a br or a '\n', will invalidate start and end. Insert | 377 // by a br or a '\n', will invalidate start and end. Insert |
| 377 // a placeholder and then recompute start and end. | 378 // a placeholder and then recompute start and end. |
| 378 RefPtrWillBeRawPtr<HTMLBRElement> placeholder = insertBlockPlacehold
er(start.deepEquivalent()); | 379 RefPtrWillBeRawPtr<HTMLBRElement> placeholder = insertBlockPlacehold
er(start.deepEquivalent()); |
| 379 start = VisiblePosition(positionBeforeNode(placeholder.get())); | 380 start = VisiblePosition(positionBeforeNode(placeholder.get())); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 return listElement; | 418 return listElement; |
| 418 } | 419 } |
| 419 | 420 |
| 420 DEFINE_TRACE(InsertListCommand) | 421 DEFINE_TRACE(InsertListCommand) |
| 421 { | 422 { |
| 422 visitor->trace(m_listElement); | 423 visitor->trace(m_listElement); |
| 423 CompositeEditCommand::trace(visitor); | 424 CompositeEditCommand::trace(visitor); |
| 424 } | 425 } |
| 425 | 426 |
| 426 } | 427 } |
| OLD | NEW |