Bug 374899: Remove powerplant, r=bsmedberg, rs=brendan

This commit is contained in:
gavin@gavinsharp.com 2007-03-23 13:16:54 -07:00
Родитель 0779143642
Коммит 84b4bbf9fe
66 изменённых файлов: 0 добавлений и 26621 удалений

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

@ -1,66 +0,0 @@
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# 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 mozilla.org code.
#
# The Initial Developer of the Original Code is
# Netscape Communications.
# Portions created by the Initial Developer are Copyright (C) 2001
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Conrad Carlen <ccarlen@netscape.com>
#
# Alternatively, the contents of this file may be used under the terms of
# either the GNU General Public License Version 2 or later (the "GPL"), or
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****
DEPTH = ../../../
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
ifdef MOZ_DEBUG
BUILDSTYLE = Development
else
BUILDSTYLE = Deployment
endif
include $(topsrcdir)/config/rules.mk
ABS_topsrcdir := $(shell cd $(topsrcdir); pwd)
ifneq ($(ABS_topsrcdir),$(MOZ_BUILD_ROOT))
export::
rsync -a --exclude .DS_Store --exclude "CVS/" $(srcdir)/PPEmbed.pbproj .
ln -fs $(srcdir)/pch
ln -fs $(srcdir)/resources
ln -fs $(srcdir)/source
endif
libs::
pbxbuild -buildstyle $(BUILDSTYLE) build
clean clobber::
rm -rf build

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Разница между файлами не показана из-за своего большого размера Загрузить разницу

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

@ -1,112 +0,0 @@
Mach-O Build Notes
1. The Mach-O build of PPEmbed is made with PowerPlant from CW Pro 8. Project
Builder has no idea where PowerPlant is installed on your drive. PPEmbed.pbproj
is set up with PowerPlant located, by absolute path, at /Developer/PowerPlant.
Needless to say, that's not where it exists on your drive, so a symlink is needed.
Open a terminal window and do this:
% cd /Developer
% ln -s <Drag the PowerPlant folder into the terminal window>
You can type the whole path to the PowerPlant folder if you like, but it's a
long, gruesome path with spaces.
2. A few changes need to be made to PowerPlant in order to get it to compile with
gcc. Fortunately, these don't prevent it from being compiled with CW. The diffs
are included below. They cannot easily be applied with patch, but do illustrate
the changes.
================================================================================
diff -u -t orig-PP-files/LException.cp changed-PP-files/LException.cp
--- orig-PP-files/LException.cp Thu Jan 23 14:41:59 2003
+++ changed-PP-files/LException.cp Thu Jan 23 14:41:20 2003
@@ -91,7 +91,7 @@
// ¥ ~LException Destructor [public]
// ---------------------------------------------------------------------------
-LException::~LException()
+LException::~LException() throw()
{
}
@@ -102,7 +102,7 @@
// Returns the error message as a C string. Inherited from std::exception.
const char*
-LException::what() const
+LException::what() const throw()
{
StringPtr lastPtr = (StringPtr) &mErrorString[mErrorString[0]];
================================================================================
diff -u -t orig-PP-files/LException.h changed-PP-files/LException.h
--- orig-PP-files/LException.h Thu Jan 23 14:41:49 2003
+++ changed-PP-files/LException.h Thu Jan 23 14:41:01 2003
@@ -30,9 +30,9 @@
LException& operator = ( const LException& inException );
- virtual ~LException();
+ virtual ~LException() throw();
- virtual const char* what() const;
+ virtual const char* what() const throw();
SInt32 GetErrorCode() const;
================================================================================
diff -u -t orig-PP-files/LGATabsControlImp.cp changed-PP-files/LGATabsControlImp.cp
--- orig-PP-files/LGATabsControlImp.cp Thu Jan 23 14:41:54 2003
+++ changed-PP-files/LGATabsControlImp.cp Thu Jan 23 14:41:08 2003
@@ -991,11 +991,11 @@
tabButton->SetIconResourceID(info->iconSuiteID);
}
break;
+ }
default:
LGAControlImp::SetDataTag(inPartCode, inTag, inDataSize, inDataPtr);
break;
- }
}
}
================================================================================
diff -u -t orig-PP-files/LStream.h changed-PP-files/LStream.h
--- orig-PP-files/LStream.h Thu Jan 23 14:41:43 2003
+++ changed-PP-files/LStream.h Thu Jan 23 14:41:14 2003
@@ -154,13 +154,13 @@
(*this) << (double) inNum;
return (*this);
}
-
+#ifdef __MWERKS__
LStream& operator << (short double inNum)
{
(*this) << (double) inNum;
return (*this);
}
-
+#endif
LStream& operator << (bool inBool)
{
WriteBlock(&inBool, sizeof(inBool));
@@ -276,7 +276,7 @@
outNum = num;
return (*this);
}
-
+#ifdef __MWERKS
LStream& operator >> (short double &outNum)
{
double num;
@@ -284,7 +284,7 @@
outNum = (short double) num;
return (*this);
}
-
+#endif
LStream& operator >> (bool &outBool)
{
ReadBlock(&outBool, sizeof(outBool));

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

@ -1,13 +0,0 @@
//--------------------------------------------------------------------------------
//
// 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
#define wantProfiles 1
#include "BrowserHeaders.pch.h"

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

@ -1,77 +0,0 @@
// ===============================================================================
// 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 <ControlDefinitions.h>
// include powerplant headers
#if wantDebugging
#include <PP_DebugHeaders.cp>
#else
#include <PP_ClassHeaders.cp>
#endif
// include mozilla prefix file
#if wantDebugging
#include "MacPrefix_debug.h"
#else
#include "MacPrefix.h"
#endif
#if wantProfiles
#define USE_PROFILES 1
#else
#define USE_PROFILES 1
#endif
// 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__

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

@ -1,13 +0,0 @@
//--------------------------------------------------------------------------------
//
// 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
#define wantProfiles 1
#include "BrowserHeaders.pch.h"

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

@ -1,159 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* 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 PPEmbed code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Conrad Carlen <ccarlen@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
// PowerPlant Config
#define PP_Target_Carbon 1
#define PP_Suppress_Notes_221 1
#define PP_MenuUtils_Option PP_MenuUtils_AppearanceOnly
#define PP_Uses_Aqua_MenuBar 1
// Carbon Headers
#include <Carbon/Carbon.h>
// PowerPlant Headers
#include <LAction.h>
#include <LUndoer.h>
#include <UTETextAction.h>
#include <UTEViewTextAction.h>
#include <LModelDirector.h>
#include <LModelObject.h>
#include <LModelProperty.h>
#include <UAppleEventsMgr.h>
#include <UExtractFromAEDesc.h>
#include <LArray.h>
#include <LArrayIterator.h>
#include <LComparator.h>
#include <LRunArray.h>
#include <LVariableArray.h>
#include <TArray.h>
#include <TArrayIterator.h>
#include <LApplication.h>
#include <LCommander.h>
#include <LDocApplication.h>
#include <LDocument.h>
#include <LSingleDoc.h>
#include <LAttachable.h>
#include <LAttachment.h>
#include <LBroadcaster.h>
#include <LDragAndDrop.h>
#include <LDragTask.h>
#include <LEventDispatcher.h>
#include <LListener.h>
#include <LPeriodical.h>
#include <LSharable.h>
#include <LDataStream.h>
#include <LFile.h>
#include <LFileStream.h>
#include <LHandleStream.h>
#include <LStream.h>
#include <LButton.h>
#include <LCaption.h>
#include <LCicnButton.h>
#include <LControl.h>
#include <LDialogBox.h>
#include <LEditField.h>
#include <LFocusBox.h>
#include <LGrafPortView.h>
#include <LListBox.h>
#include <LOffscreenView.h>
#include <LPane.h>
#include <LPicture.h>
#include <LPlaceHolder.h>
#include <LPrintout.h>
#include <LRadioGroupView.h>
#include <LScroller.h>
#include <LStdControl.h>
#include <LTabGroupView.h>
#include <LTableView.h>
#include <LTextEditView.h>
#include <LView.h>
#include <LWindow.h>
#include <UGWorld.h>
#include <UQuickTime.h>
#include <PP_Constants.h>
#include <PP_KeyCodes.h>
#include <PP_Macros.h>
#include <PP_Messages.h>
#include <PP_Prefix.h>
#include <PP_Resources.h>
#include <PP_Types.h>
#include <LClipboard.h>
#include <LFileTypeList.h>
#include <LMenu.h>
#include <LMenuBar.h>
#include <LRadioGroup.h>
#include <LString.h>
#include <LTabGroup.h>
#include <UDesktop.h>
#include <UAttachments.h>
#include <UCursor.h>
#include <UDebugging.h>
#include <UDrawingState.h>
#include <UDrawingUtils.h>
#include <UEnvironment.h>
#include <UException.h>
#include <UKeyFilters.h>
#include <UMemoryMgr.h>
#include <UModalDialogs.h>
#include <UPrinting.h>
#include <UReanimator.h>
#include <URegions.h>
#include <URegistrar.h>
#include <UScrap.h>
#include <UScreenPort.h>
#include <UTextEdit.h>
#include <UTextTraits.h>
#include <UWindows.h>
// Mozilla
#include "mozilla-config.h"
// Flags applicable to any build
#include "PPEmbedConfig.h"
// Flags for this particular build
#define POWERPLANT_IS_FRAMEWORK

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

@ -1,118 +0,0 @@
/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* 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 the Initial Developer are Copyright (C) 1999
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Conrad Carlen <ccarlen@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include <PowerPlant.r>
#include <Types.r>
#include "ApplIDs.h"
/*
These are all of the commands which can be done by CBrowserShell in
any possible context. PowerPlant's LCMAttachment takes care
of removing any commands which should not be enabled for the current
click by means of FindCommandStatus of the target (CBrowserShell)
*/
resource 'Mcmd' (mcmd_BrowserShellContextMenuCmds, "BrowserShellContextMenu") { {
cmd_OpenLinkInNewWindow,
msg_Nothing,
cmd_Back,
cmd_Forward,
cmd_Reload,
cmd_Stop,
msg_Nothing,
cmd_ViewPageSource,
cmd_ViewImage,
cmd_ViewBackgroundImage,
msg_Nothing,
cmd_SelectAll,
cmd_Copy,
msg_Nothing,
cmd_CopyImage,
cmd_CopyLinkLocation,
cmd_CopyImageLocation,
msg_Nothing,
cmd_SaveLinkTarget,
cmd_SaveImage,
msg_Nothing,
cmd_PrefillForm
} };
/*
The MENU/Mcmd combination that we use to get the text for
context menus items. PowerPlant searches its menu list in
order to do this. We can add this menu to the menu list as
a hierarchical menu so it won't show but can be used for
this purpose. The name "buzzwords" is taken from MacApp which
uses (and officially supports) this technique.
*/
resource 'MENU' (menu_Buzzwords, "Buzzwords") {
menu_Buzzwords, textMenuProc, allEnabled, enabled, "",
{
"Open Link In New Window", noIcon, noKey, noMark, plain,
"Back", noIcon, noKey, noMark, plain,
"Forward", noIcon, noKey, noMark, plain,
"Reload", noIcon, noKey, noMark, plain,
"Stop", noIcon, noKey, noMark, plain,
"View Page Source", noIcon, noKey, noMark, plain,
"View Image", noIcon, noKey, noMark, plain,
"View Background Image", noIcon, noKey, noMark, plain,
"Copy Image", noIcon, noKey, noMark, plain,
"Save Link Target AsÉ", noIcon, noKey, noMark, plain,
"Save Image AsÉ", noIcon, noKey, noMark, plain,
"Copy Link Location", noIcon, noKey, noMark, plain,
"Copy Image Location", noIcon, noKey, noMark, plain,
}
};
resource 'Mcmd' (menu_Buzzwords, "Buzzwords") { {
cmd_OpenLinkInNewWindow,
cmd_Back,
cmd_Forward,
cmd_Reload,
cmd_Stop,
cmd_ViewPageSource,
cmd_ViewImage,
cmd_ViewBackgroundImage,
cmd_CopyImage,
cmd_SaveLinkTarget,
cmd_SaveImage,
cmd_CopyLinkLocation,
cmd_CopyImageLocation,
} };

Двоичный файл не отображается.

Разница между файлами не показана из-за своего большого размера Загрузить разницу

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

@ -1,82 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* 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 PPEmbed code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include <Types.r>
resource 'DITL' (1550, "Save format panel", purgeable) {
{ /* array DITLarray: 2 elements */
/* [1] */
{16, 12, 32, 75},
StaticText {
disabled,
"Save as:"
},
/* [2] */
{12, 68, 36, 236},
Control {
enabled,
1550
}
}
};
resource 'MENU' (1550) {
1550,
textMenuProc,
allEnabled,
enabled,
"Save Format",
{ /* array: 3 elements */
/* [1] */
"Text Only", noIcon, noKey, noMark, plain,
/* [2] */
"HTML", noIcon, noKey, noMark, plain,
/* [3] */
"HTML Complete", noIcon, noKey, noMark, plain
}
};
resource 'CNTL' (1550, "Save format popup", purgeable) {
{12, 68, 36, 236},
0,
visible,
0,
1550,
401,
0,
""
};

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

@ -1,39 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* 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 Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2001
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
read 'GIF ' (128) "throbber-anim.gif";

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Двоичный файл не отображается.

Двоичный файл не отображается.

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 23 KiB

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

@ -1,79 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* 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 mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Brian Ryner <bryner@brianryner.com>
* Conrad Carlen <ccarlen@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "AppComponents.h"
#include "PromptService.h"
#include "UDownload.h"
#define NS_PROMPTSERVICE_CID \
{0xa2112d6a, 0x0e28, 0x421f, {0xb4, 0x6a, 0x25, 0xc0, 0xb3, 0x8, 0xcb, 0xd0}}
#define NS_HELPERAPPLAUNCHERDIALOG_CID \
{0xf68578eb, 0x6ec2, 0x4169, {0xae, 0x19, 0x8c, 0x62, 0x43, 0xf0, 0xab, 0xe1}}
NS_GENERIC_FACTORY_CONSTRUCTOR(CPromptService)
NS_GENERIC_FACTORY_CONSTRUCTOR(CDownload)
NS_GENERIC_FACTORY_CONSTRUCTOR(CHelperAppLauncherDialog)
static const nsModuleComponentInfo components[] = {
{
"Prompt Service",
NS_PROMPTSERVICE_CID,
"@mozilla.org/embedcomp/prompt-service;1",
CPromptServiceConstructor
},
{
"Download",
NS_DOWNLOAD_CID,
NS_TRANSFER_CONTRACTID,
CDownloadConstructor
},
{
NS_IHELPERAPPLAUNCHERDLG_CLASSNAME,
NS_HELPERAPPLAUNCHERDIALOG_CID,
NS_IHELPERAPPLAUNCHERDLG_CONTRACTID,
CHelperAppLauncherDialogConstructor
}
};
const nsModuleComponentInfo* GetAppModuleComponentInfo(int* outNumComponents)
{
*outNumComponents = sizeof(components) / sizeof(components[0]);
return components;
}

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

@ -1,51 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* 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 mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Brian Ryner <bryner@brianryner.com>
* Conrad Carlen <ccarlen@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef AppComponents_h__
#define AppComponents_h__
#ifndef nsIGenericFactory_h___
#include "nsIGenericFactory.h"
#endif
// This method should return a nsModuleComponentInfo array of
// application-provided XPCOM components to register.
extern const nsModuleComponentInfo* GetAppModuleComponentInfo(int* outNumComponents);
#endif

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

@ -1,226 +0,0 @@
/* -*- Mode: C++; tab-width: 3; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* 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 the Initial Developer are Copyright (C) 1999
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Conrad Carlen <conrad@ingress.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/*
* 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
enum {
wind_DownloadProgress = 1305
};
// Views
enum {
view_BrowserStatusBar = 130,
view_BrowserToolBar = 131,
view_DownloadProgressItem = 1306
};
// Dialogs
enum {
dlog_FindDialog = 1281
};
// nsIPrompt
enum {
dlog_Alert = 1282,
dlog_AlertCheck = 1289,
dlog_Confirm = 1283,
dlog_ConfirmCheck = 1284,
dlog_Prompt = 1285,
dlog_PromptNameAndPass = 1286,
dlog_PromptPassword = 1287,
dlog_ConfirmEx = 1288
};
// Printing
enum {
dlog_OS9PrintProgress = 1290
};
// Profile Mgmt
enum {
dlog_ManageProfiles = 1300,
dlog_NewProfile = 1301
};
// Alerts
enum {
alrt_ConfirmProfileSwitch = 1500,
alrt_ConfirmLogout = 1501
};
// MENUs
enum {
menu_Buzzwords = 1000
};
// Mcmds
enum {
mcmd_BrowserShellContextMenuCmds = 1200
};
// STR#s
enum {
STRx_FileLocProviderStrings = 5000,
str_AppRegistryName = 1,
str_ProfilesRootDirName,
str_DefaultsDirName,
str_PrefDefaultsDirName,
str_ProfileDefaultsDirName,
str_ResDirName,
str_ChromeDirName,
str_PlugInsDirName,
str_SearchPlugInsDirName
};
enum {
STRx_StdButtonTitles = 5001,
str_Blank = 1,
str_OK,
str_Cancel,
str_Yes,
str_No,
str_Save,
str_DontSave,
str_Revert,
str_Allow,
str_DenyAll
};
enum {
STRx_StdAlertStrings = 5002,
str_OpeningPopupWindow = 1,
str_OpeningPopupWindowExp,
str_ConfirmCloseDownloads,
str_ConfirmCloseDownloadsExp
};
enum {
STRx_DownloadStatus = 5003,
str_ProgressFormat = 1,
str_About5Seconds,
str_About10Seconds,
str_LessThan1Minute,
str_About1Minute,
str_AboutNMinutes,
str_About1Hour,
str_AboutNHours
};
// Icons
enum {
icon_LockInsecure = 1320,
icon_LockSecure,
icon_LockBroken
};
//*****************************************************************************
//*** Message IDs
//*****************************************************************************
enum {
msg_OnStartLoadDocument = 1000,
msg_OnEndLoadDocument = 1001
};
//*****************************************************************************
//*** Command IDs
//*****************************************************************************
enum {
cmd_OpenDirectory = 'ODir',
cmd_OpenLinkInNewWindow = 'OLnN',
cmd_Back = 'Back',
cmd_Forward = 'Forw',
cmd_Reload = 'Rlod',
cmd_Stop = 'Stop',
cmd_Find = 'Find',
cmd_FindNext = 'FNxt',
cmd_ViewPageSource = 'VSrc',
cmd_ViewImage = 'VImg',
cmd_ViewBackgroundImage = 'VBIm',
cmd_CopyImage = 'CpIm',
cmd_CopyLinkLocation = 'CLnk',
cmd_CopyImageLocation = 'CImg',
cmd_SaveFormData = 'SFrm',
cmd_PrefillForm = 'PFFm',
cmd_ManageProfiles = 'MPrf',
cmd_Logout = 'LOut',
cmd_SaveLinkTarget = 'DnlL',
cmd_SaveImage = 'DlIm'
};
//*****************************************************************************
//*** Apple Events
//*****************************************************************************
enum {
// A key that we use internally with kAEGetURL
keyGetURLReferrer = 'refe'
};
#endif // __ApplIDs__

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

@ -1,170 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* 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 Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2000
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Conrad Carlen <ccarlen@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "CAppFileLocationProvider.h"
#include "nsAppDirectoryServiceDefs.h"
#include "nsDirectoryServiceDefs.h"
#include "nsIAtom.h"
#include "nsILocalFile.h"
#include "nsString.h"
#include "nsXPIDLString.h"
#include "nsCRT.h"
#include <Folders.h>
#include <Script.h>
#include <Processes.h>
#include "nsILocalFileMac.h"
#include "ApplIDs.h"
//*****************************************************************************
// CAppFileLocationProvider::Constructor/Destructor
//*****************************************************************************
CAppFileLocationProvider::CAppFileLocationProvider(const nsAString& aAppDataDirName) :
mAppDataDirName(aAppDataDirName)
{
}
CAppFileLocationProvider::~CAppFileLocationProvider()
{
}
//*****************************************************************************
// CAppFileLocationProvider::nsISupports
//*****************************************************************************
NS_IMPL_ISUPPORTS1(CAppFileLocationProvider, nsIDirectoryServiceProvider)
//*****************************************************************************
// CAppFileLocationProvider::nsIDirectoryServiceProvider
//*****************************************************************************
NS_IMETHODIMP
CAppFileLocationProvider::GetFile(const char *prop, PRBool *persistent, nsIFile **_retval)
{
nsCOMPtr<nsILocalFile> localFile;
nsresult rv = NS_ERROR_FAILURE;
*_retval = nsnull;
*persistent = PR_TRUE;
if (strcmp(prop, NS_APP_APPLICATION_REGISTRY_DIR) == 0)
{
rv = GetAppDataDirectory(getter_AddRefs(localFile));
}
else if (strcmp(prop, NS_APP_APPLICATION_REGISTRY_FILE) == 0)
{
rv = GetAppDataDirectory(getter_AddRefs(localFile));
if (NS_SUCCEEDED(rv))
rv = localFile->AppendNative(nsDependentCString("Application Registry"));
}
else if (strcmp(prop, NS_APP_USER_PROFILES_ROOT_DIR) == 0)
{
rv = GetAppDataDirectory(getter_AddRefs(localFile));
if (NS_FAILED(rv))
return rv;
rv = localFile->AppendNative(nsDependentCString("Profiles"));
if (NS_FAILED(rv))
return rv;
PRBool exists;
rv = localFile->Exists(&exists);
if (NS_SUCCEEDED(rv) && !exists)
rv = localFile->Create(nsIFile::DIRECTORY_TYPE, 0775);
if (NS_FAILED(rv))
return rv;
}
if (localFile && NS_SUCCEEDED(rv))
rv = localFile->QueryInterface(NS_GET_IID(nsIFile), (void**)_retval);
return rv;
}
//----------------------------------------------------------------------------------------
// GetAppDataDirectory - Gets the directory which contains the application data folder
//----------------------------------------------------------------------------------------
NS_METHOD CAppFileLocationProvider::GetAppDataDirectory(nsILocalFile **aLocalFile)
{
NS_ENSURE_ARG_POINTER(aLocalFile);
NS_ENSURE_TRUE(!mAppDataDirName.IsEmpty(), NS_ERROR_NOT_INITIALIZED);
nsresult rv;
PRBool exists;
nsCOMPtr<nsILocalFile> localDir;
nsCOMPtr<nsIProperties> directoryService =
do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID, &rv);
if (NS_FAILED(rv)) return rv;
OSErr err;
#if defined(XP_MACOSX)
FSRef fsRef;
err = ::FSFindFolder(kUserDomain, kApplicationSupportFolderType, kCreateFolder, &fsRef);
if (err) return NS_ERROR_FAILURE;
NS_NewLocalFile(EmptyString(), PR_TRUE, getter_AddRefs(localDir));
if (!localDir) return NS_ERROR_FAILURE;
nsCOMPtr<nsILocalFileMac> localDirMac(do_QueryInterface(localDir));
rv = localDirMac->InitWithFSRef(&fsRef);
if (NS_FAILED(rv)) return rv;
#else
long response;
err = ::Gestalt(gestaltSystemVersion, &response);
const char *prop = (!err && response >= 0x00001000) ? NS_MAC_USER_LIB_DIR : NS_MAC_DOCUMENTS_DIR;
rv = directoryService->Get(prop, NS_GET_IID(nsILocalFile), getter_AddRefs(localDir));
if (NS_FAILED(rv)) return rv;
#endif
rv = localDir->Append(mAppDataDirName);
if (NS_FAILED(rv))
return rv;
rv = localDir->Exists(&exists);
if (NS_SUCCEEDED(rv) && !exists)
rv = localDir->Create(nsIFile::DIRECTORY_TYPE, 0775);
if (NS_FAILED(rv))
return rv;
*aLocalFile = localDir;
NS_ADDREF(*aLocalFile);
return rv;
}

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

@ -1,64 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* 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 Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2000
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Conrad Carlen <ccarlen@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsIDirectoryService.h"
#include "nsILocalFile.h"
#include "nsString.h"
class nsIFile;
//*****************************************************************************
// class CAppFileLocationProvider
//*****************************************************************************
class CAppFileLocationProvider : public nsIDirectoryServiceProvider
{
public:
CAppFileLocationProvider(const nsAString& aAppDataDirName);
NS_DECL_ISUPPORTS
NS_DECL_NSIDIRECTORYSERVICEPROVIDER
protected:
virtual ~CAppFileLocationProvider();
NS_METHOD GetAppDataDirectory(nsILocalFile **aLocalFile);
nsString mAppDataDirName;
};

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

@ -1,858 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* 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 the Initial Developer are Copyright (C) 1999
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Conrad Carlen <ccarlen@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "CBrowserApp.h"
#include <PP_Messages.h>
#include <PP_Resources.h>
#include <UDrawingState.h>
#include <UMemoryMgr.h>
#include <URegistrar.h>
#include <LPushButton.h>
#include <LStaticText.h>
#include <LIconControl.h>
#include <LWindow.h>
#include <LTextTableView.h>
#include <UControlRegistry.h>
#include <UGraphicUtils.h>
#include <UEnvironment.h>
#include <Appearance.h>
#include <LCMAttachment.h>
#include <UCMMUtils.h>
#include <UNavServicesDialogs.h>
#include "ApplIDs.h"
#include "CBrowserWindow.h"
#include "CBrowserShell.h"
#include "CBrowserChrome.h"
#include "CWindowCreator.h"
#include "CUrlField.h"
#include "CThrobber.h"
#include "CIconServicesIcon.h"
#include "CWebBrowserCMAttachment.h"
#include "UMacUnicode.h"
#include "CAppFileLocationProvider.h"
#include "EmbedEventHandling.h"
#include "AppComponents.h"
#include "nsEmbedAPI.h"
#include "nsIComponentRegistrar.h"
#include "nsIDirectoryService.h"
#include "nsDirectoryServiceDefs.h"
#include "nsAppDirectoryServiceDefs.h"
#include "nsIObserverService.h"
#include "nsObserverService.h"
#include "nsIPref.h"
#include "nsRepeater.h"
#include "nsILocalFile.h"
#include "nsILocalFileMac.h"
#include "nsIFileChannel.h"
#include "nsXPIDLString.h"
#include "nsReadableUtils.h"
#include "nsNetUtil.h"
#include "nsIWindowWatcher.h"
#include "nsIDOMWindow.h"
#include "nsIDownload.h"
#include "nsCRT.h"
#if defined(__MWERKS__) && !defined(__MACH__)
#include "macstdlibextras.h"
#include "SIOUX.h"
#endif
#include <TextServices.h>
#ifdef USE_PROFILES
#include "CProfileManager.h"
#include "nsIProfileChangeStatus.h"
#else
#include "nsProfileDirServiceProvider.h"
#endif
#ifdef SHARED_PROFILE
#include "nsIProfileSharingSetup.h"
#define kAppDataFolderName NS_LITERAL_STRING("PPEmbed Suite")
#else
#define kAppDataFolderName NS_LITERAL_STRING("PPEmbed")
#endif
// ===========================================================================
// ¥ Main Program
// ===========================================================================
int main()
{
SetDebugThrow_(PP_PowerPlant::debugAction_Alert); // Set Debugging options
SetDebugSignal_(PP_PowerPlant::debugAction_Alert);
#ifdef POWERPLANT_IS_FRAMEWORK
// A framework's Resource Mgr resources must be opened explicitly.
CFBundleRef powerplantBundle = ::CFBundleGetBundleWithIdentifier(
CFSTR("org.mozilla.PowerPlant"));
SInt16 powerPlantResRefNum = -1;
if (powerplantBundle) {
powerPlantResRefNum = ::CFBundleOpenBundleResourceMap(powerplantBundle);
::CFRelease(powerplantBundle);
}
#endif
PP_PowerPlant::InitializeHeap(3); // Initialize Memory Manager
// Parameter is number of Master Pointer
// blocks to allocate
PP_PowerPlant::UQDGlobals::InitializeToolbox();
#if defined(__MWERKS__) && !TARGET_CARBON
::InitializeSIOUX(false);
#endif
#if !TARGET_CARBON
new PP_PowerPlant::LGrowZone(20000); // Install a GrowZone function to catch low memory situations.
::InitTSMAwareApplication();
#endif
{
CBrowserApp theApp; // create instance of your application
theApp.Run();
}
#if !TARGET_CARBON
::CloseTSMAwareApplication();
#endif
return 0;
}
// ===========================================================================
// class CStartupTask
//
// A one-shot repeater which calls the application method to handle startup.
// ===========================================================================
class CStartUpTask : public LPeriodical
{
public:
CStartUpTask(CBrowserApp *aBrowserApp) :
mBrowserApp(aBrowserApp)
{
StartRepeating();
}
~CStartUpTask() { }
void SpendTime(const EventRecord& inMacEvent)
{
StopRepeating();
mBrowserApp->OnStartUp();
delete this;
}
private:
CBrowserApp *mBrowserApp;
};
// ---------------------------------------------------------------------------
// ¥ CBrowserApp
// ---------------------------------------------------------------------------
// Constructor
CBrowserApp::CBrowserApp()
{
#ifdef USE_PROFILES
mRefCnt = 1;
#else
mProfDirServiceProvider = nsnull;
#endif
#if TARGET_CARBON
InstallCarbonEventHandlers();
#endif
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.
RegisterClass_(PP_PowerPlant::LTabGroupView);
RegisterClass_(PP_PowerPlant::LIconControl);
RegisterClass_(PP_PowerPlant::LView);
RegisterClass_(PP_PowerPlant::LDialogBox);
// Register the Appearance Manager/GA classes
PP_PowerPlant::UControlRegistry::RegisterClasses();
// QuickTime is used by CThrobber
UQuickTime::Initialize();
// Register classes used by embedding
RegisterClass_(CBrowserShell);
RegisterClass_(CBrowserWindow);
RegisterClass_(CUrlField);
RegisterClass_(CThrobber);
RegisterClass_(CIconServicesIcon);
#ifdef USE_PROFILES
RegisterClass_(LScroller);
RegisterClass_(LTextTableView);
RegisterClass_(LColorEraseAttachment);
#endif
// Contexual Menu Support
UCMMUtils::Initialize();
RegisterClass_(LCMAttachment);
RegisterClass_(CWebBrowserCMAttachment);
AddAttachment(new LCMAttachment);
SetSleepTime(5);
// Get the directory which contains the mozilla parts
// In this case it is the app directory but it could
// be anywhere (an existing install of mozilla)
nsresult rv;
ProcessSerialNumber psn;
ProcessInfoRec processInfo;
FSSpec appSpec;
nsCOMPtr<nsILocalFileMac> macDir;
if (!::GetCurrentProcess(&psn)) {
processInfo.processInfoLength = sizeof(processInfo);
processInfo.processName = NULL;
processInfo.processAppSpec = &appSpec;
if (!::GetProcessInformation(&psn, &processInfo)) {
// Turn the FSSpec of the app into an FSSpec of the app's directory
OSErr err = ::FSMakeFSSpec(appSpec.vRefNum, appSpec.parID, "\p", &appSpec);
// Make an nsILocalFile out of it
if (err == noErr)
(void)NS_NewLocalFileWithFSSpec(&appSpec, PR_TRUE, getter_AddRefs(macDir));
}
}
CAppFileLocationProvider *fileLocProvider = new CAppFileLocationProvider(kAppDataFolderName);
ThrowIfNil_(fileLocProvider);
rv = NS_InitEmbedding(macDir, fileLocProvider);
OverrideComponents();
CWindowCreator::Initialize();
InitializeEmbedEventHandling(this);
}
// ---------------------------------------------------------------------------
// ¥ ~CBrowserApp
// ---------------------------------------------------------------------------
// Destructor
//
CBrowserApp::~CBrowserApp()
{
#ifdef USE_PROFILES
nsCOMPtr<nsIProfile> profileService =
do_GetService(NS_PROFILE_CONTRACTID, &rv);
if (profileService)
profileService->ShutDownCurrentProfile(nsIProfile::SHUTDOWN_PERSIST);
#else
if (mProfDirServiceProvider) {
mProfDirServiceProvider->Shutdown();
NS_RELEASE(mProfDirServiceProvider);
}
#endif
NS_TermEmbedding();
}
nsresult
CBrowserApp::OverrideComponents()
{
nsresult rv = NS_OK;
nsCOMPtr<nsIComponentRegistrar> cr;
NS_GetComponentRegistrar(getter_AddRefs(cr));
if (!cr)
return NS_ERROR_FAILURE;
int numComponents;
const nsModuleComponentInfo* componentInfo = GetAppModuleComponentInfo(&numComponents);
for (int i = 0; i < numComponents; ++i) {
nsCOMPtr<nsIGenericFactory> componentFactory;
rv = NS_NewGenericFactory(getter_AddRefs(componentFactory), &(componentInfo[i]));
if (NS_FAILED(rv)) {
NS_ASSERTION(PR_FALSE, "Unable to create factory for component");
continue;
}
rv = cr->RegisterFactory(componentInfo[i].mCID,
componentInfo[i].mDescription,
componentInfo[i].mContractID,
componentFactory);
NS_ASSERTION(NS_SUCCEEDED(rv), "Unable to register factory for component");
}
return rv;
}
// ---------------------------------------------------------------------------
// ¥ MakeMenuBar
// ---------------------------------------------------------------------------
void
CBrowserApp::MakeMenuBar()
{
LApplication::MakeMenuBar();
// Insert a menu which is not in the menu bar but which contains
// items which appear only in contextual menus. We have to do this hack
// because LCMAttachment::AddCommand needs a command which is in
// some LMenu in order to get the text for a contextual menu item.
LMenuBar::GetCurrentMenuBar()->InstallMenu(new LMenu(menu_Buzzwords), hierMenu);
}
// ---------------------------------------------------------------------------
// ¥ Initialize
// ---------------------------------------------------------------------------
// Initializes profile manager or directory service provider. If the user has
// chosen to be prompted to choose a profile at startup so the profile dialog
// appears and they cancel from that dialog, startup will terminate.
void
CBrowserApp::Initialize()
{
nsresult rv;
#ifdef SHARED_PROFILE
CFBundleRef appBundle = CFBundleGetMainBundle();
ThrowIfNil_(appBundle);
nsAutoString suiteMemberStr;
// We don't get an owning reference here, so no CFRelease.
CFStringRef bundleStrRef = (CFStringRef)CFBundleGetValueForInfoDictionaryKey(
appBundle, CFSTR("ProfilesSuiteMemberName"));
if (bundleStrRef && (CFGetTypeID(bundleStrRef) == CFStringGetTypeID())) {
UniChar buffer[256];
CFIndex strLen = CFStringGetLength(bundleStrRef);
ThrowIf_(strLen >= (sizeof(buffer) / sizeof(buffer[0])));
CFStringGetCharacters(bundleStrRef, CFRangeMake(0, strLen), buffer);
buffer[strLen] = 0;
suiteMemberStr.Assign(static_cast<PRUnichar*>(buffer));
}
ThrowIf_(suiteMemberStr.IsEmpty());
nsCOMPtr<nsIProfileSharingSetup> sharingSetup =
do_GetService("@mozilla.org/embedcomp/profile-sharing-setup;1");
ThrowIfNil_(sharingSetup);
rv = sharingSetup->EnableSharing(suiteMemberStr);
ThrowIfError_(rv);
#endif
#ifdef USE_PROFILES
// Register for profile changes
nsCOMPtr<nsIObserverService> observerService =
do_GetService(NS_OBSERVERSERVICE_CONTRACTID, &rv);
ThrowIfNil_(observerService);
observerService->AddObserver(this, "profile-approve-change", PR_FALSE);
observerService->AddObserver(this, "profile-change-teardown", PR_FALSE);
observerService->AddObserver(this, "profile-after-change", PR_FALSE);
CProfileManager *profileMgr = new CProfileManager;
profileMgr->StartUp();
AddAttachment(profileMgr);
#else
// If we don't want different user profiles, all that's needed is
// to make an nsProfileDirServiceProvider. This will provide the same file
// locations as the profile service but always within the specified folder.
nsCOMPtr<nsIFile> appDataDir;
rv = NS_GetSpecialDirectory(NS_APP_APPLICATION_REGISTRY_DIR, getter_AddRefs(appDataDir));
ThrowIfNil_(appDataDir);
nsCOMPtr<nsProfileDirServiceProvider> profDirServiceProvider;
NS_NewProfileDirServiceProvider(PR_TRUE, getter_AddRefs(profDirServiceProvider));
ThrowIfNil_(profDirServiceProvider);
rv = profDirServiceProvider->Register();
ThrowIfError_(rv);
nsCOMPtr<nsILocalFile> localAppDataDir(do_QueryInterface(appDataDir));
rv = profDirServiceProvider->SetProfileDir(localAppDataDir);
ThrowIfError_(rv);
NS_ADDREF(mProfDirServiceProvider = profDirServiceProvider);
#endif
// Now that we know profile selection wasn't canceled and we're gonna run...
CStartUpTask *startupTask = new CStartUpTask(this);
}
// ---------------------------------------------------------------------------
// ¥ AdjustCursor [public]
// ---------------------------------------------------------------------------
void CBrowserApp::AdjustCursor(const EventRecord& inMacEvent)
{
// Needed in order to give an attachment to the application a
// msg_AdjustCursor. CEmbedEventAttachment needs this.
if (ExecuteAttachments(msg_AdjustCursor, (void*) &inMacEvent))
LEventDispatcher::AdjustCursor(inMacEvent);
}
// ---------------------------------------------------------------------------
// ¥ HandleAppleEvent [public]
// ---------------------------------------------------------------------------
void CBrowserApp::HandleAppleEvent(const AppleEvent& inAppleEvent,
AppleEvent& outAEReply,
AEDesc& outResult,
long inAENumber)
{
switch (inAENumber) {
case 5000:
{
OSErr err;
StAEDescriptor urlDesc;
err = ::AEGetParamDesc(&inAppleEvent, keyDirectObject, typeChar, urlDesc);
ThrowIfOSErr_(err);
Size dataSize = ::AEGetDescDataSize(urlDesc);
StPointerBlock urlPtr(dataSize);
err = ::AEGetDescData(urlDesc, urlPtr.Get(), dataSize);
ThrowIfOSErr_(err);
const nsACString& urlAsStr = Substring(urlPtr.Get(), urlPtr.Get() + dataSize);
// If the URL begins with "view-source:", go with less chrome
PRUint32 chromeFlags;
NS_NAMED_LITERAL_CSTRING(kViewSourceProto, "view-source:");
if (Substring(urlAsStr, 0, kViewSourceProto.Length()).Equals(kViewSourceProto))
chromeFlags = nsIWebBrowserChrome::CHROME_WINDOW_CLOSE +
nsIWebBrowserChrome::CHROME_WINDOW_RESIZE;
else
chromeFlags = nsIWebBrowserChrome::CHROME_DEFAULT;
// See if we have a referrer
nsCAutoString referrerAsStr;
StAEDescriptor referrerDesc;
err = ::AEGetParamDesc(&inAppleEvent, keyGetURLReferrer, typeChar, referrerDesc);
if (err == noErr) {
dataSize = ::AEGetDescDataSize(referrerDesc);
StPointerBlock referrerPtr(dataSize);
err = ::AEGetDescData(referrerDesc, referrerPtr.Get(), dataSize);
ThrowIfOSErr_(err);
referrerAsStr = Substring(referrerPtr.Get(), referrerPtr.Get() + dataSize);
}
LWindow *theWindow = CWindowCreator::CreateWindowInternal(chromeFlags, PR_TRUE, -1, -1);
ThrowIfNil_(theWindow);
CBrowserShell *theBrowser = dynamic_cast<CBrowserShell*>(theWindow->FindPaneByID(CBrowserShell::paneID_MainBrowser));
ThrowIfNil_(theBrowser);
theBrowser->LoadURL(urlAsStr, referrerAsStr);
theWindow->Show();
}
break;
case ae_ApplicationDied: // We get these from opening downloaded files with Stuffit - ignore.
break;
default:
LApplication::HandleAppleEvent(inAppleEvent, outAEReply, outResult, inAENumber);
}
}
// ---------------------------------------------------------------------------
// ¥ 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) {
case PP_PowerPlant::cmd_About:
break;
case PP_PowerPlant::cmd_New:
{
LWindow *theWindow = CWindowCreator::CreateWindowInternal(nsIWebBrowserChrome::CHROME_DEFAULT, PR_TRUE, -1, -1);
ThrowIfNil_(theWindow);
CBrowserShell *theBrowser = dynamic_cast<CBrowserShell*>(theWindow->FindPaneByID(CBrowserShell::paneID_MainBrowser));
ThrowIfNil_(theBrowser);
// Just for demo sake, load a URL
theBrowser->LoadURL(nsDependentCString("http://www.mozilla.org"));
theWindow->Show();
}
break;
case PP_PowerPlant::cmd_Open:
case cmd_OpenDirectory:
{
FSSpec fileSpec;
if (SelectFileObject(inCommand, fileSpec))
{
nsresult rv;
nsCOMPtr<nsILocalFileMac> macFile;
rv = NS_NewLocalFileWithFSSpec(&fileSpec, PR_TRUE, getter_AddRefs(macFile));
ThrowIfError_(NS_ERROR_GET_CODE(rv));
nsCAutoString urlSpec;
rv = NS_GetURLSpecFromFile(macFile, urlSpec);
ThrowIfError_(NS_ERROR_GET_CODE(rv));
LWindow *theWindow = CWindowCreator::CreateWindowInternal(nsIWebBrowserChrome::CHROME_DEFAULT, PR_TRUE, -1, -1);
ThrowIfNil_(theWindow);
CBrowserShell *theBrowser = dynamic_cast<CBrowserShell*>(theWindow->FindPaneByID(CBrowserShell::paneID_MainBrowser));
ThrowIfNil_(theBrowser);
theBrowser->LoadURL(urlSpec);
theWindow->Show();
}
}
break;
case PP_PowerPlant::cmd_Preferences:
{
nsCOMPtr<nsIWindowWatcher> wwatch(do_GetService("@mozilla.org/embedcomp/window-watcher;1"));
ThrowIfNil_(wwatch);
// Note: We're not making this window modal even though it looks like a modal
// dialog (has OK and Cancel buttons). Reason is, the help window which can
// be opened from the prefs dialog is non-modal. If the prefs dialog was modal,
// the help window would be stuck behind it in the non-modal layer.
// And, since its non-modal, we have to check for an already open prefs window
// and just select it rather than making a new one.
nsCOMPtr<nsIDOMWindow> extantPrefsWindow;
wwatch->GetWindowByName(NS_LITERAL_STRING("_prefs").get(), nsnull, getter_AddRefs(extantPrefsWindow));
if (extantPrefsWindow) {
// activate the window
LWindow *extantPrefsLWindow = CBrowserChrome::GetLWindowForDOMWindow(extantPrefsWindow);
ThrowIfNil_(extantPrefsLWindow);
extantPrefsLWindow->Select();
}
else {
nsCOMPtr<nsIDOMWindow> domWindow;
wwatch->OpenWindow(nsnull,
"chrome://communicator/content/pref/pref.xul",
"_prefs",
"centerscreen,chrome,dialog,titlebar",
nsnull,
getter_AddRefs(domWindow));
}
}
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,
UInt16 &outMark,
Str255 outName)
{
switch (inCommand) {
case PP_PowerPlant::cmd_About:
outEnabled = false;
break;
case PP_PowerPlant::cmd_New:
outEnabled = true;
break;
case PP_PowerPlant::cmd_Open:
case cmd_OpenDirectory:
outEnabled = true;
break;
case PP_PowerPlant::cmd_Preferences:
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;
}
}
Boolean CBrowserApp::AttemptQuitSelf(SInt32 inSaveOption)
{
// IMPORTANT: This is one unfortunate thing about Powerplant - Windows don't
// get destroyed until the destructor of LCommander. We need to delete
// all of the CBrowserWindows though before we terminate embedding.
TArrayIterator<LCommander*> iterator(mSubCommanders, LArrayIterator::from_End);
LCommander* theSub;
while (iterator.Previous(theSub)) {
if (dynamic_cast<CBrowserWindow*>(theSub)) {
mSubCommanders.RemoveItemsAt(1, iterator.GetCurrentIndex());
delete theSub;
}
}
return true;
}
#if TARGET_CARBON
void CBrowserApp::InstallCarbonEventHandlers()
{
EventTypeSpec appEventList[] = {{kEventClassCommand, kEventCommandProcess},
{kEventClassCommand, kEventCommandUpdateStatus}};
InstallApplicationEventHandler(NewEventHandlerUPP(AppEventHandler), 2, appEventList, this, NULL);
}
pascal OSStatus CBrowserApp::AppEventHandler(EventHandlerCallRef aHandlerChain,
EventRef event,
void* userData)
{
HICommand command;
OSStatus result = eventNotHandledErr; /* report failure by default */
if (::GetEventParameter(event, kEventParamDirectObject,
typeHICommand, NULL, sizeof(HICommand),
NULL, &command) != noErr)
return result;
switch (::GetEventKind(event))
{
case kEventCommandProcess:
{
switch (command.commandID)
{
case kHICommandPreferences:
{
CBrowserApp *theApp = reinterpret_cast<CBrowserApp*>(userData);
theApp->ObeyCommand(PP_PowerPlant::cmd_Preferences, nsnull);
result = noErr;
break;
}
default:
break;
}
}
break;
case kEventCommandUpdateStatus:
{
switch (command.commandID)
{
case kHICommandPreferences:
::EnableMenuCommand(nsnull, kHICommandPreferences);
result = noErr;
break;
default:
break;
}
}
break;
default:
break;
}
return result;
}
#endif // TARGET_CARBON
nsresult CBrowserApp::InitializePrefs()
{
nsresult rv;
nsCOMPtr<nsIPrefService> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv));
if (NS_FAILED(rv))
return rv;
// We are using the default prefs from mozilla. If you were
// disributing your own, this would be done simply by editing
// the default pref files.
nsCOMPtr<nsIPrefBranch> branch;
rv = prefs->GetBranch(nsnull, getter_AddRefs(branch));
if (NS_FAILED(rv))
return rv;
const char kVariableFontSizePref[] = "font.size.variable.x-western";
const char kFixedFontSizePref[] = "font.size.fixed.x-western";
PRInt32 intValue;
rv = branch->GetIntPref(kVariableFontSizePref, &intValue);
if (NS_FAILED(rv))
branch->SetIntPref(kVariableFontSizePref, 14);
rv = branch->GetIntPref(kFixedFontSizePref, &intValue);
if (NS_FAILED(rv))
branch->SetIntPref(kFixedFontSizePref, 13);
return NS_OK;
}
// ---------------------------------------------------------------------------
// CBrowserApp::DoStartUp
//
// Called from CStartUpTask. We must use this INSTEAD of LApplication::StartUp.
// Reason is, LApplication::StartUp happens in response to the open application AE
// which is processed as soon as we process any events - as in while the profile
// manager dialog is up :-/
// ---------------------------------------------------------------------------
void CBrowserApp::OnStartUp()
{
ObeyCommand(PP_PowerPlant::cmd_New, nil);
}
Boolean CBrowserApp::SelectFileObject(PP_PowerPlant::CommandT inCommand,
FSSpec& outSpec)
{
UNavServicesDialogs::LFileChooser chooser;
NavDialogOptions *theDialogOptions = chooser.GetDialogOptions();
if (theDialogOptions) {
theDialogOptions->dialogOptionFlags |= kNavSelectAllReadableItem;
}
Boolean result;
SInt32 dirID;
if (inCommand == cmd_OpenDirectory)
{
result = chooser.AskChooseFolder(outSpec, dirID);
}
else
{
result = chooser.AskOpenFile(LFileTypeList(fileTypes_All));
if (result)
chooser.GetFileSpec(1, outSpec);
}
return result;
}
#ifdef USE_PROFILES
// ---------------------------------------------------------------------------
// CBrowserApp : nsISupports
// ---------------------------------------------------------------------------
NS_IMPL_ISUPPORTS2(CBrowserApp, nsIObserver, nsISupportsWeakReference)
// ---------------------------------------------------------------------------
// CBrowserApp : nsIObserver
// ---------------------------------------------------------------------------
NS_IMETHODIMP CBrowserApp::Observe(nsISupports *aSubject, const char *aTopic, const PRUnichar *someData)
{
#define CLOSE_WINDOWS_ON_SWITCH 1
nsresult rv = NS_OK;
if (!nsCRT::strcmp(aTopic, "profile-approve-change"))
{
// Ask the user if they want to
DialogItemIndex item = UModalAlerts::StopAlert(alrt_ConfirmProfileSwitch);
if (item != kStdOkItemIndex)
{
nsCOMPtr<nsIProfileChangeStatus> status = do_QueryInterface(aSubject);
NS_ENSURE_TRUE(status, NS_ERROR_FAILURE);
status->VetoChange();
}
}
else if (!nsCRT::strcmp(aTopic, "profile-change-teardown"))
{
// Close all open windows. Alternatively, we could just call CBrowserWindow::Stop()
// on each. Either way, we have to stop all network activity on this phase.
TArrayIterator<LCommander*> iterator(mSubCommanders, LArrayIterator::from_End);
LCommander* theSub;
while (iterator.Previous(theSub)) {
CBrowserWindow *browserWindow = dynamic_cast<CBrowserWindow*>(theSub);
if (browserWindow) {
//browserWindow->Stop();
mSubCommanders.RemoveItemsAt(1, iterator.GetCurrentIndex());
delete browserWindow;
}
}
}
else if (!nsCRT::strcmp(aTopic, "profile-after-change"))
{
InitializePrefs();
if (!nsCRT::strcmp(someData, NS_LITERAL_STRING("switch").get())) {
// Make a new default window
ObeyCommand(PP_PowerPlant::cmd_New, nil);
}
}
return rv;
}
#endif // USE_PROFILES

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

