browserplugins/browseraudiovideoplugin/src/BavpView.cpp
branchRCL_3
changeset 64 6385c4c93049
parent 63 4baee4f15982
child 65 8e6fa1719340
equal deleted inserted replaced
63:4baee4f15982 64:6385c4c93049
     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:  Uses the interface MPluginAdapter to notify browser of construction 
       
    15 				 and destruction of the plug-in, implements interface MPluginOptionHandler
       
    16 				 to add menus and draws animated images while video player loading the data
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include <browser_platform_variant.hrh>
       
    23 #include <AknUtils.h>
       
    24 #include <aknclearer.h>
       
    25 #include <AknBitmapAnimation.h>
       
    26 #include <data_caging_path_literals.hrh>
       
    27 #include <barsread.h>                       // For TResourceReader
       
    28 #include <StringLoader.h>
       
    29 #include <pluginadapterinterface.h>
       
    30 #include <BrowserAudioVideoPlugin.rsg>      // For text
       
    31 
       
    32 #include <brctldefs.h>
       
    33 
       
    34 #include "BavpLogger.h"
       
    35 #include "BavpView.h"
       
    36 #include "BavpController.h"
       
    37 #include "BavpPlugin.h"
       
    38 
       
    39 // ============================ MEMBER FUNCTIONS ===============================
       
    40 
       
    41 // -----------------------------------------------------------------------------
       
    42 // CBavpView::CBavpView
       
    43 // C++ default constructor can NOT contain any code, that
       
    44 // might leave.
       
    45 // -----------------------------------------------------------------------------
       
    46 CBavpView::CBavpView()
       
    47     {
       
    48     }
       
    49 
       
    50 // -----------------------------------------------------------------------------
       
    51 // CBavpView::ConstructL
       
    52 // Symbian 2nd phase constructor can leave.
       
    53 // -----------------------------------------------------------------------------
       
    54 // 
       
    55 void CBavpView::ConstructL( const CCoeControl* aParent, 
       
    56                             const TRect& aRect, CBavpPlugin* aBavPlugin )
       
    57     {
       
    58     Log( EFalse, _L("CBavpView::ConstructL") );
       
    59     iBavPlugin = aBavPlugin;
       
    60     
       
    61 	CreateWindowL(aParent);
       
    62 #ifdef BRDO_MULTITOUCH_ENABLED_FF
       
    63     if (AknLayoutUtils::PenEnabled()) {
       
    64         DrawableWindow()->SetPointerGrab(ETrue);
       
    65         EnableDragEvents();
       
    66     }
       
    67 	//To enable advance pointer info for multi-touch
       
    68    	Window().EnableAdvancedPointers();
       
    69 #endif 
       
    70 	ActivateL(); // Draws icon
       
    71 	iRect = aRect;
       
    72 	CCoeControl::SetRect( aRect ); // Calls SizeChanged
       
    73 
       
    74     User::LeaveIfError( iWsSession.Connect() );
       
    75     iWindowId = iCoeEnv->RootWin().Identifier();
       
    76 
       
    77 	// Video buffering animation, used to show that content is buffering
       
    78 	iVideoBuffAnimation = CAknBitmapAnimation::NewL();
       
    79     iVideoBuffAnimation->SetContainerWindowL( *this );
       
    80     TResourceReader rrBuffering;
       
    81     iCoeEnv->CreateResourceReaderLC( rrBuffering, R_ANIMATION_BUFFERING );
       
    82     iVideoBuffAnimation->ConstructFromResourceL( rrBuffering );
       
    83     CleanupStack::PopAndDestroy();  // rrBuffering
       
    84 	iIsVideoBuffAnimRunning = EFalse;
       
    85 
       
    86 	// Bad content animation, used to show that content is not available
       
    87 	iBadContentAnimation = CAknBitmapAnimation::NewL();
       
    88     iBadContentAnimation->SetContainerWindowL( *this );
       
    89     TResourceReader rrNoContentAnim;
       
    90     iCoeEnv->CreateResourceReaderLC( rrNoContentAnim, R_NO_CONTENT_ANIMATION );
       
    91     iBadContentAnimation->ConstructFromResourceL( rrNoContentAnim );
       
    92     CleanupStack::PopAndDestroy();  // rrNoContentAnim
       
    93 	iIsBadContentAnimRunning = EFalse;
       
    94 
       
    95 	// Video stopped animation, used to show that video content is stopped
       
    96 	iVideoStoppedAnimation = CAknBitmapAnimation::NewL();
       
    97     iVideoStoppedAnimation->SetContainerWindowL( *this );
       
    98     TResourceReader rrVideoStoppedAnim;
       
    99     iCoeEnv->CreateResourceReaderLC( rrVideoStoppedAnim, R_VIDEO_STOPPED_ANIMATION );
       
   100     iVideoStoppedAnimation->ConstructFromResourceL( rrVideoStoppedAnim );
       
   101     CleanupStack::PopAndDestroy();  // rrVideoStoppedAnim
       
   102 	iIsVideoStoppedAnimRunning = EFalse;
       
   103 
       
   104 	// Video paused animation, used to show that video content is paused
       
   105 	iVideoPausedAnimation = CAknBitmapAnimation::NewL();
       
   106     iVideoPausedAnimation->SetContainerWindowL( *this );
       
   107     TResourceReader rrVideoPausedAnim;
       
   108     iCoeEnv->CreateResourceReaderLC( rrVideoPausedAnim, R_VIDEO_PAUSED_ANIMATION );
       
   109     iVideoPausedAnimation->ConstructFromResourceL( rrVideoPausedAnim );
       
   110     CleanupStack::PopAndDestroy();  // rrVideoPausedAnim
       
   111 	iIsVideoPausedAnimRunning = EFalse;
       
   112 
       
   113 	// Audio playing animation, used when no video is present, only audio
       
   114 	iAudioPlayAnimation = CAknBitmapAnimation::NewL();
       
   115     iAudioPlayAnimation->SetContainerWindowL( *this );
       
   116     TResourceReader rrAudioPlayAnim;
       
   117     iCoeEnv->CreateResourceReaderLC( rrAudioPlayAnim, R_AUDIO_PLAY_ANIMATION );
       
   118     iAudioPlayAnimation->ConstructFromResourceL( rrAudioPlayAnim );
       
   119     CleanupStack::PopAndDestroy();  // rrAudioPlayAnim
       
   120 	iIsAudioPlayAnimRunning = EFalse;
       
   121 	
       
   122 	// Audio stopped animation, used to show that audio content is stopped
       
   123 	iAudioStoppedAnimation = CAknBitmapAnimation::NewL();
       
   124     iAudioStoppedAnimation->SetContainerWindowL( *this );
       
   125     TResourceReader rrAudioStoppedAnim;
       
   126     iCoeEnv->CreateResourceReaderLC( rrAudioStoppedAnim, R_AUDIO_STOPPED_ANIMATION );
       
   127     iAudioStoppedAnimation->ConstructFromResourceL( rrAudioStoppedAnim );
       
   128     CleanupStack::PopAndDestroy();  // rrAudioStoppedAnim
       
   129 	iIsAudioStoppedAnimRunning = EFalse;
       
   130 
       
   131 	// Audio paused animation, used to show that audio content is paused
       
   132 	iAudioPausedAnimation = CAknBitmapAnimation::NewL();
       
   133     iAudioPausedAnimation->SetContainerWindowL( *this );
       
   134     TResourceReader rrAudioPausedAnim;
       
   135     iCoeEnv->CreateResourceReaderLC( rrAudioPausedAnim, R_AUDIO_PAUSED_ANIMATION );
       
   136     iAudioPausedAnimation->ConstructFromResourceL( rrAudioPausedAnim );
       
   137     CleanupStack::PopAndDestroy();  // rrAudioPausedAnim
       
   138 	iIsAudioPausedAnimRunning = EFalse;
       
   139 
       
   140     Log( EFalse, _L("CBavpView::ConstructL - Start Buffering animation") );
       
   141     RunAnimation(iVideoBuffAnimation, iIsVideoBuffAnimRunning);
       
   142 	}
       
   143 
       
   144 // -----------------------------------------------------------------------------
       
   145 // CBavpView::NewL
       
   146 // Two-phased constructor.
       
   147 // -----------------------------------------------------------------------------
       
   148 CBavpView* CBavpView::NewL( const CCoeControl* aParent, 
       
   149                             const TRect& aRect, CBavpPlugin* aBavPlugin )
       
   150     {
       
   151     Log( EFalse, _L("CBavpView::NewL") );
       
   152 
       
   153     CBavpView* self = new( ELeave ) CBavpView;
       
   154     CleanupStack::PushL( self );
       
   155     self->ConstructL( aParent, aRect, aBavPlugin );
       
   156     CleanupStack::Pop( self );
       
   157     return self;
       
   158     }
       
   159 
       
   160 // -----------------------------------------------------------------------------
       
   161 // CBavpView::Destructor
       
   162 // -----------------------------------------------------------------------------
       
   163 CBavpView::~CBavpView()
       
   164     {
       
   165 	Log( EFalse, _L("CBavpView::~CBavpView") );
       
   166 
       
   167 	// Check if the keyhandling is on the stack, if yes, remove it
       
   168 	if ( iIsOnStack )
       
   169 		{
       
   170 		// Check if the animation is active 
       
   171 		// if it is not start animation
       
   172 		iEikonEnv->EikAppUi()->RemoveFromStack( this );
       
   173 		}
       
   174 	
       
   175 	// Cancel video buffering animation, if it's still running
       
   176 	if ( iIsVideoBuffAnimRunning )
       
   177 		{
       
   178 		iVideoBuffAnimation->CancelAnimation();
       
   179 		}
       
   180 	delete iVideoBuffAnimation;
       
   181 
       
   182     // Cancel video stopped animation, if it's still running
       
   183     if ( iIsVideoStoppedAnimRunning )
       
   184         {
       
   185         iVideoStoppedAnimation->CancelAnimation();
       
   186         }
       
   187     delete iVideoStoppedAnimation;
       
   188 
       
   189     // Cancel video paused animation, if it's still running
       
   190     if ( iIsVideoPausedAnimRunning )
       
   191         {
       
   192         iVideoPausedAnimation->CancelAnimation();
       
   193         }
       
   194     delete iVideoPausedAnimation;
       
   195 
       
   196     // Cancel audio only animation, if it's still running
       
   197 	if ( iIsAudioPlayAnimRunning )
       
   198 		{
       
   199 		iAudioPlayAnimation->CancelAnimation();
       
   200 		}
       
   201 	delete iAudioPlayAnimation;
       
   202 
       
   203     // Cancel audio stopped animation, if it's still running
       
   204     if ( iIsAudioStoppedAnimRunning )
       
   205         {
       
   206         iAudioStoppedAnimation->CancelAnimation();
       
   207         }
       
   208     delete iAudioStoppedAnimation;
       
   209 
       
   210     // Cancel audio paused animation, if it's still running
       
   211     if ( iIsAudioPausedAnimRunning )
       
   212         {
       
   213         iAudioPausedAnimation->CancelAnimation();
       
   214         }
       
   215     delete iAudioPausedAnimation;
       
   216 
       
   217     // Cancel bad content animation, if it's still running
       
   218     if ( iIsBadContentAnimRunning )
       
   219         {
       
   220         iBadContentAnimation->CancelAnimation();
       
   221         }
       
   222     delete iBadContentAnimation;
       
   223 
       
   224     iWsSession.Close();
       
   225     }
       
   226 
       
   227 // -----------------------------------------------------------------------------
       
   228 // CBavpView::SizeChanged
       
   229 // Responds to size changes to sets the size and position of the contents of 
       
   230 // this control
       
   231 // -----------------------------------------------------------------------------
       
   232 void CBavpView::SizeChanged()
       
   233     {
       
   234 	Log( EFalse, _L("CBavpView::SizeChanged") );
       
   235 	
       
   236 	if ( iBavpController )
       
   237 		{
       
   238 		iRect = Rect();
       
   239 		iBavpController->RefreshRectCoordinatesL();
       
   240 		}
       
   241     }
       
   242 
       
   243 // -----------------------------------------------------------------------------
       
   244 // CBavpView::AddPluginOptionMenuItemsL
       
   245 // Add the Option Menu items to the menuPane, these will be handled by plugin.
       
   246 // -----------------------------------------------------------------------------
       
   247 void CBavpView::AddPluginOptionMenuItemsL( CEikMenuPane& aMenuPane,
       
   248                                            TInt aCommandBase,
       
   249                                            TInt /*aAfter*/ )
       
   250     {
       
   251 	Log( EFalse, _L("CBavpView::AddPluginOptionMenuItemsL") );
       
   252 
       
   253 	iCommandBase = aCommandBase;
       
   254 	TInt index( 0 );
       
   255 
       
   256 	// The menus are only added, if the controller exists and we're in
       
   257 	// normal screen and not bad content
       
   258 	if ( !iBavpController || iBavpController->IsClipFullScreen() ||
       
   259 	     iBavpController->State() == EBavpBadContent )
       
   260 		{
       
   261 		return;
       
   262 	    }
       
   263 
       
   264     // Display the "Mute" menu item, unless we have HW volume keys, and...
       
   265 	if ( !HAS_HW_VOLUME_KEYS  &&
       
   266 		 !iBavpController->IsVolumeMuted() &&
       
   267 		 !iBavpController->IsClipRewinding() &&
       
   268 		 !iBavpController->IsClipFastForwarding() )
       
   269 		{
       
   270 		InsertOneMenuItemL( aMenuPane, EBavpCmdMuteVolume,
       
   271 		                    R_TEXT_VIDEO_PLUGIN_VOLUME_MUTE, index);
       
   272 		index++;
       
   273 		}
       
   274 
       
   275 	// Check CurrentState to determine the menu items to add
       
   276 	switch ( iBavpController->State() )
       
   277 		{
       
   278 		case EBavpStopped:
       
   279 		case EBavpRewindComplete:
       
   280 		case EBavpPlayComplete:
       
   281 			{
       
   282 			// The content is at the beginning, user can play
       
   283 			InsertOneMenuItemL( aMenuPane, EBavpCmdPlay,
       
   284 			                    R_TEXT_VIDEO_PLUGIN_PLAY, index );
       
   285 			index ++;
       
   286 			break;
       
   287 			}
       
   288 		case EBavpPlaying:
       
   289 			{
       
   290 			// Check if it can be paused
       
   291 			if ( iBavpController->IsClipSeekable() )
       
   292     			{
       
   293 				InsertOneMenuItemL( aMenuPane, EBavpCmdPause,
       
   294 				                    R_TEXT_VIDEO_PLUGIN_PAUSE, index);
       
   295 				index++;
       
   296     			}
       
   297 	
       
   298 			// If playing, user can also stop
       
   299 			InsertOneMenuItemL( aMenuPane, EBavpCmdStop,
       
   300 			                    R_TEXT_VIDEO_PLUGIN_STOP, index );
       
   301 			index++;
       
   302 			// Add FF and Rewind, only if content seekable, local media, video
       
   303 			if ( iBavpController->IsClipSeekable() &&
       
   304 			     iBavpController->IsClipLocalMedia() &&
       
   305 			     iBavpController->IsClipVideo() )
       
   306 				{
       
   307 				InsertOneMenuItemL( aMenuPane, EBavpCmdFastForward,
       
   308 				                    R_TEXT_VIDEO_PLUGIN_FAST_FORWARD, index ); 
       
   309 				index++;
       
   310 				InsertOneMenuItemL( aMenuPane, EBavpCmdRewind,
       
   311 				                    R_TEXT_VIDEO_PLUGIN_REWIND, index );
       
   312 			    index++;
       
   313 				}
       
   314 			// Add full screen, only if video content
       
   315 			if ( iBavpController->IsClipVideo() )
       
   316     			{
       
   317 				InsertOneMenuItemL( aMenuPane, EBavpCmdPlayFullScreen,
       
   318 				                    R_TEXT_VIDEO_PLUGIN_FULL_SCREEN, index );
       
   319 				index++;
       
   320     			}
       
   321 			break;
       
   322 			}
       
   323 		case EBavpPaused:
       
   324 			{
       
   325 			// If paused, user can continue (play) or stop
       
   326 			InsertOneMenuItemL( aMenuPane, EBavpCmdPlay,
       
   327 			                    R_TEXT_VIDEO_PLUGIN_PLAY, index );
       
   328 			index++;
       
   329 			
       
   330 			InsertOneMenuItemL( aMenuPane, EBavpCmdStop,
       
   331 			                    R_TEXT_VIDEO_PLUGIN_STOP, index );
       
   332 			index++;
       
   333 			// Add FF and Rewind, only if content seekable, local media, video
       
   334 			if ( iBavpController->IsClipSeekable() &&
       
   335 			     iBavpController->IsClipLocalMedia() &&
       
   336 			     iBavpController->IsClipVideo() )
       
   337 				{
       
   338 				InsertOneMenuItemL( aMenuPane, EBavpCmdFastForward,
       
   339 				                    R_TEXT_VIDEO_PLUGIN_FAST_FORWARD, index ); 
       
   340 				index++;
       
   341 				InsertOneMenuItemL( aMenuPane, EBavpCmdRewind,
       
   342 				                    R_TEXT_VIDEO_PLUGIN_REWIND, index );
       
   343 			    index++;
       
   344 				}
       
   345 			break;
       
   346 			}
       
   347 		case EBavpFastForwarding:
       
   348 		case EBavpRewinding:
       
   349 			{
       
   350 			// User can play, while FF or Rewinding
       
   351 			InsertOneMenuItemL( aMenuPane, EBavpCmdPlay,
       
   352 			                    R_TEXT_VIDEO_PLUGIN_PLAY, index );
       
   353 			index++;
       
   354 			// Add pause, we should only be fast-forwarding or rewinding
       
   355 			// seekable content, no need to check
       
   356 			InsertOneMenuItemL( aMenuPane, EBavpCmdPause,
       
   357 			                    R_TEXT_VIDEO_PLUGIN_PAUSE, index);
       
   358 			index++;
       
   359 			break;
       
   360 			}
       
   361 		case EBavpFastForwardComplete:
       
   362             {
       
   363 			// Content is at the end, user can replay
       
   364 			InsertOneMenuItemL( aMenuPane, EBavpCmdPlay,
       
   365 			                    R_TEXT_VIDEO_PLUGIN_PLAY, index );
       
   366 			index++;
       
   367 			// Add rewind, we should only be fast-forwarding seekable content,
       
   368 			// no need to check
       
   369 			InsertOneMenuItemL( aMenuPane, EBavpCmdRewind,
       
   370 			                    R_TEXT_VIDEO_PLUGIN_REWIND, index );
       
   371 		    index++;
       
   372 			break;
       
   373             }
       
   374 		default:
       
   375 			{
       
   376 			break;
       
   377 			}
       
   378 		} // End of switch
       
   379 	
       
   380     // Display "Media Volume" menu item, unless we have HW volume keys and...
       
   381 	if ( !HAS_HW_VOLUME_KEYS &&  
       
   382 		 !iBavpController->IsClipRewinding() &&
       
   383 		 !iBavpController->IsClipFastForwarding() )
       
   384 		{
       
   385 		// User can adjust volume
       
   386 		InsertOneMenuItemL( aMenuPane, EBavpCmdChangeVolume,
       
   387 		                    R_TEXT_VIDEO_PLUGIN_MEDIA_VOLUME, index );
       
   388 		}
       
   389     }
       
   390 
       
   391 // -----------------------------------------------------------------------------
       
   392 // CBavpView::HandlePluginCommandL
       
   393 // Handle the user command from the option menu to the plugin.
       
   394 // -----------------------------------------------------------------------------
       
   395 void CBavpView::HandlePluginCommandL( TInt aCommand )
       
   396 	{
       
   397 	iBavpController->HandleCommandL( (TBavpCommandIds)(aCommand - iCommandBase) );
       
   398 	}
       
   399 
       
   400 // -----------------------------------------------------------------------------
       
   401 // CBavpView::OfferKeyEventL
       
   402 // Control framework calls this function to handle the key event
       
   403 // -----------------------------------------------------------------------------
       
   404 TKeyResponse CBavpView::OfferKeyEventL( const TKeyEvent& aKeyEvent,
       
   405                                         TEventCode aType )
       
   406     {
       
   407 	Log( EFalse, _L("CBavpView::OfferKeyEventL") );
       
   408 
       
   409     TKeyResponse keyResponse( EKeyWasNotConsumed );
       
   410     
       
   411 	//Check if the controller is already initialized
       
   412     if (iBavpController)
       
   413         {
       
   414         // Let the Audio or Video controller handle the key presses
       
   415         keyResponse = iBavpController->HandleKeysL( aKeyEvent, aType );    	
       
   416         }
       
   417 	
       
   418 	return keyResponse;
       
   419     }
       
   420 
       
   421 // -----------------------------------------------------------------------------
       
   422 // CBavpView::SetRect
       
   423 // Sets the control's extent, specifying a TRect
       
   424 // -----------------------------------------------------------------------------
       
   425 void CBavpView::SetRect( NPWindow* aWindow )
       
   426     {
       
   427 	Log( EFalse, _L("CBavpView::SetRect") );
       
   428     iWindowRect = TRect(TPoint(aWindow->x, aWindow->y), TSize(aWindow->width, aWindow->height));
       
   429     iClipRect = TRect(aWindow->clipRect.left, aWindow->clipRect.top, aWindow->clipRect.right, aWindow->clipRect.bottom);
       
   430     TRect r(iClipRect);
       
   431     r.Intersection(iWindowRect);
       
   432     TBool flag = iRect != r;
       
   433     iRect = r;
       
   434 	CCoeControl::SetRect( iRect );
       
   435 
       
   436 	// Set the rect only when the animation is playing
       
   437 	if ( iIsVideoBuffAnimRunning && iVideoBuffAnimation && 
       
   438 		 flag)
       
   439     	{
       
   440     	iVideoBuffAnimation->CancelAnimation();
       
   441     	TRect animRect( iWindowRect);
       
   442     	iVideoBuffAnimation->SetRect( animRect );
       
   443     	TRAP_IGNORE( iVideoBuffAnimation->StartAnimationL() );
       
   444     	}
       
   445 	else if ( iIsAudioPlayAnimRunning && iAudioPlayAnimation &&
       
   446     	      flag)
       
   447 	    {
       
   448 		iAudioPlayAnimation->CancelAnimation();
       
   449     	TRect animRect( iWindowRect);
       
   450 		iAudioPlayAnimation->SetRect( animRect );
       
   451 		TRAP_IGNORE( iAudioPlayAnimation->StartAnimationL() );
       
   452         }
       
   453 	else if ( iIsAudioStoppedAnimRunning && iAudioStoppedAnimation &&
       
   454     	      flag)
       
   455 	    {
       
   456 		iAudioStoppedAnimation->CancelAnimation();
       
   457     	TRect animRect( iWindowRect);
       
   458 		iAudioStoppedAnimation->SetRect( animRect );
       
   459 		TRAP_IGNORE( iAudioStoppedAnimation->StartAnimationL() );
       
   460         }
       
   461 	else if ( iIsAudioPausedAnimRunning && iAudioPausedAnimation &&
       
   462     	      flag)
       
   463 	    {
       
   464 		iAudioPausedAnimation->CancelAnimation();
       
   465     	TRect animRect( iWindowRect);
       
   466 		iAudioPausedAnimation->SetRect( animRect );
       
   467 		TRAP_IGNORE( iAudioPausedAnimation->StartAnimationL() );
       
   468         }
       
   469 	else if ( iIsVideoStoppedAnimRunning && iVideoStoppedAnimation &&
       
   470     	      flag)
       
   471 	    {
       
   472 		iVideoStoppedAnimation->CancelAnimation();
       
   473     	TRect animRect( iWindowRect);
       
   474 		iVideoStoppedAnimation->SetRect( animRect );
       
   475 		TRAP_IGNORE( iVideoStoppedAnimation->StartAnimationL() );
       
   476         }
       
   477 	else if ( iIsVideoPausedAnimRunning && iVideoPausedAnimation &&
       
   478     	      flag)
       
   479 	    {
       
   480 		iVideoPausedAnimation->CancelAnimation();
       
   481     	TRect animRect( iWindowRect);
       
   482 		iVideoPausedAnimation->SetRect( animRect );
       
   483 		TRAP_IGNORE( iVideoPausedAnimation->StartAnimationL() );
       
   484         }
       
   485 	else if ( iIsBadContentAnimRunning && iBadContentAnimation &&
       
   486     	      flag)
       
   487 	    {
       
   488 		iBadContentAnimation->CancelAnimation();
       
   489     	TRect animRect( iWindowRect);
       
   490 		iBadContentAnimation->SetRect( animRect );
       
   491 		TRAP_IGNORE( iBadContentAnimation->StartAnimationL() );
       
   492         }
       
   493     }
       
   494 
       
   495 // -----------------------------------------------------------------------------
       
   496 // CBavpView::IsTopWindow
       
   497 // Return ETrue if the CCoeControl is the top window instance
       
   498 // -----------------------------------------------------------------------------
       
   499 TBool CBavpView::IsTopWindowL()
       
   500     {
       
   501 	Log( EFalse, _L("CBavpView::IsTopWindowL") );
       
   502 
       
   503     TBool ret( EFalse );
       
   504 	TInt numWg( iWsSession.NumWindowGroups() );
       
   505     CArrayFixFlat<TInt>* wgList = new (ELeave) CArrayFixFlat<TInt>( numWg );
       
   506     
       
   507     // Check if our window is front or not
       
   508     if ( iWsSession.WindowGroupList( 0, wgList ) == KErrNone )
       
   509         {
       
   510         ret = ( iWindowId == wgList->At(0) );
       
   511         }
       
   512     else
       
   513         {
       
   514         ret = EFalse;
       
   515         }
       
   516 
       
   517     delete wgList;
       
   518     return ret;
       
   519     }
       
   520 
       
   521 // -----------------------------------------------------------------------------
       
   522 // CBavpView::UpdateView
       
   523 // Check animation running status, display the animated image if the video
       
   524 // player is not playing
       
   525 // -----------------------------------------------------------------------------
       
   526 void CBavpView::UpdateView()
       
   527     {
       
   528 	Log( EFalse, _L("CBavpView::UpdateView") );
       
   529 
       
   530   	// Handle the bad content case, ie MMF reports an error that needs to
       
   531    	// be displayed to the user. (loss of network or bad content)
       
   532 	if ( iBavpController->State() == EBavpBadContent && !iIsBadContentAnimRunning )
       
   533 	    {
       
   534     	Log( EFalse, _L("CBavpView::UpdateView - Bad Content") );		
       
   535 		RunAnimation( iBadContentAnimation, iIsBadContentAnimRunning );
       
   536 	    }
       
   537     // Handle the beffering content state
       
   538 	else if ( iBavpController->State() == EBavpBuffering && !iIsVideoBuffAnimRunning )
       
   539 		{
       
   540     	Log( EFalse, _L("CBavpView::UpdateView - Buffering media") );
       
   541         RunAnimation( iVideoBuffAnimation, iIsVideoBuffAnimRunning );
       
   542 		}
       
   543     // Handle the video animations states
       
   544     else if ( iBavpController->IsClipVideo() )
       
   545         {
       
   546        	Log( EFalse, _L("CBavpView::UpdateView - We got Video") );
       
   547     	if ( iBavpController->State() == EBavpPlaying )
       
   548     		{
       
   549         	Log( EFalse, _L("CBavpView::UpdateView - Video Playing, stop animation") );
       
   550         	TBool flag( EFalse );
       
   551             RunAnimation( NULL, flag );
       
   552     		}
       
   553     	else if ( iBavpController->State() == EBavpStopped && !iIsVideoStoppedAnimRunning )
       
   554     		{
       
   555         	Log( EFalse, _L("CBavpView::UpdateView - Video Stopped") );
       
   556             RunAnimation( iVideoStoppedAnimation, iIsVideoStoppedAnimRunning );
       
   557     		}
       
   558     	else if ( iBavpController->State() == EBavpPaused && !iIsVideoPausedAnimRunning )
       
   559     		{
       
   560         	Log( EFalse, _L("CBavpView::UpdateView - Video Paused") );
       
   561             RunAnimation( iVideoPausedAnimation, iIsVideoPausedAnimRunning );
       
   562     		}
       
   563    		}
       
   564     // Handle the audio animations states
       
   565     else 
       
   566         {
       
   567        	Log( EFalse, _L("CBavpView::UpdateView - We got Audio") );
       
   568     	if ( iBavpController->State() == EBavpPlaying && !iIsAudioPlayAnimRunning )
       
   569     		{
       
   570         	Log( EFalse, _L("CBavpView::UpdateView - Audio Playing") );
       
   571             RunAnimation( iAudioPlayAnimation, iIsAudioPlayAnimRunning );
       
   572     		}
       
   573     	else if ( iBavpController->State() == EBavpStopped ||
       
   574     	          iBavpController->State() == EBavpPlayComplete &&
       
   575     	          !iIsAudioStoppedAnimRunning )
       
   576     	    {
       
   577         	Log( EFalse, _L("CBavpView::UpdateView - Audio Stopped") );
       
   578             RunAnimation( iAudioStoppedAnimation, iIsAudioStoppedAnimRunning );
       
   579     	    }
       
   580     	else if ( iBavpController->State() == EBavpPaused && !iIsAudioPausedAnimRunning )
       
   581     		{
       
   582         	Log( EFalse, _L("CBavpView::UpdateView - Audio Paused") );
       
   583             RunAnimation( iAudioPausedAnimation, iIsAudioPausedAnimRunning );
       
   584     		}
       
   585         }
       
   586     }
       
   587 
       
   588 // -----------------------------------------------------------------------------
       
   589 // CBavpView::FocusChanged
       
   590 // This method is called once CCoeControl::SetFocus is called, could be when
       
   591 // BavpPlugin::NotifyL causes SetFocus to be called
       
   592 // -----------------------------------------------------------------------------
       
   593 void CBavpView::FocusChanged( TDrawNow /*aDrawNow*/ )
       
   594     {
       
   595     iBavpController->BavpFocusChanged( IsFocused() );
       
   596     }
       
   597 
       
   598 // -----------------------------------------------------------------------------
       
   599 // CBavpView::Draw
       
   600 // This method is called by CCoeControl::Draw
       
   601 // -----------------------------------------------------------------------------
       
   602 void CBavpView::Draw( const TRect& aRect ) const
       
   603     {
       
   604     
       
   605     if (iBavpController && !iBavpController->IsClipFullScreen()) {
       
   606     if ( Window().DisplayMode() == EColor16MA )
       
   607         {
       
   608         Log( EFalse, _L("BavpView::Draw() - DisplayMode=EColor16MA") );
       
   609         CWindowGc& gc = SystemGc();
       
   610         gc.SetDrawMode( CGraphicsContext::EDrawModeWriteAlpha );
       
   611 #ifdef _DEBUG
       
   612         gc.SetBrushColor(TRgb::Color16MA(0x0000ff00));
       
   613 #else        
       
   614         gc.SetBrushColor( TRgb::Color16MA(0) );
       
   615 #endif        
       
   616         gc.Clear( aRect );
       
   617         }
       
   618     
       
   619         if (iBavpController->IsClipLocalMedia() && iBavpController->IsClipSeekable()) {
       
   620         if (iBavpController->State() == EBavpPlayComplete) {
       
   621           TRAP_IGNORE(iBavpController->setPositionL(iBavpController->Duration()));
       
   622         }
       
   623         else if (iBavpController->State() == EBavpPaused) {
       
   624           TRAP_IGNORE(iBavpController->setPositionL(iBavpController->getPositionL()));
       
   625         }
       
   626     }
       
   627         }        
       
   628         
       
   629     }
       
   630 
       
   631 // -----------------------------------------------------------------------------
       
   632 // CBavpView::ControllerStateChangedL
       
   633 // Check animation running status and the display screen mode
       
   634 // -----------------------------------------------------------------------------
       
   635 void CBavpView::ControllerStateChangedL()
       
   636     {
       
   637 	Log( EFalse, _L("CBavpView::ControllerStateChangedL") );
       
   638 	
       
   639 	// If not in full screen mode and if it is on the stack, then remove
       
   640 	// from the stack
       
   641 	if ( !iBavpController->IsClipFullScreen() && iIsOnStack )
       
   642 		{
       
   643 		iIsOnStack = EFalse;
       
   644 		iEikonEnv->EikAppUi()->RemoveFromStack( this );
       
   645 		}
       
   646 	else if ( iBavpController->IsClipFullScreen() && !iIsOnStack )
       
   647 		{
       
   648 		// If full screen mode and not on stack, add to stack
       
   649 		iIsOnStack = ETrue;
       
   650 		iEikonEnv->EikAppUi()->AddToStackL( this );
       
   651 		}
       
   652     }
       
   653 
       
   654 // -----------------------------------------------------------------------------
       
   655 // CBavpView::InsertOneMenuItemL
       
   656 // Insert one menu item
       
   657 // -----------------------------------------------------------------------------
       
   658 void CBavpView::InsertOneMenuItemL( CEikMenuPane& aMenuPane, TInt aCommand,
       
   659                                     TInt aResourceId, TInt index )
       
   660     {
       
   661 	Log( EFalse, _L("CBavpView::InsertOneMenuItemL") );
       
   662 
       
   663     CEikMenuPaneItem::SData item;
       
   664     HBufC* buf = StringLoader::LoadLC( aResourceId );
       
   665     item.iText.Copy( *buf );
       
   666     CleanupStack::PopAndDestroy();  // buf
       
   667     buf = NULL;
       
   668 
       
   669     item.iCommandId = aCommand + iCommandBase;
       
   670     item.iFlags = 0;
       
   671     item.iCascadeId = 0;
       
   672     aMenuPane.InsertMenuItemL( item, index );
       
   673     }
       
   674 
       
   675 // -----------------------------------------------------------------------------
       
   676 // CBavpView::RunAnimation
       
   677 // Run the animation specified, and stop all the other animations
       
   678 // If the animation and run flag are NULL, we stop all animations
       
   679 // Check if animation is already running, if so don't stop, this causes flicker
       
   680 // -----------------------------------------------------------------------------
       
   681 void CBavpView::RunAnimation( CAknBitmapAnimation* aAnimation,
       
   682                               TBool &aAnimRunning )
       
   683     {
       
   684 	Log( EFalse, _L("CBavpView::RunAnimation") );
       
   685 	// Display the animation specified, after cancelling any
       
   686 	// other animations first.
       
   687 	//
       
   688     // Stop the video buffering animation
       
   689     if ( iIsVideoBuffAnimRunning && iVideoBuffAnimation != aAnimation )
       
   690 		{
       
   691     	Log( EFalse, _L("CBavpView::RunAnimation - cancel VideoBuffAnimation") );
       
   692 		iVideoBuffAnimation->CancelAnimation();
       
   693 		iIsVideoBuffAnimRunning = EFalse;
       
   694 		}
       
   695 	else if ( iIsVideoStoppedAnimRunning && iVideoStoppedAnimation != aAnimation  )
       
   696 	    {
       
   697 		// Stop the video stopped animation
       
   698     	Log( EFalse, _L("CBavpView::RunAnimation - cancel VideoStoppedAnimation") );
       
   699 		iVideoStoppedAnimation->CancelAnimation();
       
   700 		iIsVideoStoppedAnimRunning = EFalse;
       
   701 	    }
       
   702 	else if ( iIsVideoPausedAnimRunning && iVideoPausedAnimation != aAnimation  )
       
   703 	    {
       
   704 		// Stop the video paused animation
       
   705     	Log( EFalse, _L("CBavpView::RunAnimation - cancel VideoPausedAnimation") );
       
   706 		iVideoPausedAnimation->CancelAnimation();
       
   707 		iIsVideoPausedAnimRunning = EFalse;
       
   708 	    }
       
   709 	else if ( iIsAudioPlayAnimRunning && iAudioPlayAnimation != aAnimation  )
       
   710 		{
       
   711     	// Stop the audio playing animation
       
   712     	Log( EFalse, _L("CBavpView::RunAnimation - cancel AudioPlayAnimation") );
       
   713 		iAudioPlayAnimation->CancelAnimation();
       
   714 		iIsAudioPlayAnimRunning = EFalse;
       
   715 		}
       
   716 	else if ( iIsAudioStoppedAnimRunning && iAudioStoppedAnimation != aAnimation  )
       
   717 	    {
       
   718 		// Stop the audio stopped animation
       
   719     	Log( EFalse, _L("CBavpView::RunAnimation - cancel AudioStoppedAnimation") );
       
   720 		iAudioStoppedAnimation->CancelAnimation();
       
   721 		iIsAudioStoppedAnimRunning = EFalse;
       
   722 	    }
       
   723 	else if ( iIsAudioPausedAnimRunning && iAudioPausedAnimation != aAnimation  )
       
   724 	    {
       
   725 		// Stop the audio paused animation
       
   726     	Log( EFalse, _L("CBavpView::RunAnimation - cancel AudioPausedAnimation") );
       
   727 		iAudioPausedAnimation->CancelAnimation();
       
   728 		iIsAudioPausedAnimRunning = EFalse;
       
   729 	    }
       
   730 	else if ( iIsBadContentAnimRunning && iBadContentAnimation != aAnimation  )
       
   731 	    {
       
   732 		// Stop the bad content animation
       
   733     	Log( EFalse, _L("CBavpView::RunAnimation - cancel BadContentAnimation") );
       
   734 		iBadContentAnimation->CancelAnimation();
       
   735 		iIsBadContentAnimRunning = EFalse;
       
   736 	    }
       
   737 	    
       
   738 	// Now, start the animation specified, if it isn't already running.
       
   739 	// If the animation and run flag are NULL, we don't start any animations.
       
   740 	if ( aAnimation && !aAnimRunning )
       
   741 		{
       
   742     	Log( EFalse, _L("CBavpView::RunAnimation - start new animation") );
       
   743 	    if ( aAnimation->Rect().Size() != iRect.Size() )
       
   744 			{
       
   745         	TRect animRect( iWindowRect);
       
   746 			aAnimation->SetRect( animRect );
       
   747 			}
       
   748 		TRAP_IGNORE
       
   749 		(
       
   750 		aAnimation->StartAnimationL();
       
   751 		aAnimRunning = ETrue;
       
   752         );
       
   753 		}
       
   754 
       
   755     }
       
   756 
       
   757 
       
   758 void CBavpView::HandlePointerEventL(const TPointerEvent &aPointerEvent)
       
   759     {
       
   760     /*
       
   761      * Plugin is sending all pointer events to the browser.
       
   762      * Browser will process them to gesture and return back using
       
   763      * event() function. (see PluginWin::HandleGesture(), BavpEvent() and
       
   764      * CBavpPlugin::HandleGesture().
       
   765      * Browser expects event position to be in absolute co-ordinates,
       
   766      * so we convert position of the pointer event here.
       
   767      */
       
   768     TPoint point(aPointerEvent.iPosition  + PositionRelativeToScreen());
       
   769     NPNetscapeFuncs* funcs = iBavPlugin->getNPNFuncs();
       
   770 #ifdef BRDO_MULTITOUCH_ENABLED_FF
       
   771     if (aPointerEvent.IsAdvancedPointerEvent()) {
       
   772         TAdvancedPointerEvent tadvp = *(static_cast<const TAdvancedPointerEvent *>(&aPointerEvent));
       
   773         tadvp.iPosition = point;
       
   774         if(funcs && funcs->setvalue) {
       
   775             (funcs->setvalue)(iBavPlugin->getNPP(), 
       
   776                                 (NPPVariable) NPPVPluginPointerEvent,
       
   777                                 (void*) &(tadvp));
       
   778         }
       
   779 
       
   780     }
       
   781     else {
       
   782 #endif 	
       
   783         TPointerEvent event(aPointerEvent);
       
   784         event.iPosition = point;
       
   785         if(funcs && funcs->setvalue) {
       
   786             (funcs->setvalue)(iBavPlugin->getNPP(), 
       
   787                                 (NPPVariable) NPPVPluginPointerEvent,
       
   788                                 (void*) &(event));
       
   789       }
       
   790 #ifdef BRDO_MULTITOUCH_ENABLED_FF	  
       
   791     }
       
   792 #endif 	
       
   793  
       
   794     }
       
   795 
       
   796 //  End of File