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
=== modified file 'src/imports/Components/Popups/1.3/PopupBase.qml'
--- src/imports/Components/Popups/1.3/PopupBase.qml 2016-04-13 19:32:20 +0000
+++ src/imports/Components/Popups/1.3/PopupBase.qml 2017-01-10 12:23:48 +0000
@@ -119,6 +119,14 @@
119119
120 /*!120 /*!
121 \internal121 \internal
122 The function saves the active focus for later.
123 */
124 function __setPreviousActiveFocusItem(item) {
125 stateWrapper.prevFocus = item;
126 }
127
128 /*!
129 \internal
122 Foreground component excluded from InverseMouseArea130 Foreground component excluded from InverseMouseArea
123 */131 */
124 property Item __foreground132 property Item __foreground
@@ -177,30 +185,14 @@
177 /*! \internal */185 /*! \internal */
178 onParentChanged: stateWrapper.rootItem = QuickUtils.rootItem(popupBase)186 onParentChanged: stateWrapper.rootItem = QuickUtils.rootItem(popupBase)
179 Component.onCompleted: {187 Component.onCompleted: {
180 stateWrapper.saveActiveFocus();
181 stateWrapper.rootItem = QuickUtils.rootItem(popupBase);188 stateWrapper.rootItem = QuickUtils.rootItem(popupBase);
182 }189 }
183190
184 Item {191 Item {
185 id: stateWrapper192 id: stateWrapper
186 property Item rootItem: QuickUtils.rootItem(popupBase)193 property Item rootItem: QuickUtils.rootItem(popupBase)
187
188 property bool windowIsValid: typeof window != "undefined"
189 property Item prevFocus194 property Item prevFocus
190195
191 function saveActiveFocus() {
192 // 'window' context property is exposed to QML after component completion
193 // before rendering is complete, therefore a simple 'if (window)' check is
194 // not enough.
195 if (windowIsValid) {
196 prevFocus = window.activeFocusItem;
197 windowIsValidChanged.disconnect(saveActiveFocus);
198 } else {
199 // connect the function so we can save the original focus item
200 windowIsValidChanged.connect(saveActiveFocus);
201 }
202 }
203
204 function restoreActiveFocus() {196 function restoreActiveFocus() {
205 if (prevFocus) {197 if (prevFocus) {
206 if (prevFocus.hasOwnProperty("requestFocus")) {198 if (prevFocus.hasOwnProperty("requestFocus")) {
207199
=== modified file 'src/imports/Components/Popups/1.3/popupUtils.js'
--- src/imports/Components/Popups/1.3/popupUtils.js 2016-09-15 15:53:27 +0000
+++ src/imports/Components/Popups/1.3/popupUtils.js 2017-01-10 12:23:48 +0000
@@ -66,6 +66,8 @@
66 }66 }
6767
68 var popupObject;68 var popupObject;
69 // If there's an active item, save it so we can restore it later
70 var prevFocusItem = (typeof window !== "undefined") ? window.activeFocusItem : null;
69 if (params !== undefined) {71 if (params !== undefined) {
70 popupObject = popupComponent.createObject(rootObject, params);72 popupObject = popupComponent.createObject(rootObject, params);
71 } else {73 } else {
@@ -75,8 +77,11 @@
75 print(popupComponent.errorString().slice(0, -1));77 print(popupComponent.errorString().slice(0, -1));
76 print("PopupUtils.open(): Failed to create the popup object.");78 print("PopupUtils.open(): Failed to create the popup object.");
77 return;79 return;
78 } else if (popupObject.hasOwnProperty("caller") && caller)80 } else if (popupObject.hasOwnProperty("caller") && caller) {
79 popupObject.caller = caller;81 popupObject.caller = caller;
82 } else if (popupObject.hasOwnProperty("__setPreviousActiveFocusItem")) {
83 popupObject.__setPreviousActiveFocusItem(prevFocusItem);
84 }
8085
81 // if caller is specified, connect its cleanup to the popup's close86 // if caller is specified, connect its cleanup to the popup's close
82 // so popups will be removed together with the caller.87 // so popups will be removed together with the caller.
8388
=== modified file 'tests/unit/visual/tst_focus.13.qml'
--- tests/unit/visual/tst_focus.13.qml 2016-09-19 16:40:49 +0000
+++ tests/unit/visual/tst_focus.13.qml 2017-01-10 12:23:48 +0000
@@ -414,13 +414,13 @@
414 component: dialogComponent,414 component: dialogComponent,
415 item: null,415 item: null,
416 foreground_name: "dialogForeground",416 foreground_name: "dialogForeground",
417 bug: "1569979"417 bug: "" // this is not buggy
418 },418 },
419 { tag: "Popover component",419 { tag: "Popover component",
420 component: popoverComponent,420 component: popoverComponent,
421 item: null,421 item: null,
422 foreground_name: "popover_foreground",422 foreground_name: "popover_foreground",
423 bug: "" // this is the only case without a bug423 bug: "" // this is not buggy
424 },424 },
425 { tag: "Dialog item",425 { tag: "Dialog item",
426 component: null,426 component: null,
427427
=== modified file 'tests/unit/visual/tst_popups_dialog.13.qml'
--- tests/unit/visual/tst_popups_dialog.13.qml 2016-06-15 13:46:51 +0000
+++ tests/unit/visual/tst_popups_dialog.13.qml 2017-01-10 12:23:48 +0000
@@ -47,6 +47,21 @@
47 keyClick(Qt.Key_Escape);47 keyClick(Qt.Key_Escape);
48 tryCompare(test, "dialogDestroyed", true, 500, "Dialog not destroyed");48 tryCompare(test, "dialogDestroyed", true, 500, "Dialog not destroyed");
49 }49 }
50
51 function test_focus_restore_ondismiss_dialog() {
52 pressMe.forceActiveFocus();
53
54 tryCompare(window, "activeFocusItem", pressMe);
55
56 var dlg = PopupUtils.open(dialog);
57 waitForRendering(dlg);
58
59 tryCompare(window, "activeFocusItem", dlg.button);
60
61 keyClick(Qt.Key_Escape);
62
63 tryCompare(window, "activeFocusItem", pressMe);
64 }
50 }65 }
5166
52 Component {67 Component {
@@ -54,10 +69,13 @@
54 Dialog {69 Dialog {
55 id: ahojDialog70 id: ahojDialog
56 title: "Ahoj"71 title: "Ahoj"
72 property alias button: closeButton
5773
58 Button {74 Button {
75 id: closeButton
59 text: "Close"76 text: "Close"
60 onClicked: PopupUtils.close(ahojDialog)77 onClicked: PopupUtils.close(ahojDialog)
78 focus: true
61 }79 }
62 }80 }
63 }81 }

Subscribers

People subscribed via source and target branches