Title: [127862] trunk
Revision
127862
Author
allan.jen...@nokia.com
Date
2012-09-07 05:51:44 -0700 (Fri, 07 Sep 2012)

Log Message

X11 Global Selection
https://bugs.webkit.org/show_bug.cgi?id=88238

Reviewed by Tony Chang.

Source/WebCore:

In X11 global selection is the ability to share the active selection
between applications and pasting with middle mouse-button.

This patch moves the implementations of global selection from the
separate implementations in Qt WebKit, Chromium and GTK to WebCore,
by implementing a new EditorCommand for pasting the global selection.

Test: editing/pasteboard/paste-global-selection.html

* editing/EditorCommand.cpp:
(WebCore::executePasteGlobalSelection):
(WebCore::createCommandMap):
* page/EditorClient.h:
(EditorClient):
(WebCore::EditorClient::supportsGlobalSelection):
* platform/Pasteboard.h:
(WebCore::Pasteboard::isSelectionMode):
(WebCore::Pasteboard::setSelectionMode):
* platform/gtk/PasteboardGtk.cpp:
(WebCore::Pasteboard::writeSelection):
(WebCore::Pasteboard::writeURL):
(WebCore::Pasteboard::isSelectionMode):
(WebCore::Pasteboard::setSelectionMode):

Source/WebKit/chromium:

Use new editor command for pasting global selection.

* src/EditorClientImpl.cpp:
(WebKit::EditorClientImpl::supportsGlobalSelection):
* src/EditorClientImpl.h:
(EditorClientImpl):
* src/WebViewImpl.cpp:
(WebKit::WebViewImpl::handleMouseUp):

Source/WebKit/qt:

Use new editor command for pasting global selection, and update it using
the respondToChangedSelection callback.

* Api/qwebpage.cpp:
(QWebPagePrivate::handleClipboard):
* WebCoreSupport/EditorClientQt.cpp:
(WebCore::EditorClientQt::respondToChangedSelection):
(WebCore::EditorClientQt::supportsGlobalSelection):
* WebCoreSupport/EditorClientQt.h:
(EditorClientQt):

Source/WebKit2:

Implements the hooks for supporting global selections in Qt WebKit2.

* WebProcess/WebCoreSupport/WebEditorClient.cpp:
(WebKit::WebEditorClient::respondToChangedSelection):
(WebKit::WebEditorClient::updateGlobalSelection):
(WebKit::WebEditorClient::supportsGlobalSelection):
* WebProcess/WebCoreSupport/WebEditorClient.h:
* WebProcess/WebCoreSupport/gtk/WebEditorClientGtk.cpp:
(WebKit::WebEditorClient::updateGlobalSelection):
* WebProcess/WebPage/WebPage.cpp:
(WebKit::handleMouseEvent):
* WebProcess/WebPage/WebPage.h:
(WebPage):
* WebProcess/WebPage/qt/WebPageQt.cpp:
(WebKit::WebPage::handleMouseReleaseEvent):

LayoutTests:

Adds a test for the new editor-command, and disables it an all platforms where it is not supported.

* editing/pasteboard/paste-global-selection-expected.txt: Added.
* editing/pasteboard/paste-global-selection.html: Added.
* platform/chromium/TestExpectations:
* platform/efl/TestExpectations:
* platform/gtk/TestExpectations:
* platform/mac/Skipped:
* platform/qt-mac/Skipped:
* platform/win/Skipped:

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (127861 => 127862)


--- trunk/LayoutTests/ChangeLog	2012-09-07 12:32:51 UTC (rev 127861)
+++ trunk/LayoutTests/ChangeLog	2012-09-07 12:51:44 UTC (rev 127862)
@@ -1,3 +1,21 @@
+2012-09-07  Allan Sandfeld Jensen  <allan.jen...@nokia.com>
+
+        X11 Global Selection
+        https://bugs.webkit.org/show_bug.cgi?id=88238
+
+        Reviewed by Tony Chang.
+
+        Adds a test for the new editor-command, and disables it an all platforms where it is not supported.
+
+        * editing/pasteboard/paste-global-selection-expected.txt: Added.
+        * editing/pasteboard/paste-global-selection.html: Added.
+        * platform/chromium/TestExpectations:
+        * platform/efl/TestExpectations:
+        * platform/gtk/TestExpectations:
+        * platform/mac/Skipped:
+        * platform/qt-mac/Skipped:
+        * platform/win/Skipped:
+
 2012-09-06  Vsevolod Vlasov  <vse...@chromium.org>
 
         Web Inspector: Migrate FileSystem to async protocol commands.

Added: trunk/LayoutTests/editing/pasteboard/paste-global-selection-expected.txt (0 => 127862)


