From 6a64bf064c4e20fe800ca671b24c7108df9fecbb Mon Sep 17 00:00:00 2001 From: "locka%iol.ie" Date: Fri, 18 Oct 2002 11:39:57 +0000 Subject: [PATCH] Implement put_innerHTML and some other simple methods. Fix property page to display proper content type for document. b=171769 r=chak@netscape.com sr=rpotts@netscape.com a=a=rjesup@wgate.com git-svn-id: svn://10.0.0.236/trunk@132231 18797224-902f-48f8-a5cc-f745e15eee43 --- .../activex/src/control/IEHtmlDocument.cpp | 92 ++++++++++++++++--- .../activex/src/control/IEHtmlElement.cpp | 11 ++- .../browser/activex/src/control/Makefile.in | 2 - .../activex/src/control/MozillaBrowser.cpp | 27 ++++-- .../activex/src/control/MozillaBrowser.h | 2 +- .../activex/src/control/MozillaControl.rc | 3 +- .../activex/src/control/PropertyDlg.cpp | 31 ++++++- .../browser/activex/src/control/PropertyDlg.h | 5 +- .../browser/activex/src/control/StdAfx.h | 2 - 9 files changed, 137 insertions(+), 38 deletions(-) diff --git a/mozilla/embedding/browser/activex/src/control/IEHtmlDocument.cpp b/mozilla/embedding/browser/activex/src/control/IEHtmlDocument.cpp index 6daa3d1d9d8..3804c5da435 100644 --- a/mozilla/embedding/browser/activex/src/control/IEHtmlDocument.cpp +++ b/mozilla/embedding/browser/activex/src/control/IEHtmlDocument.cpp @@ -41,9 +41,10 @@ #include "IEHtmlElementCollection.h" #include "IEHtmlElement.h" -#include "MozillaBrowser.h" +#include "nsIDOMHTMLDocument.h" +#include "nsIDOMNSHTMLDocument.h" -#include +#include "MozillaBrowser.h" CIEHtmlDocument::CIEHtmlDocument() : mControl(NULL) @@ -342,8 +343,29 @@ HRESULT STDMETHODCALLTYPE CIEHtmlDocument::get_frames(IHTMLFramesCollection2 __R HRESULT STDMETHODCALLTYPE CIEHtmlDocument::get_embeds(IHTMLElementCollection __RPC_FAR *__RPC_FAR *p) { + // Validate parameters + if (p == NULL) + { + return E_INVALIDARG; + } *p = NULL; - return E_NOTIMPL; + + nsCOMPtr htmlDoc = do_QueryInterface(mDOMDocument); + if (!htmlDoc) + return E_FAIL; + + nsCOMPtr nodeList; + htmlDoc->GetEmbeds(getter_AddRefs(nodeList)); + + // Get all elements + CIEHtmlElementCollectionInstance *pCollection = NULL; + CIEHtmlElementCollection::CreateFromDOMHTMLCollection(this, nodeList, (CIEHtmlElementCollection **) &pCollection); + if (pCollection) + { + pCollection->QueryInterface(IID_IHTMLElementCollection, (void **) p); + } + + return S_OK; } @@ -353,64 +375,89 @@ HRESULT STDMETHODCALLTYPE CIEHtmlDocument::get_plugins(IHTMLElementCollection __ return E_NOTIMPL; } +#define IMPL_SET_COLOR(name, v) \ + CComVariant vStr; \ + if (FAILED(::VariantChangeType(&vStr, &v, 0, VT_BSTR))) \ + return E_INVALIDARG; \ + if (!mDOMDocument) \ + return E_UNEXPECTED; \ + nsCOMPtr htmlDoc = do_QueryInterface(mDOMDocument); \ + if (!htmlDoc) \ + return E_FAIL; \ + USES_CONVERSION; \ + nsAutoString val(OLE2W(vStr.bstrVal)); \ + htmlDoc->Set ## name(val); \ + return S_OK; + +#define IMPL_GET_COLOR(name, v) \ + if (p == NULL) return E_INVALIDARG; \ + if (!mDOMDocument) return E_UNEXPECTED; \ + nsCOMPtr htmlDoc = do_QueryInterface(mDOMDocument); \ + if (!htmlDoc) return E_FAIL; \ + USES_CONVERSION; \ + nsAutoString val; \ + htmlDoc->Get ## name(val); \ + p->vt = VT_BSTR; \ + p->bstrVal = ::SysAllocString(W2COLE(val.get())); \ + return S_OK; HRESULT STDMETHODCALLTYPE CIEHtmlDocument::put_alinkColor(VARIANT v) { - return E_NOTIMPL; + IMPL_SET_COLOR(AlinkColor, v); } HRESULT STDMETHODCALLTYPE CIEHtmlDocument::get_alinkColor(VARIANT __RPC_FAR *p) { - return E_NOTIMPL; + IMPL_GET_COLOR(AlinkColor, p); } HRESULT STDMETHODCALLTYPE CIEHtmlDocument::put_bgColor(VARIANT v) { - return E_NOTIMPL; + IMPL_SET_COLOR(BgColor, v); } HRESULT STDMETHODCALLTYPE CIEHtmlDocument::get_bgColor(VARIANT __RPC_FAR *p) { - return E_NOTIMPL; + IMPL_GET_COLOR(BgColor, p); } HRESULT STDMETHODCALLTYPE CIEHtmlDocument::put_fgColor(VARIANT v) { - return E_NOTIMPL; + IMPL_SET_COLOR(FgColor, v); } HRESULT STDMETHODCALLTYPE CIEHtmlDocument::get_fgColor(VARIANT __RPC_FAR *p) { - return E_NOTIMPL; + IMPL_GET_COLOR(FgColor, p); } HRESULT STDMETHODCALLTYPE CIEHtmlDocument::put_linkColor(VARIANT v) { - return E_NOTIMPL; + IMPL_SET_COLOR(LinkColor, v); } HRESULT STDMETHODCALLTYPE CIEHtmlDocument::get_linkColor(VARIANT __RPC_FAR *p) { - return E_NOTIMPL; + IMPL_GET_COLOR(LinkColor, p); } HRESULT STDMETHODCALLTYPE CIEHtmlDocument::put_vlinkColor(VARIANT v) { - return E_NOTIMPL; + IMPL_SET_COLOR(VlinkColor, v); } HRESULT STDMETHODCALLTYPE CIEHtmlDocument::get_vlinkColor(VARIANT __RPC_FAR *p) { - return E_NOTIMPL; + IMPL_GET_COLOR(VlinkColor, p); } @@ -430,8 +477,25 @@ HRESULT STDMETHODCALLTYPE CIEHtmlDocument::get_location(IHTMLLocation __RPC_FAR HRESULT STDMETHODCALLTYPE CIEHtmlDocument::get_lastModified(BSTR __RPC_FAR *p) { + if (p == NULL) + { + return E_INVALIDARG; + } *p = NULL; - return E_NOTIMPL; + if (!mDOMDocument) + { + return E_UNEXPECTED; + } + nsCOMPtr htmlDoc = do_QueryInterface(mDOMDocument); + if (!htmlDoc) + { + return E_FAIL; + } + USES_CONVERSION; + nsAutoString val; + htmlDoc->GetLastModified(val); + *p = ::SysAllocString(W2COLE(val.get())); + return S_OK; } diff --git a/mozilla/embedding/browser/activex/src/control/IEHtmlElement.cpp b/mozilla/embedding/browser/activex/src/control/IEHtmlElement.cpp index d3f1327b78b..9448ca8fe1e 100644 --- a/mozilla/embedding/browser/activex/src/control/IEHtmlElement.cpp +++ b/mozilla/embedding/browser/activex/src/control/IEHtmlElement.cpp @@ -508,7 +508,16 @@ HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_offsetParent(IHTMLElement __RPC_FA HRESULT STDMETHODCALLTYPE CIEHtmlElement::put_innerHTML(BSTR v) { - return E_NOTIMPL; + nsCOMPtr elementHTML = do_QueryInterface(mDOMNode); + if (!elementHTML) + { + return E_UNEXPECTED; + } + + USES_CONVERSION; + nsAutoString innerHTML(OLE2W(v)); + elementHTML->SetInnerHTML(innerHTML); + return S_OK; } HRESULT STDMETHODCALLTYPE CIEHtmlElement::get_innerHTML(BSTR __RPC_FAR *p) diff --git a/mozilla/embedding/browser/activex/src/control/Makefile.in b/mozilla/embedding/browser/activex/src/control/Makefile.in index 70c6713ad8d..e28f9cfe81e 100644 --- a/mozilla/embedding/browser/activex/src/control/Makefile.in +++ b/mozilla/embedding/browser/activex/src/control/Makefile.in @@ -60,8 +60,6 @@ REQUIRES = \ CPPSRCS = \ StdAfx.cpp \ - ControlSite.cpp \ - ControlSiteIPFrame.cpp \ ItemContainer.cpp \ PropertyBag.cpp \ MozillaControl.cpp \ diff --git a/mozilla/embedding/browser/activex/src/control/MozillaBrowser.cpp b/mozilla/embedding/browser/activex/src/control/MozillaBrowser.cpp index 5f514116c84..ee03af6144b 100644 --- a/mozilla/embedding/browser/activex/src/control/MozillaBrowser.cpp +++ b/mozilla/embedding/browser/activex/src/control/MozillaBrowser.cpp @@ -68,6 +68,7 @@ #include "nsIDOMWindowInternal.h" #include "nsIDOMHTMLAnchorElement.h" +#include "nsIDOMNSDocument.h" #include "nsEmbedAPI.h" @@ -320,7 +321,7 @@ void CMozillaBrowser::ShowContextMenu(PRUint32 aContextFlags, nsIDOMEvent *aEven // // ShowURIPropertyDlg // -void CMozillaBrowser::ShowURIPropertyDlg(const nsString &aURI) +void CMozillaBrowser::ShowURIPropertyDlg(const nsAString &aURI, const nsAString &aContentType) { CPropertyDlg dlg; CPPageDlg linkDlg; @@ -328,10 +329,8 @@ void CMozillaBrowser::ShowURIPropertyDlg(const nsString &aURI) if (aURI.Length() > 0) { - USES_CONVERSION; - linkDlg.mProtocol = "Hypertext Transfer Protocol"; // TODO - linkDlg.mType = "HTML Document"; // TODO - linkDlg.mURL.AssignWithConversion(aURI); + linkDlg.mType = aContentType; + linkDlg.mURL = aURI; } dlg.DoModal(); @@ -834,8 +833,14 @@ LRESULT CMozillaBrowser::OnDocumentProperties(WORD wNotifyCode, WORD wID, HWND h { htmlDoc->GetURL(uri); } + nsAutoString contentType; + nsCOMPtr doc = do_QueryInterface(ownerDoc); + if (doc) + { + doc->GetContentType(contentType); + } - ShowURIPropertyDlg(uri); + ShowURIPropertyDlg(uri, contentType); return 0; } @@ -930,14 +935,16 @@ LRESULT CMozillaBrowser::OnLinkCopyShortcut(WORD wNotifyCode, WORD wID, HWND hWn LRESULT CMozillaBrowser::OnLinkProperties(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled) { nsAutoString uri; + nsAutoString type; nsCOMPtr anchorElement = do_QueryInterface(mContextNode); if (anchorElement) { anchorElement->GetHref(uri); + anchorElement->GetType(type); // How many anchors implement this I wonder } - ShowURIPropertyDlg(uri); + ShowURIPropertyDlg(uri, type); return 0; } @@ -1281,14 +1288,14 @@ HRESULT CMozillaBrowser::OnEditorCommand(DWORD nCmdID) PRBool bAll = PR_TRUE; // Set or remove - pHtmlEditor->GetInlineProperty(pInlineProperty, nsString(), nsString(), &bFirst, &bAny, &bAll); + pHtmlEditor->GetInlineProperty(pInlineProperty, nsAutoString(), nsAutoString(), &bFirst, &bAny, &bAll); if (bAny) { - pHtmlEditor->RemoveInlineProperty(pInlineProperty, nsString()); + pHtmlEditor->RemoveInlineProperty(pInlineProperty, nsAutoString()); } else { - pHtmlEditor->SetInlineProperty(pInlineProperty, nsString(), nsString()); + pHtmlEditor->SetInlineProperty(pInlineProperty, nsAutoString(), nsAutoString()); } } diff --git a/mozilla/embedding/browser/activex/src/control/MozillaBrowser.h b/mozilla/embedding/browser/activex/src/control/MozillaBrowser.h index 43ab1bebb09..1a78e6ae537 100644 --- a/mozilla/embedding/browser/activex/src/control/MozillaBrowser.h +++ b/mozilla/embedding/browser/activex/src/control/MozillaBrowser.h @@ -417,7 +417,7 @@ protected: // User interface methods virtual int MessageBox(LPCTSTR lpszText, LPCTSTR lpszCaption = _T(""), UINT nType = MB_OK); virtual void ShowContextMenu(PRUint32 aContextFlags, nsIDOMEvent *aEvent, nsIDOMNode *aNode); - virtual void ShowURIPropertyDlg(const nsString &aURI); + virtual void ShowURIPropertyDlg(const nsAString &aURI, const nsAString &aContentType); virtual void NextDlgControl(); virtual void PrevDlgControl(); diff --git a/mozilla/embedding/browser/activex/src/control/MozillaControl.rc b/mozilla/embedding/browser/activex/src/control/MozillaControl.rc index 60368a670e2..ee6f29b6fa6 100644 --- a/mozilla/embedding/browser/activex/src/control/MozillaControl.rc +++ b/mozilla/embedding/browser/activex/src/control/MozillaControl.rc @@ -325,9 +325,8 @@ FONT 8, "MS Sans Serif" BEGIN LTEXT "Address: (URL)",IDC_STATIC,0,68,27,20 CONTROL "",IDC_STATIC,"Static",SS_ETCHEDHORZ,0,32,185,1 - LTEXT "Type:",IDC_STATIC,0,53,19,8 LTEXT "type",IDC_TYPE,35,53,149,8 - LTEXT "Protocol:",IDC_STATIC,0,38,28,8 + LTEXT "Type:",IDC_STATIC,0,38,19,8 LTEXT "protocol",IDC_PROTOCOL,35,38,149,8 EDITTEXT IDC_ADDRESS,35,68,149,61,ES_MULTILINE | ES_AUTOVSCROLL | ES_READONLY diff --git a/mozilla/embedding/browser/activex/src/control/PropertyDlg.cpp b/mozilla/embedding/browser/activex/src/control/PropertyDlg.cpp index 8014270c4e9..e8f98f25788 100644 --- a/mozilla/embedding/browser/activex/src/control/PropertyDlg.cpp +++ b/mozilla/embedding/browser/activex/src/control/PropertyDlg.cpp @@ -42,6 +42,9 @@ #include "PropertyDlg.h" #include "resource.h" +#include "nsIMIMEInfo.h" +#include "nsIMIMEService.h" + CPropertyDlg::CPropertyDlg() : mPPage(NULL) { @@ -96,8 +99,30 @@ LRESULT CPropertyDlg::OnClose(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bH LRESULT CPPageDlg::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { - SetDlgItemText(IDC_PROTOCOL, mProtocol.get()); - SetDlgItemText(IDC_TYPE, mType.get()); - SetDlgItemText(IDC_ADDRESS, mURL.get()); + nsAutoString desc; + if (!mType.IsEmpty()) + { + nsresult rv; + nsCOMPtr mimeService; + mimeService = do_GetService("@mozilla.org/mime;1", &rv); + NS_ENSURE_TRUE(mimeService, NS_ERROR_FAILURE); + + nsCOMPtr mimeInfo; + nsCAutoString contentType; + contentType.AssignWithConversion(mType); + mimeService->GetFromMIMEType(contentType.get(), getter_AddRefs(mimeInfo)); + if (mimeInfo) + { + nsXPIDLString description; + mimeInfo->GetDescription(getter_Copies(description)); + desc = description; + } + } + + USES_CONVERSION; + SetDlgItemText(IDC_PROTOCOL, W2T(desc.get())); + SetDlgItemText(IDC_TYPE, W2T(mType.get())); + SetDlgItemText(IDC_ADDRESS, W2T(mURL.get())); + return 1; } diff --git a/mozilla/embedding/browser/activex/src/control/PropertyDlg.h b/mozilla/embedding/browser/activex/src/control/PropertyDlg.h index becec3b19e4..237c2b8ff87 100644 --- a/mozilla/embedding/browser/activex/src/control/PropertyDlg.h +++ b/mozilla/embedding/browser/activex/src/control/PropertyDlg.h @@ -45,9 +45,8 @@ class CPPageDlg : public CDialogImpl public: enum { IDD = IDD_PPAGE_LINK }; - nsCString mProtocol; - nsCString mType; - nsCString mURL; + nsString mType; + nsString mURL; BEGIN_MSG_MAP(CPPageLinkDlg) MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog) diff --git a/mozilla/embedding/browser/activex/src/control/StdAfx.h b/mozilla/embedding/browser/activex/src/control/StdAfx.h index b1b41d58c69..94cde4a8e53 100644 --- a/mozilla/embedding/browser/activex/src/control/StdAfx.h +++ b/mozilla/embedding/browser/activex/src/control/StdAfx.h @@ -160,8 +160,6 @@ typedef long int32; #include "PropertyList.h" #include "PropertyBag.h" #include "ItemContainer.h" -#include "ControlSite.h" -#include "ControlSiteIPFrame.h" #include "IEHtmlDocument.h" #include "CPMozillaControl.h"