Title: [102136] trunk/Source/WebKit2
Revision
102136
Author
kenn...@webkit.org
Date
2011-12-06 07:24:26 -0800 (Tue, 06 Dec 2011)

Log Message

[Qt] Add initial support for focusing when entering edit mode.

Reviewed by Simon Hausmann.

Next step would be to properly upstream our EditorState code.

* UIProcess/PageClient.h:
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::focusEditableArea):
* UIProcess/WebPageProxy.h:
* UIProcess/WebPageProxy.messages.in:
* UIProcess/qt/QtPageClient.cpp:
(QtPageClient::focusEditableArea):
* UIProcess/qt/QtPageClient.h:
* UIProcess/qt/QtViewportInteractionEngine.cpp:
(WebKit::QtViewportInteractionEngine::itemCoordFromCSS):
(WebKit::QtViewportInteractionEngine::itemRectFromCSS):
(WebKit::QtViewportInteractionEngine::focusEditableArea):
(WebKit::QtViewportInteractionEngine::zoomToAreaGestureEnded):
* UIProcess/qt/QtViewportInteractionEngine.h:
* UIProcess/qt/QtWebPageEventHandler.cpp:
(QtWebPageEventHandler::focusEditableArea):
* UIProcess/qt/QtWebPageEventHandler.h:
* WebProcess/WebCoreSupport/WebEditorClient.cpp:
(WebKit::WebEditorClient::respondToChangedSelection):
(WebKit::WebEditorClient::setInputMethodState):

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (102135 => 102136)


--- trunk/Source/WebKit2/ChangeLog	2011-12-06 15:05:40 UTC (rev 102135)
+++ trunk/Source/WebKit2/ChangeLog	2011-12-06 15:24:26 UTC (rev 102136)
@@ -1,3 +1,32 @@
+2011-12-06  Kenneth Rohde Christiansen  <kenn...@webkit.org>
+
+        [Qt] Add initial support for focusing when entering edit mode.
+
+        Reviewed by Simon Hausmann.
+
+        Next step would be to properly upstream our EditorState code.
+
+        * UIProcess/PageClient.h:
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::focusEditableArea):
+        * UIProcess/WebPageProxy.h:
+        * UIProcess/WebPageProxy.messages.in:
+        * UIProcess/qt/QtPageClient.cpp:
+        (QtPageClient::focusEditableArea):
+        * UIProcess/qt/QtPageClient.h:
+        * UIProcess/qt/QtViewportInteractionEngine.cpp:
+        (WebKit::QtViewportInteractionEngine::itemCoordFromCSS):
+        (WebKit::QtViewportInteractionEngine::itemRectFromCSS):
+        (WebKit::QtViewportInteractionEngine::focusEditableArea):
+        (WebKit::QtViewportInteractionEngine::zoomToAreaGestureEnded):
+        * UIProcess/qt/QtViewportInteractionEngine.h:
+        * UIProcess/qt/QtWebPageEventHandler.cpp:
+        (QtWebPageEventHandler::focusEditableArea):
+        * UIProcess/qt/QtWebPageEventHandler.h:
+        * WebProcess/WebCoreSupport/WebEditorClient.cpp:
+        (WebKit::WebEditorClient::respondToChangedSelection):
+        (WebKit::WebEditorClient::setInputMethodState):
+
 2011-12-06  Alexander Færøy  <alexander.fae...@nokia.com>
 
         [Qt] Fix assertion in QtWebPageEventHandler.cpp

Modified: trunk/Source/WebKit2/UIProcess/PageClient.h (102135 => 102136)


--- trunk/Source/WebKit2/UIProcess/PageClient.h	2011-12-06 15:05:40 UTC (rev 102135)
+++ trunk/Source/WebKit2/UIProcess/PageClient.h	2011-12-06 15:24:26 UTC (rev 102136)
@@ -107,6 +107,7 @@
 #if PLATFORM(QT)
     virtual void didChangeContentsSize(const WebCore::IntSize&) = 0;
     virtual void didFindZoomableArea(const WebCore::IntPoint&, const WebCore::IntRect&) = 0;
+    virtual void focusEditableArea(const WebCore::IntRect&, const WebCore::IntRect&) = 0;
     virtual void didReceiveMessageFromNavigatorQtObject(const String&) = 0;
     virtual void handleDownloadRequest(DownloadProxy*) = 0;
 #endif

Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp (102135 => 102136)


--- trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp	2011-12-06 15:05:40 UTC (rev 102135)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp	2011-12-06 15:24:26 UTC (rev 102136)
@@ -2323,6 +2323,11 @@
     m_pageClient->didFindZoomableArea(target, area);
 }
 
+void WebPageProxy::focusEditableArea(const WebCore::IntRect& caret, const WebCore::IntRect& area)
+{
+    m_pageClient->focusEditableArea(caret, area);
+}
+
 void WebPageProxy::findZoomableAreaForPoint(const IntPoint& point)
 {
     if (!isValid())

Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.h (102135 => 102136)


--- trunk/Source/WebKit2/UIProcess/WebPageProxy.h	2011-12-06 15:05:40 UTC (rev 102135)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.h	2011-12-06 15:24:26 UTC (rev 102136)
@@ -692,6 +692,7 @@
 #if PLATFORM(QT)
     void didChangeContentsSize(const WebCore::IntSize&);
     void didFindZoomableArea(const WebCore::IntPoint&, const WebCore::IntRect&);
+    void focusEditableArea(const WebCore::IntRect& caret, const WebCore::IntRect&);
 #endif
 #if ENABLE(TOUCH_EVENTS)
     void needTouchEvents(bool);

Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.messages.in (102135 => 102136)


--- trunk/Source/WebKit2/UIProcess/WebPageProxy.messages.in	2011-12-06 15:05:40 UTC (rev 102135)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.messages.in	2011-12-06 15:24:26 UTC (rev 102136)
@@ -74,6 +74,7 @@
 #if PLATFORM(QT)
     DidChangeContentsSize(WebCore::IntSize newSize)
     DidFindZoomableArea(WebCore::IntPoint target, WebCore::IntRect area)
+    FocusEditableArea(WebCore::IntRect caret, WebCore::IntRect area)
 #endif
 #if ENABLE(TOUCH_EVENTS)
     NeedTouchEvents(bool needTouchEvents)

Modified: trunk/Source/WebKit2/UIProcess/qt/QtPageClient.cpp (102135 => 102136)


--- trunk/Source/WebKit2/UIProcess/qt/QtPageClient.cpp	2011-12-06 15:05:40 UTC (rev 102135)
+++ trunk/Source/WebKit2/UIProcess/qt/QtPageClient.cpp	2011-12-06 15:24:26 UTC (rev 102136)
@@ -168,6 +168,12 @@
     m_eventHandler->didFindZoomableArea(target, area);
 }
 
+void QtPageClient::focusEditableArea(const IntRect& caret, const IntRect& area)
+{
+    ASSERT(m_eventHandler);
+    m_eventHandler->focusEditableArea(caret, area);
+}
+
 void QtPageClient::didReceiveMessageFromNavigatorQtObject(const String& message)
 {
     m_qtWebPageProxy->didReceiveMessageFromNavigatorQtObject(message);

Modified: trunk/Source/WebKit2/UIProcess/qt/QtPageClient.h (102135 => 102136)


--- trunk/Source/WebKit2/UIProcess/qt/QtPageClient.h	2011-12-06 15:05:40 UTC (rev 102135)
+++ trunk/Source/WebKit2/UIProcess/qt/QtPageClient.h	2011-12-06 15:24:26 UTC (rev 102136)
@@ -80,6 +80,7 @@
     virtual void findStringInCustomRepresentation(const String&, FindOptions, unsigned maxMatchCount) { }
     virtual void countStringMatchesInCustomRepresentation(const String&, FindOptions, unsigned maxMatchCount) { }
     virtual void didFindZoomableArea(const WebCore::IntPoint&, const WebCore::IntRect&);
+    virtual void focusEditableArea(const WebCore::IntRect&, const WebCore::IntRect&);
     virtual void didReceiveMessageFromNavigatorQtObject(const String&);
     virtual void handleDownloadRequest(DownloadProxy*);
 

Modified: trunk/Source/WebKit2/UIProcess/qt/QtViewportInteractionEngine.cpp (102135 => 102136)


--- trunk/Source/WebKit2/UIProcess/qt/QtViewportInteractionEngine.cpp	2011-12-06 15:05:40 UTC (rev 102135)
+++ trunk/Source/WebKit2/UIProcess/qt/QtViewportInteractionEngine.cpp	2011-12-06 15:24:26 UTC (rev 102136)
@@ -94,6 +94,23 @@
     return cssScale * m_constraints.devicePixelRatio;
 }
 
