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

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

Issue 23822003: Have EditCommand classes deal with Document references, not pointers (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 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 | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2006, 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2008 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 17 matching lines...) Expand all
28 28
29 #include "core/dom/Document.h" 29 #include "core/dom/Document.h"
30 #include "core/editing/FrameSelection.h" 30 #include "core/editing/FrameSelection.h"
31 #include "core/editing/htmlediting.h" 31 #include "core/editing/htmlediting.h"
32 #include "core/html/HTMLElement.h" 32 #include "core/html/HTMLElement.h"
33 #include "core/page/Frame.h" 33 #include "core/page/Frame.h"
34 #include "core/rendering/RenderObject.h" 34 #include "core/rendering/RenderObject.h"
35 35
36 namespace WebCore { 36 namespace WebCore {
37 37
38 ModifySelectionListLevelCommand::ModifySelectionListLevelCommand(Document* docum ent) 38 ModifySelectionListLevelCommand::ModifySelectionListLevelCommand(Document& docum ent)
39 : CompositeEditCommand(document) 39 : CompositeEditCommand(document)
40 { 40 {
41 } 41 }
42 42
43 bool ModifySelectionListLevelCommand::preservesTypingStyle() const 43 bool ModifySelectionListLevelCommand::preservesTypingStyle() const
44 { 44 {
45 return true; 45 return true;
46 } 46 }
47 47
48 // This needs to be static so it can be called by canIncreaseSelectionListLevel and canDecreaseSelectionListLevel 48 // This needs to be static so it can be called by canIncreaseSelectionListLevel and canDecreaseSelectionListLevel
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 removeNode(node); 127 removeNode(node);
128 appendNode(node, newParent); 128 appendNode(node, newParent);
129 129
130 if (node == endNode) 130 if (node == endNode)
131 break; 131 break;
132 132
133 node = next; 133 node = next;
134 } 134 }
135 } 135 }
136 136
137 IncreaseSelectionListLevelCommand::IncreaseSelectionListLevelCommand(Document* d ocument, Type listType) 137 IncreaseSelectionListLevelCommand::IncreaseSelectionListLevelCommand(Document& d ocument, Type listType)
138 : ModifySelectionListLevelCommand(document) 138 : ModifySelectionListLevelCommand(document)
139 , m_listType(listType) 139 , m_listType(listType)
140 { 140 {
141 } 141 }
142 142
143 // This needs to be static so it can be called by canIncreaseSelectionListLevel 143 // This needs to be static so it can be called by canIncreaseSelectionListLevel
144 static bool canIncreaseListLevel(const VisibleSelection& selection, Node*& start , Node*& end) 144 static bool canIncreaseListLevel(const VisibleSelection& selection, Node*& start , Node*& end)
145 { 145 {
146 if (!getStartEndListChildren(selection, start, end)) 146 if (!getStartEndListChildren(selection, start, end))
147 return false; 147 return false;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 } else { 183 } else {
184 // create a sublist for the preceding element and move nodes there 184 // create a sublist for the preceding element and move nodes there
185 RefPtr<Element> newParent; 185 RefPtr<Element> newParent;
186 switch (m_listType) { 186 switch (m_listType) {
187 case InheritedListType: 187 case InheritedListType:
188 newParent = startListChild->parentElement(); 188 newParent = startListChild->parentElement();
189 if (newParent) 189 if (newParent)
190 newParent = newParent->cloneElementWithoutChildren(); 190 newParent = newParent->cloneElementWithoutChildren();
191 break; 191 break;
192 case OrderedList: 192 case OrderedList:
193 newParent = createOrderedListElement(document()); 193 newParent = createOrderedListElement(&document());
194 break; 194 break;
195 case UnorderedList: 195 case UnorderedList:
196 newParent = createUnorderedListElement(document()); 196 newParent = createUnorderedListElement(&document());
197 break; 197 break;
198 } 198 }
199 insertNodeBefore(newParent, startListChild); 199 insertNodeBefore(newParent, startListChild);
200 appendSiblingNodeRange(startListChild, endListChild, newParent.get()); 200 appendSiblingNodeRange(startListChild, endListChild, newParent.get());
201 m_listElement = newParent.release(); 201 m_listElement = newParent.release();
202 } 202 }
203 } 203 }
204 204
205 bool IncreaseSelectionListLevelCommand::canIncreaseSelectionListLevel(Document* document) 205 bool IncreaseSelectionListLevelCommand::canIncreaseSelectionListLevel(Document& document)
206 { 206 {
207 Node* startListChild; 207 Node* startListChild;
208 Node* endListChild; 208 Node* endListChild;
209 return canIncreaseListLevel(document->frame()->selection()->selection(), sta rtListChild, endListChild); 209 return canIncreaseListLevel(document.frame()->selection()->selection(), star tListChild, endListChild);
210 } 210 }
211 211
212 PassRefPtr<Node> IncreaseSelectionListLevelCommand::increaseSelectionListLevel(D ocument* document, Type type) 212 PassRefPtr<Node> IncreaseSelectionListLevelCommand::increaseSelectionListLevel(D ocument& document, Type type)
213 { 213 {
214 ASSERT(document); 214 ASSERT(document.frame());
215 ASSERT(document->frame());
216 RefPtr<IncreaseSelectionListLevelCommand> command = create(document, type); 215 RefPtr<IncreaseSelectionListLevelCommand> command = create(document, type);
217 command->apply(); 216 command->apply();
218 return command->m_listElement.release(); 217 return command->m_listElement.release();
219 } 218 }
220 219
221 PassRefPtr<Node> IncreaseSelectionListLevelCommand::increaseSelectionListLevel(D ocument* document) 220 PassRefPtr<Node> IncreaseSelectionListLevelCommand::increaseSelectionListLevel(D ocument& document)
222 { 221 {
223 return increaseSelectionListLevel(document, InheritedListType); 222 return increaseSelectionListLevel(document, InheritedListType);
224 } 223 }
225 224
226 PassRefPtr<Node> IncreaseSelectionListLevelCommand::increaseSelectionListLevelOr dered(Document* document) 225 PassRefPtr<Node> IncreaseSelectionListLevelCommand::increaseSelectionListLevelOr dered(Document& document)
227 { 226 {
228 return increaseSelectionListLevel(document, OrderedList); 227 return increaseSelectionListLevel(document, OrderedList);
229 } 228 }
230 229
231 PassRefPtr<Node> IncreaseSelectionListLevelCommand::increaseSelectionListLevelUn ordered(Document* document) 230 PassRefPtr<Node> IncreaseSelectionListLevelCommand::increaseSelectionListLevelUn ordered(Document& document)
232 { 231 {
233 return increaseSelectionListLevel(document, UnorderedList); 232 return increaseSelectionListLevel(document, UnorderedList);
234 } 233 }
235 234
236 DecreaseSelectionListLevelCommand::DecreaseSelectionListLevelCommand(Document* d ocument) 235 DecreaseSelectionListLevelCommand::DecreaseSelectionListLevelCommand(Document& d ocument)
237 : ModifySelectionListLevelCommand(document) 236 : ModifySelectionListLevelCommand(document)
238 { 237 {
239 } 238 }
240 239
241 // This needs to be static so it can be called by canDecreaseSelectionListLevel 240 // This needs to be static so it can be called by canDecreaseSelectionListLevel
242 static bool canDecreaseListLevel(const VisibleSelection& selection, Node*& start , Node*& end) 241 static bool canDecreaseListLevel(const VisibleSelection& selection, Node*& start , Node*& end)
243 { 242 {
244 if (!getStartEndListChildren(selection, start, end)) 243 if (!getStartEndListChildren(selection, start, end))
245 return false; 244 return false;
246 245
(...skipping 24 matching lines...) Expand all
271 } else if (!nextItem) { 270 } else if (!nextItem) {
272 // at end of list, move the child(ren) to after the sublist 271 // at end of list, move the child(ren) to after the sublist
273 insertSiblingNodeRangeAfter(startListChild, endListChild, listNode); 272 insertSiblingNodeRangeAfter(startListChild, endListChild, listNode);
274 } else if (listNode) { 273 } else if (listNode) {
275 // in the middle of list, split the list and move the children to the di vide 274 // in the middle of list, split the list and move the children to the di vide
276 splitElement(listNode, startListChild); 275 splitElement(listNode, startListChild);
277 insertSiblingNodeRangeBefore(startListChild, endListChild, listNode); 276 insertSiblingNodeRangeBefore(startListChild, endListChild, listNode);
278 } 277 }
279 } 278 }
280 279
281 bool DecreaseSelectionListLevelCommand::canDecreaseSelectionListLevel(Document* document) 280 bool DecreaseSelectionListLevelCommand::canDecreaseSelectionListLevel(Document& document)
282 { 281 {
283 Node* startListChild; 282 Node* startListChild;
284 Node* endListChild; 283 Node* endListChild;
285 return canDecreaseListLevel(document->frame()->selection()->selection(), sta rtListChild, endListChild); 284 return canDecreaseListLevel(document.frame()->selection()->selection(), star tListChild, endListChild);
286 } 285 }
287 286
288 void DecreaseSelectionListLevelCommand::decreaseSelectionListLevel(Document* doc ument) 287 void DecreaseSelectionListLevelCommand::decreaseSelectionListLevel(Document& doc ument)
289 { 288 {
290 ASSERT(document); 289 ASSERT(document.frame());
291 ASSERT(document->frame());
292 applyCommand(create(document)); 290 applyCommand(create(document));
293 } 291 }
294 292
295 } 293 }
OLDNEW
« no previous file with comments | « Source/core/editing/ModifySelectionListLevel.h ('k') | Source/core/editing/MoveSelectionCommand.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698