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

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

Issue 26203002: Merge 158727 "Protect DOM nodes in IndentOutdentCommand::tryInde..." (Closed) Base URL: svn://svn.chromium.org/blink/branches/chromium/1599/
Patch Set: Created 7 years, 2 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
« 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) 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 IndentOutdentCommand::IndentOutdentCommand(Document* document, EIndentType typeO fAction, int marginInPixels) 46 IndentOutdentCommand::IndentOutdentCommand(Document* document, EIndentType typeO fAction, int marginInPixels)
47 : ApplyBlockElementCommand(document, blockquoteTag, "margin: 0 0 0 40px; bor der: none; padding: 0px;") 47 : ApplyBlockElementCommand(document, blockquoteTag, "margin: 0 0 0 40px; bor der: none; padding: 0px;")
48 , m_typeOfAction(typeOfAction) 48 , m_typeOfAction(typeOfAction)
49 , m_marginInPixels(marginInPixels) 49 , m_marginInPixels(marginInPixels)
50 { 50 {
51 } 51 }
52 52
53 bool IndentOutdentCommand::tryIndentingAsListItem(const Position& start, const P osition& end) 53 bool IndentOutdentCommand::tryIndentingAsListItem(const Position& start, const P osition& end)
54 { 54 {
55 // If our selection is not inside a list, bail out. 55 // If our selection is not inside a list, bail out.
56 Node* lastNodeInSelectedParagraph = start.deprecatedNode(); 56 RefPtr<Node> lastNodeInSelectedParagraph = start.deprecatedNode();
57 RefPtr<Element> listNode = enclosingList(lastNodeInSelectedParagraph); 57 RefPtr<Element> listNode = enclosingList(lastNodeInSelectedParagraph.get());
58 if (!listNode) 58 if (!listNode)
59 return false; 59 return false;
60 60
61 // Find the block that we want to indent. If it's not a list item (e.g., a div inside a list item), we bail out. 61 // Find the block that we want to indent. If it's not a list item (e.g., a div inside a list item), we bail out.
62 Element* selectedListItem = enclosingBlock(lastNodeInSelectedParagraph); 62 RefPtr<Element> selectedListItem = enclosingBlock(lastNodeInSelectedParagrap h.get());
63 63
64 // FIXME: we need to deal with the case where there is no li (malformed HTML ) 64 // FIXME: we need to deal with the case where there is no li (malformed HTML )
65 if (!selectedListItem->hasTagName(liTag)) 65 if (!selectedListItem->hasTagName(liTag))
66 return false; 66 return false;
67 67
68 // FIXME: previousElementSibling does not ignore non-rendered content like < span></span>. Should we? 68 // FIXME: previousElementSibling does not ignore non-rendered content like < span></span>. Should we?
69 Element* previousList = selectedListItem->previousElementSibling(); 69 RefPtr<Element> previousList = selectedListItem->previousElementSibling();
70 Element* nextList = selectedListItem->nextElementSibling(); 70 RefPtr<Element> nextList = selectedListItem->nextElementSibling();
71 71
72 RefPtr<Element> newList = document()->createElement(listNode->tagQName(), fa lse); 72 RefPtr<Element> newList = document()->createElement(listNode->tagQName(), fa lse);
73 insertNodeBefore(newList, selectedListItem); 73 insertNodeBefore(newList, selectedListItem.get());
74 74
75 moveParagraphWithClones(start, end, newList.get(), selectedListItem); 75 moveParagraphWithClones(start, end, newList.get(), selectedListItem.get());
76 76
77 if (canMergeLists(previousList, newList.get())) 77 if (canMergeLists(previousList.get(), newList.get()))
78 mergeIdenticalElements(previousList, newList); 78 mergeIdenticalElements(previousList.get(), newList.get());
79 if (canMergeLists(newList.get(), nextList)) 79 if (canMergeLists(newList.get(), nextList.get()))
80 mergeIdenticalElements(newList, nextList); 80 mergeIdenticalElements(newList.get(), nextList.get());
81 81
82 return true; 82 return true;
83 } 83 }
84 84
85 void IndentOutdentCommand::indentIntoBlockquote(const Position& start, const Pos ition& end, RefPtr<Element>& targetBlockquote) 85 void IndentOutdentCommand::indentIntoBlockquote(const Position& start, const Pos ition& end, RefPtr<Element>& targetBlockquote)
86 { 86 {
87 Node* enclosingCell = enclosingNodeOfType(start, &isTableCell); 87 Node* enclosingCell = enclosingNodeOfType(start, &isTableCell);
88 Node* nodeToSplitTo; 88 Node* nodeToSplitTo;
89 if (enclosingCell) 89 if (enclosingCell)
90 nodeToSplitTo = enclosingCell; 90 nodeToSplitTo = enclosingCell;
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 227
228 void IndentOutdentCommand::formatRange(const Position& start, const Position& en d, const Position&, RefPtr<Element>& blockquoteForNextIndent) 228 void IndentOutdentCommand::formatRange(const Position& start, const Position& en d, const Position&, RefPtr<Element>& blockquoteForNextIndent)
229 { 229 {
230 if (tryIndentingAsListItem(start, end)) 230 if (tryIndentingAsListItem(start, end))
231 blockquoteForNextIndent = 0; 231 blockquoteForNextIndent = 0;
232 else 232 else
233 indentIntoBlockquote(start, end, blockquoteForNextIndent); 233 indentIntoBlockquote(start, end, blockquoteForNextIndent);
234 } 234 }
235 235
236 } 236 }
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