Implement support for testing editing.
authorlars <lars@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 24 Oct 2007 12:32:05 +0000 (12:32 +0000)
committerlars <lars@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 24 Oct 2007 12:32:05 +0000 (12:32 +0000)
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@26962 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebKit/qt/ChangeLog
WebKit/qt/WebCoreSupport/EditorClientQt.cpp
WebKitTools/ChangeLog
WebKitTools/DumpRenderTree/qt/DumpRenderTree.cpp

index 441b7abd0cb5327620a079ffd166a22f002d8d78..97c6947cf86c3bd8c3203aa5e05fd3c5dcc77680 100644 (file)
@@ -1,3 +1,27 @@
+2007-10-24  Lars Knoll  <lars@trolltech.com>
+
+        Reviewed by Simon.
+
+        Implement support for testing editing.
+
+        * WebCoreSupport/EditorClientQt.cpp:
+        (qt_dump_editing_callbacks):
+        (qt_dump_set_accepts_editing):
+        (dumpPath):
+        (dumpRange):
+        (WebCore::EditorClientQt::shouldDeleteRange):
+        (WebCore::EditorClientQt::shouldShowDeleteInterface):
+        (WebCore::EditorClientQt::shouldBeginEditing):
+        (WebCore::EditorClientQt::shouldEndEditing):
+        (WebCore::EditorClientQt::shouldInsertText):
+        (WebCore::EditorClientQt::shouldChangeSelectedRange):
+        (WebCore::EditorClientQt::shouldApplyStyle):
+        (WebCore::EditorClientQt::didBeginEditing):
+        (WebCore::EditorClientQt::respondToChangedContents):
+        (WebCore::EditorClientQt::respondToChangedSelection):
+        (WebCore::EditorClientQt::didEndEditing):
+        (WebCore::EditorClientQt::shouldInsertNode):
+
 2007-10-19  Alp Toker  <alp@atoker.com>
 
         Reviewed by Oliver.
index 4bedf44082edad697f40afbf5f89e94efbbd7a1a..c24cc9f7cd491a9fafe30a4626ae743b42e95494 100644 (file)
 #include "Page.h"
 #include "PlatformKeyboardEvent.h"
 #include "NotImplemented.h"
+#include "Node.h"
+#include "Range.h"
 
 #include <stdio.h>
 
 #include <QUndoStack>
+#define methodDebug() qDebug("EditorClientQt: %s", __FUNCTION__);
+
+static bool dumpEditingCallbacks = false;
+static bool acceptsEditing = true;
+void QWEBKIT_EXPORT qt_dump_editing_callbacks(bool b)
+{
+    dumpEditingCallbacks = b;
+}
+
+void QWEBKIT_EXPORT qt_dump_set_accepts_editing(bool b)
+{
+    acceptsEditing = b;
+}
+
+
+static QString dumpPath(WebCore::Node *node)
+{
+    QString str = node->nodeName();
+    
+    WebCore::Node *parent = node->parentNode();
+    while (parent) {
+        str.append(QLatin1String(" > "));
+        str.append(parent->nodeName());
+        parent = parent->parentNode();
+    }
+    return str;
+}
+
+static QString dumpRange(WebCore::Range *range)
+{
+    if (!range)
+        return QLatin1String("(null)");
+    QString str;
+    WebCore::ExceptionCode code;
+    str.sprintf("range from %ld of %ls to %ld of %ls",
+                range->startOffset(code), dumpPath(range->startContainer(code)).unicode(),
+                range->endOffset(code), dumpPath(range->endContainer(code)).unicode());
+    return str;
+}
+    
 
 namespace WebCore {
 
-bool EditorClientQt::shouldDeleteRange(Range*)
+
+bool EditorClientQt::shouldDeleteRange(Range* range)
 {
+    if (dumpEditingCallbacks) 
+        printf("EDITING DELEGATE: shouldDeleteDOMRange:%s\n", dumpRange(range).toUtf8().constData());
+
     return true;
 }
 
-bool EditorClientQt::shouldShowDeleteInterface(HTMLElement*)
+bool EditorClientQt::shouldShowDeleteInterface(HTMLElement* element)
 {
+    if (dumpEditingCallbacks) 
+        return element->className() == "needsDeletionUI";
     return false;
 }
 
@@ -78,30 +126,62 @@ int EditorClientQt::spellCheckerDocumentTag()
     return 0;
 }
 
-bool EditorClientQt::shouldBeginEditing(WebCore::Range*)
-{
-    return true;
-}
-
-bool EditorClientQt::shouldEndEditing(WebCore::Range*)
+bool EditorClientQt::shouldBeginEditing(WebCore::Range* range)
 {
+    if (dumpEditingCallbacks)
+        printf("EDITING DELEGATE: shouldBeginEditingInDOMRange:%s\n", dumpRange(range).toUtf8().constData());
     return true;
 }
 
-bool EditorClientQt::shouldInsertText(String, Range*, EditorInsertAction)
+bool EditorClientQt::shouldEndEditing(WebCore::Range* range)
 {
+    if (dumpEditingCallbacks)
+        printf("EDITING DELEGATE: shouldEndEditingInDOMRange:%s\n", dumpRange(range).toUtf8().constData());
     return true;
 }
 