@ -1,116 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* 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 the Initial Developer are Copyright (C) 1999
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Conrad Carlen <ccarlen@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#pragma once
#include <PP_Prefix.h>
#include <LApplication.h>
#include "nsError.h"
#include "nsIObserver.h"
#include "nsWeakReference.h"
#ifndef USE_PROFILES
class nsProfileDirServiceProvider;
#endif
class CBrowserApp : public PP_PowerPlant::LApplication
#ifdef USE_PROFILES
,public nsIObserver
,public nsSupportsWeakReference
#endif
{
friend class CStartUpTask;
public:
CBrowserApp(); // constructor registers PPobs
virtual ~CBrowserApp(); // stub destructor
#ifdef USE_PROFILES
NS_DECL_ISUPPORTS
NS_DECL_NSIOBSERVER
#endif
virtual void AdjustCursor(const EventRecord& inMacEvent);
virtual void HandleAppleEvent(const AppleEvent& inAppleEvent,
AppleEvent& outAEReply,
AEDesc& outResult,
long inAENumber);
// 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,
UInt16 &outMark, Str255 outName);
virtual Boolean AttemptQuitSelf(SInt32 inSaveOption);
protected:
virtual nsresult OverrideComponents();
virtual void MakeMenuBar();
virtual void Initialize();
#if TARGET_CARBON
virtual void InstallCarbonEventHandlers();
static pascal OSStatus AppEventHandler(EventHandlerCallRef myHandlerChain,
EventRef event,
void* userData);
#endif
virtual nsresult InitializePrefs();
virtual void OnStartUp();
virtual Boolean SelectFileObject(PP_PowerPlant::CommandT inCommand,
FSSpec& outSpec);
#ifdef USE_PROFILES
Boolean ConfirmProfileSwitch();
#else
nsProfileDirServiceProvider* mProfDirServiceProvider;
#endif
};

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

@ -1,569 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* 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 mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Conrad Carlen <ccarlen@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
// Local Includes
#include "CBrowserChrome.h"
#include "CBrowserShell.h"
#include "CBrowserMsgDefs.h"
#include "nsIGenericFactory.h"
#include "nsString.h"
#include "nsXPIDLString.h"
#include "nsReadableUtils.h"
#include "nsIURI.h"
#include "nsIWebProgress.h"
#include "nsIDocShellTreeItem.h"
#include "nsIRequest.h"
#include "nsIChannel.h"
#include "nsIDOMWindow.h"
#include "nsIDOMDocument.h"
#include "nsIDOMElement.h"
#include "nsIWindowWatcher.h"
#include "nsServiceManagerUtils.h"
#include "UMacUnicode.h"
#include "ApplIDs.h"
#include <LStaticText.h>
#include <LCheckBox.h>
#include <LEditText.h>
#include <UModalDialogs.h>
#include <LPushButton.h>
// Interfaces needed to be included
// Defines
// Constants
const PRInt32 kGrowIconSize = 15;
//*****************************************************************************
//*** CBrowserChrome:
//*****************************************************************************
CBrowserChrome::CBrowserChrome(CBrowserShell *aShell,
UInt32 aChromeFlags,
Boolean aIsMainContent) :
mBrowserShell(aShell), mBrowserWindow(nsnull),
mChromeFlags(aChromeFlags), mIsMainContent(aIsMainContent),
mSizeToContent(false),
mInModalLoop(false), mWindowVisible(false),
mInitialLoadComplete(false)
{
ThrowIfNil_(mBrowserShell);
mBrowserWindow = LWindow::FetchWindowObject(mBrowserShell->GetMacWindow());
StartListening();
}
CBrowserChrome::~CBrowserChrome()
{
}
void CBrowserChrome::SetBrowserShell(CBrowserShell *aShell)
{
mBrowserShell = aShell;
if (mBrowserShell)
mBrowserWindow = LWindow::FetchWindowObject(mBrowserShell->GetMacWindow());
else
mBrowserWindow = nsnull;
}
//*****************************************************************************
// CBrowserChrome::nsISupports
//*****************************************************************************
NS_IMPL_ISUPPORTS8(CBrowserChrome,
nsIWebBrowserChrome,
nsIInterfaceRequestor,
nsIWebBrowserChromeFocus,
nsIEmbeddingSiteWindow,
nsIEmbeddingSiteWindow2,
nsIContextMenuListener2,
nsITooltipListener,
nsISupportsWeakReference);
//*****************************************************************************
// CBrowserChrome::nsIInterfaceRequestor
//*****************************************************************************
NS_IMETHODIMP CBrowserChrome::GetInterface(const nsIID &aIID, void** aInstancePtr)
{
if (aIID.Equals(NS_GET_IID(nsIDOMWindow)))
{
nsCOMPtr<nsIWebBrowser> browser;
GetWebBrowser(getter_AddRefs(browser));
if (browser)
return browser->GetContentDOMWindow((nsIDOMWindow **) aInstancePtr);
return NS_ERROR_NOT_INITIALIZED;
}
return QueryInterface(aIID, aInstancePtr);
}
//*****************************************************************************
// CBrowserChrome::nsIWebBrowserChrome
//*****************************************************************************
NS_IMETHODIMP CBrowserChrome::SetStatus(PRUint32 statusType, const PRUnichar *status)
{
NS_ENSURE_TRUE(mBrowserShell, NS_ERROR_NOT_INITIALIZED);
MsgChromeStatusChangeInfo info(mBrowserShell, statusType, status);
mBrowserShell->BroadcastMessage(msg_OnChromeStatusChange, &info);
return NS_OK;
}
NS_IMETHODIMP CBrowserChrome::GetWebBrowser(nsIWebBrowser** aWebBrowser)
{
NS_ENSURE_ARG_POINTER(aWebBrowser);
NS_ENSURE_TRUE(mBrowserShell, NS_ERROR_NOT_INITIALIZED);
mBrowserShell->GetWebBrowser(aWebBrowser);
return NS_OK;
}
NS_IMETHODIMP CBrowserChrome::SetWebBrowser(nsIWebBrowser* aWebBrowser)
{
NS_ENSURE_ARG(aWebBrowser); // Passing nsnull is NOT OK
NS_ENSURE_TRUE(mBrowserShell, NS_ERROR_NOT_INITIALIZED);
mBrowserShell->SetWebBrowser(aWebBrowser);
return NS_OK;
}
NS_IMETHODIMP CBrowserChrome::GetChromeFlags(PRUint32* aChromeMask)
{
NS_ENSURE_ARG_POINTER(aChromeMask);
*aChromeMask = mChromeFlags;
return NS_OK;
}
NS_IMETHODIMP CBrowserChrome::SetChromeFlags(PRUint32 aChromeMask)
{
// Yuck - our window would have to be rebuilt to do this.
NS_ERROR("Haven't implemented this yet!");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP CBrowserChrome::DestroyBrowserWindow()
{
NS_ENSURE_TRUE(mBrowserShell, NS_ERROR_NOT_INITIALIZED);
mInModalLoop = false;
delete mBrowserWindow;
return NS_OK;
}
NS_IMETHODIMP CBrowserChrome::IsWindowModal(PRBool *_retval)
{
*_retval = PR_FALSE;
return NS_OK;
}
NS_IMETHODIMP CBrowserChrome::SizeBrowserTo(PRInt32 aCX, PRInt32 aCY)
{
SDimension16 curSize;
mBrowserShell->GetFrameSize(curSize);
mBrowserWindow->ResizeWindowBy((aCX - curSize.width), (aCY - curSize.height));
return NS_OK;
}
NS_IMETHODIMP CBrowserChrome::ShowAsModal(void)
{
// We need this override because StDialogHandler deletes
// its window in its destructor. We don't want that here.
class CChromeDialogHandler : public StDialogHandler
{
public:
CChromeDialogHandler(LWindow* inWindow,
LCommander* inSuper) :
StDialogHandler(inWindow, inSuper)
{ }
virtual ~CChromeDialogHandler()
{ mDialog = nil; }
};
CChromeDialogHandler theHandler(mBrowserWindow, mBrowserWindow->GetSuperCommander());
// Set to false by ExitModalEventLoop or DestroyBrowserWindow
mInModalLoop = true;
while (mInModalLoop)
theHandler.DoDialog();
return NS_OK;
}
NS_IMETHODIMP CBrowserChrome::ExitModalEventLoop(nsresult aStatus)
{
mInModalLoop = false;
return NS_OK;
}
//*****************************************************************************
// CBrowserChrome::nsIWebBrowserChromeFocus
//*****************************************************************************
NS_IMETHODIMP CBrowserChrome::FocusNextElement()
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP CBrowserChrome::FocusPrevElement()
{
return NS_ERROR_NOT_IMPLEMENTED;
}
//*****************************************************************************
// CBrowserChrome::nsIEmbeddingSiteWindow
//*****************************************************************************
NS_IMETHODIMP CBrowserChrome::SetDimensions(PRUint32 flags, PRInt32 x, PRInt32 y, PRInt32 cx, PRInt32 cy)
{
NS_ENSURE_STATE(mBrowserWindow);
NS_ENSURE_STATE(mBrowserShell);
if ((flags & nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_INNER) &&
(flags & nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_OUTER))
return NS_ERROR_INVALID_ARG;
if (flags & nsIEmbeddingSiteWindow::DIM_FLAGS_POSITION)
{
mBrowserWindow->MoveWindowTo(x, y);
}
if (flags & nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_INNER)
{
// Don't resize the inner view independently from the window. Keep them in
// proportion by resizing the window and letting that affect the inner view.
SDimension16 curSize;
mBrowserShell->GetFrameSize(curSize);
mBrowserWindow->ResizeWindowBy(cx - curSize.width, cy - curSize.height);
}
else if (flags & nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_OUTER)
{
if (mBrowserWindow->HasAttribute(windAttr_Resizable /*windAttr_SizeBox*/))
cy += 15;
mBrowserWindow->ResizeWindowTo(cx, cy);
}
return NS_OK;
}
NS_IMETHODIMP CBrowserChrome::GetDimensions(PRUint32 flags, PRInt32 *x, PRInt32 *y, PRInt32 *cx, PRInt32 *cy)
{
NS_ENSURE_STATE(mBrowserWindow);
NS_ENSURE_STATE(mBrowserShell);
if ((flags & nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_INNER) &&
(flags & nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_OUTER))
return NS_ERROR_INVALID_ARG;
Rect outerBounds;
if ((flags & nsIEmbeddingSiteWindow::DIM_FLAGS_POSITION) ||
(flags & nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_OUTER))
mBrowserWindow->GetGlobalBounds(outerBounds);
if (flags & nsIEmbeddingSiteWindow::DIM_FLAGS_POSITION)
{
if (x)
*x = outerBounds.left;
if (y)
*y = outerBounds.top;
}
if (flags & nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_INNER)
{
SDimension16 curSize;
mBrowserShell->GetFrameSize(curSize);
if (cx)
*cx = curSize.width;
if (cy)
*cy = curSize.height;
}
else if (flags & nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_OUTER)
{
if (cx)
*cx = outerBounds.right - outerBounds.left;
if (cy)
{
*cy = outerBounds.bottom - outerBounds.top;
if (mBrowserWindow->HasAttribute(windAttr_Resizable /*windAttr_SizeBox*/))
*cy -= 15;
}
}
return NS_OK;
}
NS_IMETHODIMP CBrowserChrome::SetFocus()
{
mBrowserWindow->Select();
return NS_OK;
}
NS_IMETHODIMP CBrowserChrome::GetVisibility(PRBool *aVisibility)
{
NS_ENSURE_STATE(mBrowserWindow);
NS_ENSURE_ARG_POINTER(aVisibility);
*aVisibility = mWindowVisible;
return NS_OK;
}
NS_IMETHODIMP CBrowserChrome::SetVisibility(PRBool aVisibility)
{
NS_ENSURE_STATE(mBrowserWindow);
if (aVisibility == mWindowVisible)
return NS_OK;
mWindowVisible = aVisibility;
// If we are being told to become visible but we need to wait for
// content to load so that we can size ourselves to it,
// don't actually show it now. That will be done after the
// load completes.
PRBool sizingToContent = mIsMainContent &&
(mChromeFlags & CHROME_OPENAS_CHROME) &&
(mChromeFlags & CHROME_OPENAS_DIALOG);
if (sizingToContent && mWindowVisible && !mInitialLoadComplete)
return NS_OK;
aVisibility ? mBrowserWindow->Show() : mBrowserWindow->Hide();
return NS_OK;
}
NS_IMETHODIMP CBrowserChrome::GetTitle(PRUnichar * *aTitle)
{
NS_ENSURE_STATE(mBrowserWindow);
NS_ENSURE_ARG_POINTER(aTitle);
Str255 pStr;
nsAutoString titleStr;
mBrowserWindow->GetDescriptor(pStr);
CPlatformUCSConversion::GetInstance()->PlatformToUCS(pStr, titleStr);
*aTitle = ToNewUnicode(titleStr);
return NS_OK;
}
NS_IMETHODIMP CBrowserChrome::SetTitle(const PRUnichar * aTitle)
{
NS_ENSURE_STATE(mBrowserWindow);
NS_ENSURE_ARG(aTitle);
Str255 pStr;
CPlatformUCSConversion::GetInstance()->UCSToPlatform(nsDependentString(aTitle), pStr);
mBrowserWindow->SetDescriptor(pStr);
return NS_OK;
}
NS_IMETHODIMP CBrowserChrome::GetSiteWindow(void * *aSiteWindow)
{
NS_ENSURE_ARG(aSiteWindow);
NS_ENSURE_STATE(mBrowserWindow);
*aSiteWindow = mBrowserWindow->GetMacWindow();
return NS_OK;
}
//*****************************************************************************
// CBrowserChrome::nsIEmbeddingSiteWindow2
//*****************************************************************************
NS_IMETHODIMP CBrowserChrome::Blur(void)
{
WindowPtr currWindow = ::GetWindowList();
WindowPtr nextWindow;
// Find the rearmost window and put ourselves behind it
while (currWindow && ((nextWindow = ::MacGetNextWindow(currWindow)) != nsnull))
currWindow = nextWindow;
WindowPtr ourWindow = mBrowserWindow->GetMacWindow();
if (ourWindow != currWindow)
::SendBehind(ourWindow, currWindow);
return NS_OK;
}
//*****************************************************************************
// CBrowserChrome::nsIContextMenuListener2
//*****************************************************************************
NS_IMETHODIMP CBrowserChrome::OnShowContextMenu(PRUint32 aContextFlags, nsIContextMenuInfo *aInfo)
{
nsresult rv;
try
{
rv = mBrowserShell->OnShowContextMenu(aContextFlags, aInfo);
}
catch (...)
{
rv = NS_ERROR_FAILURE;
}
return rv;
}
//*****************************************************************************
// CBrowserChrome::nsITooltipListener
//*****************************************************************************
NS_IMETHODIMP CBrowserChrome::OnShowTooltip(PRInt32 aXCoords, PRInt32 aYCoords, const PRUnichar *aTipText)
{
nsresult rv;
try
{
rv = mBrowserShell->OnShowTooltip(aXCoords, aYCoords, aTipText);
}
catch (...)
{
rv = NS_ERROR_FAILURE;
}
return rv;
}
NS_IMETHODIMP CBrowserChrome::OnHideTooltip()
{
nsresult rv;
try
{
rv = mBrowserShell->OnHideTooltip();
}
catch (...)
{
rv = NS_ERROR_FAILURE;
}
return rv;
}
//*****************************************************************************
// CBrowserChrome::LListener
//*****************************************************************************
void CBrowserChrome::ListenToMessage(MessageT inMessage, void* ioParam)
{
switch (inMessage)
{
case msg_OnNetStopChange:
{
mInitialLoadComplete = true;
// See if we need to size it and show it
if (mIsMainContent &&
(mChromeFlags & nsIWebBrowserChrome::CHROME_OPENAS_CHROME) &&
(mChromeFlags & nsIWebBrowserChrome::CHROME_OPENAS_DIALOG))
{
nsCOMPtr<nsIDOMWindow> domWindow;
(void)GetInterface(NS_GET_IID(nsIDOMWindow), getter_AddRefs(domWindow));
if (domWindow)
domWindow->SizeToContent();
if (mWindowVisible != mBrowserWindow->IsVisible())
mBrowserWindow->Show();
}
// If we are chrome, get the window title from the DOM
if (mChromeFlags & nsIWebBrowserChrome::CHROME_OPENAS_CHROME)
{
nsresult rv;
nsCOMPtr<nsIDOMWindow> domWindow;
rv = GetInterface(NS_GET_IID(nsIDOMWindow), getter_AddRefs(domWindow));
if (NS_FAILED(rv)) return;
nsCOMPtr<nsIDOMDocument> domDoc;
rv = domWindow->GetDocument(getter_AddRefs(domDoc));
if (NS_FAILED(rv)) return;
nsCOMPtr<nsIDOMElement> domDocElem;
rv = domDoc->GetDocumentElement(getter_AddRefs(domDocElem));
if (NS_FAILED(rv)) return;
nsAutoString windowTitle;
domDocElem->GetAttribute(NS_LITERAL_STRING("title"), windowTitle);
if (!windowTitle.IsEmpty()) {
Str255 pStr;
CPlatformUCSConversion::GetInstance()->UCSToPlatform(windowTitle, pStr);
mBrowserWindow->SetDescriptor(pStr);
}
}
}
break;
}
}
//*****************************************************************************
// Static Utility Method
//*****************************************************************************
LWindow* CBrowserChrome::GetLWindowForDOMWindow(nsIDOMWindow* aDOMWindow)
{
if (!aDOMWindow)
return nsnull;
nsCOMPtr<nsIWindowWatcher> windowWatcher(do_GetService(NS_WINDOWWATCHER_CONTRACTID));
if (!windowWatcher)
return nsnull;
nsCOMPtr<nsIWebBrowserChrome> windowChrome;
windowWatcher->GetChromeForWindow(aDOMWindow, getter_AddRefs(windowChrome));
if (!windowChrome)
return nsnull;
nsCOMPtr<nsIEmbeddingSiteWindow> siteWindow(do_QueryInterface(windowChrome));
if (!siteWindow)
return nsnull;
WindowPtr macWindow = nsnull;
siteWindow->GetSiteWindow((void **)&macWindow);
if (!macWindow)
return nsnull;
return LWindow::FetchWindowObject(macWindow);
}

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

@ -1,114 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* 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 mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Conrad Carlen <ccarlen@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef __CBrowserChrome__
#define __CBrowserChrome__
#pragma once
// Helper Classes
#include "nsCOMPtr.h"
// Interfaces Needed
#include "nsIWebBrowserChrome.h"
#include "nsIWebBrowserChromeFocus.h"
#include "nsIEmbeddingSiteWindow2.h"
#include "nsIInterfaceRequestor.h"
#include "nsIInterfaceRequestorUtils.h"
#include "nsIContextMenuListener2.h"
#include "nsITooltipListener.h"
#include "nsWeakReference.h"
#include <LListener.h>
// Other
#include "nsIWebBrowser.h"
class CBrowserShell;
class CBrowserChrome : public nsIWebBrowserChrome,
public nsIWebBrowserChromeFocus,
public nsIEmbeddingSiteWindow2,
public nsIInterfaceRequestor,
public nsIContextMenuListener2,
public nsITooltipListener,
public nsSupportsWeakReference,
public LListener
{
friend class CBrowserShell;
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIWEBBROWSERCHROME
NS_DECL_NSIWEBBROWSERCHROMEFOCUS
NS_DECL_NSIEMBEDDINGSITEWINDOW
NS_DECL_NSIEMBEDDINGSITEWINDOW2
NS_DECL_NSIINTERFACEREQUESTOR
NS_DECL_NSICONTEXTMENULISTENER2
NS_DECL_NSITOOLTIPLISTENER
// LListener
virtual void ListenToMessage(MessageT inMessage,
void* ioParam);
// Utility
static LWindow* GetLWindowForDOMWindow(nsIDOMWindow* aDOMWindow);
protected:
CBrowserChrome(CBrowserShell* aShell,
UInt32 aChromeFlags,
Boolean aIsMainContent);
virtual ~CBrowserChrome();
void SetBrowserShell(CBrowserShell* aShell);
protected:
CBrowserShell *mBrowserShell;
LWindow *mBrowserWindow;
PRUint32 mChromeFlags;
Boolean mIsMainContent;
Boolean mSizeToContent;
Boolean mInModalLoop;
Boolean mWindowVisible;
Boolean mInitialLoadComplete;
};
#endif // __CBrowserChrome__

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

@ -1,153 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* 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 mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Conrad Carlen <ccarlen@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef __CBrowserShellMsgDefs__
#define __CBrowserShellMsgDefs__
#pragma once
// Messages sent by CBrowserShell
#ifndef EMBED_MSG_BASE_ID
#define EMBED_MSG_BASE_ID 1000
#endif
enum {
msg_OnNetStartChange = EMBED_MSG_BASE_ID + 0,
msg_OnNetStopChange = EMBED_MSG_BASE_ID + 1,
msg_OnProgressChange = EMBED_MSG_BASE_ID + 2,
msg_OnLocationChange = EMBED_MSG_BASE_ID + 3,
msg_OnStatusChange = EMBED_MSG_BASE_ID + 4,
msg_OnSecurityChange = EMBED_MSG_BASE_ID + 5,
msg_OnChromeStatusChange = EMBED_MSG_BASE_ID + 6
};
/**
* CBrowserShell and CBrowserChrome broadcast changes using LBroadcaster::BroadcastMessage()
* A pointer to one of the following types is passed as the ioParam.
*/
// msg_OnNetStartChange
struct MsgNetStartInfo
{
MsgNetStartInfo(CBrowserShell* broadcaster) :
mBroadcaster(broadcaster)
{ }
CBrowserShell *mBroadcaster;
};
// msg_OnNetStopChange
struct MsgNetStopInfo
{
MsgNetStopInfo(CBrowserShell* broadcaster) :
mBroadcaster(broadcaster)
{ }
CBrowserShell *mBroadcaster;
};
// msg_OnProgressChange
struct MsgOnProgressChangeInfo
{
MsgOnProgressChangeInfo(CBrowserShell* broadcaster, PRInt32 curProgress, PRInt32 maxProgress) :
mBroadcaster(broadcaster), mCurProgress(curProgress), mMaxProgress(maxProgress)
{ }
CBrowserShell *mBroadcaster;
PRInt32 mCurProgress, mMaxProgress;
};
// msg_OnLocationChange
struct MsgLocationChangeInfo
{
MsgLocationChangeInfo(CBrowserShell* broadcaster,
const char* urlSpec) :
mBroadcaster(broadcaster), mURLSpec(urlSpec)
{ }
CBrowserShell *mBroadcaster;
const char *mURLSpec;
};
// msg_OnStatusChange
struct MsgStatusChangeInfo
{
MsgStatusChangeInfo(CBrowserShell* broadcaster,
nsresult status, const PRUnichar *message) :
mBroadcaster(broadcaster),
mStatus(status), mMessage(message)
{ }
CBrowserShell *mBroadcaster;
nsresult mStatus;
const PRUnichar *mMessage;
};
// msg_OnSecurityChange
struct MsgSecurityChangeInfo
{
MsgSecurityChangeInfo(CBrowserShell* broadcaster,
PRUint32 state) :
mBroadcaster(broadcaster),
mState(state)
{ }
CBrowserShell *mBroadcaster;
PRUint32 mState;
};
// msg_OnChromeStatusChange
// See nsIWebBrowserChrome::SetStatus
struct MsgChromeStatusChangeInfo
{
MsgChromeStatusChangeInfo(CBrowserShell* broadcaster,
PRUint32 statusType,
const PRUnichar* status) :
mBroadcaster(broadcaster),
mStatusType(statusType), mStatus(status)
{ }
CBrowserShell *mBroadcaster;
PRUint32 mStatusType;
const PRUnichar *mStatus;
};
#endif // __CBrowserShellMsgDefs__

Разница между файлами не показана из-за своего большого размера Загрузить разницу

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

@ -1,254 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* 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 the Initial Developer are Copyright (C) 1999
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Conrad Carlen <ccarlen@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef __CBrowserShell__
#define __CBrowserShell__
#include <LView.h>
#include <LCommander.h>
#include <LPeriodical.h>
#include <LListener.h>
#include <LString.h>
#include <LDragAndDrop.h>
#include "CHeaderSniffer.h"
#include "nsCOMPtr.h"
#include "nsAString.h"
#include "nsIWebBrowser.h"
#include "nsIBaseWindow.h"
#include "nsIWebNavigation.h"
#include "nsIEventSink.h"
#include "nsIWebProgress.h"
#include "nsIDragHelperService.h"
#include "nsIPrintSettings.h"
class CBrowserChrome;
class CBrowserShellProgressListener;
class nsIContentViewer;
class nsIClipboardCommands;
class nsIDOMEvent;
class nsIDOMNode;
class nsIContextMenuInfo;
//*****************************************************************************
//*** CBrowserShell
//*****************************************************************************
class CBrowserShell : public LView,
public LCommander,
public LBroadcaster,
public LPeriodical,
public LDropArea
{
friend class CBrowserChrome;
private:
typedef LView Inherited;
public:
enum { class_ID = FOUR_CHAR_CODE('BroS') };
enum { paneID_MainBrowser = 'WebS' };
static const nsCString kEmptyCString;
CBrowserShell();
CBrowserShell(const SPaneInfo &inPaneInfo,
const SViewInfo &inViewInfo,
UInt32 inChromeFlags,
Boolean inIsMainContent);
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 ActivateSelf();
virtual void DeactivateSelf();
virtual void ShowSelf();
virtual void DrawSelf();
virtual void ClickSelf(const SMouseDownEvent &inMouseDown);
virtual void EventMouseUp(const EventRecord &inMacEvent);
virtual void AdjustMouseSelf(Point /* inPortPt */,
const EventRecord& inMacEvent,
RgnHandle outMouseRgn);
// LCommander
virtual void BeTarget();
virtual void DontBeTarget();
virtual Boolean HandleKeyPress(const EventRecord &inKeyEvent);
virtual Boolean ObeyCommand(PP_PowerPlant::CommandT inCommand, void* ioParam);
virtual void FindCommandStatus(PP_PowerPlant::CommandT inCommand,
Boolean &outEnabled, Boolean &outUsesMark,
UInt16 &outMark, Str255 outName);
// LPeriodical
virtual void SpendTime(const EventRecord& inMacEvent);
// Text Input Event Handling
virtual OSStatus HandleUpdateActiveInputArea(const nsAString& text,
PRInt16 script, PRInt16 language,
PRInt32 fixLen, const TextRangeArray * hiliteRng);
virtual OSStatus HandleUnicodeForKeyEvent(const nsAString& text,
PRInt16 script, PRInt16 language,
const EventRecord* keyboardEvent);
virtual OSStatus HandleOffsetToPos(PRInt32 offset, PRInt16 *pointX, PRInt16 *pointY);
virtual OSStatus HandlePosToOffset(PRInt16 currentPointX, PRInt16 currentPointY,
PRInt32 *offset, PRInt16 *regionClass);
virtual OSStatus HandleGetSelectedText(nsAString& selectedText);
// CBrowserShell
// Called by the window creator after parameterized contructor. Not used
// when we're created from a 'PPob' resource. In that case, attachments can be
// added with Constructor.
virtual void AddAttachments();
NS_METHOD GetWebBrowser(nsIWebBrowser** aBrowser);
NS_METHOD SetWebBrowser(nsIWebBrowser* aBrowser);
// Drops ref to current one, installs given one
NS_METHOD GetWebBrowserChrome(nsIWebBrowserChrome** aChrome);
NS_METHOD GetContentViewer(nsIContentViewer** aViewer);
NS_METHOD GetPrintSettings(nsIPrintSettings** aSettings);
NS_METHOD GetFocusedWindowURL(nsAString& outURL);
Boolean IsBusy();
Boolean CanGoBack();
Boolean CanGoForward();
NS_METHOD Back();
NS_METHOD Forward();
NS_METHOD Stop();
NS_METHOD Reload();
// String params are UTF-8 encoded.
NS_METHOD LoadURL(const nsACString& urlText, const nsACString& referrer = kEmptyCString);
NS_METHOD GetCurrentURL(nsACString& urlText);
// Puts up a Save As dialog and saves current URI and all images, etc.
NS_METHOD SaveDocument(ESaveFormat inSaveFormat = eSaveFormatUnspecified);
// Puts up a Save As dialog and saves the given URI. Pass null to save the current page.
NS_METHOD SaveLink(nsIURI* inURI);
NS_METHOD SaveInternal(nsIURI* inURI, nsIDOMDocument* inDocument, const nsAString& inSuggestedFilename, Boolean inBypassCache, ESaveFormat inSaveFormat = eSaveFormatUnspecified);
// 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 nsAString& searchStr,
Boolean caseSensitive,
Boolean searchBackward,
Boolean wrapSearch,
Boolean wholeWordOnly);
Boolean CanFindNext();
Boolean FindNext();
protected:
// LDropArea
virtual void InsideDropArea( DragReference inDragRef );
virtual Boolean PointInDropArea( Point inGlobalPt) ;
virtual Boolean DragIsAcceptable( DragReference inDragRef );
virtual void EnterDropArea( DragReference inDragRef, Boolean inDragHasLeftSender);
virtual void LeaveDropArea( DragReference inDragRef );
virtual void DoDragReceive( DragReference inDragRef );
NS_IMETHOD OnShowContextMenu(PRUint32 aContextFlags,
nsIContextMenuInfo *aInfo);
NS_IMETHOD OnShowTooltip(PRInt32 aXCoords,
PRInt32 aYCoords,
const PRUnichar *aTipText);
NS_IMETHOD OnHideTooltip();
NS_METHOD CommonConstruct();
void HandleMouseMoved(const EventRecord& inMacEvent);
void AdjustFrame();
virtual Boolean DoFindDialog(nsAString& searchText,
PRBool& findBackwards,
PRBool& wrapFind,
PRBool& entireWord,
PRBool& caseSensitive);
NS_METHOD GetClipboardHandler(nsIClipboardCommands **aCommand);
Boolean HasFormElements();
virtual void PostOpenURLEvent(const nsACString& url, const nsACString& referrer);
protected:
UInt32 mChromeFlags;
Boolean mIsMainContent;
nsCOMPtr<nsIEventSink> mEventSink; // for event dispatch
nsCOMPtr<nsIWebBrowser> mWebBrowser; // The thing we actually create
nsCOMPtr<nsIBaseWindow> mWebBrowserAsBaseWin; // Convenience interface to above
nsCOMPtr<nsIWebNavigation> mWebBrowserAsWebNav; // Ditto
static nsCOMPtr<nsIDragHelperService> sDragHelper;
CBrowserChrome *mChrome;
CBrowserShellProgressListener *mProgressListener;
// These are stored only during OnShowContextMenu so that they can
// be used by FindCommandStatus and ObeyCommand which get called
// during OnShowContextMenu.
PRUint32 mContextMenuFlags;
nsIContextMenuInfo *mContextMenuInfo;
nsCOMPtr<nsIPrintSettings> mPrintSettings;
};
#endif // __CBrowserShell__

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

