Title: [153884] trunk/Source
Revision
153884
Author
[email protected]
Date
2013-08-09 05:11:20 -0700 (Fri, 09 Aug 2013)

Log Message

[Qt] QtWebKit should allow sending domain specific keycode to HTML applications
https://bugs.webkit.org/show_bug.cgi?id=118445

Patch by Arunprasad Rajkumar <[email protected]> on 2013-08-09
Reviewed by Allan Sandfeld Jensen.

Source/WebCore:

No new test required, it is covered by QtWebKit API test.

This fix allows sending QKeyEvent::nativeVirtualKey as the DOM KeyboardEvent keyCode value instead
of Windows virtual key code. It can be enabled/disabled using "_q_useNativeVirtualKeyAsDOMKey"
dynamic property present in QWebPage.

* platform/PlatformKeyboardEvent.h:
(WebCore::PlatformKeyboardEvent::PlatformKeyboardEvent):
* platform/qt/PlatformKeyboardEventQt.cpp:
(WebCore::PlatformKeyboardEvent::PlatformKeyboardEvent):
(WebCore::PlatformKeyboardEvent::disambiguateKeyDownEvent):

Source/WebKit/qt:

Added API test.

* WebCoreSupport/QWebPageAdapter.cpp:
(QWebPageAdapter::QWebPageAdapter):
(QWebPageAdapter::dynamicPropertyChangeEvent):
(QWebPageAdapter::handleKeyEvent):
* WebCoreSupport/QWebPageAdapter.h:
* tests/qwebpage/tst_qwebpage.cpp:
(tst_QWebPage::domainSpecificKeyEvent):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (153883 => 153884)


--- trunk/Source/WebCore/ChangeLog	2013-08-09 12:08:28 UTC (rev 153883)
+++ trunk/Source/WebCore/ChangeLog	2013-08-09 12:11:20 UTC (rev 153884)
@@ -1,3 +1,22 @@
+2013-08-09  Arunprasad Rajkumar  <[email protected]>
+
+        [Qt] QtWebKit should allow sending domain specific keycode to HTML applications
+        https://bugs.webkit.org/show_bug.cgi?id=118445
+
+        Reviewed by Allan Sandfeld Jensen.
+
+        No new test required, it is covered by QtWebKit API test.
+
+        This fix allows sending QKeyEvent::nativeVirtualKey as the DOM KeyboardEvent keyCode value instead
+        of Windows virtual key code. It can be enabled/disabled using "_q_useNativeVirtualKeyAsDOMKey"
+        dynamic property present in QWebPage.
+
+        * platform/PlatformKeyboardEvent.h:
+        (WebCore::PlatformKeyboardEvent::PlatformKeyboardEvent):
+        * platform/qt/PlatformKeyboardEventQt.cpp:
+        (WebCore::PlatformKeyboardEvent::PlatformKeyboardEvent):
+        (WebCore::PlatformKeyboardEvent::disambiguateKeyDownEvent):
+
 2013-08-09  Renata Hodovan  <[email protected]>
 
         Missing NULL check in ApplyStyleCommand::applyInlineStyleToNodeRange()

Modified: trunk/Source/WebCore/platform/PlatformKeyboardEvent.h (153883 => 153884)


--- trunk/Source/WebCore/platform/PlatformKeyboardEvent.h	2013-08-09 12:08:28 UTC (rev 153883)
+++ trunk/Source/WebCore/platform/PlatformKeyboardEvent.h	2013-08-09 12:11:20 UTC (rev 153884)
@@ -81,6 +81,7 @@
 #endif
 #if PLATFORM(QT)
             , m_qtEvent(0)
+            , m_useNativeVirtualKeyAsDOMKey(false)
 #endif
         {
         }
@@ -155,7 +156,7 @@
 #endif
 
 #if PLATFORM(QT)
-        PlatformKeyboardEvent(QKeyEvent*);
+        PlatformKeyboardEvent(QKeyEvent*, bool);
         QKeyEvent* qtEvent() const { return m_qtEvent; }
         uint32_t nativeModifiers() const;
         uint32_t nativeScanCode() const;