--- trunk/LayoutTests/editing/pasteboard/paste-global-selection-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/editing/pasteboard/paste-global-selection-expected.txt	2012-09-07 12:51:44 UTC (rev 127862)
@@ -0,0 +1,9 @@
+  
+This test checks that we can set and paste X11-style selections.
+
+PASS confirmedMarkup is 'TestTest'
+PASS confirmedMarkup is 'SayHello'
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/editing/pasteboard/paste-global-selection.html (0 => 127862)


--- trunk/LayoutTests/editing/pasteboard/paste-global-selection.html	                        (rev 0)
+++ trunk/LayoutTests/editing/pasteboard/paste-global-selection.html	2012-09-07 12:51:44 UTC (rev 127862)
@@ -0,0 +1,48 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+    <script src=""
+</head>
+<body>
+    <iframe name="iframe1"></iframe>
+    <iframe name="iframe2"></iframe>
+
+    <p id="description">This test checks that we can set and paste X11-style selections.</p>
+    <div id="console"></div>
+
+    <script>
+
+        var document1 = frames['iframe1'].document;
+        var document2 = frames['iframe2'].document;
+
+        function createEditable(doc, tagName, markup) {
+            var node = doc.createElement(tagName);
+            node.contentEditable = true;
+            node.innerHTML = markup;
+            return node;
+        }
+
+        function testPasteSelection(tagName, originalMarkup1, originalMarkup2, expected) {
+            var node1 = createEditable(document1, tagName, originalMarkup1);
+            var node2 = createEditable(document2, tagName, originalMarkup2);
+            document1.body.appendChild(node1);
+            document2.body.appendChild(node2);
+
+            node1.focus();
+            document1.execCommand("SelectAll", false);
+            node2.focus();
+            testRunner.execCommand("MoveToEndOfLine", '');
+            testRunner.execCommand("PasteGlobalSelection", '');
+
+            confirmedMarkup = node2.innerHTML;
+
+            shouldBe("confirmedMarkup", "'" + expected + "'");
+        }
+
+        testPasteSelection("div", "Test", "Test", "TestTest");
+        testPasteSelection("div", "Hello", "Say", "SayHello");
+
+</script>
+<script src=""
+</body>
+</html>

Modified: trunk/LayoutTests/platform/chromium/TestExpectations (127861 => 127862)


--- trunk/LayoutTests/platform/chromium/TestExpectations	2012-09-07 12:32:51 UTC (rev 127861)
+++ trunk/LayoutTests/platform/chromium/TestExpectations	2012-09-07 12:51:44 UTC (rev 127862)
@@ -889,6 +889,9 @@
 // Test fails because it's trying to load a plugin we don't have. We probably don't need to fix this.
 WONTFIX : platform/gtk/plugins/invalidate-rect-with-null-npp-argument.html = TEXT
 
+// Mac and Win does not have global selection.
+WONTFIX MAC WIN : editing/pasteboard/paste-global-selection.html = TEXT
+
 // Skipping rules for ANDROID are in platform/chromium-android/TestExpectations.
 
 // -----------------------------------------------------------------

Modified: trunk/LayoutTests/platform/efl/TestExpectations (127861 => 127862)


--- trunk/LayoutTests/platform/efl/TestExpectations	2012-09-07 12:32:51 UTC (rev 127861)
+++ trunk/LayoutTests/platform/efl/TestExpectations	2012-09-07 12:51:44 UTC (rev 127862)
@@ -1086,3 +1086,6 @@
 
 // Fails after r127534.
 BUGWK95813 : fast/innerHTML/innerHTML-iframe.html = TEXT
+
+// EFL does not yet support global selection
+BUGWK88238 SKIP : editing/pasteboard/paste-global-selection.html = TEXT

Modified: trunk/LayoutTests/platform/gtk/TestExpectations (127861 => 127862)


--- trunk/LayoutTests/platform/gtk/TestExpectations	2012-09-07 12:32:51 UTC (rev 127861)
+++ trunk/LayoutTests/platform/gtk/TestExpectations	2012-09-07 12:51:44 UTC (rev 127862)
@@ -424,6 +424,9 @@
 BUGWK92942 SKIP : fast/dom/Proximity = PASS
 BUGWK92942 SKIP : fast/events/constructors/device-proximity-event-constructor.html = PASS
 
+// Mac and Win does not have global selections.
+WONTFIX MAC WIN : editing/pasteboard/paste-global-selection.html = TEXT
+
 //////////////////////////////////////////////////////////////////////////////////////////
 // End of Expected failures
 //////////////////////////////////////////////////////////////////////////////////////////

Modified: trunk/LayoutTests/platform/mac/Skipped (127861 => 127862)