-bool EditorClientQt::shouldChangeSelectedRange(Range* fromRange, Range* toRange, EAffinity, bool stillSelecting)
+bool EditorClientQt::shouldInsertText(String string, Range* range, EditorInsertAction action)
 {
-    return true;
+    if (dumpEditingCallbacks) {
+        static const char *insertactionstring[] = {
+            "WebViewInsertActionTyped",
+            "WebViewInsertActionPasted",
+            "WebViewInsertActionDropped",
+        };
+        
+        printf("EDITING DELEGATE: shouldInsertText:%s replacingDOMRange:%s givenAction:%s\n",
+               QString(string).toUtf8().constData(), dumpRange(range).toUtf8().constData(), insertactionstring[action]);
+    }
+    return acceptsEditing;
+}
+
+bool EditorClientQt::shouldChangeSelectedRange(Range* currentRange, Range* proposedRange, EAffinity selectionAffinity, bool stillSelecting)
+{
+    if (dumpEditingCallbacks) {
+        static const char *affinitystring[] = {
+            "NSSelectionAffinityUpstream",
+            "NSSelectionAffinityDownstream"
+        };
+        static const char *boolstring[] = {
+            "FALSE",
+            "TRUE"
+        };
+        
+        printf("EDITING DELEGATE: shouldChangeSelectedDOMRange:%s toDOMRange:%s affinity:%s stillSelecting:%s\n",
+               dumpRange(currentRange).toUtf8().constData(),
+               dumpRange(proposedRange).toUtf8().constData(),
+               affinitystring[selectionAffinity], boolstring[stillSelecting]);
+    }
+    return acceptsEditing;
 }
 
-bool EditorClientQt::shouldApplyStyle(WebCore::CSSStyleDeclaration*,
-                                      WebCore::Range*)
+bool EditorClientQt::shouldApplyStyle(WebCore::CSSStyleDeclaration* style,
+                                      WebCore::Range* range)
 {
-    return true;
+    if (dumpEditingCallbacks)
+        printf("EDITING DELEGATE: shouldApplyStyle:%s toElementsInDOMRange:%s\n",
+               QString(style->cssText()).toUtf8().constData(), dumpRange(range).toUtf8().constData());
+    return acceptsEditing;
 }
 
 bool EditorClientQt::shouldMoveRangeAfterDelete(WebCore::Range*, WebCore::Range*)
@@ -112,21 +192,29 @@ bool EditorClientQt::shouldMoveRangeAfterDelete(WebCore::Range*, WebCore::Range*
 
 void EditorClientQt::didBeginEditing()
 {
+    if (dumpEditingCallbacks)
+        printf("EDITING DELEGATE: webViewDidBeginEditing:WebViewDidBeginEditingNotification\n");
     m_editing = true;
 }
 
 void EditorClientQt::respondToChangedContents()
 {
+    if (dumpEditingCallbacks)
+        printf("EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification\n");
     m_page->d->modified = true;
 }
 
 void EditorClientQt::respondToChangedSelection()
 {
+    if (dumpEditingCallbacks)
+        printf("EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification\n");
     emit m_page->selectionChanged();
 }
 
 void EditorClientQt::didEndEditing()
 {
+    if (dumpEditingCallbacks)
+        printf("EDITING DELEGATE: webViewDidEndEditing:WebViewDidEndEditingNotification\n");
     m_editing = false;
 }
 
@@ -147,7 +235,7 @@ bool EditorClientQt::selectWordBeforeMenuEvent()
 }
 
 bool EditorClientQt::isEditable()
-{
+{ 
     // FIXME: should be controllable by a setting in QWebPage
     return false;
 }
@@ -194,9 +282,19 @@ void EditorClientQt::redo()
     m_inUndoRedo = false;
 }
 
-bool EditorClientQt::shouldInsertNode(Node*, Range*, EditorInsertAction)
+bool EditorClientQt::shouldInsertNode(Node* node, Range* range, EditorInsertAction action)
 {
-    return true;
+    if (dumpEditingCallbacks) {
+        static const char *insertactionstring[] = {
+            "WebViewInsertActionTyped",
+            "WebViewInsertActionPasted",
+            "WebViewInsertActionDropped",
+        };
+        
+        printf("EDITING DELEGATE: shouldInsertNode:%s replacingDOMRange:%s givenAction:%s\n", dumpPath(node).toUtf8().constData(),
+               dumpRange(range).toUtf8().constData(), insertactionstring[action]);
+    }
+    return acceptsEditing;
 }
 
 void EditorClientQt::pageDestroyed()
index 81abb96938d6f2d06ef6a3bf4e3875abcb82beab..ca72759de3b68048d6fe642908a606f86c584a31 100644 (file)
@@ -1,3 +1,12 @@
+2007-10-24  Lars Knoll  <lars@trolltech.com>
+
+        Reviewed by Simon.
+
+        Implement support for testing editing.
+
+        * DumpRenderTree/qt/DumpRenderTree.cpp:
+        (WebCore::DumpRenderTree::DumpRenderTree):
+
 2007-10-23  Sam Weinig  <sam@webkit.org>
 
         Check for null BSTR that can be passed to the UIDelegate methods
index eb0acce62a0c9f0cf8aba021933d7ed1abd8da50..3c972f6dc83ce3135eb81dca78e40f0237ec7562 100644 (file)
@@ -44,6 +44,9 @@
 
 #include <unistd.h>
 #include <qdebug.h>
+extern void qt_dump_editing_callbacks(bool b);
+extern void qt_dump_set_accepts_editing(bool b);
+
 
 namespace WebCore {
 
@@ -120,6 +123,7 @@ DumpRenderTree::DumpRenderTree()
     : m_stdin(0)
     , m_notifier(0)
 {
+    qt_dump_editing_callbacks(true);
     m_controller = new LayoutTestController(this);
     connect(m_controller, SIGNAL(done()), this, SLOT(dump()), Qt::QueuedConnection);