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

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

Issue 424493003: Use tighter typing in editing: CompositeEditCommand (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 4 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 | Annotate | Revision Log
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 16 matching lines...) Expand all
27 #include "core/editing/InsertListCommand.h" 27 #include "core/editing/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/TextIterator.h" 34 #include "core/editing/TextIterator.h"
35 #include "core/editing/VisibleUnits.h" 35 #include "core/editing/VisibleUnits.h"
36 #include "core/editing/htmlediting.h" 36 #include "core/editing/htmlediting.h"
37 #include "core/html/HTMLBRElement.h"
37 #include "core/html/HTMLElement.h" 38 #include "core/html/HTMLElement.h"
38 39
39 namespace blink { 40 namespace blink {
40 41
41 using namespace HTMLNames; 42 using namespace HTMLNames;
42 43
43 static Node* enclosingListChild(Node* node, Node* listNode) 44 static Node* enclosingListChild(Node* node, Node* listNode)
44 { 45 {
45 Node* listChild = enclosingListChild(node); 46 Node* listChild = enclosingListChild(node);
46 while (listChild && enclosingList(listChild) != listNode) 47 while (listChild && enclosingList(listChild) != listNode)
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 // A paragraph is visually a list item minus a list marker. The paragra ph will be moved. 277 // A paragraph is visually a list item minus a list marker. The paragra ph will be moved.
277 start = startOfParagraph(originalStart, CanSkipOverEditingBoundary); 278 start = startOfParagraph(originalStart, CanSkipOverEditingBoundary);
278 end = endOfParagraph(start, CanSkipOverEditingBoundary); 279 end = endOfParagraph(start, CanSkipOverEditingBoundary);
279 nextListChild = enclosingListChild(end.next().deepEquivalent().deprecate dNode(), listNode); 280 nextListChild = enclosingListChild(end.next().deepEquivalent().deprecate dNode(), listNode);
280 ASSERT(nextListChild != listChildNode); 281 ASSERT(nextListChild != listChildNode);
281 previousListChild = enclosingListChild(start.previous().deepEquivalent() .deprecatedNode(), listNode); 282 previousListChild = enclosingListChild(start.previous().deepEquivalent() .deprecatedNode(), listNode);
282 ASSERT(previousListChild != listChildNode); 283 ASSERT(previousListChild != listChildNode);
283 } 284 }
284 // When removing a list, we must always create a placeholder to act as a poi nt of insertion 285 // When removing a list, we must always create a placeholder to act as a poi nt of insertion
285 // for the list content being removed. 286 // for the list content being removed.
286 RefPtrWillBeRawPtr<Element> placeholder = createBreakElement(document()); 287 RefPtrWillBeRawPtr<HTMLBRElement> placeholder = createBreakElement(document( ));
287 RefPtrWillBeRawPtr<Element> nodeToInsert = placeholder; 288 RefPtrWillBeRawPtr<Element> nodeToInsert = placeholder;
288 // If the content of the list item will be moved into another list, put it i n a list item 289 // If the content of the list item will be moved into another list, put it i n a list item
289 // so that we don't create an orphaned list child. 290 // so that we don't create an orphaned list child.
290 if (enclosingList(listNode)) { 291 if (enclosingList(listNode)) {
291 nodeToInsert = createListItemElement(document()); 292 nodeToInsert = createListItemElement(document());
292 appendNode(placeholder, nodeToInsert); 293 appendNode(placeholder, nodeToInsert);
293 } 294 }
294 295
295 if (nextListChild && previousListChild) { 296 if (nextListChild && previousListChild) {
296 // We want to pull listChildNode out of listNode, and place it before ne xtListChild 297 // We want to pull listChildNode out of listNode, and place it before ne xtListChild
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 PassRefPtrWillBeRawPtr<HTMLElement> InsertListCommand::listifyParagraph(const Vi siblePosition& originalStart, const HTMLQualifiedName& listTag) 340 PassRefPtrWillBeRawPtr<HTMLElement> InsertListCommand::listifyParagraph(const Vi siblePosition& originalStart, const HTMLQualifiedName& listTag)
340 { 341 {
341 VisiblePosition start = startOfParagraph(originalStart, CanSkipOverEditingBo undary); 342 VisiblePosition start = startOfParagraph(originalStart, CanSkipOverEditingBo undary);
342 VisiblePosition end = endOfParagraph(start, CanSkipOverEditingBoundary); 343 VisiblePosition end = endOfParagraph(start, CanSkipOverEditingBoundary);
343 344
344 if (start.isNull() || end.isNull()) 345 if (start.isNull() || end.isNull())
345 return nullptr; 346 return nullptr;
346 347
347 // Check for adjoining lists. 348 // Check for adjoining lists.
348 RefPtrWillBeRawPtr<HTMLElement> listItemElement = createListItemElement(docu ment()); 349 RefPtrWillBeRawPtr<HTMLElement> listItemElement = createListItemElement(docu ment());
349 RefPtrWillBeRawPtr<HTMLElement> placeholder = createBreakElement(document()) ; 350 RefPtrWillBeRawPtr<HTMLBRElement> placeholder = createBreakElement(document( ));
350 appendNode(placeholder, listItemElement); 351 appendNode(placeholder, listItemElement);
351 352
352 // Place list item into adjoining lists. 353 // Place list item into adjoining lists.
353 Element* previousList = adjacentEnclosingList(start, start.previous(CannotCr ossEditingBoundary), listTag); 354 Element* previousList = adjacentEnclosingList(start, start.previous(CannotCr ossEditingBoundary), listTag);
354 Element* nextList = adjacentEnclosingList(start, end.next(CannotCrossEditing Boundary), listTag); 355 Element* nextList = adjacentEnclosingList(start, end.next(CannotCrossEditing Boundary), listTag);
355 RefPtrWillBeRawPtr<HTMLElement> listElement = nullptr; 356 RefPtrWillBeRawPtr<HTMLElement> listElement = nullptr;
356 if (previousList) 357 if (previousList)
357 appendNode(listItemElement, previousList); 358 appendNode(listItemElement, previousList);
358 else if (nextList) 359 else if (nextList)
359 insertNodeAt(listItemElement, positionBeforeNode(nextList)); 360 insertNodeAt(listItemElement, positionBeforeNode(nextList));
360 else { 361 else {
361 // Create the list. 362 // Create the list.
362 listElement = createHTMLElement(document(), listTag); 363 listElement = createHTMLElement(document(), listTag);
363 appendNode(listItemElement, listElement); 364 appendNode(listItemElement, listElement);
364 365
365 if (start == end && isBlock(start.deepEquivalent().deprecatedNode())) { 366 if (start == end && isBlock(start.deepEquivalent().deprecatedNode())) {
366 // Inserting the list into an empty paragraph that isn't held open 367 // Inserting the list into an empty paragraph that isn't held open
367 // by a br or a '\n', will invalidate start and end. Insert 368 // by a br or a '\n', will invalidate start and end. Insert
368 // a placeholder and then recompute start and end. 369 // a placeholder and then recompute start and end.
369 RefPtrWillBeRawPtr<Node> placeholder = insertBlockPlaceholder(start. deepEquivalent()); 370 RefPtrWillBeRawPtr<HTMLBRElement> placeholder = insertBlockPlacehold er(start.deepEquivalent());
370 start = VisiblePosition(positionBeforeNode(placeholder.get())); 371 start = VisiblePosition(positionBeforeNode(placeholder.get()));
371 end = start; 372 end = start;
372 } 373 }
373 374
374 // Insert the list at a position visually equivalent to start of the 375 // Insert the list at a position visually equivalent to start of the
375 // paragraph that is being moved into the list. 376 // paragraph that is being moved into the list.
376 // Try to avoid inserting it somewhere where it will be surrounded by 377 // Try to avoid inserting it somewhere where it will be surrounded by
377 // inline ancestors of start, since it is easier for editing to produce 378 // inline ancestors of start, since it is easier for editing to produce
378 // clean markup when inline elements are pushed down as far as possible. 379 // clean markup when inline elements are pushed down as far as possible.
379 Position insertionPos(start.deepEquivalent().upstream()); 380 Position insertionPos(start.deepEquivalent().upstream());
(...skipping 28 matching lines...) Expand all
408 return listElement; 409 return listElement;
409 } 410 }
410 411
411 void InsertListCommand::trace(Visitor* visitor) 412 void InsertListCommand::trace(Visitor* visitor)
412 { 413 {
413 visitor->trace(m_listElement); 414 visitor->trace(m_listElement);
414 CompositeEditCommand::trace(visitor); 415 CompositeEditCommand::trace(visitor);
415 } 416 }
416 417
417 } 418 }
OLDNEW
« no previous file with comments | « Source/core/editing/InsertLineBreakCommand.cpp ('k') | Source/core/editing/InsertParagraphSeparatorCommand.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698