@ -1,412 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* 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 the Initial Developer are Copyright (C) 1999
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Conrad Carlen <ccarlen@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsString.h"
#include "nsReadableUtils.h"
#include "nsWidgetsCID.h"
#include "nsIComponentManager.h"
#include "nsIServiceManager.h"
#include "nsIChannel.h"
#include "nsIURI.h"
#include "nsXPIDLString.h"
#include "nsIWindowCreator.h"
#include "nsIWindowWatcher.h"
#include "nsIDOMWindow.h"
#include "nsIDOMDocument.h"
#include "nsIDOMWindowInternal.h"
#include "nsRect.h"
#include "nsIWebProgressListener.h"
#include "CBrowserWindow.h"
#include "CBrowserShell.h"
#include "CBrowserMsgDefs.h"
#include "CThrobber.h"
#include "ApplIDs.h"
#include "UMacUnicode.h"
#include <LEditText.h>
#include <LStaticText.h>
#include <LWindowHeader.h>
#include <LBevelButton.h>
#include <LProgressBar.h>
#include <LIconControl.h>
#if PP_Target_Carbon
#include <UEventMgr.h>
#endif
#include <algorithm>
using namespace std;
#include <InternetConfig.h>
// 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_ReloadButton = 'RLoa',
paneID_StopButton = 'Stop',
paneID_URLField = 'gUrl',
paneID_StatusBar = 'Stat',
paneID_Throbber = 'THRB',
paneID_ProgressBar = 'Prog',
paneID_LockIcon = 'Lock'
};
// ---------------------------------------------------------------------------
// ¥ CBrowserWindow Default Constructor [public]
// ---------------------------------------------------------------------------
CBrowserWindow::CBrowserWindow() :
mURLField(NULL), mStatusBar(NULL), mThrobber(NULL),
mBackButton(NULL), mForwardButton(NULL), mStopButton(NULL),
mProgressBar(NULL), mLockIcon(NULL)
{
}
// ---------------------------------------------------------------------------
// ¥ CBrowserWindow Parameterized Constructor [public]
// ---------------------------------------------------------------------------
CBrowserWindow::CBrowserWindow(LCommander* inSuperCommander,
const Rect& inGlobalBounds,
ConstStringPtr inTitle,
SInt16 inProcID,
UInt32 inAttributes,
WindowPtr inBehind) :
LWindow(inSuperCommander, inGlobalBounds, inTitle, inProcID, inAttributes, inBehind),
mURLField(NULL), mStatusBar(NULL), mThrobber(NULL),
mBackButton(NULL), mForwardButton(NULL), mStopButton(NULL),
mProgressBar(NULL), mLockIcon(NULL)
{
}
// ---------------------------------------------------------------------------
// ¥ CBrowserWindow Stream Constructor [public]
// ---------------------------------------------------------------------------
CBrowserWindow::CBrowserWindow(LStream* inStream) :
LWindow(inStream),
mURLField(NULL), mStatusBar(NULL), mThrobber(NULL),
mBackButton(NULL), mForwardButton(NULL), mStopButton(NULL),
mProgressBar(NULL), mLockIcon(NULL)
{
}
// ---------------------------------------------------------------------------
// ¥ ~CBrowserWindow Destructor [public]
// ---------------------------------------------------------------------------
CBrowserWindow::~CBrowserWindow()
{
if (mBrowserShell)
mBrowserShell->RemoveListener(this);
}
// ---------------------------------------------------------------------------
// ¥ FinishCreateSelf
// ---------------------------------------------------------------------------
void CBrowserWindow::FinishCreateSelf()
{
mBrowserShell = dynamic_cast<CBrowserShell *>(FindPaneByID(CBrowserShell::paneID_MainBrowser));
ThrowIfNil_(mBrowserShell);
mBrowserShell->AddListener(this);
SetLatentSub(mBrowserShell);
// Find our subviews - Depending on our chrome flags, we may or may
// not have any of these subviews so don't fail if they don't exist
mURLField = dynamic_cast<LEditText*>(FindPaneByID(paneID_URLField));
mStatusBar = dynamic_cast<LStaticText*>(FindPaneByID(paneID_StatusBar));
mThrobber = dynamic_cast<CThrobber*>(FindPaneByID(paneID_Throbber));
mLockIcon = dynamic_cast<LIconControl*>(FindPaneByID(paneID_LockIcon));
mProgressBar = dynamic_cast<LProgressBar*>(FindPaneByID(paneID_ProgressBar));
if (mProgressBar)
mProgressBar->Hide();
mBackButton = dynamic_cast<LControl*>(FindPaneByID(paneID_BackButton));
if (mBackButton)
mBackButton->Disable();
mForwardButton = dynamic_cast<LControl*>(FindPaneByID(paneID_ForwardButton));
if (mForwardButton)
mForwardButton->Disable();
mReloadButton = dynamic_cast<LControl*>(FindPaneByID(paneID_ReloadButton));
if (mReloadButton)
mReloadButton->Disable();
mStopButton = dynamic_cast<LControl*>(FindPaneByID(paneID_StopButton));
if (mStopButton)
mStopButton->Disable();
UReanimator::LinkListenerToControls(this, this, view_BrowserToolBar);
StartListening();
StartBroadcasting();
}
// ---------------------------------------------------------------------------
// ¥ ListenToMessage
// ---------------------------------------------------------------------------
void CBrowserWindow::ListenToMessage(MessageT inMessage,
void* ioParam)
{
switch (inMessage)
{
case msg_OnNetStartChange:
{
if (mProgressBar) {
mProgressBar->Show();
mProgressBar->SetIndeterminateFlag(true, true);
}
if (mThrobber)
mThrobber->Start();
if (mStopButton)
mStopButton->Enable();
}
break;
case msg_OnNetStopChange:
{
if (mThrobber)
mThrobber->Stop();
if (mProgressBar) {
if (mProgressBar->IsIndeterminate())
mProgressBar->Stop();
mProgressBar->Hide();
}
// Enable back, forward, reload, stop
if (mBackButton)
mBrowserShell->CanGoBack() ? mBackButton->Enable() : mBackButton->Disable();
if (mForwardButton)
mBrowserShell->CanGoForward() ? mForwardButton->Enable() : mForwardButton->Disable();
if (mReloadButton)
mReloadButton->Enable();
if (mStopButton)
mStopButton->Disable();
// Wipe the status clean
if (mStatusBar)
mStatusBar->SetText(nsnull, 0);
}
break;
case msg_OnProgressChange:
{
const MsgOnProgressChangeInfo *info = reinterpret_cast<MsgOnProgressChangeInfo*>(ioParam);
if (mProgressBar) {
if (info->mMaxProgress != -1 && mProgressBar->IsIndeterminate())
mProgressBar->SetIndeterminateFlag(false, false);
else if (info->mMaxProgress == -1 && !mProgressBar->IsIndeterminate())
mProgressBar->SetIndeterminateFlag(true, true);
if (!mProgressBar->IsIndeterminate()) {
PRInt32 aMax = max(0, info->mMaxProgress);
PRInt32 aVal = min(aMax, max(0, info->mCurProgress));
mProgressBar->SetMaxValue(aMax);
mProgressBar->SetValue(aVal);
}
}
}
break;
case msg_OnLocationChange:
{
const MsgLocationChangeInfo *info = reinterpret_cast<MsgLocationChangeInfo*>(ioParam);
if (mURLField)
mURLField->SetText(info->mURLSpec, strlen(info->mURLSpec));
}
break;
case msg_OnStatusChange:
{
const MsgStatusChangeInfo *info = reinterpret_cast<MsgStatusChangeInfo*>(ioParam);
if (mStatusBar) {
nsCAutoString cStr;
CPlatformUCSConversion::GetInstance()->UCSToPlatform(nsDependentString(info->mMessage), cStr);
mStatusBar->SetText(const_cast<char *>(cStr.get()), cStr.Length());
}
}
break;
case msg_OnSecurityChange:
{
const MsgSecurityChangeInfo *info = reinterpret_cast<MsgSecurityChangeInfo*>(ioParam);
if (mLockIcon) {
SInt16 iconID;
switch (info->mState & 0x0000FFFF)
{
case nsIWebProgressListener::STATE_IS_SECURE:
iconID = icon_LockSecure;
break;
case nsIWebProgressListener::STATE_IS_BROKEN:
iconID = icon_LockBroken;
break;
case nsIWebProgressListener::STATE_IS_INSECURE:
iconID = icon_LockInsecure;
break;
default:
NS_ERROR("Unknown security state!");
iconID = icon_LockInsecure;
break;
}
// The kControlIconResourceIDTag requires Appearance 1.1
// That's present on 8.5 and up and mozilla requires 8.6.
mLockIcon->SetDataTag(0, kControlIconResourceIDTag, sizeof(iconID), &iconID);
}
}
break;
case msg_OnChromeStatusChange:
{
const MsgChromeStatusChangeInfo *info = reinterpret_cast<MsgChromeStatusChangeInfo*>(ioParam);
if (mStatusBar) {
nsCAutoString cStr;
CPlatformUCSConversion::GetInstance()->UCSToPlatform(nsDependentString(info->mStatus), cStr);
mStatusBar->SetText(const_cast<char *>(cStr.get()), cStr.Length());
}
}
break;
default:
ProcessCommand(inMessage, ioParam);
break;
}
}
// ---------------------------------------------------------------------------
// ¥ 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_ReloadButton:
mBrowserShell->Reload();
break;
case paneID_StopButton:
mBrowserShell->Stop();
break;
case cmd_Reload:
mBrowserShell->Reload();
break;
case paneID_URLField:
{
SInt32 urlTextLen;
mURLField->GetText(nil, 0, &urlTextLen);
StPointerBlock urlTextPtr(urlTextLen, true, false);
mURLField->GetText(urlTextPtr.Get(), urlTextLen, &urlTextLen);
mBrowserShell->LoadURL(Substring(urlTextPtr.Get(), urlTextPtr.Get() + urlTextLen));
}
break;
default:
cmdHandled = false;
break;
}
if (!cmdHandled)
cmdHandled = LWindow::ObeyCommand(inCommand, ioParam);
return cmdHandled;
}
#if 0
NS_METHOD CBrowserWindow::SetTitleFromDOMDocument()
{
nsresult rv;
nsCOMPtr<nsIDOMWindow> domWindow;
rv = mBrowserChrome->GetInterface(NS_GET_IID(nsIDOMWindow), getter_AddRefs(domWindow));
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIDOMDocument> domDoc;
rv = domWindow->GetDocument(getter_AddRefs(domDoc));
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIDOMElement> domDocElem;
rv = domDoc->GetDocumentElement(getter_AddRefs(domDocElem));
if (NS_FAILED(rv)) return rv;
nsAutoString windowTitle;
domDocElem->GetAttribute(NS_LITERAL_STRING("title"), windowTitle);
if (!windowTitle.IsEmpty()) {
Str255 pStr;
CPlatformUCSConversion::GetInstance()->UCSToPlatform(windowTitle, pStr);
SetDescriptor(pStr);
}
else
rv = NS_ERROR_FAILURE;
return rv;
}
#endif

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

@ -1,103 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* 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 the Initial Developer are Copyright (C) 1999
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Conrad Carlen <ccarlen@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include <LWindow.h>
#include <LListener.h>
#include <LBroadcaster.h>
class CBrowserShell;
class LEditText;
class LStaticText;
class CThrobber;
class LProgressBar;
class LIconControl;
// 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;
public:
enum { class_ID = FOUR_CHAR_CODE('BroW') };
CBrowserWindow();
CBrowserWindow(LCommander* inSuperCommander,
const Rect& inGlobalBounds,
ConstStringPtr inTitle,
SInt16 inProcID,
UInt32 inAttributes,
WindowPtr inBehind);
CBrowserWindow(LStream* inStream);
virtual ~CBrowserWindow();
virtual void FinishCreateSelf();
virtual void ListenToMessage(MessageT inMessage,
void* ioParam);
virtual Boolean ObeyCommand(CommandT inCommand,
void *ioParam);
protected:
CBrowserShell* mBrowserShell;
LEditText* mURLField;
LStaticText* mStatusBar;
CThrobber* mThrobber;
LControl *mBackButton, *mForwardButton, *mReloadButton, *mStopButton;
LProgressBar* mProgressBar;
LIconControl* mLockIcon;
};
// ---------------------------------------------------------------------------
// Global Functions
// ---------------------------------------------------------------------------
// Must be called at initialization time - after NS_InitEmbedding
nsresult InitializeWindowCreator();

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

@ -1,456 +0,0 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* 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 Chimera code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* David Hyatt <hyatt@netscape.com>
* Simon Fraser <sfraser@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "CHeaderSniffer.h"
#include "UMacUnicode.h"
#include "UCustomNavServicesDialogs.h"
#include "netCore.h"
#include "nsIChannel.h"
#include "nsIHttpChannel.h"
#include "nsIURL.h"
#include "nsIStringEnumerator.h"
#include "nsIPrefService.h"
#include "nsIMIMEService.h"
#include "nsIMIMEInfo.h"
#include "nsIDOMHTMLDocument.h"
#include "nsIDownload.h"
#include "nsILocalFileMac.h"
const char* const persistContractID = "@mozilla.org/embedding/browser/nsWebBrowserPersist;1";
CHeaderSniffer::CHeaderSniffer(nsIWebBrowserPersist* aPersist, nsIFile* aFile, nsIURI* aURL,
nsIDOMDocument* aDocument, nsIInputStream* aPostData,
const nsAString& aSuggestedFilename, PRBool aBypassCache, ESaveFormat aSaveFormat)
: mPersist(aPersist)
, mTmpFile(aFile)
, mURL(aURL)
, mDocument(aDocument)
, mPostData(aPostData)
, mDefaultFilename(aSuggestedFilename)
, mBypassCache(aBypassCache)
, mSaveFormat(aSaveFormat)
{
}
CHeaderSniffer::~CHeaderSniffer()
{
}
NS_IMPL_ISUPPORTS1(CHeaderSniffer, nsIWebProgressListener)
#pragma mark -
// Implementation of nsIWebProgressListener
/* void onStateChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long aStateFlags, in unsigned long aStatus); */
NS_IMETHODIMP
CHeaderSniffer::OnStateChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRUint32 aStateFlags,
PRUint32 aStatus)
{
if (aStateFlags & nsIWebProgressListener::STATE_START)
{
nsCOMPtr<nsIWebBrowserPersist> kungFuDeathGrip(mPersist); // be sure to keep it alive while we save
// since it owns us as a listener
nsCOMPtr<nsIWebProgressListener> kungFuSuicideGrip(this); // and keep ourselves alive
nsresult rv;
nsCOMPtr<nsIChannel> channel = do_QueryInterface(aRequest, &rv);
if (!channel) return rv;
channel->GetContentType(mContentType);
nsCOMPtr<nsIURI> origURI;
channel->GetOriginalURI(getter_AddRefs(origURI));
// Get the content-disposition if we're an HTTP channel.
nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(channel));
if (httpChannel)
httpChannel->GetResponseHeader(nsCAutoString("content-disposition"), mContentDisposition);
mPersist->CancelSave();
PRBool exists;
mTmpFile->Exists(&exists);
if (exists)
mTmpFile->Remove(PR_FALSE);
rv = PerformSave(origURI, mSaveFormat);
if (NS_FAILED(rv))
{
// put up some UI
}
}
return NS_OK;
}
/* void onProgressChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long aCurSelfProgress, in long aMaxSelfProgress, in long aCurTotalProgress, in long aMaxTotalProgress); */
NS_IMETHODIMP
CHeaderSniffer::OnProgressChange(nsIWebProgress *aWebProgress,
nsIRequest *aRequest,
PRInt32 aCurSelfProgress,
PRInt32 aMaxSelfProgress,
PRInt32 aCurTotalProgress,
PRInt32 aMaxTotalProgress)
{
return NS_OK;
}
/* void onLocationChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsIURI location); */
NS_IMETHODIMP
CHeaderSniffer::OnLocationChange(nsIWebProgress *aWebProgress,
nsIRequest *aRequest,
nsIURI *location)
{
return NS_OK;
}
/* void onStatusChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsresult aStatus, in wstring aMessage); */
NS_IMETHODIMP
CHeaderSniffer::OnStatusChange(nsIWebProgress *aWebProgress,
nsIRequest *aRequest,
nsresult aStatus,
const PRUnichar *aMessage)
{
return NS_OK;
}
/* void onSecurityChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in unsigned long state); */
NS_IMETHODIMP
CHeaderSniffer::OnSecurityChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRUint32 state)
{
return NS_OK;
}
#pragma mark -
static ESaveFormat SaveFormatFromPrefValue(PRInt32 inPrefValue)
{
switch (inPrefValue)
{
case 0: return eSaveFormatHTMLComplete;
default: // fall through
case 1: return eSaveFormatHTML;
case 2: return eSaveFormatPlainText;
}
}
static PRInt32 PrefValueFromSaveFormat(ESaveFormat inSaveFormat)
{
switch (inSaveFormat)
{
case eSaveFormatPlainText: return 2;
default: // fall through
case eSaveFormatHTML: return 1;
case eSaveFormatHTMLComplete: return 0;
}
}
nsresult CHeaderSniffer::PerformSave(nsIURI* inOriginalURI, const ESaveFormat inSaveFormat)
{
nsresult rv;
// Are we an HTML document? If so, we will want to append an accessory view to
// the save dialog to provide the user with the option of doing a complete
// save vs. a single file save.
PRBool isHTML = (mDocument && mContentType.Equals("text/html") ||
mContentType.Equals("text/xml") ||
mContentType.Equals("application/xhtml+xml"));
// Next find out the directory that we should start in.
nsCOMPtr<nsIPrefService> prefs(do_GetService("@mozilla.org/preferences-service;1", &rv));
if (!prefs)
return rv;
nsCOMPtr<nsIPrefBranch> dirBranch;
prefs->GetBranch("browser.download.", getter_AddRefs(dirBranch));
PRInt32 filterIndex = 0;
if (inSaveFormat != eSaveFormatUnspecified) {
filterIndex = PrefValueFromSaveFormat(inSaveFormat);
}
else if (dirBranch) {
nsresult rv = dirBranch->GetIntPref("save_converter_index", &filterIndex);
if (NS_FAILED(rv))
filterIndex = 0;
}
// We need to figure out what file name to use.
nsAutoString defaultFileName;
if (!mContentDisposition.IsEmpty()) {
// (1) Use the HTTP header suggestion.
PRInt32 index = mContentDisposition.Find("filename=");
if (index >= 0) {
// Take the substring following the prefix.
index += 9;
AppendUTF8toUTF16(Substring(mContentDisposition, index),
defaultFileName);
}
}
if (defaultFileName.IsEmpty()) {
nsCOMPtr<nsIURL> url(do_QueryInterface(mURL));
if (url) {
nsCAutoString fileNameCString;
url->GetFileName(fileNameCString); // (2) For file URLs, use the file name.
AppendUTF8toUTF16(fileNameCString, defaultFileName);
}
}
if (defaultFileName.IsEmpty() && mDocument && isHTML) {
nsCOMPtr<nsIDOMHTMLDocument> htmlDoc(do_QueryInterface(mDocument));
if (htmlDoc)
htmlDoc->GetTitle(defaultFileName); // (3) Use the title of the document.
}
if (defaultFileName.IsEmpty()) {
// (4) Use the caller provided name.
defaultFileName = mDefaultFilename;
}
if (defaultFileName.IsEmpty() && mURL) {
// (5) Use the host.
nsCAutoString hostName;
mURL->GetHost(hostName);
AppendUTF8toUTF16(hostName, defaultFileName);
}
// One last case to handle about:blank and other fruity untitled pages.
if (defaultFileName.IsEmpty())
defaultFileName.AssignLiteral("untitled");
// Validate the file name to ensure legality.
for (PRUint32 i = 0; i < defaultFileName.Length(); i++)
if (defaultFileName[i] == ':' || defaultFileName[i] == '/')
defaultFileName.SetCharAt(i, PRUnichar(' '));
// Make sure the appropriate extension is appended to the suggested file name.
nsCOMPtr<nsIURI> fileURI(do_CreateInstance("@mozilla.org/network/standard-url;1"));
nsCOMPtr<nsIURL> fileURL(do_QueryInterface(fileURI, &rv));
if (!fileURL)
return rv;
fileURL->SetFilePath(NS_ConvertUTF16toUTF8(defaultFileName));
nsCAutoString fileExtension;
fileURL->GetFileExtension(fileExtension);
PRBool setExtension = PR_FALSE;
if (mContentType.Equals("text/html")) {
if (fileExtension.IsEmpty() || (!fileExtension.Equals("htm") && !fileExtension.Equals("html"))) {
defaultFileName.AppendLiteral(".html");
setExtension = PR_TRUE;
}
}
if (!setExtension && fileExtension.IsEmpty()) {
nsCOMPtr<nsIMIMEService> mimeService(do_GetService("@mozilla.org/mime;1", &rv));
if (!mimeService)
return rv;
nsCOMPtr<nsIMIMEInfo> mimeInfo;
rv = mimeService->GetFromTypeAndExtension(mContentType, EmptyCString(), getter_AddRefs(mimeInfo));
if (!mimeInfo)
return rv;
nsCOMPtr<nsIUTF8StringEnumerator> extensions;
mimeInfo->GetFileExtensions(getter_AddRefs(extensions));
PRBool hasMore;
extensions->HasMore(&hasMore);
if (hasMore) {
nsCAutoString ext;
extensions->GetNext(ext);
defaultFileName.Append(PRUnichar('.'));
AppendUTF8toUTF16(ext, defaultFileName);
}
}
// Now it's time to pose the save dialog.
FSSpec destFileSpec;
bool isReplacing = false;
{
Str255 defaultName;
bool result;
CPlatformUCSConversion::GetInstance()->UCSToPlatform(defaultFileName, defaultName);
#ifndef XP_MACOSX
char tempBuf1[256], tempBuf2[64];
::CopyPascalStringToC(defaultName, tempBuf1);
::CopyCStringToPascal(NS_TruncNodeName(tempBuf1, tempBuf2), defaultName);
#endif
if (isHTML) {
ESaveFormat saveFormat = SaveFormatFromPrefValue(filterIndex);
UNavServicesDialogs::LCustomFileDesignator customDesignator;
result = customDesignator.AskDesignateFile(defaultName, saveFormat);
if (!result)
return NS_OK; // user canceled
filterIndex = PrefValueFromSaveFormat(saveFormat);
customDesignator.GetFileSpec(destFileSpec);
isReplacing = customDesignator.IsReplacing();
}
else {
UNavServicesDialogs::LFileDesignator stdDesignator;
result = stdDesignator.AskDesignateFile(defaultName);
if (!result)
return NS_OK; // user canceled
stdDesignator.GetFileSpec(destFileSpec);
isReplacing = stdDesignator.IsReplacing();
}
// After the dialog is dismissed, process all activation an update events right away.
// The save dialog code calls UDesktop::Activate after dismissing the dialog. All that
// does is activate the now frontmost LWindow which was behind the dialog. It does not
// remove the activate event from the queue. If that event is not processed and removed
// before we show the progress window, bad things happen. Specifically, the progress
// dialog will show in front and then, shortly thereafter, the window which was behind this save
// dialog will be moved to the front.
if (LEventDispatcher::GetCurrentEventDispatcher()) { // Can this ever be NULL?
EventRecord theEvent;
while (::WaitNextEvent(updateMask | activMask, &theEvent, 0, nil))
LEventDispatcher::GetCurrentEventDispatcher()->DispatchEvent(theEvent);
}
}
// only save the pref if the frontend didn't specify a format
if (inSaveFormat == eSaveFormatUnspecified && isHTML)
dirBranch->SetIntPref("save_converter_index", filterIndex);
nsCOMPtr<nsILocalFileMac> destFile;
rv = NS_NewLocalFileWithFSSpec(&destFileSpec, PR_TRUE, getter_AddRefs(destFile));
if (NS_FAILED(rv))
return rv;
if (isReplacing) {
PRBool exists;
rv = destFile->Exists(&exists);
if (NS_SUCCEEDED(rv) && exists)
rv = destFile->Remove(PR_TRUE);
if (NS_FAILED(rv))
return rv;
}
// if the user chose plain text, set the content type
if (isHTML && filterIndex == 2)
mContentType = "text/plain";
nsCOMPtr<nsISupports> sourceData;
if (isHTML && filterIndex != 1)
sourceData = do_QueryInterface(mDocument); // HTML complete
else
sourceData = do_QueryInterface(mURL); // HTML or text only
return InitiateDownload(sourceData, destFile, inOriginalURI);
}
// inOriginalURI is always a URI. inSourceData can be an nsIURI or an nsIDOMDocument, depending
// on what we're saving. It's that way for nsIWebBrowserPersist.
nsresult CHeaderSniffer::InitiateDownload(nsISupports* inSourceData, nsILocalFile* inDestFile, nsIURI* inOriginalURI)
{
nsresult rv = NS_OK;
nsCOMPtr<nsIWebBrowserPersist> webPersist = do_CreateInstance(persistContractID, &rv);
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIURI> sourceURI = do_QueryInterface(inSourceData);
PRInt64 timeNow = PR_Now();
nsAutoString fileDisplayName;
inDestFile->GetLeafName(fileDisplayName);
nsCOMPtr<nsIDownload> downloader = do_CreateInstance(NS_TRANSFER_CONTRACTID);
// dlListener attaches to its progress dialog here, which gains ownership
rv = downloader->Init(inOriginalURI, inDestFile, fileDisplayName.get(), nsnull, timeNow, webPersist);
if (NS_FAILED(rv)) return rv;
PRInt32 flags = nsIWebBrowserPersist::PERSIST_FLAGS_NO_CONVERSION |
nsIWebBrowserPersist::PERSIST_FLAGS_REPLACE_EXISTING_FILES;
if (mBypassCache)
flags |= nsIWebBrowserPersist::PERSIST_FLAGS_BYPASS_CACHE;
else
flags |= nsIWebBrowserPersist::PERSIST_FLAGS_FROM_CACHE;
webPersist->SetPersistFlags(flags);
if (sourceURI)
{
rv = webPersist->SaveURI(sourceURI, nsnull, nsnull, mPostData, nsnull, inDestFile);
}
else
{
nsCOMPtr<nsIDOMDocument> domDoc = do_QueryInterface(inSourceData, &rv);
if (!domDoc) return rv; // should never happen
PRInt32 encodingFlags = 0;
nsCOMPtr<nsILocalFile> filesFolder;
if (!mContentType.Equals("text/plain")) {
// Create a local directory in the same dir as our file. It
// will hold our associated files.
filesFolder = do_CreateInstance("@mozilla.org/file/local;1");
nsAutoString unicodePath;
inDestFile->GetPath(unicodePath);
filesFolder->InitWithPath(unicodePath);
nsAutoString leafName;
filesFolder->GetLeafName(leafName);
nsAutoString nameMinusExt(leafName);
PRInt32 index = nameMinusExt.RFind(".");
if (index >= 0)
nameMinusExt.Left(nameMinusExt, index);
nameMinusExt.AppendLiteral(" Files"); // XXXdwh needs to be localizable!
filesFolder->SetLeafName(nameMinusExt);
PRBool exists = PR_FALSE;
filesFolder->Exists(&exists);
if (!exists) {
rv = filesFolder->Create(nsILocalFile::DIRECTORY_TYPE, 0755);
if (NS_FAILED(rv))
return rv;
}
}
else
{
encodingFlags |= nsIWebBrowserPersist::ENCODE_FLAGS_FORMATTED |
nsIWebBrowserPersist::ENCODE_FLAGS_ABSOLUTE_LINKS |
nsIWebBrowserPersist::ENCODE_FLAGS_NOFRAMES_CONTENT;
}
rv = webPersist->SaveDocument(domDoc, inDestFile, filesFolder, mContentType.get(), encodingFlags, 80);
}
return rv;
}

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

