diff --git a/mozilla/embedding/browser/powerplant/PP Browser.mcp b/mozilla/embedding/browser/powerplant/PP Browser.mcp new file mode 100644 index 00000000000..0f9c7ffff62 Binary files /dev/null and b/mozilla/embedding/browser/powerplant/PP Browser.mcp differ diff --git a/mozilla/embedding/browser/powerplant/precompiled header/BrowserHeaders.pch++ b/mozilla/embedding/browser/powerplant/precompiled header/BrowserHeaders.pch++ new file mode 100755 index 00000000000..3c3f2ad5cda --- /dev/null +++ b/mozilla/embedding/browser/powerplant/precompiled header/BrowserHeaders.pch++ @@ -0,0 +1,11 @@ +//-------------------------------------------------------------------------------- +// +// BrowserHeaders.pch++ +// +// Includes BrowserHeaders.pch.h, which generates or loads the precompiled header file +// Flags could be set here to control that compilation +// +//-------------------------------------------------------------------------------- + +#define wantDebugging 0 +#include "BrowserHeaders.pch.h" diff --git a/mozilla/embedding/browser/powerplant/precompiled header/BrowserHeaders.pch.h b/mozilla/embedding/browser/powerplant/precompiled header/BrowserHeaders.pch.h new file mode 100644 index 00000000000..55ee040f7f9 --- /dev/null +++ b/mozilla/embedding/browser/powerplant/precompiled header/BrowserHeaders.pch.h @@ -0,0 +1,73 @@ +// =============================================================================== +// Appearance_DebugHeaders.pch++ ©1995-1998 Metrowerks Inc. All rights reserved. +// =============================================================================== + +#ifndef __BROWSERHEADERS_PCH_H__ +#define __BROWSERHEADERS_PCH_H__ + +// +// Source for precompiled header for PowerPlant headers +// +// This file #includes most header files for the PowerPlant library, +// as well as most of the Toolbox headers used by the PowerPlant library +// with all debugging symbols defined. + +#if __option(precompile) + #if __MWERKS__ >= 0x2100 + // slightly larger but much faster generation of pch files + #pragma faster_pch_gen on + #endif + + + // Option for using PowerPlant namespace + #define PP_Uses_PowerPlant_Namespace 0 // off, don't use PowerPlant namespace + + // establish some essential PowerPlant macros: + #define PP_StdDialogs_Option PP_StdDialogs_ClassicOnly // use classic standard dialog implementation + + // include powerplant headers + #if wantDebugging + #include + #else + #include + #endif + + + #if wantDebugging + #define DEBUG 1 + #else + #undef DEBUG + #endif + + #include "DefinesMac.h" + #include "DefinesMozilla.h" + + + // Support for automatically naming the precompiled header file ... + #if __POWERPC__ + #if wantDebugging + #pragma precompile_target "BrowserHeadersDebug_pch" + #else + #pragma precompile_target "BrowserHeaders_pch" + #endif + #else + #error "target currently unsupported" + #endif + +#else + + // Load the precompiled header file + #if __POWERPC__ + #if wantDebugging + #include "BrowserHeadersDebug_pch" + #else + #include "BrowserHeaders_pch" + #endif + #else + #error "target currently unsupported" + #endif + + +#endif + +#endif // __BROWSERHEADERS_PCH_H__ diff --git a/mozilla/embedding/browser/powerplant/precompiled header/BrowserHeadersDebug.pch++ b/mozilla/embedding/browser/powerplant/precompiled header/BrowserHeadersDebug.pch++ new file mode 100644 index 00000000000..a03d8d7b28e --- /dev/null +++ b/mozilla/embedding/browser/powerplant/precompiled header/BrowserHeadersDebug.pch++ @@ -0,0 +1,11 @@ +//-------------------------------------------------------------------------------- +// +// BrowserHeadersDebug.pch++ +// +// Includes BrowserHeaders.pch.h, which generates or loads the precompiled header file +// Flags could be set here to control that compilation +// +//-------------------------------------------------------------------------------- + +#define wantDebugging 1 +#include "BrowserHeaders.pch.h" diff --git a/mozilla/embedding/browser/powerplant/resources/Browser.ppob b/mozilla/embedding/browser/powerplant/resources/Browser.ppob new file mode 100644 index 00000000000..57f1c5401d1 Binary files /dev/null and b/mozilla/embedding/browser/powerplant/resources/Browser.ppob differ diff --git a/mozilla/embedding/browser/powerplant/resources/Browser.rsrc b/mozilla/embedding/browser/powerplant/resources/Browser.rsrc new file mode 100644 index 00000000000..aa106562524 Binary files /dev/null and b/mozilla/embedding/browser/powerplant/resources/Browser.rsrc differ diff --git a/mozilla/embedding/browser/powerplant/resources/cfmAlias.rsrc b/mozilla/embedding/browser/powerplant/resources/cfmAlias.rsrc new file mode 100644 index 00000000000..2fa48eef01b Binary files /dev/null and b/mozilla/embedding/browser/powerplant/resources/cfmAlias.rsrc differ diff --git a/mozilla/embedding/browser/powerplant/resources/cfmAliasDebug.rsrc b/mozilla/embedding/browser/powerplant/resources/cfmAliasDebug.rsrc new file mode 100644 index 00000000000..20a5a290a1a Binary files /dev/null and b/mozilla/embedding/browser/powerplant/resources/cfmAliasDebug.rsrc differ diff --git a/mozilla/embedding/browser/powerplant/source/ApplIDs.h b/mozilla/embedding/browser/powerplant/source/ApplIDs.h new file mode 100644 index 00000000000..6dfbdd08d1e --- /dev/null +++ b/mozilla/embedding/browser/powerplant/source/ApplIDs.h @@ -0,0 +1,51 @@ +/* -*- 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): + * Conrad Carlen + */ + +/* + * Declares application dependent IDs for resources, messages, on so on + * It is meant to be replaced or added to by any application using the + * classes in this project. The file name name should not be changed though or + * source files that include it will have to be changed. + */ + +#ifndef __ApplIDs__ +#define __ApplIDs__ + +//***************************************************************************** +//*** Resource IDs +//***************************************************************************** + +// Windows +const PP_PowerPlant::ResIDT wind_BrowserWindow = 129; + +// Dialogs +const PP_PowerPlant::ResIDT dlog_FindDialog = 1281; + + +//***************************************************************************** +//*** Message IDs +//***************************************************************************** + +const MessageT msg_OnStartLoadDocument = 1000; +const MessageT msg_OnEndLoadDocument = 1001; + +#endif // __ApplIDs__ diff --git a/mozilla/embedding/browser/powerplant/source/CBrowserApp.cp b/mozilla/embedding/browser/powerplant/source/CBrowserApp.cp new file mode 100644 index 00000000000..746da66affa --- /dev/null +++ b/mozilla/embedding/browser/powerplant/source/CBrowserApp.cp @@ -0,0 +1,383 @@ +/* -*- 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): + * Conrad Carlen + */ + +#include "CBrowserApp.h" + +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include + +#include + +#include "ApplIDs.h" +#include "CBrowserWindow.h" +#include "CBrowserShell.h" +#include "CUrlField.h" +#include "CThrobber.h" +#include "UMacUnicode.h" +#include "nsIImageManager.h" +#include "nsIServiceManager.h" +#include "nsIEventQueueService.h" +#include "nsIPref.h" +#include "macstdlibextras.h" +#include "SIOUX.h" + +#include + +extern "C" void NS_SetupRegistry(); + + +static NS_DEFINE_CID(kPrefCID, NS_PREF_CID); +static NS_DEFINE_IID(kIPrefIID, NS_IPREF_IID); + + +// =========================================================================== +// ¥ Main Program +// =========================================================================== + +int main() +{ + + SetDebugThrow_(PP_PowerPlant::debugAction_Alert); // Set Debugging options + SetDebugSignal_(PP_PowerPlant::debugAction_Alert); + + PP_PowerPlant::InitializeHeap(3); // Initialize Memory Manager + // Parameter is number of Master Pointer + // blocks to allocate + + + PP_PowerPlant::UQDGlobals::InitializeToolbox(&qd); // Initialize standard Toolbox managers + +#if DEBUG + ::InitializeSIOUX(false); +#endif + + ::InitTSMAwareApplication(); + + new PP_PowerPlant::LGrowZone(20000); // Install a GrowZone function to catch low memory situations. + + { + CBrowserApp theApp; // create instance of your application + + theApp.Run(); + } + + ::CloseTSMAwareApplication(); + + return 0; +} + + +// --------------------------------------------------------------------------- +// MMozillaApp constructor +// --------------------------------------------------------------------------- + +MMozillaApp::MMozillaApp() : + mpIEventQueueService(nsnull), mpIServiceManager(nsnull), + mpIPref(nsnull) +{ + nsresult rv = InitWebShellApp(); + if (rv != NS_OK) + ThrowOSErr_(rv); +} + +// --------------------------------------------------------------------------- +// MMozillaApp destructor +// --------------------------------------------------------------------------- + +MMozillaApp::~MMozillaApp() +{ + TermWebShellApp(); +} + +// --------------------------------------------------------------------------- +// MMozillaApp::InitWebShell +// --------------------------------------------------------------------------- +// Does once only initialization of WebShell. +// Called at application startup. + +nsresult MMozillaApp::InitWebShellApp() +{ + //RegisterClass_(CWebShell); + RegisterClass_(CBrowserShell); + RegisterClass_(CBrowserWindow); + RegisterClass_(CUrlField); + RegisterClass_(CThrobber); + + nsresult rv; + + // Initialize XPCOM + NS_InitXPCOM(&mpIServiceManager, nsnull); + + rv = nsComponentManager::AutoRegister(nsIComponentManager::NS_Startup, NULL /* default */); + if (NS_OK != rv) { + NS_ASSERTION(PR_FALSE, "Could not AutoRegister"); + return rv; + } + + // Initialize the Registry + NS_SetupRegistry(); + + // Create the Event Queue for the UI thread... + rv = nsServiceManager::GetService(NS_EVENTQUEUESERVICE_PROGID, + NS_GET_IID(nsIEventQueueService), + (nsISupports **)&mpIEventQueueService); + if (NS_OK != rv) { + NS_ASSERTION(PR_FALSE, "Could not obtain the event queue service"); + return rv; + } + + rv = mpIEventQueueService->CreateThreadEventQueue(); + if (NS_OK != rv) { + NS_ASSERTION(PR_FALSE, "Could not create the event queue for the thread"); + return rv; + } + + // Load preferences + rv = nsComponentManager::CreateInstance(kPrefCID, NULL, kIPrefIID, + (void **) &mpIPref); + if (NS_OK != rv) { + NS_ASSERTION(PR_FALSE, "Could not create prefs object"); + return rv; + } + + mpIPref->StartUp(); + mpIPref->ReadUserPrefs(); + + // HACK ALERT: Since we don't have profiles, we don't have prefs + // Reduce the default font size here by hand + mpIPref->SetIntPref("font.size.variable.x-western", 12); + mpIPref->SetIntPref("font.size.fixed.x-western", 9); + + return NS_OK; +} + + +// --------------------------------------------------------------------------- +// MMozillaApp::TermWebShell +// --------------------------------------------------------------------------- +// Does once per application run initialization of WebShell. +// Called at application quit time. + +void MMozillaApp::TermWebShellApp() +{ + nsresult rv; + + UMacUnicode::ReleaseUnit(); + + if (nsnull != mpIEventQueueService) { + nsServiceManager::ReleaseService(NS_EVENTQUEUESERVICE_PROGID, mpIEventQueueService); + mpIEventQueueService = nsnull; + } + + if (nsnull != mpIPref) { + mpIPref->ShutDown(); + NS_RELEASE(mpIPref); + } + + // Shutdown XPCOM? + rv = NS_ShutdownXPCOM(nsnull); + NS_ASSERTION(NS_SUCCEEDED(rv), "NS_ShutdownXPCOM failed"); + +} + + +// --------------------------------------------------------------------------- +// ¥ CBrowserApp +// --------------------------------------------------------------------------- +// Constructor + +CBrowserApp::CBrowserApp() +{ + if ( PP_PowerPlant::UEnvironment::HasFeature( PP_PowerPlant::env_HasAppearance ) ) { + ::RegisterAppearanceClient(); + } + + RegisterClass_(PP_PowerPlant::LWindow); // You must register each kind of + RegisterClass_(PP_PowerPlant::LCaption); // PowerPlant classes that you use in your PPob resource. + + // Register the Appearance Manager/GA classes + PP_PowerPlant::UControlRegistry::RegisterClasses(); + + SetSleepTime(0); +} + + +// --------------------------------------------------------------------------- +// ¥ ~CBrowserApp +// --------------------------------------------------------------------------- +// Destructor +// + +CBrowserApp::~CBrowserApp() +{ +} + +// --------------------------------------------------------------------------- +// ¥ StartUp +// --------------------------------------------------------------------------- +// This method lets you do something when the application starts up +// without a document. For example, you could issue your own new command. + +void +CBrowserApp::StartUp() +{ + ObeyCommand(PP_PowerPlant::cmd_New, nil); // EXAMPLE, create a new window +} + + +// --------------------------------------------------------------------------- +// ¥ ProcessNextEvent [public] +// --------------------------------------------------------------------------- +// Retrieve and handle the next event in the event queue + +void +CBrowserApp::ProcessNextEvent() +{ + EventRecord macEvent; + + // When on duty (application is in the foreground), adjust the + // cursor shape before waiting for the next event. Except for the + // very first time, this is the same as adjusting the cursor + // after every event. + + if (IsOnDuty()) { + + // Calling OSEventAvail with a zero event mask will always + // pass back a null event. However, it fills the EventRecord + // with the information we need to set the cursor shape-- + // the mouse location in global coordinates and the state + // of the modifier keys. + + ::OSEventAvail(0, &macEvent); + AdjustCursor(macEvent); + } + + // Retrieve the next event. Context switch could happen here. + + SetUpdateCommandStatus(false); + Boolean gotEvent = ::WaitNextEvent(everyEvent, &macEvent, mSleepTime, + mMouseRgn); + +#if DEBUG + // NOTE: SIOUX doesn't get any nullEvents because it rudely sets the + // cursor on nullEvents - even if the mouse is not over its window + if (gotEvent && SIOUXHandleOneEvent(&macEvent)) + return; +#endif + + // Let Attachments process the event. Continue with normal + // event dispatching unless suppressed by an Attachment. + + if (LAttachable::ExecuteAttachments(msg_Event, &macEvent)) { + if (gotEvent) { + DispatchEvent(macEvent); + } else { + UseIdleTime(macEvent); + } + } + + // Repeaters get time after every event + LPeriodical::DevoteTimeToRepeaters(macEvent); + + // Update status of menu items + if (IsOnDuty() && GetUpdateCommandStatus()) { + UpdateMenus(); + } +} + + +// --------------------------------------------------------------------------- +// ¥ ObeyCommand +// --------------------------------------------------------------------------- +// This method lets the application respond to commands like Menu commands + +Boolean +CBrowserApp::ObeyCommand( + PP_PowerPlant::CommandT inCommand, + void *ioParam) +{ + Boolean cmdHandled = true; + + switch (inCommand) { + + // Handle command messages (defined in PP_Messages.h). + case PP_PowerPlant::cmd_New: + + PP_PowerPlant::LWindow *theWindow = + PP_PowerPlant::LWindow::CreateWindow(wind_BrowserWindow, this); + ThrowIfNil_(theWindow); + + // LWindow is not initially visible in PPob resource + theWindow->Show(); + break; + + // Any that you don't handle, such as cmd_About and cmd_Quit, + // will be passed up to LApplication + default: + cmdHandled = PP_PowerPlant::LApplication::ObeyCommand(inCommand, ioParam); + break; + } + + return cmdHandled; +} + +// --------------------------------------------------------------------------- +// ¥ FindCommandStatus +// --------------------------------------------------------------------------- +// This function enables menu commands. +// + +void +CBrowserApp::FindCommandStatus( + PP_PowerPlant::CommandT inCommand, + Boolean &outEnabled, + Boolean &outUsesMark, + PP_PowerPlant::Char16 &outMark, + Str255 outName) +{ + + switch (inCommand) { + + // Return menu item status according to command messages. + case PP_PowerPlant::cmd_New: + outEnabled = true; + break; + + // Any that you don't handle, such as cmd_About and cmd_Quit, + // will be passed up to LApplication + default: + PP_PowerPlant::LApplication::FindCommandStatus(inCommand, outEnabled, + outUsesMark, outMark, outName); + break; + } +} diff --git a/mozilla/embedding/browser/powerplant/source/CBrowserApp.h b/mozilla/embedding/browser/powerplant/source/CBrowserApp.h new file mode 100644 index 00000000000..75bedfecdec --- /dev/null +++ b/mozilla/embedding/browser/powerplant/source/CBrowserApp.h @@ -0,0 +1,82 @@ +/* -*- 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): + * Conrad Carlen + */ + +#pragma once + +#include +#include + +#ifndef nsError_h +#include "nsError.h" +#endif + +class nsIEventQueueService; +class nsIServiceManager; +class nsIPref; + +// --------------------------------------------------------------------------- +// MMozillaApp - A class that can be mixed into an application class. It +// handles the startup and shutdown of mozilla. +// --------------------------------------------------------------------------- + +class MMozillaApp +{ + protected: + MMozillaApp(); + virtual ~MMozillaApp(); + + nsresult InitWebShellApp(); + void TermWebShellApp(); + + nsIEventQueueService *mpIEventQueueService; + nsIServiceManager *mpIServiceManager; + nsIPref *mpIPref; +}; + +// WARNING: CBrowserApp must descend from these in this order - we need +// the destructor for MMozillaApp to be called AFTER that of LApplication + +class CBrowserApp : public MMozillaApp, + public PP_PowerPlant::LApplication +{ + +public: + CBrowserApp(); // constructor registers PPobs + virtual ~CBrowserApp(); // stub destructor + + + virtual void ProcessNextEvent(); + + // this overriding method handles application commands + virtual Boolean ObeyCommand(PP_PowerPlant::CommandT inCommand, void* ioParam); + + + // this overriding method returns the status of menu items + virtual void FindCommandStatus(PP_PowerPlant::CommandT inCommand, + Boolean &outEnabled, Boolean &outUsesMark, + PP_PowerPlant::Char16 &outMark, Str255 outName); + +protected: + + virtual void StartUp(); // override startup functions + +}; diff --git a/mozilla/embedding/browser/powerplant/source/CBrowserShell.cpp b/mozilla/embedding/browser/powerplant/source/CBrowserShell.cpp new file mode 100644 index 00000000000..6e073da4e95 --- /dev/null +++ b/mozilla/embedding/browser/powerplant/source/CBrowserShell.cpp @@ -0,0 +1,605 @@ +/* -*- 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): + * Conrad Carlen + */ + +#ifndef __CBrowserShell__ +#include "CBrowserShell.h" +#endif + +#include "nsCWebBrowser.h" +#include "nsIComponentManager.h" +#include "nsComponentManagerUtils.h" +#include "nsWidgetsCID.h" +#include "nsRepeater.h" +#include "nsString.h" +#include "nsIWebBrowserChrome.h" +#include "nsIDocShell.h" +#include "nsIDocShellTreeOwner.h" +#include "nsIInterfaceRequestor.h" +#include "nsIWebProgressListener.h" + +#include "ApplIDs.h" +#include "CBrowserWindow.h" +#include "CFindComponent.h" +#include "UMacUnicode.h" + +// PowerPlant +#ifndef _H_LEditText +#include "LEditText.h" +#endif + +#ifndef _H_LCheckBox +#include "LCheckBox.h" +#endif + +static NS_DEFINE_IID(kWindowCID, NS_WINDOW_CID); + +// CBrowserShell static variables +nsMacMessageSink CBrowserShell::mMessageSink; + + +//***************************************************************************** +//*** CBrowserShell: constructors/destructor +//***************************************************************************** + +CBrowserShell::CBrowserShell() : + mFinder(nsnull) +{ + nsresult rv = CommonConstruct(); + if (rv != NS_OK) + Throw_Err(NS_ERROR_GET_CODE(rv)); // If this fails, there's no reason to live anymore :( +} + + +CBrowserShell::CBrowserShell(LStream* inStream) : + LView(inStream), + mFinder(nsnull) +{ + *inStream >> (StringPtr) mInitURL; + + nsresult rv = CommonConstruct(); + if (rv != NS_OK) + Throw_Err(NS_ERROR_GET_CODE(rv)); // If this fails, there's no reason to live anymore :( +} + + +CBrowserShell::~CBrowserShell() +{ + delete mFinder; + + // nsCOMPtr destructors, do your thing +} + + +NS_IMETHODIMP CBrowserShell::CommonConstruct() +{ + nsresult rv; + + mWebBrowser = do_CreateInstance(NS_WEBBROWSER_PROGID, &rv); + NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE); + + nsCOMPtr baseWin(do_QueryInterface(mWebBrowser)); + NS_ENSURE_TRUE(baseWin, NS_ERROR_FAILURE); + mWebBrowserAsBaseWin = baseWin; + + nsCOMPtr webNav(do_QueryInterface(mWebBrowser)); + NS_ENSURE_TRUE(webNav, NS_ERROR_FAILURE); + mWebBrowserAsWebNav = webNav; + + nsCOMPtr treeItem(do_QueryInterface(mWebBrowser)); + NS_ENSURE_TRUE(treeItem, NS_ERROR_FAILURE); + mWebBrowserAsTreeItem = treeItem; + + nsCOMPtr asProgress(do_QueryInterface(mWebBrowser)); + NS_ENSURE_TRUE(asProgress, NS_ERROR_FAILURE); + mWebBrowserAsProgress = asProgress; + + return NS_OK; +} + + +//***************************************************************************** +//*** CBrowserShell: LPane overrides +//***************************************************************************** + +void CBrowserShell::FinishCreateSelf() +{ + FocusDraw(); + + CBrowserWindow *ourWindow = dynamic_cast(LWindow::FetchWindowObject(GetMacPort())); + ThrowIfNil_(ourWindow); + ourWindow->AddListener(this); + + nsCOMPtr aWidget; + ourWindow->GetWidget(getter_AddRefs(aWidget)); + ThrowIfNil_(aWidget); + + Rect portFrame; + CalcPortFrameRect(portFrame); + nsRect r(portFrame.left, portFrame.top, portFrame.right - portFrame.left, portFrame.bottom - portFrame.top); + + mWebBrowserAsBaseWin->InitWindow(aWidget->GetNativeData(NS_NATIVE_WIDGET), nsnull, r.x, r.y, r.width, r.height); + mWebBrowserAsBaseWin->Create(); + + AdjustFrame(); + StartRepeating(); + StartListening(); +} + + +void CBrowserShell::ResizeFrameBy(SInt16 inWidthDelta, + SInt16 inHeightDelta, + Boolean inRefresh) +{ + LView::ResizeFrameBy(inWidthDelta, inHeightDelta, inRefresh); + AdjustFrame(); +} + + +void CBrowserShell::MoveBy(SInt32 inHorizDelta, + SInt32 inVertDelta, + Boolean inRefresh) +{ + LView::MoveBy(inHorizDelta, inVertDelta, inRefresh); + AdjustFrame(); +} + + +void CBrowserShell::ShowSelf() +{ + mWebBrowserAsBaseWin->SetVisibility(PR_TRUE); +} + + +void CBrowserShell::DrawSelf() +{ + EventRecord osEvent; + osEvent.what = updateEvt; + mMessageSink.DispatchOSEvent(osEvent, GetMacPort()); +} + + +void CBrowserShell::ClickSelf(const SMouseDownEvent &inMouseDown) +{ + if (!IsTarget()) + SwitchTarget(this); + + FocusDraw(); + mMessageSink.DispatchOSEvent((EventRecord&)inMouseDown.macEvent, GetMacPort()); +} + + +void CBrowserShell::EventMouseUp(const EventRecord &inMacEvent) +{ + FocusDraw(); + mMessageSink.DispatchOSEvent((EventRecord&)inMacEvent, GetMacPort()); +} + + +void CBrowserShell::AdjustCursorSelf(Point /* inPortPt */, + const EventRecord& /* inMacEvent */) +{ + // Do nothing - mozilla takes care of this during null events on mouse moved events +} + + +//***************************************************************************** +//*** CBrowserShell: LCommander overrides +//***************************************************************************** + +void CBrowserShell::DontBeTarget() +{ +} + + +Boolean CBrowserShell::HandleKeyPress(const EventRecord &inKeyEvent) +{ + // set the QuickDraw origin + FocusDraw(); + + // dispatch the event + Boolean keyHandled = mMessageSink.DispatchOSEvent((EventRecord&)inKeyEvent, GetMacPort()); + + return keyHandled; +} + + + +//***************************************************************************** +//*** CBrowserShell: LPeriodical overrides +//***************************************************************************** + +void CBrowserShell::SpendTime(const EventRecord& inMacEvent) +{ + + switch (inMacEvent.what) + { + case osEvt: + { + // The MacMessageSink will not set the cursor if we are in the background - which is right. + // We have to feed it suspendResumeMessages for it to know + + unsigned char eventType = ((inMacEvent.message >> 24) & 0x00ff); + if (eventType == mouseMovedMessage) + HandleMouseMoved(inMacEvent); + else if (eventType == suspendResumeMessage) + mMessageSink.DispatchOSEvent(const_cast(inMacEvent), GetMacPort()); + } + break; + + case nullEvent: + { + static Point lastWhere = {0, 0}; + + if ((*(long*)&lastWhere != *(long*)&inMacEvent.where)) + { + HandleMouseMoved(inMacEvent); + lastWhere = inMacEvent.where; + } + + Repeater::DoIdlers(inMacEvent); + // yield to other threads + ::PR_Sleep(PR_INTERVAL_NO_WAIT); + } + break; + } + + Repeater::DoRepeaters(inMacEvent); + +} + +//***************************************************************************** +//*** CBrowserShell: LListener overrides +//***************************************************************************** + +void CBrowserShell::ListenToMessage(MessageT inMessage, + void* ioParam) +{ + switch (inMessage) + { + case msg_OnStartLoadDocument: + case msg_OnEndLoadDocument: + break; + } +} + + +//***************************************************************************** +//*** CBrowserShell: +//***************************************************************************** + +NS_IMETHODIMP CBrowserShell::SetTopLevelWindow(nsIWebBrowserChrome * aTopLevelWindow) +{ + // Get the required interfaces from the chrome + nsCOMPtr windowAsProgListener(do_GetInterface(aTopLevelWindow)); + NS_ENSURE_TRUE(windowAsProgListener, NS_ERROR_INVALID_ARG); + + nsCOMPtr windowAsObserver(do_GetInterface(aTopLevelWindow)); + NS_ENSURE_TRUE(windowAsObserver, NS_ERROR_INVALID_ARG); + + mWebBrowser->SetTopLevelWindow(aTopLevelWindow); + mWebBrowserAsProgress->AddProgressListener(windowAsProgListener); + + // Get the docshell - we need to do some things directly to it + nsCOMPtr aDocShell; + mWebBrowser->GetDocShell(getter_AddRefs(aDocShell)); + NS_ENSURE_TRUE(aDocShell, NS_ERROR_FAILURE); + + aDocShell->SetDocLoaderObserver(windowAsObserver); + + return NS_OK; +} + + +//***************************************************************************** +//*** CBrowserShell: Navigation +//***************************************************************************** + +Boolean CBrowserShell::CanGoBack() +{ + PRBool canDo; + nsresult rv; + + rv = mWebBrowserAsWebNav->GetCanGoBack(&canDo); + return (NS_SUCCEEDED(rv) && canDo); +} + + +Boolean CBrowserShell::CanGoForward() +{ + PRBool canDo; + nsresult rv; + + rv = mWebBrowserAsWebNav->GetCanGoForward(&canDo); + return (NS_SUCCEEDED(rv) && canDo); +} + + +Boolean CBrowserShell::IsLoading() +{ + return false; +} + + +void CBrowserShell::Back() +{ + if (CanGoBack()) + mWebBrowserAsWebNav->GoBack(); + else + ::SysBeep(5); +} + +void CBrowserShell::Forward() +{ + if (CanGoForward()) + mWebBrowserAsWebNav->GoForward(); + else + ::SysBeep(5); +} + +void CBrowserShell::Stop() +{ + mWebBrowserAsWebNav->Stop(); +} + +//***************************************************************************** +//*** CBrowserShell: URL Loading +//***************************************************************************** + +void CBrowserShell::LoadURL(Ptr urlText, SInt32 urlTextLen) +{ + nsAutoString urlString(urlText, urlTextLen); + LoadURL(urlString); +} + + +void CBrowserShell::LoadURL(const nsString& urlText) +{ + nsresult rv = mWebBrowserAsWebNav->LoadURI(urlText.GetUnicode()); + if (NS_FAILED(rv)) + Throw_(NS_ERROR_GET_CODE(rv)); +} + + +//***************************************************************************** +//*** CBrowserShell: Text Searching +//***************************************************************************** + +Boolean CBrowserShell::Find() +{ + // Make sure we have a finder + nsresult rv = EnsureFinder(); + if (NS_FAILED(rv)) // Throw an exception?? + return FALSE; + + // Get the current find params from it + nsString searchString; + PRBool caseSensitive; + PRBool wrapSearch; + PRBool seachBackwards; + PRBool entireWord; + + mFinder->GetLastSearchString(searchString); + mFinder->GetLastCaseSensitive(caseSensitive); + mFinder->GetLastWrapSearch(wrapSearch); + mFinder->GetLastSearchBackwards(seachBackwards); + mFinder->GetLastEntireWord(entireWord); + + Boolean result = FALSE; + + if (GetFindParams(searchString, caseSensitive, seachBackwards, wrapSearch, entireWord)) + { + PRBool didFind; + + mFinder->Find(searchString, caseSensitive, seachBackwards, wrapSearch, entireWord, didFind); + result = (NS_SUCCEEDED(rv) && didFind); + if (!result) + ::SysBeep(1); + } + return result; +} + + +Boolean CBrowserShell::Find(const nsString& searchString, + Boolean caseSensitive, + Boolean searchBackwards, + Boolean wrapSearch, + Boolean entireWord) +{ + // Make sure we have a finder + nsresult rv = EnsureFinder(); + if (NS_FAILED(rv)) // Throw an exception?? + return FALSE; + + Boolean result; + PRBool didFind; + + rv = mFinder->Find(searchString, caseSensitive, searchBackwards, wrapSearch, entireWord, didFind); + result = (NS_SUCCEEDED(rv) && didFind); + if (!result) + ::SysBeep(1); + + return result; +} + +Boolean CBrowserShell::CanFindNext() +{ + if (!mFinder) + return FALSE; + + nsresult rv; + PRBool canDo; + + rv = mFinder->CanFindNext(canDo); + return (NS_SUCCEEDED(rv) && canDo); +} + + +Boolean CBrowserShell::FindNext() +{ + if (!mFinder) + { + SignalStringLiteral_("This should not be called until Find is called"); + return FALSE; + } + + Boolean result; + PRBool didFind; + + nsresult rv = mFinder->FindNext(didFind); + result = (NS_SUCCEEDED(rv) && didFind); + if (!result) + ::SysBeep(1); + + return result; +} + + +void CBrowserShell::HandleMouseMoved(const EventRecord& inMacEvent) +{ + if (IsActive()) + { + FocusDraw(); + mMessageSink.DispatchOSEvent(const_cast(inMacEvent), GetMacPort()); + } +} + + +void CBrowserShell::AdjustFrame() +{ + FocusDraw(); + + Rect portFrame; + CalcPortFrameRect(portFrame); + nsRect r(portFrame.left, portFrame.top, portFrame.right - portFrame.left, portFrame.bottom - portFrame.top); + + mWebBrowserAsBaseWin->SetPositionAndSize(r.x, r.y, r.width, r.height, PR_TRUE); +} + + +NS_METHOD CBrowserShell::EnsureFinder() +{ + nsCOMPtr ourDocShell; + mWebBrowser->GetDocShell(getter_AddRefs(ourDocShell)); + + if (mFinder) + { + // For now, we have to clear the context each time. + // The finder should be a nsIDocumentLoaderObserver and then + // it could clear itself when the contents of our docshell changed. + + mFinder->SetContext(nsnull); + mFinder->SetContext(ourDocShell); + return NS_OK; + } + + mFinder = new CFindComponent; + NS_ENSURE_TRUE(mFinder, NS_ERROR_OUT_OF_MEMORY); + mFinder->SetContext(ourDocShell); + + return NS_OK; +} + + +Boolean CBrowserShell::GetFindParams(nsString& searchText, + PRBool& caseSensitive, + PRBool& searchBackwards, + PRBool& wrapSearch, + PRBool& entireWord) +{ + enum + { + kSearchTextEdit = FOUR_CHAR_CODE('Text'), + kCaseSensitiveCheck = FOUR_CHAR_CODE('Case'), + kWrapAroundCheck = FOUR_CHAR_CODE('Wrap'), + kSearchBackwardsCheck = FOUR_CHAR_CODE('Back'), + kEntireWordCheck = FOUR_CHAR_CODE('Entr') + }; + + Boolean result; + + try + { + // Create stack-based object for handling the dialog box + + StDialogHandler theHandler(dlog_FindDialog, this); + LWindow *theDialog = theHandler.GetDialog(); + Str255 aStr; + + // Set initial text for string in dialog box + + UMacUnicode::StringToStr255(searchText, aStr); + + LEditText *editField = dynamic_cast(theDialog->FindPaneByID(kSearchTextEdit)); + editField->SetDescriptor(aStr); + theDialog->SetLatentSub(editField); + + LCheckBox *caseSensCheck, *entireWordCheck, *wrapAroundCheck, *backwardsCheck; + + caseSensCheck = dynamic_cast(theDialog->FindPaneByID(kCaseSensitiveCheck)); + ThrowIfNot_(caseSensCheck); + caseSensCheck->SetValue(caseSensitive ? 1 : 0); + entireWordCheck = dynamic_cast(theDialog->FindPaneByID(kEntireWordCheck)); + ThrowIfNot_(entireWordCheck); + entireWordCheck->SetValue(entireWord ? 1 : 0); + wrapAroundCheck = dynamic_cast(theDialog->FindPaneByID(kWrapAroundCheck)); + ThrowIfNot_(wrapAroundCheck); + wrapAroundCheck->SetValue(wrapSearch ? 1 : 0); + backwardsCheck = dynamic_cast(theDialog->FindPaneByID(kSearchBackwardsCheck)); + ThrowIfNot_(backwardsCheck); + backwardsCheck->SetValue(searchBackwards ? 1 : 0); + + theDialog->Show(); + + while (true) // This is our modal dialog event loop + { + MessageT hitMessage = theHandler.DoDialog(); + + if (hitMessage == msg_Cancel) + { + result = FALSE; + break; + + } + else if (hitMessage == msg_OK) + { + editField->GetDescriptor(aStr); + UMacUnicode::Str255ToString(aStr, searchText); + + caseSensitive = caseSensCheck->GetValue() ? TRUE : FALSE; + entireWord = entireWordCheck->GetValue() ? TRUE : FALSE; + wrapSearch = wrapAroundCheck->GetValue() ? TRUE : FALSE; + searchBackwards = backwardsCheck->GetValue() ? TRUE : FALSE; + + result = TRUE; + break; + } + } + } + catch (...) + { + result = FALSE; + // Don't propagate the error. + } + + return result; +} + diff --git a/mozilla/embedding/browser/powerplant/source/CBrowserShell.h b/mozilla/embedding/browser/powerplant/source/CBrowserShell.h new file mode 100644 index 00000000000..4d2f255d5c4 --- /dev/null +++ b/mozilla/embedding/browser/powerplant/source/CBrowserShell.h @@ -0,0 +1,143 @@ +/* -*- 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): + * Conrad Carlen + */ + +#ifndef __CBrowserShell__ +#define __CBrowserShell__ + +#include "nsIWebBrowser.h" +#include "nsIBaseWindow.h" +#include "nsIWebNavigation.h" +#include "nsIWidget.h" +#include "nsMacMessageSink.h" +#include "nsIDocShellTreeItem.h" +#include "nsIWebProgress.h" + +#ifndef nsCOMPtr_h___ +#include "nsCOMPtr.h" +#endif + +class CBrowserWindow; +class CURIContentListener; +class CFindComponent; + +//***************************************************************************** +//*** CBrowserShell +//***************************************************************************** + +class CBrowserShell : public LView, + public LCommander, + public LPeriodical, + public LListener +{ + +private: + typedef LView Inherited; + +public: + enum { class_ID = FOUR_CHAR_CODE('BroS') }; + + enum { cmd_Find = 'Find', cmd_FindNext = 'FNxt' }; + + CBrowserShell(); + CBrowserShell(LStream* inStream); + + virtual ~CBrowserShell(); + + + // LPane + virtual void FinishCreateSelf(); + virtual void ResizeFrameBy(SInt16 inWidthDelta, + SInt16 inHeightDelta, + Boolean inRefresh); + virtual void MoveBy(SInt32 inHorizDelta, + SInt32 inVertDelta, + Boolean inRefresh); + virtual void ShowSelf(); + virtual void DrawSelf(); + virtual void ClickSelf(const SMouseDownEvent &inMouseDown); + virtual void EventMouseUp(const EventRecord &inMacEvent); + virtual void AdjustCursorSelf(Point inPortPt, + const EventRecord& inMacEvent); + + // LCommander + virtual void DontBeTarget(); + virtual Boolean HandleKeyPress(const EventRecord &inKeyEvent); + + // LPeriodical + virtual void SpendTime(const EventRecord& inMacEvent); + + // LListener + virtual void ListenToMessage(MessageT inMessage, + void* ioParam); + + // CBrowserShell + NS_METHOD SetTopLevelWindow(nsIWebBrowserChrome * aTopLevelWindow); + + Boolean CanGoBack(); + Boolean CanGoForward(); + Boolean IsLoading(); + void Back(); + void Forward(); + void Stop(); + + void LoadURL(Ptr urlText, SInt32 urlTextLen); + void LoadURL(const nsString& urlText); + + // Puts up a find dialog and does the find operation + Boolean Find(); + // Does the find operation with the given params - no UI + Boolean Find(const nsString& searchStr, + Boolean caseSensitive, + Boolean searchBackward, + Boolean wrapSearch, + Boolean wholeWordOnly); + Boolean CanFindNext(); + Boolean FindNext(); + +protected: + NS_METHOD CommonConstruct(); + + void HandleMouseMoved(const EventRecord& inMacEvent); + void AdjustFrame(); + NS_METHOD EnsureFinder(); + virtual Boolean GetFindParams(nsString& searchText, + PRBool& caseSensitive, + PRBool& searchBackwards, + PRBool& wrapSearch, + PRBool& entireWord); + +protected: + static nsMacMessageSink mMessageSink; + + LStr255 mInitURL; + + nsCOMPtr mWebBrowser; // The thing we actually create + nsCOMPtr mWebBrowserAsBaseWin; // Convenience interface to above + nsCOMPtr mWebBrowserAsWebNav; // Ditto + nsCOMPtr mWebBrowserAsTreeItem; // Ditto + nsCOMPtr mWebBrowserAsProgress; // Ditto + + CFindComponent* mFinder; +}; + + +#endif // __CBrowserShell__ diff --git a/mozilla/embedding/browser/powerplant/source/CBrowserWindow.cp b/mozilla/embedding/browser/powerplant/source/CBrowserWindow.cp new file mode 100644 index 00000000000..5301a8af33e --- /dev/null +++ b/mozilla/embedding/browser/powerplant/source/CBrowserWindow.cp @@ -0,0 +1,376 @@ + +#include "nsString.h" +#include "nsWidgetsCID.h" +#include "nsIComponentManager.h" +#include "nsComponentManagerUtils.h" +#include "nsIChannel.h" +#include "nsIURI.h" +#include "nsXPIDLString.h" + +#include "CBrowserWindow.h" +#include "CBrowserShell.h" +#include "CWebBrowserChrome.h" +#include "CThrobber.h" +#include "ApplIDs.h" +#include "UMacUnicode.h" + +#include +#include +#include +#include + +// CBrowserWindow: +// A simple browser window that hooks up a CWebShell to a minimal set of controls +// (Back, Forward and Stop buttons + URL field + status bar). + + +enum +{ + paneID_BackButton = 'Back' +, paneID_ForwardButton = 'Forw' +, paneID_StopButton = 'Stop' +, paneID_URLField = 'gUrl' +, paneID_WebShellView = 'WebS' +, paneID_StatusBar = 'Stat' +, paneID_Throbber = 'THRB' +}; + +// CIDs +static NS_DEFINE_IID(kWindowCID, NS_WINDOW_CID); + +// --------------------------------------------------------------------------- +// ¥ CBrowserWindow Default Constructor [public] +// --------------------------------------------------------------------------- + +CBrowserWindow::CBrowserWindow() : + mBrowserShell(NULL), mBrowserChrome(NULL), + mURLField(NULL), mStatusBar(NULL), mThrobber(NULL), + mBackButton(NULL), mForwardButton(NULL), mStopButton(NULL) +{ + nsresult rv = CommonConstruct(); + if (NS_FAILED(rv)) + Throw_(NS_ERROR_GET_CODE(rv)); +} + + + +// --------------------------------------------------------------------------- +// ¥ CBrowserWindow Stream Constructor [public] +// --------------------------------------------------------------------------- + +CBrowserWindow::CBrowserWindow(LStream* inStream) + : LWindow(inStream), + mBrowserShell(NULL), mBrowserChrome(NULL), + mURLField(NULL), mStatusBar(NULL), mThrobber(NULL), + mBackButton(NULL), mForwardButton(NULL), mStopButton(NULL) +{ + nsresult rv = CommonConstruct(); + if (NS_FAILED(rv)) + Throw_(NS_ERROR_GET_CODE(rv)); +} + + +// --------------------------------------------------------------------------- +// ¥ ~CBrowserWindow Destructor [public] +// --------------------------------------------------------------------------- + +CBrowserWindow::~CBrowserWindow() +{ + if (mBrowserChrome) + { + mBrowserChrome->BrowserWindow(NULL); + NS_RELEASE(mBrowserChrome); + } +} + + +NS_IMETHODIMP CBrowserWindow::CommonConstruct() +{ + nsresult rv; + + // Make the base widget + mWindow = do_CreateInstance(kWindowCID, &rv); + NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE); + + // Make our CWebBrowserChrome + mBrowserChrome = new CWebBrowserChrome; + NS_ENSURE_TRUE(mBrowserChrome, NS_ERROR_OUT_OF_MEMORY); + NS_ADDREF(mBrowserChrome); + mBrowserChrome->BrowserWindow(this); + + return NS_OK; +} + + +void CBrowserWindow::FinishCreate() +{ + // Initialize the top level widget + // This needs to be done AFTER the subviews are constructed + // but BEFORE the subviews do FinishCreateSelf. + + Rect portRect = GetMacPort()->portRect; + nsRect r(0, 0, portRect.right - portRect.left, portRect.bottom - portRect.top); + + nsresult rv = mWindow->Create((nsNativeWidget)GetMacPort(), r, nsnull, nsnull, nsnull, nsnull, nsnull); + if (NS_FAILED(rv)) + Throw_(NS_ERROR_GET_CODE(rv)); + + Inherited::FinishCreate(); +} + + +// --------------------------------------------------------------------------- +// ¥ FinishCreateSelf +// --------------------------------------------------------------------------- + +void CBrowserWindow::FinishCreateSelf() +{ + mBrowserShell = dynamic_cast(FindPaneByID(paneID_WebShellView)); + ThrowIfNULL_(mBrowserShell); // Curtains if we don't have this + + // Tell our CBrowserShell about ourself + mBrowserShell->SetTopLevelWindow(mBrowserChrome); + + // Find our subviews - When we have a way of creating this + // window with various chrome flags, we may or may not have + // all of these subviews so don't fail if they don't exist + mURLField = dynamic_cast(FindPaneByID(paneID_URLField)); + if (mURLField) + SwitchTarget(mURLField); + + mStatusBar = dynamic_cast(FindPaneByID(paneID_StatusBar)); + mThrobber = dynamic_cast(FindPaneByID(paneID_Throbber)); + + mBackButton = dynamic_cast(FindPaneByID(paneID_BackButton)); + if (mBackButton) + mBackButton->Disable(); + mForwardButton = dynamic_cast(FindPaneByID(paneID_ForwardButton)); + if (mForwardButton) + mForwardButton->Disable(); + mStopButton = dynamic_cast(FindPaneByID(paneID_StopButton)); + if (mStopButton) + mStopButton->Disable(); + + UReanimator::LinkListenerToControls(this, this, mUserCon); + StartListening(); + StartBroadcasting(); + + // Just for demo sake, load a URL + LStr255 urlString("http://www.mozilla.org"); + mBrowserShell->LoadURL((Ptr)&urlString[1], urlString.Length()); +} + + +void CBrowserWindow::ResizeFrameBy(SInt16 inWidthDelta, + SInt16 inHeightDelta, + Boolean inRefresh) +{ + Inherited::ResizeFrameBy(inWidthDelta, inHeightDelta, inRefresh); + + Rect portRect = GetMacPort()->portRect; + mWindow->Resize(portRect.right - portRect.left, portRect.bottom - portRect.top, inRefresh); +} + + +void CBrowserWindow::ShowSelf() +{ + Inherited::ShowSelf(); + mWindow->Show(PR_TRUE); +} + + +// --------------------------------------------------------------------------- +// ¥ ListenToMessage +// --------------------------------------------------------------------------- + +void CBrowserWindow::ListenToMessage(MessageT inMessage, + void* ioParam) +{ + ProcessCommand(inMessage, ioParam); +} + +// --------------------------------------------------------------------------- +// ¥ ObeyCommand +// --------------------------------------------------------------------------- + +Boolean CBrowserWindow::ObeyCommand(CommandT inCommand, + void *ioParam) +{ +#pragma unused(ioParam) + + Boolean cmdHandled = true; + + switch (inCommand) + { + case paneID_BackButton: + mBrowserShell->Back(); + break; + + case paneID_ForwardButton: + mBrowserShell->Forward(); + break; + + case paneID_StopButton: + mBrowserShell->Stop(); + break; + + case paneID_URLField: + { + SInt32 urlTextLen; + mURLField->GetText(nil, 0, &urlTextLen); + StPointerBlock urlTextPtr(urlTextLen, true, false); + mURLField->GetText(urlTextPtr.Get(), urlTextLen, &urlTextLen); + mBrowserShell->LoadURL(urlTextPtr.Get(), urlTextLen); + } + break; + + case CBrowserShell::cmd_Find: + mBrowserShell->Find(); + break; + + case CBrowserShell::cmd_FindNext: + mBrowserShell->FindNext(); + break; + + default: + cmdHandled = false; + break; + } + + if (!cmdHandled) + cmdHandled = Inherited::ObeyCommand(inCommand, ioParam); + return cmdHandled; +} + + +// --------------------------------------------------------------------------- +// ¥ FindCommandStatus +// --------------------------------------------------------------------------- +// This function enables menu commands. +// Although cmd_Find and cmd_FindNext are handled by CBrowserShell, we handle them +// here because we want them to be enabled even when the CBrowserShell is not in +// the target chain. + +void +CBrowserWindow::FindCommandStatus( + PP_PowerPlant::CommandT inCommand, + Boolean &outEnabled, + Boolean &outUsesMark, + PP_PowerPlant::Char16 &outMark, + Str255 outName) +{ + + switch (inCommand) + { + case CBrowserShell::cmd_Find: + outEnabled = true; + break; + + case CBrowserShell::cmd_FindNext: + outEnabled = mBrowserShell->CanFindNext(); + break; + + default: + PP_PowerPlant::LCommander::FindCommandStatus(inCommand, outEnabled, + outUsesMark, outMark, outName); + break; + } +} + + +NS_METHOD CBrowserWindow::GetWidget(nsIWidget** aWidget) +{ + NS_ENSURE_ARG_POINTER(aWidget); + + *aWidget = mWindow; + NS_IF_ADDREF(*aWidget); + + return NS_OK; +} + + +//***************************************************************************** +//*** Chrome Interraction +//***************************************************************************** + +NS_METHOD CBrowserWindow::SetStatus(const PRUnichar* aStatus) +{ + if (mStatusBar) + { + nsAutoString statusStr(aStatus); + Str255 aStr; + + UMacUnicode::StringToStr255(statusStr, aStr); + mStatusBar->SetDescriptor(aStr); + } + return NS_OK; +} + +NS_METHOD CBrowserWindow::SetLocation(const nsString& aLocation) +{ + if (mURLField) + { + Str255 aStr; + + UMacUnicode::StringToStr255(aLocation, aStr); + mURLField->SetDescriptor(aStr); + } + return NS_OK; +} + +NS_METHOD CBrowserWindow::BeginDocumentLoad(nsIDocumentLoader *aLoader, nsIURI *aURL, const char *aCommand) +{ + // Stop the throbber + if (mThrobber) + mThrobber->Start(); + + if (mStopButton) + mStopButton->Enable(); + + // Inform any other interested parties + // Actually, all of the above stuff should done through + // broadcasters and listeners. But for demo's sake this + // better shows what's happening. + LBroadcaster::BroadcastMessage(msg_OnStartLoadDocument, 0); + + return NS_OK; +} + +NS_METHOD CBrowserWindow::EndDocumentLoad(nsIDocumentLoader *loader, nsIChannel *aChannel, PRUint32 aStatus) +{ + // Stop the throbber + if (mThrobber) + mThrobber->Stop(); + + // Enable back, forward, stop + if (mBackButton) + mBrowserShell->CanGoBack() ? mBackButton->Enable() : mBackButton->Disable(); + if (mForwardButton) + mBrowserShell->CanGoForward() ? mForwardButton->Enable() : mForwardButton->Disable(); + if (mStopButton) + mStopButton->Disable(); + + // Inform any other interested parties + // Actually, all of the above stuff should done through + // broadcasters and listeners. But for demo's sake this + // better shows what's happening. + LBroadcaster::BroadcastMessage(msg_OnEndLoadDocument, 0); + + return NS_OK; +} + + +NS_METHOD CBrowserWindow::OnStatusNetStart(nsIChannel *aChannel) +{ + return NS_OK; +} + +NS_METHOD CBrowserWindow::OnStatusNetStop(nsIChannel *aChannel) +{ + return NS_OK; +} + +NS_METHOD CBrowserWindow::OnStatusDNS(nsIChannel *aChannel) +{ + return NS_OK; +} diff --git a/mozilla/embedding/browser/powerplant/source/CBrowserWindow.h b/mozilla/embedding/browser/powerplant/source/CBrowserWindow.h new file mode 100644 index 00000000000..70bf6feb036 --- /dev/null +++ b/mozilla/embedding/browser/powerplant/source/CBrowserWindow.h @@ -0,0 +1,111 @@ + +#include +#include + +#ifndef nsError_h +#include "nsError.h" +#endif + +#ifndef nsCom_h__ +#include "nsCom.h" +#endif + +#ifndef nsCOMPtr_h___ +#include "nsCOMPtr.h" +#endif + +#ifndef nscore_h___ +#include "nscore.h" +#endif + +#ifndef nsIWidget_h__ +#include "nsIWidget.h" +#endif + +class CBrowserShell; +class CWebBrowserChrome; +class LEditText; +class LStaticText; +class CThrobber; +class LBevelButton; +class nsIDocumentLoader; +class nsIURI; +class nsIChannel; + +// CBrowserWindow: +// A simple browser window that hooks up a CBrowserShell to a minimal set of controls +// (Back, Forward and Stop buttons + URL field + status bar). + + +class CBrowserWindow : public LWindow, + public LListener, + public LBroadcaster +{ +private: + typedef LWindow Inherited; + + friend class CWebBrowserChrome; + +public: + enum { class_ID = FOUR_CHAR_CODE('BroW') }; + + CBrowserWindow(); + CBrowserWindow(LStream* inStream); + + virtual ~CBrowserWindow(); + + + virtual void FinishCreate(); + virtual void FinishCreateSelf(); + virtual void ResizeFrameBy(SInt16 inWidthDelta, + SInt16 inHeightDelta, + Boolean inRefresh); + virtual void ShowSelf(); + + virtual void ListenToMessage(MessageT inMessage, + void* ioParam); + + virtual Boolean ObeyCommand(CommandT inCommand, + void *ioParam); + + virtual void FindCommandStatus(PP_PowerPlant::CommandT inCommand, + Boolean &outEnabled, + Boolean &outUsesMark, + PP_PowerPlant::Char16 &outMark, + Str255 outName); + + NS_METHOD GetWidget(nsIWidget** aWidget); +protected: + + // Called by both constructors + NS_METHOD CommonConstruct(); + + // ----------------------------------- + // Methods called by CWebBrowserChrome + // ----------------------------------- + + NS_METHOD SetStatus(const PRUnichar* aStatus); + NS_METHOD SetOverLink(const PRUnichar* aStatus) + { return SetStatus(aStatus); } + + NS_METHOD SetLocation(const nsString& aLocation); + + NS_METHOD BeginDocumentLoad(nsIDocumentLoader *aLoader, nsIURI *aURL, const char *aCommand); + NS_METHOD EndDocumentLoad(nsIDocumentLoader *loader, nsIChannel *aChannel, PRUint32 aStatus); + + NS_METHOD OnStatusNetStart(nsIChannel *aChannel); + NS_METHOD OnStatusNetStop(nsIChannel *aChannel); + NS_METHOD OnStatusDNS(nsIChannel *aChannel); + +protected: + nsCOMPtr mWindow; + + CBrowserShell* mBrowserShell; + CWebBrowserChrome* mBrowserChrome; + LEditText* mURLField; + LStaticText* mStatusBar; + CThrobber* mThrobber; + LBevelButton *mBackButton, *mForwardButton, *mStopButton; +}; + +