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

Side by Side Diff: Source/core/editing/commands/ApplyBlockElementCommand.cpp

Issue 1305963003: Introduce {next,previous}PositionOf() as replacement of {next,previous}() member functions in Positi (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: 2015-08-22T00:12:04 Rebase Created 5 years, 4 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 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 end = endOfCurrentParagraph.deepEquivalent(); 186 end = endOfCurrentParagraph.deepEquivalent();
187 187
188 document().updateLayoutTreeIfNeeded(); 188 document().updateLayoutTreeIfNeeded();
189 189
190 bool isStartAndEndOnSameNode = false; 190 bool isStartAndEndOnSameNode = false;
191 if (const ComputedStyle* startStyle = computedStyleOfEnclosingTextNode(start )) { 191 if (const ComputedStyle* startStyle = computedStyleOfEnclosingTextNode(start )) {
192 isStartAndEndOnSameNode = computedStyleOfEnclosingTextNode(end) && start .computeContainerNode() == end.computeContainerNode(); 192 isStartAndEndOnSameNode = computedStyleOfEnclosingTextNode(end) && start .computeContainerNode() == end.computeContainerNode();
193 bool isStartAndEndOfLastParagraphOnSameNode = computedStyleOfEnclosingTe xtNode(m_endOfLastParagraph) && start.computeContainerNode() == m_endOfLastParag raph.computeContainerNode(); 193 bool isStartAndEndOfLastParagraphOnSameNode = computedStyleOfEnclosingTe xtNode(m_endOfLastParagraph) && start.computeContainerNode() == m_endOfLastParag raph.computeContainerNode();
194 194
195 // Avoid obtanining the start of next paragraph for start 195 // Avoid obtanining the start of next paragraph for start
196 if (startStyle->preserveNewline() && isNewLineAtPosition(start) && !isNe wLineAtPosition(start.previous()) && start.offsetInContainerNode() > 0) 196 // TODO(yosin) We should use |PositionMoveType::Character| for
197 start = startOfParagraph(VisiblePosition(end.previous())).deepEquiva lent(); 197 // |previousPositionOf()|.
198 if (startStyle->preserveNewline() && isNewLineAtPosition(start) && !isNe wLineAtPosition(previousPositionOf(start, PositionMoveType::CodePoint)) && start .offsetInContainerNode() > 0)
199 start = startOfParagraph(VisiblePosition(previousPositionOf(end, Pos itionMoveType::CodePoint))).deepEquivalent();
198 200
199 // If start is in the middle of a text node, split. 201 // If start is in the middle of a text node, split.
200 if (!startStyle->collapseWhiteSpace() && start.offsetInContainerNode() > 0) { 202 if (!startStyle->collapseWhiteSpace() && start.offsetInContainerNode() > 0) {
201 int startOffset = start.offsetInContainerNode(); 203 int startOffset = start.offsetInContainerNode();
202 Text* startText = toText(start.computeContainerNode()); 204 Text* startText = toText(start.computeContainerNode());
203 splitTextNode(startText, startOffset); 205 splitTextNode(startText, startOffset);
204 start = firstPositionInNode(startText); 206 start = firstPositionInNode(startText);
205 if (isStartAndEndOnSameNode) { 207 if (isStartAndEndOnSameNode) {
206 ASSERT(end.offsetInContainerNode() >= startOffset); 208 ASSERT(end.offsetInContainerNode() >= startOffset);
207 end = Position(startText, end.offsetInContainerNode() - startOff set); 209 end = Position(startText, end.offsetInContainerNode() - startOff set);
208 } 210 }
209 if (isStartAndEndOfLastParagraphOnSameNode) { 211 if (isStartAndEndOfLastParagraphOnSameNode) {
210 ASSERT(m_endOfLastParagraph.offsetInContainerNode() >= startOffs et); 212 ASSERT(m_endOfLastParagraph.offsetInContainerNode() >= startOffs et);
211 m_endOfLastParagraph = Position(startText, m_endOfLastParagraph. offsetInContainerNode() - startOffset); 213 m_endOfLastParagraph = Position(startText, m_endOfLastParagraph. offsetInContainerNode() - startOffset);
212 } 214 }
213 } 215 }
214 } 216 }
215 217
216 document().updateLayoutTreeIfNeeded(); 218 document().updateLayoutTreeIfNeeded();
217 219
218 if (const ComputedStyle* endStyle = computedStyleOfEnclosingTextNode(end)) { 220 if (const ComputedStyle* endStyle = computedStyleOfEnclosingTextNode(end)) {
219 bool isEndAndEndOfLastParagraphOnSameNode = computedStyleOfEnclosingText Node(m_endOfLastParagraph) && end.anchorNode() == m_endOfLastParagraph.anchorNod e(); 221 bool isEndAndEndOfLastParagraphOnSameNode = computedStyleOfEnclosingText Node(m_endOfLastParagraph) && end.anchorNode() == m_endOfLastParagraph.anchorNod e();
220 // Include \n at the end of line if we're at an empty paragraph 222 // Include \n at the end of line if we're at an empty paragraph
221 if (endStyle->preserveNewline() && start == end && end.offsetInContainer Node() < end.computeContainerNode()->maxCharacterOffset()) { 223 if (endStyle->preserveNewline() && start == end && end.offsetInContainer Node() < end.computeContainerNode()->maxCharacterOffset()) {
222 int endOffset = end.offsetInContainerNode(); 224 int endOffset = end.offsetInContainerNode();
223 if (!isNewLineAtPosition(end.previous()) && isNewLineAtPosition(end) ) 225 // TODO(yosin) We should use |PositionMoveType::Character| for
226 // |previousPositionOf()|.
227 if (!isNewLineAtPosition(previousPositionOf(end, PositionMoveType::C odePoint)) && isNewLineAtPosition(end))
224 end = Position(end.computeContainerNode(), endOffset + 1); 228 end = Position(end.computeContainerNode(), endOffset + 1);
225 if (isEndAndEndOfLastParagraphOnSameNode && end.offsetInContainerNod e() >= m_endOfLastParagraph.offsetInContainerNode()) 229 if (isEndAndEndOfLastParagraphOnSameNode && end.offsetInContainerNod e() >= m_endOfLastParagraph.offsetInContainerNode())
226 m_endOfLastParagraph = end; 230 m_endOfLastParagraph = end;
227 } 231 }
228 232
229 // If end is in the middle of a text node, split. 233 // If end is in the middle of a text node, split.
230 if (endStyle->userModify() != READ_ONLY && !endStyle->collapseWhiteSpace () && end.offsetInContainerNode() && end.offsetInContainerNode() < end.computeCo ntainerNode()->maxCharacterOffset()) { 234 if (endStyle->userModify() != READ_ONLY && !endStyle->collapseWhiteSpace () && end.offsetInContainerNode() && end.offsetInContainerNode() < end.computeCo ntainerNode()->maxCharacterOffset()) {
231 RefPtrWillBeRawPtr<Text> endContainer = toText(end.computeContainerN ode()); 235 RefPtrWillBeRawPtr<Text> endContainer = toText(end.computeContainerN ode());
232 splitTextNode(endContainer, end.offsetInContainerNode()); 236 splitTextNode(endContainer, end.offsetInContainerNode());
233 if (isStartAndEndOnSameNode) 237 if (isStartAndEndOnSameNode)
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 return element.release(); 294 return element.release();
291 } 295 }
292 296
293 DEFINE_TRACE(ApplyBlockElementCommand) 297 DEFINE_TRACE(ApplyBlockElementCommand)
294 { 298 {
295 visitor->trace(m_endOfLastParagraph); 299 visitor->trace(m_endOfLastParagraph);
296 CompositeEditCommand::trace(visitor); 300 CompositeEditCommand::trace(visitor);
297 } 301 }
298 302
299 } 303 }
OLDNEW
« no previous file with comments | « Source/core/editing/PositionTest.cpp ('k') | Source/core/editing/commands/BreakBlockquoteCommand.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698