summaryrefslogtreecommitdiffstats
path: root/src/3rdparty/webkit/WebCore/editing/IndentOutdentCommand.cpp
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@nokia.com>2009-06-29 11:58:03 (GMT)
committerSimon Hausmann <simon.hausmann@nokia.com>2009-06-29 11:58:03 (GMT)
commit107b7d767d99104aac9d236b3dc872663a236cd4 (patch)
treed7a0d11234e71ab013e40c83bed84b994f69936c /src/3rdparty/webkit/WebCore/editing/IndentOutdentCommand.cpp
parent1df2292eaa543f7f25e37b7f14d63f6e70394c56 (diff)
downloadQt-107b7d767d99104aac9d236b3dc872663a236cd4.zip
Qt-107b7d767d99104aac9d236b3dc872663a236cd4.tar.gz
Qt-107b7d767d99104aac9d236b3dc872663a236cd4.tar.bz2
Updated WebKit from /home/shausman/src/webkit/trunk to qtwebkit-4.6-snapshot-29062009 ( 22aadba1b4356ad7d8e9446b95baccb6b2c037b0 )
Changes in WebKit/qt since the last update: 2009-06-29 Simon Hausmann <simon.hausmann@nokia.com> Fix the Qt build, add missing isSpeaking() implementation to ContextMenuClient. * WebCoreSupport/ContextMenuClientQt.cpp: (WebCore::ContextMenuClientQt::isSpeaking): * WebCoreSupport/ContextMenuClientQt.h: 2009-06-28 Sriram Yadavalli <sriram.yadavalli@nokia.com> Reviewed by Eric Seidel. [Qt] Fix build break for Qt https://bugs.webkit.org/show_bug.cgi?id=26779 * Api/qwebpage.cpp: (QWebPage::swallowContextMenuEvent): 2009-06-27 Simon Hausmann <simon.hausmann@nokia.com> Build fix for Qt under Windows. * Api/qwebhistory.h: Use consistent export linkage for the datastream operators. 2009-06-26 Brian Weinstein <bweinstein@apple.com> Reviewed by Simon Fraser. Changed call of scrollbarUnderMouse to scrollbarUnderPoint to match new API. * Api/qwebpage.cpp: (QWebPage::swallowContextMenuEvent): 2009-06-26 Jedrzej Nowacki <jedrzej.nowacki@nokia.com> Reviewed by Simon Hausmann. Add support for saving and loading of QWebHistory to and from a QByteArray. This includes streaming operators for QWebHistory. for convenience. New autotests that test QWebHistory and QWebHistoryItem serialization. * Api/qwebhistory.cpp: (QWebHistory::restoreState): (QWebHistory::saveState): (operator<<): (operator>>): * Api/qwebhistory.h: * Api/qwebhistory_p.h: * tests/qwebhistory/tst_qwebhistory.cpp: (tst_QWebHistory::): (tst_QWebHistory::init): (tst_QWebHistory::title): (tst_QWebHistory::count): (tst_QWebHistory::back): (tst_QWebHistory::forward): (tst_QWebHistory::itemAt): (tst_QWebHistory::goToItem): (tst_QWebHistory::items): (tst_QWebHistory::serialize_1): (tst_QWebHistory::serialize_2): (tst_QWebHistory::serialize_3): (tst_QWebHistory::saveAndRestore_1): (tst_QWebHistory::saveAndRestore_2): (tst_QWebHistory::saveAndRestore_3): 2009-06-26 Jedrzej Nowacki <jedrzej.nowacki@nokia.com> Reviewed by Simon Hausmann. Fix the behaviour of QWebHistory::itemAt to interpret the specified index as absolute index. Returns an invalid QWebHistoryItem if the index is out of range. * Api/qwebhistory.cpp: (QWebHistory::itemAt): * tests/qwebhistory/tst_qwebhistory.cpp: (tst_QWebHistory::itemAt): 2009-06-26 Jedrzej Nowacki <jedrzej.nowacki@nokia.com> Reviewed by Simon Hausmann. Added a few autotest to QWebHistory. * tests/qwebhistory/data/page1.html: Added. * tests/qwebhistory/data/page2.html: Added. * tests/qwebhistory/data/page3.html: Added. * tests/qwebhistory/data/page4.html: Added. * tests/qwebhistory/data/page5.html: Added. * tests/qwebhistory/data/page6.html: Added. * tests/qwebhistory/qwebhistory.pro: Added. * tests/qwebhistory/tst_qwebhistory.cpp: Added. (tst_QWebHistory::): (tst_QWebHistory::tst_QWebHistory): (tst_QWebHistory::~tst_QWebHistory): (tst_QWebHistory::init): (tst_QWebHistory::cleanup): (tst_QWebHistory::title): (tst_QWebHistory::count): (tst_QWebHistory::back): (tst_QWebHistory::forward): (tst_QWebHistory::goToItem): (tst_QWebHistory::items): * tests/qwebhistory/tst_qwebhistory.qrc: Added. * tests/tests.pro: 2009-06-26 Jedrzej Nowacki <jedrzej.nowacki@nokia.com> Reviewed by Simon Hausmann. Fix support for documenting functions prefixed with QWEBKIT_EXPORT Add QWEBKIT_EXPORT to the list of macros to ignore by qdoc. * docs/qtwebkit.qdocconf: 2009-06-26 Yongjun Zhang <yongjun.zhang@nokia.com> Reviewed by Eric Seidel. Bug 20303: [Qt] Key events are not working in frames. Send scrolling events to current focused frame, bubble the event up to parent frame if it is not handled. Use EventHandler's new shared scrolling code. * Api/qwebpage.cpp: (QWebPagePrivate::keyPressEvent): (QWebPagePrivate::handleScrolling): * Api/qwebpage_p.h: 2009-06-25 Jakub Wieczorek <faw217@gmail.com> Reviewed by Adam Treat. Add highlight functionality to the QWebPage::findText() method. Introduced is new HighlightAllOccurrences flag which passed to the function will make it mark all existing occurrences of specified string in the page. * Api/qwebpage.cpp: (QWebPage::findText): * Api/qwebpage.h: * Api/qwebview.cpp:
Diffstat (limited to 'src/3rdparty/webkit/WebCore/editing/IndentOutdentCommand.cpp')
-rw-r--r--src/3rdparty/webkit/WebCore/editing/IndentOutdentCommand.cpp117
1 files changed, 68 insertions, 49 deletions
diff --git a/src/3rdparty/webkit/WebCore/editing/IndentOutdentCommand.cpp b/src/3rdparty/webkit/WebCore/editing/IndentOutdentCommand.cpp
index 0f9b106..3922367 100644
--- a/src/3rdparty/webkit/WebCore/editing/IndentOutdentCommand.cpp
+++ b/src/3rdparty/webkit/WebCore/editing/IndentOutdentCommand.cpp
@@ -78,7 +78,7 @@ IndentOutdentCommand::IndentOutdentCommand(Document* document, EIndentType typeO
// This function is a workaround for moveParagraph's tendency to strip blockquotes. It updates lastBlockquote to point to the
// correct level for the current paragraph, and returns a pointer to a placeholder br where the insertion should be performed.
-PassRefPtr<Element> IndentOutdentCommand::prepareBlockquoteLevelForInsertion(VisiblePosition& currentParagraph, RefPtr<Element>& lastBlockquote)
+PassRefPtr<Element> IndentOutdentCommand::prepareBlockquoteLevelForInsertion(const VisiblePosition& currentParagraph, RefPtr<Element>& lastBlockquote)
{
int currentBlockquoteLevel = 0;
int lastBlockquoteLevel = 0;
@@ -107,6 +107,62 @@ PassRefPtr<Element> IndentOutdentCommand::prepareBlockquoteLevelForInsertion(Vis
return placeholder.release();
}
+bool IndentOutdentCommand::tryIndentingAsListItem(const VisiblePosition& endOfCurrentParagraph)
+{
+ // If our selection is not inside a list, bail out.
+ Node* lastNodeInSelectedParagraph = endOfCurrentParagraph.deepEquivalent().node();
+ RefPtr<Element> listNode = enclosingList(lastNodeInSelectedParagraph);
+ if (!listNode)
+ return false;
+
+ HTMLElement* selectedListItem = enclosingListChild(lastNodeInSelectedParagraph);
+
+ // FIXME: previousElementSibling does not ignore non-rendered content like <span></span>. Should we?
+ Element* previousList = selectedListItem->previousElementSibling();
+ Element* nextList = selectedListItem->nextElementSibling();
+
+ RefPtr<Element> newList = document()->createElement(listNode->tagQName(), false);
+ RefPtr<Element> newListItem = selectedListItem->cloneElementWithoutChildren();
+ RefPtr<Element> placeholder = createBreakElement(document());
+ insertNodeBefore(newList, selectedListItem);
+ appendNode(newListItem, newList);
+ appendNode(placeholder, newListItem);
+
+ moveParagraph(startOfParagraph(endOfCurrentParagraph), endOfCurrentParagraph, VisiblePosition(Position(placeholder, 0)), true);
+
+ if (canMergeLists(previousList, newList.get()))
+ mergeIdenticalElements(previousList, newList);
+ if (canMergeLists(newList.get(), nextList))
+ mergeIdenticalElements(newList, nextList);
+
+ return true;
+}
+
+void IndentOutdentCommand::indentIntoBlockquote(const VisiblePosition& endOfCurrentParagraph, const VisiblePosition& endOfNextParagraph, RefPtr<Element>& targetBlockquote)
+{
+ Node* enclosingCell = 0;
+
+ if (!targetBlockquote) {
+ // Create a new blockquote and insert it as a child of the root editable element. We accomplish
+ // this by splitting all parents of the current paragraph up to that point.
+ targetBlockquote = createIndentBlockquoteElement(document());
+ Position start = startOfParagraph(endOfCurrentParagraph).deepEquivalent();
+ enclosingCell = enclosingNodeOfType(start, &isTableCell);
+ Node* nodeToSplitTo = enclosingCell ? enclosingCell : editableRootForPosition(start);
+ RefPtr<Node> startOfNewBlock = splitTreeToNode(start.node(), nodeToSplitTo);
+ insertNodeBefore(targetBlockquote, startOfNewBlock);
+ }
+
+ RefPtr<Element> insertionPoint = prepareBlockquoteLevelForInsertion(endOfCurrentParagraph, targetBlockquote);
+
+ // 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))
+ targetBlockquote = 0;
+
+ moveParagraph(startOfParagraph(endOfCurrentParagraph), endOfCurrentParagraph, VisiblePosition(Position(insertionPoint, 0)), true);
+}
+
void IndentOutdentCommand::indentRegion()
{
VisibleSelection selection = selectionForParagraphIteration(endingSelection());
@@ -117,7 +173,7 @@ void IndentOutdentCommand::indentRegion()
ASSERT(!startOfSelection.isNull());
ASSERT(!endOfSelection.isNull());
-
+
// Special case empty root editable elements because there's nothing to split
// and there's nothing to move.
Position start = startOfSelection.deepEquivalent().downstream();
@@ -129,58 +185,21 @@ void IndentOutdentCommand::indentRegion()
setEndingSelection(VisibleSelection(Position(placeholder.get(), 0), DOWNSTREAM));
return;
}
-
- RefPtr<Element> previousListNode;
- RefPtr<Element> newListNode;
- RefPtr<Element> newBlockquote;
+
+ RefPtr<Element> blockquoteForNextIndent;
VisiblePosition endOfCurrentParagraph = endOfParagraph(startOfSelection);
VisiblePosition endAfterSelection = endOfParagraph(endOfParagraph(endOfSelection).next());
while (endOfCurrentParagraph != endAfterSelection) {
// Iterate across the selected paragraphs...
VisiblePosition endOfNextParagraph = endOfParagraph(endOfCurrentParagraph.next());
- RefPtr<Element> listNode = enclosingList(endOfCurrentParagraph.deepEquivalent().node());
- RefPtr<Element> insertionPoint;
- if (listNode) {
- RefPtr<Element> placeholder = createBreakElement(document());
- insertionPoint = placeholder;
- newBlockquote = 0;
- RefPtr<Element> listItem = createListItemElement(document());
- if (listNode == previousListNode) {
- // The previous paragraph was inside the same list, so add this list item to the list we already created
- appendNode(listItem, newListNode);
- appendNode(placeholder, listItem);
- } else {
- // Clone the list element, insert it before the current paragraph, and move the paragraph into it.
- RefPtr<Element> clonedList = listNode->cloneElementWithoutChildren();
- insertNodeBefore(clonedList, enclosingListChild(endOfCurrentParagraph.deepEquivalent().node()));
- appendNode(listItem, clonedList);
- appendNode(placeholder, listItem);
- newListNode = clonedList;
- previousListNode = listNode;
- }
- } else if (newBlockquote)
- // The previous paragraph was put into a new blockquote, so move this paragraph there as well
- insertionPoint = prepareBlockquoteLevelForInsertion(endOfCurrentParagraph, newBlockquote);
- else {
- // Create a new blockquote and insert it as a child of the root editable element. We accomplish
- // this by splitting all parents of the current paragraph up to that point.
- RefPtr<Element> blockquote = createIndentBlockquoteElement(document());
- Position start = startOfParagraph(endOfCurrentParagraph).deepEquivalent();
-
- Node* enclosingCell = enclosingNodeOfType(start, &isTableCell);
- Node* nodeToSplitTo = enclosingCell ? enclosingCell : editableRootForPosition(start);
- RefPtr<Node> startOfNewBlock = splitTreeToNode(start.node(), nodeToSplitTo);
- insertNodeBefore(blockquote, startOfNewBlock);
- newBlockquote = blockquote;
- 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 (tryIndentingAsListItem(endOfCurrentParagraph))
+ blockquoteForNextIndent = 0;
+ else
+ indentIntoBlockquote(endOfCurrentParagraph, endOfNextParagraph, blockquoteForNextIndent);
+ // blockquoteForNextIndent maybe updated
+ // this is due to the way prepareBlockquoteLevelForInsertion was designed.
+ // Sanity check: Make sure our moveParagraph calls didn't remove endOfNextParagraph.deepEquivalent().node()
+ // If somehow we did, return to prevent crashes.
if (endOfNextParagraph.isNotNull() && !endOfNextParagraph.deepEquivalent().node()->inDocument()) {
ASSERT_NOT_REACHED();
return;