2003-06-25 01:08:26 +04:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: Mozilla-sample-code 1.0
|
|
|
|
*
|
|
|
|
* Copyright (c) 2002 Netscape Communications Corporation and
|
|
|
|
* other contributors
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this Mozilla sample software and associated documentation files
|
|
|
|
* (the "Software"), to deal in the Software without restriction, including
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
* distribute, sublicense, and/or sell copies of the Software, and to permit
|
|
|
|
* persons to whom the Software is furnished to do so, subject to the
|
|
|
|
* following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included
|
|
|
|
* in all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
* DEALINGS IN THE SOFTWARE.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Adam Lock <adamlock@netscape.com>
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
2003-06-25 00:15:14 +04:00
|
|
|
#include "global.h"
|
|
|
|
|
2003-07-03 01:52:42 +04:00
|
|
|
#include "wx/strconv.h"
|
|
|
|
|
2003-06-25 00:15:14 +04:00
|
|
|
#include "BrowserFrame.h"
|
|
|
|
|
|
|
|
#include "nsIURI.h"
|
|
|
|
|
2003-06-27 01:31:10 +04:00
|
|
|
BEGIN_EVENT_TABLE(BrowserFrame, GeckoFrame)
|
2003-06-25 02:59:43 +04:00
|
|
|
EVT_MENU(XRCID("browse_back"), BrowserFrame::OnBrowserBack)
|
|
|
|
EVT_UPDATE_UI(XRCID("browse_back"), BrowserFrame::OnUpdateBrowserBack)
|
|
|
|
EVT_MENU(XRCID("browse_fwd"), BrowserFrame::OnBrowserForward)
|
|
|
|
EVT_UPDATE_UI(XRCID("browse_fwd"), BrowserFrame::OnUpdateBrowserForward)
|
|
|
|
EVT_MENU(XRCID("browse_reload"), BrowserFrame::OnBrowserReload)
|
|
|
|
EVT_MENU(XRCID("browse_stop"), BrowserFrame::OnBrowserStop)
|
|
|
|
EVT_UPDATE_UI(XRCID("browse_stop"), BrowserFrame::OnUpdateBrowserStop)
|
|
|
|
EVT_MENU(XRCID("browse_home"), BrowserFrame::OnBrowserHome)
|
|
|
|
EVT_BUTTON(XRCID("browser_go"), BrowserFrame::OnBrowserGo)
|
|
|
|
EVT_TEXT_ENTER(XRCID("url"), BrowserFrame::OnBrowserUrl)
|
2003-07-03 01:52:42 +04:00
|
|
|
EVT_MENU(XRCID("browser_open_in_new_window"),
|
|
|
|
BrowserFrame::OnBrowserOpenLinkInNewWindow)
|
2003-06-25 00:15:14 +04:00
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
2003-06-27 01:31:10 +04:00
|
|
|
BrowserFrame::BrowserFrame(wxWindow* aParent)
|
2003-06-25 00:15:14 +04:00
|
|
|
{
|
|
|
|
wxXmlResource::Get()->LoadFrame(this, aParent, wxT("browser_frame"));
|
|
|
|
|
|
|
|
SetIcon(wxICON(appicon));
|
|
|
|
|
2003-07-01 00:49:06 +04:00
|
|
|
SetName("browser");
|
|
|
|
|
2003-06-27 01:31:10 +04:00
|
|
|
SetupDefaultGeckoWindow();
|
2003-06-25 00:15:14 +04:00
|
|
|
|
|
|
|
CreateStatusBar();
|
2003-07-03 01:52:42 +04:00
|
|
|
}
|
2003-07-01 00:49:06 +04:00
|
|
|
|
2003-07-03 01:52:42 +04:00
|
|
|
|
|
|
|
nsresult BrowserFrame::LoadURI(const wchar_t *aURI)
|
|
|
|
{
|
|
|
|
if (mWebBrowser)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIWebNavigation> webNav = do_QueryInterface(mWebBrowser);
|
|
|
|
if (webNav)
|
|
|
|
{
|
|
|
|
return webNav->LoadURI(aURI,
|
|
|
|
nsIWebNavigation::LOAD_FLAGS_NONE,
|
|
|
|
nsnull,
|
|
|
|
nsnull,
|
|
|
|
nsnull);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsresult BrowserFrame::LoadURI(const char *aURI)
|
|
|
|
{
|
|
|
|
wxMBConv conv;
|
|
|
|
return LoadURI(conv.cWX2WC(aURI));
|
2003-06-25 00:15:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Browser specific handlers
|
|
|
|
|
|
|
|
|
2003-07-01 00:49:06 +04:00
|
|
|
void BrowserFrame::OnFileSave(wxCommandEvent & WXUNUSED(event))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserFrame::OnFilePrint(wxCommandEvent & WXUNUSED(event))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2003-06-25 00:15:14 +04:00
|
|
|
void BrowserFrame::OnBrowserGo(wxCommandEvent & WXUNUSED(event))
|
|
|
|
{
|
2003-07-03 01:52:42 +04:00
|
|
|
wxTextCtrl *txtCtrl = (wxTextCtrl *) FindWindowById(XRCID("url"), this);
|
|
|
|
wxString url = txtCtrl->GetValue();
|
|
|
|
if (!url.IsEmpty())
|
2003-06-25 00:15:14 +04:00
|
|
|
{
|
2003-07-03 01:52:42 +04:00
|
|
|
LoadURI(url);
|
2003-06-25 00:15:14 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserFrame::OnBrowserUrl(wxCommandEvent & event)
|
|
|
|
{
|
|
|
|
OnBrowserGo(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserFrame::OnBrowserBack(wxCommandEvent & WXUNUSED(event))
|
|
|
|
{
|
2003-06-27 01:31:10 +04:00
|
|
|
if (mWebBrowser)
|
2003-06-25 00:15:14 +04:00
|
|
|
{
|
2003-06-27 01:31:10 +04:00
|
|
|
nsCOMPtr<nsIWebNavigation> webNav = do_QueryInterface(mWebBrowser);
|
2003-06-25 00:15:14 +04:00
|
|
|
webNav->GoBack();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-06-25 02:59:43 +04:00
|
|
|
void BrowserFrame::OnUpdateBrowserBack(wxUpdateUIEvent &event)
|
|
|
|
{
|
|
|
|
PRBool canGoBack = PR_FALSE;
|
2003-06-27 01:31:10 +04:00
|
|
|
if (mWebBrowser)
|
2003-06-25 02:59:43 +04:00
|
|
|
{
|
2003-06-27 01:31:10 +04:00
|
|
|
nsCOMPtr<nsIWebNavigation> webNav = do_QueryInterface(mWebBrowser);
|
2003-06-25 02:59:43 +04:00
|
|
|
webNav->GetCanGoBack(&canGoBack);
|
|
|
|
}
|
|
|
|
event.Enable(canGoBack);
|
|
|
|
}
|
|
|
|
|
2003-06-25 00:15:14 +04:00
|
|
|
void BrowserFrame::OnBrowserForward(wxCommandEvent & WXUNUSED(event))
|
|
|
|
{
|
2003-06-27 01:31:10 +04:00
|
|
|
if (mWebBrowser)
|
2003-06-25 00:15:14 +04:00
|
|
|
{
|
2003-06-27 01:31:10 +04:00
|
|
|
nsCOMPtr<nsIWebNavigation> webNav = do_QueryInterface(mWebBrowser);
|
2003-06-25 00:15:14 +04:00
|
|
|
webNav->GoForward();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-06-25 02:59:43 +04:00
|
|
|
void BrowserFrame::OnUpdateBrowserForward(wxUpdateUIEvent &event)
|
|
|
|
{
|
|
|
|
PRBool canGoForward = PR_FALSE;
|
2003-06-27 01:31:10 +04:00
|
|
|
if (mWebBrowser)
|
2003-06-25 02:59:43 +04:00
|
|
|
{
|
2003-06-27 01:31:10 +04:00
|
|
|
nsCOMPtr<nsIWebNavigation> webNav = do_QueryInterface(mWebBrowser);
|
2003-06-25 02:59:43 +04:00
|
|
|
webNav->GetCanGoForward(&canGoForward);
|
|
|
|
}
|
|
|
|
event.Enable(canGoForward);
|
|
|
|
}
|
|
|
|
|
2003-06-25 00:15:14 +04:00
|
|
|
void BrowserFrame::OnBrowserReload(wxCommandEvent & WXUNUSED(event))
|
|
|
|
{
|
2003-06-27 01:31:10 +04:00
|
|
|
if (mWebBrowser)
|
2003-06-25 00:15:14 +04:00
|
|
|
{
|
2003-06-27 01:31:10 +04:00
|
|
|
nsCOMPtr<nsIWebNavigation> webNav = do_QueryInterface(mWebBrowser);
|
2003-06-25 00:15:14 +04:00
|
|
|
webNav->Reload(nsIWebNavigation::LOAD_FLAGS_NONE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserFrame::OnBrowserStop(wxCommandEvent & WXUNUSED(event))
|
|
|
|
{
|
2003-06-27 01:31:10 +04:00
|
|
|
if (mWebBrowser)
|
2003-06-25 00:15:14 +04:00
|
|
|
{
|
2003-06-27 01:31:10 +04:00
|
|
|
nsCOMPtr<nsIWebNavigation> webNav = do_QueryInterface(mWebBrowser);
|
2003-06-25 00:15:14 +04:00
|
|
|
webNav->Stop(nsIWebNavigation::STOP_ALL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-06-25 02:59:43 +04:00
|
|
|
void BrowserFrame::OnUpdateBrowserStop(wxUpdateUIEvent &event)
|
|
|
|
{
|
|
|
|
event.Enable(mBusy);
|
|
|
|
}
|
|
|
|
|
2003-06-25 00:15:14 +04:00
|
|
|
void BrowserFrame::OnBrowserHome(wxCommandEvent & WXUNUSED(event))
|
|
|
|
{
|
2003-07-03 01:52:42 +04:00
|
|
|
LoadURI("http://www.mozilla.org/projects/embedding/");
|
2003-06-25 00:15:14 +04:00
|
|
|
}
|
|
|
|
|
2003-07-03 01:52:42 +04:00
|
|
|
void BrowserFrame::OnBrowserOpenLinkInNewWindow(wxCommandEvent & WXUNUSED(event))
|
|
|
|
{
|
|
|
|
BrowserFrame* frame = new BrowserFrame(NULL);
|
|
|
|
frame->Show(TRUE);
|
|
|
|
frame->LoadURI(mContextLinkUrl.get());
|
|
|
|
}
|
2003-06-25 00:15:14 +04:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// GeckoContainerUI overrides
|
|
|
|
|
2003-06-25 01:08:26 +04:00
|
|
|
nsresult BrowserFrame::CreateBrowserWindow(PRUint32 aChromeFlags,
|
|
|
|
nsIWebBrowserChrome *aParent, nsIWebBrowserChrome **aNewWindow)
|
|
|
|
{
|
|
|
|
// Create the main frame window
|
|
|
|
BrowserFrame* frame = new BrowserFrame(NULL);
|
|
|
|
if (!frame)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
frame->Show(TRUE);
|
|
|
|
GeckoContainer *container = frame->mGeckoWnd->GetGeckoContainer();
|
|
|
|
return container->QueryInterface(NS_GET_IID(nsIWebBrowserChrome), (void **) aNewWindow);
|
|
|
|
}
|
|
|
|
|
2003-06-25 00:15:14 +04:00
|
|
|
void BrowserFrame::UpdateStatusBarText(const PRUnichar* aStatusText)
|
|
|
|
{
|
|
|
|
SetStatusText(aStatusText);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserFrame::UpdateCurrentURI()
|
|
|
|
{
|
2003-06-27 01:31:10 +04:00
|
|
|
if (mWebBrowser)
|
2003-06-25 00:15:14 +04:00
|
|
|
{
|
2003-06-27 01:31:10 +04:00
|
|
|
nsCOMPtr<nsIWebNavigation> webNav = do_QueryInterface(mWebBrowser);
|
2003-06-25 00:15:14 +04:00
|
|
|
nsCOMPtr<nsIURI> currentURI;
|
|
|
|
webNav->GetCurrentURI(getter_AddRefs(currentURI));
|
|
|
|
nsCAutoString spec;
|
|
|
|
currentURI->GetSpec(spec);
|
|
|
|
|
|
|
|
wxTextCtrl *txtCtrl = (wxTextCtrl *) FindWindowById(XRCID("url"), this);
|
|
|
|
if (txtCtrl)
|
|
|
|
{
|
|
|
|
txtCtrl->SetValue(spec.get());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-06-26 02:46:11 +04:00
|
|
|
|
|
|
|
#include "nsIDOMMouseEvent.h"
|
|
|
|
|
|
|
|
void BrowserFrame::ShowContextMenu(PRUint32 aContextFlags, nsIContextMenuInfo *aContextMenuInfo)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMEvent> event;
|
|
|
|
aContextMenuInfo->GetMouseEvent(getter_AddRefs(event));
|
|
|
|
if (!event)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2003-07-03 01:52:42 +04:00
|
|
|
|
|
|
|
mContextLinkUrl.SetLength(0);
|
|
|
|
|
2003-06-26 02:46:11 +04:00
|
|
|
nsCOMPtr<nsIDOMMouseEvent> mouseEvent = do_QueryInterface(event);
|
|
|
|
if (mouseEvent)
|
|
|
|
{
|
|
|
|
PRInt32 x, y;
|
2003-07-01 00:49:06 +04:00
|
|
|
mouseEvent->GetScreenX(&x);
|
|
|
|
mouseEvent->GetScreenY(&y);
|
2003-06-26 02:46:11 +04:00
|
|
|
|
|
|
|
char *menuName = NULL;
|
|
|
|
|
|
|
|
// CONTEXT_LINK <A>
|
|
|
|
// CONTEXT_IMAGE <IMG>
|
|
|
|
// CONTEXT_IMAGE | CONTEXT_LINK <IMG> with <A> as an ancestor
|
|
|
|
// CONTEXT_INPUT <INPUT>
|
|
|
|
// CONTEXT_INPUT | CONTEXT_IMAGE <INPUT> with type=image
|
|
|
|
// CONTEXT_TEXT <TEXTAREA>
|
|
|
|
// CONTEXT_DOCUMENT <HTML>
|
|
|
|
// CONTEXT_BACKGROUND_IMAGE <HTML> with background image
|
|
|
|
|
|
|
|
if (aContextFlags & nsIContextMenuListener2::CONTEXT_IMAGE)
|
|
|
|
{
|
|
|
|
if (aContextFlags & nsIContextMenuListener2::CONTEXT_LINK)
|
|
|
|
menuName = "context_browser_image"; // TODO
|
|
|
|
else if (aContextFlags & nsIContextMenuListener2::CONTEXT_INPUT)
|
|
|
|
menuName = "context_browser_image"; // TODO
|
|
|
|
else
|
|
|
|
menuName = "context_browser_image"; // TODO
|
|
|
|
}
|
|
|
|
else if (aContextFlags & nsIContextMenuListener2::CONTEXT_LINK)
|
|
|
|
{
|
|
|
|
menuName = "context_browser_link";
|
2003-07-03 01:52:42 +04:00
|
|
|
|
|
|
|
aContextMenuInfo->GetAssociatedLink(mContextLinkUrl);
|
2003-06-26 02:46:11 +04:00
|
|
|
}
|
|
|
|
else if (aContextFlags & nsIContextMenuListener2::CONTEXT_INPUT)
|
|
|
|
{
|
|
|
|
menuName = "context_browser_input";
|
|
|
|
}
|
|
|
|
else if (aContextFlags & nsIContextMenuListener2::CONTEXT_TEXT)
|
|
|
|
{
|
|
|
|
menuName = "context_browser_text";
|
|
|
|
}
|
|
|
|
else if (aContextFlags & nsIContextMenuListener2::CONTEXT_DOCUMENT)
|
|
|
|
{
|
|
|
|
menuName = "context_browser_document";
|
|
|
|
}
|
|
|
|
else if (aContextFlags & nsIContextMenuListener2::CONTEXT_BACKGROUND_IMAGE)
|
|
|
|
{
|
|
|
|
menuName = "context_browser_document";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!menuName)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Hack for Win32 that has a #define for LoadMenu
|
|
|
|
#undef LoadMenu
|
|
|
|
wxMenu *menu = wxXmlResource::Get()->LoadMenu(menuName);
|
|
|
|
if (menu)
|
2003-07-01 00:49:06 +04:00
|
|
|
{
|
|
|
|
int fX = 0, fY = 0;
|
|
|
|
// Make screen coords relative to the frame window for accurate
|
|
|
|
// popup menu position
|
|
|
|
GetPosition(&fX, &fY);
|
|
|
|
PopupMenu(menu, x - fX, y - fY);
|
|
|
|
}
|
2003-06-26 02:46:11 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|