Skip to content

Instantly share code, notes, and snippets.

@kenchris
Created January 10, 2012 13:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kenchris/1588972 to your computer and use it in GitHub Desktop.
Save kenchris/1588972 to your computer and use it in GitHub Desktop.
commit cb7d28aecce8516fb5be9b268697e178d410fb44
Author: Kenneth Rohde Christiansen <kenneth@webkit.org>
Date: Mon Jan 9 17:19:40 2012 +0100
Implement the input panel request/close handling
Reviewed by NOBODY (OOPS!).
With the current patch we only request the input panel as a
response to a user tap. Close requests, on the other hand,
is always respected.
As multiple show/hide requests can happen while processing
the tap gesture, input panel visibility changes are postponed
until the tap gesture ends.
The input panel will become visible if the WebCore editor is
in canEdit mode and thus work for content-editable, meaning
that it won't close the input panel if you click on a link
(eg. editCommand) while in content-editable mode.
* UIProcess/PageClient.h:
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::handleGestureEvent):
(WebKit::WebPageProxy::editorStateChanged):
(WebKit::WebPageProxy::didReceiveEvent):
Add a new doneWithGestureEvent method to the PageClient
as well as add a updateTextInputState similar to that of mac.
* UIProcess/WebPageProxy.h:
* UIProcess/qt/QtPageClient.cpp:
(QtPageClient::updateTextInputState):
(QtPageClient::doneWithGestureEvent):
Propagate the new events to the Qt EventHandler.
* UIProcess/qt/QtPageClient.h:
* UIProcess/qt/QtWebPageEventHandler.cpp:
* UIProcess/qt/QtWebPageEventHandler.h:
(QtWebPageEventHandler::QtWebPageEventHandler):
(QtWebPageEventHandler::handleSingleTapEvent):
(setInputPanelVisible):
(QtWebPageEventHandler::updateTextInputState):
(QtWebPageEventHandler::doneWithGestureEvent):
Handle postponing of the input method visibility change
and the actual showing/hiding.
diff --git a/Source/WebKit2/ChangeLog b/Source/WebKit2/ChangeLog
index 6b1bc14..8dc81cb 100644
--- a/Source/WebKit2/ChangeLog
+++ b/Source/WebKit2/ChangeLog
@@ -1,3 +1,50 @@
+2012-01-10 Kenneth Rohde Christiansen <kenneth@webkit.org>
+
+ Implement the input panel request/close handling
+
+ Reviewed by NOBODY (OOPS!).
+
+ With the current patch we only request the input panel as a
+ response to a user tap. Close requests, on the other hand,
+ is always respected.
+
+ As multiple show/hide requests can happen while processing
+ the tap gesture, input panel visibility changes are postponed
+ until the tap gesture ends.
+
+ The input panel will become visible if the WebCore editor is
+ in canEdit mode and thus work for content-editable, meaning
+ that it won't close the input panel if you click on a link
+ (eg. editCommand) while in content-editable mode.
+
+ * UIProcess/PageClient.h:
+ * UIProcess/WebPageProxy.cpp:
+ (WebKit::WebPageProxy::handleGestureEvent):
+ (WebKit::WebPageProxy::editorStateChanged):
+ (WebKit::WebPageProxy::didReceiveEvent):
+
+ Add a new doneWithGestureEvent method to the PageClient
+ as well as add a updateTextInputState similar to that of mac.
+
+ * UIProcess/WebPageProxy.h:
+ * UIProcess/qt/QtPageClient.cpp:
+ (QtPageClient::updateTextInputState):
+ (QtPageClient::doneWithGestureEvent):
+
+ Propagate the new events to the Qt EventHandler.
+
+ * UIProcess/qt/QtPageClient.h:
+ * UIProcess/qt/QtWebPageEventHandler.cpp:
+ * UIProcess/qt/QtWebPageEventHandler.h:
+ (QtWebPageEventHandler::QtWebPageEventHandler):
+ (QtWebPageEventHandler::handleSingleTapEvent):
+ (setInputPanelVisible):
+ (QtWebPageEventHandler::updateTextInputState):
+ (QtWebPageEventHandler::doneWithGestureEvent):
+
+ Handle postponing of the input method visibility change
+ and the actual showing/hiding.
+
2012-01-09 Andras Becsi <andras.becsi@nokia.com>
[Qt][WK2] Pinch zoom should affect the page size
diff --git a/Source/WebKit2/UIProcess/PageClient.h b/Source/WebKit2/UIProcess/PageClient.h
index 1db4eaa..16fc879 100644
--- a/Source/WebKit2/UIProcess/PageClient.h
+++ b/Source/WebKit2/UIProcess/PageClient.h
@@ -106,6 +106,7 @@ public:
virtual void focusEditableArea(const WebCore::IntRect&, const WebCore::IntRect&) = 0;
virtual void didReceiveMessageFromNavigatorQtObject(const String&) = 0;
virtual void handleDownloadRequest(DownloadProxy*) = 0;
+ virtual void updateTextInputState() = 0;
#endif
#if PLATFORM(QT) || PLATFORM(GTK)
@@ -141,6 +142,9 @@ public:
virtual WebCore::IntRect windowToScreen(const WebCore::IntRect&) = 0;
virtual void doneWithKeyEvent(const NativeWebKeyboardEvent&, bool wasEventHandled) = 0;
+#if ENABLE(GESTURE_EVENTS)
+ virtual void doneWithGestureEvent(const WebGestureEvent&, bool wasEventHandled) = 0;
+#endif
#if ENABLE(TOUCH_EVENTS)
virtual void doneWithTouchEvent(const NativeWebTouchEvent&, bool wasEventHandled) = 0;
#endif
diff --git a/Source/WebKit2/UIProcess/WebPageProxy.cpp b/Source/WebKit2/UIProcess/WebPageProxy.cpp
index 15abf9c..452a435 100644
--- a/Source/WebKit2/UIProcess/WebPageProxy.cpp
+++ b/Source/WebKit2/UIProcess/WebPageProxy.cpp
@@ -968,6 +968,8 @@ void WebPageProxy::handleGestureEvent(const WebGestureEvent& event)
if (!isValid())
return;
+ m_gestureEventQueue.append(event);
+
process()->responsivenessTimer()->start();
process()->send(Messages::EventDispatcher::GestureEvent(m_pageID, event), 0);
}
@@ -2427,6 +2429,8 @@ void WebPageProxy::editorStateChanged(const EditorState& editorState)
#if PLATFORM(MAC)
m_pageClient->updateTextInputState(couldChangeSecureInputState);
+#elif PLATFORM(QT)
+ m_pageClient->updateTextInputState();
#endif
}
@@ -2911,9 +2915,15 @@ void WebPageProxy::didReceiveEvent(uint32_t opaqueType, bool handled)
#if ENABLE(GESTURE_EVENTS)
case WebEvent::GestureScrollBegin:
case WebEvent::GestureScrollEnd:
- case WebEvent::GestureSingleTap:
-#endif
+ case WebEvent::GestureSingleTap: {
+ WebGestureEvent event = m_gestureEventQueue.first();
+ MESSAGE_CHECK(type == event.type());
+
+ m_gestureEventQueue.removeFirst();
+ m_pageClient->doneWithGestureEvent(event, handled);
break;
+ }
+#endif
case WebEvent::MouseUp:
m_currentlyProcessedMouseDownEvent = nullptr;
break;
diff --git a/Source/WebKit2/UIProcess/WebPageProxy.h b/Source/WebKit2/UIProcess/WebPageProxy.h
index 42a18f3..9a51b36 100644
--- a/Source/WebKit2/UIProcess/WebPageProxy.h
+++ b/Source/WebKit2/UIProcess/WebPageProxy.h
@@ -952,6 +952,7 @@ private:
WebCore::PolicyAction m_syncNavigationActionPolicyAction;
uint64_t m_syncNavigationActionPolicyDownloadID;
+ Deque<WebGestureEvent> m_gestureEventQueue;
Deque<NativeWebKeyboardEvent> m_keyEventQueue;
Deque<NativeWebWheelEvent> m_wheelEventQueue;
Vector<NativeWebWheelEvent> m_currentlyProcessedWheelEvents;
diff --git a/Source/WebKit2/UIProcess/qt/QtPageClient.cpp b/Source/WebKit2/UIProcess/qt/QtPageClient.cpp
index b173776..cc96876 100644
--- a/Source/WebKit2/UIProcess/qt/QtPageClient.cpp
+++ b/Source/WebKit2/UIProcess/qt/QtPageClient.cpp
@@ -195,6 +195,20 @@ void QtPageClient::didReceiveMessageFromNavigatorQtObject(const String& message)
QQuickWebViewPrivate::get(m_webView)->didReceiveMessageFromNavigatorQtObject(message);
}
+void QtPageClient::updateTextInputState()
+{
+ ASSERT(m_eventHandler);
+ m_eventHandler->updateTextInputState();
+}
+
+#if ENABLE(GESTURE_EVENTS)
+void QtPageClient::doneWithGestureEvent(const WebGestureEvent& event, bool wasEventHandled)
+{
+ ASSERT(m_eventHandler);
+ m_eventHandler->doneWithGestureEvent(event, wasEventHandled);
+}
+#endif
+
#if ENABLE(TOUCH_EVENTS)
void QtPageClient::doneWithTouchEvent(const NativeWebTouchEvent& event, bool wasEventHandled)
{
diff --git a/Source/WebKit2/UIProcess/qt/QtPageClient.h b/Source/WebKit2/UIProcess/qt/QtPageClient.h
index a3149b6..7715026 100644
--- a/Source/WebKit2/UIProcess/qt/QtPageClient.h
+++ b/Source/WebKit2/UIProcess/qt/QtPageClient.h
@@ -93,10 +93,9 @@ public:
virtual void countStringMatchesInCustomRepresentation(const String&, WebKit::FindOptions, unsigned maxMatchCount) { }
virtual void didFindZoomableArea(const WebCore::IntPoint&, const WebCore::IntRect&);
virtual void focusEditableArea(const WebCore::IntRect&, const WebCore::IntRect&);
-
-#if ENABLE(TOUCH_EVENTS)
+ virtual void updateTextInputState();
+ virtual void doneWithGestureEvent(const WebGestureEvent&, bool wasEventHandled);
virtual void doneWithTouchEvent(const NativeWebTouchEvent&, bool wasEventHandled);
-#endif
private:
QQuickWebView* m_webView;
diff --git a/Source/WebKit2/UIProcess/qt/QtWebPageEventHandler.cpp b/Source/WebKit2/UIProcess/qt/QtWebPageEventHandler.cpp
index 2576e85..6800fe3 100644
--- a/Source/WebKit2/UIProcess/qt/QtWebPageEventHandler.cpp
+++ b/Source/WebKit2/UIProcess/qt/QtWebPageEventHandler.cpp
@@ -29,7 +29,9 @@
#include <QDrag>
#include <QGraphicsSceneMouseEvent>
#include <QGuiApplication>
+#include <QInputPanel>
#include <QMimeData>
+#include <QtDebug>
#include <QtQuick/QQuickCanvas>
#include <QStyleHints>
#include <QTextFormat>
@@ -91,6 +93,7 @@ QtWebPageEventHandler::QtWebPageEventHandler(WKPageRef pageRef, QQuickWebPage* q
, m_webPage(qmlWebPage)
, m_previousClickButton(Qt::NoButton)
, m_clickCount(0)
+ , m_postponeTextInputStateChanged(false)
{
}
@@ -282,6 +285,8 @@ bool QtWebPageEventHandler::handleDropEvent(QDropEvent* ev)
void QtWebPageEventHandler::handleSingleTapEvent(const QTouchEvent::TouchPoint& point)
{
+ m_postponeTextInputStateChanged = true;
+
QTransform fromItemTransform = m_webPage->transformFromItem();
WebGestureEvent gesture(WebEvent::GestureSingleTap, fromItemTransform.map(point.pos()).toPoint(), point.screenPos().toPoint(), WebEvent::Modifiers(0), 0);
m_webPageProxy->handleGestureEvent(gesture);
@@ -417,6 +422,44 @@ void QtWebPageEventHandler::resetGestureRecognizers()
m_tapGestureRecognizer.reset();
}
+static void setInputPanelVisible(bool visible)
+{
+ if (qApp->inputPanel()->visible() == visible)
+ return;
+
+ qWarning() << "input panel:" << ((visible) ? "show" : "hide");
+
+ qApp->inputPanel()->setVisible(visible);
+}
+
+void QtWebPageEventHandler::updateTextInputState()
+{
+ if (m_postponeTextInputStateChanged)
+ return;
+
+ const EditorState& editor = m_webPageProxy->editorState();
+
+ // Ignore input method requests not due to a tap gesture.
+ if (!editor.isContentEditable)
+ setInputPanelVisible(false);
+}
+
+void QtWebPageEventHandler::doneWithGestureEvent(const WebGestureEvent& event, bool wasEventHandled)
+{
+ if (event.type() != WebEvent::GestureSingleTap)
+ return;
+
+ m_postponeTextInputStateChanged = false;
+
+ if (!wasEventHandled)
+ return;
+
+ const EditorState& editor = m_webPageProxy->editorState();
+ bool newVisible = editor.isContentEditable;
+
+ setInputPanelVisible(newVisible);
+}
+
void QtWebPageEventHandler::doneWithTouchEvent(const NativeWebTouchEvent& event, bool wasEventHandled)
{
if (!m_interactionEngine)
diff --git a/Source/WebKit2/UIProcess/qt/QtWebPageEventHandler.h b/Source/WebKit2/UIProcess/qt/QtWebPageEventHandler.h
index f2de6c7..f5b7fb3 100644
--- a/Source/WebKit2/UIProcess/qt/QtWebPageEventHandler.h
+++ b/Source/WebKit2/UIProcess/qt/QtWebPageEventHandler.h
@@ -52,6 +52,8 @@ public:
void didFindZoomableArea(const WebCore::IntPoint& target, const WebCore::IntRect& area);
void focusEditableArea(const WebCore::IntRect& caret, const WebCore::IntRect& area);
+ void updateTextInputState();
+ void doneWithGestureEvent(const WebGestureEvent& event, bool wasEventHandled);
void doneWithTouchEvent(const NativeWebTouchEvent&, bool wasEventHandled);
void resetGestureRecognizers();
@@ -92,6 +94,7 @@ private:
QBasicTimer m_clickTimer;
Qt::MouseButton m_previousClickButton;
int m_clickCount;
+ bool m_postponeTextInputStateChanged;
};
#endif /* QtWebPageEventHandler_h */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment