📄 brctlsampleappcontainer.cpp
字号:
/*
* ============================================================================
* Name : BrCtlSampleAppContainer.cpp
* 基于SYMBIAN,通过插件方式,实现浏览器
* ============================================================================
*/
// INCLUDE FILES
#include "BrCtlSampleAppContainer.h"
#include "BrCtlSampleAppSpecialLoadObserver.h"
#include "BrCtlSampleAppLayoutObserver.h"
#include "BrCtlSampleAppSoftkeysObserver.h"
#include "BrCtlSampleAppLoadEventObserver.h"
#include "BrCtlSampleAppLinkResolver.h"
#include "BrCtlSampleAppStateChangeObserver.h"
#include "BrCtlSampleAppDialogsProvider.h"
#include "BrCtlSampleAppQueryDialog.h"
#include <eiklabel.h> // for example label control
#include <avkon.hrh>
#include <BrCtlSampleApp.rsg>
#include "brctlsampleapp.hrh"
#include <BrCtlInterface.h>
#include <CHARCONV.H>
#include <gdi.h>
#include <bitdev.h>
// ================= MEMBER FUNCTIONS =======================
// ---------------------------------------------------------
// CBrCtlSampleAppContainer::ConstructL(const TRect& aRect)
// EPOC two phased constructor
// ---------------------------------------------------------
//
void CBrCtlSampleAppContainer::ConstructL(const TRect& aRect)
{
CreateWindowL();
SetRect(aRect);
ActivateL();
iCommandBase = TBrCtlDefs::ECommandIdBase;
// Create the Observers
iBrCtlSampleAppSpecialLoadObserver = CBrCtlSampleAppSpecialLoadObserver::NewL();
iBrCtlSampleAppLayoutObserver = CBrCtlSampleAppLayoutObserver::NewL(this);
iBrCtlSampleAppSoftkeysObserver = CBrCtlSampleAppSoftkeysObserver::NewL(this);
iBrCtlSampleAppLoadEventObserver = CBrCtlSampleAppLoadEventObserver::NewL(this);
iBrCtlSampleAppLinkResolver = CBrCtlSampleAppLinkResolver::NewL();
iBrCtlSampleAppStateChangeObserver = CBrCtlSampleAppStateChangeObserver::NewL(this);
iBrCtlSampleAppDialogsProvider = CBrCtlSampleAppDialogsProvider::NewL(this);
// Initialize memeber variables
_LIT(KEmpty, "");
iText.Set(KEmpty);
iPoint = TPoint(0,130);
iBrCtlCapabilities = TBrCtlDefs::ECapabilityDisplayScrollBar | TBrCtlDefs::ECapabilityLoadHttpFw;
// Create a Screen device for use with fonts for writing text to the screen
CEikonEnv* eikEnv = CEikonEnv::Static();
CWsScreenDevice& screenDev = *eikEnv->ScreenDevice();
_LIT( KDummy, "Dummy");
iFbsScrDev = CFbsScreenDevice::NewL( KDummy, screenDev.DisplayMode());
// Create a font spec in order to retrieve a valid font
_LIT(KFontFamily, "S60 Sans");
TFontSpec fs(KFontFamily, 100);
iFbsScrDev->GetNearestFontInTwips((CFont*&)iFont, fs);
TRect rect(Position(), Size());
iBrCtlInterface = CreateBrowserControlL( this,
rect,
iBrCtlCapabilities,
iCommandBase,
iBrCtlSampleAppSoftkeysObserver,
iBrCtlSampleAppLinkResolver,
iBrCtlSampleAppSpecialLoadObserver,
iBrCtlSampleAppLayoutObserver,
iBrCtlSampleAppDialogsProvider);
// These observers can be added and removed dynamically
iBrCtlInterface->AddLoadEventObserverL(iBrCtlSampleAppLoadEventObserver);
iBrCtlInterface->AddStateChangeObserverL(iBrCtlSampleAppStateChangeObserver);
}
// Destructor
CBrCtlSampleAppContainer::~CBrCtlSampleAppContainer()
{
if (iBrCtlInterface)
{
iBrCtlInterface->RemoveLoadEventObserver(iBrCtlSampleAppLoadEventObserver);
iBrCtlInterface->RemoveStateChangeObserver(iBrCtlSampleAppStateChangeObserver);
delete iBrCtlInterface;
}
// we are required to release the font
iFbsScrDev->ReleaseFont(iFont);
// delete the screen device
delete iFbsScrDev;
// delete the observers
delete iBrCtlSampleAppSpecialLoadObserver;
delete iBrCtlSampleAppLayoutObserver;
delete iBrCtlSampleAppSoftkeysObserver;
delete iBrCtlSampleAppLoadEventObserver;
delete iBrCtlSampleAppLinkResolver;
delete iBrCtlSampleAppStateChangeObserver;
delete iBrCtlSampleAppDialogsProvider;
}
// ---------------------------------------------------------
// CBrCtlSampleAppContainer::SizeChanged()
// Called by framework when the view size is changed
// ---------------------------------------------------------
//
void CBrCtlSampleAppContainer::SizeChanged()
{
if (iBrCtlInterface)
{
iBrCtlInterface->SetRect(Rect());
}
}
// ---------------------------------------------------------
// CBrCtlSampleAppContainer::CountComponentControls() const
// ---------------------------------------------------------
//
TInt CBrCtlSampleAppContainer::CountComponentControls() const
{
if (iBrCtlInterface)
return 1;
return 0;
}
// ---------------------------------------------------------
// CBrCtlSampleAppContainer::ComponentControl(TInt aIndex) const
// ---------------------------------------------------------
//
CCoeControl* CBrCtlSampleAppContainer::ComponentControl(TInt aIndex) const
{
switch ( aIndex )
{
case 0:
return iBrCtlInterface; // Could be NULL
default:
return NULL;
}
}
// ---------------------------------------------------------
// CBrCtlSampleAppContainer::Draw(const TRect& aRect) const
// ---------------------------------------------------------
//
void CBrCtlSampleAppContainer::Draw(const TRect& aRect) const
{
CWindowGc& gc = SystemGc();
gc.SetPenStyle(CGraphicsContext::ESolidPen);
gc.SetBrushColor(KRgbGray);
gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
gc.DrawRect(aRect);
gc.UseFont(iFont);
gc.DrawText(iText, iPoint);
gc.DiscardFont();
}
// ---------------------------------------------------------
// CBrCtlSampleAppContainer::HandleControlEventL(
// CCoeControl* aControl,TCoeEvent aEventType)
// ---------------------------------------------------------
//
void CBrCtlSampleAppContainer::HandleControlEventL(
CCoeControl* /*aControl*/,TCoeEvent /*aEventType*/)
{
}
// ----------------------------------------------------
// CBrCtlSampleAppContainer::HandleKeyEventL(
// const TKeyEvent& aKeyEvent,TEventCode /*aType*/)
// ----------------------------------------------------
//
TKeyResponse CBrCtlSampleAppContainer::HandleKeyEventL(
const TKeyEvent& /*aKeyEvent*/,TEventCode /*aType*/)
{
return EKeyWasNotConsumed;
}
// ----------------------------------------------------
// CBrCtlSampleAppContainer::SetText(const TDesC& aText)
// ----------------------------------------------------
//
void
CBrCtlSampleAppContainer::SetText(const TDesC& aText)
{
iText.Set(aText);
}
// ----------------------------------------------------
// CBrCtlSampleAppContainer::SetPoint(const TPoint& aPoint)
// ----------------------------------------------------
//
void
CBrCtlSampleAppContainer::SetPoint(const TPoint& aPoint)
{
iPoint = aPoint;
}
// ----------------------------------------------------
// CBrCtlSampleAppContainer::CancelLoad()
// ----------------------------------------------------
//
void CBrCtlSampleAppContainer::CancelLoad()
{
iCancelInitDataLoad = ETrue;
}
// ----------------------------------------------------
// CBrCtlSampleAppContainer::HandleCommandL(TInt aCommand)
// ----------------------------------------------------
//
void CBrCtlSampleAppContainer::HandleCommandL(TInt aCommand)
{
switch ( aCommand )
{
case EBrCtlSampleAppCmdAppRestoreSetting:
{
if (iBrCtlInterface)
{
TRect rect( Position(), Size() );
iBrCtlInterface->SetRect( rect );
iBrCtlInterface->SetBrowserSettingL(TBrCtlDefs::ESettingsSmallScreen, 1);
iBrCtlInterface->SetBrowserSettingL(TBrCtlDefs::ESettingsSecurityWarnings, 1);
iBrCtlInterface->SetBrowserSettingL(TBrCtlDefs::ESettingsAutoLoadImages, 1);
iBrCtlInterface->SetBrowserSettingL(TBrCtlDefs::ESettingsECMAScriptEnabled, 1);
}
break;
}
case EBrCtlSampleAppCmdAppReload:
{
if (iBrCtlInterface)
{
iBrCtlInterface->HandleCommandL(iCommandBase + TBrCtlDefs::ECommandReload);
}
break;
}
case EBrCtlSampleAppCmdAppBack:
{
if (iBrCtlInterface)
{
iBrCtlInterface->HandleCommandL(iCommandBase + TBrCtlDefs::ECommandBack);
}
break;
}
case EBrCtlSampleAppCmdAppForward:
{
if (iBrCtlInterface)
{
iBrCtlInterface->HandleCommandL(iCommandBase + TBrCtlDefs::ECommandForward);
}
break;
}
case EBrCtlSampleAppCmdApp1:
{
BasicBrowserControlL();
break;
}
case EBrCtlSampleAppCmdApp2:
{
BrowserControlWithObserversL();
break;
}
case EBrCtlSampleAppCmdApp3:
{
LoadingContentWithFileHandleL();
break;
}
case EBrCtlSampleAppCmdApp4:
{
LoadingContentWithBufferL();
break;
}
case EBrCtlSampleAppCmdApp5:
{
IncrementalLoadingL();
break;
}
case EBrCtlSampleAppCmdApp6:
{
SpecialLoadRequestsL();
break;
}
case EBrCtlSampleAppCmdApp7:
{
CustomizedDialogsL();
break;
}
case EBrCtlSampleAppCmdApp8:
{
CustomizedSoftKeysL();
break;
}
case EBrCtlSampleAppCmdApp9:
{
ResolvingEmbeddedLinksL();
break;
}
case EBrCtlSampleAppCmdApp10:
{
CustomizedScrollBarsL();
break;
}
case EBrCtlSampleAppCmdApp11:
{
HandleStateChangedL();
break;
}
case EBrCtlSampleAppCmdApp12:
{
ChangeSizeExtentsL();
break;
}
case EBrCtlSampleAppCmdApp13:
{
PageInfoL();
break;
}
case EBrCtlSampleAppCmdApp14:
{
ContentSizeImageCountL();
break;
}
default:
if (aCommand >= iCommandBase &&
aCommand < iCommandBase + TBrCtlDefs::ECommandIdWMLBase &&
iBrCtlInterface)
{
iBrCtlInterface->HandleCommandL(aCommand);
}
if (aCommand >= iCommandBase + TBrCtlDefs::ECommandIdWMLBase &&
aCommand < iCommandBase + TBrCtlDefs::ECommandIdRange &&
iBrCtlInterface)
{
iBrCtlInterface->HandleCommandL(aCommand);
}
break;
}
}
// ----------------------------------------------------
// CBrCtlSampleAppContainer::OfferKeyEventL(const
// TKeyEvent& aKeyEvent,TEventCode aType)
// ----------------------------------------------------
//
TKeyResponse
CBrCtlSampleAppContainer::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
{
if (iBrCtlInterface)
{
return iBrCtlInterface->OfferKeyEventL(aKeyEvent, aType);
}
return EKeyWasConsumed;
}
// ----------------------------------------------------
// CBrCtlSampleAppContainer::DynInitMenuPaneL(
// TInt aResourceId, CEikMenuPane* aMenuPane)
// ----------------------------------------------------
//
void
CBrCtlSampleAppContainer::DynInitMenuPaneL(TInt aResourceId, CEikMenuPane* aMenuPane)
{
if (iBrCtlInterface && aResourceId == R_BRCTLSAMPLEAPP_MENU )
{
iBrCtlInterface->AddOptionMenuItemsL(*aMenuPane, aResourceId);
RPointerArray<TBrCtlWmlServiceOption>* options;
options = iBrCtlInterface->WMLOptionMenuItemsL();
TInt i;
TInt count = options->Count();
for (i = 0; i < count; i++)
{
TBrCtlWmlServiceOption* option = (*options)[i];
if (option != NULL)
{
CEikMenuPaneItem::SData item;
item.iText.Copy(option->Text());
item.iCommandId = option->ElemID();
item.iFlags = 0;
item.iCascadeId = 0;
aMenuPane->InsertMenuItemL(item, 0);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -