Merge lp:~aacid/unity8/makeSureMenuPositionOnScreen into lp:unity8

Proposed by Albert Astals Cid
Status: Superseded
Proposed branch: lp:~aacid/unity8/makeSureMenuPositionOnScreen
Merge into: lp:unity8
Prerequisite: lp:~nick-dedekind/unity8/menu.width.fix
Diff against target: 408 lines (+252/-24)
6 files modified
qml/ApplicationMenus/ApplicationMenusLimits.qml (+24/-0)
qml/ApplicationMenus/MenuBar.qml (+10/-3)
qml/ApplicationMenus/MenuPopup.qml (+67/-21)
qml/ApplicationMenus/qmldir (+1/-0)
tests/qmltests/ApplicationMenus/tst_MenuBar.qml (+50/-0)
tests/qmltests/Stage/tst_DesktopStage.qml (+100/-0)
To merge this branch: bzr merge lp:~aacid/unity8/makeSureMenuPositionOnScreen
Reviewer Review Type Date Requested Status
Unity8 CI Bot continuous-integration Approve
Unity Team Pending
Review via email: mp+315470@code.launchpad.net

This proposal has been superseded by a proposal from 2017-01-26.

Commit message

 Make the menus and submenus do not go outside the screen when popping out

Description of the change

 * Are there any related MPs required for this MP to build/function as expected?
No

 * Did you perform an exploratory manual test run of your code change and any related functionality?
Yes

 * If you changed the packaging (debian), did you subscribe the ubuntu-unity team to this MP?
N/A

 * If you changed the UI, has there been a design review?
N/A

To post a comment you must log in.
2773. By Albert Astals Cid

Now with better files!

Revision history for this message
Unity8 CI Bot (unity8-ci-bot) wrote :

FAILED: Continuous integration, rev:2772
https://unity8-jenkins.ubuntu.com/job/lp-unity8-ci/3011/
Executed test runs:
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build/3916
    UNSTABLE: https://unity8-jenkins.ubuntu.com/job/test-0-autopkgtest/label=amd64,release=xenial+overlay,testname=qmluitests.sh/2294
    UNSTABLE: https://unity8-jenkins.ubuntu.com/job/test-0-autopkgtest/label=amd64,release=zesty,testname=qmluitests.sh/2294
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-0-fetch/3944
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=xenial+overlay/3789
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=xenial+overlay/3789/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=zesty/3789
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=zesty/3789/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=xenial+overlay/3789
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=xenial+overlay/3789/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=zesty/3789
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=zesty/3789/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=xenial+overlay/3789
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=xenial+overlay/3789/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=zesty/3789
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=zesty/3789/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://unity8-jenkins.ubuntu.com/job/lp-unity8-ci/3011/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
Unity8 CI Bot (unity8-ci-bot) wrote :

FAILED: Continuous integration, rev:2773
https://unity8-jenkins.ubuntu.com/job/lp-unity8-ci/3013/
Executed test runs:
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build/3919
    UNSTABLE: https://unity8-jenkins.ubuntu.com/job/test-0-autopkgtest/label=amd64,release=xenial+overlay,testname=qmluitests.sh/2296
    UNSTABLE: https://unity8-jenkins.ubuntu.com/job/test-0-autopkgtest/label=amd64,release=zesty,testname=qmluitests.sh/2296
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-0-fetch/3947
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=xenial+overlay/3792
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=xenial+overlay/3792/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=zesty/3792
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=zesty/3792/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=xenial+overlay/3792
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=xenial+overlay/3792/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=zesty/3792
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=zesty/3792/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=xenial+overlay/3792
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=xenial+overlay/3792/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=zesty/3792
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=zesty/3792/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://unity8-jenkins.ubuntu.com/job/lp-unity8-ci/3013/rebuild

review: Needs Fixing (continuous-integration)
2774. By Albert Astals Cid

Do not use exact gu values for the compares

Since there's text involved the gu values are not the same depending your px per gu, so do it in a bit of more fuzzy way

