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

Side by Side Diff: third_party/WebKit/Source/core/editing/commands/IndentOutdentCommand.cpp

Issue 1686483002: Oilpan: Remove most WillBe types from the code base (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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
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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 62
63 IndentOutdentCommand::IndentOutdentCommand(Document& document, EIndentType typeO fAction) 63 IndentOutdentCommand::IndentOutdentCommand(Document& document, EIndentType typeO fAction)
64 : ApplyBlockElementCommand(document, blockquoteTag, "margin: 0 0 0 40px; bor der: none; padding: 0px;") 64 : ApplyBlockElementCommand(document, blockquoteTag, "margin: 0 0 0 40px; bor der: none; padding: 0px;")
65 , m_typeOfAction(typeOfAction) 65 , m_typeOfAction(typeOfAction)
66 { 66 {
67 } 67 }
68 68
69 bool IndentOutdentCommand::tryIndentingAsListItem(const Position& start, const P osition& end) 69 bool IndentOutdentCommand::tryIndentingAsListItem(const Position& start, const P osition& end)
70 { 70 {
71 // If our selection is not inside a list, bail out. 71 // If our selection is not inside a list, bail out.
72 RefPtrWillBeRawPtr<Node> lastNodeInSelectedParagraph = start.anchorNode(); 72 RawPtr<Node> lastNodeInSelectedParagraph = start.anchorNode();
73 RefPtrWillBeRawPtr<HTMLElement> listElement = enclosingList(lastNodeInSelect edParagraph.get()); 73 RawPtr<HTMLElement> listElement = enclosingList(lastNodeInSelectedParagraph. get());
74 if (!listElement) 74 if (!listElement)
75 return false; 75 return false;
76 76
77 // 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. 77 // 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.
78 RefPtrWillBeRawPtr<Element> selectedListItem = enclosingBlock(lastNodeInSele ctedParagraph.get()); 78 RawPtr<Element> selectedListItem = enclosingBlock(lastNodeInSelectedParagrap h.get());
79 79
80 // FIXME: we need to deal with the case where there is no li (malformed HTML ) 80 // FIXME: we need to deal with the case where there is no li (malformed HTML )
81 if (!isHTMLLIElement(selectedListItem)) 81 if (!isHTMLLIElement(selectedListItem))
82 return false; 82 return false;
83 83
84 // FIXME: previousElementSibling does not ignore non-rendered content like < span></span>. Should we? 84 // FIXME: previousElementSibling does not ignore non-rendered content like < span></span>. Should we?
85 RefPtrWillBeRawPtr<Element> previousList = ElementTraversal::previousSibling (*selectedListItem); 85 RawPtr<Element> previousList = ElementTraversal::previousSibling(*selectedLi stItem);
86 RefPtrWillBeRawPtr<Element> nextList = ElementTraversal::nextSibling(*select edListItem); 86 RawPtr<Element> nextList = ElementTraversal::nextSibling(*selectedListItem);
87 87
88 // We should calculate visible range in list item because inserting new 88 // We should calculate visible range in list item because inserting new
89 // list element will change visibility of list item, e.g. :first-child 89 // list element will change visibility of list item, e.g. :first-child
90 // CSS selector. 90 // CSS selector.
91 RefPtrWillBeRawPtr<HTMLElement> newList = toHTMLElement(document().createEle ment(listElement->tagQName(), false).get()); 91 RawPtr<HTMLElement> newList = toHTMLElement(document().createElement(listEle ment->tagQName(), false).get());
92 insertNodeBefore(newList, selectedListItem.get()); 92 insertNodeBefore(newList, selectedListItem.get());
93 93
94 // We should clone all the children of the list item for indenting purposes. However, in case the current 94 // We should clone all the children of the list item for indenting purposes. However, in case the current
95 // selection does not encompass all its children, we need to explicitally ha ndle the same. The original 95 // selection does not encompass all its children, we need to explicitally ha ndle the same. The original
96 // list item too would require proper deletion in that case. 96 // list item too would require proper deletion in that case.
97 if (end.anchorNode() == selectedListItem.get() || end.anchorNode()->isDescen dantOf(selectedListItem->lastChild())) { 97 if (end.anchorNode() == selectedListItem.get() || end.anchorNode()->isDescen dantOf(selectedListItem->lastChild())) {
98 moveParagraphWithClones(createVisiblePosition(start), createVisiblePosit ion(end), newList.get(), selectedListItem.get()); 98 moveParagraphWithClones(createVisiblePosition(start), createVisiblePosit ion(end), newList.get(), selectedListItem.get());
99 } else { 99 } else {
100 moveParagraphWithClones(createVisiblePosition(start), createVisiblePosit ion(positionAfterNode(selectedListItem->lastChild())), newList.get(), selectedLi stItem.get()); 100 moveParagraphWithClones(createVisiblePosition(start), createVisiblePosit ion(positionAfterNode(selectedListItem->lastChild())), newList.get(), selectedLi stItem.get());
101 removeNode(selectedListItem.get()); 101 removeNode(selectedListItem.get());
102 } 102 }
103 103
104 if (canMergeLists(previousList.get(), newList.get())) 104 if (canMergeLists(previousList.get(), newList.get()))
105 mergeIdenticalElements(previousList.get(), newList.get()); 105 mergeIdenticalElements(previousList.get(), newList.get());
106 if (canMergeLists(newList.get(), nextList.get())) 106 if (canMergeLists(newList.get(), nextList.get()))
107 mergeIdenticalElements(newList.get(), nextList.get()); 107 mergeIdenticalElements(newList.get(), nextList.get());
108 108
109 return true; 109 return true;
110 } 110 }
111 111
112 void IndentOutdentCommand::indentIntoBlockquote(const Position& start, const Pos ition& end, RefPtrWillBeRawPtr<HTMLElement>& targetBlockquote) 112 void IndentOutdentCommand::indentIntoBlockquote(const Position& start, const Pos ition& end, RawPtr<HTMLElement>& targetBlockquote)
113 { 113 {
114 Element* enclosingCell = toElement(enclosingNodeOfType(start, &isTableCell)) ; 114 Element* enclosingCell = toElement(enclosingNodeOfType(start, &isTableCell)) ;
115 Element* elementToSplitTo; 115 Element* elementToSplitTo;
116 if (enclosingCell) 116 if (enclosingCell)
117 elementToSplitTo = enclosingCell; 117 elementToSplitTo = enclosingCell;
118 else if (enclosingList(start.computeContainerNode())) 118 else if (enclosingList(start.computeContainerNode()))
119 elementToSplitTo = enclosingBlock(start.computeContainerNode()); 119 elementToSplitTo = enclosingBlock(start.computeContainerNode());
120 else 120 else
121 elementToSplitTo = rootEditableElementOf(start); 121 elementToSplitTo = rootEditableElementOf(start);
122 122
123 if (!elementToSplitTo) 123 if (!elementToSplitTo)
124 return; 124 return;
125 125
126 RefPtrWillBeRawPtr<Node> outerBlock = (start.computeContainerNode() == eleme ntToSplitTo) ? start.computeContainerNode() : splitTreeToNode(start.computeConta inerNode(), elementToSplitTo).get(); 126 RawPtr<Node> outerBlock = (start.computeContainerNode() == elementToSplitTo) ? start.computeContainerNode() : splitTreeToNode(start.computeContainerNode(), elementToSplitTo).get();
127 127
128 VisiblePosition startOfContents = createVisiblePosition(start); 128 VisiblePosition startOfContents = createVisiblePosition(start);
129 if (!targetBlockquote) { 129 if (!targetBlockquote) {
130 // Create a new blockquote and insert it as a child of the root editable element. We accomplish 130 // Create a new blockquote and insert it as a child of the root editable element. We accomplish
131 // this by splitting all parents of the current paragraph up to that poi nt. 131 // this by splitting all parents of the current paragraph up to that poi nt.
132 targetBlockquote = createBlockElement(); 132 targetBlockquote = createBlockElement();
133 if (outerBlock == start.computeContainerNode()) 133 if (outerBlock == start.computeContainerNode())
134 insertNodeAt(targetBlockquote, start); 134 insertNodeAt(targetBlockquote, start);
135 else 135 else
136 insertNodeBefore(targetBlockquote, outerBlock); 136 insertNodeBefore(targetBlockquote, outerBlock);
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 document().updateLayoutIgnorePendingStylesheets(); 188 document().updateLayoutIgnorePendingStylesheets();
189 visibleStartOfParagraph = createVisiblePosition(visibleStartOfParagraph. deepEquivalent()); 189 visibleStartOfParagraph = createVisiblePosition(visibleStartOfParagraph. deepEquivalent());
190 visibleEndOfParagraph = createVisiblePosition(visibleEndOfParagraph.deep Equivalent()); 190 visibleEndOfParagraph = createVisiblePosition(visibleEndOfParagraph.deep Equivalent());
191 if (visibleStartOfParagraph.isNotNull() && !isStartOfParagraph(visibleSt artOfParagraph)) 191 if (visibleStartOfParagraph.isNotNull() && !isStartOfParagraph(visibleSt artOfParagraph))
192 insertNodeAt(HTMLBRElement::create(document()), visibleStartOfParagr aph.deepEquivalent()); 192 insertNodeAt(HTMLBRElement::create(document()), visibleStartOfParagr aph.deepEquivalent());
193 if (visibleEndOfParagraph.isNotNull() && !isEndOfParagraph(visibleEndOfP aragraph)) 193 if (visibleEndOfParagraph.isNotNull() && !isEndOfParagraph(visibleEndOfP aragraph))
194 insertNodeAt(HTMLBRElement::create(document()), visibleEndOfParagrap h.deepEquivalent()); 194 insertNodeAt(HTMLBRElement::create(document()), visibleEndOfParagrap h.deepEquivalent());
195 195
196 return; 196 return;
197 } 197 }
198 RefPtrWillBeRawPtr<Node> splitBlockquoteNode = enclosingElement; 198 RawPtr<Node> splitBlockquoteNode = enclosingElement;
199 if (Element* enclosingBlockFlow = enclosingBlock(visibleStartOfParagraph.dee pEquivalent().anchorNode())) { 199 if (Element* enclosingBlockFlow = enclosingBlock(visibleStartOfParagraph.dee pEquivalent().anchorNode())) {
200 if (enclosingBlockFlow != enclosingElement) { 200 if (enclosingBlockFlow != enclosingElement) {
201 splitBlockquoteNode = splitTreeToNode(enclosingBlockFlow, enclosingE lement, true); 201 splitBlockquoteNode = splitTreeToNode(enclosingBlockFlow, enclosingE lement, true);
202 } else { 202 } else {
203 // We split the blockquote at where we start outdenting. 203 // We split the blockquote at where we start outdenting.
204 Node* highestInlineNode = highestEnclosingNodeOfType(visibleStartOfP aragraph.deepEquivalent(), isInline, CannotCrossEditingBoundary, enclosingBlockF low); 204 Node* highestInlineNode = highestEnclosingNodeOfType(visibleStartOfP aragraph.deepEquivalent(), isInline, CannotCrossEditingBoundary, enclosingBlockF low);
205 splitElement(enclosingElement, highestInlineNode ? highestInlineNode : visibleStartOfParagraph.deepEquivalent().anchorNode()); 205 splitElement(enclosingElement, highestInlineNode ? highestInlineNode : visibleStartOfParagraph.deepEquivalent().anchorNode());
206 } 206 }
207 } 207 }
208 VisiblePosition startOfParagraphToMove = startOfParagraph(visibleStartOfPara graph); 208 VisiblePosition startOfParagraphToMove = startOfParagraph(visibleStartOfPara graph);
209 VisiblePosition endOfParagraphToMove = endOfParagraph(visibleEndOfParagraph) ; 209 VisiblePosition endOfParagraphToMove = endOfParagraph(visibleEndOfParagraph) ;
210 if (startOfParagraphToMove.isNull() || endOfParagraphToMove.isNull()) 210 if (startOfParagraphToMove.isNull() || endOfParagraphToMove.isNull())
211 return; 211 return;
212 RefPtrWillBeRawPtr<HTMLBRElement> placeholder = HTMLBRElement::create(docume nt()); 212 RawPtr<HTMLBRElement> placeholder = HTMLBRElement::create(document());
213 insertNodeBefore(placeholder, splitBlockquoteNode); 213 insertNodeBefore(placeholder, splitBlockquoteNode);
214 moveParagraph(startOfParagraphToMove, endOfParagraphToMove, createVisiblePos ition(positionBeforeNode(placeholder.get())), true); 214 moveParagraph(startOfParagraphToMove, endOfParagraphToMove, createVisiblePos ition(positionBeforeNode(placeholder.get())), true);
215 } 215 }
216 216
217 // FIXME: We should merge this function with ApplyBlockElementCommand::formatSel ection 217 // FIXME: We should merge this function with ApplyBlockElementCommand::formatSel ection
218 void IndentOutdentCommand::outdentRegion(const VisiblePosition& startOfSelection , const VisiblePosition& endOfSelection) 218 void IndentOutdentCommand::outdentRegion(const VisiblePosition& startOfSelection , const VisiblePosition& endOfSelection)
219 { 219 {
220 VisiblePosition endOfCurrentParagraph = endOfParagraph(startOfSelection); 220 VisiblePosition endOfCurrentParagraph = endOfParagraph(startOfSelection);
221 VisiblePosition endOfLastParagraph = endOfParagraph(endOfSelection); 221 VisiblePosition endOfLastParagraph = endOfParagraph(endOfSelection);
222 222
(...skipping 29 matching lines...) Expand all
252 } 252 }
253 253
254 void IndentOutdentCommand::formatSelection(const VisiblePosition& startOfSelecti on, const VisiblePosition& endOfSelection) 254 void IndentOutdentCommand::formatSelection(const VisiblePosition& startOfSelecti on, const VisiblePosition& endOfSelection)
255 { 255 {
256 if (m_typeOfAction == Indent) 256 if (m_typeOfAction == Indent)
257 ApplyBlockElementCommand::formatSelection(startOfSelection, endOfSelecti on); 257 ApplyBlockElementCommand::formatSelection(startOfSelection, endOfSelecti on);
258 else 258 else
259 outdentRegion(startOfSelection, endOfSelection); 259 outdentRegion(startOfSelection, endOfSelection);
260 } 260 }
261 261
262 void IndentOutdentCommand::formatRange(const Position& start, const Position& en d, const Position&, RefPtrWillBeRawPtr<HTMLElement>& blockquoteForNextIndent) 262 void IndentOutdentCommand::formatRange(const Position& start, const Position& en d, const Position&, RawPtr<HTMLElement>& blockquoteForNextIndent)
263 { 263 {
264 if (tryIndentingAsListItem(start, end)) 264 if (tryIndentingAsListItem(start, end))
265 blockquoteForNextIndent = nullptr; 265 blockquoteForNextIndent = nullptr;
266 else 266 else
267 indentIntoBlockquote(start, end, blockquoteForNextIndent); 267 indentIntoBlockquote(start, end, blockquoteForNextIndent);
268 } 268 }
269 269
270 } // namespace blink 270 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698