diff --git a/mozilla/lib/layout/laylayer.c b/mozilla/lib/layout/laylayer.c index 74b85aeb1d4..a69bc1f0f4b 100644 --- a/mozilla/lib/layout/laylayer.c +++ b/mozilla/lib/layout/laylayer.c @@ -36,6 +36,9 @@ #define Z_CELL_BACKGROUND_LAYER -1000 /* Table cell backgrounds */ #define Z_BACKGROUND_LAYER -1001 /* Layer/document backgrounds */ +#ifdef LAYPROBE_API +#include "layprobe.h" +#endif #ifdef PROFILE #pragma profile on @@ -522,6 +525,15 @@ lo_html_event_handler_func(CL_Layer *layer, XP_MEMCPY(event_closure->event->fe_event, event->fe_event, event->fe_event_size); } +#ifdef LAYPROBE_API + { + LAPIEventInfo ei; + LAPI_COPY_JS2API_EVENT(&ei,jsevent); + ei.Context = closure->context; + LAPINotificationHandler(&ei); + } +#endif /* LAYPROBE_API */ + ET_SendEvent(closure->context, pElement, jsevent, lo_html_event_callback, event_closure); return PR_TRUE; diff --git a/mozilla/lib/layout/layout.c b/mozilla/lib/layout/layout.c index a004c46fa90..40972c49604 100644 --- a/mozilla/lib/layout/layout.c +++ b/mozilla/lib/layout/layout.c @@ -45,6 +45,11 @@ #include "plvector.h" #include "htrdf.h" +#ifdef LAYPROBE_API +#include "layprobe.h" +#endif + + /* WEBFONTS are defined only in laytags.c and layout.c */ #define WEBFONTS @@ -430,6 +435,7 @@ lo_NewTopState(MWContext *context, char *url) top_state->wedged_on_mocha = FALSE; top_state->in_cell_relayout = FALSE; /* Used for resize without reload stuff */ top_state->metaTags = NULL; + top_state->LAPIprobe = NULL; return(top_state); } @@ -3718,13 +3724,29 @@ lo_FinishLayout(MWContext *context, lo_DocState *state, int32 mocha_event) lo_use_default_doc_background(context, state); } - if (state && state->top_state) - ET_SendLoadEvent(context, mocha_event, NULL, NULL, - LO_DOCUMENT_LAYER_ID, - state->top_state->resize_reload); - else - ET_SendLoadEvent(context, mocha_event, NULL, NULL, - LO_DOCUMENT_LAYER_ID, FALSE); +#ifdef LAYPROBE_API + { + /* Send a notification when a frame has finished loading */ + XP_List* pList = GetCallbackFuncList((int32)FRAME_DOCUMENT_COMPLETE); + + if (pList) + { + while (pList = pList->next) + { + if (pList->object) + (*((ID_NOTIFY_PT)(pList->object)))((void*)context); + } + } + } +#endif /* LAYPROBE_API */ + + if (state && state->top_state) + ET_SendLoadEvent(context, mocha_event, NULL, NULL, + LO_DOCUMENT_LAYER_ID, + state->top_state->resize_reload); + else + ET_SendLoadEvent(context, mocha_event, NULL, NULL, + LO_DOCUMENT_LAYER_ID, FALSE); /* Reset state for force loading images. */ LO_SetForceLoadImage(NULL, FALSE); @@ -6063,6 +6085,29 @@ lo_InternalDiscardDocument(MWContext *context, lo_DocState *state, } } +#ifdef LAYPROBE_API + { + /* Send a notification when a frame unloads */ + XP_List * pList = GetCallbackFuncList((int32)FRAME_ON_UNLOAD); + + if (pList) + { + while (pList = pList->next) + { + if (pList->object) + (*((ID_NOTIFY_PT)pList->object))((void*)context); + } + } + + /* clean up allocated memory */ + if (state->top_state->LAPIprobe) + { + LAPIDestroyProbe(state->top_state->LAPIprobe); + state->top_state->LAPIprobe = NULL; + } + } +#endif /* LAYPROBE_API */ + if ( state->top_state->trash != NULL) { lo_RecycleElements(context, state, diff --git a/mozilla/lib/layout/layout.h b/mozilla/lib/layout/layout.h index 49153d88789..a3c0681e35e 100644 --- a/mozilla/lib/layout/layout.h +++ b/mozilla/lib/layout/layout.h @@ -855,6 +855,7 @@ struct lo_TopState_struct { void /*DOM_Node*/ *top_node; /* top of the DOM_Node tree */ void /*DOM_Node*/ *current_node; /* active node (only during tree gen) */ #endif + void* LAPIprobe; }; /* Script type codes, stored in top_state->in_script. */ diff --git a/mozilla/lib/layout/layprobe.c b/mozilla/lib/layout/layprobe.c index 2cfc78c632c..db5eb283b17 100644 --- a/mozilla/lib/layout/layprobe.c +++ b/mozilla/lib/layout/layprobe.c @@ -29,7 +29,6 @@ #include "layout.h" #include "xp.h" - typedef struct _lo_ProbeState { MWContext *context; lo_TopState *top_state; @@ -40,6 +39,22 @@ typedef struct _lo_ProbeState { XP_List *parent_type_stack; /* Stack of type of parents seen till now */ } lo_ProbeState; + +typedef struct _EnumInfo { + int16 LAPI_Type; + char* Name; + int32 xPos; + int32 yPos; +} stElementInfo; + + +/* Private variables */ +static int32 LAPI_LastError = 0; +static XP_List* CallbackList[MAX_CALLBACKS]; + +/* Private types */ +typedef Bool (LAPI_ELEMENTS_ENUM_FUNC)(MWContext* FrameID, LO_Element* ElementID, stElementInfo* ElementInfo, void** lppData); + /* Private function prototypes */ static Bool lo_QA_IsValidElement (LO_Element *ele); static LO_Element * lo_QA_GetValidNextElement (LO_Element *ele); @@ -47,6 +62,17 @@ static Bool lo_QA_ElementHasColor( LO_Element * ele); static Bool lo_QA_GetColor( LO_Element *ele, LO_Color *color, ColorType type); static long lo_QA_RGBColorToLong( LO_Color color ); +static lo_ProbeState* GetProbe( MWContext *context ); +static int16 GetElementLAPIType(LO_Element* ElementID); +static Bool IsLowLevelElementType(LO_Element* ElementID); +static Bool EnumElements(MWContext* FrameID, LO_Element *ElementID, + void ** lppData, stElementInfo* pElementInfo, + LAPI_ELEMENTS_ENUM_FUNC *EnumFunc); +/* Privat enum functions */ +static Bool EnumGetElementList(MWContext* FrameID, LO_Element* ElementID, stElementInfo* pElementInfo, void** lppData); +static Bool EnumGetElementFromPoint(MWContext* FrameID, LO_Element *ElementID, stElementInfo* pElementInfo, void ** lppData); + + /* * Constructor/Destructor for probe * @@ -426,7 +452,7 @@ Bool LO_QA_GetText( long probeID, char *text, long length) if (ps && ps->curr_ele) { if (ps->curr_ele->lo_any.type == LO_TEXT) { - XP_ASSERT(XP_STRLEN((const char *)ps->curr_ele->lo_text.text) == length); + XP_ASSERT(XP_STRLEN((const char *) ps->curr_ele->lo_text.text) == length); strncpy(text, (const char *) ps->curr_ele->lo_text.text, length); success = TRUE; } @@ -435,6 +461,71 @@ Bool LO_QA_GetText( long probeID, char *text, long length) return success; } +/* + Function to get text attributes (font, color, style ..) at once. Requires + preallocated LO_TextAttr_struct with size member set on. + + char * font_face + member points to allocated buffer. Caller responsibility to free buffer + + LO_TextAttr_struct * next + member ignored, set to 0. + + void * FE_Data (recently cached font object) + member ignored, set to 0; + + + +*/ + +Bool LO_QA_GetTextAttributes( long probeID, void *attributes) +{ + lo_ProbeState *ps = (lo_ProbeState *) probeID; + Bool success = FALSE; + size_t len = 0; + + if (ps && ps->curr_ele) { + if (ps->curr_ele->lo_any.type == LO_TEXT) { + if (((LO_TextAttr *)attributes)->size == + ps->curr_ele->lo_text.text_attr->size) { + + ((LO_TextAttr *)attributes)->fontmask = + ps->curr_ele->lo_text.text_attr->fontmask; + ((LO_TextAttr *)attributes)->fg = + ps->curr_ele->lo_text.text_attr->fg; + ((LO_TextAttr *)attributes)->bg = + ps->curr_ele->lo_text.text_attr->bg; + ((LO_TextAttr *)attributes)->no_background = + ps->curr_ele->lo_text.text_attr->no_background; + ((LO_TextAttr *)attributes)->attrmask = + ps->curr_ele->lo_text.text_attr->attrmask; + + /* copy string of font faces */ + if (len = strlen(ps->curr_ele->lo_text.text_attr->font_face)) { + ((LO_TextAttr *)attributes)->font_face = + (char *)XP_ALLOC(len + 1); + strcpy(((LO_TextAttr *)attributes)->font_face, + ps->curr_ele->lo_text.text_attr->font_face); + } + ((LO_TextAttr *)attributes)->font_face = + ps->curr_ele->lo_text.text_attr->font_face; + ((LO_TextAttr *)attributes)->point_size = + ps->curr_ele->lo_text.text_attr->point_size; + ((LO_TextAttr *)attributes)->font_weight = + ps->curr_ele->lo_text.text_attr->font_weight; + ((LO_TextAttr *)attributes)->FE_Data = 0; + ((LO_TextAttr *)attributes)->next = 0; + ((LO_TextAttr *)attributes)->charset = + ps->curr_ele->lo_text.text_attr->charset; + + success = TRUE; + } + } + } + + return success; +} + /* Color Type Elements containing the color type ---------- ---------------------------------- LO_QA_BACKGROUND_COLOR LO_TEXT, LO_BULLET, LO_CELL @@ -464,6 +555,1481 @@ Bool LO_QA_GetColor( long probeID, long *color, ColorType type) } +/* LAPIGetLastError +** +** Description: This function retrieves the error code of the last error +** encountered by an API call. +** +** Parameters: None. +** +** Return Value: The return value is the error code of the last error. +*/ +int32 LAPIGetLastError() +{ + return LAPI_LastError; +} + + +/* DestroyProbe +** +** Description: This function deletes a probe struct, It should +** ` only be used to clear memory allocated when a frame is destroyed. +** Parameter should be the Probe member of MWContext. +** +** Parameters: ProbeID - the probe id to destroy. +** +** Return Value: None. +*/ +void LAPIDestroyProbe( + void* ProbeID +) +{ + LO_QA_DestroyProbe((long)ProbeID); +} + + +/********************************************************** +********* Queries API ******** +**********************************************************/ + + +/* LAPIGetFrames +** +** Description: This function retrieves a list of all frames. +** +** Parameters: None. +** +** Return Value: If the function succeeds, the return value is TRUE, +** if there are no frames FALSE is returned and LastError will be LAPI_E_NOELEMENTS +*/ +Bool LAPIGetFrames(XP_List** lppContextList) +{ + *lppContextList = XP_GetGlobalContextList(); + + if (*lppContextList) + return TRUE; + + LAPI_LastError = LAPI_E_NOELEMENTS; + return FALSE; +} + + +/* LAPIFrameGetStringProperty +** +** Description: This function retrieves a property of a frame. +** +** Parameters: FrameID - a frame id. +** PropertyName - a string identifing the property +** lpszPropVal - an allocated buffer to write the string to. +** +** Return Value: If the function succeeds, the return value is TRUE, +** otherwise the function returns FALSE and LastError will be: +** LAPI_E_INVALIDFRAME if the given id doesn't identify an existing frame, +** LAPI_E_INVALIDPROP if the given propery name isn't supported. +*/ +Bool LAPIFrameGetStringProperty( + MWContext* FrameID, + char* PropertyName, + char** lpszPropVal +) +{ + lo_ProbeState* ps = GetProbe(FrameID); + + if (ps == NULL) + { /* invalid frame id */ + LAPI_LastError = LAPI_E_INVALIDFRAME; + return FALSE; + } + + if (!stricmp(PropertyName, "title")) + { + *lpszPropVal = FrameID->title; + return TRUE; + } + else if (!stricmp(PropertyName, "name")) + { + *lpszPropVal = FrameID->name; + return TRUE; + } + else if (!stricmp(PropertyName, "url")) + { + *lpszPropVal = FrameID->url; + return TRUE; + } + + LAPI_LastError = LAPI_E_INVALIDPROP; + return FALSE; +} + + +/* LAPIFrameGetNumProperty +** +** Description: This function retrieves a property of a frame. +** +** Parameters: FrameID - a frame id. +** PropertyName - a string identifing the property +** lpPropVal - a pointer to a numeric var to write the prop' val into. +** +** Return Value: If the function succeeds, the return value is TRUE, +** otherwise the function returns FALSE and LastError will be: +** LAPI_E_INVALIDFRAME if the given id doesn't identify an existing frame, +** LAPI_E_INVALIDPROP if the given propery name isn't supported, +*/ +Bool LAPIFrameGetNumProperty( + MWContext* FrameID, + char* PropertyName, + int32* lpPropVal +) +{ + lo_ProbeState* ps = GetProbe(FrameID); + + if (ps == NULL) + { /* invalid frame id */ + LAPI_LastError = LAPI_E_INVALIDFRAME; + return FALSE; + } + + if (!stricmp(PropertyName, "width")) + { + *lpPropVal = (ps->doc_state)->win_width; + return TRUE; + } + else if (!stricmp(PropertyName, "height")) + { + *lpPropVal = (ps->doc_state)->win_height; + return TRUE; + } + + LAPI_LastError = LAPI_E_INVALIDPROP; + return FALSE; +} + + +/* LAPIFrameGetElements +** +** Description: This function retrieves a list of elements which match a gived type +** and name.if not specified, all elements are retrieved.. +** +** Parameters: lpList - a list to be filled with all the elements +** FrameID - a frame id. +** ElementLAPIType - the element type/s to retrieve. +** ElementName - retrive elements with this name. +** +** Return Value: If the function succeeds, the return value is TRUE and the +** list is populated with elementID's, otherewise return value is FALSE, +** LastError will be: +** LAPI_E_INVALIDFRAME if the frame id isn't valid, +** LAPI_E_NOELEMENTS if there are no elements that fit the request. +*/ +Bool LAPIFrameGetElements( + XP_List* lpList, + MWContext* FrameID, + int16 ElementLAPIType, + char* ElementName +) +{ + lo_ProbeState* ps = GetProbe(FrameID); + stElementInfo ElementInfo; + + ElementInfo.LAPI_Type = ElementLAPIType; + ElementInfo.Name = ElementName; + + if (ps == NULL) + { /* invalid frame id */ + LAPI_LastError = LAPI_E_INVALIDFRAME; + return FALSE; + } + + EnumElements(FrameID, LAPIGetFirstElement(FrameID), &lpList, + &ElementInfo, &EnumGetElementList); + + if (lpList && lpList->next) + return TRUE; + else + { /* empty list */ + LAPI_LastError = LAPI_E_NOELEMENTS; + return FALSE; + } +} + + +/* LAPIFrameGetElementFromPoint +** +** Description: This function retrieves the lowest level +** layout element from a given point in screen coordinates. +** +** Parameters: FrameID - a frame id. +** xPos - the x coordinate of the point. +** yPos - the y coordinate of the point. +** +** Return Value: If the function succeeds, the return value an ElementID, +** if the function fails the return value is NULL and LastError +** gets set to LAPI_E_INVALIDFRAME if the frame parameter is invalid or to +** LAPI_E_NOELEMENTS if no element is under this point. +*/ +LO_Element* LAPIFrameGetElementFromPoint( + MWContext * FrameID, + int xPos, + int yPos +) +{ + lo_ProbeState* ps = GetProbe(FrameID); + LO_Element* ElementID; + stElementInfo ElementInfo; + + (ElementInfo).xPos = xPos; + (ElementInfo).yPos = yPos; + + if (ps == NULL) + { /* invalid frame id */ + LAPI_LastError = LAPI_E_INVALIDFRAME; + return NULL; + } + + EnumElements(FrameID, LAPIGetFirstElement(FrameID), &ElementID, + &ElementInfo, &EnumGetElementFromPoint); + + if (ElementID) + return ElementID; + else + { + LAPI_LastError = LAPI_E_NOELEMENTS; + return NULL; + } +} + + +/* LAPIGetFirstElement +** +** Description: The GetFirstElement function retrieves the first element in the frame. +** +** Parameters: FrameID - a frame id. +** +** Return Value: If the function succeeds, the return value an ElementID, +** if the function fails the return value is NULL and LastError +** gets set to LAPI_E_INVALIDFRAME if the frame parameter is invalid or to +** LAPI_E_NOELEMENTS if the frame contains no elements. +*/ +LO_Element* LAPIGetFirstElement ( + MWContext * FrameID +) +{ + lo_ProbeState* ps = GetProbe(FrameID); + + if (ps == NULL) + { /* invalid frame id */ + LAPI_LastError = LAPI_E_INVALIDFRAME; + return NULL; + } + + if (LO_QA_GotoFirstElement((long)ps)) + return ps->curr_ele; + else + { /* no elements */ + LAPI_LastError = LAPI_E_NOELEMENTS; + return NULL; + } +} + + +/* LAPIGetNextElement +** +** Description: Given an element, this function retrieves the next element. +** +** Parameters: FrameID - Identifies the relevant frame. +** ElementID - Identifies the reference element. +** +** Return Value: If the function succeeds, the return value an ElementID, +** if the function fails the return value is NULL and LastError +** gets set to LAPI_E_INVALIDFRAME if the frame parameter is invalid or to +** LAPI_E_INVALIDELEMENT if the given element is invalid. +** LAPI_E_NOELEMENTS if there's no next element. +*/ +LO_Element* LAPIGetNextElement ( + MWContext * FrameID, + LO_Element* ElementID +) +{ + lo_ProbeState* ps = GetProbe(FrameID); + LO_Element **line_array; + LO_Element* RefElement = ElementID; + + if (ps == NULL) + { /* invalid frame id */ + LAPI_LastError = LAPI_E_INVALIDFRAME; + return NULL; + } + + XP_LOCK_BLOCK ( line_array, LO_Element **, ps->doc_state->line_array ); + if (ElementID) + { + if (ElementID->type == LO_TABLE) + { + /* for a table we have to skip all the cells + and return the first element after */ + while(RefElement = (RefElement->lo_any).next) + { + if (RefElement->type != LO_CELL) + return RefElement; + } + } + else + { + if ((RefElement->lo_any).next) + return ((RefElement->lo_any).next); + }/* TODO - check for last cell in a table */ + + /* no next element */ + LAPI_LastError = LAPI_E_NOELEMENTS; + return NULL; + } + else + { /* invalid element */ + LAPI_LastError = LAPI_E_INVALIDELEMENT; + return NULL; + } +} + + + + +/* LAPIGetPrevElement +** +** Description: Given an element, this function retrieves the previous element. +** +** Parameters: FrameID - Identifies the relevant frame. +** ElementID - Identifies the reference element. +** +** Return Value: If the function succeeds, the return value an ElementID, +** if the function fails the return value is NULL and LastError +** gets set to LAPI_E_INVALIDFRAME if the frame parameter is invalid or to +** LAPI_E_NOELEMENTS if there's no previous element. +*/ +LO_Element* LAPIGetPrevElement ( + MWContext * FrameID, + LO_Element* ElementID +) +{ + lo_ProbeState* ps = GetProbe(FrameID); + LO_Element **line_array; + LO_Element* RefElement = ElementID; + + if (ps == NULL) + { /* invalid frame id */ + LAPI_LastError = LAPI_E_INVALIDFRAME; + return NULL; + } + + XP_LOCK_BLOCK ( line_array, LO_Element **, ps->doc_state->line_array ); + if (ElementID) + { + if (RefElement = (RefElement->lo_any).prev) + { + if (RefElement->type != LO_TABLE || ElementID->type != LO_CELL) + { /* not a first cell inside a table */ + if (RefElement->type == LO_CELL && ElementID->type != LO_CELL) + { /* a prev element can't be a cell unless the given element is a cell */ + while(RefElement = (RefElement->lo_any).prev) + { + if (RefElement->type == LO_TABLE) + return RefElement; + } + } + else + return ((RefElement->lo_any).prev); + } + } + + /* no prev element */ + LAPI_LastError = LAPI_E_NOELEMENTS; + return NULL; + } + else + { /* invalid element */ + LAPI_LastError = LAPI_E_INVALIDELEMENT; + return NULL; + } +} + + +/* LAPIGetChildElement +** +** Description: Given an element, this function retrieves its first child element. +** +** Parameters: FrameID - Identifies the relevant frame. +** ElementID - Identifies the reference element. +** +** Return Value: If the function succeeds, the return value an ElementID, +** if the function fails the return value is NULL and LastError +** gets set to LAPI_E_INVALIDFRAME if the frame parameter is invalid or to +** LAPI_E_NOELEMENTS if the element has no child elements. +*/ +LO_Element* LAPIGetChildElement ( + MWContext * FrameID, + LO_Element* ElementID +) +{ + lo_ProbeState* ps = GetProbe(FrameID); + LO_Element **line_array; + LO_Element* ret, *RefElement = (LO_Element*)ElementID; + + if (ps == NULL) + { /* invalid frame id */ + LAPI_LastError = LAPI_E_INVALIDFRAME; + return NULL; + } + + XP_LOCK_BLOCK ( line_array, LO_Element **, ps->doc_state->line_array ); + if (ElementID) + { + switch ((RefElement->lo_any).type) + { + case LO_TABLE: + { + if (ret = (RefElement->lo_any).next) + { + XP_ASSERT(ret->lo_any.type == LO_CELL); + return ret; + } + + LAPI_LastError = LAPI_E_NOELEMENTS; + return NULL; + } + case LO_CELL: + { + if (ret = (RefElement->lo_cell).cell_list) + return ret; + else if (ret = (RefElement->lo_cell).cell_float_list) + return ret; + + LAPI_LastError = LAPI_E_NOELEMENTS; + return NULL; + } + default: + { + LAPI_LastError = LAPI_E_NOELEMENTS; + return NULL; + } + + } + } + else + { /* invalid element */ + LAPI_LastError = LAPI_E_INVALIDELEMENT; + return NULL; + } +} + + + +/* +** LAPIGetParentElement +** +** Description: Given an element, this function retrieves its parenet element. +** This function is time consuming. +** +** Parameters: FrameID - Identifies the relevant frame. +** ElementID - Identifies the reference element. +** +** Return Value: If the function succeeds, the return value an ElementID, +** if the function fails the return value is NULL and LastError +** gets set to LAPI_E_INVALIDFRAME if the frame parameter is invalid or to +** LAPI_E_NOELEMENTS if the element has no parent elements. +*/ +LO_Element* LAPIGetParentElement ( + MWContext* FrameID, + LO_Element* ElementID +) +{ + lo_ProbeState* ps = GetProbe(FrameID); + + if (ps == NULL) + { + LAPI_LastError = LAPI_E_INVALIDFRAME; + return NULL; + } + + if (ElementID->type == LO_CELL) + return ((ElementID->lo_any).prev); + + if (LO_QA_GotoFirstElement((long)ps)) + { + /* do a DFS tree search for the element */ + do + { + /* goto the deepest child */ + while (LO_QA_GotoChildElement((long)ps)); + + if (ps->curr_ele == ElementID && ps->parent_type_stack) + { + /* Pop the parent type off of the parent type stack */ + uint8 parentType = (uint8) XP_ListRemoveEndObject( ps->parent_type_stack ); + switch (parentType) + { + case LO_TABLE: + { + if (ps->table_stack) + return (LO_Element *) XP_ListRemoveEndObject( ps->table_stack ); + } + case LO_CELL: + { + if (ps->cell_stack) + return (LO_Element *) XP_ListRemoveEndObject( ps->cell_stack ); + } + default: + { + LAPI_LastError = LAPI_E_UNEXPECTED; + return NULL; + } + } + } + } + while (LO_QA_GotoNextElement((long)ps)); + } + else + { + LAPI_LastError = LAPI_E_UNEXPECTED; + return NULL; + } +} + + +/* LAPIElementGetStringProperty +** +** Description: This function retrieves a property of an element. +** +** Parameters: FrameID - a frame id. +** ElementID - Identifies the reference element. +** PropertyName - a string identifing the property +** lpszPropVal - an allocated buffer to write the string to. +** +** Return Value: If the function succeeds, the return value is TRUE, otherwise FALSE is returned. +** otherwise the function returns LAPI_INVALID_NUM and LastError will be: +** LAPI_E_INVALIDFRAME if the given id doesn't identify an existing frame, +** LAPI_E_INVALIDPROP if the given propery name isn't supported, +*/ +Bool LAPIElementGetStringProperty( + MWContext* FrameID, + LO_Element* ElementID, + char* PropertyName, + char** lpszPropVal +) +{ + lo_ProbeState* ps = GetProbe(FrameID); + + if (ps == NULL) + { /* invalid frame id */ + LAPI_LastError = LAPI_E_INVALIDFRAME; + return FALSE; + } + + switch (ElementID->type) + { + case LO_TEXT: + if (!stricmp(PropertyName, "text") || !stricmp(PropertyName, "name")) + { + *lpszPropVal = (ElementID->lo_text).pText; + return TRUE; + } + if (!stricmp(PropertyName, "href")) + { + LO_AnchorData* pAnchorData = (ElementID->lo_text).anchor_href; + if (pAnchorData && pAnchorData->anchor && + (*((char*)(pAnchorData->anchor)) != '\0')) + + *lpszPropVal = (char*)pAnchorData->anchor; + return TRUE; + } + break; + + case LO_HRULE: + break; + case LO_IMAGE: + if (!stricmp(PropertyName, "alt")) + { + *lpszPropVal = (char*)((ElementID->lo_image).alt); + return TRUE; + } + else if (!stricmp(PropertyName, "url")) + { + *lpszPropVal = (char*)((ElementID->lo_image).image_url); + return TRUE; + } + if (!stricmp(PropertyName, "href")) + { + LO_AnchorData* pAnchorData = (ElementID->lo_image).anchor_href; + if (pAnchorData && pAnchorData->anchor && + (*((char*)(pAnchorData->anchor)) != '\0')) + + *lpszPropVal = (char*)pAnchorData->anchor; + return TRUE; + } + break; + case LO_BULLET: + break; + case LO_FORM_ELE: + switch (((ElementID->lo_form).element_data)->type) + { + case FORM_TYPE_TEXT: + case FORM_TYPE_PASSWORD: + case FORM_TYPE_READONLY: + if (!stricmp(PropertyName, "name")) + { + *lpszPropVal = (char*)((((ElementID->lo_form).element_data)->ele_text).name); + return TRUE; + } + else if (!stricmp(PropertyName, "defaulttext")) + { + *lpszPropVal = (char*)((((ElementID->lo_form).element_data)->ele_text).default_text); + return TRUE; + } + else if (!stricmp(PropertyName, "currenttext")) + { + *lpszPropVal = (char*)((((ElementID->lo_form).element_data)->ele_text).current_text); + return TRUE; + } + break; + + case FORM_TYPE_SUBMIT: + case FORM_TYPE_RESET: + case FORM_TYPE_BUTTON: + if (!stricmp(PropertyName, "name")) + { + *lpszPropVal = (char*)((((ElementID->lo_form).element_data)->ele_minimal).name); + return TRUE; + } + break; + + case FORM_TYPE_RADIO: + case FORM_TYPE_CHECKBOX: + if (!stricmp(PropertyName, "name")) + { + *lpszPropVal = (char*)((((ElementID->lo_form).element_data)->ele_toggle).name); + return TRUE; + } + break; + + case FORM_TYPE_SELECT_ONE: + case FORM_TYPE_SELECT_MULT: + if (!stricmp(PropertyName, "name")) + { + *lpszPropVal = (char*)((((ElementID->lo_form).element_data)->ele_select).name); + return TRUE; + } + else if (!stricmp(PropertyName, "options")) + { /* actually returns a pointer to the option list */ + *lpszPropVal = (char*)((((ElementID->lo_form).element_data)->ele_select).options); + return TRUE; + } + + case FORM_TYPE_TEXTAREA: + if (!stricmp(PropertyName, "name")) + { + *lpszPropVal = (char*)((((ElementID->lo_form).element_data)->ele_textarea).name); + return TRUE; + } + else if (!stricmp(PropertyName, "defaulttext")) + { + *lpszPropVal = (char*)((((ElementID->lo_form).element_data)->ele_textarea).default_text); + return TRUE; + } + else if (!stricmp(PropertyName, "currenttext")) + { + *lpszPropVal = (char*)((((ElementID->lo_form).element_data)->ele_textarea).current_text); + return TRUE; + } + break; + + case FORM_TYPE_IMAGE: /* TODO - what data structure?*/ + break; + + case FORM_TYPE_HIDDEN: + case FORM_TYPE_JOT: + case FORM_TYPE_ISINDEX: + case FORM_TYPE_KEYGEN: + case FORM_TYPE_OBJECT: + break; + } + break; + + case LO_TABLE: + case LO_CELL: + case LO_EMBED: + case LO_JAVA: + case LO_OBJECT: + break; + } + + LAPI_LastError = LAPI_E_INVALIDPROP; + return FALSE; +} + + +/* LAPIElementGetNumProperty +** +** Description: This function retrieves a property of a frame. +** +** Parameters: FrameID - a frame id. +** ElementID - Identifies the reference element. +** PropertyName - a string identifing the property +** lpPropVal - a pointer to a numeric var to write the prop' val into. +** +** Return Value: If the function succeeds, the return value is TRUE, +** otherwise the function returns FALSE and LastError will be: +** LAPI_E_INVALIDFRAME if the given id doesn't identify an existing frame, +** LAPI_E_INVALIDPROP if the given propery name isn't supported, +*/ +Bool LAPIElementGetNumProperty( + MWContext* FrameID, + LO_Element* ElementID, + char* PropertyName, + int32* lpPropVal +) +{ + lo_ProbeState* ps = GetProbe(FrameID); + + if (ps == NULL) + { /* invalid frame id */ + LAPI_LastError = LAPI_E_INVALIDFRAME; + return FALSE; + } + + /* TODO Add bullet type */ + + if (!stricmp(PropertyName, "type")) + { + *lpPropVal = GetElementLAPIType(ElementID); + return TRUE; + } + else if (!stricmp(PropertyName, "xpos")) + { + *lpPropVal = (ElementID->lo_any).x + (ElementID->lo_any).x_offset; + return TRUE; + } + else if (!stricmp(PropertyName, "ypos")) + { + *lpPropVal = (ElementID->lo_any).y + (ElementID->lo_any).y_offset; + return TRUE; + } + else if (!stricmp(PropertyName, "width")) + { + *lpPropVal = (ElementID->lo_any).width; + return TRUE; + } + else if (!stricmp(PropertyName, "height")) + { + *lpPropVal = (ElementID->lo_any).height; + return TRUE; + } + + if (ElementID->type == LO_FORM_ELE) + { + switch (((ElementID->lo_form).element_data)->type) + { + case FORM_TYPE_TEXT: + case FORM_TYPE_PASSWORD: + case FORM_TYPE_READONLY: + if (!stricmp(PropertyName, "disabled")) + { + *lpPropVal = (((ElementID->lo_form).element_data)->ele_text).disabled; + return TRUE; + } + else if (!stricmp(PropertyName, "readonly")) + { + *lpPropVal = (((ElementID->lo_form).element_data)->ele_text).read_only; + return TRUE; + } + else if (!stricmp(PropertyName, "size")) + { + *lpPropVal = (((ElementID->lo_form).element_data)->ele_text).size; + return TRUE; + } + else if (!stricmp(PropertyName, "maxsize")) + { + *lpPropVal = (((ElementID->lo_form).element_data)->ele_text).max_size; + return TRUE; + } + break; + + case FORM_TYPE_SUBMIT: + case FORM_TYPE_RESET: + case FORM_TYPE_BUTTON: + if (!stricmp(PropertyName, "disabled")) + { + *lpPropVal = (((ElementID->lo_form).element_data)->ele_minimal).disabled; + return TRUE; + } + break; + + case FORM_TYPE_RADIO: + case FORM_TYPE_CHECKBOX: + if (!stricmp(PropertyName, "disabled")) + { + *lpPropVal = (((ElementID->lo_form).element_data)->ele_toggle).disabled; + return TRUE; + } + else if (!stricmp(PropertyName, "toggled")) + { + *lpPropVal = (((ElementID->lo_form).element_data)->ele_toggle).toggled; + return TRUE; + } + else if (!stricmp(PropertyName, "default_toggle")) + { + *lpPropVal = (((ElementID->lo_form).element_data)->ele_toggle).default_toggle; + return TRUE; + } + break; + + case FORM_TYPE_SELECT_ONE: + case FORM_TYPE_SELECT_MULT: + if (!stricmp(PropertyName, "disabled")) + { + *lpPropVal = (((ElementID->lo_form).element_data)->ele_select).disabled; + return TRUE; + } + else if (!stricmp(PropertyName, "multiple")) + { + *lpPropVal = (((ElementID->lo_form).element_data)->ele_select).multiple; + return TRUE; + } + else if (!stricmp(PropertyName, "multiple")) + { + *lpPropVal = (((ElementID->lo_form).element_data)->ele_select).multiple; + return TRUE; + } + else if (!stricmp(PropertyName, "option_cnt")) + { + *lpPropVal = (((ElementID->lo_form).element_data)->ele_select).option_cnt; + return TRUE; + } + else if (!stricmp(PropertyName, "options")) + { /* actually returns a pointer to the option list */ + *lpPropVal = (int32)((((ElementID->lo_form).element_data)->ele_select).options); + return TRUE; + } + + case FORM_TYPE_TEXTAREA: + if (!stricmp(PropertyName, "disabled")) + { + *lpPropVal = (((ElementID->lo_form).element_data)->ele_textarea).disabled; + return TRUE; + } + else if (!stricmp(PropertyName, "readonly")) + { + *lpPropVal = (((ElementID->lo_form).element_data)->ele_textarea).read_only; + return TRUE; + } + else if (!stricmp(PropertyName, "rows")) + { + *lpPropVal = (((ElementID->lo_form).element_data)->ele_textarea).rows; + return TRUE; + } + else if (!stricmp(PropertyName, "cols")) + { + *lpPropVal = (((ElementID->lo_form).element_data)->ele_textarea).cols; + return TRUE; + } + + case FORM_TYPE_IMAGE: /* TODO - what data structure?*/ + break; + + case FORM_TYPE_HIDDEN: + case FORM_TYPE_JOT: + case FORM_TYPE_ISINDEX: + case FORM_TYPE_KEYGEN: + case FORM_TYPE_OBJECT: + break; + } + } + + LAPI_LastError = LAPI_E_INVALIDPROP; + return FALSE; +} + + + + +/********************************************************** +********* Manipulation API ******** +**********************************************************/ + + +/* LAPIElementClick +** +** Description: This function simulates a mouse button click +** operation on an element. +** +** Parameters: FrameID - Identifies the relevant frame. +** ElementID - Identifies the reference element. +** MouseButton - The mouse button to 'use'. +** +** Return Value: If the function succeeds, the return value is TRUE, +** if the function fails the return value is NULL and LastError will be: +** E_INVALIDFRAME if the frame parameter is invalid, +** E_INVALIDELEMENT if the element parameter is invalid, +** E_NOTSUPPORTED if the element does not support this operation. +*/ +Bool LAPIElementClick( + MWContext* FrameID, + void* ElementID, + int16 MouseButton +) +{ + return FALSE; +} + + +/* LAPIElementSetText +** +** Description: This function sets the text value for edits, +** lists and combo box's. +** +** Parameters: FrameID - Identifies the relevant frame. +** ElementID - Identifies the reference element. +** Text - A text buffer. +** +** Return Value: If the function succeeds, the return value is TRUE, +** if the function fails the return value is NULL and LastError will be: +** LAPI_E_INVALIDFRAME if the frame parameter is invalid, +** LAPI_E_INVALIDELEMENT if the element parameter is invalid, +** LAPI_E_NOTSUPPORTED if the element does not support this operation. +** For lists and combo boxes if the text isn't one of the existing items, +** LastError will be set to LAPI_E_NOSUCHITEM. +*/ +Bool LAPIElementSetText ( + MWContext* FrameID, + void* ElementID, + char* Text +) +{ + return FALSE; +} + + + +/* LAPIElementSetState +** +** Description: This function sets the value for radio buttons +** and checkboxes. +** +** Parameters: FrameID - Identifies the relevant frame. +** ElementID - Identifies the reference element. +** Value - The new state. +** +** Return Value: If the function succeeds, the return value is TRUE, if the function fails the return value is NULL and LastError will be: +** E_INVALIDFRAME if the frame parameter is invalid, +** E_INVALIDELEMENT if the element parameter is invalid, or to +** E_NOTSUPPORTED if the element does not support this operation. +*/ +Bool LAPIElementSetState ( + MWContext* FrameID, + void* ElementID, + int8 Value +) +{ + return FALSE; +} + + +/* LAPIElementSetState +** +** Description: This function makes the top left (or a relative specified point) +** corner of an element visible, and retrieve it's properties. +** +** Parameters: FrameID - Identifies the relevant frame. +** ElementID - Identifies the reference element. +** xPos - horizontal offset relative to top left corner. +** yPos - vertical offset relative to top left corner. +** +** Return Value: If the function succeeds, the return value is TRUE, if the function fails the return value is NULL and LastError will be: +** E_INVALIDFRAME if the frame parameter is invalid, +** E_INVALIDELEMENT if the element parameter is invalid, +** E_OUTOFBOUNDS if the point specified is not within the element's rectangle, +** E_NOTSUPPORTED if the element does not support this operation. +*/ +Bool LAPIElementScrollIntoView ( + MWContext* FrameID, + void* ElementID, + int xPos, + int yPos +) +{ + return FALSE; +} + + + +/********************************************************** +********* Callback regisration API ******** +**********************************************************/ + + + +/* LAPIRegisterNotifyCallback +** +** Description: This function is used to register a callback function +** that will be called by Netscape each time a +** specified event occurs. +** +** Parameters: lpFunc - A callback function pointer +** EventID - An event identifier. +** +** Return Value: If the function succeeds, the return value is +** a callbackID, otherwise the return value is NULL. +*/ +static int32 LAPIRegisterNotifyCallback( + ID_NOTIFY_PT* lpFunc, + int32 EventID +) +{ + if (!lpFunc) + return 0; + + if (!CallbackList[EventID]) + CallbackList[EventID] = XP_ListNew(); + + XP_ListAddObjectToEnd(CallbackList[EventID], (void*)lpFunc); + + return (int32)lpFunc; +} + + + +/* LAPIRegisterElementCallback +** +** Description: This function is used to register a callback function +** that will be called by Netscape each time a +** specified mouse event occurs. +** +** Parameters: lpFunc - A callback function pointer +** EventID - An event identifier. +** +** Return Value: If the function succeeds, the return value is +** a callbackID, otherwise the return value is NULL. +*/ +static int32 LAPIRegisterElementCallback( + ELEMENT_NOTIFY_PT* lpFunc, + int32 EventID +) +{ + if (!lpFunc) + return 0; + + if (!CallbackList[EventID]) + CallbackList[EventID] = XP_ListNew(); + + XP_ListAddObjectToEnd(CallbackList[EventID], (void*)lpFunc); + + return (int32)lpFunc; +} + + +/* GetCallbackFuncList +** +** Description: This function retrieves the list of callback +** funcions registered on a specific event. +** +** Parameters: EventID - An event identifier. +** +** Return Value: If the function succeeds, the return value is +** a pointer to the list of registerd callbacks, otherwise +** the function returns NULL. +*/ +XP_List* GetCallbackFuncList( + int32 EventID +) +{ + if (EventID <0 || EventID >= MAX_CALLBACKS) + return NULL; + else + return CallbackList[EventID]; +} + + +/* LAPIUnregisterCallbackFunction +** +** Description: This function is used to remove a previously +** registered callback function identified by +** it's CallbackID. +** +** Parameters: CalbackID - The callbackID to unregister. +** +** Return Value: If the function succeeds, the return value is a TRUE, +** otherwise the return value is FALSE. +*/ +static Bool LAPIUnregisterCallbackFunction ( + void* CallbackID +) +{ + int i; + for(i = 0; i< MAX_CALLBACKS;i++) + { + if (CallbackList[i] != NULL) + { + if (XP_ListRemoveObject(CallbackList[i], CallbackID)) + return TRUE; + } + } + return FALSE; +} + + +/* LAPINotificationHandler +** +** Description: This function should be called before ET_SendEvent +** and notify events before they are sent to the JS engine +** +** Parameters: pEvent - The event with all the info. +** +** Return Value: If the function succeeds, the return value is a TRUE, +** otherwise the return value is FALSE. +*/ +Bool LAPINotificationHandler(LAPIEventInfo* pEvent) +{ + int32 LAPIEvent = LAPI_INVALID_NUM; + XP_List *pList; + + if (!pEvent) + return FALSE; + + switch (pEvent->type) + { + case EVENT_MOUSEDOWN: + LAPIEvent = ELEMENT_MOUSE_DOWN; + break; + case EVENT_MOUSEUP: + LAPIEvent = ELEMENT_MOUSE_UP; + break; + case EVENT_MOUSEOVER: /* user is mousing over a link */ + LAPIEvent = ELEMENT_MOUSE_OVER; + break; + case EVENT_MOUSEOUT: /* user is mousing out of a link */ + LAPIEvent = ELEMENT_MOUSE_OUT; + break; + case EVENT_CLICK: /* input element click in progress */ + LAPIEvent = ELEMENT_CLICK; + break; + case EVENT_FOCUS: /* input focus event in progress */ + LAPIEvent = ELEMENT_SET_FOCUS; + break; + case EVENT_BLUR: /* loss of focus event in progress */ + LAPIEvent = ELEMENT_KILL_FOCUS; + break; + case EVENT_CHANGE: /* field value change in progress */ + LAPIEvent = ELEMENT_CHANGE; + break; + } + + pList = GetCallbackFuncList(LAPIEvent); + + if (pList) + { + while (pList = pList->next) + { + if (pList->object) + (*((ELEMENT_NOTIFY_PT)pList->object))((void*)(pEvent->Context), + (void*)pEvent->lo_element, pEvent->docx, pEvent->docy, LAPI_INVALID_NUM); + } + } +} + + +/********************************************************** +* Private methods. Only called from within this module. * +**********************************************************/ + +/* GetProbe +** +** Description: This function retrieves a frame's probe struct, +** if there isn't one, a probe is created. +** +** Parameters: FrameID - id of the frame to get the probe for. +** +** Return Value: a pointer to the probe, or NULL if FrameID not valid. +*/ +static lo_ProbeState* GetProbe( + MWContext* FrameID +) +{ + lo_TopState* top_state = NULL; + if (!FrameID) + return NULL; + + top_state = lo_FetchTopState( XP_DOCID(FrameID) ); + + if (!top_state) + return NULL; + + /* if a probe already exists return a pointer to it */ + if (top_state->LAPIprobe) + return (lo_ProbeState*)top_state->LAPIprobe; + + top_state->LAPIprobe = (void*)LO_QA_CreateProbe(FrameID); + if (top_state->LAPIprobe && ((lo_ProbeState*)top_state->LAPIprobe)->doc_state) + return (lo_ProbeState*)top_state->LAPIprobe; + + return NULL; +} + +/* GetElementLAPIType +** +** Description: An enumeration function going over all elements and for each of them +** performing an operation given as a parameter. +** +** Parameters: ElementID - An element to begin enumeration from. +** lppData - A data pointer for the use of the enum function. +** pElementInfo- A pointer to the information of the object/s we're looking for. +** EnumFunc - A pointer to the enumerator function to be called for each element +** +** Return Value: LAPI type if successful, LAPI_INVALID_NUM otherwise (error code in LAPI_LastError). +*/ +static int16 GetElementLAPIType( + LO_Element* ElementID +) +{ + switch (ElementID->type) + { + case LO_TEXT: + { + LO_AnchorData* pAnchorData = (ElementID->lo_text).anchor_href; + if (pAnchorData && pAnchorData->anchor && + (*((char*)(pAnchorData->anchor)) != '\0')) + { + return LAPI_TEXTLINK; + } + else + return LAPI_TEXT; + } + case LO_HRULE: + return LAPI_HRULE; + + case LO_IMAGE: + return LAPI_IMAGE; + + case LO_BULLET: + return LAPI_BULLET; + + case LO_TABLE: + return LAPI_TABLE; + + case LO_CELL: + return LAPI_CELL; + + case LO_FORM_ELE: + { + switch (((ElementID->lo_form).element_data)->type) + { + case FORM_TYPE_TEXT: + case FORM_TYPE_PASSWORD: + case FORM_TYPE_TEXTAREA: + return LAPI_FE_TEXT; + + case FORM_TYPE_RADIO: + return LAPI_FE_RADIOBUTTON; + + case FORM_TYPE_CHECKBOX: + return LAPI_FE_CHECKBOX; + + case FORM_TYPE_BUTTON: + case FORM_TYPE_SUBMIT: + case FORM_TYPE_RESET: + return LAPI_FE_BUTTON; + + case FORM_TYPE_JOT: + case FORM_TYPE_SELECT_ONE: + return LAPI_FE_COMBOBOX; + + case FORM_TYPE_SELECT_MULT: + return LAPI_FE_LISTBOX; + + case FORM_TYPE_ISINDEX: + case FORM_TYPE_IMAGE: + return LAPI_IMAGE; + + case FORM_TYPE_NONE: + case FORM_TYPE_HIDDEN: + case FORM_TYPE_FILE: + case FORM_TYPE_KEYGEN: + case FORM_TYPE_READONLY: + case FORM_TYPE_OBJECT: + return LAPI_UNKNOWN; + } + } + case LO_EMBED: + return LAPI_EMBED; + + case LO_JAVA: + return LAPI_JAVA; + + case LO_OBJECT: + return LAPI_OBJECT; + + default: + return LAPI_UNKNOWN; + } +} + +/* EnumElements +** +** Description: An enumeration function going over all elements and for each of them +** performing an operation given as a parameter. +** +** Parameters: FrameID - the id of the frame being queried. +** ElementID - An element to begin enumeration from. +** lppData - A data pointer for the use of the enum function. +** pElementInfo- A pointer to the information of the object/s we're looking for. +** EnumFunc - A pointer to the enumerator function to be called for each element +** +** Return Value: TRUE if enumeration stopped, FALSE otherwise. +*/ +static Bool EnumElements( + MWContext* FrameID, + LO_Element *ElementID, + void ** lppData, + stElementInfo* pElementInfo, + LAPI_ELEMENTS_ENUM_FUNC *EnumFunc +) +{ + Bool bStopEnum = FALSE; + + if (!ElementID) + return FALSE; + + do + { + if (ElementID->type == LO_CELL) + { + bStopEnum = EnumElements(FrameID, ((LO_CellStruct*)ElementID)->cell_list, lppData, pElementInfo, EnumFunc); + + if (!bStopEnum) + bStopEnum = EnumElements(FrameID, ((LO_CellStruct*)ElementID)->cell_float_list, lppData, pElementInfo, EnumFunc); + } + else if (ElementID->type == LO_FLOAT) + { + bStopEnum = EnumElements(FrameID, ((LO_FloatStruct*)ElementID)->float_ele, lppData, pElementInfo, EnumFunc); + } + else + { + bStopEnum = (*EnumFunc)(FrameID, ElementID, pElementInfo, lppData); + } + } + while (!bStopEnum && ((ElementID = (ElementID->lo_any).next))); + + return bStopEnum; +} + +/* EnumGetElementList +** +** Description: An enumerator function which creates and fils an element list +** with all elements matching a given template. +** * currently supports 'Type' and 'Name' only. +** +** Parameters: FrameID - the id of the frame being queried. +** ElementID - An element to begin enumeration from. +** lppData - the address where the list pointer will be written to. +** pElementInfo- A poiner to a template of the requested objects. +** +** Return Value: allways returns FALSE : continue enumeration +*/ +static Bool EnumGetElementList( + MWContext* FrameID, + LO_Element *ElementID, + stElementInfo* pElementInfo, + void ** lppData +) +{ + int32 LAPI_Type; + + /* stop enumeration if list is null */ + if (!(*lppData)) + return TRUE; + + if ((LAPI_Type = GetElementLAPIType(ElementID)) == LAPI_UNKNOWN) + return FALSE; /* continue enumeration */ + + /* compare element type */ + if (pElementInfo->LAPI_Type != LAPI_INVALID_NUM) + { /* request is for an exact type */ + if (pElementInfo->LAPI_Type != LAPI_Type) + return FALSE; /* continue enumeration */ + + if (pElementInfo->Name != NULL) + { + char* szName; + if (LAPIElementGetStringProperty(FrameID, ElementID, "name", &szName) == FALSE) + { + return FALSE; /* continue enumeration */ + } + + if (strcmp(pElementInfo->Name, szName)) + return FALSE; /* continue enumeration */ + } + } + + /* Add the current element to the list */ + XP_ListAddObjectToEnd ((XP_List*)(*lppData), (void *) ElementID); + + return FALSE; /* continue enumeration */ +} + + +/* EnumGetElementFromPoint +** +** Description: An enumerator function which finds the +** Lowset level layout element under a given point. +** The point is passed in Screen_xPos and Screen_yPos of +** pElementInfo. +** +** Parameters: FrameID - the id of the frame being queried. +** ElementID - An element to begin enumeration from. +** lppData - an address of a ElementID. +** pElementInfo- A poiner to a template of the requested objects. +** +** Return Value: TRUE if a low level layout object found, +** FALSE otherwise (continue enumeration). +*/ +static Bool EnumGetElementFromPoint( + MWContext* FrameID, + LO_Element *ElementID, + stElementInfo* pElementInfo, + void ** lppData +) +{ + int32 ele_xPos, ele_yPos, ele_width, ele_height; + + if (!LAPIElementGetNumProperty(FrameID, ElementID, "xpos", &ele_xPos) || + !LAPIElementGetNumProperty(FrameID, ElementID, "ypos", &ele_yPos) || + !LAPIElementGetNumProperty(FrameID, ElementID, "width", &ele_width) || + !LAPIElementGetNumProperty(FrameID, ElementID, "height", &ele_height)) + return FALSE; /* continue enumeration */ + + + if ((pElementInfo->xPos >= ele_xPos) && + (pElementInfo->xPos <= (ele_xPos + ele_width)) && + (pElementInfo->yPos >= ele_yPos) && + (pElementInfo->yPos <= (ele_yPos + ele_height))) + { + if (IsLowLevelElementType(ElementID)) + { + *lppData = ElementID; + return TRUE; /* object found, stop enumeration */ + } + } + + return FALSE; /* continue enumeration */ +} + + +static Bool IsLowLevelElementType( + LO_Element* ElementID +) +{ + if (ElementID->type == LO_TABLE || ElementID->type == LO_CELL) + return FALSE; + else + return TRUE; +} + /** Private methods. Only called from within this module. @@ -623,4 +2189,4 @@ static long lo_QA_RGBColorToLong( LO_Color color ) c += color.blue; return c; -} \ No newline at end of file +} diff --git a/mozilla/lib/layout/layprobe.h b/mozilla/lib/layout/layprobe.h index a557c77fdf3..e8a295efd01 100644 --- a/mozilla/lib/layout/layprobe.h +++ b/mozilla/lib/layout/layprobe.h @@ -25,8 +25,117 @@ * */ +#ifndef layprobe_h__ +#define layprobe_h__ + #include "structs.h" +/* API Element types */ +#define LAPI_UNKNOWN -1 +#define LAPI_TEXTLINK 0 +#define LAPI_TEXT 1 +#define LAPI_HRULE 2 +#define LAPI_IMAGE 3 +#define LAPI_BULLET 4 +#define LAPI_TABLE 5 +#define LAPI_CELL 6 +#define LAPI_EMBED 7 +#define LAPI_JAVA 8 +#define LAPI_OBJECT 9 + + +#define LAPI_FIRST_FE 30 +#define LAPI_FE_TEXT 30 +#define LAPI_FE_RADIOBUTTON 31 +#define LAPI_FE_CHECKBOX 32 +#define LAPI_FE_BUTTON 33 +#define LAPI_FE_COMBOBOX 34 +#define LAPI_FE_LISTBOX 35 +#define LAPI_LAST_FE 35 + +#define LAPI_FRAME 50 + +/* API Error codes */ +#define LAPI_E_NOTIMPL -1000 +#define LAPI_E_UNEXPECTED -1001 +#define LAPI_E_INVALIDARG -1002 +#define LAPI_E_INVALIDBROWSER -1003 +#define LAPI_E_INVALIDFRAME -1004 +#define LAPI_E_INVALIDELEMENT -1005 +#define LAPI_E_NOTSUPPORTED -1006 +#define LAPI_E_NOELEMENTS -1007 +#define LAPI_E_OUTOFBOUNDS -1008 +#define LAPI_E_INVALIDPROP -1009 +#define LAPI_E_LIB_LOAD_FAILED -1010 +#define LAPI_E_INIT_TEST_LIB_FAILED -1011 +#define LAPI_E_GENERAL_ERROR -1012 + +#define LAPI_INVALID_NUM -1 + +/* Callback function types and constatnts */ +typedef void (*ID_NOTIFY_PT)(void*); +typedef void (*ELEMENT_NOTIFY_PT)(MWContext* FrameID, void* ElementID, + int32 xPos, int32 yPos, int32 KeysState); + +#define BROWSER_NAVIGATION_COMPLETE 0 +#define BROWSER_ON_QUIT 1 +#define FRAME_DOCUMENT_COMPLETE 2 +#define FRAME_ON_UNLOAD 3 + +#define ELEMENT_MOUSE_DOWN 4 +#define ELEMENT_MOUSE_UP 5 +#define ELEMENT_MOUSE_OVER 6 +#define ELEMENT_MOUSE_OUT 7 +#define ELEMENT_CLICK 8 +#define ELEMENT_KILL_FOCUS 9 +#define ELEMENT_SET_FOCUS 10 +#define ELEMENT_CHANGE 11 + +#define MAX_CALLBACKS 15 + +/* Notification Events (same as JSEvent values) */ +#define EVENT_MOUSEDOWN 0x00000001 +#define EVENT_MOUSEUP 0x00000002 +#define EVENT_MOUSEOVER 0x00000004 /* user is mousing over a link */ +#define EVENT_MOUSEOUT 0x00000008 /* user is mousing out of a link */ +#define EVENT_MOUSEMOVE 0x00000010 +#define EVENT_MOUSEDRAG 0x00000020 +#define EVENT_CLICK 0x00000040 /* input element click in progress */ +#define EVENT_DBLCLICK 0x00000080 +#define EVENT_KEYDOWN 0x00000100 +#define EVENT_KEYUP 0x00000200 +#define EVENT_KEYPRESS 0x00000400 +#define EVENT_DRAGDROP 0x00000800 /* not yet implemented */ +#define EVENT_FOCUS 0x00001000 /* input focus event in progress */ +#define EVENT_BLUR 0x00002000 /* loss of focus event in progress */ +#define EVENT_SELECT 0x00004000 /* input field selection in progress */ +#define EVENT_CHANGE 0x00008000 /* field value change in progress */ +#define EVENT_RESET 0x00010000 /* form submit in progress */ +#define EVENT_SUBMIT 0x00020000 /* form submit in progress */ +#define EVENT_SCROLL 0x00040000 /* window is being scrolled */ +#define EVENT_LOAD 0x00080000 /* layout parsed a loaded document */ +#define EVENT_UNLOAD 0x00100000 +#define EVENT_XFER_DONE 0x00200000 /* document has loaded */ +#define EVENT_ABORT 0x00400000 +#define EVENT_ERROR 0x00800000 +#define EVENT_LOCATE 0x01000000 +#define EVENT_MOVE 0x02000000 +#define EVENT_RESIZE 0x04000000 +#define EVENT_FORWARD 0x08000000 +#define EVENT_HELP 0x10000000 /* for handling of help events */ +#define EVENT_BACK 0x20000000 + + +typedef struct { + int32 type; + MWContext* Context; + LO_Element* lo_element; + int32 x,y; + int32 docx,docy; + int32 screenx,screeny; +} LAPIEventInfo; + + /* The different types of layout elements */ #define LO_TEXT 1 #define LO_HRULE 3 @@ -38,6 +147,7 @@ #define LO_EMBED 10 #define LO_JAVA 12 #define LO_OBJECT 14 +#define LO_FLOAT 18 typedef enum _ColorType { LO_QA_BACKGROUND_COLOR, @@ -126,6 +236,7 @@ Bool LO_QA_HasParent( long probeID, Bool *hasParent ); Bool LO_QA_GetTextLength( long probeID, long *length); Bool LO_QA_GetText( long probeID, char *text, long length); +Bool LO_QA_GetTextAttributes( long probeID, void *attributes); /* Color Type Elements containing the color type ---------- ---------------------------------- @@ -137,4 +248,155 @@ Bool LO_QA_GetText( long probeID, char *text, long length); at which the probe is currently positioned. Returns TRUE if successful, FALSE if not. */ -Bool LO_QA_GetColor( long probeID, long *color, ColorType type); \ No newline at end of file +Bool LO_QA_GetColor( long probeID, long *color, ColorType type); + +/********************************************************** +********* Queries API ******** +**********************************************************/ + +int32 LAPIGetLastError(); + +Bool LAPIGetFrames( + XP_List** lppContextList +); + + +Bool LAPIFrameGetStringProperty( + MWContext* FrameID, + char* PropertyName, + char** lpszPropVal +); + +Bool LAPIFrameGetNumProperty( + MWContext* FrameID, + char* PropertyName, + int32* lpPropVal +); + + +Bool LAPIFrameGetElements( + XP_List* lpList, + MWContext* FrameID, + int16 ElementLAPIType, + char* ElementName +); + + +LO_Element* LAPIFrameGetElementFromPoint( + MWContext * FrameID, + int xPos, + int yPos +); + + +LO_Element* LAPIGetFirstElement ( + MWContext * FrameID +); + + +LO_Element* LAPIGetNextElement ( + MWContext * FrameID, + LO_Element* ElementID +); + + +LO_Element* LAPIGetPrevElement ( + MWContext * FrameID, + LO_Element* ElementID +); + + +LO_Element* LAPIGetChildElement ( + MWContext * FrameID, + LO_Element* ElementID +); + + +LO_Element* LAPIGetParentElement ( + MWContext * FrameID, + LO_Element* ElementID +); + + +Bool LAPIElementGetStringProperty( + MWContext* FrameID, + LO_Element* ElementID, + char* PropertyName, + char** lpszPropVal +); + + +Bool LAPIElementGetNumProperty( + MWContext* FrameID, + LO_Element* ElementID, + char* PropertyName, + int32* lpPropVal +); + + + +void LAPIDestroyProbe( + void* ProbeID +); + +/********************************************************** +********* Manipulation API ******** +**********************************************************/ + + +Bool LAPIElementClick( + MWContext* FrameID, + void* ElementID, + int16 MouseButton +); + + +Bool LAPIElementSetText ( + MWContext* FrameID, + void* ElementID, + char* Text +); + + +Bool LAPIElementSetState ( + MWContext* FrameID, + void* ElementID, + int8 Value +); + + +Bool LAPIElementScrollIntoView ( + MWContext* FrameID, + void* ElementID, + int xPos, + int yPos +); + + +/********************************************************** +********* API Callback regisration ******** +**********************************************************/ + +int32 LAPIRegisterNotifyCallback( + ID_NOTIFY_PT* lpFunc, + int32 EventID +); + +int32 LAPIRegisterElementCallback( + ELEMENT_NOTIFY_PT* lpFunc, + int32 EventID +); + +Bool LAPIUnregisterCallbackFunction( + void* CallbackID +); + +XP_List* GetCallbackFuncList( + int32 EventID +); + +Bool LAPINotificationHandler( + LAPIEventInfo* pEvent +); + +#endif /* layprobe_h__ */ \ No newline at end of file