--- trunk/LayoutTests/platform/mac/Skipped	2012-09-07 12:32:51 UTC (rev 127861)
+++ trunk/LayoutTests/platform/mac/Skipped	2012-09-07 12:51:44 UTC (rev 127862)
@@ -1033,6 +1033,9 @@
 platform/mac/editing/spelling/delete-autocorrected-word-1.html
 platform/mac/editing/spelling/delete-autocorrected-word-2.html
 
+// Mac does not have global selections.
+editing/pasteboard/paste-global-selection.html
+
 # --- WebGL ---
 # Currently failing WebGL tests <rdar://problem/9355460>
 fast/canvas/webgl/tex-image-and-sub-image-2d-with-video.html

Modified: trunk/LayoutTests/platform/qt-mac/Skipped (127861 => 127862)


--- trunk/LayoutTests/platform/qt-mac/Skipped	2012-09-07 12:32:51 UTC (rev 127861)
+++ trunk/LayoutTests/platform/qt-mac/Skipped	2012-09-07 12:51:44 UTC (rev 127862)
@@ -4,6 +4,9 @@
 # requires video.buffered to be able to return multiple timeranges
 http/tests/media/video-buffered.html
 
+// Mac does not have global selection
+editing/pasteboard/paste-global-selection.html
+
 # flakey tests
 http/tests/inspector/resource-tree/resource-tree-document-url.html
 http/tests/inspector/resource-tree/resource-tree-frame-add.html

Modified: trunk/LayoutTests/platform/win/Skipped (127861 => 127862)


--- trunk/LayoutTests/platform/win/Skipped	2012-09-07 12:32:51 UTC (rev 127861)
+++ trunk/LayoutTests/platform/win/Skipped	2012-09-07 12:51:44 UTC (rev 127862)
@@ -2220,3 +2220,6 @@
 
 # Dialog element is not yet enabled.
 fast/dom/HTMLDialogElement
+
+// Windows does not have global selection.
+editing/pasteboard/paste-global-selection.html

Modified: trunk/Source/WebCore/ChangeLog (127861 => 127862)


--- trunk/Source/WebCore/ChangeLog	2012-09-07 12:32:51 UTC (rev 127861)
+++ trunk/Source/WebCore/ChangeLog	2012-09-07 12:51:44 UTC (rev 127862)
@@ -1,3 +1,34 @@
+2012-09-07  Allan Sandfeld Jensen  <allan.jen...@nokia.com>
+
+        X11 Global Selection
+        https://bugs.webkit.org/show_bug.cgi?id=88238
+
+        Reviewed by Tony Chang.
+
+        In X11 global selection is the ability to share the active selection
+        between applications and pasting with middle mouse-button.
+
+        This patch moves the implementations of global selection from the 
+        separate implementations in Qt WebKit, Chromium and GTK to WebCore,
+        by implementing a new EditorCommand for pasting the global selection.
+
+        Test: editing/pasteboard/paste-global-selection.html
+
+        * editing/EditorCommand.cpp:
+        (WebCore::executePasteGlobalSelection):
+        (WebCore::createCommandMap):
+        * page/EditorClient.h:
+        (EditorClient):
+        (WebCore::EditorClient::supportsGlobalSelection):
+        * platform/Pasteboard.h:
+        (WebCore::Pasteboard::isSelectionMode):
+        (WebCore::Pasteboard::setSelectionMode):
+        * platform/gtk/PasteboardGtk.cpp:
+        (WebCore::Pasteboard::writeSelection):
+        (WebCore::Pasteboard::writeURL):
+        (WebCore::Pasteboard::isSelectionMode):
+        (WebCore::Pasteboard::setSelectionMode):
+
 2012-09-06  Vsevolod Vlasov  <vse...@chromium.org>
 
         Web Inspector: Migrate Database to async protocol commands

Modified: trunk/Source/WebCore/editing/EditorCommand.cpp (127861 => 127862)


--- trunk/Source/WebCore/editing/EditorCommand.cpp	2012-09-07 12:32:51 UTC (rev 127861)
+++ trunk/Source/WebCore/editing/EditorCommand.cpp	2012-09-07 12:51:44 UTC (rev 127862)
@@ -49,6 +49,7 @@
 #include "InsertListCommand.h"
 #include "KillRing.h"
 #include "Page.h"
+#include "Pasteboard.h"
 #include "RenderBox.h"
 #include "ReplaceSelectionCommand.h"
 #include "Scrollbar.h"
@@ -916,6 +917,20 @@
     return true;
 }
 
