summaryrefslogtreecommitdiffstats
path: root/WebCore/editing/IndentOutdentCommand.cpp
diff options
context:
space:
mode:
authorThe Android Open Source Project <initial-contribution@android.com>2008-12-17 18:05:15 -0800
committerThe Android Open Source Project <initial-contribution@android.com>2008-12-17 18:05:15 -0800
commit1cbdecfa9fc428ac2d8aca0fa91c9580b3d57353 (patch)
tree4457a7306ea5acb43fe05bfe0973b1f7faf97ba2 /WebCore/editing/IndentOutdentCommand.cpp
parent9364f22aed35e1a1e9d07c121510f80be3ab0502 (diff)
downloadexternal_webkit-1cbdecfa9fc428ac2d8aca0fa91c9580b3d57353.zip
external_webkit-1cbdecfa9fc428ac2d8aca0fa91c9580b3d57353.tar.gz
external_webkit-1cbdecfa9fc428ac2d8aca0fa91c9580b3d57353.tar.bz2
Code drop from //branches/cupcake/...@124589
Diffstat (limited to 'WebCore/editing/IndentOutdentCommand.cpp')
-rw-r--r--WebCore/editing/IndentOutdentCommand.cpp37
1 files changed, 25 insertions, 12 deletions
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<Node> 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<Node> 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<Node> splitBlockquoteNode = enclosingNode;
if (enclosingBlockFlow != enclosingNode)
splitBlockquoteNode = splitTreeToNode(enclosingBlockFlowElement(visibleStartOfParagraph), enclosingNode, true);
RefPtr<Node> placeholder = createBreakElement(document());
- insertNodeBefore(placeholder.get(), splitBlockquoteNode);
+ insertNodeBefore(placeholder.get(), splitBlockquoteNode.get());
moveParagraph(startOfParagraph(visibleStartOfParagraph), endOfParagraph(visibleEndOfParagraph), VisiblePosition(Position(placeholder.get(), 0)), true);
}