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

Proposed by Albert Astals Cid
Status: Merged
Approved by: Michael Zanetti
Approved revision: 2776
Merged at revision: 2811
Proposed branch: lp:~aacid/unity8/makeSureMenuPositionOnScreen
Merge into: lp:unity8
Prerequisite: lp:~aacid/unity8/clickOpenMenuClosesIt
Diff against target: 282 lines (+174/-17)
5 files modified
qml/ApplicationMenus/ApplicationMenusLimits.qml (+24/-0)
qml/ApplicationMenus/MenuBar.qml (+2/-2)
qml/ApplicationMenus/MenuPopup.qml (+47/-15)
qml/ApplicationMenus/qmldir (+1/-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
Michael Zanetti (community) Approve
Unity8 CI Bot continuous-integration Approve
Review via email: mp+315655@code.launchpad.net

This proposal supersedes a proposal from 2017-01-24.

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.
Revision history for this message
Unity8 CI Bot (unity8-ci-bot) wrote : Posted in a previous version of this proposal

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 : Posted in a previous version of this proposal

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)
Revision history for this message
Unity8 CI Bot (unity8-ci-bot) wrote : Posted in a previous version of this proposal

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)
Revision history for this message
Unity8 CI Bot (unity8-ci-bot) wrote : Posted in a previous version of this proposal

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)
Revision history for this message
Unity8 CI Bot (unity8-ci-bot) wrote :

FAILED: Continuous integration, rev:2776
https://unity8-jenkins.ubuntu.com/job/lp-unity8-ci/3041/
Executed test runs:
    FAILURE: https://unity8-jenkins.ubuntu.com/job/build/3956/console
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-0-fetch/3984
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=xenial+overlay/3829
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=xenial+overlay/3829/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=zesty/3829
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=zesty/3829/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=xenial+overlay/3829
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=xenial+overlay/3829/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=zesty/3829
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=zesty/3829/artifact/output/*zip*/output.zip
    FAILURE: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=xenial+overlay/3829/console
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=zesty/3829
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=zesty/3829/artifact/output/*zip*/output.zip

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

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

PASSED: Continuous integration, rev:2776
https://unity8-jenkins.ubuntu.com/job/lp-unity8-ci/3048/
Executed test runs:
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build/3963
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/test-0-autopkgtest/label=amd64,release=xenial+overlay,testname=qmluitests.sh/2318
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/test-0-autopkgtest/label=amd64,release=zesty,testname=qmluitests.sh/2318
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-0-fetch/3991
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=xenial+overlay/3836
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=xenial+overlay/3836/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=zesty/3836
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=zesty/3836/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=xenial+overlay/3836
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=xenial+overlay/3836/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=zesty/3836
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=zesty/3836/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=xenial+overlay/3836
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=xenial+overlay/3836/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=zesty/3836
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=zesty/3836/artifact/output/*zip*/output.zip

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

review: Approve (continuous-integration)
Revision history for this message
Michael Zanetti (mzanetti) wrote :

code looks fine, it also works great in my testing.

Visually it allows getting in rather unpleasant situations like for example this: http://i.imgur.com/haIc0Hr.jpg

should we report a bug for design for this? wdyt?

review: Needs Information
Revision history for this message
Albert Astals Cid (aacid) wrote :

> code looks fine, it also works great in my testing.
>
> Visually it allows getting in rather unpleasant situations like for example
> this: http://i.imgur.com/haIc0Hr.jpg
>
> should we report a bug for design for this? wdyt?

Yes, i agree we should open a bug for design about this. Will you or want me to?

Meanwhile if possible I'd like to get this landed as defenitely improves the situation.

Revision history for this message
Michael Zanetti (mzanetti) wrote :

Reported the bug: https://bugs.launchpad.net/ubuntu-ux/+bug/1659800

apart from this, it works fine. code looks good

review: Approve
2777. By Albert Astals Cid

