2001-11-27 12:30:15 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2001-09-25 05:32:19 +04:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
1999-05-06 23:25:40 +04:00
|
|
|
*
|
2001-09-25 05:32:19 +04:00
|
|
|
* The contents of this file are subject to the Netscape Public License
|
|
|
|
* Version 1.1 (the "License"); you may not use this file except in
|
|
|
|
* compliance with the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/NPL/
|
1999-05-06 23:25:40 +04:00
|
|
|
*
|
2001-09-25 05:32:19 +04:00
|
|
|
* 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.
|
1999-05-06 23:25:40 +04:00
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Communicator client code.
|
|
|
|
*
|
2001-09-25 05:32:19 +04:00
|
|
|
* 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.
|
1999-11-06 06:40:37 +03:00
|
|
|
*
|
2001-04-18 10:06:31 +04:00
|
|
|
* Contributor(s):
|
|
|
|
* Dan Rosen <dr@netscape.com>
|
2001-09-21 17:52:39 +04:00
|
|
|
* Roland Mainz <roland.mainz@informatik.med.uni-giessen.de>
|
2001-09-25 05:32:19 +04:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* 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 NPL, 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 NPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
2001-04-18 10:06:31 +04:00
|
|
|
|
2001-08-14 11:59:59 +04:00
|
|
|
#include "nscore.h"
|
1999-05-06 23:25:40 +04:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsCRT.h"
|
|
|
|
#include "nsString.h"
|
2001-09-29 12:28:41 +04:00
|
|
|
#include "nsReadableUtils.h"
|
1999-05-06 23:25:40 +04:00
|
|
|
#include "nsISupports.h"
|
1999-11-19 10:35:27 +03:00
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsIContentViewerContainer.h"
|
1999-05-06 23:25:40 +04:00
|
|
|
#include "nsIDocumentViewer.h"
|
2000-09-01 05:54:35 +04:00
|
|
|
#include "nsIDOMWindowInternal.h"
|
2002-08-21 16:01:05 +04:00
|
|
|
#include "nsIDocumentViewerPrint.h"
|
1999-09-22 11:34:31 +04:00
|
|
|
|
1999-05-06 23:25:40 +04:00
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIPresContext.h"
|
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsIStyleSet.h"
|
|
|
|
#include "nsIStyleSheet.h"
|
2000-04-29 03:32:51 +04:00
|
|
|
#include "nsICSSStyleSheet.h"
|
1999-05-06 23:25:40 +04:00
|
|
|
#include "nsIFrame.h"
|
|
|
|
|
1999-12-03 12:24:22 +03:00
|
|
|
#include "nsIScriptGlobalObjectOwner.h"
|
1999-05-06 23:25:40 +04:00
|
|
|
#include "nsIScriptGlobalObject.h"
|
|
|
|
#include "nsILinkHandler.h"
|
|
|
|
#include "nsIDOMDocument.h"
|
2000-09-14 15:45:01 +04:00
|
|
|
#include "nsISelectionListener.h"
|
|
|
|
#include "nsISelectionPrivate.h"
|
2000-01-19 00:06:10 +03:00
|
|
|
#include "nsIDOMHTMLDocument.h"
|
2002-03-26 14:43:40 +03:00
|
|
|
#include "nsIDOMNSHTMLDocument.h"
|
|
|
|
#include "nsIDOMHTMLCollection.h"
|
2000-01-19 00:06:10 +03:00
|
|
|
#include "nsIDOMHTMLElement.h"
|
|
|
|
#include "nsIDOMRange.h"
|
2001-02-19 15:55:42 +03:00
|
|
|
#include "nsContentCID.h"
|
2000-01-19 00:06:10 +03:00
|
|
|
#include "nsLayoutCID.h"
|
2001-10-30 13:14:06 +03:00
|
|
|
#include "nsGenericHTMLElement.h"
|
1999-05-06 23:25:40 +04:00
|
|
|
|
|
|
|
#include "nsViewsCID.h"
|
|
|
|
#include "nsWidgetsCID.h"
|
|
|
|
#include "nsIDeviceContext.h"
|
|
|
|
#include "nsIDeviceContextSpec.h"
|
|
|
|
#include "nsIDeviceContextSpecFactory.h"
|
|
|
|
#include "nsIViewManager.h"
|
|
|
|
#include "nsIView.h"
|
|
|
|
|
|
|
|
#include "nsIPref.h"
|
|
|
|
#include "nsIPageSequenceFrame.h"
|
|
|
|
#include "nsIURL.h"
|
1999-05-14 18:40:59 +04:00
|
|
|
#include "nsIWebShell.h"
|
1999-11-19 10:35:27 +03:00
|
|
|
#include "nsIContentViewerEdit.h"
|
|
|
|
#include "nsIContentViewerFile.h"
|
|
|
|
#include "nsIMarkupDocumentViewer.h"
|
1999-11-13 10:36:28 +03:00
|
|
|
#include "nsIInterfaceRequestor.h"
|
2001-09-06 01:28:38 +04:00
|
|
|
#include "nsIInterfaceRequestorUtils.h"
|
1999-12-18 05:09:29 +03:00
|
|
|
#include "nsIDocShellTreeItem.h"
|
|
|
|
#include "nsIDocShellTreeNode.h"
|
2000-02-08 18:49:14 +03:00
|
|
|
#include "nsIDocShellTreeOwner.h"
|
1999-12-18 05:09:29 +03:00
|
|
|
#include "nsIDocShell.h"
|
2002-04-17 08:17:16 +04:00
|
|
|
#include "nsIBaseWindow.h"
|
2000-01-26 18:14:41 +03:00
|
|
|
#include "nsIFrameDebug.h"
|
2000-10-20 01:49:12 +04:00
|
|
|
#include "nsILayoutHistoryState.h"
|
2000-09-22 18:42:13 +04:00
|
|
|
#include "nsLayoutAtoms.h"
|
|
|
|
#include "nsIFrameManager.h"
|
2001-01-27 19:58:15 +03:00
|
|
|
#include "nsIParser.h"
|
2001-01-08 23:26:05 +03:00
|
|
|
#include "nsIPrintContext.h"
|
2001-07-16 06:40:48 +04:00
|
|
|
#include "nsGUIEvent.h"
|
|
|
|
#include "nsHTMLReflowState.h"
|
2001-04-18 10:06:31 +04:00
|
|
|
#include "nsIDOMHTMLAnchorElement.h"
|
2001-09-13 03:31:37 +04:00
|
|
|
#include "nsIDOMHTMLAreaElement.h"
|
|
|
|
#include "nsIDOMHTMLLinkElement.h"
|
2001-04-18 10:06:31 +04:00
|
|
|
#include "nsIDOMHTMLImageElement.h"
|
2002-08-21 16:01:05 +04:00
|
|
|
#include "nsIDOMHTMLFrameSetElement.h"
|
2002-04-11 04:45:11 +04:00
|
|
|
#include "nsIXULDocument.h" // Temporary code for Bug 136185
|
2000-10-29 02:17:53 +04:00
|
|
|
|
2000-04-29 03:32:51 +04:00
|
|
|
#include "nsIChromeRegistry.h"
|
2002-08-02 01:36:02 +04:00
|
|
|
#include "nsIClipboardHelper.h"
|
1999-05-14 18:40:59 +04:00
|
|
|
|
1999-09-22 11:34:31 +04:00
|
|
|
#include "nsIEventQueueService.h"
|
|
|
|
#include "nsIEventQueue.h"
|
|
|
|
|
2001-02-01 23:49:10 +03:00
|
|
|
#include "nsPIDOMWindow.h"
|
|
|
|
#include "nsIFocusController.h"
|
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
#include "nsIScrollableView.h"
|
|
|
|
#include "nsIScrollable.h"
|
|
|
|
#include "nsITimelineService.h"
|
|
|
|
#include "nsGfxCIID.h"
|
|
|
|
|
|
|
|
// Printing
|
|
|
|
#include "nsIWebBrowserPrint.h"
|
|
|
|
|
|
|
|
//--------------------------
|
|
|
|
// Printing Include
|
|
|
|
//---------------------------
|
|
|
|
#ifdef NS_PRINTING
|
|
|
|
|
|
|
|
#include "nsPrintEngine.h"
|
|
|
|
|
2001-01-27 17:09:34 +03:00
|
|
|
// Print Options
|
2002-01-01 15:58:53 +03:00
|
|
|
#include "nsIPrintSettings.h"
|
2002-05-14 16:05:00 +04:00
|
|
|
#include "nsIPrintSettingsService.h"
|
2001-01-27 17:09:34 +03:00
|
|
|
#include "nsIPrintOptions.h"
|
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsHTMLAtoms.h" // XXX until atoms get factored into nsLayoutAtoms
|
2002-01-01 15:58:53 +03:00
|
|
|
#include "nsISimpleEnumerator.h"
|
2002-09-04 03:36:13 +04:00
|
|
|
#include "nsXPCOM.h"
|
2002-01-01 15:58:53 +03:00
|
|
|
#include "nsISupportsPrimitives.h"
|
2002-02-13 16:58:41 +03:00
|
|
|
static NS_DEFINE_IID(kPrinterEnumeratorCID, NS_PRINTER_ENUMERATOR_CID);
|
2001-01-27 17:09:34 +03:00
|
|
|
|
2002-05-14 16:05:00 +04:00
|
|
|
// PrintOptions is now implemented by PrintSettingsService
|
2002-05-14 18:32:42 +04:00
|
|
|
static const char sPrintSettingsServiceContractID[] = "@mozilla.org/gfx/printsettings-service;1";
|
|
|
|
static const char sPrintOptionsContractID[] = "@mozilla.org/gfx/printsettings-service;1";
|
2002-05-14 16:05:00 +04:00
|
|
|
|
2001-03-27 15:56:03 +04:00
|
|
|
// Printing Events
|
|
|
|
#include "nsIEventQueue.h"
|
|
|
|
#include "nsIEventQueueService.h"
|
2002-03-23 21:07:51 +03:00
|
|
|
#include "nsPrintPreviewListener.h"
|
2001-03-27 15:56:03 +04:00
|
|
|
|
2001-04-12 17:04:29 +04:00
|
|
|
#include "nsIDOMHTMLFrameElement.h"
|
|
|
|
#include "nsIDOMHTMLIFrameElement.h"
|
2002-03-07 15:44:57 +03:00
|
|
|
#include "nsIDOMHTMLObjectElement.h"
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2001-11-03 17:59:39 +03:00
|
|
|
// Print Preview
|
|
|
|
#include "nsIPrintPreviewContext.h"
|
2001-11-14 17:03:09 +03:00
|
|
|
#include "imgIContainer.h" // image animation mode constants
|
2001-11-03 17:59:39 +03:00
|
|
|
|
2002-05-07 18:07:28 +04:00
|
|
|
// Print Progress
|
|
|
|
#include "nsIPrintProgress.h"
|
|
|
|
#include "nsIPrintProgressParams.h"
|
|
|
|
|
2001-09-21 17:52:39 +04:00
|
|
|
// Print error dialog
|
|
|
|
#include "nsIPrompt.h"
|
|
|
|
#include "nsIWindowWatcher.h"
|
|
|
|
#include "nsIStringBundle.h"
|
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
// Printing
|
|
|
|
#include "nsPrintEngine.h"
|
|
|
|
#include "nsPagePrintTimer.h"
|
2002-05-07 16:03:37 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
#endif // NS_PRINTING
|
2001-09-21 17:52:39 +04:00
|
|
|
|
2001-02-07 02:03:17 +03:00
|
|
|
// FrameSet
|
|
|
|
#include "nsINodeInfo.h"
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsHTMLAtoms.h"
|
|
|
|
#include "nsIHTMLContent.h"
|
|
|
|
#include "nsINameSpaceManager.h"
|
|
|
|
#include "nsIWebShell.h"
|
|
|
|
|
2000-04-22 01:40:28 +04:00
|
|
|
//focus
|
2002-04-17 08:17:16 +04:00
|
|
|
#include "nsIDOMEventReceiver.h"
|
2000-04-22 01:40:28 +04:00
|
|
|
#include "nsIDOMFocusListener.h"
|
2000-04-27 11:37:12 +04:00
|
|
|
#include "nsISelectionController.h"
|
2000-04-22 01:40:28 +04:00
|
|
|
|
2001-04-13 03:35:24 +04:00
|
|
|
#ifdef IBMBIDI
|
2002-02-19 23:41:32 +03:00
|
|
|
#include "nsBidiUtils.h"
|
2001-04-13 03:35:24 +04:00
|
|
|
#endif
|
|
|
|
|
2001-02-19 15:55:42 +03:00
|
|
|
static NS_DEFINE_CID(kPresShellCID, NS_PRESSHELL_CID);
|
|
|
|
static NS_DEFINE_CID(kGalleyContextCID, NS_GALLEYCONTEXT_CID);
|
|
|
|
static NS_DEFINE_CID(kPrintContextCID, NS_PRINTCONTEXT_CID);
|
|
|
|
static NS_DEFINE_CID(kStyleSetCID, NS_STYLESET_CID);
|
1999-05-06 23:25:40 +04:00
|
|
|
|
|
|
|
#ifdef NS_DEBUG
|
2001-04-12 17:04:29 +04:00
|
|
|
|
1999-05-06 23:25:40 +04:00
|
|
|
#undef NOISY_VIEWER
|
|
|
|
#else
|
|
|
|
#undef NOISY_VIEWER
|
|
|
|
#endif
|
|
|
|
|
2002-06-20 01:51:13 +04:00
|
|
|
//-----------------------------------------------------
|
|
|
|
// PR LOGGING
|
|
|
|
#ifdef MOZ_LOGGING
|
|
|
|
#define FORCE_PR_LOG /* Allow logging in the release build */
|
2001-04-12 17:04:29 +04:00
|
|
|
#endif
|
|
|
|
|
2002-06-20 01:51:13 +04:00
|
|
|
#include "prlog.h"
|
|
|
|
|
|
|
|
#ifdef PR_LOGGING
|
|
|
|
|
|
|
|
#ifdef NS_DEBUG
|
|
|
|
// PR_LOGGING is force to always be on (even in release builds)
|
|
|
|
// but we only want some of it on,
|
|
|
|
//#define EXTENDED_DEBUG_PRINTING
|
2001-04-12 17:04:29 +04:00
|
|
|
#endif
|
|
|
|
|
2002-06-20 01:51:13 +04:00
|
|
|
#define DUMP_LAYOUT_LEVEL 9 // this turns on the dumping of each doucment's layout info
|
|
|
|
|
|
|
|
static PRLogModuleInfo * kPrintingLogMod = PR_NewLogModule("printing");
|
|
|
|
#define PR_PL(_p1) PR_LOG(kPrintingLogMod, PR_LOG_DEBUG, _p1);
|
|
|
|
|
|
|
|
#ifdef EXTENDED_DEBUG_PRINTING
|
|
|
|
static PRUint32 gDumpFileNameCnt = 0;
|
|
|
|
static PRUint32 gDumpLOFileNameCnt = 0;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define PRT_YESNO(_p) ((_p)?"YES":"NO")
|
2001-09-21 17:52:39 +04:00
|
|
|
static const char * gFrameTypesStr[] = {"eDoc", "eFrame", "eIFrame", "eFrameSet"};
|
|
|
|
static const char * gPrintFrameTypeStr[] = {"kNoFrames", "kFramesAsIs", "kSelectedFrame", "kEachFrameSep"};
|
|
|
|
static const char * gFrameHowToEnableStr[] = {"kFrameEnableNone", "kFrameEnableAll", "kFrameEnableAsIsAndEach"};
|
|
|
|
static const char * gPrintRangeStr[] = {"kRangeAllPages", "kRangeSpecifiedPageRange", "kRangeSelection", "kRangeFocusFrame"};
|
2002-06-20 01:51:13 +04:00
|
|
|
#else
|
2002-04-17 08:17:16 +04:00
|
|
|
#define PRT_YESNO(_p)
|
2002-06-20 01:51:13 +04:00
|
|
|
#define PR_PL(_p1)
|
2001-04-12 17:04:29 +04:00
|
|
|
#endif
|
2002-06-20 01:51:13 +04:00
|
|
|
//-----------------------------------------------------
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2000-02-16 04:39:30 +03:00
|
|
|
class DocumentViewerImpl;
|
|
|
|
|
2001-11-03 17:59:39 +03:00
|
|
|
// New PrintPreview
|
|
|
|
static NS_DEFINE_CID(kPrintPreviewContextCID, NS_PRINT_PREVIEW_CONTEXT_CID);
|
|
|
|
|
2000-02-16 04:39:30 +03:00
|
|
|
// a small delegate class used to avoid circular references
|
|
|
|
|
|
|
|
#ifdef XP_MAC
|
2001-04-18 10:06:31 +04:00
|
|
|
#pragma mark ** nsDocViewerSelectionListener **
|
2000-02-16 04:39:30 +03:00
|
|
|
#endif
|
|
|
|
|
2001-04-18 10:06:31 +04:00
|
|
|
class nsDocViewerSelectionListener : public nsISelectionListener
|
2000-02-16 04:39:30 +03:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
// nsISupports interface...
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
2000-09-14 15:45:01 +04:00
|
|
|
// nsISelectionListerner interface
|
2002-04-17 08:17:16 +04:00
|
|
|
NS_DECL_NSISELECTIONLISTENER
|
2000-02-16 04:39:30 +03:00
|
|
|
|
2001-04-18 10:06:31 +04:00
|
|
|
nsDocViewerSelectionListener()
|
2000-02-16 04:39:30 +03:00
|
|
|
: mDocViewer(NULL)
|
|
|
|
, mGotSelectionState(PR_FALSE)
|
|
|
|
, mSelectionWasCollapsed(PR_FALSE)
|
|
|
|
{
|
2002-09-07 21:13:19 +04:00
|
|
|
NS_INIT_ISUPPORTS();
|
2000-02-16 04:39:30 +03:00
|
|
|
}
|
2002-04-17 08:17:16 +04:00
|
|
|
|
2001-04-18 10:06:31 +04:00
|
|
|
virtual ~nsDocViewerSelectionListener() {}
|
2002-04-17 08:17:16 +04:00
|
|
|
|
2000-02-16 04:39:30 +03:00
|
|
|
nsresult Init(DocumentViewerImpl *aDocViewer);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
DocumentViewerImpl* mDocViewer;
|
|
|
|
PRPackedBool mGotSelectionState;
|
|
|
|
PRPackedBool mSelectionWasCollapsed;
|
2002-04-17 08:17:16 +04:00
|
|
|
|
2000-02-16 04:39:30 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2000-04-22 01:40:28 +04:00
|
|
|
/** editor Implementation of the FocusListener interface
|
|
|
|
*/
|
2002-04-17 08:17:16 +04:00
|
|
|
class nsDocViewerFocusListener : public nsIDOMFocusListener
|
2000-04-22 01:40:28 +04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/** default constructor
|
|
|
|
*/
|
|
|
|
nsDocViewerFocusListener();
|
|
|
|
/** default destructor
|
|
|
|
*/
|
|
|
|
virtual ~nsDocViewerFocusListener();
|
|
|
|
|
|
|
|
|
|
|
|
/*interfaces for addref and release and queryinterface*/
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
/*BEGIN implementations of focus event handler interface*/
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent);
|
|
|
|
NS_IMETHOD Focus(nsIDOMEvent* aEvent);
|
|
|
|
NS_IMETHOD Blur(nsIDOMEvent* aEvent);
|
2000-04-22 01:40:28 +04:00
|
|
|
/*END implementations of focus event handler interface*/
|
|
|
|
nsresult Init(DocumentViewerImpl *aDocViewer);
|
|
|
|
|
|
|
|
private:
|
|
|
|
DocumentViewerImpl* mDocViewer;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2000-02-16 04:39:30 +03:00
|
|
|
#ifdef XP_MAC
|
|
|
|
#pragma mark ** DocumentViewerImpl **
|
|
|
|
#endif
|
|
|
|
|
2001-04-12 17:04:29 +04:00
|
|
|
//-------------------------------------------------------------
|
1999-09-22 11:34:31 +04:00
|
|
|
class DocumentViewerImpl : public nsIDocumentViewer,
|
1999-11-19 10:35:27 +03:00
|
|
|
public nsIContentViewerEdit,
|
|
|
|
public nsIContentViewerFile,
|
2002-02-01 17:52:11 +03:00
|
|
|
public nsIMarkupDocumentViewer,
|
2002-07-09 16:39:02 +04:00
|
|
|
public nsIWebBrowserPrint,
|
2002-08-21 16:01:05 +04:00
|
|
|
public nsIDocumentViewerPrint
|
1999-05-06 23:25:40 +04:00
|
|
|
{
|
2001-04-18 10:06:31 +04:00
|
|
|
friend class nsDocViewerSelectionListener;
|
2001-11-03 17:59:39 +03:00
|
|
|
friend class nsPagePrintTimer;
|
2002-08-21 16:01:05 +04:00
|
|
|
friend class nsPrintEngine;
|
2002-04-17 08:17:16 +04:00
|
|
|
|
1999-05-06 23:25:40 +04:00
|
|
|
public:
|
|
|
|
DocumentViewerImpl();
|
|
|
|
DocumentViewerImpl(nsIPresContext* aPresContext);
|
2002-04-17 08:17:16 +04:00
|
|
|
|
1999-05-06 23:25:40 +04:00
|
|
|
NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
|
|
|
|
|
|
|
|
// nsISupports interface...
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
// nsIContentViewer interface...
|
2001-08-01 07:15:50 +04:00
|
|
|
NS_DECL_NSICONTENTVIEWER
|
1999-05-06 23:25:40 +04:00
|
|
|
|
|
|
|
// nsIDocumentViewer interface...
|
|
|
|
NS_IMETHOD SetUAStyleSheet(nsIStyleSheet* aUAStyleSheet);
|
|
|
|
NS_IMETHOD GetDocument(nsIDocument*& aResult);
|
|
|
|
NS_IMETHOD GetPresShell(nsIPresShell*& aResult);
|
|
|
|
NS_IMETHOD GetPresContext(nsIPresContext*& aResult);
|
|
|
|
NS_IMETHOD CreateDocumentViewerUsing(nsIPresContext* aPresContext,
|
|
|
|
nsIDocumentViewer*& aResult);
|
|
|
|
|
1999-11-19 10:35:27 +03:00
|
|
|
// nsIContentViewerEdit
|
|
|
|
NS_DECL_NSICONTENTVIEWEREDIT
|
|
|
|
|
|
|
|
// nsIContentViewerFile
|
|
|
|
NS_DECL_NSICONTENTVIEWERFILE
|
|
|
|
|
|
|
|
// nsIMarkupDocumentViewer
|
|
|
|
NS_DECL_NSIMARKUPDOCUMENTVIEWER
|
|
|
|
|
2002-02-01 17:52:11 +03:00
|
|
|
// nsIWebBrowserPrint
|
|
|
|
NS_DECL_NSIWEBBROWSERPRINT
|
|
|
|
|
2000-04-03 01:52:17 +04:00
|
|
|
typedef void (*CallChildFunc)(nsIMarkupDocumentViewer* aViewer,
|
|
|
|
void* aClosure);
|
|
|
|
nsresult CallChildren(CallChildFunc aFunc, void* aClosure);
|
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
// nsIDocumentViewerPrint Printing Methods
|
|
|
|
virtual nsresult CreateStyleSet(nsIDocument* aDocument, nsIStyleSet** aStyleSet);
|
|
|
|
virtual nsresult GetDocumentSelection(nsISelection **aSelection, nsIPresShell * aPresShell = nsnull);
|
|
|
|
virtual void IncrementDestroyRefCount();
|
|
|
|
virtual void ReturnToGalleyPresentation();
|
|
|
|
virtual void InstallNewPresentation();
|
|
|
|
virtual void OnDonePrinting();
|
|
|
|
virtual nsresult FindFrameSetWithIID(nsIContent * aParentContent, const nsIID& aIID);
|
|
|
|
virtual void GetPresShellAndRootContent(nsIWebShell * aWebShell, nsIPresShell** aPresShell, nsIContent** aContent);
|
|
|
|
|
|
|
|
// Printing Helpers
|
|
|
|
PRBool GetIsPrinting();
|
|
|
|
void SetIsPrinting(PRBool aIsPrinting);
|
|
|
|
PRBool GetIsPrintPreview();
|
|
|
|
void SetIsPrintPreview(PRBool aIsPrintPreview);
|
|
|
|
PRBool GetIsCreatingPrintPreview();
|
|
|
|
void SetIsCreatingPrintPreview(PRBool aIsCreatingPrintPreview);
|
|
|
|
|
|
|
|
// Helpers (also used by nsPrintEngine)
|
|
|
|
PRBool IsWebShellAFrameSet(nsIWebShell * aParent);
|
2001-11-03 17:59:39 +03:00
|
|
|
|
1999-05-06 23:25:40 +04:00
|
|
|
protected:
|
|
|
|
virtual ~DocumentViewerImpl();
|
|
|
|
|
|
|
|
private:
|
|
|
|
void ForceRefresh(void);
|
2000-03-11 04:24:59 +03:00
|
|
|
nsresult MakeWindow(nsIWidget* aParentWidget,
|
|
|
|
const nsRect& aBounds);
|
2002-03-26 14:43:40 +03:00
|
|
|
nsresult InitInternal(nsIWidget* aParentWidget,
|
|
|
|
nsIDeviceContext* aDeviceContext,
|
|
|
|
const nsRect& aBounds,
|
|
|
|
PRBool aDoCreation);
|
2002-04-17 08:17:16 +04:00
|
|
|
nsresult InitPresentationStuff(PRBool aDoInitialReflow);
|
|
|
|
|
2001-04-18 10:06:31 +04:00
|
|
|
nsresult GetPopupNode(nsIDOMNode** aNode);
|
|
|
|
nsresult GetPopupLinkNode(nsIDOMNode** aNode);
|
|
|
|
nsresult GetPopupImageNode(nsIDOMNode** aNode);
|
|
|
|
|
2001-05-25 12:49:03 +04:00
|
|
|
void PrepareToStartLoad(void);
|
2002-04-17 08:17:16 +04:00
|
|
|
|
|
|
|
nsresult SyncParentSubDocMap();
|
|
|
|
|
1999-05-06 23:25:40 +04:00
|
|
|
protected:
|
|
|
|
// IMPORTANT: The ownership implicit in the following member
|
|
|
|
// variables has been explicitly checked and set using nsCOMPtr
|
|
|
|
// for owning pointers and raw COM interface pointers for weak
|
|
|
|
// (ie, non owning) references. If you add any members to this
|
|
|
|
// class, please make the ownership explicit (pinkerton, scc).
|
2002-04-17 08:17:16 +04:00
|
|
|
|
1999-11-13 10:36:28 +03:00
|
|
|
nsISupports* mContainer; // [WEAK] it owns me!
|
1999-05-06 23:25:40 +04:00
|
|
|
nsCOMPtr<nsIDeviceContext> mDeviceContext; // ??? can't hurt, but...
|
|
|
|
|
2002-06-20 16:04:22 +04:00
|
|
|
// the following six items are explicitly in this order
|
1999-05-06 23:25:40 +04:00
|
|
|
// so they will be destroyed in the reverse order (pinkerton, scc)
|
|
|
|
nsCOMPtr<nsIDocument> mDocument;
|
|
|
|
nsCOMPtr<nsIWidget> mWindow; // ??? should we really own it?
|
|
|
|
nsCOMPtr<nsIViewManager> mViewManager;
|
|
|
|
nsCOMPtr<nsIPresContext> mPresContext;
|
|
|
|
nsCOMPtr<nsIPresShell> mPresShell;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIStyleSheet> mUAStyleSheet;
|
1999-05-07 23:26:23 +04:00
|
|
|
|
2000-09-14 15:45:01 +04:00
|
|
|
nsCOMPtr<nsISelectionListener> mSelectionListener;
|
2000-04-22 01:40:28 +04:00
|
|
|
nsCOMPtr<nsIDOMFocusListener> mFocusListener;
|
2002-04-17 08:17:16 +04:00
|
|
|
|
2001-05-02 02:50:16 +04:00
|
|
|
nsCOMPtr<nsIContentViewer> mPreviousViewer;
|
|
|
|
|
2000-01-26 18:14:41 +03:00
|
|
|
PRBool mEnableRendering;
|
2001-04-25 23:52:49 +04:00
|
|
|
PRBool mStopped;
|
2001-05-02 02:50:16 +04:00
|
|
|
PRBool mLoaded;
|
1999-07-15 18:23:40 +04:00
|
|
|
PRInt16 mNumURLStarts;
|
2001-08-06 06:27:43 +04:00
|
|
|
PRInt16 mDestroyRefCount; // a second "refcount" for the document viewer's "destroy"
|
1999-07-15 18:23:40 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
nsIWidget* mParentWidget; // purposely won't be ref counted
|
1999-07-15 18:23:40 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
#ifdef NS_PRINTING
|
|
|
|
nsPrintEngine* mPrintEngine;
|
2001-11-03 17:59:39 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
#if NS_PRINT_PREVIEW
|
2002-06-28 17:39:44 +04:00
|
|
|
// These data member support delayed printing when the document is loading
|
|
|
|
nsCOMPtr<nsIPrintSettings> mCachedPrintSettings;
|
|
|
|
nsCOMPtr<nsIWebProgressListener> mCachedPrintWebProgressListner;
|
|
|
|
PRPackedBool mPrintIsPending;
|
|
|
|
PRPackedBool mPrintDocIsFullyLoaded;
|
2002-08-21 16:01:05 +04:00
|
|
|
#endif // NS_PRINT_PREVIEW
|
2001-11-03 17:59:39 +03:00
|
|
|
|
2002-01-01 15:58:53 +03:00
|
|
|
#ifdef NS_DEBUG
|
|
|
|
FILE* mDebugFile;
|
2002-08-21 16:01:05 +04:00
|
|
|
#endif // NS_DEBUG
|
|
|
|
#endif // NS_PRINTING
|
2001-03-27 15:56:03 +04:00
|
|
|
|
1999-11-19 10:35:27 +03:00
|
|
|
// document management data
|
|
|
|
// these items are specific to markup documents (html and xml)
|
|
|
|
// may consider splitting these out into a subclass
|
2002-04-24 04:33:56 +04:00
|
|
|
PRPackedBool mAllowPlugins;
|
|
|
|
PRPackedBool mIsSticky;
|
|
|
|
|
1999-11-19 10:35:27 +03:00
|
|
|
/* character set member data */
|
|
|
|
nsString mDefaultCharacterSet;
|
|
|
|
nsString mHintCharset;
|
2001-12-26 06:17:59 +03:00
|
|
|
PRInt32 mHintCharsetSource;
|
1999-11-19 10:35:27 +03:00
|
|
|
nsString mForceCharacterSet;
|
2002-08-27 00:13:31 +04:00
|
|
|
nsString mPrevDocCharacterSet;
|
1999-05-06 23:25:40 +04:00
|
|
|
};
|
|
|
|
|
2001-04-12 17:04:29 +04:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
// DocumentViewerImpl
|
|
|
|
//------------------------------------------------------------------
|
1999-05-07 23:26:23 +04:00
|
|
|
// Class IDs
|
1999-07-15 11:00:22 +04:00
|
|
|
static NS_DEFINE_CID(kViewManagerCID, NS_VIEW_MANAGER_CID);
|
|
|
|
static NS_DEFINE_CID(kWidgetCID, NS_CHILD_CID);
|
|
|
|
static NS_DEFINE_CID(kViewCID, NS_VIEW_CID);
|
1999-05-06 23:25:40 +04:00
|
|
|
|
2002-02-01 17:52:11 +03:00
|
|
|
//------------------------------------------------------------------
|
1999-05-06 23:25:40 +04:00
|
|
|
nsresult
|
|
|
|
NS_NewDocumentViewer(nsIDocumentViewer** aResult)
|
|
|
|
{
|
2002-04-17 08:17:16 +04:00
|
|
|
*aResult = new DocumentViewerImpl();
|
|
|
|
if (!*aResult) {
|
1999-05-06 23:25:40 +04:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2002-04-17 08:17:16 +04:00
|
|
|
|
|
|
|
NS_ADDREF(*aResult);
|
|
|
|
|
|
|
|
return NS_OK;
|
1999-05-06 23:25:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Note: operator new zeros our memory
|
|
|
|
DocumentViewerImpl::DocumentViewerImpl()
|
2002-07-23 07:45:06 +04:00
|
|
|
: mIsSticky(PR_TRUE)
|
1999-05-06 23:25:40 +04:00
|
|
|
{
|
2001-03-10 06:19:36 +03:00
|
|
|
NS_INIT_ISUPPORTS();
|
2001-05-25 12:49:03 +04:00
|
|
|
PrepareToStartLoad();
|
2001-11-14 14:24:03 +03:00
|
|
|
|
2001-11-03 17:59:39 +03:00
|
|
|
mParentWidget = nsnull;
|
2001-05-25 12:49:03 +04:00
|
|
|
}
|
|
|
|
|
2002-04-17 08:17:16 +04:00
|
|
|
void DocumentViewerImpl::PrepareToStartLoad()
|
|
|
|
{
|
2001-03-27 15:56:03 +04:00
|
|
|
mEnableRendering = PR_TRUE;
|
2001-04-25 23:52:49 +04:00
|
|
|
mStopped = PR_FALSE;
|
2001-05-02 02:50:16 +04:00
|
|
|
mLoaded = PR_FALSE;
|
2002-08-21 16:01:05 +04:00
|
|
|
|
|
|
|
#ifdef NS_PRINTING
|
|
|
|
mPrintIsPending = PR_FALSE;
|
2002-06-28 17:39:44 +04:00
|
|
|
mPrintDocIsFullyLoaded = PR_FALSE;
|
2001-11-03 17:59:39 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
// Make sure we have destroyed it and cleared the data member
|
|
|
|
if (mPrintEngine) {
|
|
|
|
mPrintEngine->Destroy();
|
|
|
|
NS_RELEASE(mPrintEngine);
|
|
|
|
}
|
|
|
|
|
2001-11-03 17:59:39 +03:00
|
|
|
#ifdef NS_PRINT_PREVIEW
|
2002-08-21 16:01:05 +04:00
|
|
|
SetIsPrintPreview(PR_FALSE);
|
2001-11-03 17:59:39 +03:00
|
|
|
#endif
|
2002-01-01 15:58:53 +03:00
|
|
|
|
|
|
|
#ifdef NS_DEBUG
|
|
|
|
mDebugFile = nsnull;
|
|
|
|
#endif
|
2002-08-21 16:01:05 +04:00
|
|
|
|
|
|
|
#endif // NS_PRINTING
|
1999-05-06 23:25:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
DocumentViewerImpl::DocumentViewerImpl(nsIPresContext* aPresContext)
|
2002-07-23 07:45:06 +04:00
|
|
|
: mPresContext(aPresContext), mAllowPlugins(PR_TRUE), mIsSticky(PR_TRUE)
|
1999-05-06 23:25:40 +04:00
|
|
|
{
|
2001-03-10 06:19:36 +03:00
|
|
|
NS_INIT_ISUPPORTS();
|
1999-11-19 10:35:27 +03:00
|
|
|
mHintCharsetSource = kCharsetUninitialized;
|
2001-05-25 12:49:03 +04:00
|
|
|
PrepareToStartLoad();
|
1999-05-06 23:25:40 +04:00
|
|
|
}
|
|
|
|
|
2002-07-09 16:39:02 +04:00
|
|
|
NS_IMPL_ISUPPORTS7(DocumentViewerImpl,
|
2001-03-10 06:19:36 +03:00
|
|
|
nsIContentViewer,
|
|
|
|
nsIDocumentViewer,
|
|
|
|
nsIMarkupDocumentViewer,
|
|
|
|
nsIContentViewerFile,
|
2002-02-01 17:52:11 +03:00
|
|
|
nsIContentViewerEdit,
|
2002-07-09 16:39:02 +04:00
|
|
|
nsIWebBrowserPrint,
|
2002-08-21 16:01:05 +04:00
|
|
|
nsIDocumentViewerPrint)
|
1999-05-06 23:25:40 +04:00
|
|
|
|
|
|
|
DocumentViewerImpl::~DocumentViewerImpl()
|
|
|
|
{
|
2001-08-01 07:15:50 +04:00
|
|
|
NS_ASSERTION(!mDocument, "User did not call nsIContentViewer::Close");
|
2002-04-17 08:17:16 +04:00
|
|
|
if (mDocument) {
|
2001-08-01 07:15:50 +04:00
|
|
|
Close();
|
2002-04-17 08:17:16 +04:00
|
|
|
}
|
2001-08-01 07:15:50 +04:00
|
|
|
|
|
|
|
NS_ASSERTION(!mPresShell, "User did not call nsIContentViewer::Destroy");
|
2002-04-17 08:17:16 +04:00
|
|
|
if (mPresShell) {
|
2001-07-27 00:53:21 +04:00
|
|
|
Destroy();
|
2002-04-17 08:17:16 +04:00
|
|
|
}
|
1999-05-06 23:25:40 +04:00
|
|
|
|
2001-08-01 07:15:50 +04:00
|
|
|
// XXX(?) Revoke pending invalidate events
|
|
|
|
|
2001-03-10 06:19:36 +03:00
|
|
|
// clear weak references before we go away
|
2000-02-03 02:40:22 +03:00
|
|
|
if (mPresContext) {
|
|
|
|
mPresContext->SetContainer(nsnull);
|
|
|
|
mPresContext->SetLinkHandler(nsnull);
|
|
|
|
}
|
1999-05-06 23:25:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This method is called by the Document Loader once a document has
|
|
|
|
* been created for a particular data stream... The content viewer
|
|
|
|
* must cache this document for later use when Init(...) is called.
|
2001-05-25 12:49:03 +04:00
|
|
|
*
|
|
|
|
* This method is also called when an out of band document.write() happens.
|
|
|
|
* In that case, the document passed in is the same as the previous document.
|
1999-05-06 23:25:40 +04:00
|
|
|
*/
|
|
|
|
NS_IMETHODIMP
|
2001-05-25 12:49:03 +04:00
|
|
|
DocumentViewerImpl::LoadStart(nsISupports *aDoc)
|
1999-05-06 23:25:40 +04:00
|
|
|
{
|
|
|
|
#ifdef NOISY_VIEWER
|
2001-05-25 12:49:03 +04:00
|
|
|
printf("DocumentViewerImpl::LoadStart\n");
|
1999-05-06 23:25:40 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
nsresult rv;
|
2001-05-25 12:49:03 +04:00
|
|
|
if (!mDocument) {
|
2002-04-17 08:17:16 +04:00
|
|
|
mDocument = do_QueryInterface(aDoc, &rv);
|
2001-05-25 12:49:03 +04:00
|
|
|
}
|
|
|
|
else if (mDocument == aDoc) {
|
2002-04-17 08:17:16 +04:00
|
|
|
// Reset the document viewer's state back to what it was
|
2001-05-25 12:49:03 +04:00
|
|
|
// when the document load started.
|
|
|
|
PrepareToStartLoad();
|
|
|
|
}
|
|
|
|
|
1999-05-06 23:25:40 +04:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2002-04-17 08:17:16 +04:00
|
|
|
nsresult
|
|
|
|
DocumentViewerImpl::SyncParentSubDocMap()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> item(do_QueryInterface(mContainer));
|
|
|
|
nsCOMPtr<nsIDOMWindowInternal> win(do_GetInterface(item));
|
|
|
|
nsCOMPtr<nsPIDOMWindow> pwin(do_QueryInterface(win));
|
|
|
|
nsCOMPtr<nsIContent> content;
|
|
|
|
|
|
|
|
if (mDocument && pwin) {
|
|
|
|
nsCOMPtr<nsIDOMElement> frame_element;
|
|
|
|
pwin->GetFrameElementInternal(getter_AddRefs(frame_element));
|
|
|
|
|
|
|
|
content = do_QueryInterface(frame_element);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (content) {
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> parent;
|
|
|
|
item->GetParent(getter_AddRefs(parent));
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMWindow> parent_win(do_GetInterface(parent));
|
|
|
|
|
|
|
|
if (parent_win) {
|
|
|
|
nsCOMPtr<nsIDOMDocument> dom_doc;
|
|
|
|
parent_win->GetDocument(getter_AddRefs(dom_doc));
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocument> parent_doc(do_QueryInterface(dom_doc));
|
|
|
|
|
|
|
|
if (parent_doc) {
|
|
|
|
return parent_doc->SetSubDocumentFor(content, mDocument);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-05-06 23:25:40 +04:00
|
|
|
NS_IMETHODIMP
|
1999-11-14 13:12:21 +03:00
|
|
|
DocumentViewerImpl::SetContainer(nsISupports* aContainer)
|
1999-05-06 23:25:40 +04:00
|
|
|
{
|
|
|
|
mContainer = aContainer;
|
|
|
|
if (mPresContext) {
|
|
|
|
mPresContext->SetContainer(aContainer);
|
|
|
|
}
|
2002-04-17 08:17:16 +04:00
|
|
|
|
|
|
|
// We're loading a new document into the window where this document
|
|
|
|
// viewer lives, sync the parent document's frame element -> sub
|
|
|
|
// document map
|
|
|
|
|
|
|
|
return SyncParentSubDocMap();
|
1999-05-06 23:25:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-11-14 13:12:21 +03:00
|
|
|
DocumentViewerImpl::GetContainer(nsISupports** aResult)
|
1999-05-06 23:25:40 +04:00
|
|
|
{
|
1999-11-14 13:12:21 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(aResult);
|
|
|
|
|
|
|
|
*aResult = mContainer;
|
|
|
|
NS_IF_ADDREF(*aResult);
|
|
|
|
|
1999-11-13 10:36:28 +03:00
|
|
|
return NS_OK;
|
1999-05-06 23:25:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-03-11 04:24:59 +03:00
|
|
|
DocumentViewerImpl::Init(nsIWidget* aParentWidget,
|
1999-05-06 23:25:40 +04:00
|
|
|
nsIDeviceContext* aDeviceContext,
|
2000-03-11 04:24:59 +03:00
|
|
|
const nsRect& aBounds)
|
2002-03-26 14:43:40 +03:00
|
|
|
{
|
|
|
|
return InitInternal(aParentWidget, aDeviceContext, aBounds, PR_TRUE);
|
|
|
|
}
|
|
|
|
|
2002-04-17 08:17:16 +04:00
|
|
|
nsresult
|
|
|
|
DocumentViewerImpl::InitPresentationStuff(PRBool aDoInitialReflow)
|
|
|
|
{
|
|
|
|
// Create the style set...
|
|
|
|
nsCOMPtr<nsIStyleSet> styleSet;
|
|
|
|
nsresult rv = CreateStyleSet(mDocument, getter_AddRefs(styleSet));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// Now make the shell for the document
|
|
|
|
rv = mDocument->CreateShell(mPresContext, mViewManager, styleSet,
|
|
|
|
getter_AddRefs(mPresShell));
|
|
|
|
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2002-09-06 09:44:31 +04:00
|
|
|
if (aDoInitialReflow) {
|
|
|
|
// Since InitialReflow() will create frames for *all* items
|
|
|
|
// that are currently in the document tree, we need to flush
|
|
|
|
// any pending notifications to prevent the content sink from
|
|
|
|
// duplicating layout frames for content it has added to the tree
|
|
|
|
// but hasn't notified the document about. (Bug 154018)
|
|
|
|
//
|
|
|
|
// Note that we are flushing before we add mPresShell as an observer
|
|
|
|
// to avoid bogus notifications.
|
|
|
|
|
|
|
|
mDocument->FlushPendingNotifications(PR_FALSE);
|
|
|
|
}
|
|
|
|
|
2002-04-17 08:17:16 +04:00
|
|
|
mPresShell->BeginObservingDocument();
|
|
|
|
|
|
|
|
// Initialize our view manager
|
|
|
|
nsRect bounds;
|
|
|
|
mWindow->GetBounds(bounds);
|
|
|
|
|
|
|
|
float p2t;
|
|
|
|
|
|
|
|
mPresContext->GetPixelsToTwips(&p2t);
|
|
|
|
|
|
|
|
nscoord width = NSIntPixelsToTwips(bounds.width, p2t);
|
|
|
|
nscoord height = NSIntPixelsToTwips(bounds.height, p2t);
|
|
|
|
|
|
|
|
mViewManager->DisableRefresh();
|
|
|
|
mViewManager->SetWindowDimensions(width, height);
|
|
|
|
|
|
|
|
// Setup default view manager background color
|
|
|
|
|
|
|
|
// This may be overridden by the docshell with the background color
|
|
|
|
// for the last document loaded into the docshell
|
|
|
|
nscolor bgcolor = NS_RGB(0, 0, 0);
|
|
|
|
mPresContext->GetDefaultBackgroundColor(&bgcolor);
|
|
|
|
mViewManager->SetDefaultBackgroundColor(bgcolor);
|
|
|
|
|
|
|
|
if (aDoInitialReflow) {
|
2002-04-20 03:55:45 +04:00
|
|
|
nsCOMPtr<nsIScrollable> sc = do_QueryInterface(mContainer);
|
|
|
|
|
|
|
|
if (sc) {
|
|
|
|
nsCOMPtr<nsIContent> root;
|
|
|
|
mDocument->GetRootContent(getter_AddRefs(root));
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMHTMLFrameSetElement> frameset(do_QueryInterface(root));
|
|
|
|
|
|
|
|
if (frameset) {
|
|
|
|
// If this is a frameset (i.e. not a frame) then we never want
|
|
|
|
// scrollbars on it, the scrollbars go inside the frames
|
|
|
|
// inside the frameset...
|
|
|
|
|
|
|
|
sc->SetCurrentScrollbarPreferences(nsIScrollable::ScrollOrientation_Y,
|
|
|
|
NS_STYLE_OVERFLOW_HIDDEN);
|
|
|
|
sc->SetCurrentScrollbarPreferences(nsIScrollable::ScrollOrientation_X,
|
|
|
|
NS_STYLE_OVERFLOW_HIDDEN);
|
|
|
|
} else {
|
|
|
|
sc->ResetScrollbarPreferences();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-04-20 03:56:45 +04:00
|
|
|
// Initial reflow
|
2002-04-17 08:17:16 +04:00
|
|
|
mPresShell->InitialReflow(width, height);
|
|
|
|
|
|
|
|
// Now trigger a refresh
|
|
|
|
if (mEnableRendering) {
|
|
|
|
mViewManager->EnableRefresh(NS_VMREFRESH_IMMEDIATE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// now register ourselves as a selection listener, so that we get
|
|
|
|
// called when the selection changes in the window
|
|
|
|
nsDocViewerSelectionListener *selectionListener =
|
|
|
|
new nsDocViewerSelectionListener();
|
|
|
|
NS_ENSURE_TRUE(selectionListener, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
|
|
|
selectionListener->Init(this);
|
|
|
|
|
|
|
|
// mSelectionListener is a owning reference
|
|
|
|
mSelectionListener = selectionListener;
|
|
|
|
|
|
|
|
nsCOMPtr<nsISelection> selection;
|
|
|
|
rv = GetDocumentSelection(getter_AddRefs(selection));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCOMPtr<nsISelectionPrivate> selPrivate(do_QueryInterface(selection));
|
|
|
|
rv = selPrivate->AddSelectionListener(mSelectionListener);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2002-05-21 23:37:28 +04:00
|
|
|
// Save old listener so we can unregister it
|
|
|
|
nsCOMPtr<nsIDOMFocusListener> mOldFocusListener = mFocusListener;
|
|
|
|
|
2002-04-17 08:17:16 +04:00
|
|
|
// focus listener
|
|
|
|
//
|
|
|
|
// now register ourselves as a focus listener, so that we get called
|
|
|
|
// when the focus changes in the window
|
|
|
|
nsDocViewerFocusListener *focusListener;
|
|
|
|
NS_NEWXPCOM(focusListener, nsDocViewerFocusListener);
|
|
|
|
NS_ENSURE_TRUE(focusListener, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
|
|
|
focusListener->Init(this);
|
|
|
|
|
|
|
|
// mFocusListener is a strong reference
|
|
|
|
mFocusListener = focusListener;
|
|
|
|
|
|
|
|
// get the DOM event receiver
|
|
|
|
nsCOMPtr<nsIDOMEventReceiver> erP(do_QueryInterface(mDocument));
|
|
|
|
NS_WARN_IF_FALSE(erP, "No event receiver in document!");
|
|
|
|
|
|
|
|
if (erP) {
|
|
|
|
rv = erP->AddEventListenerByIID(mFocusListener,
|
|
|
|
NS_GET_IID(nsIDOMFocusListener));
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "failed to register focus listener");
|
2002-05-21 23:37:28 +04:00
|
|
|
if (mOldFocusListener) {
|
|
|
|
rv = erP->RemoveEventListenerByIID(mOldFocusListener,
|
|
|
|
NS_GET_IID(nsIDOMFocusListener));
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "failed to remove focus listener");
|
|
|
|
}
|
2002-04-17 08:17:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-03-26 14:43:40 +03:00
|
|
|
//-----------------------------------------------
|
|
|
|
// This method can be used to initial the "presentation"
|
|
|
|
// The aDoCreation indicates whether it should create
|
|
|
|
// all the new objects or just initialize the existing ones
|
|
|
|
nsresult
|
|
|
|
DocumentViewerImpl::InitInternal(nsIWidget* aParentWidget,
|
|
|
|
nsIDeviceContext* aDeviceContext,
|
|
|
|
const nsRect& aBounds,
|
|
|
|
PRBool aDoCreation)
|
1999-05-06 23:25:40 +04:00
|
|
|
{
|
2001-11-14 14:24:03 +03:00
|
|
|
mParentWidget = aParentWidget; // not ref counted
|
2001-11-03 17:59:39 +03:00
|
|
|
|
2002-04-17 08:17:16 +04:00
|
|
|
nsresult rv = NS_OK;
|
2001-03-10 06:19:36 +03:00
|
|
|
NS_ENSURE_TRUE(mDocument, NS_ERROR_NULL_POINTER);
|
1999-05-06 23:25:40 +04:00
|
|
|
|
|
|
|
mDeviceContext = dont_QueryInterface(aDeviceContext);
|
2002-04-17 08:17:16 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
#if defined(NS_PRINTING) && defined(NS_PRINT_PREVIEW)
|
2001-11-03 17:59:39 +03:00
|
|
|
// Clear PrintPreview Alternate Device
|
|
|
|
if (mDeviceContext) {
|
|
|
|
mDeviceContext->SetAltDevice(nsnull);
|
2001-11-29 12:59:16 +03:00
|
|
|
mDeviceContext->SetCanonicalPixelScale(1.0);
|
2001-11-03 17:59:39 +03:00
|
|
|
}
|
|
|
|
#endif
|
1999-05-06 23:25:40 +04:00
|
|
|
|
|
|
|
PRBool makeCX = PR_FALSE;
|
2002-03-26 14:43:40 +03:00
|
|
|
if (aDoCreation) {
|
2002-04-17 08:17:16 +04:00
|
|
|
if (aParentWidget && !mPresContext) {
|
2002-03-26 14:43:40 +03:00
|
|
|
// Create presentation context
|
2002-08-21 16:01:05 +04:00
|
|
|
if (GetIsCreatingPrintPreview()) {
|
2002-04-17 08:17:16 +04:00
|
|
|
mPresContext = do_CreateInstance(kPrintPreviewContextCID, &rv);
|
2002-03-26 14:43:40 +03:00
|
|
|
} else {
|
2002-04-17 08:17:16 +04:00
|
|
|
mPresContext = do_CreateInstance(kGalleyContextCID, &rv);
|
2002-03-26 14:43:40 +03:00
|
|
|
}
|
2002-04-17 08:17:16 +04:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
1999-05-06 23:25:40 +04:00
|
|
|
|
2002-03-26 14:43:40 +03:00
|
|
|
mPresContext->Init(aDeviceContext);
|
2002-04-17 08:17:16 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
#if defined(NS_PRINTING) && defined(NS_PRINT_PREVIEW)
|
|
|
|
makeCX = !GetIsPrintPreview(); // needs to be true except when we are already in PP
|
2001-11-14 14:24:03 +03:00
|
|
|
#else
|
2002-03-26 14:43:40 +03:00
|
|
|
makeCX = PR_TRUE;
|
2001-11-14 14:24:03 +03:00
|
|
|
#endif
|
2002-03-26 14:43:40 +03:00
|
|
|
}
|
1999-05-06 23:25:40 +04:00
|
|
|
}
|
|
|
|
|
2002-04-17 08:17:16 +04:00
|
|
|
if (aDoCreation && mPresContext) {
|
|
|
|
// Create the ViewManager and Root View...
|
2000-04-22 01:40:28 +04:00
|
|
|
|
2002-04-17 08:17:16 +04:00
|
|
|
// We must do this before we tell the script global object about
|
|
|
|
// this new document since doing that will cause us to re-enter
|
|
|
|
// into nsHTMLFrameInnerFrame code through reflows caused by
|
|
|
|
// FlushPendingNotifications() calls down the road...
|
2002-04-04 11:31:16 +04:00
|
|
|
|
2002-04-05 09:42:10 +04:00
|
|
|
rv = MakeWindow(aParentWidget, aBounds);
|
2002-04-17 08:17:16 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2002-04-05 09:42:10 +04:00
|
|
|
Hide();
|
2002-04-17 08:17:16 +04:00
|
|
|
}
|
2002-04-05 09:42:10 +04:00
|
|
|
|
2002-04-17 08:17:16 +04:00
|
|
|
nsCOMPtr<nsIInterfaceRequestor> requestor(do_QueryInterface(mContainer));
|
|
|
|
if (requestor) {
|
|
|
|
if (mPresContext) {
|
|
|
|
nsCOMPtr<nsILinkHandler> linkHandler;
|
|
|
|
requestor->GetInterface(NS_GET_IID(nsILinkHandler),
|
|
|
|
getter_AddRefs(linkHandler));
|
|
|
|
mPresContext->SetContainer(mContainer);
|
|
|
|
mPresContext->SetLinkHandler(linkHandler);
|
|
|
|
}
|
2002-04-05 09:42:10 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
if (!GetIsPrintPreview()) {
|
2002-04-17 08:17:16 +04:00
|
|
|
// Set script-context-owner in the document
|
2002-04-05 09:42:10 +04:00
|
|
|
|
2002-04-17 08:17:16 +04:00
|
|
|
nsCOMPtr<nsIScriptGlobalObject> global;
|
|
|
|
requestor->GetInterface(NS_GET_IID(nsIScriptGlobalObject),
|
|
|
|
getter_AddRefs(global));
|
2002-04-05 09:42:10 +04:00
|
|
|
|
2002-04-17 08:17:16 +04:00
|
|
|
if (global) {
|
|
|
|
mDocument->SetScriptGlobalObject(global);
|
|
|
|
nsCOMPtr<nsIDOMDocument> domdoc(do_QueryInterface(mDocument));
|
2002-04-04 11:31:16 +04:00
|
|
|
|
2002-04-17 08:17:16 +04:00
|
|
|
if (domdoc) {
|
2002-07-09 06:49:58 +04:00
|
|
|
global->SetNewDocument(domdoc, PR_TRUE, PR_TRUE);
|
2002-04-17 08:17:16 +04:00
|
|
|
}
|
2002-04-05 09:42:10 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-04-17 08:17:16 +04:00
|
|
|
if (aDoCreation && mPresContext) {
|
|
|
|
// The ViewManager and Root View was created above (in
|
|
|
|
// MakeWindow())...
|
2002-04-05 09:42:10 +04:00
|
|
|
|
2002-04-17 08:17:16 +04:00
|
|
|
rv = InitPresentationStuff(!makeCX);
|
2000-04-22 01:40:28 +04:00
|
|
|
}
|
2001-03-27 15:56:03 +04:00
|
|
|
|
1999-05-06 23:25:40 +04:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2000-09-06 13:11:38 +04:00
|
|
|
//
|
|
|
|
// LoadComplete(aStatus)
|
|
|
|
//
|
|
|
|
// aStatus - The status returned from loading the document.
|
|
|
|
//
|
|
|
|
// This method is called by the container when the document has been
|
|
|
|
// completely loaded.
|
|
|
|
//
|
2000-06-22 09:38:07 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
DocumentViewerImpl::LoadComplete(nsresult aStatus)
|
|
|
|
{
|
2000-11-28 02:23:28 +03:00
|
|
|
nsresult rv = NS_OK;
|
2001-03-10 06:19:36 +03:00
|
|
|
NS_ENSURE_TRUE(mDocument, NS_ERROR_NOT_AVAILABLE);
|
2000-09-06 13:11:38 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsIScriptGlobalObject> global;
|
|
|
|
|
|
|
|
// First, get the script global object from the document...
|
2001-03-10 06:19:36 +03:00
|
|
|
rv = mDocument->GetScriptGlobalObject(getter_AddRefs(global));
|
2000-09-06 13:11:38 +04:00
|
|
|
|
|
|
|
// Fail if no ScriptGlobalObject is available...
|
2002-04-17 08:17:16 +04:00
|
|
|
NS_ENSURE_TRUE(global, NS_ERROR_NULL_POINTER);
|
2000-09-06 13:11:38 +04:00
|
|
|
|
2001-05-02 02:50:16 +04:00
|
|
|
mLoaded = PR_TRUE;
|
|
|
|
|
2002-04-17 08:17:16 +04:00
|
|
|
/* We need to protect ourself against auto-destruction in case the
|
|
|
|
window is closed while processing the OnLoad event. See bug
|
|
|
|
http://bugzilla.mozilla.org/show_bug.cgi?id=78445 for more
|
|
|
|
explanation.
|
2001-05-12 21:40:12 +04:00
|
|
|
*/
|
2002-07-11 22:11:12 +04:00
|
|
|
nsCOMPtr<nsIDocumentViewer> kungFuDeathGrip(this);
|
2001-05-12 21:40:12 +04:00
|
|
|
|
2000-09-06 13:11:38 +04:00
|
|
|
// Now, fire either an OnLoad or OnError event to the document...
|
|
|
|
if(NS_SUCCEEDED(aStatus)) {
|
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
|
|
|
nsEvent event;
|
|
|
|
|
|
|
|
event.eventStructType = NS_EVENT;
|
|
|
|
event.message = NS_PAGE_LOAD;
|
|
|
|
rv = global->HandleDOMEvent(mPresContext, &event, nsnull,
|
|
|
|
NS_EVENT_FLAG_INIT, &status);
|
2001-11-27 02:13:36 +03:00
|
|
|
#ifdef MOZ_TIMELINE
|
|
|
|
// if navigator.xul's load is complete, the main nav window is visible
|
|
|
|
// mark that point.
|
2002-04-17 08:17:16 +04:00
|
|
|
|
2001-11-27 02:13:36 +03:00
|
|
|
if (mDocument) {
|
|
|
|
//printf("DEBUG: getting uri from document (%p)\n", mDocument.get());
|
2002-04-17 08:17:16 +04:00
|
|
|
|
2001-11-27 02:13:36 +03:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
mDocument->GetDocumentURL(getter_AddRefs(uri));
|
2002-04-17 08:17:16 +04:00
|
|
|
|
|
|
|
if (uri) {
|
2001-11-27 02:13:36 +03:00
|
|
|
//printf("DEBUG: getting spec fro uri (%p)\n", uri.get());
|
2002-03-06 10:48:55 +03:00
|
|
|
nsCAutoString spec;
|
|
|
|
uri->GetSpec(spec);
|
|
|
|
if (!strcmp(spec.get(), "chrome://navigator/content/navigator.xul")) {
|
2001-11-27 02:13:36 +03:00
|
|
|
NS_TIMELINE_MARK("Navigator Window visible now");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* MOZ_TIMELINE */
|
2000-09-06 13:11:38 +04:00
|
|
|
} else {
|
|
|
|
// XXX: Should fire error event to the document...
|
|
|
|
}
|
2002-04-17 08:17:16 +04:00
|
|
|
|
2001-04-25 23:52:49 +04:00
|
|
|
// Now that the document has loaded, we can tell the presshell
|
|
|
|
// to unsuppress painting.
|
2002-04-17 08:17:16 +04:00
|
|
|
if (mPresShell && !mStopped) {
|
2001-05-02 02:50:16 +04:00
|
|
|
mPresShell->UnsuppressPainting();
|
2002-04-17 08:17:16 +04:00
|
|
|
}
|
2000-09-06 13:11:38 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
#ifdef NS_PRINTING
|
2002-06-28 17:39:44 +04:00
|
|
|
// Check to see if someone tried to print during the load
|
|
|
|
if (mPrintIsPending) {
|
|
|
|
mPrintIsPending = PR_FALSE;
|
|
|
|
mPrintDocIsFullyLoaded = PR_TRUE;
|
|
|
|
Print(mCachedPrintSettings, mCachedPrintWebProgressListner);
|
|
|
|
mCachedPrintSettings = nsnull;
|
|
|
|
mCachedPrintWebProgressListner = nsnull;
|
|
|
|
}
|
2002-08-21 16:01:05 +04:00
|
|
|
#endif
|
2002-06-28 17:39:44 +04:00
|
|
|
|
2000-09-06 13:11:38 +04:00
|
|
|
return rv;
|
2000-06-22 09:38:07 +04:00
|
|
|
}
|
|
|
|
|
2001-07-18 00:17:38 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
DocumentViewerImpl::Unload()
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
if (!mDocument) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
|
|
|
|
// First, get the script global object from the document...
|
|
|
|
nsCOMPtr<nsIScriptGlobalObject> global;
|
|
|
|
|
|
|
|
rv = mDocument->GetScriptGlobalObject(getter_AddRefs(global));
|
|
|
|
if (!global) {
|
|
|
|
// Fail if no ScriptGlobalObject is available...
|
|
|
|
NS_ASSERTION(0, "nsIScriptGlobalObject not set for document!");
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now, fire an Unload event to the document...
|
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
|
|
|
nsEvent event;
|
|
|
|
|
|
|
|
event.eventStructType = NS_EVENT;
|
|
|
|
event.message = NS_PAGE_UNLOAD;
|
|
|
|
rv = global->HandleDOMEvent(mPresContext, &event, nsnull,
|
|
|
|
NS_EVENT_FLAG_INIT, &status);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2000-06-22 09:38:07 +04:00
|
|
|
NS_IMETHODIMP
|
2001-08-01 07:15:50 +04:00
|
|
|
DocumentViewerImpl::Close()
|
2000-06-22 09:38:07 +04:00
|
|
|
{
|
2001-08-01 07:15:50 +04:00
|
|
|
// All callers are supposed to call close to break circular
|
2001-03-10 06:19:36 +03:00
|
|
|
// references. If we do this stuff in the destructor, the
|
|
|
|
// destructor might never be called (especially if we're being
|
|
|
|
// used from JS.
|
|
|
|
|
2001-08-01 07:15:50 +04:00
|
|
|
// Close is also needed to disable scripts during paint suppression,
|
|
|
|
// since we transfer the existing global object to the new document
|
|
|
|
// that is loaded. In the future, the global object may become a proxy
|
|
|
|
// for an object that can be switched in and out so that we don't need
|
|
|
|
// to disable scripts during paint suppression.
|
|
|
|
|
2001-03-10 06:19:36 +03:00
|
|
|
if (mDocument) {
|
2002-08-21 16:01:05 +04:00
|
|
|
#if defined(NS_PRINTING) && defined(NS_PRINT_PREVIEW)
|
2002-04-17 08:17:16 +04:00
|
|
|
// Turn scripting back on
|
2001-11-03 17:59:39 +03:00
|
|
|
// after PrintPreview had turned it off
|
2002-08-21 16:01:05 +04:00
|
|
|
if (GetIsPrintPreview() && mPrintEngine) {
|
|
|
|
mPrintEngine->TurnScriptingOn(PR_TRUE);
|
2001-11-03 17:59:39 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2002-05-26 21:03:42 +04:00
|
|
|
// Before we clear the script global object, clear the undisplayed
|
|
|
|
// content map, since XBL content can be destroyed by the
|
|
|
|
// |SetDocument(null, ...)| triggered by calling
|
|
|
|
// |SetScriptGlobalObject(null)|.
|
|
|
|
if (mPresShell) {
|
|
|
|
nsCOMPtr<nsIFrameManager> frameManager;
|
|
|
|
mPresShell->GetFrameManager(getter_AddRefs(frameManager));
|
|
|
|
if (frameManager)
|
|
|
|
frameManager->ClearUndisplayedContentMap();
|
|
|
|
}
|
|
|
|
|
2001-03-10 06:19:36 +03:00
|
|
|
// Break global object circular reference on the document created
|
|
|
|
// in the DocViewer Init
|
|
|
|
nsCOMPtr<nsIScriptGlobalObject> globalObject;
|
|
|
|
mDocument->GetScriptGlobalObject(getter_AddRefs(globalObject));
|
2002-04-17 08:17:16 +04:00
|
|
|
|
2001-03-10 06:19:36 +03:00
|
|
|
if (globalObject) {
|
2002-07-09 06:49:58 +04:00
|
|
|
globalObject->SetNewDocument(nsnull, PR_TRUE, PR_TRUE);
|
2001-03-10 06:19:36 +03:00
|
|
|
}
|
2002-04-17 08:17:16 +04:00
|
|
|
|
2001-03-10 06:19:36 +03:00
|
|
|
// out of band cleanup of webshell
|
|
|
|
mDocument->SetScriptGlobalObject(nsnull);
|
2002-04-17 08:17:16 +04:00
|
|
|
|
2001-03-10 06:19:36 +03:00
|
|
|
if (mFocusListener) {
|
|
|
|
// get the DOM event receiver
|
2002-04-17 08:17:16 +04:00
|
|
|
nsCOMPtr<nsIDOMEventReceiver> erP(do_QueryInterface(mDocument));
|
|
|
|
NS_WARN_IF_FALSE(erP, "No event receiver in document!");
|
|
|
|
|
|
|
|
if (erP) {
|
|
|
|
erP->RemoveEventListenerByIID(mFocusListener,
|
|
|
|
NS_GET_IID(nsIDOMFocusListener));
|
|
|
|
}
|
2001-03-10 06:19:36 +03:00
|
|
|
}
|
2002-04-17 08:17:16 +04:00
|
|
|
}
|
2001-03-10 06:19:36 +03:00
|
|
|
|
2001-08-01 07:15:50 +04:00
|
|
|
mDocument = nsnull;
|
2002-04-17 08:17:16 +04:00
|
|
|
|
2001-08-01 07:15:50 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
DocumentViewerImpl::Destroy()
|
|
|
|
{
|
2002-08-21 16:01:05 +04:00
|
|
|
#ifdef NS_PRINTING
|
2002-03-23 19:48:58 +03:00
|
|
|
// Here is where we check to see if the docment was still being prepared
|
|
|
|
// for printing when it was asked to be destroy from someone externally
|
|
|
|
// This usually happens if the document is unloaded while the user is in the Print Dialog
|
|
|
|
//
|
|
|
|
// So we flip the bool to remember that the document is going away
|
|
|
|
// and we can clean up and abort later after returning from the Print Dialog
|
2002-08-21 16:01:05 +04:00
|
|
|
if (mPrintEngine) {
|
|
|
|
if (mPrintEngine->CheckBeforeDestroy()) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2002-03-23 19:48:58 +03:00
|
|
|
}
|
2002-08-21 16:01:05 +04:00
|
|
|
#endif
|
2002-03-23 19:48:58 +03:00
|
|
|
|
|
|
|
// Don't let the document get unloaded while we are printing
|
|
|
|
// this could happen if we hit the back button during printing
|
2001-08-06 06:27:43 +04:00
|
|
|
if (mDestroyRefCount != 0) {
|
|
|
|
--mDestroyRefCount;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-08-01 07:15:50 +04:00
|
|
|
// All callers are supposed to call destroy to break circular
|
|
|
|
// references. If we do this stuff in the destructor, the
|
|
|
|
// destructor might never be called (especially if we're being
|
|
|
|
// used from JS.
|
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
#ifdef NS_PRINTING
|
|
|
|
if (mPrintEngine) {
|
|
|
|
mPrintEngine->Destroy();
|
|
|
|
NS_RELEASE(mPrintEngine);
|
2002-02-01 17:52:11 +03:00
|
|
|
}
|
2001-11-03 17:59:39 +03:00
|
|
|
#endif
|
|
|
|
|
2001-08-01 07:15:50 +04:00
|
|
|
// Avoid leaking the old viewer.
|
|
|
|
if (mPreviousViewer) {
|
|
|
|
mPreviousViewer->Destroy();
|
|
|
|
mPreviousViewer = nsnull;
|
|
|
|
}
|
|
|
|
|
2002-04-17 08:17:16 +04:00
|
|
|
if (mDeviceContext) {
|
2001-03-10 06:19:36 +03:00
|
|
|
mDeviceContext->FlushFontCache();
|
2002-04-17 08:17:16 +04:00
|
|
|
mDeviceContext = nsnull;
|
|
|
|
}
|
2001-03-10 06:19:36 +03:00
|
|
|
|
|
|
|
if (mPresShell) {
|
|
|
|
// Break circular reference (or something)
|
|
|
|
mPresShell->EndObservingDocument();
|
2002-04-17 08:17:16 +04:00
|
|
|
|
2001-03-10 06:19:36 +03:00
|
|
|
nsCOMPtr<nsISelection> selection;
|
2002-04-17 08:17:16 +04:00
|
|
|
GetDocumentSelection(getter_AddRefs(selection));
|
|
|
|
|
2001-03-10 06:19:36 +03:00
|
|
|
nsCOMPtr<nsISelectionPrivate> selPrivate(do_QueryInterface(selection));
|
2002-04-17 08:17:16 +04:00
|
|
|
|
|
|
|
if (selPrivate && mSelectionListener)
|
2001-03-10 06:19:36 +03:00
|
|
|
selPrivate->RemoveSelectionListener(mSelectionListener);
|
2002-04-17 08:17:16 +04:00
|
|
|
|
2001-08-01 07:15:50 +04:00
|
|
|
mPresShell->Destroy();
|
|
|
|
mPresShell = nsnull;
|
2001-03-10 06:19:36 +03:00
|
|
|
}
|
2002-04-17 08:17:16 +04:00
|
|
|
|
2001-03-10 06:19:36 +03:00
|
|
|
return NS_OK;
|
2000-06-22 09:38:07 +04:00
|
|
|
}
|
|
|
|
|
1999-05-06 23:25:40 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
DocumentViewerImpl::Stop(void)
|
|
|
|
{
|
2001-03-10 06:19:36 +03:00
|
|
|
NS_ASSERTION(mDocument, "Stop called too early or too late");
|
Landing changes Vidur made while the tree was closed for beta1 work, here's a list of the changes. r=me
[1] Cutting down the size of content. Made nsIJSScriptObject inherit from nsIScriptObjectOwner
[2] Cutting down the size of content. Made nsITextContent inherit from nsIContent.
[3] Cutting down the size of content. Moved implementation of nsIDOMReceiver to nsListenerManager. This is not true aggregation since it isn't transitive, but it's OK for now. It will be necessary for nsListenerManager to have a reference to its content in the future anyway, so the transitivity could be done.
dom/public/nsDOMPropEnums.h,v - bug 12559
dom/public/nsIJSScriptObject.h,v - [1]
dom/public/html/MANIFEST,v - bug 12559
dom/public/html/Makefile.in,v - bug 12559
dom/public/html/makefile.win,v - bug 12559
dom/public/html/nsIDOMHTMLInputElement.h,v - bug 17544
dom/public/idl/html/HTMLAnchorElement.idl,v - bug 12559
dom/public/idl/html/HTMLAreaElement.idl,v - bug 12559
dom/public/idl/html/HTMLInputElement.idl,v - bug 17544
dom/src/base/nsGlobalWindow.cpp,v - bug 30700
dom/src/base/nsGlobalWindow.h,v - [1]
dom/src/base/nsLocation.cpp,v - [1]
dom/src/html/nsJSHTMLAnchorElement.cpp,v - bug 12559
dom/src/html/nsJSHTMLAreaElement.cpp,v - bug 12559
dom/src/html/nsJSHTMLInputElement.cpp,v - bug 17544
layout/base/public/nsIDocument.h,v - bug 27953
layout/base/public/nsITextContent.h,v - [2]
layout/base/src/nsCommentNode.cpp,v - [2]
layout/base/src/nsDocument.cpp,v - bug 27953
layout/base/src/nsDocument.h,v - bug 27953
layout/base/src/nsDocumentViewer.cpp,v - bug 27953
layout/base/src/nsGenericDOMDataNode.cpp,v - [3]
layout/base/src/nsGenericDOMDataNode.h,v - [3]
layout/base/src/nsGenericElement.cpp,v - [3]
layout/base/src/nsGenericElement.h,v - [3]
layout/base/src/nsNameSpaceManager.cpp,v - bug 7834
layout/base/src/nsStyleContext.cpp,v - outline property shouldn't reflow
layout/base/src/nsTextNode.cpp,v - [2]
layout/events/src/nsEventListenerManager.cpp,v - [3]
layout/events/src/nsEventListenerManager.h,v - [3]
layout/html/base/src/nsGfxScrollFrame.cpp,v - nsString->nsAutoString
layout/html/content/src/nsAttributeContent.cpp,v - [2]
layout/html/content/src/nsHTMLAnchorElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLAppletElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLAreaElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLBRElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLBaseElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLBaseFontElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLBodyElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLButtonElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLDListElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLDelElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLDirectoryElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLDivElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLEmbedElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLFieldSetElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLFontElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLFormElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLFrameElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLFrameSetElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLHRElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLHeadElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLHeadingElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLHtmlElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLIFrameElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLImageElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLInputElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLInsElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLIsIndexElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLLIElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLLabelElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLLayerElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLLegendElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLLinkElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLMapElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLMenuElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLMetaElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLModElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLOListElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLObjectElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLOptGroupElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLOptionElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLParagraphElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLParamElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLPreElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLQuoteElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLScriptElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLSelectElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLSpacerElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLSpanElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLStyleElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLTableCaptionElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLTableCellElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLTableColElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLTableColGroupElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLTableElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLTableRowElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLTableSectionElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLTextAreaElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLTitleElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLUListElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLWBRElement.cpp,v - [1][3]
layout/html/document/src/nsHTMLDocument.cpp,v - bug 27953
layout/html/document/src/nsHTMLDocument.h,v - bug 27953
layout/xml/content/src/nsXMLCDATASection.cpp,v - [1][2]
layout/xml/content/src/nsXMLDocumentType.cpp,v - [1][2]
layout/xml/content/src/nsXMLElement.h,v - [1][2]
layout/xml/content/src/nsXMLEntity.cpp,v - [1][2]
layout/xml/content/src/nsXMLNotation.cpp,v - [1][2]
layout/xml/content/src/nsXMLProcessingInstruction.cpp,v - [1][2]
layout/xul/base/src/nsBoxFrame.cpp,v - nsString->nsAutoString
layout/xul/base/src/nsSliderFrame.cpp,v - nsString->nsAutoString
netwerk/protocol/http/src/nsHTTPRequest.cpp,v - nsString->nsAutoString
rdf/content/src/nsXULDocument.cpp,v - bug 27953
rdf/content/src/nsXULDocument.h,v - bug 27953
rdf/content/src/nsXULElement.h,v - [1]
xpcom/base/IIDS.h,v - bug 12559
2000-03-17 16:27:00 +03:00
|
|
|
if (mDocument) {
|
|
|
|
mDocument->StopDocumentLoad();
|
|
|
|
}
|
|
|
|
|
2001-05-02 02:50:16 +04:00
|
|
|
mStopped = PR_TRUE;
|
|
|
|
|
|
|
|
if (!mLoaded && mPresShell) {
|
|
|
|
// Well, we might as well paint what we have so far.
|
|
|
|
mPresShell->UnsuppressPainting();
|
1999-05-06 23:25:40 +04:00
|
|
|
}
|
2001-04-25 23:52:49 +04:00
|
|
|
|
1999-05-06 23:25:40 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-06-22 09:38:07 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
DocumentViewerImpl::GetDOMDocument(nsIDOMDocument **aResult)
|
|
|
|
{
|
2001-03-10 06:19:36 +03:00
|
|
|
NS_ENSURE_TRUE(mDocument, NS_ERROR_NOT_AVAILABLE);
|
2000-06-22 09:38:07 +04:00
|
|
|
return CallQueryInterface(mDocument.get(), aResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
DocumentViewerImpl::SetDOMDocument(nsIDOMDocument *aDocument)
|
|
|
|
{
|
2000-09-02 19:32:28 +04:00
|
|
|
// Assumptions:
|
|
|
|
//
|
|
|
|
// 1) this document viewer has been initialized with a call to Init().
|
2002-04-17 08:17:16 +04:00
|
|
|
// 2) the stylesheets associated with the document have been added
|
|
|
|
// to the document.
|
2000-09-02 19:32:28 +04:00
|
|
|
|
2002-04-17 08:17:16 +04:00
|
|
|
// XXX Right now, this method assumes that the layout of the current
|
|
|
|
// document hasn't started yet. More cleanup will probably be
|
|
|
|
// necessary to make this method work for the case when layout *has*
|
|
|
|
// occurred for the current document.
|
2000-09-02 19:32:28 +04:00
|
|
|
// That work can happen when and if it is needed.
|
2002-04-17 08:17:16 +04:00
|
|
|
|
2000-09-02 19:32:28 +04:00
|
|
|
nsresult rv;
|
2002-04-17 08:17:16 +04:00
|
|
|
if (!aDocument)
|
2000-09-02 19:32:28 +04:00
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocument> newDoc = do_QueryInterface(aDocument, &rv);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
// 0) Replace the old document with the new one
|
|
|
|
mDocument = newDoc;
|
|
|
|
|
|
|
|
// 1) Set the script global object on the new document
|
2002-04-17 08:17:16 +04:00
|
|
|
nsCOMPtr<nsIScriptGlobalObject> global(do_GetInterface(mContainer));
|
2002-04-05 02:42:19 +04:00
|
|
|
|
2002-04-17 08:17:16 +04:00
|
|
|
if (global) {
|
|
|
|
mDocument->SetScriptGlobalObject(global);
|
2002-07-09 06:49:58 +04:00
|
|
|
global->SetNewDocument(aDocument, PR_TRUE, PR_TRUE);
|
2002-04-05 02:42:19 +04:00
|
|
|
|
2002-04-17 08:17:16 +04:00
|
|
|
rv = SyncParentSubDocMap();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2002-04-05 02:42:19 +04:00
|
|
|
|
2002-04-17 08:17:16 +04:00
|
|
|
// 2) Replace the current pres shell with a new shell for the new document
|
2002-04-05 02:42:19 +04:00
|
|
|
|
2002-04-17 08:17:16 +04:00
|
|
|
if (mPresShell) {
|
|
|
|
mPresShell->EndObservingDocument();
|
|
|
|
mPresShell->Destroy();
|
|
|
|
|
|
|
|
mPresShell = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
// And if we're already given a prescontext...
|
|
|
|
if (mPresContext) {
|
|
|
|
// 3) Create a new style set for the document
|
|
|
|
|
|
|
|
nsCOMPtr<nsIStyleSet> styleSet;
|
|
|
|
rv = CreateStyleSet(mDocument, getter_AddRefs(styleSet));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
rv = newDoc->CreateShell(mPresContext, mViewManager, styleSet,
|
|
|
|
getter_AddRefs(mPresShell));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
mPresShell->BeginObservingDocument();
|
|
|
|
|
|
|
|
// 4) Register the focus listener on the new document
|
2000-09-02 19:32:28 +04:00
|
|
|
|
2001-08-01 07:15:50 +04:00
|
|
|
nsCOMPtr<nsIDOMEventReceiver> erP = do_QueryInterface(mDocument, &rv);
|
2002-04-17 08:17:16 +04:00
|
|
|
NS_WARN_IF_FALSE(erP, "No event receiver in document!");
|
2000-09-02 19:32:28 +04:00
|
|
|
|
2002-04-17 08:17:16 +04:00
|
|
|
if (erP) {
|
|
|
|
rv = erP->AddEventListenerByIID(mFocusListener,
|
|
|
|
NS_GET_IID(nsIDOMFocusListener));
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "failed to register focus listener");
|
|
|
|
}
|
2000-09-02 19:32:28 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
2000-06-22 09:38:07 +04:00
|
|
|
}
|
|
|
|
|
1999-05-06 23:25:40 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
DocumentViewerImpl::SetUAStyleSheet(nsIStyleSheet* aUAStyleSheet)
|
|
|
|
{
|
2002-05-24 03:09:31 +04:00
|
|
|
NS_ASSERTION(aUAStyleSheet, "unexpected null pointer");
|
2002-01-22 08:36:50 +03:00
|
|
|
if (aUAStyleSheet) {
|
|
|
|
nsCOMPtr<nsICSSStyleSheet> sheet(do_QueryInterface(aUAStyleSheet));
|
|
|
|
nsCOMPtr<nsICSSStyleSheet> newSheet;
|
|
|
|
sheet->Clone(*getter_AddRefs(newSheet));
|
|
|
|
mUAStyleSheet = newSheet;
|
|
|
|
}
|
1999-05-06 23:25:40 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2002-04-17 08:17:16 +04:00
|
|
|
|
1999-05-06 23:25:40 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
DocumentViewerImpl::GetDocument(nsIDocument*& aResult)
|
|
|
|
{
|
|
|
|
aResult = mDocument;
|
|
|
|
NS_IF_ADDREF(aResult);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2002-04-17 08:17:16 +04:00
|
|
|
|
1999-05-06 23:25:40 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
DocumentViewerImpl::GetPresShell(nsIPresShell*& aResult)
|
|
|
|
{
|
|
|
|
aResult = mPresShell;
|
|
|
|
NS_IF_ADDREF(aResult);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2002-04-17 08:17:16 +04:00
|
|
|
|
1999-05-06 23:25:40 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
DocumentViewerImpl::GetPresContext(nsIPresContext*& aResult)
|
|
|
|
{
|
|
|
|
aResult = mPresContext;
|
|
|
|
NS_IF_ADDREF(aResult);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
DocumentViewerImpl::GetBounds(nsRect& aResult)
|
|
|
|
{
|
2001-03-10 06:19:36 +03:00
|
|
|
NS_ENSURE_TRUE(mDocument, NS_ERROR_NOT_AVAILABLE);
|
1999-05-06 23:25:40 +04:00
|
|
|
NS_PRECONDITION(mWindow, "null window");
|
|
|
|
if (mWindow) {
|
|
|
|
mWindow->GetBounds(aResult);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
aResult.SetRect(0, 0, 0, 0);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-05-02 02:50:16 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
DocumentViewerImpl::GetPreviousViewer(nsIContentViewer** aViewer)
|
|
|
|
{
|
|
|
|
*aViewer = mPreviousViewer;
|
|
|
|
NS_IF_ADDREF(*aViewer);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
DocumentViewerImpl::SetPreviousViewer(nsIContentViewer* aViewer)
|
|
|
|
{
|
2001-08-01 07:15:50 +04:00
|
|
|
// NOTE: |Show| sets |mPreviousViewer| to null without calling this
|
|
|
|
// function.
|
|
|
|
|
|
|
|
if (aViewer) {
|
|
|
|
NS_ASSERTION(!mPreviousViewer,
|
|
|
|
"can't set previous viewer when there already is one");
|
2001-05-02 02:50:16 +04:00
|
|
|
|
|
|
|
// In a multiple chaining situation (which occurs when running a thrashing
|
2002-04-17 08:17:16 +04:00
|
|
|
// test like i-bench or jrgm's tests with no delay), we can build up a
|
2001-05-02 02:50:16 +04:00
|
|
|
// whole chain of viewers. In order to avoid this, we always set our previous
|
|
|
|
// viewer to the MOST previous viewer in the chain, and then dump the intermediate
|
|
|
|
// link from the chain. This ensures that at most only 2 documents are alive
|
|
|
|
// and undestroyed at any given time (the one that is showing and the one that
|
|
|
|
// is loading with painting suppressed).
|
|
|
|
nsCOMPtr<nsIContentViewer> prevViewer;
|
|
|
|
aViewer->GetPreviousViewer(getter_AddRefs(prevViewer));
|
|
|
|
if (prevViewer) {
|
2001-08-01 07:15:50 +04:00
|
|
|
aViewer->SetPreviousViewer(nsnull);
|
|
|
|
aViewer->Destroy();
|
|
|
|
return SetPreviousViewer(prevViewer);
|
2001-05-02 02:50:16 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mPreviousViewer = aViewer;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-05-06 23:25:40 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
DocumentViewerImpl::SetBounds(const nsRect& aBounds)
|
|
|
|
{
|
2001-03-10 06:19:36 +03:00
|
|
|
NS_ENSURE_TRUE(mDocument, NS_ERROR_NOT_AVAILABLE);
|
2002-04-17 08:17:16 +04:00
|
|
|
|
1999-05-06 23:25:40 +04:00
|
|
|
if (mWindow) {
|
|
|
|
// Don't have the widget repaint. Layout will generate repaint requests
|
|
|
|
// during reflow
|
|
|
|
mWindow->Resize(aBounds.x, aBounds.y, aBounds.width, aBounds.height,
|
|
|
|
PR_FALSE);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
DocumentViewerImpl::Move(PRInt32 aX, PRInt32 aY)
|
|
|
|
{
|
2001-03-10 06:19:36 +03:00
|
|
|
NS_ENSURE_TRUE(mDocument, NS_ERROR_NOT_AVAILABLE);
|
1999-05-06 23:25:40 +04:00
|
|
|
NS_PRECONDITION(mWindow, "null window");
|
|
|
|
if (mWindow) {
|
|
|
|
mWindow->Move(aX, aY);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
DocumentViewerImpl::Show(void)
|
|
|
|
{
|
2001-03-10 06:19:36 +03:00
|
|
|
NS_ENSURE_TRUE(mDocument, NS_ERROR_NOT_AVAILABLE);
|
2001-08-01 07:15:50 +04:00
|
|
|
|
|
|
|
// We don't need the previous viewer anymore since we're not
|
|
|
|
// displaying it.
|
|
|
|
if (mPreviousViewer) {
|
|
|
|
// This little dance *may* only be to keep
|
|
|
|
// PresShell::EndObservingDocument happy, but I'm not sure.
|
|
|
|
nsCOMPtr<nsIContentViewer> prevViewer(mPreviousViewer);
|
|
|
|
mPreviousViewer = nsnull;
|
|
|
|
prevViewer->Destroy();
|
|
|
|
}
|
|
|
|
|
1999-05-06 23:25:40 +04:00
|
|
|
if (mWindow) {
|
|
|
|
mWindow->Show(PR_TRUE);
|
|
|
|
}
|
2002-04-17 08:17:16 +04:00
|
|
|
|
|
|
|
if (mDocument && !mPresShell && !mWindow) {
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIBaseWindow> base_win(do_QueryInterface(mContainer));
|
|
|
|
NS_ENSURE_TRUE(base_win, NS_ERROR_UNEXPECTED);
|
|
|
|
|
|
|
|
base_win->GetParentWidget(&mParentWidget);
|
|
|
|
NS_ENSURE_TRUE(mParentWidget, NS_ERROR_UNEXPECTED);
|
|
|
|
|
|
|
|
mDeviceContext = dont_AddRef(mParentWidget->GetDeviceContext());
|
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
#if defined(NS_PRINTING) && defined(NS_PRINT_PREVIEW)
|
2002-04-17 08:17:16 +04:00
|
|
|
// Clear PrintPreview Alternate Device
|
|
|
|
if (mDeviceContext) {
|
|
|
|
mDeviceContext->SetAltDevice(nsnull);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Create presentation context
|
2002-08-21 16:01:05 +04:00
|
|
|
if (GetIsCreatingPrintPreview()) {
|
2002-04-17 08:17:16 +04:00
|
|
|
NS_ERROR("Whoa, we should not get here!");
|
|
|
|
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
mPresContext = do_CreateInstance(kGalleyContextCID, &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
mPresContext->Init(mDeviceContext);
|
|
|
|
|
|
|
|
nsRect tbounds;
|
|
|
|
mParentWidget->GetBounds(tbounds);
|
|
|
|
|
|
|
|
float p2t;
|
|
|
|
mPresContext->GetPixelsToTwips(&p2t);
|
|
|
|
tbounds *= p2t;
|
|
|
|
|
|
|
|
// Create the view manager
|
|
|
|
mViewManager = do_CreateInstance(kViewManagerCID);
|
|
|
|
NS_ENSURE_TRUE(mViewManager, NS_ERROR_NOT_AVAILABLE);
|
|
|
|
|
|
|
|
// Initialize the view manager with an offset. This allows the
|
|
|
|
// viewmanager to manage a coordinate space offset from (0,0)
|
|
|
|
rv = mViewManager->Init(mDeviceContext);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
rv = mViewManager->SetWindowOffset(tbounds.x, tbounds.y);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
// Reset the bounds offset so the root view is set to 0,0. The
|
|
|
|
// offset is specified in nsIViewManager::Init above.
|
|
|
|
// Besides, layout will reset the root view to (0,0) during reflow,
|
|
|
|
// so changing it to 0,0 eliminates placing the root view in the
|
|
|
|
// wrong place initially.
|
|
|
|
tbounds.x = 0;
|
|
|
|
tbounds.y = 0;
|
|
|
|
|
|
|
|
// Create a child window of the parent that is our "root
|
|
|
|
// view/window" Create a view
|
|
|
|
|
|
|
|
nsIView *view = nsnull;
|
|
|
|
rv = CallCreateInstance(kViewCID, &view);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
rv = view->Init(mViewManager, tbounds, nsnull);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
rv = view->CreateWidget(kWidgetCID, nsnull,
|
|
|
|
mParentWidget->GetNativeData(NS_NATIVE_WIDGET),
|
|
|
|
PR_TRUE, PR_FALSE);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
// Setup hierarchical relationship in view manager
|
|
|
|
mViewManager->SetRootView(view);
|
|
|
|
|
|
|
|
view->GetWidget(*getter_AddRefs(mWindow));
|
|
|
|
|
|
|
|
if (mPresContext && mContainer) {
|
|
|
|
nsCOMPtr<nsILinkHandler> linkHandler(do_GetInterface(mContainer));
|
|
|
|
|
|
|
|
if (linkHandler) {
|
|
|
|
mPresContext->SetLinkHandler(linkHandler);
|
|
|
|
}
|
|
|
|
|
|
|
|
mPresContext->SetContainer(mContainer);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mPresContext) {
|
|
|
|
Hide();
|
|
|
|
|
|
|
|
rv = InitPresentationStuff(PR_TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we get here the document load has already started and the
|
|
|
|
// window is shown because some JS on the page caused it to be
|
|
|
|
// shown...
|
|
|
|
|
|
|
|
mPresShell->UnsuppressPainting();
|
|
|
|
}
|
|
|
|
|
1999-05-06 23:25:40 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
DocumentViewerImpl::Hide(void)
|
|
|
|
{
|
2002-04-23 03:12:18 +04:00
|
|
|
PRBool is_in_print_mode = PR_FALSE;
|
2002-04-17 08:17:16 +04:00
|
|
|
|
2002-04-23 03:12:18 +04:00
|
|
|
GetDoingPrint(&is_in_print_mode);
|
2002-04-17 08:17:16 +04:00
|
|
|
|
2002-04-23 03:12:18 +04:00
|
|
|
if (is_in_print_mode) {
|
|
|
|
// If we, or one of our parents, is in print mode it means we're
|
|
|
|
// right now returning from print and the layout frame that was
|
|
|
|
// created for this document is being destroyed. In such a case we
|
|
|
|
// ignore the Hide() call.
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
GetDoingPrintPreview(&is_in_print_mode);
|
|
|
|
|
|
|
|
if (is_in_print_mode) {
|
2002-04-17 08:17:16 +04:00
|
|
|
// If we, or one of our parents, is in print preview mode it means
|
|
|
|
// we're right now returning from print preview and the layout
|
|
|
|
// frame that was created for this document is being destroyed. In
|
|
|
|
// such a case we ignore the Hide() call.
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-03-10 06:19:36 +03:00
|
|
|
NS_ENSURE_TRUE(mDocument, NS_ERROR_NOT_AVAILABLE);
|
1999-05-06 23:25:40 +04:00
|
|
|
NS_PRECONDITION(mWindow, "null window");
|
|
|
|
if (mWindow) {
|
|
|
|
mWindow->Show(PR_FALSE);
|
|
|
|
}
|
2002-04-17 08:17:16 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
if (!mPresShell || GetIsPrintPreview()) {
|
2002-04-17 08:17:16 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Avoid leaking the old viewer.
|
|
|
|
if (mPreviousViewer) {
|
|
|
|
mPreviousViewer->Destroy();
|
|
|
|
mPreviousViewer = nsnull;
|
|
|
|
}
|
|
|
|
|
2002-04-24 04:33:56 +04:00
|
|
|
if (mIsSticky) {
|
|
|
|
// This window is sticky, that means that it might be shown again
|
|
|
|
// and we don't want the presshell n' all that to be thrown away
|
|
|
|
// just because the window is hidden.
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-04-23 03:48:14 +04:00
|
|
|
if (mDeviceContext) {
|
2002-04-17 08:17:16 +04:00
|
|
|
mDeviceContext->FlushFontCache();
|
2002-04-23 03:48:14 +04:00
|
|
|
}
|
2002-04-17 08:17:16 +04:00
|
|
|
|
|
|
|
// Break circular reference (or something)
|
|
|
|
mPresShell->EndObservingDocument();
|
|
|
|
nsCOMPtr<nsISelection> selection;
|
|
|
|
|
|
|
|
GetDocumentSelection(getter_AddRefs(selection));
|
|
|
|
|
|
|
|
nsCOMPtr<nsISelectionPrivate> selPrivate(do_QueryInterface(selection));
|
|
|
|
|
2002-04-23 03:48:14 +04:00
|
|
|
if (selPrivate && mSelectionListener) {
|
2002-04-17 08:17:16 +04:00
|
|
|
selPrivate->RemoveSelectionListener(mSelectionListener);
|
2002-04-23 03:48:14 +04:00
|
|
|
}
|
2002-04-17 08:17:16 +04:00
|
|
|
|
2002-04-18 23:50:31 +04:00
|
|
|
nsCOMPtr<nsIXULDocument> xul_doc(do_QueryInterface(mDocument));
|
|
|
|
|
|
|
|
if (xul_doc) {
|
2002-04-23 03:48:14 +04:00
|
|
|
xul_doc->OnHide();
|
2002-04-18 23:50:31 +04:00
|
|
|
}
|
|
|
|
|
2002-04-17 08:17:16 +04:00
|
|
|
mPresShell->Destroy();
|
|
|
|
|
|
|
|
mPresShell = nsnull;
|
|
|
|
mPresContext = nsnull;
|
|
|
|
mViewManager = nsnull;
|
|
|
|
mWindow = nsnull;
|
|
|
|
mDeviceContext = nsnull;
|
|
|
|
mParentWidget = nsnull;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIBaseWindow> base_win(do_QueryInterface(mContainer));
|
|
|
|
|
|
|
|
if (base_win) {
|
|
|
|
base_win->SetParentWidget(nsnull);
|
|
|
|
}
|
|
|
|
|
1999-05-06 23:25:40 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2002-08-21 16:01:05 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
DocumentViewerImpl::SetEnableRendering(PRBool aOn)
|
2000-09-22 18:42:13 +04:00
|
|
|
{
|
2002-08-21 16:01:05 +04:00
|
|
|
NS_ENSURE_TRUE(mDocument, NS_ERROR_NOT_AVAILABLE);
|
|
|
|
mEnableRendering = aOn;
|
|
|
|
if (mViewManager) {
|
|
|
|
if (aOn) {
|
|
|
|
mViewManager->EnableRefresh(NS_VMREFRESH_IMMEDIATE);
|
|
|
|
nsIView* view;
|
|
|
|
mViewManager->GetRootView(view); // views are not refCounted
|
|
|
|
if (view) {
|
|
|
|
mViewManager->UpdateView(view, NS_VMREFRESH_IMMEDIATE);
|
2000-09-22 18:42:13 +04:00
|
|
|
}
|
|
|
|
}
|
2002-08-21 16:01:05 +04:00
|
|
|
else {
|
|
|
|
mViewManager->DisableRefresh();
|
|
|
|
}
|
2000-09-22 18:42:13 +04:00
|
|
|
}
|
2002-08-21 16:01:05 +04:00
|
|
|
return NS_OK;
|
2000-09-22 18:42:13 +04:00
|
|
|
}
|
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
DocumentViewerImpl::GetSticky(PRBool *aSticky)
|
2001-04-12 17:04:29 +04:00
|
|
|
{
|
2002-08-21 16:01:05 +04:00
|
|
|
*aSticky = mIsSticky;
|
2002-03-26 14:43:40 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2002-03-26 14:43:40 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
DocumentViewerImpl::SetSticky(PRBool aSticky)
|
|
|
|
{
|
|
|
|
mIsSticky = aSticky;
|
2002-03-26 14:43:40 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
return NS_OK;
|
2001-04-12 17:04:29 +04:00
|
|
|
}
|
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
DocumentViewerImpl::GetEnableRendering(PRBool* aResult)
|
|
|
|
{
|
|
|
|
NS_ENSURE_TRUE(mDocument, NS_ERROR_NOT_AVAILABLE);
|
|
|
|
NS_PRECONDITION(nsnull != aResult, "null OUT ptr");
|
|
|
|
if (aResult) {
|
|
|
|
*aResult = mEnableRendering;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
2002-01-25 17:30:14 +03:00
|
|
|
}
|
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
void
|
|
|
|
DocumentViewerImpl::ForceRefresh()
|
|
|
|
{
|
|
|
|
mWindow->Invalidate(PR_TRUE);
|
|
|
|
}
|
2001-01-27 17:09:34 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
nsresult
|
|
|
|
DocumentViewerImpl::CreateStyleSet(nsIDocument* aDocument,
|
|
|
|
nsIStyleSet** aStyleSet)
|
2002-02-19 14:49:27 +03:00
|
|
|
{
|
2002-08-21 16:01:05 +04:00
|
|
|
// this should eventually get expanded to allow for creating
|
|
|
|
// different sets for different media
|
|
|
|
nsresult rv;
|
2002-02-19 14:49:27 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
if (!mUAStyleSheet) {
|
|
|
|
NS_WARNING("unable to load UA style sheet");
|
2002-02-19 14:49:27 +03:00
|
|
|
}
|
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
rv = CallCreateInstance(kStyleSetCID, aStyleSet);
|
|
|
|
if (NS_OK == rv) {
|
|
|
|
PRInt32 index = 0;
|
|
|
|
aDocument->GetNumberOfStyleSheets(&index);
|
2001-01-27 17:09:34 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
while (0 < index--) {
|
|
|
|
nsCOMPtr<nsIStyleSheet> sheet;
|
|
|
|
aDocument->GetStyleSheetAt(index, getter_AddRefs(sheet));
|
2001-01-27 17:09:34 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
/*
|
|
|
|
* GetStyleSheetAt will return all style sheets in the document but
|
|
|
|
* we're only interested in the ones that are enabled.
|
|
|
|
*/
|
2001-01-27 17:09:34 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
PRBool styleEnabled;
|
|
|
|
sheet->GetEnabled(styleEnabled);
|
2001-01-27 17:09:34 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
if (styleEnabled) {
|
|
|
|
(*aStyleSet)->AddDocStyleSheet(sheet, aDocument);
|
2001-01-27 17:09:34 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
nsCOMPtr<nsIChromeRegistry> chromeRegistry =
|
|
|
|
do_GetService("@mozilla.org/chrome/chrome-registry;1");
|
2001-11-03 17:59:39 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
if (chromeRegistry) {
|
|
|
|
nsCOMPtr<nsISupportsArray> sheets;
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
// Now handle the user sheets.
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> docShell(do_QueryInterface(mContainer));
|
|
|
|
PRInt32 shellType;
|
|
|
|
docShell->GetItemType(&shellType);
|
|
|
|
PRBool isChrome = (shellType == nsIDocShellTreeItem::typeChrome);
|
|
|
|
sheets = nsnull;
|
|
|
|
chromeRegistry->GetUserSheets(isChrome, getter_AddRefs(sheets));
|
|
|
|
if(sheets){
|
|
|
|
nsCOMPtr<nsICSSStyleSheet> sheet;
|
|
|
|
PRUint32 count;
|
|
|
|
sheets->Count(&count);
|
|
|
|
for(PRUint32 i=0; i<count; i++) {
|
|
|
|
sheets->GetElementAt(i, getter_AddRefs(sheet));
|
|
|
|
(*aStyleSet)->AppendUserStyleSheet(sheet);
|
|
|
|
}
|
|
|
|
}
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
// Append chrome sheets (scrollbars + forms).
|
|
|
|
nsCOMPtr<nsIDocShell> ds(do_QueryInterface(mContainer));
|
|
|
|
chromeRegistry->GetAgentSheets(ds, getter_AddRefs(sheets));
|
|
|
|
if(sheets){
|
|
|
|
nsCOMPtr<nsICSSStyleSheet> sheet;
|
|
|
|
PRUint32 count;
|
|
|
|
sheets->Count(&count);
|
|
|
|
for(PRUint32 i=0; i<count; i++) {
|
|
|
|
sheets->GetElementAt(i, getter_AddRefs(sheet));
|
|
|
|
(*aStyleSet)->AppendAgentStyleSheet(sheet);
|
2001-04-12 17:04:29 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
if (mUAStyleSheet) {
|
|
|
|
(*aStyleSet)->AppendAgentStyleSheet(mUAStyleSheet);
|
|
|
|
}
|
2002-04-17 08:17:16 +04:00
|
|
|
}
|
2002-08-21 16:01:05 +04:00
|
|
|
return NS_OK;
|
2001-04-12 17:04:29 +04:00
|
|
|
}
|
2002-04-17 08:17:16 +04:00
|
|
|
|
2001-11-03 17:59:39 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
//---------------------------------------------------------------------
|
|
|
|
// Note this is also defined in nsPrintEngine
|
|
|
|
// They can't share it because nsPrintEngine may not be available
|
|
|
|
// when printing isn't turned on
|
|
|
|
static nsIPresShell*
|
|
|
|
GetPresShellFor(nsIDocShell* aDocShell)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMDocument> domDoc(do_GetInterface(aDocShell));
|
|
|
|
if (!domDoc) return nsnull;
|
2002-03-27 06:02:42 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
nsCOMPtr<nsIDocument> doc(do_QueryInterface(domDoc));
|
|
|
|
if (!doc) return nsnull;
|
2001-11-03 17:59:39 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
nsIPresShell* shell = nsnull;
|
|
|
|
doc->GetShellAt(0, &shell);
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
return shell;
|
2002-04-17 08:17:16 +04:00
|
|
|
}
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
//---------------------------------------------------------------------
|
|
|
|
// This gets ref counted copies of the PresShell and Root Content
|
|
|
|
// for a given nsIWebShell
|
|
|
|
void
|
|
|
|
DocumentViewerImpl::GetPresShellAndRootContent(nsIWebShell * aWebShell,
|
|
|
|
nsIPresShell** aPresShell,
|
|
|
|
nsIContent** aContent)
|
2001-04-12 17:04:29 +04:00
|
|
|
{
|
2002-08-21 16:01:05 +04:00
|
|
|
NS_ASSERTION(aWebShell, "Pointer is null!");
|
|
|
|
NS_ASSERTION(aPresShell, "Pointer is null!");
|
|
|
|
NS_ASSERTION(aContent, "Pointer is null!");
|
2002-06-20 01:51:13 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
*aContent = nsnull;
|
|
|
|
*aPresShell = nsnull;
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(aWebShell));
|
2001-01-27 17:09:34 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
nsCOMPtr<nsIPresShell> presShell(getter_AddRefs(GetPresShellFor(docShell)));
|
|
|
|
if (!presShell) return;
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
nsCOMPtr<nsIDocument> doc;
|
|
|
|
presShell->GetDocument(getter_AddRefs(doc));
|
|
|
|
if (!doc) return;
|
2001-01-27 17:09:34 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
doc->GetRootContent(aContent); // this addrefs
|
|
|
|
*aPresShell = presShell.get();
|
|
|
|
NS_ADDREF(*aPresShell);
|
2001-01-27 17:09:34 +03:00
|
|
|
}
|
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
//---------------------------------------------------------------------
|
|
|
|
nsresult
|
|
|
|
DocumentViewerImpl::FindFrameSetWithIID(nsIContent * aParentContent,
|
|
|
|
const nsIID& aIID)
|
|
|
|
{
|
|
|
|
PRInt32 numChildren;
|
|
|
|
aParentContent->ChildCount(numChildren);
|
2001-01-27 17:09:34 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
// do a breadth search across all siblings
|
|
|
|
PRInt32 inx;
|
|
|
|
for (inx=0;inx<numChildren;inx++) {
|
|
|
|
nsCOMPtr<nsIContent> child;
|
|
|
|
if (NS_SUCCEEDED(aParentContent->ChildAt(inx, *getter_AddRefs(child))) && child) {
|
|
|
|
nsCOMPtr<nsISupports> temp;
|
|
|
|
if (NS_SUCCEEDED(child->QueryInterface(aIID, (void**)getter_AddRefs(temp)))) {
|
|
|
|
return NS_OK;
|
2001-01-27 17:09:34 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-08-21 16:01:05 +04:00
|
|
|
|
|
|
|
return NS_ERROR_FAILURE;
|
2001-01-27 17:09:34 +03:00
|
|
|
}
|
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
//-------------------------------------------------------
|
|
|
|
PRBool
|
|
|
|
DocumentViewerImpl::IsWebShellAFrameSet(nsIWebShell * aWebShell)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aWebShell, "Pointer is null!");
|
2001-01-27 17:09:34 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
PRBool doesContainFrameSet = PR_FALSE;
|
|
|
|
nsCOMPtr<nsIPresShell> presShell;
|
|
|
|
nsCOMPtr<nsIContent> rootContent;
|
|
|
|
GetPresShellAndRootContent(aWebShell, getter_AddRefs(presShell), getter_AddRefs(rootContent));
|
|
|
|
if (rootContent) {
|
|
|
|
if (NS_SUCCEEDED(FindFrameSetWithIID(rootContent, NS_GET_IID(nsIDOMHTMLFrameSetElement)))) {
|
|
|
|
doesContainFrameSet = PR_TRUE;
|
2001-01-27 17:09:34 +03:00
|
|
|
}
|
|
|
|
}
|
2002-08-21 16:01:05 +04:00
|
|
|
return doesContainFrameSet;
|
2001-01-27 17:09:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
nsresult
|
|
|
|
DocumentViewerImpl::MakeWindow(nsIWidget* aParentWidget,
|
|
|
|
const nsRect& aBounds)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
2001-01-27 17:09:34 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
mViewManager = do_CreateInstance(kViewManagerCID, &rv);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2001-01-27 17:09:34 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
nsCOMPtr<nsIDeviceContext> dx;
|
|
|
|
mPresContext->GetDeviceContext(getter_AddRefs(dx));
|
2001-01-27 17:09:34 +03:00
|
|
|
|
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
nsRect tbounds = aBounds;
|
|
|
|
float p2t;
|
|
|
|
mPresContext->GetPixelsToTwips(&p2t);
|
|
|
|
tbounds *= p2t;
|
2001-01-27 17:09:34 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
// Initialize the view manager with an offset. This allows the viewmanager
|
|
|
|
// to manage a coordinate space offset from (0,0)
|
|
|
|
rv = mViewManager->Init(dx);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
rv = mViewManager->SetWindowOffset(tbounds.x, tbounds.y);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2001-01-27 17:09:34 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
// Reset the bounds offset so the root view is set to 0,0. The
|
|
|
|
// offset is specified in nsIViewManager::Init above.
|
|
|
|
// Besides, layout will reset the root view to (0,0) during reflow,
|
|
|
|
// so changing it to 0,0 eliminates placing the root view in the
|
|
|
|
// wrong place initially.
|
|
|
|
tbounds.x = 0;
|
|
|
|
tbounds.y = 0;
|
2001-01-27 17:09:34 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
// Create a child window of the parent that is our "root view/window"
|
|
|
|
// Create a view
|
2001-01-27 17:09:34 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
nsIView *view = nsnull;
|
|
|
|
rv = CallCreateInstance(kViewCID, &view);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
// if aParentWidget has a view, we'll hook our view manager up to its view tree
|
|
|
|
void* clientData;
|
|
|
|
nsIView* containerView = nsnull;
|
|
|
|
if (NS_SUCCEEDED(aParentWidget->GetClientData(clientData))) {
|
|
|
|
nsISupports* data = (nsISupports*)clientData;
|
2000-09-22 18:42:13 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
if (data) {
|
|
|
|
data->QueryInterface(NS_GET_IID(nsIView), (void **)&containerView);
|
2000-09-22 18:42:13 +04:00
|
|
|
}
|
2001-04-12 17:04:29 +04:00
|
|
|
}
|
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
if (containerView) {
|
|
|
|
// see if the containerView has already been hooked into a foreign view manager hierarchy
|
|
|
|
// if it has, then we have to hook into the hierarchy too otherwise bad things will happen.
|
|
|
|
nsCOMPtr<nsIViewManager> containerVM;
|
|
|
|
containerView->GetViewManager(*getter_AddRefs(containerVM));
|
|
|
|
nsCOMPtr<nsIViewManager> checkVM;
|
|
|
|
nsIView* pView = containerView;
|
|
|
|
do {
|
|
|
|
pView->GetParent(pView);
|
|
|
|
} while (pView != nsnull
|
|
|
|
&& NS_SUCCEEDED(pView->GetViewManager(*getter_AddRefs(checkVM))) && checkVM == containerVM);
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
if (!pView) {
|
|
|
|
// OK, so the container is not already hooked up into a foreign view manager hierarchy.
|
|
|
|
// That means we can choose not to hook ourselves up.
|
|
|
|
//
|
|
|
|
// If the parent container is a chrome shell, or a frameset, then we won't hook into its view
|
|
|
|
// tree. This will improve performance a little bit (especially given scrolling/painting perf bugs)
|
|
|
|
// but is really just for peace of mind. This check can be removed if we want to support fancy
|
|
|
|
// chrome effects like transparent controls floating over content, transparent Web browsers, and
|
|
|
|
// things like that, and the perf bugs are fixed.
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> container(do_QueryInterface(mContainer));
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> parentContainer;
|
|
|
|
PRInt32 itemType;
|
|
|
|
if (nsnull == container
|
|
|
|
|| NS_FAILED(container->GetParent(getter_AddRefs(parentContainer)))
|
|
|
|
|| nsnull == parentContainer
|
|
|
|
|| NS_FAILED(parentContainer->GetItemType(&itemType))
|
|
|
|
|| itemType != nsIDocShellTreeItem::typeContent) {
|
|
|
|
containerView = nsnull;
|
|
|
|
} else {
|
|
|
|
nsCOMPtr<nsIWebShell> webShell(do_QueryInterface(parentContainer));
|
|
|
|
if (nsnull == webShell || IsWebShellAFrameSet(webShell)) {
|
|
|
|
containerView = nsnull;
|
|
|
|
}
|
|
|
|
}
|
2001-04-12 17:04:29 +04:00
|
|
|
}
|
|
|
|
}
|
2001-02-07 02:03:17 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
rv = view->Init(mViewManager, tbounds, containerView);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2002-02-12 16:33:39 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
// pass in a native widget to be the parent widget ONLY if the view hierarchy will stand alone.
|
|
|
|
// otherwise the view will find its own parent widget and "do the right thing" to
|
|
|
|
// establish a parent/child widget relationship
|
|
|
|
rv = view->CreateWidget(kWidgetCID, nsnull,
|
|
|
|
containerView != nsnull ? nsnull : aParentWidget->GetNativeData(NS_NATIVE_WIDGET),
|
|
|
|
PR_TRUE, PR_FALSE);
|
|
|
|
if (rv != NS_OK)
|
|
|
|
return rv;
|
2002-02-12 16:33:39 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
// Setup hierarchical relationship in view manager
|
|
|
|
mViewManager->SetRootView(view);
|
2002-02-12 16:33:39 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
view->GetWidget(*getter_AddRefs(mWindow));
|
2002-02-12 16:33:39 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
// This SetFocus is necessary so the Arrow Key and Page Key events
|
|
|
|
// go to the scrolled view as soon as the Window is created instead of going to
|
|
|
|
// the browser window (this enables keyboard scrolling of the document)
|
|
|
|
// mWindow->SetFocus();
|
2002-02-12 16:33:39 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
return rv;
|
2002-02-12 16:33:39 +03:00
|
|
|
}
|
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
nsresult DocumentViewerImpl::GetDocumentSelection(nsISelection **aSelection,
|
|
|
|
nsIPresShell *aPresShell)
|
|
|
|
{
|
|
|
|
if (!aPresShell) {
|
|
|
|
if (!mPresShell) {
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
2002-01-08 04:17:40 +03:00
|
|
|
}
|
2002-08-21 16:01:05 +04:00
|
|
|
aPresShell = mPresShell;
|
|
|
|
}
|
|
|
|
if (!aSelection)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
if (!aPresShell)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
2002-01-08 04:17:40 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
nsCOMPtr<nsISelectionController> selcon;
|
|
|
|
selcon = do_QueryInterface(aPresShell);
|
|
|
|
if (selcon)
|
|
|
|
return selcon->GetSelection(nsISelectionController::SELECTION_NORMAL,
|
|
|
|
aSelection);
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2002-01-08 04:17:40 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
DocumentViewerImpl::CreateDocumentViewerUsing(nsIPresContext* aPresContext,
|
|
|
|
nsIDocumentViewer*& aResult)
|
|
|
|
{
|
|
|
|
if (!mDocument) {
|
|
|
|
// XXX better error
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
if (!aPresContext) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
2002-01-08 04:17:40 +03:00
|
|
|
}
|
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
// Create new viewer
|
|
|
|
DocumentViewerImpl* viewer = new DocumentViewerImpl(aPresContext);
|
|
|
|
if (!viewer) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2002-02-12 16:33:39 +03:00
|
|
|
}
|
2002-08-21 16:01:05 +04:00
|
|
|
NS_ADDREF(viewer);
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
// XXX make sure the ua style sheet is used (for now; need to be
|
|
|
|
// able to specify an alternate)
|
|
|
|
viewer->SetUAStyleSheet(mUAStyleSheet);
|
2002-02-12 16:33:39 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
// Bind the new viewer to the old document
|
|
|
|
nsresult rv = viewer->LoadStart(mDocument);
|
|
|
|
|
|
|
|
aResult = viewer;
|
2002-02-12 16:33:39 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
return rv;
|
2001-02-07 02:03:17 +03:00
|
|
|
}
|
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
#ifdef XP_MAC
|
|
|
|
#pragma mark -
|
|
|
|
#endif
|
2001-03-27 15:56:03 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
/* ========================================================================================
|
|
|
|
* nsIContentViewerEdit
|
|
|
|
* ======================================================================================== */
|
2001-03-27 15:56:03 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
NS_IMETHODIMP DocumentViewerImpl::Search()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(0, "NOT IMPLEMENTED");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
2001-03-27 15:56:03 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
NS_IMETHODIMP DocumentViewerImpl::GetSearchable(PRBool *aSearchable)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(0, "NOT IMPLEMENTED");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
2001-03-27 15:56:03 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
NS_IMETHODIMP DocumentViewerImpl::ClearSelection()
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsISelection> selection;
|
2001-03-27 15:56:03 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
rv = GetDocumentSelection(getter_AddRefs(selection));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
2001-08-06 06:27:43 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
return selection->CollapseToStart();
|
2001-03-27 15:56:03 +04:00
|
|
|
}
|
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
NS_IMETHODIMP DocumentViewerImpl::SelectAll()
|
|
|
|
{
|
|
|
|
// XXX this is a temporary implementation copied from nsWebShell
|
|
|
|
// for now. I think nsDocument and friends should have some helper
|
|
|
|
// functions to make this easier.
|
|
|
|
nsCOMPtr<nsISelection> selection;
|
|
|
|
nsresult rv;
|
|
|
|
rv = GetDocumentSelection(getter_AddRefs(selection));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
nsCOMPtr<nsIDOMHTMLDocument> htmldoc = do_QueryInterface(mDocument);
|
|
|
|
nsCOMPtr<nsIDOMNode> bodyNode;
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
if (htmldoc)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMHTMLElement>bodyElement;
|
|
|
|
rv = htmldoc->GetBody(getter_AddRefs(bodyElement));
|
|
|
|
if (NS_FAILED(rv) || !bodyElement) return rv;
|
2002-02-12 16:33:39 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
bodyNode = do_QueryInterface(bodyElement);
|
2002-01-01 15:58:53 +03:00
|
|
|
}
|
2002-08-21 16:01:05 +04:00
|
|
|
else if (mDocument)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIContent> rootContent;
|
|
|
|
mDocument->GetRootContent(getter_AddRefs(rootContent));
|
|
|
|
bodyNode = do_QueryInterface(rootContent);
|
2001-03-27 15:56:03 +04:00
|
|
|
}
|
2002-08-21 16:01:05 +04:00
|
|
|
if (!bodyNode) return NS_ERROR_FAILURE;
|
2001-03-27 15:56:03 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
rv = selection->RemoveAllRanges();
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
rv = selection->SelectAllChildren(bodyNode);
|
|
|
|
return rv;
|
|
|
|
}
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
NS_IMETHODIMP DocumentViewerImpl::CopySelection()
|
|
|
|
{
|
|
|
|
NS_ENSURE_TRUE(mPresShell, NS_ERROR_NOT_INITIALIZED);
|
|
|
|
return mPresShell->DoCopy();
|
|
|
|
}
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
NS_IMETHODIMP DocumentViewerImpl::CopyLinkLocation()
|
|
|
|
{
|
|
|
|
NS_ENSURE_TRUE(mPresShell, NS_ERROR_NOT_INITIALIZED);
|
|
|
|
nsCOMPtr<nsIDOMNode> node;
|
|
|
|
nsresult rv = GetPopupLinkNode(getter_AddRefs(node));
|
|
|
|
// make noise if we're not in a link
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
NS_ENSURE_TRUE(node, NS_ERROR_FAILURE);
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
nsAutoString locationText;
|
|
|
|
rv = mPresShell->GetLinkLocation(node, locationText);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
nsCOMPtr<nsIClipboardHelper> clipboard(do_GetService("@mozilla.org/widget/clipboardhelper;1", &rv));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
// copy the href onto the clipboard
|
|
|
|
return clipboard->CopyString(locationText);
|
|
|
|
}
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
NS_IMETHODIMP DocumentViewerImpl::CopyImageLocation()
|
|
|
|
{
|
|
|
|
NS_ENSURE_TRUE(mPresShell, NS_ERROR_NOT_INITIALIZED);
|
|
|
|
nsCOMPtr<nsIDOMNode> node;
|
|
|
|
nsresult rv = GetPopupImageNode(getter_AddRefs(node));
|
|
|
|
// make noise if we're not in an image
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
NS_ENSURE_TRUE(node, NS_ERROR_FAILURE);
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
nsAutoString locationText;
|
2002-08-29 05:01:31 +04:00
|
|
|
rv = mPresShell->GetImageLocation(node, locationText);
|
2002-08-21 16:01:05 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
nsCOMPtr<nsIClipboardHelper> clipboard(do_GetService("@mozilla.org/widget/clipboardhelper;1", &rv));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
// copy the href onto the clipboard
|
|
|
|
return clipboard->CopyString(locationText);
|
2001-04-12 17:04:29 +04:00
|
|
|
}
|
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
NS_IMETHODIMP DocumentViewerImpl::CopyImageContents()
|
2001-04-12 17:04:29 +04:00
|
|
|
{
|
2002-08-21 16:01:05 +04:00
|
|
|
NS_ENSURE_TRUE(mPresShell, NS_ERROR_NOT_INITIALIZED);
|
|
|
|
nsCOMPtr<nsIDOMNode> node;
|
|
|
|
nsresult rv = GetPopupImageNode(getter_AddRefs(node));
|
|
|
|
// make noise if we're not in an image
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
NS_ENSURE_TRUE(node, NS_ERROR_FAILURE);
|
|
|
|
return mPresShell->DoCopyImageContents(node);
|
2001-04-12 17:04:29 +04:00
|
|
|
}
|
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
NS_IMETHODIMP DocumentViewerImpl::GetCopyable(PRBool *aCopyable)
|
2001-04-12 17:04:29 +04:00
|
|
|
{
|
2002-08-21 16:01:05 +04:00
|
|
|
nsCOMPtr<nsISelection> selection;
|
|
|
|
nsresult rv;
|
|
|
|
rv = GetDocumentSelection(getter_AddRefs(selection));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
2002-04-17 08:17:16 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
PRBool isCollapsed;
|
|
|
|
selection->GetIsCollapsed(&isCollapsed);
|
2002-04-17 08:17:16 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
*aCopyable = !isCollapsed;
|
|
|
|
return NS_OK;
|
2001-04-12 17:04:29 +04:00
|
|
|
}
|
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
NS_IMETHODIMP DocumentViewerImpl::CutSelection()
|
2001-04-12 17:04:29 +04:00
|
|
|
{
|
2002-08-21 16:01:05 +04:00
|
|
|
NS_ASSERTION(0, "NOT IMPLEMENTED");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
NS_IMETHODIMP DocumentViewerImpl::GetCutable(PRBool *aCutable)
|
|
|
|
{
|
|
|
|
*aCutable = PR_FALSE; // mm, will this ever be called for an editable document?
|
|
|
|
return NS_OK;
|
2001-04-12 17:04:29 +04:00
|
|
|
}
|
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
NS_IMETHODIMP DocumentViewerImpl::Paste()
|
2001-04-12 17:04:29 +04:00
|
|
|
{
|
2002-08-21 16:01:05 +04:00
|
|
|
NS_ASSERTION(0, "NOT IMPLEMENTED");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
NS_IMETHODIMP DocumentViewerImpl::GetPasteable(PRBool *aPasteable)
|
|
|
|
{
|
|
|
|
*aPasteable = PR_FALSE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2002-04-11 04:33:24 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
#ifdef XP_MAC
|
|
|
|
#pragma mark -
|
|
|
|
#endif
|
2002-04-11 04:33:24 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
static NS_DEFINE_IID(kDeviceContextSpecFactoryCID, NS_DEVICE_CONTEXT_SPEC_FACTORY_CID);
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
/* ========================================================================================
|
|
|
|
* nsIContentViewerFile
|
|
|
|
* ======================================================================================== */
|
|
|
|
/** ---------------------------------------------------
|
|
|
|
* See documentation above in the nsIContentViewerfile class definition
|
|
|
|
* @update 01/24/00 dwc
|
|
|
|
*/
|
|
|
|
NS_IMETHODIMP
|
|
|
|
DocumentViewerImpl::Print(PRBool aSilent,
|
|
|
|
FILE * aDebugFile,
|
|
|
|
nsIPrintSettings* aPrintSettings)
|
2001-04-12 17:04:29 +04:00
|
|
|
{
|
2002-08-21 16:01:05 +04:00
|
|
|
#ifdef NS_PRINTING
|
|
|
|
nsCOMPtr<nsIPrintSettings> printSettings;
|
2002-01-12 15:31:05 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
#ifdef NS_DEBUG
|
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
mDebugFile = aDebugFile;
|
|
|
|
// if they don't pass in a PrintSettings, then make one
|
|
|
|
// it will have all the default values
|
|
|
|
printSettings = aPrintSettings;
|
|
|
|
nsCOMPtr<nsIPrintOptions> printOptions = do_GetService(sPrintOptionsContractID, &rv);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
// if they don't pass in a PrintSettings, then make one
|
|
|
|
if (printSettings == nsnull) {
|
|
|
|
printOptions->CreatePrintSettings(getter_AddRefs(printSettings));
|
2001-04-12 17:04:29 +04:00
|
|
|
}
|
2002-08-21 16:01:05 +04:00
|
|
|
NS_ASSERTION(printSettings, "You can't PrintPreview without a PrintSettings!");
|
2001-04-12 17:04:29 +04:00
|
|
|
}
|
2002-08-21 16:01:05 +04:00
|
|
|
if (printSettings) printSettings->SetPrintSilent(aSilent);
|
|
|
|
if (printSettings) printSettings->SetShowPrintProgress(PR_FALSE);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
return Print(printSettings, nsnull);
|
|
|
|
#else
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
#endif
|
2001-04-12 17:04:29 +04:00
|
|
|
}
|
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
// nsIContentViewerFile interface
|
|
|
|
NS_IMETHODIMP
|
|
|
|
DocumentViewerImpl::GetPrintable(PRBool *aPrintable)
|
2001-04-12 17:04:29 +04:00
|
|
|
{
|
2002-08-21 16:01:05 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aPrintable);
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
*aPrintable = !GetIsPrinting();
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2002-01-12 15:31:05 +03:00
|
|
|
return NS_OK;
|
2001-04-12 17:04:29 +04:00
|
|
|
}
|
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
#ifdef XP_MAC
|
|
|
|
#pragma mark -
|
|
|
|
#endif
|
|
|
|
|
|
|
|
//*****************************************************************************
|
|
|
|
// nsIMarkupDocumentViewer
|
|
|
|
//*****************************************************************************
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
NS_IMETHODIMP DocumentViewerImpl::ScrollToNode(nsIDOMNode* aNode)
|
2001-04-12 17:04:29 +04:00
|
|
|
{
|
2002-08-21 16:01:05 +04:00
|
|
|
NS_ENSURE_ARG(aNode);
|
|
|
|
NS_ENSURE_TRUE(mDocument, NS_ERROR_NOT_AVAILABLE);
|
|
|
|
nsCOMPtr<nsIPresShell> presShell;
|
|
|
|
NS_ENSURE_SUCCESS(GetPresShell(*(getter_AddRefs(presShell))), NS_ERROR_FAILURE);
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
// Get the nsIContent interface, because that's what we need to
|
|
|
|
// get the primary frame
|
2002-04-17 08:17:16 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
nsCOMPtr<nsIContent> content(do_QueryInterface(aNode));
|
|
|
|
NS_ENSURE_TRUE(content, NS_ERROR_FAILURE);
|
2002-04-17 08:17:16 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
// Get the primary frame
|
|
|
|
nsIFrame* frame; // Remember Frames aren't ref-counted. They are in their
|
|
|
|
// own special little world.
|
2002-04-17 08:17:16 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
NS_ENSURE_SUCCESS(presShell->GetPrimaryFrameFor(content, &frame),
|
|
|
|
NS_ERROR_FAILURE);
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
// tell the pres shell to scroll to the frame
|
|
|
|
NS_ENSURE_SUCCESS(presShell->ScrollFrameIntoView(frame,
|
|
|
|
NS_PRESSHELL_SCROLL_TOP,
|
|
|
|
NS_PRESSHELL_SCROLL_ANYWHERE),
|
|
|
|
NS_ERROR_FAILURE);
|
|
|
|
return NS_OK;
|
2001-04-12 17:04:29 +04:00
|
|
|
}
|
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
NS_IMETHODIMP DocumentViewerImpl::GetAllowPlugins(PRBool* aAllowPlugins)
|
2001-04-12 17:04:29 +04:00
|
|
|
{
|
2002-08-21 16:01:05 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aAllowPlugins);
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
*aAllowPlugins = mAllowPlugins;
|
|
|
|
return NS_OK;
|
2001-04-12 17:04:29 +04:00
|
|
|
}
|
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
NS_IMETHODIMP DocumentViewerImpl::SetAllowPlugins(PRBool aAllowPlugins)
|
2002-07-22 14:55:07 +04:00
|
|
|
{
|
2002-08-21 16:01:05 +04:00
|
|
|
mAllowPlugins = aAllowPlugins;
|
|
|
|
return NS_OK;
|
2002-07-22 14:55:07 +04:00
|
|
|
}
|
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
nsresult
|
|
|
|
DocumentViewerImpl::CallChildren(CallChildFunc aFunc, void* aClosure)
|
2001-04-12 17:04:29 +04:00
|
|
|
{
|
2002-08-21 16:01:05 +04:00
|
|
|
nsCOMPtr<nsIDocShellTreeNode> docShellNode(do_QueryInterface(mContainer));
|
|
|
|
if (docShellNode)
|
|
|
|
{
|
|
|
|
PRInt32 i;
|
|
|
|
PRInt32 n;
|
|
|
|
docShellNode->GetChildCount(&n);
|
|
|
|
for (i=0; i < n; i++)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> child;
|
|
|
|
docShellNode->GetChildAt(i, getter_AddRefs(child));
|
|
|
|
nsCOMPtr<nsIDocShell> childAsShell(do_QueryInterface(child));
|
|
|
|
NS_ASSERTION(childAsShell, "null child in docshell");
|
|
|
|
if (childAsShell)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIContentViewer> childCV;
|
|
|
|
childAsShell->GetContentViewer(getter_AddRefs(childCV));
|
|
|
|
if (childCV)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIMarkupDocumentViewer> markupCV = do_QueryInterface(childCV);
|
|
|
|
if (markupCV) {
|
|
|
|
(*aFunc)(markupCV, aClosure);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
struct TextZoomInfo
|
|
|
|
{
|
|
|
|
float mTextZoom;
|
|
|
|
};
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
static void
|
|
|
|
SetChildTextZoom(nsIMarkupDocumentViewer* aChild, void* aClosure)
|
|
|
|
{
|
|
|
|
struct TextZoomInfo* textZoomInfo = (struct TextZoomInfo*) aClosure;
|
|
|
|
aChild->SetTextZoom(textZoomInfo->mTextZoom);
|
|
|
|
}
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
NS_IMETHODIMP DocumentViewerImpl::SetTextZoom(float aTextZoom)
|
|
|
|
{
|
|
|
|
if (mDeviceContext) {
|
2002-09-06 23:16:11 +04:00
|
|
|
float oldTextZoom = 1.0; // just in case mDeviceContext doesn't implement
|
|
|
|
// Don't reflow if there's no change in the textZoom.
|
|
|
|
mDeviceContext->GetTextZoom(oldTextZoom);
|
2002-08-21 16:01:05 +04:00
|
|
|
mDeviceContext->SetTextZoom(aTextZoom);
|
2002-09-06 23:16:11 +04:00
|
|
|
if (oldTextZoom != aTextZoom && mPresContext) {
|
2002-08-21 16:01:05 +04:00
|
|
|
mPresContext->ClearStyleDataAndReflow();
|
|
|
|
}
|
|
|
|
}
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2002-09-06 23:16:11 +04:00
|
|
|
// now set the text zoom on all children of mContainer (even if our zoom
|
|
|
|
// didn't change, our children's zoom may be different, though it would
|
|
|
|
// be unusual).
|
2002-08-21 16:01:05 +04:00
|
|
|
struct TextZoomInfo textZoomInfo = { aTextZoom };
|
|
|
|
return CallChildren(SetChildTextZoom, &textZoomInfo);
|
2001-04-12 17:04:29 +04:00
|
|
|
}
|
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
NS_IMETHODIMP DocumentViewerImpl::GetTextZoom(float* aTextZoom)
|
2001-04-12 17:04:29 +04:00
|
|
|
{
|
2002-08-21 16:01:05 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aTextZoom);
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
if (mDeviceContext) {
|
|
|
|
return mDeviceContext->GetTextZoom(*aTextZoom);
|
2002-04-17 08:17:16 +04:00
|
|
|
}
|
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
*aTextZoom = 1.0;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-04-13 16:32:18 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
// XXX: SEMANTIC CHANGE!
|
|
|
|
// returns a copy of the string. Caller is responsible for freeing result
|
|
|
|
// using Recycle(aDefaultCharacterSet)
|
|
|
|
NS_IMETHODIMP DocumentViewerImpl::GetDefaultCharacterSet(PRUnichar** aDefaultCharacterSet)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aDefaultCharacterSet);
|
|
|
|
NS_ENSURE_STATE(mContainer);
|
2001-04-13 16:32:18 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
if (mDefaultCharacterSet.IsEmpty())
|
|
|
|
{
|
|
|
|
nsXPIDLString defCharset;
|
2001-04-13 16:32:18 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
nsCOMPtr<nsIWebShell> webShell;
|
|
|
|
webShell = do_QueryInterface(mContainer);
|
|
|
|
if (webShell)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIPref> prefs(do_GetService(NS_PREF_CONTRACTID));
|
|
|
|
if (prefs)
|
|
|
|
prefs->GetLocalizedUnicharPref("intl.charset.default", getter_Copies(defCharset));
|
2001-04-13 16:32:18 +04:00
|
|
|
}
|
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
if (!defCharset.IsEmpty())
|
|
|
|
mDefaultCharacterSet.Assign(defCharset.get());
|
|
|
|
else
|
|
|
|
mDefaultCharacterSet.Assign(NS_LITERAL_STRING("ISO-8859-1"));
|
2001-04-12 17:04:29 +04:00
|
|
|
}
|
2002-08-21 16:01:05 +04:00
|
|
|
*aDefaultCharacterSet = ToNewUnicode(mDefaultCharacterSet);
|
|
|
|
return NS_OK;
|
2001-04-12 17:04:29 +04:00
|
|
|
}
|
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
static void
|
|
|
|
SetChildDefaultCharacterSet(nsIMarkupDocumentViewer* aChild, void* aClosure)
|
2001-04-12 17:04:29 +04:00
|
|
|
{
|
2002-08-21 16:01:05 +04:00
|
|
|
aChild->SetDefaultCharacterSet((PRUnichar*) aClosure);
|
|
|
|
}
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
NS_IMETHODIMP DocumentViewerImpl::SetDefaultCharacterSet(const PRUnichar* aDefaultCharacterSet)
|
|
|
|
{
|
|
|
|
mDefaultCharacterSet = aDefaultCharacterSet; // this does a copy of aDefaultCharacterSet
|
|
|
|
// now set the default char set on all children of mContainer
|
|
|
|
return CallChildren(SetChildDefaultCharacterSet,
|
|
|
|
(void*) aDefaultCharacterSet);
|
|
|
|
}
|
2002-02-19 14:49:27 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
// XXX: SEMANTIC CHANGE!
|
|
|
|
// returns a copy of the string. Caller is responsible for freeing result
|
|
|
|
// using Recycle(aForceCharacterSet)
|
|
|
|
NS_IMETHODIMP DocumentViewerImpl::GetForceCharacterSet(PRUnichar** aForceCharacterSet)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aForceCharacterSet);
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
nsAutoString emptyStr;
|
|
|
|
if (mForceCharacterSet.Equals(emptyStr)) {
|
|
|
|
*aForceCharacterSet = nsnull;
|
2002-01-12 15:31:05 +03:00
|
|
|
}
|
2002-08-21 16:01:05 +04:00
|
|
|
else {
|
|
|
|
*aForceCharacterSet = ToNewUnicode(mForceCharacterSet);
|
2001-04-12 17:04:29 +04:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
static void
|
|
|
|
SetChildForceCharacterSet(nsIMarkupDocumentViewer* aChild, void* aClosure)
|
2001-04-12 17:04:29 +04:00
|
|
|
{
|
2002-08-21 16:01:05 +04:00
|
|
|
aChild->SetForceCharacterSet((PRUnichar*) aClosure);
|
|
|
|
}
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
NS_IMETHODIMP DocumentViewerImpl::SetForceCharacterSet(const PRUnichar* aForceCharacterSet)
|
|
|
|
{
|
|
|
|
mForceCharacterSet = aForceCharacterSet;
|
|
|
|
// now set the force char set on all children of mContainer
|
|
|
|
return CallChildren(SetChildForceCharacterSet, (void*) aForceCharacterSet);
|
|
|
|
}
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
// XXX: SEMANTIC CHANGE!
|
|
|
|
// returns a copy of the string. Caller is responsible for freeing result
|
|
|
|
// using Recycle(aHintCharacterSet)
|
|
|
|
NS_IMETHODIMP DocumentViewerImpl::GetHintCharacterSet(PRUnichar * *aHintCharacterSet)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aHintCharacterSet);
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
if(kCharsetUninitialized == mHintCharsetSource) {
|
|
|
|
*aHintCharacterSet = nsnull;
|
2001-04-12 17:04:29 +04:00
|
|
|
} else {
|
2002-08-21 16:01:05 +04:00
|
|
|
*aHintCharacterSet = ToNewUnicode(mHintCharset);
|
|
|
|
// this can't possibly be right. we can't set a value just because somebody got a related value!
|
|
|
|
//mHintCharsetSource = kCharsetUninitialized;
|
2001-04-12 17:04:29 +04:00
|
|
|
}
|
2002-08-21 16:01:05 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
NS_IMETHODIMP DocumentViewerImpl::GetHintCharacterSetSource(PRInt32 *aHintCharacterSetSource)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aHintCharacterSetSource);
|
2002-02-15 17:48:12 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
*aHintCharacterSetSource = mHintCharsetSource;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2002-02-15 17:48:12 +03:00
|
|
|
|
2002-08-27 00:13:31 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP DocumentViewerImpl::GetPrevDocCharacterSet(PRUnichar * *aPrevDocCharacterSet)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aPrevDocCharacterSet);
|
|
|
|
|
|
|
|
*aPrevDocCharacterSet = ToNewUnicode(mPrevDocCharacterSet);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
SetChildPrevDocCharacterSet(nsIMarkupDocumentViewer* aChild, void* aClosure)
|
|
|
|
{
|
|
|
|
aChild->SetPrevDocCharacterSet((PRUnichar*) aClosure);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP DocumentViewerImpl::SetPrevDocCharacterSet(const PRUnichar* aPrevDocCharacterSet)
|
|
|
|
{
|
|
|
|
mPrevDocCharacterSet = aPrevDocCharacterSet;
|
|
|
|
return CallChildren(SetChildPrevDocCharacterSet,
|
|
|
|
(void*) aPrevDocCharacterSet);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
static void
|
|
|
|
SetChildHintCharacterSetSource(nsIMarkupDocumentViewer* aChild, void* aClosure)
|
|
|
|
{
|
|
|
|
aChild->SetHintCharacterSetSource(NS_PTR_TO_INT32(aClosure));
|
|
|
|
}
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
NS_IMETHODIMP DocumentViewerImpl::SetHintCharacterSetSource(PRInt32 aHintCharacterSetSource)
|
|
|
|
{
|
|
|
|
mHintCharsetSource = aHintCharacterSetSource;
|
|
|
|
// now set the hint char set source on all children of mContainer
|
|
|
|
return CallChildren(SetChildHintCharacterSetSource,
|
|
|
|
(void*) aHintCharacterSetSource);
|
|
|
|
}
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
static void
|
|
|
|
SetChildHintCharacterSet(nsIMarkupDocumentViewer* aChild, void* aClosure)
|
|
|
|
{
|
|
|
|
aChild->SetHintCharacterSet((PRUnichar*) aClosure);
|
|
|
|
}
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
NS_IMETHODIMP DocumentViewerImpl::SetHintCharacterSet(const PRUnichar* aHintCharacterSet)
|
|
|
|
{
|
|
|
|
mHintCharset = aHintCharacterSet;
|
|
|
|
// now set the hint char set on all children of mContainer
|
|
|
|
return CallChildren(SetChildHintCharacterSet, (void*) aHintCharacterSet);
|
|
|
|
}
|
2001-12-01 17:31:45 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
#ifdef IBMBIDI
|
|
|
|
static void
|
|
|
|
SetChildBidiOptions(nsIMarkupDocumentViewer* aChild, void* aClosure)
|
|
|
|
{
|
|
|
|
aChild->SetBidiOptions(NS_PTR_TO_INT32(aClosure));
|
|
|
|
}
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
#endif // IBMBIDI
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
NS_IMETHODIMP DocumentViewerImpl::SetBidiTextDirection(PRUint8 aTextDirection)
|
|
|
|
{
|
|
|
|
#ifdef IBMBIDI
|
|
|
|
PRUint32 bidiOptions;
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
GetBidiOptions(&bidiOptions);
|
|
|
|
SET_BIDI_OPTION_DIRECTION(bidiOptions, aTextDirection);
|
|
|
|
SetBidiOptions(bidiOptions);
|
|
|
|
#endif
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
NS_IMETHODIMP DocumentViewerImpl::GetBidiTextDirection(PRUint8* aTextDirection)
|
|
|
|
{
|
|
|
|
#ifdef IBMBIDI
|
|
|
|
PRUint32 bidiOptions;
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
if (aTextDirection) {
|
|
|
|
GetBidiOptions(&bidiOptions);
|
|
|
|
*aTextDirection = GET_BIDI_OPTION_DIRECTION(bidiOptions);
|
2001-04-12 17:04:29 +04:00
|
|
|
}
|
2002-08-21 16:01:05 +04:00
|
|
|
#endif
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2002-04-17 08:17:16 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
NS_IMETHODIMP DocumentViewerImpl::SetBidiTextType(PRUint8 aTextType)
|
|
|
|
{
|
|
|
|
#ifdef IBMBIDI
|
|
|
|
PRUint32 bidiOptions;
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
GetBidiOptions(&bidiOptions);
|
|
|
|
SET_BIDI_OPTION_TEXTTYPE(bidiOptions, aTextType);
|
|
|
|
SetBidiOptions(bidiOptions);
|
|
|
|
#endif
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
NS_IMETHODIMP DocumentViewerImpl::GetBidiTextType(PRUint8* aTextType)
|
|
|
|
{
|
|
|
|
#ifdef IBMBIDI
|
|
|
|
PRUint32 bidiOptions;
|
2002-04-17 08:17:16 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
if (aTextType) {
|
|
|
|
GetBidiOptions(&bidiOptions);
|
|
|
|
*aTextType = GET_BIDI_OPTION_TEXTTYPE(bidiOptions);
|
2001-11-03 17:59:39 +03:00
|
|
|
}
|
2002-08-21 16:01:05 +04:00
|
|
|
#endif
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
NS_IMETHODIMP DocumentViewerImpl::SetBidiControlsTextMode(PRUint8 aControlsTextMode)
|
|
|
|
{
|
|
|
|
#ifdef IBMBIDI
|
|
|
|
PRUint32 bidiOptions;
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
GetBidiOptions(&bidiOptions);
|
|
|
|
SET_BIDI_OPTION_CONTROLSTEXTMODE(bidiOptions, aControlsTextMode);
|
|
|
|
SetBidiOptions(bidiOptions);
|
|
|
|
#endif
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
NS_IMETHODIMP DocumentViewerImpl::GetBidiControlsTextMode(PRUint8* aControlsTextMode)
|
|
|
|
{
|
|
|
|
#ifdef IBMBIDI
|
|
|
|
PRUint32 bidiOptions;
|
2001-09-29 21:50:15 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
if (aControlsTextMode) {
|
|
|
|
GetBidiOptions(&bidiOptions);
|
|
|
|
*aControlsTextMode = GET_BIDI_OPTION_CONTROLSTEXTMODE(bidiOptions);
|
2001-11-14 14:24:03 +03:00
|
|
|
}
|
2002-08-21 16:01:05 +04:00
|
|
|
#endif
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-11-14 14:24:03 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
NS_IMETHODIMP DocumentViewerImpl::SetBidiClipboardTextMode(PRUint8 aClipboardTextMode)
|
|
|
|
{
|
|
|
|
#ifdef IBMBIDI
|
|
|
|
PRUint32 bidiOptions;
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
GetBidiOptions(&bidiOptions);
|
|
|
|
SET_BIDI_OPTION_CLIPBOARDTEXTMODE(bidiOptions, aClipboardTextMode);
|
|
|
|
SetBidiOptions(bidiOptions);
|
|
|
|
#endif
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
NS_IMETHODIMP DocumentViewerImpl::GetBidiClipboardTextMode(PRUint8* aClipboardTextMode)
|
|
|
|
{
|
|
|
|
#ifdef IBMBIDI
|
|
|
|
PRUint32 bidiOptions;
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
if (aClipboardTextMode) {
|
|
|
|
GetBidiOptions(&bidiOptions);
|
|
|
|
*aClipboardTextMode = GET_BIDI_OPTION_CLIPBOARDTEXTMODE(bidiOptions);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-04-13 16:32:18 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
NS_IMETHODIMP DocumentViewerImpl::SetBidiNumeral(PRUint8 aNumeral)
|
|
|
|
{
|
|
|
|
#ifdef IBMBIDI
|
|
|
|
PRUint32 bidiOptions;
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
GetBidiOptions(&bidiOptions);
|
|
|
|
SET_BIDI_OPTION_NUMERAL(bidiOptions, aNumeral);
|
|
|
|
SetBidiOptions(bidiOptions);
|
|
|
|
#endif
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
NS_IMETHODIMP DocumentViewerImpl::GetBidiNumeral(PRUint8* aNumeral)
|
|
|
|
{
|
|
|
|
#ifdef IBMBIDI
|
|
|
|
PRUint32 bidiOptions;
|
|
|
|
|
|
|
|
if (aNumeral) {
|
|
|
|
GetBidiOptions(&bidiOptions);
|
|
|
|
*aNumeral = GET_BIDI_OPTION_NUMERAL(bidiOptions);
|
2002-02-20 06:21:25 +03:00
|
|
|
}
|
2002-08-21 16:01:05 +04:00
|
|
|
#endif
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2002-02-20 06:21:25 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
NS_IMETHODIMP DocumentViewerImpl::SetBidiSupport(PRUint8 aSupport)
|
|
|
|
{
|
|
|
|
#ifdef IBMBIDI
|
|
|
|
PRUint32 bidiOptions;
|
2002-02-19 14:49:27 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
GetBidiOptions(&bidiOptions);
|
|
|
|
SET_BIDI_OPTION_SUPPORT(bidiOptions, aSupport);
|
|
|
|
SetBidiOptions(bidiOptions);
|
2002-02-19 14:49:27 +03:00
|
|
|
#endif
|
2002-08-21 16:01:05 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-06-29 09:42:47 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
NS_IMETHODIMP DocumentViewerImpl::GetBidiSupport(PRUint8* aSupport)
|
|
|
|
{
|
|
|
|
#ifdef IBMBIDI
|
|
|
|
PRUint32 bidiOptions;
|
|
|
|
|
|
|
|
if (aSupport) {
|
|
|
|
GetBidiOptions(&bidiOptions);
|
|
|
|
*aSupport = GET_BIDI_OPTION_SUPPORT(bidiOptions);
|
2001-04-12 17:04:29 +04:00
|
|
|
}
|
2002-08-21 16:01:05 +04:00
|
|
|
#endif
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
NS_IMETHODIMP DocumentViewerImpl::SetBidiCharacterSet(PRUint8 aCharacterSet)
|
|
|
|
{
|
|
|
|
#ifdef IBMBIDI
|
|
|
|
PRUint32 bidiOptions;
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
GetBidiOptions(&bidiOptions);
|
|
|
|
SET_BIDI_OPTION_CHARACTERSET(bidiOptions, aCharacterSet);
|
|
|
|
SetBidiOptions(bidiOptions);
|
|
|
|
#endif
|
|
|
|
return NS_OK;
|
2001-04-12 17:04:29 +04:00
|
|
|
}
|
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
NS_IMETHODIMP DocumentViewerImpl::GetBidiCharacterSet(PRUint8* aCharacterSet)
|
2001-04-12 17:04:29 +04:00
|
|
|
{
|
2002-08-21 16:01:05 +04:00
|
|
|
#ifdef IBMBIDI
|
|
|
|
PRUint32 bidiOptions;
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
if (aCharacterSet) {
|
|
|
|
GetBidiOptions(&bidiOptions);
|
|
|
|
*aCharacterSet = GET_BIDI_OPTION_CHARACTERSET(bidiOptions);
|
2001-04-12 17:04:29 +04:00
|
|
|
}
|
2002-08-21 16:01:05 +04:00
|
|
|
#endif
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
NS_IMETHODIMP DocumentViewerImpl::SetBidiOptions(PRUint32 aBidiOptions)
|
|
|
|
{
|
|
|
|
#ifdef IBMBIDI
|
|
|
|
if (mPresContext) {
|
|
|
|
#if 1
|
|
|
|
// forcing reflow will cause bug 80352. Temp turn off force reflow and
|
|
|
|
// wait for simon@softel.co.il to find the real solution
|
|
|
|
mPresContext->SetBidi(aBidiOptions, PR_FALSE);
|
|
|
|
#else
|
|
|
|
mPresContext->SetBidi(aBidiOptions, PR_TRUE); // force reflow
|
|
|
|
#endif
|
2001-04-12 17:04:29 +04:00
|
|
|
}
|
2002-08-21 16:01:05 +04:00
|
|
|
// now set bidi on all children of mContainer
|
|
|
|
CallChildren(SetChildBidiOptions, (void*) aBidiOptions);
|
|
|
|
#endif // IBMBIDI
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
NS_IMETHODIMP DocumentViewerImpl::GetBidiOptions(PRUint32* aBidiOptions)
|
|
|
|
{
|
|
|
|
#ifdef IBMBIDI
|
|
|
|
if (aBidiOptions) {
|
|
|
|
if (mPresContext) {
|
|
|
|
mPresContext->GetBidi(aBidiOptions);
|
2001-04-12 17:04:29 +04:00
|
|
|
}
|
2002-08-21 16:01:05 +04:00
|
|
|
else
|
|
|
|
*aBidiOptions = IBMBIDI_DEFAULT_BIDI_OPTIONS;
|
2001-04-12 17:04:29 +04:00
|
|
|
}
|
2002-08-21 16:01:05 +04:00
|
|
|
#endif // IBMBIDI
|
|
|
|
return NS_OK;
|
2001-04-12 17:04:29 +04:00
|
|
|
}
|
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
NS_IMETHODIMP DocumentViewerImpl::SizeToContent()
|
2001-04-12 17:04:29 +04:00
|
|
|
{
|
2002-08-21 16:01:05 +04:00
|
|
|
NS_ENSURE_TRUE(mDocument, NS_ERROR_NOT_AVAILABLE);
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
nsCOMPtr<nsIDocShellTreeItem> docShellAsItem(do_QueryInterface(mContainer));
|
|
|
|
NS_ENSURE_TRUE(docShellAsItem, NS_ERROR_FAILURE);
|
2002-03-26 14:43:40 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
nsCOMPtr<nsIDocShellTreeItem> docShellParent;
|
|
|
|
docShellAsItem->GetSameTypeParent(getter_AddRefs(docShellParent));
|
2002-03-26 14:43:40 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
// It's only valid to access this from a top frame. Doesn't work from
|
|
|
|
// sub-frames.
|
|
|
|
NS_ENSURE_TRUE(!docShellParent, NS_ERROR_FAILURE);
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
nsCOMPtr<nsIPresShell> presShell;
|
|
|
|
GetPresShell(*getter_AddRefs(presShell));
|
|
|
|
NS_ENSURE_TRUE(presShell, NS_ERROR_FAILURE);
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
NS_ENSURE_SUCCESS(presShell->ResizeReflow(NS_UNCONSTRAINEDSIZE,
|
|
|
|
NS_UNCONSTRAINEDSIZE), NS_ERROR_FAILURE);
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
nsCOMPtr<nsIPresContext> presContext;
|
|
|
|
GetPresContext(*getter_AddRefs(presContext));
|
|
|
|
NS_ENSURE_TRUE(presContext, NS_ERROR_FAILURE);
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
nsRect shellArea;
|
|
|
|
PRInt32 width, height;
|
|
|
|
float pixelScale;
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
// so how big is it?
|
|
|
|
presContext->GetVisibleArea(shellArea);
|
|
|
|
presContext->GetTwipsToPixels(&pixelScale);
|
|
|
|
width = PRInt32((float)shellArea.width*pixelScale);
|
|
|
|
height = PRInt32((float)shellArea.height*pixelScale);
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
nsCOMPtr<nsIDocShellTreeOwner> treeOwner;
|
|
|
|
docShellAsItem->GetTreeOwner(getter_AddRefs(treeOwner));
|
|
|
|
NS_ENSURE_TRUE(treeOwner, NS_ERROR_FAILURE);
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
/* presContext's size was calculated in twips and has already been
|
|
|
|
rounded to the equivalent pixels (so the width/height calculation
|
|
|
|
we just performed was probably exact, though it was based on
|
|
|
|
values already rounded during ResizeReflow). In a surprising
|
|
|
|
number of instances, this rounding makes a window which for want
|
|
|
|
of one extra pixel's width ends up wrapping the longest line of
|
|
|
|
text during actual window layout. This makes the window too short,
|
|
|
|
generally clipping the OK/Cancel buttons. Here we add one pixel
|
|
|
|
to the calculated width, to circumvent this problem. */
|
|
|
|
NS_ENSURE_SUCCESS(treeOwner->SizeShellTo(docShellAsItem, width+1, height),
|
|
|
|
NS_ERROR_FAILURE);
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2002-04-17 08:17:16 +04:00
|
|
|
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
#ifdef XP_MAC
|
|
|
|
#pragma mark -
|
|
|
|
#endif
|
2001-03-27 15:56:03 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
NS_IMPL_ISUPPORTS1(nsDocViewerSelectionListener, nsISelectionListener);
|
2001-03-27 15:56:03 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
nsresult nsDocViewerSelectionListener::Init(DocumentViewerImpl *aDocViewer)
|
|
|
|
{
|
|
|
|
mDocViewer = aDocViewer;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
/*
|
|
|
|
* GetPopupNode, GetPopupLinkNode and GetPopupImageNode are helpers
|
|
|
|
* for the cmd_copyLink / cmd_copyImageLocation / cmd_copyImageContents family
|
|
|
|
* of commands. The focus controller stores the popup node, these retrieve
|
|
|
|
* them and munge appropriately. Note that we have to store the popup node
|
|
|
|
* rather than retrieving it from EventStateManager::GetFocusedContent because
|
|
|
|
* not all content (images included) can receive focus.
|
|
|
|
*/
|
2002-04-17 08:17:16 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
nsresult
|
|
|
|
DocumentViewerImpl::GetPopupNode(nsIDOMNode** aNode)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aNode);
|
2001-03-27 15:56:03 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
nsresult rv;
|
2001-03-27 15:56:03 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
// get the document
|
|
|
|
nsCOMPtr<nsIDocument> document;
|
|
|
|
rv = GetDocument(*getter_AddRefs(document));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
NS_ENSURE_TRUE(document, NS_ERROR_FAILURE);
|
2002-02-19 14:49:27 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
// get the script global object
|
|
|
|
nsCOMPtr<nsIScriptGlobalObject> global;
|
|
|
|
rv = document->GetScriptGlobalObject(getter_AddRefs(global));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
NS_ENSURE_TRUE(global, NS_ERROR_FAILURE);
|
2002-02-19 14:49:27 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
// get the internal dom window
|
|
|
|
nsCOMPtr<nsIDOMWindowInternal> internalWin(do_QueryInterface(global, &rv));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
NS_ENSURE_TRUE(internalWin, NS_ERROR_FAILURE);
|
2002-02-19 14:49:27 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
// get the private dom window
|
|
|
|
nsCOMPtr<nsPIDOMWindow> privateWin(do_QueryInterface(internalWin, &rv));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
NS_ENSURE_TRUE(privateWin, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
// get the focus controller
|
|
|
|
nsCOMPtr<nsIFocusController> focusController;
|
|
|
|
rv = privateWin->GetRootFocusController(getter_AddRefs(focusController));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
NS_ENSURE_TRUE(focusController, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
// get the popup node
|
|
|
|
rv = focusController->GetPopupNode(aNode); // addref happens here
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return rv;
|
2002-02-19 14:49:27 +03:00
|
|
|
}
|
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
// GetPopupLinkNode: return popup link node or fail
|
|
|
|
nsresult
|
|
|
|
DocumentViewerImpl::GetPopupLinkNode(nsIDOMNode** aNode)
|
2002-02-19 14:49:27 +03:00
|
|
|
{
|
2002-08-21 16:01:05 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aNode);
|
2002-02-19 14:49:27 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
// you get null unless i say so
|
|
|
|
*aNode = nsnull;
|
2002-02-19 14:49:27 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
// find popup node
|
|
|
|
nsCOMPtr<nsIDOMNode> node;
|
|
|
|
nsresult rv = GetPopupNode(getter_AddRefs(node));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2002-02-19 14:49:27 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
// find out if we have a link in our ancestry
|
|
|
|
while (node) {
|
2002-02-19 14:49:27 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
// are we an anchor?
|
|
|
|
nsCOMPtr<nsIDOMHTMLAnchorElement> anchor(do_QueryInterface(node));
|
|
|
|
nsCOMPtr<nsIDOMHTMLAreaElement> area;
|
|
|
|
nsCOMPtr<nsIDOMHTMLLinkElement> link;
|
|
|
|
nsAutoString xlinkType;
|
|
|
|
if (!anchor) {
|
|
|
|
// area?
|
|
|
|
area = do_QueryInterface(node);
|
|
|
|
if (!area) {
|
|
|
|
// link?
|
|
|
|
link = do_QueryInterface(node);
|
|
|
|
if (!link) {
|
|
|
|
// XLink?
|
|
|
|
nsCOMPtr<nsIDOMElement> element(do_QueryInterface(node));
|
|
|
|
if (element) {
|
|
|
|
element->GetAttributeNS(NS_LITERAL_STRING("http://www.w3.org/1999/xlink"),NS_LITERAL_STRING("type"),xlinkType);
|
|
|
|
}
|
2002-02-19 14:49:27 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-08-21 16:01:05 +04:00
|
|
|
if (anchor || area || link || xlinkType.Equals(NS_LITERAL_STRING("simple"))) {
|
|
|
|
*aNode = node;
|
|
|
|
NS_IF_ADDREF(*aNode); // addref
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// if not, get our parent and keep trying...
|
|
|
|
nsCOMPtr<nsIDOMNode> parentNode;
|
|
|
|
node->GetParentNode(getter_AddRefs(parentNode));
|
|
|
|
node = parentNode;
|
|
|
|
}
|
2002-02-19 14:49:27 +03:00
|
|
|
}
|
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
// if we have no node, fail
|
|
|
|
return NS_ERROR_FAILURE;
|
2002-02-19 14:49:27 +03:00
|
|
|
}
|
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
// GetPopupLinkNode: return popup image node or fail
|
2001-02-07 02:03:17 +03:00
|
|
|
nsresult
|
2002-08-21 16:01:05 +04:00
|
|
|
DocumentViewerImpl::GetPopupImageNode(nsIDOMNode** aNode)
|
2001-03-27 15:56:03 +04:00
|
|
|
{
|
2002-08-21 16:01:05 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aNode);
|
2001-02-07 02:03:17 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
// you get null unless i say so
|
|
|
|
*aNode = nsnull;
|
2001-02-07 02:03:17 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
// find popup node
|
|
|
|
nsCOMPtr<nsIDOMNode> node;
|
|
|
|
nsresult rv = GetPopupNode(getter_AddRefs(node));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2001-02-07 02:03:17 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
// XXX find out if we're an image. this really ought to look for objects
|
|
|
|
// XXX with type "image/...", but this is good enough for now.
|
|
|
|
nsCOMPtr<nsIDOMHTMLImageElement> img(do_QueryInterface(node, &rv));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
NS_ENSURE_TRUE(img, NS_ERROR_FAILURE);
|
2000-09-22 18:42:13 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
// if we made it here, we're an image.
|
|
|
|
*aNode = node;
|
|
|
|
NS_IF_ADDREF(*aNode); // addref
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2002-02-19 14:49:27 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
/*
|
|
|
|
* XXX dr
|
|
|
|
* ------
|
|
|
|
* These two functions -- GetInLink and GetInImage -- are kind of annoying
|
|
|
|
* in that they only get called from the controller (in
|
|
|
|
* nsDOMWindowController::IsCommandEnabled). The actual construction of the
|
|
|
|
* context menus in communicator (nsContextMenu.js) has its own, redundant
|
|
|
|
* tests. No big deal, but good to keep in mind if we ever clean context
|
|
|
|
* menus.
|
|
|
|
*/
|
2001-03-27 15:56:03 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
NS_IMETHODIMP DocumentViewerImpl::GetInLink(PRBool* aInLink)
|
|
|
|
{
|
|
|
|
#ifdef DEBUG_dr
|
|
|
|
printf("dr :: DocumentViewerImpl::GetInLink\n");
|
|
|
|
#endif
|
2002-02-19 14:49:27 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aInLink);
|
2002-04-06 17:09:15 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
// we're not in a link unless i say so
|
|
|
|
*aInLink = PR_FALSE;
|
2002-02-19 14:49:27 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
// get the popup link
|
|
|
|
nsCOMPtr<nsIDOMNode> node;
|
|
|
|
nsresult rv = GetPopupLinkNode(getter_AddRefs(node));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
NS_ENSURE_TRUE(node, NS_ERROR_FAILURE);
|
2002-06-20 01:51:13 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
// if we made it here, we're in a link
|
|
|
|
*aInLink = PR_TRUE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2002-06-20 01:51:13 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
NS_IMETHODIMP DocumentViewerImpl::GetInImage(PRBool* aInImage)
|
|
|
|
{
|
|
|
|
#ifdef DEBUG_dr
|
|
|
|
printf("dr :: DocumentViewerImpl::GetInImage\n");
|
2002-05-07 16:03:37 +04:00
|
|
|
#endif
|
2002-02-19 14:49:27 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aInImage);
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
// we're not in an image unless i say so
|
|
|
|
*aInImage = PR_FALSE;
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
// get the popup image
|
|
|
|
nsCOMPtr<nsIDOMNode> node;
|
|
|
|
nsresult rv = GetPopupImageNode(getter_AddRefs(node));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
NS_ENSURE_TRUE(node, NS_ERROR_FAILURE);
|
2001-03-27 15:56:03 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
// if we made it here, we're in an image
|
|
|
|
*aInImage = PR_TRUE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2002-07-09 16:39:02 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
NS_IMETHODIMP nsDocViewerSelectionListener::NotifySelectionChanged(nsIDOMDocument *, nsISelection *, short)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mDocViewer, "Should have doc viewer!");
|
2001-03-27 15:56:03 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
// get the selection state
|
|
|
|
nsCOMPtr<nsISelection> selection;
|
|
|
|
nsresult rv = mDocViewer->GetDocumentSelection(getter_AddRefs(selection));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
2002-05-07 16:03:37 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
PRBool selectionCollapsed;
|
|
|
|
selection->GetIsCollapsed(&selectionCollapsed);
|
|
|
|
// we only call UpdateCommands when the selection changes from collapsed
|
|
|
|
// to non-collapsed or vice versa. We might need another update string
|
|
|
|
// for simple selection changes, but that would be expenseive.
|
|
|
|
if (!mGotSelectionState || mSelectionWasCollapsed != selectionCollapsed)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDocument> theDoc;
|
|
|
|
mDocViewer->GetDocument(*getter_AddRefs(theDoc));
|
|
|
|
if (!theDoc) return NS_ERROR_FAILURE;
|
2002-05-07 16:03:37 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
nsCOMPtr<nsIScriptGlobalObject> scriptGlobalObject;
|
|
|
|
theDoc->GetScriptGlobalObject(getter_AddRefs(scriptGlobalObject));
|
2002-05-07 16:03:37 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
nsCOMPtr<nsIDOMWindowInternal> domWindow = do_QueryInterface(scriptGlobalObject);
|
|
|
|
if (!domWindow) return NS_ERROR_FAILURE;
|
2002-05-07 16:03:37 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
domWindow->UpdateCommands(NS_LITERAL_STRING("select"));
|
|
|
|
mGotSelectionState = PR_TRUE;
|
|
|
|
mSelectionWasCollapsed = selectionCollapsed;
|
2002-05-07 16:03:37 +04:00
|
|
|
}
|
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2002-05-07 16:03:37 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
//nsDocViewerFocusListener
|
|
|
|
NS_IMPL_ISUPPORTS1(nsDocViewerFocusListener, nsIDOMFocusListener);
|
2002-05-07 16:03:37 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
nsDocViewerFocusListener::nsDocViewerFocusListener()
|
|
|
|
:mDocViewer(nsnull)
|
|
|
|
{
|
2002-09-07 21:13:19 +04:00
|
|
|
NS_INIT_ISUPPORTS();
|
2002-08-21 16:01:05 +04:00
|
|
|
}
|
2001-03-27 15:56:03 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
nsDocViewerFocusListener::~nsDocViewerFocusListener(){}
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
nsresult
|
|
|
|
nsDocViewerFocusListener::HandleEvent(nsIDOMEvent* aEvent)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
2001-03-27 15:56:03 +04:00
|
|
|
}
|
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocViewerFocusListener::Focus(nsIDOMEvent* aEvent)
|
2001-03-27 15:56:03 +04:00
|
|
|
{
|
2002-08-21 16:01:05 +04:00
|
|
|
nsCOMPtr<nsIPresShell> shell;
|
|
|
|
if(!mDocViewer)
|
|
|
|
return NS_ERROR_FAILURE;
|
2001-03-27 15:56:03 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
nsresult result = mDocViewer->GetPresShell(*getter_AddRefs(shell));//deref once cause it take a ptr ref
|
|
|
|
if(NS_FAILED(result) || !shell)
|
|
|
|
return result?result:NS_ERROR_FAILURE;
|
|
|
|
nsCOMPtr<nsISelectionController> selCon;
|
|
|
|
selCon = do_QueryInterface(shell);
|
|
|
|
PRInt16 selectionStatus;
|
|
|
|
selCon->GetDisplaySelection( &selectionStatus);
|
2001-03-27 15:56:03 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
//if selection was nsISelectionController::SELECTION_OFF, do nothing
|
|
|
|
//otherwise re-enable it.
|
|
|
|
if(selectionStatus == nsISelectionController::SELECTION_DISABLED ||
|
|
|
|
selectionStatus == nsISelectionController::SELECTION_HIDDEN)
|
|
|
|
{
|
|
|
|
selCon->SetDisplaySelection(nsISelectionController::SELECTION_ON);
|
|
|
|
selCon->RepaintSelection(nsISelectionController::SELECTION_NORMAL);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocViewerFocusListener::Blur(nsIDOMEvent* aEvent)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIPresShell> shell;
|
|
|
|
if(!mDocViewer)
|
|
|
|
return NS_ERROR_FAILURE;
|
2001-02-07 02:03:17 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
nsresult result = mDocViewer->GetPresShell(*getter_AddRefs(shell));//deref once cause it take a ptr ref
|
|
|
|
if(NS_FAILED(result) || !shell)
|
|
|
|
return result?result:NS_ERROR_FAILURE;
|
|
|
|
nsCOMPtr<nsISelectionController> selCon;
|
|
|
|
selCon = do_QueryInterface(shell);
|
|
|
|
PRInt16 selectionStatus;
|
|
|
|
selCon->GetDisplaySelection(&selectionStatus);
|
2001-02-01 23:49:10 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
//if selection was nsISelectionController::SELECTION_OFF, do nothing
|
|
|
|
//otherwise re-enable it.
|
|
|
|
if(selectionStatus == nsISelectionController::SELECTION_ON)
|
|
|
|
{
|
|
|
|
selCon->SetDisplaySelection(nsISelectionController::SELECTION_DISABLED);
|
|
|
|
selCon->RepaintSelection(nsISelectionController::SELECTION_NORMAL);
|
2002-01-01 15:58:53 +03:00
|
|
|
}
|
2002-08-21 16:01:05 +04:00
|
|
|
return result;
|
|
|
|
}
|
2002-01-01 15:58:53 +03:00
|
|
|
|
2001-02-07 02:03:17 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
nsresult
|
|
|
|
nsDocViewerFocusListener::Init(DocumentViewerImpl *aDocViewer)
|
|
|
|
{
|
|
|
|
mDocViewer = aDocViewer;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-02-07 02:03:17 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
/** ---------------------------------------------------
|
|
|
|
* From nsIWebBrowserPrint
|
|
|
|
*/
|
|
|
|
NS_IMETHODIMP
|
|
|
|
DocumentViewerImpl::Print(nsIPrintSettings* aPrintSettings,
|
|
|
|
nsIWebProgressListener* aWebProgressListener)
|
|
|
|
{
|
|
|
|
#ifdef NS_PRINTING
|
2002-09-04 03:21:15 +04:00
|
|
|
INIT_RUNTIME_ERROR_CHECKING();
|
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
// Temporary code for Bug 136185
|
|
|
|
nsCOMPtr<nsIXULDocument> xulDoc(do_QueryInterface(mDocument));
|
|
|
|
if (xulDoc) {
|
|
|
|
nsPrintEngine::ShowPrintErrorDialog(NS_ERROR_GFX_PRINTER_NO_XUL);
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2001-01-27 17:09:34 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(mContainer));
|
|
|
|
NS_ASSERTION(docShell, "This has to be a docshell");
|
1999-05-06 23:25:40 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
// Check to see if this document is still busy
|
|
|
|
// If it is busy and we aren't already "queued" up to print then
|
|
|
|
// Indicate there is a print pending and cache the args for later
|
|
|
|
PRUint32 busyFlags = nsIDocShell::BUSY_FLAGS_NONE;
|
|
|
|
if ((NS_FAILED(docShell->GetBusyFlags(&busyFlags)) ||
|
|
|
|
(busyFlags != nsIDocShell::BUSY_FLAGS_NONE && busyFlags & nsIDocShell::BUSY_FLAGS_PAGE_LOADING)) &&
|
|
|
|
!mPrintDocIsFullyLoaded) {
|
|
|
|
if (!mPrintIsPending) {
|
|
|
|
mCachedPrintSettings = aPrintSettings;
|
|
|
|
mCachedPrintWebProgressListner = aWebProgressListener;
|
|
|
|
mPrintIsPending = PR_TRUE;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-10-20 01:49:12 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
nsCOMPtr<nsIPresShell> presShell;
|
|
|
|
docShell->GetPresShell(getter_AddRefs(presShell));
|
2001-01-27 17:09:34 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
if (!presShell) {
|
|
|
|
// A frame that's not displayed can't be printed!
|
|
|
|
PR_PL(("Printing Stopped - PreShell was NULL!"));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-05-14 18:40:59 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
2000-10-20 01:49:12 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
// if we are printing another URL, then exit
|
|
|
|
// the reason we check here is because this method can be called while
|
|
|
|
// another is still in here (the printing dialog is a good example).
|
|
|
|
// the only time we can print more than one job at a time is the regression tests
|
|
|
|
if (GetIsPrinting()) {
|
|
|
|
// Let the user know we are not ready to print.
|
|
|
|
rv = NS_ERROR_NOT_AVAILABLE;
|
|
|
|
nsPrintEngine::ShowPrintErrorDialog(rv);
|
|
|
|
return rv;
|
|
|
|
}
|
1999-05-14 18:40:59 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
if (!mPrintEngine) {
|
|
|
|
mPrintEngine = new nsPrintEngine();
|
|
|
|
NS_ENSURE_TRUE(mPrintEngine, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
NS_ADDREF(mPrintEngine);
|
2002-04-04 17:04:21 +04:00
|
|
|
|
2002-01-01 15:58:53 +03:00
|
|
|
#ifdef NS_DEBUG
|
2002-08-21 16:01:05 +04:00
|
|
|
mPrintEngine->Initialize(this, this, mContainer, mDocument,
|
|
|
|
mDeviceContext, mPresContext, mWindow, mParentWidget, mDebugFile);
|
|
|
|
#else
|
|
|
|
mPrintEngine->Initialize(this, this, mContainer, mDocument,
|
|
|
|
mDeviceContext, mPresContext, mWindow, mParentWidget, nsnull);
|
2002-01-01 15:58:53 +03:00
|
|
|
#endif
|
2002-08-21 16:01:05 +04:00
|
|
|
}
|
2001-01-27 17:09:34 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
rv = mPrintEngine->Print(aPrintSettings, aWebProgressListener);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
OnDonePrinting();
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
#else
|
|
|
|
return NS_ERROR_FAILURE;
|
2001-01-27 17:09:34 +03:00
|
|
|
#endif
|
2002-08-21 16:01:05 +04:00
|
|
|
}
|
2001-01-27 17:09:34 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
/** ---------------------------------------------------
|
|
|
|
* See documentation above in the nsIContentViewerfile class definition
|
|
|
|
* @update 11/01/01 rods
|
|
|
|
*
|
|
|
|
* For a full and detailed understanding of the issues with
|
|
|
|
* PrintPreview: See the design spec that is attached to Bug 107562
|
|
|
|
*/
|
|
|
|
NS_IMETHODIMP
|
|
|
|
DocumentViewerImpl::PrintPreview(nsIPrintSettings* aPrintSettings,
|
|
|
|
nsIDOMWindow *aChildDOMWin,
|
|
|
|
nsIWebProgressListener* aWebProgressListener)
|
|
|
|
{
|
|
|
|
#if defined(NS_PRINTING) && defined(NS_PRINT_PREVIEW)
|
|
|
|
nsresult rv = NS_OK;
|
2001-01-27 17:09:34 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
if (GetIsPrinting()) {
|
|
|
|
nsPrintEngine::CloseProgressDialog(aWebProgressListener);
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
// Temporary code for Bug 136185
|
|
|
|
nsCOMPtr<nsIXULDocument> xulDoc(do_QueryInterface(mDocument));
|
|
|
|
if (xulDoc) {
|
|
|
|
nsPrintEngine::CloseProgressDialog(aWebProgressListener);
|
|
|
|
nsPrintEngine::ShowPrintErrorDialog(NS_ERROR_GFX_PRINTER_NO_XUL, PR_FALSE);
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2001-01-27 17:09:34 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
if (!mPrintEngine) {
|
|
|
|
mPrintEngine = new nsPrintEngine();
|
|
|
|
NS_ENSURE_TRUE(mPrintEngine, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
NS_ADDREF(mPrintEngine);
|
2002-05-09 00:11:14 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
#ifdef NS_DEBUG
|
|
|
|
mPrintEngine->Initialize(this, this, mContainer, mDocument,
|
|
|
|
mDeviceContext, mPresContext, mWindow, mParentWidget, mDebugFile);
|
|
|
|
#else
|
|
|
|
mPrintEngine->Initialize(this, this, mContainer, mDocument,
|
|
|
|
mDeviceContext, mPresContext, mWindow, mParentWidget, nsnull);
|
|
|
|
#endif
|
2001-04-12 17:04:29 +04:00
|
|
|
}
|
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
rv = mPrintEngine->PrintPreview(aPrintSettings, aChildDOMWin, aWebProgressListener);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
OnDonePrinting();
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
#else
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
#endif
|
2001-04-12 17:04:29 +04:00
|
|
|
}
|
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
NS_IMETHODIMP
|
|
|
|
DocumentViewerImpl::PrintPreviewNavigate(PRInt16 aType, PRInt32 aPageNum)
|
|
|
|
{
|
|
|
|
#if defined(NS_PRINTING) && defined(NS_PRINT_PREVIEW)
|
|
|
|
if (GetIsPrinting()) return NS_ERROR_FAILURE;
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
if (!mPrintEngine) return NS_ERROR_FAILURE;
|
2001-02-07 02:03:17 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
nsIScrollableView* scrollableView;
|
|
|
|
mViewManager->GetRootScrollableView(&scrollableView);
|
|
|
|
if (scrollableView == nsnull) return NS_OK;
|
|
|
|
|
|
|
|
// Check to see if we can short circut scrolling to the top
|
|
|
|
if (aType == nsIWebBrowserPrint::PRINTPREVIEW_HOME ||
|
|
|
|
(aType == nsIWebBrowserPrint::PRINTPREVIEW_GOTO_PAGENUM && aPageNum == 1)) {
|
|
|
|
scrollableView->ScrollTo(0, 0, PR_TRUE);
|
|
|
|
return NS_OK;
|
2001-02-07 02:03:17 +03:00
|
|
|
}
|
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
// Finds the SimplePageSequencer frame
|
|
|
|
// in PP mPrtPreview->mPrintObject->mSeqFrame is null
|
|
|
|
nsIFrame* seqFrame = nsnull;
|
|
|
|
PRInt32 pageCount = 0;
|
|
|
|
if (NS_FAILED(mPrintEngine->GetSeqFrameAndCountPages(seqFrame, pageCount))) {
|
|
|
|
return NS_ERROR_FAILURE;
|
2001-04-12 17:04:29 +04:00
|
|
|
}
|
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
// Figure where we are currently scrolled to
|
|
|
|
const nsIView * clippedView;
|
|
|
|
scrollableView->GetClipView(&clippedView);
|
|
|
|
nscoord x;
|
|
|
|
nscoord y;
|
|
|
|
scrollableView->GetScrollPosition(x, y);
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
PRInt32 pageNum = 1;
|
|
|
|
nsIFrame * fndPageFrame = nsnull;
|
|
|
|
nsIFrame * currentPage = nsnull;
|
2001-08-06 06:27:43 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
// If it is "End" then just do a "goto" to the last page
|
|
|
|
if (aType == nsIWebBrowserPrint::PRINTPREVIEW_END) {
|
|
|
|
aType = nsIWebBrowserPrint::PRINTPREVIEW_GOTO_PAGENUM;
|
|
|
|
aPageNum = pageCount;
|
2001-04-12 17:04:29 +04:00
|
|
|
}
|
1999-05-12 17:32:09 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
// Now, locate the current page we are on and
|
|
|
|
// and the page of the page number
|
|
|
|
nscoord gap = 0;
|
|
|
|
nsIFrame * pageFrame;
|
|
|
|
seqFrame->FirstChild(mPresContext, nsnull, &pageFrame);
|
|
|
|
while (pageFrame != nsnull) {
|
|
|
|
nsRect pageRect;
|
|
|
|
pageFrame->GetRect(pageRect);
|
|
|
|
if (pageNum == 1) {
|
|
|
|
gap = pageRect.y;
|
|
|
|
}
|
|
|
|
pageRect.y -= gap;
|
|
|
|
if (pageRect.Contains(pageRect.x, y)) {
|
|
|
|
currentPage = pageFrame;
|
|
|
|
}
|
|
|
|
if (pageNum == aPageNum) {
|
|
|
|
fndPageFrame = pageFrame;
|
|
|
|
break;
|
2001-04-12 17:04:29 +04:00
|
|
|
}
|
2002-08-21 16:01:05 +04:00
|
|
|
pageNum++;
|
|
|
|
pageFrame->GetNextSibling(&pageFrame);
|
2002-04-17 08:17:16 +04:00
|
|
|
}
|
1999-05-12 17:32:09 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
if (aType == nsIWebBrowserPrint::PRINTPREVIEW_PREV_PAGE) {
|
|
|
|
if (currentPage) {
|
|
|
|
currentPage->GetPrevInFlow(&fndPageFrame);
|
|
|
|
if (!fndPageFrame) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
} else if (aType == nsIWebBrowserPrint::PRINTPREVIEW_NEXT_PAGE) {
|
|
|
|
if (currentPage) {
|
|
|
|
currentPage->GetNextInFlow(&fndPageFrame);
|
|
|
|
if (!fndPageFrame) {
|
|
|
|
return NS_OK;
|
2002-04-17 08:17:16 +04:00
|
|
|
}
|
2002-08-21 16:01:05 +04:00
|
|
|
} else {
|
|
|
|
return NS_OK;
|
1999-05-07 23:26:23 +04:00
|
|
|
}
|
2002-08-21 16:01:05 +04:00
|
|
|
} else { // If we get here we are doing "GoTo"
|
|
|
|
if (aPageNum < 0 || aPageNum > pageCount) {
|
|
|
|
return NS_OK;
|
1999-05-07 23:26:23 +04:00
|
|
|
}
|
|
|
|
}
|
2001-04-18 10:06:31 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
if (fndPageFrame && scrollableView) {
|
|
|
|
// get the child rect
|
|
|
|
nsRect fRect;
|
|
|
|
fndPageFrame->GetRect(fRect);
|
|
|
|
// find offset from view
|
|
|
|
nsPoint pnt;
|
|
|
|
nsIView * view;
|
|
|
|
fndPageFrame->GetOffsetFromView(mPresContext, pnt, &view);
|
|
|
|
|
|
|
|
nscoord deadSpaceGap = 0;
|
|
|
|
nsIPageSequenceFrame * sqf;
|
|
|
|
if (NS_SUCCEEDED(CallQueryInterface(seqFrame, &sqf))) {
|
|
|
|
sqf->GetDeadSpaceValue(&deadSpaceGap);
|
2001-04-18 10:06:31 +04:00
|
|
|
}
|
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
// scroll so that top of page (plus the gray area) is at the top of the scroll area
|
|
|
|
scrollableView->ScrollTo(0, fRect.y-deadSpaceGap, PR_TRUE);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
#else
|
2001-04-18 10:06:31 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2002-08-21 16:01:05 +04:00
|
|
|
#endif // NS_PRINT_PREVIEW
|
|
|
|
|
2001-04-18 10:06:31 +04:00
|
|
|
}
|
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
/* readonly attribute nsIPrintSettings globalPrintSettings; */
|
|
|
|
NS_IMETHODIMP
|
|
|
|
DocumentViewerImpl::GetGlobalPrintSettings(nsIPrintSettings * *aGlobalPrintSettings)
|
2001-04-18 10:06:31 +04:00
|
|
|
{
|
2002-08-21 16:01:05 +04:00
|
|
|
#ifdef NS_PRINTING
|
|
|
|
NS_ENSURE_ARG_POINTER(aGlobalPrintSettings);
|
2001-04-18 10:06:31 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
nsPrintEngine printEngine;
|
|
|
|
return printEngine.GetGlobalPrintSettings(aGlobalPrintSettings);
|
|
|
|
#else
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
#endif
|
2001-04-18 10:06:31 +04:00
|
|
|
}
|
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
/* readonly attribute boolean doingPrint; */
|
|
|
|
NS_IMETHODIMP
|
|
|
|
DocumentViewerImpl::GetDoingPrint(PRBool *aDoingPrint)
|
2001-04-18 10:06:31 +04:00
|
|
|
{
|
2002-08-21 16:01:05 +04:00
|
|
|
#ifdef NS_PRINTING
|
|
|
|
NS_ENSURE_ARG_POINTER(aDoingPrint);
|
|
|
|
|
|
|
|
*aDoingPrint = PR_FALSE;
|
|
|
|
if (mPrintEngine) {
|
|
|
|
return mPrintEngine->GetDoingPrintPreview(aDoingPrint);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
#else
|
|
|
|
return NS_ERROR_FAILURE;
|
2001-04-18 10:06:31 +04:00
|
|
|
#endif
|
2002-08-21 16:01:05 +04:00
|
|
|
}
|
2001-04-18 10:06:31 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
/* readonly attribute boolean doingPrintPreview; */
|
|
|
|
NS_IMETHODIMP
|
|
|
|
DocumentViewerImpl::GetDoingPrintPreview(PRBool *aDoingPrintPreview)
|
|
|
|
{
|
|
|
|
#ifdef NS_PRINTING
|
|
|
|
NS_ENSURE_ARG_POINTER(aDoingPrintPreview);
|
2001-04-18 10:06:31 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
*aDoingPrintPreview = PR_FALSE;
|
|
|
|
if (mPrintEngine) {
|
|
|
|
return mPrintEngine->GetDoingPrintPreview(aDoingPrintPreview);
|
|
|
|
}
|
2001-04-18 10:06:31 +04:00
|
|
|
return NS_OK;
|
2002-08-21 16:01:05 +04:00
|
|
|
#else
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
#endif
|
2001-04-18 10:06:31 +04:00
|
|
|
}
|
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
/* readonly attribute nsIPrintSettings currentPrintSettings; */
|
|
|
|
NS_IMETHODIMP
|
|
|
|
DocumentViewerImpl::GetCurrentPrintSettings(nsIPrintSettings * *aCurrentPrintSettings)
|
2001-04-18 10:06:31 +04:00
|
|
|
{
|
2002-08-21 16:01:05 +04:00
|
|
|
#ifdef NS_PRINTING
|
|
|
|
NS_ENSURE_ARG_POINTER(aCurrentPrintSettings);
|
2001-04-18 10:06:31 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
*aCurrentPrintSettings = nsnull;
|
|
|
|
NS_ENSURE_TRUE(mPrintEngine, NS_ERROR_FAILURE);
|
2001-04-18 10:06:31 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
return mPrintEngine->GetCurrentPrintSettings(aCurrentPrintSettings);
|
|
|
|
#else
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
#endif
|
2001-04-18 10:06:31 +04:00
|
|
|
}
|
2000-02-16 04:39:30 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
/* readonly attribute nsIDOMWindow currentChildDOMWindow; */
|
|
|
|
NS_IMETHODIMP
|
|
|
|
DocumentViewerImpl::GetCurrentChildDOMWindow(nsIDOMWindow * *aCurrentChildDOMWindow)
|
2000-01-19 00:06:10 +03:00
|
|
|
{
|
2002-08-21 16:01:05 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aCurrentChildDOMWindow);
|
|
|
|
*aCurrentChildDOMWindow = nsnull;
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
2002-04-17 08:17:16 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
/* void cancel (); */
|
|
|
|
NS_IMETHODIMP
|
|
|
|
DocumentViewerImpl::Cancel()
|
|
|
|
{
|
|
|
|
#ifdef NS_PRINTING
|
|
|
|
NS_ENSURE_TRUE(mPrintEngine, NS_ERROR_FAILURE);
|
|
|
|
return mPrintEngine->Cancelled();
|
|
|
|
#else
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
#endif
|
|
|
|
}
|
2000-02-16 04:39:30 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
/* void exitPrintPreview (); */
|
|
|
|
NS_IMETHODIMP
|
|
|
|
DocumentViewerImpl::ExitPrintPreview()
|
|
|
|
{
|
|
|
|
#ifdef NS_PRINTING
|
|
|
|
if (GetIsPrinting()) return NS_ERROR_FAILURE;
|
|
|
|
NS_ENSURE_TRUE(mPrintEngine, NS_ERROR_FAILURE);
|
2002-04-17 08:17:16 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
if (GetIsPrintPreview()) {
|
|
|
|
ReturnToGalleyPresentation();
|
2002-04-17 08:17:16 +04:00
|
|
|
}
|
2000-01-19 00:06:10 +03:00
|
|
|
return NS_OK;
|
2002-08-21 16:01:05 +04:00
|
|
|
#else
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
#endif
|
2000-01-19 00:06:10 +03:00
|
|
|
}
|
2000-02-10 07:35:51 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
//----------------------------------------------------------------------------------
|
|
|
|
// Enumerate all the documents for their titles
|
|
|
|
NS_IMETHODIMP
|
|
|
|
DocumentViewerImpl::EnumerateDocumentNames(PRUint32* aCount,
|
|
|
|
PRUnichar*** aResult)
|
2000-04-22 01:40:28 +04:00
|
|
|
{
|
2002-08-21 16:01:05 +04:00
|
|
|
#ifdef NS_PRINTING
|
|
|
|
NS_ENSURE_ARG(aCount);
|
|
|
|
NS_ENSURE_ARG_POINTER(aResult);
|
|
|
|
NS_ENSURE_TRUE(mPrintEngine, NS_ERROR_FAILURE);
|
2000-04-22 01:40:28 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
return mPrintEngine->EnumerateDocumentNames(aCount, aResult);
|
|
|
|
#else
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
#endif
|
|
|
|
}
|
2000-04-22 01:40:28 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
/* readonly attribute boolean isFramesetFrameSelected; */
|
|
|
|
NS_IMETHODIMP
|
|
|
|
DocumentViewerImpl::GetIsFramesetFrameSelected(PRBool *aIsFramesetFrameSelected)
|
2000-04-22 01:40:28 +04:00
|
|
|
{
|
2002-08-21 16:01:05 +04:00
|
|
|
#ifdef NS_PRINTING
|
|
|
|
*aIsFramesetFrameSelected = PR_FALSE;
|
|
|
|
NS_ENSURE_TRUE(mPrintEngine, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
return mPrintEngine->GetIsFramesetFrameSelected(aIsFramesetFrameSelected);
|
|
|
|
#else
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
#endif
|
2000-04-22 01:40:28 +04:00
|
|
|
}
|
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
/* readonly attribute long printPreviewNumPages; */
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
NS_IMETHODIMP
|
2002-08-21 16:01:05 +04:00
|
|
|
DocumentViewerImpl::GetPrintPreviewNumPages(PRInt32 *aPrintPreviewNumPages)
|
2000-04-22 01:40:28 +04:00
|
|
|
{
|
2002-08-21 16:01:05 +04:00
|
|
|
#ifdef NS_PRINTING
|
|
|
|
NS_ENSURE_ARG_POINTER(aPrintPreviewNumPages);
|
|
|
|
NS_ENSURE_TRUE(mPrintEngine, NS_ERROR_FAILURE);
|
2000-04-22 01:40:28 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
return mPrintEngine->GetPrintPreviewNumPages(aPrintPreviewNumPages);
|
|
|
|
#else
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
#endif
|
2000-04-22 01:40:28 +04:00
|
|
|
}
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
/* readonly attribute boolean isFramesetDocument; */
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
NS_IMETHODIMP
|
2002-08-21 16:01:05 +04:00
|
|
|
DocumentViewerImpl::GetIsFramesetDocument(PRBool *aIsFramesetDocument)
|
2000-04-22 01:40:28 +04:00
|
|
|
{
|
2002-08-21 16:01:05 +04:00
|
|
|
#ifdef NS_PRINTING
|
|
|
|
*aIsFramesetDocument = PR_FALSE;
|
|
|
|
NS_ENSURE_TRUE(mPrintEngine, NS_ERROR_FAILURE);
|
2000-04-22 01:40:28 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
return mPrintEngine->GetIsFramesetDocument(aIsFramesetDocument);
|
|
|
|
#else
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
#endif
|
|
|
|
}
|
2002-04-17 08:17:16 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
/* readonly attribute boolean isIFrameSelected; */
|
|
|
|
NS_IMETHODIMP
|
|
|
|
DocumentViewerImpl::GetIsIFrameSelected(PRBool *aIsIFrameSelected)
|
|
|
|
{
|
|
|
|
#ifdef NS_PRINTING
|
|
|
|
*aIsIFrameSelected = PR_FALSE;
|
|
|
|
NS_ENSURE_TRUE(mPrintEngine, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
return mPrintEngine->GetIsIFrameSelected(aIsIFrameSelected);
|
|
|
|
#else
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/* readonly attribute boolean isRangeSelection; */
|
|
|
|
NS_IMETHODIMP
|
|
|
|
DocumentViewerImpl::GetIsRangeSelection(PRBool *aIsRangeSelection)
|
|
|
|
{
|
|
|
|
#ifdef NS_PRINTING
|
|
|
|
*aIsRangeSelection = PR_FALSE;
|
|
|
|
NS_ENSURE_TRUE(mPrintEngine, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
return mPrintEngine->GetIsRangeSelection(aIsRangeSelection);
|
|
|
|
#else
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
#endif
|
2000-04-22 01:40:28 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
//----------------------------------------------------------------------------------
|
|
|
|
// Printing/Print Preview Helpers
|
|
|
|
//----------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
//------------------------------------------------------------
|
|
|
|
PRBool
|
|
|
|
DocumentViewerImpl::GetIsPrinting()
|
2000-04-22 01:40:28 +04:00
|
|
|
{
|
2002-08-21 16:01:05 +04:00
|
|
|
#ifdef NS_PRINTING
|
|
|
|
if (mPrintEngine) {
|
|
|
|
return mPrintEngine->GetIsPrinting();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return PR_FALSE;
|
2000-04-22 02:17:14 +04:00
|
|
|
}
|
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
//------------------------------------------------------------
|
|
|
|
void
|
|
|
|
DocumentViewerImpl::SetIsPrinting(PRBool aIsPrinting)
|
|
|
|
{
|
|
|
|
#ifdef NS_PRINTING
|
|
|
|
if (mPrintEngine) {
|
|
|
|
mPrintEngine->SetIsPrinting(aIsPrinting);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
2001-02-01 23:49:10 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
//------------------------------------------------------------
|
2002-04-17 08:17:16 +04:00
|
|
|
PRBool
|
2002-08-21 16:01:05 +04:00
|
|
|
DocumentViewerImpl::GetIsPrintPreview()
|
|
|
|
{
|
|
|
|
#ifdef NS_PRINTING
|
|
|
|
if (mPrintEngine) {
|
|
|
|
return mPrintEngine->GetIsPrintPreview();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2001-02-07 02:03:17 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
//------------------------------------------------------------
|
|
|
|
void
|
|
|
|
DocumentViewerImpl::SetIsPrintPreview(PRBool aIsPrintPreview)
|
|
|
|
{
|
|
|
|
#ifdef NS_PRINTING
|
|
|
|
if (mPrintEngine) {
|
|
|
|
mPrintEngine->SetIsPrintPreview(aIsPrintPreview);
|
|
|
|
}
|
|
|
|
#endif
|
2001-02-07 02:03:17 +03:00
|
|
|
}
|
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
//------------------------------------------------------------
|
|
|
|
PRBool
|
|
|
|
DocumentViewerImpl::GetIsCreatingPrintPreview()
|
|
|
|
{
|
|
|
|
#if defined(NS_PRINTING) && defined(NS_PRINT_PREVIEW)
|
|
|
|
if (mPrintEngine) {
|
|
|
|
return mPrintEngine->GetIsCreatingPrintPreview();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2002-02-01 17:52:11 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
//------------------------------------------------------------
|
2002-04-17 08:17:16 +04:00
|
|
|
void
|
2002-08-21 16:01:05 +04:00
|
|
|
DocumentViewerImpl::SetIsCreatingPrintPreview(PRBool aIsCreatingPrintPreview)
|
2002-02-01 17:52:11 +03:00
|
|
|
{
|
2002-08-21 16:01:05 +04:00
|
|
|
#ifdef NS_PRINTING
|
|
|
|
if (mPrintEngine) {
|
|
|
|
mPrintEngine->SetIsCreatingPrintPreview(aIsCreatingPrintPreview);
|
2002-02-01 17:52:11 +03:00
|
|
|
}
|
2002-08-21 16:01:05 +04:00
|
|
|
#endif
|
2002-02-01 17:52:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------
|
2002-08-21 16:01:05 +04:00
|
|
|
// nsIDocumentViewerPrint IFace
|
|
|
|
//----------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
//------------------------------------------------------------
|
|
|
|
void
|
|
|
|
DocumentViewerImpl::IncrementDestroyRefCount()
|
2002-02-01 17:52:11 +03:00
|
|
|
{
|
2002-08-21 16:01:05 +04:00
|
|
|
++mDestroyRefCount;
|
|
|
|
}
|
2002-02-01 17:52:11 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
//------------------------------------------------------------
|
|
|
|
void
|
|
|
|
DocumentViewerImpl::ReturnToGalleyPresentation()
|
|
|
|
{
|
|
|
|
#if defined(NS_PRINTING) && defined(NS_PRINT_PREVIEW)
|
|
|
|
if (!GetIsPrintPreview()) {
|
|
|
|
NS_ASSERTION(0, "Wow, we should never get here!");
|
|
|
|
return;
|
|
|
|
}
|
2002-04-17 08:17:16 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
// Get the current size of what is being viewed
|
|
|
|
nsRect area;
|
|
|
|
mPresContext->GetVisibleArea(area);
|
2002-04-17 08:17:16 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
nsRect bounds;
|
|
|
|
mWindow->GetBounds(bounds);
|
|
|
|
|
|
|
|
// In case we have focus focus the parent DocShell
|
|
|
|
// which in this case should always be chrome
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> dstParentItem;
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> dstItem(do_QueryInterface(mContainer));
|
|
|
|
if (dstItem) {
|
|
|
|
dstItem->GetParent(getter_AddRefs(dstParentItem));
|
|
|
|
nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(dstParentItem));
|
|
|
|
if (docShell) {
|
|
|
|
docShell->SetHasFocus(PR_TRUE);
|
2002-02-01 17:52:11 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
// Start to kill off the old Presentation
|
|
|
|
// by cleaning up the PresShell
|
|
|
|
if (mPresShell) {
|
|
|
|
// Break circular reference (or something)
|
|
|
|
mPresShell->EndObservingDocument();
|
|
|
|
nsCOMPtr<nsISelection> selection;
|
|
|
|
nsresult rv = GetDocumentSelection(getter_AddRefs(selection));
|
|
|
|
nsCOMPtr<nsISelectionPrivate> selPrivate(do_QueryInterface(selection));
|
|
|
|
if (NS_SUCCEEDED(rv) && selPrivate && mSelectionListener)
|
|
|
|
selPrivate->RemoveSelectionListener(mSelectionListener);
|
|
|
|
mPresShell->Destroy();
|
|
|
|
}
|
2002-02-01 17:52:11 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
// clear weak references before we go away
|
|
|
|
if (mPresContext) {
|
|
|
|
mPresContext->SetContainer(nsnull);
|
|
|
|
mPresContext->SetLinkHandler(nsnull);
|
|
|
|
}
|
2002-02-01 17:52:11 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
// wasCached will be used below to indicate whether the
|
|
|
|
// InitInternal should create all new objects or just
|
|
|
|
// initialize the existing ones
|
|
|
|
PRBool wasCached = PR_FALSE;
|
2002-02-01 17:52:11 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
if (mPrintEngine && mPrintEngine->HasCachedPres()) {
|
2002-02-01 17:52:11 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
mPrintEngine->GetCachedPresentation(mPresShell, mPresContext, mViewManager, mWindow);
|
2002-04-17 08:17:16 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
// Tell the "real" presshell to start observing the document
|
|
|
|
// again.
|
|
|
|
mPresShell->BeginObservingDocument();
|
2002-04-23 03:12:18 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
mWindow->Show(PR_TRUE);
|
2002-04-17 08:17:16 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
// Very important! Turn On scripting
|
|
|
|
mPrintEngine->TurnScriptingOn(PR_TRUE);
|
2002-04-17 08:17:16 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
mPrintEngine->Destroy();
|
|
|
|
NS_RELEASE(mPrintEngine);
|
2002-04-17 08:17:16 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
wasCached = PR_TRUE;
|
|
|
|
} else {
|
|
|
|
// Destroy the old Presentation
|
|
|
|
mPresShell = nsnull;
|
|
|
|
mPresContext = nsnull;
|
|
|
|
mViewManager = nsnull;
|
|
|
|
mWindow = nsnull;
|
2002-04-23 03:12:18 +04:00
|
|
|
}
|
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
if (mPrintEngine) {
|
|
|
|
// Very important! Turn On scripting
|
|
|
|
mPrintEngine->TurnScriptingOn(PR_TRUE);
|
|
|
|
}
|
2002-04-23 03:12:18 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
InitInternal(mParentWidget, mDeviceContext, bounds, !wasCached);
|
2002-04-23 03:12:18 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
if (mPrintEngine && !mPrintEngine->HasCachedPres()) {
|
|
|
|
mPrintEngine->Destroy();
|
|
|
|
NS_RELEASE(mPrintEngine);
|
2002-04-23 03:12:18 +04:00
|
|
|
}
|
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
// this needs to be set here not earlier,
|
|
|
|
// because it is needing when re-constructing the Galley Mode)
|
|
|
|
SetIsPrintPreview(PR_FALSE);
|
|
|
|
|
|
|
|
mViewManager->EnableRefresh(NS_VMREFRESH_NO_SYNC);
|
|
|
|
|
|
|
|
Show();
|
|
|
|
|
|
|
|
#endif // NS_PRINTING && NS_PRINT_PREVIEW
|
2002-04-23 03:12:18 +04:00
|
|
|
}
|
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
//------------------------------------------------------------
|
|
|
|
void
|
|
|
|
DocumentViewerImpl::InstallNewPresentation()
|
2002-04-23 03:12:18 +04:00
|
|
|
{
|
2002-08-21 16:01:05 +04:00
|
|
|
#if defined(NS_PRINTING) && defined(NS_PRINT_PREVIEW)
|
|
|
|
// Get the current size of what is being viewed
|
|
|
|
nsRect area;
|
|
|
|
mPresContext->GetVisibleArea(area);
|
2002-04-17 08:17:16 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
nsRect bounds;
|
|
|
|
mWindow->GetBounds(bounds);
|
2002-04-17 08:17:16 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
// In case we have focus focus the parent DocShell
|
|
|
|
// which in this case should always be chrome
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> dstParentItem;
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> dstItem(do_QueryInterface(mContainer));
|
|
|
|
if (dstItem) {
|
|
|
|
dstItem->GetParent(getter_AddRefs(dstParentItem));
|
|
|
|
nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(dstParentItem));
|
|
|
|
if (docShell) {
|
|
|
|
docShell->SetHasFocus(PR_TRUE);
|
2002-04-17 08:17:16 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
// turn off selection painting
|
|
|
|
nsCOMPtr<nsISelectionController> selectionController =
|
|
|
|
do_QueryInterface(mPresShell);
|
|
|
|
if (selectionController) {
|
|
|
|
selectionController->SetDisplaySelection(nsISelectionController::SELECTION_OFF);
|
|
|
|
}
|
2002-02-01 17:52:11 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
// Start to kill off the old Presentation
|
|
|
|
// by cleaning up the PresShell
|
|
|
|
if (mPresShell) {
|
|
|
|
// Break circular reference (or something)
|
|
|
|
mPresShell->EndObservingDocument();
|
|
|
|
nsCOMPtr<nsISelection> selection;
|
|
|
|
nsresult rv = GetDocumentSelection(getter_AddRefs(selection));
|
|
|
|
nsCOMPtr<nsISelectionPrivate> selPrivate(do_QueryInterface(selection));
|
|
|
|
if (NS_SUCCEEDED(rv) && selPrivate && mSelectionListener)
|
|
|
|
selPrivate->RemoveSelectionListener(mSelectionListener);
|
2002-03-07 15:57:33 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
// We need to destroy the PreShell if there is an existing PP
|
|
|
|
// or we are not caching the original Presentation
|
|
|
|
if (!mPrintEngine->IsCachingPres() || mPrintEngine->IsOldPrintPreviewPres()) {
|
|
|
|
mPresShell->Destroy();
|
|
|
|
}
|
|
|
|
}
|
2002-03-07 15:57:33 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
// clear weak references before we go away
|
|
|
|
if (mPresContext) {
|
|
|
|
mPresContext->SetContainer(nsnull);
|
|
|
|
mPresContext->SetLinkHandler(nsnull);
|
|
|
|
}
|
2002-03-07 15:57:33 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
// See if we are suppose to be caching the old Presentation
|
|
|
|
// and then check to see if we already have.
|
|
|
|
if (mPrintEngine->IsCachingPres() && !mPrintEngine->HasCachedPres()) {
|
|
|
|
// Cach old presentation
|
|
|
|
mPrintEngine->CachePresentation(mPresShell, mPresContext, mViewManager, mWindow);
|
|
|
|
mWindow->Show(PR_FALSE);
|
2002-03-07 15:57:33 +03:00
|
|
|
} else {
|
2002-08-21 16:01:05 +04:00
|
|
|
// Destroy the old Presentation
|
|
|
|
mPresShell = nsnull;
|
|
|
|
mPresContext = nsnull;
|
|
|
|
mViewManager = nsnull;
|
|
|
|
mWindow = nsnull;
|
2002-03-07 15:57:33 +03:00
|
|
|
}
|
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
// XXX InstallPrintPreviewListener();
|
2002-05-16 17:51:54 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
mPrintEngine->GetNewPresentation(mPresShell, mPresContext, mViewManager, mWindow);
|
2002-02-01 17:52:11 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
mPresShell->BeginObservingDocument();
|
2001-02-01 23:49:10 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
nscoord width = bounds.width;
|
|
|
|
nscoord height = bounds.height;
|
|
|
|
float p2t;
|
|
|
|
mPresContext->GetPixelsToTwips(&p2t);
|
|
|
|
width = NSIntPixelsToTwips(width, p2t);
|
|
|
|
height = NSIntPixelsToTwips(height, p2t);
|
|
|
|
mViewManager->DisableRefresh();
|
|
|
|
mViewManager->SetWindowDimensions(width, height);
|
2001-03-27 15:56:03 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
mDeviceContext->SetUseAltDC(kUseAltDCFor_FONTMETRICS, PR_FALSE);
|
|
|
|
mDeviceContext->SetUseAltDC(kUseAltDCFor_CREATERC_PAINT, PR_TRUE);
|
2001-03-27 15:56:03 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
mViewManager->EnableRefresh(NS_VMREFRESH_NO_SYNC);
|
2001-08-06 06:27:43 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
Show();
|
2001-03-27 15:56:03 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
mPrintEngine->ShowDocList(PR_TRUE);
|
|
|
|
#endif // NS_PRINTING && NS_PRINT_PREVIEW
|
2001-03-27 15:56:03 +04:00
|
|
|
}
|
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
//------------------------------------------------------------
|
2002-09-10 05:57:09 +04:00
|
|
|
// This called ONLY when printing has completed and the DV
|
|
|
|
// is being notified that it should get rid of the PrintEngine.
|
|
|
|
//
|
|
|
|
// BUT, if we are in Print Preview then we want to ignore the
|
|
|
|
// notification (we do not get rid of the PrintEngine)
|
|
|
|
//
|
|
|
|
// One small caveat:
|
|
|
|
// This IS called from two places in this module for cleaning
|
|
|
|
// up when an error occurred during the start up printing
|
|
|
|
// and print preview
|
|
|
|
//
|
2002-08-21 16:01:05 +04:00
|
|
|
void
|
|
|
|
DocumentViewerImpl::OnDonePrinting()
|
2002-07-09 16:39:02 +04:00
|
|
|
{
|
2002-08-21 16:01:05 +04:00
|
|
|
#if defined(NS_PRINTING) && defined(NS_PRINT_PREVIEW)
|
|
|
|
if (mPrintEngine) {
|
2002-09-10 05:57:09 +04:00
|
|
|
if (GetIsPrintPreview()) {
|
|
|
|
mPrintEngine->DestroyPrintingData();
|
|
|
|
} else {
|
|
|
|
mPrintEngine->Destroy();
|
|
|
|
NS_RELEASE(mPrintEngine);
|
|
|
|
}
|
2002-07-09 16:39:02 +04:00
|
|
|
}
|
2002-08-21 16:01:05 +04:00
|
|
|
#endif // NS_PRINTING && NS_PRINT_PREVIEW
|
2002-07-09 16:39:02 +04:00
|
|
|
}
|