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

Side by Side Diff: third_party/WebKit/Source/core/editing/commands/CompositeEditCommand.cpp

Issue 2196553003: Refactoring: Introduce nextSiblingIsTextNode and shouldEmitNBSPbeforeEnd variables (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: updated Created 4 years, 4 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/Source/core/editing/EditingUtilities.cpp ('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, 2007, 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2005, 2006, 2007, 2008 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 711 matching lines...) Expand 10 before | Expand all | Expand 10 after
722 downstream++; 722 downstream++;
723 723
724 int length = downstream - upstream; 724 int length = downstream - upstream;
725 if (!length) 725 if (!length)
726 return; 726 return;
727 727
728 VisiblePosition visibleUpstreamPos = createVisiblePosition(Position(textNode , upstream)); 728 VisiblePosition visibleUpstreamPos = createVisiblePosition(Position(textNode , upstream));
729 VisiblePosition visibleDownstreamPos = createVisiblePosition(Position(textNo de, downstream)); 729 VisiblePosition visibleDownstreamPos = createVisiblePosition(Position(textNo de, downstream));
730 730
731 String string = text.substring(upstream, length); 731 String string = text.substring(upstream, length);
732 String rebalancedString = stringWithRebalancedWhitespace(string,
733 // FIXME: Because of the problem mentioned at the top of this function, we 732 // FIXME: Because of the problem mentioned at the top of this function, we
734 // must also use nbsps at the start/end of the string because this function 733 // must also use nbsps at the start/end of the string because this function
735 // doesn't get all surrounding whitespace, just the whitespace in the 734 // doesn't get all surrounding whitespace, just the whitespace in the
736 // current text node. 735 // current text node. However, if the next sibling node is a text node
737 isStartOfParagraph(visibleUpstreamPos) || upstream == 0, 736 // (not empty, see http://crbug.com/632300), we should use a plain space.
738 (isEndOfParagraph(visibleDownstreamPos) || (unsigned)downstream == text. length()) 737 // See http://crbug.com/310149
739 && !(textNode->nextSibling() && textNode->nextSibling()->isTextNode() && toText(textNode->nextSibling())->data().length() != 0)); 738 bool nextSiblingIsTextNode = textNode->nextSibling() && textNode->nextSiblin g()->isTextNode()
yosin_UTC9 2016/08/01 01:39:13 nit: better to have |const|
739 && toText(textNode->nextSibling())->data().length();
740 bool shouldEmitNBSPbeforeEnd =(isEndOfParagraph(visibleDownstreamPos) || (un signed)downstream == text.length()) && !nextSiblingIsTextNode;
yosin_UTC9 2016/08/01 01:39:13 nit: better to have |const|
741 String rebalancedString = stringWithRebalancedWhitespace(string,
742 isStartOfParagraph(visibleUpstreamPos) || !upstream, shouldEmitNBSPbefor eEnd);
740 743
741 if (string != rebalancedString) 744 if (string != rebalancedString)
742 replaceTextInNodePreservingMarkers(textNode, upstream, length, rebalance dString); 745 replaceTextInNodePreservingMarkers(textNode, upstream, length, rebalance dString);
743 } 746 }
744 747
745 void CompositeEditCommand::prepareWhitespaceAtPositionForSplit(Position& positio n) 748 void CompositeEditCommand::prepareWhitespaceAtPositionForSplit(Position& positio n)
746 { 749 {
747 if (!isRichlyEditablePosition(position)) 750 if (!isRichlyEditablePosition(position))
748 return; 751 return;
749 Node* node = position.anchorNode(); 752 Node* node = position.anchorNode();
(...skipping 894 matching lines...) Expand 10 before | Expand all | Expand 10 after
1644 } 1647 }
1645 1648
1646 DEFINE_TRACE(CompositeEditCommand) 1649 DEFINE_TRACE(CompositeEditCommand)
1647 { 1650 {
1648 visitor->trace(m_commands); 1651 visitor->trace(m_commands);
1649 visitor->trace(m_composition); 1652 visitor->trace(m_composition);
1650 EditCommand::trace(visitor); 1653 EditCommand::trace(visitor);
1651 } 1654 }
1652 1655
1653 } // namespace blink 1656 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/editing/EditingUtilities.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698