+static bool executePasteGlobalSelection(Frame* frame, Event*, EditorCommandSource source, const String&)
+{
+    if (!frame->editor()->client()->supportsGlobalSelection())
+        return false;
+    ASSERT_UNUSED(source, source == CommandFromMenuOrKeyBinding);
+    UserTypingGestureIndicator typingGestureIndicator(frame);
+
+    bool oldSelectionMode = Pasteboard::generalPasteboard()->isSelectionMode();
+    Pasteboard::generalPasteboard()->setSelectionMode(true);
+    frame->editor()->paste();
+    Pasteboard::generalPasteboard()->setSelectionMode(oldSelectionMode);
+    return true;
+}
+
 static bool executePasteAndMatchStyle(Frame* frame, Event*, EditorCommandSource source, const String&)
 {
     if (source == CommandFromMenuOrKeyBinding) {
@@ -1544,6 +1559,7 @@
         { "Paste", { executePaste, supportedPaste, enabledPaste, stateNone, valueNull, notTextInsertion, allowExecutionWhenDisabled } },
         { "PasteAndMatchStyle", { executePasteAndMatchStyle, supportedPaste, enabledPaste, stateNone, valueNull, notTextInsertion, allowExecutionWhenDisabled } },
         { "PasteAsPlainText", { executePasteAsPlainText, supportedPaste, enabledPaste, stateNone, valueNull, notTextInsertion, allowExecutionWhenDisabled } },
+        { "PasteGlobalSelection", { executePasteGlobalSelection, supportedFromMenuOrKeyBinding, enabledPaste, stateNone, valueNull, notTextInsertion, allowExecutionWhenDisabled } },
         { "Print", { executePrint, supported, enabled, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
         { "Redo", { executeRedo, supported, enabledRedo, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
         { "RemoveFormat", { executeRemoveFormat, supported, enabledRangeInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },

Modified: trunk/Source/WebCore/page/EditorClient.h (127861 => 127862)


--- trunk/Source/WebCore/page/EditorClient.h	2012-09-07 12:32:51 UTC (rev 127861)
+++ trunk/Source/WebCore/page/EditorClient.h	2012-09-07 12:51:44 UTC (rev 127862)
@@ -155,6 +155,10 @@
     virtual bool spellingUIIsShowing() = 0;
     virtual void willSetInputMethodState() = 0;
     virtual void setInputMethodState(bool enabled) = 0;
+
+    // Support for global selections, used on platforms like the X Window System that treat
+    // selection as a type of clipboard.
+    virtual bool supportsGlobalSelection() { return false; }
 };
 
 }

Modified: trunk/Source/WebCore/platform/Pasteboard.h (127861 => 127862)


--- trunk/Source/WebCore/platform/Pasteboard.h	2012-09-07 12:32:51 UTC (rev 127861)
+++ trunk/Source/WebCore/platform/Pasteboard.h	2012-09-07 12:51:44 UTC (rev 127862)
@@ -100,9 +100,12 @@
     PassRefPtr<DocumentFragment> documentFragment(Frame*, PassRefPtr<Range>, bool allowPlainText, bool& chosePlainText);
     String plainText(Frame* = 0);
     
-#if PLATFORM(QT) || PLATFORM(CHROMIUM)
+#if PLATFORM(QT) || PLATFORM(CHROMIUM) || PLATFORM(GTK)
     bool isSelectionMode() const;
-    void setSelectionMode(bool selectionMode);
+    void setSelectionMode(bool);
+#else
+    bool isSelectionMode() const { return false; }
+    void setSelectionMode(bool) { }
 #endif
 
 #if PLATFORM(GTK)

Modified: trunk/Source/WebCore/platform/gtk/PasteboardGtk.cpp (127861 => 127862)


--- trunk/Source/WebCore/platform/gtk/PasteboardGtk.cpp	2012-09-07 12:32:51 UTC (rev 127861)
+++ trunk/Source/WebCore/platform/gtk/PasteboardGtk.cpp	2012-09-07 12:51:44 UTC (rev 127862)
@@ -58,7 +58,7 @@
 void Pasteboard::writeSelection(Range* selectedRange, bool canSmartCopyOrDelete, Frame* frame)
 {
     PasteboardHelper* helper = PasteboardHelper::defaultPasteboardHelper();
-    GtkClipboard* clipboard = helper->getClipboard(frame);
+    GtkClipboard* clipboard = helper->getCurrentClipboard(frame);
 
     DataObjectGtk* dataObject = DataObjectGtk::forClipboard(clipboard);
     dataObject->clearAll();
@@ -85,7 +85,7 @@
         return;
 
     PasteboardHelper* helper = PasteboardHelper::defaultPasteboardHelper();
-    GtkClipboard* clipboard = helper->getClipboard(frame);
+    GtkClipboard* clipboard = helper->getCurrentClipboard(frame);
 
     DataObjectGtk* dataObject = DataObjectGtk::forClipboard(clipboard);
     dataObject->clearAll();
@@ -199,4 +199,14 @@
     return dataObject->text();
 }
 
+bool Pasteboard::isSelectionMode() const
+{
+    return PasteboardHelper::defaultPasteboardHelper()->usePrimarySelectionClipboard();
 }
+
+void Pasteboard::setSelectionMode(bool selectionMode)
+{
+    PasteboardHelper::defaultPasteboardHelper()->setUsePrimarySelectionClipboard(selectionMode);
+}
+
+}

Modified: trunk/Source/WebKit/chromium/ChangeLog (127861 => 127862)


--- trunk/Source/WebKit/chromium/ChangeLog	2012-09-07 12:32:51 UTC (rev 127861)
+++ trunk/Source/WebKit/chromium/ChangeLog	2012-09-07 12:51:44 UTC (rev 127862)
@@ -1,3 +1,19 @@
+2012-09-07  Allan Sandfeld Jensen  <allan.jen...@nokia.com>
+
+        X11 Global Selection
+        https://bugs.webkit.org/show_bug.cgi?id=88238
+
+        Reviewed by Tony Chang.
+
+        Use new editor command for pasting global selection.
+
+        * src/EditorClientImpl.cpp:
+        (WebKit::EditorClientImpl::supportsGlobalSelection):
+        * src/EditorClientImpl.h:
+        (EditorClientImpl):
+        * src/WebViewImpl.cpp:
+        (WebKit::WebViewImpl::handleMouseUp):
+
 2012-09-07  Yoshifumi Inoue  <yo...@chromium.org>
 
         We should have a localized string of empty for date time field

Modified: trunk/Source/WebKit/chromium/src/EditorClientImpl.cpp (127861 => 127862)


--- trunk/Source/WebKit/chromium/src/EditorClientImpl.cpp	2012-09-07 12:32:51 UTC (rev 127861)
+++ trunk/Source/WebKit/chromium/src/EditorClientImpl.cpp	2012-09-07 12:51:44 UTC (rev 127862)
@@ -849,6 +849,15 @@
     notImplemented();
 }
 
+bool EditorClientImpl::supportsGlobalSelection()
+{
+#if OS(UNIX) && !OS(DARWIN)
+    return true;
+#else
+    return false;
+#endif
+}
+
 void EditorClientImpl::willSetInputMethodState()
 {
     if (m_webView->client())

Modified: trunk/Source/WebKit/chromium/src/EditorClientImpl.h (127861 => 127862)


--- trunk/Source/WebKit/chromium/src/EditorClientImpl.h	2012-09-07 12:32:51 UTC (rev 127861)
+++ trunk/Source/WebKit/chromium/src/EditorClientImpl.h	2012-09-07 12:51:44 UTC (rev 127862)
@@ -113,6 +113,7 @@
     virtual void willSetInputMethodState();
     virtual void setInputMethodState(bool enabled);
     virtual void requestCheckingOfString(WTF::PassRefPtr<WebCore::TextCheckingRequest>);
+    virtual bool supportsGlobalSelection() OVERRIDE;
 
     virtual WebCore::TextCheckerClient* textChecker() { return this; }
 

Modified: trunk/Source/WebKit/chromium/src/WebViewImpl.cpp (127861 => 127862)


--- trunk/Source/WebKit/chromium/src/WebViewImpl.cpp	2012-09-07 12:32:51 UTC (rev 127861)
+++ trunk/Source/WebKit/chromium/src/WebViewImpl.cpp	2012-09-07 12:51:44 UTC (rev 127862)
@@ -643,11 +643,7 @@
         // have to be handled separately.
         if (!hitTestResult.scrollbar() && !hitTestResult.isLiveLink() && focused && !view->scrollbarAtPoint(clickPoint)) {
             Editor* editor = focused->editor();
-            Pasteboard* pasteboard = Pasteboard::generalPasteboard();
-            bool oldSelectionMode = pasteboard->isSelectionMode();
-            pasteboard->setSelectionMode(true);
-            editor->command(AtomicString("Paste")).execute();
-            pasteboard->setSelectionMode(oldSelectionMode);
+            editor->command(AtomicString("PasteGlobalSelection")).execute();
         }
     }
 #endif

Modified: trunk/Source/WebKit/qt/Api/qwebpage.cpp (127861 => 127862)


--- trunk/Source/WebKit/qt/Api/qwebpage.cpp	2012-09-07 12:32:51 UTC (rev 127861)
+++ trunk/Source/WebKit/qt/Api/qwebpage.cpp	2012-09-07 12:51:44 UTC (rev 127862)
@@ -757,21 +757,13 @@
 {
 #ifndef QT_NO_CLIPBOARD
     if (QApplication::clipboard()->supportsSelection()) {
-        bool oldSelectionMode = Pasteboard::generalPasteboard()->isSelectionMode();
-        Pasteboard::generalPasteboard()->setSelectionMode(true);
         WebCore::Frame* focusFrame = page->focusController()->focusedOrMainFrame();
-        if (button == Qt::LeftButton) {
-            if (focusFrame && (focusFrame->editor()->canCopy() || focusFrame->editor()->canDHTMLCopy())) {
-                Pasteboard::generalPasteboard()->writeSelection(focusFrame->editor()->selectedRange().get(), focusFrame->editor()->canSmartCopyOrDelete(), focusFrame);
+        if (button == Qt::MidButton) {
+            if (focusFrame) {
+                focusFrame->editor()->command(AtomicString("PasteGlobalSelection")).execute();
                 ev->setAccepted(true);
             }
-        } else if (button == Qt::MidButton) {
-            if (focusFrame && (focusFrame->editor()->canPaste() || focusFrame->editor()->canDHTMLPaste())) {
-                focusFrame->editor()->paste();
-                ev->setAccepted(true);
-            }
         }
-        Pasteboard::generalPasteboard()->setSelectionMode(oldSelectionMode);
     }
 #endif
 }

Modified: trunk/Source/WebKit/qt/ChangeLog (127861 => 127862)


--- trunk/Source/WebKit/qt/ChangeLog	2012-09-07 12:32:51 UTC (rev 127861)
+++ trunk/Source/WebKit/qt/ChangeLog	2012-09-07 12:51:44 UTC (rev 127862)
@@ -1,3 +1,21 @@
+2012-09-07  Allan Sandfeld Jensen  <allan.jen...@nokia.com>
+
+        X11 Global Selection
+        https://bugs.webkit.org/show_bug.cgi?id=88238
+
+        Reviewed by Tony Chang.
+
+        Use new editor command for pasting global selection, and update it using
+        the respondToChangedSelection callback.
+
+        * Api/qwebpage.cpp:
+        (QWebPagePrivate::handleClipboard):
+        * WebCoreSupport/EditorClientQt.cpp:
+        (WebCore::EditorClientQt::respondToChangedSelection):
+        (WebCore::EditorClientQt::supportsGlobalSelection):
+        * WebCoreSupport/EditorClientQt.h:
+        (EditorClientQt):
+
 2012-09-05  Sam Weinig  <s...@webkit.org>
 
         Part 2 of removing PlatformString.h, remove PlatformString.h

Modified: trunk/Source/WebKit/qt/WebCoreSupport/EditorClientQt.cpp (127861 => 127862)


--- trunk/Source/WebKit/qt/WebCoreSupport/EditorClientQt.cpp	2012-09-07 12:32:51 UTC (rev 127861)
+++ trunk/Source/WebKit/qt/WebCoreSupport/EditorClientQt.cpp	2012-09-07 12:51:44 UTC (rev 127862)
@@ -42,6 +42,7 @@
 #include "KeyboardEvent.h"
 #include "NotImplemented.h"
 #include "Page.h"
+#include "Pasteboard.h"
 #include "PlatformKeyboardEvent.h"
 #include "QWebPageClient.h"
 #include "Range.h"
@@ -49,9 +50,11 @@
 #include "SpatialNavigation.h"
 #include "StylePropertySet.h"
 #include "WindowsKeyboardCodes.h"
+#include "qguiapplication.h"
 #include "qwebpage.h"
 #include "qwebpage_p.h"
 
+#include <QClipboard>
 #include <QUndoStack>
 #include <stdio.h>
 #include <wtf/OwnPtr.h>
@@ -210,6 +213,13 @@
 //     selection.formatForDebugger(buffer, sizeof(buffer));
 //     printf("%s\n", buffer);
 
+    if (supportsGlobalSelection() && frame->selection()->isRange()) {
+        bool oldSelectionMode = Pasteboard::generalPasteboard()->isSelectionMode();
+        Pasteboard::generalPasteboard()->setSelectionMode(true);
+        Pasteboard::generalPasteboard()->writeSelection(frame->selection()->toNormalizedRange().get(), frame->editor()->canSmartCopyOrDelete(), frame);
+        Pasteboard::generalPasteboard()->setSelectionMode(oldSelectionMode);
+    }
+
     m_page->d->updateEditorActions();
     emit m_page->selectionChanged();
     if (!frame->editor()->ignoreCompositionSelectionChange())
@@ -632,6 +642,11 @@
     emit m_page->microFocusChanged();
 }
 
+bool EditorClientQt::supportsGlobalSelection()
+{
+    return qApp->clipboard()->supportsSelection();
 }
 
+}
+
 // vim: ts=4 sw=4 et

Modified: trunk/Source/WebKit/qt/WebCoreSupport/EditorClientQt.h (127861 => 127862)


--- trunk/Source/WebKit/qt/WebCoreSupport/EditorClientQt.h	2012-09-07 12:32:51 UTC (rev 127861)
+++ trunk/Source/WebKit/qt/WebCoreSupport/EditorClientQt.h	2012-09-07 12:51:44 UTC (rev 127862)
@@ -105,6 +105,8 @@
     virtual void setInputMethodState(bool enabled);
     virtual TextCheckerClient* textChecker() { return &m_textCheckerClient; }
 
+    virtual bool supportsGlobalSelection() OVERRIDE;
+
     bool isEditing() const;
 
     static bool dumpEditingCallbacks;

Modified: trunk/Source/WebKit2/ChangeLog (127861 => 127862)


--- trunk/Source/WebKit2/ChangeLog	2012-09-07 12:32:51 UTC (rev 127861)
+++ trunk/Source/WebKit2/ChangeLog	2012-09-07 12:51:44 UTC (rev 127862)
@@ -1,3 +1,26 @@
+2012-09-07  Allan Sandfeld Jensen  <allan.jen...@nokia.com>
+
+        X11 Global Selection
+        https://bugs.webkit.org/show_bug.cgi?id=88238
+
+        Reviewed by Tony Chang.
+
+        Implements the hooks for supporting global selections in Qt WebKit2.
+
+        * WebProcess/WebCoreSupport/WebEditorClient.cpp:
+        (WebKit::WebEditorClient::respondToChangedSelection):
+        (WebKit::WebEditorClient::updateGlobalSelection):
+        (WebKit::WebEditorClient::supportsGlobalSelection):
+        * WebProcess/WebCoreSupport/WebEditorClient.h:
+        * WebProcess/WebCoreSupport/gtk/WebEditorClientGtk.cpp:
+        (WebKit::WebEditorClient::updateGlobalSelection):
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::handleMouseEvent):
+        * WebProcess/WebPage/WebPage.h:
+        (WebPage):
+        * WebProcess/WebPage/qt/WebPageQt.cpp:
+        (WebKit::WebPage::handleMouseReleaseEvent):
+
 2012-09-07  Mikhail Pozdnyakov  <mikhail.pozdnya...@intel.com>
 
         [WK2] APIClientTraits<WKPageLoaderClient> and APIClientTraits<WKBundlePageLoaderClient> are not initialized properly

Modified: trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebEditorClient.cpp (127861 => 127862)


--- trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebEditorClient.cpp	2012-09-07 12:32:51 UTC (rev 127861)
+++ trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebEditorClient.cpp	2012-09-07 12:51:44 UTC (rev 127862)
@@ -48,6 +48,12 @@
 #include <WebCore/UndoStep.h>
 #include <WebCore/UserTypingGestureIndicator.h>
 
+#if PLATFORM(QT)
+#include <QClipboard>
+#include <QGuiApplication>
+#include <WebCore/Pasteboard.h>
+#endif
+
 using namespace WebCore;
 using namespace HTMLNames;
 
@@ -195,11 +201,24 @@
     unsigned start;
     unsigned end;
     m_page->send(Messages::WebPageProxy::DidChangeCompositionSelection(frame->editor()->getCompositionSelection(start, end)));
-#elif PLATFORM(GTK)
-    setSelectionPrimaryClipboardIfNeeded(frame);
+#elif PLATFORM(GTK) || PLATFORM(QT)
+    updateGlobalSelection(frame);
 #endif
 }
 
+#if PLATFORM(QT)
+// FIXME: Use this function for other X11-based platforms that need to manually update the global selection.
+void WebEditorClient::updateGlobalSelection(Frame* frame)
+{
+    if (supportsGlobalSelection() && frame->selection()->isRange()) {
+        bool oldSelectionMode = Pasteboard::generalPasteboard()->isSelectionMode();
+        Pasteboard::generalPasteboard()->setSelectionMode(true);
+        Pasteboard::generalPasteboard()->writeSelection(frame->selection()->toNormalizedRange().get(), frame->editor()->canSmartCopyOrDelete(), frame);
+        Pasteboard::generalPasteboard()->setSelectionMode(oldSelectionMode);
+    }
+}
+#endif
+
 void WebEditorClient::didEndEditing()
 {
     DEFINE_STATIC_LOCAL(String, WebViewDidEndEditingNotification, (ASCIILiteral("WebViewDidEndEditingNotification")));
@@ -462,4 +481,16 @@
     notImplemented();
 }
 
+bool WebEditorClient::supportsGlobalSelection()
+{
+#if PLATFORM(QT)
+    return qApp->clipboard()->supportsSelection();
+#elif PLATFORM(GTK) && PLATFORM(X11)
+    return true;
+#else
+    // FIXME: Return true on other X11 platforms when they support global selection.
+    return false;
+#endif
+}
+
 } // namespace WebKit

