browserui/browser/BrowserAppSrc/BrowserWindowManager.cpp
changeset 51 48e827313edd
parent 37 481242ead638
child 53 f427d27b98d8
equal deleted inserted replaced
37:481242ead638 51:48e827313edd
     1 /*
       
     2 * Copyright (c) 2002 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: 
       
    15 *     Multiple Windows' WindowManager.
       
    16 *
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include "BrowserWindowManager.h"
       
    23 #include "BrowserWindow.h"
       
    24 #include "BrowserWindowQueue.h"
       
    25 #include "BrowserContentView.h"
       
    26 #include "WindowInfoProvider.h"
       
    27 #include "Logger.h"
       
    28 #include "Preferences.h"
       
    29 #include "Display.h"
       
    30 #include "ApiProvider.h"
       
    31 #include <brctldefs.h>
       
    32 #include "BrowserUtil.h"
       
    33 #include <BrowserNG.rsg>
       
    34 #include <StringLoader.h>
       
    35 #include <AknQueryDialog.h>
       
    36 
       
    37 
       
    38 // -----------------------------------------------------------------------------
       
    39 // CBrowserWindowQue::LastItem()
       
    40 // -----------------------------------------------------------------------------
       
    41 //
       
    42 CBrowserWindowQue* CBrowserWindowQue::LastItem() const
       
    43     {
       
    44     // remove 'const' modifier from 'this' in a const member function
       
    45     CBrowserWindowQue* a = CONST_CAST( CBrowserWindowQue*, this );
       
    46     for( ; a->iNext; a=a->iNext)
       
    47         ;
       
    48     return a;
       
    49     }
       
    50 
       
    51 // -----------------------------------------------------------------------------
       
    52 // CBrowserWindowQue::~CBrowserWindowQue()
       
    53 // -----------------------------------------------------------------------------
       
    54 //
       
    55 CBrowserWindowQue::~CBrowserWindowQue()
       
    56     {
       
    57 LOG_ENTERFN("WindowQue::~WindowQue");
       
    58     if( this->iPrev )
       
    59         {
       
    60 		BROWSER_LOG( ( _L( "iPrev" ) ) );
       
    61         this->iPrev->iNext = this->iNext;
       
    62         }
       
    63     if( this->iNext )
       
    64         {
       
    65 		BROWSER_LOG( ( _L( "iNext" ) ) );
       
    66         this->iNext->iPrev = this->iPrev;
       
    67         }
       
    68     delete iWindow;
       
    69     iWindow = NULL;
       
    70     }
       
    71 
       
    72 // -----------------------------------------------------------------------------
       
    73 // CBrowserWindowQue::AppendL()
       
    74 // -----------------------------------------------------------------------------
       
    75 //
       
    76 void CBrowserWindowQue::AppendL( CBrowserWindowQue* aItem )
       
    77     {
       
    78 	__ASSERT_DEBUG( (aItem != NULL), Util::Panic( Util::EUninitializedData ));
       
    79     aItem->iPrev = LastItem();
       
    80     aItem->iPrev->iNext = aItem;
       
    81     }
       
    82 
       
    83 // -----------------------------------------------------------------------------
       
    84 // CBrowserWindowQue::Next()
       
    85 // -----------------------------------------------------------------------------
       
    86 //
       
    87 CBrowserWindowQue* CBrowserWindowQue::Next() const
       
    88     {
       
    89     CBrowserWindowQue* b = this->iNext;
       
    90     while( b && (b->iStatus & CBrowserWindowQue::EWindowDeleted ) )
       
    91         {
       
    92         b = b->iNext;
       
    93         }
       
    94     return b;
       
    95     }
       
    96 
       
    97 // -----------------------------------------------------------------------------
       
    98 // CBrowserWindowQue::Prev()
       
    99 // -----------------------------------------------------------------------------
       
   100 //
       
   101 CBrowserWindowQue* CBrowserWindowQue::Prev() const
       
   102     {
       
   103     CBrowserWindowQue* b = this->iPrev;
       
   104     while( b && (b->iStatus & CBrowserWindowQue::EWindowDeleted ) )
       
   105         {
       
   106         b = b->iPrev;
       
   107         }
       
   108     return b;
       
   109     }
       
   110 
       
   111 // -----------------------------------------------------------------------------
       
   112 // CBrowserWindowManager::
       
   113 // -----------------------------------------------------------------------------
       
   114 // initialization of static member variable
       
   115 TInt CBrowserWindowManager::iWindowIdGenerator( 0 );
       
   116 
       
   117 // -----------------------------------------------------------------------------
       
   118 // CBrowserWindowManager::NewLC()
       
   119 // -----------------------------------------------------------------------------
       
   120 //
       
   121 CBrowserWindowManager* CBrowserWindowManager::NewLC(
       
   122         MApiProvider& aApiProvider,
       
   123         CBrowserContentView& aContentView,
       
   124         TInt aMaxWindowCount )
       
   125     {
       
   126     CBrowserWindowManager* self = new (ELeave)
       
   127         CBrowserWindowManager( aApiProvider, aContentView, aMaxWindowCount );
       
   128     CleanupStack::PushL( self );
       
   129     self->ConstructL();
       
   130     return self;
       
   131     }
       
   132 
       
   133 // -----------------------------------------------------------------------------
       
   134 // CBrowserWindowManager::NewL()
       
   135 // -----------------------------------------------------------------------------
       
   136 //
       
   137 CBrowserWindowManager* CBrowserWindowManager::NewL(
       
   138         MApiProvider& aApiProvider,
       
   139         CBrowserContentView& aContentView,
       
   140         TInt aMaxWindowCount )
       
   141     {
       
   142     CBrowserWindowManager* self = CBrowserWindowManager::NewLC(
       
   143         aApiProvider, aContentView, aMaxWindowCount );
       
   144     CleanupStack::Pop( self );
       
   145     return self;
       
   146     }
       
   147 
       
   148 // -----------------------------------------------------------------------------
       
   149 // CBrowserWindowManager::~CBrowserWindowManager()
       
   150 // -----------------------------------------------------------------------------
       
   151 //
       
   152 CBrowserWindowManager::~CBrowserWindowManager( )
       
   153     {
       
   154 LOG_ENTERFN("WindowManager::~WindowManager");
       
   155     // Preferences must exist!
       
   156     if(iApiProvider!=NULL)
       
   157     	{
       
   158     	iApiProvider->Preferences().RemoveObserver( this );
       
   159     	}
       
   160     RemoveObserver(iContentView);
       
   161     CBrowserWindowQue *window = iWindowQueue;
       
   162     CBrowserWindowQue *temp = NULL;
       
   163 
       
   164 
       
   165     TBool isStandAlone( !iApiProvider->IsEmbeddedModeOn() );
       
   166     if ( ( isStandAlone && !iUserExit ) || ( !isStandAlone ) )
       
   167         {
       
   168         TRAP_IGNORE( window->iWindow->BrCtlInterface().HandleCommandL(
       
   169             (TInt)TBrCtlDefs::ECommandSaveLaunchParams + (TInt)TBrCtlDefs::ECommandIdBase ) );
       
   170         }
       
   171 
       
   172     for(; window; )
       
   173         {
       
   174         temp = window;
       
   175         window = window->iNext;
       
   176         DeleteOneWindowL( temp->iWindow->WindowId() );
       
   177         /*delete temp; 
       
   178         temp = NULL;*/
       
   179         }
       
   180         RemoveDeletedWindowsL();
       
   181     delete iObservers;
       
   182     iObservers = NULL;
       
   183     }
       
   184 
       
   185 // -----------------------------------------------------------------------------
       
   186 // CBrowserWindowManager::WindowCount()
       
   187 // -----------------------------------------------------------------------------
       
   188 //
       
   189 TInt CBrowserWindowManager::WindowCount() const
       
   190     {
       
   191     return iWindowCount - iDeletedWindowCount;
       
   192     }
       
   193 
       
   194 // -----------------------------------------------------------------------------
       
   195 // CBrowserWindowManager::CBrowserWindowManager()
       
   196 // -----------------------------------------------------------------------------
       
   197 //
       
   198 CBrowserWindowManager::CBrowserWindowManager(
       
   199         MApiProvider& aApiProvider,
       
   200         CBrowserContentView& aContentView,
       
   201         TInt aMaxWindowCount ) :
       
   202     iApiProvider( &aApiProvider ),
       
   203     iContentView( &aContentView),
       
   204     iMaxWindowCount( aMaxWindowCount ),
       
   205     iWindowCount( 0 ),
       
   206     iDeletedWindowCount( 0 ),
       
   207     iWindowQueue( NULL ),
       
   208     iCurrentWindow( NULL ),
       
   209     iUserExit( EFalse ),
       
   210     iIsContentExist( EFalse )
       
   211     {
       
   212     }
       
   213 
       
   214 // -----------------------------------------------------------------------------
       
   215 // CBrowserWindowManager::ConstructL()
       
   216 // -----------------------------------------------------------------------------
       
   217 //
       
   218 void CBrowserWindowManager::ConstructL( )
       
   219     {
       
   220     iApiProvider->Preferences().AddObserverL( this );
       
   221     CreateWindowL( 0, &KNullDesC );
       
   222     iCurrentWindow = iWindowQueue;
       
   223     // don't draw anything, just activate it
       
   224     iCurrentWindow->iWindow->ActivateL( EFalse );
       
   225     iObservers = new ( ELeave ) CArrayPtrFlat< MWindowObserver >( 1 );
       
   226     AddObserverL(iContentView);
       
   227     }
       
   228 
       
   229 // -----------------------------------------------------------------------------
       
   230 // CBrowserWindowManager::Window()
       
   231 // -----------------------------------------------------------------------------
       
   232 //
       
   233 TInt CBrowserWindowManager::Window(
       
   234         TInt aWindowId,
       
   235         CBrowserWindow*& aWindow )
       
   236     {
       
   237     RemoveDeletedWindowsL();
       
   238     CBrowserWindowQue *windowQue = NULL;
       
   239     TInt error( Window( aWindowId, windowQue, iWindowQueue ) );
       
   240     if( windowQue )
       
   241         {
       
   242         aWindow = windowQue->iWindow;
       
   243         }
       
   244     return error;
       
   245     }
       
   246 
       
   247 // -----------------------------------------------------------------------------
       
   248 // CBrowserWindowManager::FindWindowL()
       
   249 // -----------------------------------------------------------------------------
       
   250 //
       
   251 CBrowserWindow* CBrowserWindowManager::FindWindowL(
       
   252         const TDesC& aTargetName )
       
   253     {
       
   254 LOG_ENTERFN("WindowManager::FindWindowL( Target )");
       
   255     RemoveDeletedWindowsL();
       
   256     CBrowserWindow* result = NULL;
       
   257     CBrowserWindow* window = NULL;
       
   258     CBrowserWindowQue *windowQue = iWindowQueue;
       
   259     for( ; windowQue; windowQue = windowQue->Next() )
       
   260         {
       
   261         window = windowQue->iWindow;
       
   262         if( window->TargetName()->Compare( aTargetName ) == 0 )
       
   263             {
       
   264             result = window;
       
   265             }
       
   266         }
       
   267     return result;
       
   268     }
       
   269 
       
   270 // -----------------------------------------------------------------------------
       
   271 // CBrowserWindowManager::CurrentWindow()
       
   272 // -----------------------------------------------------------------------------
       
   273 //
       
   274 CBrowserWindow* CBrowserWindowManager::CurrentWindow() const
       
   275     {
       
   276     if( iCurrentWindow )
       
   277         {
       
   278         return iCurrentWindow->iWindow;
       
   279         }
       
   280     else
       
   281         {
       
   282         return NULL;
       
   283         }
       
   284     }
       
   285 	
       
   286 // -----------------------------------------------------------------------------
       
   287 // CBrowserWindowManager::CurrentWindowQue()
       
   288 // -----------------------------------------------------------------------------
       
   289 //
       
   290 CBrowserWindowQue* CBrowserWindowManager::CurrentWindowQue() const
       
   291     {
       
   292     if( iCurrentWindow )
       
   293         {
       
   294         return iCurrentWindow;
       
   295         }
       
   296     else
       
   297         {
       
   298         return NULL;
       
   299         }
       
   300     }
       
   301 
       
   302 // -----------------------------------------------------------------------------
       
   303 // CBrowserWindowManager::GetWindowInfoL()
       
   304 // -----------------------------------------------------------------------------
       
   305 //
       
   306 CArrayFixFlat<CWindowInfo*>* CBrowserWindowManager::GetWindowInfoL(
       
   307         MWindowInfoProvider* aWindowInfo )
       
   308     {
       
   309 	__ASSERT_DEBUG( (aWindowInfo != NULL), Util::Panic( Util::EUninitializedData ));
       
   310 
       
   311     RemoveDeletedWindowsL();
       
   312     CBrowserWindowQue* window = iWindowQueue;
       
   313     CArrayFixFlat<CWindowInfo*>* windowInfoList = new (ELeave)
       
   314         CArrayFixFlat<CWindowInfo*>( 3 /* KGranularityMedium */ );
       
   315     CleanupStack::PushL( windowInfoList );
       
   316     for( ; window; window = window->Next() )
       
   317         {
       
   318         // create window info text by client
       
   319         HBufC* buf = aWindowInfo->CreateWindowInfoLC( *( window->iWindow ) );
       
   320 
       
   321         if (!buf)
       
   322         {
       
   323 	  		CleanupStack::PopAndDestroy( buf );
       
   324      		buf = KNullDesC().AllocLC();
       
   325         }
       
   326 
       
   327         // create window info( text, id, current )
       
   328         CWindowInfo* windowInfo = new ( ELeave ) CWindowInfo(
       
   329           	buf, window->iWindow->WindowId(), iCurrentWindow == window );
       
   330 
       
   331         CleanupStack::Pop( buf );
       
   332 
       
   333         // append to list
       
   334         windowInfoList->AppendL( windowInfo );
       
   335 
       
   336         }
       
   337 
       
   338     CleanupStack::Pop( windowInfoList );
       
   339     return windowInfoList;
       
   340     }
       
   341 
       
   342 // -----------------------------------------------------------------------------
       
   343 // CBrowserWindowManager::AddObserver()
       
   344 // -----------------------------------------------------------------------------
       
   345 //
       
   346 void CBrowserWindowManager::AddObserverL( MWindowObserver* aObserver )
       
   347     {
       
   348     LOG_ENTERFN("CBrowserWindowManager::AddObserver");
       
   349     if ( iObservers )
       
   350         {
       
   351         iObservers->AppendL( aObserver );
       
   352         }
       
   353     }
       
   354 
       
   355 // -----------------------------------------------------------------------------
       
   356 // CBrowserWindowManager::RemoveObserver()
       
   357 // -----------------------------------------------------------------------------
       
   358 //
       
   359 void CBrowserWindowManager::RemoveObserver( MWindowObserver* aObserver )
       
   360     {
       
   361     LOG_ENTERFN("CBrowserWindowManager::RemoveObserver");
       
   362     TInt i( 0 );
       
   363     TInt count = iObservers->Count();
       
   364     for ( i = 0; i < count; i++ )
       
   365         {
       
   366         if ( iObservers->At( i ) == aObserver )
       
   367             {
       
   368             iObservers->Delete( i );
       
   369             break;
       
   370             }
       
   371         }
       
   372     }
       
   373 
       
   374 // -----------------------------------------------------------------------------
       
   375 // CBrowserWindowManager::NotifyObservers()
       
   376 // -----------------------------------------------------------------------------
       
   377 //
       
   378 void CBrowserWindowManager::NotifyObserversL( TWindowEvent aEvent, TInt aWindowId )
       
   379     {
       
   380     LOG_ENTERFN("CBrowserWindowManager::NotifyObservers");
       
   381     if ( iObservers )
       
   382         {
       
   383         TInt i;
       
   384         TInt count = iObservers->Count();
       
   385 
       
   386         if ( count )
       
   387             {
       
   388             for ( i = 0; i < count; i++ )
       
   389                 {
       
   390                 iObservers->At( i )->WindowEventHandlerL( aEvent, aWindowId );
       
   391                 }
       
   392             }
       
   393         }
       
   394     }
       
   395 
       
   396 // -----------------------------------------------------------------------------
       
   397 // CBrowserWindowManager::CreateWindowL()
       
   398 // -----------------------------------------------------------------------------
       
   399 //
       
   400 CBrowserWindow* CBrowserWindowManager::CreateWindowL(
       
   401         TInt aParentId,
       
   402         const TDesC* aTargetName )
       
   403     {
       
   404 PERFLOG_LOCAL_INIT
       
   405 PERFLOG_STOPWATCH_START
       
   406 LOG_ENTERFN("WindowManager::CreateWindowL");
       
   407     RemoveDeletedWindowsL();
       
   408     if( WindowCount() >= iMaxWindowCount )
       
   409         {
       
   410         HBufC* maxWinsReached = StringLoader::LoadLC(R_BROWSER_NOTE_MAX_WINDOWS);
       
   411 	  	ApiProvider()->DialogsProvider().DialogNoteL( *maxWinsReached );
       
   412 	  	CleanupStack::PopAndDestroy( maxWinsReached );
       
   413         return NULL;
       
   414         }
       
   415     CBrowserWindow* window = NULL;
       
   416     // search for already existing window
       
   417     Window( aParentId, aTargetName, window, iWindowQueue );  // error is ignored
       
   418     if( window )
       
   419         {
       
   420 
       
   421         return window;
       
   422         }
       
   423     window = CBrowserWindow::NewLC( ++iWindowIdGenerator, aTargetName, this );
       
   424 BROWSER_LOG( ( _L( "Window is created, ID: %d, windowCount: %d" ),
       
   425     window->WindowId(), WindowCount ) );
       
   426     // create a WindowQue instance initiated by the new window
       
   427     CBrowserWindowQue *windowQue = new (ELeave) CBrowserWindowQue( window );
       
   428     CleanupStack::PushL( windowQue );
       
   429     // and set window's parent
       
   430     TInt error2( Window( aParentId, windowQue->iParent, iWindowQueue ) );
       
   431 BROWSER_LOG( ( _L( "error2: %d" ), error2 ) );
       
   432     // append window to the list
       
   433     if( iWindowQueue )
       
   434         {
       
   435         BROWSER_LOG( ( _L( "window queue not empty" ) ) );
       
   436         iWindowQueue->AppendL( windowQue );
       
   437         }
       
   438     else
       
   439         {
       
   440         BROWSER_LOG( ( _L( "window queue empty" ) ) );
       
   441         iWindowQueue = windowQue;
       
   442         }
       
   443     CleanupStack::Pop( windowQue );
       
   444 
       
   445     // window is created and append to the list successfully
       
   446     ++iWindowCount;
       
   447 
       
   448     CleanupStack::Pop( window );
       
   449     NotifyObserversL( EWindowOpen, window->WindowId() );
       
   450 
       
   451     // window is activated by the client
       
   452 PERFLOG_STOP_WRITE("****CreateWindowL***")
       
   453     return window;
       
   454     }
       
   455 
       
   456 // -----------------------------------------------------------------------------
       
   457 // CBrowserWindowManager::DeleteWindowL()
       
   458 // -----------------------------------------------------------------------------
       
   459 //
       
   460 TInt CBrowserWindowManager::DeleteWindowL(
       
   461         TInt aWindowId,
       
   462         TBool aUserInitiated )
       
   463     {
       
   464 LOG_ENTERFN("WindowManager::DeleteWindowL");
       
   465     TInt windowToBeActivated( KErrNotFound );
       
   466     // find the window
       
   467     CBrowserWindowQue* windowQue = NULL;
       
   468     Window( aWindowId, windowQue, iWindowQueue );
       
   469     if( windowQue )
       
   470         {
       
   471         // make the old window absolutely inactive
       
   472         windowQue->iWindow->BrCtlInterface().HandleCommandL(
       
   473 	        (TInt)TBrCtlDefs::ECommandClearHistory + (TInt)TBrCtlDefs::ECommandIdBase );
       
   474 		// Changes were made to ClearHistory that cause it to keep one (current) page
       
   475 		// In order to reuse a window we need to clear the history again after the first new page
       
   476 		// is loaded.
       
   477 		windowQue->iWindow->SetFirstPage(ETrue);
       
   478 
       
   479 
       
   480         windowQue->iWindow->BrCtlInterface().HandleCommandL(
       
   481             (TInt)TBrCtlDefs::ECommandLoseFocus + (TInt)TBrCtlDefs::ECommandIdBase );
       
   482 
       
   483         if(windowQue->iWindow->HasWMLContent(EFalse))
       
   484             {
       
   485             windowQue->iWindow->BrCtlInterface().HandleCommandL(
       
   486                 (TInt)TBrCtlDefs::ECommandUnloadWMLEngine + (TInt)TBrCtlDefs::ECommandIdBase );
       
   487             }
       
   488 
       
   489         // On 3.1 CancelFetch activates the content view for some reason
       
   490         // this section is temporarily flagged out until further
       
   491         // investigation.
       
   492         windowQue->iWindow->BrCtlInterface().HandleCommandL(
       
   493            (TInt)TBrCtlDefs::ECommandCancelFetch + (TInt)TBrCtlDefs::ECommandIdBase );
       
   494 
       
   495         // if the topmost window is deleted
       
   496         // try to find a new one to be activated
       
   497         if( iCurrentWindow == windowQue )
       
   498             {
       
   499             CBrowserWindowQue* next = windowQue->Next();
       
   500             CBrowserWindowQue* prev = windowQue->Prev();
       
   501             if( next )
       
   502                 {
       
   503                 windowToBeActivated = next->iWindow->WindowId();
       
   504                 iCurrentWindow = next;
       
   505                 }
       
   506             else if( prev )
       
   507                 {
       
   508                 windowToBeActivated = prev->iWindow->WindowId();
       
   509                 iCurrentWindow = prev;
       
   510                 }
       
   511             else
       
   512                 {
       
   513                 windowToBeActivated = 0;
       
   514                 }
       
   515             }
       
   516         // else a background window was deleted
       
   517 
       
   518         // last window handling
       
   519         if( WindowCount() == 1 )
       
   520             {
       
   521             // here we already set the windowToBeActivated to 0
       
   522             // means CloseContentView or Exit in AppUi
       
   523 
       
   524             // clear all content of Window (images, scripts)
       
   525 
       
   526 //            windowQue->iWindow->BrCtlInterface().HandleCommandL(
       
   527 //                (TInt)TBrCtlDefs::ECommand + (TInt)TBrCtlDefs::ECommandIdBase );
       
   528             windowQue->iWindow->BrCtlInterface().HandleCommandL(
       
   529                 (TInt)TBrCtlDefs::ECommandUnloadWMLEngine + (TInt)TBrCtlDefs::ECommandIdBase );
       
   530 
       
   531             //Remove the plugins windows. This is a fix for plugins still plays in the background
       
   532             //while the page is closed.
       
   533             windowQue->iWindow->BrCtlInterface().HandleCommandL(
       
   534                  (TInt)TBrCtlDefs::ECommandUnLoadPluginWindows + (TInt)TBrCtlDefs::ECommandIdBase );
       
   535 
       
   536             iIsContentExist = EFalse;
       
   537             windowQue->iWindow->SetHasWMLContent(EFalse);
       
   538             windowQue->iWindow->SetCurrWinHasWMLContent(EFalse);
       
   539 
       
   540 
       
   541             }
       
   542         // Update MW Indicator
       
   543         else if ( WindowCount() == 2 )
       
   544             {
       
   545             // sets the window status
       
   546             windowQue->iStatus |= CBrowserWindowQue::EWindowDeleted;
       
   547             windowQue->iWindow->DeactivateL();
       
   548             // maintain deleted windows' count
       
   549             ++iDeletedWindowCount;
       
   550 
       
   551             if( aUserInitiated )
       
   552                 {
       
   553                 DeleteOneWindowL( aWindowId );
       
   554                 }
       
   555             }
       
   556         else
       
   557             {
       
   558             // sets the window status
       
   559             windowQue->iStatus |= CBrowserWindowQue::EWindowDeleted;
       
   560             windowQue->iWindow->DeactivateL();
       
   561             // maintain deleted windows' count
       
   562             ++iDeletedWindowCount;
       
   563 
       
   564             if( aUserInitiated )
       
   565                 {
       
   566                 DeleteOneWindowL( aWindowId );
       
   567                 }
       
   568             }
       
   569         }
       
   570     NotifyObserversL( EWindowClose, aWindowId );
       
   571 
       
   572     return windowToBeActivated;
       
   573     }
       
   574 
       
   575 // -----------------------------------------------------------------------------
       
   576 // CBrowserWindowManager::SwitchWindowL()
       
   577 // -----------------------------------------------------------------------------
       
   578 //
       
   579 TInt CBrowserWindowManager::SwitchWindowL( TInt aWindowId, TBool aDraw )
       
   580     {
       
   581 LOG_ENTERFN("WindowManager::SwitchWindowL");
       
   582     CBrowserWindowQue* windowQue = NULL;
       
   583     TBool wdnSwitching = EFalse;
       
   584     TInt error( Window( aWindowId, windowQue, iWindowQueue ) );
       
   585 BROWSER_LOG( ( _L( "error: %d" ), error ) );
       
   586     if( windowQue )
       
   587         {
       
   588 		BROWSER_LOG( ( _L( "Switching..." ) ) );
       
   589         if( windowQue != iCurrentWindow )
       
   590             {
       
   591             wdnSwitching = ETrue;
       
   592             iCurrentWindow->iWindow->DeactivateL();
       
   593             iCurrentWindow = windowQue;
       
   594             }
       
   595         //If the history view is up, don't activate the content view unless it is switching the window. Otherwise,
       
   596         //it will overdraw the history view and it will cause serious problems when there
       
   597         //is a background redirection
       
   598         if(!iCurrentWindow->iWindow->IsWindowActive() && (!iContentView->IsHistoryViewUp() || wdnSwitching))
       
   599            {
       
   600            iCurrentWindow->iWindow->ActivateL( aDraw );
       
   601            iContentView->UpdateCbaL();
       
   602            }
       
   603         }
       
   604     return error;
       
   605     }
       
   606 
       
   607 // -----------------------------------------------------------------------------
       
   608 // CBrowserWindowManager::Window()
       
   609 // -----------------------------------------------------------------------------
       
   610 // search for a window identified by its Id
       
   611 TInt CBrowserWindowManager::Window(
       
   612         TInt aWindowId,
       
   613         CBrowserWindowQue*& aWindowQue,
       
   614         CBrowserWindowQue* aStartingItem ) const
       
   615     {
       
   616 LOG_ENTERFN("WindowManager::Window( Id )");
       
   617     TInt error( KErrNotFound );
       
   618     CBrowserWindowQue *windowQue = aStartingItem;
       
   619     for( ; (error != KErrNone) && (windowQue); windowQue = windowQue->iNext )
       
   620         {
       
   621         if( windowQue->iWindow->WindowId() == aWindowId )
       
   622             {
       
   623             error = KErrNone;
       
   624             aWindowQue = windowQue;
       
   625             }
       
   626         }
       
   627     return error;
       
   628     }
       
   629 
       
   630 // -----------------------------------------------------------------------------
       
   631 // CBrowserWindowManager::Window()
       
   632 // -----------------------------------------------------------------------------
       
   633 // search for a window identified by TargetName and its Parent
       
   634 TInt CBrowserWindowManager::Window(
       
   635         TInt aParentId,
       
   636         const TDesC* aTargetName,
       
   637         CBrowserWindow*& aWindow,
       
   638         CBrowserWindowQue* aStartingItem ) const
       
   639     {
       
   640 LOG_ENTERFN("WindowManager::Window( Parent, Target )");
       
   641     TInt error( KErrNotFound );
       
   642     if( aTargetName && aTargetName->Length() )  // sanity check
       
   643         {
       
   644         CBrowserWindow* window = NULL;
       
   645         CBrowserWindowQue *windowQue = aStartingItem;
       
   646         CBrowserWindowQue* parent = NULL;
       
   647         for( ; (error != KErrNone) && (windowQue); windowQue = windowQue->iNext )
       
   648             {
       
   649             window = windowQue->iWindow;
       
   650             parent = windowQue->iParent;
       
   651             if( parent &&
       
   652                 ( parent->iWindow->WindowId() == aParentId ) &&
       
   653                 ( window->TargetName()->Compare( *aTargetName ) == 0 ) )
       
   654                 {
       
   655                 error = KErrNone;
       
   656                 aWindow = window;
       
   657                 }
       
   658             }
       
   659         }
       
   660     return error;
       
   661     }
       
   662 
       
   663 // -----------------------------------------------------------------------------
       
   664 // CBrowserWindowManager::DeleteOneWindowL()
       
   665 // -----------------------------------------------------------------------------
       
   666 //
       
   667 TInt CBrowserWindowManager::DeleteOneWindowL( TInt aWindowId )
       
   668     {
       
   669     // Last window cannot be deleted, this is not called then.
       
   670 LOG_ENTERFN("WindowManager::DeleteOneWindowL");
       
   671     CBrowserWindowQue* windowQue = NULL;
       
   672     // find window, error ignored
       
   673     Window( aWindowId, windowQue, iWindowQueue );
       
   674     if( windowQue )
       
   675         {
       
   676         // set WindowQueue's first item if required
       
   677         if( iWindowQueue == windowQue )
       
   678             {
       
   679             iWindowQueue = windowQue->iNext;
       
   680             }
       
   681 
       
   682         // clear children's parent pointer
       
   683         CBrowserWindowQue* queue = iWindowQueue;
       
   684         for( ; queue; queue = queue->iNext )
       
   685             {
       
   686             if( queue->iParent == windowQue )
       
   687                 {
       
   688                 queue->iParent = NULL;
       
   689                 }
       
   690             }
       
   691 
       
   692         // decrease WindowCount
       
   693         --iWindowCount;
       
   694 
       
   695         // maintain deleted status
       
   696         if ( windowQue->iStatus & CBrowserWindowQue::EWindowDeleted )
       
   697             {
       
   698             __ASSERT_DEBUG( iDeletedWindowCount,
       
   699                 Util::Panic( Util::EUnExpected ));
       
   700             --iDeletedWindowCount;
       
   701             }
       
   702         // delete window via its windowQue container
       
   703         delete windowQue;
       
   704         }
       
   705     return KErrNone;
       
   706     }
       
   707 
       
   708 // ----------------------------------------------------------------------------
       
   709 // CBrowserWindowManager::RemoveDeletedWindowsL()
       
   710 // ----------------------------------------------------------------------------
       
   711 //
       
   712 void CBrowserWindowManager::RemoveDeletedWindowsL()
       
   713     {
       
   714     CBrowserWindowQue *window = iWindowQueue;
       
   715     CBrowserWindowQue *temp = NULL;
       
   716     // walk through all the windows
       
   717     for( ; window; )
       
   718         {
       
   719         temp = window;
       
   720         window = window->iNext;
       
   721         // if it is set as deleted
       
   722         if( temp->iStatus & CBrowserWindowQue::EWindowDeleted )
       
   723             {
       
   724             DeleteOneWindowL( temp->iWindow->WindowId() );
       
   725             }
       
   726         }
       
   727     }
       
   728 
       
   729 // ----------------------------------------------------------------------------
       
   730 // CBrowserWindowManager::HandlePreferencesChangeL()
       
   731 // ----------------------------------------------------------------------------
       
   732 //
       
   733 void CBrowserWindowManager::HandlePreferencesChangeL(
       
   734         const TPreferencesEvent aEvent,
       
   735         TPreferencesValues& aValues,
       
   736         TBrCtlDefs::TBrCtlSettings aSettingType )
       
   737     {
       
   738 LOG_ENTERFN("WindowManager::HandlePreferencesChangeL");
       
   739 BROWSER_LOG( ( _L( "Preferences event: %d" ), aEvent ) );
       
   740     switch( aEvent )
       
   741         {
       
   742         case EPreferencesActivate:
       
   743             {
       
   744             // Topmost Window ONLY
       
   745             if ( iCurrentWindow )
       
   746                 {
       
   747                 iCurrentWindow->iWindow->HandlePreferencesChangeL(
       
   748                     aEvent, aValues, aSettingType );
       
   749                 }
       
   750             break;
       
   751             }
       
   752         case EPreferencesDeactivate:
       
   753         case EPreferencesItemChange:
       
   754             {
       
   755             // All windows
       
   756             CBrowserWindowQue *windowQue = iWindowQueue;
       
   757             for( ; windowQue; windowQue = windowQue->Next() )
       
   758                 {
       
   759                 windowQue->iWindow->HandlePreferencesChangeL(
       
   760                     aEvent, aValues, aSettingType );
       
   761                 }
       
   762             break;
       
   763             }
       
   764         default:
       
   765             // don't do anything
       
   766             break;
       
   767         }
       
   768     }
       
   769 
       
   770 // ----------------------------------------------------------------------------
       
   771 // CBrowserWindowManager::SendCommandToAllWindowsL()
       
   772 // ----------------------------------------------------------------------------
       
   773 //
       
   774 void CBrowserWindowManager::SendCommandToAllWindowsL(
       
   775         TInt aCommand )
       
   776     {
       
   777 LOG_ENTERFN("WindowManager::SendCommandToAllWindowsL");
       
   778 BROWSER_LOG( ( _L( "Command: %d" ), aCommand ) );
       
   779 
       
   780     CBrowserWindowQue *windowQue = iWindowQueue;
       
   781     for( ; windowQue; windowQue = windowQue->Next() )
       
   782         {
       
   783         windowQue->iWindow->BrCtlInterface().HandleCommandL(aCommand);
       
   784         }
       
   785     }
       
   786 
       
   787 // ----------------------------------------------------------------------------
       
   788 // CBrowserWindowManager::SetCurrentWindowViewState()
       
   789 // ----------------------------------------------------------------------------
       
   790 //
       
   791 void CBrowserWindowManager::SetCurrentWindowViewState(TBrCtlDefs::TBrCtlState aViewState, TInt aValue)
       
   792 	{
       
   793 LOG_ENTERFN("WindowManager::SetCurrentWindowViewState");
       
   794 BROWSER_LOG( ( _L( "State: %d" ), aViewState ) );
       
   795 
       
   796 	TBool val(aValue > 0);
       
   797 	if (aViewState == TBrCtlDefs::EStateWmlView)
       
   798 		{
       
   799 		CurrentWindow()->SetWMLMode(val); // set current page has wml (true or false)
       
   800 		if (val)
       
   801 			{
       
   802 			CurrentWindow()->SetHasWMLContent(ETrue); // at least 1 page in window has/had wml
       
   803 			CurrentWindow()->SetCurrWinHasWMLContent(ETrue); // current page has wml content
       
   804 
       
   805 			}
       
   806 		else
       
   807 			{
       
   808 			CurrentWindow()->SetCurrWinHasWMLContent(EFalse);// current page isn't wml
       
   809 			}
       
   810 		}
       
   811 	}
       
   812 
       
   813 // ----------------------------------------------------------------------------
       
   814 // CBrowserWindowManager::CloseAllWindowsExceptCurrent()
       
   815 // ----------------------------------------------------------------------------
       
   816 //
       
   817 void CBrowserWindowManager::CloseAllWindowsExceptCurrent()
       
   818     {
       
   819     LOG_ENTERFN("WindowManager::CloseAllWindowsExceptCurrent");
       
   820     CBrowserWindowQue* window = iWindowQueue;
       
   821     for( ; window; window = window->Next() )
       
   822         {
       
   823         if(iCurrentWindow != window)
       
   824             {
       
   825             DeleteWindowL(window->iWindow->WindowId(), EFalse);
       
   826             }
       
   827         }
       
   828     }
       
   829 // End of file