Symbian Study Notes (14): Use browser control API

Source: Internet
Author: User
Let's take a look at this browser control API, just as a guide. In fact, the best way to grasp its usage is to open the example 9.1/s60_3rd/s60ex/brctlsampleapp for reading, it covers almost all the usage of this API.

In uninews, I only use the most basic usage. The following code is provided:

First, declare a control member in the H file: # include <coecntrl. h>
# Include <brctlinterface. h>
# Include <brctldefs. h>
# Include <brctllayoutobserver. h>
# Include <brctllinkresolver. h>

Class cuninewswebcontainer: Public ccoecontrol, mcoecontrolobserver, mbrctlloadeventobserver ...{
Public:
// Constructors and destructor
~ Cuninewswebcontainer ();
Static cuninewswebcontainer * newl (const trect & arect );
Static cuninewswebcontainer * newlc (const trect & arect );

PRIVATE:
// New functions
Void constructl (const trect & arect );
Cuninewswebcontainer ();

Public:
// Functions from base classes
Tkeyresponse offerkeyeventl (const tkeyevent & akeyevent, teventcode Atype );
Void handlebrowserloadeventl (tbrctldefs: tbrctlloadevent aloadevent, tuint asize, tuint16 atransactionid );
Void loadcontentl (tint ID );

PRIVATE:
// Functions from base classes
Void sizechanged ();
Tint countcomponentcontrols () const;
Ccoecontrol * componentcontrol (tint aindex) const;
Void draw (const trect & arect) const;
Void handlecontroleventl (ccoecontrol * acontrol, tcoeevent aeventtype );

Hbufc8 * readfilelc (const tdesc & afilename );
PRIVATE:
// Data
Cbrctlinterface * ibrowser;
Tuint icapabilities;
Tint icommandbase;
};

It mainly declares three members, of which cbrctlinterface is the main browser control, and the other two are the parameters required during the construction. This class is derived from the interface mbrctlloadeventobserver, so the method to implement it is void handlebrowserloadeventl (tbrctldefs: tbrctlloadevent aloadevent, tuint asize, tuint16 atransactionid );

In the implementation file CPP, we need to construct it: void cuninewswebcontainer: constructl (const trect & arect )...{
// Create a window for this application view
Createmediawl ();
Setrect (arect );

// Add your code here...
Ibrocontro= createbrowsercontroll (this
, Arect
, Icapabilities
, Icommandbase
, Null // softkey observer
, Null // link Resolver
, Null // special load observer
, Null // layout observer
, Null // dialog provider
);
Ibroel-> activatel ();
If (ibrowser )...{
Ibrowser-> addloadeventobserverl (this );
Ibrowser-> setbrowsersettingl (tbrctldefs: esettingsfontsize, tbrctldefs: efontsizelevelnormal );


}
Activatel ();
}

In the constructor, We initialize the two parameters: cuninewswebcontainer ()...{
// No implementation required
Icapabilities = tbrctldefs: ecapabilitydisplayscrollbar | tbrctldefs: ecapabilityloadhttpfw;
Icommandbase = tbrctldefs: ecommandidbase;
Ibrowser = NULL;
}

Remember to cancel the event listener: cuninewswebcontainer ::~ Cuninewswebcontainer ()...{
// No implementation required
If (ibrowser )...{
Ibrowser-> removeloadeventobserver (this );
}
Delete ibrowser;
Ibrowser = NULL;
}

In addition, like other controls, it needs to be processed during resize, and it also needs to declare itself as a component.
The handlebrowserloadeventl method only needs to be re-painted.

It's easy to use void cuninewswebcontainer: loadcontentl (tint ID)
...{
If (ibrowser )...{
Tfilename fname;
Fname. Format (kcontentfile, ID );
Ibroll-> loadurll (fname );
}
}

This is just one sentence of loadurll. This URL can be http: // or file: //, which is very convenient.

However, we often need to load and display the content in the memory, so we can do a little more work: void cuninewswebcontainer: loadcontentl (tint ID)
...{
If (ibrowser )...{
Tfilename fname;
Fname. Format (kcontentfile, ID );

Hbufc8 * Buf = readfilelc (fname );

_ Forward (kurl, "data: % d ");
Tbuf <32> URL;
URL. Format (kurl, ID );

_ Lit8 (kdatatype, "text/html ");
Tdatatype datatype (kdatatype ());
Tuid uid;
UID. iuid = kcharactersetidentifierutf8;

Ibroype-> loaddatal (URL, * Buf, datatype, UID );
Cleanupstack: popanddestroy ();
}
}

Here, the URL starts with data: // and is mainly used as a tag for historical records. The content format is text/html, but it must be tdatatype. The character set uses utf8.

After a try, I felt that loading to the memory is faster than loading files directly (mainly when switching pages ).

In addition, this control has a bug, which may cause memory leakage when exiting. According to the online saying, activate it after construction, but it does not work after I try it ?!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.