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

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

Issue 177093016: Fix crash in ApplyStyleCommand::applyRelativeFontStyleChange() (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 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 | Annotate | Revision Log
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 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 342
343 if (isValidCaretPositionInTextNode(end)) { 343 if (isValidCaretPositionInTextNode(end)) {
344 splitTextAtEnd(start, end); 344 splitTextAtEnd(start, end);
345 start = startPosition(); 345 start = startPosition();
346 end = endPosition(); 346 end = endPosition();
347 } 347 }
348 348
349 // Calculate loop end point. 349 // Calculate loop end point.
350 // If the end node is before the start node (can only happen if the end node is 350 // If the end node is before the start node (can only happen if the end node is
351 // an ancestor of the start node), we gather nodes up to the next sibling of the end node 351 // an ancestor of the start node), we gather nodes up to the next sibling of the end node
352 Node *beyondEnd; 352 Node* beyondEnd;
353 ASSERT(start.deprecatedNode());
354 ASSERT(end.deprecatedNode());
353 if (start.deprecatedNode()->isDescendantOf(end.deprecatedNode())) 355 if (start.deprecatedNode()->isDescendantOf(end.deprecatedNode()))
354 beyondEnd = NodeTraversal::nextSkippingChildren(*end.deprecatedNode()); 356 beyondEnd = NodeTraversal::nextSkippingChildren(*end.deprecatedNode());
355 else 357 else
356 beyondEnd = NodeTraversal::next(*end.deprecatedNode()); 358 beyondEnd = NodeTraversal::next(*end.deprecatedNode());
357 359
358 start = start.upstream(); // Move upstream to ensure we do not add redundant spans. 360 start = start.upstream(); // Move upstream to ensure we do not add redundant spans.
359 Node* startNode = start.deprecatedNode(); 361 Node* startNode = start.deprecatedNode();
360 ASSERT(startNode); 362 ASSERT(startNode);
363
364 // Make sure we're not already at the end or the next NodeTraversal::next() will traverse
365 // past it.
366 if (startNode == beyondEnd)
367 return;
368
361 if (startNode->isTextNode() && start.deprecatedEditingOffset() >= caretMaxOf fset(startNode)) // Move out of text node if range does not include its characte rs. 369 if (startNode->isTextNode() && start.deprecatedEditingOffset() >= caretMaxOf fset(startNode)) // Move out of text node if range does not include its characte rs.
362 startNode = NodeTraversal::next(*startNode); 370 startNode = NodeTraversal::next(*startNode);
Inactive 2014/02/25 15:00:42 This traverses past beyondEnd if startNode == beyo
363 371
364 // Store away font size before making any changes to the document. 372 // Store away font size before making any changes to the document.
365 // This ensures that changes to one node won't effect another. 373 // This ensures that changes to one node won't effect another.
366 HashMap<Node*, float> startingFontSizes; 374 HashMap<Node*, float> startingFontSizes;
367 for (Node* node = startNode; node != beyondEnd; node = NodeTraversal::next(* node)) 375 for (Node* node = startNode; node != beyondEnd; node = NodeTraversal::next(* node)) {
376 ASSERT(node);
368 startingFontSizes.set(node, computedFontSize(node)); 377 startingFontSizes.set(node, computedFontSize(node));
378 }
369 379
370 // These spans were added by us. If empty after font size changes, they can be removed. 380 // These spans were added by us. If empty after font size changes, they can be removed.
371 Vector<RefPtr<HTMLElement> > unstyledSpans; 381 Vector<RefPtr<HTMLElement> > unstyledSpans;
372 382
373 Node* lastStyledNode = 0; 383 Node* lastStyledNode = 0;
374 for (Node* node = startNode; node != beyondEnd; node = NodeTraversal::next(* node)) { 384 for (Node* node = startNode; node != beyondEnd; node = NodeTraversal::next(* node)) {
385 ASSERT(node);
375 RefPtr<HTMLElement> element; 386 RefPtr<HTMLElement> element;
376 if (node->isHTMLElement()) { 387 if (node->isHTMLElement()) {
377 // Only work on fully selected nodes. 388 // Only work on fully selected nodes.
378 if (!nodeFullySelected(node, start, end)) 389 if (!nodeFullySelected(node, start, end))
379 continue; 390 continue;
380 element = toHTMLElement(node); 391 element = toHTMLElement(node);
381 } else if (node->isTextNode() && node->renderer() && node->parentNode() != lastStyledNode) { 392 } else if (node->isTextNode() && node->renderer() && node->parentNode() != lastStyledNode) {
382 // Last styled node was not parent node of this text node, but we wi sh to style this 393 // Last styled node was not parent node of this text node, but we wi sh to style this
383 // text node. To make this possible, add a style span to surround th is text node. 394 // text node. To make this possible, add a style span to surround th is text node.
384 RefPtr<HTMLElement> span = createStyleSpanElement(document()); 395 RefPtr<HTMLElement> span = createStyleSpanElement(document());
(...skipping 1143 matching lines...) Expand 10 before | Expand all | Expand 10 after
1528 String textToMove = nextText->data(); 1539 String textToMove = nextText->data();
1529 insertTextIntoNode(childText, childText->length(), textToMove); 1540 insertTextIntoNode(childText, childText->length(), textToMove);
1530 removeNode(next); 1541 removeNode(next);
1531 // don't move child node pointer. it may want to merge with more text no des. 1542 // don't move child node pointer. it may want to merge with more text no des.
1532 } 1543 }
1533 1544
1534 updateStartEnd(newStart, newEnd); 1545 updateStartEnd(newStart, newEnd);
1535 } 1546 }
1536 1547
1537 } 1548 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698