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

Unified Diff: sky/engine/core/editing/CompositeEditCommand.cpp

Issue 665613003: Remove the ability to parse HTML fragments (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years, 2 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
« no previous file with comments | « sky/engine/core/dom/shadow/ShadowRoot.idl ('k') | sky/engine/core/editing/markup.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/engine/core/editing/CompositeEditCommand.cpp
diff --git a/sky/engine/core/editing/CompositeEditCommand.cpp b/sky/engine/core/editing/CompositeEditCommand.cpp
index f1e0fd8319ebf1d11ceae6c02b4150e6f89da5ec..e41deb8662e31fef7fd768f8fed34eee9d75ccfc 100644
--- a/sky/engine/core/editing/CompositeEditCommand.cpp
+++ b/sky/engine/core/editing/CompositeEditCommand.cpp
@@ -971,116 +971,6 @@ void CompositeEditCommand::moveParagraph(const VisiblePosition& startOfParagraph
void CompositeEditCommand::moveParagraphs(const VisiblePosition& startOfParagraphToMove, const VisiblePosition& endOfParagraphToMove, const VisiblePosition& destination, bool preserveSelection, bool preserveStyle, Node* constrainingAncestor)
eseidel 2014/10/24 22:48:21 I'm sure this horribly breaks editing.
{
esprehn 2014/10/24 22:52:06 Can you add a FIXME or something? Just deleting th
- if (startOfParagraphToMove == destination || startOfParagraphToMove.isNull())
- return;
-
- int startIndex = -1;
- int endIndex = -1;
- int destinationIndex = -1;
- bool originalIsDirectional = endingSelection().isDirectional();
- if (preserveSelection && !endingSelection().isNone()) {
- VisiblePosition visibleStart = endingSelection().visibleStart();
- VisiblePosition visibleEnd = endingSelection().visibleEnd();
-
- bool startAfterParagraph = comparePositions(visibleStart, endOfParagraphToMove) > 0;
- bool endBeforeParagraph = comparePositions(visibleEnd, startOfParagraphToMove) < 0;
-
- if (!startAfterParagraph && !endBeforeParagraph) {
- bool startInParagraph = comparePositions(visibleStart, startOfParagraphToMove) >= 0;
- bool endInParagraph = comparePositions(visibleEnd, endOfParagraphToMove) <= 0;
-
- startIndex = 0;
- if (startInParagraph) {
- RefPtrWillBeRawPtr<Range> startRange = Range::create(document(), startOfParagraphToMove.deepEquivalent().parentAnchoredEquivalent(), visibleStart.deepEquivalent().parentAnchoredEquivalent());
- startIndex = TextIterator::rangeLength(startRange.get(), true);
- }
-
- endIndex = 0;
- if (endInParagraph) {
- RefPtrWillBeRawPtr<Range> endRange = Range::create(document(), startOfParagraphToMove.deepEquivalent().parentAnchoredEquivalent(), visibleEnd.deepEquivalent().parentAnchoredEquivalent());
- endIndex = TextIterator::rangeLength(endRange.get(), true);
- }
- }
- }
-
- VisiblePosition beforeParagraph = startOfParagraphToMove.previous(CannotCrossEditingBoundary);
- VisiblePosition afterParagraph(endOfParagraphToMove.next(CannotCrossEditingBoundary));
-
- // We upstream() the end and downstream() the start so that we don't include collapsed whitespace in the move.
- // When we paste a fragment, spaces after the end and before the start are treated as though they were rendered.
- Position start = startOfParagraphToMove.deepEquivalent().downstream();
- Position end = endOfParagraphToMove.deepEquivalent().upstream();
-
- // start and end can't be used directly to create a Range; they are "editing positions"
- Position startRangeCompliant = start.parentAnchoredEquivalent();
- Position endRangeCompliant = end.parentAnchoredEquivalent();
- RefPtrWillBeRawPtr<Range> range = Range::create(document(), startRangeCompliant.deprecatedNode(), startRangeCompliant.deprecatedEditingOffset(), endRangeCompliant.deprecatedNode(), endRangeCompliant.deprecatedEditingOffset());
-
- // FIXME: This is an inefficient way to preserve style on nodes in the paragraph to move. It
- // shouldn't matter though, since moved paragraphs will usually be quite small.
- RefPtrWillBeRawPtr<DocumentFragment> fragment = startOfParagraphToMove != endOfParagraphToMove ?
- createFragmentFromMarkup(document(), createMarkup(range.get(), 0, DoNotAnnotateForInterchange, true, DoNotResolveURLs, constrainingAncestor)) : nullptr;
-
- // A non-empty paragraph's style is moved when we copy and move it. We don't move
- // anything if we're given an empty paragraph, but an empty paragraph can have style
- // too, <div><b><br></b></div> for example. Save it so that we can preserve it later.
- RefPtrWillBeRawPtr<EditingStyle> styleInEmptyParagraph = nullptr;
- if (startOfParagraphToMove == endOfParagraphToMove && preserveStyle) {
- styleInEmptyParagraph = EditingStyle::create(startOfParagraphToMove.deepEquivalent());
- styleInEmptyParagraph->mergeTypingStyle(&document());
- // The moved paragraph should assume the block style of the destination.
- styleInEmptyParagraph->removeBlockProperties();
- }
-
- // FIXME (5098931): We should add a new insert action "WebViewInsertActionMoved" and call shouldInsertFragment here.
-
- setEndingSelection(VisibleSelection(start, end, DOWNSTREAM));
- document().frame()->spellChecker().clearMisspellingsAndBadGrammar(endingSelection());
- deleteSelection(false, false, false);
-
- ASSERT(destination.deepEquivalent().inDocument());
- cleanupAfterDeletion(destination);
- ASSERT(destination.deepEquivalent().inDocument());
-
- // Add a br if pruning an empty block level element caused a collapse. For example:
- // foo^
- // <div>bar</div>
- // baz
- // Imagine moving 'bar' to ^. 'bar' will be deleted and its div pruned. That would
- // cause 'baz' to collapse onto the line with 'foobar' unless we insert a br.
- // Must recononicalize these two VisiblePositions after the pruning above.
- beforeParagraph = VisiblePosition(beforeParagraph.deepEquivalent());
- afterParagraph = VisiblePosition(afterParagraph.deepEquivalent());
- if (beforeParagraph.isNotNull() && (!isEndOfParagraph(beforeParagraph) || beforeParagraph == afterParagraph)) {
- // Need an updateLayout here in case inserting the br has split a text node.
- document().updateLayoutIgnorePendingStylesheets();
- }
-
- RefPtrWillBeRawPtr<Range> startToDestinationRange(Range::create(document(), firstPositionInNode(document().documentElement()), destination.deepEquivalent().parentAnchoredEquivalent()));
- destinationIndex = TextIterator::rangeLength(startToDestinationRange.get(), true);
-
- setEndingSelection(VisibleSelection(destination, originalIsDirectional));
- ASSERT(endingSelection().isCaretOrRange());
- ReplaceSelectionCommand::CommandOptions options = ReplaceSelectionCommand::SelectReplacement | ReplaceSelectionCommand::MovingParagraph;
- if (!preserveStyle)
- options |= ReplaceSelectionCommand::MatchStyle;
- applyCommandToComposite(ReplaceSelectionCommand::create(document(), fragment, options));
-
- document().frame()->spellChecker().markMisspellingsAndBadGrammar(endingSelection());
-
- if (preserveSelection && startIndex != -1) {
- if (Element* documentElement = document().documentElement()) {
- // Fragment creation (using createMarkup) incorrectly uses regular
- // spaces instead of nbsps for some spaces that were rendered (11475), which
- // causes spaces to be collapsed during the move operation. This results
- // in a call to rangeFromLocationAndLength with a location past the end
- // of the document (which will return null).
- RefPtrWillBeRawPtr<Range> start = PlainTextRange(destinationIndex + startIndex).createRangeForSelection(*documentElement);
- RefPtrWillBeRawPtr<Range> end = PlainTextRange(destinationIndex + endIndex).createRangeForSelection(*documentElement);
- if (start && end)
- setEndingSelection(VisibleSelection(start->startPosition(), end->startPosition(), DOWNSTREAM, originalIsDirectional));
- }
- }
}
// FIXME: Send an appropriate shouldDeleteRange call.
« no previous file with comments | « sky/engine/core/dom/shadow/ShadowRoot.idl ('k') | sky/engine/core/editing/markup.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698