@ -1,89 +0,0 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* 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 Chimera code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* David Hyatt <hyatt@netscape.com>
* Simon Fraser <sfraser@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#pragma once
#include "nsString.h"
#include "nsIWebProgressListener.h"
#include "nsIWebBrowserPersist.h"
#include "nsIURI.h"
#include "nsILocalFile.h"
#include "nsIInputStream.h"
#include "nsIDOMDocument.h"
typedef enum
{
eSaveFormatUnspecified = 0,
eSaveFormatPlainText, // items should match the MENU in resources
eSaveFormatHTML,
eSaveFormatHTMLComplete
} ESaveFormat;
// Implementation of a header sniffer class that is used when saving Web pages and images.
class CHeaderSniffer : public nsIWebProgressListener
{
public:
CHeaderSniffer(nsIWebBrowserPersist* aPersist, nsIFile* aFile, nsIURI* aURL,
nsIDOMDocument* aDocument, nsIInputStream* aPostData,
const nsAString& aSuggestedFilename, PRBool aBypassCache,
ESaveFormat aSaveFormat = eSaveFormatUnspecified);
virtual ~CHeaderSniffer();
NS_DECL_ISUPPORTS
NS_DECL_NSIWEBPROGRESSLISTENER
protected:
nsresult PerformSave(nsIURI* inOriginalURI, const ESaveFormat inSaveFormat);
nsresult InitiateDownload(nsISupports* inSourceData, nsILocalFile* inDestFile, nsIURI* inOriginalURI);
private:
nsIWebBrowserPersist* mPersist; // Weak. It owns us as a listener.
nsCOMPtr<nsIFile> mTmpFile;
nsCOMPtr<nsIURI> mURL;
nsCOMPtr<nsIDOMDocument> mDocument;
nsCOMPtr<nsIInputStream> mPostData;
nsString mDefaultFilename;
PRBool mBypassCache;
ESaveFormat mSaveFormat;
nsCString mContentType;
nsCString mContentDisposition;
};

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

@ -1,248 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* 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 the Initial Developer are Copyright (C) 1999
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Conrad Carlen <ccarlen@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "CIconServicesIcon.h"
#include "UResourceMgr.h"
#include "UMemoryMgr.h"
#include <Processes.h>
//*****************************************************************************
// CIconServicesIcon
//*****************************************************************************
OSType CIconServicesIcon::mgAppCreator;
FSSpec CIconServicesIcon::mgIconFileSpec;
CIconServicesIcon::CIconServicesIcon(const SPaneInfo& inPaneInfo,
MessageT inValueMessage,
OSType inIconType,
SInt16 inIconResID) :
LControl(inPaneInfo, inValueMessage),
mIconType(inIconType), mIconResID(inIconResID),
mAlignmentType(kAlignAbsoluteCenter), mIconRef(nil),
mbIsPressed(false)
{
Init();
}
CIconServicesIcon::CIconServicesIcon(LStream* inStream) :
LControl(inStream),
mAlignmentType(kAlignAbsoluteCenter), mIconRef(nil),
mbIsPressed(false)
{
*inStream >> mIconType;
*inStream >> mIconResID;
Init();
}
CIconServicesIcon::~CIconServicesIcon()
{
ReleaseIconRef();
}
void CIconServicesIcon::DrawSelf()
{
if (!mIconRef)
return;
Rect iconRect;
CalcLocalFrameRect(iconRect);
AdjustIconRect(iconRect);
IconTransformType transform;
if (mbIsPressed)
transform = kTransformSelected;
else if (mEnabled != triState_On)
transform = kTransformDisabled;
else
transform = kTransformNone;
// Because the icon may be translucent, clear out the
// region under it. The icon will draw differently
// depending on the background. This makes it consistent.
StRegion cleanRgn;
if (::IconRefToRgn(cleanRgn,
&iconRect,
mAlignmentType,
kIconServicesNormalUsageFlag,
mIconRef) == noErr)
::EraseRgn(cleanRgn);
::PlotIconRef(&iconRect,
mAlignmentType,
transform,
kIconServicesNormalUsageFlag,
mIconRef);
}
void CIconServicesIcon::EnableSelf()
{
Refresh();
}
void CIconServicesIcon::DisableSelf()
{
Refresh();
}
SInt16 CIconServicesIcon::FindHotSpot(Point inPoint) const
{
Boolean inHotSpot = PointInHotSpot(inPoint, 0);
return inHotSpot ? 1 : 0;
}
Boolean CIconServicesIcon::PointInHotSpot(Point inPoint,
SInt16 inHotSpot) const
{
if (!mIconRef)
return false;
Rect iconRect;
CalcLocalFrameRect(iconRect);
AdjustIconRect(iconRect);
return ::PtInIconRef(&inPoint, &iconRect, mAlignmentType, kIconServicesNormalUsageFlag, mIconRef);
}
void CIconServicesIcon::HotSpotAction(SInt16 /* inHotSpot */,
Boolean inCurrInside,
Boolean inPrevInside)
{
if (inCurrInside != inPrevInside)
{
mbIsPressed = inCurrInside;
Draw(nil);
}
}
void CIconServicesIcon::HotSpotResult(SInt16 /* inHotSpot */)
{
BroadcastValueMessage();
}
void CIconServicesIcon::Init()
{
static bool gInitialized;
if (!gInitialized)
{
OSErr err;
// Since this a part of mozilla, which requires System 8.6,
// we can be sure of having this. Just in case...
long response;
err = ::Gestalt(gestaltIconUtilitiesAttr, &response);
ThrowIfError_(err);
if (!(response & gestaltIconUtilitiesHasIconServices))
Throw_(-12345);
ProcessSerialNumber psn;
err = ::GetCurrentProcess(&psn);
ThrowIfError_(err);
ProcessInfoRec info;
info.processInfoLength = sizeof(info);
info.processName = nil;
info.processAppSpec = nil;
err = ::GetProcessInformation(&psn, &info);
ThrowIfError_(err);
mgAppCreator = info.processSignature;
// RegisterIconRefFromResource() needs to be given an FSSpec of
// the file containing the 'icns' resource of the icon being
// registered. The following will track down the file no matter
// how our application is packaged.
StResLoad resLoadState(false);
StResource resHandle('icns', mIconResID); // throws if N/A
SInt16 resRefNum = ::HomeResFile(resHandle);
if (resRefNum != -1)
{
FCBPBRec pb;
pb.ioNamePtr = mgIconFileSpec.name;
pb.ioVRefNum = 0;
pb.ioRefNum = resRefNum;
pb.ioFCBIndx = 0;
err = PBGetFCBInfoSync(&pb);
if (err == noErr)
{
mgIconFileSpec.vRefNum = pb.ioFCBVRefNum;
mgIconFileSpec.parID = pb.ioFCBParID;
}
}
gInitialized = true;
}
GetIconRef();
}
void CIconServicesIcon::AdjustIconRect(Rect& ioRect) const
{
SDimension16 frameSize;
GetFrameSize(frameSize);
SInt16 iconSize = (frameSize.width <= 16 && frameSize.height <= 16) ? 16 : 32;
ioRect.top += ((ioRect.bottom - ioRect.top) - iconSize) / 2;
ioRect.left += ((ioRect.right - ioRect.left) - iconSize) / 2;
ioRect.right = ioRect.left + iconSize;
ioRect.bottom = ioRect.top + iconSize;
}
void CIconServicesIcon::GetIconRef()
{
// We would like to first see if the icon is already registered
// But, for some reason, the following call always returns noErr and the wrong icon.
// err = ::GetIconRef(mgIconFileSpec.vRefNum, mgAppCreator, mIconType, &iconRef);
// if (err != noErr)
::RegisterIconRefFromResource(mgAppCreator, mIconType, &mgIconFileSpec, mIconResID, &mIconRef);
}
void CIconServicesIcon::ReleaseIconRef()
{
if (mIconRef)
{
::ReleaseIconRef(mIconRef);
mIconRef = nil;
}
}

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

@ -1,93 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* 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 the Initial Developer are Copyright (C) 1999
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Conrad Carlen <ccarlen@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef __CIconServicesIcon_h__
#define __CIconServicesIcon_h__
#include <LControl.h>
class CIconServicesIcon : public LControl
{
public:
enum { class_ID = FOUR_CHAR_CODE('CISC') };
CIconServicesIcon(const SPaneInfo& inPaneInfo,
MessageT inValueMessage,
OSType inIconType,
SInt16 inIconResID);
CIconServicesIcon(LStream* inStream);
virtual ~CIconServicesIcon();
// LPane
virtual void DrawSelf();
virtual void EnableSelf();
virtual void DisableSelf();
// LControl
SInt16 FindHotSpot(Point inPoint) const;
Boolean PointInHotSpot(Point inPoint,
SInt16 inHotSpot) const;
void HotSpotAction(SInt16 inHotSpot,
Boolean inCurrInside,
Boolean inPrevInside);
void HotSpotResult(SInt16 inHotSpot);
// CIconServicesIcon
protected:
void Init();
void AdjustIconRect(Rect& ioRect) const;
void GetIconRef();
void ReleaseIconRef();
protected:
OSType mIconType;
SInt16 mIconResID;
IconAlignmentType mAlignmentType;
IconRef mIconRef;
bool mbIsPressed;
static OSType mgAppCreator;
static FSSpec mgIconFileSpec;
};
#endif // __CIconServicesIcon_h__

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

@ -1,192 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* 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 mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Conrad Carlen <ccarlen@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
// Local
#include "CPrintAttachment.h"
#include "CBrowserShell.h"
// Gecko
#include "nsIPrintingPromptService.h"
#include "nsIDOMWindow.h"
#include "nsServiceManagerUtils.h"
#include "nsIWebBrowserPrint.h"
#include "nsIInterfaceRequestorUtils.h"
#include "nsIWebProgressListener.h"
#include "nsIWebBrowserChrome.h"
#include "nsIEmbeddingSiteWindow.h"
//*****************************************************************************
//*** CPrintAttachment
//*****************************************************************************
CPrintAttachment::CPrintAttachment(PaneIDT inBrowserPaneID,
MessageT inMessage,
Boolean inExecuteHost) :
LAttachment(inMessage,inExecuteHost),
mBrowserShell(nil), mBrowserShellPaneID(inBrowserPaneID)
{
}
CPrintAttachment::CPrintAttachment(LStream* inStream) :
LAttachment(inStream),
mBrowserShell(nil), mBrowserShellPaneID(PaneIDT_Unspecified)
{
*inStream >> mBrowserShellPaneID;
}
CPrintAttachment::~CPrintAttachment()
{
}
//*****************************************************************************
//*** CPrintAttachment::LAttachment
//*****************************************************************************
void CPrintAttachment::SetOwnerHost(LAttachable* inOwnerHost)
{
LAttachment::SetOwnerHost(inOwnerHost);
if (mBrowserShell == nil) {
if (mBrowserShellPaneID != PaneIDT_Unspecified) {
LView* container = GetTopmostView(dynamic_cast<LPane*>(mOwnerHost));
if (container != nil) {
LPane* targetPane = container->FindPaneByID(mBrowserShellPaneID);
if (targetPane != nil)
mBrowserShell = dynamic_cast<CBrowserShell*>(targetPane);
}
}
else
mBrowserShell = dynamic_cast<CBrowserShell*>(mOwnerHost);
Assert_(mBrowserShell != nil); // Programmer error
}
}
void CPrintAttachment::ExecuteSelf(MessageT inMessage, void *ioParam)
{
mExecuteHost = true;
if (inMessage == msg_CommandStatus) {
SCommandStatus *status = (SCommandStatus *)ioParam;
if (status->command == cmd_Print) {
*status->enabled = true;
*status->usesMark = false;
mExecuteHost = false; // we handled it
}
else if (status->command == cmd_PageSetup) {
*status->enabled = true;
*status->usesMark = false;
mExecuteHost = false; // we handled it
}
}
else if (inMessage == cmd_Print) {
DoPrint();
mExecuteHost = false; // we handled it
}
else if (inMessage == cmd_PageSetup) {
DoPageSetup();
mExecuteHost = false; // we handled it
}
}
//*****************************************************************************
//*** CPrintAttachment::CPrintAttachment
//*****************************************************************************
void CPrintAttachment::DoPrint()
{
nsCOMPtr<nsIWebBrowser> wb;
mBrowserShell->GetWebBrowser(getter_AddRefs(wb));
ThrowIfNil_(wb);
nsCOMPtr<nsIWebBrowserPrint> wbPrint(do_GetInterface(wb));
ThrowIfNil_(wbPrint);
nsCOMPtr<nsIPrintSettings> settings;
mBrowserShell->GetPrintSettings(getter_AddRefs(settings));
ThrowIfNil_(settings);
nsresult rv = wbPrint->Print(settings, nsnull);
if (rv != NS_ERROR_ABORT)
ThrowIfError_(rv);
}
void CPrintAttachment::DoPageSetup()
{
nsCOMPtr<nsIWebBrowser> wb;
mBrowserShell->GetWebBrowser(getter_AddRefs(wb));
ThrowIfNil_(wb);
nsCOMPtr<nsIDOMWindow> domWindow;
wb->GetContentDOMWindow(getter_AddRefs(domWindow));
ThrowIfNil_(domWindow);
nsCOMPtr<nsIPrintSettings> settings;
mBrowserShell->GetPrintSettings(getter_AddRefs(settings));
ThrowIfNil_(settings);
nsCOMPtr<nsIPrintingPromptService> printingPromptService =
do_GetService("@mozilla.org/embedcomp/printingprompt-service;1");
ThrowIfNil_(printingPromptService);
nsresult rv = printingPromptService->ShowPageSetup(domWindow, settings, nsnull);
if (rv != NS_ERROR_ABORT)
ThrowIfError_(rv);
}
LView* CPrintAttachment::GetTopmostView(LPane* inStartPane)
{
// Begin with the start Pane as a
// View. Will be nil if start Pane
// is nil or is not an LView.
LView* theView = dynamic_cast<LView*>(inStartPane);
if (inStartPane != nil) {
// Look at SuperView of start Pane
LView* superView = inStartPane->GetSuperView();
while (superView != nil) { // Move up view hierarchy until
theView = superView; // reaching a nil SuperView
superView = theView->GetSuperView();
}
}
return theView;
}

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

@ -1,76 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* 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 mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Conrad Carlen <ccarlen@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef __CPrintAttachment__
#define __CPrintAttachment__
#include <LAttachment.h>
class CBrowserShell;
class CPrintAttachment : public LAttachment
{
public:
enum { class_ID = FOUR_CHAR_CODE('BRPR') };
CPrintAttachment(PaneIDT inBrowserPaneID,
MessageT inMessage = msg_AnyMessage,
Boolean inExecuteHost = true);
CPrintAttachment(LStream* inStream);
virtual ~CPrintAttachment();
// LAttachment
virtual void SetOwnerHost(LAttachable *inOwnerHost);
virtual void ExecuteSelf(MessageT inMessage,
void* ioParam);
// CPrintAttachment
virtual void DoPrint();
virtual void DoPageSetup();
protected:
static LView* GetTopmostView(LPane* inStartPane);
protected:
CBrowserShell *mBrowserShell;
PaneIDT mBrowserShellPaneID;
};
#endif

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

@ -1,432 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* 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 the Initial Developer are Copyright (C) 1999
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Conrad Carlen <ccarlen@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
// PPBrowser
#include "CProfileManager.h"
#include "ApplIDs.h"
#include "UMacUnicode.h"
// PowerPlant
#include <LEditText.h>
#include <LTextTableView.h>
#include <LPushButton.h>
#include <LTableMonoGeometry.h>
#include <LTableArrayStorage.h>
#include <LTableSingleSelector.h>
#include <LCheckBox.h>
// Carbon
#include <CFPreferences.h>
// Mozilla
#include "nsIProfile.h"
#include "nsIDirectoryService.h"
#include "nsDirectoryServiceDefs.h"
#include "nsAppDirectoryServiceDefs.h"
#include "nsIObserverService.h"
#include "nsXPIDLString.h"
#include "nsCRT.h"
// ANSI
#include <climits>
// Constants
const MessageT msg_OnNewProfile = 2000;
const MessageT msg_OnDeleteProfile = 2001;
const MessageT msg_OnRenameProfile = 2002;
#define kPrefShowProfilesAtStartup "start-show-dialog"
//*****************************************************************************
//*** CProfileManager
//*****************************************************************************
CProfileManager::CProfileManager() :
LAttachment(msg_AnyMessage,true)
{
}
CProfileManager::~CProfileManager()
{
}
void CProfileManager::StartUp()
{
nsresult rv;
nsCOMPtr<nsIProfile> profileService =
do_GetService(NS_PROFILE_CONTRACTID, &rv);
ThrowIfNil_(profileService);
PRInt32 profileCount;
rv = profileService->GetProfileCount(&profileCount);
ThrowIfError_(rv);
if (profileCount == 0)
{
// Make a new default profile
NS_NAMED_LITERAL_STRING(newProfileName, "default");
rv = profileService->CreateNewProfile(newProfileName.get(), nsnull, nsnull, PR_FALSE);
ThrowIfError_(rv);
rv = profileService->SetCurrentProfile(newProfileName.get());
ThrowIfError_(rv);
}
else
{
// Use our flag here to check for whether to show profile mgr UI. If the flag
// says don't show it, just start with the last used profile.
PRBool showIt;
rv = GetShowDialogOnStart(&showIt);
if (NS_FAILED(rv) || (profileCount > 1 && showIt))
{
DoManageProfilesDialog();
}
else
{
// GetCurrentProfile returns the profile which was last used but is not nescesarily
// active. Call SetCurrentProfile to make it installed and active.
nsXPIDLString currProfileName;
rv = profileService->GetCurrentProfile(getter_Copies(currProfileName));
ThrowIfError_(rv);
rv = profileService->SetCurrentProfile(currProfileName);
ThrowIfError_(rv);
}
}
}
Boolean CProfileManager::DoNewProfileDialog(char *outName, UInt32 bufSize)
{
Boolean confirmed;
StDialogHandler theHandler(dlog_NewProfile, LCommander::GetTopCommander());
LWindow *theDialog = theHandler.GetDialog();
ThrowIfNil_(theDialog);
LEditText *responseText = dynamic_cast<LEditText*>(theDialog->FindPaneByID('Name'));
ThrowIfNil_(responseText);
theDialog->SetLatentSub(responseText);
theDialog->Show();
theDialog->Select();
while (true) // This is our modal dialog event loop
{
MessageT hitMessage = theHandler.DoDialog();
if (hitMessage == msg_OK)
{
Str255 pStr;
UInt32 outLen;
responseText->GetDescriptor(pStr);
outLen = pStr[0] >= bufSize ? bufSize - 1 : pStr[0];
memcpy(outName, &pStr[1], outLen);
outName[outLen] = '\0';
confirmed = PR_TRUE;
break;
}
else if (hitMessage == msg_Cancel)
{
confirmed = PR_FALSE;
break;
}
}
return confirmed;
}
void CProfileManager::DoManageProfilesDialog()
{
nsresult rv;
StDialogHandler theHandler(dlog_ManageProfiles, LCommander::GetTopCommander());
LWindow *theDialog = theHandler.GetDialog();
nsCOMPtr<nsIProfile> profileService =
do_GetService(NS_PROFILE_CONTRACTID, &rv);
ThrowIfNil_(profileService);
// Set up the dialog by filling the list of current profiles
LTextTableView *table = (LTextTableView*) theDialog->FindPaneByID('List');
ThrowIfNil_(table);
LPushButton *deleteButton = (LPushButton *) theDialog->FindPaneByID('Dele');
ThrowIfNil_(deleteButton);
//Str255 pascalStr;
nsAutoString unicodeStr;
nsCAutoString cStr;
char dataBuf[256];
UInt32 dataSize;
// PowerPlant stuff to set up the list view
STableCell selectedCell(1, 1);
SDimension16 tableSize;
TableIndexT rows, cols;
table->GetFrameSize(tableSize);
table->SetTableGeometry(new LTableMonoGeometry(table, tableSize.width, 16));
table->SetTableStorage(new LTableArrayStorage(table, 0UL));
table->SetTableSelector(new LTableSingleSelector(table));
table->InsertCols(1, 0);
// Get the name of the current profile so we can select it
nsXPIDLString currProfileName;
profileService->GetCurrentProfile(getter_Copies(currProfileName));
// Get the list of profile names and add them to the list
PRUint32 listLen;
PRUnichar **profileList;
rv = profileService->GetProfileList(&listLen, &profileList);
ThrowIfError_(rv);
for (PRUint32 index = 0; index < listLen; index++)
{
CPlatformUCSConversion::GetInstance()->UCSToPlatform(nsDependentString(profileList[index]), cStr);
table->InsertRows(1, LONG_MAX, cStr.get(), cStr.Length(), true);
if (nsCRT::strcmp(profileList[index], currProfileName.get()) == 0)
selectedCell.row = index + 1;
}
PRInt32 numProfiles;
rv = profileService->GetProfileCount(&numProfiles);
ThrowIfError_(rv);
(numProfiles > 1) ? deleteButton->Enable() : deleteButton->Disable();
table->SelectCell(selectedCell);
// Handle the "Ask At StartUp" checkbox
LCheckBox *showAtStartCheck = (LCheckBox*) theDialog->FindPaneByID('Show');
ThrowIfNil_(showAtStartCheck);
PRBool showIt;
rv = GetShowDialogOnStart(&showIt);
if (NS_FAILED(rv))
showIt = PR_TRUE;
showAtStartCheck->SetValue(showIt);
theDialog->Show();
theDialog->Select();
while (true) // This is our modal dialog event loop
{
MessageT hitMessage = theHandler.DoDialog();
if (hitMessage == msg_OK)
{
theDialog->Hide();
SetShowDialogOnStart(showAtStartCheck->GetValue());
selectedCell = table->GetFirstSelectedCell();
if (selectedCell.row > 0)
{
dataSize = sizeof(dataBuf) - 1;
table->GetCellData(selectedCell, dataBuf, dataSize);
dataBuf[dataSize] = '\0';
CPlatformUCSConversion::GetInstance()->PlatformToUCS(nsDependentCString(dataBuf), unicodeStr);
rv = profileService->SetCurrentProfile(unicodeStr.get());
}
break;
}
else if (hitMessage == msg_Cancel)
{
break;
}
else if (hitMessage == msg_OnNewProfile)
{
if (DoNewProfileDialog(dataBuf, sizeof(dataBuf)))
{
CPlatformUCSConversion::GetInstance()->PlatformToUCS(nsDependentCString(dataBuf), unicodeStr);
rv = profileService->CreateNewProfile(unicodeStr.get(), nsnull, nsnull, PR_FALSE);
if (NS_FAILED(rv))
break;
table->InsertRows(1, LONG_MAX, dataBuf, strlen(dataBuf), true);
table->GetTableSize(rows, cols);
table->SelectCell(STableCell(rows, cols));
rv = profileService->GetProfileCount(&numProfiles);
(NS_SUCCEEDED(rv) && numProfiles > 1) ? deleteButton->Enable() : deleteButton->Disable();
}
}
else if (hitMessage == msg_OnDeleteProfile)
{
selectedCell = table->GetFirstSelectedCell();
if (selectedCell.row > 0)
{
dataSize = sizeof(dataBuf) - 1;
table->GetCellData(selectedCell, dataBuf, dataSize);
dataBuf[dataSize] = '\0';
CPlatformUCSConversion::GetInstance()->PlatformToUCS(nsDependentCString(dataBuf), unicodeStr);
rv = profileService->DeleteProfile(unicodeStr.get(), PR_TRUE);
if (NS_FAILED(rv))
break;
table->RemoveRows(1, selectedCell.row, true);
table->GetTableSize(rows, cols);
if (selectedCell.row >= rows)
selectedCell.row = rows - 1;
table->SelectCell(selectedCell);
rv = profileService->GetProfileCount(&numProfiles);
(NS_SUCCEEDED(rv) && numProfiles > 1) ? deleteButton->Enable() : deleteButton->Disable();
}
}
else if (hitMessage == msg_OnRenameProfile)
{
nsAutoString oldName;
selectedCell = table->GetFirstSelectedCell();
dataSize = sizeof(dataBuf) - 1;
table->GetCellData(selectedCell, dataBuf, dataSize);
dataBuf[dataSize] = '\0';
CPlatformUCSConversion::GetInstance()->PlatformToUCS(nsDependentCString(dataBuf), oldName);
if (DoNewProfileDialog(dataBuf, sizeof(dataBuf)))
{
CPlatformUCSConversion::GetInstance()->PlatformToUCS(nsDependentCString(dataBuf), unicodeStr);
profileService->RenameProfile(oldName.get(), unicodeStr.get());
table->SetCellData(selectedCell, dataBuf, strlen(dataBuf));
}
}
}
}
void CProfileManager::DoLogout()
{
enum { iPersist = 1, iCancel, iCleanse };
nsresult rv;
nsCOMPtr<nsIProfile> profileService =
do_GetService(NS_PROFILE_CONTRACTID, &rv);
ThrowIfNil_(profileService);
nsXPIDLString currentProfile;
Str255 pStr;
profileService->GetCurrentProfile(getter_Copies(currentProfile));
CPlatformUCSConversion::GetInstance()->UCSToPlatform(nsDependentString(currentProfile.get()), pStr);
::ParamText(pStr, "\p", "\p", "\p");
DialogItemIndex item = UModalAlerts::StopAlert(alrt_ConfirmLogout);
if (item == iCancel)
return;
if (item == iPersist)
rv = profileService->ShutDownCurrentProfile(nsIProfile::SHUTDOWN_PERSIST);
else
rv = profileService->ShutDownCurrentProfile(nsIProfile::SHUTDOWN_CLEANSE);
if (NS_SUCCEEDED(rv)) {
// Just put this up modally until they pick a new profile
DoManageProfilesDialog();
}
}
/*
The following three methods have nothing to do with profile management per se.
They use the registry to store a flag which allows the user to choose whether
to show the profile manager dialog at startup. After all, since we can switch
it at any time - why must we deal with the dialog every time we start the app?
*/
nsresult CProfileManager::GetShowDialogOnStart(PRBool* showIt)
{
*showIt = PR_TRUE;
CFStringRef showDialogKey = CFSTR(kPrefShowProfilesAtStartup);
Boolean keyExistsAndIsValid, value;
value = CFPreferencesGetAppBooleanValue(showDialogKey,
kCFPreferencesCurrentApplication,
&keyExistsAndIsValid);
if (!keyExistsAndIsValid)
return NS_ERROR_FAILURE;
*showIt = value;
return NS_OK;
}
nsresult CProfileManager::SetShowDialogOnStart(PRBool showIt)
{
CFStringRef showDialogKey = CFSTR(kPrefShowProfilesAtStartup);
CFPreferencesSetAppValue(showDialogKey,
showIt ? kCFBooleanTrue : kCFBooleanFalse,
kCFPreferencesCurrentApplication);
// Write out the preference data - this is our 1 and only use of it.
CFPreferencesAppSynchronize(kCFPreferencesCurrentApplication);
return NS_OK;
}
//*****************************************************************************
//*** CProfileManager::LAttachment
//*****************************************************************************
void CProfileManager::ExecuteSelf(MessageT inMessage, void *ioParam)
{
mExecuteHost = true;
// update status
if (inMessage == msg_CommandStatus) {
SCommandStatus *status = (SCommandStatus *)ioParam;
if (status->command == cmd_ManageProfiles) {
*status->enabled = true;
*status->usesMark = false;
mExecuteHost = false; // we handled it
}
else if (status->command == cmd_Logout) {
*status->enabled = true;
*status->usesMark = false;
mExecuteHost = false; // we handled it
}
}
else if (inMessage == cmd_ManageProfiles) {
DoManageProfilesDialog();
mExecuteHost = false; // we handled it
}
else if (inMessage == cmd_Logout) {
DoLogout();
mExecuteHost = false; // we handled it
}
}

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

@ -1,71 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* 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 the Initial Developer are Copyright (C) 1999
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Conrad Carlen <ccarlen@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#pragma once
// Mozilla
#include "nsError.h"
// PowerPlant
#include <LAttachment.h>
// ForwardDeclarations
class nsIRegistry;
class CProfileManager : public LAttachment
{
public:
CProfileManager();
virtual ~CProfileManager();
virtual void StartUp();
virtual void DoManageProfilesDialog();
virtual Boolean DoNewProfileDialog(char *outName, UInt32 bufSize);
virtual void DoLogout();
protected:
// LAttachment
void ExecuteSelf(MessageT inMessage, void *ioParam);
nsresult GetShowDialogOnStart(PRBool* showIt);
nsresult SetShowDialogOnStart(PRBool showIt);
nsresult OpenAppRegistry(nsIRegistry **aRegistry);
};

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

@ -1,85 +0,0 @@
/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* 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 the Initial Developer are Copyright (C) 1999
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Frank Yung-Fong Tang <ftang@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef CTextInputEventHandler_h__
#define CTextInputEventHandler_h__
#include <CarbonEvents.h>
#include <TextServices.h>
#include "nsIMacTextInputEventSink.h"
#include "CBrowserShell.h"
class CTextInputEventHandler
{
public:
CTextInputEventHandler() {};
virtual ~CTextInputEventHandler() {};
virtual OSStatus HandleAll( EventHandlerCallRef inHandlerCallRef,
EventRef inEvent);
protected:
virtual OSStatus HandleUnicodeForKeyEvent( CBrowserShell* aBrowserShell,
EventHandlerCallRef inHandlerCallRef,
EventRef inEvent);
virtual OSStatus HandleUpdateActiveInputArea( CBrowserShell* sink,
EventHandlerCallRef inHandlerCallRef,
EventRef inEvent);
virtual OSStatus HandleOffsetToPos( CBrowserShell* aBrowserShell,
EventHandlerCallRef inHandlerCallRef,
EventRef inEvent);
virtual OSStatus HandlePosToOffset( CBrowserShell* aBrowserShell,
EventHandlerCallRef inHandlerCallRef,
EventRef inEvent);
virtual OSStatus HandleGetSelectedText( CBrowserShell* aBrowserShell,
EventHandlerCallRef inHandlerCallRef,
EventRef inEvent);
virtual CBrowserShell* GetGeckoTarget();
private:
OSStatus GetText(EventRef inEvent, nsString& outString);
OSStatus GetScriptLang(EventRef inEvent, ScriptLanguageRecord& outSlr);
};
void InitializeTextInputEventHandling();
#endif /* CTextInputEventHandler_h__ */

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

