on xenial help sign in
fixed more focus issues
b170d09Nick Dedekind
qml/Stages/DesktopStage.qml+9−3
@@ -21,7 +21,7 @@ import Ubuntu.Components 1.1
21import Unity.Application 0.1
21import Unity.Application 0.1
22import "../Components/PanelState"
22import "../Components/PanelState"
23
23
24−FocusScope {
24+Rectangle {
25 id: root
25 id: root
26
26
27 anchors.fill: parent
27 anchors.fill: parent
@@ -48,7 +48,6 @@ FocusScope {
48 appDelegate.state = "normal"
48 appDelegate.state = "normal"
49 }
49 }
50 ApplicationManager.focusApplication(appId);
50 ApplicationManager.focusApplication(appId);
51− appDelegate.focus = true;
52 }
51 }
53 }
52 }
54
53
@@ -56,7 +55,14 @@ FocusScope {
56 id: priv
55 id: priv
57
56
58 readonly property string focusedAppId: ApplicationManager.focusedApplicationId
57 readonly property string focusedAppId: ApplicationManager.focusedApplicationId
58+ readonly property int focusedAppIndex: indexOf(focusedAppId)
59− readonly property var focusedAppDelegate: focusedAppId ? appRepeater.itemAt(indexOf(focusedAppId)) : null
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+ }
60
66
61 function indexOf(appId) {
67 function indexOf(appId) {
62 for (var i = 0; i < ApplicationManager.count; i++) {
68 for (var i = 0; i < ApplicationManager.count; i++) {
qml/Stages/PhoneStage.qml+2−4
@@ -117,14 +117,12 @@ Rectangle {
117
117
118 readonly property int firstSpreadIndex: root.focusFirstApp ? 1 : 0
118 readonly property int firstSpreadIndex: root.focusFirstApp ? 1 : 0
119 property string focusedAppId: applicationManager.focusedApplicationId
119 property string focusedAppId: applicationManager.focusedApplicationId
120− property var focusedApplication: applicationManager.findApplication(focusedAppId)
120+ readonly property int focusedAppIndex: indexOf(focusedAppId)
121− property var focusedAppDelegate: null
121+ readonly property var focusedAppDelegate: focusedAppId && spreadRepeater.count > focusedAppIndex ? spreadRepeater.itemAt(focusedAppIndex) : null
122
122
123 property real oldInverseProgress: 0
123 property real oldInverseProgress: 0
124 property bool animateX: false
124 property bool animateX: false
125
125
126− onFocusedAppIdChanged: focusedAppDelegate = spreadRepeater.itemAt(0);
127−
128 onFocusedAppDelegateChanged: {
126 onFocusedAppDelegateChanged: {
129 if (focusedAppDelegate) {
127 if (focusedAppDelegate) {
130 focusedAppDelegate.focus = true;
128 focusedAppDelegate.focus = true;
qml/Stages/TabletStage.qml+6−11
@@ -53,6 +53,9 @@ Rectangle {
53 id: priv
53 id: priv
54
54
55 property string focusedAppId: ApplicationManager.focusedApplicationId
55 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+
56 property string oldFocusedAppId: ""
59 property string oldFocusedAppId: ""
57
60
58 property string mainStageAppId
61 property string mainStageAppId
@@ -76,19 +79,11 @@ Rectangle {
76
79
77 appId0 = ApplicationManager.count >= 1 ? ApplicationManager.get(0).appId : "";
80 appId0 = ApplicationManager.count >= 1 ? ApplicationManager.get(0).appId : "";
78 appId1 = ApplicationManager.count > 1 ? ApplicationManager.get(1).appId : "";
81 appId1 = ApplicationManager.count > 1 ? ApplicationManager.get(1).appId : "";
79−
80− // Update the QML focus accordingly
81− updateSpreadDelegateFocus();
82 }
82 }
83
83
84− function updateSpreadDelegateFocus() {
84+ onFocusedAppDelegateChanged: {
85− if (priv.focusedAppId) {
85+ if (focusedAppDelegate) {
86− var focusedAppIndex = priv.indexOf(priv.focusedAppId);
86+ focusedAppDelegate.focus = true;
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− }
92 }
87 }
93 }
88 }
94
89
tests/qmltests/tst_Shell.qml+31−4
@@ -740,13 +740,40 @@ Rectangle {
740 loadShell(data.formFactor);
740 loadShell(data.formFactor);
741 swipeAwayGreeter();
741 swipeAwayGreeter();
742
742
743− var dialerApp = ApplicationManager.startApplication("webbrowser-app");
743+ var webApp = ApplicationManager.startApplication("webbrowser-app");
744− verify(dialerApp);
744+ verify(webApp);
745 waitUntilAppSurfaceShowsUp("webbrowser-app")
745 waitUntilAppSurfaceShowsUp("webbrowser-app")
746
746
747− verify(dialerApp.session.surface);
747+ verify(webApp.session.surface);
748
748
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);
749− tryCompare(dialerApp.session.surface, "activeFocus", true);
776+ tryCompare(webApp.session.surface, "activeFocus", true);
750 }
777 }
751
778
752 function waitUntilAppSurfaceShowsUp(appId) {
779 function waitUntilAppSurfaceShowsUp(appId) {