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

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

Issue 2175163004: Add a plain space instead of   between text nodes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix a test fail in Win 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved. 2 * Copyright (C) 2004, 2005, 2006, 2007 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 941 matching lines...) Expand 10 before | Expand all | Expand 10 after
952 for (const LayoutObject* r = node.layoutObject(); r; r = r->parent()) { 952 for (const LayoutObject* r = node.layoutObject(); r; r = r->parent()) {
953 if (r->isLayoutBlockFlow()) { 953 if (r->isLayoutBlockFlow()) {
954 primaryDirection = r->style()->direction(); 954 primaryDirection = r->style()->direction();
955 break; 955 break;
956 } 956 }
957 } 957 }
958 958
959 return primaryDirection; 959 return primaryDirection;
960 } 960 }
961 961
962 String stringWithRebalancedWhitespace(const String& string, bool startIsStartOfP aragraph, bool endIsEndOfParagraph) 962 String stringWithRebalancedWhitespace(const String& string, bool startIsStartOfP aragraph, bool shouldEmitNBSPbeforeEnd)
963 { 963 {
964 unsigned length = string.length(); 964 unsigned length = string.length();
965 965
966 StringBuilder rebalancedString; 966 StringBuilder rebalancedString;
967 rebalancedString.reserveCapacity(length); 967 rebalancedString.reserveCapacity(length);
968 968
969 bool previousCharacterWasSpace = false; 969 bool previousCharacterWasSpace = false;
970 for (size_t i = 0; i < length; i++) { 970 for (size_t i = 0; i < length; i++) {
971 UChar c = string[i]; 971 UChar c = string[i];
972 if (!isWhitespace(c)) { 972 if (!isWhitespace(c)) {
973 rebalancedString.append(c); 973 rebalancedString.append(c);
974 previousCharacterWasSpace = false; 974 previousCharacterWasSpace = false;
975 continue; 975 continue;
976 } 976 }
977 977
978 if (previousCharacterWasSpace || (!i && startIsStartOfParagraph) || (i + 1 == length && endIsEndOfParagraph)) { 978 // We need to ensure there is no next sibling text node. See http://crbu g.com/310149
979 if (previousCharacterWasSpace || (!i && startIsStartOfParagraph) || (i + 1 == length && shouldEmitNBSPbeforeEnd)) {
979 rebalancedString.append(noBreakSpaceCharacter); 980 rebalancedString.append(noBreakSpaceCharacter);
980 previousCharacterWasSpace = false; 981 previousCharacterWasSpace = false;
981 } else { 982 } else {
982 rebalancedString.append(' '); 983 rebalancedString.append(' ');
983 previousCharacterWasSpace = true; 984 previousCharacterWasSpace = true;
984 } 985 }
985 } 986 }
986 987
987 DCHECK_EQ(rebalancedString.length(), length); 988 DCHECK_EQ(rebalancedString.length(), length);
988 989
(...skipping 935 matching lines...) Expand 10 before | Expand all | Expand 10 after
1924 { 1925 {
1925 if (!RuntimeEnabledFeatures::inputEventEnabled()) 1926 if (!RuntimeEnabledFeatures::inputEventEnabled())
1926 return DispatchEventResult::NotCanceled; 1927 return DispatchEventResult::NotCanceled;
1927 if (!target) 1928 if (!target)
1928 return DispatchEventResult::NotCanceled; 1929 return DispatchEventResult::NotCanceled;
1929 InputEvent* beforeInputEvent = InputEvent::createBeforeInput(inputType, data , InputEvent::EventCancelable::IsCancelable, InputEvent::EventIsComposing::NotCo mposing, ranges); 1930 InputEvent* beforeInputEvent = InputEvent::createBeforeInput(inputType, data , InputEvent::EventCancelable::IsCancelable, InputEvent::EventIsComposing::NotCo mposing, ranges);
1930 return target->dispatchEvent(beforeInputEvent); 1931 return target->dispatchEvent(beforeInputEvent);
1931 } 1932 }
1932 1933
1933 } // namespace blink 1934 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698