Merge ~santoshbit2007/oxide:focus_issue into oxide:master

Proposed by Santosh
Status: Merged
Approved by: Chris Coulson
Approved revision: a8742c91e126f264e7f25b11f35906ade893537b
Merge reported by: Santosh
Merged at revision: not available
Proposed branch: ~santoshbit2007/oxide:focus_issue
Merge into: oxide:master
Diff against target: 114 lines (+89/-2)
3 files modified
qt/quick/oxide_qquick_contents_view.cc (+3/-2)
qt/tests/qmltests/core/tst_focus.html (+20/-0)
qt/tests/qmltests/core/tst_focus.qml (+66/-0)
Reviewer Review Type Date Requested Status
Chris Coulson Approve
Review via email: mp+301475@code.launchpad.net

Commit message

Decide focus state of webview based on activeFocusItem check of window
instead of activeFocus.

LP: #1599771

Description of the change

Decide focus state of webview based on activeFocusItem check of window
instead of activeFocus.

LP: #1599771

To post a comment you must log in.
Revision history for this message
Chris Coulson (chrisccoulson) wrote :

Thanks for this - there's a few issues with the test. I've left some comments inline.

review: Needs Fixing
Revision history for this message
Chris Coulson (chrisccoulson) wrote :

Thanks. This looks mostly ok, but there is one change I forgot to ask for in the initial review - could you please move the test to qt/tests/qmltests/web_platform?

Once that's done, feel free to push this.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/qt/quick/oxide_qquick_contents_view.cc b/qt/quick/oxide_qquick_contents_view.cc
index afa7525..cd4ba2c 100644
--- a/qt/quick/oxide_qquick_contents_view.cc
+++ b/qt/quick/oxide_qquick_contents_view.cc
@@ -104,8 +104,9 @@ bool ContentsView::IsVisible() const {
104}104}
105105
106bool ContentsView::HasFocus() const {106bool ContentsView::HasFocus() const {
107 return item_->hasActiveFocus() &&107 QQuickWindow* window = item_->window();
108 (item_->window() ? item_->window()->isActive() : false);108 return window ? (window->isActive() &&
109 (window->activeFocusItem() == item_)) : false;
109}110}
110111
111QRect ContentsView::GetBounds() const {112QRect ContentsView::GetBounds() const {
diff --git a/qt/tests/qmltests/core/tst_focus.html b/qt/tests/qmltests/core/tst_focus.html
112new file mode 100644113new file mode 100644
index 0000000..8e54900
--- /dev/null
+++ b/qt/tests/qmltests/core/tst_focus.html
@@ -0,0 +1,20 @@
1<html>
2<body>
3<center>
4 Enter your name: <input type="text" id="input" onfocusout="focusOff()"
5 onfocusin="focusIn()" autofocus>
6</center>
7 <script>
8 function focusOff() {
9 var e = new CustomEvent("oxidefocusstate", { bubbles: true, detail: { status: false } });
10 document.documentElement.dispatchEvent(e);
11 }
12
13 function focusIn() {
14 var e = new CustomEvent("oxidefocusstate", { bubbles: true, detail: { status: true } });
15 document.documentElement.dispatchEvent(e);
16 }
17 </script>
18</body>
19</html>
20
diff --git a/qt/tests/qmltests/core/tst_focus.qml b/qt/tests/qmltests/core/tst_focus.qml
0new file mode 10064421new file mode 100644
index 0000000..d4b221e
--- /dev/null
+++ b/qt/tests/qmltests/core/tst_focus.qml
@@ -0,0 +1,66 @@
1import QtQuick 2.0
2import QtTest 1.0
3import com.canonical.Oxide 1.0
4import Oxide.testsupport 1.0
5
6Item {
7 id: root
8 TestWebView {
9 id: webView
10
11 property bool htmlInputElementFocus: true;
12 focus: true;
13 messageHandlers: [
14 ScriptMessageHandler {
15 msgId: "FOCUS-STATE"
16 contexts: [ "oxide://testutils/" ]
17 callback: function(msg) {
18 webView.htmlInputElementFocus = msg.payload;
19 }
20 }
21 ]
22 }
23
24 TestCase {
25 name: "webview_focus"
26 when: windowShown
27
28 function init() {
29 webView.htmlInputElementFocus = true;
30 }
31
32 function cleanupTestCase() {
33
34 }
35
36 function test_initial_focus() {
37 compare(webView.activeFocus, true, "webView.activeFocus == true");
38 }
39
40 function test_toggle_focus() {
41 webView.url = "https://testsuite/tst_focus.html";
42 verify(webView.waitForLoadSucceeded(),
43 "Timed out waiting for successful load");
44
45 compare(webView.activeFocus, true, "webView.activeFocus == true");
46 compare(webView.htmlInputElementFocus, true, "webview.htmlInputElementFocus == true");
47
48 webView.getTestApi().evaluateCode(
49 "document.addEventListener(\"oxidefocusstate\", function(event) {
50 oxide.sendMessage(\"FOCUS-STATE\", event.detail.status);
51 });", true);
52
53 webView.focus = false;
54 TestUtils.waitFor(function() { return webView.activeFocus == false; });
55 compare(webView.activeFocus, false, "webView.activeFocus == false");
56 TestUtils.waitFor(function() { return webView.htmlInputElementFocus == false; });
57 compare(webView.htmlInputElementFocus, false, "webview.htmlInputElementFocus == false");
58
59 webView.focus = true;
60 TestUtils.waitFor(function() { return webView.activeFocus == false; });
61 compare(webView.activeFocus, true, "webView.activeFocus == true");
62 TestUtils.waitFor(function() { return webView.htmlInputElementFocus == true; });
63 compare(webView.htmlInputElementFocus, true, "webview.htmlInputElementFocus == true");
64 }
65 }
66}

Subscribers

People subscribed via source and target branches

to all changes: