Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: third_party/WebKit/Source/core/editing/commands/InsertListCommand.cpp

Issue 2757563004: Adjust insertion point when listifying unordered list items (Closed)
Patch Set: Added regression test. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 590 matching lines...) Expand 10 before | Expand all | Expand 10 after
601 } 601 }
602 602
603 document().updateStyleAndLayoutIgnorePendingStylesheets(); 603 document().updateStyleAndLayoutIgnorePendingStylesheets();
604 604
605 // Insert the list at a position visually equivalent to start of the 605 // Insert the list at a position visually equivalent to start of the
606 // paragraph that is being moved into the list. 606 // paragraph that is being moved into the list.
607 // Try to avoid inserting it somewhere where it will be surrounded by 607 // Try to avoid inserting it somewhere where it will be surrounded by
608 // inline ancestors of start, since it is easier for editing to produce 608 // inline ancestors of start, since it is easier for editing to produce
609 // clean markup when inline elements are pushed down as far as possible. 609 // clean markup when inline elements are pushed down as far as possible.
610 Position insertionPos(mostBackwardCaretPosition(startPos)); 610 Position insertionPos(mostBackwardCaretPosition(startPos));
611 // Also avoid the temporary <span> element created by 'unlistifyParagraph'.
612 // This element can be selected by mostBackwardCaretPosition when startPor
613 // points to a element with previous siblings or ancestors with siblings.
614 // |-A
615 // | |-B
616 // | +-C (insertion point)
617 // | |-D (*)
618 if (isHTMLSpanElement(insertionPos.anchorNode()))
yosin_UTC9 2017/03/21 05:37:20 Could you use Position::computeContainerNode() ins
jfernandez 2017/03/24 01:57:55 Done.
619 insertionPos = Position::inParentBeforeNode(*insertionPos.anchorNode());
611 // Also avoid the containing list item. 620 // Also avoid the containing list item.
612 Node* const listChild = enclosingListChild(insertionPos.anchorNode()); 621 Node* const listChild = enclosingListChild(insertionPos.anchorNode());
613 if (isHTMLLIElement(listChild)) 622 if (isHTMLLIElement(listChild))
614 insertionPos = Position::inParentBeforeNode(*listChild); 623 insertionPos = Position::inParentBeforeNode(*listChild);
615 624
616 HTMLElement* listElement = createHTMLElement(document(), listTag); 625 HTMLElement* listElement = createHTMLElement(document(), listTag);
617 insertNodeAt(listElement, insertionPos, editingState); 626 insertNodeAt(listElement, insertionPos, editingState);
618 if (editingState->isAborted()) 627 if (editingState->isAborted())
619 return; 628 return;
620 HTMLLIElement* listItemElement = HTMLLIElement::create(document()); 629 HTMLLIElement* listItemElement = HTMLLIElement::create(document());
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
663 endOfParagraph(validPos, CanSkipOverEditingBoundary); 672 endOfParagraph(validPos, CanSkipOverEditingBoundary);
664 moveParagraph(start, end, VisiblePosition::beforeNode(placeholder), 673 moveParagraph(start, end, VisiblePosition::beforeNode(placeholder),
665 editingState, PreserveSelection); 674 editingState, PreserveSelection);
666 } 675 }
667 676
668 DEFINE_TRACE(InsertListCommand) { 677 DEFINE_TRACE(InsertListCommand) {
669 CompositeEditCommand::trace(visitor); 678 CompositeEditCommand::trace(visitor);
670 } 679 }
671 680
672 } // namespace blink 681 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698