Back to index

lightning-sunbird  0.9+nobinonly
IEHtmlElement.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Adam Lock <adamlock@netscape.com>
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either the GNU General Public License Version 2 or later (the "GPL"), or
00027  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 
00039 #include "stdafx.h"
00040 
00041 #include "nsCOMPtr.h"
00042 #include "nsIDOMElement.h"
00043 #include "nsString.h"
00044 
00045 #include "IEHtmlElement.h"
00046 #include "IEHtmlElementCollection.h"
00047 
00048 #include "nsIDOMHTMLElement.h"
00049 #include "nsIDOMNSHTMLElement.h"
00050 #include "nsIDOM3Node.h"
00051 #include "nsIDOMDocumentRange.h"
00052 #include "nsIDOMRange.h"
00053 #include "nsIDOMNSRange.h"
00054 #include "nsIDOMDocumentFragment.h"
00055 #include "nsIDocumentEncoder.h"
00056 
00057 CIEHtmlElement::CIEHtmlElement()
00058 {
00059     m_pNodeAgg = NULL;
00060 }
00061 
00062 HRESULT CIEHtmlElement::FinalConstruct( )
00063 {
00064     return CComCreator<CComAggObject<CIEHtmlDomNode> >::CreateInstance(GetControllingUnknown(),
00065         IID_IUnknown, reinterpret_cast<void**>(&m_pNodeAgg));
00066 }
00067 
00068 CIEHtmlElement::~CIEHtmlElement()
00069 {
00070 }
00071 
00072 void CIEHtmlElement::FinalRelease( )
00073 {
00074     m_pNodeAgg->Release();
00075 }
00076 
00077 HRESULT CIEHtmlElement::GetChildren(CIEHtmlElementCollectionInstance **ppCollection)
00078 {
00079     // Validate parameters
00080     if (ppCollection == NULL)
00081     {
00082         return E_INVALIDARG;
00083     }
00084 
00085     *ppCollection = NULL;
00086 
00087     // Create a collection representing the children of this node
00088     CIEHtmlElementCollectionInstance *pCollection = NULL;
00089     CIEHtmlElementCollection::CreateFromParentNode(this, FALSE, (CIEHtmlElementCollection **) &pCollection);
00090     if (pCollection)
00091     {
00092         pCollection->AddRef();
00093         *ppCollection = pCollection;
00094     }
00095 
00096     return S_OK;
00097 }
00098 
00099 HRESULT CIEHtmlElement::GetHtmlDomNode(CIEHtmlDomNode **ppHtmlDomNode)
00100 {
00101     if (ppHtmlDomNode == NULL)
00102         return E_FAIL;
00103     *ppHtmlDomNode = NULL;
00104     IHTMLDOMNode* pHtmlNode = NULL;
00105     // This causes an AddRef on outer unknown:
00106     HRESULT hr = m_pNodeAgg->QueryInterface(__uuidof(IHTMLDOMNode), (void**)&pHtmlNode);
00107     *ppHtmlDomNode = (CIEHtmlDomNode*)pHtmlNode;
00108     return hr;
00109 }
00110 
00111 HRESULT CIEHtmlElement::SetDOMNode(nsIDOMNode *pDomNode)
00112 {
00113     mDOMNode = pDomNode;
00114     // Forward to aggregated object:
00115     CIEHtmlDomNode *pHtmlDomNode;
00116     GetHtmlDomNode(&pHtmlDomNode);
00117     HRESULT hr = pHtmlDomNode->SetDOMNode(pDomNode);
00118     // Release on outer unknown because GetHtmlDomNode does AddRef on it:
00119     GetControllingUnknown()->Release();
00120     return hr;
00121 }
00122 
00123 HRESULT CIEHtmlElement::SetParent(CNode *pParent)
00124 {
00125     CNode::SetParent(pParent);
00126     // Forward to aggregated object:
00127     CIEHtmlDomNode *pHtmlDomNode;
00128     GetHtmlDomNode(&pHtmlDomNode);
00129     HRESULT hr = pHtmlDomNode->SetParent(pParent);
00130     // Release on outer unknown because GetHtmlDomNode does AddRef on it:
00131     GetControllingUnknown()->Release();
00132     return hr;
00133 }
00134 
00136 // IHTMLElement implementation
00137 
00138 HRESULT STDMETHODCALLTYPE CIEHtmlElement::setAttribute(BSTR strAttributeName, VARIANT AttributeValue, LONG lFlags)
00139 {
00140     if (strAttributeName == NULL)
00141     {
00142         return E_INVALIDARG;
00143     }
00144 
00145     nsCOMPtr<nsIDOMElement> element = do_QueryInterface(mDOMNode);
00146     if (!element)
00147     {
00148         return E_UNEXPECTED;
00149     }
00150 
00151     // Get the name from the BSTR
00152     USES_CONVERSION;
00153     nsAutoString name(OLE2W(strAttributeName));
00154 
00155     // Get the value from the variant
00156     CComVariant vValue;
00157     if (FAILED(vValue.ChangeType(VT_BSTR, &AttributeValue)))
00158     {
00159         return E_INVALIDARG;
00160     }
00161 
00162     // Set the attribute
00163     nsAutoString value(OLE2W(vValue.bstrVal));
00164     element->SetAttribute(name, value);
00165 
00166     return S_OK;
00167 }
00168 
00169 HRESULT STDMETHODCALLTYPE CIEHtmlElement::getAttribute(BSTR strAttributeName, LONG lFlags, VARIANT __RPC_FAR *AttributeValue)
00170 {
00171     if (strAttributeName == NULL)
00172     {
00173         return E_INVALIDARG;
00174     }
00175     if (AttributeValue == NULL)
00176     {
00177         return E_INVALIDARG;
00178     }
00179     VariantInit(AttributeValue);
00180 
00181     // Get the name from the BSTR
00182     USES_CONVERSION;
00183     nsAutoString name(OLE2W(strAttributeName));
00184 
00185     nsCOMPtr<nsIDOMElement> element = do_QueryInterface(mDOMNode);
00186     if (!element)
00187     {
00188         return E_UNEXPECTED;
00189     }
00190 
00191     BOOL bCaseSensitive = (lFlags == VARIANT_TRUE) ? TRUE : FALSE;
00192 
00193 
00194     // Get the attribute
00195     nsAutoString value;
00196     nsresult rv = element->GetAttribute(name, value);
00197     if (NS_SUCCEEDED(rv))
00198     {
00199         USES_CONVERSION;
00200         AttributeValue->vt = VT_BSTR;
00201         AttributeValue->bstrVal = SysAllocString(W2COLE(value.get()));
00202         return S_OK;
00203     }
00204     else
00205     {
00206         return S_FALSE;
00207     }
00208 
00209     return S_OK;
00210 }
00211 
00212 HRESULT STDMETHODCALLTYPE CIEHtmlElement::removeAttribute(BSTR strAttributeName, LONG lFlags, VARIANT_BOOL __RPC_FAR *pfSuccess)
00213 {
00214     if (strAttributeName == NULL)
00215     {
00216         return E_INVALIDARG;
00217     }
00218 
00219     nsCOMPtr<nsIDOMElement> element = do_QueryInterface(mDOMNode);
00220     if (!element)
00221     {
00222         return E_UNEXPECTED;
00223     }
00224 
00225     BOOL bCaseSensitive = (lFlags == VARIANT_TRUE) ? TRUE : FALSE;
00226 
00227     // Get the name from the BSTR
00228     USES_CONVERSION;
00229     nsAutoString name(OLE2W(strAttributeName));
00230 
00231     // Remove the attribute
00232     nsresult nr = element->RemoveAttribute(name);
00233     BOOL bRemoved = (nr == NS_OK) ? TRUE : FALSE;
00234 
00235     if (pfSuccess)
00236     {
00237         *pfSuccess = (bRemoved) ? VARIANT_TRUE : VARIANT_FALSE;
00238     }
00239 
00240     return S_OK;
00241 }
00242 
00243 HRESULT STDMETHODCALLTYPE CIEHtmlElement::put_className(BSTR v)
00244 {
00245     return E_NOTIMPL;
00246 }
00247 
00248 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_className(BSTR __RPC_FAR *p)
00249 {
00250     if (p == NULL)
00251     {
00252         return E_INVALIDARG;
00253     }
00254 
00255     VARIANT vValue;
00256     VariantInit(&vValue);
00257     BSTR bstrName = SysAllocString(OLESTR("class"));
00258     getAttribute(bstrName, FALSE, &vValue);
00259     SysFreeString(bstrName);
00260 
00261     *p = vValue.bstrVal;
00262     return S_OK;
00263 }
00264 
00265 HRESULT STDMETHODCALLTYPE CIEHtmlElement::put_id(BSTR v)
00266 {
00267     nsCOMPtr<nsIDOMHTMLElement> domHtmlElmt = do_QueryInterface(mDOMNode);
00268     if (!domHtmlElmt)
00269         return E_UNEXPECTED;
00270     USES_CONVERSION;
00271     nsDependentString strID(OLE2CW(v));
00272     if (FAILED(domHtmlElmt->SetId(strID)))
00273         return E_FAIL;
00274     return S_OK;
00275 }
00276 
00277 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_id(BSTR __RPC_FAR *p)
00278 {
00279     if (p == NULL)
00280     {
00281         return E_INVALIDARG;
00282     }
00283 
00284     VARIANT vValue;
00285     VariantInit(&vValue);
00286     BSTR bstrName = SysAllocString(OLESTR("id"));
00287     getAttribute(bstrName, FALSE, &vValue);
00288     SysFreeString(bstrName);
00289 
00290     *p = vValue.bstrVal;
00291     return S_OK;
00292 }
00293 
00294 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_tagName(BSTR __RPC_FAR *p)
00295 {
00296     if (p == NULL)
00297     {
00298         return E_INVALIDARG;
00299     }
00300 
00301     nsCOMPtr<nsIDOMElement> element = do_QueryInterface(mDOMNode);
00302     if (!element)
00303     {
00304         return E_UNEXPECTED;
00305     }
00306 
00307     nsAutoString tagName;
00308     element->GetTagName(tagName);
00309 
00310     USES_CONVERSION;
00311     *p = SysAllocString(W2COLE(tagName.get()));
00312     return S_OK;
00313 }
00314 
00315 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_parentElement(IHTMLElement __RPC_FAR *__RPC_FAR *p)
00316 {
00317     if (p == NULL)
00318     {
00319         return E_INVALIDARG;
00320     }
00321 
00322     *p = NULL;
00323     if (mParent)
00324     {
00325         CIEHtmlElement *pElt = static_cast<CIEHtmlElement *>(mParent);
00326         pElt->QueryInterface(IID_IHTMLElement, (void **) p);
00327     }
00328     else
00329     {
00330         nsCOMPtr<nsIDOMNode> parentNode;
00331         mDOMNode->GetParentNode(getter_AddRefs(parentNode));
00332         nsCOMPtr<nsIDOMElement> domElement = do_QueryInterface(parentNode);
00333         if (domElement)
00334         {
00335             CComPtr<IUnknown> pNode;
00336             HRESULT hr = CIEHtmlDomNode::FindOrCreateFromDOMNode(parentNode, &pNode);
00337             if (FAILED(hr))
00338                 return hr;
00339             if (FAILED(pNode->QueryInterface(IID_IHTMLElement, (void **) p)))
00340                 return E_UNEXPECTED;
00341         }
00342     }
00343         
00344     return S_OK;
00345 }
00346 
00347 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_style(IHTMLStyle __RPC_FAR *__RPC_FAR *p)
00348 {
00349     return E_NOTIMPL;
00350 }
00351 
00352 HRESULT STDMETHODCALLTYPE CIEHtmlElement::put_onhelp(VARIANT v)
00353 {
00354     return E_NOTIMPL;
00355 }
00356 
00357 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_onhelp(VARIANT __RPC_FAR *p)
00358 {
00359     return E_NOTIMPL;
00360 }
00361 
00362 HRESULT STDMETHODCALLTYPE CIEHtmlElement::put_onclick(VARIANT v)
00363 {
00364     return E_NOTIMPL;
00365 }
00366 
00367 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_onclick(VARIANT __RPC_FAR *p)
00368 {
00369     return E_NOTIMPL;
00370 }
00371 
00372 HRESULT STDMETHODCALLTYPE CIEHtmlElement::put_ondblclick(VARIANT v)
00373 {
00374     return E_NOTIMPL;
00375 }
00376 
00377 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_ondblclick(VARIANT __RPC_FAR *p)
00378 {
00379     return E_NOTIMPL;
00380 }
00381 
00382 HRESULT STDMETHODCALLTYPE CIEHtmlElement::put_onkeydown(VARIANT v)
00383 {
00384     return E_NOTIMPL;
00385 }
00386 
00387 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_onkeydown(VARIANT __RPC_FAR *p)
00388 {
00389     return E_NOTIMPL;
00390 }
00391 
00392 HRESULT STDMETHODCALLTYPE CIEHtmlElement::put_onkeyup(VARIANT v)
00393 {
00394     return E_NOTIMPL;
00395 }
00396 
00397 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_onkeyup(VARIANT __RPC_FAR *p)
00398 {
00399     return E_NOTIMPL;
00400 }
00401 
00402 HRESULT STDMETHODCALLTYPE CIEHtmlElement::put_onkeypress(VARIANT v)
00403 {
00404     return E_NOTIMPL;
00405 }
00406 
00407 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_onkeypress(VARIANT __RPC_FAR *p)
00408 {
00409     return E_NOTIMPL;
00410 }
00411 
00412 HRESULT STDMETHODCALLTYPE CIEHtmlElement::put_onmouseout(VARIANT v)
00413 {
00414     return E_NOTIMPL;
00415 }
00416 
00417 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_onmouseout(VARIANT __RPC_FAR *p)
00418 {
00419     return E_NOTIMPL;
00420 }
00421 
00422 HRESULT STDMETHODCALLTYPE CIEHtmlElement::put_onmouseover(VARIANT v)
00423 {
00424     return E_NOTIMPL;
00425 }
00426 
00427 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_onmouseover(VARIANT __RPC_FAR *p)
00428 {
00429     return E_NOTIMPL;
00430 }
00431 
00432 HRESULT STDMETHODCALLTYPE CIEHtmlElement::put_onmousemove(VARIANT v)
00433 {
00434     return E_NOTIMPL;
00435 }
00436 
00437 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_onmousemove(VARIANT __RPC_FAR *p)
00438 {
00439     return E_NOTIMPL;
00440 }
00441 
00442 HRESULT STDMETHODCALLTYPE CIEHtmlElement::put_onmousedown(VARIANT v)
00443 {
00444     return E_NOTIMPL;
00445 }
00446 
00447 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_onmousedown(VARIANT __RPC_FAR *p)
00448 {
00449     return E_NOTIMPL;
00450 }
00451 
00452 HRESULT STDMETHODCALLTYPE CIEHtmlElement::put_onmouseup(VARIANT v)
00453 {
00454     return E_NOTIMPL;
00455 }
00456 
00457 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_onmouseup(VARIANT __RPC_FAR *p)
00458 {
00459     return E_NOTIMPL;
00460 }
00461 
00462 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_document(IDispatch __RPC_FAR *__RPC_FAR *p)
00463 {
00464     return E_NOTIMPL;
00465 }
00466 
00467 HRESULT STDMETHODCALLTYPE CIEHtmlElement::put_title(BSTR v)
00468 {
00469     return E_NOTIMPL;
00470 }
00471 
00472 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_title(BSTR __RPC_FAR *p)
00473 {
00474     return E_NOTIMPL;
00475 }
00476 
00477 HRESULT STDMETHODCALLTYPE CIEHtmlElement::put_language(BSTR v)
00478 {
00479     return E_NOTIMPL;
00480 }
00481 
00482 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_language(BSTR __RPC_FAR *p)
00483 {
00484     return E_NOTIMPL;
00485 }
00486 
00487 HRESULT STDMETHODCALLTYPE CIEHtmlElement::put_onselectstart(VARIANT v)
00488 {
00489     return E_NOTIMPL;
00490 }
00491 
00492 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_onselectstart(VARIANT __RPC_FAR *p)
00493 {
00494     return E_NOTIMPL;
00495 }
00496 
00497 HRESULT STDMETHODCALLTYPE CIEHtmlElement::scrollIntoView(VARIANT varargStart)
00498 {
00499     return E_NOTIMPL;
00500 }
00501 
00502 HRESULT STDMETHODCALLTYPE CIEHtmlElement::contains(IHTMLElement __RPC_FAR *pChild, VARIANT_BOOL __RPC_FAR *pfResult)
00503 {
00504     return E_NOTIMPL;
00505 }
00506 
00507 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_sourceIndex(long __RPC_FAR *p)
00508 {
00509     return E_NOTIMPL;
00510 }
00511 
00512 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_recordNumber(VARIANT __RPC_FAR *p)
00513 {
00514     return E_NOTIMPL;
00515 }
00516 
00517 HRESULT STDMETHODCALLTYPE CIEHtmlElement::put_lang(BSTR v)
00518 {
00519     return E_NOTIMPL;
00520 }
00521 
00522 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_lang(BSTR __RPC_FAR *p)
00523 {
00524     return E_NOTIMPL;
00525 }
00526 
00527 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_offsetLeft(long __RPC_FAR *p)
00528 {
00529     nsCOMPtr<nsIDOMNSHTMLElement> nodeAsHTMLElement = do_QueryInterface(mDOMNode);
00530     if (!nodeAsHTMLElement)
00531     {
00532         return E_NOINTERFACE;
00533     }
00534 
00535     PRInt32 nData;
00536     nodeAsHTMLElement->GetOffsetLeft(&nData);
00537     *p = nData;
00538     return S_OK;
00539 }
00540 
00541 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_offsetTop(long __RPC_FAR *p)
00542 {
00543     nsCOMPtr<nsIDOMNSHTMLElement> nodeAsHTMLElement = do_QueryInterface(mDOMNode);
00544     if (!nodeAsHTMLElement)
00545     {
00546         return E_NOINTERFACE;
00547     }
00548 
00549     PRInt32 nData;
00550     nodeAsHTMLElement->GetOffsetTop(&nData);
00551     *p = nData;
00552     return S_OK;
00553 }
00554 
00555 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_offsetWidth(long __RPC_FAR *p)
00556 {
00557     nsCOMPtr<nsIDOMNSHTMLElement> nodeAsHTMLElement = do_QueryInterface(mDOMNode);
00558     if (!nodeAsHTMLElement)
00559     {
00560         return E_NOINTERFACE;
00561     }
00562 
00563     PRInt32 nData;
00564     nodeAsHTMLElement->GetOffsetWidth(&nData);
00565     *p = nData;
00566     return S_OK;
00567 }
00568 
00569 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_offsetHeight(long __RPC_FAR *p)
00570 {
00571     nsCOMPtr<nsIDOMNSHTMLElement> nodeAsHTMLElement = do_QueryInterface(mDOMNode);
00572     if (!nodeAsHTMLElement)
00573     {
00574         return E_NOINTERFACE;
00575     }
00576 
00577     PRInt32 nData;
00578     nodeAsHTMLElement->GetOffsetHeight(&nData);
00579     *p = nData;
00580     return S_OK;
00581 }
00582 
00583 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_offsetParent(IHTMLElement __RPC_FAR *__RPC_FAR *p)
00584 {
00585     return E_NOTIMPL;
00586 }
00587 
00588 HRESULT STDMETHODCALLTYPE CIEHtmlElement::put_innerHTML(BSTR v)
00589 {
00590     nsCOMPtr<nsIDOMNSHTMLElement> elementHTML = do_QueryInterface(mDOMNode);
00591     if (!elementHTML)
00592     {
00593         return E_UNEXPECTED;
00594     }
00595 
00596     USES_CONVERSION;
00597     nsAutoString innerHTML(OLE2W(v));
00598     elementHTML->SetInnerHTML(innerHTML);
00599     return S_OK;
00600 }
00601 
00602 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_innerHTML(BSTR __RPC_FAR *p)
00603 {
00604     nsCOMPtr<nsIDOMNSHTMLElement> elementHTML = do_QueryInterface(mDOMNode);
00605     if (!elementHTML)
00606     {
00607         return E_UNEXPECTED;
00608     }
00609 
00610     nsAutoString innerHTML;
00611     elementHTML->GetInnerHTML(innerHTML);
00612 
00613     USES_CONVERSION;
00614     *p = SysAllocString(W2COLE(innerHTML.get()));
00615     return S_OK;
00616 }
00617 
00618 HRESULT STDMETHODCALLTYPE CIEHtmlElement::put_innerText(BSTR v)
00619 {
00620     nsCOMPtr<nsIDOM3Node> node = do_QueryInterface(mDOMNode);
00621     if (!node)
00622     {
00623         return E_UNEXPECTED;
00624     }
00625 
00626     USES_CONVERSION;
00627     nsAutoString innerText(OLE2W(v));
00628     node->SetTextContent(innerText);
00629 
00630     return S_OK;
00631 }
00632 
00633 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_innerText(BSTR __RPC_FAR *p)
00634 {
00635     nsCOMPtr<nsIDOM3Node> node = do_QueryInterface(mDOMNode);
00636     if (!node)
00637     {
00638         return E_UNEXPECTED;
00639     }
00640 
00641     nsAutoString innerText;
00642     node->GetTextContent(innerText);
00643 
00644     USES_CONVERSION;
00645     *p = SysAllocString(W2COLE(innerText.get()));
00646     return S_OK;
00647 }
00648 
00649 HRESULT STDMETHODCALLTYPE CIEHtmlElement::put_outerHTML(BSTR v)
00650 {
00651     nsresult rv;
00652     nsCOMPtr<nsIDOMDocument> domDoc;
00653     nsCOMPtr<nsIDOMRange> domRange;
00654     nsCOMPtr<nsIDOMDocumentFragment> domDocFragment;
00655 
00656     mDOMNode->GetOwnerDocument(getter_AddRefs(domDoc));
00657     nsCOMPtr<nsIDOMDocumentRange> domDocRange = do_QueryInterface(domDoc);
00658     if (!domDocRange)
00659         return E_FAIL;
00660     domDocRange->CreateRange(getter_AddRefs(domRange));
00661     if (!domRange)
00662         return E_FAIL;
00663     if (domRange->SetStartBefore(mDOMNode))
00664         return E_FAIL;
00665     if (domRange->DeleteContents())
00666         return E_FAIL;
00667     nsAutoString outerHTML(OLE2W(v));
00668     nsCOMPtr<nsIDOMNSRange> domNSRange = do_QueryInterface(domRange);
00669     rv = domNSRange->CreateContextualFragment(outerHTML, getter_AddRefs(domDocFragment));
00670     if (!domDocFragment)
00671         return E_FAIL;
00672     nsCOMPtr<nsIDOMNode> parentNode;
00673     mDOMNode->GetParentNode(getter_AddRefs(parentNode));
00674     nsCOMPtr<nsIDOMNode> domNode;
00675     parentNode->ReplaceChild(domDocFragment, mDOMNode, getter_AddRefs(domNode));
00676 
00677     return S_OK;
00678 }
00679 
00680 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_outerHTML(BSTR __RPC_FAR *p)
00681 {
00682     if (p == NULL)
00683     {
00684         return E_INVALIDARG;
00685     }
00686 
00687     *p = NULL;
00688 
00689     nsresult rv;
00690     nsAutoString outerHTML;
00691     nsCOMPtr<nsIDOMDocument> domDoc;
00692     nsCOMPtr<nsIDocumentEncoder> docEncoder;
00693     nsCOMPtr<nsIDOMRange> domRange;
00694 
00695     mDOMNode->GetOwnerDocument(getter_AddRefs(domDoc));
00696     nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc);
00697     if (!doc)
00698         return E_FAIL;
00699     docEncoder = do_CreateInstance(NS_DOC_ENCODER_CONTRACTID_BASE "text/html");
00700     NS_ENSURE_TRUE(docEncoder, NS_ERROR_FAILURE);
00701     docEncoder->Init(doc, NS_LITERAL_STRING("text/html"),
00702         nsIDocumentEncoder::OutputEncodeBasicEntities);
00703     nsCOMPtr<nsIDOMDocumentRange> domDocRange = do_QueryInterface(domDoc);
00704     if (!domDocRange)
00705         return E_FAIL;
00706     domDocRange->CreateRange(getter_AddRefs(domRange));
00707     if (!domRange)
00708         return E_FAIL;
00709     rv = domRange->SelectNode(mDOMNode);
00710     NS_ENSURE_SUCCESS(rv, rv);
00711     docEncoder->SetRange(domRange);
00712     docEncoder->EncodeToString(outerHTML);
00713 
00714     USES_CONVERSION;
00715     *p = SysAllocString(W2COLE(outerHTML.get()));
00716 
00717     return S_OK;
00718 }
00719 
00720 HRESULT STDMETHODCALLTYPE CIEHtmlElement::put_outerText(BSTR v)
00721 {
00722     return E_NOTIMPL;
00723 }
00724 
00725 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_outerText(BSTR __RPC_FAR *p)
00726 {
00727     return E_NOTIMPL;
00728 }
00729 
00730 HRESULT STDMETHODCALLTYPE CIEHtmlElement::insertAdjacentHTML(BSTR where, BSTR html)
00731 {
00732     nsresult rv;
00733     nsCOMPtr<nsIDOMDocument> domDoc;
00734     nsCOMPtr<nsIDOMRange> domRange;
00735     nsCOMPtr<nsIDOMDocumentFragment> domDocFragment;
00736 
00737     NS_ASSERTION(mDOMNode, "");
00738     //Create a range:
00739     mDOMNode->GetOwnerDocument(getter_AddRefs(domDoc));
00740     nsCOMPtr<nsIDOMDocumentRange> domDocRange = do_QueryInterface(domDoc);
00741     if (!domDocRange)
00742         return E_FAIL;
00743     domDocRange->CreateRange(getter_AddRefs(domRange));
00744     if (!domRange)
00745         return E_FAIL;
00746     // Must position range first before calling CreateContextualFragment:
00747     if (domRange->SetStartBefore(mDOMNode))
00748         return E_FAIL;
00749     USES_CONVERSION;
00750     // Create doc fragment:
00751     nsDependentString strAdjacentHTML(OLE2CW(html));
00752     nsCOMPtr<nsIDOMNSRange> domNSRange = do_QueryInterface(domRange);
00753     domNSRange->CreateContextualFragment(strAdjacentHTML, getter_AddRefs(domDocFragment));
00754     if (!domDocFragment)
00755         return E_FAIL;
00756     if (_wcsicmp(OLE2CW(where), L"beforeBegin") == 0)
00757     {
00758         // Insert fragment immediately before us:
00759         nsCOMPtr<nsIDOMNode> parentNode;
00760         mDOMNode->GetParentNode(getter_AddRefs(parentNode));
00761         nsCOMPtr<nsIDOMNode> dummyNode;
00762         rv = parentNode->InsertBefore(domDocFragment, mDOMNode, getter_AddRefs(dummyNode));
00763         return SUCCEEDED(rv)? S_OK: E_FAIL;
00764     }
00765     if (_wcsicmp(OLE2CW(where), L"afterEnd") == 0)
00766     {
00767         // Insert fragment immediately after us:
00768         nsCOMPtr<nsIDOMNode> parentNode;
00769         mDOMNode->GetParentNode(getter_AddRefs(parentNode));
00770         nsCOMPtr<nsIDOMNode> dummyNode;
00771         nsCOMPtr<nsIDOMNode> nextNode;
00772         mDOMNode->GetNextSibling(getter_AddRefs(nextNode));
00773         if (nextNode)
00774         {
00775             // Insert immediately before next node:
00776             rv = parentNode->InsertBefore(domDocFragment, nextNode, getter_AddRefs(dummyNode));
00777         }
00778         else
00779         {
00780             // We are the last child, insert after us:
00781             rv = parentNode->AppendChild(domDocFragment, getter_AddRefs(dummyNode));
00782         }
00783         return SUCCEEDED(rv)? S_OK: E_FAIL;
00784     }
00785     if (_wcsicmp(OLE2CW(where), L"afterBegin") == 0)
00786     {
00787         // Insert fragment immediately before first child:
00788         nsCOMPtr<nsIDOMNode> firstChildNode;
00789         mDOMNode->GetFirstChild(getter_AddRefs(firstChildNode));
00790         if (!firstChildNode)
00791             return E_FAIL; // IE fails when inserting into a tag that has no childs
00792         nsCOMPtr<nsIDOMNode> dummyNode;
00793         rv = mDOMNode->InsertBefore(domDocFragment, firstChildNode, getter_AddRefs(dummyNode));
00794         return SUCCEEDED(rv)? S_OK: E_FAIL;
00795     }
00796     if (_wcsicmp(OLE2CW(where), L"beforeEnd") == 0)
00797     {
00798         // Insert fragment immediately as last child:
00799         nsCOMPtr<nsIDOMNode> dummyNode;
00800         rv = mDOMNode->AppendChild(domDocFragment, getter_AddRefs(dummyNode));
00801         return SUCCEEDED(rv)? S_OK: E_FAIL;
00802     }
00803     return E_INVALIDARG;
00804 }
00805 
00806 HRESULT STDMETHODCALLTYPE CIEHtmlElement::insertAdjacentText(BSTR where, BSTR text)
00807 {
00808     return E_NOTIMPL;
00809 }
00810 
00811 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_parentTextEdit(IHTMLElement __RPC_FAR *__RPC_FAR *p)
00812 {
00813     return E_NOTIMPL;
00814 }
00815 
00816 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_isTextEdit(VARIANT_BOOL __RPC_FAR *p)
00817 {
00818     return E_NOTIMPL;
00819 }
00820 
00821 HRESULT STDMETHODCALLTYPE CIEHtmlElement::click(void)
00822 {
00823     return E_NOTIMPL;
00824 }
00825 
00826 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_filters(IHTMLFiltersCollection __RPC_FAR *__RPC_FAR *p)
00827 {
00828     return E_NOTIMPL;
00829 }
00830 
00831 HRESULT STDMETHODCALLTYPE CIEHtmlElement::put_ondragstart(VARIANT v)
00832 {
00833     return E_NOTIMPL;
00834 }
00835 
00836 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_ondragstart(VARIANT __RPC_FAR *p)
00837 {
00838     return E_NOTIMPL;
00839 }
00840 
00841 HRESULT STDMETHODCALLTYPE CIEHtmlElement::toString(BSTR __RPC_FAR *String)
00842 {
00843     return E_NOTIMPL;
00844 }
00845 
00846 HRESULT STDMETHODCALLTYPE CIEHtmlElement::put_onbeforeupdate(VARIANT v)
00847 {
00848     return E_NOTIMPL;
00849 }
00850 
00851 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_onbeforeupdate(VARIANT __RPC_FAR *p)
00852 {
00853     return E_NOTIMPL;
00854 }
00855 
00856 HRESULT STDMETHODCALLTYPE CIEHtmlElement::put_onafterupdate(VARIANT v)
00857 {
00858     return E_NOTIMPL;
00859 }
00860 
00861 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_onafterupdate(VARIANT __RPC_FAR *p)
00862 {
00863     return E_NOTIMPL;
00864 }
00865 
00866 HRESULT STDMETHODCALLTYPE CIEHtmlElement::put_onerrorupdate(VARIANT v)
00867 {
00868     return E_NOTIMPL;
00869 }
00870 
00871 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_onerrorupdate(VARIANT __RPC_FAR *p)
00872 {
00873     return E_NOTIMPL;
00874 }
00875 
00876 HRESULT STDMETHODCALLTYPE CIEHtmlElement::put_onrowexit(VARIANT v)
00877 {
00878     return E_NOTIMPL;
00879 }
00880 
00881 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_onrowexit(VARIANT __RPC_FAR *p)
00882 {
00883     return E_NOTIMPL;
00884 }
00885 
00886 HRESULT STDMETHODCALLTYPE CIEHtmlElement::put_onrowenter(VARIANT v)
00887 {
00888     return E_NOTIMPL;
00889 }
00890 
00891 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_onrowenter(VARIANT __RPC_FAR *p)
00892 {
00893     return E_NOTIMPL;
00894 }
00895 
00896 HRESULT STDMETHODCALLTYPE CIEHtmlElement::put_ondatasetchanged(VARIANT v)
00897 {
00898     return E_NOTIMPL;
00899 }
00900 
00901 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_ondatasetchanged(VARIANT __RPC_FAR *p)
00902 {
00903     return E_NOTIMPL;
00904 }
00905 
00906 HRESULT STDMETHODCALLTYPE CIEHtmlElement::put_ondataavailable(VARIANT v)
00907 {
00908     return E_NOTIMPL;
00909 }
00910 
00911 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_ondataavailable(VARIANT __RPC_FAR *p)
00912 {
00913     return E_NOTIMPL;
00914 }
00915 
00916 HRESULT STDMETHODCALLTYPE CIEHtmlElement::put_ondatasetcomplete(VARIANT v)
00917 {
00918     return E_NOTIMPL;
00919 }
00920 
00921 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_ondatasetcomplete(VARIANT __RPC_FAR *p)
00922 {
00923     return E_NOTIMPL;
00924 }
00925 
00926 HRESULT STDMETHODCALLTYPE CIEHtmlElement::put_onfilterchange(VARIANT v)
00927 {
00928     return E_NOTIMPL;
00929 }
00930 
00931 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_onfilterchange(VARIANT __RPC_FAR *p)
00932 {
00933     return E_NOTIMPL;
00934 }
00935 
00936 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_children(IDispatch __RPC_FAR *__RPC_FAR *p)
00937 {
00938     // Validate parameters
00939     if (p == NULL)
00940     {
00941         return E_INVALIDARG;
00942     }
00943 
00944     *p = NULL;
00945 
00946     // Create a collection representing the children of this node
00947     CIEHtmlElementCollectionInstance *pCollection = NULL;
00948     HRESULT hr = GetChildren(&pCollection);
00949     if (SUCCEEDED(hr))
00950     {
00951         *p = pCollection;
00952     }
00953 
00954     return hr;
00955 }
00956 
00957 HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_all(IDispatch __RPC_FAR *__RPC_FAR *p)
00958 {
00959     // Validate parameters
00960     if (p == NULL)
00961     {
00962         return E_INVALIDARG;
00963     }
00964 
00965     *p = NULL;
00966 
00967     // TODO get ALL contained elements, not just the immediate children
00968 
00969     CIEHtmlElementCollectionInstance *pCollection = NULL;
00970     CIEHtmlElementCollection::CreateFromParentNode(this, TRUE, (CIEHtmlElementCollection **) &pCollection);
00971     if (pCollection)
00972     {
00973         pCollection->AddRef();
00974         *p = pCollection;
00975     }
00976 
00977     return S_OK;
00978 }
00979