browserui/browser/BrowserAppSrc/BrowserShortcutKeyMap.cpp
changeset 51 48e827313edd
parent 37 481242ead638
child 53 f427d27b98d8
equal deleted inserted replaced
37:481242ead638 51:48e827313edd
     1 /*
       
     2 * Copyright (c) 2007 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:  Browser View
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include <aknutils.h>
       
    20 #include <gulicon.h>
       
    21 #include <StringLoader.h>
       
    22 #include <data_caging_path_literals.hrh>
       
    23 #include <eikbtgpc.h>
       
    24 #include <eikapp.h>
       
    25 #include <AknsUtils.h>
       
    26 #include <e32math.h>
       
    27 #include <browser.mbg>
       
    28 #include "BrowserShortcutKeyMap.h"
       
    29 #include "BrowserContentViewContainer.h"
       
    30 #include "BrowserPreferences.h"
       
    31 #include "BrowserWindowManager.h"
       
    32 #include "BrowserWindow.h"
       
    33 #include "ApiProvider.h"
       
    34 #include "BrowserUIVariant.hrh"
       
    35 #include "BrowserAppUi.h"
       
    36 #include <AknBidiTextUtils.h> 
       
    37 
       
    38 // CONSTANTS
       
    39 _LIT( KKeyMapSvgFile, "browser.mif" );
       
    40 
       
    41 // Value table for 70% Transparency
       
    42 const TInt KTransparency[256] =
       
    43     {
       
    44     0, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 7, 7, 7,
       
    45     8, 8, 8, 8, 9, 9, 9, 10, 10, 10, 11, 11, 11, 11, 12, 12, 12, 13, 13, 13,
       
    46     14, 14, 14, 14, 15, 15, 15, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 19,
       
    47     19, 19, 20, 20, 20, 20, 21, 21, 21, 22, 22, 22, 23, 23, 23, 23, 24, 24,
       
    48     24, 25, 25, 25, 26, 26, 26, 26, 27, 27, 27, 28, 28, 28, 29, 29, 29, 29,
       
    49     30, 30, 30, 31, 31, 31, 32, 32, 32, 32, 33, 33, 33, 34, 34, 34, 35, 35,
       
    50     35, 35, 36, 36, 36, 37, 37, 37, 38, 38, 38, 38, 39, 39, 39, 40, 40, 40,
       
    51     41, 41, 41, 41, 42, 42, 42, 43, 43, 43, 44, 44, 44, 44, 45, 45, 45, 46,
       
    52     46, 46, 47, 47, 47, 47, 48, 48, 48, 49, 49, 49, 50, 50, 50, 50, 51, 51,
       
    53     51, 52, 52, 52, 53, 53, 53, 53, 54, 54, 54, 55, 55, 55, 56, 56, 56, 56,
       
    54     57, 57, 57, 58, 58, 58, 59, 59, 59, 59, 60, 60, 60, 61, 61, 61, 62, 62,
       
    55     62, 62, 63, 63, 63, 64, 64, 64, 65, 65, 65, 65, 66, 66, 66, 67, 67, 67,
       
    56     68, 68, 68, 68, 69, 69, 69, 70, 70, 70, 71, 71, 71, 71, 72, 72, 72, 73,
       
    57     73, 73, 74, 74, 74, 74, 75, 75, 75, 76, 76, 76, 77, 77
       
    58     };
       
    59 
       
    60 
       
    61 // keymap is 3x4
       
    62 #define KNumCellsX 3
       
    63 #define KNumCellsY 4
       
    64 #define KNumCells  12
       
    65 
       
    66 // spacing in pixels for scroll bars
       
    67 #define KKeymapHScrollbarSize 4
       
    68 #define KKeymapVScrollbarSize 4
       
    69 
       
    70 // sizing for entire keymap (not counting scrollbar)
       
    71 // as a percentage of vertical and horizontal screen size
       
    72 #define KKeymapVSize 0.90
       
    73 #define KKeymapHSize 0.90
       
    74 
       
    75 // margins for each cell
       
    76 #define KCellTopMargin    2
       
    77 #define KCellRightMargin  5
       
    78 #define KCellBotMargin    2
       
    79 #define KCellLeftMargin   5
       
    80 
       
    81 // Create constant icon assignments for each command
       
    82 // note that this follows TShortcutsCommandDecodeEntry in BrowserPreferences.h
       
    83 
       
    84 typedef const TInt TShortcutsIconAndTextDecodeEntry[2];
       
    85 
       
    86 #define KShortcutsIconAndTextAssignmentSize 22
       
    87 #define KShortcutsIconAndTextDecodeMatrixText  0  // First entry is the Text
       
    88 #define KShortcutsIconAndTextDecodeMatrixIcon  1  // Second entry is the Icon
       
    89 
       
    90 static const TShortcutsIconAndTextDecodeEntry KShortcutsIconAndTextAssignmentMatrix[] =
       
    91 {
       
    92     /* 0   EWmlNoCmd,                       */  { R_BROWSER_KEYMAP_TEXT_NONE,               EMbmBrowserQgn_indi_browser_tb_key_map      },
       
    93     /* 1   EWmlCmdHelp,                     */  { R_BROWSER_KEYMAP_TEXT_SHOW_HELP,          EMbmBrowserQgn_indi_browser_tb_help         },
       
    94     /* 2   EWmlCmdSwitchWindow,             */  { R_BROWSER_KEYMAP_TEXT_SWITCH_WINDOW,      EMbmBrowserQgn_indi_browser_tb_switch_win   },
       
    95     /* 3   EWmlCmdSavePage,                 */  { R_BROWSER_KEYMAP_TEXT_SAVE_PAGE,          EMbmBrowserQgn_indi_browser_tb_save_page    },
       
    96     /* 4   EWmlCmdShowImages,               */  { R_BROWSER_KEYMAP_TEXT_VIEW_IMAGES,        EMbmBrowserQgn_indi_browser_tb_view_images  },
       
    97     /* 5   EWmlCmdHistory,                  */  { R_BROWSER_KEYMAP_TEXT_VISUAL_HISTORY,     EMbmBrowserQgn_indi_browser_tb_view_pages   },
       
    98     /* 6   EWmlCmdFavourites,               */  { R_BROWSER_KEYMAP_TEXT_MANAGE_BOOKMARKS,   EMbmBrowserQgn_indi_browser_tb_bm           },
       
    99     /* 7   EWmlCmdShowSubscribeList,        */  { R_BROWSER_KEYMAP_TEXT_SUBSCRIBE_TO_FEEDS, EMbmBrowserQgn_indi_browser_tb_rss          },
       
   100     /* 8   EWmlCmdRotateDisplay,            */  { R_BROWSER_KEYMAP_TEXT_ROTATE_SCREEN,      EMbmBrowserQgn_indi_browser_tb_rotate       },
       
   101     /* 9   EWmlCmdPreferences,              */  { R_BROWSER_KEYMAP_TEXT_SETTINGS,           EMbmBrowserQgn_indi_browser_tb_settings     },
       
   102     /* 10  EWmlCmdZoomOut,                  */  { R_BROWSER_KEYMAP_TEXT_ZOOM_OUT,           EMbmBrowserQgn_indi_browser_tb_zoom_out     },
       
   103     /* 11  EWmlCmdZoomIn,                   */  { R_BROWSER_KEYMAP_TEXT_ZOOM_IN,            EMbmBrowserQgn_indi_browser_tb_zoom_in      },
       
   104     /* 12  EWmlCmdLaunchHomePage,           */  { R_BROWSER_KEYMAP_TEXT_GO_TO_HOMEPAGE,     EMbmBrowserQgn_indi_browser_tb_home         },
       
   105     /* 13  EWmlCmdOneStepBack,              */  { R_BROWSER_KEYMAP_TEXT_PREVIOUS_PAGE,      EMbmBrowserQgn_indi_browser_tb_back         },
       
   106     /* 14  EWmlCmdShowMiniature,            */  { R_BROWSER_KEYMAP_TEXT_MINIATURE_SHOW,     EMbmBrowserQgn_indi_browser_tb_page         },
       
   107     /* 15  EWmlCmdReload,                   */  { R_BROWSER_KEYMAP_TEXT_RELOAD,             EMbmBrowserQgn_indi_browser_tb_reload       },
       
   108     /* 16  EWmlCmdFindKeyword,              */  { R_BROWSER_KEYMAP_TEXT_FIND_KEYWORD,       EMbmBrowserQgn_indi_browser_tb_find_kw      },
       
   109     /* 17  EWmlCmdSaveAsBookmark,           */  { R_BROWSER_KEYMAP_TEXT_SAVE_AS_BOOKMARK,   EMbmBrowserQgn_indi_browser_tb_save_bm      },
       
   110     /* 18  EWmlCmdGoToAddress,              */  { R_BROWSER_KEYMAP_TEXT_GO_TO_WEB_ADDRESS,  EMbmBrowserQgn_indi_browser_tb_goto         },
       
   111     /* 19  EWmlCmdShowToolBar,              */  { R_BROWSER_KEYMAP_TEXT_SHOW_TOOLBAR,       EMbmBrowserQgn_indi_browser_tb_tb           },
       
   112     /* 20  EWmlCmdShowShortcutKeymap,       */  { R_BROWSER_KEYMAP_TEXT_SHOW_KEYMAP,        EMbmBrowserQgn_indi_browser_tb_key_map      },
       
   113     /* 21  EWmlCmdEnterFullScreenBrowsing,  */  { R_BROWSER_KEYMAP_TEXT_FULL_SCREEN,        EMbmBrowserQgn_indi_button_exit_fs          },
       
   114 };
       
   115 
       
   116 // key assignments
       
   117 static const TInt KDialpadAssignments[] =
       
   118 {
       
   119     /*  0  */ R_BROWSER_KEYMAP_KEY0,
       
   120     /*  1  */ R_BROWSER_KEYMAP_KEY1,
       
   121     /*  2  */ R_BROWSER_KEYMAP_KEY2,
       
   122     /*  3  */ R_BROWSER_KEYMAP_KEY3,
       
   123     /*  4  */ R_BROWSER_KEYMAP_KEY4,
       
   124     /*  5  */ R_BROWSER_KEYMAP_KEY5,
       
   125     /*  6  */ R_BROWSER_KEYMAP_KEY6,
       
   126     /*  7  */ R_BROWSER_KEYMAP_KEY7,
       
   127     /*  8  */ R_BROWSER_KEYMAP_KEY8,
       
   128     /*  9  */ R_BROWSER_KEYMAP_KEY9,
       
   129     /* 10  */ R_BROWSER_KEYMAP_KEY10,
       
   130     /* 11  */ R_BROWSER_KEYMAP_KEY11
       
   131 };
       
   132 
       
   133 // ============================= LOCAL FUNCTIONS ===============================
       
   134 
       
   135 // ============================ MEMBER FUNCTIONS ===============================
       
   136 
       
   137 // -----------------------------------------------------------------------------
       
   138 // TKeymapCellData::TKeymapCellData
       
   139 // TKeymapCellData Utility Class constructor
       
   140 // -----------------------------------------------------------------------------
       
   141 
       
   142 TKeymapCellData::TKeymapCellData() :
       
   143     keyText(NULL),
       
   144     lineText(NULL),
       
   145     cmdRscId(NULL),
       
   146     keyBitmapImage(NULL),
       
   147     keyBitmapMask(NULL)
       
   148     {
       
   149     }
       
   150 
       
   151 
       
   152 // -----------------------------------------------------------------------------
       
   153 // TKeymapCellData::TKeymapCellData
       
   154 // TKeymapCellData Utility Class destructor
       
   155 // -----------------------------------------------------------------------------
       
   156 TKeymapCellData::~TKeymapCellData()
       
   157     {
       
   158     if(keyText) delete keyText;
       
   159     if(lineText) delete lineText;
       
   160     if(keyBitmapImage) delete keyBitmapImage;
       
   161     if(keyBitmapMask) delete keyBitmapMask;
       
   162     }
       
   163 
       
   164 // -----------------------------------------------------------------------------
       
   165 // CBrowserShortcutKeyMap::NewL
       
   166 // The two-phase Symbian constructor
       
   167 // -----------------------------------------------------------------------------
       
   168 //
       
   169 CBrowserShortcutKeyMap* CBrowserShortcutKeyMap::NewL( CBrowserContentViewContainer* aContentViewContainer, MApiProvider& aApiProvider )
       
   170     {
       
   171     CBrowserShortcutKeyMap* self = new (ELeave) CBrowserShortcutKeyMap( aContentViewContainer, aApiProvider );
       
   172     CleanupStack::PushL(self);
       
   173     self->ConstructL();
       
   174     CleanupStack::Pop(); //self
       
   175     return self;
       
   176     }
       
   177 
       
   178 
       
   179 
       
   180 // -----------------------------------------------------------------------------
       
   181 // Destructor
       
   182 // -----------------------------------------------------------------------------
       
   183 CBrowserShortcutKeyMap::~CBrowserShortcutKeyMap()
       
   184     {
       
   185     // Close out array and delete data members
       
   186     iCellData.Close();
       
   187 
       
   188     // cleanup svg mbm file name
       
   189     if(iSvgMbmFile)
       
   190         {
       
   191         delete iSvgMbmFile;
       
   192         iSvgMbmFile = NULL;
       
   193         }
       
   194 
       
   195     // Cleanup Sprite data
       
   196     iSprite.Close();
       
   197     if(iSpriteBitmapDevice)
       
   198         {
       
   199         delete iSpriteBitmapDevice;
       
   200         iSpriteBitmapDevice = NULL;
       
   201         }
       
   202     if(iSpriteBitmapContext)
       
   203         {
       
   204         delete iSpriteBitmapContext;
       
   205         iSpriteBitmapContext = NULL;
       
   206         }
       
   207     if(iSpriteBitmap)
       
   208         {
       
   209         delete iSpriteBitmap;
       
   210         iSpriteBitmap = NULL;
       
   211         }
       
   212 
       
   213     if(iSpriteMaskBitmapDevice)
       
   214         {
       
   215         delete iSpriteMaskBitmapDevice;
       
   216         iSpriteMaskBitmapDevice = NULL;
       
   217         }
       
   218     if(iSpriteMaskBitmapContext)
       
   219         {
       
   220         delete iSpriteMaskBitmapContext;
       
   221         iSpriteMaskBitmapContext = NULL;
       
   222         }
       
   223     if(iSpriteMaskBitmap)
       
   224         {
       
   225         delete iSpriteMaskBitmap;
       
   226         iSpriteMaskBitmap = NULL;
       
   227         }
       
   228 
       
   229     }
       
   230 
       
   231 
       
   232 
       
   233 // -----------------------------------------------------------------------------
       
   234 // CBrowserShortcutKeyMap::CBrowserShortcutKeyMap
       
   235 // C++ default constructor can NOT contain any code, that
       
   236 // might leave.
       
   237 // -----------------------------------------------------------------------------
       
   238 //
       
   239 CBrowserShortcutKeyMap::CBrowserShortcutKeyMap( CBrowserContentViewContainer* aContentViewContainer, MApiProvider& aApiProvider )
       
   240     : iContentViewContainer( aContentViewContainer ), iApiProvider( aApiProvider )
       
   241     {
       
   242     }
       
   243 
       
   244 
       
   245 
       
   246 // -----------------------------------------------------------------------------
       
   247 // CBrowserShortcutKeyMap::ConstructL
       
   248 // The constructor that can contain code that might leave.
       
   249 // -----------------------------------------------------------------------------
       
   250 //
       
   251 void CBrowserShortcutKeyMap::ConstructL()
       
   252     {
       
   253     //LoadResourceFileL();
       
   254     iSvgMbmFile = GetCannedImageDirL();
       
   255     iSvgMbmFile->Des().Append( KKeyMapSvgFile );
       
   256 
       
   257     InitKeymap();
       
   258     CreateBitmapAndContextL();
       
   259     ConstructSprite();
       
   260     }
       
   261 
       
   262 
       
   263 
       
   264 // -----------------------------------------------------------------------------
       
   265 // CBrowserShortcutKeyMap::InitKeymap
       
   266 // Initialize Keymap properties
       
   267 // -----------------------------------------------------------------------------
       
   268 //
       
   269 void CBrowserShortcutKeyMap::InitKeymap()
       
   270     {
       
   271     // derive keymap's size from the container's size
       
   272     iTargetRect = iContentViewContainer->Rect();
       
   273 
       
   274     // resize it to account for scrollbar width/height
       
   275     iTargetRect.Resize(-TSize(KKeymapHScrollbarSize,KKeymapVScrollbarSize));
       
   276     
       
   277     TBool landscape = iTargetRect.Size().iWidth > iTargetRect.Size().iHeight ; 
       
   278 
       
   279     //
       
   280     // derive shrink amounts based on keymap size constants and shrink the rect
       
   281     //
       
   282     TInt newHeight = (KKeymapVSize * iTargetRect.Size().iHeight);
       
   283     TInt newWidth  = (KKeymapHSize * iTargetRect.Size().iWidth);
       
   284     
       
   285     if(newWidth > KKeymapHSize * iTargetRect.Size().iWidth)
       
   286         {
       
   287         newWidth = (KKeymapHSize * iTargetRect.Size().iWidth);
       
   288         }
       
   289 
       
   290     // shrink the height and width slightly
       
   291     // as necessary to be evenly divisible by the rows/cols later on
       
   292     TReal remainder;
       
   293     TInt result;
       
   294     result = Math::Mod(remainder,newWidth,KNumCellsX);
       
   295     if((result == KErrNone) && (remainder != 0))
       
   296         {
       
   297         newWidth -= remainder;
       
   298         }
       
   299     result = Math::Mod(remainder,newHeight,KNumCellsY);
       
   300     if((result == KErrNone) && (remainder != 0))
       
   301         {
       
   302         newHeight -= remainder;
       
   303         }
       
   304     TInt hShrink = (iTargetRect.Size().iWidth - newWidth)/2;
       
   305     TInt vShrink = (iTargetRect.Size().iHeight - newHeight)/2;
       
   306     iTargetRect.Shrink(TSize(hShrink,vShrink));
       
   307 
       
   308     // Set font types
       
   309     iLineFont = LatinPlain12();
       
   310     
       
   311     if (landscape)
       
   312         { // in landscape need to shrink the font or else it gets clipped
       
   313         iKeyFont = LatinBold13();
       
   314         }
       
   315     else
       
   316         {
       
   317         iKeyFont = LatinBold16();
       
   318         }
       
   319 
       
   320     // init cell data
       
   321     InitCellDataL();
       
   322     }
       
   323 
       
   324 
       
   325 
       
   326 // -----------------------------------------------------------------------------
       
   327 // CBrowserShortcutKeyMap::InitCellDataL
       
   328 // Initialize Keymap data kept for each cell of the map
       
   329 // -----------------------------------------------------------------------------
       
   330 
       
   331 void CBrowserShortcutKeyMap::InitCellDataL()
       
   332     {
       
   333     for(TInt i = 0; i < KNumCells; i++)
       
   334         {
       
   335         TKeymapCellData* cellData = new (ELeave) TKeymapCellData();
       
   336 
       
   337         TInt shortcutAssign;
       
   338 
       
   339         // get the shortcut assignment from Browser Prefs
       
   340         switch(i)
       
   341             {
       
   342             case 0:
       
   343                 shortcutAssign = iApiProvider.Preferences().ShortcutKey1Cmd();
       
   344                 break;
       
   345             case 1:
       
   346                 shortcutAssign = iApiProvider.Preferences().ShortcutKey2Cmd();
       
   347                 break;
       
   348             case 2:
       
   349                 shortcutAssign = iApiProvider.Preferences().ShortcutKey3Cmd();
       
   350                 break;
       
   351             case 3:
       
   352                 shortcutAssign = iApiProvider.Preferences().ShortcutKey4Cmd();
       
   353                 break;
       
   354             case 4:
       
   355                 shortcutAssign = iApiProvider.Preferences().ShortcutKey5Cmd();
       
   356                 break;
       
   357             case 5:
       
   358                 shortcutAssign = iApiProvider.Preferences().ShortcutKey6Cmd();
       
   359                 break;
       
   360             case 6:
       
   361                 shortcutAssign = iApiProvider.Preferences().ShortcutKey7Cmd();
       
   362                 break;
       
   363             case 7:
       
   364                 shortcutAssign = iApiProvider.Preferences().ShortcutKey8Cmd();
       
   365                 break;
       
   366             case 8:
       
   367                 shortcutAssign = iApiProvider.Preferences().ShortcutKey9Cmd();
       
   368                 break;
       
   369             case 9:
       
   370                 shortcutAssign = iApiProvider.Preferences().ShortcutKeyStarCmd();
       
   371                 break;
       
   372             case 10:
       
   373                 shortcutAssign = iApiProvider.Preferences().ShortcutKey0Cmd();
       
   374                 break;
       
   375             case 11:
       
   376                 shortcutAssign = iApiProvider.Preferences().ShortcutKeyHashCmd();
       
   377                 break;
       
   378             default:
       
   379                 shortcutAssign = iApiProvider.Preferences().ShortcutKey1Cmd();
       
   380                 break;
       
   381             }
       
   382 
       
   383         cellData->cmdRscId = KShortcutsIconAndTextAssignmentMatrix[shortcutAssign][KShortcutsIconAndTextDecodeMatrixText];
       
   384         cellData->lineText = StringLoader::LoadLC(cellData->cmdRscId);
       
   385 
       
   386         // get shortcut key assignments and set dialpad assignments
       
   387         cellData->keyText = StringLoader::LoadLC(KDialpadAssignments[i]);
       
   388 
       
   389         // load the icon its mask (use a default if we're out of range)
       
   390         TInt iconId = EMbmBrowserQgn_indi_browser_tb_key_map;
       
   391         if(shortcutAssign < KShortcutsIconAndTextAssignmentSize)
       
   392             {
       
   393             iconId = KShortcutsIconAndTextAssignmentMatrix[shortcutAssign][KShortcutsIconAndTextDecodeMatrixIcon];
       
   394             }
       
   395 
       
   396         if(shortcutAssign == NULL)
       
   397             {
       
   398             cellData->keyBitmapImage = NULL;
       
   399             cellData->keyBitmapMask = NULL;
       
   400             }
       
   401         else
       
   402             {
       
   403             LoadSvg(iconId,
       
   404                     *iSvgMbmFile,
       
   405                     cellData->keyBitmapImage,
       
   406                     cellData->keyBitmapMask);
       
   407             }
       
   408 
       
   409         // add to the data array
       
   410         iCellData.Append(cellData);
       
   411 
       
   412         // remove keytext, linetext from stack
       
   413         CleanupStack::Pop(2);
       
   414         }
       
   415     }
       
   416 
       
   417 
       
   418 
       
   419 // -----------------------------------------------------------------------------
       
   420 // CBrowserShortcutKeyMap::CreateBitmapAndContextL
       
   421 // Create the bitmap and context that will be used for the sprite
       
   422 // -----------------------------------------------------------------------------
       
   423 //
       
   424 void CBrowserShortcutKeyMap::CreateBitmapAndContextL()
       
   425     {
       
   426     // Create Sprite Bitmap
       
   427     iSpriteBitmap = new (ELeave) CFbsBitmap;
       
   428     User::LeaveIfError( iSpriteBitmap->Create( iTargetRect.Size(), EColor16MA ) );
       
   429 
       
   430     iSpriteBitmapDevice = CFbsBitmapDevice::NewL( iSpriteBitmap );
       
   431     User::LeaveIfError( iSpriteBitmapDevice->CreateContext( iSpriteBitmapContext ) );
       
   432 
       
   433     // Create Mask Bitmap
       
   434     iSpriteMaskBitmap = new (ELeave) CFbsBitmap;
       
   435     User::LeaveIfError( iSpriteMaskBitmap->Create( iTargetRect.Size(), EColor16MA ) );
       
   436     iSpriteMaskBitmapDevice = CFbsBitmapDevice::NewL( iSpriteMaskBitmap );
       
   437     User::LeaveIfError( iSpriteMaskBitmapDevice->CreateContext( iSpriteMaskBitmapContext ) );
       
   438 
       
   439     TRect r( TPoint( 0, 0 ), iSpriteMaskBitmap->SizeInPixels());
       
   440 
       
   441     iSpriteMaskBitmapContext->SetBrushStyle( CGraphicsContext::ESolidBrush );
       
   442     iSpriteMaskBitmapContext->SetPenStyle( CGraphicsContext::ESolidPen );
       
   443     iSpriteMaskBitmapContext->SetBrushColor( TRgb( 0, 0, 0) );
       
   444     iSpriteMaskBitmapContext->SetPenColor( TRgb( 0, 0, 0) );
       
   445     iSpriteMaskBitmapContext->DrawRect(r);
       
   446 
       
   447     // Draw the rectangular outline
       
   448     iSpriteBitmapContext->SetBrushStyle( CGraphicsContext::ESolidBrush );
       
   449     iSpriteBitmapContext->SetPenStyle( CGraphicsContext::ESolidPen );
       
   450     iSpriteBitmapContext->SetBrushColor( TRgb( 242, 244, 242) );
       
   451     iSpriteBitmapContext->SetPenColor( TRgb( 100, 100, 0) );
       
   452     iSpriteBitmapContext->SetPenSize( TSize(2,2) );
       
   453     iSpriteBitmapContext->DrawRect(r);
       
   454 
       
   455     TSize cellSize(r.Width()/KNumCellsX,r.Height()/KNumCellsY);
       
   456 
       
   457     for(TInt i = 0; i < KNumCellsY; i++)
       
   458         {
       
   459         for(TInt j = 0; j < KNumCellsX; j++)
       
   460             {
       
   461             TInt cellIndex(i*KNumCellsX + j);
       
   462             CreateCellLayout( cellIndex, TPoint(j*cellSize.iWidth,i*cellSize.iHeight),cellSize);
       
   463             CreateSpriteCellL( cellIndex );
       
   464             }
       
   465         }
       
   466     }
       
   467 
       
   468 
       
   469 
       
   470 // -----------------------------------------------------------------------------
       
   471 // CBrowserShortcutKeyMap::CreateCellLayout
       
   472 // Calculate the layout of the sprite rects for a given cell
       
   473 // -----------------------------------------------------------------------------
       
   474 
       
   475 void CBrowserShortcutKeyMap::CreateCellLayout(const TInt& aCellIndex, const TPoint& aUpperL, const TSize& aSize)
       
   476     {
       
   477     // Create pointer for easy access curr Cell
       
   478     TKeymapCellData* pCurrCell = iCellData[aCellIndex];
       
   479 
       
   480     // Create rect for Cell
       
   481     pCurrCell->r.SetRect(aUpperL, aSize);
       
   482 
       
   483     // Internally, Our Cell is sized accounting for margin
       
   484     // Setup this
       
   485     TPoint marginOffset(KCellLeftMargin, KCellTopMargin);
       
   486     TSize marginSize(KCellLeftMargin + KCellRightMargin, KCellTopMargin + KCellBotMargin);
       
   487     pCurrCell->rCell.SetRect( aUpperL + marginOffset, aSize - marginSize );
       
   488 
       
   489     // Upper LH key indicator
       
   490     TInt keyFontHeight = iKeyFont->HeightInPixels() + iKeyFont->DescentInPixels();
       
   491     pCurrCell->rKey.SetRect( pCurrCell->rCell.iTl, TSize(keyFontHeight, iKeyFont->MaxCharWidthInPixels()) );
       
   492 
       
   493     // Prep the line rects, calculating the position based upon the font size
       
   494     TInt lineFontHeight = iLineFont->HeightInPixels() + iLineFont->DescentInPixels();
       
   495     TSize lineSize(pCurrCell->rCell.Width(),lineFontHeight);
       
   496     TPoint lineAreaUpperLH(pCurrCell->rCell.iTl.iX, pCurrCell->rCell.iBr.iY - (2*lineSize.iHeight));
       
   497 
       
   498     // Set this point to be the upper left of the line(s) of text.
       
   499     // If we have two lines, this will be the upperLH of Line1
       
   500     // If we have one line, this will be the upperLH of Line2
       
   501     // This, we will use to set the rect size of the icon later
       
   502     pCurrCell->rLine1.SetRect(lineAreaUpperLH,lineSize);
       
   503     pCurrCell->rLine2.SetRect(lineAreaUpperLH + TPoint(0,lineSize.iHeight),lineSize);
       
   504     TPoint linesUpperLH = pCurrCell->rLine1.iTl;
       
   505 
       
   506     // CREATE the icon area from what is left over
       
   507     TPoint iconUpperLH(pCurrCell->rCell.iTl + TPoint(pCurrCell->rKey.Size().iWidth,0));
       
   508     TPoint iconLowerRH(pCurrCell->rCell.iBr.iX,linesUpperLH.iY);
       
   509     pCurrCell->rIcon.SetRect(iconUpperLH,iconLowerRH);
       
   510 
       
   511     // resize the icon rect to be square if its not already... according to its smallest dimension
       
   512     if(pCurrCell->rIcon.Height() > pCurrCell->rIcon.Width())
       
   513         {
       
   514         TSize sizeChange(0,pCurrCell->rIcon.Width() - pCurrCell->rIcon.Height());
       
   515         pCurrCell->rIcon.Resize(sizeChange);
       
   516         pCurrCell->rIcon.Move(TPoint(0,-sizeChange.iHeight/2));
       
   517         }
       
   518     else if(pCurrCell->rIcon.Width() > pCurrCell->rIcon.Height())
       
   519         {
       
   520         TSize sizeChange(pCurrCell->rIcon.Height() - pCurrCell->rIcon.Width(),0);
       
   521         pCurrCell->rIcon.Resize(sizeChange);
       
   522         pCurrCell->rIcon.Move(TPoint(-sizeChange.iWidth/2,0));
       
   523         }
       
   524     }
       
   525 
       
   526 
       
   527 
       
   528 // -----------------------------------------------------------------------------
       
   529 // CBrowserShortcutKeyMap::CreateSpriteCellL
       
   530 // Draw the sprite rects to the sprite bitmap
       
   531 // ----------------------------------------------------------------------------
       
   532 
       
   533 void CBrowserShortcutKeyMap::CreateSpriteCellL(const TInt& aCellIndex)
       
   534     {
       
   535     // Create pointer for easy access curr Cell
       
   536     TKeymapCellData* pCurrCell = iCellData[aCellIndex];
       
   537 
       
   538     TBool ShowDim = EFalse;
       
   539 
       
   540 
       
   541     // Draw rect for Cell
       
   542     iSpriteBitmapContext->SetPenSize( TSize(1,1) );
       
   543     iSpriteBitmapContext->SetPenStyle( CGraphicsContext::ESolidPen );
       
   544     iSpriteBitmapContext->SetPenColor( TRgb( 0, 0, 0) );
       
   545     iSpriteBitmapContext->DrawRect(pCurrCell->r);
       
   546 
       
   547 
       
   548 
       
   549     // DRAW TEXT
       
   550     iSpriteBitmapContext->SetPenColor( TRgb( 0, 0, 0) );
       
   551 
       
   552     // Draw key text
       
   553     if(pCurrCell->keyText)
       
   554     {
       
   555         iSpriteBitmapContext->UseFont( iKeyFont );
       
   556         iSpriteBitmapContext->DrawText(pCurrCell->keyText->Des(),
       
   557             pCurrCell->rKey, iKeyFont->FontMaxHeight(), CGraphicsContext::ECenter, 0);
       
   558     }
       
   559 
       
   560     // For line1, line2 text, we need to first wrap them
       
   561     // based upon the width of their enclosing rectangles
       
   562     if(pCurrCell->lineText)
       
   563         {
       
   564         CArrayFixFlat<TInt> *lineWidthArray = new( ELeave ) CArrayFixFlat<TInt>(2);
       
   565         lineWidthArray->AppendL(pCurrCell->rLine1.Width());
       
   566         lineWidthArray->AppendL(pCurrCell->rLine2.Width());
       
   567 
       
   568         CArrayFixFlat<TPtrC> *WrappedArray = new( ELeave ) CArrayFixFlat<TPtrC>(3);        
       
   569         pCurrCell->lineText = pCurrCell->lineText->ReAllocL(pCurrCell->lineText->Length() + lineWidthArray->Count() * KAknBidiExtraSpacePerLine);
       
   570         TPtr ptr(pCurrCell->lineText->Des());
       
   571         AknBidiTextUtils::ConvertToVisualAndWrapToArrayL( ptr,*lineWidthArray, *iLineFont, *WrappedArray, EFalse );
       
   572         iSpriteBitmapContext->UseFont( iLineFont );
       
   573         iSpriteBitmapContext->DrawText(WrappedArray->At(0),
       
   574             pCurrCell->rLine2, iLineFont->FontMaxHeight(), CGraphicsContext::ECenter, 0);
       
   575 
       
   576         if(WrappedArray->Count() >= 2)
       
   577             {
       
   578             iSpriteBitmapContext->DrawText(WrappedArray->At(0),
       
   579                 pCurrCell->rLine1, iLineFont->FontMaxHeight(), CGraphicsContext::ECenter, 0);
       
   580             iSpriteBitmapContext->DrawText(WrappedArray->At(1),
       
   581                 pCurrCell->rLine2, iLineFont->FontMaxHeight(), CGraphicsContext::ECenter, 0);
       
   582             }
       
   583 
       
   584 
       
   585         // Set dim flag if needed
       
   586         switch (pCurrCell->cmdRscId)
       
   587             {
       
   588             case R_BROWSER_KEYMAP_TEXT_SWITCH_WINDOW:
       
   589                 { //EWmlCmdSwitchWindow;
       
   590                 ShowDim = ( !iApiProvider.Preferences().UiLocalFeatureSupported( KBrowserMultipleWindows ) ||
       
   591                             iApiProvider.IsEmbeddedModeOn() ||
       
   592                             iApiProvider.WindowMgr().WindowCount() < 2);
       
   593                 break;
       
   594                 }
       
   595 
       
   596             case R_BROWSER_KEYMAP_TEXT_VIEW_IMAGES:
       
   597                 { //EWmlCmdShowImages;
       
   598                 ShowDim = ( !iApiProvider.BrCtlInterface().ImageCountL() );
       
   599                 break;
       
   600                 }
       
   601 
       
   602             case R_BROWSER_KEYMAP_TEXT_SUBSCRIBE_TO_FEEDS:
       
   603                 { // EWmlCmdShowSubscribeList
       
   604                 CBrCtlInterface& brctl = iApiProvider.BrCtlInterface();
       
   605                 TBool subscribeToItems(EFalse);
       
   606                 TRAPD(err, const RPointerArray<TBrCtlSubscribeTo>& items = brctl.SubscribeToMenuItemsL();
       
   607                 subscribeToItems = (err == KErrNone && items.Count() > 0));
       
   608                 ShowDim = !subscribeToItems;
       
   609                 break;
       
   610                 }
       
   611 
       
   612             case R_BROWSER_KEYMAP_TEXT_GO_TO_HOMEPAGE:
       
   613                 { // EWmlCmdLaunchHomePage
       
   614                 ShowDim = iApiProvider.IsLaunchHomePageDimmedL();
       
   615                 break;
       
   616                 }
       
   617 
       
   618             case R_BROWSER_KEYMAP_TEXT_PREVIOUS_PAGE:
       
   619                 { // EWmlCmdOneStepBack
       
   620                 ShowDim = (!iApiProvider.BrCtlInterface().NavigationAvailable(TBrCtlDefs::ENavigationBack ) );
       
   621                 break;
       
   622                 }
       
   623 
       
   624             case R_BROWSER_KEYMAP_TEXT_MINIATURE_SHOW:
       
   625                 { //EWmlCmdShowMiniature;
       
   626                 ShowDim = ( !iApiProvider.Preferences().UiLocalFeatureSupported( KBrowserGraphicalPage ) ||
       
   627                             iApiProvider.WindowMgr().CurrentWindow()->HasWMLContent(ETrue) );
       
   628                 break;
       
   629                 }
       
   630 
       
   631             case R_BROWSER_KEYMAP_TEXT_SHOW_TOOLBAR:
       
   632                 { //EWmlCmdShowToolBar;
       
   633                 if ( !AknLayoutUtils::PenEnabled() && iApiProvider.Preferences().ShowToolbarOnOff() )
       
   634                     {
       
   635                     ShowDim = iApiProvider.WindowMgr().CurrentWindow()->WMLMode();
       
   636                     }
       
   637                 else
       
   638                     {
       
   639                     ShowDim = ETrue;
       
   640                     }
       
   641                 break;
       
   642                 }
       
   643 
       
   644             case R_BROWSER_KEYMAP_TEXT_SAVE_AS_BOOKMARK:
       
   645                 { //EWmlCmdSaveAsBookmark;
       
   646                 if ( iApiProvider.IsEmbeddedModeOn() && CBrowserAppUi::Static()->IsEmbeddedInOperatorMenu() )
       
   647                     {
       
   648                     ShowDim = ETrue;
       
   649                     }
       
   650                 else
       
   651                     {
       
   652                     HBufC *pageUrl = iApiProvider.BrCtlInterface().PageInfoLC( TBrCtlDefs::EPageInfoUrl );
       
   653                     if( ( pageUrl == NULL ) || ( pageUrl->Length() == 0 ) )
       
   654                         {
       
   655                         ShowDim = ETrue;
       
   656                         }
       
   657                     CleanupStack::PopAndDestroy( pageUrl );
       
   658                     }
       
   659                 break;
       
   660                 }
       
   661 
       
   662             /* Zoom Mode currently disabled
       
   663             case R_BROWSER_KEYMAP_TEXT_ZOOM_MODE:
       
   664                 { //EWmlCmdZoomMode;
       
   665 
       
   666                 ShowDim = ( iApiProvider.WindowMgr().CurrentWindow()->WMLMode() ||
       
   667                             !iApiProvider.ContentDisplayed() ||
       
   668                             AknLayoutUtils::PenEnabled() );
       
   669                 break;
       
   670                 }
       
   671             */
       
   672 
       
   673             default:
       
   674             break;
       
   675             }
       
   676         }
       
   677 
       
   678     // DRAW the icon,
       
   679     // setting the icon size according to iconRect
       
   680     if(pCurrCell->keyBitmapImage != NULL && pCurrCell->keyBitmapMask != NULL)
       
   681         {
       
   682         AknIconUtils::SetSize(pCurrCell->keyBitmapImage, pCurrCell->rIcon.Size() );
       
   683         AknIconUtils::SetSize(pCurrCell->keyBitmapMask, pCurrCell->rIcon.Size() );
       
   684 
       
   685         if (ShowDim)
       
   686             {
       
   687             CFbsBitmap* keyBitmapDimImage;
       
   688             CFbsBitmap* keyBitmapDimMask;
       
   689 
       
   690             CreateDimBitmapL(pCurrCell->keyBitmapImage,
       
   691                              pCurrCell->keyBitmapMask,
       
   692                              keyBitmapDimImage,
       
   693                              keyBitmapDimMask);
       
   694 
       
   695             iSpriteBitmapContext->BitBltMasked(pCurrCell->rIcon.iTl,
       
   696                 keyBitmapDimImage,
       
   697                 TRect(TPoint(0, 0),pCurrCell->rIcon.Size() ),
       
   698                 keyBitmapDimMask,
       
   699                 ETrue);
       
   700 
       
   701             delete keyBitmapDimImage;
       
   702             delete keyBitmapDimMask;
       
   703             }
       
   704         else
       
   705             {
       
   706             iSpriteBitmapContext->BitBltMasked(pCurrCell->rIcon.iTl,
       
   707                 pCurrCell->keyBitmapImage,
       
   708                 TRect(TPoint(0, 0),pCurrCell->rIcon.Size() ),
       
   709                 pCurrCell->keyBitmapMask,
       
   710                 ETrue);
       
   711             }
       
   712         }
       
   713     }
       
   714 
       
   715 
       
   716 
       
   717 // -----------------------------------------------------------------------------
       
   718 // CBrowserShortcutKeyMap::ConstructSprite
       
   719 // Construct the Sprite from the bitmap and context
       
   720 // -----------------------------------------------------------------------------
       
   721 //
       
   722 void CBrowserShortcutKeyMap::ConstructSprite()
       
   723     {
       
   724     iSprite = RWsSprite( CEikonEnv::Static()->WsSession() );
       
   725     RWindowTreeNode *window = iContentViewContainer->DrawableWindow();
       
   726     iSprite.Construct(*window,iTargetRect.iTl,ESpriteNoChildClip);
       
   727 
       
   728     TSpriteMember spriteMem;
       
   729     spriteMem.iBitmap = iSpriteBitmap;
       
   730     spriteMem.iMaskBitmap = iSpriteMaskBitmap;
       
   731     spriteMem.iInvertMask = ETrue;
       
   732     iSprite.AppendMember(spriteMem);
       
   733 
       
   734     iSprite.SetPosition(iTargetRect.iTl);
       
   735     iSprite.Activate();
       
   736     }
       
   737 
       
   738 
       
   739 
       
   740 // -----------------------------------------------------------------------------
       
   741 // CBrowserShortcutKeyMap::GetCannedImageDirL
       
   742 // Utility: Get the folder where the canned image is located
       
   743 // -----------------------------------------------------------------------------
       
   744 //
       
   745 HBufC* CBrowserShortcutKeyMap::GetCannedImageDirL( )
       
   746     {
       
   747     HBufC* mbmFile = NULL;
       
   748     TParse parse;
       
   749 
       
   750     // Get the drive letter where mbm resides.. it will be the same
       
   751     // as this AppUi (browser ng)
       
   752     CEikAppUi* pAppUI = (CEikAppUi*)(CCoeEnv::Static()->AppUi());
       
   753     TFileName mbmDrive = pAppUI->Application()->DllName();
       
   754 
       
   755     parse.Set( mbmDrive, NULL, NULL );
       
   756     mbmDrive = parse.Drive();
       
   757 
       
   758     // allocate memory for MBM file name
       
   759     mbmFile = HBufC::NewL( KMaxFileName );
       
   760 
       
   761     // assemble the MBM file name
       
   762     TPtr ptr( mbmFile->Des() );
       
   763     ptr.SetLength( 0 );
       
   764     ptr.Append( mbmDrive );
       
   765     ptr.Append( KDC_APP_BITMAP_DIR );
       
   766     return mbmFile;
       
   767     }
       
   768 
       
   769 
       
   770 
       
   771 // -----------------------------------------------------------------------------
       
   772 // CBrowserShortcutKeyMap::LoadSvg
       
   773 // Utility: get the SVG bitmaps, etc, given its filename
       
   774 // -----------------------------------------------------------------------------
       
   775 //
       
   776 void CBrowserShortcutKeyMap::LoadSvg(
       
   777     TInt aImageId,
       
   778     const TDesC& aFileName,
       
   779     CFbsBitmap*& aImage ,
       
   780     CFbsBitmap*& aImageMask )
       
   781     {
       
   782     // Don't skin icons--at least for now.
       
   783     TRAPD(error, AknIconUtils::CreateIconL( aImage,
       
   784                                             aImageMask,
       
   785                                             aFileName,
       
   786                                             aImageId,
       
   787                                             aImageId+1));
       
   788 
       
   789     if (error!=KErrNone)
       
   790         {
       
   791         return;
       
   792         }
       
   793     }
       
   794 
       
   795 // -----------------------------------------------------------------------------
       
   796 // CBrowserShortcutKeyMap::CreateDimBitmap
       
   797 // Utility: Create Dimmed version of Bitmap
       
   798 // -----------------------------------------------------------------------------
       
   799 //
       
   800 void CBrowserShortcutKeyMap::CreateDimBitmapL(
       
   801     CFbsBitmap* aImage,
       
   802     CFbsBitmap* aImageMask,
       
   803     CFbsBitmap*& aDimImage,
       
   804     CFbsBitmap*& aDimImageMask)
       
   805     {
       
   806 
       
   807     aDimImage = new ( ELeave ) CFbsBitmap;
       
   808     CleanupStack::PushL( aDimImage );
       
   809 
       
   810     aDimImage->Duplicate( aImage->Handle() );
       
   811 
       
   812     aDimImageMask = new ( ELeave ) CFbsBitmap;
       
   813 
       
   814     User::LeaveIfError( aDimImageMask->Create(aDimImage->SizeInPixels(),
       
   815                                         EGray256 ) );
       
   816 
       
   817     CleanupStack::PushL( aDimImageMask );
       
   818 
       
   819     CFbsBitmapDevice* bitmapDevice = CFbsBitmapDevice::NewL( aDimImageMask );
       
   820     CleanupStack::PushL( bitmapDevice );
       
   821 
       
   822     CFbsBitGc* bitGc( NULL );
       
   823     User::LeaveIfError( bitmapDevice->CreateContext( bitGc ) );
       
   824     CleanupStack::PushL( bitGc );
       
   825 
       
   826     bitGc->SetPenStyle( CGraphicsContext::ESolidPen );
       
   827     bitGc->BitBlt( TPoint( 0, 0 ), aImageMask );
       
   828 
       
   829 
       
   830     aDimImageMask->LockHeap();
       
   831     TInt w = aImageMask->SizeInPixels().iWidth;
       
   832     TInt h = aImageMask->SizeInPixels().iHeight;
       
   833     TInt dataStride = aImageMask->DataStride() - w;
       
   834     unsigned char* address = (unsigned char *)aDimImageMask->DataAddress();
       
   835 
       
   836     for ( TInt i = 0; i < h; ++i )
       
   837         {
       
   838         for ( TInt j = 0; j < w; ++j )
       
   839             {
       
   840             *address = KTransparency[*address];
       
   841             ++address;
       
   842             }
       
   843         address += dataStride;
       
   844         }
       
   845 
       
   846     aDimImageMask->UnlockHeap();
       
   847 
       
   848     CleanupStack::PopAndDestroy( 2 ); // bitmapDevice, bitGc
       
   849     CleanupStack::Pop( 2 ); // aDimImage, aDimImageMask
       
   850 
       
   851 
       
   852     }
       
   853 
       
   854 //  End of File