Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / embedding / browser / activex / src / common / IEHtmlElement.cpp
blob00d02dc951787c1fa2c8e3632476484e839e66fb
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
23 * Adam Lock <adamlock@netscape.com>
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
39 #include "stdafx.h"
41 #include "nsCOMPtr.h"
42 #include "nsIDOMElement.h"
44 #include "IEHtmlElement.h"
45 #include "IEHtmlElementCollection.h"
47 #include "nsIDOMHTMLElement.h"
48 #include "nsIDOMNSHTMLElement.h"
49 #include "nsIDOM3Node.h"
50 #include "nsIDOMDocumentRange.h"
51 #include "nsIDOMRange.h"
52 #include "nsIDOMNSRange.h"
53 #include "nsIDOMDocumentFragment.h"
54 #include "nsIDocumentEncoder.h"
55 #include "nsContentCID.h"
57 CIEHtmlElement::CIEHtmlElement()
59 m_pNodeAgg = NULL;
62 HRESULT CIEHtmlElement::FinalConstruct( )
64 return CComCreator<CComAggObject<CIEHtmlDomNode> >::CreateInstance(GetControllingUnknown(),
65 IID_IUnknown, reinterpret_cast<void**>(&m_pNodeAgg));
68 CIEHtmlElement::~CIEHtmlElement()
72 void CIEHtmlElement::FinalRelease( )
74 m_pNodeAgg->Release();
77 HRESULT CIEHtmlElement::GetChildren(CIEHtmlElementCollectionInstance **ppCollection)
79 // Validate parameters
80 if (ppCollection == NULL)
82 return E_INVALIDARG;
85 *ppCollection = NULL;
87 // Create a collection representing the children of this node
88 CIEHtmlElementCollectionInstance *pCollection = NULL;
89 CIEHtmlElementCollection::CreateFromParentNode(this, FALSE, (CIEHtmlElementCollection **) &pCollection);
90 if (pCollection)
92 pCollection->AddRef();
93 *ppCollection = pCollection;
96 return S_OK;
99 HRESULT CIEHtmlElement::GetHtmlDomNode(CIEHtmlDomNode **ppHtmlDomNode)
101 if (ppHtmlDomNode == NULL)
102 return E_FAIL;
103 *ppHtmlDomNode = NULL;
104 IHTMLDOMNode* pHtmlNode = NULL;
105 // This causes an AddRef on outer unknown:
106 HRESULT hr = m_pNodeAgg->QueryInterface(__uuidof(IHTMLDOMNode), (void**)&pHtmlNode);
107 *ppHtmlDomNode = (CIEHtmlDomNode*)pHtmlNode;
108 return hr;
111 HRESULT CIEHtmlElement::SetDOMNode(nsIDOMNode *pDomNode)
113 mDOMNode = pDomNode;
114 // Forward to aggregated object:
115 CIEHtmlDomNode *pHtmlDomNode;
116 GetHtmlDomNode(&pHtmlDomNode);
117 HRESULT hr = pHtmlDomNode->SetDOMNode(pDomNode);
118 // Release on outer unknown because GetHtmlDomNode does AddRef on it:
119 GetControllingUnknown()->Release();
120 return hr;
123 HRESULT CIEHtmlElement::SetParent(CNode *pParent)
125 CNode::SetParent(pParent);
126 // Forward to aggregated object:
127 CIEHtmlDomNode *pHtmlDomNode;
128 GetHtmlDomNode(&pHtmlDomNode);
129 HRESULT hr = pHtmlDomNode->SetParent(pParent);
130 // Release on outer unknown because GetHtmlDomNode does AddRef on it:
131 GetControllingUnknown()->Release();
132 return hr;
135 ///////////////////////////////////////////////////////////////////////////////
136 // IHTMLElement implementation
138 HRESULT STDMETHODCALLTYPE CIEHtmlElement::setAttribute(BSTR strAttributeName, VARIANT AttributeValue, LONG lFlags)
140 if (strAttributeName == NULL)
142 return E_INVALIDARG;
145 nsCOMPtr<nsIDOMElement> element = do_QueryInterface(mDOMNode);
146 if (!element)
148 return E_UNEXPECTED;
151 // Get the name from the BSTR
152 USES_CONVERSION;
153 nsAutoString name(OLE2W(strAttributeName));
155 // Get the value from the variant
156 CComVariant vValue;
157 if (FAILED(vValue.ChangeType(VT_BSTR, &AttributeValue)))
159 return E_INVALIDARG;
162 // Set the attribute
163 nsAutoString value(OLE2W(vValue.bstrVal));
164 element->SetAttribute(name, value);
166 return S_OK;
169 HRESULT STDMETHODCALLTYPE CIEHtmlElement::getAttribute(BSTR strAttributeName, LONG lFlags, VARIANT __RPC_FAR *AttributeValue)
171 if (strAttributeName == NULL)
173 return E_INVALIDARG;
175 if (AttributeValue == NULL)
177 return E_INVALIDARG;
179 VariantInit(AttributeValue);
181 // Get the name from the BSTR
182 USES_CONVERSION;
183 nsAutoString name(OLE2W(strAttributeName));
185 nsCOMPtr<nsIDOMElement> element = do_QueryInterface(mDOMNode);
186 if (!element)
188 return E_UNEXPECTED;
191 BOOL bCaseSensitive = (lFlags == VARIANT_TRUE) ? TRUE : FALSE;
194 // Get the attribute
195 nsAutoString value;
196 nsresult rv = element->GetAttribute(name, value);
197 if (NS_SUCCEEDED(rv))
199 USES_CONVERSION;
200 AttributeValue->vt = VT_BSTR;
201 AttributeValue->bstrVal = SysAllocString(W2COLE(value.get()));
202 return S_OK;
204 else
206 return S_FALSE;
209 return S_OK;
212 HRESULT STDMETHODCALLTYPE CIEHtmlElement::removeAttribute(BSTR strAttributeName, LONG lFlags, VARIANT_BOOL __RPC_FAR *pfSuccess)
214 if (strAttributeName == NULL)
216 return E_INVALIDARG;
219 nsCOMPtr<nsIDOMElement> element = do_QueryInterface(mDOMNode);
220 if (!element)
222 return E_UNEXPECTED;
225 BOOL bCaseSensitive = (lFlags == VARIANT_TRUE) ? TRUE : FALSE;
227 // Get the name from the BSTR
228 USES_CONVERSION;
229 nsAutoString name(OLE2W(strAttributeName));
231 // Remove the attribute
232 nsresult nr = element->RemoveAttribute(name);
233 BOOL bRemoved = (nr == NS_OK) ? TRUE : FALSE;
235 if (pfSuccess)
237 *pfSuccess = (bRemoved) ? VARIANT_TRUE : VARIANT_FALSE;
240 return S_OK;
243 HRESULT STDMETHODCALLTYPE CIEHtmlElement::put_className(BSTR v)
245 return E_NOTIMPL;
248 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_className(BSTR __RPC_FAR *p)
250 if (p == NULL)
252 return E_INVALIDARG;
255 VARIANT vValue;
256 VariantInit(&vValue);
257 BSTR bstrName = SysAllocString(OLESTR("class"));
258 getAttribute(bstrName, FALSE, &vValue);
259 SysFreeString(bstrName);
261 *p = vValue.bstrVal;
262 return S_OK;
265 HRESULT STDMETHODCALLTYPE CIEHtmlElement::put_id(BSTR v)
267 nsCOMPtr<nsIDOMHTMLElement> domHtmlElmt = do_QueryInterface(mDOMNode);
268 if (!domHtmlElmt)
269 return E_UNEXPECTED;
270 USES_CONVERSION;
271 nsDependentString strID(OLE2CW(v));
272 if (FAILED(domHtmlElmt->SetId(strID)))
273 return E_FAIL;
274 return S_OK;
277 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_id(BSTR __RPC_FAR *p)
279 if (p == NULL)
281 return E_INVALIDARG;
284 VARIANT vValue;
285 VariantInit(&vValue);
286 BSTR bstrName = SysAllocString(OLESTR("id"));
287 getAttribute(bstrName, FALSE, &vValue);
288 SysFreeString(bstrName);
290 *p = vValue.bstrVal;
291 return S_OK;
294 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_tagName(BSTR __RPC_FAR *p)
296 if (p == NULL)
298 return E_INVALIDARG;
301 nsCOMPtr<nsIDOMElement> element = do_QueryInterface(mDOMNode);
302 if (!element)
304 return E_UNEXPECTED;
307 nsAutoString tagName;
308 element->GetTagName(tagName);
310 USES_CONVERSION;
311 *p = SysAllocString(W2COLE(tagName.get()));
312 return S_OK;
315 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_parentElement(IHTMLElement __RPC_FAR *__RPC_FAR *p)
317 if (p == NULL)
319 return E_INVALIDARG;
322 *p = NULL;
323 if (mParent)
325 CIEHtmlElement *pElt = static_cast<CIEHtmlElement *>(mParent);
326 pElt->QueryInterface(IID_IHTMLElement, (void **) p);
328 else
330 nsCOMPtr<nsIDOMNode> parentNode;
331 mDOMNode->GetParentNode(getter_AddRefs(parentNode));
332 nsCOMPtr<nsIDOMElement> domElement = do_QueryInterface(parentNode);
333 if (domElement)
335 CComPtr<IUnknown> pNode;
336 HRESULT hr = CIEHtmlDomNode::FindOrCreateFromDOMNode(parentNode, &pNode);
337 if (FAILED(hr))
338 return hr;
339 if (FAILED(pNode->QueryInterface(IID_IHTMLElement, (void **) p)))
340 return E_UNEXPECTED;
344 return S_OK;
347 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_style(IHTMLStyle __RPC_FAR *__RPC_FAR *p)
349 return E_NOTIMPL;
352 HRESULT STDMETHODCALLTYPE CIEHtmlElement::put_onhelp(VARIANT v)
354 return E_NOTIMPL;
357 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_onhelp(VARIANT __RPC_FAR *p)
359 return E_NOTIMPL;
362 HRESULT STDMETHODCALLTYPE CIEHtmlElement::put_onclick(VARIANT v)
364 return E_NOTIMPL;
367 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_onclick(VARIANT __RPC_FAR *p)
369 return E_NOTIMPL;
372 HRESULT STDMETHODCALLTYPE CIEHtmlElement::put_ondblclick(VARIANT v)
374 return E_NOTIMPL;
377 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_ondblclick(VARIANT __RPC_FAR *p)
379 return E_NOTIMPL;
382 HRESULT STDMETHODCALLTYPE CIEHtmlElement::put_onkeydown(VARIANT v)
384 return E_NOTIMPL;
387 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_onkeydown(VARIANT __RPC_FAR *p)
389 return E_NOTIMPL;
392 HRESULT STDMETHODCALLTYPE CIEHtmlElement::put_onkeyup(VARIANT v)
394 return E_NOTIMPL;
397 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_onkeyup(VARIANT __RPC_FAR *p)
399 return E_NOTIMPL;
402 HRESULT STDMETHODCALLTYPE CIEHtmlElement::put_onkeypress(VARIANT v)
404 return E_NOTIMPL;
407 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_onkeypress(VARIANT __RPC_FAR *p)
409 return E_NOTIMPL;
412 HRESULT STDMETHODCALLTYPE CIEHtmlElement::put_onmouseout(VARIANT v)
414 return E_NOTIMPL;
417 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_onmouseout(VARIANT __RPC_FAR *p)
419 return E_NOTIMPL;
422 HRESULT STDMETHODCALLTYPE CIEHtmlElement::put_onmouseover(VARIANT v)
424 return E_NOTIMPL;
427 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_onmouseover(VARIANT __RPC_FAR *p)
429 return E_NOTIMPL;
432 HRESULT STDMETHODCALLTYPE CIEHtmlElement::put_onmousemove(VARIANT v)
434 return E_NOTIMPL;
437 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_onmousemove(VARIANT __RPC_FAR *p)
439 return E_NOTIMPL;
442 HRESULT STDMETHODCALLTYPE CIEHtmlElement::put_onmousedown(VARIANT v)
444 return E_NOTIMPL;
447 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_onmousedown(VARIANT __RPC_FAR *p)
449 return E_NOTIMPL;
452 HRESULT STDMETHODCALLTYPE CIEHtmlElement::put_onmouseup(VARIANT v)
454 return E_NOTIMPL;
457 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_onmouseup(VARIANT __RPC_FAR *p)
459 return E_NOTIMPL;
462 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_document(IDispatch __RPC_FAR *__RPC_FAR *p)
464 return E_NOTIMPL;
467 HRESULT STDMETHODCALLTYPE CIEHtmlElement::put_title(BSTR v)
469 return E_NOTIMPL;
472 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_title(BSTR __RPC_FAR *p)
474 return E_NOTIMPL;
477 HRESULT STDMETHODCALLTYPE CIEHtmlElement::put_language(BSTR v)
479 return E_NOTIMPL;
482 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_language(BSTR __RPC_FAR *p)
484 return E_NOTIMPL;
487 HRESULT STDMETHODCALLTYPE CIEHtmlElement::put_onselectstart(VARIANT v)
489 return E_NOTIMPL;
492 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_onselectstart(VARIANT __RPC_FAR *p)
494 return E_NOTIMPL;
497 HRESULT STDMETHODCALLTYPE CIEHtmlElement::scrollIntoView(VARIANT varargStart)
499 return E_NOTIMPL;
502 HRESULT STDMETHODCALLTYPE CIEHtmlElement::contains(IHTMLElement __RPC_FAR *pChild, VARIANT_BOOL __RPC_FAR *pfResult)
504 return E_NOTIMPL;
507 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_sourceIndex(long __RPC_FAR *p)
509 return E_NOTIMPL;
512 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_recordNumber(VARIANT __RPC_FAR *p)
514 return E_NOTIMPL;
517 HRESULT STDMETHODCALLTYPE CIEHtmlElement::put_lang(BSTR v)
519 return E_NOTIMPL;
522 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_lang(BSTR __RPC_FAR *p)
524 return E_NOTIMPL;
527 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_offsetLeft(long __RPC_FAR *p)
529 nsCOMPtr<nsIDOMNSHTMLElement> nodeAsHTMLElement = do_QueryInterface(mDOMNode);
530 if (!nodeAsHTMLElement)
532 return E_NOINTERFACE;
535 PRInt32 nData;
536 nodeAsHTMLElement->GetOffsetLeft(&nData);
537 *p = nData;
538 return S_OK;
541 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_offsetTop(long __RPC_FAR *p)
543 nsCOMPtr<nsIDOMNSHTMLElement> nodeAsHTMLElement = do_QueryInterface(mDOMNode);
544 if (!nodeAsHTMLElement)
546 return E_NOINTERFACE;
549 PRInt32 nData;
550 nodeAsHTMLElement->GetOffsetTop(&nData);
551 *p = nData;
552 return S_OK;
555 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_offsetWidth(long __RPC_FAR *p)
557 nsCOMPtr<nsIDOMNSHTMLElement> nodeAsHTMLElement = do_QueryInterface(mDOMNode);
558 if (!nodeAsHTMLElement)
560 return E_NOINTERFACE;
563 PRInt32 nData;
564 nodeAsHTMLElement->GetOffsetWidth(&nData);
565 *p = nData;
566 return S_OK;
569 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_offsetHeight(long __RPC_FAR *p)
571 nsCOMPtr<nsIDOMNSHTMLElement> nodeAsHTMLElement = do_QueryInterface(mDOMNode);
572 if (!nodeAsHTMLElement)
574 return E_NOINTERFACE;
577 PRInt32 nData;
578 nodeAsHTMLElement->GetOffsetHeight(&nData);
579 *p = nData;
580 return S_OK;
583 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_offsetParent(IHTMLElement __RPC_FAR *__RPC_FAR *p)
585 return E_NOTIMPL;
588 HRESULT STDMETHODCALLTYPE CIEHtmlElement::put_innerHTML(BSTR v)
590 nsCOMPtr<nsIDOMNSHTMLElement> elementHTML = do_QueryInterface(mDOMNode);
591 if (!elementHTML)
593 return E_UNEXPECTED;
596 USES_CONVERSION;
597 nsAutoString innerHTML(OLE2W(v));
598 elementHTML->SetInnerHTML(innerHTML);
599 return S_OK;
602 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_innerHTML(BSTR __RPC_FAR *p)
604 nsCOMPtr<nsIDOMNSHTMLElement> elementHTML = do_QueryInterface(mDOMNode);
605 if (!elementHTML)
607 return E_UNEXPECTED;
610 nsAutoString innerHTML;
611 elementHTML->GetInnerHTML(innerHTML);
613 USES_CONVERSION;
614 *p = SysAllocString(W2COLE(innerHTML.get()));
615 return S_OK;
618 HRESULT STDMETHODCALLTYPE CIEHtmlElement::put_innerText(BSTR v)
620 nsCOMPtr<nsIDOM3Node> node = do_QueryInterface(mDOMNode);
621 if (!node)
623 return E_UNEXPECTED;
626 USES_CONVERSION;
627 nsAutoString innerText(OLE2W(v));
628 node->SetTextContent(innerText);
630 return S_OK;
633 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_innerText(BSTR __RPC_FAR *p)
635 nsCOMPtr<nsIDOM3Node> node = do_QueryInterface(mDOMNode);
636 if (!node)
638 return E_UNEXPECTED;
641 nsAutoString innerText;
642 node->GetTextContent(innerText);
644 USES_CONVERSION;
645 *p = SysAllocString(W2COLE(innerText.get()));
646 return S_OK;
649 HRESULT STDMETHODCALLTYPE CIEHtmlElement::put_outerHTML(BSTR v)
651 nsresult rv;
652 nsCOMPtr<nsIDOMDocument> domDoc;
653 nsCOMPtr<nsIDOMRange> domRange;
654 nsCOMPtr<nsIDOMDocumentFragment> domDocFragment;
656 mDOMNode->GetOwnerDocument(getter_AddRefs(domDoc));
657 nsCOMPtr<nsIDOMDocumentRange> domDocRange = do_QueryInterface(domDoc);
658 if (!domDocRange)
659 return E_FAIL;
660 domDocRange->CreateRange(getter_AddRefs(domRange));
661 if (!domRange)
662 return E_FAIL;
663 if (domRange->SetStartBefore(mDOMNode))
664 return E_FAIL;
665 if (domRange->DeleteContents())
666 return E_FAIL;
667 nsAutoString outerHTML(OLE2W(v));
668 nsCOMPtr<nsIDOMNSRange> domNSRange = do_QueryInterface(domRange);
669 rv = domNSRange->CreateContextualFragment(outerHTML, getter_AddRefs(domDocFragment));
670 if (!domDocFragment)
671 return E_FAIL;
672 nsCOMPtr<nsIDOMNode> parentNode;
673 mDOMNode->GetParentNode(getter_AddRefs(parentNode));
674 nsCOMPtr<nsIDOMNode> domNode;
675 parentNode->ReplaceChild(domDocFragment, mDOMNode, getter_AddRefs(domNode));
677 return S_OK;
680 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_outerHTML(BSTR __RPC_FAR *p)
682 if (p == NULL)
684 return E_INVALIDARG;
687 *p = NULL;
689 nsresult rv;
690 nsAutoString outerHTML;
691 nsCOMPtr<nsIDOMDocument> domDoc;
692 nsCOMPtr<nsIDocumentEncoder> docEncoder;
693 nsCOMPtr<nsIDOMRange> domRange;
695 mDOMNode->GetOwnerDocument(getter_AddRefs(domDoc));
696 if (!domDoc)
697 return E_FAIL;
699 docEncoder = do_CreateInstance(NS_DOC_ENCODER_CONTRACTID_BASE "text/html");
700 NS_ENSURE_TRUE(docEncoder, NS_ERROR_FAILURE);
701 docEncoder->Init(domDoc, NS_LITERAL_STRING("text/html"),
702 nsIDocumentEncoder::OutputEncodeBasicEntities);
703 nsCOMPtr<nsIDOMDocumentRange> domDocRange = do_QueryInterface(domDoc);
704 if (!domDocRange)
705 return E_FAIL;
706 domDocRange->CreateRange(getter_AddRefs(domRange));
707 if (!domRange)
708 return E_FAIL;
709 rv = domRange->SelectNode(mDOMNode);
710 NS_ENSURE_SUCCESS(rv, rv);
711 docEncoder->SetRange(domRange);
712 docEncoder->EncodeToString(outerHTML);
714 USES_CONVERSION;
715 *p = SysAllocString(W2COLE(outerHTML.get()));
717 return S_OK;
720 HRESULT STDMETHODCALLTYPE CIEHtmlElement::put_outerText(BSTR v)
722 return E_NOTIMPL;
725 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_outerText(BSTR __RPC_FAR *p)
727 return E_NOTIMPL;
730 HRESULT STDMETHODCALLTYPE CIEHtmlElement::insertAdjacentHTML(BSTR where, BSTR html)
732 nsresult rv;
733 nsCOMPtr<nsIDOMDocument> domDoc;
734 nsCOMPtr<nsIDOMRange> domRange;
735 nsCOMPtr<nsIDOMDocumentFragment> domDocFragment;
737 NS_ASSERTION(mDOMNode, "");
738 //Create a range:
739 mDOMNode->GetOwnerDocument(getter_AddRefs(domDoc));
740 nsCOMPtr<nsIDOMDocumentRange> domDocRange = do_QueryInterface(domDoc);
741 if (!domDocRange)
742 return E_FAIL;
743 domDocRange->CreateRange(getter_AddRefs(domRange));
744 if (!domRange)
745 return E_FAIL;
746 // Must position range first before calling CreateContextualFragment:
747 if (domRange->SetStartBefore(mDOMNode))
748 return E_FAIL;
749 USES_CONVERSION;
750 // Create doc fragment:
751 nsDependentString strAdjacentHTML(OLE2CW(html));
752 nsCOMPtr<nsIDOMNSRange> domNSRange = do_QueryInterface(domRange);
753 domNSRange->CreateContextualFragment(strAdjacentHTML, getter_AddRefs(domDocFragment));
754 if (!domDocFragment)
755 return E_FAIL;
756 if (_wcsicmp(OLE2CW(where), L"beforeBegin") == 0)
758 // Insert fragment immediately before us:
759 nsCOMPtr<nsIDOMNode> parentNode;
760 mDOMNode->GetParentNode(getter_AddRefs(parentNode));
761 nsCOMPtr<nsIDOMNode> dummyNode;
762 rv = parentNode->InsertBefore(domDocFragment, mDOMNode, getter_AddRefs(dummyNode));
763 return SUCCEEDED(rv)? S_OK: E_FAIL;
765 if (_wcsicmp(OLE2CW(where), L"afterEnd") == 0)
767 // Insert fragment immediately after us:
768 nsCOMPtr<nsIDOMNode> parentNode;
769 mDOMNode->GetParentNode(getter_AddRefs(parentNode));
770 nsCOMPtr<nsIDOMNode> dummyNode;
771 nsCOMPtr<nsIDOMNode> nextNode;
772 mDOMNode->GetNextSibling(getter_AddRefs(nextNode));
773 if (nextNode)
775 // Insert immediately before next node:
776 rv = parentNode->InsertBefore(domDocFragment, nextNode, getter_AddRefs(dummyNode));
778 else
780 // We are the last child, insert after us:
781 rv = parentNode->AppendChild(domDocFragment, getter_AddRefs(dummyNode));
783 return SUCCEEDED(rv)? S_OK: E_FAIL;
785 if (_wcsicmp(OLE2CW(where), L"afterBegin") == 0)
787 // Insert fragment immediately before first child:
788 nsCOMPtr<nsIDOMNode> firstChildNode;
789 mDOMNode->GetFirstChild(getter_AddRefs(firstChildNode));
790 if (!firstChildNode)
791 return E_FAIL; // IE fails when inserting into a tag that has no childs
792 nsCOMPtr<nsIDOMNode> dummyNode;
793 rv = mDOMNode->InsertBefore(domDocFragment, firstChildNode, getter_AddRefs(dummyNode));
794 return SUCCEEDED(rv)? S_OK: E_FAIL;
796 if (_wcsicmp(OLE2CW(where), L"beforeEnd") == 0)
798 // Insert fragment immediately as last child:
799 nsCOMPtr<nsIDOMNode> dummyNode;
800 rv = mDOMNode->AppendChild(domDocFragment, getter_AddRefs(dummyNode));
801 return SUCCEEDED(rv)? S_OK: E_FAIL;
803 return E_INVALIDARG;
806 HRESULT STDMETHODCALLTYPE CIEHtmlElement::insertAdjacentText(BSTR where, BSTR text)
808 return E_NOTIMPL;
811 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_parentTextEdit(IHTMLElement __RPC_FAR *__RPC_FAR *p)
813 return E_NOTIMPL;
816 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_isTextEdit(VARIANT_BOOL __RPC_FAR *p)
818 return E_NOTIMPL;
821 HRESULT STDMETHODCALLTYPE CIEHtmlElement::click(void)
823 return E_NOTIMPL;
826 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_filters(IHTMLFiltersCollection __RPC_FAR *__RPC_FAR *p)
828 return E_NOTIMPL;
831 HRESULT STDMETHODCALLTYPE CIEHtmlElement::put_ondragstart(VARIANT v)
833 return E_NOTIMPL;
836 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_ondragstart(VARIANT __RPC_FAR *p)
838 return E_NOTIMPL;
841 HRESULT STDMETHODCALLTYPE CIEHtmlElement::toString(BSTR __RPC_FAR *String)
843 return E_NOTIMPL;
846 HRESULT STDMETHODCALLTYPE CIEHtmlElement::put_onbeforeupdate(VARIANT v)
848 return E_NOTIMPL;
851 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_onbeforeupdate(VARIANT __RPC_FAR *p)
853 return E_NOTIMPL;
856 HRESULT STDMETHODCALLTYPE CIEHtmlElement::put_onafterupdate(VARIANT v)
858 return E_NOTIMPL;
861 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_onafterupdate(VARIANT __RPC_FAR *p)
863 return E_NOTIMPL;
866 HRESULT STDMETHODCALLTYPE CIEHtmlElement::put_onerrorupdate(VARIANT v)
868 return E_NOTIMPL;
871 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_onerrorupdate(VARIANT __RPC_FAR *p)
873 return E_NOTIMPL;
876 HRESULT STDMETHODCALLTYPE CIEHtmlElement::put_onrowexit(VARIANT v)
878 return E_NOTIMPL;
881 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_onrowexit(VARIANT __RPC_FAR *p)
883 return E_NOTIMPL;
886 HRESULT STDMETHODCALLTYPE CIEHtmlElement::put_onrowenter(VARIANT v)
888 return E_NOTIMPL;
891 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_onrowenter(VARIANT __RPC_FAR *p)
893 return E_NOTIMPL;
896 HRESULT STDMETHODCALLTYPE CIEHtmlElement::put_ondatasetchanged(VARIANT v)
898 return E_NOTIMPL;
901 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_ondatasetchanged(VARIANT __RPC_FAR *p)
903 return E_NOTIMPL;
906 HRESULT STDMETHODCALLTYPE CIEHtmlElement::put_ondataavailable(VARIANT v)
908 return E_NOTIMPL;
911 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_ondataavailable(VARIANT __RPC_FAR *p)
913 return E_NOTIMPL;
916 HRESULT STDMETHODCALLTYPE CIEHtmlElement::put_ondatasetcomplete(VARIANT v)
918 return E_NOTIMPL;
921 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_ondatasetcomplete(VARIANT __RPC_FAR *p)
923 return E_NOTIMPL;
926 HRESULT STDMETHODCALLTYPE CIEHtmlElement::put_onfilterchange(VARIANT v)
928 return E_NOTIMPL;
931 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_onfilterchange(VARIANT __RPC_FAR *p)
933 return E_NOTIMPL;
936 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_children(IDispatch __RPC_FAR *__RPC_FAR *p)
938 // Validate parameters
939 if (p == NULL)
941 return E_INVALIDARG;
944 *p = NULL;
946 // Create a collection representing the children of this node
947 CIEHtmlElementCollectionInstance *pCollection = NULL;
948 HRESULT hr = GetChildren(&pCollection);
949 if (SUCCEEDED(hr))
951 *p = pCollection;
954 return hr;
957 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_all(IDispatch __RPC_FAR *__RPC_FAR *p)
959 // Validate parameters
960 if (p == NULL)
962 return E_INVALIDARG;
965 *p = NULL;
967 // TODO get ALL contained elements, not just the immediate children
969 CIEHtmlElementCollectionInstance *pCollection = NULL;
970 CIEHtmlElementCollection::CreateFromParentNode(this, TRUE, (CIEHtmlElementCollection **) &pCollection);
971 if (pCollection)
973 pCollection->AddRef();
974 *p = pCollection;
977 return S_OK;