Merge

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-02-07 15:45:21 +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-02-07 15:45:21 +0000
+++ qml/ApplicationMenus/MenuBar.qml 2017-02-07 15:45:21 +0000
@@ -149,8 +149,8 @@
149 Component {149 Component {
150 id: menuComponent150 id: menuComponent
151 MenuPopup {151 MenuPopup {
152 x: visualItem.x - units.gu(1)152 desiredX: visualItem.x - units.gu(1)
153 anchors.top: parent.bottom153 desiredY: parent.height
154 unityMenuModel: root.unityMenuModel.submenu(visualItem.__ownIndex)154 unityMenuModel: root.unityMenuModel.submenu(visualItem.__ownIndex)
155155
156 Component.onCompleted: reset();156 Component.onCompleted: reset();
157157
=== modified file 'qml/ApplicationMenus/MenuPopup.qml'
--- qml/ApplicationMenus/MenuPopup.qml 2017-02-07 15:45:21 +0000
+++ qml/ApplicationMenus/MenuPopup.qml 2017-02-07 15:45:21 +0000
@@ -16,10 +16,10 @@
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
@@ -28,6 +28,38 @@
2828
29 signal childActivated()29 signal childActivated()
3030
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
31 property alias unityMenuModel: repeater.model63 property alias unityMenuModel: repeater.model
3264
33 function show() {65 function show() {
@@ -66,9 +98,9 @@
66 readonly property int currentIndex: currentItem ? currentItem.__ownIndex : -198 readonly property int currentIndex: currentItem ? currentItem.__ownIndex : -1
6799
68 property real __minimumWidth: units.gu(20)100 property real __minimumWidth: units.gu(20)
69 property real __maximumWidth: Screen.width * 0.7101 property real __maximumWidth: ApplicationMenusLimits.screenWidth * 0.7
70 property real __minimumHeight: units.gu(2)102 property real __minimumHeight: units.gu(2)
71 property real __maximumHeight: Screen.height * 0.7103 property real __maximumHeight: ApplicationMenusLimits.screenHeight * 0.7
72104
73 signal dismissAll()105 signal dismissAll()
74106
@@ -259,8 +291,9 @@
259 popup = submenuComponent.createObject(focusScope, {291 popup = submenuComponent.createObject(focusScope, {
260 objectName: loader.objectName + "-",292 objectName: loader.objectName + "-",
261 unityMenuModel: model,293 unityMenuModel: model,
262 x: Qt.binding(function() { return root.width }),294 substractWidth: true,
263 y: Qt.binding(function() {295 desiredX: Qt.binding(function() { return root.width }),
296 desiredY: Qt.binding(function() {
264 var dummy = listView.contentY; // force a recalc on contentY change.297 var dummy = listView.contentY; // force a recalc on contentY change.
265 return mapToItem(container, 0, y).y;298 return mapToItem(container, 0, y).y;
266 })299 })
@@ -383,20 +416,19 @@
383 id: submenuLoader416 id: submenuLoader
384 source: "MenuPopup.qml"417 source: "MenuPopup.qml"
385418
419 property real desiredX
420 property real desiredY
421 property bool substractWidth
386 property var unityMenuModel: null422 property var unityMenuModel: null
387 signal retreat()423 signal retreat()
388 signal childActivated()424 signal childActivated()
389425
390 Binding {426 onLoaded: {
391 target: item427 item.unityMenuModel = Qt.binding(function() { return submenuLoader.unityMenuModel; });
392 property: "unityMenuModel"428 item.objectName = Qt.binding(function() { return submenuLoader.objectName + "menu"; });
393 value: submenuLoader.unityMenuModel429 item.desiredX = Qt.binding(function() { return submenuLoader.desiredX; });
394 }430 item.desiredY = Qt.binding(function() { return submenuLoader.desiredY; });
395431 item.substractWidth = Qt.binding(function() { return submenuLoader.substractWidth; });
396 Binding {
397 target: item
398 property: "objectName"
399 value: submenuLoader.objectName + "menu"
400 }432 }
401433
402 Keys.onLeftPressed: retreat()434 Keys.onLeftPressed: retreat()
403435
=== added file 'qml/ApplicationMenus/qmldir'
--- qml/ApplicationMenus/qmldir 1970-01-01 00:00:00 +0000
+++ qml/ApplicationMenus/qmldir 2017-02-07 15:45:21 +0000
@@ -0,0 +1,1 @@
1singleton ApplicationMenusLimits 0.1 ApplicationMenusLimits.qml
02
=== 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-02-07 15:45:21 +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