Merge lp:~aacid/ubuntu-ui-toolkit/fix_popup_focus_restore into lp:ubuntu-ui-toolkit/staging

Proposed by Albert Astals Cid
Status: Merged
Approved by: Zsombor Egri
Approved revision: 2155
Merged at revision: 2154
Proposed branch: lp:~aacid/ubuntu-ui-toolkit/fix_popup_focus_restore
Merge into: lp:ubuntu-ui-toolkit/staging
Diff against target: 135 lines (+34/-19)
4 files modified
src/imports/Components/Popups/1.3/PopupBase.qml (+8/-16)
src/imports/Components/Popups/1.3/popupUtils.js (+6/-1)
tests/unit/visual/tst_focus.13.qml (+2/-2)
tests/unit/visual/tst_popups_dialog.13.qml (+18/-0)
To merge this branch: bzr merge lp:~aacid/ubuntu-ui-toolkit/fix_popup_focus_restore
Reviewer Review Type Date Requested Status
ubuntu-sdk-build-bot continuous-integration Approve
Zsombor Egri Approve
Cris Dywan Needs Fixing
Review via email: mp+314156@code.launchpad.net

Commit message

Fix saving/restoring of previous item focus for popups

You can't save the focus after the popup/dialog has been created,
at that stage the dialog has focus already,
you need to do it before creating it

To post a comment you must log in.
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Cris Dywan (kalikiana) wrote :

XPASS : components::FocusingTests::test_popover_refocus(Dialog component) 'Button focus not restored.' returned TRUE unexpectedly. ()
   Loc: [/tmp/buildd/ubuntu-ui-toolkit-1.3.2151+17.04.20161223/tests/unit/visual/tst_focus.13.qml(470)]
PASS : components::FocusingTests::test_popover_refocus(Popover component)
XFAIL : components::FocusingTests::test_popover_refocus(Dialog item) Incorrect focus restoration. See bug 1569979 and 1569981.
   Loc: [/tmp/buildd/ubuntu-ui-toolkit-1.3.2151+17.04.20161223/tests/unit/visual/tst_focus.13.qml(470)]
PASS : components::FocusingTests::test_popover_refocus(Dialog item)
XFAIL : components::FocusingTests::test_popover_refocus(Popover item) Incorrect focus restoration. See bug 1569981.
   Loc: [/tmp/buildd/ubuntu-ui-toolkit-1.3.2151+17.04.20161223/tests/unit/visual/tst_focus.13.qml(470)]

review: Needs Fixing
2154. By Albert Astals Cid

Merge

2155. By Albert Astals Cid

Seems i fixed 1569979

Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Zsombor Egri (zsombi) wrote :

Looks good to me. Thanks for fixing!

