on xenial help sign in
Save the last surface stage on stage drop. (LP: #1579003)
commit41e6820c4432237d6038288de2ce7aef160b21eb authorNick Dedekind <nick.dedekind@canonical.com> dateMon 27 Jun 2016, 18:44 (10 years ago) parent0d1c87e4cbca1b
2 files changed+123−51
qml/Stages/TabletStage.qml+7−5 tests/qmltests/Stages/tst_TabletStage.qml+116−46
qml/Stages/TabletStage.qml+7−5
@@ -624,7 +624,7 @@ AbstractStage {
624624 enabled: priv.sideStageEnabled
625625
626626 onDropped: {
627− drop.source.spreadDelegate.stage = ApplicationInfoInterface.MainStage;
627+ drop.source.spreadDelegate.saveStage(ApplicationInfoInterface.MainStage);
628628 drop.source.spreadDelegate.focus = true;
629629 }
630630 keys: "SideStage"
@@ -679,7 +679,7 @@ AbstractStage {
679679 }
680680 onDropped: {
681681 if (drop.keys == "MainStage") {
682− drop.source.spreadDelegate.stage = ApplicationInfoInterface.SideStage;
682+ drop.source.spreadDelegate.saveStage(ApplicationInfoInterface.SideStage);
683683 drop.source.spreadDelegate.focus = true;
684684 }
685685 }
@@ -810,6 +810,11 @@ AbstractStage {
810810 }
811811 }
812812
813+ function saveStage(newStage) {
814+ stage = newStage;
815+ WindowStateStorage.saveStage(application.appId, newStage);
816+ }
817+
813818 // FIXME: A regular binding doesn't update any more after closing an app.
814819 // Using a Binding for now.
815820 Binding {
@@ -843,9 +848,6 @@ AbstractStage {
843848 refreshStage();
844849 _constructing = false;
845850 }
846− Component.onDestruction: {
847− WindowStateStorage.saveStage(application.appId, stage);
848− }
849851
850852 function refreshStage() {
851853 var newStage = ApplicationInfoInterface.MainStage;
tests/qmltests/Stages/tst_TabletStage.qml+116−46
@@ -242,6 +242,48 @@ Rectangle {
242242 appWindow.width * 0.1, -appWindow.height / 2);
243243 }
244244
245+ function dragToSideStage(surfaceId) {
246+ sideStage.showNow();
247+ var targetAppDelegate = findChild(tabletStage, "spreadDelegate_" + surfaceId);
248+
249+ var pos = tabletStage.width - sideStage.width - (tabletStage.width - sideStage.width) / 2;
250+ var end_pos = tabletStage.width - sideStage.width / 2;
251+
252+ multiTouchDragUntil([0,1,2],
253+ tabletStage,
254+ pos,
255+ tabletStage.height / 2,
256+ units.gu(3),
257+ 0,
258+ function() {
259+ pos += units.gu(3);
260+ return sideStage.shown && !sideStage.showAnimation.running &&
261+ pos >= end_pos;
262+ });
263+ tryCompare(targetAppDelegate, "stage", ApplicationInfoInterface.SideStage);
264+ }
265+
266+ function dragToMainStage(surfaceId) {
267+ sideStage.showNow();
268+ var targetAppDelegate = findChild(tabletStage, "spreadDelegate_" + surfaceId);
269+ verify(targetAppDelegate);
270+
271+ var pos = tabletStage.width - sideStage.width / 2;
272+ var end_pos = tabletStage.width - sideStage.width - (tabletStage.width - sideStage.width) / 2;
273+
274+ multiTouchDragUntil([0,1,2],
275+ tabletStage,
276+ pos,
277+ tabletStage.height / 2,
278+ -units.gu(3),
279+ 0,
280+ function() {
281+ pos -= units.gu(3);
282+ return pos <= end_pos;
283+ });
284+ tryCompare(targetAppDelegate, "stage", ApplicationInfoInterface.MainStage);
285+ }
286+
245287 function test_tappingSwitchesFocusBetweenStages() {
246288 WindowStateStorage.saveStage(dialerCheckBox.appId, ApplicationInfoInterface.SideStage)
247289
@@ -519,13 +561,13 @@ Rectangle {
519561
520562 function test_applicationSavesLastStage_data() {
521563 return [
522− { tag: "MainStage", stage: ApplicationInfoInterface.MainStage},
523− { tag: "SideStage", stage: ApplicationInfoInterface.SideStage},
564+ { tag: "MainStage", fromStage: ApplicationInfoInterface.MainStage, toStage: ApplicationInfoInterface.SideStage },
565+ { tag: "SideStage", fromStage: ApplicationInfoInterface.SideStage, toStage: ApplicationInfoInterface.MainStage },
524566 ];
525567 }
526568
527569 function test_applicationSavesLastStage(data) {
528− WindowStateStorage.saveStage(webbrowserCheckBox.appId, data.stage);
570+ WindowStateStorage.saveStage(webbrowserCheckBox.appId, data.fromStage);
529571 stageSaver.clear();
530572
531573 var stagesPriv = findInvisibleChild(tabletStage, "stagesPriv");
@@ -538,11 +580,15 @@ Rectangle {
538580 webbrowserCheckBox.checked = true;
539581 waitUntilAppSurfaceShowsUp(webbrowserSurfaceId);
540582
541− webbrowserCheckBox.checked = false;
583+ if (data.toStage === ApplicationInfoInterface.SideStage) {
584+ dragToSideStage(webbrowserSurfaceId);
585+ } else {
586+ dragToMainStage(webbrowserSurfaceId);
587+ }
542588
543589 tryCompare(stageSaver, "count", 1);
544590 compare(stageSaver.signalArguments[0][0], "webbrowser-app")
545− compare(stageSaver.signalArguments[0][1], data.stage)
591+ compare(stageSaver.signalArguments[0][1], data.toStage)
546592 }
547593
548594 function test_loadSideStageByDraggingFromMainStage() {
@@ -555,20 +601,7 @@ Rectangle {
555601 verify(appDelegate);
556602 compare(appDelegate.stage, ApplicationInfoInterface.MainStage);
557603
558− var pos = tabletStage.width - sideStage.width - (tabletStage.width - sideStage.width) / 2;
559− var end_pos = tabletStage.width - sideStage.width / 2;
560−
561− multiTouchDragUntil([0,1,2],
562− tabletStage,
563− pos,
564− tabletStage.height / 2,
565− units.gu(3),
566− 0,
567− function() {
568− pos += units.gu(3);
569− return sideStage.shown && !sideStage.showAnimation.running &&
570− pos >= end_pos;
571− });
604+ dragToSideStage(webbrowserSurfaceId);
572605
573606 var spreadView = findChild(tabletStageLoader, "spreadView")
574607 tryCompare(spreadView, "surfaceDragging", false);
@@ -586,19 +619,7 @@ Rectangle {
586619 verify(appDelegate);
587620 compare(appDelegate.stage, ApplicationInfoInterface.SideStage);
588621
589− var pos = tabletStage.width - sideStage.width / 2;
590− var end_pos = tabletStage.width - sideStage.width - (tabletStage.width - sideStage.width) / 2;
591−
592− multiTouchDragUntil([0,1,2],
593− tabletStage,
594− pos,
595− tabletStage.height / 2,
596− -units.gu(3),
597− 0,
598− function() {
599− pos -= units.gu(3);
600− return pos <= end_pos;
601− });
622+ dragToMainStage(webbrowserSurfaceId);
602623
603624 var spreadView = findChild(tabletStageLoader, "spreadView")
604625 tryCompare(spreadView, "surfaceDragging", false);
@@ -741,20 +762,7 @@ Rectangle {
741762
742763 tryCompare(appDelegate.surface, "activeFocus", true);
743764
744− var pos = tabletStage.width - sideStage.width - (tabletStage.width - sideStage.width) / 2;
745− var end_pos = tabletStage.width - sideStage.width / 2;
746−
747− multiTouchDragUntil([0,1,2],
748− tabletStage,
749− pos,
750− tabletStage.height / 2,
751− units.gu(3),
752− 0,
753− function() {
754− pos += units.gu(3);
755− return sideStage.shown && !sideStage.showAnimation.running &&
756− pos >= end_pos;
757− });
765+ dragToSideStage(webbrowserSurfaceId);
758766
759767 var spreadView = findChild(tabletStageLoader, "spreadView")
760768 tryCompare(spreadView, "surfaceDragging", false);
@@ -789,5 +797,67 @@ Rectangle {
789797 tryCompare(spreadView, "surfaceDragging", false);
790798 tryCompare(appDelegate, "stage", ApplicationInfoInterface.MainStage);
791799 }
800+
801+ function test_switchStageOnRotation() {
802+ WindowStateStorage.saveStage(webbrowserCheckBox.appId, ApplicationInfoInterface.SideStage)
803+ var webbrowserSurfaceId = topSurfaceList.nextId;
804+ webbrowserCheckBox.checked = true;
805+ waitUntilAppSurfaceShowsUp(webbrowserSurfaceId);
806+
807+ var appDelegate = findChild(tabletStage, "spreadDelegate_" + webbrowserSurfaceId);
808+ verify(appDelegate);
809+ compare(appDelegate.stage, ApplicationInfoInterface.SideStage);
810+
811+ tabletStage.shellOrientation = Qt.PortraitOrientation;
812+ tryCompare(appDelegate, "stage", ApplicationInfoInterface.MainStage);
813+ }
814+
815+ function test_restoreOriginalStageOnRotation() {
816+ var webbrowserSurfaceId = topSurfaceList.nextId;
817+ webbrowserCheckBox.checked = true;
818+ waitUntilAppSurfaceShowsUp(webbrowserSurfaceId);
819+
820+ var appDelegate = findChild(tabletStage, "spreadDelegate_" + webbrowserSurfaceId);
821+ verify(appDelegate);
822+
823+ dragToSideStage(webbrowserSurfaceId);
824+
825+ // will be in sidestage now
826+ tabletStage.shellOrientation = Qt.PortraitOrientation;
827+ tryCompare(appDelegate, "stage", ApplicationInfoInterface.MainStage);
828+
829+ tabletStage.shellOrientation = Qt.LandscapeOrientation;
830+ tryCompare(appDelegate, "stage", ApplicationInfoInterface.SideStage);
831+ }
832+
833+ function test_restoreSavedStageOnCloseReopen() {
834+ var webbrowserSurfaceId = topSurfaceList.nextId;
835+ webbrowserCheckBox.checked = true;
836+ waitUntilAppSurfaceShowsUp(webbrowserSurfaceId);
837+
838+ var appDelegate = findChild(tabletStage, "spreadDelegate_" + webbrowserSurfaceId);
839+ verify(appDelegate);
840+
841+ dragToSideStage(webbrowserSurfaceId);
842+ // will be in sidestage now
843+ tabletStage.shellOrientation = Qt.PortraitOrientation;
844+ tryCompare(appDelegate, "stage", ApplicationInfoInterface.MainStage);
845+
846+ webbrowserCheckBox.checked = false;
847+ tryCompare(ApplicationManager, "count", 1);
848+
849+ // back to landscape
850+ tabletStage.shellOrientation = Qt.LandscapeOrientation;
851+
852+ webbrowserSurfaceId = topSurfaceList.nextId;
853+ webbrowserCheckBox.checked = true;
854+ waitUntilAppSurfaceShowsUp(webbrowserSurfaceId);
855+
856+ appDelegate = findChild(tabletStage, "spreadDelegate_" + webbrowserSurfaceId);
857+ verify(appDelegate);
858+ tryCompare(appDelegate, "stage", ApplicationInfoInterface.SideStage);
859+ }
860+
861+
792862 }
793863}