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

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

Issue 1310043003: Introduce previousPositionOf() for VisiblePosition (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: 2015-08-28T16:28:03 Created 5 years, 3 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 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 VisiblePosition visibleStart = endingSelection().visibleStart(); 125 VisiblePosition visibleStart = endingSelection().visibleStart();
126 // When a selection ends at the start of a paragraph, we rarely paint 126 // When a selection ends at the start of a paragraph, we rarely paint
127 // the selection gap before that paragraph, because there often is no gap. 127 // the selection gap before that paragraph, because there often is no gap.
128 // In a case like this, it's not obvious to the user that the selection 128 // In a case like this, it's not obvious to the user that the selection
129 // ends "inside" that paragraph, so it would be confusing if InsertUn{Ordere d}List 129 // ends "inside" that paragraph, so it would be confusing if InsertUn{Ordere d}List
130 // operated on that paragraph. 130 // operated on that paragraph.
131 // FIXME: We paint the gap before some paragraphs that are indented with lef t 131 // FIXME: We paint the gap before some paragraphs that are indented with lef t
132 // margin/padding, but not others. We should make the gap painting more con sistent and 132 // margin/padding, but not others. We should make the gap painting more con sistent and
133 // then use a left margin/padding rule here. 133 // then use a left margin/padding rule here.
134 if (visibleEnd.deepEquivalent() != visibleStart.deepEquivalent() && isStartO fParagraph(visibleEnd, CanSkipOverEditingBoundary)) { 134 if (visibleEnd.deepEquivalent() != visibleStart.deepEquivalent() && isStartO fParagraph(visibleEnd, CanSkipOverEditingBoundary)) {
135 setEndingSelection(VisibleSelection(visibleStart, visibleEnd.previous(Ca nnotCrossEditingBoundary), endingSelection().isDirectional())); 135 setEndingSelection(VisibleSelection(visibleStart, previousPositionOf(vis ibleEnd, CannotCrossEditingBoundary), endingSelection().isDirectional()));
136 if (!endingSelection().rootEditableElement()) 136 if (!endingSelection().rootEditableElement())
137 return; 137 return;
138 } 138 }
139 139
140 const HTMLQualifiedName& listTag = (m_type == OrderedList) ? olTag : ulTag; 140 const HTMLQualifiedName& listTag = (m_type == OrderedList) ? olTag : ulTag;
141 if (endingSelection().isRange()) { 141 if (endingSelection().isRange()) {
142 bool forceListCreation = false; 142 bool forceListCreation = false;
143 VisibleSelection selection = selectionForParagraphIteration(endingSelect ion()); 143 VisibleSelection selection = selectionForParagraphIteration(endingSelect ion());
144 ASSERT(selection.isRange()); 144 ASSERT(selection.isRange());
145 VisiblePosition startOfSelection = selection.visibleStart(); 145 VisiblePosition startOfSelection = selection.visibleStart();
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 start = VisiblePosition(firstPositionInNode(listChildNode)); 289 start = VisiblePosition(firstPositionInNode(listChildNode));
290 end = VisiblePosition(lastPositionInNode(listChildNode)); 290 end = VisiblePosition(lastPositionInNode(listChildNode));
291 nextListChild = listChildNode->nextSibling(); 291 nextListChild = listChildNode->nextSibling();
292 previousListChild = listChildNode->previousSibling(); 292 previousListChild = listChildNode->previousSibling();
293 } else { 293 } else {
294 // A paragraph is visually a list item minus a list marker. The paragra ph will be moved. 294 // A paragraph is visually a list item minus a list marker. The paragra ph will be moved.
295 start = startOfParagraph(originalStart, CanSkipOverEditingBoundary); 295 start = startOfParagraph(originalStart, CanSkipOverEditingBoundary);
296 end = endOfParagraph(start, CanSkipOverEditingBoundary); 296 end = endOfParagraph(start, CanSkipOverEditingBoundary);
297 nextListChild = enclosingListChild(end.next().deepEquivalent().anchorNod e(), listElement); 297 nextListChild = enclosingListChild(end.next().deepEquivalent().anchorNod e(), listElement);
298 ASSERT(nextListChild != listChildNode); 298 ASSERT(nextListChild != listChildNode);
299 previousListChild = enclosingListChild(start.previous().deepEquivalent() .anchorNode(), listElement); 299 previousListChild = enclosingListChild(previousPositionOf(start).deepEqu ivalent().anchorNode(), listElement);
300 ASSERT(previousListChild != listChildNode); 300 ASSERT(previousListChild != listChildNode);
301 } 301 }
302 // When removing a list, we must always create a placeholder to act as a poi nt of insertion 302 // When removing a list, we must always create a placeholder to act as a poi nt of insertion
303 // for the list content being removed. 303 // for the list content being removed.
304 RefPtrWillBeRawPtr<HTMLBRElement> placeholder = createBreakElement(document( )); 304 RefPtrWillBeRawPtr<HTMLBRElement> placeholder = createBreakElement(document( ));
305 RefPtrWillBeRawPtr<HTMLElement> elementToInsert = placeholder; 305 RefPtrWillBeRawPtr<HTMLElement> elementToInsert = placeholder;
306 // If the content of the list item will be moved into another list, put it i n a list item 306 // If the content of the list item will be moved into another list, put it i n a list item
307 // so that we don't create an orphaned list child. 307 // so that we don't create an orphaned list child.
308 if (enclosingList(listElement)) { 308 if (enclosingList(listElement)) {
309 elementToInsert = createListItemElement(document()); 309 elementToInsert = createListItemElement(document());
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 362
363 if (start.isNull() || end.isNull()) 363 if (start.isNull() || end.isNull())
364 return nullptr; 364 return nullptr;
365 365
366 // Check for adjoining lists. 366 // Check for adjoining lists.
367 RefPtrWillBeRawPtr<HTMLElement> listItemElement = createListItemElement(docu ment()); 367 RefPtrWillBeRawPtr<HTMLElement> listItemElement = createListItemElement(docu ment());
368 RefPtrWillBeRawPtr<HTMLBRElement> placeholder = createBreakElement(document( )); 368 RefPtrWillBeRawPtr<HTMLBRElement> placeholder = createBreakElement(document( ));
369 appendNode(placeholder, listItemElement); 369 appendNode(placeholder, listItemElement);
370 370
371 // Place list item into adjoining lists. 371 // Place list item into adjoining lists.
372 HTMLElement* previousList = adjacentEnclosingList(start, start.previous(Cann otCrossEditingBoundary), listTag); 372 HTMLElement* previousList = adjacentEnclosingList(start, previousPositionOf( start, CannotCrossEditingBoundary), listTag);
373 HTMLElement* nextList = adjacentEnclosingList(start, end.next(CannotCrossEdi tingBoundary), listTag); 373 HTMLElement* nextList = adjacentEnclosingList(start, end.next(CannotCrossEdi tingBoundary), listTag);
374 RefPtrWillBeRawPtr<HTMLElement> listElement = nullptr; 374 RefPtrWillBeRawPtr<HTMLElement> listElement = nullptr;
375 if (previousList) { 375 if (previousList) {
376 appendNode(listItemElement, previousList); 376 appendNode(listItemElement, previousList);
377 } else if (nextList) { 377 } else if (nextList) {
378 insertNodeAt(listItemElement, positionBeforeNode(nextList)); 378 insertNodeAt(listItemElement, positionBeforeNode(nextList));
379 } else { 379 } else {
380 // Create the list. 380 // Create the list.
381 listElement = createHTMLElement(document(), listTag); 381 listElement = createHTMLElement(document(), listTag);
382 appendNode(listItemElement, listElement); 382 appendNode(listItemElement, listElement);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 return listElement; 427 return listElement;
428 } 428 }
429 429
430 DEFINE_TRACE(InsertListCommand) 430 DEFINE_TRACE(InsertListCommand)
431 { 431 {
432 visitor->trace(m_listElement); 432 visitor->trace(m_listElement);
433 CompositeEditCommand::trace(visitor); 433 CompositeEditCommand::trace(visitor);
434 } 434 }
435 435
436 } 436 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698