@ -1,357 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* 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 the Initial Developer are Copyright (C) 1999
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Frank Yung-Fong Tang <ftang@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/*
* The embedding application could choose to install either Carbon Event Handler
* or Apple Event to implement Asian Input Method and/or Unicode keyboard mapping.
*
* This file is a sample implementation of how ot use Carbon Text Input event handler
* that. Example of Apple event handler could be found at nsMacTSMMessagePump.{h,cpp}
*/
#include "CTextInputEventHandler.h"
#include "nsCRT.h"
#include "nsAutoBuffer.h"
#pragma mark -
#pragma mark -
//*************************************************************************************
// GetGeckoTarget
//*************************************************************************************
CBrowserShell* CTextInputEventHandler::GetGeckoTarget()
{
return dynamic_cast<CBrowserShell*> (LCommander::GetTarget());
}
#pragma mark -
//*************************************************************************************
// GetScriptLang
//*************************************************************************************
OSStatus CTextInputEventHandler::GetScriptLang(EventRef inEvent, ScriptLanguageRecord& outSlr )
{
OSStatus err = ::GetEventParameter(inEvent, kEventParamTextInputSendSLRec, typeIntlWritingCode, NULL,
sizeof(outSlr), NULL, &outSlr);
return err;
}
//*************************************************************************************
// GetText
//*************************************************************************************
OSStatus CTextInputEventHandler::GetText(EventRef inEvent, nsString& outString)
{
UInt32 neededSize;
outString.Truncate(0);
OSStatus err = ::GetEventParameter(inEvent, kEventParamTextInputSendText, typeUnicodeText, NULL, 0, &neededSize, NULL);
if (noErr != err)
return err;
if (neededSize > 0)
{
nsAutoBuffer<PRUnichar, 256> buf;
if (! buf.EnsureElemCapacity(neededSize/sizeof(PRUnichar)))
return eventParameterNotFoundErr;
err = ::GetEventParameter(inEvent, kEventParamTextInputSendText, typeUnicodeText, NULL,
neededSize, &neededSize, buf.get());
if (noErr == err)
outString.Assign(buf.get(), neededSize/sizeof(PRUnichar));
}
return err;
}
#pragma mark -
//*************************************************************************************
// HandleUnicodeForKeyEvent
//*************************************************************************************
OSStatus CTextInputEventHandler::HandleUnicodeForKeyEvent(
CBrowserShell* aBrowserShell,
EventHandlerCallRef inHandlerCallRef,
EventRef inEvent)
{
NS_ENSURE_TRUE(aBrowserShell, eventNotHandledErr);
EventRef keyboardEvent;
OSStatus err = ::GetEventParameter(inEvent, kEventParamTextInputSendKeyboardEvent, typeEventRef, NULL,
sizeof(keyboardEvent), NULL, &keyboardEvent);
if (noErr != err)
return eventParameterNotFoundErr;
// Check first to see if the key event is a cmd-key or control-key.
// If so, return eventNotHandledErr, and the keydown event will end
// up being handled by LEventDispatcher::EventKeyDown() which is the
// standard PowerPlant handling.
UInt32 keyModifiers;
err = ::GetEventParameter(keyboardEvent, kEventParamKeyModifiers, typeUInt32,
NULL, sizeof(UInt32), NULL, &keyModifiers);
if ((noErr == err) && (keyModifiers & (cmdKey | controlKey)))
return eventNotHandledErr;
EventRecord eventRecord;
if (! ::ConvertEventRefToEventRecord(keyboardEvent, &eventRecord))
return eventParameterNotFoundErr;
// printf("uk1- %d %d %d %d %d\n", eventRecord.what, eventRecord.message, eventRecord.when, eventRecord.where, eventRecord.modifiers);
ScriptLanguageRecord slr;
err = GetScriptLang(inEvent, slr);
if (noErr != err)
return eventParameterNotFoundErr;
nsAutoString text;
err = GetText(inEvent, text);
if (noErr != err)
return eventParameterNotFoundErr;
// printf("call HandleUnicodeForKeyEvent textlength = %d script=%d language=%d\n", text.Length(), slr.fScript, slr.fLanguage);
err = aBrowserShell->HandleUnicodeForKeyEvent(text, slr.fScript, slr.fLanguage, &eventRecord);
// printf("err = %d\n", err);
return err;
}
//*************************************************************************************
// HandleUpdateActiveInputArea
//*************************************************************************************
OSStatus CTextInputEventHandler::HandleUpdateActiveInputArea(
CBrowserShell* aBrowserShell,
EventHandlerCallRef inHandlerCallRef,
EventRef inEvent)
{
NS_ENSURE_TRUE(aBrowserShell, eventNotHandledErr);
PRUint32 fixLength;
OSStatus err = ::GetEventParameter(inEvent, kEventParamTextInputSendFixLen, typeLongInteger, NULL,
sizeof(fixLength), NULL, &fixLength);
if (noErr != err)
return eventParameterNotFoundErr;
ScriptLanguageRecord slr;
err = GetScriptLang(inEvent, slr);
if (noErr != err)
return eventParameterNotFoundErr;
nsAutoString text;
err = GetText(inEvent, text);
if (noErr != err)
return eventParameterNotFoundErr;
// kEventParamTextInputSendHiliteRng is optional parameter, don't return if we cannot get it.
TextRangeArray* hiliteRng = nsnull;
UInt32 rngSize=0;
err = ::GetEventParameter(inEvent, kEventParamTextInputSendHiliteRng, typeTextRangeArray, NULL,
0, NULL, &rngSize);
if (noErr == err)
{
TextRangeArray* pt = (TextRangeArray*)::malloc(rngSize);
NS_ASSERTION( (pt), "Cannot malloc for hiliteRng") ;
if (pt)
{
hiliteRng = pt;
err = ::GetEventParameter(inEvent, kEventParamTextInputSendHiliteRng, typeTextRangeArray, NULL,
rngSize, &rngSize, hiliteRng);
NS_ASSERTION( (noErr == err), "Cannot get hiliteRng") ;
}
}
// printf("call HandleUpdateActiveInputArea textlength = %d ",text.Length());
// printf("script=%d language=%d fixlen=%d\n", slr.fScript, slr.fLanguage, fixLength / 2);
err = aBrowserShell->HandleUpdateActiveInputArea(text, slr.fScript, slr.fLanguage,
fixLength / sizeof(PRUnichar), hiliteRng);
if (hiliteRng)
::free(hiliteRng);
return err;
}
//*************************************************************************************
// HandleUpdateActiveInputArea
//*************************************************************************************
OSStatus CTextInputEventHandler::HandleGetSelectedText(
CBrowserShell* aBrowserShell,
EventHandlerCallRef inHandlerCallRef,
EventRef inEvent)
{
NS_ENSURE_TRUE(aBrowserShell, eventNotHandledErr);
nsAutoString outString;
OSStatus err = aBrowserShell->HandleGetSelectedText(outString);
if (noErr != err)
return eventParameterNotFoundErr;
err = ::SetEventParameter(inEvent, kEventParamTextInputReplyText, typeUnicodeText,
outString.Length()*sizeof(PRUnichar), outString.get());
return err;
}
//*************************************************************************************
// HandleOffsetToPos
//*************************************************************************************
OSStatus CTextInputEventHandler::HandleOffsetToPos(
CBrowserShell* aBrowserShell,
EventHandlerCallRef inHandlerCallRef,
EventRef inEvent)
{
NS_ENSURE_TRUE(aBrowserShell, eventNotHandledErr);
PRUint32 offset;
OSStatus err = ::GetEventParameter(inEvent, kEventParamTextInputSendTextOffset, typeLongInteger, NULL,
sizeof(offset), NULL, &offset);
if (noErr != err)
return eventParameterNotFoundErr;
Point thePoint;
// printf("call HandleOffsetToPos offset = %d\n", offset);
err = aBrowserShell->HandleOffsetToPos(offset, &thePoint.h, &thePoint.v);
// printf("return %d, %d\n", thePoint.v, thePoint.h);
if (noErr != err)
return eventParameterNotFoundErr;
err = ::SetEventParameter(inEvent, kEventParamTextInputReplyPoint, typeQDPoint,
sizeof(thePoint), &thePoint);
return err;
}
//*************************************************************************************
// HandlePosToOffset
//*************************************************************************************
OSStatus CTextInputEventHandler::HandlePosToOffset(
CBrowserShell* aBrowserShell,
EventHandlerCallRef inHandlerCallRef,
EventRef inEvent)
{
NS_ENSURE_TRUE(aBrowserShell, eventNotHandledErr);
PRInt32 offset;
Point thePoint;
short regionClass;
OSStatus err = ::GetEventParameter(inEvent, kEventParamTextInputSendCurrentPoint, typeQDPoint, NULL,
sizeof(thePoint), NULL, &thePoint);
if (noErr != err)
return eventParameterNotFoundErr;
// printf("call HandlePosToOffset Point = %d, %d\n", thePoint.h, thePoint.v);
err = aBrowserShell->HandlePosToOffset(thePoint.h, thePoint.v, &offset, &regionClass);
// printf("return offset = %d, region = %d\n", offset, regionClass);
if (noErr != err)
return eventParameterNotFoundErr;
err = ::SetEventParameter(inEvent, kEventParamTextInputReplyRegionClass, typeShortInteger,
sizeof(regionClass), &regionClass);
if (noErr != err)
return eventParameterNotFoundErr;
err = ::SetEventParameter(inEvent, kEventParamTextInputReplyTextOffset, typeLongInteger,
sizeof(offset), &offset);
return err;
}
//*************************************************************************************
// HandleAll
//*************************************************************************************
OSStatus CTextInputEventHandler::HandleAll(EventHandlerCallRef inHandlerCallRef, EventRef inEvent)
{
CBrowserShell* aBrowserShell = GetGeckoTarget();
// if this is not an event for Gecko, just return eventNotHandledErr and let
// OS to fallback to class event handling
if (!aBrowserShell)
return eventNotHandledErr;
UInt32 eventClass = ::GetEventClass(inEvent);
if (eventClass != kEventClassTextInput)
return eventNotHandledErr;
UInt32 eventKind = ::GetEventKind(inEvent);
if ((kEventTextInputUpdateActiveInputArea != eventKind) &&
(kEventTextInputUnicodeForKeyEvent!= eventKind) &&
(kEventTextInputOffsetToPos != eventKind) &&
(kEventTextInputPosToOffset != eventKind) &&
(kEventTextInputGetSelectedText != eventKind))
return eventNotHandledErr;
switch(eventKind)
{
case kEventTextInputUpdateActiveInputArea:
return HandleUpdateActiveInputArea(aBrowserShell, inHandlerCallRef, inEvent);
case kEventTextInputUnicodeForKeyEvent:
return HandleUnicodeForKeyEvent(aBrowserShell, inHandlerCallRef, inEvent);
case kEventTextInputOffsetToPos:
return HandleOffsetToPos(aBrowserShell, inHandlerCallRef, inEvent);
case kEventTextInputPosToOffset:
return HandlePosToOffset(aBrowserShell, inHandlerCallRef, inEvent);
case kEventTextInputGetSelectedText:
return HandleGetSelectedText(aBrowserShell, inHandlerCallRef, inEvent);
}
return eventNotHandledErr;
}
#pragma mark -
//*************************************************************************************
// TextInputHandler
//*************************************************************************************
static pascal OSStatus TextInputHandler(EventHandlerCallRef inHandlerCallRef, EventRef inEvent, void *inUserData)
{
CTextInputEventHandler* realHandler = (CTextInputEventHandler*)inUserData;
return realHandler->HandleAll(inHandlerCallRef, inEvent);
}
//*************************************************************************************
// InitializeTextInputEventHandling
//*************************************************************************************
void InitializeTextInputEventHandling()
{
static CTextInputEventHandler Singleton;
EventTypeSpec eventTypes[5] = {
{kEventClassTextInput, kEventTextInputUpdateActiveInputArea },
{kEventClassTextInput, kEventTextInputUnicodeForKeyEvent },
{kEventClassTextInput, kEventTextInputOffsetToPos },
{kEventClassTextInput, kEventTextInputPosToOffset },
{kEventClassTextInput, kEventTextInputGetSelectedText }
};
EventHandlerUPP textInputUPP = NewEventHandlerUPP(TextInputHandler);
OSStatus err = InstallApplicationEventHandler( textInputUPP, 5, eventTypes, &Singleton, NULL);
NS_ASSERTION(err==noErr, "Cannot install carbon event");
}

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

