webengine/wmlengine/src/xhtml/include/XhtmlObjectElementHandler.h
changeset 0 dd21522fd290
child 37 cb62a4f66ebe
equal deleted inserted replaced
-1:000000000000 0:dd21522fd290
       
     1 /*
       
     2 * Copyright (c) 2003 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:  Handles object tags in XHTML documents.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #ifndef CXHTMLOBJECTELEMENTHANDLER__H
       
    21 #define CXHTMLOBJECTELEMENTHANDLER__H
       
    22 
       
    23 // INCLUDES
       
    24 #include <e32def.h>
       
    25 #include <e32base.h>
       
    26 
       
    27 #include "nwx_defs.h"
       
    28 #include "nw_dom_node.h"
       
    29 
       
    30 #include "HedLoadObserver.h"
       
    31 #include "LMgrBoxDestructionListener.h"
       
    32 #include "ObjectUtils.h"
       
    33 
       
    34 // CONSTANTS
       
    35 
       
    36 // MACROS
       
    37 
       
    38 // DATA TYPES
       
    39 
       
    40 // FUNCTION PROTOTYPES
       
    41 
       
    42 // FORWARD DECLARATIONS
       
    43 #ifdef __cplusplus
       
    44 extern "C" {
       
    45 #endif /* __cplusplus */
       
    46 
       
    47 typedef struct NW_HED_ContentHandler_s NW_HED_ContentHandler_t;
       
    48 typedef struct NW_XHTML_ContentHandler_s NW_XHTML_ContentHandler_t;
       
    49 typedef struct NW_XHTML_ElementHandler_s NW_XHTML_ElementHandler_t;
       
    50 typedef struct NW_LMgr_ContainerBox_s NW_LMgr_ContainerBox_t;
       
    51 typedef struct NW_LMgr_Box_s NW_LMgr_Box_t;
       
    52 typedef struct NW_Evt_Event_s NW_Evt_Event_t;
       
    53 typedef struct NW_Text_Abstract_s NW_Text_t;
       
    54 
       
    55 #ifdef __cplusplus
       
    56 }
       
    57 #endif /* __cplusplus */
       
    58 
       
    59 // CLASS DECLARATION
       
    60 
       
    61 // TODO: This class should be derived from CElementHandler once the browser is
       
    62 //       converted to c++.
       
    63 
       
    64 class CXHTMLObjectElementHandler : public CBase, public MLMgrBoxDestructionListener, 
       
    65         public MHEDLoadObserver
       
    66     {
       
    67     public:  // Constructors and destructor
       
    68         /**
       
    69         * Two-phased constructor.
       
    70         */
       
    71         static CXHTMLObjectElementHandler* NewL(const NW_XHTML_ElementHandler_t* aElementHandler,
       
    72                 NW_XHTML_ContentHandler_t* aContentHandler, NW_DOM_ElementNode_t* aElementNode);
       
    73 
       
    74         /**
       
    75         * Destructor.
       
    76         */
       
    77         virtual ~CXHTMLObjectElementHandler();
       
    78 
       
    79 
       
    80     public:  // Functions from MLMgrBoxDestructionListener
       
    81         /**
       
    82         * Recieves notifications when the box has been destroyed. 
       
    83         *
       
    84         * @since 2.6
       
    85         * @return void
       
    86         */
       
    87         void Destroyed();
       
    88 
       
    89 
       
    90     public:  // MHEDLoadObserver
       
    91         /**
       
    92         * Passes a HEAD response to the observer.
       
    93         *
       
    94         * @param aTransactionId the transaction id.
       
    95         * @param aResponse the HEAD response to be processed.
       
    96         * @param aUrlRequest the url request.
       
    97         * @param aClientData the client data past with the request.
       
    98         * @return void.
       
    99         */
       
   100         void HeadCompleted(TUint16 aTransactionId, const NW_Url_Resp_t& aResponse, 
       
   101                 const NW_HED_UrlRequest_t& aUrlRequest, void* aClientData);
       
   102 
       
   103         /**
       
   104         * Passes a chunk of a response to the observer.
       
   105         *
       
   106         * @param aTransactionId the transaction id.
       
   107         * @param aChunkIndex the chunk count of this call, aChunkIndex > 0
       
   108         * @param aResponse the HEAD response to be processed.
       
   109         * @param aUrlRequest the url request.
       
   110         * @param aClientData the client data past with the request.
       
   111         * @return void.
       
   112         */
       
   113         void ChunkReceived(TUint16 aTransactionId, TUint32 aChunkIndex, 
       
   114                 const NW_Url_Resp_t& aResponse, const NW_HED_UrlRequest_t& aUrlRequest, 
       
   115                 void* aClientData);
       
   116 
       
   117         /**
       
   118         * Called when a response completes successfully or in error.
       
   119         *
       
   120         * @param aStatusClass the type of status-code found in aStatus -- 
       
   121                  BRSR_STAT_CLASS_HTTP or BRSR_STAT_CLASS_GENERAL.
       
   122         * @param aStatus the final load status of the request.
       
   123         * @param aTransactionId the transaction id.
       
   124         * @param aUrlRequest the url request.
       
   125         * @param aClientData the client data past with the request.
       
   126         * @return void.
       
   127         */
       
   128         void LoadCompleted(TInt16 aStatusClass, TBrowserStatusCode aStatus, 
       
   129                 TUint16 aTransactionId, const NW_HED_UrlRequest_t& aUrlRequest, 
       
   130                 void* aClientData);
       
   131 
       
   132 
       
   133     public:  // New Methods
       
   134         /**
       
   135         * Initializes the ElementHandler.
       
   136         *
       
   137         * @return status code
       
   138         */
       
   139         virtual TBrowserStatusCode Initialize(void);
       
   140 
       
   141         /**
       
   142         * Creates the box-tree associated with the tag.
       
   143         *
       
   144         * @param aParentBox the parent to attach the new box-tree to.
       
   145         * @return status code
       
   146         */
       
   147         virtual TBrowserStatusCode CreateBoxTree(NW_LMgr_ContainerBox_t& aParentBox);  
       
   148 
       
   149         /**
       
   150         * Processes events targeted at boxes created by the ElementHandler.
       
   151         *
       
   152         * @param aBox the target box.
       
   153         * @param aEvent the event.
       
   154         * @return NW_LMgr_EventAbsorbed or NW_LMgr_EventNotAbsorbed
       
   155         */
       
   156         virtual NW_Uint8 ProcessEvent(const NW_LMgr_Box_t& aBox, const NW_Evt_Event_t& aEvent);
       
   157 
       
   158         /**
       
   159         * This is a special purpose method to get the element node 
       
   160         * associated with this handler.
       
   161         *
       
   162         * @return the elementNode associated with this handler.
       
   163         */
       
   164         const NW_DOM_ElementNode_t* ElementNode(void) const;
       
   165 
       
   166         /**
       
   167         * This is a special purpose method to get the "selected" element.
       
   168         * See the comment on SelectElement.
       
   169         *
       
   170         * @return the selected elementNode.
       
   171         */
       
   172         const NW_DOM_ElementNode_t* SelectedElementNode(void) const;
       
   173 
       
   174         /**
       
   175         * Applies the content type and length properties on the given box.  This is 
       
   176         * used in the download dialog box.
       
   177         *
       
   178         * @param aBox the box to apply the properties on.
       
   179         * @return status code.
       
   180         */
       
   181         TBrowserStatusCode ApplyInfoProperties(NW_LMgr_Box_t& aBox);
       
   182 
       
   183 
       
   184     private:  // Private Methods
       
   185         /**
       
   186         * C++ default constructor.
       
   187         */
       
   188         CXHTMLObjectElementHandler(const NW_XHTML_ElementHandler_t* aElementHandler,
       
   189                 NW_XHTML_ContentHandler_t* aContentHandler, NW_DOM_ElementNode_t* aElementNode);
       
   190 
       
   191         /**
       
   192         * By default Symbian 2nd phase constructor is private.
       
   193         */
       
   194         void ConstructL(void);
       
   195 
       
   196         /**
       
   197         * Loads the resource associated with object tag.
       
   198         *
       
   199         * @param aType the mime-type of the of the resource or NULL 
       
   200         *        if the type isn't known.
       
   201         * @param aUrl the url of the of the resource or NULL.
       
   202         * @param aHandlerType Type of the load
       
   203         * @return status code
       
   204         */
       
   205         TBrowserStatusCode LoadObjectResource(const TDesC* aType, 
       
   206                 const TDesC* aUrl, ObjectUtils::THandlerType aHandlerType);
       
   207 
       
   208         /**
       
   209         * Loads the HEAD information of the resource associated with object tag.
       
   210         *
       
   211         * @return status code
       
   212         */
       
   213         TBrowserStatusCode LoadObjectInfo(void);
       
   214 
       
   215         /**
       
   216         * Returns the associated content handler or NULL if one isn't found.
       
   217         *
       
   218         * @return the associated content handler 
       
   219         */
       
   220         NW_HED_ContentHandler_t* AssociatedContentHandler(void);
       
   221 
       
   222         /**
       
   223         * Set the place-holder text to the given descriptor.
       
   224         *
       
   225         * @param aObjectBox the Object box. 
       
   226         * @param aPlaceHolderText the string.
       
   227         *
       
   228         * @return status code 
       
   229         */
       
   230         TBrowserStatusCode SetPlaceHolderText(NW_LMgr_Box_t& aObjectBox, 
       
   231                 const TDesC& aPlaceHolderText);
       
   232 
       
   233         /**
       
   234         * Set the place-holder text to the given resource id.
       
   235         *
       
   236         * @param aObjectBox the Object box. 
       
   237         * @param aResourceId the string's resource id.
       
   238         *
       
   239         * @return status code 
       
   240         */
       
   241         TBrowserStatusCode SetPlaceHolderText(NW_LMgr_Box_t& aObjectBox, 
       
   242                 TInt aResourceId);
       
   243 
       
   244         /**
       
   245         * Removes the place holder -- puts the Object box in the active state.
       
   246         *
       
   247         * @param aObjectBox the Object box. 
       
   248         *
       
   249         * @return void 
       
   250         */
       
   251         void RemovePlaceHolder(NW_LMgr_Box_t& aObjectBox);
       
   252 
       
   253         /**
       
   254         * CXHTMLObjectElementHandler::SelectElement
       
   255         *
       
   256         * Embedded resources are specified in an xhtml document using the object tag.  
       
   257         * This tag can be very simple to quite complex.  See the cpp file for some examples.
       
   258         * This method determines if iElementNode or one of its descendants can be selected
       
   259         * and displayed.  Once an element is selected it is stored in iSelectedElementNode.
       
   260         * iSelectedElementNode is used in GetAttribute to extract attribute values from 
       
   261         * the selected element.
       
   262         *
       
   263         * @return status code. 
       
   264         */
       
   265         TBrowserStatusCode SelectElement(void);
       
   266 
       
   267         /**
       
   268         * Gets the value of the given attribute as a descriptor.
       
   269         *
       
   270         * @param aToken identifies the attribute to get.
       
   271         * @param aValue upon success it equals the value of the attribute.
       
   272         *        The caller adopts aValue.
       
   273         * @return status code
       
   274         */
       
   275         TBrowserStatusCode GetAttribute(TInt16 aToken, TDesC** aValue);
       
   276 
       
   277         /**
       
   278         * Gets the value of the source attribute as a descriptor.
       
   279         *
       
   280         * @param aValue upon success it equals the value of the src attribute.
       
   281         *        The caller adopts aValue.
       
   282         * @return status code
       
   283         */
       
   284         TBrowserStatusCode GetSrcAttribute(TDesC** aValue);
       
   285 
       
   286         /**
       
   287         * Gets the value of the content-type attribute as a descriptor.
       
   288         *
       
   289         * @param aValue upon success it equals the value of the src attribute.
       
   290         *        The caller adopts aValue.
       
   291         * @return status code
       
   292         */
       
   293         TBrowserStatusCode GetTypeAttribute(TDesC** aValue);
       
   294 
       
   295         /**
       
   296         * Gets the value of the source attribute by using the classId attribute,
       
   297         * the cooresponding param element and the object attribute mappings table.
       
   298         *
       
   299         * @param aValue upon success it equals the value of the src attribute.
       
   300         *        The caller adopts aValue.
       
   301         * @return status code
       
   302         */
       
   303         TBrowserStatusCode GetObjectAttributeMapSrc(TDesC** aValue);
       
   304 
       
   305         /**
       
   306         * Returns the cooresponding value (either param-name or content-type) given
       
   307         * the class-id.
       
   308         *
       
   309         * @param aClassId the class-id used to map to the requested value.
       
   310         * @param aValueSelector used to select the cooresponding value 
       
   311         *                       (either KParamName or KContentType)
       
   312         * @return the value or NULL on out of memory.
       
   313         */
       
   314         TDesC* GetObjectAttributeMappedValue(const TDesC& aClassId, TInt aValueSelector);
       
   315 
       
   316         /**
       
   317         * Returns if the <object> element is enclosed within a hyperlink
       
   318         *
       
   319         * @return If the <object> element is enclosed within a hyperlink
       
   320         */
       
   321         TBool InHyperLink();
       
   322 
       
   323     private:  // Data
       
   324         const NW_XHTML_ElementHandler_t*    iElementHandler;
       
   325 	      NW_XHTML_ContentHandler_t*          iContentHandler;
       
   326         NW_DOM_ElementNode_t*               iElementNode;
       
   327         NW_DOM_ElementNode_t*               iSelectedElementNode;
       
   328 
       
   329         NW_LMgr_Box_t*                      iObjectBox;
       
   330         ObjectUtils::THandlerType           iLoadedHandlerType;
       
   331         TBool                               iIsDownloading;
       
   332 
       
   333         TBool                               iObjectInfoValidated;
       
   334         HBufC*                              iContentType;
       
   335         HBufC*                              iContentLength;
       
   336         TInt16                              iTransactionId;
       
   337     };
       
   338 
       
   339 #endif  // CXHTMLOBJECTELEMENTHANDLER__H