Пример #1
0
AbstractWebElement *ExplorerElement::getParent()
{
	IHTMLElement *e;
	HRESULT hr = m_pElement->QueryInterface(IID_IHTMLElement, reinterpret_cast<void**>(&e));
	ExplorerElement *parent = NULL;
	if (!FAILED(hr) && e != NULL)
	{
		IHTMLElement *nativeParent;
		hr = e->get_parentElement(&nativeParent);
		if (nativeParent != NULL) {
			parent = new ExplorerElement(nativeParent, m_pApp);
			nativeParent->Release();
		}
		e->Release();
	}
	return parent;
}
Пример #2
0
BOOL CAutoBrowser::GetVisibleElemRect( IHTMLElement *pElem,RECT &elemRect)
{
#define COM_CHECK_FAILED(_hr_) if( (_hr_)!=S_OK ) {break;}
	BOOL bOK = FALSE;
	do
	{
		if(pElem == NULL)
		{
			break;
		}

		IHTMLRect *pRect = NULL;
		CComQIPtr<IHTMLElement2> pqElem2(pElem);

		if(pqElem2)
		{
			HRESULT hr = pqElem2->getBoundingClientRect(&pRect);
				COM_CHECK_FAILED(hr)

			hr = pRect->get_left(&elemRect.left);
				COM_CHECK_FAILED(hr)

			hr = pRect->get_top(&elemRect.top);
				COM_CHECK_FAILED(hr)
			hr = pRect->get_right(&elemRect.right);
				COM_CHECK_FAILED(hr)
			hr = pRect->get_bottom(&elemRect.bottom);
				COM_CHECK_FAILED(hr)
			bOK = TRUE;
		}
		else
		{
			LONG lOffsetX = 0;
			LONG lOffsetY = 0;
			LONG lWidth = 0;
			LONG lHeight = 0;

			IHTMLElement *pTempElem = pElem;

			HRESULT hr = pElem->get_offsetWidth(&lWidth);
			COM_CHECK_FAILED(hr)
			hr = pElem->get_offsetHeight(&lHeight);
			COM_CHECK_FAILED(hr)
			
			BOOL bGetLeftTop = TRUE;
			do 
			{
				HRESULT hr;
				long dwLeft = 0;
				long dwTop = 0;

				hr = pTempElem->get_offsetLeft(&dwLeft);
				if(hr != S_OK)
				{
					bGetLeftTop = FALSE;
					break;
				}

				lOffsetX+=dwLeft;

				hr = pTempElem->get_offsetTop(&dwTop);
				if(hr != S_OK)
				{
					bGetLeftTop = FALSE;
					break;
				}
				lOffsetY+=dwTop;

				hr = pTempElem->get_parentElement(&pTempElem);

				CComQIPtr<IHTMLBodyElement> pqBodyElem(pTempElem);
				if(pqBodyElem)
				{
					bGetLeftTop = TRUE;
					break;
				}
			} while (pTempElem);
			
			if(bGetLeftTop)
			{
				elemRect.left = lOffsetX;
				elemRect.top = lOffsetY;
				elemRect.right= elemRect.left+lWidth;
				elemRect.bottom= elemRect.top+lHeight;
				bOK = TRUE;
			}
		}
	}
	while(FALSE);

	if (bOK)
	{
		//元素不可见
		CRect rcElem;
		rcElem = elemRect;
		if (/*rcElem.left > 0 && rcElem.top > 0 && */rcElem.Width() > 0 &&  rcElem.Height() > 0 )
		{

		}
		else
		{
			bOK = FALSE;
		}

		CPoint ptElemCenter;
		ptElemCenter = rcElem.CenterPoint();
	}

	if(!bOK)
	{
		elemRect.left=0;
		elemRect.top=0;
		elemRect.right=0;
		elemRect.bottom=0;
	}

	return bOK;

}