2009-09-08 Steve VanDeBogart <vandebo@chromium.org>
authorjaphet@chromium.org <japhet@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 8 Sep 2009 17:58:05 +0000 (17:58 +0000)
committerjaphet@chromium.org <japhet@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 8 Sep 2009 17:58:05 +0000 (17:58 +0000)
        Reviewed by Eric Seidel.

        Handle middle click in Chromium like QT
        https://bugs.webkit.org/show_bug.cgi?id=28696

        Tested by middle-click-onpaste.html.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@48168 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/platform/gtk/editing/pasteboard/middle-click-onpaste-expected.txt [new file with mode: 0644]
LayoutTests/platform/gtk/editing/pasteboard/resources/TEMPLATE.html [new file with mode: 0644]
LayoutTests/platform/gtk/editing/pasteboard/resources/middle-click-onpaste.js [new file with mode: 0644]
WebCore/ChangeLog
WebCore/platform/Pasteboard.h
WebCore/platform/chromium/ChromiumBridge.h
WebCore/platform/chromium/ClipboardChromium.cpp
WebCore/platform/chromium/PasteboardChromium.cpp
WebCore/platform/chromium/PasteboardPrivate.h

index 9bbf70c..fc4ef58 100644 (file)
@@ -1,3 +1,17 @@
+2009-09-08  Steve VanDeBogart  <vandebo@chromium.org>
+
+        Reviewed by Eric Seidel.
+
+        Check that middle click triggers an onpaste event in Linux.
+        https://bugs.webkit.org/show_bug.cgi?id=28696
+
+        * platform/gtk/editing/pasteboard: Added.
+        * platform/gtk/editing/pasteboard/middle-click-onpaste-expected.txt: Added.
+        * platform/gtk/editing/pasteboard/resources: Added.
+        * platform/gtk/editing/pasteboard/resources/TEMPLATE.html: Added.
+        * platform/gtk/editing/pasteboard/resources/middle-click-onpaste.js: Added.
+        (handlePaste):
+
 2009-09-08  Kent Tamura  <tkent@chromium.org>
 
         Reviewed by Eric Seidel.
diff --git a/LayoutTests/platform/gtk/editing/pasteboard/middle-click-onpaste-expected.txt b/LayoutTests/platform/gtk/editing/pasteboard/middle-click-onpaste-expected.txt
new file mode 100644 (file)
index 0000000..d8c20d7
--- /dev/null
@@ -0,0 +1,9 @@
+Test that middle click triggers the onpaste event
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS pasteCount is 1
+PASS successfullyParsed is true
+
+TEST COMPLETE
diff --git a/LayoutTests/platform/gtk/editing/pasteboard/resources/TEMPLATE.html b/LayoutTests/platform/gtk/editing/pasteboard/resources/TEMPLATE.html
new file mode 100644 (file)
index 0000000..2431ed5
--- /dev/null
@@ -0,0 +1,13 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<link rel="stylesheet" href="../../../../fast/js/resources/js-test-style.css">
+<script src="../../../../fast/js/resources/js-test-pre.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+<script src="YOUR_JS_FILE_HERE"></script>
+<script src="../../../../fast/js/resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/platform/gtk/editing/pasteboard/resources/middle-click-onpaste.js b/LayoutTests/platform/gtk/editing/pasteboard/resources/middle-click-onpaste.js
new file mode 100644 (file)
index 0000000..eb563e3
--- /dev/null
@@ -0,0 +1,26 @@
+description('Test that middle click triggers the onpaste event');
+
+var pasteCount = 0;
+
+function handlePaste(eventObj)
+{
+    pasteCount++;
+}
+
+var target = document.getElementById("description");
+target.onpaste = handlePaste;
+
+if (window.layoutTestController)
+{
+    layoutTestController.dumpAsText();
+    var x = target.offsetParent.offsetLeft + target.offsetLeft + 
+        target.offsetWidth / 2;
+    var y = target.offsetParent.offsetTop + target.offsetTop + 
+        target.offsetHeight / 2;
+    eventSender.mouseMoveTo(x, y);
+    eventSender.mouseDown(1);
+    eventSender.mouseUp(1);
+    shouldBe("pasteCount", "1");
+}
+
+var successfullyParsed = true;
index 569d2c2..0b480bb 100644 (file)
@@ -1,3 +1,26 @@
+2009-09-08  Steve VanDeBogart  <vandebo@chromium.org>
+
+        Reviewed by Eric Seidel.
+
+        Handle middle click in Chromium like QT
+        https://bugs.webkit.org/show_bug.cgi?id=28696
+
+        Tested by middle-click-onpaste.html.
+
+        * platform/Pasteboard.h:
+        * platform/chromium/ChromiumBridge.h:
+        * platform/chromium/ClipboardChromium.cpp:
+        (WebCore::ClipboardChromium::getData):
+        * platform/chromium/PasteboardChromium.cpp:
+        (WebCore::Pasteboard::Pasteboard):
+        (WebCore::Pasteboard::isSelectionMode):
+        (WebCore::Pasteboard::setSelectionMode):
+        (WebCore::Pasteboard::canSmartReplace):
+        (WebCore::Pasteboard::plainText):
+        (WebCore::Pasteboard::documentFragment):
+        * platform/chromium/PasteboardPrivate.h:
+        (WebCore::PasteboardPrivate::):
+
 2009-09-08  Kelly Norton  <knorton@google.com>
 
         Reviewed by Eric Seidel.
