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

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

Issue 422693002: Use tighter typing in editing: htmlediting create methods (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase 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 18 matching lines...) Expand all
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/HTMLBRElement.h"
38 #include "core/html/HTMLElement.h" 38 #include "core/html/HTMLElement.h"
39 #include "core/html/HTMLLIElement.h"
40 #include "core/html/HTMLUListElement.h"
39 41
40 namespace blink { 42 namespace blink {
41 43
42 using namespace HTMLNames; 44 using namespace HTMLNames;
43 45
44 static Node* enclosingListChild(Node* node, Node* listNode) 46 static Node* enclosingListChild(Node* node, Node* listNode)
45 { 47 {
46 Node* listChild = enclosingListChild(node); 48 Node* listChild = enclosingListChild(node);
47 while (listChild && enclosingList(listChild) != listNode) 49 while (listChild && enclosingList(listChild) != listNode)
48 listChild = enclosingListChild(listChild->parentNode()); 50 listChild = enclosingListChild(listChild->parentNode());
49 return listChild; 51 return listChild;
50 } 52 }
51 53
52 HTMLElement* InsertListCommand::fixOrphanedListChild(Node* node) 54 HTMLElement* InsertListCommand::fixOrphanedListChild(Node* node)
53 { 55 {
54 RefPtrWillBeRawPtr<HTMLElement> listElement = createUnorderedListElement(doc ument()); 56 RefPtrWillBeRawPtr<HTMLUListElement> listElement = createUnorderedListElemen t(document());
55 insertNodeBefore(listElement, node); 57 insertNodeBefore(listElement, node);
56 removeNode(node); 58 removeNode(node);
57 appendNode(node, listElement); 59 appendNode(node, listElement);
58 m_listElement = listElement; 60 m_listElement = listElement;
59 return listElement.get(); 61 return listElement.get();
60 } 62 }
61 63
62 PassRefPtrWillBeRawPtr<HTMLElement> InsertListCommand::mergeWithNeighboringLists (PassRefPtrWillBeRawPtr<HTMLElement> passedList) 64 PassRefPtrWillBeRawPtr<HTMLElement> InsertListCommand::mergeWithNeighboringLists (PassRefPtrWillBeRawPtr<HTMLElement> passedList)
63 { 65 {
64 RefPtrWillBeRawPtr<HTMLElement> list = passedList; 66 RefPtrWillBeRawPtr<HTMLElement> list = passedList;
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 start = startOfParagraph(originalStart, CanSkipOverEditingBoundary); 280 start = startOfParagraph(originalStart, CanSkipOverEditingBoundary);
279 end = endOfParagraph(start, CanSkipOverEditingBoundary); 281 end = endOfParagraph(start, CanSkipOverEditingBoundary);
280 nextListChild = enclosingListChild(end.next().deepEquivalent().deprecate dNode(), listNode); 282 nextListChild = enclosingListChild(end.next().deepEquivalent().deprecate dNode(), listNode);
281 ASSERT(nextListChild != listChildNode); 283 ASSERT(nextListChild != listChildNode);
282 previousListChild = enclosingListChild(start.previous().deepEquivalent() .deprecatedNode(), listNode); 284 previousListChild = enclosingListChild(start.previous().deepEquivalent() .deprecatedNode(), listNode);
283 ASSERT(previousListChild != listChildNode); 285 ASSERT(previousListChild != listChildNode);
284 } 286 }
285 // When removing a list, we must always create a placeholder to act as a poi nt of insertion 287 // When removing a list, we must always create a placeholder to act as a poi nt of insertion
286 // for the list content being removed. 288 // for the list content being removed.
287 RefPtrWillBeRawPtr<HTMLBRElement> placeholder = createBreakElement(document( )); 289 RefPtrWillBeRawPtr<HTMLBRElement> placeholder = createBreakElement(document( ));
288 RefPtrWillBeRawPtr<Element> nodeToInsert = placeholder; 290 RefPtrWillBeRawPtr<HTMLElement> elementToInsert = placeholder;
289 // If the content of the list item will be moved into another list, put it i n a list item 291 // If the content of the list item will be moved into another list, put it i n a list item
290 // so that we don't create an orphaned list child. 292 // so that we don't create an orphaned list child.
291 if (enclosingList(listNode)) { 293 if (enclosingList(listNode)) {
292 nodeToInsert = createListItemElement(document()); 294 elementToInsert = createListItemElement(document());
293 appendNode(placeholder, nodeToInsert); 295 appendNode(placeholder, elementToInsert);
294 } 296 }
295 297
296 if (nextListChild && previousListChild) { 298 if (nextListChild && previousListChild) {
297 // We want to pull listChildNode out of listNode, and place it before ne xtListChild 299 // We want to pull listChildNode out of listNode, and place it before ne xtListChild
298 // and after previousListChild, so we split listNode and insert it betwe en the two lists. 300 // and after previousListChild, so we split listNode and insert it betwe en the two lists.
299 // But to split listNode, we must first split ancestors of listChildNode between it and listNode, 301 // But to split listNode, we must first split ancestors of listChildNode between it and listNode,
300 // if any exist. 302 // if any exist.
301 // FIXME: We appear to split at nextListChild as opposed to listChildNod e so that when we remove 303 // FIXME: We appear to split at nextListChild as opposed to listChildNod e so that when we remove
302 // listChildNode below in moveParagraphs, previousListChild will be remo ved along with it if it is 304 // listChildNode below in moveParagraphs, previousListChild will be remo ved along with it if it is
303 // unrendered. But we ought to remove nextListChild too, if it is unrend ered. 305 // unrendered. But we ought to remove nextListChild too, if it is unrend ered.
304 splitElement(listNode, splitTreeToNode(nextListChild, listNode)); 306 splitElement(listNode, splitTreeToNode(nextListChild, listNode));
305 insertNodeBefore(nodeToInsert, listNode); 307 insertNodeBefore(elementToInsert, listNode);
306 } else if (nextListChild || listChildNode->parentNode() != listNode) { 308 } else if (nextListChild || listChildNode->parentNode() != listNode) {
307 // Just because listChildNode has no previousListChild doesn't mean ther e isn't any content 309 // Just because listChildNode has no previousListChild doesn't mean ther e isn't any content
308 // in listNode that comes before listChildNode, as listChildNode could h ave ancestors 310 // in listNode that comes before listChildNode, as listChildNode could h ave ancestors
309 // between it and listNode. So, we split up to listNode before inserting the placeholder 311 // between it and listNode. So, we split up to listNode before inserting the placeholder
310 // where we're about to move listChildNode to. 312 // where we're about to move listChildNode to.
311 if (listChildNode->parentNode() != listNode) 313 if (listChildNode->parentNode() != listNode)
312 splitElement(listNode, splitTreeToNode(listChildNode, listNode).get( )); 314 splitElement(listNode, splitTreeToNode(listChildNode, listNode).get( ));
313 insertNodeBefore(nodeToInsert, listNode); 315 insertNodeBefore(elementToInsert, listNode);
314 } else 316 } else {
315 insertNodeAfter(nodeToInsert, listNode); 317 insertNodeAfter(elementToInsert, listNode);
318 }
316 319
317 VisiblePosition insertionPoint = VisiblePosition(positionBeforeNode(placehol der.get())); 320 VisiblePosition insertionPoint = VisiblePosition(positionBeforeNode(placehol der.get()));
318 moveParagraphs(start, end, insertionPoint, /* preserveSelection */ true, /* preserveStyle */ true, listChildNode); 321 moveParagraphs(start, end, insertionPoint, /* preserveSelection */ true, /* preserveStyle */ true, listChildNode);
319 } 322 }
320 323
321 static Element* adjacentEnclosingList(const VisiblePosition& pos, const VisibleP osition& adjacentPos, const HTMLQualifiedName& listTag) 324 static Element* adjacentEnclosingList(const VisiblePosition& pos, const VisibleP osition& adjacentPos, const HTMLQualifiedName& listTag)
322 { 325 {
323 Element* listNode = outermostEnclosingList(adjacentPos.deepEquivalent().depr ecatedNode()); 326 Element* listNode = outermostEnclosingList(adjacentPos.deepEquivalent().depr ecatedNode());
324 327
325 if (!listNode) 328 if (!listNode)
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 return listElement; 412 return listElement;
410 } 413 }
411 414
412 void InsertListCommand::trace(Visitor* visitor) 415 void InsertListCommand::trace(Visitor* visitor)
413 { 416 {
414 visitor->trace(m_listElement); 417 visitor->trace(m_listElement);
415 CompositeEditCommand::trace(visitor); 418 CompositeEditCommand::trace(visitor);
416 } 419 }
417 420
418 } 421 }
OLDNEW
« no previous file with comments | « Source/core/editing/CompositeEditCommand.cpp ('k') | Source/core/editing/ReplaceSelectionCommand.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698