on xenial help sign in
SurfaceContainer: make the contained surface reliably follow the size of its container
ce390f8Daniel d'Andrada
qml/Stages/SurfaceContainer.qml+4−10
@@ -26,9 +26,12 @@ Item {
26 if (surface) {
26 if (surface) {
27 surface.parent = container;
27 surface.parent = container;
28 surface.z = 1;
28 surface.z = 1;
29− state = "initial"
30 }
29 }
31 }
30 }
31+ Binding {
32+ target: surface
33+ property: "anchors.fill"; value: container
34+ }
32
35
33 Connections {
36 Connections {
34 target: surface
37 target: surface
@@ -81,8 +84,6 @@ Item {
81 var popped = tmp.pop();
84 var popped = tmp.pop();
82 popped.end();
85 popped.end();
83 d.animations = tmp;
86 d.animations = tmp;
84− } else {
85− container.state = "initial";
86 }
87 }
87 }
88 }
88
89
@@ -96,11 +97,4 @@ Item {
96 id: swipeFromBottom
97 id: swipeFromBottom
97 SwipeFromBottomAnimation {}
98 SwipeFromBottomAnimation {}
98 }
99 }
99−
100− states: [
101− State {
102− name: "initial"
103− PropertyChanges { target: surface; anchors.fill: container }
104− }
105− ]
106}
100}
tests/qmltests/CMakeLists.txt+1
@@ -78,3 +78,4 @@ add_qml_test(Panel/Indicators MessageMenuItemFactory IMPORT_PATHS ${CMAKE_BINARY
78add_qml_test(Stages ApplicationWindow ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/tests/mocks/libusermetrics:${CMAKE_BINARY_DIR}/tests/mocks/LightDM/single")
78add_qml_test(Stages ApplicationWindow ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/tests/mocks/libusermetrics:${CMAKE_BINARY_DIR}/tests/mocks/LightDM/single")
79add_qml_test(Stages PhoneStage ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/tests/mocks/libusermetrics:${CMAKE_BINARY_DIR}/tests/mocks/LightDM/single")
79add_qml_test(Stages PhoneStage ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/tests/mocks/libusermetrics:${CMAKE_BINARY_DIR}/tests/mocks/LightDM/single")
80add_qml_test(Stages SpreadDelegate ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/tests/mocks/libusermetrics:${CMAKE_BINARY_DIR}/tests/mocks/LightDM/single")
80add_qml_test(Stages SpreadDelegate ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/tests/mocks/libusermetrics:${CMAKE_BINARY_DIR}/tests/mocks/LightDM/single")
81+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_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+}