on xenial help sign in
composition of ApplicationWindow & SessionContainer
commit4979650fa8f34efd08a4723b080247e9a1f4b1e4 authorNick Dedekind <nick.dedekind@canonical.com> dateFri 29 Aug 2014, 14:53 (12 years ago) parentb4e331f
6 files changed+100−58
qml/Stages/ApplicationWindow.qml+44−31 qml/Stages/SessionContainer.qml−2 tests/mocks/Unity/Application/SessionManager.cpp−1 tests/qmltests/Stages/RecursingChildSessionControl.qml+4−3 tests/qmltests/Stages/tst_ApplicationWindow.qml+51−20 tests/qmltests/Stages/tst_SessionContainer.qml+1−1
qml/Stages/ApplicationWindow.qml+44−31
@@ -18,15 +18,15 @@ import QtQuick 2.0
1818import Ubuntu.Components 1.1
1919import Unity.Application 0.1
2020
21−SessionContainer {
21+Item {
2222 id: root
2323
2424 // to be read from outside
2525 readonly property bool fullscreen: application ? application.fullscreen : false
26+ property alias interactive: sessionContainer.interactive
2627
2728 // to be set from outside
2829 property QtObject application
29− session: application ? application.session : null
3030
3131 QtObject {
3232 id: d
@@ -41,7 +41,7 @@ SessionContainer {
4141 property bool hadSurface: false
4242
4343 property bool needToTakeScreenshot:
44− root.surface && d.surfaceInitialized && screenshotImage.status === Image.Null
44+ sessionContainer.surface && d.surfaceInitialized && screenshotImage.status === Image.Null
4545 && d.applicationState === ApplicationInfoInterface.Stopped
4646 onNeedToTakeScreenshotChanged: {
4747 if (needToTakeScreenshot) {
@@ -54,31 +54,23 @@ SessionContainer {
5454 // Remove this when possible
5555 property bool surfaceInitialized: false
5656 }
57− onSurfaceChanged: {
58− if (root.surface) {
59− surfaceInitTimer.start();
60− } else {
61− d.hadSurface = true;
62− d.surfaceInitialized = false;
63− }
64− }
6557
6658 Timer {
6759 id: surfaceInitTimer
6860 interval: 100
69− onTriggered: { if (root.surface) {d.surfaceInitialized = true;} }
61+ onTriggered: { if (sessionContainer.surface) {d.surfaceInitialized = true;} }
7062 }
7163
7264 Connections {
73− target: root.surface
65+ target: sessionContainer.surface
7466 // FIXME: I would rather not need to do this, but currently it doesn't get
7567 // active focus without it and I don't know why.
7668 onFocusChanged: forceSurfaceActiveFocusIfReady();
7769 onParentChanged: forceSurfaceActiveFocusIfReady();
7870 onEnabledChanged: forceSurfaceActiveFocusIfReady();
7971 function forceSurfaceActiveFocusIfReady() {
80− if (root.surface.focus && root.surface.parent === surfaceContainer && root.surface.enabled) {
81− root.surface.forceActiveFocus();
72+ if (sessionContainer.surface.focus && sessionContainer.surface.parent === sessionContainer.surfaceContainer && sessionContainer.surface.enabled) {
73+ sessionContainer.surface.forceActiveFocus();
8274 }
8375 }
8476 }
@@ -111,27 +103,42 @@ SessionContainer {
111103 }
112104 }
113105
106+ SessionContainer {
107+ id: sessionContainer
108+ session: application ? application.session : null
109+ anchors.fill: parent
110+
111+ onSurfaceChanged: {
112+ if (sessionContainer.surface) {
113+ surfaceInitTimer.start();
114+ } else {
115+ d.hadSurface = true;
116+ d.surfaceInitialized = false;
117+ }
118+ }
119+ }
120+
114121 StateGroup {
115122 objectName: "applicationWindowStateGroup"
116123 states: [
117124 State {
118125 name: "void"
119126 when:
120− d.hadSurface && (!root.surface || !d.surfaceInitialized)
127+ d.hadSurface && (!sessionContainer.surface || !d.surfaceInitialized)
121128 &&
122129 screenshotImage.status !== Image.Ready
123130 },
124131 State {
125132 name: "splashScreen"
126133 when:
127− !d.hadSurface && (!root.surface || !d.surfaceInitialized)
134+ !d.hadSurface && (!sessionContainer.surface || !d.surfaceInitialized)
128135 &&
129136 screenshotImage.status !== Image.Ready
130137 },
131138 State {
132139 name: "surface"
133140 when:
134− (root.surface && d.surfaceInitialized)
141+ (sessionContainer.surface && d.surfaceInitialized)
135142 &&
136143 (d.applicationState !== ApplicationInfoInterface.Stopped
137144 || screenshotImage.status !== Image.Ready)
@@ -142,7 +149,7 @@ SessionContainer {
142149 screenshotImage.status === Image.Ready
143150 &&
144151 (d.applicationState === ApplicationInfoInterface.Stopped
145− || !root.surface || !d.surfaceInitialized)
152+ || !sessionContainer.surface || !d.surfaceInitialized)
146153 }
147154 ]
148155
@@ -150,14 +157,18 @@ SessionContainer {
150157 Transition {
151158 from: ""; to: "splashScreen"
152159 PropertyAction { target: splashLoader; property: "active"; value: true }
160+ PropertyAction { target: sessionContainer.surfaceContainer
161+ property: "visible"; value: false }
153162 },
154163 Transition {
155164 from: "splashScreen"; to: "surface"
156165 SequentialAnimation {
157− PropertyAction { target: surfaceContainer
166+ PropertyAction { target: sessionContainer.surfaceContainer
167+ property: "opacity"; value: 0.0 }
168+ PropertyAction { target: sessionContainer.surfaceContainer
158169 property: "visible"; value: true }
159− UbuntuNumberAnimation { target: splashLoader; property: "opacity";
160− from: 1.0; to: 0.0
170+ UbuntuNumberAnimation { target: sessionContainer.surfaceContainer; property: "opacity";
171+ from: 0.0; to: 1.0
161172 duration: UbuntuAnimation.BriskDuration }
162173 PropertyAction { target: splashLoader; property: "active"; value: false }
163174 }
@@ -166,11 +177,13 @@ SessionContainer {
166177 from: "surface"; to: "splashScreen"
167178 SequentialAnimation {
168179 PropertyAction { target: splashLoader; property: "active"; value: true }
169− PropertyAction { target: surfaceContainer
180+ PropertyAction { target: sessionContainer.surfaceContainer
170181 property: "visible"; value: true }
171182 UbuntuNumberAnimation { target: splashLoader; property: "opacity";
172183 from: 0.0; to: 1.0
173184 duration: UbuntuAnimation.BriskDuration }
185+ PropertyAction { target: sessionContainer.surfaceContainer
186+ property: "visible"; value: false }
174187 }
175188 },
176189 Transition {
@@ -181,15 +194,15 @@ SessionContainer {
181194 UbuntuNumberAnimation { target: screenshotImage; property: "opacity";
182195 from: 0.0; to: 1.0
183196 duration: UbuntuAnimation.BriskDuration }
184− PropertyAction { target: surfaceContainer
197+ PropertyAction { target: sessionContainer.surfaceContainer
185198 property: "visible"; value: false }
186− ScriptAction { script: { if (root.session) { root.session.release(); } } }
199+ ScriptAction { script: { if (sessionContainer.session) { sessionContainer.session.release(); } } }
187200 }
188201 },
189202 Transition {
190203 from: "screenshot"; to: "surface"
191204 SequentialAnimation {
192− PropertyAction { target: surfaceContainer
205+ PropertyAction { target: sessionContainer.surfaceContainer
193206 property: "visible"; value: true }
194207 UbuntuNumberAnimation { target: screenshotImage; property: "opacity";
195208 from: 1.0; to: 0.0
@@ -201,16 +214,16 @@ SessionContainer {
201214 Transition {
202215 from: "surface"; to: "void"
203216 SequentialAnimation {
204− PropertyAction { target: surfaceContainer; property: "visible"; value: false }
205− ScriptAction { script: { if (root.session) { d.session.release(); } } }
217+ PropertyAction { target: sessionContainer.surfaceContainer; property: "visible"; value: false }
218+ ScriptAction { script: { if (sessionContainer.session) { sessionContainer.session.release(); } } }
206219 }
207220 },
208221 Transition {
209222 from: "void"; to: "surface"
210223 SequentialAnimation {
211− PropertyAction { target: surfaceContainer; property: "opacity"; value: 0.0 }
212− PropertyAction { target: surfaceContainer; property: "visible"; value: true }
213− UbuntuNumberAnimation { target: surfaceContainer; property: "opacity";
224+ PropertyAction { target: sessionContainer.surfaceContainer; property: "opacity"; value: 0.0 }
225+ PropertyAction { target: sessionContainer.surfaceContainer; property: "visible"; value: true }
226+ UbuntuNumberAnimation { target: sessionContainer.surfaceContainer; property: "opacity";
214227 from: 0.0; to: 1.0
215228 duration: UbuntuAnimation.BriskDuration }
216229 }
qml/Stages/SessionContainer.qml−2
@@ -30,7 +30,6 @@ Item {
3030 SurfaceContainer {
3131 id: _surfaceContainer
3232 anchors.fill: parent
33− z: 2
3433 surface: session ? session.surface : null
3534 }
3635
@@ -53,7 +52,6 @@ Item {
5352 delegate: Loader {
5453 objectName: "childDelegate" + index
5554 anchors.fill: surfaceContainer
56− z: 4
5755
5856 // Only way to do recursive qml items.
5957 source: Qt.resolvedUrl("SessionContainer.qml")
tests/mocks/Unity/Application/SessionManager.cpp−1
@@ -51,4 +51,3 @@ void SessionManager::registerSession(Session *session)
5151 Q_EMIT sessionStopping(session);
5252 });
5353}
54−
tests/qmltests/Stages/RecursingChildSessionControl.qml+4−3
@@ -25,6 +25,7 @@ ColumnLayout {
2525 property var session
2626 property var childSessions: session ? session.childSessions : 0
2727 property bool removable: false
28+ property alias surfaceCheckbox: _surfaceCheckbox
2829
2930 property var screenshotIds: [ "gallery", "map", "facebook", "camera", "browser", "music", "twitter"]
3031
@@ -86,10 +87,10 @@ ColumnLayout {
8687 Layout.fillWidth: true
8788
8889 CheckBox {
89− id: surfaceCheckbox;
90+ id: _surfaceCheckbox;
9091 checked: false;
9192 enabled: root.session
92− onClicked: {
93+ onCheckedChanged: {
9394 if (checked) {
9495 root.session.createSurface();
9596 } else if (root.session.surface) {
@@ -106,7 +107,7 @@ ColumnLayout {
106107 }
107108
108109 Label {
109− text: "surface"
110+ text: "Surface"
110111 anchors.verticalCenter: parent.verticalCenter
111112 }
112113 }
tests/qmltests/Stages/tst_ApplicationWindow.qml+51−20
@@ -14,7 +14,8 @@
1414 * along with this program. If not, see <http://www.gnu.org/licenses/>.
1515 */
1616
17−import QtQuick 2.0
17+import QtQuick 2.1
18+import QtQuick.Layouts 1.1
1819import QtTest 1.0
1920import Unity.Test 0.1 as UT
2021import ".."
@@ -40,7 +41,7 @@ Rectangle {
4041 Connections {
4142 target: fakeApplication
4243 onSessionChanged: {
43− surfaceCheckbox.checked = fakeApplication.session !== null
44+ sessionCheckbox.checked = fakeApplication.session !== null
4445 }
4546 }
4647
@@ -71,30 +72,51 @@ Rectangle {
7172 right: parent.right
7273 }
7374
74− Column {
75+ ColumnLayout {
7576 anchors { left: parent.left; right: parent.right; top: parent.top; margins: units.gu(1) }
7677 spacing: units.gu(1)
77− Row {
78− anchors { left: parent.left; right: parent.right }
78+
79+ RowLayout {
80+ Layout.fillWidth: true
81+
7982 CheckBox {
80− id: surfaceCheckbox; checked: false
83+ id: sessionCheckbox; checked: false
8184 onCheckedChanged: {
8285 if (applicationWindowLoader.status !== Loader.Ready)
8386 return;
8487
8588 if (checked && !fakeApplication.session) {
8689 fakeApplication.createSession();
87− fakeSession.createSurface();
8890 } else if (!checked && fakeApplication.session) {
8991 fakeApplication.session.release();
9092 }
9193 }
9294 }
9395 Label {
94− text: "Surface"
96+ text: "Session"
9597 anchors.verticalCenter: parent.verticalCenter
9698 }
9799 }
100+
101+ Rectangle {
102+ border {
103+ color: "black"
104+ width: 1
105+ }
106+ anchors {
107+ left: parent.left
108+ right: parent.right
109+ }
110+ Layout.preferredHeight: sessionControl.height
111+
112+ RecursingChildSessionControl {
113+ id: sessionControl
114+ anchors { left: parent.left; right: parent.right; }
115+
116+ session: fakeSession
117+ }
118+ }
119+
98120 ListItem.ItemSelector {
99121 id: appStateSelector
100122 anchors { left: parent.left; right: parent.right }
@@ -119,6 +141,7 @@ Rectangle {
119141 fakeApplication.setState(selectedApplicationState);
120142 }
121143 }
144+
122145 }
123146 }
124147
@@ -175,6 +198,14 @@ Rectangle {
175198 findInterestingApplicationWindowChildren();
176199 }
177200
201+ function initSession() {
202+ sessionCheckbox.checked = true;
203+ sessionControl.surfaceCheckbox.checked = true;
204+ }
205+ function cleanupSession() {
206+ sessionCheckbox.checked = false;
207+ }
208+
178209 function cleanup() {
179210 forgetApplicationWindowChildren();
180211
@@ -182,7 +213,7 @@ Rectangle {
182213 applicationWindowLoader.active = false;
183214
184215 appStateSelector.selectedIndex = 0;
185− surfaceCheckbox.checked = false;
216+ cleanupSession();
186217
187218 if (fakeApplication.session)
188219 fakeApplication.session.release();
@@ -202,7 +233,7 @@ Rectangle {
202233 verify(stateGroup.state === "splashScreen");
203234
204235 if (data.swapInitOrder) {
205− surfaceCheckbox.checked = true;
236+ initSession();
206237 } else {
207238 setApplicationState(appRunning);
208239 }
@@ -212,14 +243,14 @@ Rectangle {
212243 if (data.swapInitOrder) {
213244 setApplicationState(appRunning);
214245 } else {
215− surfaceCheckbox.checked = true;
246+ initSession();
216247 }
217248
218249 tryCompare(stateGroup, "state", "surface");
219250 }
220251
221252 function test_suspendedAppShowsSurface() {
222− surfaceCheckbox.checked = true;
253+ initSession();
223254 setApplicationState(appRunning);
224255
225256 tryCompare(stateGroup, "state", "surface");
@@ -233,7 +264,7 @@ Rectangle {
233264 }
234265
235266 function test_killedAppShowsScreenshot() {
236− surfaceCheckbox.checked = true;
267+ initSession();
237268 setApplicationState(appRunning);
238269 tryCompare(stateGroup, "state", "surface");
239270
@@ -252,7 +283,7 @@ Rectangle {
252283 function test_restartApp() {
253284 var screenshotImage = findChild(applicationWindowLoader.item, "screenshotImage");
254285
255− surfaceCheckbox.checked = true;
286+ initSession();
256287 setApplicationState(appRunning);
257288 tryCompare(stateGroup, "state", "surface");
258289 waitUntilTransitionsEnd();
@@ -278,14 +309,14 @@ Rectangle {
278309 waitUntilTransitionsEnd();
279310 verify(stateGroup.state === "screenshot");
280311
281− surfaceCheckbox.checked = true;
312+ initSession();
282313
283314 tryCompare(stateGroup, "state", "surface");
284315 tryCompare(screenshotImage, "status", Image.Null);
285316 }
286317
287318 function test_appCrashed() {
288− surfaceCheckbox.checked = true;
319+ initSession();
289320 setApplicationState(appRunning);
290321 tryCompare(stateGroup, "state", "surface");
291322 waitUntilTransitionsEnd();
@@ -298,7 +329,7 @@ Rectangle {
298329 }
299330
300331 function test_keepSurfaceWhileInvisible() {
301− surfaceCheckbox.checked = true;
332+ initSession();
302333 setApplicationState(appRunning);
303334 tryCompare(stateGroup, "state", "surface");
304335 waitUntilTransitionsEnd();
@@ -319,7 +350,7 @@ Rectangle {
319350
320351 function test_touchesReachSurfaceWhenItsShown() {
321352 setApplicationState(appRunning);
322− surfaceCheckbox.checked = true;
353+ initSession();
323354
324355 tryCompare(stateGroup, "state", "surface");
325356
@@ -338,12 +369,12 @@ Rectangle {
338369 }
339370
340371 function test_showNothingOnSuddenSurfaceLoss() {
341− surfaceCheckbox.checked = true;
372+ initSession();
342373 setApplicationState(appRunning);
343374 tryCompare(stateGroup, "state", "surface");
344375 waitUntilTransitionsEnd();
345376
346− surfaceCheckbox.checked = false;
377+ cleanupSession();
347378
348379 verify(stateGroup.state === "void");
349380 }
tests/qmltests/Stages/tst_SessionContainer.qml+1−1
@@ -103,7 +103,7 @@ Rectangle {
103103 left: parent.left
104104 right: parent.right
105105 }
106− height: sessionChildrenControl.height
106+ Layout.preferredHeight: sessionChildrenControl.height
107107
108108 RecursingChildSessionControl {
109109 id: sessionChildrenControl