index 5d63254..cd6a3b5 100644 (file)
@@ -95,7 +95,7 @@ public:
     bool canSmartReplace();
     PassRefPtr<DocumentFragment> documentFragment(Frame*, PassRefPtr<Range>, bool allowPlainText, bool& chosePlainText);
     String plainText(Frame* = 0);
-#if PLATFORM(QT)
+#if PLATFORM(QT) || PLATFORM(CHROMIUM)
     bool isSelectionMode() const;
     void setSelectionMode(bool selectionMode);
 #endif
@@ -118,7 +118,7 @@ private:
     HWND m_owner;
 #endif
 
-#if PLATFORM(QT)
+#if PLATFORM(QT) || PLATFORM(CHROMIUM)
     bool m_selectionMode;
 #endif
 
index aaa2db7..b34924b 100644 (file)
@@ -67,11 +67,14 @@ namespace WebCore {
     class ChromiumBridge {
     public:
         // Clipboard ----------------------------------------------------------
-        static bool clipboardIsFormatAvailable(PasteboardPrivate::ClipboardFormat);
+        static bool clipboardIsFormatAvailable(PasteboardPrivate::ClipboardFormat, PasteboardPrivate::ClipboardBuffer);
 
-        static String clipboardReadPlainText();
-        static void clipboardReadHTML(String*, KURL*);
+        static String clipboardReadPlainText(PasteboardPrivate::ClipboardBuffer);
+        static void clipboardReadHTML(PasteboardPrivate::ClipboardBuffer, String*, KURL*);
 
+        // Only the clipboardRead functions take a buffer argument because 
+        // Chromium currently uses a different technique to write to alternate
+        // clipboard buffers.
         static void clipboardWriteSelection(const String&, const KURL&, const String&, bool);
         static void clipboardWriteURL(const KURL&, const String&);
         static void clipboardWriteImage(const NativeImageSkia*, const KURL&, const String&);
index 542d8ac..d330d3b 100644 (file)
@@ -40,6 +40,7 @@
 #include "MIMETypeRegistry.h"
 #include "markup.h"
 #include "NamedNodeMap.h"
+#include "Pasteboard.h"
 #include "PlatformString.h"
 #include "Range.h"
 #include "RenderImage.h"
@@ -117,7 +118,11 @@ String ClipboardChromium::getData(const String& type, bool& success) const
         if (!isForDragging()) {
             // If this isn't for a drag, it's for a cut/paste event handler.
             // In this case, we need to check the clipboard.
-            text = ChromiumBridge::clipboardReadPlainText();
+            PasteboardPrivate::ClipboardBuffer buffer = 
+                Pasteboard::generalPasteboard()->isSelectionMode() ?
+                PasteboardPrivate::SelectionBuffer : 
+                PasteboardPrivate::StandardBuffer;
+            text = ChromiumBridge::clipboardReadPlainText(buffer);
             success = !text.isEmpty();
         } else if (!m_dataObject->plainText.isEmpty()) {
             success = true;
index c5dee82..4fd6cf2 100644 (file)
@@ -59,6 +59,7 @@ Pasteboard* Pasteboard::generalPasteboard()
 }
 
 Pasteboard::Pasteboard()
+    : m_selectionMode(false)
 {
 }
 
@@ -68,6 +69,16 @@ void Pasteboard::clear()
     // previous contents.
 }
 
+bool Pasteboard::isSelectionMode() const
+{
+    return m_selectionMode;
+}
+
+void Pasteboard::setSelectionMode(bool selectionMode)
+{
+    m_selectionMode = selectionMode;
+}
+
 void Pasteboard::writeSelection(Range* selectedRange, bool canSmartCopyOrDelete, Frame* frame)
 {
     String html = createMarkup(selectedRange, 0, AnnotateForInterchange);
@@ -134,23 +145,23 @@ void Pasteboard::writeImage(Node* node, const KURL&, const String& title)
 
 bool Pasteboard::canSmartReplace()
 {
-    return ChromiumBridge::clipboardIsFormatAvailable(
-        PasteboardPrivate::WebSmartPasteFormat);
+    return ChromiumBridge::clipboardIsFormatAvailable(PasteboardPrivate::WebSmartPasteFormat, m_selectionMode ? PasteboardPrivate::SelectionBuffer : PasteboardPrivate::StandardBuffer);
 }
 
 String Pasteboard::plainText(Frame* frame)
 {
-    return ChromiumBridge::clipboardReadPlainText();
+    return ChromiumBridge::clipboardReadPlainText(m_selectionMode ? PasteboardPrivate::SelectionBuffer : PasteboardPrivate::StandardBuffer);
 }
 
 PassRefPtr<DocumentFragment> Pasteboard::documentFragment(Frame* frame, PassRefPtr<Range> context, bool allowPlainText, bool& chosePlainText)
 {
     chosePlainText = false;
+    PasteboardPrivate::ClipboardBuffer buffer = m_selectionMode ? PasteboardPrivate::SelectionBuffer : PasteboardPrivate::StandardBuffer;
 
-    if (ChromiumBridge::clipboardIsFormatAvailable(PasteboardPrivate::HTMLFormat)) {
+    if (ChromiumBridge::clipboardIsFormatAvailable(PasteboardPrivate::HTMLFormat, buffer)) {
         String markup;
         KURL srcURL;
-        ChromiumBridge::clipboardReadHTML(&markup, &srcURL);
+        ChromiumBridge::clipboardReadHTML(buffer, &markup, &srcURL);
 
         RefPtr<DocumentFragment> fragment =
             createFragmentFromMarkup(frame->document(), markup, srcURL);
@@ -159,7 +170,7 @@ PassRefPtr<DocumentFragment> Pasteboard::documentFragment(Frame* frame, PassRefP
     }
 
     if (allowPlainText) {
-        String markup = ChromiumBridge::clipboardReadPlainText();
+        String markup = ChromiumBridge::clipboardReadPlainText(buffer);
         if (!markup.isEmpty()) {
             chosePlainText = true;
 
index 26d45a0..95cc697 100644 (file)
@@ -41,6 +41,10 @@ namespace WebCore {
             BookmarkFormat,
             WebSmartPasteFormat,
         };
+        enum ClipboardBuffer {
+            StandardBuffer,
+            SelectionBuffer,
+        };
     };
 
 } // namespace WebCore