on xenial help sign in
fixed more focus issues
commitb170d09b05e7040d17f6623d68c81516a9442ad2 authorNick Dedekind <nick.dedekind@canonical.com> dateFri 1 May 2015, 14:11 (11 years ago) parentc45fe74
4 files changed+48−22
qml/Stages/DesktopStage.qml+9−3 qml/Stages/PhoneStage.qml+2−4 qml/Stages/TabletStage.qml+6−11 tests/qmltests/tst_Shell.qml+31−4
qml/Stages/DesktopStage.qml+9−3
@@ -21,7 +21,7 @@ import Ubuntu.Components 1.1
2121import Unity.Application 0.1
2222import "../Components/PanelState"
2323
24−FocusScope {
24+Rectangle {
2525 id: root
2626
2727 anchors.fill: parent
@@ -48,7 +48,6 @@ FocusScope {
4848 appDelegate.state = "normal"
4949 }
5050 ApplicationManager.focusApplication(appId);
51− appDelegate.focus = true;
5251 }
5352 }
5453
@@ -56,7 +55,14 @@ FocusScope {
5655 id: priv
5756
5857 readonly property string focusedAppId: ApplicationManager.focusedApplicationId
59− readonly property var focusedAppDelegate: focusedAppId ? appRepeater.itemAt(indexOf(focusedAppId)) : null
58+ readonly property int focusedAppIndex: indexOf(focusedAppId)
59+ readonly property var focusedAppDelegate: focusedAppId && appRepeater.count > focusedAppIndex ? appRepeater.itemAt(focusedAppIndex) : null
60+
61+ onFocusedAppDelegateChanged: {
62+ if (focusedAppDelegate) {
63+ focusedAppDelegate.focus = true;
64+ }
65+ }
6066
6167 function indexOf(appId) {
6268 for (var i = 0; i < ApplicationManager.count; i++) {
qml/Stages/PhoneStage.qml+2−4
@@ -117,14 +117,12 @@ Rectangle {
117117
118118 readonly property int firstSpreadIndex: root.focusFirstApp ? 1 : 0
119119 property string focusedAppId: applicationManager.focusedApplicationId
120− property var focusedApplication: applicationManager.findApplication(focusedAppId)
121− property var focusedAppDelegate: null
120+ readonly property int focusedAppIndex: indexOf(focusedAppId)
121+ readonly property var focusedAppDelegate: focusedAppId && spreadRepeater.count > focusedAppIndex ? spreadRepeater.itemAt(focusedAppIndex) : null
122122
123123 property real oldInverseProgress: 0
124124 property bool animateX: false
125125
126− onFocusedAppIdChanged: focusedAppDelegate = spreadRepeater.itemAt(0);
127−
128126 onFocusedAppDelegateChanged: {
129127 if (focusedAppDelegate) {
130128 focusedAppDelegate.focus = true;
qml/Stages/TabletStage.qml+6−11
@@ -53,6 +53,9 @@ Rectangle {
5353 id: priv
5454
5555 property string focusedAppId: ApplicationManager.focusedApplicationId
56+ readonly property int focusedAppIndex: indexOf(focusedAppId)
57+ readonly property var focusedAppDelegate: focusedAppId && spreadRepeater.count > focusedAppIndex ? spreadRepeater.itemAt(focusedAppIndex) : null
58+
5659 property string oldFocusedAppId: ""
5760
5861 property string mainStageAppId
@@ -76,19 +79,11 @@ Rectangle {
7679
7780 appId0 = ApplicationManager.count >= 1 ? ApplicationManager.get(0).appId : "";
7881 appId1 = ApplicationManager.count > 1 ? ApplicationManager.get(1).appId : "";
79−
80− // Update the QML focus accordingly
81− updateSpreadDelegateFocus();
8282 }
8383
84− function updateSpreadDelegateFocus() {
85− if (priv.focusedAppId) {
86− var focusedAppIndex = priv.indexOf(priv.focusedAppId);
87− if (focusedAppIndex !== -1) {
88− spreadRepeater.itemAt(focusedAppIndex).focus = true;
89− } else {
90− console.warn("TabletStage: Failed to find the SpreadDelegate for appID=" + priv.focusedAppId);
91− }
84+ onFocusedAppDelegateChanged: {
85+ if (focusedAppDelegate) {
86+ focusedAppDelegate.focus = true;
9287 }
9388 }
9489
tests/qmltests/tst_Shell.qml+31−4
@@ -740,13 +740,40 @@ Rectangle {
740740 loadShell(data.formFactor);
741741 swipeAwayGreeter();
742742
743− var dialerApp = ApplicationManager.startApplication("webbrowser-app");
744− verify(dialerApp);
743+ var webApp = ApplicationManager.startApplication("webbrowser-app");
744+ verify(webApp);
745745 waitUntilAppSurfaceShowsUp("webbrowser-app")
746746
747− verify(dialerApp.session.surface);
747+ verify(webApp.session.surface);
748748
749− tryCompare(dialerApp.session.surface, "activeFocus", true);
749+ tryCompare(webApp.session.surface, "activeFocus", true);
750+ }
751+
752+ function test_launchedAppHasActiveFocusWhenFormFactorSwitched_data() {
753+ return [
754+ {tag: "phone->tablet", from: "phone", to: "tablet"},
755+ {tag: "phone->desktop", from: "phone", to: "desktop"},
756+ {tag: "tablet->phone", from: "tablet", to: "phone"},
757+ {tag: "tablet->desktop", from: "tablet", to: "desktop"},
758+ {tag: "desktop->phone", from: "desktop", to: "phone"},
759+ {tag: "desktop->tablet", from: "desktop", to: "tablet"},
760+ ];
761+ }
762+
763+ function test_launchedAppHasActiveFocusWhenFormFactorSwitched(data) {
764+ loadShell(data.from);
765+ swipeAwayGreeter();
766+
767+ var webApp = ApplicationManager.startApplication("webbrowser-app");
768+ verify(webApp);
769+ waitUntilAppSurfaceShowsUp("webbrowser-app")
770+
771+ verify(webApp.session.surface);
772+
773+ tryCompare(webApp.session.surface, "activeFocus", true);
774+
775+ loadShell(data.to);
776+ tryCompare(webApp.session.surface, "activeFocus", true);
750777 }
751778
752779 function waitUntilAppSurfaceShowsUp(appId) {