Modified: trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebEditorClient.h (127861 => 127862)


--- trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebEditorClient.h	2012-09-07 12:32:51 UTC (rev 127861)
+++ trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebEditorClient.h	2012-09-07 12:51:44 UTC (rev 127862)
@@ -124,8 +124,10 @@
 #if PLATFORM(GTK)
     bool executePendingEditorCommands(WebCore::Frame*, Vector<WTF::String>, bool) OVERRIDE;
     void getEditorCommandsForKeyEvent(const WebCore::KeyboardEvent*, Vector<WTF::String>&) OVERRIDE;
-    void setSelectionPrimaryClipboardIfNeeded(WebCore::Frame*) OVERRIDE;
 #endif
+#if PLATFORM(GTK) || PLATFORM(QT)
+    void updateGlobalSelection(WebCore::Frame*);
+#endif
 
     TextCheckerClient* textChecker()  OVERRIDE { return this; }
 
@@ -149,6 +151,9 @@
 #if PLATFORM(GTK)
     virtual bool shouldShowUnicodeMenu() OVERRIDE;
 #endif
+
+    virtual bool supportsGlobalSelection() OVERRIDE;
+
     WebPage* m_page;
 };
 

Modified: trunk/Source/WebKit2/WebProcess/WebCoreSupport/gtk/WebEditorClientGtk.cpp (127861 => 127862)


