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

Side by Side Diff: third_party/WebKit/Source/core/editing/iterators/TextIterator.cpp

Issue 2336043006: Restore only the collapsed leading space when copy text (Closed)
Patch Set: [For landing] Fix crash on Android Created 4 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
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/editing/iterators/TextIteratorTest.cpp » ('j') | 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) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012 Apple Inc. All r ights reserved. 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012 Apple Inc. All r ights reserved.
3 * Copyright (C) 2005 Alexey Proskuryakov. 3 * Copyright (C) 2005 Alexey Proskuryakov.
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 597 matching lines...) Expand 10 before | Expand all | Expand 10 after
608 spliceBuffer(spaceCharacter, m_node, 0, runStart, runSta rt + 1); 608 spliceBuffer(spaceCharacter, m_node, 0, runStart, runSta rt + 1);
609 m_offset = runStart + 1; 609 m_offset = runStart + 1;
610 } else { 610 } else {
611 size_t subrunEnd = str.find('\n', runStart); 611 size_t subrunEnd = str.find('\n', runStart);
612 if (subrunEnd == kNotFound || subrunEnd > runEnd) { 612 if (subrunEnd == kNotFound || subrunEnd > runEnd) {
613 subrunEnd = runEnd; 613 subrunEnd = runEnd;
614 // Restore the collapsed space for copy & paste. 614 // Restore the collapsed space for copy & paste.
615 // See http://crbug.com/318925 615 // See http://crbug.com/318925
616 // For trailing space. 616 // For trailing space.
617 if (!nextTextBox && m_textBox->root().nextRootBox() && m _textBox->root().lastChild() == m_textBox) { 617 if (!nextTextBox && m_textBox->root().nextRootBox() && m _textBox->root().lastChild() == m_textBox) {
618 if (str.endsWith(' ') && subrunEnd == str.length() - 1 && str[subrunEnd - 1] != ' ') 618 if (str.endsWith(' ') && subrunEnd == str.length() - 1 && str[subrunEnd - 1] != ' ') {
619 ++subrunEnd; 619 // If there is the leading space in the next lin e, we don't need to restore the trailing space.
620 // Example: <div style="width: 2em;"><b><i>foo < /i></b> bar</div>
621 InlineBox* firstBoxOfNextLine = m_textBox->root( ).nextRootBox()->firstChild();
622 Node* firstNodeOfNextLine = nullptr;
623 if (firstBoxOfNextLine)
joone 2016/09/16 05:04:13 |firstBoxOfNextLine| can be null on Android.
624 firstNodeOfNextLine = firstBoxOfNextLine->ge tLineLayoutItem().node();
625 if (!firstNodeOfNextLine || firstNodeOfNextLine- >nodeValue()[0] != ' ')
626 ++subrunEnd;
627 }
620 } 628 }
621 // For leading space. 629 // For leading space.
622 if (!emitsImageAltText() && !doesNotBreakAtReplacedEleme nt() && !forInnerText() 630 if (!emitsImageAltText() && !doesNotBreakAtReplacedEleme nt() && !forInnerText()
623 && m_textBox->root().prevRootBox() && m_textBox->roo t().firstChild() == m_textBox) { 631 && m_textBox->root().prevRootBox() && m_textBox->roo t().firstChild() == m_textBox) {
624 InlineBox* lastChildOfPrevRoot = m_textBox->root().p revRootBox()->lastChild(); 632 InlineBox* lastChildOfPrevRoot = m_textBox->root().p revRootBox()->lastChild();
625 if (m_textBox->getLineLayoutItem() != lastChildOfPre vRoot->getLineLayoutItem() && !lastChildOfPrevRoot->getLineLayoutItem().isBR() 633 if (m_textBox->getLineLayoutItem() != lastChildOfPre vRoot->getLineLayoutItem() && !lastChildOfPrevRoot->getLineLayoutItem().isBR()
626 && !lastChildOfPrevRoot->isInlineFlowBox()) { 634 && !lastChildOfPrevRoot->isInlineFlowBox()) {
627 if (runStart > 0 && str[0] == ' ' && str[1] != ' ') 635 if (runStart > 0 && str[0] == ' ' && str[1] != ' ')
628 --runStart; 636 --runStart;
629 } 637 }
(...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after
1217 1225
1218 String plainText(const EphemeralRangeInFlatTree& range, TextIteratorBehaviorFlag s behavior) 1226 String plainText(const EphemeralRangeInFlatTree& range, TextIteratorBehaviorFlag s behavior)
1219 { 1227 {
1220 return createPlainText<EditingInFlatTreeStrategy>(range, behavior); 1228 return createPlainText<EditingInFlatTreeStrategy>(range, behavior);
1221 } 1229 }
1222 1230
1223 template class CORE_TEMPLATE_EXPORT TextIteratorAlgorithm<EditingStrategy>; 1231 template class CORE_TEMPLATE_EXPORT TextIteratorAlgorithm<EditingStrategy>;
1224 template class CORE_TEMPLATE_EXPORT TextIteratorAlgorithm<EditingInFlatTreeStrat egy>; 1232 template class CORE_TEMPLATE_EXPORT TextIteratorAlgorithm<EditingInFlatTreeStrat egy>;
1225 1233
1226 } // namespace blink 1234 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/editing/iterators/TextIteratorTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698