review: Approve
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/imports/Components/Popups/1.3/PopupBase.qml'
2--- src/imports/Components/Popups/1.3/PopupBase.qml 2016-04-13 19:32:20 +0000
3+++ src/imports/Components/Popups/1.3/PopupBase.qml 2017-01-10 12:23:48 +0000
4@@ -119,6 +119,14 @@
5
6 /*!
7 \internal
8+ The function saves the active focus for later.
9+ */
10+ function __setPreviousActiveFocusItem(item) {
11+ stateWrapper.prevFocus = item;
12+ }
13+
14+ /*!
15+ \internal
16 Foreground component excluded from InverseMouseArea
17 */
18 property Item __foreground
19@@ -177,30 +185,14 @@
20 /*! \internal */
21 onParentChanged: stateWrapper.rootItem = QuickUtils.rootItem(popupBase)
22 Component.onCompleted: {
23- stateWrapper.saveActiveFocus();
24 stateWrapper.rootItem = QuickUtils.rootItem(popupBase);
25 }
26
27 Item {
28 id: stateWrapper
29 property Item rootItem: QuickUtils.rootItem(popupBase)
30-
31- property bool windowIsValid: typeof window != "undefined"
32 property Item prevFocus
33
34- function saveActiveFocus() {
35- // 'window' context property is exposed to QML after component completion
36- // before rendering is complete, therefore a simple 'if (window)' check is
37- // not enough.
38- if (windowIsValid) {
39- prevFocus = window.activeFocusItem;
40- windowIsValidChanged.disconnect(saveActiveFocus);
41- } else {
42- // connect the function so we can save the original focus item
43- windowIsValidChanged.connect(saveActiveFocus);
44- }
45- }
46-
47 function restoreActiveFocus() {
48 if (prevFocus) {
49 if (prevFocus.hasOwnProperty("requestFocus")) {
50
51=== modified file 'src/imports/Components/Popups/1.3/popupUtils.js'
52--- src/imports/Components/Popups/1.3/popupUtils.js 2016-09-15 15:53:27 +0000
53+++ src/imports/Components/Popups/1.3/popupUtils.js 2017-01-10 12:23:48 +0000
54@@ -66,6 +66,8 @@
55 }
56
57 var popupObject;
58+ // If there's an active item, save it so we can restore it later
59+ var prevFocusItem = (typeof window !== "undefined") ? window.activeFocusItem : null;
60 if (params !== undefined) {
61 popupObject = popupComponent.createObject(rootObject, params);
62 } else {
63@@ -75,8 +77,11 @@
64 print(popupComponent.errorString().slice(0, -1));
65 print("PopupUtils.open(): Failed to create the popup object.");
66 return;
67- } else if (popupObject.hasOwnProperty("caller") && caller)
68+ } else if (popupObject.hasOwnProperty("caller") && caller) {
69 popupObject.caller = caller;
70+ } else if (popupObject.hasOwnProperty("__setPreviousActiveFocusItem")) {
71+ popupObject.__setPreviousActiveFocusItem(prevFocusItem);
72+ }
73
74 // if caller is specified, connect its cleanup to the popup's close
75 // so popups will be removed together with the caller.
76
77=== modified file 'tests/unit/visual/tst_focus.13.qml'
78--- tests/unit/visual/tst_focus.13.qml 2016-09-19 16:40:49 +0000
79+++ tests/unit/visual/tst_focus.13.qml 2017-01-10 12:23:48 +0000
80@@ -414,13 +414,13 @@
81 component: dialogComponent,
82 item: null,
83 foreground_name: "dialogForeground",
84- bug: "1569979"
85+ bug: "" // this is not buggy
86 },
87 { tag: "Popover component",
88 component: popoverComponent,
89 item: null,
90 foreground_name: "popover_foreground",
91- bug: "" // this is the only case without a bug
92+ bug: "" // this is not buggy
93 },
94 { tag: "Dialog item",
95 component: null,
96
97=== modified file 'tests/unit/visual/tst_popups_dialog.13.qml'
98--- tests/unit/visual/tst_popups_dialog.13.qml 2016-06-15 13:46:51 +0000
99+++ tests/unit/visual/tst_popups_dialog.13.qml 2017-01-10 12:23:48 +0000
100@@ -47,6 +47,21 @@
101 keyClick(Qt.Key_Escape);
102 tryCompare(test, "dialogDestroyed", true, 500, "Dialog not destroyed");
103 }
104+
105+ function test_focus_restore_ondismiss_dialog() {
106+ pressMe.forceActiveFocus();
107+
108+ tryCompare(window, "activeFocusItem", pressMe);
109+
110+ var dlg = PopupUtils.open(dialog);
111+ waitForRendering(dlg);
112+
113+ tryCompare(window, "activeFocusItem", dlg.button);
114+
115+ keyClick(Qt.Key_Escape);
116+
117+ tryCompare(window, "activeFocusItem", pressMe);
118+ }
119 }
120
121 Component {
122@@ -54,10 +69,13 @@
123 Dialog {
124 id: ahojDialog
125 title: "Ahoj"
126+ property alias button: closeButton
127
128 Button {
129+ id: closeButton
130 text: "Close"
131 onClicked: PopupUtils.close(ahojDialog)
132+ focus: true
133 }
134 }
135 }

Subscribers

People subscribed via source and target branches