@@ -194,6 +195,7 @@
 #endif
 #if PLATFORM(QT)
         QKeyEvent* m_qtEvent;
+        bool m_useNativeVirtualKeyAsDOMKey;
 #endif
     };
     

Modified: trunk/Source/WebCore/platform/qt/PlatformKeyboardEventQt.cpp (153883 => 153884)


--- trunk/Source/WebCore/platform/qt/PlatformKeyboardEventQt.cpp	2013-08-09 12:08:28 UTC (rev 153883)
+++ trunk/Source/WebCore/platform/qt/PlatformKeyboardEventQt.cpp	2013-08-09 12:11:20 UTC (rev 153884)
@@ -814,7 +814,7 @@
     return event->text();
 }
 
-PlatformKeyboardEvent::PlatformKeyboardEvent(QKeyEvent* event)
+PlatformKeyboardEvent::PlatformKeyboardEvent(QKeyEvent* event, bool useNativeVirtualKeyAsDOMKey)
 {
     const int state = event->modifiers();
     m_type = (event->type() == QEvent::KeyRelease) ? PlatformEvent::KeyUp : PlatformEvent::KeyDown;
@@ -829,14 +829,22 @@
     if (state & Qt::MetaModifier)
         m_modifiers |= MetaKey;
 
+    m_useNativeVirtualKeyAsDOMKey = useNativeVirtualKeyAsDOMKey;
     m_text = keyTextForKeyEvent(event);
     m_unmodifiedText = m_text; // FIXME: not correct
     m_keyIdentifier = keyIdentifierForQtKeyCode(event->key());
     m_autoRepeat = event->isAutoRepeat();
     m_isKeypad = (state & Qt::KeypadModifier);
     m_isSystemKey = false;
-    m_windowsVirtualKeyCode = windowsKeyCodeForKeyEvent(event->key(), m_isKeypad);
     m_nativeVirtualKeyCode = event->nativeVirtualKey();
+    // If QKeyEvent::nativeVirtualKey() is valid (!=0) and useNativeVirtualKeyAsDOMKey is set,
+    // then it is a special case desired by QtWebKit embedder to send domain specific keys
+    // to Web Applications intented for platforms like HbbTV,CE-HTML,OIPF,..etc.
+    if (useNativeVirtualKeyAsDOMKey && m_nativeVirtualKeyCode)
+        m_windowsVirtualKeyCode = m_nativeVirtualKeyCode;
+    else
+        m_windowsVirtualKeyCode = windowsKeyCodeForKeyEvent(event->key(), m_isKeypad);
+
     m_macCharCode = 0;
     m_qtEvent = event;
     m_timestamp = WTF::currentTime();
@@ -858,7 +866,7 @@
             we try to detect this situation and still set the text, to ensure that the
             general event handling sends a key press event after this disambiguation.
         */
-        if (m_text.isEmpty() && m_windowsVirtualKeyCode && isVirtualKeyCodeRepresentingCharacter(m_windowsVirtualKeyCode))
+        if (!m_useNativeVirtualKeyAsDOMKey && m_text.isEmpty() && m_windowsVirtualKeyCode && isVirtualKeyCodeRepresentingCharacter(m_windowsVirtualKeyCode))
             m_text.append(UChar(m_windowsVirtualKeyCode));
 
         m_keyIdentifier = String();

Modified: trunk/Source/WebKit/qt/ChangeLog (153883 => 153884)


--- trunk/Source/WebKit/qt/ChangeLog	2013-08-09 12:08:28 UTC (rev 153883)
+++ trunk/Source/WebKit/qt/ChangeLog	2013-08-09 12:11:20 UTC (rev 153884)
@@ -1,3 +1,20 @@
+2013-08-09  Arunprasad Rajkumar  <[email protected]>
+
+        [Qt] QtWebKit should allow sending domain specific keycode to HTML applications
+        https://bugs.webkit.org/show_bug.cgi?id=118445
+
+        Reviewed by Allan Sandfeld Jensen.
+
+        Added API test.
+
+        * WebCoreSupport/QWebPageAdapter.cpp:
+        (QWebPageAdapter::QWebPageAdapter):
+        (QWebPageAdapter::dynamicPropertyChangeEvent):
+        (QWebPageAdapter::handleKeyEvent):
+        * WebCoreSupport/QWebPageAdapter.h:
+        * tests/qwebpage/tst_qwebpage.cpp:
+        (tst_QWebPage::domainSpecificKeyEvent):
+
 2013-08-09  Andreas Kling  <[email protected]>
 
         StyleRule*::properties() should return const references.

Modified: trunk/Source/WebKit/qt/WebCoreSupport/QWebPageAdapter.cpp (153883 => 153884)


--- trunk/Source/WebKit/qt/WebCoreSupport/QWebPageAdapter.cpp	2013-08-09 12:08:28 UTC (rev 153883)
+++ trunk/Source/WebKit/qt/WebCoreSupport/QWebPageAdapter.cpp	2013-08-09 12:11:20 UTC (rev 153884)
@@ -209,6 +209,7 @@
     , forwardUnsupportedContent(false)
     , insideOpenCall(false)
     , clickCausedFocus(false)
+    , m_useNativeVirtualKeyAsDOMKey(false)
     , m_totalBytes(0)
     , m_bytesReceived()
     , networkManager(0)
@@ -838,6 +839,8 @@
     } else if (event->propertyName() == "_q_deadDecodedDataDeletionInterval") {
         double interval = obj->property("_q_deadDecodedDataDeletionInterval").toDouble();
         memoryCache()->setDeadDecodedDataDeletionInterval(interval);
+    }  else if (event->propertyName() == "_q_useNativeVirtualKeyAsDOMKey") {
+        m_useNativeVirtualKeyAsDOMKey = obj->property("_q_useNativeVirtualKeyAsDOMKey").toBool();
     }
 }
 
