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: third_party/WebKit/Source/core/editing/commands/ApplyStyleCommand.cpp

Issue 2170823002: Make ApplyStyleCommand::applyBlockStyle() to use connected position only (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 2016-07-21T17:08:56 Created 4 years, 5 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
« no previous file with comments | « third_party/WebKit/LayoutTests/editing/execCommand/apply_style/justify_right_ul_br_crash.html ('k') | 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) 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 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 Node& scope = NodeTraversal::highestAncestorOrSelf(*visibleStart.deepEquival ent().anchorNode()); 268 Node& scope = NodeTraversal::highestAncestorOrSelf(*visibleStart.deepEquival ent().anchorNode());
269 Range* startRange = Range::create(document(), Position::firstPositionInNode( &scope), visibleStart.deepEquivalent().parentAnchoredEquivalent()); 269 Range* startRange = Range::create(document(), Position::firstPositionInNode( &scope), visibleStart.deepEquivalent().parentAnchoredEquivalent());
270 Range* endRange = Range::create(document(), Position::firstPositionInNode(&s cope), visibleEnd.deepEquivalent().parentAnchoredEquivalent()); 270 Range* endRange = Range::create(document(), Position::firstPositionInNode(&s cope), visibleEnd.deepEquivalent().parentAnchoredEquivalent());
271 int startIndex = TextIterator::rangeLength(startRange->startPosition(), star tRange->endPosition(), true); 271 int startIndex = TextIterator::rangeLength(startRange->startPosition(), star tRange->endPosition(), true);
272 int endIndex = TextIterator::rangeLength(endRange->startPosition(), endRange ->endPosition(), true); 272 int endIndex = TextIterator::rangeLength(endRange->startPosition(), endRange ->endPosition(), true);
273 273
274 VisiblePosition paragraphStart(startOfParagraph(visibleStart)); 274 VisiblePosition paragraphStart(startOfParagraph(visibleStart));
275 VisiblePosition nextParagraphStart(nextPositionOf(endOfParagraph(paragraphSt art))); 275 VisiblePosition nextParagraphStart(nextPositionOf(endOfParagraph(paragraphSt art)));
276 VisiblePosition beyondEnd(nextPositionOf(endOfParagraph(visibleEnd))); 276 VisiblePosition beyondEnd(nextPositionOf(endOfParagraph(visibleEnd)));
277 while (paragraphStart.isNotNull() && paragraphStart.deepEquivalent() != beyo ndEnd.deepEquivalent()) { 277 while (paragraphStart.isNotNull() && paragraphStart.deepEquivalent() != beyo ndEnd.deepEquivalent()) {
278 DCHECK(!paragraphStart.isOrphan()) << paragraphStart;
278 StyleChange styleChange(style, paragraphStart.deepEquivalent()); 279 StyleChange styleChange(style, paragraphStart.deepEquivalent());
279 if (styleChange.cssStyle().length() || m_removeOnly) { 280 if (styleChange.cssStyle().length() || m_removeOnly) {
280 Element* block = enclosingBlock(paragraphStart.deepEquivalent().anch orNode()); 281 Element* block = enclosingBlock(paragraphStart.deepEquivalent().anch orNode());
281 const Position& paragraphStartToMove = paragraphStart.deepEquivalent (); 282 const Position& paragraphStartToMove = paragraphStart.deepEquivalent ();
282 if (!m_removeOnly && isEditablePosition(paragraphStartToMove)) { 283 if (!m_removeOnly && isEditablePosition(paragraphStartToMove)) {
283 HTMLElement* newBlock = moveParagraphContentsToNewBlockIfNecessa ry(paragraphStartToMove, editingState); 284 HTMLElement* newBlock = moveParagraphContentsToNewBlockIfNecessa ry(paragraphStartToMove, editingState);
284 if (editingState->isAborted()) 285 if (editingState->isAborted())
285 return; 286 return;
286 if (newBlock) 287 if (newBlock) {
287 block = newBlock; 288 block = newBlock;
289 if (paragraphStart.isOrphan())
290 paragraphStart = createVisiblePosition(Position::firstPo sitionInNode(newBlock));
291 }
292 DCHECK(!paragraphStart.isOrphan()) << paragraphStart;
288 } 293 }
289 if (block && block->isHTMLElement()) { 294 if (block && block->isHTMLElement()) {
290 removeCSSStyle(style, toHTMLElement(block), editingState); 295 removeCSSStyle(style, toHTMLElement(block), editingState);
291 if (editingState->isAborted()) 296 if (editingState->isAborted())
292 return; 297 return;
293 if (!m_removeOnly) 298 DCHECK(!paragraphStart.isOrphan()) << paragraphStart;
299 if (!m_removeOnly) {
294 addBlockStyle(styleChange, toHTMLElement(block)); 300 addBlockStyle(styleChange, toHTMLElement(block));
301 DCHECK(!paragraphStart.isOrphan()) << paragraphStart;
302 }
295 } 303 }
296 304
305 DCHECK(!paragraphStart.isOrphan()) << paragraphStart;
297 if (nextParagraphStart.isOrphan()) 306 if (nextParagraphStart.isOrphan())
298 nextParagraphStart = nextPositionOf(endOfParagraph(paragraphStar t)); 307 nextParagraphStart = nextPositionOf(endOfParagraph(paragraphStar t));
299 } 308 }
300 309
310 DCHECK(!nextParagraphStart.isOrphan()) << nextParagraphStart;
301 paragraphStart = nextParagraphStart; 311 paragraphStart = nextParagraphStart;
302 nextParagraphStart = nextPositionOf(endOfParagraph(paragraphStart)); 312 nextParagraphStart = nextPositionOf(endOfParagraph(paragraphStart));
303 } 313 }
304 314
305 // Update style and layout again, since added or removed styles could have 315 // Update style and layout again, since added or removed styles could have
306 // affected the layout. We need clean layout in order to compute 316 // affected the layout. We need clean layout in order to compute
307 // plain-text ranges below. 317 // plain-text ranges below.
308 document().updateStyleAndLayoutIgnorePendingStylesheets(); 318 document().updateStyleAndLayoutIgnorePendingStylesheets();
309 319
310 EphemeralRange startEphemeralRange = PlainTextRange(startIndex).createRangeF orSelection(toContainerNode(scope)); 320 EphemeralRange startEphemeralRange = PlainTextRange(startIndex).createRangeF orSelection(toContainerNode(scope));
(...skipping 1420 matching lines...) Expand 10 before | Expand all | Expand 10 after
1731 DEFINE_TRACE(ApplyStyleCommand) 1741 DEFINE_TRACE(ApplyStyleCommand)
1732 { 1742 {
1733 visitor->trace(m_style); 1743 visitor->trace(m_style);
1734 visitor->trace(m_start); 1744 visitor->trace(m_start);
1735 visitor->trace(m_end); 1745 visitor->trace(m_end);
1736 visitor->trace(m_styledInlineElement); 1746 visitor->trace(m_styledInlineElement);
1737 CompositeEditCommand::trace(visitor); 1747 CompositeEditCommand::trace(visitor);
1738 } 1748 }
1739 1749
1740 } // namespace blink 1750 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/LayoutTests/editing/execCommand/apply_style/justify_right_ul_br_crash.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698