From 1cbdecfa9fc428ac2d8aca0fa91c9580b3d57353 Mon Sep 17 00:00:00 2001 From: The Android Open Source Project Date: Wed, 17 Dec 2008 18:05:15 -0800 Subject: Code drop from //branches/cupcake/...@124589 --- WebCore/editing/IndentOutdentCommand.cpp | 37 +++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 12 deletions(-) (limited to 'WebCore/editing/IndentOutdentCommand.cpp') diff --git a/WebCore/editing/IndentOutdentCommand.cpp b/WebCore/editing/IndentOutdentCommand.cpp index 0d66467..385f1b7 100644 --- a/WebCore/editing/IndentOutdentCommand.cpp +++ b/WebCore/editing/IndentOutdentCommand.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. + * Copyright (C) 2006, 2008 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -106,8 +106,9 @@ Node* IndentOutdentCommand::prepareBlockquoteLevelForInsertion(VisiblePosition& void IndentOutdentCommand::indentRegion() { - VisiblePosition startOfSelection = endingSelection().visibleStart(); - VisiblePosition endOfSelection = endingSelection().visibleEnd(); + Selection selection = selectionForParagraphIteration(endingSelection()); + VisiblePosition startOfSelection = selection.visibleStart(); + VisiblePosition endOfSelection = selection.visibleEnd(); int startIndex = indexForVisiblePosition(startOfSelection); int endIndex = indexForVisiblePosition(endOfSelection); @@ -162,14 +163,25 @@ void IndentOutdentCommand::indentRegion() // this by splitting all parents of the current paragraph up to that point. RefPtr blockquote = createIndentBlockquoteElement(document()); Position start = startOfParagraph(endOfCurrentParagraph).deepEquivalent(); - - // FIXME: This will break table structure. - Node* startOfNewBlock = splitTreeToNode(start.node(), editableRootForPosition(start)); - insertNodeBefore(blockquote.get(), startOfNewBlock); + + Node* enclosingCell = enclosingNodeOfType(start, &isTableCell); + Node* nodeToSplitTo = enclosingCell ? enclosingCell : editableRootForPosition(start); + RefPtr startOfNewBlock = splitTreeToNode(start.node(), nodeToSplitTo); + insertNodeBefore(blockquote.get(), startOfNewBlock.get()); newBlockquote = blockquote.get(); insertionPoint = prepareBlockquoteLevelForInsertion(endOfCurrentParagraph, &newBlockquote); + // Don't put the next paragraph in the blockquote we just created for this paragraph unless + // the next paragraph is in the same cell. + if (enclosingCell && enclosingCell != enclosingNodeOfType(endOfNextParagraph.deepEquivalent(), &isTableCell)) + newBlockquote = 0; } moveParagraph(startOfParagraph(endOfCurrentParagraph), endOfCurrentParagraph, VisiblePosition(Position(insertionPoint, 0)), true); + // moveParagraph should not destroy content that contains endOfNextParagraph, but if it does, return here + // to avoid a crash. + if (endOfNextParagraph.isNotNull() && !endOfNextParagraph.deepEquivalent().node()->inDocument()) { + ASSERT_NOT_REACHED(); + return; + } endOfCurrentParagraph = endOfNextParagraph; } @@ -190,10 +202,11 @@ void IndentOutdentCommand::outdentParagraph() // Use InsertListCommand to remove the selection from the list if (enclosingNode->hasTagName(olTag)) { - applyCommandToComposite(new InsertListCommand(document(), InsertListCommand::OrderedList, "")); + applyCommandToComposite(InsertListCommand::create(document(), InsertListCommand::OrderedList, "")); return; - } else if (enclosingNode->hasTagName(ulTag)) { - applyCommandToComposite(new InsertListCommand(document(), InsertListCommand::UnorderedList, "")); + } + if (enclosingNode->hasTagName(ulTag)) { + applyCommandToComposite(InsertListCommand::create(document(), InsertListCommand::UnorderedList, "")); return; } @@ -215,11 +228,11 @@ void IndentOutdentCommand::outdentParagraph() return; } Node* enclosingBlockFlow = enclosingBlockFlowElement(visibleStartOfParagraph); - Node* splitBlockquoteNode = enclosingNode; + RefPtr splitBlockquoteNode = enclosingNode; if (enclosingBlockFlow != enclosingNode) splitBlockquoteNode = splitTreeToNode(enclosingBlockFlowElement(visibleStartOfParagraph), enclosingNode, true); RefPtr placeholder = createBreakElement(document()); - insertNodeBefore(placeholder.get(), splitBlockquoteNode); + insertNodeBefore(placeholder.get(), splitBlockquoteNode.get()); moveParagraph(startOfParagraph(visibleStartOfParagraph), endOfParagraph(visibleEndOfParagraph), VisiblePosition(Position(placeholder.get(), 0)), true); } -- cgit v1.1