@@ -1295,7 +1298,7 @@
 bool QWebPageAdapter::handleKeyEvent(QKeyEvent *ev)
 {
     Frame* frame = page->focusController()->focusedOrMainFrame();
-    return frame->eventHandler()->keyEvent(ev);
+    return frame->eventHandler()->keyEvent(PlatformKeyboardEvent(ev, m_useNativeVirtualKeyAsDOMKey));
 }
 
 bool QWebPageAdapter::handleScrolling(QKeyEvent *ev)

Modified: trunk/Source/WebKit/qt/WebCoreSupport/QWebPageAdapter.h (153883 => 153884)


--- trunk/Source/WebKit/qt/WebCoreSupport/QWebPageAdapter.h	2013-08-09 12:08:28 UTC (rev 153883)
+++ trunk/Source/WebKit/qt/WebCoreSupport/QWebPageAdapter.h	2013-08-09 12:11:20 UTC (rev 153884)
@@ -359,6 +359,7 @@
     QBasicTimer tripleClickTimer;
 
     bool clickCausedFocus;
+    bool m_useNativeVirtualKeyAsDOMKey;
     quint64 m_totalBytes;
     quint64 m_bytesReceived;
     QWebHistory history;

Modified: trunk/Source/WebKit/qt/tests/qwebpage/tst_qwebpage.cpp (153883 => 153884)


--- trunk/Source/WebKit/qt/tests/qwebpage/tst_qwebpage.cpp	2013-08-09 12:08:28 UTC (rev 153883)
+++ trunk/Source/WebKit/qt/tests/qwebpage/tst_qwebpage.cpp	2013-08-09 12:11:20 UTC (rev 153884)
@@ -114,6 +114,7 @@
     void contextMenuCopy();
     void contextMenuPopulatedOnce();
     void acceptNavigationRequest();
+    void domainSpecificKeyEvent();
     void geolocationRequestJS();
     void loadFinished();
     void actionStates();
@@ -283,6 +284,58 @@
     m_view->setPage(0);
 }
 
