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: Source/WebCore/editing/ApplyStyleCommand.cpp

Issue 10414053: Merge 116669 (Closed) Base URL: http://svn.webkit.org/repository/webkit/branches/chromium/1084/
Patch Set: Created 8 years, 7 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 | « LayoutTests/editing/style/apply-style-join-child-text-nodes-crash-expected.txt ('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 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 start = end; 313 start = end;
314 end = swap; 314 end = swap;
315 } 315 }
316 316
317 // Join up any adjacent text nodes. 317 // Join up any adjacent text nodes.
318 if (start.deprecatedNode()->isTextNode()) { 318 if (start.deprecatedNode()->isTextNode()) {
319 joinChildTextNodes(start.deprecatedNode()->parentNode(), start, end); 319 joinChildTextNodes(start.deprecatedNode()->parentNode(), start, end);
320 start = startPosition(); 320 start = startPosition();
321 end = endPosition(); 321 end = endPosition();
322 } 322 }
323
324 if (start.isNull() || end.isNull())
325 return;
326
323 if (end.deprecatedNode()->isTextNode() && start.deprecatedNode()->parentNode () != end.deprecatedNode()->parentNode()) { 327 if (end.deprecatedNode()->isTextNode() && start.deprecatedNode()->parentNode () != end.deprecatedNode()->parentNode()) {
324 joinChildTextNodes(end.deprecatedNode()->parentNode(), start, end); 328 joinChildTextNodes(end.deprecatedNode()->parentNode(), start, end);
325 start = startPosition(); 329 start = startPosition();
326 end = endPosition(); 330 end = endPosition();
327 } 331 }
328 332
333 if (start.isNull() || end.isNull())
334 return;
335
329 // Split the start text nodes if needed to apply style. 336 // Split the start text nodes if needed to apply style.
330 if (isValidCaretPositionInTextNode(start)) { 337 if (isValidCaretPositionInTextNode(start)) {
331 splitTextAtStart(start, end); 338 splitTextAtStart(start, end);
332 start = startPosition(); 339 start = startPosition();
333 end = endPosition(); 340 end = endPosition();
334 } 341 }
335 342
336 if (isValidCaretPositionInTextNode(end)) { 343 if (isValidCaretPositionInTextNode(end)) {
337 splitTextAtEnd(start, end); 344 splitTextAtEnd(start, end);
338 start = startPosition(); 345 start = startPosition();
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 Node* endDummySpanAncestor = 0; 542 Node* endDummySpanAncestor = 0;
536 543
537 // update document layout once before removing styles 544 // update document layout once before removing styles
538 // so that we avoid the expense of updating before each and every call 545 // so that we avoid the expense of updating before each and every call
539 // to check a computed style 546 // to check a computed style
540 document()->updateLayoutIgnorePendingStylesheets(); 547 document()->updateLayoutIgnorePendingStylesheets();
541 548
542 // adjust to the positions we want to use for applying style 549 // adjust to the positions we want to use for applying style
543 Position start = startPosition(); 550 Position start = startPosition();
544 Position end = endPosition(); 551 Position end = endPosition();
552
553 if (start.isNull() || end.isNull())
554 return;
555
545 if (comparePositions(end, start) < 0) { 556 if (comparePositions(end, start) < 0) {
546 Position swap = start; 557 Position swap = start;
547 start = end; 558 start = end;
548 end = swap; 559 end = swap;
549 } 560 }
550 561
551 // split the start node and containing element if the selection starts insid e of it 562 // split the start node and containing element if the selection starts insid e of it
552 bool splitStart = isValidCaretPositionInTextNode(start); 563 bool splitStart = isValidCaretPositionInTextNode(start);
553 if (splitStart) { 564 if (splitStart) {
554 if (shouldSplitTextElement(start.deprecatedNode()->parentElement(), styl e)) 565 if (shouldSplitTextElement(start.deprecatedNode()->parentElement(), styl e))
(...skipping 866 matching lines...) Expand 10 before | Expand all | Expand 10 after
1421 } 1432 }
1422 1433
1423 void ApplyStyleCommand::joinChildTextNodes(Node* node, const Position& start, co nst Position& end) 1434 void ApplyStyleCommand::joinChildTextNodes(Node* node, const Position& start, co nst Position& end)
1424 { 1435 {
1425 if (!node) 1436 if (!node)
1426 return; 1437 return;
1427 1438
1428 Position newStart = start; 1439 Position newStart = start;
1429 Position newEnd = end; 1440 Position newEnd = end;
1430 1441
1431 Node* child = node->firstChild(); 1442 Vector<RefPtr<Text> > textNodes;
1432 while (child) { 1443 for (Node* curr = node->firstChild(); curr; curr = curr->nextSibling()) {
1433 Node* next = child->nextSibling(); 1444 if (!curr->isTextNode())
1434 if (child->isTextNode() && next && next->isTextNode()) { 1445 continue;
1435 Text* childText = toText(child); 1446
1436 Text* nextText = toText(next); 1447 textNodes.append(toText(curr));
1437 if (start.anchorType() == Position::PositionIsOffsetInAnchor && next == start.containerNode()) 1448 }
1438 newStart = Position(childText, childText->length() + start.offse tInContainerNode()); 1449
1439 if (end.anchorType() == Position::PositionIsOffsetInAnchor && next = = end.containerNode()) 1450 for (size_t i = 0; i < textNodes.size(); ++i) {
1440 newEnd = Position(childText, childText->length() + end.offsetInC ontainerNode()); 1451 Text* childText = textNodes[i].get();
1441 String textToMove = nextText->data(); 1452 Node* next = childText->nextSibling();
1442 insertTextIntoNode(childText, childText->length(), textToMove); 1453 if (!next || !next->isTextNode())
1443 removeNode(next); 1454 continue;
1444 // don't move child node pointer. it may want to merge with more tex t nodes. 1455
1445 } 1456 Text* nextText = toText(next);
1446 else { 1457 if (start.anchorType() == Position::PositionIsOffsetInAnchor && next == start.containerNode())
1447 child = child->nextSibling(); 1458 newStart = Position(childText, childText->length() + start.offsetInC ontainerNode());
1448 } 1459 if (end.anchorType() == Position::PositionIsOffsetInAnchor && next == en d.containerNode())
1460 newEnd = Position(childText, childText->length() + end.offsetInConta inerNode());
1461 String textToMove = nextText->data();
1462 insertTextIntoNode(childText, childText->length(), textToMove);
1463 removeNode(next);
1464 // don't move child node pointer. it may want to merge with more text no des.
1449 } 1465 }
1450 1466
1451 updateStartEnd(newStart, newEnd); 1467 updateStartEnd(newStart, newEnd);
1452 } 1468 }
1453 1469
1454 } 1470 }
OLDNEW
« no previous file with comments | « LayoutTests/editing/style/apply-style-join-child-text-nodes-crash-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698