Revision history for this message
Unity8 CI Bot (unity8-ci-bot) wrote :

PASSED: Continuous integration, rev:2774
https://unity8-jenkins.ubuntu.com/job/lp-unity8-ci/3014/
Executed test runs:
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build/3921
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/test-0-autopkgtest/label=amd64,release=xenial+overlay,testname=qmluitests.sh/2297
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/test-0-autopkgtest/label=amd64,release=zesty,testname=qmluitests.sh/2297
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-0-fetch/3949
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=xenial+overlay/3794
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=xenial+overlay/3794/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=zesty/3794
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=zesty/3794/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=xenial+overlay/3794
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=xenial+overlay/3794/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=zesty/3794
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=zesty/3794/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=xenial+overlay/3794
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=xenial+overlay/3794/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=zesty/3794
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=zesty/3794/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://unity8-jenkins.ubuntu.com/job/lp-unity8-ci/3014/rebuild

review: Approve (continuous-integration)
2775. By Albert Astals Cid

Merge

2776. By Albert Astals Cid

Merge clickOpenMenuClosesIt

Revision history for this message
Unity8 CI Bot (unity8-ci-bot) wrote :

PASSED: Continuous integration, rev:2775
https://unity8-jenkins.ubuntu.com/job/lp-unity8-ci/3035/
Executed test runs:
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build/3950
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/test-0-autopkgtest/label=amd64,release=xenial+overlay,testname=qmluitests.sh/2308
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/test-0-autopkgtest/label=amd64,release=zesty,testname=qmluitests.sh/2308
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-0-fetch/3978
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=xenial+overlay/3823
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=xenial+overlay/3823/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=zesty/3823
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=zesty/3823/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=xenial+overlay/3823
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=xenial+overlay/3823/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=zesty/3823
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=zesty/3823/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=xenial+overlay/3823
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=xenial+overlay/3823/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=zesty/3823
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=zesty/3823/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://unity8-jenkins.ubuntu.com/job/lp-unity8-ci/3035/rebuild

review: Approve (continuous-integration)
2777. By Albert Astals Cid

