116
|
1 |
/*
|
|
2 |
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include "tsbackstepping.h"
|
|
19 |
|
|
20 |
#include <w32std.h>// key event
|
|
21 |
#include <apgwgnam.h>// for CApaWindowGroupName
|
|
22 |
#include <apgtask.h>
|
|
23 |
#include <coedef.h>
|
|
24 |
#include <e32property.h>
|
|
25 |
#include <e32debug.h>
|
|
26 |
|
|
27 |
#include <homescreendomainpskeys.h>
|
|
28 |
#include <afactivitylauncher.h>
|
|
29 |
|
|
30 |
#include "tsbacksteppingfilter.h"
|
125
|
31 |
#include "tsrunningapp.h"
|
|
32 |
#include "tsrunningappstorage.h"
|
|
33 |
#include "tsresourcemanager.h"
|
119
|
34 |
/**
|
|
35 |
* String to switch hsapplication to IDLE state using activity framework
|
|
36 |
*/
|
116
|
37 |
_LIT(KHsActivactionUri, "appto://20022F35?activityname=HsIdleView&activityinbackground=true");
|
|
38 |
|
|
39 |
// -----------------------------------------------------------------------------
|
|
40 |
/**
|
119
|
41 |
* Symbian two-phases constructor. Allocate create and initialize backstepping engine
|
|
42 |
* Instance is pushed int cleanup stack.
|
|
43 |
* @param aMonitor - window group changes monitor
|
|
44 |
* @return address to backstepping engine
|
116
|
45 |
*/
|
|
46 |
CTsBackstepping* CTsBackstepping::NewL( MTsWindowGroupsMonitor& aMonitor )
|
|
47 |
{
|
|
48 |
CTsBackstepping* self = CTsBackstepping::NewLC( aMonitor );
|
|
49 |
CleanupStack::Pop( self );
|
|
50 |
return self;
|
|
51 |
}
|
|
52 |
|
|
53 |
// -----------------------------------------------------------------------------
|
|
54 |
/**
|
119
|
55 |
* Symbian two-phases constructor. Allocate create and initialize backstepping engine
|
|
56 |
* @param aMonitor - window group changes monitor
|
|
57 |
* @return address to backstepping engine
|
116
|
58 |
*/
|
|
59 |
CTsBackstepping* CTsBackstepping::NewLC( MTsWindowGroupsMonitor& aMonitor )
|
|
60 |
{
|
|
61 |
CTsBackstepping* self = new (ELeave) CTsBackstepping( aMonitor );
|
|
62 |
CleanupStack::PushL( self );
|
|
63 |
self->ConstructL();
|
|
64 |
return self;
|
|
65 |
}
|
|
66 |
|
|
67 |
// -----------------------------------------------------------------------------
|
|
68 |
/**
|
119
|
69 |
* Constructor.
|
|
70 |
* @param aMonitor - window group changes monitor
|
116
|
71 |
*/
|
|
72 |
CTsBackstepping::CTsBackstepping( MTsWindowGroupsMonitor &aMonitor )
|
|
73 |
:
|
125
|
74 |
CTsWindowGroupsObserverBase( aMonitor ), iHsWasFirst(ETrue)
|
116
|
75 |
{
|
|
76 |
}
|
|
77 |
|
|
78 |
// -----------------------------------------------------------------------------
|
|
79 |
/**
|
|
80 |
* CTsBackstepping::~CTsBackstepping
|
|
81 |
* deconstructor
|
|
82 |
*/
|
|
83 |
CTsBackstepping::~CTsBackstepping()
|
|
84 |
{
|
|
85 |
delete iFilter;
|
|
86 |
}
|
|
87 |
|
|
88 |
// -----------------------------------------------------------------------------
|
|
89 |
/**
|
119
|
90 |
* Symbian second-phase constructor.
|
|
91 |
* Subscribe to window group monitor events (using BaseConstructL) and allocate
|
|
92 |
* filtering list
|
116
|
93 |
*/
|
|
94 |
void CTsBackstepping::ConstructL ()
|
|
95 |
{
|
|
96 |
BaseConstructL();
|
|
97 |
iFilter = CTsBacksteppingFilter::NewL();
|
|
98 |
}
|
|
99 |
|
|
100 |
// -----------------------------------------------------------------------------
|
119
|
101 |
/**
|
|
102 |
* Analyzes window stack and move homescreen to proper position
|
|
103 |
* Interface implementation.
|
|
104 |
* @see MTsWindowGroupsObserver::HandleWindowGroupChanged
|
116
|
105 |
*/
|
|
106 |
void CTsBackstepping::HandleWindowGroupChanged(
|
119
|
107 |
MTsResourceManager &aResources,
|
|
108 |
const MTsRunningApplicationStorage& aStorage )
|
|
109 |
|
116
|
110 |
{
|
|
111 |
RDebug::Print(_L("[Backstepping] started"));
|
119
|
112 |
TRAP_IGNORE( HandleWindowGroupChangedL( aResources, aStorage ) );
|
116
|
113 |
RDebug::Print(_L("[Backstepping] finished"));
|
|
114 |
}
|
|
115 |
|
|
116 |
// -----------------------------------------------------------------------------
|
|
117 |
/**
|
|
118 |
* Analyzes window stack and move homescreen to proper position
|
119
|
119 |
* @see MTsWindowGroupsObserver::HandleWindowGroupChanged from param info
|
116
|
120 |
*/
|
|
121 |
void CTsBackstepping::HandleWindowGroupChangedL(
|
119
|
122 |
MTsResourceManager &aResources,
|
|
123 |
const MTsRunningApplicationStorage& aStorage )
|
116
|
124 |
{
|
|
125 |
// calculate the desired position of Homescreen
|
119
|
126 |
const TInt currentHsOffset( HomescreenOffsetL( aStorage ) );
|
116
|
127 |
TInt optimalOffset(1);
|
|
128 |
TInt targetHsOffset(currentHsOffset);
|
119
|
129 |
TBool isFirst(ETrue);
|
116
|
130 |
for( TInt offset(0); offset < currentHsOffset; ++offset )
|
|
131 |
{
|
119
|
132 |
RDebug::Print( _L("[Backstepping] application: %08x"),
|
|
133 |
aStorage[offset].UidL().iUid );
|
|
134 |
if( TUid::Null() != aStorage[offset].UidL() )
|
116
|
135 |
{
|
119
|
136 |
isFirst = EFalse;
|
|
137 |
if( aStorage[offset].IsEmbeded())
|
116
|
138 |
{
|
119
|
139 |
targetHsOffset = aStorage.ParentIndex(aStorage[offset])+ 1;
|
116
|
140 |
}
|
119
|
141 |
else if (!iFilter->isBlocked( aStorage[offset].UidL() ))
|
116
|
142 |
{
|
|
143 |
if(offset + 1 < currentHsOffset &&
|
119
|
144 |
aStorage[offset+1].UidL() == TUid::Null() )
|
116
|
145 |
{
|
|
146 |
++optimalOffset;
|
|
147 |
}
|
|
148 |
targetHsOffset = optimalOffset;
|
|
149 |
}
|
|
150 |
break;
|
|
151 |
}
|
|
152 |
else
|
|
153 |
{
|
|
154 |
++optimalOffset;
|
|
155 |
}
|
|
156 |
}
|
119
|
157 |
SwitchToIdleStateL(aResources, isFirst);
|
116
|
158 |
// change windows order if necessary
|
|
159 |
if(targetHsOffset != currentHsOffset)
|
|
160 |
{
|
|
161 |
RDebug::Print(_L("[Backstepping] about to change window groups order"));
|
119
|
162 |
aResources.WsSession().SetWindowGroupOrdinalPosition(
|
|
163 |
aStorage[currentHsOffset].WindowGroupId(),
|
|
164 |
targetHsOffset );
|
116
|
165 |
}
|
|
166 |
}
|
|
167 |
|
|
168 |
// -----------------------------------------------------------------------------
|
|
169 |
/**
|
119
|
170 |
* Find and return current position of hsapplication on window server stack
|
|
171 |
* @param aStorage - storage with running app info
|
|
172 |
* @return position of hsapplication on window server stack
|
116
|
173 |
*/
|
|
174 |
TInt CTsBackstepping::HomescreenOffsetL(
|
119
|
175 |
const MTsRunningApplicationStorage& aStorage ) const
|
116
|
176 |
{
|
|
177 |
TInt offset( KErrNotFound );
|
119
|
178 |
for( TInt iter(0); KErrNotFound == offset && iter < aStorage.Count(); ++iter )
|
116
|
179 |
{
|
119
|
180 |
if( KHsCategoryUid == aStorage[iter].UidL() )
|
116
|
181 |
{
|
|
182 |
offset = iter;
|
|
183 |
}
|
|
184 |
}
|
|
185 |
User::LeaveIfError( offset );
|
|
186 |
return offset;
|
|
187 |
}
|
|
188 |
|
|
189 |
// -----------------------------------------------------------------------------
|
119
|
190 |
/**
|
|
191 |
* Change hsapplication state to IDLE if moves to background
|
|
192 |
* @param aResources - OS resources manager
|
|
193 |
* @param aIsFrst - flag to inform if hsapplication is in foreground
|
116
|
194 |
*/
|
119
|
195 |
void CTsBackstepping::SwitchToIdleStateL(MTsResourceManager& aResources,
|
|
196 |
TBool aIsFirst)
|
116
|
197 |
{
|
119
|
198 |
// switch Homescreen to Idle state if Homescreen is not in foreground and is in different state
|
|
199 |
if( iHsWasFirst && !aIsFirst )
|
116
|
200 |
{
|
119
|
201 |
TInt hsState( EHomeScreenIdleState );
|
|
202 |
User::LeaveIfError(RProperty::Get( KHsCategoryUid,
|
|
203 |
KHsCategoryStateKey,
|
|
204 |
hsState ) );
|
|
205 |
if(!(hsState & EHomeScreenWidgetViewActive ) )
|
116
|
206 |
{
|
119
|
207 |
RDebug::Print(_L("[Backstepping] about to switch HS activity"));
|
|
208 |
CAfActivityLauncher *activityEnabler =
|
|
209 |
CAfActivityLauncher::NewLC( aResources.ApaSession(),
|
|
210 |
aResources.WsSession() );
|
|
211 |
activityEnabler->launchActivityL( KHsActivactionUri );
|
|
212 |
CleanupStack::PopAndDestroy( activityEnabler );
|
116
|
213 |
}
|
|
214 |
}
|
119
|
215 |
iHsWasFirst = aIsFirst;
|
116
|
216 |
}
|
|
217 |
|
|
218 |
// end of file
|