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

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

Issue 2692093003: Rewrite DocumentMarkerController to use SynchronousMutationObserver (Closed)
Patch Set: Don't try to use -1 as default value for unsigned int Created 3 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/editing/commands/CompositeEditCommand.cpp
diff --git a/third_party/WebKit/Source/core/editing/commands/CompositeEditCommand.cpp b/third_party/WebKit/Source/core/editing/commands/CompositeEditCommand.cpp
index c9d245114588a09065e5d4913f9fb2fff3045f9a..35c1d0f53f53a914372cf3707b353a7981dfe981 100644
--- a/third_party/WebKit/Source/core/editing/commands/CompositeEditCommand.cpp
+++ b/third_party/WebKit/Source/core/editing/commands/CompositeEditCommand.cpp
@@ -530,6 +530,11 @@ void CompositeEditCommand::replaceTextInNode(Text* node,
unsigned offset,
unsigned count,
const String& replacementText) {
+ // Notify listeners that a replacement has occurred rather than two separate
+ // insert + delete operations
+ SynchronousMutationNotifier::ScopedNotificationSuppressor suppressor(
+ &document());
+
// DeleteFromTextNodeCommand and InsertIntoTextNodeCommand are never
// aborted.
applyCommandToComposite(
@@ -557,50 +562,6 @@ Position CompositeEditCommand::replaceSelectedTextInNode(const String& text) {
return Position(textNode, start.offsetInContainerNode() + text.length());
}
-static void copyMarkerTypesAndDescriptions(
- const DocumentMarkerVector& markerPointers,
- Vector<DocumentMarker::MarkerType>& types,
- Vector<String>& descriptions) {
- size_t arraySize = markerPointers.size();
- types.reserveCapacity(arraySize);
- descriptions.reserveCapacity(arraySize);
- for (const auto& markerPointer : markerPointers) {
- types.push_back(markerPointer->type());
- descriptions.push_back(markerPointer->description());
- }
-}
-
-void CompositeEditCommand::replaceTextInNodePreservingMarkers(
- Text* node,
- unsigned offset,
- unsigned count,
- const String& replacementText) {
- DocumentMarkerController& markerController = document().markers();
- Vector<DocumentMarker::MarkerType> types;
- Vector<String> descriptions;
- copyMarkerTypesAndDescriptions(
- markerController.markersInRange(
- EphemeralRange(Position(node, offset),
- Position(node, offset + count)),
- DocumentMarker::AllMarkers()),
- types, descriptions);
-
- replaceTextInNode(node, offset, count, replacementText);
-
- // Re-adding markers requires a clean tree.
- document().updateStyleAndLayout();
-
- DocumentLifecycle::DisallowTransitionScope disallowTransition(
- document().lifecycle());
- Position startPosition(node, offset);
- Position endPosition(node, offset + replacementText.length());
- DCHECK_EQ(types.size(), descriptions.size());
-
- for (size_t i = 0; i < types.size(); ++i)
- markerController.addMarker(startPosition, endPosition, types[i],
- descriptions[i]);
-}
-
Position CompositeEditCommand::positionOutsideTabSpan(const Position& pos) {
if (!isTabHTMLSpanElementTextNode(pos.anchorNode()))
return pos;
@@ -773,8 +734,7 @@ void CompositeEditCommand::rebalanceWhitespaceOnTextSubstring(Text* textNode,
shouldEmitNBSPbeforeEnd);
if (string != rebalancedString)
- replaceTextInNodePreservingMarkers(textNode, upstream, length,
- rebalancedString);
+ replaceTextInNode(textNode, upstream, length, rebalancedString);
yosin_UTC9 2017/02/15 02:23:25 Let's make |replaceTextInNode()| to use |Character
}
void CompositeEditCommand::prepareWhitespaceAtPositionForSplit(
@@ -815,9 +775,8 @@ void CompositeEditCommand::
Position pos = mostForwardCaretPosition(visiblePosition.deepEquivalent());
if (!pos.computeContainerNode() || !pos.computeContainerNode()->isTextNode())
return;
- replaceTextInNodePreservingMarkers(toText(pos.computeContainerNode()),
- pos.offsetInContainerNode(), 1,
- nonBreakingSpaceString());
+ replaceTextInNode(toText(pos.computeContainerNode()),
+ pos.offsetInContainerNode(), 1, nonBreakingSpaceString());
}
void CompositeEditCommand::rebalanceWhitespace() {

Powered by Google App Engine
This is Rietveld 408576698