47003. Make the test embedding application use the chrome interfaces.
The WebBrowserChrome.cpp/h are the same as the ones in winEmbed/. git-svn-id: svn://10.0.0.236/trunk@77377 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
parent
1935be3062
commit
27d79dc82e
@ -24,7 +24,7 @@ VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
CPPSRCS = WebBrowser.cpp \
|
||||
CPPSRCS = WebBrowserChrome.cpp \
|
||||
main.cpp \
|
||||
$(NULL)
|
||||
|
||||
|
||||
@ -1,168 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Doug Turner <dougt@netscape.com>
|
||||
*/
|
||||
|
||||
#include "WebBrowser.h"
|
||||
|
||||
#include "nsCWebBrowser.h"
|
||||
#include "nsWidgetsCID.h"
|
||||
#include "nsIGenericFactory.h"
|
||||
#include "nsString.h"
|
||||
#include "nsXPIDLString.h"
|
||||
#include "nsIURI.h"
|
||||
#include "nsIWebProgress.h"
|
||||
#include "nsIWebNavigation.h"
|
||||
#include "nsIDocShell.h"
|
||||
#include "nsIContentViewer.h"
|
||||
#include "nsIContentViewerFile.h"
|
||||
#include "nsIDocShell.h"
|
||||
#include "nsIWebNavigation.h"
|
||||
#include "nsIEditorShell.h"
|
||||
#include "nsIDOMWindow.h"
|
||||
#include "nsIScriptGlobalObject.h"
|
||||
#include "nsIInterfaceRequestor.h"
|
||||
|
||||
#include "nsIDocShellTreeItem.h"
|
||||
#include "nsIDocShellTreeOwner.h"
|
||||
|
||||
nsresult
|
||||
ConvertDocShellToDOMWindow(nsIDocShell* aDocShell, nsIDOMWindow** aDOMWindow)
|
||||
{
|
||||
if (!aDOMWindow)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
*aDOMWindow = nsnull;
|
||||
|
||||
nsCOMPtr<nsIScriptGlobalObject> scriptGlobalObject(do_GetInterface(aDocShell));
|
||||
|
||||
nsCOMPtr<nsIDOMWindow> domWindow(do_QueryInterface(scriptGlobalObject));
|
||||
if (!domWindow)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
*aDOMWindow = domWindow.get();
|
||||
NS_ADDREF(*aDOMWindow);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
WebBrowser::WebBrowser(){}
|
||||
WebBrowser::~WebBrowser()
|
||||
{
|
||||
PRBool duh;
|
||||
if (mEditor) // not good place for it!
|
||||
mEditor->SaveDocument(PR_FALSE, PR_FALSE, &duh);
|
||||
}
|
||||
|
||||
nsresult
|
||||
WebBrowser::Init(nsNativeWidget widget, nsIWebBrowserChrome* aTopWindow)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
mWebBrowser = do_CreateInstance(NS_WEBBROWSER_PROGID, &rv);
|
||||
|
||||
if (!mWebBrowser)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
mBaseWindow = do_QueryInterface(mWebBrowser);
|
||||
|
||||
mTopWindow = aTopWindow;
|
||||
mWebBrowser->SetContainerWindow(aTopWindow);
|
||||
|
||||
nsCOMPtr<nsIDocShellTreeItem> dsti = do_QueryInterface(mWebBrowser);
|
||||
dsti->SetItemType(nsIDocShellTreeItem::typeChromeWrapper);
|
||||
|
||||
rv = mBaseWindow->InitWindow( widget,
|
||||
nsnull,
|
||||
0,
|
||||
0,
|
||||
100,
|
||||
100);
|
||||
|
||||
mBaseWindow->Create();
|
||||
mBaseWindow->SetVisibility(PR_TRUE);
|
||||
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
WebBrowser::GetWebBrowser(nsIWebBrowser **outBrowser)
|
||||
{
|
||||
*outBrowser = mWebBrowser;
|
||||
NS_IF_ADDREF(*outBrowser);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
WebBrowser::GoTo(char* url)
|
||||
{
|
||||
nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(mWebBrowser));
|
||||
return webNav->LoadURI(NS_ConvertASCIItoUCS2(url).GetUnicode());
|
||||
}
|
||||
|
||||
nsresult
|
||||
WebBrowser::Edit(char* url)
|
||||
{
|
||||
nsresult rv;
|
||||
mEditor = do_CreateInstance("component://netscape/editor/editorshell", &rv);
|
||||
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr <nsIDocShell> rootDocShell = do_GetInterface(mWebBrowser);
|
||||
|
||||
nsCOMPtr<nsIDOMWindow> domWindow;
|
||||
ConvertDocShellToDOMWindow(rootDocShell, getter_AddRefs(domWindow));
|
||||
|
||||
mEditor->Init();
|
||||
mEditor->SetEditorType(NS_ConvertASCIItoUCS2("html").GetUnicode());
|
||||
mEditor->SetWebShellWindow(domWindow);
|
||||
mEditor->SetContentWindow(domWindow);
|
||||
return mEditor->LoadUrl(NS_ConvertASCIItoUCS2(url).GetUnicode());
|
||||
}
|
||||
|
||||
nsresult
|
||||
WebBrowser::Print(void)
|
||||
{
|
||||
nsCOMPtr <nsIDocShell> rootDocShell = do_GetInterface(mWebBrowser);
|
||||
|
||||
|
||||
nsIContentViewer *pContentViewer = nsnull;
|
||||
nsresult res = rootDocShell->GetContentViewer(&pContentViewer);
|
||||
|
||||
if (NS_SUCCEEDED(res))
|
||||
{
|
||||
nsCOMPtr<nsIContentViewerFile> spContentViewerFile = do_QueryInterface(pContentViewer);
|
||||
spContentViewerFile->Print(PR_TRUE, nsnull);
|
||||
NS_RELEASE(pContentViewer);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
WebBrowser::SetPositionAndSize(int x, int y, int cx, int cy)
|
||||
{
|
||||
return mBaseWindow->SetPositionAndSize(x, y, cx, cy, PR_TRUE);
|
||||
}
|
||||
|
||||
@ -1,56 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Doug Turner <dougt@netscape.com>
|
||||
*/
|
||||
|
||||
#ifndef __WebBrowser__
|
||||
#define __WebBrowser__
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIWidget.h"
|
||||
#include "nsIBaseWindow.h"
|
||||
#include "nsIWebBrowser.h"
|
||||
#include "nsIEditorShell.h"
|
||||
#include "nsIWebBrowserChrome.h"
|
||||
|
||||
class WebBrowser
|
||||
{
|
||||
public:
|
||||
nsresult Init(nsNativeWidget widget, nsIWebBrowserChrome* aTopWindow);
|
||||
nsresult SetPositionAndSize(int x, int y, int cx, int cy);
|
||||
nsresult GoTo(char* url);
|
||||
nsresult Edit(char* url);
|
||||
nsresult Print(void);
|
||||
|
||||
nsresult GetWebBrowser(nsIWebBrowser **outBrowser);
|
||||
|
||||
WebBrowser();
|
||||
virtual ~WebBrowser();
|
||||
|
||||
protected:
|
||||
nsCOMPtr<nsIWebBrowser> mWebBrowser;
|
||||
nsCOMPtr<nsIBaseWindow> mBaseWindow;
|
||||
nsCOMPtr<nsIWebBrowserChrome> mTopWindow;
|
||||
//for editing
|
||||
nsCOMPtr<nsIEditorShell> mEditor;
|
||||
};
|
||||
|
||||
#endif /* __WebBrowser__ */
|
||||
360
mozilla/embedding/tests/gtkEmbed/WebBrowserChrome.cpp
Normal file
360
mozilla/embedding/tests/gtkEmbed/WebBrowserChrome.cpp
Normal file
@ -0,0 +1,360 @@
|
||||
/* -*- Mode: C++; tab-width: 3; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Mozilla browser.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications, Inc. Portions created by Netscape are
|
||||
* Copyright (C) 1999, Mozilla. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
// Local Includes
|
||||
|
||||
#include "nsIGenericFactory.h"
|
||||
#include "nsString.h"
|
||||
#include "nsXPIDLString.h"
|
||||
#include "nsIURI.h"
|
||||
#include "nsIWebProgress.h"
|
||||
#include "nsIDocShellTreeItem.h"
|
||||
#include "nsIRequest.h"
|
||||
#include "nsIChannel.h"
|
||||
#include "nsCWebBrowser.h"
|
||||
#include "nsWidgetsCID.h"
|
||||
|
||||
#include "WebBrowserChrome.h"
|
||||
|
||||
nsVoidArray WebBrowserChrome::sBrowserList;
|
||||
|
||||
WebBrowserChrome::WebBrowserChrome()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
mNativeWindow = nsnull;
|
||||
}
|
||||
|
||||
WebBrowserChrome::~WebBrowserChrome()
|
||||
{
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
// WebBrowserChrome::nsISupports
|
||||
//*****************************************************************************
|
||||
|
||||
NS_IMPL_ADDREF(WebBrowserChrome)
|
||||
NS_IMPL_RELEASE(WebBrowserChrome)
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN(WebBrowserChrome)
|
||||
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIWebBrowserChrome)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIInterfaceRequestor)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIWebBrowserChrome)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIBaseWindow)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIWebProgressListener) //optional
|
||||
// NS_INTERFACE_MAP_ENTRY(nsIPrompt)
|
||||
NS_INTERFACE_MAP_END
|
||||
|
||||
//*****************************************************************************
|
||||
// WebBrowserChrome::nsIInterfaceRequestor
|
||||
//*****************************************************************************
|
||||
|
||||
NS_IMETHODIMP WebBrowserChrome::GetInterface(const nsIID &aIID, void** aInstancePtr)
|
||||
{
|
||||
return QueryInterface(aIID, aInstancePtr);
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
// WebBrowserChrome::nsIWebBrowserChrome
|
||||
//*****************************************************************************
|
||||
|
||||
NS_IMETHODIMP WebBrowserChrome::SetStatus(PRUint32 aType, const PRUnichar* aStatus)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP WebBrowserChrome::GetWebBrowser(nsIWebBrowser** aWebBrowser)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aWebBrowser);
|
||||
NS_ENSURE_TRUE(mWebBrowser, NS_ERROR_NOT_INITIALIZED);
|
||||
*aWebBrowser = mWebBrowser;
|
||||
NS_IF_ADDREF(*aWebBrowser);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP WebBrowserChrome::SetWebBrowser(nsIWebBrowser* aWebBrowser)
|
||||
{
|
||||
NS_ENSURE_ARG(aWebBrowser); // Passing nsnull is NOT OK
|
||||
NS_ENSURE_TRUE(mWebBrowser, NS_ERROR_NOT_INITIALIZED);
|
||||
NS_ERROR("Who be calling me");
|
||||
mWebBrowser = aWebBrowser;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP WebBrowserChrome::GetChromeFlags(PRUint32* aChromeMask)
|
||||
{
|
||||
NS_ERROR("Haven't Implemented this yet");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP WebBrowserChrome::SetChromeFlags(PRUint32 aChromeMask)
|
||||
{
|
||||
NS_ERROR("Haven't Implemented this yet");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
|
||||
// in winEmbed.cpp
|
||||
extern nativeWindow CreateNativeWindow(nsIWebBrowserChrome* chrome);
|
||||
|
||||
NS_IMETHODIMP WebBrowserChrome::CreateBrowserWindow(PRUint32 chromeMask, nsIWebBrowser **aWebBrowser)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aWebBrowser);
|
||||
*aWebBrowser = nsnull;
|
||||
|
||||
mWebBrowser = do_CreateInstance(NS_WEBBROWSER_PROGID);
|
||||
|
||||
if (!mWebBrowser)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
mWebBrowser->SetContainerWindow(NS_STATIC_CAST(nsIWebBrowserChrome*, this));
|
||||
|
||||
nsCOMPtr<nsIDocShellTreeItem> dsti = do_QueryInterface(mWebBrowser);
|
||||
dsti->SetItemType(nsIDocShellTreeItem::typeChromeWrapper);
|
||||
|
||||
|
||||
mBaseWindow = do_QueryInterface(mWebBrowser);
|
||||
mNativeWindow = CreateNativeWindow(NS_STATIC_CAST(nsIWebBrowserChrome*, this));
|
||||
|
||||
if (!mNativeWindow)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
mBaseWindow->InitWindow( mNativeWindow,
|
||||
nsnull,
|
||||
0, 0, 450, 450);
|
||||
mBaseWindow->Create();
|
||||
|
||||
NS_IF_ADDREF(*aWebBrowser = mWebBrowser);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP WebBrowserChrome::FindNamedBrowserItem(const PRUnichar* aName,
|
||||
nsIDocShellTreeItem ** aBrowserItem)
|
||||
{
|
||||
NS_ENSURE_ARG(aName);
|
||||
NS_ENSURE_ARG_POINTER(aBrowserItem);
|
||||
*aBrowserItem = nsnull;
|
||||
|
||||
if (!mWebBrowser)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsIDocShellTreeItem> docShellAsItem(do_QueryInterface(mWebBrowser));
|
||||
NS_ENSURE_TRUE(docShellAsItem, NS_ERROR_FAILURE);
|
||||
|
||||
return docShellAsItem->FindItemWithName(aName, NS_STATIC_CAST(nsIWebBrowserChrome*, this), aBrowserItem);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP WebBrowserChrome::SizeBrowserTo(PRInt32 aCX, PRInt32 aCY)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP WebBrowserChrome::ShowAsModal(void)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP WebBrowserChrome::ExitModalEventLoop(nsresult aStatus)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
WebBrowserChrome::SetPersistence(PRBool aPersistX, PRBool aPersistY,
|
||||
PRBool aPersistCX, PRBool aPersistCY,
|
||||
PRBool aPersistSizeMode)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
WebBrowserChrome::GetPersistence(PRBool* aPersistX, PRBool* aPersistY,
|
||||
PRBool* aPersistCX, PRBool* aPersistCY,
|
||||
PRBool* aPersistSizeMode)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
// WebBrowserChrome::nsIWebProgressListener
|
||||
//*****************************************************************************
|
||||
|
||||
NS_IMETHODIMP WebBrowserChrome::OnProgressChange(nsIWebProgress *progress, nsIRequest *request,
|
||||
PRInt32 curSelfProgress, PRInt32 maxSelfProgress,
|
||||
PRInt32 curTotalProgress, PRInt32 maxTotalProgress)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP WebBrowserChrome::OnStateChange(nsIWebProgress *progress, nsIRequest *request,
|
||||
PRInt32 progressStateFlags, PRUint32 status)
|
||||
{
|
||||
|
||||
if ((progressStateFlags & STATE_STOP) && (progressStateFlags & STATE_IS_REQUEST))
|
||||
{
|
||||
}
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP WebBrowserChrome::OnLocationChange(nsIWebProgress* aWebProgress,
|
||||
nsIRequest* aRequest,
|
||||
nsIURI *location)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
WebBrowserChrome::OnStatusChange(nsIWebProgress* aWebProgress,
|
||||
nsIRequest* aRequest,
|
||||
nsresult aStatus,
|
||||
const PRUnichar* aMessage)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
// WebBrowserChrome::nsIBaseWindow
|
||||
//*****************************************************************************
|
||||
|
||||
NS_IMETHODIMP WebBrowserChrome::InitWindow(nativeWindow aParentNativeWindow,
|
||||
nsIWidget* parentWidget, PRInt32 x, PRInt32 y, PRInt32 cx, PRInt32 cy)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP WebBrowserChrome::Create()
|
||||
{
|
||||
NS_ASSERTION(PR_FALSE, "You can't call this");
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP WebBrowserChrome::Destroy()
|
||||
{
|
||||
NS_ASSERTION(PR_FALSE, "You can't call this");
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP WebBrowserChrome::SetPosition(PRInt32 x, PRInt32 y)
|
||||
{
|
||||
return mBaseWindow->SetPosition(x, y);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP WebBrowserChrome::GetPosition(PRInt32* x, PRInt32* y)
|
||||
{
|
||||
return mBaseWindow->GetPosition(x, y);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP WebBrowserChrome::SetSize(PRInt32 cx, PRInt32 cy, PRBool fRepaint)
|
||||
{
|
||||
return mBaseWindow->SetSize(cx, cy, fRepaint);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP WebBrowserChrome::GetSize(PRInt32* cx, PRInt32* cy)
|
||||
{
|
||||
return mBaseWindow->GetSize(cx, cy);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP WebBrowserChrome::SetPositionAndSize(PRInt32 x, PRInt32 y, PRInt32 cx, PRInt32 cy, PRBool fRepaint)
|
||||
{
|
||||
return mBaseWindow->SetPositionAndSize(x, y, cx, cy, fRepaint);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP WebBrowserChrome::GetPositionAndSize(PRInt32* x, PRInt32* y, PRInt32* cx, PRInt32* cy)
|
||||
{
|
||||
return mBaseWindow->GetPositionAndSize(x, y, cx, cy);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP WebBrowserChrome::Repaint(PRBool aForce)
|
||||
{
|
||||
return mBaseWindow->Repaint(aForce);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP WebBrowserChrome::GetParentWidget(nsIWidget** aParentWidget)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aParentWidget);
|
||||
|
||||
NS_ASSERTION(PR_FALSE, "Not Yet Implemented");
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP WebBrowserChrome::SetParentWidget(nsIWidget* aParentWidget)
|
||||
{
|
||||
NS_ASSERTION(PR_FALSE, "You can't call this");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP WebBrowserChrome::GetParentNativeWindow(nativeWindow* aParentNativeWindow)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aParentNativeWindow);
|
||||
|
||||
*aParentNativeWindow = mNativeWindow;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP WebBrowserChrome::SetParentNativeWindow(nativeWindow aParentNativeWindow)
|
||||
{
|
||||
mNativeWindow = aParentNativeWindow;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP WebBrowserChrome::GetVisibility(PRBool* aVisibility)
|
||||
{
|
||||
return mBaseWindow->GetVisibility(aVisibility);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP WebBrowserChrome::SetVisibility(PRBool aVisibility)
|
||||
{
|
||||
return mBaseWindow->SetVisibility(aVisibility);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP WebBrowserChrome::GetMainWidget(nsIWidget** aMainWidget)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP WebBrowserChrome::SetFocus()
|
||||
{
|
||||
return mBaseWindow->SetFocus();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP WebBrowserChrome::FocusAvailable(nsIBaseWindow* aCurrentFocus,
|
||||
PRBool* aTookFocus)
|
||||
{
|
||||
return mBaseWindow->FocusAvailable(aCurrentFocus, aTookFocus);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP WebBrowserChrome::GetTitle(PRUnichar** aTitle)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aTitle);
|
||||
|
||||
*aTitle = nsnull;
|
||||
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP WebBrowserChrome::SetTitle(const PRUnichar* aTitle)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
72
mozilla/embedding/tests/gtkEmbed/WebBrowserChrome.h
Normal file
72
mozilla/embedding/tests/gtkEmbed/WebBrowserChrome.h
Normal file
@ -0,0 +1,72 @@
|
||||
/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Mozilla browser.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications, Inc. Portions created by Netscape are
|
||||
* Copyright (C) 1999, Mozilla. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#ifndef __WebBrowserChrome__
|
||||
#define __WebBrowserChrome__
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIGenericFactory.h"
|
||||
#include "nsString.h"
|
||||
#include "nsIWebBrowserChrome.h"
|
||||
|
||||
#include "nsIDocShell.h"
|
||||
#include "nsIContentViewer.h"
|
||||
#include "nsIContentViewerFile.h"
|
||||
#include "nsIBaseWindow.h"
|
||||
#include "nsIWebNavigation.h"
|
||||
#include "nsIWebProgressListener.h"
|
||||
#include "nsIInterfaceRequestor.h"
|
||||
#include "nsIPrompt.h"
|
||||
#include "nsIWebBrowser.h"
|
||||
#include "nsVoidArray.h"
|
||||
|
||||
|
||||
|
||||
class WebBrowserChrome : public nsIWebBrowserChrome,
|
||||
public nsIWebProgressListener,
|
||||
public nsIBaseWindow,
|
||||
// public nsIPrompt,
|
||||
public nsIInterfaceRequestor
|
||||
{
|
||||
public:
|
||||
WebBrowserChrome();
|
||||
virtual ~WebBrowserChrome();
|
||||
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIWEBBROWSERCHROME
|
||||
NS_DECL_NSIWEBPROGRESSLISTENER
|
||||
NS_DECL_NSIBASEWINDOW
|
||||
// NS_DECL_NSIPROMPT
|
||||
NS_DECL_NSIINTERFACEREQUESTOR
|
||||
|
||||
protected:
|
||||
|
||||
nativeWindow mNativeWindow;
|
||||
|
||||
nsCOMPtr<nsIWebBrowser> mWebBrowser;
|
||||
nsCOMPtr<nsIBaseWindow> mBaseWindow;
|
||||
nsCOMPtr<nsIWebBrowserChrome> mTopWindow;
|
||||
|
||||
static nsVoidArray sBrowserList;
|
||||
};
|
||||
|
||||
#endif /* __WebBrowserChrome__ */
|
||||
@ -1,3 +1,4 @@
|
||||
|
||||
//
|
||||
// What follows is a hacked version the the sample hello
|
||||
// world gtk app found: http://www.gtk.org/tutorial/gtk_tut-2.html
|
||||
@ -6,8 +7,9 @@
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsEmbedAPI.h"
|
||||
#include "WebBrowser.h"
|
||||
#include "WebBrowserChrome.h"
|
||||
|
||||
#include "nsIEventQueueService.h"
|
||||
#include "nsIServiceManager.h"
|
||||
@ -16,6 +18,14 @@ static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID);
|
||||
|
||||
static gint io_identifier = 0;
|
||||
|
||||
gint delete_window( GtkWidget *widget,
|
||||
GdkEvent *event,
|
||||
gpointer data )
|
||||
{
|
||||
gtk_main_quit();
|
||||
return(FALSE);
|
||||
}
|
||||
|
||||
static void
|
||||
handle_event_queue(gpointer data, gint source, GdkInputCondition condition)
|
||||
{
|
||||
@ -23,68 +33,119 @@ handle_event_queue(gpointer data, gint source, GdkInputCondition condition)
|
||||
eventQueue->ProcessPendingEvents();
|
||||
}
|
||||
|
||||
int main( int argc,
|
||||
char *argv[] )
|
||||
{
|
||||
nsresult rv;
|
||||
NS_InitEmbedding(nsnull, nsnull);
|
||||
|
||||
// set up the thread event queue
|
||||
nsIEventQueueService* eventQService;
|
||||
rv = nsServiceManager::GetService(kEventQueueServiceCID,
|
||||
NS_GET_IID(nsIEventQueueService),
|
||||
(nsISupports **)&eventQService);
|
||||
if (NS_OK == rv)
|
||||
{
|
||||
// get our hands on the thread event queue
|
||||
nsIEventQueue *eventQueue;
|
||||
rv = eventQService->GetThreadEventQueue( NS_CURRENT_THREAD,
|
||||
&eventQueue);
|
||||
if (NS_FAILED(rv))
|
||||
return FALSE;
|
||||
nsresult OpenWebPage(char* url)
|
||||
{
|
||||
WebBrowserChrome * chrome = new WebBrowserChrome();
|
||||
if (!chrome)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
io_identifier = gdk_input_add( eventQueue->GetEventQueueSelectFD(),
|
||||
GDK_INPUT_READ,
|
||||
handle_event_queue,
|
||||
eventQueue);
|
||||
NS_RELEASE(eventQService);
|
||||
NS_RELEASE(eventQueue);
|
||||
}
|
||||
NS_ADDREF(chrome); // native window will hold the addref.
|
||||
|
||||
nsCOMPtr<nsIWebBrowser> newBrowser;
|
||||
chrome->CreateBrowserWindow(0, getter_AddRefs(newBrowser));
|
||||
if (!newBrowser)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsIBaseWindow> baseWindow = do_QueryInterface(newBrowser);
|
||||
|
||||
baseWindow->SetPositionAndSize(0,
|
||||
0,
|
||||
450,
|
||||
450,
|
||||
PR_TRUE);
|
||||
|
||||
baseWindow->SetVisibility(PR_TRUE);
|
||||
|
||||
|
||||
|
||||
GtkWidget *window;
|
||||
|
||||
/* This is called in all GTK applications. Arguments are parsed
|
||||
* from the command line and are returned to the application. */
|
||||
gtk_init(&argc, &argv);
|
||||
|
||||
/* create a new window */
|
||||
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
||||
|
||||
gtk_window_set_title (GTK_WINDOW (window), "Embedding is Fun!");
|
||||
gtk_container_set_border_width (GTK_CONTAINER (window), 10);
|
||||
|
||||
|
||||
gtk_widget_realize (window);
|
||||
|
||||
WebBrowser *browser = new WebBrowser();
|
||||
if (! browser)
|
||||
return -1;
|
||||
|
||||
browser->Init(window,nsnull);
|
||||
browser->SetPositionAndSize(0, 320, 400, 400);
|
||||
browser->GoTo("http://people.netscape.com");
|
||||
|
||||
gtk_widget_show (window);
|
||||
GtkWidget *widget;
|
||||
baseWindow->GetParentNativeWindow((void**)&widget);
|
||||
|
||||
/* All GTK applications must have a gtk_main(). Control ends here
|
||||
* and waits for an event to occur (like a key press or
|
||||
* mouse event). */
|
||||
gtk_main ();
|
||||
|
||||
gtk_widget_show (widget); // should this function do this?
|
||||
|
||||
nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(newBrowser));
|
||||
|
||||
if (!webNav)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
return webNav->LoadURI(NS_ConvertASCIItoUCS2(url).GetUnicode());
|
||||
}
|
||||
|
||||
|
||||
|
||||
nativeWindow CreateNativeWindow(nsIWebBrowserChrome* chrome)
|
||||
{
|
||||
GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
||||
|
||||
return(0);
|
||||
}
|
||||
if (!window)
|
||||
return window;
|
||||
|
||||
gtk_signal_connect (GTK_OBJECT (window),
|
||||
"delete_event",
|
||||
GTK_SIGNAL_FUNC (delete_window),
|
||||
NULL);
|
||||
|
||||
gtk_window_set_title (GTK_WINDOW (window), "Embedding is Fun!");
|
||||
gtk_window_set_default_size (GTK_WINDOW(window), 450, 450);
|
||||
|
||||
|
||||
gtk_container_set_border_width (GTK_CONTAINER (window), 10);
|
||||
|
||||
gtk_widget_realize (window);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return window;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main( int argc,
|
||||
char *argv[] )
|
||||
{
|
||||
nsresult rv;
|
||||
NS_InitEmbedding(nsnull, nsnull);
|
||||
|
||||
// set up the thread event queue
|
||||
nsIEventQueueService* eventQService;
|
||||
rv = nsServiceManager::GetService(kEventQueueServiceCID,
|
||||
NS_GET_IID(nsIEventQueueService),
|
||||
(nsISupports **)&eventQService);
|
||||
if (NS_OK == rv)
|
||||
{
|
||||
// get our hands on the thread event queue
|
||||
nsIEventQueue *eventQueue;
|
||||
rv = eventQService->GetThreadEventQueue( NS_CURRENT_THREAD,
|
||||
&eventQueue);
|
||||
if (NS_FAILED(rv))
|
||||
return FALSE;
|
||||
|
||||
io_identifier = gdk_input_add( eventQueue->GetEventQueueSelectFD(),
|
||||
GDK_INPUT_READ,
|
||||
handle_event_queue,
|
||||
eventQueue);
|
||||
NS_RELEASE(eventQService);
|
||||
NS_RELEASE(eventQueue);
|
||||
}
|
||||
|
||||
/* This is called in all GTK applications. Arguments are parsed
|
||||
* from the command line and are returned to the application. */
|
||||
gtk_init(&argc, &argv);
|
||||
|
||||
|
||||
if ( NS_FAILED( OpenWebPage("http://people.netscape.com/dougt") ))
|
||||
return (-1);
|
||||
|
||||
|
||||
/* All GTK applications must have a gtk_main(). Control ends here
|
||||
* and waits for an event to occur (like a key press or
|
||||
* mouse event). */
|
||||
gtk_main ();
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user