email/mail/PluginSrc/MailHtmlView/CMailHtmlBodyControl.cpp
changeset 0 72b543305e3a
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     1 /*
       
     2 * Copyright (c) 2002-2004 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 "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:  HTML body control
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include    "CMailHtmlBodyControl.h"
       
    22 #include 	"MailLog.h"
       
    23 #include 	<MsgBaseControl.h>
       
    24 #include	<MsgEditor.hrh>
       
    25 #include 	<CMailMessage.h>
       
    26 // Browser
       
    27 #include 	<BrCtlInterface.h>
       
    28 #include 	<BrCtlDefs.h>
       
    29 #include    <TXTRICH.H> 
       
    30 #include    <MMailAppUiInterface.h>
       
    31 
       
    32 // CONSTANTS
       
    33 //const ?type ?constant_var = ?constant;
       
    34 
       
    35 
       
    36 // ============================ MEMBER FUNCTIONS ===============================
       
    37 
       
    38 // -----------------------------------------------------------------------------
       
    39 // CMailHtmlBodyControl::CMailHtmlBodyControl
       
    40 // C++ default constructor can NOT contain any code, that
       
    41 // might leave.
       
    42 // -----------------------------------------------------------------------------
       
    43 //
       
    44 CMailHtmlBodyControl::CMailHtmlBodyControl( 
       
    45 	CMailMessage& aMessage,
       
    46 	MMailAppUiInterface& aUICallBack ): 
       
    47 	iMessage( aMessage ), iUICallBack( aUICallBack )
       
    48     {
       
    49     }
       
    50 
       
    51 // -----------------------------------------------------------------------------
       
    52 // CMailHtmlBodyControl::ConstructL
       
    53 // Symbian 2nd phase constructor can leave.
       
    54 // -----------------------------------------------------------------------------
       
    55 //
       
    56 void CMailHtmlBodyControl::ConstructL()
       
    57     {   
       
    58     CCoeControl& appui = iUICallBack.ParentControl();
       
    59     TRect base = iUICallBack.MsgViewRect(0);
       
    60 	LOG2("CMailHtmlBodyControl::ConstructL W:%d H:%d", 
       
    61 	base.Width(), base.Height() );
       
    62 
       
    63 
       
    64     TUint capabilities(TBrCtlDefs::ECapabilityClientResolveEmbeddedURL);
       
    65     capabilities |= TBrCtlDefs::ECapabilityFindItem;
       
    66     capabilities |= TBrCtlDefs::ECapabilityDisableInputAndPlugins;
       
    67     
       
    68     iBrControl = CreateBrowserControlL(
       
    69     	&appui, 
       
    70     	base, capabilities, 
       
    71     	TBrCtlDefs::ECommandIdBase, 
       
    72     	NULL, this, NULL, NULL, NULL, NULL);
       
    73     iBrControl->SetBrowserSettingL(TBrCtlDefs::ESettingsSmallScreen, ETrue);
       
    74     iBrControl->SetBrowserSettingL(TBrCtlDefs::ESettingsEmbedded, ETrue);
       
    75     
       
    76 /*
       
    77     iBrControl->SetBrowserSettingL(TBrCtlDefs::ESettingsSmallScreen, 1);
       
    78     //iBrControl->SetBrowserSettingL(TBrCtlDefs::ESettingSecurityWarnings, 1);
       
    79     iBrControl->SetBrowserSettingL(TBrCtlDefs::ESettingsAutoLoadImages, 1);
       
    80     //iBrControl->SetContainerWindowL(appui.Window());
       
    81     iBrControl = CreateBrowserControlL(CCoeControl* aParent, TRect aRect,
       
    82     TUint aBrCtlCapabilities, TUint aCommandIdBase = TBrCtlDefs::ECommandIdBase,
       
    83     MBrCtlSoftkeysObserver* aBrCtlSoftkeysObserver = NULL,
       
    84     MBrCtlLinkResolver* aBrCtlLinkResolver = NULL,
       
    85     MBrCtlSpecialLoadObserver* aBrCtlSpecialLoadObserver = NULL,
       
    86     MBrCtlLayoutObserver* aBrCtlLayoutObserver = NULL,
       
    87     MBrCtlDialogsProvider* aBrCtlDialogsProvider = NULL);    */    
       
    88     }
       
    89 
       
    90 // -----------------------------------------------------------------------------
       
    91 // CMailHtmlBodyControl::NewL
       
    92 // Two-phased constructor.
       
    93 // -----------------------------------------------------------------------------
       
    94 //
       
    95 CMailHtmlBodyControl* CMailHtmlBodyControl::NewLC( 
       
    96 	CMailMessage& aMessage ,MMailAppUiInterface& aUICallBack )
       
    97     {
       
    98     CMailHtmlBodyControl* self = new( ELeave ) CMailHtmlBodyControl( 
       
    99     	aMessage, aUICallBack );
       
   100     CleanupStack::PushL( self );
       
   101     self->ConstructL();
       
   102     return self;
       
   103     }
       
   104 
       
   105     
       
   106 // Destructor
       
   107 CMailHtmlBodyControl::~CMailHtmlBodyControl()
       
   108     {
       
   109     delete iBrControl;
       
   110     }
       
   111 
       
   112 
       
   113 // -----------------------------------------------------------------------------
       
   114 // CMailHtmlBodyControl::BrowserControl
       
   115 // -----------------------------------------------------------------------------
       
   116 //
       
   117 CBrCtlInterface& CMailHtmlBodyControl::BrowserControl()
       
   118     {
       
   119     return *iBrControl;
       
   120     }
       
   121     
       
   122 // -----------------------------------------------------------------------------
       
   123 // CMailHtmlBodyControl::MessageLoadingL
       
   124 // -----------------------------------------------------------------------------
       
   125 //
       
   126 void CMailHtmlBodyControl::MessageLoadingL(TInt aStatus, CMailMessage& aMessage)
       
   127     {
       
   128 	if( aStatus == CMailMessage::ELinkedFileReady ) 
       
   129 		{
       
   130         LOG1( "CMailHtmlBodyControl::ELinkedFileReady 0x%08x", 
       
   131 	        aMessage.LinkedHtmlId());		
       
   132 		RFile linkedHtml = aMessage.LinkedHtmlContent();
       
   133 		if ( linkedHtml.SubSessionHandle() != 0 )
       
   134 			{			
       
   135 			CleanupClosePushL( linkedHtml );
       
   136 			TInt fileSize(0);
       
   137 			linkedHtml.Size( fileSize );
       
   138 			HBufC8* data = HBufC8::NewLC( fileSize );
       
   139 			TPtr8 ptr( data->Des() );
       
   140 			User::LeaveIfError( linkedHtml.Read( ptr ) );
       
   141 			_LIT(KContent, "image/gif");
       
   142 			iEmbeddedLinkContent->HandleResolveComplete(
       
   143 			    KContent,
       
   144                 KNullDesC(),
       
   145                 data );
       
   146 	        CleanupStack::PopAndDestroy(2);		// CSI: 47 # data, linkedHtml
       
   147 			}
       
   148 		else
       
   149 		    {		    
       
   150 		    iEmbeddedLinkContent->HandleResolveError( KErrCorrupt );
       
   151 		    }
       
   152 		}		    
       
   153     }
       
   154     
       
   155 // -----------------------------------------------------------------------------
       
   156 // CMailHtmlBodyControl::CurrentLineRect
       
   157 // -----------------------------------------------------------------------------
       
   158 //
       
   159 TRect CMailHtmlBodyControl::CurrentLineRect()
       
   160 	{
       
   161 	TRect rect = iBrControl->Rect();
       
   162 	LOG2("CMailHtmlBodyControl::CurrentLineRect W:%d H:%d", 
       
   163 		rect.Width(), rect.Height() );	
       
   164 
       
   165 	return rect;
       
   166 	}
       
   167 	
       
   168 // -----------------------------------------------------------------------------
       
   169 // CMailHtmlBodyControl::SetAndGetSizeL
       
   170 // -----------------------------------------------------------------------------
       
   171 //
       
   172 void CMailHtmlBodyControl::SetAndGetSizeL( TSize& aSize )
       
   173 	{
       
   174 	TSize htmlSize = iBrControl->ContentSize();
       
   175 	TSize brc = iBrControl->Size();
       
   176 	iBrControl->SetSize( aSize );
       
   177 	htmlSize = iBrControl->ContentSize();	
       
   178 	}
       
   179 
       
   180 // -----------------------------------------------------------------------------
       
   181 // CMailHtmlBodyControl::ClipboardL
       
   182 // -----------------------------------------------------------------------------
       
   183 //
       
   184 void CMailHtmlBodyControl::ClipboardL( TMsgClipboardFunc aFunc )
       
   185 	{
       
   186 	LOG1("CMailHtmlBodyControl::ClipboardL %d", aFunc );
       
   187 	}
       
   188 	
       
   189 // -----------------------------------------------------------------------------
       
   190 // CMailHtmlBodyControl::EditL
       
   191 // -----------------------------------------------------------------------------
       
   192 //
       
   193 void CMailHtmlBodyControl::EditL( TMsgEditFunc aFunc )
       
   194 	{
       
   195 	LOG1("CMailHtmlBodyControl::EditL %d", aFunc );	
       
   196 	}
       
   197 // -----------------------------------------------------------------------------
       
   198 // CMailHtmlBodyControl::IsFocusChangePossible
       
   199 // -----------------------------------------------------------------------------
       
   200 //
       
   201 TBool CMailHtmlBodyControl::IsFocusChangePossible( 
       
   202 	TMsgFocusDirection aDirection )  const
       
   203 	{
       
   204 	LOG1("CMailHtmlBodyControl::IsFocusChangePossible %d", aDirection );
       
   205 	return aDirection == EMsgFocusDown ? EFalse : ETrue;
       
   206 	}
       
   207 // -----------------------------------------------------------------------------
       
   208 // CMailHtmlBodyControl::IsCursorLocation
       
   209 // -----------------------------------------------------------------------------
       
   210 //
       
   211 TBool CMailHtmlBodyControl::IsCursorLocation( 
       
   212 	TMsgCursorLocation aLocation ) const
       
   213 	{
       
   214 	LOG1("CMailHtmlBodyControl::IsCursorLocation %d", aLocation );
       
   215 	return EFalse;
       
   216 	}
       
   217 
       
   218 // -----------------------------------------------------------------------------
       
   219 // CMailHtmlBodyControl::EditPermission
       
   220 // -----------------------------------------------------------------------------
       
   221 //
       
   222 TUint32 CMailHtmlBodyControl::EditPermission() const
       
   223 	{
       
   224 	return 0;
       
   225 	}
       
   226 
       
   227 // -----------------------------------------------------------------------------
       
   228 // CMailHtmlBodyControl::PrepareForReadOnly
       
   229 // -----------------------------------------------------------------------------
       
   230 //
       
   231 void CMailHtmlBodyControl::PrepareForReadOnly( TBool /*aReadOnly*/ )
       
   232 	{
       
   233 	
       
   234 	}
       
   235 
       
   236 
       
   237 // -----------------------------------------------------------------------------
       
   238 // CMailHtmlBodyControl::VirtualHeight
       
   239 // Returns approximate height of the control.
       
   240 // -----------------------------------------------------------------------------
       
   241 //
       
   242 TInt CMailHtmlBodyControl::VirtualHeight()
       
   243     {
       
   244 	LOG1("CMailHtmlBodyControl::VirtualHeight H:%d", 
       
   245 	    iBrControl->Size().iHeight);
       
   246     TSize htmlSize = iBrControl->ContentSize();
       
   247 	LOG1("CMailHtmlBodyControl::VirtualHeight brContent h:%d", 
       
   248 	    htmlSize.iHeight);    
       
   249     return htmlSize.iHeight;
       
   250     }
       
   251 
       
   252 // -----------------------------------------------------------------------------
       
   253 // CMailHtmlBodyControl::VirtualVisibleTop
       
   254 // Returns a topmost visible text position.
       
   255 // -----------------------------------------------------------------------------
       
   256 //
       
   257 TInt CMailHtmlBodyControl::VirtualVisibleTop()
       
   258     {
       
   259     LOG("CMailHtmlBodyControl::VirtualVisibleTop");   
       
   260     return iBrControl->Rect().iTl.iY; // left corner
       
   261     }
       
   262 
       
   263 // -----------------------------------------------------------------------------
       
   264 // CMailHtmlBodyControl::HandleBrowserLoadEventL
       
   265 // -----------------------------------------------------------------------------
       
   266 //
       
   267 void CMailHtmlBodyControl::HandleBrowserLoadEventL(
       
   268         	TBrCtlDefs::TBrCtlLoadEvent aLoadEvent, 
       
   269         	TUint /*aSize*/, 
       
   270         	TUint16 /*aTransactionId*/)
       
   271 	{
       
   272 	if (aLoadEvent == TBrCtlDefs::EEventNewUrlContentArrived)
       
   273 		{
       
   274 		//
       
   275 		}
       
   276 	}
       
   277 	
       
   278 // -----------------------------------------------------------------------------
       
   279 // CMailHtmlBodyControl::ResolveEmbeddedLinkL
       
   280 // -----------------------------------------------------------------------------
       
   281 //	
       
   282 TBool CMailHtmlBodyControl::ResolveEmbeddedLinkL(const TDesC& aEmbeddedUrl,
       
   283     const TDesC& aCurrentUrl,
       
   284     TBrCtlLoadContentType aLoadContentType, 
       
   285     MBrCtlLinkContent& aEmbeddedLinkContent)
       
   286 	{
       
   287 	TBool resolve(EFalse);
       
   288 	LOG2("CMailHtmlBodyControl::ResolveEmbeddedLinkL eURL:%S, cURL:%S",
       
   289 		&aEmbeddedUrl , &aCurrentUrl);
       
   290 	// Resolve local image link
       
   291 	if (aLoadContentType==ELoadContentTypeImage)
       
   292 		{
       
   293 		iEmbeddedLinkContent = &aEmbeddedLinkContent;
       
   294 		iMessage.LoadLinkedHtmlContentL(aCurrentUrl, aEmbeddedUrl, *this);
       
   295 		resolve = ETrue;
       
   296 		}
       
   297     return resolve;
       
   298 	}
       
   299 // -----------------------------------------------------------------------------
       
   300 // CMailHtmlBodyControl::ResolveLinkL
       
   301 // -----------------------------------------------------------------------------
       
   302 //        	
       
   303 TBool CMailHtmlBodyControl::ResolveLinkL(const TDesC& aUrl, 
       
   304     const TDesC& aCurrentUrl,
       
   305     MBrCtlLinkContent& /*aBrCtlLinkContent*/)
       
   306 	{
       
   307 	LOG2("CMailHtmlBodyControl::ResolveLinkL aURL:%S, cURL:%S",
       
   308 		&aUrl , &aCurrentUrl);
       
   309 	return EFalse;
       
   310 	}
       
   311 
       
   312 // -----------------------------------------------------------------------------
       
   313 // CMailHtmlBodyControl::CancelAll
       
   314 // -----------------------------------------------------------------------------
       
   315 //            
       
   316 void CMailHtmlBodyControl::CancelAll()
       
   317 	{
       
   318 	// Cancel content loadin
       
   319 	LOG("CMailHtmlBodyControl::CancelAll");	
       
   320 	iMessage.Cancel();
       
   321 	}
       
   322 	
       
   323 	
       
   324 // -----------------------------------------------------------------------------
       
   325 // CMailHtmlBodyControl::CountPluginComponentControls
       
   326 // -----------------------------------------------------------------------------
       
   327 //
       
   328 TInt CMailHtmlBodyControl::CountPluginComponentControls() const
       
   329     {
       
   330     return iBrControl ? 1 : 0; // iBrControl
       
   331     }
       
   332 
       
   333 // -----------------------------------------------------------------------------
       
   334 // CMailHtmlBodyControl::PluginComponentControl
       
   335 // -----------------------------------------------------------------------------
       
   336 //
       
   337 CCoeControl* CMailHtmlBodyControl::PluginComponentControl(TInt /*aIndex*/) const
       
   338     {
       
   339     return iBrControl;
       
   340     }
       
   341 
       
   342 // -----------------------------------------------------------------------------
       
   343 // CMailHtmlBodyControl::PluginSizeChanged
       
   344 // -----------------------------------------------------------------------------
       
   345 //
       
   346 void CMailHtmlBodyControl::PluginSizeChanged()
       
   347     {
       
   348     LOG("CMailHtmlBodyControl::PluginSizeChanged");
       
   349     
       
   350    for (TInt i=0; i<4; ++i)								// CSI: 47 # <insert a comment here>
       
   351     	{
       
   352 	    TRect base = iUICallBack.MsgViewRect(i);
       
   353 		LOG2("CMailHtmlBodyControl::SizeChanged-EB- W:%d H:%d", 
       
   354 			base.Width(), base.Height() );
       
   355     	}
       
   356     TPoint move(10,10);									// CSI: 47 # <insert a comment here>
       
   357     iBrControl->SetPosition( move );
       
   358 /*	LOG2("CMailHtmlBodyControl::SizeChanged W:%d H:%d", 
       
   359 		Size().iWidth, Size().iHeight);
       
   360 	iBrControl->SetSize( Size() );
       
   361 	
       
   362 	LOG2("CMailHtmlBodyControl::SizeChanged - Position X:%d Y:%d", 
       
   363 		Position().iX, Position().iY);
       
   364 	iBrControl->SetSize( Size() );	
       
   365 	
       
   366 	LOG2("CMailHtmlBodyControl::SizeChanged - BRC Position X:%d Y:%d", 
       
   367 		iBrControl->Position().iX, iBrControl->Position().iY);
       
   368 	iBrControl->SetPosition( Position() );		
       
   369 
       
   370     for (TInt i=0; i<4; ++i)
       
   371     	{
       
   372 	    TRect base = iUICallBack.MsgViewRect(i);
       
   373 		LOG2("CMailHtmlBodyControl::SizeChanged-EB- W:%d H:%d", 
       
   374 			base.Width(), base.Height() );
       
   375     	}*/
       
   376     }
       
   377 
       
   378 // -----------------------------------------------------------------------------
       
   379 // CMailHtmlBodyControl::PluginFocusChanged
       
   380 // -----------------------------------------------------------------------------
       
   381 //
       
   382 void CMailHtmlBodyControl::PluginFocusChanged( TDrawNow /*aDrawNow*/ )
       
   383     {
       
   384     LOG("CMailHtmlBodyControl::PluginFocusChanged");
       
   385 	//iBrControl->SetFocus( IsFocused(), aDrawNow );
       
   386     }
       
   387 
       
   388 
       
   389 
       
   390 // -----------------------------------------------------------------------------
       
   391 // CMailHtmlBodyControl::PluginHandleResourceChange
       
   392 // -----------------------------------------------------------------------------
       
   393 //
       
   394 void CMailHtmlBodyControl::PluginHandleResourceChange(TInt aType)
       
   395     {
       
   396     LOG("CMailHtmlBodyControl::PluginHandleResourceChange");
       
   397     iBrControl->HandleResourceChange( aType );
       
   398     }
       
   399 
       
   400 // -----------------------------------------------------------------------------
       
   401 // CMailHtmlBodyControl::PluginOfferKeyEventL
       
   402 // -----------------------------------------------------------------------------
       
   403 //    
       
   404 TKeyResponse CMailHtmlBodyControl::PluginOfferKeyEventL(
       
   405     const TKeyEvent& aKeyEvent,
       
   406     TEventCode aType)
       
   407     {
       
   408     LOG("CMailHtmlBodyControl::PluginOfferKeyEventL");
       
   409     return iBrControl->OfferKeyEventL( aKeyEvent, aType );
       
   410     }
       
   411 
       
   412 // -----------------------------------------------------------------------------
       
   413 // CMailHtmlBodyControl::SetPluginExtent
       
   414 // -----------------------------------------------------------------------------
       
   415 //
       
   416 void CMailHtmlBodyControl::SetPluginExtent(
       
   417     const TPoint& aPosition,const TSize& aSize)
       
   418 	{
       
   419 	LOG2("CMailHtmlBodyControl::SetPosition X:%d Y:%d", 
       
   420 		aPosition.iX, aPosition.iY);
       
   421 	iBrControl->SetExtent( aPosition, aSize );		
       
   422 	}
       
   423 
       
   424 //  End of File  
       
   425