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

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

Issue 1307803003: Introduce nextPositionOf() for VisiblePosition (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: 2015-08-28T18:13:02 Created 5 years, 3 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) 2005, 2006, 2008, 2009 Apple Inc. All rights reserved. 2 * Copyright (C) 2005, 2006, 2008, 2009 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 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 // Save and restore the selection endpoints using their indices in the docum ent, since 259 // Save and restore the selection endpoints using their indices in the docum ent, since
260 // addBlockStyleIfNeeded may moveParagraphs, which can remove these endpoint s. 260 // addBlockStyleIfNeeded may moveParagraphs, which can remove these endpoint s.
261 // Calculate start and end indices from the start of the tree that they're i n. 261 // Calculate start and end indices from the start of the tree that they're i n.
262 Node& scope = NodeTraversal::highestAncestorOrSelf(*visibleStart.deepEquival ent().anchorNode()); 262 Node& scope = NodeTraversal::highestAncestorOrSelf(*visibleStart.deepEquival ent().anchorNode());
263 RefPtrWillBeRawPtr<Range> startRange = Range::create(document(), firstPositi onInNode(&scope), visibleStart.deepEquivalent().parentAnchoredEquivalent()); 263 RefPtrWillBeRawPtr<Range> startRange = Range::create(document(), firstPositi onInNode(&scope), visibleStart.deepEquivalent().parentAnchoredEquivalent());
264 RefPtrWillBeRawPtr<Range> endRange = Range::create(document(), firstPosition InNode(&scope), visibleEnd.deepEquivalent().parentAnchoredEquivalent()); 264 RefPtrWillBeRawPtr<Range> endRange = Range::create(document(), firstPosition InNode(&scope), visibleEnd.deepEquivalent().parentAnchoredEquivalent());
265 int startIndex = TextIterator::rangeLength(startRange->startPosition(), star tRange->endPosition(), true); 265 int startIndex = TextIterator::rangeLength(startRange->startPosition(), star tRange->endPosition(), true);
266 int endIndex = TextIterator::rangeLength(endRange->startPosition(), endRange ->endPosition(), true); 266 int endIndex = TextIterator::rangeLength(endRange->startPosition(), endRange ->endPosition(), true);
267 267
268 VisiblePosition paragraphStart(startOfParagraph(visibleStart)); 268 VisiblePosition paragraphStart(startOfParagraph(visibleStart));
269 VisiblePosition nextParagraphStart(endOfParagraph(paragraphStart).next()); 269 VisiblePosition nextParagraphStart(nextPositionOf(endOfParagraph(paragraphSt art)));
270 VisiblePosition beyondEnd(endOfParagraph(visibleEnd).next()); 270 VisiblePosition beyondEnd(nextPositionOf(endOfParagraph(visibleEnd)));
271 while (paragraphStart.isNotNull() && paragraphStart.deepEquivalent() != beyo ndEnd.deepEquivalent()) { 271 while (paragraphStart.isNotNull() && paragraphStart.deepEquivalent() != beyo ndEnd.deepEquivalent()) {
272 StyleChange styleChange(style, paragraphStart.deepEquivalent()); 272 StyleChange styleChange(style, paragraphStart.deepEquivalent());
273 if (styleChange.cssStyle().length() || m_removeOnly) { 273 if (styleChange.cssStyle().length() || m_removeOnly) {
274 RefPtrWillBeRawPtr<Element> block = enclosingBlock(paragraphStart.de epEquivalent().anchorNode()); 274 RefPtrWillBeRawPtr<Element> block = enclosingBlock(paragraphStart.de epEquivalent().anchorNode());
275 const Position& paragraphStartToMove = paragraphStart.deepEquivalent (); 275 const Position& paragraphStartToMove = paragraphStart.deepEquivalent ();
276 if (!m_removeOnly && isEditablePosition(paragraphStartToMove)) { 276 if (!m_removeOnly && isEditablePosition(paragraphStartToMove)) {
277 RefPtrWillBeRawPtr<HTMLElement> newBlock = moveParagraphContents ToNewBlockIfNecessary(paragraphStartToMove); 277 RefPtrWillBeRawPtr<HTMLElement> newBlock = moveParagraphContents ToNewBlockIfNecessary(paragraphStartToMove);
278 if (newBlock) 278 if (newBlock)
279 block = newBlock; 279 block = newBlock;
280 } 280 }
281 if (block && block->isHTMLElement()) { 281 if (block && block->isHTMLElement()) {
282 removeCSSStyle(style, toHTMLElement(block)); 282 removeCSSStyle(style, toHTMLElement(block));
283 if (!m_removeOnly) 283 if (!m_removeOnly)
284 addBlockStyle(styleChange, toHTMLElement(block)); 284 addBlockStyle(styleChange, toHTMLElement(block));
285 } 285 }
286 286
287 if (nextParagraphStart.isOrphan()) 287 if (nextParagraphStart.isOrphan())
288 nextParagraphStart = endOfParagraph(paragraphStart).next(); 288 nextParagraphStart = nextPositionOf(endOfParagraph(paragraphStar t));
289 } 289 }
290 290
291 paragraphStart = nextParagraphStart; 291 paragraphStart = nextParagraphStart;
292 nextParagraphStart = endOfParagraph(paragraphStart).next(); 292 nextParagraphStart = nextPositionOf(endOfParagraph(paragraphStart));
293 } 293 }
294 294
295 EphemeralRange startEphemeralRange = PlainTextRange(startIndex).createRangeF orSelection(toContainerNode(scope)); 295 EphemeralRange startEphemeralRange = PlainTextRange(startIndex).createRangeF orSelection(toContainerNode(scope));
296 if (startEphemeralRange.isNull()) 296 if (startEphemeralRange.isNull())
297 return; 297 return;
298 EphemeralRange endEphemeralRange = PlainTextRange(endIndex).createRangeForSe lection(toContainerNode(scope)); 298 EphemeralRange endEphemeralRange = PlainTextRange(endIndex).createRangeForSe lection(toContainerNode(scope));
299 if (endEphemeralRange.isNull()) 299 if (endEphemeralRange.isNull())
300 return; 300 return;
301 updateStartEnd(startEphemeralRange.startPosition(), endEphemeralRange.startP osition()); 301 updateStartEnd(startEphemeralRange.startPosition(), endEphemeralRange.startP osition());
302 } 302 }
(...skipping 1291 matching lines...) Expand 10 before | Expand all | Expand 10 after
1594 DEFINE_TRACE(ApplyStyleCommand) 1594 DEFINE_TRACE(ApplyStyleCommand)
1595 { 1595 {
1596 visitor->trace(m_style); 1596 visitor->trace(m_style);
1597 visitor->trace(m_start); 1597 visitor->trace(m_start);
1598 visitor->trace(m_end); 1598 visitor->trace(m_end);
1599 visitor->trace(m_styledInlineElement); 1599 visitor->trace(m_styledInlineElement);
1600 CompositeEditCommand::trace(visitor); 1600 CompositeEditCommand::trace(visitor);
1601 } 1601 }
1602 1602
1603 } 1603 }
OLDNEW
« no previous file with comments | « Source/core/editing/commands/ApplyBlockElementCommand.cpp ('k') | Source/core/editing/commands/BreakBlockquoteCommand.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698