--- trunk/Source/WebKit2/WebProcess/WebCoreSupport/gtk/WebEditorClientGtk.cpp	2012-09-07 12:32:51 UTC (rev 127861)
+++ trunk/Source/WebKit2/WebProcess/WebCoreSupport/gtk/WebEditorClientGtk.cpp	2012-09-07 12:51:44 UTC (rev 127862)
@@ -170,7 +170,7 @@
 }
 #endif
 
-void WebEditorClient::setSelectionPrimaryClipboardIfNeeded(Frame* frame)
+void WebEditorClient::updateGlobalSelection(Frame* frame)
 {
 #if PLATFORM(X11)
     GtkClipboard* clipboard = PasteboardHelper::defaultPasteboardHelper()->getPrimarySelectionClipboard(frame);

Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp (127861 => 127862)


--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp	2012-09-07 12:32:51 UTC (rev 127861)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp	2012-09-07 12:51:44 UTC (rev 127862)
@@ -1352,6 +1352,10 @@
             return handled;
         }
         case PlatformEvent::MouseReleased:
+#if PLATFORM(QT)
+            if (page->handleMouseReleaseEvent(platformMouseEvent))
+                return true;
+#endif
             return frame->eventHandler()->handleMouseReleaseEvent(platformMouseEvent);
         case PlatformEvent::MouseMoved:
             if (onlyUpdateScrollbars)

Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h (127861 => 127862)


