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 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 if (listNode && listNode->inDocument()) | 235 if (listNode && listNode->inDocument()) |
236 removeNode(listNode); | 236 removeNode(listNode); |
237 | 237 |
238 newList = mergeWithNeighboringLists(newList); | 238 newList = mergeWithNeighboringLists(newList); |
239 | 239 |
240 // Restore the start and the end of current selection if they starte
d inside listNode | 240 // Restore the start and the end of current selection if they starte
d inside listNode |
241 // because moveParagraphWithClones could have removed them. | 241 // because moveParagraphWithClones could have removed them. |
242 if (rangeStartIsInList && newList) | 242 if (rangeStartIsInList && newList) |
243 currentSelection.setStart(newList, 0, IGNORE_EXCEPTION); | 243 currentSelection.setStart(newList, 0, IGNORE_EXCEPTION); |
244 if (rangeEndIsInList && newList) | 244 if (rangeEndIsInList && newList) |
245 currentSelection.setEnd(newList, lastOffsetInNode(newList.get())
, IGNORE_EXCEPTION); | 245 currentSelection.setEnd(newList, lastOffsetInNode(*newList), IGN
ORE_EXCEPTION); |
246 | 246 |
247 setEndingSelection(VisiblePosition(firstPositionInNode(newList.get()
))); | 247 setEndingSelection(VisiblePosition(firstPositionInNode(newList.get()
))); |
248 | 248 |
249 return; | 249 return; |
250 } | 250 } |
251 | 251 |
252 unlistifyParagraph(endingSelection().visibleStart(), listNode.get(), lis
tChildNode); | 252 unlistifyParagraph(endingSelection().visibleStart(), listNode.get(), lis
tChildNode); |
253 } | 253 } |
254 | 254 |
255 if (!listChildNode || switchListType || forceCreateList) | 255 if (!listChildNode || switchListType || forceCreateList) |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 // Just because listChildNode has no previousListChild doesn't mean ther
e isn't any content | 301 // Just because listChildNode has no previousListChild doesn't mean ther
e isn't any content |
302 // in listNode that comes before listChildNode, as listChildNode could h
ave ancestors | 302 // in listNode that comes before listChildNode, as listChildNode could h
ave ancestors |
303 // between it and listNode. So, we split up to listNode before inserting
the placeholder | 303 // between it and listNode. So, we split up to listNode before inserting
the placeholder |
304 // where we're about to move listChildNode to. | 304 // where we're about to move listChildNode to. |
305 if (listChildNode->parentNode() != listNode) | 305 if (listChildNode->parentNode() != listNode) |
306 splitElement(listNode, splitTreeToNode(listChildNode, listNode).get(
)); | 306 splitElement(listNode, splitTreeToNode(listChildNode, listNode).get(
)); |
307 insertNodeBefore(nodeToInsert, listNode); | 307 insertNodeBefore(nodeToInsert, listNode); |
308 } else | 308 } else |
309 insertNodeAfter(nodeToInsert, listNode); | 309 insertNodeAfter(nodeToInsert, listNode); |
310 | 310 |
311 VisiblePosition insertionPoint = VisiblePosition(positionBeforeNode(placehol
der.get())); | 311 VisiblePosition insertionPoint = VisiblePosition(positionBeforeNode(*placeho
lder)); |
312 moveParagraphs(start, end, insertionPoint, /* preserveSelection */ true, /*
preserveStyle */ true, listChildNode); | 312 moveParagraphs(start, end, insertionPoint, /* preserveSelection */ true, /*
preserveStyle */ true, listChildNode); |
313 } | 313 } |
314 | 314 |
315 static Element* adjacentEnclosingList(const VisiblePosition& pos, const VisibleP
osition& adjacentPos, const QualifiedName& listTag) | 315 static Element* adjacentEnclosingList(const VisiblePosition& pos, const VisibleP
osition& adjacentPos, const QualifiedName& listTag) |
316 { | 316 { |
317 Element* listNode = outermostEnclosingList(adjacentPos.deepEquivalent().depr
ecatedNode()); | 317 Element* listNode = outermostEnclosingList(adjacentPos.deepEquivalent().depr
ecatedNode()); |
318 | 318 |
319 if (!listNode) | 319 if (!listNode) |
320 return 0; | 320 return 0; |
321 | 321 |
(...skipping 19 matching lines...) Expand all Loading... |
341 | 341 |
342 // Check for adjoining lists. | 342 // Check for adjoining lists. |
343 RefPtr<HTMLElement> listItemElement = createListItemElement(document()); | 343 RefPtr<HTMLElement> listItemElement = createListItemElement(document()); |
344 RefPtr<HTMLElement> placeholder = createBreakElement(document()); | 344 RefPtr<HTMLElement> placeholder = createBreakElement(document()); |
345 appendNode(placeholder, listItemElement); | 345 appendNode(placeholder, listItemElement); |
346 | 346 |
347 // Place list item into adjoining lists. | 347 // Place list item into adjoining lists. |
348 Element* previousList = adjacentEnclosingList(start, start.previous(CannotCr
ossEditingBoundary), listTag); | 348 Element* previousList = adjacentEnclosingList(start, start.previous(CannotCr
ossEditingBoundary), listTag); |
349 Element* nextList = adjacentEnclosingList(start, end.next(CannotCrossEditing
Boundary), listTag); | 349 Element* nextList = adjacentEnclosingList(start, end.next(CannotCrossEditing
Boundary), listTag); |
350 RefPtr<HTMLElement> listElement; | 350 RefPtr<HTMLElement> listElement; |
351 if (previousList) | 351 if (previousList) { |
352 appendNode(listItemElement, previousList); | 352 appendNode(listItemElement, previousList); |
353 else if (nextList) | 353 } else if (nextList) { |
354 insertNodeAt(listItemElement, positionBeforeNode(nextList)); | 354 insertNodeAt(listItemElement, positionBeforeNode(*nextList)); |
355 else { | 355 } else { |
356 // Create the list. | 356 // Create the list. |
357 listElement = createHTMLElement(document(), listTag); | 357 listElement = createHTMLElement(document(), listTag); |
358 appendNode(listItemElement, listElement); | 358 appendNode(listItemElement, listElement); |
359 | 359 |
360 if (start == end && isBlock(start.deepEquivalent().deprecatedNode())) { | 360 if (start == end && isBlock(start.deepEquivalent().deprecatedNode())) { |
361 // Inserting the list into an empty paragraph that isn't held open | 361 // Inserting the list into an empty paragraph that isn't held open |
362 // by a br or a '\n', will invalidate start and end. Insert | 362 // by a br or a '\n', will invalidate start and end. Insert |
363 // a placeholder and then recompute start and end. | 363 // a placeholder and then recompute start and end. |
364 RefPtr<Node> placeholder = insertBlockPlaceholder(start.deepEquivale
nt()); | 364 RefPtr<Node> placeholder = insertBlockPlaceholder(start.deepEquivale
nt()); |
365 start = VisiblePosition(positionBeforeNode(placeholder.get())); | 365 start = VisiblePosition(positionBeforeNode(*placeholder)); |
366 end = start; | 366 end = start; |
367 } | 367 } |
368 | 368 |
369 // Insert the list at a position visually equivalent to start of the | 369 // Insert the list at a position visually equivalent to start of the |
370 // paragraph that is being moved into the list. | 370 // paragraph that is being moved into the list. |
371 // Try to avoid inserting it somewhere where it will be surrounded by | 371 // Try to avoid inserting it somewhere where it will be surrounded by |
372 // inline ancestors of start, since it is easier for editing to produce | 372 // inline ancestors of start, since it is easier for editing to produce |
373 // clean markup when inline elements are pushed down as far as possible. | 373 // clean markup when inline elements are pushed down as far as possible. |
374 Position insertionPos(start.deepEquivalent().upstream()); | 374 Position insertionPos(start.deepEquivalent().upstream()); |
375 // Also avoid the containing list item. | 375 // Also avoid the containing list item. |
376 Node* listChild = enclosingListChild(insertionPos.deprecatedNode()); | 376 Node* listChild = enclosingListChild(insertionPos.deprecatedNode()); |
377 if (listChild && listChild->hasTagName(liTag)) | 377 if (listChild && listChild->hasTagName(liTag)) |
378 insertionPos = positionInParentBeforeNode(*listChild); | 378 insertionPos = positionInParentBeforeNode(*listChild); |
379 | 379 |
380 insertNodeAt(listElement, insertionPos); | 380 insertNodeAt(listElement, insertionPos); |
381 | 381 |
382 // We inserted the list at the start of the content we're about to move | 382 // We inserted the list at the start of the content we're about to move |
383 // Update the start of content, so we don't try to move the list into it
self. bug 19066 | 383 // Update the start of content, so we don't try to move the list into it
self. bug 19066 |
384 // Layout is necessary since start's node's inline renderers may have be
en destroyed by the insertion | 384 // Layout is necessary since start's node's inline renderers may have be
en destroyed by the insertion |
385 // The end of the content may have changed after the insertion and layou
t so update it as well. | 385 // The end of the content may have changed after the insertion and layou
t so update it as well. |
386 if (insertionPos == start.deepEquivalent()) { | 386 if (insertionPos == start.deepEquivalent()) { |
387 listElement->document().updateLayoutIgnorePendingStylesheets(); | 387 listElement->document().updateLayoutIgnorePendingStylesheets(); |
388 start = startOfParagraph(originalStart, CanSkipOverEditingBoundary); | 388 start = startOfParagraph(originalStart, CanSkipOverEditingBoundary); |
389 end = endOfParagraph(start, CanSkipOverEditingBoundary); | 389 end = endOfParagraph(start, CanSkipOverEditingBoundary); |
390 } | 390 } |
391 } | 391 } |
392 | 392 |
393 moveParagraph(start, end, VisiblePosition(positionBeforeNode(placeholder.get
())), true); | 393 moveParagraph(start, end, VisiblePosition(positionBeforeNode(*placeholder)),
true); |
394 | 394 |
395 if (listElement) | 395 if (listElement) |
396 return mergeWithNeighboringLists(listElement); | 396 return mergeWithNeighboringLists(listElement); |
397 | 397 |
398 if (canMergeLists(previousList, nextList)) | 398 if (canMergeLists(previousList, nextList)) |
399 mergeIdenticalElements(previousList, nextList); | 399 mergeIdenticalElements(previousList, nextList); |
400 | 400 |
401 return listElement; | 401 return listElement; |
402 } | 402 } |
403 | 403 |
404 } | 404 } |
OLD | NEW |