From 8e427dff2d77e7cc40a0a2167b9a556e956398eb Mon Sep 17 00:00:00 2001 From: "locka%iol.ie" Date: Tue, 3 Apr 2001 22:00:21 +0000 Subject: [PATCH] Added read-only implementations of innerHTML, innerText, offsetLeft, offsetTop, offsetWidth, offsetHeight. b=58475 --- .../activex/src/control/IEHtmlElement.cpp | 112 ++++++++++++++---- 1 file changed, 90 insertions(+), 22 deletions(-) diff --git a/embedding/browser/activex/src/control/IEHtmlElement.cpp b/embedding/browser/activex/src/control/IEHtmlElement.cpp index e7c8c079d110..3e0a47f0aacf 100644 --- a/embedding/browser/activex/src/control/IEHtmlElement.cpp +++ b/embedding/browser/activex/src/control/IEHtmlElement.cpp @@ -93,15 +93,14 @@ HRESULT STDMETHODCALLTYPE CIEHtmlElement::setAttribute(BSTR strAttributeName, VA } nsString szValue(OLE2W(vValue.bstrVal)); - nsIDOMElement *pIDOMElement = nsnull; - if (FAILED(GetDOMElement(&pIDOMElement))) + nsCOMPtr element; + if (FAILED(GetDOMElement(getter_AddRefs(element)))) { return E_UNEXPECTED; } // Set the attribute - pIDOMElement->SetAttribute(szName, szValue); - pIDOMElement->Release(); + element->SetAttribute(szName, szValue); return S_OK; } @@ -122,8 +121,8 @@ HRESULT STDMETHODCALLTYPE CIEHtmlElement::getAttribute(BSTR strAttributeName, LO USES_CONVERSION; nsString szName(OLE2W(strAttributeName)); - nsIDOMElement *pIDOMElement = nsnull; - if (FAILED(GetDOMElement(&pIDOMElement))) + nsCOMPtr element; + if (FAILED(GetDOMElement(getter_AddRefs(element)))) { return E_UNEXPECTED; } @@ -133,8 +132,7 @@ HRESULT STDMETHODCALLTYPE CIEHtmlElement::getAttribute(BSTR strAttributeName, LO nsString szValue; // Get the attribute - nsresult nr = pIDOMElement->GetAttribute(szName, szValue); - pIDOMElement->Release(); + nsresult nr = element->GetAttribute(szName, szValue); if (nr == NS_OK) { @@ -158,8 +156,8 @@ HRESULT STDMETHODCALLTYPE CIEHtmlElement::removeAttribute(BSTR strAttributeName, return E_INVALIDARG; } - nsIDOMElement *pIDOMElement = nsnull; - if (FAILED(GetDOMElement(&pIDOMElement))) + nsCOMPtr element; + if (FAILED(GetDOMElement(getter_AddRefs(element)))) { return E_UNEXPECTED; } @@ -171,9 +169,8 @@ HRESULT STDMETHODCALLTYPE CIEHtmlElement::removeAttribute(BSTR strAttributeName, nsString szName(OLE2W(strAttributeName)); // Remove the attribute - nsresult nr = pIDOMElement->RemoveAttribute(szName); + nsresult nr = element->RemoveAttribute(szName); BOOL bRemoved = (nr == NS_OK) ? TRUE : FALSE; - pIDOMElement->Release(); if (pfSuccess) { @@ -234,15 +231,14 @@ HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_tagName(BSTR __RPC_FAR *p) return E_INVALIDARG; } - nsIDOMElement *pIDOMElement = nsnull; - if (FAILED(GetDOMElement(&pIDOMElement))) + nsCOMPtr element; + if (FAILED(GetDOMElement(getter_AddRefs(element)))) { return E_UNEXPECTED; } nsString szTagName; - pIDOMElement->GetTagName(szTagName); - pIDOMElement->Release(); + element->GetTagName(szTagName); USES_CONVERSION; *p = SysAllocString(W2COLE(szTagName.GetUnicode())); @@ -447,22 +443,82 @@ HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_lang(BSTR __RPC_FAR *p) HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_offsetLeft(long __RPC_FAR *p) { - return E_NOTIMPL; + nsCOMPtr domNode; + if (FAILED(GetDOMNode(getter_AddRefs(domNode)))) + { + return E_UNEXPECTED; + } + + nsCOMPtr nodeAsHTMLElement = do_QueryInterface(domNode); + if (!nodeAsHTMLElement) + { + return E_NOINTERFACE; + } + + PRInt32 nData; + nodeAsHTMLElement->GetOffsetLeft(&nData); + *p = nData; + return S_OK; } HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_offsetTop(long __RPC_FAR *p) { - return E_NOTIMPL; + nsCOMPtr domNode; + if (FAILED(GetDOMNode(getter_AddRefs(domNode)))) + { + return E_UNEXPECTED; + } + + nsCOMPtr nodeAsHTMLElement = do_QueryInterface(domNode); + if (!nodeAsHTMLElement) + { + return E_NOINTERFACE; + } + + PRInt32 nData; + nodeAsHTMLElement->GetOffsetTop(&nData); + *p = nData; + return S_OK; } HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_offsetWidth(long __RPC_FAR *p) { - return E_NOTIMPL; + nsCOMPtr domNode; + if (FAILED(GetDOMNode(getter_AddRefs(domNode)))) + { + return E_UNEXPECTED; + } + + nsCOMPtr nodeAsHTMLElement = do_QueryInterface(domNode); + if (!nodeAsHTMLElement) + { + return E_NOINTERFACE; + } + + PRInt32 nData; + nodeAsHTMLElement->GetOffsetWidth(&nData); + *p = nData; + return S_OK; } HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_offsetHeight(long __RPC_FAR *p) { - return E_NOTIMPL; + nsCOMPtr domNode; + if (FAILED(GetDOMNode(getter_AddRefs(domNode)))) + { + return E_UNEXPECTED; + } + + nsCOMPtr nodeAsHTMLElement = do_QueryInterface(domNode); + if (!nodeAsHTMLElement) + { + return E_NOINTERFACE; + } + + PRInt32 nData; + nodeAsHTMLElement->GetOffsetHeight(&nData); + *p = nData; + return S_OK; } HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_offsetParent(IHTMLElement __RPC_FAR *__RPC_FAR *p) @@ -477,7 +533,19 @@ HRESULT STDMETHODCALLTYPE CIEHtmlElement::put_innerHTML(BSTR v) HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_innerHTML(BSTR __RPC_FAR *p) { - return E_NOTIMPL; + nsCOMPtr element; + if (FAILED(GetDOMElement(getter_AddRefs(element)))) + { + return E_UNEXPECTED; + } + + nsCOMPtr elementHTML = do_QueryInterface(element); + nsAutoString szTagName; + elementHTML->GetInnerHTML(szTagName); + + USES_CONVERSION; + *p = SysAllocString(W2COLE(szTagName.GetUnicode())); + return S_OK; } HRESULT STDMETHODCALLTYPE CIEHtmlElement::put_innerText(BSTR v) @@ -487,7 +555,7 @@ HRESULT STDMETHODCALLTYPE CIEHtmlElement::put_innerText(BSTR v) HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_innerText(BSTR __RPC_FAR *p) { - return E_NOTIMPL; + return get_innerHTML(p); } HRESULT STDMETHODCALLTYPE CIEHtmlElement::put_outerHTML(BSTR v)