webengine/widgetengine/src/WidgetClient.cpp
changeset 0 dd21522fd290
child 13 10e98eab6f85
equal deleted inserted replaced
-1:000000000000 0:dd21522fd290
       
     1 /*
       
     2 * Copyright (c) 2006 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 the License "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:  This class represents the Widget Extension object
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include <e32std.h>
       
    20 #include <eikenv.h>
       
    21 #include <apgcli.h>
       
    22 #include <apgtask.h>
       
    23 #include <browserlauncher.h>
       
    24 #include <widgetmenu.rsg>
       
    25 #include <avkon.hrh>
       
    26 
       
    27 #include "WidgetClient.h"
       
    28 #include "Widget.h"
       
    29 #include "Renderer.h"
       
    30 #include "Preferences.h"
       
    31 
       
    32 
       
    33 // EXTERNAL DATA STRUCTURES
       
    34 
       
    35 // EXTERNAL FUNCTION PROTOTYPES
       
    36 
       
    37 // CONSTANTS
       
    38 
       
    39 // MACROS
       
    40 
       
    41 // LOCAL CONSTANTS AND MACROS
       
    42 
       
    43 const TInt KWebBrowserUid = 0x10008D39;
       
    44 
       
    45 // MODULE DATA STRUCTURES
       
    46 
       
    47 // LOCAL FUNCTION PROTOTYPES
       
    48 
       
    49 
       
    50 // ----------------------------------------------------------------------------
       
    51 // CWidgetClient::NewL
       
    52 //
       
    53 //
       
    54 //
       
    55 // ----------------------------------------------------------------------------
       
    56 //
       
    57 CWidgetClient* CWidgetClient::NewL(MWidgetCallback& aWidgetCallback, 
       
    58                                   MWidgetEngineCallbacks& aWidgetEngineCallback, 
       
    59                                   WidgetPreferences* preferences)
       
    60 {
       
    61     CWidgetClient* self = new ( ELeave ) CWidgetClient(aWidgetCallback, aWidgetEngineCallback, preferences);
       
    62     CleanupStack::PushL( self );
       
    63     self->ConstructL(aWidgetEngineCallback);
       
    64     CleanupStack::Pop();
       
    65     return self;
       
    66 }
       
    67 
       
    68 // ----------------------------------------------------------------------------
       
    69 // CWidgetClient::CWidgetClient
       
    70 //
       
    71 //
       
    72 //
       
    73 // ----------------------------------------------------------------------------
       
    74 //
       
    75 CWidgetClient::CWidgetClient(MWidgetCallback& aWidgetCallback, 
       
    76                              MWidgetEngineCallbacks& aWidgetEngineCallback, 
       
    77                              WidgetPreferences* preferences) : 
       
    78                                                             m_preferences (preferences), 
       
    79                                                             m_renderer(0), 
       
    80                                                             m_widgetcallback( &aWidgetCallback ), 
       
    81                                                             m_widgetenginecallback(&aWidgetEngineCallback),
       
    82                                                             m_jswidget(0)
       
    83 {
       
    84 }
       
    85 
       
    86 // ----------------------------------------------------------------------------
       
    87 // CWidgetClient::~CWidgetClient
       
    88 //
       
    89 //
       
    90 //
       
    91 // ----------------------------------------------------------------------------
       
    92 //
       
    93 CWidgetClient::~CWidgetClient()
       
    94 {    
       
    95     if (m_jswidget) {
       
    96         KJS::Collector::unprotect(m_jswidget);        
       
    97     }
       
    98     
       
    99     delete m_renderer;
       
   100 }
       
   101 
       
   102 
       
   103 // ----------------------------------------------------------------------------
       
   104 // CWidgetClient::ConstructL
       
   105 //
       
   106 //
       
   107 //
       
   108 // ----------------------------------------------------------------------------
       
   109 //
       
   110 void CWidgetClient::ConstructL(MWidgetEngineCallbacks& aWidgetEngineCallback)
       
   111 {    
       
   112     m_jswidget = new KJS::JSWidget(this);     
       
   113     m_renderer = new (ELeave) WidgetRenderer(aWidgetEngineCallback);    
       
   114     KJS::Collector::protect(m_jswidget);
       
   115 }
       
   116 
       
   117 
       
   118 // ----------------------------------------------------------------------------
       
   119 // CWidgetClient::OnShowSelected
       
   120 //
       
   121 //
       
   122 //
       
   123 // ----------------------------------------------------------------------------
       
   124 //
       
   125 void CWidgetClient::onShowSelected()
       
   126 {
       
   127     if (m_jswidget) {
       
   128         m_jswidget->setVisibility(true);        
       
   129     }
       
   130 }
       
   131 
       
   132 
       
   133 // ----------------------------------------------------------------------------
       
   134 // CWidgetClient::OnHideSelected
       
   135 //
       
   136 //
       
   137 //
       
   138 // ----------------------------------------------------------------------------
       
   139 //
       
   140 void CWidgetClient::onHideSelected()
       
   141 {
       
   142     if (m_jswidget) {
       
   143         m_jswidget->setVisibility(false);        
       
   144     }    
       
   145 }
       
   146 
       
   147 // ----------------------------------------------------------------------------
       
   148 // CWidgetClient::OnExitCalled
       
   149 //
       
   150 //
       
   151 //
       
   152 // ----------------------------------------------------------------------------
       
   153 //
       
   154 void CWidgetClient::onExitCalled()
       
   155 {
       
   156     if (m_jswidget) {
       
   157         m_jswidget->handleExit();        
       
   158     }    
       
   159 }
       
   160 
       
   161 ////////////////////////////////////////////////////////////////////////////////
       
   162 // From MWidgetExtension
       
   163 // -----------------------------------------------------------------------------
       
   164 // CWidgetClient::HandleCommandL
       
   165 //
       
   166 //
       
   167 //
       
   168 // -----------------------------------------------------------------------------
       
   169 //
       
   170 TBool CWidgetClient::HandleCommandL( TInt aCommandId )
       
   171 {
       
   172     TInt cmnd(aCommandId - (TInt)TBrCtlDefs::ECommandIdBase);
       
   173     
       
   174     if ( cmnd == TBrCtlDefs::ECommandAppForeground ) {
       
   175         onShowSelected();
       
   176         return ETrue;
       
   177     }
       
   178     if ( cmnd == TBrCtlDefs::ECommandAppBackground ) {
       
   179         onHideSelected();
       
   180         return ETrue;
       
   181     }
       
   182     if ((aCommandId == EEikCmdExit) || (aCommandId == EAknCmdExit) || (aCommandId == EAknSoftkeyExit)) {
       
   183         onExitCalled();
       
   184     }
       
   185 
       
   186     return EFalse;
       
   187 }
       
   188 
       
   189 // From MWidgetCallbacks
       
   190 // ----------------------------------------------------------------------------
       
   191 // CWidgetClient::launchApplicationL
       
   192 //
       
   193 //
       
   194 //
       
   195 // ----------------------------------------------------------------------------
       
   196 //
       
   197 void CWidgetClient::launchApplicationL(const TUid& aUid, const TDesC& aParam)
       
   198 {
       
   199     RApaLsSession apaLsSession;
       
   200     TApaTaskList taskList(CEikonEnv::Static()->WsSession());
       
   201     TApaTask task = taskList.FindApp(aUid);
       
   202 
       
   203     if ( task.Exists() ) {
       
   204     
       
   205         task.BringToForeground();
       
   206         if ( aParam.Length() > 0 ) {
       
   207             HBufC8* param8 = HBufC8::NewLC( aParam.Length() );
       
   208             param8->Des().Append( aParam );
       
   209             task.SendMessage( TUid::Uid( 0 ), *param8 );
       
   210             CleanupStack::PopAndDestroy( param8 );
       
   211         }
       
   212     }
       
   213     else {
       
   214     
       
   215         TInt eConnect = KErrNone;
       
   216         if ( !apaLsSession.Handle() ) {
       
   217             eConnect = apaLsSession.Connect();
       
   218         }
       
   219 
       
   220         if ( eConnect == KErrNone ) {
       
   221             TThreadId threadId;
       
   222             apaLsSession.StartDocument( aParam, aUid, threadId );
       
   223             apaLsSession.Close();
       
   224         }
       
   225     }
       
   226 
       
   227 }
       
   228 
       
   229 // ----------------------------------------------------------------------------
       
   230 // CWidgetClient::openApplication
       
   231 //
       
   232 //
       
   233 //
       
   234 // ----------------------------------------------------------------------------
       
   235 //
       
   236 void CWidgetClient::openApplication(const TUid& aAppUid, const TDesC& aParam)
       
   237 {
       
   238     TRAP_IGNORE( launchApplicationL( aAppUid, aParam ) );
       
   239 }
       
   240 
       
   241 // ----------------------------------------------------------------------------
       
   242 // CWidgetClient::openUrl
       
   243 //
       
   244 //
       
   245 //
       
   246 // ----------------------------------------------------------------------------
       
   247 //
       
   248 void CWidgetClient::openUrl( const TDesC& aUrl )
       
   249 {    
       
   250     HBufC* param = HBufC::NewLC( aUrl.Length() + 2 );
       
   251     param->Des().Append( _L("4 ") );
       
   252     param->Des().Append( aUrl );
       
   253     TRAP_IGNORE( launchApplicationL( TUid::Uid( KWebBrowserUid ), *param ) );
       
   254     CleanupStack::PopAndDestroy( param );
       
   255 }
       
   256 
       
   257 // ----------------------------------------------------------------------------
       
   258 // CWidgetClient::getWidgetBundleId
       
   259 //
       
   260 //
       
   261 //
       
   262 // ----------------------------------------------------------------------------
       
   263 //
       
   264 TDesC& CWidgetClient::getWidgetBundleId()
       
   265 {            
       
   266     return m_preferences->getWidgetBundleId();    
       
   267 }
       
   268 
       
   269 
       
   270 // ----------------------------------------------------------------------------
       
   271 // CWidgetClient::setNavigationEnabled
       
   272 //
       
   273 //
       
   274 //
       
   275 // ----------------------------------------------------------------------------
       
   276 //
       
   277 void CWidgetClient::setNavigationEnabled( TBool aEnable )
       
   278 {
       
   279     m_widgetenginecallback->setTabbednavigation(!aEnable);
       
   280 }
       
   281 
       
   282 // ----------------------------------------------------------------------------
       
   283 // CWidgetClient::prepareForTransition
       
   284 //
       
   285 //
       
   286 //
       
   287 // ----------------------------------------------------------------------------
       
   288 //
       
   289 void CWidgetClient::prepareForTransition( const TDesC& aTransition )
       
   290 {    
       
   291     TRAP_IGNORE( m_renderer->prepareForTransitionL( aTransition ) );
       
   292 }
       
   293 
       
   294 // ----------------------------------------------------------------------------
       
   295 // CWidgetClient::performTransition
       
   296 //
       
   297 //
       
   298 //
       
   299 // ----------------------------------------------------------------------------
       
   300 //
       
   301 void CWidgetClient::performTransition()
       
   302 {    
       
   303     TRAP_IGNORE( m_renderer->performTransitionL() );
       
   304 }
       
   305 
       
   306 // ----------------------------------------------------------------------------
       
   307 // CWidgetClient::preferenceForKey
       
   308 //
       
   309 //
       
   310 //
       
   311 // ----------------------------------------------------------------------------
       
   312 //
       
   313 TInt CWidgetClient::preferenceForKey( const TDesC& aKey, TPtrC& aValue )
       
   314 {    
       
   315     TInt ret = KErrNotFound;
       
   316     TRAP_IGNORE( ret = m_preferences->preferenceL( aKey, aValue ) );
       
   317     return ret;
       
   318 }
       
   319 
       
   320 // ----------------------------------------------------------------------------
       
   321 // CWidgetClient::setPreferenceForKey
       
   322 //
       
   323 //
       
   324 //
       
   325 // ----------------------------------------------------------------------------
       
   326 //
       
   327 void CWidgetClient::setPreferenceForKey( const TDesC& aKey, const TDesC& aValue )
       
   328 {    
       
   329     TRAP_IGNORE( m_preferences->setPreferenceL( aKey, aValue ) );
       
   330 }
       
   331 
       
   332 // ----------------------------------------------------------------------------
       
   333 // CWidgetClient::removePreferenceForKey
       
   334 //
       
   335 //
       
   336 //
       
   337 // ----------------------------------------------------------------------------
       
   338 //
       
   339 void CWidgetClient::removePreferenceForKey( const TDesC& aKey, const TDesC& aValue )
       
   340 {    
       
   341     TRAP_IGNORE( m_preferences->removePreferenceL( aKey, aValue ) );
       
   342 }
       
   343 
       
   344 // ----------------------------------------------------------------------------
       
   345 // CWidgetClient::setDisplayLandscape
       
   346 //
       
   347 //
       
   348 //
       
   349 // ----------------------------------------------------------------------------
       
   350 //
       
   351 void CWidgetClient::setDisplayLandscape()
       
   352 {    
       
   353     m_widgetcallback->SetDisplayMode(TBrCtlDefs::EOrientationLandscape);
       
   354 }
       
   355 
       
   356 // ----------------------------------------------------------------------------
       
   357 // CWidgetClient::setDisplayPortrait
       
   358 //
       
   359 //
       
   360 //
       
   361 // ----------------------------------------------------------------------------
       
   362 //
       
   363 void CWidgetClient::setDisplayPortrait()
       
   364 {   
       
   365     m_widgetcallback->SetDisplayMode(TBrCtlDefs::EOrientationPortrait);
       
   366 }
       
   367 
       
   368 
       
   369 //END OF FILE
       
   370 
       
   371 
       
   372 
       
   373