Merge

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== added file 'qml/ApplicationMenus/ApplicationMenusLimits.qml'
--- qml/ApplicationMenus/ApplicationMenusLimits.qml 1970-01-01 00:00:00 +0000
+++ qml/ApplicationMenus/ApplicationMenusLimits.qml 2017-01-26 09:29:42 +0000
@@ -0,0 +1,24 @@
1/*
2 * Copyright (C) 2017 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
17pragma Singleton
18import QtQuick 2.4
19import QtQuick.Window 2.2
20
21QtObject {
22 property real screenWidth: Screen.width
23 property real screenHeight: Screen.height
24}
025
=== modified file 'qml/ApplicationMenus/MenuBar.qml'
--- qml/ApplicationMenus/MenuBar.qml 2017-01-17 09:45:22 +0000
+++ qml/ApplicationMenus/MenuBar.qml 2017-01-26 09:29:42 +0000
@@ -114,6 +114,7 @@
114 function show() {114 function show() {
115 if (!__popup) {115 if (!__popup) {
116 __popup = menuComponent.createObject(root, { objectName: visualItem.objectName + "-menu" });116 __popup = menuComponent.createObject(root, { objectName: visualItem.objectName + "-menu" });
117 __popup.childActivated.connect(dismiss);
117 // force the current item to be the newly popped up menu118 // force the current item to be the newly popped up menu
118 } else {119 } else {
119 __popup.show();120 __popup.show();
@@ -148,8 +149,8 @@
148 Component {149 Component {
149 id: menuComponent150 id: menuComponent
150 MenuPopup {151 MenuPopup {
151 x: visualItem.x - units.gu(1)152 desiredX: visualItem.x - units.gu(1)
152 anchors.top: parent.bottom153 desiredY: parent.height
153 unityMenuModel: root.unityMenuModel.submenu(visualItem.__ownIndex)154 unityMenuModel: root.unityMenuModel.submenu(visualItem.__ownIndex)
154155
155 Component.onCompleted: reset();156 Component.onCompleted: reset();
@@ -212,7 +213,13 @@
212 updateCurrentItemFromPosition(Qt.point(mouse.x, mouse.y))213 updateCurrentItemFromPosition(Qt.point(mouse.x, mouse.y))
213 }214 }
214 }215 }
215 onClicked: updateCurrentItemFromPosition(Qt.point(mouse.x, mouse.y))216 onClicked: {
217 var prevItem = d.currentItem;
218 updateCurrentItemFromPosition(Qt.point(mouse.x, mouse.y))
219 if (prevItem && d.currentItem == prevItem) {
220 prevItem.hide();
221 }
222 }
216223
217 function updateCurrentItemFromPosition(point) {224 function updateCurrentItemFromPosition(point) {
218 var pos = mapToItem(row, point.x, point.y);225 var pos = mapToItem(row, point.x, point.y);
219226
=== modified file 'qml/ApplicationMenus/MenuPopup.qml'
--- qml/ApplicationMenus/MenuPopup.qml 2017-01-18 12:08:05 +0000
+++ qml/ApplicationMenus/MenuPopup.qml 2017-01-26 09:29:42 +0000
@@ -16,16 +16,50 @@
1616
17import QtQuick 2.417import QtQuick 2.4
18import QtQuick.Layouts 1.118import QtQuick.Layouts 1.1
19import QtQuick.Window 2.2
20import Ubuntu.Components 1.319import Ubuntu.Components 1.3
21import Ubuntu.Components.ListItems 1.3 as ListItems20import Ubuntu.Components.ListItems 1.3 as ListItems
22import "../Components"21import "../Components"
22import "."
2323
24UbuntuShape {24UbuntuShape {
25 id: root25 id: root
26 objectName: "menu"26 objectName: "menu"
27 backgroundColor: theme.palette.normal.overlay27 backgroundColor: theme.palette.normal.overlay
2828
29 signal childActivated()
30
31 // true for submenus that need to show on the other side of their parent
32 // if they don't fit when growing right
33 property bool substractWidth: false
34
35 property real desiredX
36 x: {
37 var dummy = visible; // force recalc when shown/hidden
38 var parentTopLeft = parent.mapToItem(null, 0, 0);
39 var farX = ApplicationMenusLimits.screenWidth;
40 if (parentTopLeft.x + width + desiredX <= farX) {
41 return desiredX;
42 } else {
43 if (substractWidth) {
44 return -width;
45 } else {
46 return farX - parentTopLeft.x - width;
47 }
48 }
49 }
50
51 property real desiredY
52 y: {
53 var dummy = visible; // force recalc when shown/hidden
54 var parentTopLeft = parent.mapToItem(null, 0, 0);
55 var bottomY = ApplicationMenusLimits.screenHeight;
56 if (parentTopLeft.y + height + desiredY <= bottomY) {
57 return desiredY;
58 } else {
59 return bottomY - parentTopLeft.y - height;
60 }
61 }
62
29 property alias unityMenuModel: repeater.model63 property alias unityMenuModel: repeater.model
3064
31 function show() {65 function show() {
@@ -64,9 +98,9 @@
64 readonly property int currentIndex: currentItem ? currentItem.__ownIndex : -198 readonly property int currentIndex: currentItem ? currentItem.__ownIndex : -1
6599
66 property real __minimumWidth: units.gu(20)100 property real __minimumWidth: units.gu(20)
67 property real __maximumWidth: Screen.width * 0.7101 property real __maximumWidth: ApplicationMenusLimits.screenWidth * 0.7
68 property real __minimumHeight: units.gu(2)102 property real __minimumHeight: units.gu(2)
69 property real __maximumHeight: Screen.height * 0.7103 property real __maximumHeight: ApplicationMenusLimits.screenHeight * 0.7
70104
71 signal dismissAll()105 signal dismissAll()
72106
@@ -257,22 +291,29 @@
257 popup = submenuComponent.createObject(focusScope, {291 popup = submenuComponent.createObject(focusScope, {
258 objectName: loader.objectName + "-",292 objectName: loader.objectName + "-",
259 unityMenuModel: model,293 unityMenuModel: model,
260 x: Qt.binding(function() { return root.width }),294 substractWidth: true,
261 y: Qt.binding(function() {295 desiredX: Qt.binding(function() { return root.width }),
296 desiredY: Qt.binding(function() {
262 var dummy = listView.contentY; // force a recalc on contentY change.297 var dummy = listView.contentY; // force a recalc on contentY change.
263 return mapToItem(container, 0, y).y;298 return mapToItem(container, 0, y).y;
264 })299 })
265 });300 });
301 popup.retreat.connect(function() {
302 popup.destroy();
303 popup = null;
304 menuItem.forceActiveFocus();
305 });
306 popup.childActivated.connect(function() {
307 popup.destroy();
308 popup = null;
309 root.childActivated();
310 });
266 } else if (popup) {311 } else if (popup) {
267 popup.visible = true;312 popup.visible = true;
268 }313 }
269 popup.retreat.connect(function() {
270 popup.destroy();
271 popup = null;
272 menuItem.forceActiveFocus();
273 })
274 } else {314 } else {
275 root.unityMenuModel.activate(__ownIndex);315 root.unityMenuModel.activate(__ownIndex);
316 root.childActivated();
276 }317 }
277 }318 }
278319
@@ -375,23 +416,28 @@
375 id: submenuLoader416 id: submenuLoader
376 source: "MenuPopup.qml"417 source: "MenuPopup.qml"
377418
419 property real desiredX
420 property real desiredY
421 property bool substractWidth
378 property var unityMenuModel: null422 property var unityMenuModel: null
379 signal retreat()423 signal retreat()
380424 signal childActivated()
381 Binding {425
382 target: item426 onLoaded: {
383 property: "unityMenuModel"427 item.unityMenuModel = Qt.binding(function() { return submenuLoader.unityMenuModel; });
384 value: submenuLoader.unityMenuModel428 item.objectName = Qt.binding(function() { return submenuLoader.objectName + "menu"; });
385 }429 item.desiredX = Qt.binding(function() { return submenuLoader.desiredX; });
386430 item.desiredY = Qt.binding(function() { return submenuLoader.desiredY; });
387 Binding {431 item.substractWidth = Qt.binding(function() { return submenuLoader.substractWidth; });
388 target: item
389 property: "objectName"
390 value: submenuLoader.objectName + "menu"
391 }432 }
392433
393 Keys.onLeftPressed: retreat()434 Keys.onLeftPressed: retreat()
394435
436 Connections {
437 target: item
438 onChildActivated: childActivated();
439 }
440
395 Component.onCompleted: item.select(0);441 Component.onCompleted: item.select(0);
396 onVisibleChanged: if (visible) { item.select(0); }442 onVisibleChanged: if (visible) { item.select(0); }
397 }443 }
398444
=== added file 'qml/ApplicationMenus/qmldir'
--- qml/ApplicationMenus/qmldir 1970-01-01 00:00:00 +0000
+++ qml/ApplicationMenus/qmldir 2017-01-26 09:29:42 +0000
@@ -0,0 +1,1 @@
1singleton ApplicationMenusLimits 0.1 ApplicationMenusLimits.qml
02
=== modified file 'tests/qmltests/ApplicationMenus/tst_MenuBar.qml'
--- tests/qmltests/ApplicationMenus/tst_MenuBar.qml 2017-01-24 07:41:35 +0000
+++ tests/qmltests/ApplicationMenus/tst_MenuBar.qml 2017-01-26 09:29:42 +0000
@@ -180,6 +180,41 @@
180 tryCompare(priv, "currentItem", menuItem);180 tryCompare(priv, "currentItem", menuItem);
181 }181 }
182182
183 function test_menuActivateClosesMenu() {
184 menuBackend.modelData = appMenuData.generateTestData(3,3,0,0,"menu");
185 var priv = findInvisibleChild(menuBar, "d");
186
187 var menuItem = findChild(menuBar, "menuBar-item0");
188 menuItem.show();
189 compare(priv.currentItem, menuItem, "CurrentItem should be set to item 0");
190 compare(priv.currentItem.popupVisible, true, "Popup should be visible");
191
192 var actionItem = findChild(menuBar, "menuBar-item0-menu-item0-actionItem");
193 mouseClick(actionItem);
194 compare(priv.currentItem, null, "CurrentItem should be null");
195 }
196
197 function test_subMenuActivateClosesMenu() {
198 menuBackend.modelData = appMenuData.generateTestData(3,4,1,0,"menu");
199 var priv = findInvisibleChild(menuBar, "d");
200
201 var menuItem = findChild(menuBar, "menuBar-item0");
202 menuItem.show();
203 compare(priv.currentItem, menuItem, "CurrentItem should be set to item 0");
204 compare(priv.currentItem.popupVisible, true, "Popup should be visible");
205
206 var actionItem = findChild(menuBar, "menuBar-item0-menu-item0-actionItem");
207 mouseClick(actionItem);
208
209 actionItem = findChild(menuBar, "menuBar-item0-menu-item0-menu-item0-actionItem");
210 mouseClick(actionItem);
211
212 actionItem = findChild(menuBar, "menuBar-item0-menu-item0-menu-item0-menu-item0-actionItem");
213 mouseClick(actionItem);
214
215 compare(priv.currentItem, null, "CurrentItem should be null");
216 }
217
183 function test_openAppMenuShortcut() {218 function test_openAppMenuShortcut() {
184 var priv = findInvisibleChild(menuBar, "d");219 var priv = findInvisibleChild(menuBar, "d");
185220
@@ -192,5 +227,20 @@
192 keyClick(Qt.Key_F10, Qt.AltModifier);227 keyClick(Qt.Key_F10, Qt.AltModifier);
193 compare(priv.currentItem, menuItem1, "First enabled item should be opened");228 compare(priv.currentItem, menuItem1, "First enabled item should be opened");
194 }229 }
230
231 function test_clickOpenMenuClosesMenu() {
232 menuBackend.modelData = appMenuData.generateTestData(3,3,0,0,"menu");
233 var priv = findInvisibleChild(menuBar, "d");
234
235 var menuItem = findChild(menuBar, "menuBar-item0");
236 waitForRendering(menuItem);
237 mouseClick(menuItem);
238 compare(priv.currentItem, menuItem, "CurrentItem should be set to item 0");
239 compare(priv.currentItem.popupVisible, true, "Popup should be visible");
240
241 waitForRendering(menuItem);
242 mouseClick(menuItem);
243 compare(priv.currentItem, null, "CurrentItem should be null");
244 }
195 }245 }
196}246}
197247
=== modified file 'tests/qmltests/Stage/tst_DesktopStage.qml'
--- tests/qmltests/Stage/tst_DesktopStage.qml 2017-01-10 14:44:29 +0000
+++ tests/qmltests/Stage/tst_DesktopStage.qml 2017-01-26 09:29:42 +0000
@@ -29,6 +29,7 @@
29import "../../../qml/Stage"29import "../../../qml/Stage"
30import "../../../qml/Components"30import "../../../qml/Components"
31import "../../../qml/Components/PanelState"31import "../../../qml/Components/PanelState"
32import "../../../qml/ApplicationMenus"
3233
33Item {34Item {
34 id: root35 id: root
@@ -44,6 +45,8 @@
44 }45 }
4546
46 Component.onCompleted: {47 Component.onCompleted: {
48 ApplicationMenusLimits.screenWidth = Qt.binding( function() { return stageLoader.width; } );
49 ApplicationMenusLimits.screenHeight = Qt.binding( function() { return stageLoader.height; } );
47 QuickUtils.keyboardAttached = true;50 QuickUtils.keyboardAttached = true;
48 theme.name = "Ubuntu.Components.Themes.SuruDark";51 theme.name = "Ubuntu.Components.Themes.SuruDark";
49 resetGeometry();52 resetGeometry();
@@ -830,5 +833,102 @@
830 mouseRelease(decoration);833 mouseRelease(decoration);
831 tryCompare(Mir, "cursorName", "");834 tryCompare(Mir, "cursorName", "");
832 }835 }
836
837 function test_menuPositioning_data() {
838 return [
839 {tag: "good",
840 windowPosition: Qt.point(units.gu(10), units.gu(10))
841 },
842 {tag: "collides right",
843 windowPosition: Qt.point(units.gu(100), units.gu(10)),
844 minimumXDifference: units.gu(8)
845 },
846 {tag: "collides bottom",
847 windowPosition: Qt.point(units.gu(10), units.gu(80)),
848 minimumYDifference: units.gu(7)
849 },
850 ]
851 }
852
853 function test_menuPositioning(data) {
854 var appDelegate = startApplication("dialer-app");
855 appDelegate.windowedX = data.windowPosition.x;
856 appDelegate.windowedY = data.windowPosition.y;
857
858 var menuItem = findChild(appDelegate, "menuBar-item3");
859 menuItem.show();
860
861 var menu = findChild(appDelegate, "menuBar-item3-menu");
862 tryCompare(menu, "visible", true);
863
864 var normalPositioningX = menuItem.x - units.gu(1);
865 var normalPositioningY = menuItem.height;
866
867 // We do this fuzzy checking because otherwise we would be duplicating the code
868 // that calculates the coordinates and any bug it may have, what we want is really
869 // to check that on collision with the border the menu is shifted substantially
870 if (data.minimumXDifference) {
871 verify(menu.x < normalPositioningX - data.minimumXDifference);
872 } else {
873 compare(menu.x, normalPositioningX);
874 }
875
876 if (data.minimumYDifference) {
877 verify(menu.y < normalPositioningY - data.minimumYDifference);
878 } else {
879 compare(menu.y, normalPositioningY);
880 }
881 }
882
883 function test_submenuPositioning_data() {
884 return [
885 {tag: "good",
886 windowPosition: Qt.point(units.gu(10), units.gu(10))
887 },
888 {tag: "collides right",
889 windowPosition: Qt.point(units.gu(100), units.gu(10)),
890 minimumXDifference: units.gu(35)
891 },
892 {tag: "collides bottom",
893 windowPosition: Qt.point(units.gu(10), units.gu(80)),
894 minimumYDifference: units.gu(8)
895 },
896 ]
897 }
898
899 function test_submenuPositioning(data) {
900 var appDelegate = startApplication("dialer-app");
901 appDelegate.windowedX = data.windowPosition.x;
902 appDelegate.windowedY = data.windowPosition.y;
903
904 var menuItem = findChild(appDelegate, "menuBar-item3");
905 menuItem.show();
906
907 var menu = findChild(appDelegate, "menuBar-item3-menu");
908 menuItem = findChild(menu, "menuBar-item3-menu-item3-actionItem");
909 tryCompare(menuItem, "visible", true);
910 mouseMove(menuItem);
911 mouseClick(menuItem);
912
913 menu = findChild(appDelegate, "menuBar-item3-menu-item3-menu");
914
915 var normalPositioningX = menuItem.width;
916 var normalPositioningY = menuItem.parent.y;
917
918 // We do this fuzzy checking because otherwise we would be duplicating the code
919 // that calculates the coordinates and any bug it may have, what we want is really
920 // to check that on collision with the border the menu is shifted substantially
921 if (data.minimumXDifference) {
922 verify(menu.x < normalPositioningX - data.minimumXDifference);
923 } else {
924 compare(menu.x, normalPositioningX);
925 }
926
927 if (data.minimumYDifference) {
928 verify(menu.y < normalPositioningY - data.minimumYDifference);
929 } else {
930 compare(menu.y, normalPositioningY);
931 }
932 }
833 }933 }
834}934}

Subscribers

People subscribed via source and target branches