@ -1,231 +0,0 @@
/* -*- Mode: C++; tab-width: 3; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* 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 the Initial Developer are Copyright (C) 1999
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Conrad Carlen <ccarlen@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "CThrobber.h"
#include <LString.h>
#include <LStream.h>
#include <UDrawingState.h>
#include <UResourceMgr.h>
#include <QuickTimeComponents.h>
//*****************************************************************************
//*** CThrobber: constructors/destructor
//*****************************************************************************
CThrobber::CThrobber() :
mMovieResID(-1), mMovieHandle(nil),
mMovie(nil), mMovieController(nil)
{
}
CThrobber::CThrobber(LStream* inStream) :
LControl(inStream),
mMovieResID(-1), mMovieHandle(nil),
mMovie(nil), mMovieController(nil)
{
*inStream >> mMovieResID;
}
CThrobber::~CThrobber()
{
if (mMovieController)
::DisposeMovieController(mMovieController);
if (mMovieHandle)
::DisposeHandle(mMovieHandle);
}
void CThrobber::FinishCreateSelf()
{
CreateMovie();
}
void CThrobber::ShowSelf()
{
LControl::ShowSelf();
if (!mMovieController)
return;
::MCSetClip(mMovieController, NULL, NULL);
}
void CThrobber::HideSelf()
{
LControl::HideSelf();
if (!mMovieController)
return;
StRegion emptyRgn;
::MCSetClip(mMovieController, NULL, emptyRgn);
}
void CThrobber::DrawSelf()
{
if (mMovieController)
::MCDraw(mMovieController, GetMacWindow());
}
void CThrobber::ResizeFrameBy(SInt16 inWidthDelta,
SInt16 inHeightDelta,
Boolean inRefresh)
{
LControl::ResizeFrameBy(inWidthDelta, inHeightDelta, inRefresh);
if (!mMovieController)
return;
FocusDraw();
Rect newFrame;
::MCGetControllerBoundsRect(mMovieController, &newFrame);
newFrame.right += inWidthDelta;
newFrame.bottom += inHeightDelta;
::MCSetControllerBoundsRect(mMovieController, &newFrame);
}
void CThrobber::MoveBy(SInt32 inHorizDelta,
SInt32 inVertDelta,
Boolean inRefresh)
{
LControl::MoveBy(inHorizDelta, inVertDelta, inRefresh);
if (!mMovieController)
return;
FocusDraw();
Rect newFrame;
::MCGetControllerBoundsRect(mMovieController, &newFrame);
::OffsetRect(&newFrame, inHorizDelta, inVertDelta);
::MCSetControllerBoundsRect(mMovieController, &newFrame);
}
void CThrobber::SpendTime(const EventRecord &inMacEvent)
{
FocusDraw();
::MCIsPlayerEvent(mMovieController, &inMacEvent);
}
void CThrobber::Start()
{
if (!mMovieController)
return;
::StartMovie(mMovie);
StartRepeating();
}
void CThrobber::Stop()
{
if (!mMovieController)
return;
StopRepeating();
::StopMovie(mMovie);
::GoToBeginningOfMovie(mMovie);
Refresh();
}
void CThrobber::CreateMovie()
{
OSErr err;
Handle dataRef = NULL;
try {
// Get the movie from our resource
StApplicationContext appResContext;
mMovieHandle = ::Get1Resource('GIF ', 128);
ThrowIfResFail_(mMovieHandle);
::DetachResource(mMovieHandle);
// Create a dataRef handle - from TN2018
err = ::PtrToHand(&mMovieHandle, &dataRef, sizeof(Handle));
ThrowIfError_(err);
err = ::PtrAndHand("\p", dataRef, 1);
ThrowIfError_(err);
long fileTypeAtom[3];
fileTypeAtom[0] = sizeof(long) * 3;
fileTypeAtom[1] = kDataRefExtensionMacOSFileType;
fileTypeAtom[2] = kQTFileTypeGIF;
err = ::PtrAndHand(fileTypeAtom, dataRef, sizeof(long) * 3);
ThrowIfError_(err);
err = ::NewMovieFromDataRef(&mMovie, newMovieActive, NULL, dataRef, HandleDataHandlerSubType);
ThrowIfError_(err);
DisposeHandle(dataRef);
dataRef = NULL;
// Make a controller for the movie
Rect movieBounds;
::GetMovieBox(mMovie, &movieBounds);
::MacOffsetRect(&movieBounds, (SInt16) -movieBounds.left, (SInt16) -movieBounds.top);
::SetMovieBox(mMovie, &movieBounds);
::SetMovieGWorld(mMovie, (CGrafPtr) GetMacPort(), nil);
Rect frame;
CalcLocalFrameRect(frame);
mMovieController = ::NewMovieController(mMovie, &frame, mcTopLeftMovie + mcNotVisible);
::MCDoAction(mMovieController, mcActionSetLooping, (void *)1);
::MCMovieChanged(mMovieController, mMovie);
}
catch (...) {
if (dataRef)
DisposeHandle(dataRef);
// Don't rethrow
}
}

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

@ -1,91 +0,0 @@
/* -*- Mode: C++; tab-width: 3; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* 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 the Initial Developer are Copyright (C) 1999
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Conrad Carlen <ccarlen@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef __CThrobber__
#define __CThrobber__
#include <LControl.h>
#include <LPeriodical.h>
// ToolBox
#include <Movies.h>
class CThrobber : public LControl,
public LPeriodical
{
public:
enum { class_ID = FOUR_CHAR_CODE('Thrb') };
CThrobber();
CThrobber(LStream* inStream);
virtual ~CThrobber();
// LPane
virtual void FinishCreateSelf();
virtual void ShowSelf();
virtual void HideSelf();
virtual void DrawSelf();
void ResizeFrameBy(SInt16 inWidthDelta,
SInt16 inHeightDelta,
Boolean inRefresh);
void MoveBy(SInt32 inHorizDelta,
SInt32 inVertDelta,
Boolean inRefresh);
// LPeriodical
virtual void SpendTime(const EventRecord &inMacEvent);
// CThrobber
virtual void Start();
virtual void Stop();
protected:
void CreateMovie();
protected:
SInt16 mMovieResID;
Handle mMovieHandle;
Movie mMovie;
MovieController mMovieController;
};
#endif

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

@ -1,72 +0,0 @@
#include "CUrlField.h"
#include <LString.h>
#include <PP_KeyCodes.h>
// CUrlField:
// A text edit field that broadcasts its PaneID on Return or Enter.
// ---------------------------------------------------------------------------
// ¥ CUrlField Stream Constructor [public]
// ---------------------------------------------------------------------------
CUrlField::CUrlField(LStream* inStream)
: LEditText(inStream)
{
}
// ---------------------------------------------------------------------------
// ¥ ~CUrlField Destructor [public]
// ---------------------------------------------------------------------------
CUrlField::~CUrlField()
{
}
// ---------------------------------------------------------------------------
// ¥ HandleKeyPress
// ---------------------------------------------------------------------------
// Broadcast the paneID when the user hits Return or Enter
Boolean
CUrlField::HandleKeyPress(const EventRecord &inKeyEvent)
{
Boolean keyHandled = true;
SInt16 theChar = (SInt16) (inKeyEvent.message & charCodeMask);
if (theChar == char_Return || theChar == char_Enter)
{
Str255 urlString;
BroadcastMessage(GetPaneID(), (void*)GetDescriptor(urlString));
}
else
keyHandled = Inherited::HandleKeyPress(inKeyEvent);
return keyHandled;
}
// ---------------------------------------------------------------------------
// ¥ ClickSelf
// ---------------------------------------------------------------------------
// Select everything when a single click gives us the focus
void
CUrlField::ClickSelf(const SMouseDownEvent &inMouseDown)
{
Boolean wasTarget = IsTarget();
Inherited::ClickSelf(inMouseDown);
if (!wasTarget)
{
ControlEditTextSelectionRec selection;
GetSelection(selection);
if (selection.selStart == selection.selEnd)
SelectAll();
}
}

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

@ -1,28 +0,0 @@
#include <LEditText.h>
// CUrlField:
// A text edit field that broadcasts its PaneID on Return or Enter.
class CUrlField : public LEditText
{
private:
typedef LEditText Inherited;
public:
enum { class_ID = FOUR_CHAR_CODE('UrlF') };
CUrlField(LStream* inStream);
virtual ~CUrlField();
virtual Boolean HandleKeyPress(
const EventRecord &inKeyEvent);
virtual void ClickSelf(
const SMouseDownEvent &inMouseDown);
};

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

@ -1,145 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* 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 the Initial Developer are Copyright (C) 1999
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Conrad Carlen <ccarlen@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "CWebBrowserCMAttachment.h"
//*****************************************************************************
// CWebBrowserChrome
//
// This override is needed because LCMAttachment intercepts mouse clicks, tracks
// the click, and handles it if the click is on a context menu. We don't want so
// complete a solution. In our case, mozilla handles the click, determines that
// it's a context menu click and then calls nsIContextMenuListener::OnShowContextMenu.
// This override allows DoContextMenuClick to be called after the click.
//
//*****************************************************************************
CWebBrowserCMAttachment::CWebBrowserCMAttachment()
{
}
CWebBrowserCMAttachment::CWebBrowserCMAttachment(LCommander* inTarget,
PaneIDT inTargetPaneID)
: LCMAttachment(inTarget, inTargetPaneID)
{
}
CWebBrowserCMAttachment::CWebBrowserCMAttachment(LStream* inStream)
: LCMAttachment(inStream)
{
}
CWebBrowserCMAttachment::~CWebBrowserCMAttachment()
{
}
void CWebBrowserCMAttachment::ExecuteSelf(MessageT inMessage,
void* ioParam)
{
SetExecuteHost(true);
// Ensure the CMM is installed and initialized. If not, just
// return quietly.
if (not mCMMInitialized) {
return;
}
// Dispatch to the various messages we handle.
if (inMessage == msg_AdjustCursor) {
// Only display the cursor if the control key is depressed
if (((static_cast<EventRecord*>(ioParam))->modifiers & controlKey) != 0) {
//+++ This needs to be updated to use kThemeContextualMenuArrowCursor,
//+++ but UCursor needs to be updated to be Theme-savvy first.
UCursor::SetTheCursor(mCMMCursorID);
SetExecuteHost(false);
}
} else if (inMessage == msg_Event) {
} else if (inMessage == msg_Click) {
// It's a click, but is it a CMM click?
if (::IsShowContextualMenuClick(
&(static_cast<SMouseDownEvent*>(ioParam))->macEvent)) {
// It is; let's handle it. However, first we must switch the
// target to our object, and update the port.
LCommander* target = FindCommandTarget();
if ((target != nil) && LCommander::SwitchTarget(target)) {
LPane* ownerAsPane = dynamic_cast<LPane*>(mOwnerHost);
if (ownerAsPane != nil) {
ownerAsPane->UpdatePort();
}
}
}
}
}
void CWebBrowserCMAttachment::SetCommandList(SInt16 mcmdResID)
{
Handle mcmdRes = ::GetResource(ResType_MenuCommands, mcmdResID);
ThrowIfResFail_(mcmdRes);
::DetachResource(mcmdRes); // LHandleStream takes ownership and uses DisposeHandle()
LHandleStream inStream(mcmdRes);
mCommandList.RemoveItemsAt(mCommandList.GetCount(), LArray::index_First);
UInt16 numCommands;
inStream >> numCommands;
for (SInt16 i = 1; i <= numCommands; i++) {
CommandT theCommand;
inStream >> theCommand;
mCommandList.AddItem(theCommand);
}
}
void CWebBrowserCMAttachment::DoContextMenuClick(const EventRecord& inMacEvent)
{
DoCMMClick(inMacEvent);
}

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

@ -1,79 +0,0 @@
/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* 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 the Initial Developer are Copyright (C) 1999
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Conrad Carlen <ccarlen@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef __CWebBrowserCMAttachment__
#define __CWebBrowserCMAttachment__
#include "LCMAttachment.h"
//*****************************************************************************
// class CWebBrowserCMAttachment
//
// This override is needed because LCMAttachment intercepts mouse clicks, tracks
// the click, and handles it if the click is on a context menu. We don't want so
// complete a solution. In our case, mozilla handles the click, determines that
// it's a context menu click and then calls nsIContextMenuListener::OnShowContextMenu.
// This override allows DoContextMenuClick to be called after the click.
//
//*****************************************************************************
class CWebBrowserCMAttachment : public LCMAttachment {
public:
enum { class_ID = FOUR_CHAR_CODE('WBCM') };
CWebBrowserCMAttachment();
CWebBrowserCMAttachment(LCommander* inTarget,
PaneIDT inTargetPaneID = PaneIDT_Unspecified);
CWebBrowserCMAttachment(LStream* inStream);
virtual ~CWebBrowserCMAttachment();
// LAttachment
virtual void ExecuteSelf(MessageT inMessage,
void* ioParam);
// CWebBrowserCMAttachment
virtual void SetCommandList(SInt16 mcmdResID);
virtual void DoContextMenuClick(const EventRecord& inMacEvent);
};
#endif // __CWebBrowserCMAttachment__

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

@ -1,557 +0,0 @@
/* -*- Mode: C++; tab-width: 3; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* 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 the Initial Developer are Copyright (C) 1999
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Travis Bogard <travis@netscape.com>
* Conrad Carlen <ccarlen@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
// Local Includes
#include "CWebBrowserChrome.h"
#include "CBrowserWindow.h"
#include "CBrowserShell.h"
#include "nsIGenericFactory.h"
#include "nsString.h"
#include "nsXPIDLString.h"
#include "nsReadableUtils.h"
#include "nsIURI.h"
#include "nsIWebProgress.h"
#include "nsIDocShellTreeItem.h"
#include "nsIRequest.h"
#include "nsIChannel.h"
#include "nsIDOMWindow.h"
#include "UMacUnicode.h"
#include "ApplIDs.h"
#include <LStaticText.h>
#include <LCheckBox.h>
#include <LEditText.h>
#include <UModalDialogs.h>
#include <LPushButton.h>
// Interfaces needed to be included
// Defines
#define USE_BALLOONS_FOR_TOOL_TIPS 0 // Using balloons for this is really obnoxious
// Constants
const PRInt32 kGrowIconSize = 15;
//*****************************************************************************
//*** CWebBrowserChrome: Object Management
//*****************************************************************************
CWebBrowserChrome::CWebBrowserChrome() :
mBrowserWindow(nsnull), mBrowserShell(nsnull),
mPreviousBalloonState(false), mInModalLoop(false)
{
}
CWebBrowserChrome::~CWebBrowserChrome()
{
}
//*****************************************************************************
// CWebBrowserChrome::nsISupports
//*****************************************************************************
NS_IMPL_ADDREF(CWebBrowserChrome)
NS_IMPL_RELEASE(CWebBrowserChrome)
NS_INTERFACE_MAP_BEGIN(CWebBrowserChrome)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIWebBrowserChrome)
NS_INTERFACE_MAP_ENTRY(nsIInterfaceRequestor)
NS_INTERFACE_MAP_ENTRY(nsIWebBrowserChrome)
NS_INTERFACE_MAP_ENTRY(nsIWebBrowserChromeFocus)
NS_INTERFACE_MAP_ENTRY(nsIWebProgressListener)
NS_INTERFACE_MAP_ENTRY(nsIEmbeddingSiteWindow)
NS_INTERFACE_MAP_ENTRY(nsIContextMenuListener)
NS_INTERFACE_MAP_ENTRY(nsITooltipListener)
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
NS_INTERFACE_MAP_END
//*****************************************************************************
// CWebBrowserChrome::nsIInterfaceRequestor
//*****************************************************************************
NS_IMETHODIMP CWebBrowserChrome::GetInterface(const nsIID &aIID, void** aInstancePtr)
{
if (aIID.Equals(NS_GET_IID(nsIDOMWindow)))
{
nsCOMPtr<nsIWebBrowser> browser;
GetWebBrowser(getter_AddRefs(browser));
if (browser)
return browser->GetContentDOMWindow((nsIDOMWindow **) aInstancePtr);
return NS_ERROR_NOT_INITIALIZED;
}
return QueryInterface(aIID, aInstancePtr);
}
//*****************************************************************************
// CWebBrowserChrome::nsIWebBrowserChrome
//*****************************************************************************
NS_IMETHODIMP CWebBrowserChrome::SetStatus(PRUint32 statusType, const PRUnichar *status)
{
NS_ENSURE_TRUE(mBrowserWindow, NS_ERROR_NOT_INITIALIZED);
if (statusType == STATUS_SCRIPT)
mBrowserWindow->SetStatus(status);
else if (statusType == STATUS_LINK)
mBrowserWindow->SetOverLink(status);
return NS_OK;
}
NS_IMETHODIMP CWebBrowserChrome::GetWebBrowser(nsIWebBrowser** aWebBrowser)
{
NS_ENSURE_ARG_POINTER(aWebBrowser);
NS_ENSURE_TRUE(mBrowserShell, NS_ERROR_NOT_INITIALIZED);
mBrowserShell->GetWebBrowser(aWebBrowser);
return NS_OK;
}
NS_IMETHODIMP CWebBrowserChrome::SetWebBrowser(nsIWebBrowser* aWebBrowser)
{
NS_ENSURE_ARG(aWebBrowser); // Passing nsnull is NOT OK
NS_ENSURE_TRUE(mBrowserShell, NS_ERROR_NOT_INITIALIZED);
mBrowserShell->SetWebBrowser(aWebBrowser);
return NS_OK;
}
NS_IMETHODIMP CWebBrowserChrome::GetChromeFlags(PRUint32* aChromeMask)
{
NS_ERROR("Haven't Implemented this yet");
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP CWebBrowserChrome::SetChromeFlags(PRUint32 aChromeMask)
{
NS_ERROR("Haven't Implemented this yet");
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP CWebBrowserChrome::DestroyBrowserWindow()
{
mInModalLoop = false;
delete mBrowserWindow;
return NS_OK;
}
NS_IMETHODIMP CWebBrowserChrome::IsWindowModal(PRBool *_retval)
{
*_retval = PR_FALSE;
return NS_OK;
}
NS_IMETHODIMP CWebBrowserChrome::SizeBrowserTo(PRInt32 aCX, PRInt32 aCY)
{
CBrowserShell *browserShell = mBrowserWindow->GetBrowserShell();
NS_ENSURE_TRUE(browserShell, NS_ERROR_NULL_POINTER);
SDimension16 curSize;
browserShell->GetFrameSize(curSize);
mBrowserWindow->ResizeWindowBy(aCX - curSize.width, aCY - curSize.height);
mBrowserWindow->SetSizeToContent(false);
return NS_OK;
}
NS_IMETHODIMP CWebBrowserChrome::ShowAsModal(void)
{
// We need this override because StDialogHandler deletes
// its window in its destructor. We don't want that here.
class CChromeDialogHandler : public StDialogHandler
{
public:
CChromeDialogHandler(LWindow* inWindow,
LCommander* inSuper) :
StDialogHandler(inWindow, inSuper)
{ }
virtual ~CChromeDialogHandler()
{ mDialog = nil; }
};
CChromeDialogHandler theHandler(mBrowserWindow, mBrowserWindow->GetSuperCommander());
// Set to false by ExitModalEventLoop or DestroyBrowserWindow
mInModalLoop = true;
while (mInModalLoop)
theHandler.DoDialog();
return NS_OK;
}
NS_IMETHODIMP CWebBrowserChrome::ExitModalEventLoop(nsresult aStatus)
{
mInModalLoop = false;
return NS_OK;
}
//*****************************************************************************
// CWebBrowserChrome::nsIWebBrowserChromeFocus
//*****************************************************************************
NS_IMETHODIMP CWebBrowserChrome::FocusNextElement()
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP CWebBrowserChrome::FocusPrevElement()
{
return NS_ERROR_NOT_IMPLEMENTED;
}
//*****************************************************************************
// CWebBrowserChrome::nsIWebProgressListener
//*****************************************************************************
NS_IMETHODIMP CWebBrowserChrome::OnProgressChange(nsIWebProgress *progress, nsIRequest *request,
PRInt32 curSelfProgress, PRInt32 maxSelfProgress,
PRInt32 curTotalProgress, PRInt32 maxTotalProgress)
{
NS_ENSURE_TRUE(mBrowserWindow, NS_OK);
return mBrowserWindow->OnProgressChange(progress, request,
curSelfProgress, maxSelfProgress,
curTotalProgress, maxTotalProgress);
}
NS_IMETHODIMP CWebBrowserChrome::OnStateChange(nsIWebProgress *progress, nsIRequest *request,
PRInt32 progressStateFlags, PRUint32 status)
{
NS_ENSURE_TRUE(mBrowserWindow, NS_OK);
if (progressStateFlags & STATE_IS_NETWORK) {
if (progressStateFlags & STATE_START)
mBrowserWindow->OnStatusNetStart(progress, request, progressStateFlags, status);
else if (progressStateFlags & STATE_STOP)
mBrowserWindow->OnStatusNetStop(progress, request, progressStateFlags, status);
}
return NS_OK;
}
NS_IMETHODIMP CWebBrowserChrome::OnLocationChange(nsIWebProgress* aWebProgress,
nsIRequest* aRequest,
nsIURI *location)
{
NS_ENSURE_TRUE(mBrowserWindow, NS_OK);
nsCAutoString buf;
if (location)
location->GetSpec(buf);
nsAutoString tmp;
CopyUTF8toUTF16(buf, tmp);
mBrowserWindow->SetLocation(tmp);
return NS_OK;
}
NS_IMETHODIMP
CWebBrowserChrome::OnStatusChange(nsIWebProgress* aWebProgress,
nsIRequest* aRequest,
nsresult aStatus,
const PRUnichar* aMessage)
{
return NS_OK;
}
NS_IMETHODIMP
CWebBrowserChrome::OnSecurityChange(nsIWebProgress *aWebProgress,
nsIRequest *aRequest,
PRUint32 state)
{
return NS_OK;
}
//*****************************************************************************
// CWebBrowserChrome::nsIEmbeddingSiteWindow
//*****************************************************************************
NS_IMETHODIMP CWebBrowserChrome::SetDimensions(PRUint32 flags, PRInt32 x, PRInt32 y, PRInt32 cx, PRInt32 cy)
{
NS_ENSURE_STATE(mBrowserWindow);
nsresult rv = NS_OK;
CBrowserShell *browserShell;
if (flags & nsIEmbeddingSiteWindow::DIM_FLAGS_POSITION) // setting position
{
if (flags & nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_INNER)
{
// Don't allow setting the position of the embedded area
rv = NS_ERROR_UNEXPECTED;
}
else // (flags & nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_OUTER)
{
mBrowserWindow->MoveWindowTo(x, y);
}
}
else // setting size
{
mBrowserWindow->SetSizeToContent(false);
if (flags & nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_INNER)
{
browserShell = mBrowserWindow->GetBrowserShell();
NS_ENSURE_TRUE(browserShell, NS_ERROR_NULL_POINTER);
SDimension16 curSize;
browserShell->GetFrameSize(curSize);
mBrowserWindow->ResizeWindowBy(cx - curSize.width, cy - curSize.height);
}
else // (flags & nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_OUTER)
{
if (mBrowserWindow->HasAttribute(windAttr_Resizable /*windAttr_SizeBox*/))
cy += 15;
mBrowserWindow->ResizeWindowTo(cx, cy);
}
}
return rv;
}
NS_IMETHODIMP CWebBrowserChrome::GetDimensions(PRUint32 flags, PRInt32 *x, PRInt32 *y, PRInt32 *cx, PRInt32 *cy)
{
NS_ENSURE_STATE(mBrowserWindow);
nsresult rv = NS_OK;
CBrowserShell *browserShell;
Rect bounds;
if (flags & nsIEmbeddingSiteWindow::DIM_FLAGS_POSITION) // getting position
{
if (flags & nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_INNER)
{
browserShell = mBrowserWindow->GetBrowserShell();
NS_ENSURE_TRUE(browserShell, NS_ERROR_NULL_POINTER);
SPoint32 curPos;
browserShell->GetFrameLocation(curPos);
if (x)
*x = curPos.h;
if (y)
*y = curPos.v;
}
else // (flags & nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_OUTER)
{
mBrowserWindow->GetGlobalBounds(bounds);
if (x)
*x = bounds.left;
if (y)
*y = bounds.top;
}
}
else // getting size
{
if (flags & nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_INNER)
{
browserShell = mBrowserWindow->GetBrowserShell();
NS_ENSURE_TRUE(browserShell, NS_ERROR_NULL_POINTER);
SDimension16 curSize;
browserShell->GetFrameSize(curSize);
if (cx)
*cx = curSize.width;
if (cy)
*cy = curSize.height;
}
else // (flags & nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_OUTER)
{
mBrowserWindow->GetGlobalBounds(bounds);
if (cx)
*cx = bounds.right - bounds.left;
if (cy)
{
*cy = bounds.bottom - bounds.top;
if (mBrowserWindow->HasAttribute(windAttr_Resizable /*windAttr_SizeBox*/))
*cy -= 15;
}
}
}
return rv;
}
NS_IMETHODIMP CWebBrowserChrome::SetFocus()
{
NS_ASSERTION(PR_FALSE, "Not Yet Implemented");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP CWebBrowserChrome::GetVisibility(PRBool *aVisibility)
{
NS_ENSURE_STATE(mBrowserWindow);
NS_ENSURE_ARG_POINTER(aVisibility);
mBrowserWindow->GetVisibility(aVisibility);
return NS_OK;
}
NS_IMETHODIMP CWebBrowserChrome::SetVisibility(PRBool aVisibility)
{
NS_ENSURE_STATE(mBrowserWindow);
mBrowserWindow->SetVisibility(aVisibility);
return NS_OK;
}
NS_IMETHODIMP CWebBrowserChrome::GetTitle(PRUnichar * *aTitle)
{
NS_ENSURE_STATE(mBrowserWindow);
NS_ENSURE_ARG_POINTER(aTitle);
Str255 pStr;
nsAutoString titleStr;
mBrowserWindow->GetDescriptor(pStr);
CPlatformUCSConversion::GetInstance()->PlatformToUCS(pStr, titleStr);
*aTitle = ToNewUnicode(titleStr);
return NS_OK;
}
NS_IMETHODIMP CWebBrowserChrome::SetTitle(const PRUnichar * aTitle)
{
NS_ENSURE_STATE(mBrowserWindow);
NS_ENSURE_ARG(aTitle);
Str255 pStr;
CPlatformUCSConversion::GetInstance()->UCSToPlatform(nsDependentString(aTitle), pStr);
mBrowserWindow->SetDescriptor(pStr);
return NS_OK;
}
NS_IMETHODIMP CWebBrowserChrome::GetSiteWindow(void * *aSiteWindow)
{
NS_ENSURE_ARG(aSiteWindow);
NS_ENSURE_STATE(mBrowserWindow);
*aSiteWindow = mBrowserWindow->Compat_GetMacWindow();
return NS_OK;
}
//*****************************************************************************
// CWebBrowserChrome::nsIContextMenuListener
//*****************************************************************************
NS_IMETHODIMP CWebBrowserChrome::OnShowContextMenu(PRUint32 aContextFlags, nsIDOMEvent *aEvent, nsIDOMNode *aNode)
{
nsresult rv;
NS_ENSURE_TRUE(mBrowserWindow, NS_ERROR_NOT_INITIALIZED);
try
{
rv = mBrowserWindow->OnShowContextMenu(aContextFlags, aEvent, aNode);
}
catch (...)
{
rv = NS_ERROR_FAILURE;
}
return rv;
}
//*****************************************************************************
// CWebBrowserChrome: Helpers
//*****************************************************************************
//*****************************************************************************
// CWebBrowserChrome: Accessors
//*****************************************************************************
CBrowserWindow*& CWebBrowserChrome::BrowserWindow()
{
return mBrowserWindow;
}
CBrowserShell*& CWebBrowserChrome::BrowserShell()
{
return mBrowserShell;
}
NS_IMETHODIMP
CWebBrowserChrome::OnShowTooltip(PRInt32 aXCoords, PRInt32 aYCoords, const PRUnichar *aTipText)
{
nsCAutoString printable;
CPlatformUCSConversion::GetInstance()->UCSToPlatform(nsDependentString(aTipText), printable);
#ifdef DEBUG
printf("--------- SHOW TOOLTIP AT %ld %ld, |%s|\n", aXCoords, aYCoords, printable.get() );
#endif
#if USE_BALLOONS_FOR_TOOL_TIPS
Point where;
::GetMouse ( &where );
::LocalToGlobal ( &where );
HMMessageRecord helpRec;
helpRec.hmmHelpType = khmmString;
helpRec.u.hmmString[0] = strlen(printable);
memcpy ( &helpRec.u.hmmString[1], printable, strlen(printable) );
mPreviousBalloonState = ::HMGetBalloons();
::HMSetBalloons ( true );
OSErr err = ::HMShowBalloon ( &helpRec, where, NULL, NULL, 0, 0, 0 );
#endif
return NS_OK;
}
NS_IMETHODIMP
CWebBrowserChrome::OnHideTooltip()
{
#ifdef DEBUG
printf("--------- HIDE TOOLTIP\n");
#endif
#if USE_BALLOONS_FOR_TOOL_TIPS
::HMRemoveBalloon();
::HMSetBalloons ( mPreviousBalloonState );
#endif
return NS_OK;
}

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

@ -1,103 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* 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 the Initial Developer are Copyright (C) 1999
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Conrad Carlen <conrad@ingress.com> based on work by:
* Travis Bogard <travis@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef __CWebBrowserChrome__
#define __CWebBrowserChrome__
// Helper Classes
#include "nsCOMPtr.h"
// Interfaces Needed
#include "nsIWebBrowserChrome.h"
#include "nsIWebBrowserChromeFocus.h"
#include "nsIWebProgressListener.h"
#include "nsIEmbeddingSiteWindow.h"
#include "nsIInterfaceRequestor.h"
#include "nsIInterfaceRequestorUtils.h"
#include "nsIPrompt.h"
#include "nsIContextMenuListener.h"
#include "nsITooltipListener.h"
#include "nsWeakReference.h"
// Other
#include "nsIWebBrowser.h"
class CBrowserWindow;
class CBrowserShell;
class CWebBrowserChrome : public nsIWebBrowserChrome,
public nsIWebBrowserChromeFocus,
public nsIWebProgressListener,
public nsIEmbeddingSiteWindow,
public nsIInterfaceRequestor,
public nsIContextMenuListener,
public nsITooltipListener,
public nsSupportsWeakReference
{
friend class CBrowserWindow;
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIWEBBROWSERCHROME
NS_DECL_NSIWEBBROWSERCHROMEFOCUS
NS_DECL_NSIWEBPROGRESSLISTENER
NS_DECL_NSIEMBEDDINGSITEWINDOW
NS_DECL_NSIINTERFACEREQUESTOR
NS_DECL_NSICONTEXTMENULISTENER
NS_DECL_NSITOOLTIPLISTENER
protected:
CWebBrowserChrome();
virtual ~CWebBrowserChrome();
CBrowserWindow*& BrowserWindow();
CBrowserShell*& BrowserShell();
protected:
CBrowserWindow* mBrowserWindow;
CBrowserShell* mBrowserShell;
Boolean mPreviousBalloonState; // are balloons on or off?
Boolean mInModalLoop;
nsCOMPtr<nsIPrompt> mPrompter;
};
#endif /* __CWebBrowserChrome__ */

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

@ -1,335 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* 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 mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Conrad Carlen <ccarlen@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "CWindowCreator.h"
#include "nsIWindowWatcher.h"
#include "nsServiceManagerUtils.h"
#include "nsIWebBrowserSetup.h"
#include "nsIPrefBranch.h"
#include "nsIURI.h"
#include "CBrowserShell.h"
#include "CBrowserWindow.h"
#include "CPrintAttachment.h"
#include "ApplIDs.h"
// ---------------------------------------------------------------------------
// CWindowCreator
// ---------------------------------------------------------------------------
NS_IMPL_ISUPPORTS2(CWindowCreator, nsIWindowCreator, nsIWindowCreator2)
CWindowCreator::CWindowCreator()
{
}
CWindowCreator::~CWindowCreator()
{
}
NS_IMETHODIMP CWindowCreator::CreateChromeWindow(nsIWebBrowserChrome *aParent,
PRUint32 aChromeFlags,
nsIWebBrowserChrome **_retval)
{
NS_ENSURE_ARG_POINTER(_retval);
*_retval = 0;
// we're ignoring aParent,
// but since windows on the Mac don't have parents anyway...
try {
LWindow *theWindow = CreateWindowInternal(aChromeFlags, PR_FALSE, -1, -1);
CBrowserShell *browser = dynamic_cast<CBrowserShell*>(theWindow->FindPaneByID(CBrowserShell::paneID_MainBrowser));
ThrowIfNil_(browser);
browser->GetWebBrowserChrome(_retval);
} catch(...) {
return NS_ERROR_FAILURE;
}
return NS_OK;
}
NS_IMETHODIMP CWindowCreator::CreateChromeWindow2(nsIWebBrowserChrome *parent,
PRUint32 chromeFlags, PRUint32 contextFlags,
nsIURI *aURI, PRBool *aCancel,
nsIWebBrowserChrome **_retval)
{
NS_ENSURE_ARG_POINTER(aCancel);
*aCancel = PR_FALSE;
if (contextFlags & nsIWindowCreator2::PARENT_IS_LOADING_OR_RUNNING_TIMEOUT) {
nsCOMPtr<nsIPrefBranch> prefs(do_GetService("@mozilla.org/preferences-service;1"));
if (prefs) {
PRBool showBlocker = PR_TRUE;
prefs->GetBoolPref("browser.popups.showPopupBlocker", &showBlocker);
if (showBlocker) {
short itemHit;
AlertStdAlertParamRec pb;
LStr255 msgString(STRx_StdAlertStrings, str_OpeningPopupWindow);
LStr255 explainString(STRx_StdAlertStrings, str_OpeningPopupWindowExp);
LStr255 defaultButtonText(STRx_StdButtonTitles, str_DenyAll);
LStr255 cancelButtonText(STRx_StdButtonTitles, str_Allow);
pb.movable = false;
pb.helpButton = false;
pb.filterProc = nil;
pb.defaultText = defaultButtonText;
pb.cancelText = cancelButtonText;
pb.otherText = nil;
pb.defaultButton = kStdOkItemIndex;
pb.cancelButton = kStdCancelItemIndex;
pb.position = kWindowAlertPositionParentWindowScreen;
::StandardAlert(kAlertStopAlert, msgString, explainString, &pb, &itemHit);
// This a one-time (for the life of prefs.js) alert
prefs->SetBoolPref("browser.popups.showPopupBlocker", PR_FALSE);
if (itemHit == kAlertStdAlertOKButton) {
// Also, if these prefs are set, the DOM itself will prevent future
// popups from being opened and our window creator won't even get
// called. If you wanted to filter each request, don't set these
// prefs. For this purpose, it's what we want, though.
prefs->SetBoolPref("dom.disable_open_during_load", PR_TRUE);
prefs->SetIntPref("dom.disable_open_click_delay", 1000);
return NS_ERROR_FAILURE;
}
}
}
}
return CreateChromeWindow(parent, chromeFlags, _retval);
}
/*
InitializeWindowCreator creates and hands off an object with a callback
to a window creation function. This will be used by Gecko C++ code
(never JS) to create new windows when no previous window is handy
to begin with. This is done in a few exceptional cases, like PSM code.
Failure to set this callback will only disable the ability to create
new windows under these circumstances.
*/
nsresult CWindowCreator::Initialize()
{
// Create a CWindowCreator and give it to the WindowWatcher service
// The WindowWatcher service will own it so we don't keep a ref.
CWindowCreator *windowCreator = new CWindowCreator;
if (!windowCreator) return NS_ERROR_FAILURE;
nsCOMPtr<nsIWindowWatcher> wwatch(do_GetService(NS_WINDOWWATCHER_CONTRACTID));
if (!wwatch) return NS_ERROR_FAILURE;
return wwatch->SetWindowCreator(windowCreator);
}
LWindow* CWindowCreator::CreateWindowInternal(PRUint32 inChromeFlags,
PRBool enablePrinting,
PRInt32 width, PRInt32 height)
{
const SInt16 kStatusBarHeight = 16;
const SDimension16 kMinimumWindowDimension = { 300, 150 };
const SInt16 kStdSizeVertMargin = 100;
LWindow *theWindow;
PRUint32 chromeFlags;
if (inChromeFlags == nsIWebBrowserChrome::CHROME_DEFAULT)
chromeFlags = nsIWebBrowserChrome::CHROME_WINDOW_RESIZE |
nsIWebBrowserChrome::CHROME_WINDOW_CLOSE |
nsIWebBrowserChrome::CHROME_TOOLBAR |
nsIWebBrowserChrome::CHROME_STATUSBAR;
else
chromeFlags = inChromeFlags;
// Bounds - Set to an arbitrary rect - we'll size it after all the subviews are in.
Rect globalBounds;
globalBounds.left = 4;
globalBounds.top = 42;
globalBounds.right = globalBounds.left + 600;
globalBounds.bottom = globalBounds.top + 400;
// ProcID and attributes
short windowDefProc;
UInt32 windowAttrs = (windAttr_Enabled | windAttr_Targetable);
if (chromeFlags & nsIWebBrowserChrome::CHROME_OPENAS_DIALOG)
{
if (chromeFlags & nsIWebBrowserChrome::CHROME_TITLEBAR)
{
windowDefProc = kWindowMovableModalDialogProc;
windowAttrs |= windAttr_TitleBar;
}
else
windowDefProc = kWindowModalDialogProc;
}
else
{
if (chromeFlags & nsIWebBrowserChrome::CHROME_WINDOW_RESIZE)
{
windowDefProc = kWindowGrowDocumentProc;
windowAttrs |= windAttr_Resizable;
windowAttrs |= windAttr_Zoomable;
}
else
windowDefProc = kWindowDocumentProc;
if (chromeFlags & nsIWebBrowserChrome::CHROME_WINDOW_CLOSE)
windowAttrs |= windAttr_CloseBox;
}
if (chromeFlags & nsIWebBrowserChrome::CHROME_MODAL)
windowAttrs |= windAttr_Modal;
else
windowAttrs |= windAttr_Regular;
theWindow = new CBrowserWindow(LCommander::GetTopCommander(), globalBounds, "\p", windowDefProc, windowAttrs, window_InFront);
ThrowIfNil_(theWindow);
if (windowAttrs & windAttr_Resizable)
{
Rect stdBounds, minMaxBounds;
SDimension16 stdSize;
theWindow->CalcStandardBounds(stdBounds);
stdSize.width = stdBounds.right - stdBounds.left;
stdSize.height = stdBounds.bottom - stdBounds.top;
stdSize.width -= kStdSizeVertMargin; // Leave a vertical strip of desktop exposed
theWindow->SetStandardSize(stdSize);
minMaxBounds.left = kMinimumWindowDimension.width;
minMaxBounds.top = kMinimumWindowDimension.height;
Rect deskRect;
::GetRegionBounds(::GetGrayRgn(), &deskRect);
minMaxBounds.left = kMinimumWindowDimension.width;
minMaxBounds.top = kMinimumWindowDimension.height;
minMaxBounds.right = deskRect.right - deskRect.left;
minMaxBounds.bottom = deskRect.bottom - deskRect.top;
theWindow->SetMinMaxSize(minMaxBounds);
}
SDimension16 windowSize, toolBarSize;
theWindow->GetFrameSize(windowSize);
if (chromeFlags & nsIWebBrowserChrome::CHROME_TOOLBAR)
{
LView::SetDefaultView(theWindow);
LCommander::SetDefaultCommander(theWindow);
LAttachable::SetDefaultAttachable(nil);
LView *toolBarView = static_cast<LView*>(UReanimator::ReadObjects(ResType_PPob, 131));
ThrowIfNil_(toolBarView);
toolBarView->GetFrameSize(toolBarSize);
toolBarView->PlaceInSuperFrameAt(0, 0, false);
toolBarSize.width = windowSize.width;
toolBarView->ResizeFrameTo(toolBarSize.width, toolBarSize.height, false);
}
SPaneInfo aPaneInfo;
SViewInfo aViewInfo;
aPaneInfo.paneID = CBrowserShell::paneID_MainBrowser;
aPaneInfo.width = windowSize.width;
aPaneInfo.height = windowSize.height;
if (chromeFlags & nsIWebBrowserChrome::CHROME_TOOLBAR)
aPaneInfo.height -= toolBarSize.height;
if (chromeFlags & nsIWebBrowserChrome::CHROME_STATUSBAR)
aPaneInfo.height -= kStatusBarHeight - 1;
aPaneInfo.visible = true;
aPaneInfo.enabled = true;
aPaneInfo.bindings.left = true;
aPaneInfo.bindings.top = true;
aPaneInfo.bindings.right = true;
aPaneInfo.bindings.bottom = true;
aPaneInfo.left = 0;
aPaneInfo.top = (chromeFlags & nsIWebBrowserChrome::CHROME_TOOLBAR) ? toolBarSize.height : 0;
aPaneInfo.userCon = 0;
aPaneInfo.superView = theWindow;
aViewInfo.imageSize.width = 0;
aViewInfo.imageSize.height = 0;
aViewInfo.scrollPos.h = aViewInfo.scrollPos.v = 0;
aViewInfo.scrollUnit.h = aViewInfo.scrollUnit.v = 1;
aViewInfo.reconcileOverhang = 0;
CBrowserShell *aShell = new CBrowserShell(aPaneInfo, aViewInfo, chromeFlags, PR_TRUE);
ThrowIfNil_(aShell);
aShell->AddAttachments();
aShell->PutInside(theWindow, false);
if (chromeFlags & nsIWebBrowserChrome::CHROME_OPENAS_CHROME)
{
nsCOMPtr<nsIWebBrowser> browser;
aShell->GetWebBrowser(getter_AddRefs(browser));
nsCOMPtr<nsIWebBrowserSetup> setup(do_QueryInterface(browser));
if (setup)
setup->SetProperty(nsIWebBrowserSetup::SETUP_IS_CHROME_WRAPPER, PR_TRUE);
}
if (chromeFlags & nsIWebBrowserChrome::CHROME_STATUSBAR)
{
LView::SetDefaultView(theWindow);
LCommander::SetDefaultCommander(theWindow);
LAttachable::SetDefaultAttachable(nil);
LView *statusView = static_cast<LView*>(UReanimator::ReadObjects(ResType_PPob, 130));
ThrowIfNil_(statusView);
statusView->PlaceInSuperFrameAt(0, windowSize.height - kStatusBarHeight + 1, false);
statusView->ResizeFrameTo(windowSize.width - 15, kStatusBarHeight, false);
}
if (enablePrinting)
{
CPrintAttachment *printAttachment = new CPrintAttachment(CBrowserShell::paneID_MainBrowser);
ThrowIfNil_(printAttachment);
theWindow->AddAttachment(printAttachment);
}
// Now the window is constructed...
theWindow->FinishCreate();
Rect theBounds;
theWindow->GetGlobalBounds(theBounds);
if (width == -1)
width = theBounds.right - theBounds.left;
if (height == -1)
height = theBounds.bottom - theBounds.top;
theWindow->ResizeWindowTo(width, height);
return theWindow;
}

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

@ -1,67 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* 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 mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Conrad Carlen <ccarlen@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef __CWindowCreator__
#define __CWindowCreator__
#include "nsIWindowCreator2.h"
#include "nsIWebBrowserChrome.h"
// ---------------------------------------------------------------------------
// CWindowCreator
// ---------------------------------------------------------------------------
class CWindowCreator : public nsIWindowCreator2
{
public:
CWindowCreator();
virtual ~CWindowCreator();
NS_DECL_ISUPPORTS
NS_DECL_NSIWINDOWCREATOR
NS_DECL_NSIWINDOWCREATOR2
// Call at startup time.
static nsresult Initialize();
static LWindow* CreateWindowInternal(PRUint32 inChromeFlags,
PRBool enablePrinting,
PRInt32 width, PRInt32 height);
};
#endif // __CWindowCreator__

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

@ -1,281 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* 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 the Initial Developer are Copyright (C) 1999
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Conrad Carlen <ccarlen@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "EmbedEventHandling.h"
#include "CTextInputEventHandler.h"
#include "prthread.h"
#if defined(__MWERKS__) && defined(DEBUG) && !TARGET_CARBON
#include "SIOUX.h"
#endif
#include "nsIWidget.h"
#include "nsIEventSink.h"
#include "nsCOMPtr.h"
// Static Variables
WindowPtr CEmbedEventAttachment::mLastAlienWindowClicked;
//*****************************************************************************
// CEmbedEventAttachment
//
// Handles events for windows popped up by Gecko which are not LWindows
//
//*****************************************************************************
CEmbedEventAttachment::CEmbedEventAttachment()
{
}
CEmbedEventAttachment::~CEmbedEventAttachment()
{
}
//
// GetTopWidget
//
// We've stashed the nsIWidget for the given windowPtr in the data
// properties of the window. Fetch it.
//
void
CEmbedEventAttachment::GetTopWidget ( WindowPtr aWindow, nsIWidget** outWidget )
{
nsIWidget* topLevelWidget = nsnull;
::GetWindowProperty ( aWindow, 'MOSS', 'GEKO', sizeof(nsIWidget*), nsnull, (void*)&topLevelWidget);
if ( topLevelWidget ) {
*outWidget = topLevelWidget;
NS_ADDREF(*outWidget);
}
}
//
// GetWindowEventSink
//
// We've stashed the nsIEventSink for the given windowPtr in the data of the
// root control. Fetch it.
//
void
CEmbedEventAttachment::GetWindowEventSink ( WindowPtr aWindow, nsIEventSink** outSink )
{
*outSink = nsnull;
nsCOMPtr<nsIWidget> topWidget;
GetTopWidget ( aWindow, getter_AddRefs(topWidget) );
nsCOMPtr<nsIEventSink> sink ( do_QueryInterface(topWidget) );
if ( sink ) {
*outSink = sink;
NS_ADDREF(*outSink);
}
}
void CEmbedEventAttachment::ExecuteSelf(MessageT inMessage,
void* ioParam)
{
SetExecuteHost(true);
EventRecord *inMacEvent;
WindowPtr macWindowP;
// 1. Handle the msg_AdjustCursor message. PowerPlant
// sends this message to attachments which are attached
// to views but not those attached to the application.
// IMPORTANT: For this to be called, the application's
// AdjustCursor() method must be overridden to send the
// msg_AdjustCursor to its attachments.
if (inMessage == msg_AdjustCursor) {
inMacEvent = static_cast<EventRecord*>(ioParam);
::MacFindWindow(inMacEvent->where, &macWindowP);
if (IsAlienGeckoWindow(macWindowP)) {
nsCOMPtr<nsIEventSink> sink;
GetWindowEventSink(macWindowP, getter_AddRefs(sink));
if ( sink ) {
PRBool handled = PR_FALSE;
sink->DispatchEvent(inMacEvent, &handled);
SetExecuteHost(false);
}
}
} else if (inMessage == msg_Event) {
inMacEvent = static_cast<EventRecord*>(ioParam);
#if defined(__MWERKS__) && defined(DEBUG) && !TARGET_CARBON
// 2. See if the event is for the console window.
// Limit what types of events we send to it.
if ((inMacEvent->what == mouseDown ||
inMacEvent->what == updateEvt ||
inMacEvent->what == activateEvt ||
inMacEvent->what == keyDown) &&
SIOUXHandleOneEvent(inMacEvent))
{
SetExecuteHost(false);
return;
}
#endif
// 3. Finally, see if we have an event for a Gecko window
// which is not an LWindow. These get created by widget to
// show pop-up list boxes - grrr. The following events are
// sufficient for those.
switch (inMacEvent->what)
{
case mouseDown:
{
mLastAlienWindowClicked = nil;
// If an alien window is frontmost, as they always are when present,
// Gecko needs to get the event - no matter where the click occured.
// This is so the pop-up window (what these alien windows are used for)
// will be rolled up on a click in the menu bar, title bar, etc.
WindowPtr frontWindow = ::FrontWindow();
if (IsAlienGeckoWindow(frontWindow)) {
nsCOMPtr<nsIEventSink> sink;
GetWindowEventSink(frontWindow, getter_AddRefs(sink));
if (sink) {
PRBool handled = PR_FALSE;
sink->DispatchEvent(inMacEvent, &handled);
SInt16 thePart = ::MacFindWindow(inMacEvent->where, &macWindowP);
if ((thePart == inContent) && (frontWindow == macWindowP)) {
// It the click was actually in an alien window - done processing
// Otherwise, let PowerPlant continue processing the click.
mLastAlienWindowClicked = macWindowP;
SetExecuteHost(false);
}
}
}
}
break;
case mouseUp:
{
if (mLastAlienWindowClicked) {
nsCOMPtr<nsIEventSink> sink;
GetWindowEventSink(mLastAlienWindowClicked, getter_AddRefs(sink));
if ( sink ) {
PRBool handled = PR_FALSE;
sink->DispatchEvent(inMacEvent, &handled);
mLastAlienWindowClicked = nil;
SetExecuteHost(false);
}
}
}
break;
case updateEvt:
case activateEvt:
{
macWindowP = (WindowPtr)inMacEvent->message;
if (IsAlienGeckoWindow(macWindowP)) {
nsCOMPtr<nsIEventSink> sink;
GetWindowEventSink(macWindowP, getter_AddRefs(sink));
if ( sink ) {
PRBool handled = PR_FALSE;
sink->DispatchEvent(inMacEvent, &handled);
SetExecuteHost(false);
}
}
}
break;
}
}
}
Boolean CEmbedEventAttachment::IsAlienGeckoWindow(WindowPtr inMacWindow)
{
PRBool isAlien = PR_FALSE;
// it's an 'alien' window if there's no LWindow object and there is
// an nsIEventSink stashed in the window's root control.
if (inMacWindow && !LWindow::FetchWindowObject(inMacWindow)) {
nsCOMPtr<nsIEventSink> sink;
GetWindowEventSink ( inMacWindow, getter_AddRefs(sink) );
if ( sink )
isAlien = PR_TRUE;
}
return isAlien;
}
//*****************************************************************************
// CEmbedIdler
//
//
//*****************************************************************************
CEmbedIdler::CEmbedIdler()
{
}
CEmbedIdler::~CEmbedIdler()
{
}
void CEmbedIdler::SpendTime(const EventRecord& inMacEvent)
{
::PR_Sleep(PR_INTERVAL_NO_WAIT);
}
//*****************************************************************************
// Initialization Function - Call at application startup.
//*****************************************************************************
void InitializeEmbedEventHandling(LApplication* theApplication)
{
CEmbedEventAttachment *windowAttachment = new CEmbedEventAttachment;
ThrowIfNil_(windowAttachment);
theApplication->AddAttachment(windowAttachment);
CEmbedIdler *embedIdler = new CEmbedIdler;
ThrowIfNil_(embedIdler);
embedIdler->StartIdling();
#if TARGET_CARBON
InitializeTextInputEventHandling();
#endif
}

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

@ -1,124 +0,0 @@
/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* 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 the Initial Developer are Copyright (C) 1999
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Conrad Carlen <ccarlen@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef __EmbedEventHandling__
#define __EmbedEventHandling__
#include "LAttachment.h"
#include "LPeriodical.h"
class nsIWidget;
class nsIEventSink;
//*****************************************************************************
// class CEmbedEventAttachment
//
// Handles events for windows popped up by Gecko which are not LWindows
//
//*****************************************************************************
class CEmbedEventAttachment : public LAttachment
{
public:
enum { class_ID = FOUR_CHAR_CODE('GAWA') };
CEmbedEventAttachment();
virtual ~CEmbedEventAttachment();
// LAttachment
virtual void ExecuteSelf(MessageT inMessage,
void* ioParam);
protected:
Boolean IsAlienGeckoWindow(WindowPtr inMacWindow);
// utility routines for getting the toplevel widget and event sink
// stashed in the properties of gecko windows.
static void GetWindowEventSink ( WindowPtr aWindow, nsIEventSink** outSink ) ;
static void GetTopWidget ( WindowPtr aWindow, nsIWidget** outWidget ) ;
static WindowPtr mLastAlienWindowClicked;
};
//*****************************************************************************
// class CEmbedIdler
//
// LPeriodical idler which calls Gecko's idling
//
//*****************************************************************************
class CEmbedIdler : public LPeriodical
{
public:
CEmbedIdler();
virtual ~CEmbedIdler();
// LPeriodical
virtual void SpendTime(const EventRecord& inMacEvent);
};
//*****************************************************************************
// class CEmbedRepeater
//
// LPeriodical repeater which calls Gecko's repeaters
//
//*****************************************************************************
class CEmbedRepeater : public LPeriodical
{
public:
CEmbedRepeater();
virtual ~CEmbedRepeater();
// LPeriodical
virtual void SpendTime(const EventRecord& inMacEvent);
};
//*****************************************************************************
// Initialization Function - Call at application startup.
//*****************************************************************************
void InitializeEmbedEventHandling(LApplication* theApplication);
#endif // __EmbedEventHandling__

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

@ -1,83 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* 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 the Initial Developer are Copyright (C) 1999
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Conrad Carlen <ccarlen@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
// Configuration flags used by all targets
#ifndef __PPEmbedConfig_h
#define __PPEmbedConfig_h
/*
USE_PROFILES
If defined, the application will use nsIProfileManager to allow
distinct user profiles. It also demonstrates dynamic profile switching in this case.
If undefined, the application will construct and register an
nsIDirectoryServiceProvider which provides profile-relative file locations to one
fixed directory.
*/
#undef USE_PROFILES
/*
SHARED_PROFILE
If defined, the application will share profile data (that which is shareable) with
other applications in its "suite." The data which is not shared by applications
in the suite is stored in a subdir of the profile which is named for each particular
member of the suite. This can be used with or without USE_PROFILES.
*/
#define SHARED_PROFILE
/*
NATIVE_PROMPTS
If defined, the application will override Gecko's prompt service
component with the implementation in PromptService.cpp. This implementation uses
PowerPlant dialogs.
If undefined, the application will use Gecko's default prompt service. This implementation
creates chrome dialogs through the nsIWindowCreator interface. Undefining this
is useful for testing the implementation of nsIWindowCreator, nsIWebBrowserChrome, etc.
*/
#define NATIVE_PROMPTS
#endif

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

@ -1,51 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* 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 the Initial Developer are Copyright (C) 1999
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Conrad Carlen <ccarlen@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef __PPEmbedPrefix_h
#define __PPEmbedPrefix_h
// The precompiled header is built by the PowerPlant lib project
// It includes the needed mozilla configuration #defines
#include "PPHeaders_pch"
// Config flags common to all builds
#include "PPEmbedConfig.h"
#endif

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

@ -1,51 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* 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 the Initial Developer are Copyright (C) 1999
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Conrad Carlen <ccarlen@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef __PPEmbedPrefix_debug_h
#define __PPEmbedPrefix_debug_h
// The precompiled header is built by the PowerPlant lib project
// It includes the needed mozilla configuration #defines
#include "PPHeadersDebug_pch"
// Config flags common to all builds
#include "PPEmbedConfig.h"
#endif

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

@ -1,648 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* 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 mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "PromptService.h"
#include "nsCOMPtr.h"
#include "nsIPromptService.h"
#include "nsString.h"
#include "nsReadableUtils.h"
#include "nsIWindowWatcher.h"
#include "nsIServiceManager.h"
#include "nsIWebBrowserChrome.h"
#include "nsIEmbeddingSiteWindow.h"
// Local Includes
#include "ApplIDs.h"
#include "UMacUnicode.h"
#include "CBrowserChrome.h"
// PowerPlant
#include <LStaticText.h>
#include <LCheckBox.h>
#include <LEditText.h>
#include <UModalDialogs.h>
#include <LPushButton.h>
//*****************************************************************************
// CPromptService
//*****************************************************************************
NS_IMPL_ISUPPORTS1(CPromptService, nsIPromptService)
CPromptService::CPromptService()
{
}
CPromptService::~CPromptService()
{
}
NS_IMETHODIMP CPromptService::Alert(nsIDOMWindow *parent, const PRUnichar *dialogTitle,
const PRUnichar *text)
{
StDialogHandler theHandler(dlog_Alert, CBrowserChrome::GetLWindowForDOMWindow(parent));
LWindow *theDialog = theHandler.GetDialog();
nsCAutoString cStr;
Str255 pStr;
CPlatformUCSConversion::GetInstance()->UCSToPlatform(nsDependentString(dialogTitle), pStr);
theDialog->SetDescriptor(pStr);
LStaticText *msgText = dynamic_cast<LStaticText*>(theDialog->FindPaneByID('Msg '));
CPlatformUCSConversion::GetInstance()->UCSToPlatform(nsDependentString(text), cStr);
cStr.ReplaceChar('\n', '\r');
msgText->SetText(const_cast<char *>(cStr.get()), cStr.Length());
theDialog->Show();
theDialog->Select();
while (true) // This is our modal dialog event loop
{
MessageT hitMessage = theHandler.DoDialog();
if (hitMessage == msg_OK)
break;
}
return NS_OK;
}
NS_IMETHODIMP CPromptService::AlertCheck(nsIDOMWindow *parent, const PRUnichar *dialogTitle,
const PRUnichar *text,
const PRUnichar *checkMsg, PRBool *checkValue)
{
NS_ENSURE_ARG_POINTER(checkValue);
StDialogHandler theHandler(dlog_AlertCheck, CBrowserChrome::GetLWindowForDOMWindow(parent));
LWindow *theDialog = theHandler.GetDialog();
nsCAutoString cStr;
Str255 pStr;
CPlatformUCSConversion::GetInstance()->UCSToPlatform(nsDependentString(dialogTitle), pStr);
theDialog->SetDescriptor(pStr);
LStaticText *msgText = dynamic_cast<LStaticText*>(theDialog->FindPaneByID('Msg '));
CPlatformUCSConversion::GetInstance()->UCSToPlatform(nsDependentString(text), cStr);
cStr.ReplaceChar('\n', '\r');
msgText->SetText(const_cast<char *>(cStr.get()), cStr.Length());
LCheckBox *checkBox = dynamic_cast<LCheckBox*>(theDialog->FindPaneByID('Chck'));
CPlatformUCSConversion::GetInstance()->UCSToPlatform(nsDependentString(checkMsg), pStr);
checkBox->SetDescriptor(pStr);
checkBox->SetValue(*checkValue ? 1 : 0);
theDialog->Show();
theDialog->Select();
while (true) // This is our modal dialog event loop
{
MessageT hitMessage = theHandler.DoDialog();
if (hitMessage == msg_OK)
{
*checkValue = checkBox->GetValue();
break;
}
}
return NS_OK;
}
NS_IMETHODIMP CPromptService::Confirm(nsIDOMWindow *parent, const PRUnichar *dialogTitle,
const PRUnichar *text,
PRBool *_retval)
{
NS_ENSURE_ARG_POINTER(_retval);
StDialogHandler theHandler(dlog_Confirm, CBrowserChrome::GetLWindowForDOMWindow(parent));
LWindow *theDialog = theHandler.GetDialog();
nsCAutoString cStr;
Str255 pStr;
CPlatformUCSConversion::GetInstance()->UCSToPlatform(nsDependentString(dialogTitle), pStr);
theDialog->SetDescriptor(pStr);
LStaticText *msgText = dynamic_cast<LStaticText*>(theDialog->FindPaneByID('Msg '));
CPlatformUCSConversion::GetInstance()->UCSToPlatform(nsDependentString(text), cStr);
cStr.ReplaceChar('\n', '\r');
msgText->SetText(const_cast<char *>(cStr.get()), cStr.Length());
theDialog->Show();
theDialog->Select();
while (true) // This is our modal dialog event loop
{
MessageT hitMessage = theHandler.DoDialog();
if (hitMessage == msg_OK)
{
*_retval = PR_TRUE;
break;
}
else if (hitMessage == msg_Cancel)
{
*_retval = PR_FALSE;
break;
}
}
return NS_OK;
}
NS_IMETHODIMP CPromptService::ConfirmCheck(nsIDOMWindow *parent, const PRUnichar *dialogTitle,
const PRUnichar *text,
const PRUnichar *checkMsg, PRBool *checkValue,
PRBool *_retval)
{
NS_ENSURE_ARG_POINTER(checkValue);
NS_ENSURE_ARG_POINTER(_retval);
StDialogHandler theHandler(dlog_ConfirmCheck, CBrowserChrome::GetLWindowForDOMWindow(parent));
LWindow *theDialog = theHandler.GetDialog();
nsCAutoString cStr;
Str255 pStr;
CPlatformUCSConversion::GetInstance()->UCSToPlatform(nsDependentString(dialogTitle), pStr);
theDialog->SetDescriptor(pStr);
LStaticText *msgText = dynamic_cast<LStaticText*>(theDialog->FindPaneByID('Msg '));
CPlatformUCSConversion::GetInstance()->UCSToPlatform(nsDependentString(text), cStr);
cStr.ReplaceChar('\n', '\r');
msgText->SetText(const_cast<char *>(cStr.get()), cStr.Length());
LCheckBox *checkBox = dynamic_cast<LCheckBox*>(theDialog->FindPaneByID('Chck'));
CPlatformUCSConversion::GetInstance()->UCSToPlatform(nsDependentString(checkMsg), pStr);
checkBox->SetDescriptor(pStr);
checkBox->SetValue(*checkValue ? 1 : 0);
theDialog->Show();
theDialog->Select();
while (true) // This is our modal dialog event loop
{
MessageT hitMessage = theHandler.DoDialog();
if (hitMessage == msg_OK)
{
*_retval = PR_TRUE;
*checkValue = checkBox->GetValue();
break;
}
else if (hitMessage == msg_Cancel)
{
*_retval = PR_FALSE;
break;
}
}
return NS_OK;
}
NS_IMETHODIMP CPromptService::ConfirmEx(nsIDOMWindow *parent, const PRUnichar *dialogTitle,
const PRUnichar *text,
PRUint32 buttonFlags,
const PRUnichar *button0Title,
const PRUnichar *button1Title,
const PRUnichar *button2Title,
const PRUnichar *checkMsg, PRBool *checkValue,
PRInt32 *buttonPressed)
{
NS_ENSURE_ARG_POINTER(buttonPressed);
StDialogHandler theHandler(dlog_ConfirmEx, CBrowserChrome::GetLWindowForDOMWindow(parent));
LWindow *theDialog = theHandler.GetDialog();
nsCAutoString cStr;
Str255 pStr;
SDimension16 oldSize;
SInt16 bestWidth, bestHeight, baselineOffset;
if (dialogTitle) {
CPlatformUCSConversion::GetInstance()->UCSToPlatform(nsDependentString(dialogTitle), pStr);
theDialog->SetDescriptor(pStr);
}
LCheckBox *checkBox = nil;
if (checkMsg && checkValue) {
checkBox = dynamic_cast<LCheckBox*>(theDialog->FindPaneByID('Chck'));
CPlatformUCSConversion::GetInstance()->UCSToPlatform(nsDependentString(checkMsg), pStr);
checkBox->SetDescriptor(pStr);
checkBox->SetValue(*checkValue ? 1 : 0);
// Let the checkbox text first stretch the width of the dialog.
// Do not let it reduce the width.
// For checkboxes, CalcBestControlRect will attempt to keep the text on one line.
if (checkBox->SupportsCalcBestRect()) {
checkBox->GetFrameSize(oldSize);
checkBox->CalcBestControlRect(bestWidth, bestHeight, baselineOffset);
// The view is set up so that this will shift and stretch everything properly.
if (bestWidth > oldSize.width)
theDialog->ResizeWindowBy(bestWidth - oldSize.width, bestHeight - oldSize.height);
}
}
LStaticText *msgText = dynamic_cast<LStaticText*>(theDialog->FindPaneByID('Msg '));
CPlatformUCSConversion::GetInstance()->UCSToPlatform(nsDependentString(text), cStr);
cStr.ReplaceChar('\n', '\r');
msgText->SetText(const_cast<char *>(cStr.get()), cStr.Length());
// For static text, CalcBestControlRect will stretch vertically
if (msgText->SupportsCalcBestRect()) {
msgText->GetFrameSize(oldSize);
msgText->CalcBestControlRect(bestWidth, bestHeight, baselineOffset);
// The view is set up so that this will shift and stretch everything properly.
// Do not let it reduce the width of the dialog.
SInt16 hDelta = bestWidth - oldSize.width;
if (hDelta < 0)
hDelta = 0;
theDialog->ResizeWindowBy(hDelta, bestHeight - oldSize.height);
}
const PRUnichar* buttonTitles[3] = { button0Title, button1Title, button2Title };
PaneIDT buttonIDs[3] = { 'Btn0', 'Btn1', 'Btn2' };
SInt16 buttonShift = 0;
for (int i = 0; i < 3; i++)
{
LPushButton *button = dynamic_cast<LPushButton*>(theDialog->FindPaneByID(buttonIDs[i]));
if (!button)
continue;
SInt16 strIndex = -1;
Boolean hidden = false;
switch (buttonFlags & 0x00FF)
{
case 0:
button->Hide();
hidden = true;
break;
case BUTTON_TITLE_OK:
strIndex = str_OK;
break;
case BUTTON_TITLE_CANCEL:
strIndex = str_Cancel;
break;
case BUTTON_TITLE_YES:
strIndex = str_Yes;
break;
case BUTTON_TITLE_NO:
strIndex = str_No;
break;
case BUTTON_TITLE_SAVE:
strIndex = str_Save;
break;
case BUTTON_TITLE_DONT_SAVE:
strIndex = str_DontSave;
break;
case BUTTON_TITLE_REVERT:
strIndex = str_Revert;
break;
case BUTTON_TITLE_IS_STRING:
{
CPlatformUCSConversion::GetInstance()->UCSToPlatform(nsDependentString(buttonTitles[i]), pStr);
button->SetDescriptor(pStr);
}
break;
}
if (strIndex != -1) {
LStr255 buttonTitle(STRx_StdButtonTitles, strIndex);
button->SetDescriptor(buttonTitle);
}
if (!hidden) {
if (button->SupportsCalcBestRect()) {
button->GetFrameSize(oldSize);
button->CalcBestControlRect(bestWidth, bestHeight, baselineOffset);
buttonShift += bestWidth - oldSize.width;
button->MoveBy(-buttonShift, 0, false);
button->ResizeFrameTo(bestWidth, bestHeight, false);
}
}
buttonFlags >>= 8;
}
theDialog->Show();
theDialog->Select();
while (true) // This is our modal dialog event loop
{
MessageT hitMessage = theHandler.DoDialog();
if (hitMessage == 'Btn0')
{
*buttonPressed = 0;
break;
}
else if (hitMessage == 'Btn1')
{
*buttonPressed = 1;
break;
}
else if (hitMessage == 'Btn2')
{
*buttonPressed = 2;
break;
}
}
if (checkBox)
*checkValue = checkBox->GetValue();
return NS_OK;
}
NS_IMETHODIMP CPromptService::Prompt(nsIDOMWindow *parent, const PRUnichar *dialogTitle,
const PRUnichar *text, PRUnichar **value,
const PRUnichar *checkMsg, PRBool *checkValue,
PRBool *_retval)
{
NS_ENSURE_ARG_POINTER(_retval);
nsresult resultErr = NS_OK;
StDialogHandler theHandler(dlog_Prompt, CBrowserChrome::GetLWindowForDOMWindow(parent));
LWindow *theDialog = theHandler.GetDialog();
LCheckBox *checkbox = dynamic_cast<LCheckBox*>(theDialog->FindPaneByID('Chck'));
nsCAutoString cStr;
Str255 pStr;
if (dialogTitle) {
CPlatformUCSConversion::GetInstance()->UCSToPlatform(nsDependentString(dialogTitle), pStr);
theDialog->SetDescriptor(pStr);
}
LStaticText *msgText = dynamic_cast<LStaticText*>(theDialog->FindPaneByID('Msg '));
CPlatformUCSConversion::GetInstance()->UCSToPlatform(nsDependentString(text), cStr);
cStr.ReplaceChar('\n', '\r');
msgText->SetText(const_cast<char *>(cStr.get()), cStr.Length());
LEditText *responseText = dynamic_cast<LEditText*>(theDialog->FindPaneByID('Rslt'));
if (value && *value) {
CPlatformUCSConversion::GetInstance()->UCSToPlatform(nsDependentString(*value), pStr);
responseText->SetDescriptor(pStr);
}
if (checkValue) {
checkbox->SetValue(*checkValue);
if (checkMsg) {
CPlatformUCSConversion::GetInstance()->UCSToPlatform(nsDependentString(checkMsg), pStr);
checkbox->SetDescriptor(pStr);
}
}
else
checkbox->Hide();
theDialog->SetLatentSub(responseText);
theDialog->Show();
theDialog->Select();
while (true) // This is our modal dialog event loop
{
MessageT hitMessage = theHandler.DoDialog();
if (hitMessage == msg_OK)
{
nsAutoString ucStr;
*_retval = PR_TRUE;
if (value && *value) {
nsMemory::Free(*value);
*value = nsnull;
}
responseText->GetDescriptor(pStr);
CPlatformUCSConversion::GetInstance()->PlatformToUCS(pStr, ucStr);
*value = ToNewUnicode(ucStr);
if (*value == nsnull)
resultErr = NS_ERROR_OUT_OF_MEMORY;
if (checkValue)
*checkValue = checkbox->GetValue();
break;
}
else if (hitMessage == msg_Cancel)
{
*_retval = PR_FALSE;
break;
}
}
return resultErr;
}
NS_IMETHODIMP CPromptService::PromptUsernameAndPassword(nsIDOMWindow *parent, const PRUnichar *dialogTitle,
const PRUnichar *text,
PRUnichar **username, PRUnichar **password,
const PRUnichar *checkMsg, PRBool *checkValue,
PRBool *_retval)
{
NS_ENSURE_ARG_POINTER(_retval);
nsresult resultErr = NS_OK;
StDialogHandler theHandler(dlog_PromptNameAndPass, CBrowserChrome::GetLWindowForDOMWindow(parent));
LWindow *theDialog = theHandler.GetDialog();
LCheckBox *checkbox = dynamic_cast<LCheckBox*>(theDialog->FindPaneByID('Chck'));
nsCAutoString cStr;
Str255 pStr;
if (dialogTitle) {
CPlatformUCSConversion::GetInstance()->UCSToPlatform(nsDependentString(dialogTitle), pStr);
theDialog->SetDescriptor(pStr);
}
LStaticText *msgText = dynamic_cast<LStaticText*>(theDialog->FindPaneByID('Msg '));
CPlatformUCSConversion::GetInstance()->UCSToPlatform(nsDependentString(text), cStr);
cStr.ReplaceChar('\n', '\r');
msgText->SetText(const_cast<char *>(cStr.get()), cStr.Length());
LEditText *userText = dynamic_cast<LEditText*>(theDialog->FindPaneByID('Name'));
if (username && *username) {
CPlatformUCSConversion::GetInstance()->UCSToPlatform(nsDependentString(*username), pStr);
userText->SetDescriptor(pStr);
}
LEditText *pwdText = dynamic_cast<LEditText*>(theDialog->FindPaneByID('Pass'));
if (password && *password) {
CPlatformUCSConversion::GetInstance()->UCSToPlatform(nsDependentString(*password), pStr);
pwdText->SetDescriptor(pStr);
}
if (checkValue) {
checkbox->SetValue(*checkValue);
if (checkMsg) {
CPlatformUCSConversion::GetInstance()->UCSToPlatform(nsDependentString(checkMsg), pStr);
checkbox->SetDescriptor(pStr);
}
}
else
checkbox->Hide();
theDialog->SetLatentSub(userText);
theDialog->Show();
theDialog->Select();
while (true) // This is our modal dialog event loop
{
MessageT hitMessage = theHandler.DoDialog();
if (hitMessage == msg_OK)
{
nsAutoString ucStr;
if (username && *username) {
nsMemory::Free(*username);
*username = nsnull;
}
userText->GetDescriptor(pStr);
CPlatformUCSConversion::GetInstance()->PlatformToUCS(pStr, ucStr);
*username = ToNewUnicode(ucStr);
if (*username == nsnull)
resultErr = NS_ERROR_OUT_OF_MEMORY;
if (password && *password) {
nsMemory::Free(*password);
*password = nsnull;
}
pwdText->GetDescriptor(pStr);
CPlatformUCSConversion::GetInstance()->PlatformToUCS(pStr, ucStr);
*password = ToNewUnicode(ucStr);
if (*password == nsnull)
resultErr = NS_ERROR_OUT_OF_MEMORY;
if (checkValue)
*checkValue = checkbox->GetValue();
*_retval = PR_TRUE;
break;
}
else if (hitMessage == msg_Cancel)
{
*_retval = PR_FALSE;
break;
}
}
return resultErr;
}
NS_IMETHODIMP CPromptService::PromptPassword(nsIDOMWindow *parent, const PRUnichar *dialogTitle,
const PRUnichar *text,
PRUnichar **password,
const PRUnichar *checkMsg, PRBool *checkValue,
PRBool *_retval)
{
NS_ENSURE_ARG_POINTER(_retval);
nsresult resultErr = NS_OK;
StDialogHandler theHandler(dlog_PromptPassword, CBrowserChrome::GetLWindowForDOMWindow(parent));
LWindow *theDialog = theHandler.GetDialog();
LCheckBox *checkbox = dynamic_cast<LCheckBox*>(theDialog->FindPaneByID('Chck'));
nsCAutoString cStr;
Str255 pStr;
if (dialogTitle) {
CPlatformUCSConversion::GetInstance()->UCSToPlatform(nsDependentString(dialogTitle), pStr);
theDialog->SetDescriptor(pStr);
}
LStaticText *msgText = dynamic_cast<LStaticText*>(theDialog->FindPaneByID('Msg '));
CPlatformUCSConversion::GetInstance()->UCSToPlatform(nsDependentString(text), cStr);
cStr.ReplaceChar('\n', '\r');
msgText->SetText(const_cast<char *>(cStr.get()), cStr.Length());
LEditText *pwdText = dynamic_cast<LEditText*>(theDialog->FindPaneByID('Pass'));
if (password && *password) {
CPlatformUCSConversion::GetInstance()->UCSToPlatform(nsDependentString(*password), pStr);
pwdText->SetDescriptor(pStr);
}
if (checkValue) {
checkbox->SetValue(*checkValue);
if (checkMsg) {
CPlatformUCSConversion::GetInstance()->UCSToPlatform(nsDependentString(checkMsg), pStr);
checkbox->SetDescriptor(pStr);
}
}
else
checkbox->Hide();
theDialog->SetLatentSub(pwdText);
theDialog->Show();
theDialog->Select();
while (true) // This is our modal dialog event loop
{
MessageT hitMessage = theHandler.DoDialog();
if (hitMessage == msg_OK)
{
nsAutoString ucStr;
if (password && *password) {
nsMemory::Free(*password);
*password = nsnull;
}
pwdText->GetDescriptor(pStr);
CPlatformUCSConversion::GetInstance()->PlatformToUCS(pStr, ucStr);
*password = ToNewUnicode(ucStr);
if (*password == nsnull)
resultErr = NS_ERROR_OUT_OF_MEMORY;
if (checkValue)
*checkValue = checkbox->GetValue();
*_retval = PR_TRUE;
break;
}
else if (hitMessage == msg_Cancel)
{
*_retval = PR_FALSE;
break;
}
}
return resultErr;
}
NS_IMETHODIMP CPromptService::Select(nsIDOMWindow *parent, const PRUnichar *dialogTitle,
const PRUnichar *text, PRUint32 count,
const PRUnichar **selectList, PRInt32 *outSelection,
PRBool *_retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}

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

@ -1,57 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* 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 Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef __PromptService_h
#define __PromptService_h
#include "nsIPromptService.h"
//*****************************************************************************
// CPromptService
//*****************************************************************************
class CPromptService: public nsIPromptService
{
public:
CPromptService();
virtual ~CPromptService();
NS_DECL_ISUPPORTS
NS_DECL_NSIPROMPTSERVICE
};
#endif

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

@ -1,275 +0,0 @@
#include <Navigation.h>
#include "CHeaderSniffer.h" // for ESaveFormat, which needs a better home.
#include "UCustomNavServicesDialogs.h"
const ResIDT kCustomSaveFilePanelDITLResID = 1550;
const Rect kCustomSaveFilePanelSize = {0, 0, 48, 248};
enum
{
eSaveFormatPanelStaticTextID = 1,
eSaveFormatPanelFormatPopupID
};
// ---------------------------------------------------------------------------
// ¥ CNavCallbackData
// ---------------------------------------------------------------------------
// generic callback data for any Nav Services extension
class CNavCallbackData
{
public:
CNavCallbackData(const Rect& inPanelRect, ResIDT inPanelResID)
: mPanelRect(inPanelRect)
, mLastTryWidth(0)
, mLastTryHeight(0)
, mResource('DITL', inPanelResID, false /* don't throw */, false /* all res files */)
, mFirstControlID(0)
{
}
virtual ~CNavCallbackData()
{
}
Handle GetDITLHandle() { return mResource.Get(); }
void SetFirstControlID(short inFirstID) { mFirstControlID = inFirstID; }
short GetFirstControlID() { return mFirstControlID; }; // only valid after the NavCustomControl call
virtual void NegotiatePanelBounds(NavCBRecPtr inNavCallbackData);
virtual void InitControls(NavCBRecPtr inNavCallbackData) = 0;
virtual void SaveControlValues(NavCBRecPtr inNavCallbackData) = 0;
protected:
Rect mPanelRect;
short mLastTryWidth; // used during panel bounds negotiation
short mLastTryHeight; // used during panel bounds negotiation
StResource mResource;
short mFirstControlID;
};
// ---------------------------------------------------------------------------
// ¥ NegotiatePanelBounds
// ---------------------------------------------------------------------------
void CNavCallbackData::NegotiatePanelBounds(NavCBRecPtr inNavCallbackData)
{
Rect& offeredRect = inNavCallbackData->customRect;
short neededWidth = offeredRect.left + (mPanelRect.right - mPanelRect.left);
short neededHeight = offeredRect.top + (mPanelRect.bottom - mPanelRect.top);
// first round of negotiations
if (offeredRect.right == 0 && offeredRect.bottom == 0)
{
// just tell it what dimensions we want
offeredRect.right = neededWidth;
offeredRect.bottom = neededHeight;
}
else
{
// we are in the middle of negotiating
if (mLastTryWidth != offeredRect.right)
if (offeredRect.right < neededWidth)
offeredRect.right = neededWidth;
if (mLastTryHeight != offeredRect.bottom)
if (offeredRect.bottom < neededHeight)
offeredRect.bottom = neededHeight;
mLastTryWidth = offeredRect.right;
mLastTryHeight = offeredRect.bottom;
}
}
#pragma mark -
// ---------------------------------------------------------------------------
// ¥ CNavCustomPutFileCallbackData
// ---------------------------------------------------------------------------
// callback data specific to our file saving dialog
class CNavCustomPutFileCallbackData : public CNavCallbackData
{
public:
CNavCustomPutFileCallbackData(const Rect& inPanelRect, ResIDT inPanelResID, ESaveFormat inDefaultSaveFormat)
: CNavCallbackData(inPanelRect, inPanelResID)
, mSaveFormat(inDefaultSaveFormat)
, mSaveFormatPopupControl(nil)
{
if (mSaveFormat == eSaveFormatUnspecified)
mSaveFormat = eSaveFormatHTML;
}
virtual ~CNavCustomPutFileCallbackData()
{
}
virtual void InitControls(NavCBRecPtr inNavCallbackData);
virtual void SaveControlValues(NavCBRecPtr inNavCallbackData);
ESaveFormat GetSaveFormat() { return mSaveFormat; }
protected:
ESaveFormat mSaveFormat;
ControlHandle mSaveFormatPopupControl;
};
void CNavCustomPutFileCallbackData::InitControls(NavCBRecPtr inNavCallbackData)
{
OSErr err = ::GetDialogItemAsControl(::GetDialogFromWindow(inNavCallbackData->window), mFirstControlID + eSaveFormatPanelFormatPopupID, &mSaveFormatPopupControl);
ThrowIfOSErr_(err);
::SetControlValue(mSaveFormatPopupControl, (SInt32)mSaveFormat);
}
void CNavCustomPutFileCallbackData::SaveControlValues(NavCBRecPtr inNavCallbackData)
{
if (mSaveFormatPopupControl)
mSaveFormat = (ESaveFormat)::GetControlValue(mSaveFormatPopupControl);
}
#pragma mark -
// ---------------------------------------------------------------------------
// ¥ NavEventProc [static]
// ---------------------------------------------------------------------------
// Event filter callback routine for Navigation Services
pascal void
UNavServicesDialogs::NavCustomEventProc(
NavEventCallbackMessage inSelector,
NavCBRecPtr ioParams,
NavCallBackUserData ioUserData)
{
CNavCustomPutFileCallbackData *callbackData = reinterpret_cast<CNavCustomPutFileCallbackData*>(ioUserData);
OSErr err = noErr;
try // Can't throw back through the Toolbox
{
switch (inSelector)
{
case kNavCBStart:
if (callbackData)
{
err = ::NavCustomControl(ioParams->context, kNavCtlAddControlList, callbackData->GetDITLHandle());
ThrowIfOSErr_(err);
short firstControlID;
err = ::NavCustomControl(ioParams->context, kNavCtlGetFirstControlID, &firstControlID);
ThrowIfOSErr_(err);
callbackData->SetFirstControlID(firstControlID);
callbackData->InitControls(ioParams);
}
break;
case kNavCBCustomize:
if (callbackData)
{
callbackData->NegotiatePanelBounds(ioParams);
}
break;
case kNavCBTerminate:
if (callbackData)
{
callbackData->SaveControlValues(ioParams);
}
break;
case kNavCBEvent:
{
short itemHit = ioParams->eventData.itemHit;
if (itemHit == eSaveFormatPanelFormatPopupID)
{
// process control click?
break;
}
UModalAlerts::ProcessModalEvent(*(ioParams->eventData.eventDataParms.event));
}
break;
}
}
catch (...)
{
Assert_(0); // error
}
}
// ---------------------------------------------------------------------------
// ¥ LCustomFileDesignator
// ---------------------------------------------------------------------------
UNavServicesDialogs::LCustomFileDesignator::LCustomFileDesignator()
{
}
// ---------------------------------------------------------------------------
// ¥ ~LCustomFileDesignator
// ---------------------------------------------------------------------------
UNavServicesDialogs::LCustomFileDesignator::~LCustomFileDesignator()
{
}
// ---------------------------------------------------------------------------
// ¥ LCustomFileDesignator::AskDesignateFile [public]
// ---------------------------------------------------------------------------
bool
UNavServicesDialogs::LCustomFileDesignator::AskDesignateFile(ConstStringPtr inDefaultName, ESaveFormat& ioSaveFormat)
{
StNavEventUPP eventUPP(NavCustomEventProc);
CNavCustomPutFileCallbackData callbackData(kCustomSaveFilePanelSize, kCustomSaveFilePanelDITLResID, ioSaveFormat);
LString::CopyPStr(inDefaultName, mNavOptions.savedFileName);
mNavReply.SetDefaultValues();
AEDesc* defaultLocationDesc = nil;
if (not mDefaultLocation.IsNull()) {
defaultLocationDesc = mDefaultLocation;
if (mSelectDefault) {
mNavOptions.dialogOptionFlags |= kNavSelectDefaultLocation;
} else {
mNavOptions.dialogOptionFlags &= ~kNavSelectDefaultLocation;
}
}
UDesktop::Deactivate();
OSErr err = ::NavPutFile(
defaultLocationDesc,
mNavReply,
&mNavOptions,
eventUPP,
mFileType,
mFileCreator,
&callbackData);
UDesktop::Activate();
if ( (err != noErr) && (err != userCanceledErr) ) {
Throw_(err);
}
ioSaveFormat = callbackData.GetSaveFormat();
return mNavReply.IsValid();
}

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

@ -1,26 +0,0 @@
#pragma once
#include "UNavServicesDialogs.h"
namespace UNavServicesDialogs {
pascal void NavCustomEventProc(
NavEventCallbackMessage inSelector,
NavCBRecPtr ioParams,
NavCallBackUserData ioUserData);
class LCustomFileDesignator : public LFileDesignator
{
public:
LCustomFileDesignator();
~LCustomFileDesignator();
bool AskDesignateFile(ConstStringPtr inDefaultName, ESaveFormat& ioSaveFormat);
};
}

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

@ -1,334 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* 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 mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Conrad Carlen <ccarlen@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "UDownload.h"
#include "nsIExternalHelperAppService.h"
#include "nsILocalFIleMac.h"
#include "nsDirectoryServiceDefs.h"
#include "nsDirectoryServiceUtils.h"
#include "nsIRequest.h"
#include "netCore.h"
#include "UDownloadDisplay.h"
#include "UMacUnicode.h"
#include "UNavServicesDialogs.h"
//*****************************************************************************
// CDownload
//*****************************************************************************
#pragma mark [CDownload]
ADownloadProgressView *CDownload::sProgressView;
CDownload::CDownload() :
mGotFirstStateChange(false), mIsNetworkTransfer(false),
mUserCanceled(false),
mStatus(NS_OK)
{
}
CDownload::~CDownload()
{
}
NS_IMPL_ISUPPORTS4(CDownload, nsIDownload, nsITransfer,
nsIWebProgressListener, nsIWebProgressListener2)
#pragma mark -
#pragma mark [CDownload::nsIDownload]
/* void init (in nsIURI aSource, in nsILocalFile aTarget, in wstring aDisplayName, in nsIMIMEInfo aMIMEInfo, in long long startTime, in nsILocalFile aTempFile, in nsICancelable aCancelable); */
NS_IMETHODIMP CDownload::Init(nsIURI *aSource, nsILocalFile *aTarget,
const PRUnichar *aDisplayName, nsIMIMEInfo *aMIMEInfo, PRInt64 startTime,
nsILocalFile* aTempFile, nsICancelable* aCancelable)
{
try {
mSource = aSource;
mDestination = aTarget;
mStartTime = startTime;
mPercentComplete = 0;
// We have to break this circular ref when the download is done
mCancelable = aCancelable;
EnsureProgressView();
sProgressView->AddDownloadItem(this);
}
catch (...) {
return NS_ERROR_FAILURE;
}
return NS_OK;
}
/* readonly attribute nsIURI source; */
NS_IMETHODIMP CDownload::GetSource(nsIURI * *aSource)
{
NS_ENSURE_ARG_POINTER(aSource);
NS_IF_ADDREF(*aSource = mSource);
return NS_OK;
}
/* readonly attribute nsILocalFile target; */
NS_IMETHODIMP CDownload::GetTarget(nsILocalFile * *aTarget)
{
NS_ENSURE_ARG_POINTER(aTarget);
NS_IF_ADDREF(*aTarget = mDestination);
return NS_OK;
}
/* readonly attribute nsICancelable cancelable; */
NS_IMETHODIMP CDownload::GetCancelable(nsIWebBrowserCancelable * *aCancelable)
{
NS_ENSURE_ARG_POINTER(aCancelable);
NS_IF_ADDREF(*aCancelable = mCancelable);
return NS_OK;
}
/* readonly attribute PRInt32 percentComplete; */
NS_IMETHODIMP CDownload::GetPercentComplete(PRInt32 *aPercentComplete)
{
NS_ENSURE_ARG_POINTER(aPercentComplete);
*aPercentComplete = mPercentComplete;
return NS_OK;
}
/* attribute wstring displayName; */
NS_IMETHODIMP CDownload::GetDisplayName(PRUnichar * *aDisplayName)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* readonly attribute long long startTime; */
NS_IMETHODIMP CDownload::GetStartTime(PRInt64 *aStartTime)
{
NS_ENSURE_ARG_POINTER(aStartTime);
*aStartTime = mStartTime;
return NS_OK;
}
/* readonly attribute double speed; */
NS_IMETHODIMP CDownload::GetSpeed(double *aSpeed)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* readonly attribute nsIMIMEInfo MIMEInfo; */
NS_IMETHODIMP CDownload::GetMIMEInfo(nsIMIMEInfo * *aMIMEInfo)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
#pragma mark -
#pragma mark [CDownload::nsIWebProgressListener]
/* void onStateChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in unsigned long aStateFlags, in nsresult aStatus); */
NS_IMETHODIMP CDownload::OnStateChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRUint32 aStateFlags, nsresult aStatus)
{
// For a file download via the external helper app service, we will never get a start
// notification. The helper app service has gotten that notification before it created us.
if (!mGotFirstStateChange) {
mIsNetworkTransfer = ((aStateFlags & STATE_IS_NETWORK) != 0);
mGotFirstStateChange = PR_TRUE;
BroadcastMessage(msg_OnDLStart, this);
}
if (NS_FAILED(aStatus) && NS_SUCCEEDED(mStatus))
mStatus = aStatus;
// We will get this even in the event of a cancel,
if ((aStateFlags & STATE_STOP) && (!mIsNetworkTransfer || (aStateFlags & STATE_IS_NETWORK))) {
mCancelable = nsnull;
BroadcastMessage(msg_OnDLComplete, this);
}
return NS_OK;
}
/* void onProgressChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long aCurSelfProgress, in long aMaxSelfProgress, in long aCurTotalProgress, in long aMaxTotalProgress); */
NS_IMETHODIMP CDownload::OnProgressChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRInt32 aCurSelfProgress, PRInt32 aMaxSelfProgress, PRInt32 aCurTotalProgress, PRInt32 aMaxTotalProgress)
{
if (mUserCanceled) {
mCancelable->Cancel(NS_BINDING_ABORTED);
mUserCanceled = false;
}
if (aMaxTotalProgress == -1)
mPercentComplete = -1;
else
mPercentComplete = (PRInt32)(((float)aCurTotalProgress / (float)aMaxTotalProgress) * 100.0 + 0.5);
MsgOnDLProgressChangeInfo info(this, aCurTotalProgress, aMaxTotalProgress);
BroadcastMessage(msg_OnDLProgressChange, &info);
return NS_OK;
}
/* void onProgressChange64 (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long long aCurSelfProgress, in long long aMaxSelfProgress, in long long aCurTotalProgress, in long long aMaxTotalProgress); */
NS_IMETHODIMP CDownload::OnProgressChange64(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRInt64 aCurSelfProgress, PRInt64 aMaxSelfProgress, PRInt64 aCurTotalProgress, PRInt64 aMaxTotalProgress)
{
// XXX truncates 64-bit to 32-bit
return OnProgressChange(aProgress, aRequest,
PRInt32(curSelfProgress), PRInt32(maxSelfProgress),
PRInt32(curTotalProgress), PRInt32(maxTotalProgress));
}
/* void onLocationChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsIURI location); */
NS_IMETHODIMP CDownload::OnLocationChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, nsIURI *location)
{
return NS_OK;
}
/* void onStatusChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsresult aStatus, in wstring aMessage); */
NS_IMETHODIMP CDownload::OnStatusChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, nsresult aStatus, const PRUnichar *aMessage)
{
return NS_OK;
}
/* void onSecurityChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in unsigned long state); */
NS_IMETHODIMP CDownload::OnSecurityChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRUint32 state)
{
return NS_OK;
}
/* boolean onRefreshAttempted (in nsIWebProgress aWebProgress, in nsIURI aRefreshURI, in long aDelay, in boolean aSameURI); */
NS_IMETHODIMP CDownload::OnRefreshAttempted(nsIWebProgress *aWebProgress, nsIURI *aUri, PRInt32 aDelay, PRBool aSameUri, PRBool *allowRefresh)
{
*allowRefresh = PR_TRUE;
return NS_OK;
}
#pragma mark -
#pragma mark [CDownload Internal Methods]
void CDownload::Cancel()
{
mUserCanceled = true;
// nsWebBrowserPersist does the right thing: After canceling, next time through
// OnStateChange(), aStatus != NS_OK. This isn't the case with nsExternalHelperAppService.
mStatus = NS_ERROR_ABORT;
}
void CDownload::CreateProgressView()
{
sProgressView = new CMultiDownloadProgress;
ThrowIfNil_(sProgressView);
}
//*****************************************************************************
// CHelperAppLauncherDialog
//*****************************************************************************
#pragma mark -
#pragma mark [CHelperAppLauncherDialog]
CHelperAppLauncherDialog::CHelperAppLauncherDialog()
{
}
CHelperAppLauncherDialog::~CHelperAppLauncherDialog()
{
}
NS_IMPL_ISUPPORTS1(CHelperAppLauncherDialog, nsIHelperAppLauncherDialog)
/* void show (in nsIHelperAppLauncher aLauncher, in nsISupports aContext, in unsigned long aReason); */
NS_IMETHODIMP CHelperAppLauncherDialog::Show(nsIHelperAppLauncher *aLauncher, nsISupports *aContext, PRUint32 aReason)
{
return aLauncher->SaveToDisk(nsnull, PR_FALSE);
}
/* nsILocalFile promptForSaveToFile (in nsIHelperAppLauncher aLauncher, in nsISupports aWindowContext, in wstring aDefaultFile, in wstring aSuggestedFileExtension); */
NS_IMETHODIMP CHelperAppLauncherDialog::PromptForSaveToFile(nsIHelperAppLauncher* aLauncher,
nsISupports *aWindowContext,
const PRUnichar *aDefaultFile,
const PRUnichar *aSuggestedFileExtension,
nsILocalFile **_retval)
{
NS_ENSURE_ARG_POINTER(_retval);
*_retval = nsnull;
static bool sFirstTime = true;
UNavServicesDialogs::LFileDesignator designator;
if (sFirstTime) {
// Get the default download folder and point Nav Sevices to it.
nsCOMPtr<nsIFile> defaultDownloadDir;
NS_GetSpecialDirectory(NS_MAC_DEFAULT_DOWNLOAD_DIR, getter_AddRefs(defaultDownloadDir));
if (defaultDownloadDir) {
nsCOMPtr<nsILocalFileMac> macDir(do_QueryInterface(defaultDownloadDir));
FSSpec defaultDownloadSpec;
if (NS_SUCCEEDED(macDir->GetFSSpec(&defaultDownloadSpec)))
designator.SetDefaultLocation(defaultDownloadSpec, true);
}
sFirstTime = false;
}
Str255 defaultName;
CPlatformUCSConversion::GetInstance()->UCSToPlatform(nsDependentString(aDefaultFile), defaultName);
bool result = designator.AskDesignateFile(defaultName);
// After the dialog is dismissed, process all activation an update events right away.
// The save dialog code calls UDesktop::Activate after dismissing the dialog. All that
// does is activate the now frontmost LWindow which was behind the dialog. It does not
// remove the activate event from the queue. If that event is not processed and removed
// before we show the progress window, bad things happen. Specifically, the progress
// dialog will show in front and then, shortly thereafter, the window which was behind this save
// dialog will be moved to the front.
if (LEventDispatcher::GetCurrentEventDispatcher()) { // Can this ever be NULL?
EventRecord theEvent;
while (::WaitNextEvent(updateMask | activMask, &theEvent, 0, nil))
LEventDispatcher::GetCurrentEventDispatcher()->DispatchEvent(theEvent);
}
if (result) {
FSSpec destSpec;
designator.GetFileSpec(destSpec);
nsCOMPtr<nsILocalFileMac> destFile;
NS_NewLocalFileWithFSSpec(&destSpec, PR_TRUE, getter_AddRefs(destFile));
if (!destFile)
return NS_ERROR_FAILURE;
*_retval = destFile;
NS_ADDREF(*_retval);
return NS_OK;
}
else
return NS_ERROR_ABORT;
}

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

