on xenial help sign in
Fixed menu layout width calculations. (LP: #1657050)

Approved by: Albert Astals Cid, Unity8 CI Bot

commitdf8c9d548fdc2f7f0d6b75b08756e267be6afc26 authorNick Dedekind <nick.dedekind@canonical.com> dateTue 24 Jan 2017, 07:41 (10 years ago) parentd76e34a75ef09c
4 files changed+328−170
qml/ApplicationMenus/MenuPopup.qml+162−123 tests/qmltests/ApplicationMenuDataLoader.qml+13−5 tests/qmltests/ApplicationMenus/tst_MenuBar.qml+5−5 tests/qmltests/ApplicationMenus/tst_MenuPopup.qml+148−37
qml/ApplicationMenus/MenuPopup.qml+162−123
@@ -26,19 +26,7 @@ UbuntuShape {
2626 objectName: "menu"
2727 backgroundColor: theme.palette.normal.overlay
2828
29− property alias unityMenuModel: listView.model
30−
31− readonly property real __ajustedMinimumHeight: {
32− if (listView.contentHeight > __minimumHeight) {
33− return units.gu(30);
34− }
35− return Math.max(listView.contentHeight, units.gu(2));
36− }
37−
38− readonly property real __minimumWidth: units.gu(20)
39− readonly property real __minimumHeight: units.gu(30)
40− readonly property real __maximumWidth: Screen.width * 0.7
41− readonly property real __maximumHeight: Screen.height * 0.7
29+ property alias unityMenuModel: repeater.model
4230
4331 function show() {
4432 visible = true;
@@ -63,18 +51,23 @@ UbuntuShape {
6351 d.dismissAll();
6452 }
6553
66− implicitWidth: container.width
67− implicitHeight: MathUtils.clamp(listView.contentHeight, __ajustedMinimumHeight, __maximumHeight)
54+ implicitWidth: focusScope.width
55+ implicitHeight: focusScope.height
6856
6957 MenuNavigator {
7058 id: d
7159 objectName: "d"
72− itemView: listView
60+ itemView: repeater
7361
7462 property Item currentItem: null
7563 property Item hoveredItem: null
7664 readonly property int currentIndex: currentItem ? currentItem.__ownIndex : -1
7765
66+ property real __minimumWidth: units.gu(20)
67+ property real __maximumWidth: Screen.width * 0.7
68+ property real __minimumHeight: units.gu(2)
69+ property real __maximumHeight: Screen.height * 0.7
70+
7871 signal dismissAll()
7972
8073 onCurrentItemChanged: {
@@ -86,13 +79,26 @@ UbuntuShape {
8679 }
8780
8881 onSelect: {
89− currentItem = listView.itemAt(index);
82+ currentItem = repeater.itemAt(index);
83+ if (currentItem) {
84+ if (currentItem.y < listView.contentY) {
85+ listView.contentY = currentItem.y;
86+ } else if (currentItem.y + currentItem.height > listView.contentY + listView.height) {
87+ listView.contentY = currentItem.y + currentItem.height - listView.height;
88+ }
89+ }
9090 }
9191 }
9292
93+ MouseArea {
94+ // Eat events.
95+ anchors.fill: parent
96+ }
97+
9398 Item {
9499 id: focusScope
95− anchors.fill: parent
100+ width: container.width
101+ height: container.height
96102 focus: visible
97103
98104 Keys.onUpPressed: d.selectPrevious(d.currentIndex)
@@ -108,17 +114,17 @@ UbuntuShape {
108114 id: container
109115 objectName: "container"
110116
111− width: listView.contentWidth
112− height: parent.height
117+ height: MathUtils.clamp(listView.contentHeight, d.__minimumHeight, d.__maximumHeight)
118+ width: menuColumn.width
113119 spacing: 0
114120
115− // FIXME use ListView.header - tried but was flaky with positionViewAtIndex.
121+ // Header - scroll up
116122 Item {
117− Layout.fillWidth: true;
118− Layout.maximumHeight: units.gu(3)
119− Layout.minimumHeight: units.gu(3)
123+ Layout.fillWidth: true
124+ height: units.gu(3)
120125 visible: listView.contentHeight > root.height
121126 enabled: !listView.atYBeginning
127+ z: 1
122128
123129 Rectangle {
124130 color: enabled ? theme.palette.normal.overlayText :
@@ -143,47 +149,35 @@ UbuntuShape {
143149 MouseArea {
144150 anchors.fill: parent
145151 onPressed: {
146− var index = listView.indexAt(0, listView.contentY);
147− listView.positionViewAtIndex(index-1, ListView.Beginning);
152+ var item = menuColumn.childAt(0, listView.contentY);
153+ if (item) {
154+ var previousItem = item;
155+ do {
156+ previousItem = repeater.itemAt(previousItem.__ownIndex-1);
157+ if (!previousItem) {
158+ listView.contentY = 0;
159+ return;
160+ }
161+ } while (previousItem.__isSeparator);
162+
163+ listView.contentY = previousItem.y
164+ }
148165 }
149166 }
150167 }
151168
152− ListView {
169+ // Menu Items
170+ Flickable {
153171 id: listView
154− objectName: "listView"
155− Layout.fillHeight: true
156− Layout.fillWidth: true
157− contentWidth: MathUtils.clamp(contentItem.childrenRect.width,
158− __minimumWidth,
159− __maximumWidth)
160−
161− orientation: Qt.Vertical
162− interactive: contentHeight > height
163172 clip: interactive
164− highlightFollowsCurrentItem: false
165−
166− highlight: Rectangle {
167− color: "transparent"
168− border.width: units.dp(1)
169− border.color: UbuntuColors.orange
170− z: 1
171173
172− width: listView.width
173− height: d.currentItem ? d.currentItem.height : 0
174− y: d.currentItem ? d.currentItem.y : 0
175− visible: d.currentItem
176− }
177−
178− function itemAt(index) {
179− if (index > count || index < 0) return null;
180− currentIndex = index;
181− return currentItem;
182− }
174+ Layout.fillHeight: true
175+ Layout.fillWidth: true
176+ contentHeight: menuColumn.height
177+ interactive: height < contentHeight
183178
184179 MouseArea {
185− id: menuMouseArea
186− anchors.fill: listView
180+ anchors.fill: parent
187181 hoverEnabled: true
188182 propagateComposedEvents: true // propogate events so we send clicks to children.
189183 z: 1 // on top so we override any other hovers
@@ -195,7 +189,7 @@ UbuntuShape {
195189
196190 if (!d.hoveredItem || !d.currentItem ||
197191 !d.hoveredItem.contains(Qt.point(pos.x - d.currentItem.x, pos.y - d.currentItem.y))) {
198− d.hoveredItem = listView.itemAt(listView.indexAt(pos.x, pos.y));
192+ d.hoveredItem = menuColumn.childAt(pos.x, pos.y)
199193 if (!d.hoveredItem || !d.hoveredItem.enabled)
200194 return false;
201195 d.currentItem = d.hoveredItem;
@@ -216,89 +210,123 @@ UbuntuShape {
216210 }
217211 }
218212
219− delegate: Loader {
220− id: loader
221− objectName: root.objectName + "-item" + __ownIndex
213+ ColumnLayout {
214+ id: menuColumn
215+ spacing: 0
222216
223− property int __ownIndex: index
217+ width: MathUtils.clamp(implicitWidth, d.__minimumWidth, d.__maximumWidth)
224218
225− width: root.width
226− enabled: model.isSeparator ? false : model.sensitive
219+ Repeater {
220+ id: repeater
227221
228− sourceComponent: {
229− if (model.isSeparator) {
230− return separatorComponent;
231− }
232− return menuItemComponent;
233− }
222+ Loader {
223+ id: loader
224+ objectName: root.objectName + "-item" + __ownIndex
234225
235− property Item popup: null
236−
237− Component {
238− id: menuItemComponent
239− MenuItem {
240− id: menuItem
241− menuData: model
242− objectName: loader.objectName + "-actionItem"
243−
244− action.onTriggered: {
245− d.currentItem = loader;
246−
247− if (hasSubmenu) {
248− if (!popup) {
249− var model = root.unityMenuModel.submenu(__ownIndex);
250− popup = submenuComponent.createObject(focusScope, {
251− objectName: loader.objectName + "-",
252− unityMenuModel: model,
253− x: Qt.binding(function() { return root.width }),
254− y: Qt.binding(function() { return loader.y })
255− });
256− } else if (popup) {
257− popup.visible = true;
258− }
259− popup.retreat.connect(function() {
260− popup.destroy();
261− popup = null;
262− menuItem.forceActiveFocus();
263− })
264− } else {
265− root.unityMenuModel.activate(__ownIndex);
226+ property int __ownIndex: index
227+ property bool __isSeparator: model.isSeparator
228+
229+ enabled: __isSeparator ? false : model.sensitive
230+
231+ sourceComponent: {
232+ if (model.isSeparator) {
233+ return separatorComponent;
266234 }
235+ return menuItemComponent;
267236 }
268237
269− Connections {
270− target: d
271− onCurrentIndexChanged: {
272− if (popup && d.currentIndex != __ownIndex) {
273− popup.visible = false;
238+ property Item popup: null
239+
240+ Layout.fillWidth: true
241+
242+ Component {
243+ id: menuItemComponent
244+ MenuItem {
245+ id: menuItem
246+ menuData: model
247+ objectName: loader.objectName + "-actionItem"
248+
249+ width: MathUtils.clamp(implicitWidth, d.__minimumWidth, d.__maximumWidth)
250+
251+ action.onTriggered: {
252+ d.currentItem = loader;
253+
254+ if (hasSubmenu) {
255+ if (!popup) {
256+ var model = root.unityMenuModel.submenu(__ownIndex);
257+ popup = submenuComponent.createObject(focusScope, {
258+ objectName: loader.objectName + "-",
259+ unityMenuModel: model,
260+ x: Qt.binding(function() { return root.width }),
261+ y: Qt.binding(function() {
262+ var dummy = listView.contentY; // force a recalc on contentY change.
263+ return mapToItem(container, 0, y).y;
264+ })
265+ });
266+ } else if (popup) {
267+ popup.visible = true;
268+ }
269+ popup.retreat.connect(function() {
270+ popup.destroy();
271+ popup = null;
272+ menuItem.forceActiveFocus();
273+ })
274+ } else {
275+ root.unityMenuModel.activate(__ownIndex);
276+ }
274277 }
275− }
276− onDismissAll: {
277− if (popup) {
278− popup.destroy();
279− popup = null;
278+
279+ Connections {
280+ target: d
281+ onCurrentIndexChanged: {
282+ if (popup && d.currentIndex != __ownIndex) {
283+ popup.visible = false;
284+ }
285+ }
286+ onDismissAll: {
287+ if (popup) {
288+ popup.destroy();
289+ popup = null;
290+ }
291+ }
280292 }
281293 }
282294 }
283− }
284− }
285295
286− Component {
287− id: separatorComponent
288− ListItems.ThinDivider {
289− objectName: loader.objectName + "-separator"
296+ Component {
297+ id: separatorComponent
298+ ListItems.ThinDivider {
299+ objectName: loader.objectName + "-separator"
300+ implicitHeight: units.dp(2)
301+ }
302+ }
290303 }
304+
291305 }
292306 }
293− } // ListView
294307
295− // FIXME use ListView.footer - tried but was flaky with positionViewAtIndex.
308+ // Highlight
309+ Rectangle {
310+ color: "transparent"
311+ border.width: units.dp(1)
312+ border.color: UbuntuColors.orange
313+ z: 1
314+
315+ width: listView.width
316+ height: d.currentItem ? d.currentItem.height : 0
317+ y: d.currentItem ? d.currentItem.y : 0
318+ visible: d.currentItem
319+ }
320+
321+ } // Flickable
322+
323+ // Header - scroll down
296324 Item {
297− Layout.fillWidth: true;
298− Layout.maximumHeight: units.gu(3)
299− Layout.minimumHeight: units.gu(3)
325+ Layout.fillWidth: true
326+ height: units.gu(3)
300327 visible: listView.contentHeight > root.height
301328 enabled: !listView.atYEnd
329+ z: 1
302330
303331 Rectangle {
304332 color: enabled ? theme.palette.normal.overlayText :
@@ -323,8 +351,19 @@ UbuntuShape {
323351 MouseArea {
324352 anchors.fill: parent
325353 onPressed: {
326− var index = listView.indexAt(0, listView.contentY);
327− listView.positionViewAtIndex(index+1, ListView.Beginning);
354+ var item = menuColumn.childAt(0, listView.contentY + listView.height);
355+ if (item) {
356+ var nextItem = item;
357+ do {
358+ nextItem = repeater.itemAt(nextItem.__ownIndex+1);
359+ if (!nextItem) {
360+ listView.contentY = listView.contentHeight - listView.height;
361+ return;
362+ }
363+ } while (nextItem.__isSeparator);
364+
365+ listView.contentY = nextItem.y - listView.height
366+ }
328367 }
329368 }
330369 }
tests/qmltests/ApplicationMenuDataLoader.qml+13−5
@@ -10,6 +10,7 @@ Object {
1010
1111 Connections {
1212 id: sMgrHandler
13+ target: null
1314 onSurfaceCreated: {
1415 var fakeMenuPath = "/" + surface.persistentId.replace(/\W+/g, "");
1516
@@ -25,21 +26,28 @@ Object {
2526 var data = [];
2627 if (root === undefined) root = true;
2728
28− if (prefix === undefined) prefix = "menu"
29−
3029 for (var i = 0; i < length; i++) {
3130
31+ var menuName = prefix;
32+ if (menuName === undefined) {
33+ var chars = Math.random() * 20;
34+ menuName = "";
35+ for (var x = 0; x < chars; x++) {
36+ menuName += String.fromCharCode((Math.random() * 26) + 65);
37+ }
38+ }
39+
3240 var menuCode = String.fromCharCode(i+65);
3341
3442 var isSeparator = !root && separatorInterval > 0 && ((i+1) % separatorInterval == 0);
3543 var row = {
3644 "rowData": { // 1
37− "label": prefix + "&" + menuCode,
45+ "label": menuName + "&" + menuCode,
3846 "sensitive": true,
3947 "isSeparator": isSeparator,
4048 "icon": "",
4149 "ext": {},
42− "action": prefix + menuCode,
50+ "action": menuName + menuCode,
4351 "actionState": {},
4452 "isCheck": false,
4553 "isRadio": false,
@@ -49,7 +57,7 @@ Object {
4957 }
5058 var isSubmenu = root === undefined || root === true || (submenuInterval > 0 && ((i+1) % submenuInterval == 0));
5159 if (isSubmenu && !isSeparator && depth > 1) {
52− row["submenu"] = generateTestData(length, depth-1, submenuInterval, separatorInterval, prefix + menuCode + ".", false);
60+ row["submenu"] = generateTestData(length, depth-1, submenuInterval, separatorInterval,prefix, false);
5361 }
5462 data[i] = row;
5563 }
tests/qmltests/ApplicationMenus/tst_MenuBar.qml+5−5
@@ -65,7 +65,7 @@ Item {
6565
6666 unityMenuModel: UnityMenuModel {
6767 id: menuBackend
68− modelData: appMenuData.generateTestData(7,5,2,3,"menu")
68+ modelData: appMenuData.generateTestData(17,5,2,3)
6969 }
7070 }
7171 }
@@ -83,12 +83,12 @@ Item {
8383
8484 function init() {
8585 menuBar.dismiss();
86− menuBackend.modelData = appMenuData.generateTestData(5,5,2,3,"menu")
86+ menuBackend.modelData = appMenuData.generateTestData(5,5,2,3)
8787 activatedSpy.clear();
8888 }
8989
9090 function test_mouseNavigation() {
91− menuBackend.modelData = appMenuData.generateTestData(3,3,0,0,"menu");
91+ menuBackend.modelData = appMenuData.generateTestData(3,3,0,0);
9292 wait(50) // wait for row to build
9393 var priv = findInvisibleChild(menuBar, "d");
9494
@@ -114,7 +114,7 @@ Item {
114114 }
115115
116116 function test_keyboardNavigation_RightKeySelectsNextMenuItem(data) {
117− menuBackend.modelData = appMenuData.generateTestData(3,3,0,0,"menu");
117+ menuBackend.modelData = appMenuData.generateTestData(3,3,0,0);
118118 var priv = findInvisibleChild(menuBar, "d");
119119
120120 var menuItem0 = findChild(menuBar, "menuBar-item0"); verify(menuItem0);
@@ -139,7 +139,7 @@ Item {
139139 }
140140
141141 function test_keyboardNavigation_LeftKeySelectsPreviousMenuItem(data) {
142− menuBackend.modelData = appMenuData.generateTestData(3,3,0,0,"menu");
142+ menuBackend.modelData = appMenuData.generateTestData(3,3,0,0);
143143 var priv = findInvisibleChild(menuBar, "d");
144144
145145 var menuItem0 = findChild(menuBar, "menuBar-item0"); verify(menuItem0);
tests/qmltests/ApplicationMenus/tst_MenuPopup.qml+148−37
@@ -1,4 +1,4 @@
1−/*
1+/*
22 * Copyright (C) 2016 Canonical, Ltd.
33 *
44 * This program is free software; you can redistribute it and/or modify
@@ -28,8 +28,8 @@ import ".."
2828
2929Item {
3030 id: root
31− width: Math.max(units.gu(100), page.width + units.gu(6))
32− height: Math.max(units.gu(50), page.height + units.gu(6))
31+ width: Math.max(units.gu(100), loader.width + units.gu(6))
32+ height: Math.max(units.gu(50), loader.height + units.gu(6))
3333
3434 Binding {
3535 target: MouseTouchAdaptor
@@ -39,25 +39,37 @@ Item {
3939
4040 ApplicationMenuDataLoader { id: appMenuData }
4141
42− MenuPopup {
43− id: page
42+ Loader {
43+ id: loader
44+ sourceComponent: MenuPopup {
45+ anchors {
46+ left: parent ? parent.left : undefined
47+ top: parent ? parent.top : undefined
48+ leftMargin: units.gu(3)
49+ topMargin: units.gu(3)
50+ }
4451
45− anchors {
46− left: parent.left
47− top: parent.top
48− leftMargin: units.gu(3)
49− topMargin: units.gu(3)
50− }
52+ unityMenuModel: UnityMenuModel {
53+ modelData: [{
54+ "rowData": {
55+ "label": "Short",
56+ }}, {
57+ "rowData": {
58+ "label": "This is a long menu item which tests width",
59+ }}
60+ ]
61+ }
5162
52− unityMenuModel: UnityMenuModel {
53− id: menuBackend
54− modelData: appMenuData.generateTestData(7,5,2,3,"menu")
63+ Binding {
64+ target: activatedSpy
65+ property: "target"
66+ value: unityMenuModel
67+ }
5568 }
5669 }
5770
5871 SignalSpy {
5972 id: activatedSpy
60− target: menuBackend
6173 signalName: "activated"
6274 }
6375
@@ -66,14 +78,20 @@ Item {
6678 name: "MenuPopup"
6779 when: windowShown
6880
81+ property var menu: loader.status === Loader.Ready ? loader.item : null
82+
6983 function init() {
70− page.show();
84+ loader.active = true;
85+ menu.show();
7186 }
7287
7388 function cleanup() {
74− page.reset();
89+ menu.reset();
7590 wait(100); // let the page dismiss
7691 activatedSpy.clear();
92+
93+ loader.active = false;
94+ tryCompare(loader, "item", null);
7795 }
7896
7997 // visit and verify that all the backend menus have been created
@@ -90,6 +108,7 @@ Item {
90108 // recurse into submenu
91109 var submenu = rows[i]["submenu"];
92110 if (submenu) {
111+ waitForRendering(menuItem);
93112 mouseClick(menuItem, menuItem.width/2, menuItem.height/2);
94113 tryCompare(menuPriv, "currentItem", menuItem);
95114
@@ -113,15 +132,15 @@ Item {
113132 }
114133
115134 function test_mouseNavigation(data) {
116− menuBackend.modelData = data.testData;
135+ menu.unityMenuModel.modelData = data.testData;
117136
118− recurseMenuConstruction(data.testData, page);
137+ recurseMenuConstruction(data.testData, menu);
119138 }
120139
121140 function test_checkableMenuTogglesOnClick() {
122− menuBackend.modelData = appMenuData.singleCheckable;
141+ menu.unityMenuModel.modelData = appMenuData.singleCheckable;
123142
124− var menuItem = findChild(page, "menu-item0-actionItem");
143+ var menuItem = findChild(menu, "menu-item0-actionItem");
125144 verify(menuItem);
126145 compare(menuItem.action.checkable, true, "Menu item should be checkable");
127146 compare(menuItem.action.checked, false, "Menu item should not be checked");
@@ -132,13 +151,13 @@ Item {
132151 }
133152
134153 function test_keyboardNavigation_DownKeySelectsAndOpensNextMenuItemAndRotates() {
135− menuBackend.modelData = appMenuData.generateTestData(3,3,0,0,"menu",false);
154+ menu.unityMenuModel.modelData = appMenuData.generateTestData(3,3,0,0,"menu",false);
136155
137− var item0 = findChild(page, "menu-item0"); verify(item0);
138− var item1 = findChild(page, "menu-item1"); verify(item1);
139− var item2 = findChild(page, "menu-item2"); verify(item2);
156+ var item0 = findChild(menu, "menu-item0"); verify(item0);
157+ var item1 = findChild(menu, "menu-item1"); verify(item1);
158+ var item2 = findChild(menu, "menu-item2"); verify(item2);
140159
141− var priv = findInvisibleChild(page, "d");
160+ var priv = findInvisibleChild(menu, "d");
142161
143162 keyClick(Qt.Key_Down, Qt.NoModifier);
144163 compare(priv.currentItem, item0, "CurrentItem should have moved to item 0");
@@ -154,13 +173,13 @@ Item {
154173 }
155174
156175 function test_keyboardNavigation_UpKeySelectsAndOpensPreviousMenuItemAndRotates() {
157− menuBackend.modelData = appMenuData.generateTestData(3,3,0,0,"menu",false);
176+ menu.unityMenuModel.modelData = appMenuData.generateTestData(3,3,0,0,"menu",false);
158177
159− var item0 = findChild(page, "menu-item0"); verify(item0);
160− var item1 = findChild(page, "menu-item1"); verify(item1);
161− var item2 = findChild(page, "menu-item2"); verify(item2);
178+ var item0 = findChild(menu, "menu-item0"); verify(item0);
179+ var item1 = findChild(menu, "menu-item1"); verify(item1);
180+ var item2 = findChild(menu, "menu-item2"); verify(item2);
162181
163− var priv = findInvisibleChild(page, "d");
182+ var priv = findInvisibleChild(menu, "d");
164183
165184 keyClick(Qt.Key_Down, Qt.NoModifier);
166185 compare(priv.currentItem, item0, "CurrentItem should have moved to item 2");
@@ -176,17 +195,17 @@ Item {
176195 }
177196
178197 function test_keyboardNavigation_RightKeyEntersSubMenu() {
179− menuBackend.modelData = appMenuData.generateTestData(3,3,1,0,"menu",false);
198+ menu.unityMenuModel.modelData = appMenuData.generateTestData(3,3,1,0,"menu",false);
180199
181− var menuItem = findChild(page, "menu-item0");
200+ var menuItem = findChild(menu, "menu-item0");
182201
183− var priv = findInvisibleChild(page, "d");
202+ var priv = findInvisibleChild(menu, "d");
184203 priv.currentItem = menuItem;
185204
186205 keyClick(Qt.Key_Right, Qt.NoModifier);
187206 tryCompareFunction(function() { return menuItem.popup !== null && menuItem.popup.visible }, true);
188207
189− var submenu0 = findChild(page, "menu-item0-menu"); verify(submenu0);
208+ var submenu0 = findChild(menu, "menu-item0-menu"); verify(submenu0);
190209 var submenu0item0 = findChild(submenu0, "menu-item0-menu-item0"); verify(submenu0item0);
191210
192211 var submenu0Priv = findInvisibleChild(submenu0, "d"); verify(submenu0Priv);
@@ -194,14 +213,106 @@ Item {
194213 }
195214
196215 function test_keyboardNavigation_LeftKeyClosesSubMenu() {
197− menuBackend.modelData = appMenuData.generateTestData(3,3,1,0,"menu",false);
216+ menu.unityMenuModel.modelData = appMenuData.generateTestData(3,3,1,0,"menu",false);
198217
199− var menuItem = findChild(page, "menu-item0"); verify(menuItem);
218+ var menuItem = findChild(menu, "menu-item0"); verify(menuItem);
200219 mouseClick(menuItem, menuItem.width/2, menuItem.height/2);
201220 tryCompareFunction(function() { return menuItem.popup !== null && menuItem.popup.visible }, true);
202221
203222 keyClick(Qt.Key_Left, Qt.NoModifier);
204223 tryCompareFunction(function() { return menuItem.popup !== null && menuItem.popup.visible }, false);
205224 }
225+
226+ function test_differentSizes() {
227+ var differentSizesMenu = [{
228+ "rowData": { "label": "Short" }}, {
229+ "rowData": { "label": "This is a long menu item which tests width" }
230+ }];
231+
232+ menu.unityMenuModel.modelData = differentSizesMenu;
233+
234+ waitForRendering(menu);
235+ var longWidth = menu.width;
236+ differentSizesMenu.pop();
237+ menu.unityMenuModel.modelData = differentSizesMenu;
238+
239+ waitForRendering(menu);
240+ verify(menu.width < longWidth);
241+ }
242+
243+ function test_minimumWidth() {
244+ var shortMenu = [{
245+ "rowData": { "label": "Short" }
246+ }];
247+ menu.unityMenuModel.modelData = shortMenu;
248+
249+ var priv = findInvisibleChild(menu, "d");
250+ priv.__minimumWidth = 0;
251+ priv.__maximumWidth = 1000;
252+ tryCompareFunction(function() { return menu.width > priv.__minimumWidth; }, true);
253+
254+ priv.__minimumWidth = 300;
255+ tryCompare(menu, "width", priv.__minimumWidth);
256+ }
257+
258+ function test_maximumWidth() {
259+ var longMenu = [{
260+ "rowData": { "label": "This is a long menu item which tests width" }
261+ }];
262+
263+ var priv = findInvisibleChild(menu, "d");
264+ priv.__minimumWidth = 0;
265+ priv.__maximumWidth = 100;
266+
267+ menu.unityMenuModel.modelData = longMenu;
268+ tryCompare(menu, "width", priv.__maximumWidth);
269+
270+ priv.__maximumWidth = 200;
271+ tryCompare(menu, "width", priv.__maximumWidth);
272+
273+ priv.__maximumWidth = 1200;
274+ tryCompareFunction(function() { return menu.width < priv.__maximumWidth; }, true);
275+ }
276+
277+ function test_minimumHeight() {
278+ var shortMenu = [{
279+ "rowData": { "label": "menu1" }
280+ }];
281+ menu.unityMenuModel.modelData = shortMenu;
282+
283+ var priv = findInvisibleChild(menu, "d");
284+ priv.__minimumHeight = 0;
285+ priv.__maximumHeight = 1000;
286+ tryCompareFunction(function() { return menu.height > priv.__minimumHeight; }, true);
287+
288+ priv.__minimumHeight = 300;
289+ tryCompare(menu, "height", priv.__minimumHeight);
290+ }
291+
292+ function test_maximumHeight() {
293+ var shortMenu = [{
294+ "rowData": { "label": "menu1" }}, {
295+ "rowData": { "label": "menu2" }}, {
296+ "rowData": { "label": "menu3" }}, {
297+ "rowData": { "label": "menu4" }}, {
298+ "rowData": { "label": "menu5" }}, {
299+ "rowData": { "label": "menu6" }}, {
300+ "rowData": { "label": "menu7" }}, {
301+ "rowData": { "label": "menu8" }}, {
302+ "rowData": { "label": "menu9" }
303+ }];
304+ menu.unityMenuModel.modelData = shortMenu;
305+
306+ var priv = findInvisibleChild(menu, "d");
307+ priv.__minimumHeight = 0;
308+ priv.__maximumHeight = 100;
309+ tryCompare(menu, "height", priv.__maximumHeight);
310+
311+ priv.__maximumHeight = 200;
312+ tryCompare(menu, "height", priv.__maximumHeight);
313+
314+ priv.__maximumHeight = 1200;
315+ tryCompareFunction(function() { return menu.height < priv.__maximumHeight; }, true);
316+ }
206317 }
207318}