webengine/osswebengine/WebKit/s60/webview/WebSprite.cpp
changeset 5 10e98eab6f85
child 46 30342f40acbf
equal deleted inserted replaced
1:7c90e6132015 5:10e98eab6f85
       
     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:  Handles the viewing of a single frame. If the page is not frame
       
    15 *               enabled, this class is used as the single view.  If frame
       
    16 *               enabled, there is one instance of this class for each frame.
       
    17 *
       
    18 */
       
    19 
       
    20 #include "../../bidi.h"
       
    21 #include <fbs.h>
       
    22 #include <coemain.h>
       
    23 #include "WebSprite.h"
       
    24 
       
    25 
       
    26 /*
       
    27  * CWebSprite class serves as a replacement for Symbian RWsSprite 
       
    28  * in the cases when transparent window is possible (platform supports it).
       
    29  * It's a window owning CCoeControl which window gets highest priority and
       
    30  * smallest ordinal number. That allows to CWebSprite be on top of all windows
       
    31  * in the same window group. The movement is restricted by boundaries of the
       
    32  * parent CCoeControl window or Root Window if parent is NULL.
       
    33  * Only one bitmap is supported, so animation is not possible.
       
    34  * If platform doesn't support window transparency CWebSprite acts as wrapper
       
    35  * around RWsSprite.
       
    36  */
       
    37 
       
    38 // ======================================================================
       
    39 // CWebSprite::NewL
       
    40 // ======================================================================
       
    41 CWebSprite* CWebSprite::NewL(TPoint& aPos, CFbsBitmap* aBitmap, 
       
    42                              CFbsBitmap* aMask, TBool aInvertMask)
       
    43     {
       
    44     CWebSprite* self = new(ELeave)CWebSprite(NULL, aBitmap, aMask, aInvertMask);
       
    45     CleanupStack::PushL(self);
       
    46     self->ConstructL(aPos);
       
    47     CleanupStack::Pop();
       
    48     return self;
       
    49     }
       
    50 
       
    51 // ======================================================================
       
    52 // CWebSprite::NewL
       
    53 // ======================================================================
       
    54 CWebSprite* CWebSprite::NewL(CCoeControl* aParent, TPoint& aPos, 
       
    55                              CFbsBitmap* aBitmap, CFbsBitmap* aMask, 
       
    56 			     TBool aInvertMask)
       
    57     {
       
    58     CWebSprite* self = new(ELeave)CWebSprite(aParent, aBitmap, aMask, aInvertMask);
       
    59     CleanupStack::PushL(self);
       
    60     self->ConstructL(aParent, aPos);
       
    61     CleanupStack::Pop();
       
    62     return self;
       
    63     }
       
    64 
       
    65 // ======================================================================
       
    66 // CWebSprite::BaseConstructL
       
    67 // ======================================================================
       
    68 void CWebSprite::BaseConstructL(TPoint& aPos, CFbsBitmap* aBitmap, 
       
    69                                 CFbsBitmap* aMask, TBool aInvertMask)
       
    70     {
       
    71     iBitmap = aBitmap;
       
    72     iMask = aMask;
       
    73     iInvertMask = aInvertMask;
       
    74     iParent = NULL;
       
    75     ConstructL(aPos);
       
    76     }
       
    77 
       
    78 // ======================================================================
       
    79 // CWebSprite::BaseConstructL
       
    80 // ======================================================================
       
    81 void CWebSprite::BaseConstructL(CCoeControl* aParent, TPoint& aPos, 
       
    82                                 CFbsBitmap* aBitmap, CFbsBitmap* aMask, 
       
    83 				TBool aInvertMask)
       
    84     {
       
    85     iBitmap = aBitmap;
       
    86     iMask = aMask;
       
    87     iInvertMask = aInvertMask;
       
    88     iParent = aParent;
       
    89     ConstructL(aParent, aPos);
       
    90     }
       
    91 
       
    92 // ======================================================================
       
    93 // CWebSprite::CWebSprite()
       
    94 // ======================================================================
       
    95 CWebSprite::CWebSprite()
       
    96     {
       
    97     }
       
    98 
       
    99 // ======================================================================
       
   100 // CWebSprite::CWebSprite()
       
   101 // ======================================================================
       
   102 CWebSprite::CWebSprite(CCoeControl* aParent, CFbsBitmap* aBitmap, 
       
   103                        CFbsBitmap* aMask, TBool aInvertMask) : 
       
   104                        iParent(aParent), iBitmap(aBitmap), iMask(aMask), 
       
   105 		       iInvertMask(aInvertMask), iWin(NULL)
       
   106     {    
       
   107     }
       
   108 
       
   109 // ======================================================================
       
   110 // CWebSprite::ConstructL
       
   111 // ======================================================================
       
   112 void CWebSprite::ConstructL(TPoint& aPos)
       
   113     {
       
   114     ConstructL(NULL, aPos);
       
   115     }
       
   116 
       
   117 // ======================================================================
       
   118 // CWebSprite::ConstructL
       
   119 // ======================================================================
       
   120 void CWebSprite::ConstructL(CCoeControl* aParent, TPoint& aPos)
       
   121     {
       
   122     TInt err = KErrNone;
       
   123     if (aParent)
       
   124         {
       
   125         CreateWindowL(aParent);
       
   126         }
       
   127     else
       
   128         {
       
   129         CreateWindowL();
       
   130         }
       
   131     
       
   132     iWin = &(Window());
       
   133     iWin->SetRequiredDisplayMode(EColor16MA);
       
   134     err = iWin->SetTransparencyAlphaChannel();
       
   135     if (err != KErrNone)
       
   136         {
       
   137         // Transparency is not possible - close window and use sprites
       
   138         CloseWindow();
       
   139         iWin = NULL;
       
   140         }
       
   141     
       
   142     if (iWin)
       
   143         {
       
   144         iWin->SetOrdinalPosition(0, KPasswordWindowGroupPriority - 1);   
       
   145         iWin->SetBackgroundColor(TRgb(0,0));    
       
   146         if (iBitmap) 
       
   147             {
       
   148             init(aPos, iBitmap->SizeInPixels());
       
   149             ActivateL();
       
   150             }
       
   151         else
       
   152             {
       
   153             SetPosition(aPos);
       
   154             Hide();
       
   155             }
       
   156         }
       
   157     else
       
   158         {
       
   159         MakeVisible(EFalse);
       
   160         CreateSprite(aPos);
       
   161         }
       
   162     }
       
   163 
       
   164 // ======================================================================
       
   165 // CWebSprite::CreateSprite
       
   166 // ======================================================================
       
   167 void CWebSprite::CreateSprite(TPoint& aPos)
       
   168     {
       
   169     /*
       
   170      * We should come here only if iWin is NULL since it will mean that 
       
   171      * transparent windowis not possible and we are using sprite
       
   172      */
       
   173     RWindowTreeNode* window = iParent ? static_cast<RWindowTreeNode*>(iParent->DrawableWindow()) :
       
   174                                         static_cast<RWindowTreeNode*>(&(ControlEnv()->RootWin()));
       
   175     iSprite = RWsSprite(ControlEnv()->WsSession());
       
   176     iSprite.Construct(*window, aPos, ESpriteNoChildClip);
       
   177 
       
   178     TSpriteMember spriteMem;
       
   179     spriteMem.iBitmap = iBitmap;
       
   180     spriteMem.iMaskBitmap = iMask;
       
   181     spriteMem.iInvertMask = iInvertMask;
       
   182 
       
   183     iSprite.AppendMember(spriteMem);
       
   184     iSprite.Activate();
       
   185     }
       
   186 
       
   187 // ======================================================================
       
   188 // CWebSprite::UpdateSprite
       
   189 // ======================================================================
       
   190 void CWebSprite::UpdateSprite()
       
   191     {
       
   192     /*
       
   193      * We should come here only if iWin is NULL since it will mean that 
       
   194      * transparent windowis not possible and we are using sprite
       
   195      */
       
   196     TSpriteMember spriteMem;
       
   197     spriteMem.iBitmap = iBitmap;
       
   198     spriteMem.iMaskBitmap = iMask;
       
   199     spriteMem.iInvertMask = iInvertMask;
       
   200 
       
   201     iSprite.UpdateMember(0, spriteMem);
       
   202     }
       
   203 
       
   204 // ======================================================================
       
   205 // CWebSprite::init
       
   206 // ======================================================================
       
   207 void CWebSprite::init(TPoint& aPos, TSize aSize)
       
   208     {
       
   209     if (iWin)
       
   210         { // we have a window - let's set position and size
       
   211         SetPosition(aPos);
       
   212         SetSizeWithoutNotification(aSize);
       
   213         }
       
   214     }
       
   215 
       
   216 // ======================================================================
       
   217 // CWebSprite::Draw
       
   218 // ======================================================================
       
   219 void CWebSprite::Draw(const TRect& aRect) const
       
   220     {
       
   221     if (IsActivated() && iBitmap)
       
   222         {
       
   223         CWindowGc& gc = SystemGc();       
       
   224         gc.Clear(aRect);   
       
   225         Window().SetOrdinalPosition(0, KPasswordWindowGroupPriority - 1); 
       
   226         TPoint pt = TPoint(0,0);
       
   227         TRect rect = TRect(pt, iBitmap->SizeInPixels());
       
   228         gc.BitBltMasked(pt, iBitmap, rect, iMask, iInvertMask);
       
   229         }
       
   230     }
       
   231 
       
   232 // ======================================================================
       
   233 // CWebSprite::SetBitmap
       
   234 // ======================================================================
       
   235 void CWebSprite::SetBitmap(CFbsBitmap* aBitmap, CFbsBitmap* aMask, TBool aInvertMask)
       
   236     {
       
   237     iBitmap = aBitmap;
       
   238     iMask = aMask;   
       
   239     iInvertMask = aInvertMask;
       
   240     
       
   241     if(iWin && aBitmap)
       
   242         {
       
   243         TPoint pos = Position();
       
   244         init(pos, aBitmap->SizeInPixels());
       
   245         }
       
   246     }
       
   247 
       
   248 // ======================================================================
       
   249 // CWebSprite::Update
       
   250 // ======================================================================
       
   251 void CWebSprite::Update(const TPoint& aPos, CFbsBitmap* aBitmap, 
       
   252                         CFbsBitmap* aMask)
       
   253     {
       
   254     SetPos(aPos);
       
   255     Update(aBitmap, aMask);
       
   256     }
       
   257 
       
   258 // ======================================================================
       
   259 // CWebSprite::Update
       
   260 // ======================================================================
       
   261 void CWebSprite::Update(CFbsBitmap* aBitmap, CFbsBitmap* aMask)
       
   262     {
       
   263     TInt err = KErrNone;
       
   264     if(iWin && aBitmap) // if we have a window and bitmap check if we need 
       
   265         {               // to finish initialization
       
   266         if (!IsActivated() || !iBitmap)         // if control wasn't activated 
       
   267             {                                   // or bitmap was reset last time to NULL,
       
   268             TPoint pos = Position();            // because somebody wanted to reuse this control, 
       
   269             init(pos, aBitmap->SizeInPixels()); // we will try to initialize the control.
       
   270             TRAP(err, ActivateL());
       
   271             }
       
   272         }
       
   273 
       
   274     if (err == KErrNone)
       
   275         {
       
   276         iBitmap = aBitmap;
       
   277         iMask = aMask;   
       
   278         }
       
   279     else
       
   280         {
       
   281         iBitmap = NULL;
       
   282         iMask = NULL;    
       
   283         }
       
   284 
       
   285     if (!iWin)
       
   286         {
       
   287         UpdateSprite();
       
   288         }
       
   289     else if (iBitmap)
       
   290         {
       
   291         Show();
       
   292         DrawNow();
       
   293         }
       
   294     }
       
   295 
       
   296 // ======================================================================
       
   297 // CWebSprite::Update
       
   298 // ======================================================================
       
   299 void CWebSprite::Update(CFbsBitmap* aBitmap, CFbsBitmap* aMask, 
       
   300                         TBool aInvertMask)
       
   301     {
       
   302     iInvertMask = aInvertMask;
       
   303     Update(aBitmap, aMask);
       
   304     }
       
   305 
       
   306 // ======================================================================
       
   307 // CWebSprite::Show
       
   308 // ======================================================================
       
   309 void CWebSprite::Show()
       
   310     {
       
   311     if (iWin)
       
   312         {
       
   313         MakeVisible(ETrue);
       
   314         }
       
   315     else
       
   316         {
       
   317         UpdateSprite();
       
   318         }
       
   319     }
       
   320 
       
   321 // ======================================================================
       
   322 // CWebSprite::Hide
       
   323 // ======================================================================
       
   324 void CWebSprite::Hide()
       
   325     {
       
   326     if (iWin)
       
   327         {
       
   328         MakeVisible(EFalse);
       
   329         }
       
   330     else
       
   331         {
       
   332         Update(NULL, NULL);
       
   333         }
       
   334     }
       
   335 
       
   336 // ======================================================================
       
   337 // CWebSprite::~CWebSprite
       
   338 // ======================================================================
       
   339 CWebSprite::~CWebSprite()
       
   340     {
       
   341     if (!iWin)
       
   342         {
       
   343         iSprite.Close();
       
   344         }
       
   345     }
       
   346 
       
   347 // ======================================================================
       
   348 // CWebSprite::SetPos
       
   349 // ======================================================================
       
   350 void CWebSprite::SetPos(const TPoint& aPos)
       
   351     {
       
   352     if (!iWin)
       
   353         {
       
   354         iSprite.SetPosition(aPos);
       
   355         }
       
   356     else
       
   357         {
       
   358         TPoint pos = Position();
       
   359         if (pos != aPos) 
       
   360             {
       
   361             CCoeControl::SetPosition(aPos);
       
   362             }
       
   363         }
       
   364     }
       
   365 
       
   366 
       
   367 // ======================================================================
       
   368 // CWebSprite::IsShown
       
   369 // ======================================================================
       
   370 TBool CWebSprite::IsShown()
       
   371     {
       
   372     // if it's a window owning CoeControl just return IsVisible()
       
   373     // otherwise check if bitmap != NULL and if it's not then
       
   374     // sprite is shown.
       
   375     return (iWin && IsVisible()) || iBitmap != NULL;
       
   376     }