webengine/widgetengine/src/WidgetFuncs.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:  Implemetation of JSWidgetFunc
       
    15 *
       
    16 */
       
    17 #include "WidgetFuncs.h"
       
    18 #include "Widget.h"
       
    19 #include "WidgetCallbacks.h"
       
    20 #include "WidgetEventHandler.h"
       
    21 
       
    22 #include <interpreter.h>
       
    23 
       
    24 const int INTBUFSIZE = 256;
       
    25 
       
    26 // ============================ MEMBER FUNCTIONS ===============================
       
    27 using namespace KJS;
       
    28 
       
    29 
       
    30 // ----------------------------------------------------------------------------
       
    31 // JSWidgetFunc::JSWidgetFunc
       
    32 //
       
    33 //
       
    34 //
       
    35 // ----------------------------------------------------------------------------
       
    36 JSWidgetFunc::JSWidgetFunc(ExecState* exec, int fType,
       
    37                         MJSWidgetCallbacks* aWidgetCallbacks) : 
       
    38                         JSObject(exec->lexicalInterpreter()->builtinObjectPrototype()), funcType(fType),                        
       
    39                         m_callbacks(aWidgetCallbacks)
       
    40 {
       
    41 }
       
    42 
       
    43 // ----------------------------------------------------------------------------
       
    44 // JSWidgetFunc::~JSWidgetFunc
       
    45 //
       
    46 //
       
    47 //
       
    48 // ----------------------------------------------------------------------------
       
    49 JSWidgetFunc::~JSWidgetFunc()
       
    50 {
       
    51 }
       
    52 
       
    53 // ----------------------------------------------------------------------------
       
    54 // JSWidgetFunc::implementsCall
       
    55 //
       
    56 //
       
    57 //
       
    58 // ----------------------------------------------------------------------------
       
    59 bool JSWidgetFunc::implementsCall() const
       
    60 {
       
    61     return true;
       
    62 }
       
    63 
       
    64 // ----------------------------------------------------------------------------
       
    65 // JSWidgetFunc::call
       
    66 //
       
    67 //
       
    68 //
       
    69 // ----------------------------------------------------------------------------
       
    70 
       
    71 JSValue* JSWidgetFunc::callAsFunction(ExecState *exec, JSObject *thisObj, const List &args)
       
    72 {
       
    73 
       
    74     switch (funcType) {
       
    75         case openApplication: {
       
    76             if ( args[0]->type() == NumberType &&
       
    77                  args[0]->toString(exec).size() > 0 ) {
       
    78                 
       
    79                 TPtrC tstrParam(KNullDesC);
       
    80                 if ( !args[1]->isNull() && ( args[1]->type() == StringType ) ) {
       
    81                     tstrParam.Set((const TUint16 *)args[1]->toString(exec).data(), args[1]->toString(exec).size());
       
    82                 }
       
    83                 
       
    84                 m_callbacks->openApplication(TUid::Uid(args[0]->toInt32(exec)),tstrParam);
       
    85             }
       
    86         break;
       
    87         }
       
    88         case openURL: {
       
    89             if ( args[0]->type() == StringType &&
       
    90                  args[0]->toString(exec).size() > 0 ) {
       
    91                 TPtrC tstrUrl((const TUint16 *)args[0]->toString(exec).data(), args[0]->toString(exec).size());
       
    92                 m_callbacks->openUrl(tstrUrl);
       
    93             }
       
    94         break;
       
    95         }
       
    96         case preferenceForKey: {
       
    97             //the key must be a string or number type
       
    98             if ( !args[0]->isNull() &&
       
    99                 (args[0]->type() == StringType || args[0]->type() == NumberType) &&
       
   100                 args[0]->toString(exec).size() >= 0 ) {
       
   101                 
       
   102                 TPtrC tstrKey(KNullDesC);
       
   103                 TPtrC tstrValue(KNullDesC);
       
   104                 TInt retCode = KErrNone;
       
   105 
       
   106                 if ( args[0]->type() == NumberType ) {
       
   107                     TBuf<INTBUFSIZE> intKey;
       
   108                     intKey.Num( args[0]->toNumber(exec) );
       
   109                     retCode = m_callbacks->preferenceForKey(intKey,tstrValue);
       
   110                 }
       
   111                 else {
       
   112                     tstrKey.Set((const TUint16 *)args[0]->toString(exec).data(),args[0]->toString(exec).size());
       
   113                     retCode = m_callbacks->preferenceForKey(tstrKey,tstrValue);
       
   114                 }
       
   115 
       
   116 
       
   117                 if (retCode == KErrNone) {
       
   118                     return jsString(UString((const UChar *)tstrValue.Ptr(),tstrValue.Length()));
       
   119                 }
       
   120 
       
   121         }
       
   122         break;
       
   123         }
       
   124         case prepareForTransition: {
       
   125             
       
   126             if (  args[0]->type() == StringType && args[0]->toString(exec).size() > 0 ) {
       
   127                 TPtrC tstrTrans((const TUint16 *)args[0]->toString(exec).data(), args[0]->toString(exec).size());
       
   128                 m_callbacks->prepareForTransition(tstrTrans);
       
   129             }
       
   130         break;
       
   131         }
       
   132         case performTransition: {
       
   133             m_callbacks->performTransition();
       
   134         break;
       
   135         }
       
   136         case setPreferenceForKey: {
       
   137                 
       
   138             if ( !args[1]->isNull() && 
       
   139                     args[1]->toString(exec).size() >= 0 ) {
       
   140                 
       
   141                 TPtrC tstrValue( KNullDesC );
       
   142                 TPtrC tstrKey( KNullDesC );
       
   143 
       
   144                 TBuf<INTBUFSIZE> intKey;
       
   145                 TBuf<INTBUFSIZE> intVal;
       
   146 
       
   147                 if ( args[1]->type() == NumberType ) {
       
   148                     intKey.Num( args[1]->toNumber(exec) );
       
   149                     tstrKey.Set( intKey );
       
   150                 }
       
   151                 else {
       
   152                     tstrKey.Set((const TUint16 *)args[1]->toString(exec).data(), args[1]->toString(exec).size());
       
   153                 }
       
   154 
       
   155                 if ( args[0]->isNull() ) {
       
   156                     m_callbacks->removePreferenceForKey(tstrKey,tstrValue);
       
   157                 }
       
   158                 else if ( args[0]->type() == NumberType ) {
       
   159                     intVal.Num( args[0]->toNumber(exec) );
       
   160                     tstrValue.Set( intVal );
       
   161 
       
   162                     m_callbacks->setPreferenceForKey(tstrKey,tstrValue);
       
   163                 }
       
   164                 else if ( args[0]->toString(exec).size() >= 0 ) {
       
   165                     tstrValue.Set((const TUint16 *)args[0]->toString(exec).data(), args[0]->toString(exec).size());
       
   166 
       
   167                     m_callbacks->setPreferenceForKey(tstrKey,tstrValue);
       
   168                 }
       
   169             }
       
   170         break;
       
   171         }
       
   172         case setNavigationMode: {
       
   173             if ( args[0]->type() == BooleanType ) {
       
   174                 m_callbacks->setNavigationEnabled(args[0]->toBoolean(exec));
       
   175             }
       
   176         break;
       
   177         }
       
   178         case setDisplayLandscape: {
       
   179             m_callbacks->setDisplayLandscape();
       
   180         break;
       
   181         }
       
   182         case setDisplayPortrait: {
       
   183             m_callbacks->setDisplayPortrait();
       
   184         break;
       
   185         }
       
   186         default:
       
   187         break;
       
   188     }
       
   189             
       
   190     return jsUndefined();
       
   191 }
       
   192