@ -1,170 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* 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 mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Conrad Carlen <ccarlen@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef UDownload_h__
#define UDownload_h__
#pragma once
#include "nsIDownload.h"
#include "nsIWebProgressListener.h"
#include "nsIHelperAppLauncherDialog.h"
#include "nsIExternalHelperAppService.h"
#include "nsIURI.h"
#include "nsILocalFile.h"
#include "nsIWebBrowserPersist.h"
class ADownloadProgressView;
//*****************************************************************************
// CDownload
//
// Holds information used to display a single download in the UI. This object is
// created in one of two ways:
// (1) By nsExternalHelperAppHandler when Gecko encounters a MIME type which
// it doesn't itself handle. In this case, the notifications sent to
// nsIDownload are controlled by nsExternalHelperAppHandler.
// (2) By the embedding app's file saving code when saving a web page or a link
// target. See CHeaderSniffer.cpp. In this case, the notifications sent to
// nsIDownload are controlled by the implementation of nsIWebBrowserPersist.
//*****************************************************************************
class CDownload : public nsIDownload,
public nsIWebProgressListener,
public LBroadcaster
{
public:
// Messages we broadcast to listeners.
enum {
msg_OnDLStart = 57723, // param is CDownload*
msg_OnDLComplete, // param is CDownload*
msg_OnDLProgressChange // param is MsgOnDLProgressChangeInfo*
};
struct MsgOnDLProgressChangeInfo
{
MsgOnDLProgressChangeInfo(CDownload* broadcaster, PRInt32 curProgress, PRInt32 maxProgress) :
mBroadcaster(broadcaster), mCurProgress(curProgress), mMaxProgress(maxProgress)
{ }
CDownload *mBroadcaster;
PRInt32 mCurProgress, mMaxProgress;
};
CDownload();
virtual ~CDownload();
NS_DECL_ISUPPORTS
NS_DECL_NSIDOWNLOAD
NS_DECL_NSIWEBPROGRESSLISTENER
virtual void Cancel();
virtual void GetStatus(nsresult& aStatus)
{ aStatus = mStatus; }
protected:
void EnsureProgressView()
{
if (!sProgressView)
CreateProgressView();
}
virtual void CreateProgressView();
// sProgressView is a singleton. This will only be called once.
protected:
nsCOMPtr<nsIURI> mSource;
nsCOMPtr<nsILocalFile> mDestination;
PRInt64 mStartTime;
PRInt32 mPercentComplete;
bool mGotFirstStateChange, mIsNetworkTransfer;
bool mUserCanceled;
nsresult mStatus;
nsCOMPtr<nsICancelable> mCancelable;
static ADownloadProgressView *sProgressView;
};
//*****************************************************************************
// CHelperAppLauncherDialog
//
// The implementation of nsIExternalHelperAppService in Gecko creates one of
// these at the beginning of the download and calls its Show() method. Typically,
// this will create a non-modal dialog in which the user can decide whether to
// save the file to disk or open it with an application. This implementation
// just saves the file to disk unconditionally. The user can decide what they
// wish to do with the download from the progress dialog.
//*****************************************************************************
class CHelperAppLauncherDialog : public nsIHelperAppLauncherDialog
{
public:
CHelperAppLauncherDialog();
virtual ~CHelperAppLauncherDialog();
NS_DECL_ISUPPORTS
NS_DECL_NSIHELPERAPPLAUNCHERDIALOG
protected:
};
//*****************************************************************************
// ADownloadProgressView
//
// An abstract class which handles the display and interaction with a download.
// Typically, it presents a progress dialog.
//*****************************************************************************
class ADownloadProgressView
{
friend class CDownload;
virtual void AddDownloadItem(CDownload *aDownloadItem) = 0;
// A download is beginning. Initialize the UI for this download.
// Throughout the download process, the CDownload will broadcast
// status messages. The UI needs to call LBroadcaster::AddListener()
// on the CDownload at this point in order to get the messages.
};
#endif // UDownload_h__

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

