This commit is contained in:
locka%iol.ie 1999-03-22 18:59:48 +00:00
Родитель e1db9ebcc4
Коммит 43cac2bed5
6 изменённых файлов: 177 добавлений и 37 удалений

Просмотреть файл

@ -41,17 +41,6 @@ HRESULT STDMETHODCALLTYPE CIEHtmlDocument::get_Script(IDispatch __RPC_FAR *__RPC
// IHTMLDocument2 methods
HRESULT STDMETHODCALLTYPE CIEHtmlDocument::get_all(IHTMLElementCollection __RPC_FAR *__RPC_FAR *p)
{
// Get the associated document
nsIDOMNode *pIDOMNode = nsnull;
if (m_pIDOMNode != nsnull)
{
m_pIDOMNode->QueryInterface(kIDOMNodeIID, (void **) &pIDOMNode);
}
if (pIDOMNode == nsnull)
{
return E_UNEXPECTED;
}
// Validate parameters
if (p == NULL)
{
@ -61,15 +50,13 @@ HRESULT STDMETHODCALLTYPE CIEHtmlDocument::get_all(IHTMLElementCollection __RPC_
*p = NULL;
CIEHtmlElementCollectionInstance *pCollection = NULL;
CIEHtmlElementCollection::CreateFromParentNode(pIDOMNode, (CIEHtmlElementCollection **) &pCollection);
CIEHtmlElementCollection::CreateFromParentNode(this, (CIEHtmlElementCollection **) &pCollection);
if (pCollection)
{
pCollection->AddRef();
*p = pCollection;
}
pIDOMNode->Release();
return S_OK;
}

Просмотреть файл

@ -99,7 +99,18 @@ HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_tagName(BSTR __RPC_FAR *p)
HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_parentElement(IHTMLElement __RPC_FAR *__RPC_FAR *p)
{
return E_NOTIMPL;
if (p == NULL)
{
return E_INVALIDARG;
}
*p = NULL;
if (m_pParent)
{
// m_pParent->QueryInterface(IID_IHTMLElement, (void **) p);
}
return S_OK;
}
HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_style(IHTMLStyle __RPC_FAR *__RPC_FAR *p)
@ -484,22 +495,6 @@ HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_onfilterchange(VARIANT __RPC_FAR *
HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_children(IDispatch __RPC_FAR *__RPC_FAR *p)
{
return E_NOTIMPL;
}
HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_all(IDispatch __RPC_FAR *__RPC_FAR *p)
{
// Get the associated document
nsIDOMNode *pIDOMNode = nsnull;
if (m_pIDOMNode != nsnull)
{
m_pIDOMNode->QueryInterface(kIDOMNodeIID, (void **) &pIDOMNode);
}
if (pIDOMNode == nsnull)
{
return E_UNEXPECTED;
}
// Validate parameters
if (p == NULL)
{
@ -509,14 +504,35 @@ HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_all(IDispatch __RPC_FAR *__RPC_FAR
*p = NULL;
CIEHtmlElementCollectionInstance *pCollection = NULL;
CIEHtmlElementCollection::CreateFromParentNode(pIDOMNode, (CIEHtmlElementCollection **) &pCollection);
CIEHtmlElementCollection::CreateFromParentNode(this, (CIEHtmlElementCollection **) &pCollection);
if (pCollection)
{
pCollection->AddRef();
*p = pCollection;
}
pIDOMNode->Release();
return S_OK;
}
HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_all(IDispatch __RPC_FAR *__RPC_FAR *p)
{
// Validate parameters
if (p == NULL)
{
return E_INVALIDARG;
}
*p = NULL;
// TODO get ALL contained elements, not just the immediate children
CIEHtmlElementCollectionInstance *pCollection = NULL;
CIEHtmlElementCollection::CreateFromParentNode(this, (CIEHtmlElementCollection **) &pCollection);
if (pCollection)
{
pCollection->AddRef();
*p = pCollection;
}
return S_OK;
}

Просмотреть файл

@ -21,21 +21,34 @@
CIEHtmlElementCollection::CIEHtmlElementCollection()
{
m_pParent = NULL;
}
CIEHtmlElementCollection::~CIEHtmlElementCollection()
{
}
HRESULT CIEHtmlElementCollection::SetParentNode(CIEHtmlNode *pParent)
{
m_pParent = pParent;
return S_OK;
}
HRESULT CIEHtmlElementCollection::CreateFromParentNode(nsIDOMNode *pParentNode, CIEHtmlElementCollection **pInstance)
HRESULT CIEHtmlElementCollection::CreateFromParentNode(CIEHtmlNode *pParentNode, CIEHtmlElementCollection **pInstance)
{
if (pInstance == NULL)
{
return E_INVALIDARG;
}
if (pParentNode == nsnull)
if (pParentNode == NULL)
{
return E_INVALIDARG;
}
nsIDOMNode *pIDOMNode = nsnull;
pParentNode->GetDOMNode(&pIDOMNode);
if (pIDOMNode == nsnull)
{
return E_INVALIDARG;
}
@ -45,9 +58,11 @@ HRESULT CIEHtmlElementCollection::CreateFromParentNode(nsIDOMNode *pParentNode,
CIEHtmlElementCollectionInstance *pCollection = NULL;
CIEHtmlElementCollectionInstance::CreateInstance(&pCollection);
pCollection->SetParentNode(pParentNode);
// Get elements
nsIDOMNodeList *pIDOMNodeList = nsnull;
pParentNode->GetChildNodes(&pIDOMNodeList);
pIDOMNode->GetChildNodes(&pIDOMNodeList);
if (pIDOMNodeList)
{
PRUint32 aLength = 0;
@ -63,6 +78,7 @@ HRESULT CIEHtmlElementCollection::CreateFromParentNode(nsIDOMNode *pParentNode,
if (pElement)
{
pElement->SetDOMNode(pChildNode);
pElement->SetParentNode(pCollection->m_pParent);
pCollection->AddNode(pElement);
}
@ -76,6 +92,8 @@ HRESULT CIEHtmlElementCollection::CreateFromParentNode(nsIDOMNode *pParentNode,
*pInstance = pCollection;
pIDOMNode->Release();
return S_OK;
}

Просмотреть файл

@ -20,6 +20,8 @@
#include "IEHtmlNode.h"
class CIEHtmlElement;
class CIEHtmlElementCollection : public CComObjectRootEx<CComSingleThreadModel>,
public IDispatchImpl<IHTMLElementCollection, &IID_IHTMLElementCollection, &LIBID_MSHTML>
{
@ -30,12 +32,17 @@ public:
protected:
virtual ~CIEHtmlElementCollection();
CIEHtmlNode *m_pParent;
public:
// Adds a node to the collection
virtual HRESULT AddNode(IDispatch *pNode);
// Sets the parent node of this collection
virtual HRESULT SetParentNode(CIEHtmlNode *pParent);
// Helper method creates a collection from a parent node
static HRESULT CreateFromParentNode(nsIDOMNode *pParentNode, CIEHtmlElementCollection **pInstance);
static HRESULT CreateFromParentNode(CIEHtmlNode *pParentNode, CIEHtmlElementCollection **pInstance);
BEGIN_COM_MAP(CIEHtmlElementCollection)
COM_INTERFACE_ENTRY_IID(IID_IDispatch, IHTMLElementCollection)

Просмотреть файл

@ -0,0 +1,72 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL") you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "stdafx.h"
#include "IEHtmlNode.h"
static NS_DEFINE_IID(kIDOMNodeIID, NS_IDOMNODE_IID);
CIEHtmlNode::CIEHtmlNode()
{
m_pIDOMNode = nsnull;
m_pParent = NULL;
}
CIEHtmlNode::~CIEHtmlNode()
{
SetDOMNode(nsnull);
}
HRESULT CIEHtmlNode::SetParentNode(CIEHtmlNode *pParent)
{
m_pParent = pParent;
return S_OK;
}
HRESULT CIEHtmlNode::SetDOMNode(nsIDOMNode *pIDOMNode)
{
if (m_pIDOMNode)
{
m_pIDOMNode->Release();
m_pIDOMNode = nsnull;
}
if (pIDOMNode)
{
m_pIDOMNode = pIDOMNode;
m_pIDOMNode->AddRef();
}
return S_OK;
}
HRESULT CIEHtmlNode::GetDOMNode(nsIDOMNode **pIDOMNode)
{
if (pIDOMNode == NULL)
{
return E_INVALIDARG;
}
*pIDOMNode = nsnull;
if (m_pIDOMNode)
{
m_pIDOMNode->AddRef();
*pIDOMNode = m_pIDOMNode;
}
return S_OK;
}

Просмотреть файл

@ -0,0 +1,40 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef IEHTMLNODE_H
#define IEHTMLNODE_H
class CIEHtmlNode : public CComObjectRootEx<CComSingleThreadModel>
{
protected:
nsIDOMNode *m_pIDOMNode;
CIEHtmlNode *m_pParent;
public:
CIEHtmlNode();
protected:
virtual ~CIEHtmlNode();
public:
virtual HRESULT SetDOMNode(nsIDOMNode *pIDOMNode);
virtual HRESULT GetDOMNode(nsIDOMNode **pIDOMNode);
virtual HRESULT SetParentNode(CIEHtmlNode *pParent);
};
typedef CComObject<CIEHtmlNode> CIEHtmlNodeInstance;
#endif