+inline qreal QtViewportInteractionEngine::itemCoordFromCSS(qreal value)
+{
+    return value * m_constraints.devicePixelRatio;
+}
+
+inline QRectF QtViewportInteractionEngine::itemRectFromCSS(const QRectF& cssRect)
+{
+    QRectF itemRect;
+
+    itemRect.setX(itemCoordFromCSS(cssRect.x()));
+    itemRect.setY(itemCoordFromCSS(cssRect.y()));
+    itemRect.setWidth(itemCoordFromCSS(cssRect.width()));
+    itemRect.setHeight(itemCoordFromCSS(cssRect.height()));
+
+    return itemRect;
+}
+
 QtViewportInteractionEngine::QtViewportInteractionEngine(const QQuickItem* viewport, QQuickItem* content)
     : m_viewport(viewport)
     , m_content(content)
@@ -309,6 +326,40 @@
     return QRectF(QPointF(0, 0), QSizeF(horizontalRange, verticalRange));
 }
 
+void QtViewportInteractionEngine::focusEditableArea(const QRectF& caretArea, const QRectF& targetArea)
+{
+    QRectF endArea = itemRectFromCSS(targetArea);
+
+    qreal endItemScale = itemScaleFromCSS(innerBoundedCSSScale(2.0));
+    const QRectF viewportRect = m_viewport->boundingRect();
+
+    qreal x;
+    const qreal borderOffset = 10;
+    if ((endArea.width() + borderOffset) * endItemScale <= viewportRect.width()) {
+        // Center the input field in the middle of the view, if it is smaller than
+        // the view at the scale target.
+        x = viewportRect.center().x() - endArea.width() * endItemScale / 2.0;
+    } else {
+        // Ensure that the caret always has borderOffset contents pixels to the right
+        // of it, and secondarily (if possible), that the area has borderOffset
+        // contents pixels to the left of it.
+        qreal caretOffset = itemCoordFromCSS(caretArea.x()) - endArea.x();
+        x = qMin(viewportRect.width() - (caretOffset + borderOffset) * endItemScale, borderOffset * endItemScale);
+    }
+
+    const QPointF hotspot = QPointF(endArea.x(), endArea.center().y());
+    const QPointF viewportHotspot = QPointF(x, /* FIXME: visibleCenter */ viewportRect.center().y());
+
+    QPointF endPosition = hotspot * endItemScale - viewportHotspot;
+    QRectF endPosRange = computePosRangeForItemAtScale(endItemScale);
+
+    endPosition = boundPosition(endPosRange.topLeft(), endPosition, endPosRange.bottomRight());
+
+    QRectF endVisibleContentRect(endPosition / endItemScale, viewportRect.size() / endItemScale);
+
+    animateItemRectVisible(endVisibleContentRect);
+}
+
 void QtViewportInteractionEngine::zoomToAreaGestureEnded(const QPointF& touchPoint, const QRectF& targetArea)
 {
     if (!targetArea.isValid())
@@ -318,11 +369,7 @@
         return;
 
     const int margin = 10; // We want at least a little bit or margin.
-    QRectF endArea = targetArea.adjusted(-margin, -margin, margin, margin);
-    endArea.setX(endArea.x() * m_constraints.devicePixelRatio);
-    endArea.setY(endArea.y() * m_constraints.devicePixelRatio);
-    endArea.setWidth(endArea.width() * m_constraints.devicePixelRatio);
-    endArea.setHeight(endArea.height() * m_constraints.devicePixelRatio);
+    QRectF endArea = itemRectFromCSS(targetArea.adjusted(-margin, -margin, margin, margin));
 
     const QRectF viewportRect = m_viewport->boundingRect();
 

Modified: trunk/Source/WebKit2/UIProcess/qt/QtViewportInteractionEngine.h (102135 => 102136)


--- trunk/Source/WebKit2/UIProcess/qt/QtViewportInteractionEngine.h	2011-12-06 15:05:40 UTC (rev 102135)
+++ trunk/Source/WebKit2/UIProcess/qt/QtViewportInteractionEngine.h	2011-12-06 15:24:26 UTC (rev 102136)
@@ -91,7 +91,8 @@
     void pinchGestureRequestUpdate(const QPointF& pinchCenterInContentCoordinates, qreal totalScaleFactor);
     void pinchGestureEnded();
 
-    void zoomToAreaGestureEnded(const QPointF& touchPoint, const QRectF& endArea);
+    void zoomToAreaGestureEnded(const QPointF& touchPoint, const QRectF& targetArea);
+    void focusEditableArea(const QRectF& caretArea, const QRectF& targetArea);
 
 Q_SIGNALS:
     void contentSuspendRequested();
@@ -112,6 +113,9 @@
 
     qreal cssScaleFromItem(qreal);
     qreal itemScaleFromCSS(qreal);
+    qreal itemCoordFromCSS(qreal);
+    QRectF itemRectFromCSS(const QRectF&);
+
     qreal innerBoundedCSSScale(qreal);
     qreal outerBoundedCSSScale(qreal);
 

Modified: trunk/Source/WebKit2/UIProcess/qt/QtWebPageEventHandler.cpp (102135 => 102136)


--- trunk/Source/WebKit2/UIProcess/qt/QtWebPageEventHandler.cpp	2011-12-06 15:05:40 UTC (rev 102135)
+++ trunk/Source/WebKit2/UIProcess/qt/QtWebPageEventHandler.cpp	2011-12-06 15:24:26 UTC (rev 102136)
@@ -385,4 +385,12 @@
     m_interactionEngine->zoomToAreaGestureEnded(QPointF(target), QRectF(area));
 }
 
