зеркало из https://github.com/mozilla/pjs.git
Implement IHTMLDomNode and IHTMLButtonElement interfaces on IE DOM. Checkin on behalf of atremon@elansoftware.com r=adamlock sr=jst b=238786
This commit is contained in:
Родитель
824d4541a4
Коммит
c7f46c164f
|
@ -54,13 +54,24 @@
|
|||
|
||||
CIEHtmlElement::CIEHtmlElement()
|
||||
{
|
||||
m_pNodeAgg = NULL;
|
||||
}
|
||||
|
||||
HRESULT CIEHtmlElement::FinalConstruct( )
|
||||
{
|
||||
return CComCreator<CComAggObject<CIEHtmlDomNode> >::CreateInstance(GetControllingUnknown(),
|
||||
IID_IUnknown, reinterpret_cast<void**>(&m_pNodeAgg));
|
||||
}
|
||||
|
||||
CIEHtmlElement::~CIEHtmlElement()
|
||||
{
|
||||
}
|
||||
|
||||
void CIEHtmlElement::FinalRelease( )
|
||||
{
|
||||
m_pNodeAgg->Release();
|
||||
}
|
||||
|
||||
HRESULT CIEHtmlElement::GetChildren(CIEHtmlElementCollectionInstance **ppCollection)
|
||||
{
|
||||
// Validate parameters
|
||||
|
@ -83,6 +94,41 @@ HRESULT CIEHtmlElement::GetChildren(CIEHtmlElementCollectionInstance **ppCollect
|
|||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CIEHtmlElement::GetHtmlDomNode(CIEHtmlDomNode **ppHtmlDomNode)
|
||||
{
|
||||
if (ppHtmlDomNode == NULL)
|
||||
return E_FAIL;
|
||||
*ppHtmlDomNode = NULL;
|
||||
IHTMLDOMNode* pHtmlNode = NULL;
|
||||
// This causes an AddRef on outer unknown:
|
||||
HRESULT hr = m_pNodeAgg->QueryInterface(IID_IHTMLDOMNode, (void**)&pHtmlNode);
|
||||
*ppHtmlDomNode = (CIEHtmlDomNode*)pHtmlNode;
|
||||
return hr;
|
||||
}
|
||||
|
||||
HRESULT CIEHtmlElement::SetDOMNode(nsIDOMNode *pDomNode)
|
||||
{
|
||||
mDOMNode = pDomNode;
|
||||
// Forward to aggregated object:
|
||||
CIEHtmlDomNode *pHtmlDomNode;
|
||||
GetHtmlDomNode(&pHtmlDomNode);
|
||||
HRESULT hr = pHtmlDomNode->SetDOMNode(pDomNode);
|
||||
// Release on outer unknown because GetHtmlDomNode does AddRef on it:
|
||||
GetControllingUnknown()->Release();
|
||||
return hr;
|
||||
}
|
||||
|
||||
HRESULT CIEHtmlElement::SetParent(CNode *pParent)
|
||||
{
|
||||
CNode::SetParent(pParent);
|
||||
// Forward to aggregated object:
|
||||
CIEHtmlDomNode *pHtmlDomNode;
|
||||
GetHtmlDomNode(&pHtmlDomNode);
|
||||
HRESULT hr = pHtmlDomNode->SetParent(pParent);
|
||||
// Release on outer unknown because GetHtmlDomNode does AddRef on it:
|
||||
GetControllingUnknown()->Release();
|
||||
return hr;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// IHTMLElement implementation
|
||||
|
@ -277,26 +323,15 @@ HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_parentElement(IHTMLElement __RPC_F
|
|||
nsCOMPtr<nsIDOMElement> domElement = do_QueryInterface(parentNode);
|
||||
if (domElement)
|
||||
{
|
||||
CIEHtmlNode *pHtmlNode = NULL;
|
||||
CIEHtmlElementInstance *pHtmlElement = NULL;
|
||||
CIEHtmlElementInstance::FindFromDOMNode(parentNode, &pHtmlNode);
|
||||
if (!pHtmlNode)
|
||||
{
|
||||
CIEHtmlElementInstance::CreateInstance(&pHtmlElement);
|
||||
if (!pHtmlElement)
|
||||
{
|
||||
NS_ASSERTION(0, "Could not create element");
|
||||
return E_OUTOFMEMORY;
|
||||
}
|
||||
pHtmlElement->SetDOMNode(parentNode);
|
||||
}
|
||||
else
|
||||
{
|
||||
pHtmlElement = (CIEHtmlElementInstance *) pHtmlNode;
|
||||
}
|
||||
pHtmlElement->QueryInterface(IID_IHTMLElement, (void **) p);
|
||||
CComPtr<IUnknown> pNode;
|
||||
HRESULT hr = CIEHtmlDomNode::FindOrCreateFromDOMNode(parentNode, &pNode);
|
||||
if (FAILED(hr))
|
||||
return hr;
|
||||
if (FAILED(pNode->QueryInterface(IID_IHTMLElement, (void **) p)))
|
||||
return E_UNEXPECTED;
|
||||
}
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -42,11 +42,16 @@
|
|||
#include "IEHtmlElementCollection.h"
|
||||
|
||||
class CIEHtmlElement :
|
||||
public CIEHtmlNode,
|
||||
public CNode,
|
||||
public IDispatchImpl<IHTMLElement, &IID_IHTMLElement, &LIBID_MSHTML>
|
||||
{
|
||||
public:
|
||||
DECLARE_AGGREGATABLE(CIEHtmlElement)
|
||||
CIEHtmlElement();
|
||||
HRESULT FinalConstruct( );
|
||||
void FinalRelease( );
|
||||
|
||||
DECLARE_GET_CONTROLLING_UNKNOWN()
|
||||
|
||||
protected:
|
||||
virtual ~CIEHtmlElement();
|
||||
|
@ -54,11 +59,15 @@ protected:
|
|||
public:
|
||||
|
||||
BEGIN_COM_MAP(CIEHtmlElement)
|
||||
COM_INTERFACE_ENTRY_IID(IID_IDispatch, IHTMLElement)
|
||||
COM_INTERFACE_ENTRY_IID(IID_IHTMLElement, IHTMLElement)
|
||||
COM_INTERFACE_ENTRY2(IDispatch, IHTMLElement)
|
||||
COM_INTERFACE_ENTRY(IHTMLElement)
|
||||
COM_INTERFACE_ENTRY_AGGREGATE(IID_IHTMLDOMNode, m_pNodeAgg)
|
||||
END_COM_MAP()
|
||||
|
||||
virtual HRESULT GetChildren(CIEHtmlElementCollectionInstance **ppCollection);
|
||||
virtual HRESULT GetHtmlDomNode(CIEHtmlDomNode **ppHtmlDomNode);
|
||||
virtual HRESULT SetDOMNode(nsIDOMNode *pDomNode);
|
||||
virtual HRESULT SetParent(CNode *pParent);
|
||||
|
||||
// Implementation of IHTMLElement
|
||||
virtual HRESULT STDMETHODCALLTYPE setAttribute(BSTR strAttributeName, VARIANT AttributeValue, LONG lFlags);
|
||||
|
@ -148,6 +157,9 @@ END_COM_MAP()
|
|||
virtual HRESULT STDMETHODCALLTYPE get_onfilterchange(VARIANT __RPC_FAR *p);
|
||||
virtual HRESULT STDMETHODCALLTYPE get_children(IDispatch __RPC_FAR *__RPC_FAR *p);
|
||||
virtual HRESULT STDMETHODCALLTYPE get_all(IDispatch __RPC_FAR *__RPC_FAR *p);
|
||||
|
||||
protected:
|
||||
IUnknown* m_pNodeAgg;
|
||||
};
|
||||
|
||||
#define CIEHTMLELEMENT_INTERFACES \
|
||||
|
|
|
@ -75,26 +75,14 @@ CIEHtmlElementCollection::~CIEHtmlElementCollection()
|
|||
}
|
||||
}
|
||||
|
||||
HRESULT CIEHtmlElementCollection::FindOrCreateIEElement(nsIDOMNode* pDomNode, CIEHtmlElement** ppIEHtmlElement)
|
||||
HRESULT CIEHtmlElementCollection::FindOrCreateIEElement(nsIDOMNode* domNode, IHTMLElement** pIHtmlElement)
|
||||
{
|
||||
CIEHtmlNode *pHtmlNode = NULL;
|
||||
CIEHtmlElementInstance *pHtmlElement = NULL;
|
||||
CIEHtmlNode::FindFromDOMNode(pDomNode, &pHtmlNode);
|
||||
if (!pHtmlNode)
|
||||
{
|
||||
CIEHtmlElementInstance::CreateInstance(&pHtmlElement);
|
||||
if (!pHtmlElement)
|
||||
{
|
||||
NS_ASSERTION(0, "Could not create element");
|
||||
return E_OUTOFMEMORY;
|
||||
}
|
||||
pHtmlElement->SetDOMNode(pDomNode);
|
||||
*ppIEHtmlElement = pHtmlElement;
|
||||
}
|
||||
else
|
||||
{
|
||||
*ppIEHtmlElement = (CIEHtmlElementInstance *) pHtmlNode;
|
||||
}
|
||||
CComPtr<IUnknown> pNode;
|
||||
HRESULT hr = CIEHtmlDomNode::FindOrCreateFromDOMNode(domNode, &pNode);
|
||||
if (FAILED(hr))
|
||||
return hr;
|
||||
if (FAILED(pNode->QueryInterface(IID_IHTMLElement, (void**)pIHtmlElement)))
|
||||
return E_UNEXPECTED;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
|
@ -132,14 +120,11 @@ HRESULT CIEHtmlElementCollection::PopulateFromDOMHTMLCollection(nsIDOMHTMLCollec
|
|||
}
|
||||
|
||||
// Create an equivalent IE element
|
||||
CIEHtmlElement *pHtmlElement = NULL;
|
||||
CComQIPtr<IHTMLElement> pHtmlElement;
|
||||
HRESULT hr = FindOrCreateIEElement(childNode, &pHtmlElement);
|
||||
if (FAILED(hr))
|
||||
return hr;
|
||||
if (pHtmlElement)
|
||||
{
|
||||
AddNode(pHtmlElement);
|
||||
}
|
||||
AddNode(pHtmlElement);
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
|
@ -190,14 +175,11 @@ HRESULT CIEHtmlElementCollection::PopulateFromDOMNode(nsIDOMNode *aDOMNode, BOOL
|
|||
while (currentNode)
|
||||
{
|
||||
// Create an equivalent IE element
|
||||
CIEHtmlElement *pHtmlElement = NULL;
|
||||
CComQIPtr<IHTMLElement> pHtmlElement;
|
||||
HRESULT hr = FindOrCreateIEElement(currentNode, &pHtmlElement);
|
||||
if (FAILED(hr))
|
||||
return hr;
|
||||
if (pHtmlElement)
|
||||
{
|
||||
AddNode(pHtmlElement);
|
||||
}
|
||||
AddNode(pHtmlElement);
|
||||
walker->NextNode(getter_AddRefs(currentNode));
|
||||
}
|
||||
}
|
||||
|
@ -212,7 +194,7 @@ HRESULT CIEHtmlElementCollection::PopulateFromDOMNode(nsIDOMNode *aDOMNode, BOOL
|
|||
}
|
||||
|
||||
|
||||
HRESULT CIEHtmlElementCollection::CreateFromDOMHTMLCollection(CIEHtmlNode *pParentNode, nsIDOMHTMLCollection *pNodeList, CIEHtmlElementCollection **pInstance)
|
||||
HRESULT CIEHtmlElementCollection::CreateFromDOMHTMLCollection(CNode *pParentNode, nsIDOMHTMLCollection *pNodeList, CIEHtmlElementCollection **pInstance)
|
||||
{
|
||||
if (pInstance == NULL || pParentNode == NULL)
|
||||
{
|
||||
|
@ -247,7 +229,7 @@ HRESULT CIEHtmlElementCollection::CreateFromDOMHTMLCollection(CIEHtmlNode *pPare
|
|||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CIEHtmlElementCollection::CreateFromParentNode(CIEHtmlNode *pParentNode, BOOL bRecurseChildren, CIEHtmlElementCollection **pInstance)
|
||||
HRESULT CIEHtmlElementCollection::CreateFromParentNode(CNode *pParentNode, BOOL bRecurseChildren, CIEHtmlElementCollection **pInstance)
|
||||
{
|
||||
if (pInstance == NULL || pParentNode == NULL)
|
||||
{
|
||||
|
@ -443,7 +425,7 @@ HRESULT STDMETHODCALLTYPE CIEHtmlElementCollection::get__newEnum(IUnknown __RPC_
|
|||
}
|
||||
|
||||
// Store the element in the array
|
||||
CIEHtmlElement *pHtmlElement = NULL;
|
||||
CComQIPtr<IHTMLElement> pHtmlElement;
|
||||
HRESULT hr = FindOrCreateIEElement(childNode, &pHtmlElement);
|
||||
if (FAILED(hr))
|
||||
return hr;
|
||||
|
@ -511,6 +493,8 @@ HRESULT STDMETHODCALLTYPE CIEHtmlElementCollection::item(VARIANT name, VARIANT i
|
|||
case VT_UI4:
|
||||
case VT_I1:
|
||||
case VT_I2:
|
||||
case VT_I1 | VT_BYREF:
|
||||
case VT_I2 | VT_BYREF:
|
||||
// Coerce the variant into a long
|
||||
if (FAILED(VariantChangeType(&name, &name, 0, VT_I4)))
|
||||
{
|
||||
|
@ -533,7 +517,7 @@ HRESULT STDMETHODCALLTYPE CIEHtmlElementCollection::item(VARIANT name, VARIANT i
|
|||
|
||||
if (mDOMNodeList)
|
||||
{
|
||||
CIEHtmlElement *pHtmlElement = NULL;
|
||||
CComQIPtr<IHTMLElement> pHtmlElement;
|
||||
// Search for the Nth element in the list
|
||||
PRUint32 elementCount = 0;
|
||||
PRUint32 length = 0;
|
||||
|
@ -593,7 +577,7 @@ HRESULT STDMETHODCALLTYPE CIEHtmlElementCollection::item(VARIANT name, VARIANT i
|
|||
HRESULT hr = FindOrCreateIEElement(childNode, &pHtmlElement);
|
||||
if (FAILED(hr))
|
||||
return hr;
|
||||
pHtmlElement->SetParent(mParent);
|
||||
((CIEHtmlElement*)pHtmlElement.p)->SetParent(mParent);
|
||||
}
|
||||
elementCount++;
|
||||
}
|
||||
|
@ -724,8 +708,7 @@ HRESULT STDMETHODCALLTYPE CIEHtmlElementCollection::tags(VARIANT tagName, IDispa
|
|||
nodeAsHtmlElement->GetTagName(elementTagName);
|
||||
if (_wcsicmp(elementTagName.get(), OLE2CW(tagName.bstrVal)) == 0)
|
||||
{
|
||||
//Create the element :
|
||||
CIEHtmlElement *pHtmlElement = NULL;
|
||||
CComQIPtr<IHTMLElement> pHtmlElement;
|
||||
HRESULT hr = FindOrCreateIEElement(childNode, &pHtmlElement);
|
||||
if (FAILED(hr))
|
||||
return hr;
|
||||
|
|
|
@ -46,7 +46,7 @@
|
|||
class CIEHtmlElement;
|
||||
|
||||
class CIEHtmlElementCollection :
|
||||
public CIEHtmlNode,
|
||||
public CNode,
|
||||
public IDispatchImpl<IHTMLElementCollection, &IID_IHTMLElementCollection, &LIBID_MSHTML>
|
||||
{
|
||||
private:
|
||||
|
@ -62,7 +62,7 @@ public:
|
|||
|
||||
protected:
|
||||
virtual ~CIEHtmlElementCollection();
|
||||
virtual HRESULT FindOrCreateIEElement(nsIDOMNode* pDomNode, CIEHtmlElement** ppIEHtmlElement);
|
||||
virtual HRESULT FindOrCreateIEElement(nsIDOMNode* domNode, IHTMLElement** pIHtmlElement);
|
||||
|
||||
public:
|
||||
// Adds a node to the collection
|
||||
|
@ -74,15 +74,15 @@ public:
|
|||
virtual HRESULT PopulateFromDOMNode(nsIDOMNode *pIDOMNode, BOOL bRecurseChildren);
|
||||
|
||||
// Helper method creates a collection from a parent node
|
||||
static HRESULT CreateFromParentNode(CIEHtmlNode *pParentNode, BOOL bRecurseChildren, CIEHtmlElementCollection **pInstance);
|
||||
static HRESULT CreateFromParentNode(CNode *pParentNode, BOOL bRecurseChildren, CIEHtmlElementCollection **pInstance);
|
||||
|
||||
// Helper method creates a collection from the specified HTML collection
|
||||
static HRESULT CreateFromDOMHTMLCollection(CIEHtmlNode *pParentNode, nsIDOMHTMLCollection *pNodeList, CIEHtmlElementCollection **pInstance);
|
||||
static HRESULT CreateFromDOMHTMLCollection(CNode *pParentNode, nsIDOMHTMLCollection *pNodeList, CIEHtmlElementCollection **pInstance);
|
||||
|
||||
|
||||
BEGIN_COM_MAP(CIEHtmlElementCollection)
|
||||
COM_INTERFACE_ENTRY_IID(IID_IDispatch, IHTMLElementCollection)
|
||||
COM_INTERFACE_ENTRY_IID(IID_IHTMLElementCollection, IHTMLElementCollection)
|
||||
COM_INTERFACE_ENTRY(IDispatch)
|
||||
COM_INTERFACE_ENTRY(IHTMLElementCollection)
|
||||
END_COM_MAP()
|
||||
|
||||
// IHTMLElementCollection methods
|
||||
|
|
|
@ -58,25 +58,24 @@ PRIntn PR_CALLBACK HashComparator(const void *v1, const void *v2)
|
|||
}
|
||||
|
||||
|
||||
CIEHtmlNode::CIEHtmlNode() :
|
||||
mParent(NULL)
|
||||
CNode::CNode() :
|
||||
mParent(NULL),mDOMNode(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
CIEHtmlNode::~CIEHtmlNode()
|
||||
CNode::~CNode()
|
||||
{
|
||||
SetDOMNode(nsnull);
|
||||
}
|
||||
|
||||
|
||||
HRESULT CIEHtmlNode::SetParent(CIEHtmlNode *pParent)
|
||||
HRESULT CNode::SetParent(CNode *pParent)
|
||||
{
|
||||
mParent = pParent;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
|
||||
HRESULT CIEHtmlNode::FindFromDOMNode(nsIDOMNode *pIDOMNode, CIEHtmlNode **pHtmlNode)
|
||||
HRESULT CNode::FindFromDOMNode(nsIDOMNode *pIDOMNode, CNode **pNode)
|
||||
{
|
||||
if (pIDOMNode == nsnull)
|
||||
{
|
||||
|
@ -89,12 +88,12 @@ HRESULT CIEHtmlNode::FindFromDOMNode(nsIDOMNode *pIDOMNode, CIEHtmlNode **pHtmlN
|
|||
}
|
||||
|
||||
nsCOMPtr<nsISupports> nodeAsSupports = do_QueryInterface(pIDOMNode);
|
||||
*pHtmlNode = (CIEHtmlNode *) PL_HashTableLookup(g_NodeLookupTable, nodeAsSupports);
|
||||
*pNode = (CNode *) PL_HashTableLookup(g_NodeLookupTable, nodeAsSupports);
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CIEHtmlNode::SetDOMNode(nsIDOMNode *pIDOMNode)
|
||||
HRESULT CNode::SetDOMNode(nsIDOMNode *pIDOMNode)
|
||||
{
|
||||
if (pIDOMNode)
|
||||
{
|
||||
|
@ -122,3 +121,261 @@ HRESULT CIEHtmlNode::SetDOMNode(nsIDOMNode *pIDOMNode)
|
|||
}
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// CIEHtmlDomNode methods
|
||||
|
||||
#include "nsIDOMHTMLButtonElement.h"
|
||||
#include "nsIDOMHTMLElement.h"
|
||||
|
||||
#include "IEHtmlButtonElement.h"
|
||||
#include "IEHtmlElement.h"
|
||||
|
||||
CIEHtmlDomNode::CIEHtmlDomNode()
|
||||
{
|
||||
}
|
||||
|
||||
CIEHtmlDomNode::~CIEHtmlDomNode()
|
||||
{
|
||||
SetDOMNode(nsnull);
|
||||
}
|
||||
|
||||
#define CREATE_FROM_DOMNODE(nsInterface, WrapperType, errorMsg) \
|
||||
nsCOMPtr<nsInterface> domNode_##nsInterface = do_QueryInterface(pIDOMNode); \
|
||||
if (domNode_##nsInterface) \
|
||||
{ \
|
||||
WrapperType *pWrapper = NULL; \
|
||||
WrapperType::CreateInstance(&pWrapper); \
|
||||
if (!pWrapper) \
|
||||
{ \
|
||||
NS_ASSERTION(0, errorMsg); \
|
||||
return E_OUTOFMEMORY; \
|
||||
} \
|
||||
if (FAILED(pWrapper->QueryInterface(IID_IUnknown, (void**)pNode))) \
|
||||
return E_UNEXPECTED; \
|
||||
pWrapper->SetDOMNode(pIDOMNode); \
|
||||
return S_OK; \
|
||||
}
|
||||
|
||||
|
||||
HRESULT CIEHtmlDomNode::CreateFromDOMNode(nsIDOMNode *pIDOMNode, IUnknown **pNode)
|
||||
{
|
||||
CREATE_FROM_DOMNODE(nsIDOMHTMLButtonElement, CIEHtmlButtonElementInstance, "")
|
||||
CREATE_FROM_DOMNODE(nsIDOMHTMLElement, CIEHtmlElementInstance, "Could not create element")
|
||||
CREATE_FROM_DOMNODE(nsIDOMNode, CIEHtmlDomNodeInstance, "Could not create node")
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
HRESULT CIEHtmlDomNode::FindFromDOMNode(nsIDOMNode *pIDOMNode, IUnknown **pNode)
|
||||
{
|
||||
if (pIDOMNode == nsnull)
|
||||
{
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
if (g_NodeLookupTable == NULL)
|
||||
{
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsISupports> nodeAsSupports = do_QueryInterface(pIDOMNode);
|
||||
*pNode = (IUnknown *) PL_HashTableLookup(g_NodeLookupTable, nodeAsSupports);
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CIEHtmlDomNode::FindOrCreateFromDOMNode(nsIDOMNode *pIDOMNode, IUnknown **pNode)
|
||||
{
|
||||
FindFromDOMNode(pIDOMNode,pNode);
|
||||
|
||||
if (*pNode)
|
||||
{
|
||||
(*pNode)->AddRef();
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT hr = CreateFromDOMNode(pIDOMNode, pNode);
|
||||
if SUCCEEDED(hr)
|
||||
return S_OK;
|
||||
return hr;
|
||||
}
|
||||
|
||||
HRESULT CIEHtmlDomNode::SetDOMNode(nsIDOMNode *pIDOMNode)
|
||||
{
|
||||
if (pIDOMNode)
|
||||
{
|
||||
if (g_NodeLookupTable == NULL)
|
||||
{
|
||||
g_NodeLookupTable = PL_NewHashTable(123, HashFunction, HashComparator, HashComparator, NULL, NULL);
|
||||
}
|
||||
|
||||
mDOMNode = pIDOMNode;
|
||||
nsCOMPtr<nsISupports> nodeAsSupports= do_QueryInterface(mDOMNode);
|
||||
PL_HashTableAdd(g_NodeLookupTable, nodeAsSupports, (IUnknown *)this );
|
||||
}
|
||||
else if (mDOMNode)
|
||||
{
|
||||
// Remove the entry from the hashtable
|
||||
nsCOMPtr<nsISupports> nodeAsSupports = do_QueryInterface(mDOMNode);
|
||||
PL_HashTableRemove(g_NodeLookupTable, nodeAsSupports);
|
||||
mDOMNode = nsnull;
|
||||
|
||||
if (g_NodeLookupTable->nentries == 0)
|
||||
{
|
||||
PL_HashTableDestroy(g_NodeLookupTable);
|
||||
g_NodeLookupTable = NULL;
|
||||
}
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// IHTMLDOMNode methods
|
||||
|
||||
#define SIB_NODE_GET_NUMERIC(function,numtype) \
|
||||
{ \
|
||||
if (!p) return E_INVALIDARG; \
|
||||
if (!mDOMNode) return E_UNEXPECTED; \
|
||||
numtype nData; \
|
||||
HRESULT rc = mDOMNode->function(&nData); \
|
||||
*p=nData; \
|
||||
return rc; \
|
||||
}
|
||||
|
||||
HRESULT STDMETHODCALLTYPE CIEHtmlDomNode::get_nodeType(long __RPC_FAR *p)
|
||||
SIB_NODE_GET_NUMERIC(GetNodeType,PRUint16)
|
||||
|
||||
#define SIB_NODE_GET_ELEMENT(function,fn_elt_type) \
|
||||
{ \
|
||||
return E_NOTIMPL; \
|
||||
}
|
||||
|
||||
HRESULT STDMETHODCALLTYPE CIEHtmlDomNode::get_parentNode(IHTMLDOMNode __RPC_FAR *__RPC_FAR *p)
|
||||
SIB_NODE_GET_ELEMENT(GetParentNode,nsIDOMNode)
|
||||
|
||||
HRESULT STDMETHODCALLTYPE CIEHtmlDomNode::hasChildNodes(VARIANT_BOOL __RPC_FAR *p)
|
||||
SIB_NODE_GET_NUMERIC(HasChildNodes,PRBool)
|
||||
|
||||
#define SIB_STD_NOTIMPL \
|
||||
{ \
|
||||
return E_NOTIMPL; \
|
||||
}
|
||||
|
||||
HRESULT STDMETHODCALLTYPE CIEHtmlDomNode::get_childNodes(IDispatch __RPC_FAR *__RPC_FAR *p)
|
||||
SIB_STD_NOTIMPL
|
||||
|
||||
HRESULT STDMETHODCALLTYPE CIEHtmlDomNode::get_attributes(IDispatch __RPC_FAR *__RPC_FAR *p)
|
||||
SIB_STD_NOTIMPL
|
||||
|
||||
HRESULT STDMETHODCALLTYPE CIEHtmlDomNode::insertBefore(IHTMLDOMNode __RPC_FAR *newChild,
|
||||
VARIANT refChild,
|
||||
IHTMLDOMNode __RPC_FAR *__RPC_FAR *node)
|
||||
SIB_STD_NOTIMPL
|
||||
|
||||
HRESULT STDMETHODCALLTYPE CIEHtmlDomNode::removeChild(
|
||||
IHTMLDOMNode __RPC_FAR *oldChild,
|
||||
IHTMLDOMNode __RPC_FAR *__RPC_FAR *node)
|
||||
SIB_STD_NOTIMPL
|
||||
|
||||
HRESULT STDMETHODCALLTYPE CIEHtmlDomNode::replaceChild(
|
||||
IHTMLDOMNode __RPC_FAR *newChild,
|
||||
IHTMLDOMNode __RPC_FAR *oldChild,
|
||||
IHTMLDOMNode __RPC_FAR *__RPC_FAR *node)
|
||||
SIB_STD_NOTIMPL
|
||||
|
||||
HRESULT STDMETHODCALLTYPE CIEHtmlDomNode::cloneNode(
|
||||
VARIANT_BOOL fDeep,
|
||||
IHTMLDOMNode __RPC_FAR *__RPC_FAR *clonedNode)
|
||||
SIB_STD_NOTIMPL
|
||||
|
||||
HRESULT STDMETHODCALLTYPE CIEHtmlDomNode::removeNode(
|
||||
VARIANT_BOOL fDeep,
|
||||
IHTMLDOMNode __RPC_FAR *__RPC_FAR *removed)
|
||||
SIB_STD_NOTIMPL
|
||||
|
||||
HRESULT STDMETHODCALLTYPE CIEHtmlDomNode::swapNode(
|
||||
IHTMLDOMNode __RPC_FAR *otherNode,
|
||||
IHTMLDOMNode __RPC_FAR *__RPC_FAR *swappedNode)
|
||||
SIB_STD_NOTIMPL
|
||||
|
||||
HRESULT STDMETHODCALLTYPE CIEHtmlDomNode::replaceNode(
|
||||
IHTMLDOMNode __RPC_FAR *replacement,
|
||||
IHTMLDOMNode __RPC_FAR *__RPC_FAR *replaced)
|
||||
SIB_STD_NOTIMPL
|
||||
|
||||
HRESULT STDMETHODCALLTYPE CIEHtmlDomNode::appendChild(IHTMLDOMNode *newChild, IHTMLDOMNode **node)
|
||||
{
|
||||
if (!newChild || !node)
|
||||
return E_INVALIDARG;
|
||||
*node = NULL;
|
||||
if (!mDOMNode)
|
||||
return E_UNEXPECTED;
|
||||
nsCOMPtr<nsIDOMNode> domNode;
|
||||
nsresult rv = mDOMNode->AppendChild(((CIEHtmlDomNode*)newChild)->mDOMNode, getter_AddRefs(domNode));
|
||||
if (NS_FAILED(rv))
|
||||
return E_FAIL;
|
||||
// Create com object:
|
||||
CComPtr<IUnknown> pNode = NULL;
|
||||
HRESULT hr = CIEHtmlDomNode::FindOrCreateFromDOMNode(domNode, &pNode);
|
||||
if (FAILED(hr))
|
||||
return hr;
|
||||
if (FAILED(pNode->QueryInterface(IID_IHTMLDOMNode, (void**)node)))
|
||||
return E_UNEXPECTED;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT STDMETHODCALLTYPE CIEHtmlDomNode::get_nodeName(BSTR __RPC_FAR *p)
|
||||
{
|
||||
if (!mDOMNode) return E_UNEXPECTED;
|
||||
nsString szTagName;
|
||||
HRESULT rc = mDOMNode->GetNodeName(szTagName);
|
||||
USES_CONVERSION;
|
||||
*p = SysAllocString(W2COLE(ToNewUnicode(szTagName)));
|
||||
return rc;
|
||||
}
|
||||
|
||||
HRESULT STDMETHODCALLTYPE CIEHtmlDomNode::put_nodeValue(VARIANT p)
|
||||
{
|
||||
if (!mDOMNode) return E_UNEXPECTED;
|
||||
CComVariant vValue;
|
||||
if (FAILED(vValue.ChangeType(VT_BSTR, &p))) {
|
||||
return E_INVALIDARG;
|
||||
}
|
||||
nsString szValue(OLE2W(vValue.bstrVal));
|
||||
if (!mDOMNode->SetNodeValue(szValue))
|
||||
return E_FAIL;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT STDMETHODCALLTYPE CIEHtmlDomNode::get_nodeValue(VARIANT __RPC_FAR *p)
|
||||
{
|
||||
if (p == NULL) {
|
||||
return E_INVALIDARG;
|
||||
}
|
||||
if (!mDOMNode) return E_UNEXPECTED;
|
||||
nsString szValue;
|
||||
nsresult nr = mDOMNode->GetNodeValue(szValue);
|
||||
if (nr == NS_OK) {
|
||||
USES_CONVERSION;
|
||||
p->vt = VT_BSTR;
|
||||
p->bstrVal = SysAllocString(W2COLE(ToNewUnicode(szValue)));
|
||||
return S_OK;
|
||||
}
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
HRESULT STDMETHODCALLTYPE CIEHtmlDomNode::get_firstChild(IHTMLDOMNode __RPC_FAR *__RPC_FAR *p)
|
||||
SIB_NODE_GET_ELEMENT(GetFirstChild,nsIDOMNode)
|
||||
|
||||
HRESULT STDMETHODCALLTYPE CIEHtmlDomNode::get_lastChild(IHTMLDOMNode __RPC_FAR *__RPC_FAR *p)
|
||||
SIB_NODE_GET_ELEMENT(GetLastChild,nsIDOMNode)
|
||||
|
||||
HRESULT STDMETHODCALLTYPE CIEHtmlDomNode::get_previousSibling(IHTMLDOMNode __RPC_FAR *__RPC_FAR *p)
|
||||
{
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
HRESULT STDMETHODCALLTYPE CIEHtmlDomNode::get_nextSibling(IHTMLDOMNode __RPC_FAR *__RPC_FAR *p)
|
||||
{
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
|
|
@ -20,7 +20,8 @@
|
|||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Adam Lock <adamlock@netscape.com>
|
||||
* Adam Lock <adamlock@eircom.net>
|
||||
* Alexandre Trémon <atremon@elansoftware.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
|
@ -42,22 +43,72 @@
|
|||
#include "nsCOMPtr.h"
|
||||
#include "nsIDOMNode.h"
|
||||
|
||||
class CIEHtmlNode :
|
||||
class CNode :
|
||||
public CComObjectRootEx<CComMultiThreadModel>
|
||||
{
|
||||
protected:
|
||||
CIEHtmlNode();
|
||||
virtual ~CIEHtmlNode();
|
||||
CNode();
|
||||
virtual ~CNode();
|
||||
|
||||
public:
|
||||
CIEHtmlNode *mParent;
|
||||
CNode *mParent;
|
||||
nsCOMPtr<nsIDOMNode> mDOMNode;
|
||||
|
||||
static HRESULT FindFromDOMNode(nsIDOMNode *pIDOMNode, CIEHtmlNode **pHtmlNode);
|
||||
virtual HRESULT SetParent(CIEHtmlNode *mParent);
|
||||
static HRESULT FindFromDOMNode(nsIDOMNode *pIDOMNode, CNode **pNode);
|
||||
virtual HRESULT SetParent(CNode *pParent);
|
||||
virtual HRESULT SetDOMNode(nsIDOMNode *pIDOMNode);
|
||||
};
|
||||
|
||||
typedef CComObject<CIEHtmlNode> CIEHtmlNodeInstance;
|
||||
class CIEHtmlDomNode :
|
||||
public CNode,
|
||||
public IDispatchImpl<IHTMLDOMNode, &IID_IHTMLDOMNode, &LIBID_MSHTML>
|
||||
{
|
||||
public:
|
||||
DECLARE_AGGREGATABLE(CIEHtmlDomNode)
|
||||
CIEHtmlDomNode();
|
||||
|
||||
static HRESULT FindFromDOMNode(nsIDOMNode *pIDOMNode, IUnknown **pNode);
|
||||
static HRESULT FindOrCreateFromDOMNode(nsIDOMNode *pIDOMNode, IUnknown **pNode);
|
||||
static HRESULT CreateFromDOMNode(nsIDOMNode *pIDOMNode, IUnknown **pNode);
|
||||
virtual HRESULT SetDOMNode(nsIDOMNode *pIDOMNode);
|
||||
|
||||
DECLARE_GET_CONTROLLING_UNKNOWN()
|
||||
protected:
|
||||
virtual ~CIEHtmlDomNode();
|
||||
|
||||
public:
|
||||
|
||||
BEGIN_COM_MAP(CIEHtmlDomNode)
|
||||
COM_INTERFACE_ENTRY(IDispatch)
|
||||
COM_INTERFACE_ENTRY(IHTMLDOMNode)
|
||||
//COM_INTERFACE_ENTRY_FUNC(IID_IHTMLElement, 0, QueryInterfaceOnNode)
|
||||
END_COM_MAP()
|
||||
|
||||
static HRESULT WINAPI QueryInterfaceOnNode(void* pv, REFIID riid, LPVOID* ppv, DWORD dw);
|
||||
|
||||
//IID_IHTMLDOMNode
|
||||
virtual HRESULT STDMETHODCALLTYPE get_nodeType(long __RPC_FAR *p);
|
||||
virtual HRESULT STDMETHODCALLTYPE get_parentNode(IHTMLDOMNode __RPC_FAR *__RPC_FAR *p);
|
||||
virtual HRESULT STDMETHODCALLTYPE hasChildNodes(VARIANT_BOOL __RPC_FAR *fChildren);
|
||||
virtual HRESULT STDMETHODCALLTYPE get_childNodes(IDispatch __RPC_FAR *__RPC_FAR *p);
|
||||
virtual HRESULT STDMETHODCALLTYPE get_attributes(IDispatch __RPC_FAR *__RPC_FAR *p);
|
||||
virtual HRESULT STDMETHODCALLTYPE insertBefore(IHTMLDOMNode __RPC_FAR *newChild, VARIANT refChild, IHTMLDOMNode __RPC_FAR *__RPC_FAR *node);
|
||||
virtual HRESULT STDMETHODCALLTYPE removeChild(IHTMLDOMNode __RPC_FAR *oldChild, IHTMLDOMNode __RPC_FAR *__RPC_FAR *node);
|
||||
virtual HRESULT STDMETHODCALLTYPE replaceChild(IHTMLDOMNode __RPC_FAR *newChild, IHTMLDOMNode __RPC_FAR *oldChild, IHTMLDOMNode __RPC_FAR *__RPC_FAR *node);
|
||||
virtual HRESULT STDMETHODCALLTYPE cloneNode(VARIANT_BOOL fDeep, IHTMLDOMNode __RPC_FAR *__RPC_FAR *clonedNode);
|
||||
virtual HRESULT STDMETHODCALLTYPE removeNode(VARIANT_BOOL fDeep, IHTMLDOMNode __RPC_FAR *__RPC_FAR *removed);
|
||||
virtual HRESULT STDMETHODCALLTYPE swapNode(IHTMLDOMNode __RPC_FAR *otherNode, IHTMLDOMNode __RPC_FAR *__RPC_FAR *swappedNode);
|
||||
virtual HRESULT STDMETHODCALLTYPE replaceNode(IHTMLDOMNode __RPC_FAR *replacement, IHTMLDOMNode __RPC_FAR *__RPC_FAR *replaced);
|
||||
virtual HRESULT STDMETHODCALLTYPE appendChild(IHTMLDOMNode __RPC_FAR *newChild, IHTMLDOMNode __RPC_FAR *__RPC_FAR *node);
|
||||
virtual HRESULT STDMETHODCALLTYPE get_nodeName(BSTR __RPC_FAR *p);
|
||||
virtual HRESULT STDMETHODCALLTYPE put_nodeValue(VARIANT p);
|
||||
virtual HRESULT STDMETHODCALLTYPE get_nodeValue(VARIANT __RPC_FAR *p);
|
||||
virtual HRESULT STDMETHODCALLTYPE get_firstChild(IHTMLDOMNode __RPC_FAR *__RPC_FAR *p);
|
||||
virtual HRESULT STDMETHODCALLTYPE get_lastChild(IHTMLDOMNode __RPC_FAR *__RPC_FAR *p);
|
||||
virtual HRESULT STDMETHODCALLTYPE get_previousSibling(IHTMLDOMNode __RPC_FAR *__RPC_FAR *p);
|
||||
virtual HRESULT STDMETHODCALLTYPE get_nextSibling(IHTMLDOMNode __RPC_FAR *__RPC_FAR *p);
|
||||
};
|
||||
|
||||
typedef CComObject<CIEHtmlDomNode> CIEHtmlDomNodeInstance;
|
||||
|
||||
#endif
|
|
@ -20,7 +20,7 @@
|
|||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Adam Lock <adamlock@netscape.com>
|
||||
* Alexandre Trémon <atremon@elansoftware.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
|
|
|
@ -80,25 +80,12 @@ HRESULT CRange::GetParentElement(IHTMLElement **ppParent)
|
|||
domNode = parentNode;
|
||||
}
|
||||
// get or create com object:
|
||||
CIEHtmlNode *pHtmlNode = NULL;
|
||||
CIEHtmlElementInstance *pHtmlElement = NULL;
|
||||
CIEHtmlElementInstance::FindFromDOMNode(domNode, &pHtmlNode);
|
||||
if (!pHtmlNode)
|
||||
{
|
||||
CIEHtmlElementInstance::CreateInstance(&pHtmlElement);
|
||||
if (!pHtmlElement)
|
||||
{
|
||||
NS_ASSERTION(0, "Could not create element");
|
||||
return E_OUTOFMEMORY;
|
||||
}
|
||||
pHtmlElement->SetDOMNode(domNode);
|
||||
}
|
||||
else
|
||||
{
|
||||
pHtmlElement = (CIEHtmlElementInstance *) pHtmlNode;
|
||||
}
|
||||
// return com object:
|
||||
pHtmlElement->QueryInterface(IID_IHTMLElement, (void **)ppParent);
|
||||
CComPtr<IUnknown> pNode;
|
||||
HRESULT hr = CIEHtmlDomNode::FindOrCreateFromDOMNode(domNode, &pNode);
|
||||
if (FAILED(hr))
|
||||
return hr;
|
||||
if (FAILED(pNode->QueryInterface(IID_IHTMLElement, (void **)ppParent)))
|
||||
return E_UNEXPECTED;
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
@ -118,7 +105,7 @@ HRESULT STDMETHODCALLTYPE CIEHtmlTxtRange::pasteHTML(BSTR html)
|
|||
nsCOMPtr<nsIDOMDocumentFragment> domDocFragment;
|
||||
nsAutoString nsStrHtml(OLE2W(html));
|
||||
|
||||
if (mRange->DeleteContents())
|
||||
if (NS_FAILED(mRange->DeleteContents()))
|
||||
return E_FAIL;
|
||||
nsCOMPtr<nsIDOMNSRange> domNSRange = do_QueryInterface(mRange);
|
||||
if (!domNSRange)
|
||||
|
@ -142,7 +129,7 @@ HRESULT STDMETHODCALLTYPE CIEHtmlTxtRange::get_text(BSTR __RPC_FAR *p)
|
|||
mRange->ToString(strText);
|
||||
|
||||
*p = SysAllocString(strText.get());
|
||||
return p ? S_OK : E_OUTOFMEMORY;
|
||||
return *p ? S_OK : E_OUTOFMEMORY;
|
||||
}
|
||||
|
||||
HRESULT STDMETHODCALLTYPE CIEHtmlTxtRange::parentElement(IHTMLElement __RPC_FAR *__RPC_FAR *Parent)
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Alexandre Trémon <atremon@elansoftware.com>
|
||||
* Adam Lock <adamlock@eircom.net>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
|
|
|
@ -70,6 +70,7 @@ CPPSRCS = \
|
|||
ItemContainer.cpp \
|
||||
IEHtmlSelectionObject.cpp \
|
||||
IEHtmlTxtRange.cpp \
|
||||
IEHtmlButtonElement.cpp \
|
||||
$(NULL)
|
||||
|
||||
EXPORTS = \
|
||||
|
|
|
@ -133,14 +133,13 @@ HRESULT STDMETHODCALLTYPE CIEHtmlDocument::get_body(IHTMLElement __RPC_FAR *__RP
|
|||
{
|
||||
nsCOMPtr<nsIDOMNode> bodyNode = do_QueryInterface(bodyElement);
|
||||
|
||||
CIEHtmlElementInstance *pElement = NULL;
|
||||
CIEHtmlElementInstance::CreateInstance(&pElement);
|
||||
if (pElement)
|
||||
{
|
||||
pElement->SetDOMNode(bodyNode);
|
||||
pElement->SetParent(this);
|
||||
pElement->QueryInterface(IID_IHTMLElement, (void **) p);
|
||||
}
|
||||
// get or create com object:
|
||||
CComPtr<IUnknown> pNode;
|
||||
HRESULT hr = CIEHtmlDomNode::FindOrCreateFromDOMNode(bodyNode, &pNode);
|
||||
if (FAILED(hr))
|
||||
return hr;
|
||||
if (FAILED(pNode->QueryInterface(IID_IHTMLElement, (void **)p)))
|
||||
return E_UNEXPECTED;
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
|
|
|
@ -46,7 +46,7 @@
|
|||
class CMozillaBrowser;
|
||||
|
||||
class CIEHtmlDocument :
|
||||
public CIEHtmlNode,
|
||||
public CNode,
|
||||
public IDispatchImpl<IHTMLDocument2, &IID_IHTMLDocument2, &LIBID_MSHTML, 4, 0>,
|
||||
public IOleCommandTarget
|
||||
{
|
||||
|
|
|
@ -226,6 +226,9 @@ SOURCE=..\common\ControlSiteIPFrame.cpp
|
|||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\common\IEHtmlButtonElement.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
SOURCE=..\common\IEHtmlElement.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
@ -274,6 +277,9 @@ SOURCE=..\common\CPMozillaControl.h
|
|||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\common\IEHtmlButtonElement.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
SOURCE=..\common\IEHtmlElement.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
|
Загрузка…
Ссылка в новой задаче