Ton of changes. Basically using nsIWebBrowserChrome now.

valeski@netscape.com
47003
This commit is contained in:
dougt%netscape.com 2000-08-01 01:37:07 +00:00
Родитель 0ec3ab5882
Коммит 9673ce80c4
8 изменённых файлов: 254 добавлений и 373 удалений

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

@ -1,170 +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->SetTopLevelWindow(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;
mWebBrowser->GetDocShell(getter_AddRefs(rootDocShell));
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;
mWebBrowser->GetDocShell(getter_AddRefs(rootDocShell));
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, 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__ */

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

@ -29,8 +29,9 @@
#include "nsIDocShellTreeItem.h" #include "nsIDocShellTreeItem.h"
#include "nsIRequest.h" #include "nsIRequest.h"
#include "nsIChannel.h" #include "nsIChannel.h"
#include "nsCWebBrowser.h"
#include "nsWidgetsCID.h"
#include "WebBrowser.h"
#include "WebBrowserChrome.h" #include "WebBrowserChrome.h"
nsVoidArray WebBrowserChrome::sBrowserList; nsVoidArray WebBrowserChrome::sBrowserList;
@ -38,12 +39,11 @@ nsVoidArray WebBrowserChrome::sBrowserList;
WebBrowserChrome::WebBrowserChrome() WebBrowserChrome::WebBrowserChrome()
{ {
NS_INIT_REFCNT(); NS_INIT_REFCNT();
sBrowserList.AppendElement(this); mNativeWindow = nsnull;
} }
WebBrowserChrome::~WebBrowserChrome() WebBrowserChrome::~WebBrowserChrome()
{ {
sBrowserList.RemoveElement(this);
} }
//***************************************************************************** //*****************************************************************************
@ -58,7 +58,7 @@ NS_INTERFACE_MAP_BEGIN(WebBrowserChrome)
NS_INTERFACE_MAP_ENTRY(nsIInterfaceRequestor) NS_INTERFACE_MAP_ENTRY(nsIInterfaceRequestor)
NS_INTERFACE_MAP_ENTRY(nsIWebBrowserChrome) NS_INTERFACE_MAP_ENTRY(nsIWebBrowserChrome)
NS_INTERFACE_MAP_ENTRY(nsIBaseWindow) NS_INTERFACE_MAP_ENTRY(nsIBaseWindow)
// NS_INTERFACE_MAP_ENTRY(nsIWebProgressListener) NS_INTERFACE_MAP_ENTRY(nsIWebProgressListener) //optional
// NS_INTERFACE_MAP_ENTRY(nsIPrompt) // NS_INTERFACE_MAP_ENTRY(nsIPrompt)
NS_INTERFACE_MAP_END NS_INTERFACE_MAP_END
@ -93,9 +93,8 @@ NS_IMETHODIMP WebBrowserChrome::SetOverLink(const PRUnichar* aLink)
NS_IMETHODIMP WebBrowserChrome::GetWebBrowser(nsIWebBrowser** aWebBrowser) NS_IMETHODIMP WebBrowserChrome::GetWebBrowser(nsIWebBrowser** aWebBrowser)
{ {
NS_ENSURE_ARG_POINTER(aWebBrowser); NS_ENSURE_ARG_POINTER(aWebBrowser);
NS_ENSURE_TRUE(mBrowser, NS_ERROR_NOT_INITIALIZED); NS_ENSURE_TRUE(mWebBrowser, NS_ERROR_NOT_INITIALIZED);
*aWebBrowser = mWebBrowser;
*aWebBrowser = mBrowser;
NS_IF_ADDREF(*aWebBrowser); NS_IF_ADDREF(*aWebBrowser);
return NS_OK; return NS_OK;
@ -104,9 +103,9 @@ NS_IMETHODIMP WebBrowserChrome::GetWebBrowser(nsIWebBrowser** aWebBrowser)
NS_IMETHODIMP WebBrowserChrome::SetWebBrowser(nsIWebBrowser* aWebBrowser) NS_IMETHODIMP WebBrowserChrome::SetWebBrowser(nsIWebBrowser* aWebBrowser)
{ {
NS_ENSURE_ARG(aWebBrowser); // Passing nsnull is NOT OK NS_ENSURE_ARG(aWebBrowser); // Passing nsnull is NOT OK
NS_ENSURE_TRUE(mBrowser, NS_ERROR_NOT_INITIALIZED); NS_ENSURE_TRUE(mWebBrowser, NS_ERROR_NOT_INITIALIZED);
NS_ERROR("Who be calling me");
mBrowser = aWebBrowser; mWebBrowser = aWebBrowser;
return NS_OK; return NS_OK;
} }
@ -123,18 +122,38 @@ NS_IMETHODIMP WebBrowserChrome::SetChromeMask(PRUint32 aChromeMask)
} }
// in winEmbed.cpp
extern nativeWindow CreateNativeWindow(nsIWebBrowserChrome* chrome);
NS_IMETHODIMP WebBrowserChrome::GetNewBrowser(PRUint32 chromeMask, nsIWebBrowser **aWebBrowser) NS_IMETHODIMP WebBrowserChrome::GetNewBrowser(PRUint32 chromeMask, nsIWebBrowser **aWebBrowser)
{ {
NS_ENSURE_ARG_POINTER(aWebBrowser); NS_ENSURE_ARG_POINTER(aWebBrowser);
*aWebBrowser = nsnull; *aWebBrowser = nsnull;
extern WebBrowser * CreateWebBrowser(); mWebBrowser = do_CreateInstance(NS_WEBBROWSER_PROGID);
WebBrowser *aBrowser = CreateWebBrowser();
if (!aBrowser) if (!mWebBrowser)
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
return aBrowser->GetWebBrowser(aWebBrowser); mWebBrowser->SetTopLevelWindow(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;
} }
@ -145,28 +164,13 @@ NS_IMETHODIMP WebBrowserChrome::FindNamedBrowserItem(const PRUnichar* aName,
NS_ENSURE_ARG_POINTER(aBrowserItem); NS_ENSURE_ARG_POINTER(aBrowserItem);
*aBrowserItem = nsnull; *aBrowserItem = nsnull;
if (!mWebBrowser)
return NS_ERROR_FAILURE;
PRInt32 cnt = sBrowserList.Count(); nsCOMPtr<nsIDocShellTreeItem> docShellAsItem(do_QueryInterface(mWebBrowser));
for (int i = 0; i < cnt; cnt++)
{
WebBrowserChrome* aChrome = (WebBrowserChrome*) sBrowserList.ElementAt(cnt);
if (aChrome == this || !aChrome)
continue;
nsCOMPtr<nsIWebBrowser> webBrowser;
aChrome->GetWebBrowser(getter_AddRefs(webBrowser));
nsCOMPtr<nsIDocShellTreeItem> docShellAsItem(do_QueryInterface(webBrowser));
NS_ENSURE_TRUE(docShellAsItem, NS_ERROR_FAILURE); NS_ENSURE_TRUE(docShellAsItem, NS_ERROR_FAILURE);
docShellAsItem->FindItemWithName(aName, NS_STATIC_CAST(nsIWebBrowserChrome*, this), aBrowserItem); return docShellAsItem->FindItemWithName(aName, NS_STATIC_CAST(nsIWebBrowserChrome*, this), aBrowserItem);
if (*aBrowserItem)
break;
}
return NS_OK; // Return OK even if we didn't find it???
} }
NS_IMETHODIMP WebBrowserChrome::SizeBrowserTo(PRInt32 aCX, PRInt32 aCY) NS_IMETHODIMP WebBrowserChrome::SizeBrowserTo(PRInt32 aCX, PRInt32 aCY)
@ -180,6 +184,11 @@ NS_IMETHODIMP WebBrowserChrome::ShowAsModal(void)
return NS_ERROR_NOT_IMPLEMENTED; return NS_ERROR_NOT_IMPLEMENTED;
} }
NS_IMETHODIMP WebBrowserChrome::ExitModalEventLoop(nsresult aStatus)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP NS_IMETHODIMP
WebBrowserChrome::SetPersistence(PRBool aPersistX, PRBool aPersistY, WebBrowserChrome::SetPersistence(PRBool aPersistX, PRBool aPersistY,
@ -211,6 +220,10 @@ NS_IMETHODIMP WebBrowserChrome::OnProgressChange(nsIWebProgress *progress, nsIRe
NS_IMETHODIMP WebBrowserChrome::OnStateChange(nsIWebProgress *progress, nsIRequest *request, NS_IMETHODIMP WebBrowserChrome::OnStateChange(nsIWebProgress *progress, nsIRequest *request,
PRInt32 progressStateFlags, PRUint32 status) PRInt32 progressStateFlags, PRUint32 status)
{ {
if ((progressStateFlags & flag_stop) && (progressStateFlags & flag_is_request))
{
}
return NS_ERROR_NOT_IMPLEMENTED; return NS_ERROR_NOT_IMPLEMENTED;
} }
@ -255,37 +268,37 @@ NS_IMETHODIMP WebBrowserChrome::Destroy()
NS_IMETHODIMP WebBrowserChrome::SetPosition(PRInt32 x, PRInt32 y) NS_IMETHODIMP WebBrowserChrome::SetPosition(PRInt32 x, PRInt32 y)
{ {
return NS_ERROR_NOT_IMPLEMENTED; return mBaseWindow->SetPosition(x, y);
} }
NS_IMETHODIMP WebBrowserChrome::GetPosition(PRInt32* x, PRInt32* y) NS_IMETHODIMP WebBrowserChrome::GetPosition(PRInt32* x, PRInt32* y)
{ {
return NS_ERROR_NOT_IMPLEMENTED; return mBaseWindow->GetPosition(x, y);
} }
NS_IMETHODIMP WebBrowserChrome::SetSize(PRInt32 cx, PRInt32 cy, PRBool fRepaint) NS_IMETHODIMP WebBrowserChrome::SetSize(PRInt32 cx, PRInt32 cy, PRBool fRepaint)
{ {
return NS_ERROR_NOT_IMPLEMENTED; return mBaseWindow->SetSize(cx, cy, fRepaint);
} }
NS_IMETHODIMP WebBrowserChrome::GetSize(PRInt32* cx, PRInt32* cy) NS_IMETHODIMP WebBrowserChrome::GetSize(PRInt32* cx, PRInt32* cy)
{ {
return NS_ERROR_NOT_IMPLEMENTED; return mBaseWindow->GetSize(cx, cy);
} }
NS_IMETHODIMP WebBrowserChrome::SetPositionAndSize(PRInt32 x, PRInt32 y, PRInt32 cx, PRInt32 cy, PRBool fRepaint) NS_IMETHODIMP WebBrowserChrome::SetPositionAndSize(PRInt32 x, PRInt32 y, PRInt32 cx, PRInt32 cy, PRBool fRepaint)
{ {
return NS_ERROR_NOT_IMPLEMENTED; return mBaseWindow->SetPositionAndSize(x, y, cx, cy, fRepaint);
} }
NS_IMETHODIMP WebBrowserChrome::GetPositionAndSize(PRInt32* x, PRInt32* y, PRInt32* cx, PRInt32* cy) NS_IMETHODIMP WebBrowserChrome::GetPositionAndSize(PRInt32* x, PRInt32* y, PRInt32* cx, PRInt32* cy)
{ {
return NS_ERROR_NOT_IMPLEMENTED; return mBaseWindow->GetPositionAndSize(x, y, cx, cy);
} }
NS_IMETHODIMP WebBrowserChrome::Repaint(PRBool aForce) NS_IMETHODIMP WebBrowserChrome::Repaint(PRBool aForce)
{ {
return NS_ERROR_NOT_IMPLEMENTED; return mBaseWindow->Repaint(aForce);
} }
NS_IMETHODIMP WebBrowserChrome::GetParentWidget(nsIWidget** aParentWidget) NS_IMETHODIMP WebBrowserChrome::GetParentWidget(nsIWidget** aParentWidget)
@ -306,24 +319,24 @@ NS_IMETHODIMP WebBrowserChrome::GetParentNativeWindow(nativeWindow* aParentNativ
{ {
NS_ENSURE_ARG_POINTER(aParentNativeWindow); NS_ENSURE_ARG_POINTER(aParentNativeWindow);
NS_ASSERTION(PR_FALSE, "Not Yet Implemented"); *aParentNativeWindow = mNativeWindow;
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP WebBrowserChrome::SetParentNativeWindow(nativeWindow aParentNativeWindow) NS_IMETHODIMP WebBrowserChrome::SetParentNativeWindow(nativeWindow aParentNativeWindow)
{ {
NS_ASSERTION(PR_FALSE, "You can't call this"); mNativeWindow = aParentNativeWindow;
return NS_ERROR_NOT_IMPLEMENTED; return NS_OK;
} }
NS_IMETHODIMP WebBrowserChrome::GetVisibility(PRBool* aVisibility) NS_IMETHODIMP WebBrowserChrome::GetVisibility(PRBool* aVisibility)
{ {
return NS_ERROR_NOT_IMPLEMENTED; return mBaseWindow->GetVisibility(aVisibility);
} }
NS_IMETHODIMP WebBrowserChrome::SetVisibility(PRBool aVisibility) NS_IMETHODIMP WebBrowserChrome::SetVisibility(PRBool aVisibility)
{ {
return NS_ERROR_NOT_IMPLEMENTED; return mBaseWindow->SetVisibility(aVisibility);
} }
NS_IMETHODIMP WebBrowserChrome::GetMainWidget(nsIWidget** aMainWidget) NS_IMETHODIMP WebBrowserChrome::GetMainWidget(nsIWidget** aMainWidget)
@ -333,13 +346,13 @@ NS_IMETHODIMP WebBrowserChrome::GetMainWidget(nsIWidget** aMainWidget)
NS_IMETHODIMP WebBrowserChrome::SetFocus() NS_IMETHODIMP WebBrowserChrome::SetFocus()
{ {
return NS_ERROR_NOT_IMPLEMENTED; return mBaseWindow->SetFocus();
} }
NS_IMETHODIMP WebBrowserChrome::FocusAvailable(nsIBaseWindow* aCurrentFocus, NS_IMETHODIMP WebBrowserChrome::FocusAvailable(nsIBaseWindow* aCurrentFocus,
PRBool* aTookFocus) PRBool* aTookFocus)
{ {
return NS_ERROR_NOT_IMPLEMENTED; return mBaseWindow->FocusAvailable(aCurrentFocus, aTookFocus);
} }
NS_IMETHODIMP WebBrowserChrome::GetTitle(PRUnichar** aTitle) NS_IMETHODIMP WebBrowserChrome::GetTitle(PRUnichar** aTitle)

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

@ -23,8 +23,15 @@
#define __WebBrowserChrome__ #define __WebBrowserChrome__
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
#include "nsIGenericFactory.h"
#include "nsString.h"
#include "nsIWebBrowserChrome.h" #include "nsIWebBrowserChrome.h"
#include "nsIDocShell.h"
#include "nsIContentViewer.h"
#include "nsIContentViewerFile.h"
#include "nsIBaseWindow.h" #include "nsIBaseWindow.h"
#include "nsIWebNavigation.h"
#include "nsIWebProgressListener.h" #include "nsIWebProgressListener.h"
#include "nsIInterfaceRequestor.h" #include "nsIInterfaceRequestor.h"
#include "nsIPrompt.h" #include "nsIPrompt.h"
@ -32,6 +39,7 @@
#include "nsVoidArray.h" #include "nsVoidArray.h"
class WebBrowserChrome : public nsIWebBrowserChrome, class WebBrowserChrome : public nsIWebBrowserChrome,
public nsIWebProgressListener, public nsIWebProgressListener,
public nsIBaseWindow, public nsIBaseWindow,
@ -52,7 +60,11 @@ public:
protected: protected:
nsCOMPtr<nsIWebBrowser> mBrowser; nativeWindow mNativeWindow;
nsCOMPtr<nsIWebBrowser> mWebBrowser;
nsCOMPtr<nsIBaseWindow> mBaseWindow;
nsCOMPtr<nsIWebBrowserChrome> mTopWindow;
static nsVoidArray sBrowserList; static nsVoidArray sBrowserList;
}; };

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

@ -29,7 +29,7 @@ RESFILE = $(MODULE).res
OBJS = \ OBJS = \
.\$(OBJDIR)\winEmbed.obj \ .\$(OBJDIR)\winEmbed.obj \
.\$(OBJDIR)\WebBrowser.obj \ .\$(OBJDIR)\WebBrowserChrome.obj \
.\$(OBJDIR)\StdAfx.obj \ .\$(OBJDIR)\StdAfx.obj \
$(NULL) $(NULL)

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

@ -20,14 +20,20 @@
#define MOZ_Print 32772 #define MOZ_Print 32772
#define MOZ_NewBrowser 32773 #define MOZ_NewBrowser 32773
#define MOZ_NewEditor 32774 #define MOZ_NewEditor 32774
#define MOZ_Save 32775
#define MOZ_Cut 32776
#define MOZ_Copy 32777
#define MOZ_Paste 32778
#define MOZ_Delete 32779
#define MOZ_SelectAll 32780
#define IDC_STATIC -1 #define IDC_STATIC -1
// Next default values for new objects // Next default values for new objects
// //
#ifdef APSTUDIO_INVOKED #ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS #ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 129 #define _APS_NEXT_RESOURCE_VALUE 130
#define _APS_NEXT_COMMAND_VALUE 32775 #define _APS_NEXT_COMMAND_VALUE 32781
#define _APS_NEXT_CONTROL_VALUE 1002 #define _APS_NEXT_CONTROL_VALUE 1002
#define _APS_NEXT_SYMED_VALUE 110 #define _APS_NEXT_SYMED_VALUE 110
#endif #endif

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

@ -27,16 +27,15 @@
#include "resource.h" #include "resource.h"
#include "nsIContentViewerEdit.h"
#include "nsEmbedAPI.h" #include "nsEmbedAPI.h"
#include "WebBrowser.h"
#include "WebBrowserChrome.h" #include "WebBrowserChrome.h"
WebBrowser* CreateWebBrowser();
#define MAX_LOADSTRING 100 #define MAX_LOADSTRING 100
#define IDC_Status 100
// Global Variables: // Global Variables:
HINSTANCE hInst; HINSTANCE hInst;
TCHAR szTitle[MAX_LOADSTRING]; TCHAR szTitle[MAX_LOADSTRING];
@ -51,6 +50,55 @@ LRESULT CALLBACK GetURI(HWND, UINT, WPARAM, LPARAM);
char gLastURI[100]; char gLastURI[100];
// utility function
nsresult ResizeEmbedding(nsIWebBrowserChrome* chrome)
{
if (!chrome)
return NS_ERROR_FAILURE;
nsCOMPtr<nsIBaseWindow> baseWindow = do_QueryInterface(chrome);
HWND hWnd;
baseWindow->GetParentNativeWindow((void**)&hWnd);
if (!hWnd)
return NS_ERROR_NULL_POINTER;
RECT rect;
GetClientRect(hWnd, &rect);
rect.top += 32;
rect.bottom -= 32;
baseWindow->SetPositionAndSize(rect.left,
rect.top,
rect.right - rect.left,
rect.bottom - rect.top,
PR_TRUE);
baseWindow->SetVisibility(PR_TRUE);
return NS_OK;
}
nsresult OpenWebPage(char* url)
{
WebBrowserChrome * chrome = new WebBrowserChrome();
if (!chrome)
return NS_ERROR_FAILURE;
NS_ADDREF(chrome); // native window will hold the addref.
nsCOMPtr<nsIWebBrowser> newBrowser;
chrome->GetNewBrowser(0, getter_AddRefs(newBrowser));
if (!newBrowser)
return NS_ERROR_FAILURE;
// Place it where we want it.
ResizeEmbedding(NS_STATIC_CAST(nsIWebBrowserChrome*, chrome));
nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(newBrowser));
return webNav->LoadURI(NS_ConvertASCIItoUCS2(url).GetUnicode());
}
int main () int main ()
{ {
@ -69,10 +117,7 @@ int main ()
// put up at lease on browser window .... // put up at lease on browser window ....
///////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////
WebBrowser* newBrowser = CreateWebBrowser(); OpenWebPage("http://people.netscape.com/dougt");
if (!newBrowser)
return -1;
newBrowser->GoTo("http://people.netscape.com/dougt");
///////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////
@ -83,7 +128,7 @@ int main ()
DispatchMessage(&msg); DispatchMessage(&msg);
} }
// Close down Embedding APIs // Close down Embedding APIs
NS_TermEmbedding(); NS_TermEmbedding();
return msg.wParam; return msg.wParam;
@ -127,24 +172,11 @@ ATOM MyRegisterClass(HINSTANCE hInstance)
WebBrowser * CreateWebBrowser() nativeWindow CreateNativeWindow(nsIWebBrowserChrome* chrome)
{ {
HWND mainWindow;
STARTUPINFO StartupInfo; mainWindow = CreateWindow( szWindowClass,
StartupInfo.dwFlags = 0;
GetStartupInfo( &StartupInfo );
HINSTANCE hInstance = GetModuleHandle(NULL);
int nCmdShow = StartupInfo.dwFlags & STARTF_USESHOWWINDOW ? StartupInfo.wShowWindow : SW_SHOWDEFAULT;
WebBrowser *browser = new WebBrowser();
if (! browser)
return NULL;
HWND hWnd;
hWnd = CreateWindow( szWindowClass,
szTitle, szTitle,
WS_OVERLAPPEDWINDOW, WS_OVERLAPPEDWINDOW,
0, 0,
@ -153,31 +185,18 @@ WebBrowser * CreateWebBrowser()
450, 450,
NULL, NULL,
NULL, NULL,
hInstance, GetModuleHandle(NULL),
NULL); NULL);
if (!hWnd) if (!mainWindow)
{
return NULL;
}
SetWindowLong( hWnd, GWL_USERDATA, (LONG)browser); // save the browser LONG_PTR.
WebBrowserChrome* chrome = nsnull;//new WebBrowserChrome();
if ( NS_FAILED( browser->Init(hWnd, chrome) ) ) // this will own hWnd
return NULL; return NULL;
RECT rect; SetWindowLong( mainWindow, GWL_USERDATA, (LONG)chrome); // save the browser LONG_PTR.
GetClientRect(hWnd, &rect);
rect.top += 32;
browser->SetPositionAndSize(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top); ShowWindow(mainWindow, SW_SHOWDEFAULT);
UpdateWindow(mainWindow);
ShowWindow(hWnd, nCmdShow); return mainWindow;
UpdateWindow(hWnd);
return browser;
} }
// //
@ -197,7 +216,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
HDC hdc; HDC hdc;
TCHAR szHello[MAX_LOADSTRING]; TCHAR szHello[MAX_LOADSTRING];
LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING); LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING);
WebBrowser *browser = (WebBrowser *) GetWindowLong(hWnd, GWL_USERDATA); nsIWebBrowserChrome *chrome = (nsIWebBrowserChrome *) GetWindowLong(hWnd, GWL_USERDATA);
switch (message) switch (message)
{ {
@ -207,49 +226,99 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
// Parse the menu selections: // Parse the menu selections:
switch (wmId) switch (wmId)
{ {
case IDM_EXIT:
if (browser)
delete browser;
DestroyWindow(hWnd);
break;
case MOZ_NewBrowser: case MOZ_NewBrowser:
gLastURI[0] = 0; gLastURI[0] = 0;
if (DialogBox(hInst, (LPCTSTR)MOZ_GetURI, hWnd, (DLGPROC)GetURI)) if (DialogBox(hInst, (LPCTSTR)MOZ_GetURI, hWnd, (DLGPROC)GetURI))
{ OpenWebPage(gLastURI);
WebBrowser* newBrowser = CreateWebBrowser();
if (!newBrowser)
break;
newBrowser->GoTo(gLastURI);
}
break; break;
case MOZ_NewEditor: case MOZ_NewEditor:
gLastURI[0] = 0; gLastURI[0] = 0;
if (DialogBox(hInst, (LPCTSTR)MOZ_GetURI, hWnd, (DLGPROC)GetURI))
{
WebBrowser* newBrowser = CreateWebBrowser();
if (!newBrowser)
break;
newBrowser->Edit(gLastURI);
}
break; break;
case MOZ_Open: case MOZ_Open:
gLastURI[0] = 0; gLastURI[0] = 0;
if (browser && DialogBox(hInst, (LPCTSTR)MOZ_GetURI, hWnd, (DLGPROC)GetURI)) if (chrome && DialogBox(hInst, (LPCTSTR)MOZ_GetURI, hWnd, (DLGPROC)GetURI))
{ {
browser->GoTo(gLastURI); nsCOMPtr<nsIWebBrowser> wb;
chrome->GetWebBrowser(getter_AddRefs(wb));
nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(wb));
webNav->LoadURI(NS_ConvertASCIItoUCS2(gLastURI).GetUnicode());
}
break;
case MOZ_Save:
if (chrome)
{
nsCOMPtr<nsIWebBrowser> wb;
chrome->GetWebBrowser(getter_AddRefs(wb));
nsCOMPtr <nsIDocShell> rootDocShell;
wb->GetDocShell(getter_AddRefs(rootDocShell));
nsCOMPtr<nsIContentViewer> pContentViewer;
nsresult res = rootDocShell->GetContentViewer(getter_AddRefs(pContentViewer));
if (NS_SUCCEEDED(res))
{
nsCOMPtr<nsIContentViewerFile> spContentViewerFile = do_QueryInterface(pContentViewer);
spContentViewerFile->Save();
}
} }
break; break;
case MOZ_Print: case MOZ_Print:
if (browser) if (chrome)
browser->Print(); {
// editor->SetTextProperty(NS_ConvertASCIItoUCS2("font").GetUnicode(), nsCOMPtr<nsIWebBrowser> wb;
// NS_ConvertASCIItoUCS2("color").GetUnicode(), chrome->GetWebBrowser(getter_AddRefs(wb));
// NS_ConvertASCIItoUCS2("BLUE").GetUnicode());
nsCOMPtr <nsIDocShell> rootDocShell;
wb->GetDocShell(getter_AddRefs(rootDocShell));
nsCOMPtr<nsIContentViewer> pContentViewer;
nsresult res = rootDocShell->GetContentViewer(getter_AddRefs(pContentViewer));
if (NS_SUCCEEDED(res))
{
nsCOMPtr<nsIContentViewerFile> spContentViewerFile = do_QueryInterface(pContentViewer);
spContentViewerFile->Print(PR_TRUE, nsnull);
}
}
break;
case MOZ_Cut:
case MOZ_Copy:
case MOZ_Paste:
case MOZ_SelectAll:
if (chrome)
{
nsCOMPtr<nsIWebBrowser> wb;
chrome->GetWebBrowser(getter_AddRefs(wb));
nsCOMPtr <nsIDocShell> rootDocShell;
wb->GetDocShell(getter_AddRefs(rootDocShell));
nsCOMPtr<nsIContentViewer> pContentViewer;
nsresult res = rootDocShell->GetContentViewer(getter_AddRefs(pContentViewer));
if (NS_SUCCEEDED(res))
{
nsCOMPtr<nsIContentViewerEdit> spContentViewerEdit = do_QueryInterface(pContentViewer);
if (message == MOZ_Cut)
spContentViewerEdit->CopySelection();
else if (message == MOZ_Copy)
spContentViewerEdit->CutSelection();
else if (message == MOZ_SelectAll)
spContentViewerEdit->SelectAll();
}
}
break; break;
default: default:
@ -258,11 +327,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
break; break;
case WM_SIZE: case WM_SIZE:
RECT rect; ResizeEmbedding(chrome);
GetClientRect(hWnd, &rect);
rect.top += 32;
if (browser)
browser->SetPositionAndSize(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top);
break; break;
case WM_PAINT: case WM_PAINT:
@ -284,6 +349,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
case WM_DESTROY: case WM_DESTROY:
PostQuitMessage(0); PostQuitMessage(0);
NS_RELEASE(chrome);
break; break;
default: default:
return DefWindowProc(hWnd, message, wParam, lParam); return DefWindowProc(hWnd, message, wParam, lParam);

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

@ -44,11 +44,21 @@ BEGIN
POPUP "&File" POPUP "&File"
BEGIN BEGIN
MENUITEM "New Browser...", MOZ_NewBrowser MENUITEM "New Browser...", MOZ_NewBrowser
MENUITEM "New Editor...", MOZ_NewEditor MENUITEM "Goto...", MOZ_Open
MENUITEM "Change Current URL...", MOZ_Open MENUITEM SEPARATOR
MENUITEM "Save...", MOZ_Save
MENUITEM "Print Page", MOZ_Print MENUITEM "Print Page", MOZ_Print
MENUITEM "E&xit", IDM_EXIT MENUITEM "E&xit", IDM_EXIT
END END
POPUP "&Edit"
BEGIN
MENUITEM "Cut", MOZ_Cut
MENUITEM "Copy", MOZ_Copy
MENUITEM "Paste", MOZ_Paste, GRAYED
MENUITEM "Delete", MOZ_Delete, GRAYED
MENUITEM SEPARATOR
MENUITEM "Select All", MOZ_SelectAll
END
END END
@ -62,10 +72,10 @@ STYLE DS_MODALFRAME | WS_CAPTION | WS_SYSMENU
CAPTION "Enter A URL" CAPTION "Enter A URL"
FONT 8, "System" FONT 8, "System"
BEGIN BEGIN
ICON IDI_WINEMBED,IDC_MYICON,8,4,20,20 EDITTEXT MOZ_EDIT_URI,34,33,182,14,ES_AUTOHSCROLL
DEFPUSHBUTTON "OK",IDOK,182,55,30,11,WS_GROUP DEFPUSHBUTTON "OK",IDOK,182,55,30,11,WS_GROUP
PUSHBUTTON "Cancel",IDNO,146,55,30,11,WS_GROUP PUSHBUTTON "Cancel",IDNO,146,55,30,11,WS_GROUP
EDITTEXT MOZ_EDIT_URI,34,33,182,14,ES_AUTOHSCROLL ICON IDI_WINEMBED,IDC_MYICON,8,4,20,20
LTEXT "URL:",IDC_STATIC,13,34,17,8 LTEXT "URL:",IDC_STATIC,13,34,17,8
END END