+void QtWebPageEventHandler::focusEditableArea(const IntRect& caret, const IntRect& area)
+{
+    if (!m_interactionEngine)
+        return;
+
+    m_interactionEngine->focusEditableArea(QRectF(caret), QRectF(area));
+}
+
 #include "moc_QtWebPageEventHandler.cpp"

Modified: trunk/Source/WebKit2/UIProcess/qt/QtWebPageEventHandler.h (102135 => 102136)


--- trunk/Source/WebKit2/UIProcess/qt/QtWebPageEventHandler.h	2011-12-06 15:05:40 UTC (rev 102135)
+++ trunk/Source/WebKit2/UIProcess/qt/QtWebPageEventHandler.h	2011-12-06 15:24:26 UTC (rev 102136)
@@ -52,6 +52,7 @@
     void handleDoubleTapEvent(const QTouchEvent::TouchPoint&);
 
     void didFindZoomableArea(const WebCore::IntPoint& target, const WebCore::IntRect& area);
+    void focusEditableArea(const WebCore::IntRect& caret, const WebCore::IntRect& area);
     void doneWithTouchEvent(const NativeWebTouchEvent&, bool wasEventHandled);
     void resetGestureRecognizers();
 

Modified: trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebEditorClient.cpp (102135 => 102136)


--- trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebEditorClient.cpp	2011-12-06 15:05:40 UTC (rev 102135)
+++ trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebEditorClient.cpp	2011-12-06 15:24:26 UTC (rev 102136)
@@ -38,12 +38,14 @@
 #include <WebCore/EditCommand.h>
 #include <WebCore/FocusController.h>
 #include <WebCore/Frame.h>
+#include <WebCore/FrameView.h>
 #include <WebCore/HTMLInputElement.h>
 #include <WebCore/HTMLNames.h>
 #include <WebCore/HTMLTextAreaElement.h>
 #include <WebCore/KeyboardEvent.h>
 #include <WebCore/NotImplemented.h>
 #include <WebCore/Page.h>
+#include <WebCore/TextIterator.h>
 #include <WebCore/UserTypingGestureIndicator.h>
 
 using namespace WebCore;
@@ -181,6 +183,27 @@
     if (!frame)
         return;
 
+#if PLATFORM(QT)
+    bool selectionIsNone = frame->selection()->isNone();
+    Element* scope = frame->selection()->rootEditableElement();
+
+    RefPtr<Range> range;
+    if (scope && !selectionIsNone && (range = frame->selection()->selection().firstRange())) {
+        size_t location = 0;
+        size_t length = 0;
+
+        TextIterator::getLocationAndLengthFromRange(scope, range.get(), location, length);
+
+        ExceptionCode ec = 0;
+        RefPtr<Range> tempRange = range->cloneRange(ec);
+        tempRange->setStart(tempRange->startContainer(ec), tempRange->startOffset(ec) + location, ec);
+        IntRect caretRect = frame->view()->contentsToWindow(frame->editor()->firstRectForRange(tempRange.get()));
+        IntRect nodeRect = frame->view()->contentsToWindow(scope->getRect());
+
+        m_page->send(Messages::WebPageProxy::FocusEditableArea(caretRect, nodeRect));
+    }
+#endif
+
     m_page->send(Messages::WebPageProxy::EditorStateChanged(m_page->editorState()));
 
 #if PLATFORM(WIN)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to