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 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 355 } | 355 } |
| 356 | 356 |
| 357 PassRefPtrWillBeRawPtr<HTMLElement> InsertListCommand::listifyParagraph(const Vi siblePosition& originalStart, const HTMLQualifiedName& listTag) | 357 PassRefPtrWillBeRawPtr<HTMLElement> InsertListCommand::listifyParagraph(const Vi siblePosition& originalStart, const HTMLQualifiedName& listTag) |
| 358 { | 358 { |
| 359 VisiblePosition start = startOfParagraph(originalStart, CanSkipOverEditingBo undary); | 359 VisiblePosition start = startOfParagraph(originalStart, CanSkipOverEditingBo undary); |
| 360 VisiblePosition end = endOfParagraph(start, CanSkipOverEditingBoundary); | 360 VisiblePosition end = endOfParagraph(start, CanSkipOverEditingBoundary); |
| 361 | 361 |
| 362 if (start.isNull() || end.isNull()) | 362 if (start.isNull() || end.isNull()) |
| 363 return nullptr; | 363 return nullptr; |
| 364 | 364 |
| 365 { | |
| 366 // The paragraph between |start| and |end| shoule be editable. | |
| 367 Position startPosition = start.toParentAnchoredPosition(); | |
|
yosin_UTC9
2016/01/12 05:51:44
nit: |const Position&|
| |
| 368 Position endPosition = end.toParentAnchoredPosition(); | |
|
yosin_UTC9
2016/01/12 05:51:44
nit: |const Position&|
| |
| 369 if (!isEditablePosition(startPosition) || !isEditablePosition(endPositio n)) | |
| 370 return nullptr; | |
| 371 Node* commonAncestor = NodeTraversal::commonAncestor(*startPosition.anch orNode(), *endPosition.anchorNode()); | |
| 372 if (!commonAncestor || !commonAncestor->hasEditableStyle()) | |
| 373 return nullptr; | |
| 374 } | |
| 375 | |
| 365 // Check for adjoining lists. | 376 // Check for adjoining lists. |
| 366 RefPtrWillBeRawPtr<HTMLElement> listItemElement = HTMLLIElement::create(docu ment()); | 377 RefPtrWillBeRawPtr<HTMLElement> listItemElement = HTMLLIElement::create(docu ment()); |
| 367 RefPtrWillBeRawPtr<HTMLBRElement> placeholder = HTMLBRElement::create(docume nt()); | 378 RefPtrWillBeRawPtr<HTMLBRElement> placeholder = HTMLBRElement::create(docume nt()); |
| 368 appendNode(placeholder, listItemElement); | 379 appendNode(placeholder, listItemElement); |
| 369 | 380 |
| 370 // Place list item into adjoining lists. | 381 // Place list item into adjoining lists. |
| 371 HTMLElement* previousList = adjacentEnclosingList(start, previousPositionOf( start, CannotCrossEditingBoundary), listTag); | 382 HTMLElement* previousList = adjacentEnclosingList(start, previousPositionOf( start, CannotCrossEditingBoundary), listTag); |
| 372 HTMLElement* nextList = adjacentEnclosingList(start, nextPositionOf(end, Can notCrossEditingBoundary), listTag); | 383 HTMLElement* nextList = adjacentEnclosingList(start, nextPositionOf(end, Can notCrossEditingBoundary), listTag); |
| 373 RefPtrWillBeRawPtr<HTMLElement> listElement = nullptr; | 384 RefPtrWillBeRawPtr<HTMLElement> newListElementToBeInserted = nullptr; |
|
yosin_UTC9
2016/01/12 05:51:44
It seems renaming |listElement| to |lnewListElemen
| |
| 374 if (previousList) { | 385 if (previousList) { |
| 375 appendNode(listItemElement, previousList); | 386 appendNode(listItemElement, previousList); |
| 376 } else if (nextList) { | 387 } else if (nextList) { |
| 377 insertNodeAt(listItemElement, positionBeforeNode(nextList)); | 388 insertNodeAt(listItemElement, positionBeforeNode(nextList)); |
| 378 } else { | 389 } else { |
| 379 // Create the list. | 390 // Create the list. |
| 380 listElement = createHTMLElement(document(), listTag); | 391 newListElementToBeInserted = createHTMLElement(document(), listTag); |
| 381 appendNode(listItemElement, listElement); | 392 appendNode(listItemElement, newListElementToBeInserted); |
| 382 | 393 |
| 383 if (start.deepEquivalent() == end.deepEquivalent() && isEnclosingBlock(s tart.deepEquivalent().anchorNode())) { | 394 if (start.deepEquivalent() == end.deepEquivalent() && isEnclosingBlock(s tart.deepEquivalent().anchorNode())) { |
| 384 // Inserting the list into an empty paragraph that isn't held open | 395 // Inserting the list into an empty paragraph that isn't held open |
| 385 // by a br or a '\n', will invalidate start and end. Insert | 396 // by a br or a '\n', will invalidate start and end. Insert |
| 386 // a placeholder and then recompute start and end. | 397 // a placeholder and then recompute start and end. |
| 387 RefPtrWillBeRawPtr<HTMLBRElement> placeholder = insertBlockPlacehold er(start.deepEquivalent()); | 398 RefPtrWillBeRawPtr<HTMLBRElement> placeholder = insertBlockPlacehold er(start.deepEquivalent()); |
| 388 start = createVisiblePosition(positionBeforeNode(placeholder.get())) ; | 399 start = createVisiblePosition(positionBeforeNode(placeholder.get())) ; |
| 389 end = start; | 400 end = start; |
| 390 } | 401 } |
| 391 | 402 |
| 392 // Insert the list at a position visually equivalent to start of the | 403 // Insert the list at a position visually equivalent to start of the |
| 393 // paragraph that is being moved into the list. | 404 // paragraph that is being moved into the list. |
| 394 // Try to avoid inserting it somewhere where it will be surrounded by | 405 // Try to avoid inserting it somewhere where it will be surrounded by |
| 395 // inline ancestors of start, since it is easier for editing to produce | 406 // inline ancestors of start, since it is easier for editing to produce |
| 396 // clean markup when inline elements are pushed down as far as possible. | 407 // clean markup when inline elements are pushed down as far as possible. |
| 397 Position insertionPos(mostBackwardCaretPosition(start.deepEquivalent())) ; | 408 Position insertionPos(mostBackwardCaretPosition(start.deepEquivalent())) ; |
| 398 // Also avoid the containing list item. | 409 // Also avoid the containing list item. |
| 399 Node* listChild = enclosingListChild(insertionPos.anchorNode()); | 410 Node* listChild = enclosingListChild(insertionPos.anchorNode()); |
| 400 if (isHTMLLIElement(listChild)) | 411 if (isHTMLLIElement(listChild)) |
| 401 insertionPos = positionInParentBeforeNode(*listChild); | 412 insertionPos = positionInParentBeforeNode(*listChild); |
| 402 | 413 |
| 403 insertNodeAt(listElement, insertionPos); | 414 insertNodeAt(newListElementToBeInserted, insertionPos); |
| 404 | 415 |
| 405 // We inserted the list at the start of the content we're about to move | 416 // We inserted the list at the start of the content we're about to move |
| 406 // Update the start of content, so we don't try to move the list into it self. bug 19066 | 417 // Update the start of content, so we don't try to move the list into it self. bug 19066 |
| 407 // Layout is necessary since start's node's inline layoutObjects may hav e been destroyed by the insertion | 418 // Layout is necessary since start's node's inline layoutObjects may hav e been destroyed by the insertion |
| 408 // The end of the content may have changed after the insertion and layou t so update it as well. | 419 // The end of the content may have changed after the insertion and layou t so update it as well. |
| 409 if (insertionPos == start.deepEquivalent()) | 420 if (insertionPos == start.deepEquivalent()) |
| 410 start = originalStart; | 421 start = originalStart; |
| 411 } | 422 } |
| 412 | 423 |
| 413 // Inserting list element and list item list may change start of pargraph | 424 // Inserting list element and list item list may change start of pargraph |
| 414 // to move. We calculate start of paragraph again. | 425 // to move. We calculate start of paragraph again. |
| 415 document().updateLayoutIgnorePendingStylesheets(); | 426 document().updateLayoutIgnorePendingStylesheets(); |
| 416 start = startOfParagraph(start, CanSkipOverEditingBoundary); | 427 const VisiblePosition paragraphStartToInsert = startOfParagraph(start, CanSk ipOverEditingBoundary); |
|
yosin_UTC9
2016/01/12 05:51:44
nit: |const VisiblePosition&|
This is kind of rena
| |
| 417 end = endOfParagraph(start, CanSkipOverEditingBoundary); | 428 moveParagraph(paragraphStartToInsert, endOfParagraph(paragraphStartToInsert, CanSkipOverEditingBoundary), |
| 418 moveParagraph(start, end, createVisiblePosition(positionBeforeNode(placehold er.get())), true); | 429 createVisiblePosition(positionBeforeNode(placeholder.get())), true); |
| 419 | 430 |
| 420 if (listElement) | 431 if (newListElementToBeInserted) |
| 421 return mergeWithNeighboringLists(listElement); | 432 return mergeWithNeighboringLists(newListElementToBeInserted); |
| 422 | 433 |
| 423 if (canMergeLists(previousList, nextList)) | 434 if (canMergeLists(previousList, nextList)) |
| 424 mergeIdenticalElements(previousList, nextList); | 435 mergeIdenticalElements(previousList, nextList); |
| 425 | 436 |
| 426 return listElement; | 437 return nullptr; |
| 427 } | 438 } |
| 428 | 439 |
| 429 DEFINE_TRACE(InsertListCommand) | 440 DEFINE_TRACE(InsertListCommand) |
| 430 { | 441 { |
| 431 visitor->trace(m_listElement); | 442 visitor->trace(m_listElement); |
| 432 CompositeEditCommand::trace(visitor); | 443 CompositeEditCommand::trace(visitor); |
| 433 } | 444 } |
| 434 | 445 |
| 435 } | 446 } |
| OLD | NEW |