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

Side by Side Diff: Source/WebCore/editing/CompositeEditCommand.cpp

Issue 10544115: Merge 119872 (Closed) Base URL: http://svn.webkit.org/repository/webkit/branches/chromium/1132/
Patch Set: Created 8 years, 6 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2005, 2006, 2007, 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 1229 matching lines...) Expand 10 before | Expand all | Expand 10 after
1240 RefPtr<Range> start = TextIterator::rangeFromLocationAndLength(document( )->documentElement(), destinationIndex + startIndex, 0, true); 1240 RefPtr<Range> start = TextIterator::rangeFromLocationAndLength(document( )->documentElement(), destinationIndex + startIndex, 0, true);
1241 RefPtr<Range> end = TextIterator::rangeFromLocationAndLength(document()- >documentElement(), destinationIndex + endIndex, 0, true); 1241 RefPtr<Range> end = TextIterator::rangeFromLocationAndLength(document()- >documentElement(), destinationIndex + endIndex, 0, true);
1242 if (start && end) 1242 if (start && end)
1243 setEndingSelection(VisibleSelection(start->startPosition(), end->sta rtPosition(), DOWNSTREAM, originalIsDirectional)); 1243 setEndingSelection(VisibleSelection(start->startPosition(), end->sta rtPosition(), DOWNSTREAM, originalIsDirectional));
1244 } 1244 }
1245 } 1245 }
1246 1246
1247 // FIXME: Send an appropriate shouldDeleteRange call. 1247 // FIXME: Send an appropriate shouldDeleteRange call.
1248 bool CompositeEditCommand::breakOutOfEmptyListItem() 1248 bool CompositeEditCommand::breakOutOfEmptyListItem()
1249 { 1249 {
1250 Node* emptyListItem = enclosingEmptyListItem(endingSelection().visibleStart( )); 1250 RefPtr<Node> emptyListItem = enclosingEmptyListItem(endingSelection().visibl eStart());
1251 if (!emptyListItem) 1251 if (!emptyListItem)
1252 return false; 1252 return false;
1253 1253
1254 RefPtr<EditingStyle> style = EditingStyle::create(endingSelection().start()) ; 1254 RefPtr<EditingStyle> style = EditingStyle::create(endingSelection().start()) ;
1255 style->mergeTypingStyle(document()); 1255 style->mergeTypingStyle(document());
1256 1256
1257 ContainerNode* listNode = emptyListItem->parentNode(); 1257 RefPtr<ContainerNode> listNode = emptyListItem->parentNode();
1258 // FIXME: Can't we do something better when the immediate parent wasn't a li st node? 1258 // FIXME: Can't we do something better when the immediate parent wasn't a li st node?
1259 if (!listNode 1259 if (!listNode
1260 || (!listNode->hasTagName(ulTag) && !listNode->hasTagName(olTag)) 1260 || (!listNode->hasTagName(ulTag) && !listNode->hasTagName(olTag))
1261 || !listNode->rendererIsEditable() 1261 || !listNode->rendererIsEditable()
1262 || listNode == emptyListItem->rootEditableElement()) 1262 || listNode == emptyListItem->rootEditableElement())
1263 return false; 1263 return false;
1264 1264
1265 RefPtr<Element> newBlock = 0; 1265 RefPtr<Element> newBlock = 0;
1266 if (ContainerNode* blockEnclosingList = listNode->parentNode()) { 1266 if (ContainerNode* blockEnclosingList = listNode->parentNode()) {
1267 if (blockEnclosingList->hasTagName(liTag)) { // listNode is inside anoth er list item 1267 if (blockEnclosingList->hasTagName(liTag)) { // listNode is inside anoth er list item
1268 if (visiblePositionAfterNode(blockEnclosingList) == visiblePositionA fterNode(listNode)) { 1268 if (visiblePositionAfterNode(blockEnclosingList) == visiblePositionA fterNode(listNode.get())) {
1269 // If listNode appears at the end of the outer list item, then m ove listNode outside of this list item 1269 // If listNode appears at the end of the outer list item, then m ove listNode outside of this list item
1270 // e.g. <ul><li>hello <ul><li><br></li></ul> </li></ul> should b ecome <ul><li>hello</li> <ul><li><br></li></ul> </ul> after this section 1270 // e.g. <ul><li>hello <ul><li><br></li></ul> </li></ul> should b ecome <ul><li>hello</li> <ul><li><br></li></ul> </ul> after this section
1271 // If listNode does NOT appear at the end, then we should consid er it as a regular paragraph. 1271 // If listNode does NOT appear at the end, then we should consid er it as a regular paragraph.
1272 // e.g. <ul><li> <ul><li><br></li></ul> hello</li></ul> should b ecome <ul><li> <div><br></div> hello</li></ul> at the end 1272 // e.g. <ul><li> <ul><li><br></li></ul> hello</li></ul> should b ecome <ul><li> <div><br></div> hello</li></ul> at the end
1273 splitElement(static_cast<Element*>(blockEnclosingList), listNode ); 1273 splitElement(static_cast<Element*>(blockEnclosingList), listNode );
1274 removeNodePreservingChildren(listNode->parentNode()); 1274 removeNodePreservingChildren(listNode->parentNode());
1275 newBlock = createListItemElement(document()); 1275 newBlock = createListItemElement(document());
1276 } 1276 }
1277 // If listNode does NOT appear at the end of the outer list item, th en behave as if in a regular paragraph. 1277 // If listNode does NOT appear at the end of the outer list item, th en behave as if in a regular paragraph.
1278 } else if (blockEnclosingList->hasTagName(olTag) || blockEnclosingList-> hasTagName(ulTag)) 1278 } else if (blockEnclosingList->hasTagName(olTag) || blockEnclosingList-> hasTagName(ulTag))
1279 newBlock = createListItemElement(document()); 1279 newBlock = createListItemElement(document());
1280 } 1280 }
1281 if (!newBlock) 1281 if (!newBlock)
1282 newBlock = createDefaultParagraphElement(document()); 1282 newBlock = createDefaultParagraphElement(document());
1283 1283
1284 Node* previousListNode = emptyListItem->isElementNode() ? toElement(emptyLis tItem)->previousElementSibling(): emptyListItem->previousSibling(); 1284 RefPtr<Node> previousListNode = emptyListItem->isElementNode() ? toElement(e mptyListItem.get())->previousElementSibling(): emptyListItem->previousSibling();
1285 Node* nextListNode = emptyListItem->isElementNode() ? toElement(emptyListIte m)->nextElementSibling(): emptyListItem->nextSibling(); 1285 RefPtr<Node> nextListNode = emptyListItem->isElementNode() ? toElement(empty ListItem.get())->nextElementSibling(): emptyListItem->nextSibling();
1286 if (isListItem(nextListNode) || isListElement(nextListNode)) { 1286 if (isListItem(nextListNode.get()) || isListElement(nextListNode.get())) {
1287 // If emptyListItem follows another list item or nested list, split the list node. 1287 // If emptyListItem follows another list item or nested list, split the list node.
1288 if (isListItem(previousListNode) || isListElement(previousListNode)) 1288 if (isListItem(previousListNode.get()) || isListElement(previousListNode .get()))
1289 splitElement(static_cast<Element*>(listNode), emptyListItem); 1289 splitElement(static_cast<Element*>(listNode.get()), emptyListItem);
1290 1290
1291 // If emptyListItem is followed by other list item or nested list, then insert newBlock before the list node. 1291 // If emptyListItem is followed by other list item or nested list, then insert newBlock before the list node.
1292 // Because we have splitted the element, emptyListItem is the first elem ent in the list node. 1292 // Because we have splitted the element, emptyListItem is the first elem ent in the list node.
1293 // i.e. insert newBlock before ul or ol whose first element is emptyList Item 1293 // i.e. insert newBlock before ul or ol whose first element is emptyList Item
1294 insertNodeBefore(newBlock, listNode); 1294 insertNodeBefore(newBlock, listNode);
1295 removeNode(emptyListItem); 1295 removeNode(emptyListItem);
1296 } else { 1296 } else {
1297 // When emptyListItem does not follow any list item or nested list, inse rt newBlock after the enclosing list node. 1297 // When emptyListItem does not follow any list item or nested list, inse rt newBlock after the enclosing list node.
1298 // Remove the enclosing node if emptyListItem is the only child; otherwi se just remove emptyListItem. 1298 // Remove the enclosing node if emptyListItem is the only child; otherwi se just remove emptyListItem.
1299 insertNodeAfter(newBlock, listNode); 1299 insertNodeAfter(newBlock, listNode);
1300 removeNode(isListItem(previousListNode) || isListElement(previousListNod e) ? emptyListItem : listNode); 1300 removeNode(isListItem(previousListNode.get()) || isListElement(previousL istNode.get()) ? emptyListItem.get() : listNode.get());
1301 } 1301 }
1302 1302
1303 appendBlockPlaceholder(newBlock); 1303 appendBlockPlaceholder(newBlock);
1304 setEndingSelection(VisibleSelection(firstPositionInNode(newBlock.get()), DOW NSTREAM, endingSelection().isDirectional())); 1304 setEndingSelection(VisibleSelection(firstPositionInNode(newBlock.get()), DOW NSTREAM, endingSelection().isDirectional()));
1305 1305
1306 style->prepareToApplyAt(endingSelection().start()); 1306 style->prepareToApplyAt(endingSelection().start());
1307 if (!style->isEmpty()) 1307 if (!style->isEmpty())
1308 applyStyle(style.get()); 1308 applyStyle(style.get());
1309 1309
1310 return true; 1310 return true;
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
1451 return node.release(); 1451 return node.release();
1452 } 1452 }
1453 1453
1454 PassRefPtr<Element> createBlockPlaceholderElement(Document* document) 1454 PassRefPtr<Element> createBlockPlaceholderElement(Document* document)
1455 { 1455 {
1456 RefPtr<Element> breakNode = document->createElement(brTag, false); 1456 RefPtr<Element> breakNode = document->createElement(brTag, false);
1457 return breakNode.release(); 1457 return breakNode.release();
1458 } 1458 }
1459 1459
1460 } // namespace WebCore 1460 } // namespace WebCore
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698