@ -1,615 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* 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 mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Conrad Carlen <ccarlen@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "UDownloadDisplay.h"
#include "ApplIDs.h"
#include "CIconServicesIcon.h"
// Gecko
#include "nsString.h"
#include "nsILocalFileMac.h"
// Std
#include <algorithm>
using namespace std;
// PowerPlant
#include <LStaticText.h>
#include <LProgressBar.h>
//*****************************************************************************
// CMultiDownloadProgress
//*****************************************************************************
#pragma mark [CMultiDownloadProgress]
bool CMultiDownloadProgress::sRegisteredViewClasses = false;
CMultiDownloadProgress::CMultiDownloadProgress() :
mWindow(nil)
{
if (!sRegisteredViewClasses) {
RegisterClass_(CMultiDownloadProgressWindow);
RegisterClass_(CDownloadProgressView);
RegisterClass_(CIconServicesIcon);
sRegisteredViewClasses = true;
}
}
CMultiDownloadProgress::~CMultiDownloadProgress()
{
}
void CMultiDownloadProgress::AddDownloadItem(CDownload *aDownloadItem)
{
if (!mWindow) {
mWindow = static_cast<CMultiDownloadProgressWindow*>
(LWindow::CreateWindow(wind_DownloadProgress, this));
ThrowIfNil_(mWindow);
// Add this as a listener to the window so we can know when it's destroyed.
mWindow->AddListener(this);
}
// Create the view...
LView::SetDefaultView(mWindow);
LCommander::SetDefaultCommander(mWindow);
LAttachable::SetDefaultAttachable(nil);
CDownloadProgressView *itemView = static_cast<CDownloadProgressView*>
(UReanimator::ReadObjects(ResType_PPob, view_DownloadProgressItem));
ThrowIfNil_(itemView);
// and add it to the window.
mWindow->AddDownloadView(itemView);
itemView->SetDownload(aDownloadItem);
}
// This happens in response to the window being closed. Check for active
// downloads and confirm stopping them if there are any. Returning false
// will prevent the window from being closed.
Boolean CMultiDownloadProgress::AllowSubRemoval(LCommander* inSub)
{
return (!mWindow || (inSub == mWindow && mWindow->ConfirmClose()));
}
// This happens in response to the app being quit. Check for active
// downloads and confirm stopping them if there are any. Returning
// false will prevent the app from quitting.
Boolean CMultiDownloadProgress::AttemptQuitSelf(SInt32 inSaveOption)
{
return (!mWindow || mWindow->ConfirmClose());
}
void CMultiDownloadProgress::ListenToMessage(MessageT inMessage,
void* ioParam)
{
if (inMessage == msg_BroadcasterDied &&
(CMultiDownloadProgressWindow*)((LBroadcaster*)ioParam) == mWindow)
mWindow = nil;
}
//*****************************************************************************
// CMultiDownloadProgressWindow
//*****************************************************************************
#pragma mark -
#pragma mark [CMultiDownloadProgressWindow]
CMultiDownloadProgressWindow::CMultiDownloadProgressWindow() :
mDownloadViewCount(0)
{
StartBroadcasting();
}
CMultiDownloadProgressWindow::CMultiDownloadProgressWindow(LStream* inStream) :
LWindow(inStream),
mDownloadViewCount(0)
{
StartBroadcasting();
}
CMultiDownloadProgressWindow::~CMultiDownloadProgressWindow()
{
}
void CMultiDownloadProgressWindow::AddDownloadView(CDownloadProgressView *aView)
{
const SInt16 kSeparatorHeight = 3;
SDimension16 currSize;
GetFrameSize(currSize);
SDimension16 viewSize;
aView->GetFrameSize(viewSize);
ResizeWindowTo(currSize.width, (viewSize.height * (mDownloadViewCount + 1)) - kSeparatorHeight);
aView->PlaceInSuperFrameAt(0, viewSize.height * mDownloadViewCount++, false);
aView->FinishCreate();
}
void CMultiDownloadProgressWindow::RemoveDownloadView(CDownloadProgressView *aView)
{
// We can't remove the last view, leaving an empty window frame
if (mDownloadViewCount <= 1)
return;
SDimension16 removedPaneSize;
aView->GetFrameSize(removedPaneSize);
SPoint32 removedPaneLoc;
aView->GetFrameLocation(removedPaneLoc);
delete aView;
RemoveSubPane(aView);
mDownloadViewCount--;
TArrayIterator<LPane*> iterator(GetSubPanes());
LPane *subPane;
while (iterator.Next(subPane)) {
SPoint32 subPaneLoc;
subPane->GetFrameLocation(subPaneLoc);
if (subPaneLoc.v >= removedPaneLoc.v + removedPaneSize.height) {
subPane->MoveBy(0, -removedPaneSize.height, true);
}
}
ResizeWindowBy(0, -removedPaneSize.height);
}
Boolean CMultiDownloadProgressWindow::ConfirmClose()
{
Boolean canClose = true;
SInt32 numActiveDownloads = 0;
TArrayIterator<LPane*> iterator(GetSubPanes());
LPane *subPane;
while (iterator.Next(subPane)) {
CDownloadProgressView *downloadView = dynamic_cast<CDownloadProgressView*>(subPane);
if (downloadView && downloadView->IsActive())
numActiveDownloads++;
}
if (numActiveDownloads != 0) {
short itemHit;
AlertStdAlertParamRec pb;
pb.movable = false;
pb.helpButton = false;
pb.filterProc = nil;
pb.defaultText = (StringPtr) kAlertDefaultOKText;
pb.cancelText = (StringPtr) kAlertDefaultCancelText;
pb.otherText = nil;
pb.defaultButton = kStdOkItemIndex;
pb.cancelButton = kStdCancelItemIndex;
pb.position = kWindowAlertPositionParentWindowScreen;
LStr255 msgString(STRx_StdAlertStrings, str_ConfirmCloseDownloads);
LStr255 explainString(STRx_StdAlertStrings, str_ConfirmCloseDownloadsExp);
::StandardAlert(kAlertStopAlert, msgString, explainString, &pb, &itemHit);
if (itemHit != kAlertStdAlertOKButton)
canClose = false;
}
return canClose;
}
//*****************************************************************************
// CDownloadProgressView
//*****************************************************************************
#pragma mark -
#pragma mark [CDownloadProgressView]
enum {
paneID_ProgressBar = 'Prog',
paneID_CancelButton = 'Cncl',
paneID_OpenButton = 'Open',
paneID_RevealButton = 'Rvel',
paneID_CloseButton = 'Clos',
paneID_StatusText = 'Stat',
paneID_StatusLabel = 'StLa',
paneID_TimeRemText = 'Time',
paneID_TimeRemLabel = 'TiLa',
paneID_SrcURIText = 'SURI',
paneID_SrcURILabel = 'SULa',
paneID_DestFileText = 'Dest',
paneID_DestFileLabel = 'DFLa'
};
CDownloadProgressView::CDownloadProgressView() :
mDownloadActive(false)
{
}
CDownloadProgressView::CDownloadProgressView(LStream* inStream) :
LView(inStream),
mDownloadActive(false)
{
}
CDownloadProgressView::~CDownloadProgressView()
{
if (mDownloadActive)
CancelDownload();
mDownload = nsnull;
}
void CDownloadProgressView::FinishCreateSelf()
{
mProgressBar = dynamic_cast<LProgressBar*>(FindPaneByID(paneID_ProgressBar));
mCancelButton = dynamic_cast<LControl*>(FindPaneByID(paneID_CancelButton));
mOpenButton = dynamic_cast<LControl*>(FindPaneByID(paneID_OpenButton));
mRevealButton = dynamic_cast<LControl*>(FindPaneByID(paneID_RevealButton));
mCloseButton = dynamic_cast<LControl*>(FindPaneByID(paneID_CloseButton));
mStatusText = dynamic_cast<LStaticText*>(FindPaneByID(paneID_StatusText));
mTimeRemainingText = dynamic_cast<LStaticText*>(FindPaneByID(paneID_TimeRemText));
mSrcURIText = dynamic_cast<LStaticText*>(FindPaneByID(paneID_SrcURIText));
mDestFileText = dynamic_cast<LStaticText*>(FindPaneByID(paneID_DestFileText));
// The control value is set in terms of percent
if (mProgressBar)
mProgressBar->SetMaxValue(100);
ControlFontStyleRec styleRec;
if (CreateStyleRecFromThemeFont(kThemeSmallSystemFont, styleRec) == noErr) {
if (mStatusText)
mStatusText->SetFontStyle(styleRec);
if (mTimeRemainingText)
mTimeRemainingText->SetFontStyle(styleRec);
if (mSrcURIText)
mSrcURIText->SetFontStyle(styleRec);
if (mDestFileText)
mDestFileText->SetFontStyle(styleRec);
}
if (CreateStyleRecFromThemeFont(kThemeSmallEmphasizedSystemFont, styleRec) == noErr) {
ResIDT labelIDs [] = { paneID_StatusLabel,
paneID_TimeRemLabel,
paneID_SrcURILabel,
paneID_DestFileLabel };
for (size_t i = 0; i < sizeof(labelIDs) / sizeof(labelIDs[0]); i++) {
LStaticText *staticText = dynamic_cast<LStaticText*>(FindPaneByID(labelIDs[i]));
if (staticText)
staticText->SetFontStyle(styleRec);
}
}
UReanimator::LinkListenerToControls(this, this, view_DownloadProgressItem);
StartListening();
}
Boolean CDownloadProgressView::ObeyCommand(CommandT inCommand,
void *ioParam)
{
#pragma unused(ioParam)
Boolean cmdHandled = false;
nsCOMPtr<nsILocalFile> targetFile;
switch (inCommand)
{
case paneID_CancelButton:
{
CancelDownload();
cmdHandled = true;
}
break;
case paneID_OpenButton:
{
mDownload->GetTarget(getter_AddRefs(targetFile));
if (targetFile)
targetFile->Launch();
}
break;
case paneID_RevealButton:
{
mDownload->GetTarget(getter_AddRefs(targetFile));
if (targetFile)
targetFile->Reveal();
}
break;
case paneID_CloseButton:
{
LView *view = this, *superView;
while ((superView = view->GetSuperView()) != nil)
view = superView;
CMultiDownloadProgressWindow *multiWindow = dynamic_cast<CMultiDownloadProgressWindow*>(view);
if (multiWindow)
multiWindow->RemoveDownloadView(this);
}
break;
}
return cmdHandled;
}
void CDownloadProgressView::ListenToMessage(MessageT inMessage,
void* ioParam)
{
switch (inMessage) {
case CDownload::msg_OnDLStart:
{
mDownloadActive = true;
if (mCancelButton)
mCancelButton->Enable();
}
break;
case CDownload::msg_OnDLComplete:
{
mDownloadActive = false;
if (mCancelButton)
mCancelButton->Disable();
if (mCloseButton)
mCloseButton->Enable();
CDownload *download = reinterpret_cast<CDownload*>(ioParam);
nsresult downloadStatus;
download->GetStatus(downloadStatus);
// When saving documents as plain text, we might not get any
// progress change notifications in which to set the progress bar.
// Now that the download is done, put the bar in a reasonable state.
if (mProgressBar) {
mProgressBar->SetIndeterminateFlag(false, false);
if (NS_SUCCEEDED(downloadStatus))
mProgressBar->SetValue(mProgressBar->GetMaxValue());
else
mProgressBar->SetValue(0);
}
if (NS_SUCCEEDED(downloadStatus)) {
if (mOpenButton)
mOpenButton->Enable();
}
if (mRevealButton)
mRevealButton->Enable();
if (mTimeRemainingText)
mTimeRemainingText->SetText(LStr255("\p"));
}
break;
case CDownload::msg_OnDLProgressChange:
{
CDownload::MsgOnDLProgressChangeInfo *info =
static_cast<CDownload::MsgOnDLProgressChangeInfo*>(ioParam);
if (mProgressBar) {
PRInt32 percentComplete;
info->mBroadcaster->GetPercentComplete(&percentComplete);
if (percentComplete != -1 && mProgressBar->IsIndeterminate())
mProgressBar->SetIndeterminateFlag(false, false);
else if (percentComplete == -1 && !mProgressBar->IsIndeterminate())
mProgressBar->SetIndeterminateFlag(true, true);
if (!mProgressBar->IsIndeterminate()) {
PRInt32 controlVal = min(100, max(0, percentComplete));
mProgressBar->SetValue(controlVal);
}
}
// Set the progress bar as often as we're called. Smooth movement is nice.
// Limit the frequency at which the textual status is updated though.
if (info->mCurProgress == info->mMaxProgress ||
::TickCount() - mLastStatusUpdateTicks >= kStatusUpdateIntervalTicks) {
UpdateStatus(info);
mLastStatusUpdateTicks = ::TickCount();
}
}
break;
default:
ProcessCommand(inMessage, ioParam);
break;
}
}
void CDownloadProgressView::SetDownload(CDownload *aDownload)
{
mDownload = aDownload;
if (!mDownload)
return;
mDownloadActive = true;
mLastStatusUpdateTicks = ::TickCount();
aDownload->AddListener(this);
nsresult rv;
nsCAutoString tempStr;
if (mSrcURIText) {
nsCOMPtr<nsIURI> srcURI;
aDownload->GetSource(getter_AddRefs(srcURI));
if (srcURI) {
rv = srcURI->GetSpec(tempStr);
if (NS_SUCCEEDED(rv))
mSrcURIText->SetText(const_cast<Ptr>(PromiseFlatCString(tempStr).get()), tempStr.Length());
}
}
if (mDestFileText) {
nsCOMPtr<nsILocalFile> destFile;
aDownload->GetTarget(getter_AddRefs(destFile));
if (destFile) {
rv = destFile->GetNativePath(tempStr);
if (NS_SUCCEEDED(rv))
mDestFileText->SetText(const_cast<Ptr>(PromiseFlatCString(tempStr).get()), tempStr.Length());
}
}
// At this point, make sure our window is showing.
LWindow::FetchWindowObject(GetMacWindow())->Show();
}
void CDownloadProgressView::CancelDownload()
{
CDownload *download = dynamic_cast<CDownload*>(mDownload.get());
download->Cancel();
}
Boolean CDownloadProgressView::IsActive()
{
return mDownloadActive;
}
void CDownloadProgressView::UpdateStatus(CDownload::MsgOnDLProgressChangeInfo *info)
{
PRInt64 startTime;
mDownload->GetStartTime(&startTime);
PRInt32 elapsedSecs = (PR_Now() - startTime) / PR_USEC_PER_SEC;
float bytesPerSec = info->mCurProgress / elapsedSecs;
UInt8 startPos;
LStr255 valueStr;
if (mStatusText) {
// "@1 of @2 (at @3/sec)"
LStr255 formatStr(STRx_DownloadStatus, str_ProgressFormat);
// Insert each item into the string individually in order to
// allow certain elements to be omitted from the format.
if ((startPos = formatStr.Find("\p@1")) != 0)
formatStr.Replace(startPos, 2, FormatBytes(info->mCurProgress, valueStr));
if ((startPos = formatStr.Find("\p@2")) != 0)
formatStr.Replace(startPos, 2, FormatBytes(info->mMaxProgress, valueStr));
if ((startPos = formatStr.Find("\p@3")) != 0)
formatStr.Replace(startPos, 2, FormatBytes(bytesPerSec, valueStr));
mStatusText->SetText(formatStr);
}
if (mTimeRemainingText) {
PRInt32 secsRemaining = (PRInt32)(float(info->mMaxProgress - info->mCurProgress) / bytesPerSec + 0.5);
mTimeRemainingText->SetText(FormatFuzzyTime(secsRemaining, valueStr));
}
}
LStr255& CDownloadProgressView::FormatBytes(float inBytes, LStr255& ioString)
{
const float kOneThousand24 = 1024.0;
char buf[256];
if (inBytes < 0) {
return (ioString = "???");
}
if (inBytes < kOneThousand24) {
sprintf(buf, "%.1f Bytes", inBytes);
return (ioString = buf);
}
inBytes /= kOneThousand24;
if (inBytes < 1024) {
sprintf(buf, "%.1f KB", inBytes);
return (ioString = buf);
}
inBytes /= kOneThousand24;
if (inBytes < 1024) {
sprintf(buf, "%.1f MB", inBytes);
return (ioString = buf);
}
inBytes /= kOneThousand24;
sprintf(buf, "%.2f GB", inBytes);
return (ioString = buf);
}
LStr255& CDownloadProgressView::FormatFuzzyTime(PRInt32 inSecs, LStr255& ioString)
{
char valueBuf[32];
if (inSecs < 90) {
if (inSecs < 7)
ioString.Assign(STRx_DownloadStatus, str_About5Seconds);
else if (inSecs < 13)
ioString.Assign(STRx_DownloadStatus, str_About10Seconds);
else if (inSecs < 60)
ioString.Assign(STRx_DownloadStatus, str_LessThan1Minute);
else
ioString.Assign(STRx_DownloadStatus, str_About1Minute);
return ioString;
}
inSecs = (inSecs + 30) / 60; // Round up so we don't say "About 1 minutes"
if (inSecs < 60) {
sprintf(valueBuf, "%d", inSecs);
ioString.Assign(STRx_DownloadStatus, str_AboutNMinutes);
ioString.Replace(ioString.Find("\p@1"), 2, LStr255(valueBuf));
return ioString;
}
inSecs /= 60;
if (inSecs == 1)
ioString.Assign(STRx_DownloadStatus, str_About1Hour);
else {
sprintf(valueBuf, "%d", inSecs);
ioString.Assign(STRx_DownloadStatus, str_AboutNHours);
ioString.Replace(ioString.Find("\p@1"), 2, LStr255(valueBuf));
}
return ioString;
}
OSErr CDownloadProgressView::CreateStyleRecFromThemeFont(ThemeFontID inThemeID,
ControlFontStyleRec& outStyle)
{
Str255 themeFontName;
SInt16 themeFontSize;
Style themeStyle;
SInt16 themeFontNum;
OSErr err = ::GetThemeFont(kThemeSmallSystemFont,
smSystemScript,
themeFontName,
&themeFontSize,
&themeStyle);
if (err != noErr)
return err;
outStyle.flags = kControlUseFontMask +
kControlUseFaceMask +
kControlUseSizeMask;
::GetFNum(themeFontName, &themeFontNum);
outStyle.font = themeFontNum;
outStyle.size = themeFontSize;
outStyle.style = themeStyle;
return noErr;
}

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

@ -1,178 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* 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 mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Conrad Carlen <ccarlen@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef UDownloadDisplay_h__
#define UDownloadDisplay_h__
#pragma once
#include "UDownload.h"
#include <LWindow.h>
class CMultiDownloadProgressWindow;
class CDownloadProgressView;
class LProgressBar;
class LStaticText;
//*****************************************************************************
// CMultiDownloadProgress
//
// A concrete instance of ADownloadProgressView which displays each download
// as a subpane of the same window.
//
// NOTE: The implementation uses nsILocalFile::Launch() to "open" a downloaded
// item. If the app which opens it is Stuffit Expander, we will receive an
// ae_ApplicationDied event when Stuffit finishes and terminates.
// PowerPlant will throw an exception for any unhandled Apple Event. To inhibit
// this, add a case for ae_ApplicationDied to your application's HandleAppleEvent().
// The event does not need to be handled, just prevented from reaching
// the default handler.
//*****************************************************************************
class CMultiDownloadProgress : public ADownloadProgressView,
public LCommander,
public LListener
{
public:
CMultiDownloadProgress();
virtual ~CMultiDownloadProgress();
// ADownloadProgressView
virtual void AddDownloadItem(CDownload *aDownloadItem);
// LCommander
virtual Boolean AllowSubRemoval(LCommander* inSub);
virtual Boolean AttemptQuitSelf(SInt32 inSaveOption);
// LListener
virtual void ListenToMessage(MessageT inMessage,
void* ioParam);
protected:
static bool sRegisteredViewClasses;
CMultiDownloadProgressWindow *mWindow;
};
//*****************************************************************************
// CMultiDownloadProgressWindow
//
// A window class which holds an array of progress views.
//*****************************************************************************
class CMultiDownloadProgressWindow : public LWindow,
public LBroadcaster
{
public:
enum { class_ID = FOUR_CHAR_CODE('MDPW') };
CMultiDownloadProgressWindow();
CMultiDownloadProgressWindow(LStream* inStream);
virtual ~CMultiDownloadProgressWindow();
// CMultiDownloadProgressWindow
virtual void AddDownloadView(CDownloadProgressView *aView);
virtual void RemoveDownloadView(CDownloadProgressView *aView);
virtual Boolean ConfirmClose();
protected:
SInt32 mDownloadViewCount;
};
//*****************************************************************************
// CDownloadProgressView
//
// A view class which tracks a single download.
//*****************************************************************************
class CDownloadProgressView : public LView,
public LCommander,
public LListener
{
public:
enum { class_ID = FOUR_CHAR_CODE('DPrV') };
CDownloadProgressView();
CDownloadProgressView(LStream* inStream);
virtual ~CDownloadProgressView();
// LCommander
virtual Boolean ObeyCommand(CommandT inCommand,
void *ioParam);
// LPane
virtual void FinishCreateSelf();
// LListener
virtual void ListenToMessage(MessageT inMessage,
void* ioParam);
// CDownloadProgressView
virtual void SetDownload(CDownload *aDownload);
virtual void CancelDownload();
virtual Boolean IsActive();
virtual void UpdateStatus(CDownload::MsgOnDLProgressChangeInfo *info);
LStr255& FormatBytes(float inBytes, LStr255& ioString);
LStr255& FormatFuzzyTime(PRInt32 inSecs, LStr255& ioString);
static OSErr CreateStyleRecFromThemeFont(ThemeFontID inThemeID,
ControlFontStyleRec& outStyle);
protected:
enum { kStatusUpdateIntervalTicks = 60 };
LProgressBar *mProgressBar;
LControl *mCancelButton, *mOpenButton, *mRevealButton;
LControl *mCloseButton;
LStaticText *mStatusText, *mTimeRemainingText;
LStaticText *mSrcURIText, *mDestFileText;
nsCOMPtr<nsIDownload> mDownload;
Boolean mDownloadActive;
SInt32 mLastStatusUpdateTicks;
};
#endif // DownloadProgressViews_h__

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

@ -1,228 +0,0 @@
/* -*- Mode: C++; tab-width: 3; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* 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 the Initial Developer are Copyright (C) 1999
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Conrad Carlen <ccarlen@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "UMacUnicode.h"
#include <TextCommon.h>
#include <Script.h>
#include "nsString.h"
static TextEncoding getSystemEncoding()
{
OSStatus err;
TextEncoding theEncoding;
err = ::UpgradeScriptInfoToTextEncoding(smSystemScript, kTextLanguageDontCare,
kTextRegionDontCare, NULL, &theEncoding);
if (err != noErr)
theEncoding = kTextEncodingMacRoman;
return theEncoding;
}
CPlatformUCSConversion *CPlatformUCSConversion::mgInstance = nsnull;
UnicodeToTextInfo CPlatformUCSConversion::sEncoderInfo = nsnull;
TextToUnicodeInfo CPlatformUCSConversion::sDecoderInfo = nsnull;
CPlatformUCSConversion::CPlatformUCSConversion()
{
}
CPlatformUCSConversion*
CPlatformUCSConversion::GetInstance()
{
if (!mgInstance)
mgInstance = new CPlatformUCSConversion;
return mgInstance;
}
NS_IMETHODIMP
CPlatformUCSConversion::PrepareEncoder()
{
nsresult rv = NS_OK;
if (!sEncoderInfo) {
OSStatus err;
err = ::CreateUnicodeToTextInfoByEncoding(getSystemEncoding(), &sEncoderInfo);
if (err)
rv = NS_ERROR_FAILURE;
}
return rv;
}
NS_IMETHODIMP
CPlatformUCSConversion::PrepareDecoder()
{
nsresult rv = NS_OK;
if (!sDecoderInfo) {
OSStatus err;
err = ::CreateTextToUnicodeInfoByEncoding(getSystemEncoding(), &sDecoderInfo);
if (err)
rv = NS_ERROR_FAILURE;
}
return rv;
}
NS_IMETHODIMP
CPlatformUCSConversion::UCSToPlatform(const nsAString& aIn, nsACString& aOut)
{
nsresult rv = PrepareEncoder();
if (NS_FAILED(rv)) return rv;
OSStatus err = noErr;
char stackBuffer[512];
aOut.Truncate(0);
nsReadingIterator<PRUnichar> done_reading;
aIn.EndReading(done_reading);
// for each chunk of |aIn|...
PRUint32 fragmentLength = 0;
nsReadingIterator<PRUnichar> iter;
for (aIn.BeginReading(iter); iter != done_reading && err == noErr; iter.advance(PRInt32(fragmentLength)))
{
fragmentLength = PRUint32(iter.size_forward());
UInt32 bytesLeft = fragmentLength * sizeof(UniChar);
nsReadingIterator<PRUnichar> sub_iter(iter);
do {
UInt32 bytesRead = 0, bytesWritten = 0;
err = ::ConvertFromUnicodeToText(sEncoderInfo,
bytesLeft,
(const UniChar*)sub_iter.get(),
kUnicodeUseFallbacksMask | kUnicodeLooseMappingsMask,
0, nsnull, nsnull, nsnull,
sizeof(stackBuffer),
&bytesRead,
&bytesWritten,
stackBuffer);
if (err == kTECUsedFallbacksStatus)
err = noErr;
else if (err == kTECOutputBufferFullStatus) {
bytesLeft -= bytesRead;
sub_iter.advance(bytesRead / sizeof(UniChar));
}
aOut.Append(stackBuffer, bytesWritten);
}
while (err == kTECOutputBufferFullStatus);
}
return (err == noErr) ? NS_OK : NS_ERROR_FAILURE;
}
NS_IMETHODIMP
CPlatformUCSConversion::UCSToPlatform(const nsAString& aIn, Str255& aOut)
{
nsresult res;
nsCAutoString cStr;
res = UCSToPlatform(aIn, cStr);
if (NS_SUCCEEDED(res))
{
PRUint32 outLength = cStr.Length();
if (outLength > 255)
outLength = 255;
memcpy(&aOut[1], cStr.get(), outLength);
aOut[0] = outLength;
}
return res;
}
NS_IMETHODIMP
CPlatformUCSConversion::PlatformToUCS(const nsACString& aIn, nsAString& aOut)
{
nsresult rv = PrepareDecoder();
if (NS_FAILED(rv)) return rv;
OSStatus err = noErr;
UniChar stackBuffer[512];
aOut.Truncate(0);
nsReadingIterator<char> done_reading;
aIn.EndReading(done_reading);
// for each chunk of |aIn|...
PRUint32 fragmentLength = 0;
nsReadingIterator<char> iter;
for (aIn.BeginReading(iter); iter != done_reading && err == noErr; iter.advance(PRInt32(fragmentLength)))
{
fragmentLength = PRUint32(iter.size_forward());
UInt32 bytesLeft = fragmentLength;
nsReadingIterator<char> sub_iter(iter);
do {
UInt32 bytesRead = 0, bytesWritten = 0;
err = ::ConvertFromTextToUnicode(sDecoderInfo,
bytesLeft,
sub_iter.get(),
kUnicodeUseFallbacksMask | kUnicodeLooseMappingsMask,
0, nsnull, nsnull, nsnull,
sizeof(stackBuffer),
&bytesRead,
&bytesWritten,
stackBuffer);
if (err == kTECUsedFallbacksStatus)
err = noErr;
else if (err == kTECOutputBufferFullStatus) {
bytesLeft -= bytesRead;
sub_iter.advance(bytesRead);
}
aOut.Append((PRUnichar *)stackBuffer, bytesWritten / sizeof(PRUnichar));
}
while (err == kTECOutputBufferFullStatus);
}
return (err == noErr) ? NS_OK : NS_ERROR_FAILURE;
}
NS_IMETHODIMP
CPlatformUCSConversion::PlatformToUCS(const Str255& aIn, nsAString& aOut)
{
char charBuf[256];
memcpy(charBuf, &aIn[1], aIn[0]);
charBuf[aIn[0]] = '\0';
return PlatformToUCS(nsDependentCString(charBuf, aIn[0]), aOut);
}

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

@ -1,70 +0,0 @@
/* -*- Mode: C++; tab-width: 3; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* 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 the Initial Developer are Copyright (C) 1999
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Conrad Carlen <ccarlen@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef __UMacUnicode__
#define __UMacUnicode__
#include "nsString.h"
#include "nsCOMPtr.h"
#include <UnicodeConverter.h>
class CPlatformUCSConversion {
public:
CPlatformUCSConversion();
virtual ~CPlatformUCSConversion(){};
static CPlatformUCSConversion* GetInstance();
NS_IMETHOD UCSToPlatform(const nsAString& aIn, nsACString& aOut);
NS_IMETHOD UCSToPlatform(const nsAString& aIn, Str255& aOut);
NS_IMETHOD PlatformToUCS(const nsACString& ain, nsAString& aOut);
NS_IMETHOD PlatformToUCS(const Str255& aIn, nsAString& aOut);
private:
static CPlatformUCSConversion *mgInstance;
static UnicodeToTextInfo sEncoderInfo;
static TextToUnicodeInfo sDecoderInfo;
nsresult PrepareEncoder();
nsresult PrepareDecoder();
};
#endif // __UMacUnicode__