on xenial help sign in
[HACK] Force focus back to the prent surface when a trusted session is closed.
bff46a9josharenson
qml/Stages/SessionContainer.qml+4−6
@@ -36,7 +36,6 @@ Item {
36
36
37
37
38 Repeater {
38 Repeater {
39− id: theRepeater
40 model: root.childSessions
39 model: root.childSessions
41
40
42 delegate: Loader {
41 delegate: Loader {
@@ -71,12 +70,11 @@ Item {
71 property: "orientation"; value: root.orientation
70 property: "orientation"; value: root.orientation
72 }
71 }
73
72
73+ /* FIXME: This is a hack to restore focus to an app
74+ when a trusted session prompt is closed
75+ */
74 Component.onDestruction: {
76 Component.onDestruction: {
75− //console.log("FAIL: count: " + root.childSessions.count())
76− //console.log("FAIL: " + theRepeater.itemAt(0));
77− var nextSession = root.childSessions.count() ? theRepeater.itemAt(root.childSessions.count() - 1) : root.session;
78− console.log("FAIL: " + nextSession);
79− nextSession.forceActiveFocus()
77+ root.session.surface.forceActiveFocus();
80 }
78 }
81 }
79 }
82 }
80 }
tests/qmltests/Stages/tst_SessionContainer.qml+19−31
@@ -186,50 +186,38 @@ Rectangle {
186 }
186 }
187
187
188 function test_childSessionDestructionReturnsFocusToSiblingOrParent() {
188 function test_childSessionDestructionReturnsFocusToSiblingOrParent() {
189− console.log("FAIL: entering childSessionDestriction....")
190 sessionCheckbox.checked = true;
189 sessionCheckbox.checked = true;
191−
192 var sessionContainer = sessionContainerLoader.item;
190 var sessionContainer = sessionContainerLoader.item;
191+ compare(sessionContainer.childSessions.count(), 0);
193
192
194− // Without this, we cannot get active focus
195− sessionContainer.interactive = true;
193+ sessionContainer.interactive = true;
196− compare(sessionContainer.childSessions.count(), 0);
197
194
198− /*
199− * Build a stack of fake sessions
200− * 3 sessions should cover all edge cases
201− * - Focus from departing session goes to sibling
202− * - Focus from last child goes to parent
203− */
204 var i;
195 var i;
205 var sessions = [];
196 var sessions = [];
197+ // 3 sessions should cover all edge cases
206 for(i = 0; i < 3; i++) {
198 for(i = 0; i < 3; i++) {
207− var session = ApplicationTest.addChildSession(
199+ var a_session = ApplicationTest.addChildSession(
208− sessionContainer.session, "gallery");
200+ sessionContainer.session, "gallery"
209− session.createSurface();
201+ )
210− sessionContainer.session.addChildSession(session);
211− compare(sessionContainer.childSessions.count(), i+1);
212
202
203+ a_session.createSurface();
204+ sessionContainer.session.addChildSession(a_session);
205+ compare(sessionContainer.childSessions.count(), i + 1);
206+
213− sessions.push(session);
207+ sessions.push(a_session);
214 }
208 }
215
209
216− // Traverse the fake session stack, following and testing focus
210+ var a_session;
217− var sessionUnderTest;
218− while(sessionUnderTest = sessions.pop()) {
211+ while(a_session = sessions.pop()) {
219− var surface = sessionUnderTest.surface;
220− surface.forceActiveFocus();
212+ a_session.surface.forceActiveFocus();
221− compare(surface.activeFocus, true);
213+ compare(a_session.surface.activeFocus, true);
222
214
223− var nextSession = sessions.pop();
215+ var parentSession = a_session.parentSession;
224− if(nextSession != undefined) {
225− sessions.push(nextSession);
226− sessionContainer.session.removeChildSession(sessionUnderTest);
216+ sessionContainer.session.removeChildSession(a_session);
227− compare(surface.activeFocus, false);
217+ compare(a_session.surface.activeFocus, false);
228
218
229− compare(nextSession.surface.activeFocus, true)
219+ compare(parentSession.surface.activeFocus, true);
230− }
231 }
220 }
232− console.log("FAIL: exiting childSessionDestriction....")
233 }
221 }
234
222
235 function test_nestedChildSessions_data() {
223 function test_nestedChildSessions_data() {