当前位置: 首页>>代码示例>>C++>>正文


C++ HTMLDocument::FindElement方法代码示例

本文整理汇总了C++中HTMLDocument::FindElement方法的典型用法代码示例。如果您正苦于以下问题:C++ HTMLDocument::FindElement方法的具体用法?C++ HTMLDocument::FindElement怎么用?C++ HTMLDocument::FindElement使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在HTMLDocument的用法示例。


在下文中一共展示了HTMLDocument::FindElement方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: jhtml_collection_item

/**
 * HTMLCollection item(long) method
 *
 * param  - index - the index of the element to get
 * return - the HTMLElement at index
 */
JSBool jhtml_collection_item(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
	int index;
	int32 dIndex = 0;
	WebcJSScript *jsscr = (WebcJSScript *) jhutil_GetContextPrivate(cx);
	WebcJSDocumentContext *jsmgr = (jsscr)? jsscr->GetJSMgr() : 0;
	if (!jsmgr)
	{
		return JS_FALSE;
	}
	HTMLDocument *pDoc = jsmgr->GetDocument();
	if (!pDoc)
	{
		return JS_FALSE;
	}

	//if we have at least 1 argument and it is a number
	if (argc > 0 && JSVAL_IS_INT(argv[0]))
	{
		//convert the jsval to a number
		JS_ValueToInt32(cx, argv[0], &dIndex);
		index = (int)dIndex;
		HTMLElementType ele_type = HTML_ELEMENT_NONE;
		jhtml_collection *pColl = (jhtml_collection*)jhutil_GetPrivate(cx, obj);
		if (!pColl)
		{
			return JS_FALSE;
		}
		HTMLElement *pElem = 0;
		switch(pColl->finderType)
		{
			case DOCUMENT_IMAGES:
				ele_type = HTML_IMAGE_ELEMENT;
				break;

			case DOCUMENT_ANCHORS:
				ele_type = HTML_ANCHOR_ELEMENT;
				break;

			case TABLE_ROWS:
				ele_type = HTML_TABLE_ROW_ELEMENT;
				break;

			case TABLEROW_CELLS:
				ele_type = HTML_TABLE_CELL_ELEMENT;
				break;

			case MAP_AREAS:
				ele_type = HTML_AREA_ELEMENT;
				break;

			case SELECT_OPTIONS:
				ele_type = HTML_OPTION_ELEMENT;
				break;

			case WIN_FRAMES:
			{
				*rval = JSVAL_NULL;
			  #if (WEBC_SUPPORT_FRAMES)
				HTMLNthOfTypeFinder finder(HTML_FRAME_ELEMENT, index);
				pElem = pColl->pTop->FindElement(&finder,1, INCLUDE_SELF_ELEMENT_DEFAULT);
				if (pElem)
				{
					HTMLFrame *pFrame = (HTMLFrame *) pElem;
					if (pFrame->FrameDocument() && pFrame->FrameDocument()->GetJSMgr())
					{
						*rval = OBJECT_TO_JSVAL(pFrame->FrameDocument()->GetJSMgr()->GetGlobalObject());
					}
				}
			  #endif // WEBC_SUPPORT_FRAMES
				return JS_TRUE;
			}

			case ELEMENT_NODES:
			{
				HTMLNthOfAnyTypeFinder finder(index);
				pElem = pColl->pTop->FindElement(&finder,1, INCLUDE_SELF_NODES_DEFAULT);
				if (pElem)
				{
					*rval = OBJECT_TO_JSVAL(pElem->CreateJSObject());
				}
				else
				{
					*rval = JSVAL_NULL;
				}
				return JS_TRUE;
			}

			case DOCUMENT_FORMS:
			{
				HTMLElementTypeFinder formFinder(HTML_FORM_ELEMENT);
				HTMLNthElementFinder nthFormFinder(&formFinder, index);

				pElem = pDoc->FindElement(&nthFormFinder);
//.........这里部分代码省略.........
开发者ID:peteratebs,项目名称:webcwebbrowser,代码行数:101,代码来源:jhcoll.cpp

示例2: jhtml_collection_namedItem

/**
 * HTMLCollection namedItem(long) method
 *
 * param - name - the name of the element to get
 * return - the first htmlelement in the tree with the given name
 */
JSBool jhtml_collection_namedItem(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
	WebcJSScript *jsscr = (WebcJSScript *) jhutil_GetContextPrivate(cx);
	WebcJSDocumentContext *jsmgr = (jsscr)? jsscr->GetJSMgr() : 0;
	if (!jsmgr)
	{
		return JS_FALSE;
	}
	HTMLDocument *pDoc = jsmgr->GetDocument();
	if (!pDoc)
	{
		return JS_FALSE;
	}
	HTMLElementType ele_type = HTML_ELEMENT_NONE;
	//if we have atleast one argument and it is a string
	if (argc > 0 && JSVAL_IS_STRINGABLE(argv[0]))
	{
		//conver the JSString to char *
		WEBC_CHAR *name = WEBC_JS_STRING_TO_WEBC_STRING(JS_ValueToString(cx, argv[0]));
		if (!name || !(*name))
		{
			*rval = JSVAL_NULL;
			return JS_TRUE;;
		}

		if (webc_c_stricmp(name, "toString")==0)
		{
				return JS_TRUE;
		}

		jhtml_collection *pColl = (jhtml_collection*)jhutil_GetPrivate(cx, obj);
		if (!pColl)
			return JS_TRUE;

		HTMLElement *pElem = 0;
		switch(pColl->finderType)
		{
			case DOCUMENT_IMAGES:
				ele_type = HTML_IMAGE_ELEMENT;
				break;

			case DOCUMENT_ANCHORS:
				ele_type = HTML_ANCHOR_ELEMENT;
				break;

			case TABLE_ROWS:
				ele_type = HTML_TABLE_ROW_ELEMENT;
				break;

			case TABLEROW_CELLS:
				ele_type = HTML_TABLE_CELL_ELEMENT;
				break;

			case MAP_AREAS:
				ele_type = HTML_AREA_ELEMENT;
				break;

			case SELECT_OPTIONS:
				ele_type = HTML_OPTION_ELEMENT;
				break;

			case WIN_FRAMES:
			{
			  #if (WEBC_SUPPORT_FRAMES)
				HTMLTypeAndNameOrIdFinder finder(name, HTML_FRAME_ELEMENT);
				pElem = pColl->pTop->FindElement(&finder,1, INCLUDE_SELF_ELEMENT_DEFAULT);
				if (pElem)
				{
					HTMLFrame *pFrame = (HTMLFrame *) pElem;
					if (pFrame->FrameDocument() && pFrame->FrameDocument()->GetJSMgr())
					{
						*rval = OBJECT_TO_JSVAL(pFrame->FrameDocument()->GetJSMgr()->GetGlobalObject());
						return JS_TRUE;
					}
				}
				*rval = JSVAL_NULL;
			  #endif // WEBC_SUPPORT_FRAMES

				return JS_TRUE;
			}

			case DOCUMENT_FORMS:
			{
				WebcJSScript *jsscr = (WebcJSScript *) jhutil_GetContextPrivate(cx);
				WebcJSDocumentContext *jsmgr = (jsscr)? jsscr->GetJSMgr() : 0;
				if (jsmgr)
				{
					HTMLNameOrIdFinder nameFinder(name);
					HTMLElementTypeFinder formFinder(HTML_FORM_ELEMENT);
					HTMLElementAndFinder formNameFinder(&nameFinder, &formFinder);

					HTMLDocument *pDoc = jsmgr->GetDocument();
					pElem = pDoc->FindElement(&formNameFinder);
				}
//.........这里部分代码省略.........
开发者ID:peteratebs,项目名称:webcwebbrowser,代码行数:101,代码来源:jhcoll.cpp


注:本文中的HTMLDocument::FindElement方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。