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

Side by Side Diff: third_party/WebKit/Source/core/editing/commands/ApplyBlockElementCommand.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 * Copyright (C) 2010 Google Inc. All rights reserved. 3 * Copyright (C) 2010 Google Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 if (newSelection.isNone()) 78 if (newSelection.isNone())
79 return; 79 return;
80 setEndingSelection(newSelection); 80 setEndingSelection(newSelection);
81 } 81 }
82 82
83 VisibleSelection selection = selectionForParagraphIteration(endingSelection( )); 83 VisibleSelection selection = selectionForParagraphIteration(endingSelection( ));
84 VisiblePosition startOfSelection = selection.visibleStart(); 84 VisiblePosition startOfSelection = selection.visibleStart();
85 VisiblePosition endOfSelection = selection.visibleEnd(); 85 VisiblePosition endOfSelection = selection.visibleEnd();
86 ASSERT(!startOfSelection.isNull()); 86 ASSERT(!startOfSelection.isNull());
87 ASSERT(!endOfSelection.isNull()); 87 ASSERT(!endOfSelection.isNull());
88 RefPtrWillBeRawPtr<ContainerNode> startScope = nullptr; 88 RawPtr<ContainerNode> startScope = nullptr;
89 int startIndex = indexForVisiblePosition(startOfSelection, startScope); 89 int startIndex = indexForVisiblePosition(startOfSelection, startScope);
90 RefPtrWillBeRawPtr<ContainerNode> endScope = nullptr; 90 RawPtr<ContainerNode> endScope = nullptr;
91 int endIndex = indexForVisiblePosition(endOfSelection, endScope); 91 int endIndex = indexForVisiblePosition(endOfSelection, endScope);
92 92
93 formatSelection(startOfSelection, endOfSelection); 93 formatSelection(startOfSelection, endOfSelection);
94 94
95 document().updateLayoutIgnorePendingStylesheets(); 95 document().updateLayoutIgnorePendingStylesheets();
96 96
97 ASSERT(startScope == endScope); 97 ASSERT(startScope == endScope);
98 ASSERT(startIndex >= 0); 98 ASSERT(startIndex >= 0);
99 ASSERT(startIndex <= endIndex); 99 ASSERT(startIndex <= endIndex);
100 if (startScope == endScope && startIndex >= 0 && startIndex <= endIndex) { 100 if (startScope == endScope && startIndex >= 0 && startIndex <= endIndex) {
101 VisiblePosition start(visiblePositionForIndex(startIndex, startScope.get ())); 101 VisiblePosition start(visiblePositionForIndex(startIndex, startScope.get ()));
102 VisiblePosition end(visiblePositionForIndex(endIndex, endScope.get())); 102 VisiblePosition end(visiblePositionForIndex(endIndex, endScope.get()));
103 if (start.isNotNull() && end.isNotNull()) 103 if (start.isNotNull() && end.isNotNull())
104 setEndingSelection(VisibleSelection(start, end, endingSelection().is Directional())); 104 setEndingSelection(VisibleSelection(start, end, endingSelection().is Directional()));
105 } 105 }
106 } 106 }
107 107
108 void ApplyBlockElementCommand::formatSelection(const VisiblePosition& startOfSel ection, const VisiblePosition& endOfSelection) 108 void ApplyBlockElementCommand::formatSelection(const VisiblePosition& startOfSel ection, const VisiblePosition& endOfSelection)
109 { 109 {
110 // Special case empty unsplittable elements because there's nothing to split 110 // Special case empty unsplittable elements because there's nothing to split
111 // and there's nothing to move. 111 // and there's nothing to move.
112 Position start = mostForwardCaretPosition(startOfSelection.deepEquivalent()) ; 112 Position start = mostForwardCaretPosition(startOfSelection.deepEquivalent()) ;
113 if (isAtUnsplittableElement(start)) { 113 if (isAtUnsplittableElement(start)) {
114 RefPtrWillBeRawPtr<HTMLElement> blockquote = createBlockElement(); 114 RawPtr<HTMLElement> blockquote = createBlockElement();
115 insertNodeAt(blockquote, start); 115 insertNodeAt(blockquote, start);
116 RefPtrWillBeRawPtr<HTMLBRElement> placeholder = HTMLBRElement::create(do cument()); 116 RawPtr<HTMLBRElement> placeholder = HTMLBRElement::create(document());
117 appendNode(placeholder, blockquote); 117 appendNode(placeholder, blockquote);
118 setEndingSelection(VisibleSelection(positionBeforeNode(placeholder.get() ), TextAffinity::Downstream, endingSelection().isDirectional())); 118 setEndingSelection(VisibleSelection(positionBeforeNode(placeholder.get() ), TextAffinity::Downstream, endingSelection().isDirectional()));
119 return; 119 return;
120 } 120 }
121 121
122 RefPtrWillBeRawPtr<HTMLElement> blockquoteForNextIndent = nullptr; 122 RawPtr<HTMLElement> blockquoteForNextIndent = nullptr;
123 VisiblePosition endOfCurrentParagraph = endOfParagraph(startOfSelection); 123 VisiblePosition endOfCurrentParagraph = endOfParagraph(startOfSelection);
124 VisiblePosition endOfLastParagraph = endOfParagraph(endOfSelection); 124 VisiblePosition endOfLastParagraph = endOfParagraph(endOfSelection);
125 VisiblePosition endAfterSelection = endOfParagraph(nextPositionOf(endOfLastP aragraph)); 125 VisiblePosition endAfterSelection = endOfParagraph(nextPositionOf(endOfLastP aragraph));
126 m_endOfLastParagraph = endOfLastParagraph.deepEquivalent(); 126 m_endOfLastParagraph = endOfLastParagraph.deepEquivalent();
127 127
128 bool atEnd = false; 128 bool atEnd = false;
129 Position end; 129 Position end;
130 while (endOfCurrentParagraph.deepEquivalent() != endAfterSelection.deepEquiv alent() && !atEnd) { 130 while (endOfCurrentParagraph.deepEquivalent() != endAfterSelection.deepEquiv alent() && !atEnd) {
131 if (endOfCurrentParagraph.deepEquivalent() == m_endOfLastParagraph) 131 if (endOfCurrentParagraph.deepEquivalent() == m_endOfLastParagraph)
132 atEnd = true; 132 atEnd = true;
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 // TODO(yosin) We should use |PositionMoveType::Character| for 224 // TODO(yosin) We should use |PositionMoveType::Character| for
225 // |previousPositionOf()|. 225 // |previousPositionOf()|.
226 if (!isNewLineAtPosition(previousPositionOf(end, PositionMoveType::C odePoint)) && isNewLineAtPosition(end)) 226 if (!isNewLineAtPosition(previousPositionOf(end, PositionMoveType::C odePoint)) && isNewLineAtPosition(end))
227 end = Position(end.computeContainerNode(), endOffset + 1); 227 end = Position(end.computeContainerNode(), endOffset + 1);
228 if (isEndAndEndOfLastParagraphOnSameNode && end.offsetInContainerNod e() >= m_endOfLastParagraph.offsetInContainerNode()) 228 if (isEndAndEndOfLastParagraphOnSameNode && end.offsetInContainerNod e() >= m_endOfLastParagraph.offsetInContainerNode())
229 m_endOfLastParagraph = end; 229 m_endOfLastParagraph = end;
230 } 230 }
231 231
232 // If end is in the middle of a text node, split. 232 // If end is in the middle of a text node, split.
233 if (endStyle->userModify() != READ_ONLY && !endStyle->collapseWhiteSpace () && end.offsetInContainerNode() && end.offsetInContainerNode() < end.computeCo ntainerNode()->maxCharacterOffset()) { 233 if (endStyle->userModify() != READ_ONLY && !endStyle->collapseWhiteSpace () && end.offsetInContainerNode() && end.offsetInContainerNode() < end.computeCo ntainerNode()->maxCharacterOffset()) {
234 RefPtrWillBeRawPtr<Text> endContainer = toText(end.computeContainerN ode()); 234 RawPtr<Text> endContainer = toText(end.computeContainerNode());
235 splitTextNode(endContainer, end.offsetInContainerNode()); 235 splitTextNode(endContainer, end.offsetInContainerNode());
236 if (isStartAndEndOnSameNode) 236 if (isStartAndEndOnSameNode)
237 start = firstPositionInOrBeforeNode(endContainer->previousSiblin g()); 237 start = firstPositionInOrBeforeNode(endContainer->previousSiblin g());
238 if (isEndAndEndOfLastParagraphOnSameNode) { 238 if (isEndAndEndOfLastParagraphOnSameNode) {
239 if (m_endOfLastParagraph.offsetInContainerNode() == end.offsetIn ContainerNode()) 239 if (m_endOfLastParagraph.offsetInContainerNode() == end.offsetIn ContainerNode())
240 m_endOfLastParagraph = lastPositionInOrAfterNode(endContaine r->previousSibling()); 240 m_endOfLastParagraph = lastPositionInOrAfterNode(endContaine r->previousSibling());
241 else 241 else
242 m_endOfLastParagraph = Position(endContainer, m_endOfLastPar agraph.offsetInContainerNode() - end.offsetInContainerNode()); 242 m_endOfLastParagraph = Position(endContainer, m_endOfLastPar agraph.offsetInContainerNode() - end.offsetInContainerNode());
243 } 243 }
244 end = lastPositionInNode(endContainer->previousSibling()); 244 end = lastPositionInNode(endContainer->previousSibling());
245 } 245 }
246 } 246 }
247 } 247 }
248 248
249 VisiblePosition ApplyBlockElementCommand::endOfNextParagrahSplittingTextNodesIfN eeded(VisiblePosition& endOfCurrentParagraph, Position& start, Position& end) 249 VisiblePosition ApplyBlockElementCommand::endOfNextParagrahSplittingTextNodesIfN eeded(VisiblePosition& endOfCurrentParagraph, Position& start, Position& end)
250 { 250 {
251 VisiblePosition endOfNextParagraph = endOfParagraph(nextPositionOf(endOfCurr entParagraph)); 251 VisiblePosition endOfNextParagraph = endOfParagraph(nextPositionOf(endOfCurr entParagraph));
252 Position position = endOfNextParagraph.deepEquivalent(); 252 Position position = endOfNextParagraph.deepEquivalent();
253 const ComputedStyle* style = computedStyleOfEnclosingTextNode(position); 253 const ComputedStyle* style = computedStyleOfEnclosingTextNode(position);
254 if (!style) 254 if (!style)
255 return endOfNextParagraph; 255 return endOfNextParagraph;
256 256
257 RefPtrWillBeRawPtr<Text> text = toText(position.computeContainerNode()); 257 RawPtr<Text> text = toText(position.computeContainerNode());
258 if (!style->preserveNewline() || !position.offsetInContainerNode() || !isNew LineAtPosition(firstPositionInNode(text.get()))) 258 if (!style->preserveNewline() || !position.offsetInContainerNode() || !isNew LineAtPosition(firstPositionInNode(text.get())))
259 return endOfNextParagraph; 259 return endOfNextParagraph;
260 260
261 // \n at the beginning of the text node immediately following the current pa ragraph is trimmed by moveParagraphWithClones. 261 // \n at the beginning of the text node immediately following the current pa ragraph is trimmed by moveParagraphWithClones.
262 // If endOfNextParagraph was pointing at this same text node, endOfNextParag raph will be shifted by one paragraph. 262 // If endOfNextParagraph was pointing at this same text node, endOfNextParag raph will be shifted by one paragraph.
263 // Avoid this by splitting "\n" 263 // Avoid this by splitting "\n"
264 splitTextNode(text, 1); 264 splitTextNode(text, 1);
265 265
266 if (text == start.computeContainerNode() && text->previousSibling() && text- >previousSibling()->isTextNode()) { 266 if (text == start.computeContainerNode() && text->previousSibling() && text- >previousSibling()->isTextNode()) {
267 ASSERT(start.offsetInContainerNode() < position.offsetInContainerNode()) ; 267 ASSERT(start.offsetInContainerNode() < position.offsetInContainerNode()) ;
(...skipping 10 matching lines...) Expand all
278 && static_cast<unsigned>(m_endOfLastParagraph.offsetInContainerN ode()) <= toText(text->previousSibling())->length()) 278 && static_cast<unsigned>(m_endOfLastParagraph.offsetInContainerN ode()) <= toText(text->previousSibling())->length())
279 m_endOfLastParagraph = Position(toText(text->previousSibling()), m_endOfLastParagraph.offsetInContainerNode()); 279 m_endOfLastParagraph = Position(toText(text->previousSibling()), m_endOfLastParagraph.offsetInContainerNode());
280 } else { 280 } else {
281 m_endOfLastParagraph = Position(text.get(), m_endOfLastParagraph.off setInContainerNode() - 1); 281 m_endOfLastParagraph = Position(text.get(), m_endOfLastParagraph.off setInContainerNode() - 1);
282 } 282 }
283 } 283 }
284 284
285 return createVisiblePosition(Position(text.get(), position.offsetInContainer Node() - 1)); 285 return createVisiblePosition(Position(text.get(), position.offsetInContainer Node() - 1));
286 } 286 }
287 287
288 PassRefPtrWillBeRawPtr<HTMLElement> ApplyBlockElementCommand::createBlockElement () const 288 RawPtr<HTMLElement> ApplyBlockElementCommand::createBlockElement() const
289 { 289 {
290 RefPtrWillBeRawPtr<HTMLElement> element = createHTMLElement(document(), m_ta gName); 290 RawPtr<HTMLElement> element = createHTMLElement(document(), m_tagName);
291 if (m_inlineStyle.length()) 291 if (m_inlineStyle.length())
292 element->setAttribute(styleAttr, m_inlineStyle); 292 element->setAttribute(styleAttr, m_inlineStyle);
293 return element.release(); 293 return element.release();
294 } 294 }
295 295
296 DEFINE_TRACE(ApplyBlockElementCommand) 296 DEFINE_TRACE(ApplyBlockElementCommand)
297 { 297 {
298 visitor->trace(m_endOfLastParagraph); 298 visitor->trace(m_endOfLastParagraph);
299 CompositeEditCommand::trace(visitor); 299 CompositeEditCommand::trace(visitor);
300 } 300 }
301 301
302 } // namespace blink 302 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698