Permalink
Browse files

[Qt] Input method hints are not being set.

https://bugs.webkit.org/show_bug.cgi?id=92386

Patch by Marcelo Lira <marcelo.lira@openbossa.org> on 2012-08-16
Reviewed by Kenneth Rohde Christiansen.

Input method hints for an editable element must be obtained from a proper
HTML element. If the editable element is a complex one, it will have elements
in the Shadow DOM, and it's one of those that will be returned as the root
editable element. This works for editable DIVs, but not for INPUT elements.
Using Element::shadowHost() on the root editable element will provide the
needed HTML element, and for further clarity a method that does this was added
to FrameSelection.

Source/WebCore:

* editing/FrameSelection.cpp:
(WebCore::FrameSelection::rootEditableElementRespectingShadowTree): Similar to
WebCore::FrameSelection::rootEditableElement, but returns the first ancestor of
the editable element outside the shadow tree.
(WebCore):
* editing/FrameSelection.h:
(FrameSelection):

Source/WebKit2:

Added an API test to the Qt port regarding the correct setting
of input method hints information on INPUT HTML tags.

* UIProcess/API/qt/tests/html/inputmethod.html:
* UIProcess/API/qt/tests/qquickwebview/tst_qquickwebview.cpp:
(tst_QQuickWebView):
(tst_QQuickWebView::inputMethodHints):
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::editorState):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@125777 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information...
1 parent 968ea2f commit 359290cfdbcf9dc98731544ca1b5b8e3365c9965 commit-queue committed Aug 16, 2012
View
@@ -1,3 +1,26 @@
+2012-08-16 Marcelo Lira <marcelo.lira@openbossa.org>
+
+ [Qt] Input method hints are not being set.
+ https://bugs.webkit.org/show_bug.cgi?id=92386
+
+ Reviewed by Kenneth Rohde Christiansen.
+
+ Input method hints for an editable element must be obtained from a proper
+ HTML element. If the editable element is a complex one, it will have elements
+ in the Shadow DOM, and it's one of those that will be returned as the root
+ editable element. This works for editable DIVs, but not for INPUT elements.
+ Using Element::shadowHost() on the root editable element will provide the
+ needed HTML element, and for further clarity a method that does this was added
+ to FrameSelection.
+
+ * editing/FrameSelection.cpp:
+ (WebCore::FrameSelection::rootEditableElementRespectingShadowTree): Similar to
+ WebCore::FrameSelection::rootEditableElement, but returns the first ancestor of
+ the editable element outside the shadow tree.
+ (WebCore):
+ * editing/FrameSelection.h:
+ (FrameSelection):
+
2012-08-16 Zeno Albisser <zeno@webkit.org>
Make GraphicsSurface double buffered by default.
@@ -124,6 +124,14 @@ Element* FrameSelection::rootEditableElementOrDocumentElement() const
return selectionRoot ? selectionRoot : m_frame->document()->documentElement();
}
+Element* FrameSelection::rootEditableElementRespectingShadowTree() const
+{
+ Element* selectionRoot = m_selection.rootEditableElement();
+ if (selectionRoot && selectionRoot->isInShadowTree())
+ selectionRoot = selectionRoot->shadowHost();
+ return selectionRoot;
+}
+
void FrameSelection::moveTo(const VisiblePosition &pos, EUserTriggered userTriggered, CursorAlignOnScroll align)
{
SetSelectionOptions options = CloseTyping | ClearTypingStyle | userTriggered;
@@ -135,6 +135,8 @@ class FrameSelection : private CaretBase {
Element* rootEditableElement() const { return m_selection.rootEditableElement(); }
Element* rootEditableElementOrDocumentElement() const;
+ Element* rootEditableElementRespectingShadowTree() const;
+
bool rendererIsEditable() const { return m_selection.rendererIsEditable(); }
bool isContentEditable() const { return m_selection.isContentEditable(); }
bool isContentRichlyEditable() const { return m_selection.isContentRichlyEditable(); }
View
@@ -1,3 +1,28 @@
+2012-08-16 Marcelo Lira <marcelo.lira@openbossa.org>
+
+ [Qt] Input method hints are not being set.
+ https://bugs.webkit.org/show_bug.cgi?id=92386
+
+ Reviewed by Kenneth Rohde Christiansen.
+
+ Input method hints for an editable element must be obtained from a proper
+ HTML element. If the editable element is a complex one, it will have elements
+ in the Shadow DOM, and it's one of those that will be returned as the root
+ editable element. This works for editable DIVs, but not for INPUT elements.
+ Using Element::shadowHost() on the root editable element will provide the
+ needed HTML element, and for further clarity a method that does this was added
+ to FrameSelection.
+
+ Added an API test to the Qt port regarding the correct setting
+ of input method hints information on INPUT HTML tags.
+
+ * UIProcess/API/qt/tests/html/inputmethod.html:
+ * UIProcess/API/qt/tests/qquickwebview/tst_qquickwebview.cpp:
+ (tst_QQuickWebView):
+ (tst_QQuickWebView::inputMethodHints):
+ * WebProcess/WebPage/WebPage.cpp:
+ (WebKit::WebPage::editorState):
+
2012-08-16 Zeno Albisser <zeno@webkit.org>
Make GraphicsSurface double buffered by default.
@@ -5,5 +5,7 @@
<body>
<h1>Basic page</h1>
<input id="inputField" />
+<input id="emailInputField" type="email" />
+<div id="editableDiv" contenteditable></div>
</body>
</html>
@@ -58,6 +58,7 @@ private Q_SLOTS:
void transparentWebViews();
void inputMethod();
+ void inputMethodHints();
void basicRenderingSanity();
private:
@@ -410,6 +411,33 @@ void tst_QQuickWebView::inputMethod()
QVERIFY(!view->flags().testFlag(QQuickItem::ItemAcceptsInputMethod));
}
+void tst_QQuickWebView::inputMethodHints()
+{
+ QQuickWebView* view = webView();
+
+ view->setUrl(QUrl::fromLocalFile(QLatin1String(TESTS_SOURCE_DIR "/html/inputmethod.html")));
+ QVERIFY(waitForLoadSucceeded(view));
+
+ // Setting focus on an input element results in an element in its shadow tree becoming the focus node.
+ // Input hints should not be set from this shadow tree node but from the input element itself.
+ runJavaScript("document.getElementById('emailInputField').focus();");
+ QVERIFY(view->flags().testFlag(QQuickItem::ItemAcceptsInputMethod));
+ QInputMethodQueryEvent query(Qt::ImHints);
+ QGuiApplication::sendEvent(view, &query);
+ Qt::InputMethodHints hints(query.value(Qt::ImHints).toUInt() & Qt::ImhExclusiveInputMask);
+ QCOMPARE(hints, Qt::ImhEmailCharactersOnly);
+
+ // The focus of an editable DIV is given directly to it, so no shadow root element
+ // is necessary. This tests the WebPage::editorState() method ability to get the
+ // right element without breaking.
+ runJavaScript("document.getElementById('editableDiv').focus();");
+ QVERIFY(view->flags().testFlag(QQuickItem::ItemAcceptsInputMethod));
+ query = QInputMethodQueryEvent(Qt::ImHints);
+ QGuiApplication::sendEvent(view, &query);
+ hints = Qt::InputMethodHints(query.value(Qt::ImHints).toUInt());
+ QCOMPARE(hints, Qt::ImhNone);
+}
+
void tst_QQuickWebView::scrollRequest()
{
webView()->setSize(QSizeF(300, 400));
@@ -485,7 +485,7 @@ EditorState WebPage::editorState() const
size_t location = 0;
size_t length = 0;
- Element* selectionRoot = frame->selection()->rootEditableElement();
+ Element* selectionRoot = frame->selection()->rootEditableElementRespectingShadowTree();
Element* scope = selectionRoot ? selectionRoot : frame->document()->documentElement();
if (!scope)

0 comments on commit 359290c

Please sign in to comment.