on xenial help sign in
SpreadDelegate - properly transition between splash screen, surface and screenshot

- A new component, ApplicationWindow, was created to hold the   splash+surface+screenshot logic originally in the SpreadDelegate. Now the   responsibility of SpreadDelegate is just to do the vertical swipe to close   the app. - qml tests were added for both SpreadDelegate and ApplicationWindow - Fixed UnityTestCase.tap() Fixes: 1359819, 1359821 Approved by: Michał Sawicz, Michael Zanetti

commit76a6dd2c606c0ccd6f873fdd61a2f140d5cb0545 authorDaniel d'Andrada <daniel.dandrada@canonical.com> dateMon 25 Aug 2014, 13:10 (12 years ago) parent48ff4d4645a3f2
41 files changed+1493−751
debian/control+3−3 include/paths.h.in+8 plugins/Unity/Launcher/CMakeLists.txt+1−1 qml/Dash/graphics/phone/screenshots/vkb_portrait.png qml/Stages/AppSurfaceContainer.qml−96 qml/Stages/ApplicationWindow.qml+258 qml/Stages/PhoneStage.qml+16−4 qml/Stages/SpreadDelegate.qml+32−57 qml/Stages/SurfaceContainer.qml+5−11 qml/Stages/TabletStage.qml+13−3 qml/Stages/TransformedSpreadDelegate.qml+1−1 tests/mocks/Unity/Application/Application.qmltypes−19 tests/mocks/Unity/Application/ApplicationImage.cpp−123 tests/mocks/Unity/Application/ApplicationImage.h−79 tests/mocks/Unity/Application/ApplicationInfo.cpp+83−14 tests/mocks/Unity/Application/ApplicationInfo.h+50−44 tests/mocks/Unity/Application/ApplicationManager.cpp+87−102 tests/mocks/Unity/Application/ApplicationManager.h+8−4 tests/mocks/Unity/Application/ApplicationScreenshotProvider.cpp+2−4 tests/mocks/Unity/Application/CMakeLists.txt+1−3 tests/mocks/Unity/Application/InputFilterArea.qml−21 tests/mocks/Unity/Application/MirSurfaceItem.cpp+87−16 tests/mocks/Unity/Application/MirSurfaceItem.h+14−11 tests/mocks/Unity/Application/MirSurfaceItem.qml+57 tests/mocks/Unity/Application/OSKController.qml−20 tests/mocks/Unity/Application/SurfaceManager.cpp+14−3 tests/mocks/Unity/Application/SurfaceManager.h+1−2 tests/mocks/Unity/Application/VirtualKeyboard.cpp−55 tests/mocks/Unity/Application/VirtualKeyboard.h−35 tests/mocks/Unity/Application/VirtualKeyboard.qml+40 tests/mocks/Unity/Application/plugin.cpp−3 tests/mocks/Unity/Application/qmldir−3 tests/plugins/Unity/Launcher/CMakeLists.txt+1−1 tests/plugins/Unity/Launcher/launchermodeltest.cpp−1 tests/qmltests/CMakeLists.txt+3 tests/qmltests/Stages/tst_ApplicationWindow.qml+346 tests/qmltests/Stages/tst_PhoneStage.qml+34−8 tests/qmltests/Stages/tst_SpreadDelegate.qml+167 tests/qmltests/Stages/tst_SurfaceContainer.qml+154 tests/qmltests/tst_Shell.qml+2−2 tests/utils/modules/Unity/Test/UnityTestCase.qml+5−2
debian/control+3−3
@@ -24,7 +24,7 @@ Build-Depends: cmake,
2424 libpulse-dev,
2525 libqmenumodel-dev (>= 0.2.8),
2626 libqt5xmlpatterns5-dev,
27− libunity-api-dev (>= 7.88),
27+ libunity-api-dev (>= 7.89),
2828 libusermetricsoutput1-dev,
2929 libxcb1-dev,
3030 pkg-config,
@@ -112,7 +112,7 @@ Depends: qml-module-qtquick-layouts,
112112 qtdeclarative5-ubuntu-ui-toolkit-plugin (>= 0.1.49) | qtdeclarative5-ubuntu-ui-toolkit-plugin-gles (>= 0.1.49),
113113 qtdeclarative5-unity-notifications-plugin (>= 0.1.2) | unity-notifications-impl,
114114 ubuntu-thumbnailer-impl-0,
115− unity-application-impl-2,
115+ unity-application-impl-3,
116116 unity-notifications-impl-3,
117117 unity-plugin-scopes | unity-scopes-impl,
118118 unity-scopes-impl-4,
@@ -159,7 +159,7 @@ Pre-Depends: ${misc:Pre-Depends},
159159Depends: ${misc:Depends},
160160 ${shlibs:Depends},
161161Provides: unity-application-impl,
162− unity-application-impl-2,
162+ unity-application-impl-3,
163163Description: Fake environment for running Unity 8 shell
164164 Provides fake implementations of some QML modules used by Unity 8 shell
165165 (e.g Ubuntu.Application) so that you can run it in a sandboxed environment.
include/paths.h.in+8
@@ -80,6 +80,14 @@ inline QStringList fallbackImportPaths() {
8080 return paths;
8181}
8282
83+inline QString mockPluginsDir() {
84+ if (isRunningInstalled()) {
85+ return QString("@CMAKE_INSTALL_PREFIX@/@SHELL_INSTALL_QML@/mocks");
86+ } else {
87+ return QString("@CMAKE_BINARY_DIR@/tests/mocks");
88+ }
89+}
90+
8391inline QStringList shellDataDirs() {
8492 QStringList dirs = QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation);
8593 if (!isRunningInstalled()) {
plugins/Unity/Launcher/CMakeLists.txt+1−1
@@ -1,6 +1,6 @@
11include(FindPkgConfig)
22pkg_check_modules(LAUNCHER_API REQUIRED unity-shell-launcher=3)
3−pkg_check_modules(APPLICATION_API REQUIRED unity-shell-application=1)
3+pkg_check_modules(APPLICATION_API REQUIRED unity-shell-application=3)
44pkg_check_modules(GSETTINGS_QT REQUIRED gsettings-qt)
55
66add_definitions(-DSM_BUSNAME=systemBus)
qml/Dash/graphics/phone/screenshots/vkb_portrait.png

Binary file not shown.

qml/Stages/AppSurfaceContainer.qmldeleted−96
@@ -1,96 +0,0 @@
1−/*
2− * Copyright 2014 Canonical Ltd.
3− *
4− * This program is free software; you can redistribute it and/or modify
5− * it under the terms of the GNU Lesser General Public License as published by
6− * the Free Software Foundation; version 3.
7− *
8− * This program is distributed in the hope that it will be useful,
9− * but WITHOUT ANY WARRANTY; without even the implied warranty of
10− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11− * GNU Lesser General Public License for more details.
12− *
13− * You should have received a copy of the GNU Lesser General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15−*/
16−
17−import QtQuick 2.0
18−import "Animations"
19−
20−SurfaceContainer {
21− id: container
22− property var promptSurfaces
23−
24− property bool appHasCreatedASurface: false
25−
26− onSurfaceChanged: {
27− if (surface) {
28− if (!appHasCreatedASurface) {
29− surface.visible = false; // hide until splash screen removed
30− appHasCreatedASurface = true;
31− }
32− }
33− }
34−
35− function revealSurface() {
36− surface.visible = true;
37− splashLoader.source = "";
38− }
39−
40− Timer { //FIXME - need to delay removing splash screen to allow surface resize to complete
41− id: surfaceRevealDelay
42− interval: 100
43− onTriggered: surfaceContainer.revealSurface()
44− }
45−
46− Loader {
47− z: 3
48− id: splashLoader
49− anchors.fill: parent
50− }
51−
52− Repeater {
53− model: container.promptSurfaces
54−
55− delegate: SurfaceContainer {
56− anchors {
57− fill: container
58− topMargin: container.surface.anchors.topMargin
59− rightMargin: container.surface.anchors.rightMargin
60− bottomMargin: container.surface.anchors.bottomMargin
61− leftMargin: container.surface.anchors.leftMargin
62− }
63−
64− z: 4 + index
65− surface: modelData
66−
67− Component.onCompleted: {
68− animateIn();
69− }
70− }
71− }
72−
73− StateGroup {
74− id: appSurfaceState
75− states: [
76− State {
77− name: "noSurfaceYet"
78− when: !surfaceContainer.appHasCreatedASurface
79− StateChangeScript {
80− script: { splashLoader.setSource("Splash.qml", { "name": model.name, "image": model.icon }); }
81− }
82− },
83− State {
84− name: "hasSurface"
85− when: surfaceContainer.appHasCreatedASurface && (surfaceContainer.surface !== null)
86− StateChangeScript { script: { surfaceRevealDelay.start(); } }
87− },
88− State {
89− name: "surfaceLostButAppStillAlive"
90− when: surfaceContainer.appHasCreatedASurface && (surfaceContainer.surface === null)
91− // TODO - use app snapshot
92− }
93− ]
94− state: "noSurfaceYet"
95− }
96−}
qml/Stages/ApplicationWindow.qmlnew file+258
@@ -0,0 +1,258 @@
1+/*
2+ * Copyright 2014 Canonical Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU Lesser General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU Lesser General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU Lesser General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+import QtQuick 2.0
18+import Ubuntu.Components 1.1
19+import Unity.Application 0.1
20+
21+Item {
22+ id: root
23+
24+ // to be read from outside
25+ readonly property bool fullscreen: application ? application.fullscreen : false
26+
27+ // to be set from outside
28+ property bool interactive: true
29+ property QtObject application
30+
31+ QtObject {
32+ id: d
33+
34+ // helpers so that we don't have to check for the existence of an application everywhere
35+ // (in order to avoid breaking qml binding due to a javascript exception)
36+ readonly property string name: root.application ? root.application.name : ""
37+ readonly property url icon: root.application ? root.application.icon : ""
38+ readonly property Item surface: root.application ? root.application.surface : null
39+ readonly property int applicationState: root.application ? root.application.state : -1
40+ readonly property var promptSurfaces: root.application ? root.application.promptSurfaces : null
41+
42+ // Whether the Application had a surface before but lost it.
43+ property bool hadSurface: false
44+
45+ property bool needToTakeScreenshot:
46+ d.surface && d.surfaceInitialized && screenshotImage.status === Image.Null
47+ && d.applicationState === ApplicationInfo.Stopped
48+ onNeedToTakeScreenshotChanged: {
49+ if (needToTakeScreenshot) {
50+ screenshotImage.take();
51+ }
52+ }
53+
54+ //FIXME - this is a hack to avoid the first few rendered frames as they
55+ // might show the UI accommodating due to surface resizes on startup.
56+ // Remove this when possible
57+ property bool surfaceInitialized: false
58+ onSurfaceChanged: {
59+ if (surface) {
60+ surfaceInitTimer.start();
61+ } else {
62+ hadSurface = true;
63+ surfaceInitialized = false;
64+ }
65+ }
66+ }
67+
68+ Timer {
69+ id: surfaceInitTimer
70+ interval: 100
71+ onTriggered: { if (d.surface) {d.surfaceInitialized = true;} }
72+ }
73+
74+ Binding {
75+ target: d.surface
76+ when: d.surface
77+ property: "enabled"
78+ value: root.interactive
79+ }
80+ Binding {
81+ target: d.surface
82+ when: d.surface
83+ property: "focus"
84+ value: root.interactive
85+ }
86+ Connections {
87+ target: d.surface
88+ // FIXME: I would rather not need to do this, but currently it doesn't get
89+ // active focus without it and I don't know why.
90+ onFocusChanged: forceSurfaceActiveFocusIfReady();
91+ onParentChanged: forceSurfaceActiveFocusIfReady();
92+ onEnabledChanged: forceSurfaceActiveFocusIfReady();
93+ function forceSurfaceActiveFocusIfReady() {
94+ if (d.surface.focus && d.surface.parent === surfaceContainer && d.surface.enabled) {
95+ d.surface.forceActiveFocus();
96+ }
97+ }
98+ }
99+
100+ SurfaceContainer {
101+ id: surfaceContainer
102+ objectName: "surfaceContainer"
103+ anchors.fill: parent
104+ surface: d.surface
105+ }
106+
107+ Image {
108+ id: screenshotImage
109+ objectName: "screenshotImage"
110+ source: ""
111+ anchors.fill: parent
112+
113+ function take() {
114+ // Format: "image://application/$APP_ID/$CURRENT_TIME_MS"
115+ // eg: "image://application/calculator-app/123456"
116+ var timeMs = new Date().getTime();
117+ source = "image://application/" + root.application.appId + "/" + timeMs;
118+ }
119+
120+ // Save memory by using a half-resolution (thus quarter size) screenshot
121+ sourceSize.width: root.width / 2
122+ sourceSize.height: root.height / 2
123+ }
124+
125+ Loader {
126+ id: splashLoader
127+ visible: active
128+ active: false
129+ anchors.fill: surfaceContainer
130+ sourceComponent: Component {
131+ Splash { name: d.name; image: d.icon }
132+ }
133+ }
134+
135+ Repeater {
136+ model: d.promptSurfaces
137+
138+ delegate: SurfaceContainer {
139+ anchors {
140+ fill: surfaceContainer
141+ }
142+
143+ surface: modelData
144+
145+ Component.onCompleted: {
146+ animateIn();
147+ }
148+ }
149+ }
150+
151+ StateGroup {
152+ objectName: "applicationWindowStateGroup"
153+ states: [
154+ State {
155+ name: "void"
156+ when:
157+ d.hadSurface && (!d.surface || !d.surfaceInitialized)
158+ &&
159+ screenshotImage.status !== Image.Ready
160+ },
161+ State {
162+ name: "splashScreen"
163+ when:
164+ !d.hadSurface && (!d.surface || !d.surfaceInitialized)
165+ &&
166+ screenshotImage.status !== Image.Ready
167+ },
168+ State {
169+ name: "surface"
170+ when:
171+ (d.surface && d.surfaceInitialized)
172+ &&
173+ (d.applicationState !== ApplicationInfo.Stopped
174+ || screenshotImage.status !== Image.Ready)
175+ },
176+ State {
177+ name: "screenshot"
178+ when:
179+ screenshotImage.status === Image.Ready
180+ &&
181+ (d.applicationState === ApplicationInfo.Stopped
182+ || !d.surface || !d.surfaceInitialized)
183+ }
184+ ]
185+
186+ transitions: [
187+ Transition {
188+ from: ""; to: "splashScreen"
189+ PropertyAction { target: splashLoader; property: "active"; value: true }
190+ },
191+ Transition {
192+ from: "splashScreen"; to: "surface"
193+ SequentialAnimation {
194+ PropertyAction { target: surfaceContainer
195+ property: "visible"; value: true }
196+ UbuntuNumberAnimation { target: splashLoader; property: "opacity";
197+ from: 1.0; to: 0.0
198+ duration: UbuntuAnimation.BriskDuration }
199+ PropertyAction { target: splashLoader; property: "active"; value: false }
200+ }
201+ },
202+ Transition {
203+ from: "surface"; to: "splashScreen"
204+ SequentialAnimation {
205+ PropertyAction { target: splashLoader; property: "active"; value: true }
206+ PropertyAction { target: surfaceContainer
207+ property: "visible"; value: true }
208+ UbuntuNumberAnimation { target: splashLoader; property: "opacity";
209+ from: 0.0; to: 1.0
210+ duration: UbuntuAnimation.BriskDuration }
211+ }
212+ },
213+ Transition {
214+ from: "surface"; to: "screenshot"
215+ SequentialAnimation {
216+ PropertyAction { target: screenshotImage
217+ property: "visible"; value: true }
218+ UbuntuNumberAnimation { target: screenshotImage; property: "opacity";
219+ from: 0.0; to: 1.0
220+ duration: UbuntuAnimation.BriskDuration }
221+ PropertyAction { target: surfaceContainer
222+ property: "visible"; value: false }
223+ ScriptAction { script: { if (d.surface) { d.surface.release(); } } }
224+ }
225+ },
226+ Transition {
227+ from: "screenshot"; to: "surface"
228+ SequentialAnimation {
229+ PropertyAction { target: surfaceContainer
230+ property: "visible"; value: true }
231+ UbuntuNumberAnimation { target: screenshotImage; property: "opacity";
232+ from: 1.0; to: 0.0
233+ duration: UbuntuAnimation.BriskDuration }
234+ PropertyAction { target: screenshotImage; property: "visible"; value: false }
235+ PropertyAction { target: screenshotImage; property: "source"; value: "" }
236+ }
237+ },
238+ Transition {
239+ from: "surface"; to: "void"
240+ SequentialAnimation {
241+ PropertyAction { target: surfaceContainer; property: "visible"; value: false }
242+ ScriptAction { script: { if (d.surface) { d.surface.release(); } } }
243+ }
244+ },
245+ Transition {
246+ from: "void"; to: "surface"
247+ SequentialAnimation {
248+ PropertyAction { target: surfaceContainer; property: "opacity"; value: 0.0 }
249+ PropertyAction { target: surfaceContainer; property: "visible"; value: true }
250+ UbuntuNumberAnimation { target: surfaceContainer; property: "opacity";
251+ from: 0.0; to: 1.0
252+ duration: UbuntuAnimation.BriskDuration }
253+ }
254+ }
255+ ]
256+ }
257+
258+}
qml/Stages/PhoneStage.qml+16−4
@@ -110,7 +110,8 @@ Rectangle {
110110 id: spreadView
111111 objectName: "spreadView"
112112 anchors.fill: parent
113− interactive: (spreadDragArea.status == DirectionalDragArea.Recognized || phase > 1) && draggedIndex == -1
113+ interactive: (spreadDragArea.status == DirectionalDragArea.Recognized || phase > 1)
114+ && draggedDelegateCount === 0
114115 contentWidth: spreadRow.width - shift
115116 contentX: -shift
116117
@@ -148,7 +149,7 @@ Rectangle {
148149 property int phase: 0
149150
150151 property int selectedIndex: -1
151− property int draggedIndex: -1
152+ property int draggedDelegateCount: 0
152153 property int closingIndex: -1
153154
154155 property bool focusChanging: false
@@ -269,7 +270,7 @@ Rectangle {
269270 swipeToCloseEnabled: spreadView.interactive
270271 maximizedAppTopMargin: root.maximizedAppTopMargin
271272 dropShadow: spreadView.active ||
272− priv.focusedAppDelegate.x !== 0
273+ (priv.focusedAppDelegate && priv.focusedAppDelegate.x !== 0)
273274
274275 readonly property bool isDash: model.appId == "unity8-dash"
275276
@@ -290,6 +291,10 @@ Rectangle {
290291 // Otherwise line up for the spread
291292 return spreadView.width + (index - 1) * spreadView.tileDistance;
292293 }
294+
295+ application: ApplicationManager.get(index)
296+ closeable: !isDash
297+
293298 property real behavioredIndex: index
294299 Behavior on behavioredIndex {
295300 enabled: spreadView.closingIndex >= 0
@@ -372,8 +377,15 @@ Rectangle {
372377 }
373378 }
374379
380+ onDraggedChanged: {
381+ if (dragged) {
382+ spreadView.draggedDelegateCount++;
383+ } else {
384+ spreadView.draggedDelegateCount--;
385+ }
386+ }
387+
375388 onClosed: {
376− spreadView.draggedIndex = -1;
377389 spreadView.closingIndex = index;
378390 ApplicationManager.stopApplication(ApplicationManager.get(index).appId);
379391 }
qml/Stages/SpreadDelegate.qml+32−57
@@ -14,75 +14,43 @@
1414 * along with this program. If not, see <http://www.gnu.org/licenses/>.
1515 *
1616 * Authors: Michael Zanetti <michael.zanetti@canonical.com>
17−*/
17+ * Daniel d'Andrada <daniel.dandrada@canonical.com>
18+ */
1819
1920import QtQuick 2.0
20−import Unity.Application 0.1
2121import Ubuntu.Components 1.1
2222import "../Components"
2323
2424Item {
2525 id: root
2626
27+ // to be read from outside
28+ readonly property bool dragged: dragArea.moving
29+ signal clicked()
30+ signal closed()
31+
2732 // to be set from outside
2833 property bool interactive: true
2934 property bool dropShadow: true
3035 property real maximizedAppTopMargin
3136 property alias swipeToCloseEnabled: dragArea.enabled
37+ property bool closeable
38+ property alias application: appWindow.application
3239
33− readonly property bool isFullscreen: surface !== null && surfaceContainer.surface.anchors.topMargin == 0
34−
35− signal clicked()
36− signal closed()
37−
38− AppSurfaceContainer {
39− id: surfaceContainer
40− objectName: "surfaceContainer"
41− anchors.fill: parent
42− surface: model.surface
43− promptSurfaces: model.application.promptSurfaces
44−
45− Binding {
46− target: surfaceContainer.surface
47− property: "anchors.topMargin"
48− value: {
49− return surfaceContainer.surface.state === MirSurfaceItem.Fullscreen ? 0 : maximizedAppTopMargin;
50− }
51− }
52−
53− Binding {
54− target: surface
55− property: "enabled"
56− value: root.interactive
57− }
58− Binding {
59− target: surface
60− property: "focus"
61− value: root.interactive
62− }
40+ Item {
41+ objectName: "appWindowWithShadow"
6342
64− Connections {
65− target: surface
66− // FIXME: I would rather not need to do this, but currently it doesn't get
67− // active focus without it and I don't know why.
68− onFocusChanged: forceSurfaceActiveFocusIfReady();
69− onParentChanged: forceSurfaceActiveFocusIfReady();
70− onEnabledChanged: forceSurfaceActiveFocusIfReady();
71− function forceSurfaceActiveFocusIfReady() {
72− if (surface.focus && surface.parent === surfaceContainer && surface.enabled) {
73− surface.forceActiveFocus();
74− }
75− }
76− }
43+ y: dragArea.distance
44+ width: parent.width
45+ height: parent.height
7746
7847 BorderImage {
79− id: dropShadowImage
8048 anchors {
81− fill: parent
49+ fill: appWindow
8250 leftMargin: -units.gu(2)
8351 rightMargin: -units.gu(2)
8452 bottomMargin: -units.gu(2)
85− topMargin: -units.gu(2) + (root.isFullscreen ? 0 : maximizedAppTopMargin)
53+ topMargin: -units.gu(2)
8654 }
8755 source: "graphics/dropshadow.png"
8856 border { left: 50; right: 50; top: 50; bottom: 50 }
@@ -90,21 +58,26 @@ Item {
9058 Behavior on opacity { UbuntuNumberAnimation {} }
9159 }
9260
93− transform: Translate {
94− y: dragArea.distance
61+ ApplicationWindow {
62+ id: appWindow
63+ anchors {
64+ fill: parent
65+ topMargin: appWindow.fullscreen ? 0 : maximizedAppTopMargin
66+ }
67+
68+ interactive: root.interactive
9569 }
9670 }
9771
9872 DraggingArea {
9973 id: dragArea
74+ objectName: "dragArea"
10075 anchors.fill: parent
10176
10277 property bool moving: false
10378 property real distance: 0
10479
105− onMovingChanged: {
106− spreadView.draggedIndex = moving ? index : -1
107− }
80+ readonly property real minSpeedToClose: units.gu(40)
10881
10982 onDragValueChanged: {
11083 if (!dragging) {
@@ -123,15 +96,15 @@ Item {
12396 }
12497
12598 onDragEnd: {
126− if (model.appId == "unity8-dash") {
99+ if (!root.closeable) {
127100 animation.animate("center")
128101 return;
129102 }
130103
131104 // velocity and distance values specified by design prototype
132− if ((dragVelocity < -units.gu(40) && distance < -units.gu(8)) || distance < -root.height / 2) {
105+ if ((dragVelocity < -minSpeedToClose && distance < -units.gu(8)) || distance < -root.height / 2) {
133106 animation.animate("up")
134− } else if ((dragVelocity > units.gu(40) && distance > units.gu(8)) || distance > root.height / 2) {
107+ } else if ((dragVelocity > minSpeedToClose && distance > units.gu(8)) || distance > root.height / 2) {
135108 animation.animate("down")
136109 } else {
137110 animation.animate("center")
@@ -140,6 +113,7 @@ Item {
140113
141114 UbuntuNumberAnimation {
142115 id: animation
116+ objectName: "closeAnimation"
143117 target: dragArea
144118 property: "distance"
145119 property bool requestClose: false
@@ -164,9 +138,10 @@ Item {
164138 onRunningChanged: {
165139 if (!running) {
166140 dragArea.moving = false;
167− dragArea.distance = 0;
168141 if (requestClose) {
169142 root.closed();
143+ } else {
144+ dragArea.distance = 0;
170145 }
171146 }
172147 }
qml/Stages/SurfaceContainer.qml+5−11
@@ -26,9 +26,12 @@ Item {
2626 if (surface) {
2727 surface.parent = container;
2828 surface.z = 1;
29− state = "initial"
3029 }
3130 }
31+ Binding {
32+ target: surface
33+ property: "anchors.fill"; value: container
34+ }
3235
3336 Connections {
3437 target: surface
@@ -45,7 +48,7 @@ Item {
4548 }
4649
4750 Repeater {
48− model: surface.childSurfaces
51+ model: surface ? surface.childSurfaces : null
4952
5053 delegate: Loader {
5154 z: 2
@@ -81,8 +84,6 @@ Item {
8184 var popped = tmp.pop();
8285 popped.end();
8386 d.animations = tmp;
84− } else {
85− container.state = "initial";
8687 }
8788 }
8889
@@ -96,11 +97,4 @@ Item {
9697 id: swipeFromBottom
9798 SwipeFromBottomAnimation {}
9899 }
99−
100− states: [
101− State {
102− name: "initial"
103− PropertyChanges { target: surface; anchors.fill: container }
104− }
105− ]
106100}
qml/Stages/TabletStage.qml+13−3
@@ -145,7 +145,8 @@ Rectangle {
145145 Flickable {
146146 id: spreadView
147147 anchors.fill: parent
148− interactive: (spreadDragArea.status == DirectionalDragArea.Recognized || phase > 1) && draggedIndex == -1
148+ interactive: (spreadDragArea.status == DirectionalDragArea.Recognized || phase > 1)
149+ && draggedDelegateCount === 0
149150 contentWidth: spreadRow.width - shift
150151 contentX: -shift
151152
@@ -189,7 +190,7 @@ Rectangle {
189190 readonly property real snapPosition: 0.75
190191
191192 property int selectedIndex: -1
192− property int draggedIndex: -1
193+ property int draggedDelegateCount: 0
193194 property int closingIndex: -1
194195
195196 property bool sideStageDragging: sideStageDragHandle.dragging
@@ -475,6 +476,8 @@ Rectangle {
475476 swipeToCloseEnabled: spreadView.interactive
476477 maximizedAppTopMargin: root.maximizedAppTopMargin
477478 dragOffset: !isDash && model.appId == priv.mainStageAppId && root.inverseProgress > 0 ? root.inverseProgress : 0
479+ application: ApplicationManager.get(index)
480+ closeable: !isDash
478481
479482 readonly property bool isDash: model.appId == "unity8-dash"
480483
@@ -533,8 +536,15 @@ Rectangle {
533536 }
534537 }
535538
539+ onDraggedChanged: {
540+ if (dragged) {
541+ spreadView.draggedDelegateCount++;
542+ } else {
543+ spreadView.draggedDelegateCount--;
544+ }
545+ }
546+
536547 onClosed: {
537− spreadView.draggedIndex = -1;
538548 spreadView.closingIndex = index;
539549 ApplicationManager.stopApplication(ApplicationManager.get(index).appId);
540550 }
qml/Stages/TransformedSpreadDelegate.qml+1−1
@@ -309,7 +309,7 @@ SpreadDelegate {
309309 Scale {
310310 origin { x: 0; y: (spreadView.height * priv.scale) + maximizedAppTopMargin * 3 }
311311 xScale: 1
312− yScale: isFullscreen ? 1 - priv.topMarginProgress * maximizedAppTopMargin / spreadView.height : 1
312+ yScale: fullscreen ? 1 - priv.topMarginProgress * maximizedAppTopMargin / spreadView.height : 1
313313 },
314314 Translate {
315315 x: priv.xTranslate
tests/mocks/Unity/Application/Application.qmltypes−19
@@ -7,25 +7,6 @@ import QtQuick.tooling 1.1
77// 'qmlplugindump -notrelocatable Unity.Application 0.1 tests/mocks'
88
99Module {
10− Component {
11− name: "ApplicationImage"
12− defaultProperty: "data"
13− prototype: "QQuickItem"
14− exports: ["Unity.Application/ApplicationImage 0.1"]
15− exportMetaObjectRevisions: [0]
16− Enum {
17− name: "FillMode"
18− values: {
19− "Stretch": 0,
20− "PreserveAspectCrop": 1
21− }
22− }
23− Property { name: "source"; type: "ApplicationInfo"; isPointer: true }
24− Property { name: "fillMode"; type: "FillMode" }
25− Property { name: "ready"; type: "bool" }
26− Method { name: "scheduleUpdate" }
27− Method { name: "updateFromCache" }
28− }
2910 Component {
3011 name: "ApplicationInfo"
3112 prototype: "unity::shell::application::ApplicationInfoInterface"
tests/mocks/Unity/Application/ApplicationImage.cppdeleted−123
@@ -1,123 +0,0 @@
1−/*
2− * Copyright (C) 2013 Canonical, Ltd.
3− *
4− * This program is free software; you can redistribute it and/or modify
5− * it under the terms of the GNU General Public License as published by
6− * the Free Software Foundation; version 3.
7− *
8− * This program is distributed in the hope that it will be useful,
9− * but WITHOUT ANY WARRANTY; without even the implied warranty of
10− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11− * GNU General Public License for more details.
12− *
13− * You should have received a copy of the GNU General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− */
16−
17−#include "ApplicationImage.h"
18−#include "ApplicationInfo.h"
19−
20−#include <QQmlEngine>
21−#include <QQmlComponent>
22−#include <QQmlContext>
23−
24−ApplicationImage::ApplicationImage(QQuickItem* parent)
25− : QQuickItem(parent),
26− m_source(NULL),
27− m_fillMode(Stretch),
28− m_ready(false),
29− m_imageComponent(0),
30− m_imageItem(0)
31−{
32−}
33−
34−void ApplicationImage::setSource(ApplicationInfo* source)
35−{
36− if (m_source != source) {
37− if (m_source)
38− disconnect(m_source, &ApplicationInfo::imageQmlChanged,
39− this, &ApplicationImage::updateImage);
40−
41− m_source = source;
42−
43− if (m_source) {
44− connect(m_source, &ApplicationInfo::imageQmlChanged,
45− this, &ApplicationImage::updateImage);
46− }
47− updateImage();
48−
49− Q_EMIT sourceChanged();
50− }
51−}
52−
53−void ApplicationImage::setFillMode(FillMode newFillMode)
54−{
55− if (m_fillMode != newFillMode) {
56− m_fillMode = newFillMode;
57− Q_EMIT fillModeChanged();
58− }
59−}
60−
61−void ApplicationImage::setReady(bool value)
62−{
63− if (value != m_ready) {
64− m_ready = value;
65− Q_EMIT readyChanged();
66− }
67−}
68−
69−void ApplicationImage::destroyImage()
70−{
71− delete m_imageItem;
72− m_imageItem = 0;
73− delete m_imageComponent;
74− m_imageComponent = 0;
75− m_qmlUsed.clear();
76− setReady(false);
77−}
78−
79−void ApplicationImage::updateImage()
80−{
81− if (!m_source || m_source->imageQml().isEmpty()) {
82− destroyImage();
83− } else if (m_source->imageQml() != m_qmlUsed) {
84− destroyImage();
85− createImageItem();
86− }
87−}
88−
89−void ApplicationImage::createImageItem()
90−{
91−
92− if (!m_imageComponent)
93− createImageComponent();
94−
95− // only create the windowItem one the component is ready
96− if (!m_imageComponent->isReady()) {
97− connect(m_imageComponent, &QQmlComponent::statusChanged,
98− this, &ApplicationImage::onImageComponentStatusChanged);
99− } else {
100− doCreateImageItem();
101− }
102−
103−}
104−
105−void ApplicationImage::createImageComponent()
106−{
107− QQmlEngine *engine = QQmlEngine::contextForObject(this)->engine();
108− m_imageComponent = new QQmlComponent(engine, this);
109− m_imageComponent->setData(m_source->imageQml().toLatin1(), QUrl());
110−}
111−
112−void ApplicationImage::doCreateImageItem()
113−{
114− m_imageItem = qobject_cast<QQuickItem *>(m_imageComponent->create());
115− m_imageItem->setParentItem(this);
116− setReady(true);
117−}
118−
119−void ApplicationImage::onImageComponentStatusChanged(QQmlComponent::Status status)
120−{
121− if (status == QQmlComponent::Ready && !m_imageItem)
122− doCreateImageItem();
123−}
tests/mocks/Unity/Application/ApplicationImage.hdeleted−79
@@ -1,79 +0,0 @@
1−/*
2− * Copyright (C) 2013 Canonical, Ltd.
3− *
4− * This program is free software; you can redistribute it and/or modify
5− * it under the terms of the GNU General Public License as published by
6− * the Free Software Foundation; version 3.
7− *
8− * This program is distributed in the hope that it will be useful,
9− * but WITHOUT ANY WARRANTY; without even the implied warranty of
10− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11− * GNU General Public License for more details.
12− *
13− * You should have received a copy of the GNU General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− */
16−
17−#ifndef APPLICATION_IMAGE_H
18−#define APPLICATION_IMAGE_H
19−
20−#include <QQuickItem>
21−
22−class ApplicationInfo;
23−
24−/* Fake implementation of ApplicationImage
25−
26− That fake implementation is not made in QML just because we can only declare
27− enumerations in C++. We can't even make readonly properties to mimic an enum
28− because properties must begin with a lower case letter.
29−*/
30−class ApplicationImage : public QQuickItem {
31− Q_OBJECT
32− Q_ENUMS(FillMode)
33− Q_PROPERTY(ApplicationInfo* source READ source WRITE setSource NOTIFY sourceChanged)
34− Q_PROPERTY(FillMode fillMode READ fillMode WRITE setFillMode NOTIFY fillModeChanged)
35− Q_PROPERTY(bool ready READ ready WRITE setReady NOTIFY readyChanged)
36−
37−public:
38− explicit ApplicationImage(QQuickItem* parent = 0);
39− virtual ~ApplicationImage() {}
40−
41− enum FillMode { Stretch, PreserveAspectCrop };
42−
43− ApplicationInfo* source() const { return m_source; }
44− void setSource(ApplicationInfo* source);
45−
46− FillMode fillMode() const { return m_fillMode; }
47− void setFillMode(FillMode);
48−
49− void setReady(bool value);
50− bool ready() const { return m_ready; }
51−
52− Q_INVOKABLE void scheduleUpdate() {}
53− Q_INVOKABLE void updateFromCache() {}
54−
55−Q_SIGNALS:
56− void sourceChanged();
57− void fillModeChanged();
58− void readyChanged();
59−
60−private Q_SLOTS:
61− void updateImage();
62− void onImageComponentStatusChanged(QQmlComponent::Status status);
63−
64−private:
65− void createImageItem();
66− void createImageComponent();
67− void doCreateImageItem();
68− void destroyImage();
69−
70− ApplicationInfo* m_source;
71− FillMode m_fillMode;
72− bool m_ready;
73− QQmlComponent *m_imageComponent;
74− QQuickItem* m_imageItem;
75− // the QML script used to create the current m_imageItem
76− QString m_qmlUsed;
77−};
78−
79−#endif // APPLICATION_IMAGE_H
tests/mocks/Unity/Application/ApplicationInfo.cpp+83−14
@@ -18,6 +18,8 @@
1818#include "MirSurfaceItem.h"
1919#include "SurfaceManager.h"
2020
21+#include <paths.h>
22+
2123#include <QGuiApplication>
2224#include <QQuickItem>
2325#include <QQuickView>
@@ -31,10 +33,10 @@ ApplicationInfo::ApplicationInfo(const QString &appId, QObject *parent)
3133 , m_state(Starting)
3234 , m_focused(false)
3335 , m_fullscreen(false)
34− , m_parentItem(0)
3536 , m_surface(0)
37+ , m_manualSurfaceCreation(false)
38+ , m_parentItem(0)
3639{
37− connect(this, &ApplicationInfo::stateChanged, this, &ApplicationInfo::onStateChanged);
3840}
3941
4042ApplicationInfo::ApplicationInfo(QObject *parent)
@@ -43,10 +45,10 @@ ApplicationInfo::ApplicationInfo(QObject *parent)
4345 , m_state(Starting)
4446 , m_focused(false)
4547 , m_fullscreen(false)
46− , m_parentItem(0)
4748 , m_surface(0)
49+ , m_manualSurfaceCreation(false)
50+ , m_parentItem(0)
4851{
49− connect(this, &ApplicationInfo::stateChanged, this, &ApplicationInfo::onStateChanged);
5052}
5153
5254ApplicationInfo::~ApplicationInfo()
@@ -58,23 +60,16 @@ ApplicationInfo::~ApplicationInfo()
5860 }
5961}
6062
61−void ApplicationInfo::onStateChanged(State state)
62−{
63− if (state == ApplicationInfo::Running) {
64− QTimer::singleShot(1000, this, SLOT(createSurface()));
65− } else if (state == ApplicationInfo::Stopped) {
66− setSurface(nullptr);
67− }
68−}
69−
7063void ApplicationInfo::createSurface()
7164{
7265 if (m_surface || state() == ApplicationInfo::Stopped) return;
7366
67+ QUrl screenshotUrl = QString("file://%1").arg(m_screenshotFileName);
68+
7469 setSurface(new MirSurfaceItem(name(),
7570 MirSurfaceItem::Normal,
7671 fullscreen() ? MirSurfaceItem::Fullscreen : MirSurfaceItem::Maximized,
77− screenshot()));
72+ screenshotUrl));
7873}
7974
8075void ApplicationInfo::setSurface(MirSurfaceItem* surface)
@@ -152,3 +147,77 @@ MirSurfaceItem* ApplicationInfo::promptSurfaceAt(QQmlListProperty<MirSurfaceItem
152147 return nullptr;
153148 return p->m_promptSurfaces[index];
154149}
150+
151+void ApplicationInfo::setIconId(const QString &iconId)
152+{
153+ setIcon(QString("file://%1/graphics/applicationIcons/%2@18.png")
154+ .arg(qmlDirectory())
155+ .arg(iconId));
156+}
157+
158+void ApplicationInfo::setScreenshotId(const QString &screenshotId)
159+{
160+ m_screenshotFileName = QString("%1/Dash/graphics/phone/screenshots/%2@12.png")
161+ .arg(qmlDirectory())
162+ .arg(screenshotId);
163+}
164+
165+void ApplicationInfo::setName(const QString &value)
166+{
167+ if (value != m_name) {
168+ m_name = value;
169+ Q_EMIT nameChanged(value);
170+ }
171+}
172+
173+void ApplicationInfo::setIcon(const QUrl &value)
174+{
175+ if (value != m_icon) {
176+ m_icon = value;
177+ Q_EMIT iconChanged(value);
178+ }
179+}
180+
181+void ApplicationInfo::setStage(Stage value)
182+{
183+ if (value != m_stage) {
184+ m_stage = value;
185+ Q_EMIT stageChanged(value);
186+ }
187+}
188+
189+void ApplicationInfo::setState(State value)
190+{
191+ if (value != m_state) {
192+ m_state = value;
193+ Q_EMIT stateChanged(value);
194+
195+ if (!m_manualSurfaceCreation && m_state == ApplicationInfo::Running) {
196+ QTimer::singleShot(1000, this, SLOT(createSurface()));
197+ }
198+ }
199+}
200+
201+void ApplicationInfo::setFocused(bool value)
202+{
203+ if (value != m_focused) {
204+ m_focused = value;
205+ Q_EMIT focusedChanged(value);
206+ }
207+}
208+
209+void ApplicationInfo::setFullscreen(bool value)
210+{
211+ if (value != m_fullscreen) {
212+ m_fullscreen = value;
213+ Q_EMIT fullscreenChanged(value);
214+ }
215+}
216+
217+void ApplicationInfo::setManualSurfaceCreation(bool value)
218+{
219+ if (value != m_manualSurfaceCreation) {
220+ m_manualSurfaceCreation = value;
221+ Q_EMIT manualSurfaceCreationChanged(value);
222+ }
223+}
tests/mocks/Unity/Application/ApplicationInfo.h+50−44
@@ -26,63 +26,52 @@ class MirSurfaceItem;
2626// unity-api
2727#include <unity/shell/application/ApplicationInfoInterface.h>
2828
29−// A pretty dumb file. Just a container for properties.
30−// Implemented in C++ instead of QML just because of the enumerations
31−// See QTBUG-14861
32−
3329using namespace unity::shell::application;
3430
3531class ApplicationInfo : public ApplicationInfoInterface {
3632 Q_OBJECT
3733
3834 Q_PROPERTY(bool fullscreen READ fullscreen WRITE setFullscreen NOTIFY fullscreenChanged)
39− Q_PROPERTY(Stage stage READ stage WRITE setStage NOTIFY stageChanged)
4035 Q_PROPERTY(MirSurfaceItem* surface READ surface NOTIFY surfaceChanged)
4136 Q_PROPERTY(QQmlListProperty<MirSurfaceItem> promptSurfaces READ promptSurfaces NOTIFY promptSurfacesChanged DESIGNABLE false)
4237
4338 // Only exists in this fake implementation
4439
45− // QML component used to represent its image/screenhot
46− Q_PROPERTY(QString imageQml READ imageQml WRITE setImageQml NOTIFY imageQmlChanged)
47−
48− // QML component used to represent the application window
49− Q_PROPERTY(QString windowQml READ windowQml WRITE setWindowQml NOTIFY windowQmlChanged)
40+ // whether the test code will explicitly control the creation of the application surface
41+ Q_PROPERTY(bool manualSurfaceCreation READ manualSurfaceCreation WRITE setManualSurfaceCreation NOTIFY manualSurfaceCreationChanged)
5042
5143public:
5244 ApplicationInfo(QObject *parent = NULL);
5345 ApplicationInfo(const QString &appId, QObject *parent = NULL);
5446 ~ApplicationInfo();
5547
56− #define IMPLEMENT_PROPERTY(name, Name, type) \
57− public: \
58− type name() const { return m_##name; } \
59− void set##Name(const type& value) \
60− { \
61− if (m_##name != value) { \
62− m_##name = value; \
63− Q_EMIT name##Changed(value); \
64− } \
65− } \
66− Q_SIGNALS: \
67− void name##Changed(const type&); \
68− private: \
69− type m_##name;
70−
71− IMPLEMENT_PROPERTY(appId, AppId, QString)
72− IMPLEMENT_PROPERTY(name, Name, QString)
73− IMPLEMENT_PROPERTY(comment, Comment, QString)
74− IMPLEMENT_PROPERTY(icon, Icon, QUrl)
75− IMPLEMENT_PROPERTY(stage, Stage, Stage)
76− IMPLEMENT_PROPERTY(state, State, State)
77− IMPLEMENT_PROPERTY(focused, Focused, bool)
78− IMPLEMENT_PROPERTY(fullscreen, Fullscreen, bool)
79− IMPLEMENT_PROPERTY(imageQml, ImageQml, QString)
80− IMPLEMENT_PROPERTY(windowQml, WindowQml, QString)
81− IMPLEMENT_PROPERTY(screenshot, Screenshot, QUrl)
82−
83− #undef IMPLEMENT_PROPERTY
48+ void setIconId(const QString &iconId);
49+ void setScreenshotId(const QString &screenshotId);
50+
51+ void setAppId(const QString &value) { m_appId = value; }
52+ QString appId() const override { return m_appId; }
53+
54+ void setName(const QString &value);
55+ QString name() const override { return m_name; }
56+
57+ QString comment() const override { return QString(); }
58+
59+ QUrl icon() const override { return m_icon; }
60+
61+ void setStage(Stage value);
62+ Stage stage() const override { return m_stage; }
63+
64+ Q_INVOKABLE void setState(State value);
65+ State state() const override { return m_state; }
66+
67+ void setFocused(bool value);
68+ bool focused() const override { return m_focused; }
69+
70+ QString screenshot() const { return m_screenshotFileName; }
71+
72+ void setFullscreen(bool value);
73+ bool fullscreen() const { return m_fullscreen; }
8474
85−public:
8675 void setSurface(MirSurfaceItem* surface);
8776 MirSurfaceItem* surface() const { return m_surface; }
8877
@@ -92,21 +81,38 @@ public:
9281 QList<MirSurfaceItem*> promptSurfaceList() const;
9382 QQmlListProperty<MirSurfaceItem> promptSurfaces();
9483
84+ bool manualSurfaceCreation() const { return m_manualSurfaceCreation; }
85+ void setManualSurfaceCreation(bool value);
86+
9587Q_SIGNALS:
9688 void surfaceChanged(MirSurfaceItem*);
9789 void promptSurfacesChanged();
90+ void fullscreenChanged(bool value);
91+ void manualSurfaceCreationChanged(bool value);
9892
99−private Q_SLOTS:
100− void onStateChanged(State state);
101−
102− void createSurface();
93+public Q_SLOTS:
94+ Q_INVOKABLE void createSurface();
10395
10496private:
10597 static int promptSurfaceCount(QQmlListProperty<MirSurfaceItem> *prop);
10698 static MirSurfaceItem* promptSurfaceAt(QQmlListProperty<MirSurfaceItem> *prop, int index);
99+ void setIcon(const QUrl &value);
100+ void setScreenshot(const QUrl &value);
101+
102+ QString m_screenshotFileName;
103+
104+ QString m_appId;
105+ QString m_name;
106+ QUrl m_icon;
107+ Stage m_stage;
108+ State m_state;
109+ bool m_focused;
110+ bool m_fullscreen;
111+ MirSurfaceItem* m_surface;
112+
113+ bool m_manualSurfaceCreation;
107114
108115 QQuickItem *m_parentItem;
109− MirSurfaceItem* m_surface;
110116 QList<MirSurfaceItem*> m_promptSurfaces;
111117};
112118
tests/mocks/Unity/Application/ApplicationManager.cpp+87−102
@@ -55,14 +55,32 @@ ApplicationManager::ApplicationManager(QObject *parent)
5555
5656 buildListOfAvailableApplications();
5757
58− startApplication("unity8-dash");
59− focusApplication("unity8-dash");
58+ // polling to find out when the toplevel window has been created as there's
59+ // no signal telling us that
60+ connect(&m_windowCreatedTimer, &QTimer::timeout,
61+ this, &ApplicationManager::onWindowCreatedTimerTimeout);
62+ m_windowCreatedTimer.setSingleShot(false);
63+ m_windowCreatedTimer.start(200);
6064}
6165
6266ApplicationManager::~ApplicationManager()
6367{
6468}
6569
70+void ApplicationManager::onWindowCreatedTimerTimeout()
71+{
72+ if (QGuiApplication::topLevelWindows().count() > 0) {
73+ m_windowCreatedTimer.stop();
74+ onWindowCreated();
75+ }
76+}
77+
78+void ApplicationManager::onWindowCreated()
79+{
80+ startApplication("unity8-dash");
81+ focusApplication("unity8-dash");
82+}
83+
6684int ApplicationManager::rowCount(const QModelIndex& parent) const {
6785 return !parent.isValid() ? m_runningApplications.size() : 0;
6886}
@@ -87,8 +105,6 @@ QVariant ApplicationManager::data(const QModelIndex& index, int role) const {
87105 return app->state();
88106 case RoleFocused:
89107 return app->focused();
90− case RoleScreenshot:
91− return app->screenshot();
92108 case RoleSurface:
93109 return QVariant::fromValue(app->surface());
94110 case RoleFullscreen:
@@ -143,6 +159,16 @@ void ApplicationManager::add(ApplicationInfo *application) {
143159 if (!appIndex.isValid()) return;
144160 Q_EMIT dataChanged(appIndex, appIndex, QVector<int>() << ApplicationManager::RoleSurface);
145161 });
162+ connect(application, &ApplicationInfo::focusedChanged, this, [application, this]() {
163+ QModelIndex appIndex = findIndex(application);
164+ if (!appIndex.isValid()) return;
165+ Q_EMIT dataChanged(appIndex, appIndex, QVector<int>() << ApplicationManager::RoleFocused);
166+ });
167+ connect(application, &ApplicationInfo::stateChanged, this, [application, this]() {
168+ QModelIndex appIndex = findIndex(application);
169+ if (!appIndex.isValid()) return;
170+ Q_EMIT dataChanged(appIndex, appIndex, QVector<int>() << ApplicationManager::RoleState);
171+ });
146172}
147173
148174void ApplicationManager::remove(ApplicationInfo *application) {
@@ -155,7 +181,7 @@ void ApplicationManager::remove(ApplicationInfo *application) {
155181 Q_EMIT countChanged();
156182 if (isEmpty()) Q_EMIT emptyChanged(isEmpty());
157183 }
158− disconnect(application, &ApplicationInfo::surfaceChanged, this, 0);
184+ disconnect(application, 0, this, 0);
159185}
160186
161187void ApplicationManager::move(int from, int to) {
@@ -198,6 +224,21 @@ ApplicationInfo* ApplicationManager::startApplication(const QString &appId,
198224 const QStringList &arguments)
199225{
200226 Q_UNUSED(arguments)
227+ ApplicationInfo *application = add(appId);
228+ if (!application)
229+ return 0;
230+
231+ if (flags.testFlag(ApplicationManager::ForceMainStage)
232+ && application->stage() == ApplicationInfo::SideStage) {
233+ application->setStage(ApplicationInfo::MainStage);
234+ }
235+ application->setState(ApplicationInfo::Running);
236+
237+ return application;
238+}
239+
240+ApplicationInfo* ApplicationManager::add(QString appId)
241+{
201242 ApplicationInfo *application = 0;
202243
203244 for (ApplicationInfo *availableApp : m_availableApplications) {
@@ -207,15 +248,8 @@ ApplicationInfo* ApplicationManager::startApplication(const QString &appId,
207248 }
208249 }
209250
210− if (!application)
211− return 0;
212−
213− if (flags.testFlag(ApplicationManager::ForceMainStage)
214− && application->stage() == ApplicationInfo::SideStage) {
215− application->setStage(ApplicationInfo::MainStage);
216− }
217− add(application);
218− application->setState(ApplicationInfo::Running);
251+ if (application)
252+ add(application);
219253
220254 return application;
221255}
@@ -238,27 +272,6 @@ bool ApplicationManager::stopApplication(const QString &appId)
238272 return true;
239273}
240274
241−bool ApplicationManager::updateScreenshot(const QString &appId)
242−{
243− int idx = -1;
244− ApplicationInfo *application = nullptr;
245− for (int i = 0; i < m_availableApplications.count(); ++i) {
246− application = m_availableApplications.at(i);
247− if (application->appId() == appId) {
248− idx = i;
249− break;
250− }
251− }
252−
253− if (idx == -1) {
254− return false;
255− }
256−
257− QModelIndex appIndex = index(idx);
258− Q_EMIT dataChanged(appIndex, appIndex, QVector<int>() << RoleScreenshot);
259− return true;
260−}
261−
262275QString ApplicationManager::focusedApplicationId() const {
263276 for (ApplicationInfo *app : m_runningApplications) {
264277 if (app->focused()) {
@@ -293,32 +306,18 @@ bool ApplicationManager::focusApplication(const QString &appId)
293306 if (application == nullptr)
294307 return false;
295308
296− if (application->stage() == ApplicationInfo::MainStage) {
297− // unfocus currently focused mainstage app
298− for (ApplicationInfo *app : m_runningApplications) {
299− if (app->focused() && app->stage() == ApplicationInfo::MainStage) {
300− app->setFocused(false);
301− app->setState(ApplicationInfo::Suspended);
302− }
303− }
304−
305− // focus this app
306− application->setFocused(true);
307− application->setState(ApplicationInfo::Running);
308− } else if (application->stage() == ApplicationInfo::SideStage) {
309− // unfocus currently focused sidestage app
310− for (ApplicationInfo *app : m_runningApplications) {
311− if (app->focused() && app->stage() == ApplicationInfo::SideStage) {
312− app->setFocused(false);
313− app->setState(ApplicationInfo::Suspended);
314− }
309+ // unfocus currently focused app
310+ for (ApplicationInfo *app : m_runningApplications) {
311+ if (app->focused()) {
312+ app->setFocused(false);
313+ app->setState(ApplicationInfo::Suspended);
315314 }
316−
317− // focus this app
318− application->setFocused(true);
319− application->setState(ApplicationInfo::Running);
320315 }
321316
317+ // focus this app
318+ application->setFocused(true);
319+ application->setState(ApplicationInfo::Running);
320+
322321 // move app to top of stack
323322 move(m_runningApplications.indexOf(application), 0);
324323 Q_EMIT focusedApplicationIdChanged();
@@ -341,12 +340,6 @@ void ApplicationManager::unfocusCurrentApplication()
341340 Q_EMIT focusedApplicationIdChanged();
342341}
343342
344−void ApplicationManager::generateQmlStrings(ApplicationInfo *application)
345−{
346− application->setScreenshot(QString("file://%1/Dash/graphics/phone/screenshots/%2@12.png").arg(qmlDirectory())
347− .arg(application->icon().toString()));
348−}
349−
350343void ApplicationManager::buildListOfAvailableApplications()
351344{
352345 ApplicationInfo *application;
@@ -354,128 +347,120 @@ void ApplicationManager::buildListOfAvailableApplications()
354347 application = new ApplicationInfo(this);
355348 application->setAppId("unity8-dash");
356349 application->setName("Unity 8 Mock Dash");
357− application->setIcon(QUrl("unity8-dash"));
350+ application->setScreenshotId("unity8-dash");
358351 application->setStage(ApplicationInfo::MainStage);
359− generateQmlStrings(application);
360352 m_availableApplications.append(application);
361353
362354 application = new ApplicationInfo(this);
363355 application->setAppId("dialer-app");
364356 application->setName("Dialer");
365− application->setIcon(QUrl("dialer"));
357+ application->setScreenshotId("dialer");
358+ application->setIconId("dialer-app");
366359 application->setStage(ApplicationInfo::SideStage);
367− generateQmlStrings(application);
368360 m_availableApplications.append(application);
369361
370362 application = new ApplicationInfo(this);
371363 application->setAppId("camera-app");
372364 application->setName("Camera");
373− application->setIcon(QUrl("camera"));
365+ application->setScreenshotId("camera");
366+ application->setIconId("camera");
374367 application->setFullscreen(true);
375− generateQmlStrings(application);
376368 m_availableApplications.append(application);
377369
378370 application = new ApplicationInfo(this);
379371 application->setAppId("gallery-app");
380372 application->setName("Gallery");
381− application->setIcon(QUrl("gallery"));
382− generateQmlStrings(application);
373+ application->setScreenshotId("gallery");
374+ application->setIconId("gallery");
375+ application->setFullscreen(true);
383376 m_availableApplications.append(application);
384377
385378 application = new ApplicationInfo(this);
386379 application->setAppId("facebook-webapp");
387380 application->setName("Facebook");
388− application->setIcon(QUrl("facebook"));
381+ application->setScreenshotId("facebook");
382+ application->setIconId("facebook");
389383 application->setStage(ApplicationInfo::SideStage);
390− generateQmlStrings(application);
391384 m_availableApplications.append(application);
392385
393386 application = new ApplicationInfo(this);
394387 application->setAppId("webbrowser-app");
395388 application->setFullscreen(true);
396389 application->setName("Browser");
397− application->setIcon(QUrl("browser"));
398− generateQmlStrings(application);
390+ application->setScreenshotId("browser");
391+ application->setIconId("browser");
399392 m_availableApplications.append(application);
400393
401394 application = new ApplicationInfo(this);
402395 application->setAppId("twitter-webapp");
403396 application->setName("Twitter");
404− application->setIcon(QUrl("twitter"));
397+ application->setScreenshotId("twitter");
398+ application->setIconId("twitter");
405399 application->setStage(ApplicationInfo::SideStage);
406− generateQmlStrings(application);
400+ m_availableApplications.append(application);
401+
402+ application = new ApplicationInfo(this);
403+ application->setAppId("map");
404+ application->setName("Map");
405+ application->setIconId("map");
406+ application->setScreenshotId("map");
407407 m_availableApplications.append(application);
408408
409409 application = new ApplicationInfo(this);
410410 application->setAppId("gmail-webapp");
411411 application->setName("GMail");
412− application->setIcon(QUrl("gmail"));
412+ application->setIconId("gmail");
413413 m_availableApplications.append(application);
414414
415415 application = new ApplicationInfo(this);
416416 application->setAppId("ubuntu-weather-app");
417417 application->setName("Weather");
418− application->setIcon(QUrl("weather"));
418+ application->setIconId("weather");
419419 application->setStage(ApplicationInfo::SideStage);
420− generateQmlStrings(application);
421420 m_availableApplications.append(application);
422421
423422 application = new ApplicationInfo(this);
424423 application->setAppId("notes-app");
425424 application->setName("Notepad");
426− application->setIcon(QUrl("notepad"));
425+ application->setIconId("notepad");
427426 application->setStage(ApplicationInfo::SideStage);
428427 m_availableApplications.append(application);
429428
430429 application = new ApplicationInfo(this);
431430 application->setAppId("calendar-app");
432431 application->setName("Calendar");
433− application->setIcon(QUrl("calendar"));
432+ application->setIconId("calendar");
434433 application->setStage(ApplicationInfo::SideStage);
435434 m_availableApplications.append(application);
436435
437− application = new ApplicationInfo(this);
438− application->setAppId("mediaplayer-app");
439− application->setName("Media Player");
440− application->setIcon(QUrl("mediaplayer-app"));
441− application->setFullscreen(true);
442− m_availableApplications.append(application);
443−
444436 application = new ApplicationInfo(this);
445437 application->setAppId("evernote");
446438 application->setName("Evernote");
447− application->setIcon(QUrl("evernote"));
448− m_availableApplications.append(application);
449−
450− application = new ApplicationInfo(this);
451− application->setAppId("map");
452− application->setName("Map");
453− application->setIcon(QUrl("map"));
454− generateQmlStrings(application);
439+ application->setIconId("evernote");
455440 m_availableApplications.append(application);
456441
457442 application = new ApplicationInfo(this);
458443 application->setAppId("pinterest");
459444 application->setName("Pinterest");
460− application->setIcon(QUrl("pinterest"));
445+ application->setIconId("pinterest");
461446 m_availableApplications.append(application);
462447
463448 application = new ApplicationInfo(this);
464449 application->setAppId("soundcloud");
465450 application->setName("SoundCloud");
466− application->setIcon(QUrl("soundcloud"));
451+ application->setIconId("soundcloud");
467452 m_availableApplications.append(application);
468453
469454 application = new ApplicationInfo(this);
470455 application->setAppId("wikipedia");
471456 application->setName("Wikipedia");
472− application->setIcon(QUrl("wikipedia"));
457+ application->setIconId("wikipedia");
473458 m_availableApplications.append(application);
474459
475460 application = new ApplicationInfo(this);
476461 application->setAppId("youtube");
477462 application->setName("YouTube");
478− application->setIcon(QUrl("youtube"));
463+ application->setIconId("youtube");
479464 m_availableApplications.append(application);
480465}
481466
tests/mocks/Unity/Application/ApplicationManager.h+8−4
@@ -20,6 +20,7 @@
2020#include <QObject>
2121#include <QList>
2222#include <QStringList>
23+#include <QTimer>
2324#include "ApplicationInfo.h"
2425
2526// unity-api
@@ -51,7 +52,7 @@ class ApplicationManager : public ApplicationManagerInterface {
5152 static ApplicationManager *singleton();
5253
5354 enum MoreRoles {
54− RoleSurface = RoleScreenshot+1,
55+ RoleSurface = RoleFocused+1,
5556 RoleFullscreen,
5657 RoleApplication,
5758 };
@@ -97,7 +98,6 @@ class ApplicationManager : public ApplicationManagerInterface {
9798 Q_INVOKABLE ApplicationInfo *startApplication(const QString &appId, const QStringList &arguments = QStringList()) override;
9899 Q_INVOKABLE ApplicationInfo *startApplication(const QString &appId, ExecFlags flags, const QStringList &arguments = QStringList());
99100 Q_INVOKABLE bool stopApplication(const QString &appId) override;
100− Q_INVOKABLE bool updateScreenshot(const QString &appId) override;
101101
102102 QString focusedApplicationId() const override;
103103 bool suspended() const;
@@ -105,6 +105,7 @@ class ApplicationManager : public ApplicationManagerInterface {
105105
106106 // Only for testing
107107 Q_INVOKABLE QStringList availableApplications();
108+ Q_INVOKABLE ApplicationInfo* add(QString appId);
108109
109110 QModelIndex findIndex(ApplicationInfo* application);
110111
@@ -115,15 +116,18 @@ class ApplicationManager : public ApplicationManagerInterface {
115116 void focusRequested(const QString &appId);
116117 void emptyChanged(bool empty);
117118
119+ private Q_SLOTS:
120+ void onWindowCreatedTimerTimeout();
121+
118122 private:
119123 void add(ApplicationInfo *application);
120124 void remove(ApplicationInfo* application);
121− void showApplicationWindow(ApplicationInfo *application);
122125 void buildListOfAvailableApplications();
123− void generateQmlStrings(ApplicationInfo *application);
126+ void onWindowCreated();
124127 bool m_suspended;
125128 QList<ApplicationInfo*> m_runningApplications;
126129 QList<ApplicationInfo*> m_availableApplications;
130+ QTimer m_windowCreatedTimer;
127131
128132 static ApplicationManager *the_application_manager;
129133};
tests/mocks/Unity/Application/ApplicationScreenshotProvider.cpp+2−4
@@ -44,11 +44,9 @@ QImage ApplicationScreenshotProvider::requestImage(const QString &imageId, QSize
4444 return QImage();
4545 }
4646
47− QString filePath = QString("%1/Dash/graphics/phone/screenshots/%2@12.png").arg(qmlDirectory()).arg(app->icon().toString());
48−
4947 QImage image;
50− if (!image.load(filePath)) {
51− qWarning() << "failed loading app image" << filePath;
48+ if (!image.load(app->screenshot())) {
49+ qWarning() << "failed loading app image" << app->screenshot();
5250 }
5351
5452
tests/mocks/Unity/Application/CMakeLists.txt+1−3
@@ -1,15 +1,13 @@
1−pkg_check_modules(APPLICATION_API REQUIRED unity-shell-application)
1+pkg_check_modules(APPLICATION_API REQUIRED unity-shell-application=3)
22
33set(FakeUnityApplicationQml_SOURCES
44 plugin.cpp
55 ApplicationDBusAdaptor.cpp
66 ApplicationInfo.cpp
7− ApplicationImage.cpp
87 ApplicationManager.cpp
98 ApplicationScreenshotProvider.cpp
109 MirSurfaceItem.cpp
1110 SurfaceManager.cpp
12− VirtualKeyboard.cpp
1311 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/ApplicationInfoInterface.h
1412 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/ApplicationManagerInterface.h
1513)
tests/mocks/Unity/Application/InputFilterArea.qmldeleted−21
@@ -1,21 +0,0 @@
1−/*
2− * Copyright (C) 2013 Canonical, Ltd.
3− *
4− * This program is free software; you can redistribute it and/or modify
5− * it under the terms of the GNU General Public License as published by
6− * the Free Software Foundation; version 3.
7− *
8− * This program is distributed in the hope that it will be useful,
9− * but WITHOUT ANY WARRANTY; without even the implied warranty of
10− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11− * GNU General Public License for more details.
12− *
13− * You should have received a copy of the GNU General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− */
16−
17−import QtQuick 2.0;
18−
19−Item {
20− property bool blockInput: false
21−}
tests/mocks/Unity/Application/MirSurfaceItem.cpp+87−16
@@ -17,33 +17,67 @@
1717#include "MirSurfaceItem.h"
1818#include "ApplicationInfo.h"
1919
20−#include <QPainter>
20+#include <paths.h>
21+
22+#include <QGuiApplication>
23+#include <QQuickView>
24+#include <QQmlProperty>
2125#include <QQmlEngine>
26+#include <QString>
27+
28+#include <QDebug>
2229
2330MirSurfaceItem::MirSurfaceItem(const QString& name,
2431 MirSurfaceItem::Type type,
2532 MirSurfaceItem::State state,
2633 const QUrl& screenshot,
34+ const QString &qmlFilePath,
2735 QQuickItem *parent)
28− : QQuickPaintedItem(parent)
36+ : QQuickItem(parent)
2937 , m_application(nullptr)
3038 , m_name(name)
3139 , m_type(type)
3240 , m_state(state)
33− , m_img(screenshot.isLocalFile() ? screenshot.toLocalFile() : screenshot.toString())
3441 , m_parentSurface(nullptr)
35− , m_haveInputMethod(false)
42+ , m_qmlItem(nullptr)
43+ , m_screenshotUrl(screenshot)
3644{
3745 qDebug() << "MirSurfaceItem::MirSurfaceItem() " << this->name();
3846
3947 QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership);
4048
41− // The virtual keyboard (input method) has a big transparent area so that
42− // content behind it show through
43− setFillColor(Qt::transparent);
44−
4549 connect(this, &QQuickItem::focusChanged,
4650 this, &MirSurfaceItem::onFocusChanged);
51+
52+ // The assumptions I make here really should hold.
53+ QQuickView *quickView =
54+ qobject_cast<QQuickView*>(QGuiApplication::topLevelWindows()[0]);
55+
56+ QString qmlComponentFilePath;
57+ if (!qmlFilePath.isEmpty()) {
58+ qmlComponentFilePath.append(qmlFilePath);
59+ } else {
60+ qmlComponentFilePath = QString("%1/Unity/Application/MirSurfaceItem.qml")
61+ .arg(mockPluginsDir());
62+ }
63+
64+ m_qmlContentComponent = new QQmlComponent(quickView->engine(), qmlComponentFilePath);
65+
66+ switch (m_qmlContentComponent->status()) {
67+ case QQmlComponent::Ready:
68+ createQmlContentItem();
69+ break;
70+ case QQmlComponent::Loading:
71+ connect(m_qmlContentComponent, &QQmlComponent::statusChanged,
72+ this, &MirSurfaceItem::onComponentStatusChanged);
73+ break;
74+ case QQmlComponent::Error:
75+ printComponentErrors();
76+ qFatal("MirSurfaceItem: failed to create content component.");
77+ break;
78+ default:
79+ qFatal("MirSurfaceItem: Unhandled component status");
80+ }
4781}
4882
4983MirSurfaceItem::~MirSurfaceItem()
@@ -61,10 +95,11 @@ MirSurfaceItem::~MirSurfaceItem()
6195 m_application->removeSurface(this);
6296}
6397
64−void MirSurfaceItem::paint(QPainter * painter)
98+void MirSurfaceItem::printComponentErrors()
6599{
66− if (!m_img.isNull()) {
67− painter->drawImage(contentsBoundingRect(), m_img, QRect(QPoint(0,0), m_img.size()));
100+ QList<QQmlError> errors = m_qmlContentComponent->errors();
101+ for (int i = 0; i < errors.count(); ++i) {
102+ qDebug() << errors[i];
68103 }
69104}
70105
@@ -155,19 +190,24 @@ MirSurfaceItem* MirSurfaceItem::childSurfaceAt(QQmlListProperty<MirSurfaceItem>
155190}
156191
157192
158−void MirSurfaceItem::touchEvent(QTouchEvent * event)
193+void MirSurfaceItem::onQmlWantInputMethodChanged()
159194{
160− if (event->type() == QEvent::TouchBegin && hasFocus()) {
195+ QQmlProperty prop(m_qmlItem, "wantInputMethod");
196+ bool wantInputMethod = prop.read().toBool();
197+
198+ if (hasFocus() && wantInputMethod) {
161199 Q_EMIT inputMethodRequested();
162− m_haveInputMethod = true;
163200 }
164201}
165202
166203void MirSurfaceItem::onFocusChanged()
167204{
168− if (!hasFocus() && m_haveInputMethod) {
205+ QQmlProperty prop(m_qmlItem, "wantInputMethod");
206+ bool wantInputMethod = prop.read().toBool();
207+
208+ if (!hasFocus() && wantInputMethod) {
169209 Q_EMIT inputMethodDismissed();
170− m_haveInputMethod = false;
210+ prop.write(QVariant::fromValue(false));
171211 }
172212}
173213
@@ -178,3 +218,34 @@ void MirSurfaceItem::setState(MirSurfaceItem::State newState)
178218 Q_EMIT stateChanged(newState);
179219 }
180220}
221+
222+void MirSurfaceItem::onComponentStatusChanged(QQmlComponent::Status status)
223+{
224+ if (status == QQmlComponent::Ready) {
225+ createQmlContentItem();
226+ }
227+}
228+
229+void MirSurfaceItem::createQmlContentItem()
230+{
231+ qDebug() << "MirSurfaceItem::createQmlContentItem()";
232+
233+ m_qmlItem = qobject_cast<QQuickItem*>(m_qmlContentComponent->create());
234+ m_qmlItem->setParentItem(this);
235+
236+ setImplicitWidth(m_qmlItem->implicitWidth());
237+ setImplicitHeight(m_qmlItem->implicitHeight());
238+
239+ {
240+ QQmlProperty screenshotSource(m_qmlItem, "screenshotSource");
241+ screenshotSource.write(QVariant::fromValue(m_screenshotUrl));
242+ }
243+
244+ {
245+ QQmlProperty prop(m_qmlItem, "wantInputMethod");
246+ if (prop.type() == QQmlProperty::Property) {
247+ bool ok = prop.connectNotifySignal(this, SLOT(onQmlWantInputMethodChanged()));
248+ if (!ok) qCritical("MirSurfaceItem: failed to connect to wantInputMethod notify signal");
249+ }
250+ }
251+}
tests/mocks/Unity/Application/MirSurfaceItem.h+14−11
@@ -17,12 +17,13 @@
1717#ifndef MIRSURFACEITEM_H
1818#define MIRSURFACEITEM_H
1919
20−#include <QQuickPaintedItem>
21−#include <QImage>
20+#include <QQuickItem>
21+#include <QQmlComponent>
22+#include <QUrl>
2223
2324class ApplicationInfo;
2425
25−class MirSurfaceItem : public QQuickPaintedItem
26+class MirSurfaceItem : public QQuickItem
2627{
2728 Q_OBJECT
2829 Q_ENUMS(Type)
@@ -59,6 +60,7 @@ public:
5960 Type type,
6061 State state,
6162 const QUrl& screenshot,
63+ const QString &qmlFilePath = QString(),
6264 QQuickItem *parent = 0);
6365 ~MirSurfaceItem();
6466
@@ -76,9 +78,6 @@ public:
7678 Q_INVOKABLE void setState(State newState);
7779 Q_INVOKABLE void release();
7880
79− void paint(QPainter * painter) override;
80− void touchEvent(QTouchEvent * event) override;
81−
8281Q_SIGNALS:
8382 void typeChanged(Type);
8483 void stateChanged(State);
@@ -93,9 +92,8 @@ Q_SIGNALS:
9392
9493private Q_SLOTS:
9594 void onFocusChanged();
96−
97−protected:
98− const QImage &screenshotImage() { return m_img; }
95+ void onComponentStatusChanged(QQmlComponent::Status status);
96+ void onQmlWantInputMethodChanged();
9997
10098private:
10199 void addChildSurface(MirSurfaceItem* surface);
@@ -105,15 +103,20 @@ private:
105103 static int childSurfaceCount(QQmlListProperty<MirSurfaceItem> *prop);
106104 static MirSurfaceItem* childSurfaceAt(QQmlListProperty<MirSurfaceItem> *prop, int index);
107105
106+ void createQmlContentItem();
107+ void printComponentErrors();
108+
108109 ApplicationInfo* m_application;
109110 const QString m_name;
110111 const Type m_type;
111112 State m_state;
112− const QImage m_img;
113113
114114 MirSurfaceItem* m_parentSurface;
115115 QList<MirSurfaceItem*> m_children;
116− bool m_haveInputMethod;
116+
117+ QQmlComponent *m_qmlContentComponent;
118+ QQuickItem *m_qmlItem;
119+ QUrl m_screenshotUrl;
117120};
118121
119122Q_DECLARE_METATYPE(MirSurfaceItem*)
tests/mocks/Unity/Application/MirSurfaceItem.qmlnew file+57
@@ -0,0 +1,57 @@
1+/*
2+ * Copyright 2014 Canonical Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU Lesser General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU Lesser General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU Lesser General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+import QtQuick 2.0
18+
19+Rectangle {
20+ objectName: "fakeSurfaceQML"
21+ id: root
22+ color: "pink"
23+
24+ anchors.fill: parent
25+
26+ implicitWidth: units.gu(40)
27+ implicitHeight: units.gu(70)
28+
29+ property alias screenshotSource: screenshotImage.source
30+
31+ property bool wantInputMethod: false
32+
33+ property int touchPressCount: 0
34+ property int touchReleaseCount: 0
35+
36+ Image {
37+ id: screenshotImage
38+ anchors.fill: parent
39+ fillMode: Image.Stretch
40+ }
41+
42+ Text {
43+ anchors.fill: parent
44+ text: "SURFACE"
45+ color: "yellow"
46+ font.bold: true
47+ fontSizeMode: Text.Fit
48+ minimumPixelSize: 10; font.pixelSize: 200
49+ verticalAlignment: Text.AlignVCenter
50+ }
51+
52+ MultiPointTouchArea {
53+ anchors.fill: parent
54+ onPressed: { root.wantInputMethod = true; root.touchPressCount++; }
55+ onReleased: { root.touchReleaseCount++; }
56+ }
57+}
tests/mocks/Unity/Application/OSKController.qmldeleted−20
@@ -1,20 +0,0 @@
1−/*
2− * Copyright (C) 2013 Canonical, Ltd.
3− *
4− * This program is free software; you can redistribute it and/or modify
5− * it under the terms of the GNU General Public License as published by
6− * the Free Software Foundation; version 3.
7− *
8− * This program is distributed in the hope that it will be useful,
9− * but WITHOUT ANY WARRANTY; without even the implied warranty of
10− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11− * GNU General Public License for more details.
12− *
13− * You should have received a copy of the GNU General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− */
16−
17−import QtQuick 2.0;
18−
19−Item {
20−}
tests/mocks/Unity/Application/SurfaceManager.cpp+14−3
@@ -16,9 +16,8 @@
1616
1717#include "SurfaceManager.h"
1818
19+#include <paths.h>
1920#include "MirSurfaceItem.h"
20−#include "VirtualKeyboard.h"
21−
2221
2322SurfaceManager *SurfaceManager::the_surface_manager = nullptr;
2423
@@ -66,7 +65,19 @@ void SurfaceManager::hideInputMethod()
6665MirSurfaceItem *SurfaceManager::inputMethodSurface()
6766{
6867 if (!m_virtualKeyboard) {
69− m_virtualKeyboard = new VirtualKeyboard(MirSurfaceItem::Minimized);
68+
69+ QString screenshotPath = QString("file://%1/Dash/graphics/phone/screenshots/vkb_portrait.png")
70+ .arg(qmlDirectory());
71+
72+ QString qmlFilePath = QString("%1/Unity/Application/VirtualKeyboard.qml")
73+ .arg(mockPluginsDir());
74+
75+ m_virtualKeyboard = new MirSurfaceItem(
76+ "input-method",
77+ MirSurfaceItem::InputMethod,
78+ MirSurfaceItem::Minimized,
79+ screenshotPath,
80+ qmlFilePath);
7081 Q_EMIT surfaceCreated(m_virtualKeyboard);
7182 }
7283 return m_virtualKeyboard;
tests/mocks/Unity/Application/SurfaceManager.h+1−2
@@ -20,7 +20,6 @@
2020#include <QObject>
2121
2222class MirSurfaceItem;
23−class VirtualKeyboard;
2423
2524class SurfaceManager : public QObject
2625{
@@ -48,7 +47,7 @@ private Q_SLOTS:
4847
4948private:
5049 static SurfaceManager *the_surface_manager;
51− VirtualKeyboard *m_virtualKeyboard;
50+ MirSurfaceItem *m_virtualKeyboard;
5251};
5352
5453#endif // SURFACEMANAGER_H
tests/mocks/Unity/Application/VirtualKeyboard.cppdeleted−55
@@ -1,55 +0,0 @@
1−/*
2− * Copyright (C) 2014 Canonical, Ltd.
3− *
4− * This program is free software; you can redistribute it and/or modify
5− * it under the terms of the GNU General Public License as published by
6− * the Free Software Foundation; version 3.
7− *
8− * This program is distributed in the hope that it will be useful,
9− * but WITHOUT ANY WARRANTY; without even the implied warranty of
10− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11− * GNU General Public License for more details.
12− *
13− * You should have received a copy of the GNU General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− */
16−
17−#include "VirtualKeyboard.h"
18−
19−#include <paths.h>
20−
21−VirtualKeyboard::VirtualKeyboard(State state, QQuickItem *parent)
22− : MirSurfaceItem("input-method",
23− MirSurfaceItem::InputMethod,
24− state,
25− QString("file://%1/Dash/graphics/phone/screenshots/vkb_portrait.png").arg(qmlDirectory()),
26− parent)
27−{
28−}
29−
30−void VirtualKeyboard::touchEvent(QTouchEvent *event)
31−{
32− if (event->type() == QEvent::TouchBegin && !hasTouchInsideKeyboard(event)) {
33− event->ignore();
34− }
35−}
36−
37−bool VirtualKeyboard::hasTouchInsideKeyboard(QTouchEvent *event)
38−{
39− const QList<QTouchEvent::TouchPoint> &touchPoints = event->touchPoints();
40− for (int i = 0; i < touchPoints.count(); ++i) {
41− QPoint pos = touchPoints.at(i).pos().toPoint();
42−
43− // Map to image coords
44− int imageX = (int)( ( ((qreal)pos.x()) / width() ) * ((qreal)screenshotImage().size().width()) );
45− int imageY = (int)( ( ((qreal)pos.y()) / height() ) * ((qreal)screenshotImage().size().height()) );
46−
47− QRgb pixelHit = screenshotImage().pixel(imageX, imageY);
48−
49− // The keyboard depicted in the image is in its opaque part.
50− if (qAlpha(pixelHit) != 0) {
51− return true;
52− }
53− }
54− return false;
55−}
tests/mocks/Unity/Application/VirtualKeyboard.hdeleted−35
@@ -1,35 +0,0 @@
1−/*
2− * Copyright (C) 2014 Canonical, Ltd.
3− *
4− * This program is free software; you can redistribute it and/or modify
5− * it under the terms of the GNU General Public License as published by
6− * the Free Software Foundation; version 3.
7− *
8− * This program is distributed in the hope that it will be useful,
9− * but WITHOUT ANY WARRANTY; without even the implied warranty of
10− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11− * GNU General Public License for more details.
12− *
13− * You should have received a copy of the GNU General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− */
16−
17−#ifndef VIRTUALKEYBOARD_H
18−#define VIRTUALKEYBOARD_H
19−
20−#include "MirSurfaceItem.h"
21−
22−class VirtualKeyboard : public MirSurfaceItem
23−{
24− Q_OBJECT
25−public:
26− VirtualKeyboard(State state,
27− QQuickItem *parent = 0);
28−
29− void touchEvent(QTouchEvent * event) override;
30−
31−private:
32− bool hasTouchInsideKeyboard(QTouchEvent *event);
33−};
34−
35−#endif // VIRTUALKEYBOARD_H
tests/mocks/Unity/Application/VirtualKeyboard.qmlnew file+40
@@ -0,0 +1,40 @@
1+/*
2+ * Copyright 2014 Canonical Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU Lesser General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU Lesser General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU Lesser General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+import QtQuick 2.0
18+
19+Item {
20+ implicitWidth: units.gu(40)
21+ implicitHeight: units.gu(70)
22+
23+ anchors.fill: parent
24+
25+ property alias screenshotSource: screenshotImage.source
26+
27+ property bool landscape: width > height
28+
29+ Image {
30+ id: screenshotImage
31+ height: landscape ? parent.height * 0.4 : width * 0.6
32+ anchors.bottom: parent.bottom
33+ anchors.left: parent.left
34+ anchors.right: parent.right
35+
36+ MultiPointTouchArea {
37+ anchors.fill: parent
38+ }
39+ }
40+}
tests/mocks/Unity/Application/plugin.cpp−3
@@ -16,7 +16,6 @@
1616
1717#include "plugin.h"
1818#include "ApplicationInfo.h"
19−#include "ApplicationImage.h"
2019#include "ApplicationManager.h"
2120#include "ApplicationScreenshotProvider.h"
2221#include "MirSurfaceItem.h"
@@ -49,8 +48,6 @@ void FakeUnityApplicationQmlPlugin::registerTypes(const char *uri)
4948 qmlRegisterType<ApplicationInfo>(uri, 0, 1, "ApplicationInfo");
5049
5150 qmlRegisterUncreatableType<MirSurfaceItem>(uri, 0, 1, "MirSurfaceItem", "MirSurfaceItem can't be instantiated from QML");
52−
53− qmlRegisterType<ApplicationImage>(uri, 0, 1, "ApplicationImage");
5451}
5552
5653void FakeUnityApplicationQmlPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
tests/mocks/Unity/Application/qmldir−3
@@ -1,6 +1,3 @@
11module Unity.Application
22plugin FakeUnityApplicationQml
33typeinfo Application.qmltypes
4−
5−InputFilterArea 0.1 InputFilterArea.qml
6−OSKController 0.1 OSKController.qml
tests/plugins/Unity/Launcher/CMakeLists.txt+1−1
@@ -1,6 +1,6 @@
11pkg_check_modules(GSETTINGS_QT REQUIRED gsettings-qt)
22pkg_check_modules(LAUNCHER_API REQUIRED unity-shell-launcher=3)
3−pkg_check_modules(APPLICATION_API REQUIRED unity-shell-application=1)
3+pkg_check_modules(APPLICATION_API REQUIRED unity-shell-application=3)
44
55include_directories(
66 ${CMAKE_CURRENT_BINARY_DIR}
tests/plugins/Unity/Launcher/launchermodeltest.cpp−1
@@ -93,7 +93,6 @@ public:
9393 m_list.takeAt(index)->deleteLater();
9494 endRemoveRows();
9595 }
96− bool updateScreenshot(const QString &appId) { Q_UNUSED(appId); return true; }
9796 bool requestFocusApplication(const QString &appId) { Q_UNUSED(appId); return true; }
9897 bool suspended() const { return false; }
9998 void setSuspended(bool) {}
tests/qmltests/CMakeLists.txt+3
@@ -76,4 +76,7 @@ add_qml_test(Panel/Indicators CachedUnityMenuModel ENVIRONMENT "LD_LIBRARY_PATH=
7676# These MenuItemFactory tests need the test/mocks/ to come before plugins/
7777add_qml_test(Panel/Indicators MenuItemFactory IMPORT_PATHS ${CMAKE_BINARY_DIR}/tests/mocks ${qmltest_DEFAULT_IMPORT_PATHS})
7878add_qml_test(Panel/Indicators MessageMenuItemFactory IMPORT_PATHS ${CMAKE_BINARY_DIR}/tests/mocks ${qmltest_DEFAULT_IMPORT_PATHS})
79+add_qml_test(Stages ApplicationWindow ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/tests/mocks/libusermetrics:${CMAKE_BINARY_DIR}/tests/mocks/LightDM/single")
7980add_qml_test(Stages PhoneStage ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/tests/mocks/libusermetrics:${CMAKE_BINARY_DIR}/tests/mocks/LightDM/single")
81+add_qml_test(Stages SpreadDelegate ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/tests/mocks/libusermetrics:${CMAKE_BINARY_DIR}/tests/mocks/LightDM/single")
82+add_qml_test(Stages SurfaceContainer ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/tests/mocks/libusermetrics:${CMAKE_BINARY_DIR}/tests/mocks/LightDM/single")
tests/qmltests/Stages/tst_ApplicationWindow.qmlnew file+346
@@ -0,0 +1,346 @@
1+/*
2+ * Copyright 2014 Canonical Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+import QtQuick 2.0
18+import QtTest 1.0
19+import Unity.Test 0.1 as UT
20+import ".."
21+import "../../../qml/Stages"
22+import Ubuntu.Components 0.1
23+import Ubuntu.Components.ListItems 1.0 as ListItem
24+import Unity.Application 0.1
25+
26+Rectangle {
27+ color: "red"
28+ id: root
29+ width: units.gu(70)
30+ height: units.gu(70)
31+
32+ Component.onCompleted: {
33+ root.fakeApplication = ApplicationManager.add("gallery-app");
34+ root.fakeApplication.manualSurfaceCreation = true;
35+ root.fakeApplication.setState(ApplicationInfo.Starting);
36+ }
37+ property QtObject fakeApplication: null
38+
39+ Connections {
40+ target: fakeApplication
41+ onSurfaceChanged: {
42+ surfaceCheckbox.checked = fakeApplication.surface !== null;
43+ }
44+ }
45+
46+ Component {
47+ id: applicationWindowComponent
48+ ApplicationWindow {
49+ anchors.fill: parent
50+ application: fakeApplication
51+ }
52+ }
53+ Loader {
54+ id: applicationWindowLoader
55+ anchors {
56+ top: parent.top
57+ bottom: parent.bottom
58+ left: parent.left
59+ }
60+ width: units.gu(40)
61+ sourceComponent: applicationWindowComponent
62+ }
63+
64+ Rectangle {
65+ color: "white"
66+ anchors {
67+ top: parent.top
68+ bottom: parent.bottom
69+ left: applicationWindowLoader.right
70+ right: parent.right
71+ }
72+
73+ Column {
74+ anchors { left: parent.left; right: parent.right; top: parent.top; margins: units.gu(1) }
75+ spacing: units.gu(1)
76+ Row {
77+ anchors { left: parent.left; right: parent.right }
78+ CheckBox {
79+ id: surfaceCheckbox; checked: false
80+ onCheckedChanged: {
81+ if (applicationWindowLoader.status !== Loader.Ready)
82+ return;
83+
84+ if (checked && !fakeApplication.surface) {
85+ fakeApplication.createSurface();
86+ } else if (!checked && fakeApplication.surface) {
87+ fakeApplication.surface.release();
88+ }
89+ }
90+ }
91+ Label { text: "Surface" }
92+ }
93+ ListItem.ItemSelector {
94+ id: appStateSelector
95+ anchors { left: parent.left; right: parent.right }
96+ text: "Application state"
97+ model: ["Starting",
98+ "Running",
99+ "Suspended",
100+ "Stopped"]
101+ property int selectedApplicationState: {
102+ if (model[selectedIndex] === "Starting") {
103+ return ApplicationInfo.Starting;
104+ } else if (model[selectedIndex] === "Running") {
105+ return ApplicationInfo.Running;
106+ } else if (model[selectedIndex] === "Suspended") {
107+ return ApplicationInfo.Suspended;
108+ } else {
109+ return ApplicationInfo.Stopped;
110+ }
111+ }
112+ onSelectedApplicationStateChanged: {
113+ // state is a read-only property, thus we have to call the setter function
114+ fakeApplication.setState(selectedApplicationState);
115+ }
116+ }
117+ }
118+ }
119+
120+ UT.UnityTestCase {
121+ id: testCase
122+ name: "ApplicationWindow"
123+ when: windowShown
124+
125+ // just to make them shorter
126+ property int appStarting: ApplicationInfo.Starting
127+ property int appRunning: ApplicationInfo.Running
128+ property int appSuspended: ApplicationInfo.Suspended
129+ property int appStopped: ApplicationInfo.Stopped
130+
131+ function setApplicationState(appState) {
132+ switch (appState) {
133+ case appStarting:
134+ appStateSelector.selectedIndex = 0;
135+ break;
136+ case appRunning:
137+ appStateSelector.selectedIndex = 1;
138+ break;
139+ case appSuspended:
140+ appStateSelector.selectedIndex = 2;
141+ break;
142+ case appStopped:
143+ appStateSelector.selectedIndex = 3;
144+ break;
145+ }
146+ }
147+
148+ // holds some of the internal ApplicationWindow objects we probe during the tests
149+ property var stateGroup: null
150+
151+ function findInterestingApplicationWindowChildren() {
152+ stateGroup = findInvisibleChild(applicationWindowLoader.item, "applicationWindowStateGroup");
153+ verify(stateGroup);
154+ }
155+
156+ function forgetApplicationWindowChildren() {
157+ stateGroup = null;
158+ }
159+
160+ // wait until any transition animation has finished
161+ function waitUntilTransitionsEnd() {
162+ var transitions = stateGroup.transitions;
163+ for (var i = 0; i < transitions.length; ++i) {
164+ var transition = transitions[i];
165+ tryCompare(transition, "running", false, 2000);
166+ }
167+ }
168+
169+ function init() {
170+ findInterestingApplicationWindowChildren();
171+ }
172+
173+ function cleanup() {
174+ forgetApplicationWindowChildren();
175+
176+ // reload our test subject to get it in a fresh state once again
177+ applicationWindowLoader.active = false;
178+
179+ appStateSelector.selectedIndex = 0;
180+ surfaceCheckbox.checked = false;
181+
182+ if (fakeApplication.surface)
183+ fakeApplication.surface.release();
184+
185+ applicationWindowLoader.active = true;
186+ }
187+
188+ function test_showSplashUntilAppFullyInit_data() {
189+ return [
190+ {tag: "state=Running then create surface", swapInitOrder: false},
191+
192+ {tag: "create surface then state=Running", swapInitOrder: true},
193+ ]
194+ }
195+
196+ function test_showSplashUntilAppFullyInit() {
197+ verify(stateGroup.state === "splashScreen");
198+
199+ if (data.swapInitOrder) {
200+ surfaceCheckbox.checked = true;
201+ } else {
202+ setApplicationState(appRunning);
203+ }
204+
205+ verify(stateGroup.state === "splashScreen");
206+
207+ if (data.swapInitOrder) {
208+ setApplicationState(appRunning);
209+ } else {
210+ surfaceCheckbox.checked = true;
211+ }
212+
213+ tryCompare(stateGroup, "state", "surface");
214+ }
215+
216+ function test_suspendedAppShowsSurface() {
217+ surfaceCheckbox.checked = true;
218+ setApplicationState(appRunning);
219+
220+ tryCompare(stateGroup, "state", "surface");
221+
222+ waitUntilTransitionsEnd();
223+
224+ setApplicationState(appSuspended);
225+
226+ verify(stateGroup.state === "surface");
227+ waitUntilTransitionsEnd();
228+ }
229+
230+ function test_killedAppShowsScreenshot() {
231+ surfaceCheckbox.checked = true;
232+ setApplicationState(appRunning);
233+ tryCompare(stateGroup, "state", "surface");
234+
235+ setApplicationState(appSuspended);
236+
237+ verify(stateGroup.state === "surface");
238+ verify(fakeApplication.surface !== null);
239+
240+ // kill it!
241+ setApplicationState(appStopped);
242+
243+ tryCompare(stateGroup, "state", "screenshot");
244+ tryCompare(fakeApplication, "surface", null);
245+ }
246+
247+ function test_restartApp() {
248+ var screenshotImage = findChild(applicationWindowLoader.item, "screenshotImage");
249+
250+ surfaceCheckbox.checked = true;
251+ setApplicationState(appRunning);
252+ tryCompare(stateGroup, "state", "surface");
253+ waitUntilTransitionsEnd();
254+
255+ setApplicationState(appSuspended);
256+
257+ // kill it
258+ setApplicationState(appStopped);
259+
260+ tryCompare(stateGroup, "state", "screenshot");
261+ waitUntilTransitionsEnd();
262+ tryCompare(fakeApplication, "surface", null);
263+
264+ // and restart it
265+ setApplicationState(appStarting);
266+
267+ waitUntilTransitionsEnd();
268+ verify(stateGroup.state === "screenshot");
269+ verify(fakeApplication.surface === null);
270+
271+ setApplicationState(appRunning);
272+
273+ waitUntilTransitionsEnd();
274+ verify(stateGroup.state === "screenshot");
275+
276+ surfaceCheckbox.checked = true;
277+
278+ tryCompare(stateGroup, "state", "surface");
279+ tryCompare(screenshotImage, "status", Image.Null);
280+ }
281+
282+ function test_appCrashed() {
283+ surfaceCheckbox.checked = true;
284+ setApplicationState(appRunning);
285+ tryCompare(stateGroup, "state", "surface");
286+ waitUntilTransitionsEnd();
287+
288+ // oh, it crashed...
289+ setApplicationState(appStopped);
290+
291+ tryCompare(stateGroup, "state", "screenshot");
292+ tryCompare(fakeApplication, "surface", null);
293+ }
294+
295+ function test_keepSurfaceWhileInvisible() {
296+ surfaceCheckbox.checked = true;
297+ setApplicationState(appRunning);
298+ tryCompare(stateGroup, "state", "surface");
299+ waitUntilTransitionsEnd();
300+ verify(fakeApplication.surface !== null);
301+
302+ applicationWindowLoader.item.visible = false;
303+
304+ waitUntilTransitionsEnd();
305+ verify(stateGroup.state === "surface");
306+ verify(fakeApplication.surface !== null);
307+
308+ applicationWindowLoader.item.visible = true;
309+
310+ waitUntilTransitionsEnd();
311+ verify(stateGroup.state === "surface");
312+ verify(fakeApplication.surface !== null);
313+ }
314+
315+ function test_touchesReachSurfaceWhenItsShown() {
316+ setApplicationState(appRunning);
317+ surfaceCheckbox.checked = true;
318+
319+ tryCompare(stateGroup, "state", "surface");
320+
321+ waitUntilTransitionsEnd();
322+
323+ // Because doing stuff in C++ is a PITA we keep the counter in the interal qml impl.
324+ var fakeSurface = findChild(fakeApplication.surface, "fakeSurfaceQML");
325+ fakeSurface.touchPressCount = 0;
326+ fakeSurface.touchReleaseCount = 0;
327+
328+ tap(applicationWindowLoader.item,
329+ applicationWindowLoader.item.width / 2, applicationWindowLoader.item.height / 2);
330+
331+ verify(fakeSurface.touchPressCount === 1);
332+ verify(fakeSurface.touchReleaseCount === 1);
333+ }
334+
335+ function test_showNothingOnSuddenSurfaceLoss() {
336+ surfaceCheckbox.checked = true;
337+ setApplicationState(appRunning);
338+ tryCompare(stateGroup, "state", "surface");
339+ waitUntilTransitionsEnd();
340+
341+ surfaceCheckbox.checked = false;
342+
343+ verify(stateGroup.state === "void");
344+ }
345+ }
346+}
tests/qmltests/Stages/tst_PhoneStage.qml+34−8
@@ -26,14 +26,11 @@ Item {
2626 width: units.gu(70)
2727 height: units.gu(70)
2828
29− Rectangle {
30−
31− }
32−
3329 PhoneStage {
3430 id: phoneStage
3531 anchors { fill: parent; rightMargin: units.gu(30) }
3632 dragAreaWidth: units.gu(2)
33+ maximizedAppTopMargin: units.gu(3) + units.dp(2)
3734 }
3835
3936 Binding {
@@ -46,6 +43,7 @@ Item {
4643 anchors { fill: parent; leftMargin: phoneStage.width }
4744
4845 Column {
46+ id: buttons
4947 anchors { left: parent.left; right: parent.right; top: parent.top; margins: units.gu(1) }
5048 spacing: units.gu(1)
5149 Button {
@@ -57,9 +55,33 @@ Item {
5755 }
5856 Button {
5957 anchors { left: parent.left; right: parent.right }
60− text: "Remove App"
58+ text: "Remove Selected"
6159 onClicked: {
62− ApplicationManager.stopApplication(ApplicationManager.get(0).appId)
60+ ApplicationManager.stopApplication(ApplicationManager.get(appList.selectedAppIndex).appId);
61+ }
62+ }
63+ Button {
64+ anchors { left: parent.left; right: parent.right }
65+ text: "Stop Selected"
66+ onClicked: {
67+ ApplicationManager.get(appList.selectedAppIndex).setState(ApplicationInfo.Stopped);
68+ }
69+ }
70+ }
71+ ListView {
72+ id: appList
73+ property int selectedAppIndex
74+ anchors { left: parent.left; right: parent.right; top: buttons.bottom; bottom: parent.bottom }
75+ boundsBehavior: Flickable.StopAtBounds
76+ model: ApplicationManager
77+ delegate: Rectangle {
78+ anchors { left: parent.left; right: parent.right }
79+ height: units.gu(2)
80+ color: appList.selectedAppIndex === model.index ? "red" : "white"
81+ Text { anchors.fill: parent; text: model.appId }
82+ MouseArea {
83+ anchors.fill: parent
84+ onPressed: { appList.selectedAppIndex = model.index; }
6385 }
6486 }
6587 }
@@ -84,7 +106,9 @@ Item {
84106 function goToSpread() {
85107 var spreadView = findChild(phoneStage, "spreadView");
86108
87− var startX = phoneStage.width;
109+ // Keep it inside the PhoneStage otherwise the controls on the right side will
110+ // capture the press thus the "- 2" on startX.
111+ var startX = phoneStage.width - 2;
88112 var startY = phoneStage.height / 2;
89113 var endY = startY;
90114 var endX = units.gu(2);
@@ -132,7 +156,9 @@ Item {
132156
133157 var spreadView = findChild(phoneStage, "spreadView");
134158
135− var startX = phoneStage.width;
159+ // Keep it inside the PhoneStage otherwise the controls on the right side will
160+ // capture the press thus the "- 2" on startX.
161+ var startX = phoneStage.width - 2;
136162 var startY = phoneStage.height / 2;
137163 var endY = startY;
138164 var endX = spreadView.width - (spreadView.width * spreadView[data.positionMarker]) - data.offset;
tests/qmltests/Stages/tst_SpreadDelegate.qmlnew file+167
@@ -0,0 +1,167 @@
1+/*
2+ * Copyright 2014 Canonical Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+import QtQuick 2.0
18+import QtTest 1.0
19+import Unity.Test 0.1 as UT
20+import ".."
21+import "../../../qml/Stages"
22+import Ubuntu.Components 0.1
23+import Ubuntu.Components.ListItems 1.0 as ListItem
24+import Unity.Application 0.1
25+
26+Rectangle {
27+ color: "red"
28+ id: root
29+ width: units.gu(70)
30+ height: units.gu(70)
31+
32+ Component.onCompleted: {
33+ root.fakeApplication = ApplicationManager.startApplication("gallery-app");
34+ }
35+ property QtObject fakeApplication: null
36+
37+ Component {
38+ id: spreadDelegateComponent
39+ SpreadDelegate {
40+ anchors.fill: parent
41+ swipeToCloseEnabled: swipeToCloseCheckbox.checked
42+ closeable: closeableCheckbox.checked
43+ application: fakeApplication
44+ }
45+ }
46+ Loader {
47+ id: spreadDelegateLoader
48+ anchors {
49+ top: parent.top
50+ bottom: parent.bottom
51+ left: parent.left
52+ }
53+ width: units.gu(40)
54+ sourceComponent: spreadDelegateComponent
55+ }
56+
57+ Rectangle {
58+ color: "white"
59+ anchors {
60+ top: parent.top
61+ bottom: parent.bottom
62+ left: spreadDelegateLoader.right
63+ right: parent.right
64+ }
65+
66+ Column {
67+ anchors { left: parent.left; right: parent.right; top: parent.top; margins: units.gu(1) }
68+ spacing: units.gu(1)
69+ Row {
70+ anchors { left: parent.left; right: parent.right }
71+ CheckBox { id: swipeToCloseCheckbox; checked: false; }
72+ Label { text: "swipeToCloseEnabled" }
73+ }
74+ Row {
75+ anchors { left: parent.left; right: parent.right }
76+ CheckBox { id: closeableCheckbox; checked: false }
77+ Label { text: "closeable" }
78+ }
79+ }
80+ }
81+
82+ UT.UnityTestCase {
83+ id: testCase
84+ name: "SpreadDelegate"
85+ when: windowShown
86+
87+ SignalSpy {
88+ id: spyClosedSignal
89+ target: spreadDelegateLoader.item
90+ signalName: "closed"
91+ }
92+
93+ property var dragArea
94+
95+ function init() {
96+ dragArea = findInvisibleChild(spreadDelegateLoader.item, "dragArea");
97+ dragArea.__dateTime = fakeDateTime;
98+ }
99+
100+ function cleanup() {
101+ // reload our test subject to get it in a fresh state once again
102+ spreadDelegateLoader.active = false;
103+ spreadDelegateLoader.active = true;
104+
105+ spyClosedSignal.clear();
106+ }
107+
108+ function test_swipeToClose_data() {
109+ return [
110+ {tag: "swipeToClose=true closeable=true -> appWindow moves away",
111+ swipeToClose: true, closeable: true },
112+
113+ {tag: "swipeToClose=true closeable=alse -> appWindow bounces back",
114+ swipeToClose: true, closeable: false },
115+
116+ {tag: "swipeToClose=false -> appWindow stays put",
117+ swipeToClose: false, closeable: true },
118+ ]
119+ }
120+
121+ function test_swipeToClose(data) {
122+ var appWindowWithShadow = findChild(spreadDelegateLoader.item, "appWindowWithShadow");
123+
124+ verify(appWindowWithShadow.y === 0);
125+
126+ swipeToCloseCheckbox.checked = data.swipeToClose;
127+ closeableCheckbox.checked = data.closeable;
128+
129+ var dragDistance = spreadDelegateLoader.item.height / 2;
130+ var touchX = spreadDelegateLoader.item.width / 2;
131+ var fromY = spreadDelegateLoader.item.height / 2;
132+ var toY = fromY - dragDistance;
133+ touchFlick(spreadDelegateLoader.item,
134+ touchX /* fromX */, fromY, touchX /* toX */, toY,
135+ true /* beginTouch */, false /* endTouch */, dragArea.minSpeedToClose * 1.1 /* speed */);
136+
137+
138+ if (data.swipeToClose) {
139+ verify(appWindowWithShadow.y < 0);
140+ verify(Math.abs(Math.abs(appWindowWithShadow.y) - dragDistance) < units.gu(1));
141+
142+ touchRelease(spreadDelegateLoader.item, touchX, toY - units.gu(1));
143+
144+ waitForCloseAnimationToFinish();
145+
146+ if (data.closeable) {
147+ verify(spyClosedSignal.count === 1);
148+ } else {
149+ verify(spyClosedSignal.count === 0);
150+ tryCompare(appWindowWithShadow, "y", 0);
151+ }
152+
153+ } else {
154+ verify(appWindowWithShadow.y === 0);
155+
156+ touchRelease(spreadDelegateLoader.item, touchX, toY);
157+ }
158+ }
159+
160+ function waitForCloseAnimationToFinish() {
161+ var closeAnimation = findInvisibleChild(spreadDelegateLoader.item, "closeAnimation");
162+ wait(closeAnimation.duration * 1.5);
163+ tryCompare(closeAnimation, "running", false);
164+ }
165+
166+ }
167+}
tests/qmltests/Stages/tst_SurfaceContainer.qmlnew file+154
@@ -0,0 +1,154 @@
1+/*
2+ * Copyright 2014 Canonical Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+import QtQuick 2.0
18+import QtTest 1.0
19+import Unity.Test 0.1 as UT
20+import ".."
21+import "../../../qml/Stages"
22+import Ubuntu.Components 0.1
23+import Unity.Application 0.1
24+
25+Rectangle {
26+ color: "black"
27+ id: root
28+ width: units.gu(70)
29+ height: units.gu(70)
30+
31+ Component {
32+ id: fakeSurfaceComponent
33+ Rectangle {
34+ color: "green"
35+
36+ Rectangle {
37+ color: "blue"
38+ anchors.fill: parent
39+ anchors.margins: units.gu(2)
40+ Text {
41+ anchors.fill: parent
42+ text: "Surface"
43+ color: "green"
44+ font.bold: true
45+ fontSizeMode: Text.Fit
46+ minimumPixelSize: 10; font.pixelSize: 200
47+ verticalAlignment: Text.AlignVCenter
48+ }
49+ }
50+
51+ width: units.gu(1)
52+ height: units.gu(1)
53+
54+ property int type: MirSurfaceItem.Normal
55+ property int state: MirSurfaceItem.Restored
56+ property string name: "Fake Surface"
57+ property Item parentSurface: null
58+ property list<Item> childSurfaces
59+ function release() {}
60+ signal removed();
61+ }
62+ }
63+
64+ Item {
65+ id: tempSurfaceHolder
66+ }
67+
68+ Component {
69+ id: surfaceContainerComponent
70+ SurfaceContainer {
71+ anchors.fill: parent
72+ }
73+ }
74+ Loader {
75+ id: surfaceContainerLoader
76+ anchors {
77+ top: parent.top
78+ topMargin: fullscreenCheckbox.checked ? 0 : units.gu(3) + units.dp(2)
79+ bottom: parent.bottom
80+ left: parent.left
81+ }
82+ width: units.gu(40)
83+ sourceComponent: surfaceContainerComponent
84+ }
85+
86+ Rectangle {
87+ color: "white"
88+ anchors {
89+ top: parent.top
90+ bottom: parent.bottom
91+ left: surfaceContainerLoader.right
92+ right: parent.right
93+ }
94+
95+ Column {
96+ anchors { left: parent.left; right: parent.right; top: parent.top; margins: units.gu(1) }
97+ spacing: units.gu(1)
98+ Row {
99+ anchors { left: parent.left; right: parent.right }
100+ CheckBox {
101+ id: surfaceCheckbox; checked: false;
102+ onCheckedChanged: {
103+ if (surfaceContainerLoader.status !== Loader.Ready)
104+ return;
105+
106+ if (checked) {
107+ var fakeSurface = fakeSurfaceComponent.createObject(tempSurfaceHolder);
108+ surfaceContainerLoader.item.surface = fakeSurface;
109+ } else {
110+ var fakeSurface = surfaceContainerLoader.item.surface;
111+ surfaceContainerLoader.item.surface = null;
112+ fakeSurface.parent = null;
113+ fakeSurface.destroy();
114+ }
115+ }
116+ }
117+ Label { text: "surface" }
118+ }
119+ Row {
120+ anchors { left: parent.left; right: parent.right }
121+ CheckBox {id: fullscreenCheckbox; checked: true; }
122+ Label { text: "fullscreen" }
123+ }
124+ }
125+ }
126+
127+ UT.UnityTestCase {
128+ id: testCase
129+ name: "SurfaceContainer"
130+ when: windowShown
131+
132+ function cleanup() {
133+ // reload our test subject to get it in a fresh state once again
134+ surfaceContainerLoader.active = false;
135+ surfaceCheckbox.checked = false;
136+ surfaceContainerLoader.active = true;
137+ }
138+
139+ /*
140+ Add a first surface. Then remove it. Then add a second surface.
141+ That second surface should be properly sized.
142+
143+ Regression test for https://bugs.launchpad.net/ubuntu/+source/qtmir/+bug/1359819
144+ */
145+ function test_resetSurfaceGetsProperlySized() {
146+ surfaceCheckbox.checked = true;
147+ surfaceCheckbox.checked = false;
148+ surfaceCheckbox.checked = true;
149+ var fakeSurface = surfaceContainerLoader.item.surface;
150+ compare(fakeSurface.width, surfaceContainerLoader.item.width);
151+ compare(fakeSurface.height, surfaceContainerLoader.item.height);
152+ }
153+ }
154+}
tests/qmltests/tst_Shell.qml+2−2
@@ -416,11 +416,11 @@ Item {
416416 compare(panel.fullscreenMode, false);
417417 ApplicationManager.startApplication("camera-app");
418418 tryCompare(panel, "fullscreenMode", true);
419− ApplicationManager.startApplication("gallery-app");
419+ ApplicationManager.startApplication("dialer-app");
420420 tryCompare(panel, "fullscreenMode", false);
421421 ApplicationManager.requestFocusApplication("camera-app");
422422 tryCompare(panel, "fullscreenMode", true);
423− ApplicationManager.requestFocusApplication("gallery-app");
423+ ApplicationManager.requestFocusApplication("dialer-app");
424424 tryCompare(panel, "fullscreenMode", false);
425425 }
426426
tests/utils/modules/Unity/Test/UnityTestCase.qml+5−2
@@ -312,12 +312,15 @@ TestCase {
312312 }
313313
314314 function tap(item, x, y) {
315+ var root = fetchRootItem(item)
316+ var rootPoint = item.mapToItem(root, x, y)
317+
315318 var event = touchEvent()
316− event.press(0 /* touchId */, x, y)
319+ event.press(0 /* touchId */, rootPoint.x, rootPoint.y)
317320 event.commit()
318321
319322 event = touchEvent()
320− event.release(0 /* touchId */, x, y)
323+ event.release(0 /* touchId */, rootPoint.x, rootPoint.y)
321324 event.commit()
322325 }
323326