--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h	2012-09-07 12:32:51 UTC (rev 127861)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h	2012-09-07 12:51:44 UTC (rev 127862)
@@ -460,6 +460,10 @@
 #endif
 #endif
 
+#if PLATFORM(QT)
+    bool handleMouseReleaseEvent(const WebCore::PlatformMouseEvent&);
+#endif
+
     void setCompositionForTesting(const String& compositionString, uint64_t from, uint64_t length);
     bool hasCompositionForTesting();
     void confirmCompositionForTesting(const String& compositionString);

Modified: trunk/Source/WebKit2/WebProcess/WebPage/qt/WebPageQt.cpp (127861 => 127862)


--- trunk/Source/WebKit2/WebProcess/WebPage/qt/WebPageQt.cpp	2012-09-07 12:32:51 UTC (rev 127861)
+++ trunk/Source/WebKit2/WebProcess/WebPage/qt/WebPageQt.cpp	2012-09-07 12:51:44 UTC (rev 127862)
@@ -34,6 +34,8 @@
 #include "WebPageProxyMessages.h"
 #include "WebPopupMenu.h"
 #include "WebProcess.h"
+#include <QClipboard>
+#include <QGuiApplication>
 #include <WebCore/DOMWrapperWorld.h>
 #include <WebCore/FocusController.h>
 #include <WebCore/Frame.h>
@@ -438,4 +440,19 @@
     m_activePopupMenu = 0;
 }
 
+bool WebPage::handleMouseReleaseEvent(const PlatformMouseEvent& platformMouseEvent)
+{
+    if (platformMouseEvent.button() != WebCore::MiddleButton)
+        return false;
+
+    if (qApp->clipboard()->supportsSelection()) {
+        WebCore::Frame* focusFrame = m_page->focusController()->focusedOrMainFrame();
+        if (focusFrame) {
+            focusFrame->editor()->command(AtomicString("PasteGlobalSelection")).execute();
+            return true;
+        }
+    }
+    return false;
+}
+
 } // namespace WebKit
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to