+void tst_QWebPage::domainSpecificKeyEvent()
+{
+    QWebView webView;
+    webView.show();
+    QTest::qWaitForWindowExposed(&webView);
+
+    webView.setHtml(QLatin1String("<html><head>"
+        "<script>"
+        "var receivedKeyArray = new Array();"
+        "function keyEvent(e) {"
+        "receivedKeyArray.push(e.type+':'+e.keyCode+':'+e.charCode);"
+        "};"
+        "window._onkeyup_ = keyEvent; window._onkeypress_ = keyEvent; window._onkeydown_ = keyEvent;"
+        "</script></head><body>test</body></html>"));
+
+    // Enable settings to use nativeVirtualKey as DOM key value.
+    webView.page()->setProperty("_q_useNativeVirtualKeyAsDOMKey", true);
+    // Simulate domain specific keyevent to WebKit by passing it as nativeVirtualKey in QKeyEvent.
+    // Qt::Key_Pause --> 0x51
+    QKeyEvent keyEvent(QEvent::KeyPress, Qt::Key_Pause, Qt::NoModifier, 0, 81, 0);
+    QApplication::sendEvent(&webView, &keyEvent);
+    keyEvent = QKeyEvent(QEvent::KeyRelease, Qt::Key_Pause, Qt::NoModifier, 0, 81, 0);
+    QApplication::sendEvent(&webView, &keyEvent);
+    const QLatin1String expectedReceivedKeyArray1("keydown:81:0,keyup:81:0");
+    QString receivedKeyArray = webView.page()->mainFrame()->evaluateJavaScript(QLatin1String("receivedKeyArray")).toStringList().join(",");
+    QVERIFY(receivedKeyArray == expectedReceivedKeyArray1);
+
+    // Normal PC keyboard key converstion flow shouldn't be affected when sending nativeVirtual key as 0.
+    // Qt::Key_Pause --> VK_PAUSE(0x13)
+    webView.page()->mainFrame()->evaluateJavaScript(QLatin1String("receivedKeyArray = new Array()")); // Reset
+    keyEvent = QKeyEvent(QEvent::KeyPress, Qt::Key_Pause, Qt::NoModifier, 0, 0, 0);
+    QApplication::sendEvent(&webView, &keyEvent);
+    keyEvent = QKeyEvent(QEvent::KeyRelease, Qt::Key_Pause, Qt::NoModifier, 0, 0, 0);
+    QApplication::sendEvent(&webView, &keyEvent);
+    const QLatin1String expectedReceivedKeyArray2("keydown:19:0,keyup:19:0");
+    receivedKeyArray = webView.page()->mainFrame()->evaluateJavaScript(QLatin1String("receivedKeyArray")).toStringList().join(",");
+    QVERIFY(receivedKeyArray == expectedReceivedKeyArray2);
+
+    // Negative case.
+    // Disable settings to use nativeVirtualKey as DOM key value.
+    webView.page()->setProperty("_q_useNativeVirtualKeyAsDOMKey", false);
+    // Qt::Key_Pause --> VK_PAUSE(0x13)
+    webView.page()->mainFrame()->evaluateJavaScript(QLatin1String("receivedKeyArray = new Array()")); // Reset
+    keyEvent = QKeyEvent(QEvent::KeyPress, Qt::Key_Pause, Qt::NoModifier, 0, 81, 0);
+    QApplication::sendEvent(&webView, &keyEvent);
+    keyEvent = QKeyEvent(QEvent::KeyRelease, Qt::Key_Pause, Qt::NoModifier, 0, 81, 0);
+    QApplication::sendEvent(&webView, &keyEvent);
+    const QLatin1String expectedReceivedKeyArray3("keydown:19:0,keyup:19:0");
+    receivedKeyArray = webView.page()->mainFrame()->evaluateJavaScript(QLatin1String("receivedKeyArray")).toStringList().join(",");
+    QVERIFY(receivedKeyArray == expectedReceivedKeyArray3);
+}
+
 class JSTestPage : public QWebPage
 {
 Q_OBJECT
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to