on xenial help sign in
Fixed saving current stage and loss of surface focus when switching stages

Approved by: Michał Sawicz

commit9f9405bc8925d6ede8affca94cde118bd87b4aa0 authorMichał Sawicz <michal.sawicz@canonical.com> dateFri 20 May 2016, 08:43 (10 years ago) parentc714565d7d92a3
7 files changed+94−13
qml/Stages/SurfaceContainer.qml+3 qml/Stages/TabletStage.qml+4−3 tests/mocks/Unity/Application/MirSurfaceItem.cpp+16−7 tests/mocks/Unity/Application/MirSurfaceItem.h+1−1 tests/mocks/Utils/windowstatestorage.cpp+1 tests/mocks/Utils/windowstatestorage.h+3 tests/qmltests/Stages/tst_TabletStage.qml+66−2
qml/Stages/SurfaceContainer.qml+3
@@ -34,6 +34,9 @@ FocusScope {
3434 property int surfaceOrientationAngle: 0
3535 property bool resizeSurface: true
3636 property bool isPromptSurface: false
37+ // FIME - dont export, use interactive property. Need to fix qtmir to handle consumesInputChanged
38+ // to update surface activeFocus. See mock MirSurfaceItem.
39+ property alias consumesInput: surfaceItem.consumesInput
3740
3841 onSurfaceChanged: {
3942 // Not a binding because animations might remove the surface from the surfaceItem
qml/Stages/TabletStage.qml+4−3
@@ -752,7 +752,7 @@ AbstractStage {
752752
753753 readonly property bool wantsMainStage: stage == ApplicationInfoInterface.MainStage
754754
755− readonly property bool isDash: model.application.appId == "unity8-dash"
755+ readonly property bool isDash: application.appId == "unity8-dash"
756756
757757 onFocusChanged: {
758758 if (focus && !spreadRepeater.startingUp) {
@@ -768,7 +768,7 @@ AbstractStage {
768768 onFocusRequested: spreadTile.focus = true;
769769 }
770770 Connections {
771− target: model.application
771+ target: spreadTile.application
772772 onFocusRequested: {
773773 if (!model.surface) {
774774 // when an app has no surfaces, we assume there's only one entry representing it:
@@ -844,7 +844,7 @@ AbstractStage {
844844 _constructing = false;
845845 }
846846 Component.onDestruction: {
847− WindowStateStorage.saveStage(model.application.appId, stage);
847+ WindowStateStorage.saveStage(application.appId, stage);
848848 }
849849
850850 function refreshStage() {
@@ -1073,6 +1073,7 @@ AbstractStage {
10731073
10741074 surface: spreadDelegate ? spreadDelegate.surface : null
10751075
1076+ consumesInput: false
10761077 interactive: false
10771078 resizeSurface: false
10781079 focus: false
tests/mocks/Unity/Application/MirSurfaceItem.cpp+16−7
@@ -56,7 +56,11 @@ MirSurfaceItem::MirSurfaceItem(QQuickItem *parent)
5656 Qt::ExtraButton9 | Qt::ExtraButton10 | Qt::ExtraButton11 |
5757 Qt::ExtraButton12 | Qt::ExtraButton13);
5858
59+ connect(this, &QQuickItem::activeFocusChanged, this, &MirSurfaceItem::updateMirSurfaceActiveFocus);
5960 connect(this, &QQuickItem::visibleChanged, this, &MirSurfaceItem::updateMirSurfaceVisibility);
61+ connect(this, &MirSurfaceItem::consumesInputChanged, this, [this]() {
62+ updateMirSurfaceActiveFocus(hasActiveFocus());
63+ });
6064}
6165
6266MirSurfaceItem::~MirSurfaceItem()
@@ -234,6 +238,10 @@ void MirSurfaceItem::setSurface(MirSurfaceInterface* surface)
234238 delete m_qmlContentComponent;
235239 m_qmlContentComponent = nullptr;
236240
241+ if (hasActiveFocus() && m_consumesInput && m_qmlSurface->live()) {
242+ m_qmlSurface->setActiveFocus(false);
243+ }
244+
237245 disconnect(m_qmlSurface, nullptr, this, nullptr);
238246 m_qmlSurface->unregisterView((qintptr)this);
239247 }
@@ -243,8 +251,6 @@ void MirSurfaceItem::setSurface(MirSurfaceInterface* surface)
243251 if (m_qmlSurface) {
244252 m_qmlSurface->registerView((qintptr)this);
245253
246− m_qmlSurface->setActiveFocus(hasActiveFocus());
247−
248254 updateSurfaceSize();
249255 updateMirSurfaceVisibility();
250256
@@ -277,17 +283,20 @@ void MirSurfaceItem::setSurface(MirSurfaceInterface* surface)
277283 default:
278284 qFatal("MirSurfaceItem: Unhandled component status");
279285 }
286+
287+ if (m_consumesInput) {
288+ m_qmlSurface->setActiveFocus(hasActiveFocus());
289+ }
280290 }
281291
282292 Q_EMIT surfaceChanged(m_qmlSurface);
283293}
284294
285−void MirSurfaceItem::itemChange(ItemChange change, const ItemChangeData & value)
295+
296+void MirSurfaceItem::updateMirSurfaceActiveFocus(bool focused)
286297{
287− if (change == QQuickItem::ItemActiveFocusHasChanged) {
288− if (m_qmlSurface) {
289− m_qmlSurface->setActiveFocus(value.boolValue);
290− }
298+ if (m_qmlSurface && m_consumesInput && m_qmlSurface->live()) {
299+ m_qmlSurface->setActiveFocus(focused);
291300 }
292301}
293302
tests/mocks/Unity/Application/MirSurfaceItem.h+1−1
@@ -98,12 +98,12 @@ protected:
9898 void mousePressEvent(QMouseEvent * event) override;
9999 void mouseMoveEvent(QMouseEvent * event) override;
100100 void mouseReleaseEvent(QMouseEvent * event) override;
101− void itemChange(ItemChange change, const ItemChangeData & value) override;
102101
103102private Q_SLOTS:
104103 void onComponentStatusChanged(QQmlComponent::Status status);
105104 void updateScreenshot(QUrl screenshot);
106105 void updateMirSurfaceVisibility();
106+ void updateMirSurfaceActiveFocus(bool focused);
107107
108108private:
109109 void createQmlContentItem();
tests/mocks/Utils/windowstatestorage.cpp+1
@@ -50,6 +50,7 @@ QRect WindowStateStorage::getGeometry(const QString &windowId, const QRect &defa
5050void WindowStateStorage::saveStage(const QString &appId, int stage)
5151{
5252 m_stage[appId] = stage;
53+ Q_EMIT stageSaved(appId, stage);
5354}
5455
5556int WindowStateStorage::getStage(const QString &appId) const
tests/mocks/Utils/windowstatestorage.h+3
@@ -45,6 +45,9 @@ public:
4545Q_SIGNALS:
4646 void geometryChanged(const QVariantMap& geometry);
4747
48+ // For testing.
49+ void stageSaved(const QString& appId, int stage);
50+
4851private:
4952 void setGeometry(const QVariantMap& geometry);
5053 QVariantMap geometry() const;
tests/qmltests/Stages/tst_TabletStage.qml+66−2
@@ -129,6 +129,12 @@ Rectangle {
129129 }
130130 }
131131
132+ SignalSpy {
133+ id: stageSaver
134+ target: WindowStateStorage
135+ signalName: "stageSaved"
136+ }
137+
132138 UnityTestCase {
133139 id: testCase
134140 name: "TabletStage"
@@ -138,6 +144,7 @@ Rectangle {
138144 property Item sideStage: tabletStage ? findChild(tabletStage, "sideStage") : null
139145
140146 function init() {
147+ stageSaver.clear();
141148 tabletStageLoader.active = true;
142149 tryCompare(tabletStageLoader, "status", Loader.Ready);
143150
@@ -510,7 +517,35 @@ Rectangle {
510517 tryCompare(stagesPriv, "sideStageAppId", data.sideStageAppId);
511518 }
512519
513− function test_loadSideStageByDragginFromMainStage() {
520+ function test_applicationSavesLastStage_data() {
521+ return [
522+ { tag: "MainStage", stage: ApplicationInfoInterface.MainStage},
523+ { tag: "SideStage", stage: ApplicationInfoInterface.SideStage},
524+ ];
525+ }
526+
527+ function test_applicationSavesLastStage(data) {
528+ WindowStateStorage.saveStage(webbrowserCheckBox.appId, data.stage);
529+ stageSaver.clear();
530+
531+ var stagesPriv = findInvisibleChild(tabletStage, "stagesPriv");
532+ verify(stagesPriv);
533+
534+ tryCompare(stagesPriv, "mainStageAppId", "unity8-dash");
535+ tryCompare(stagesPriv, "sideStageAppId", "");
536+
537+ var webbrowserSurfaceId = topSurfaceList.nextId;
538+ webbrowserCheckBox.checked = true;
539+ waitUntilAppSurfaceShowsUp(webbrowserSurfaceId);
540+
541+ webbrowserCheckBox.checked = false;
542+
543+ tryCompare(stageSaver, "count", 1);
544+ compare(stageSaver.signalArguments[0][0], "webbrowser-app")
545+ compare(stageSaver.signalArguments[0][1], data.stage)
546+ }
547+
548+ function test_loadSideStageByDraggingFromMainStage() {
514549 sideStage.showNow();
515550 var webbrowserSurfaceId = topSurfaceList.nextId;
516551 webbrowserCheckBox.checked = true;
@@ -538,7 +573,7 @@ Rectangle {
538573 tryCompare(appDelegate, "stage", ApplicationInfoInterface.SideStage);
539574 }
540575
541− function test_unloadSideStageByDragginFromStageStage() {
576+ function test_unloadSideStageByDraggingFromStageStage() {
542577 sideStage.showNow();
543578 WindowStateStorage.saveStage(webbrowserCheckBox.appId, ApplicationInfoInterface.SideStage)
544579 var webbrowserSurfaceId = topSurfaceList.nextId;
@@ -690,5 +725,34 @@ Rectangle {
690725 // only unity8-dash surface is left
691726 compare(topSurfaceList.count, 1);
692727 }
728+
729+ function test_draggingSurfaceKeepsSurfaceFocus() {
730+ var webbrowserSurfaceId = topSurfaceList.nextId;
731+ webbrowserCheckBox.checked = true;
732+ waitUntilAppSurfaceShowsUp(webbrowserSurfaceId);
733+
734+ var appDelegate = findChild(tabletStage, "spreadDelegate_" + webbrowserSurfaceId);
735+ verify(appDelegate);
736+ compare(appDelegate.stage, ApplicationInfoInterface.MainStage);
737+
738+ tryCompare(appDelegate.surface, "activeFocus", true);
739+
740+ var pos = tabletStage.width - sideStage.width - (tabletStage.width - sideStage.width) / 2;
741+ var end_pos = tabletStage.width - sideStage.width / 2;
742+
743+ multiTouchDragUntil([0,1,2],
744+ tabletStage,
745+ pos,
746+ tabletStage.height / 2,
747+ units.gu(3),
748+ 0,
749+ function() {
750+ pos += units.gu(3);
751+ return sideStage.shown && !sideStage.showAnimation.running &&
752+ pos >= end_pos;
753+ });
754+
755+ tryCompare(appDelegate.surface, "activeFocus", true);
756+ }
693757 }
694758}