2001-11-27 12:30:15 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2005-08-15 22:16:42 +04:00
|
|
|
/* vim: set ts=2 sw=2 et tw=80: */
|
2001-09-25 05:32:19 +04:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-18 01:52:36 +04:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1999-05-06 23:25:40 +04:00
|
|
|
*
|
2004-04-18 01:52:36 +04:00
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
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.
|
|
|
|
*
|
2004-04-18 01:52:36 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-25 05:32:19 +04:00
|
|
|
* 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>
|
2011-08-25 00:54:30 +04:00
|
|
|
* Mats Palmgren <matspal@gmail.com>
|
2001-09-25 05:32:19 +04:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-18 01:52:36 +04:00
|
|
|
* either of 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"),
|
2001-09-25 05:32:19 +04:00
|
|
|
* 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
|
2004-04-18 01:52:36 +04:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-25 05:32:19 +04:00
|
|
|
* 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
|
2004-04-18 01:52:36 +04:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-25 05:32:19 +04:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
2001-04-18 10:06:31 +04:00
|
|
|
|
2006-03-30 09:56:38 +04:00
|
|
|
/* container for a document and its presentation */
|
|
|
|
|
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"
|
2011-10-15 11:33:26 +04:00
|
|
|
#include "nsIContentViewer.h"
|
2010-04-30 23:40:59 +04:00
|
|
|
#include "mozilla/FunctionTimer.h"
|
2002-08-21 16:01:05 +04:00
|
|
|
#include "nsIDocumentViewerPrint.h"
|
2009-06-24 12:42:00 +04:00
|
|
|
#include "nsIPrivateDOMEvent.h"
|
|
|
|
#include "nsIDOMBeforeUnloadEvent.h"
|
1999-05-06 23:25:40 +04:00
|
|
|
#include "nsIDocument.h"
|
2004-08-01 03:15:21 +04:00
|
|
|
#include "nsPresContext.h"
|
1999-05-06 23:25:40 +04:00
|
|
|
#include "nsIPresShell.h"
|
2004-01-08 01:30:53 +03:00
|
|
|
#include "nsStyleSet.h"
|
1999-05-06 23:25:40 +04:00
|
|
|
#include "nsIStyleSheet.h"
|
2010-05-12 00:41:47 +04:00
|
|
|
#include "nsCSSStyleSheet.h"
|
1999-05-06 23:25:40 +04:00
|
|
|
#include "nsIFrame.h"
|
2010-09-18 15:28:50 +04:00
|
|
|
#include "nsSubDocumentFrame.h"
|
1999-05-06 23:25:40 +04:00
|
|
|
|
|
|
|
#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 "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"
|
2004-12-07 05:28:38 +03:00
|
|
|
#include "nsContentUtils.h"
|
2004-03-09 22:59:09 +03:00
|
|
|
#include "nsLayoutStylesheetCache.h"
|
2011-05-28 11:03:00 +04:00
|
|
|
#include "mozilla/Preferences.h"
|
1999-05-06 23:25:40 +04:00
|
|
|
|
|
|
|
#include "nsViewsCID.h"
|
|
|
|
#include "nsIDeviceContextSpec.h"
|
|
|
|
#include "nsIViewManager.h"
|
|
|
|
#include "nsIView.h"
|
|
|
|
|
|
|
|
#include "nsIPageSequenceFrame.h"
|
|
|
|
#include "nsIURL.h"
|
2004-03-09 22:59:09 +03:00
|
|
|
#include "nsNetUtil.h"
|
1999-11-19 10:35:27 +03:00
|
|
|
#include "nsIContentViewerEdit.h"
|
|
|
|
#include "nsIContentViewerFile.h"
|
2010-06-29 02:49:35 +04:00
|
|
|
#include "mozilla/css/Loader.h"
|
1999-11-19 10:35:27 +03:00
|
|
|
#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-10-20 01:49:12 +04:00
|
|
|
#include "nsILayoutHistoryState.h"
|
2012-03-22 18:42:42 +04:00
|
|
|
#include "nsCharsetSource.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"
|
2004-06-05 21:57:00 +04:00
|
|
|
#include "nsIImageLoadingContent.h"
|
|
|
|
#include "nsCopySupport.h"
|
2002-08-21 16:01:05 +04:00
|
|
|
#include "nsIDOMHTMLFrameSetElement.h"
|
2003-04-11 04:56:27 +04:00
|
|
|
#ifdef MOZ_XUL
|
2004-12-25 01:27:57 +03:00
|
|
|
#include "nsIXULDocument.h"
|
2007-07-04 19:49:38 +04:00
|
|
|
#include "nsXULPopupManager.h"
|
2007-07-24 04:04:36 +04:00
|
|
|
#endif
|
2000-10-29 02:17:53 +04:00
|
|
|
|
2002-08-02 01:36:02 +04:00
|
|
|
#include "nsIClipboardHelper.h"
|
1999-05-14 18:40:59 +04:00
|
|
|
|
2001-02-01 23:49:10 +03:00
|
|
|
#include "nsPIDOMWindow.h"
|
2011-06-23 14:39:48 +04:00
|
|
|
#include "nsDOMNavigationTiming.h"
|
2010-02-20 19:07:03 +03:00
|
|
|
#include "nsPIWindowRoot.h"
|
2007-01-11 03:02:58 +03:00
|
|
|
#include "nsJSEnvironment.h"
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 22:00:39 +04:00
|
|
|
#include "nsFocusManager.h"
|
2001-02-01 23:49:10 +03:00
|
|
|
|
2009-09-03 08:26:00 +04:00
|
|
|
#include "nsIScrollableFrame.h"
|
2004-09-04 23:51:21 +04:00
|
|
|
#include "nsIHTMLDocument.h"
|
2002-08-21 16:01:05 +04:00
|
|
|
#include "nsGfxCIID.h"
|
2005-01-15 03:10:19 +03:00
|
|
|
#include "nsStyleSheetService.h"
|
2009-02-16 14:27:22 +03:00
|
|
|
#include "nsURILoader.h"
|
2011-04-08 05:04:40 +04:00
|
|
|
#include "nsRenderingContext.h"
|
2002-08-21 16:01:05 +04:00
|
|
|
|
2005-09-16 06:25:37 +04:00
|
|
|
#include "nsIPrompt.h"
|
|
|
|
#include "imgIContainer.h" // image animation mode constants
|
2002-08-21 16:01:05 +04:00
|
|
|
|
|
|
|
//--------------------------
|
|
|
|
// Printing Include
|
|
|
|
//---------------------------
|
|
|
|
#ifdef NS_PRINTING
|
|
|
|
|
2005-09-16 06:25:37 +04:00
|
|
|
#include "nsIWebBrowserPrint.h"
|
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
#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"
|
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"
|
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 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
|
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"
|
2003-03-22 06:20:23 +03:00
|
|
|
#include "nsIPluginDocument.h"
|
2001-04-12 17:04:29 +04: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 "nsIWindowWatcher.h"
|
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
// Printing
|
|
|
|
#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
|
|
|
|
2000-04-22 01:40:28 +04:00
|
|
|
//focus
|
2007-05-14 13:11:38 +04:00
|
|
|
#include "nsIDOMEventTarget.h"
|
2011-06-28 21:59:14 +04:00
|
|
|
#include "nsIDOMEventListener.h"
|
2000-04-27 11:37:12 +04:00
|
|
|
#include "nsISelectionController.h"
|
2000-04-22 01:40:28 +04:00
|
|
|
|
2002-02-19 23:41:32 +03:00
|
|
|
#include "nsBidiUtils.h"
|
2005-05-05 00:22:32 +04:00
|
|
|
#include "nsISHEntry.h"
|
|
|
|
#include "nsISHistory.h"
|
|
|
|
#include "nsISHistoryInternal.h"
|
|
|
|
#include "nsIWebNavigation.h"
|
2005-05-15 04:30:02 +04:00
|
|
|
#include "nsWeakPtr.h"
|
2006-03-07 20:08:51 +03:00
|
|
|
#include "nsEventDispatcher.h"
|
2001-04-13 03:35:24 +04:00
|
|
|
|
2004-01-09 17:20:53 +03:00
|
|
|
//paint forcing
|
|
|
|
#include "prenv.h"
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2012-01-07 04:42:42 +04:00
|
|
|
#include "nsObserverService.h"
|
|
|
|
|
2011-07-20 23:18:54 +04:00
|
|
|
#include "mozilla/dom/Element.h"
|
|
|
|
|
2012-01-25 22:59:55 +04:00
|
|
|
#include "jsfriendapi.h"
|
|
|
|
|
2011-05-28 11:03:00 +04:00
|
|
|
using namespace mozilla;
|
|
|
|
|
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
|
|
|
|
|
|
|
|
static PRLogModuleInfo * kPrintingLogMod = PR_NewLogModule("printing");
|
|
|
|
#define PR_PL(_p1) PR_LOG(kPrintingLogMod, PR_LOG_DEBUG, _p1);
|
|
|
|
|
|
|
|
#define PRT_YESNO(_p) ((_p)?"YES":"NO")
|
|
|
|
#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;
|
|
|
|
|
|
|
|
// a small delegate class used to avoid circular references
|
|
|
|
|
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)
|
2011-10-17 18:59:28 +04:00
|
|
|
, mGotSelectionState(false)
|
|
|
|
, mSelectionWasCollapsed(false)
|
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;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mGotSelectionState;
|
|
|
|
bool 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
|
|
|
|
*/
|
2011-06-28 21:59:14 +04:00
|
|
|
class nsDocViewerFocusListener : public nsIDOMEventListener
|
2000-04-22 01:40:28 +04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/** default constructor
|
|
|
|
*/
|
|
|
|
nsDocViewerFocusListener();
|
|
|
|
/** default destructor
|
|
|
|
*/
|
|
|
|
virtual ~nsDocViewerFocusListener();
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
2011-06-28 21:59:14 +04:00
|
|
|
NS_DECL_NSIDOMEVENTLISTENER
|
2000-04-22 01:40:28 +04:00
|
|
|
|
|
|
|
nsresult Init(DocumentViewerImpl *aDocViewer);
|
|
|
|
|
|
|
|
private:
|
|
|
|
DocumentViewerImpl* mDocViewer;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2001-04-12 17:04:29 +04:00
|
|
|
//-------------------------------------------------------------
|
2011-10-15 11:33:26 +04:00
|
|
|
class DocumentViewerImpl : public nsIContentViewer,
|
1999-11-19 10:35:27 +03:00
|
|
|
public nsIContentViewerEdit,
|
|
|
|
public nsIContentViewerFile,
|
2011-05-30 20:36:23 +04:00
|
|
|
public nsIMarkupDocumentViewer,
|
2002-08-21 16:01:05 +04:00
|
|
|
public nsIDocumentViewerPrint
|
2005-09-16 06:25:37 +04:00
|
|
|
|
|
|
|
#ifdef NS_PRINTING
|
|
|
|
, public nsIWebBrowserPrint
|
|
|
|
#endif
|
|
|
|
|
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:
|
2007-02-23 07:50:06 +03:00
|
|
|
DocumentViewerImpl();
|
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
|
|
|
|
1999-11-19 10:35:27 +03:00
|
|
|
// nsIContentViewerEdit
|
|
|
|
NS_DECL_NSICONTENTVIEWEREDIT
|
|
|
|
|
|
|
|
// nsIContentViewerFile
|
|
|
|
NS_DECL_NSICONTENTVIEWERFILE
|
|
|
|
|
|
|
|
// nsIMarkupDocumentViewer
|
|
|
|
NS_DECL_NSIMARKUPDOCUMENTVIEWER
|
|
|
|
|
2005-09-16 06:25:37 +04:00
|
|
|
#ifdef NS_PRINTING
|
2002-02-01 17:52:11 +03:00
|
|
|
// nsIWebBrowserPrint
|
|
|
|
NS_DECL_NSIWEBBROWSERPRINT
|
2005-09-16 06:25:37 +04:00
|
|
|
#endif
|
2002-02-01 17:52:11 +03:00
|
|
|
|
2000-04-03 01:52:17 +04:00
|
|
|
typedef void (*CallChildFunc)(nsIMarkupDocumentViewer* aViewer,
|
|
|
|
void* aClosure);
|
2004-12-01 06:28:44 +03:00
|
|
|
void CallChildren(CallChildFunc aFunc, void* aClosure);
|
2000-04-03 01:52:17 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
// nsIDocumentViewerPrint Printing Methods
|
2002-10-08 17:17:56 +04:00
|
|
|
NS_DECL_NSIDOCUMENTVIEWERPRINT
|
2002-08-21 16:01:05 +04:00
|
|
|
|
2011-05-14 16:03:58 +04:00
|
|
|
|
|
|
|
static void DispatchBeforePrint(nsIDocument* aTop)
|
|
|
|
{
|
|
|
|
DispatchEventToWindowTree(aTop, NS_LITERAL_STRING("beforeprint"));
|
|
|
|
}
|
|
|
|
static void DispatchAfterPrint(nsIDocument* aTop)
|
|
|
|
{
|
|
|
|
DispatchEventToWindowTree(aTop, NS_LITERAL_STRING("afterprint"));
|
|
|
|
}
|
|
|
|
static void DispatchEventToWindowTree(nsIDocument* aTop,
|
|
|
|
const nsAString& aEvent);
|
|
|
|
|
1999-05-06 23:25:40 +04:00
|
|
|
protected:
|
|
|
|
virtual ~DocumentViewerImpl();
|
|
|
|
|
|
|
|
private:
|
2007-12-01 13:42:12 +03:00
|
|
|
/**
|
|
|
|
* Creates a view manager, root view, and widget for the root view, setting
|
|
|
|
* mViewManager and mWindow.
|
|
|
|
* @param aSize the initial size in appunits
|
2009-07-22 04:44:53 +04:00
|
|
|
* @param aContainerView the container view to hook our root view up
|
|
|
|
* to as a child, or null if this will be the root view manager
|
2007-12-01 13:42:12 +03:00
|
|
|
*/
|
2009-07-22 04:44:53 +04:00
|
|
|
nsresult MakeWindow(const nsSize& aSize, nsIView* aContainerView);
|
|
|
|
|
2008-08-18 23:22:19 +04:00
|
|
|
/**
|
|
|
|
* Create our device context
|
|
|
|
*/
|
2009-07-22 04:45:10 +04:00
|
|
|
nsresult CreateDeviceContext(nsIView* aContainerView);
|
2008-08-18 23:22:19 +04:00
|
|
|
|
|
|
|
/**
|
2009-07-22 04:45:10 +04:00
|
|
|
* If aDoCreation is true, this creates the device context, creates a
|
|
|
|
* prescontext if necessary, and calls MakeWindow.
|
2011-01-21 22:09:11 +03:00
|
|
|
*
|
|
|
|
* If aForceSetNewDocument is false, then SetNewDocument won't be
|
|
|
|
* called if the window's current document is already mDocument.
|
2008-08-18 23:22:19 +04:00
|
|
|
*/
|
2002-03-26 14:43:40 +03:00
|
|
|
nsresult InitInternal(nsIWidget* aParentWidget,
|
2005-08-15 22:16:42 +04:00
|
|
|
nsISupports *aState,
|
2009-01-15 06:27:09 +03:00
|
|
|
const nsIntRect& aBounds,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aDoCreation,
|
|
|
|
bool aNeedMakeCX = true,
|
|
|
|
bool aForceSetNewDocument = true);
|
2008-01-10 01:41:43 +03:00
|
|
|
/**
|
|
|
|
* @param aDoInitialReflow set to true if you want to kick off the initial
|
|
|
|
* reflow
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
nsresult InitPresentationStuff(bool aDoInitialReflow);
|
2002-04-17 08:17:16 +04:00
|
|
|
|
2001-04-18 10:06:31 +04:00
|
|
|
nsresult GetPopupNode(nsIDOMNode** aNode);
|
|
|
|
nsresult GetPopupLinkNode(nsIDOMNode** aNode);
|
2004-06-05 21:57:00 +04:00
|
|
|
nsresult GetPopupImageNode(nsIImageLoadingContent** aNode);
|
2001-04-18 10:06:31 +04:00
|
|
|
|
2001-05-25 12:49:03 +04:00
|
|
|
void PrepareToStartLoad(void);
|
2002-04-17 08:17:16 +04:00
|
|
|
|
|
|
|
nsresult SyncParentSubDocMap();
|
|
|
|
|
2006-12-10 11:05:05 +03:00
|
|
|
nsresult GetDocumentSelection(nsISelection **aSelection);
|
|
|
|
|
2009-01-14 15:24:10 +03:00
|
|
|
void DestroyPresShell();
|
2011-01-21 22:09:11 +03:00
|
|
|
void DestroyPresContext();
|
2009-01-14 15:24:10 +03:00
|
|
|
|
2002-10-08 17:17:56 +04:00
|
|
|
#ifdef NS_PRINTING
|
|
|
|
// Called when the DocViewer is notified that the state
|
|
|
|
// of Printing or PP has changed
|
|
|
|
void SetIsPrintingInDocShellTree(nsIDocShellTreeNode* aParentNode,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aIsPrintingOrPP,
|
|
|
|
bool aStartAtTop);
|
2002-10-08 17:17:56 +04:00
|
|
|
#endif // NS_PRINTING
|
|
|
|
|
2011-02-09 23:13:18 +03:00
|
|
|
// Whether we should attach to the top level widget. This is true if we
|
|
|
|
// are sharing/recycling a single base widget and not creating multiple
|
|
|
|
// child widgets.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool ShouldAttachToTopLevel();
|
2011-02-09 23:13:18 +03:00
|
|
|
|
1999-05-06 23:25:40 +04:00
|
|
|
protected:
|
2007-11-09 13:19:12 +03:00
|
|
|
// These return the current shell/prescontext etc.
|
|
|
|
nsIPresShell* GetPresShell();
|
|
|
|
nsPresContext* GetPresContext();
|
|
|
|
nsIViewManager* GetViewManager();
|
|
|
|
|
2010-06-25 06:01:06 +04:00
|
|
|
void DetachFromTopLevelWidget();
|
|
|
|
|
1999-05-06 23:25:40 +04:00
|
|
|
// 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
|
|
|
|
2005-05-15 04:30:02 +04:00
|
|
|
nsWeakPtr mContainer; // it owns me!
|
2011-03-24 14:42:54 +03:00
|
|
|
nsWeakPtr mTopContainerWhilePrinting;
|
2011-04-17 05:22:44 +04:00
|
|
|
nsRefPtr<nsDeviceContext> mDeviceContext; // We create and own this baby
|
1999-05-06 23:25:40 +04:00
|
|
|
|
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;
|
2009-07-22 04:45:10 +04:00
|
|
|
nsCOMPtr<nsIWidget> mWindow; // may be null
|
1999-05-06 23:25:40 +04:00
|
|
|
nsCOMPtr<nsIViewManager> mViewManager;
|
2010-03-25 16:17:11 +03:00
|
|
|
nsRefPtr<nsPresContext> mPresContext;
|
1999-05-06 23:25:40 +04:00
|
|
|
nsCOMPtr<nsIPresShell> mPresShell;
|
|
|
|
|
2000-09-14 15:45:01 +04:00
|
|
|
nsCOMPtr<nsISelectionListener> mSelectionListener;
|
2011-06-28 21:59:14 +04:00
|
|
|
nsRefPtr<nsDocViewerFocusListener> mFocusListener;
|
2002-04-17 08:17:16 +04:00
|
|
|
|
2001-05-02 02:50:16 +04:00
|
|
|
nsCOMPtr<nsIContentViewer> mPreviousViewer;
|
2005-05-05 00:22:32 +04:00
|
|
|
nsCOMPtr<nsISHEntry> mSHEntry;
|
1999-07-15 18:23:40 +04:00
|
|
|
|
2008-09-28 23:14:28 +04:00
|
|
|
nsIWidget* mParentWidget; // purposely won't be ref counted. May be null
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mAttachedToParent; // view is attached to the parent widget
|
1999-07-15 18:23:40 +04:00
|
|
|
|
2009-07-22 04:45:10 +04:00
|
|
|
nsIntRect mBounds;
|
|
|
|
|
2007-11-10 01:29:43 +03:00
|
|
|
// mTextZoom/mPageZoom record the textzoom/pagezoom of the first (galley)
|
|
|
|
// presshell only.
|
2006-06-12 17:49:46 +04:00
|
|
|
float mTextZoom; // Text zoom, defaults to 1.0
|
2007-08-28 05:20:17 +04:00
|
|
|
float mPageZoom;
|
2011-03-11 07:33:43 +03:00
|
|
|
int mMinFontSize;
|
2006-06-12 17:49:46 +04:00
|
|
|
|
2005-05-05 00:22:32 +04:00
|
|
|
PRInt16 mNumURLStarts;
|
|
|
|
PRInt16 mDestroyRefCount; // a second "refcount" for the document viewer's "destroy"
|
|
|
|
|
|
|
|
unsigned mStopped : 1;
|
|
|
|
unsigned mLoaded : 1;
|
|
|
|
unsigned mDeferredWindowClose : 1;
|
|
|
|
// document management data
|
|
|
|
// these items are specific to markup documents (html and xml)
|
|
|
|
// may consider splitting these out into a subclass
|
|
|
|
unsigned mIsSticky : 1;
|
|
|
|
unsigned mInPermitUnload : 1;
|
2004-02-11 09:09:51 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
#ifdef NS_PRINTING
|
2005-05-05 00:22:32 +04:00
|
|
|
unsigned mClosingWhilePrinting : 1;
|
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
#if NS_PRINT_PREVIEW
|
2009-03-08 22:01:02 +03:00
|
|
|
unsigned mPrintPreviewZoomed : 1;
|
|
|
|
|
2005-05-05 00:22:32 +04:00
|
|
|
// These data members support delayed printing when the document is loading
|
|
|
|
unsigned mPrintIsPending : 1;
|
|
|
|
unsigned mPrintDocIsFullyLoaded : 1;
|
2002-06-28 17:39:44 +04:00
|
|
|
nsCOMPtr<nsIPrintSettings> mCachedPrintSettings;
|
|
|
|
nsCOMPtr<nsIWebProgressListener> mCachedPrintWebProgressListner;
|
2001-11-03 17:59:39 +03:00
|
|
|
|
2006-12-10 11:05:05 +03:00
|
|
|
nsCOMPtr<nsPrintEngine> mPrintEngine;
|
2009-03-08 22:01:02 +03:00
|
|
|
float mOriginalPrintPreviewScale;
|
|
|
|
float mPrintPreviewZoom;
|
2005-09-16 06:25:37 +04:00
|
|
|
#endif // NS_PRINT_PREVIEW
|
2005-05-05 00:22:32 +04: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
|
|
|
|
2003-06-17 20:40:34 +04:00
|
|
|
/* character set member data */
|
|
|
|
PRInt32 mHintCharsetSource;
|
|
|
|
nsCString mHintCharset;
|
|
|
|
nsCString mDefaultCharacterSet;
|
|
|
|
nsCString mForceCharacterSet;
|
|
|
|
nsCString mPrevDocCharacterSet;
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mIsPageMode;
|
|
|
|
bool mCallerIsClosingWindow;
|
|
|
|
bool mInitializedForPrintPreview;
|
|
|
|
bool mHidden;
|
1999-05-06 23:25:40 +04:00
|
|
|
};
|
|
|
|
|
2011-05-14 16:03:58 +04:00
|
|
|
class nsPrintEventDispatcher
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsPrintEventDispatcher(nsIDocument* aTop) : mTop(aTop)
|
|
|
|
{
|
|
|
|
DocumentViewerImpl::DispatchBeforePrint(mTop);
|
|
|
|
}
|
|
|
|
~nsPrintEventDispatcher()
|
|
|
|
{
|
|
|
|
DocumentViewerImpl::DispatchAfterPrint(mTop);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocument> mTop;
|
|
|
|
};
|
|
|
|
|
2012-03-12 20:03:38 +04:00
|
|
|
class nsBeforeFirstPaintDispatcher : public nsRunnable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsBeforeFirstPaintDispatcher(nsIDocument* aDocument)
|
|
|
|
: mDocument(aDocument) {}
|
|
|
|
|
|
|
|
NS_IMETHOD Run();
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsCOMPtr<nsIDocument> mDocument;
|
|
|
|
};
|
|
|
|
|
2012-01-07 04:42:42 +04:00
|
|
|
class nsDocumentShownDispatcher : public nsRunnable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsDocumentShownDispatcher(nsCOMPtr<nsIDocument> aDocument)
|
|
|
|
: mDocument(aDocument) {}
|
|
|
|
|
|
|
|
NS_IMETHOD Run();
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsCOMPtr<nsIDocument> mDocument;
|
|
|
|
};
|
|
|
|
|
2011-05-14 16:03:58 +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);
|
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
|
2011-10-15 11:33:26 +04:00
|
|
|
NS_NewContentViewer(nsIContentViewer** aResult)
|
1999-05-06 23:25:40 +04:00
|
|
|
{
|
2007-02-23 07:50:06 +03:00
|
|
|
*aResult = new DocumentViewerImpl();
|
2002-04-17 08:17:16 +04:00
|
|
|
|
|
|
|
NS_ADDREF(*aResult);
|
|
|
|
|
|
|
|
return NS_OK;
|
1999-05-06 23:25:40 +04:00
|
|
|
}
|
|
|
|
|
2002-04-17 08:17:16 +04:00
|
|
|
void DocumentViewerImpl::PrepareToStartLoad()
|
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
mStopped = false;
|
|
|
|
mLoaded = false;
|
|
|
|
mAttachedToParent = false;
|
|
|
|
mDeferredWindowClose = false;
|
|
|
|
mCallerIsClosingWindow = false;
|
2002-08-21 16:01:05 +04:00
|
|
|
|
|
|
|
#ifdef NS_PRINTING
|
2011-10-17 18:59:28 +04:00
|
|
|
mPrintIsPending = false;
|
|
|
|
mPrintDocIsFullyLoaded = false;
|
|
|
|
mClosingWhilePrinting = 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();
|
2006-12-10 11:05:05 +03:00
|
|
|
mPrintEngine = nsnull;
|
2001-11-03 17:59:39 +03:00
|
|
|
#ifdef NS_PRINT_PREVIEW
|
2011-10-17 18:59:28 +04:00
|
|
|
SetIsPrintPreview(false);
|
2001-11-03 17:59:39 +03:00
|
|
|
#endif
|
2009-12-11 07:02:13 +03:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2003-04-05 02:37:52 +04:00
|
|
|
// Note: operator new zeros our memory, so no need to init things to null.
|
2007-02-23 07:50:06 +03:00
|
|
|
DocumentViewerImpl::DocumentViewerImpl()
|
2011-03-11 07:33:43 +03:00
|
|
|
: mTextZoom(1.0), mPageZoom(1.0), mMinFontSize(0),
|
2011-10-17 18:59:28 +04:00
|
|
|
mIsSticky(true),
|
2009-03-08 22:01:02 +03:00
|
|
|
#ifdef NS_PRINT_PREVIEW
|
|
|
|
mPrintPreviewZoom(1.0),
|
|
|
|
#endif
|
2009-12-11 07:02:13 +03:00
|
|
|
mHintCharsetSource(kCharsetUninitialized),
|
2011-10-17 18:59:28 +04:00
|
|
|
mInitializedForPrintPreview(false),
|
|
|
|
mHidden(false)
|
1999-05-06 23:25:40 +04:00
|
|
|
{
|
2001-05-25 12:49:03 +04:00
|
|
|
PrepareToStartLoad();
|
1999-05-06 23:25:40 +04:00
|
|
|
}
|
|
|
|
|
2005-09-16 06:25:37 +04:00
|
|
|
NS_IMPL_ADDREF(DocumentViewerImpl)
|
|
|
|
NS_IMPL_RELEASE(DocumentViewerImpl)
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN(DocumentViewerImpl)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIContentViewer)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIMarkupDocumentViewer)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIContentViewerFile)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIContentViewerEdit)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDocumentViewerPrint)
|
2005-09-16 23:57:20 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIContentViewer)
|
2005-09-16 06:25:37 +04:00
|
|
|
#ifdef NS_PRINTING
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIWebBrowserPrint)
|
|
|
|
#endif
|
|
|
|
NS_INTERFACE_MAP_END
|
1999-05-06 23:25:40 +04:00
|
|
|
|
|
|
|
DocumentViewerImpl::~DocumentViewerImpl()
|
|
|
|
{
|
2002-04-17 08:17:16 +04:00
|
|
|
if (mDocument) {
|
2005-05-18 07:52:33 +04:00
|
|
|
Close(nsnull);
|
2005-05-05 00:22:32 +04:00
|
|
|
mDocument->Destroy();
|
2002-04-17 08:17:16 +04:00
|
|
|
}
|
2001-08-01 07:15:50 +04:00
|
|
|
|
2004-02-11 09:48:37 +03:00
|
|
|
NS_ASSERTION(!mPresShell && !mPresContext,
|
|
|
|
"User did not call nsIContentViewer::Destroy");
|
|
|
|
if (mPresShell || mPresContext) {
|
2005-06-17 11:01:36 +04:00
|
|
|
// Make sure we don't hand out a reference to the content viewer to
|
|
|
|
// the SHEntry!
|
|
|
|
mSHEntry = nsnull;
|
|
|
|
|
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
|
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
|
|
|
|
|
2006-04-20 01:14:57 +04:00
|
|
|
nsresult rv = NS_OK;
|
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()
|
|
|
|
{
|
2005-05-15 04:30:02 +04:00
|
|
|
nsCOMPtr<nsIDocShellTreeItem> item(do_QueryReferent(mContainer));
|
2004-05-07 15:57:10 +04:00
|
|
|
nsCOMPtr<nsPIDOMWindow> pwin(do_GetInterface(item));
|
2002-04-17 08:17:16 +04:00
|
|
|
nsCOMPtr<nsIContent> content;
|
|
|
|
|
|
|
|
if (mDocument && pwin) {
|
2004-05-04 01:48:36 +04:00
|
|
|
content = do_QueryInterface(pwin->GetFrameElementInternal());
|
2002-04-17 08:17:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
2011-10-30 00:22:19 +04:00
|
|
|
if (mDocument &&
|
|
|
|
parent_doc->GetSubDocumentFor(content) != mDocument) {
|
2009-03-03 23:11:14 +03:00
|
|
|
mDocument->SuppressEventHandling(parent_doc->EventHandlingSuppressed());
|
|
|
|
}
|
2011-10-30 00:22:19 +04:00
|
|
|
return parent_doc->SetSubDocumentFor(content->AsElement(), mDocument);
|
2002-04-17 08:17:16 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2005-05-15 04:30:02 +04:00
|
|
|
mContainer = do_GetWeakReference(aContainer);
|
1999-05-06 23:25:40 +04:00
|
|
|
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);
|
|
|
|
|
2005-05-15 04:30:02 +04:00
|
|
|
*aResult = nsnull;
|
|
|
|
nsCOMPtr<nsISupports> container = do_QueryReferent(mContainer);
|
|
|
|
container.swap(*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,
|
2009-01-15 06:27:09 +03:00
|
|
|
const nsIntRect& aBounds)
|
2002-03-26 14:43:40 +03:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
return InitInternal(aParentWidget, nsnull, aBounds, true);
|
2002-03-26 14:43:40 +03:00
|
|
|
}
|
|
|
|
|
2002-04-17 08:17:16 +04:00
|
|
|
nsresult
|
2011-09-29 10:19:26 +04:00
|
|
|
DocumentViewerImpl::InitPresentationStuff(bool aDoInitialReflow)
|
2002-04-17 08:17:16 +04:00
|
|
|
{
|
2009-12-11 07:02:13 +03:00
|
|
|
if (GetIsPrintPreview())
|
|
|
|
return NS_OK;
|
|
|
|
|
2009-01-14 15:24:10 +03:00
|
|
|
NS_ASSERTION(!mPresShell,
|
|
|
|
"Someone should have destroyed the presshell!");
|
|
|
|
|
2002-04-17 08:17:16 +04:00
|
|
|
// Create the style set...
|
2004-01-11 12:34:07 +03:00
|
|
|
nsStyleSet *styleSet;
|
|
|
|
nsresult rv = CreateStyleSet(mDocument, &styleSet);
|
2002-04-17 08:17:16 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// Now make the shell for the document
|
|
|
|
rv = mDocument->CreateShell(mPresContext, mViewManager, styleSet,
|
|
|
|
getter_AddRefs(mPresShell));
|
2004-01-11 12:34:07 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
delete styleSet;
|
|
|
|
return rv;
|
|
|
|
}
|
2004-01-08 22:23:12 +03:00
|
|
|
|
2004-07-16 00:30:30 +04:00
|
|
|
// We're done creating the style set
|
|
|
|
styleSet->EndUpdate();
|
|
|
|
|
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.
|
|
|
|
|
2004-05-28 02:08:42 +04:00
|
|
|
mDocument->FlushPendingNotifications(Flush_ContentAndNotify);
|
2002-09-06 09:44:31 +04:00
|
|
|
}
|
|
|
|
|
2002-04-17 08:17:16 +04:00
|
|
|
mPresShell->BeginObservingDocument();
|
|
|
|
|
|
|
|
// Initialize our view manager
|
2009-07-22 04:45:10 +04:00
|
|
|
nscoord width = mPresContext->DeviceContext()->UnscaledAppUnitsPerDevPixel() * mBounds.width;
|
|
|
|
nscoord height = mPresContext->DeviceContext()->UnscaledAppUnitsPerDevPixel() * mBounds.height;
|
2002-04-17 08:17:16 +04:00
|
|
|
|
|
|
|
mViewManager->SetWindowDimensions(width, height);
|
2006-06-12 17:49:46 +04:00
|
|
|
mPresContext->SetTextZoom(mTextZoom);
|
2007-08-28 05:20:17 +04:00
|
|
|
mPresContext->SetFullZoom(mPageZoom);
|
2011-03-11 07:33:43 +03:00
|
|
|
mPresContext->SetMinFontSize(mMinFontSize);
|
2002-04-17 08:17:16 +04:00
|
|
|
|
|
|
|
if (aDoInitialReflow) {
|
2004-09-04 23:51:21 +04:00
|
|
|
nsCOMPtr<nsIHTMLDocument> htmlDoc = do_QueryInterface(mDocument);
|
|
|
|
if (htmlDoc) {
|
|
|
|
nsCOMPtr<nsIDOMHTMLFrameSetElement> frameset =
|
2010-04-30 17:12:05 +04:00
|
|
|
do_QueryInterface(mDocument->GetRootElement());
|
2004-09-04 23:51:21 +04:00
|
|
|
htmlDoc->SetIsFrameset(frameset != nsnull);
|
2002-04-20 03:55:45 +04:00
|
|
|
}
|
|
|
|
|
2007-05-14 07:52:48 +04:00
|
|
|
nsCOMPtr<nsIPresShell> shellGrip = mPresShell;
|
2002-04-20 03:56:45 +04:00
|
|
|
// Initial reflow
|
2002-04-17 08:17:16 +04:00
|
|
|
mPresShell->InitialReflow(width, height);
|
2004-10-14 01:59:26 +04:00
|
|
|
} else {
|
|
|
|
// Store the visible area so it's available for other callers of
|
|
|
|
// InitialReflow, like nsContentSink::StartLayout.
|
|
|
|
mPresContext->SetVisibleArea(nsRect(0, 0, width, height));
|
2002-04-17 08:17:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// now register ourselves as a selection listener, so that we get
|
|
|
|
// called when the selection changes in the window
|
2009-01-14 15:24:10 +03:00
|
|
|
if (!mSelectionListener) {
|
|
|
|
nsDocViewerSelectionListener *selectionListener =
|
|
|
|
new nsDocViewerSelectionListener();
|
2002-04-17 08:17:16 +04:00
|
|
|
|
2009-01-14 15:24:10 +03:00
|
|
|
selectionListener->Init(this);
|
2002-04-17 08:17:16 +04:00
|
|
|
|
2009-01-14 15:24:10 +03:00
|
|
|
// mSelectionListener is a owning reference
|
|
|
|
mSelectionListener = selectionListener;
|
|
|
|
}
|
2002-04-17 08:17:16 +04:00
|
|
|
|
|
|
|
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
|
2011-06-28 21:59:14 +04:00
|
|
|
nsRefPtr<nsDocViewerFocusListener> oldFocusListener = mFocusListener;
|
2002-05-21 23:37:28 +04:00
|
|
|
|
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
|
2010-07-05 13:42:18 +04:00
|
|
|
nsDocViewerFocusListener *focusListener = new nsDocViewerFocusListener();
|
2002-04-17 08:17:16 +04:00
|
|
|
|
|
|
|
focusListener->Init(this);
|
|
|
|
|
|
|
|
// mFocusListener is a strong reference
|
|
|
|
mFocusListener = focusListener;
|
|
|
|
|
2007-05-14 13:11:38 +04:00
|
|
|
if (mDocument) {
|
2011-06-28 21:59:14 +04:00
|
|
|
mDocument->AddEventListener(NS_LITERAL_STRING("focus"),
|
|
|
|
mFocusListener,
|
2011-10-17 18:59:28 +04:00
|
|
|
false, false);
|
2011-06-28 21:59:14 +04:00
|
|
|
mDocument->AddEventListener(NS_LITERAL_STRING("blur"),
|
|
|
|
mFocusListener,
|
2011-10-17 18:59:28 +04:00
|
|
|
false, false);
|
2011-06-28 21:59:14 +04:00
|
|
|
|
2008-01-10 01:41:43 +03:00
|
|
|
if (oldFocusListener) {
|
2011-06-28 21:59:14 +04:00
|
|
|
mDocument->RemoveEventListener(NS_LITERAL_STRING("focus"),
|
2011-10-17 18:59:28 +04:00
|
|
|
oldFocusListener, false);
|
2011-06-28 21:59:14 +04:00
|
|
|
mDocument->RemoveEventListener(NS_LITERAL_STRING("blur"),
|
2011-10-17 18:59:28 +04:00
|
|
|
oldFocusListener, false);
|
2002-05-21 23:37:28 +04:00
|
|
|
}
|
2002-04-17 08:17:16 +04:00
|
|
|
}
|
|
|
|
|
2010-05-12 04:30:40 +04:00
|
|
|
if (aDoInitialReflow && mDocument) {
|
|
|
|
mDocument->ScrollToRef();
|
|
|
|
}
|
|
|
|
|
2002-04-17 08:17:16 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-07-22 04:44:54 +04:00
|
|
|
static nsPresContext*
|
|
|
|
CreatePresContext(nsIDocument* aDocument,
|
|
|
|
nsPresContext::nsPresContextType aType,
|
|
|
|
nsIView* aContainerView)
|
|
|
|
{
|
|
|
|
if (aContainerView)
|
|
|
|
return new nsPresContext(aDocument, aType);
|
|
|
|
return new nsRootPresContext(aDocument, aType);
|
|
|
|
}
|
|
|
|
|
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,
|
2005-08-15 22:16:42 +04:00
|
|
|
nsISupports *aState,
|
2009-01-15 06:27:09 +03:00
|
|
|
const nsIntRect& aBounds,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aDoCreation,
|
|
|
|
bool aNeedMakeCX /*= true*/,
|
|
|
|
bool aForceSetNewDocument /* = true*/)
|
1999-05-06 23:25:40 +04:00
|
|
|
{
|
2011-01-21 22:09:11 +03:00
|
|
|
if (mIsPageMode) {
|
2011-10-17 18:59:28 +04:00
|
|
|
// XXXbz should the InitInternal in SetPageMode just pass false
|
2011-01-21 22:09:11 +03:00
|
|
|
// here itself?
|
2011-10-17 18:59:28 +04:00
|
|
|
aForceSetNewDocument = false;
|
2011-01-21 22:09:11 +03:00
|
|
|
}
|
|
|
|
|
2009-11-19 02:40:31 +03:00
|
|
|
// We don't want any scripts to run here. That can cause flushing,
|
|
|
|
// which can cause reentry into initialization of this document viewer,
|
|
|
|
// which would be disastrous.
|
|
|
|
nsAutoScriptBlocker blockScripts;
|
|
|
|
|
2001-11-14 14:24:03 +03:00
|
|
|
mParentWidget = aParentWidget; // not ref counted
|
2009-07-22 04:45:10 +04:00
|
|
|
mBounds = aBounds;
|
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
|
|
|
|
2009-07-22 04:44:53 +04:00
|
|
|
nsIView* containerView = FindContainerView();
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool makeCX = false;
|
2002-03-26 14:43:40 +03:00
|
|
|
if (aDoCreation) {
|
2009-07-22 04:45:10 +04:00
|
|
|
nsresult rv = CreateDeviceContext(containerView);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2008-10-05 00:00:09 +04:00
|
|
|
// XXXbz this is a nasty hack to do with the fact that we create
|
|
|
|
// presentations both in Init() and in Show()... Ideally we would only do
|
|
|
|
// it in one place (Show()) and require that callers call init(), open(),
|
|
|
|
// show() in that order or something.
|
2009-07-22 04:45:10 +04:00
|
|
|
if (!mPresContext &&
|
2010-09-09 00:40:39 +04:00
|
|
|
(aParentWidget || containerView || mDocument->IsBeingUsedAsImage() ||
|
2010-08-12 01:05:26 +04:00
|
|
|
(mDocument->GetDisplayDocument() &&
|
|
|
|
mDocument->GetDisplayDocument()->GetShell()))) {
|
2002-03-26 14:43:40 +03:00
|
|
|
// Create presentation context
|
2006-12-10 11:05:05 +03:00
|
|
|
if (mIsPageMode) {
|
|
|
|
//Presentation context already created in SetPageMode which is calling this method
|
2009-07-22 04:44:54 +04:00
|
|
|
} else {
|
|
|
|
mPresContext = CreatePresContext(mDocument,
|
|
|
|
nsPresContext::eContext_Galley, containerView);
|
2006-12-10 11:05:05 +03:00
|
|
|
}
|
2004-07-29 23:41:39 +04:00
|
|
|
NS_ENSURE_TRUE(mPresContext, NS_ERROR_OUT_OF_MEMORY);
|
1999-05-06 23:25:40 +04:00
|
|
|
|
2008-08-18 23:22:19 +04:00
|
|
|
nsresult rv = mPresContext->Init(mDeviceContext);
|
2004-01-21 12:35:59 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
mPresContext = nsnull;
|
|
|
|
return rv;
|
|
|
|
}
|
2002-04-17 08:17:16 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
#if defined(NS_PRINTING) && defined(NS_PRINT_PREVIEW)
|
2006-04-01 05:19:28 +04:00
|
|
|
makeCX = !GetIsPrintPreview() && aNeedMakeCX; // needs to be true except when we are already in PP or we are enabling/disabling paginated mode.
|
2001-11-14 14:24:03 +03:00
|
|
|
#else
|
2011-10-17 18:59:28 +04:00
|
|
|
makeCX = 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
|
|
|
|
2005-05-05 00:22:32 +04:00
|
|
|
if (mPresContext) {
|
|
|
|
// Create the ViewManager and Root View...
|
2000-04-22 01:40:28 +04:00
|
|
|
|
2005-05-05 00:22:32 +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 nsSubDocumentFrame code through reflows caused by
|
|
|
|
// FlushPendingNotifications() calls down the road...
|
2002-04-04 11:31:16 +04:00
|
|
|
|
2007-12-01 13:42:12 +03:00
|
|
|
rv = MakeWindow(nsSize(mPresContext->DevPixelsToAppUnits(aBounds.width),
|
2009-07-22 04:44:53 +04:00
|
|
|
mPresContext->DevPixelsToAppUnits(aBounds.height)),
|
|
|
|
containerView);
|
2005-05-05 00:22:32 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
Hide();
|
2006-04-01 05:19:28 +04:00
|
|
|
|
2006-04-05 08:37:44 +04:00
|
|
|
#ifdef NS_PRINT_PREVIEW
|
2006-04-01 05:19:28 +04:00
|
|
|
if (mIsPageMode) {
|
2007-03-21 09:07:42 +03:00
|
|
|
// I'm leaving this in a broken state for the moment; we should
|
|
|
|
// be measuring/scaling with the print device context, not the
|
|
|
|
// screen device context, but this is good enough to allow
|
|
|
|
// printing reftests to work.
|
2007-07-17 03:16:48 +04:00
|
|
|
double pageWidth = 0, pageHeight = 0;
|
|
|
|
mPresContext->GetPrintSettings()->GetEffectivePageSize(&pageWidth,
|
|
|
|
&pageHeight);
|
2007-03-21 09:07:42 +03:00
|
|
|
mPresContext->SetPageSize(
|
2010-08-13 13:58:04 +04:00
|
|
|
nsSize(mPresContext->CSSTwipsToAppUnits(NSToIntFloor(pageWidth)),
|
|
|
|
mPresContext->CSSTwipsToAppUnits(NSToIntFloor(pageHeight))));
|
2011-10-17 18:59:28 +04:00
|
|
|
mPresContext->SetIsRootPaginatedDocument(true);
|
2007-03-21 09:07:42 +03:00
|
|
|
mPresContext->SetPageScale(1.0f);
|
2006-04-01 05:19:28 +04:00
|
|
|
}
|
2006-04-05 08:37:44 +04:00
|
|
|
#endif
|
2005-05-05 00:22:32 +04:00
|
|
|
}
|
2002-04-17 08:17:16 +04:00
|
|
|
}
|
2002-04-05 09:42:10 +04:00
|
|
|
|
2005-05-15 04:30:02 +04:00
|
|
|
nsCOMPtr<nsIInterfaceRequestor> requestor(do_QueryReferent(mContainer));
|
2002-04-17 08:17:16 +04:00
|
|
|
if (requestor) {
|
|
|
|
if (mPresContext) {
|
|
|
|
nsCOMPtr<nsILinkHandler> linkHandler;
|
|
|
|
requestor->GetInterface(NS_GET_IID(nsILinkHandler),
|
|
|
|
getter_AddRefs(linkHandler));
|
2005-05-15 04:30:02 +04:00
|
|
|
|
|
|
|
mPresContext->SetContainer(requestor);
|
2002-04-17 08:17:16 +04:00
|
|
|
mPresContext->SetLinkHandler(linkHandler);
|
|
|
|
}
|
2002-04-05 09:42:10 +04:00
|
|
|
|
2010-08-28 03:15:08 +04:00
|
|
|
// Set script-context-owner in the document
|
2002-04-05 09:42:10 +04:00
|
|
|
|
2010-08-28 03:15:08 +04:00
|
|
|
nsCOMPtr<nsPIDOMWindow> window;
|
|
|
|
requestor->GetInterface(NS_GET_IID(nsPIDOMWindow),
|
|
|
|
getter_AddRefs(window));
|
2002-04-05 09:42:10 +04:00
|
|
|
|
2010-08-28 03:15:08 +04:00
|
|
|
if (window) {
|
|
|
|
nsCOMPtr<nsIDocument> curDoc =
|
|
|
|
do_QueryInterface(window->GetExtantDocument());
|
2011-01-21 22:09:11 +03:00
|
|
|
if (aForceSetNewDocument || curDoc != mDocument) {
|
2011-10-17 18:59:28 +04:00
|
|
|
window->SetNewDocument(mDocument, aState, false);
|
2010-08-28 03:15:08 +04:00
|
|
|
nsJSContext::LoadStart();
|
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
|
|
|
|
2010-02-18 22:23:23 +03: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;
|
|
|
|
}
|
|
|
|
|
2011-06-23 14:39:48 +04:00
|
|
|
void DocumentViewerImpl::SetNavigationTiming(nsDOMNavigationTiming* timing)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mDocument, "Must have a document to set navigation timing.");
|
|
|
|
if (mDocument) {
|
|
|
|
mDocument->SetNavigationTiming(timing);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
2010-04-30 23:40:59 +04:00
|
|
|
NS_TIME_FUNCTION;
|
2007-03-23 02:01:14 +03: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.
|
|
|
|
*/
|
2011-10-15 11:33:26 +04:00
|
|
|
nsRefPtr<DocumentViewerImpl> kungFuDeathGrip(this);
|
2007-03-23 02:01:14 +03:00
|
|
|
|
2007-05-01 23:11:28 +04:00
|
|
|
// Flush out layout so it's up-to-date by the time onload is called.
|
|
|
|
// Note that this could destroy the window, so do this before
|
|
|
|
// checking for our mDocument and its window.
|
2007-04-30 07:09:55 +04:00
|
|
|
if (mPresShell && !mStopped) {
|
|
|
|
// Hold strong ref because this could conceivably run script
|
|
|
|
nsCOMPtr<nsIPresShell> shell = mPresShell;
|
|
|
|
shell->FlushPendingNotifications(Flush_Layout);
|
|
|
|
}
|
2009-09-01 20:45:05 +04:00
|
|
|
|
2011-03-01 10:08:56 +03:00
|
|
|
nsresult rv = NS_OK;
|
2007-05-01 23:11:28 +04:00
|
|
|
NS_ENSURE_TRUE(mDocument, NS_ERROR_NOT_AVAILABLE);
|
|
|
|
|
|
|
|
// First, get the window from the document...
|
|
|
|
nsPIDOMWindow *window = mDocument->GetWindow();
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mLoaded = true;
|
2007-05-01 23:11:28 +04:00
|
|
|
|
2000-09-06 13:11:38 +04:00
|
|
|
// Now, fire either an OnLoad or OnError event to the document...
|
2011-09-29 10:19:26 +04:00
|
|
|
bool restoring = false;
|
2008-11-19 01:54:36 +03:00
|
|
|
// XXXbz imagelib kills off the document load for a full-page image with
|
2009-02-16 14:27:22 +03:00
|
|
|
// NS_ERROR_PARSED_DATA_CACHED if it's in the cache. So we want to treat
|
2008-11-19 01:54:36 +03:00
|
|
|
// that one as a success code; otherwise whether we fire onload for the image
|
|
|
|
// will depend on whether it's cached!
|
|
|
|
if(window &&
|
2009-02-16 14:27:22 +03:00
|
|
|
(NS_SUCCEEDED(aStatus) || aStatus == NS_ERROR_PARSED_DATA_CACHED)) {
|
2009-01-09 20:12:09 +03:00
|
|
|
if (mDocument)
|
|
|
|
mDocument->SetReadyStateInternal(nsIDocument::READYSTATE_COMPLETE);
|
2000-09-06 13:11:38 +04:00
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
2011-10-17 18:59:28 +04:00
|
|
|
nsEvent event(true, NS_LOAD);
|
2006-03-07 20:08:51 +03:00
|
|
|
event.flags |= NS_EVENT_FLAG_CANT_BUBBLE;
|
|
|
|
// XXX Dispatching to |window|, but using |document| as the target.
|
|
|
|
event.target = mDocument;
|
2000-09-06 13:11:38 +04:00
|
|
|
|
2005-06-16 03:52:46 +04:00
|
|
|
// If the document presentation is being restored, we don't want to fire
|
|
|
|
// onload to the document content since that would likely confuse scripts
|
|
|
|
// on the page.
|
|
|
|
|
2005-11-29 02:56:44 +03:00
|
|
|
nsIDocShell *docShell = window->GetDocShell();
|
2005-06-16 03:52:46 +04:00
|
|
|
NS_ENSURE_TRUE(docShell, NS_ERROR_UNEXPECTED);
|
|
|
|
|
|
|
|
docShell->GetRestoringDocument(&restoring);
|
|
|
|
if (!restoring) {
|
2011-06-23 14:39:48 +04:00
|
|
|
nsRefPtr<nsDOMNavigationTiming> timing(mDocument->GetNavigationTiming());
|
|
|
|
if (timing) {
|
|
|
|
timing->NotifyLoadEventStart();
|
|
|
|
}
|
2006-03-07 20:08:51 +03:00
|
|
|
nsEventDispatcher::Dispatch(window, mPresContext, &event, nsnull,
|
|
|
|
&status);
|
2011-06-23 14:39:48 +04:00
|
|
|
if (timing) {
|
|
|
|
timing->NotifyLoadEventEnd();
|
|
|
|
}
|
2005-06-16 03:52:46 +04:00
|
|
|
}
|
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
|
|
|
|
2005-06-16 03:52:46 +04:00
|
|
|
// Notify the document that it has been shown (regardless of whether
|
2005-06-18 01:49:01 +04:00
|
|
|
// it was just loaded). Note: mDocument may be null now if the above
|
|
|
|
// firing of onload caused the document to unload.
|
2009-11-01 03:06:47 +03:00
|
|
|
if (mDocument) {
|
|
|
|
// Re-get window, since it might have changed during above firing of onload
|
|
|
|
window = mDocument->GetWindow();
|
|
|
|
if (window) {
|
|
|
|
nsIDocShell *docShell = window->GetDocShell();
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isInUnload;
|
2009-12-27 02:11:04 +03:00
|
|
|
if (docShell && NS_SUCCEEDED(docShell->GetIsInUnload(&isInUnload)) &&
|
|
|
|
!isInUnload) {
|
2009-11-01 03:06:47 +03:00
|
|
|
mDocument->OnPageShow(restoring, nsnull);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-06-16 03:52:46 +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) {
|
2008-04-11 02:42:03 +04:00
|
|
|
nsCOMPtr<nsIPresShell> shellDeathGrip(mPresShell);
|
2001-05-02 02:50:16 +04:00
|
|
|
mPresShell->UnsuppressPainting();
|
2008-04-11 02:42:03 +04:00
|
|
|
// mPresShell could have been removed now, see bug 378682/421432
|
|
|
|
if (mPresShell) {
|
|
|
|
mPresShell->ScrollToAnchor();
|
|
|
|
}
|
2007-03-23 02:01:14 +03:00
|
|
|
}
|
|
|
|
|
2007-10-21 20:46:54 +04:00
|
|
|
nsJSContext::LoadEnd();
|
2007-01-11 03:02:58 +03: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) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mPrintIsPending = false;
|
|
|
|
mPrintDocIsFullyLoaded = true;
|
2002-06-28 17:39:44 +04:00
|
|
|
Print(mCachedPrintSettings, mCachedPrintWebProgressListner);
|
|
|
|
mCachedPrintSettings = nsnull;
|
|
|
|
mCachedPrintWebProgressListner = nsnull;
|
|
|
|
}
|
2002-08-21 16:01:05 +04:00
|
|
|
#endif
|
2002-06-28 17:39:44 +04:00
|
|
|
|
2011-03-01 10:08:56 +03:00
|
|
|
return rv;
|
2000-06-22 09:38:07 +04:00
|
|
|
}
|
|
|
|
|
2004-02-11 09:09:51 +03:00
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
DocumentViewerImpl::PermitUnload(bool aCallerClosesWindow, bool *aPermitUnload)
|
2004-02-11 09:09:51 +03:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
*aPermitUnload = true;
|
2004-02-11 09:09:51 +03:00
|
|
|
|
2009-10-20 18:19:43 +04:00
|
|
|
if (!mDocument || mInPermitUnload || mCallerIsClosingWindow) {
|
2004-02-11 09:09:51 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// First, get the script global object from the document...
|
2005-11-29 02:56:44 +03:00
|
|
|
nsPIDOMWindow *window = mDocument->GetWindow();
|
2004-02-11 09:09:51 +03:00
|
|
|
|
2005-11-29 02:56:44 +03:00
|
|
|
if (!window) {
|
2004-02-11 09:09:51 +03:00
|
|
|
// This is odd, but not fatal
|
2005-11-29 02:56:44 +03:00
|
|
|
NS_WARNING("window not set for document!");
|
2004-02-11 09:09:51 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-03-15 02:08:57 +03:00
|
|
|
NS_ASSERTION(nsContentUtils::IsSafeToRunScript(), "This is unsafe");
|
|
|
|
|
2004-02-11 09:09:51 +03:00
|
|
|
// Now, fire an BeforeUnload event to the document and see if it's ok
|
|
|
|
// to unload...
|
2011-05-23 20:46:36 +04:00
|
|
|
nsCOMPtr<nsIDOMDocument> domDoc = do_QueryInterface(mDocument);
|
2009-06-24 12:42:00 +04:00
|
|
|
nsCOMPtr<nsIDOMEvent> event;
|
2011-05-23 20:46:36 +04:00
|
|
|
domDoc->CreateEvent(NS_LITERAL_STRING("beforeunloadevent"),
|
|
|
|
getter_AddRefs(event));
|
2009-06-24 12:42:00 +04:00
|
|
|
nsCOMPtr<nsIDOMBeforeUnloadEvent> beforeUnload = do_QueryInterface(event);
|
|
|
|
nsCOMPtr<nsIPrivateDOMEvent> pEvent = do_QueryInterface(beforeUnload);
|
|
|
|
NS_ENSURE_STATE(pEvent);
|
|
|
|
nsresult rv = event->InitEvent(NS_LITERAL_STRING("beforeunload"),
|
2011-10-17 18:59:28 +04:00
|
|
|
false, true);
|
2009-06-24 12:42:00 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2006-03-07 20:08:51 +03:00
|
|
|
// XXX Dispatching to |window|, but using |document| as the target.
|
2009-06-24 12:42:00 +04:00
|
|
|
nsCOMPtr<nsIDOMEventTarget> target = do_QueryInterface(mDocument);
|
|
|
|
pEvent->SetTarget(target);
|
2011-10-17 18:59:28 +04:00
|
|
|
pEvent->SetTrusted(true);
|
2004-09-24 03:39:16 +04:00
|
|
|
|
2006-04-06 03:57:30 +04:00
|
|
|
// In evil cases we might be destroyed while handling the
|
|
|
|
// onbeforeunload event, don't let that happen. (see also bug#331040)
|
|
|
|
nsRefPtr<DocumentViewerImpl> kungFuDeathGrip(this);
|
|
|
|
|
2004-09-24 03:39:16 +04:00
|
|
|
{
|
|
|
|
// Never permit popups from the beforeunload handler, no matter
|
|
|
|
// how we get here.
|
2011-10-17 18:59:28 +04:00
|
|
|
nsAutoPopupStatePusher popupStatePusher(openAbused, true);
|
2004-02-11 09:09:51 +03:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mInPermitUnload = true;
|
2009-06-24 12:42:00 +04:00
|
|
|
nsEventDispatcher::DispatchDOMEvent(window, nsnull, event, mPresContext,
|
|
|
|
nsnull);
|
2011-10-17 18:59:28 +04:00
|
|
|
mInPermitUnload = false;
|
2004-09-24 03:39:16 +04:00
|
|
|
}
|
2004-02-11 09:09:51 +03:00
|
|
|
|
2005-05-15 04:30:02 +04:00
|
|
|
nsCOMPtr<nsIDocShellTreeNode> docShellNode(do_QueryReferent(mContainer));
|
2009-06-24 12:42:00 +04:00
|
|
|
nsAutoString text;
|
|
|
|
beforeUnload->GetReturnValue(text);
|
|
|
|
if (pEvent->GetInternalNSEvent()->flags & NS_EVENT_FLAG_NO_DEFAULT ||
|
|
|
|
!text.IsEmpty()) {
|
2004-02-11 09:09:51 +03:00
|
|
|
// Ask the user if it's ok to unload the current page
|
|
|
|
|
2005-05-15 04:30:02 +04:00
|
|
|
nsCOMPtr<nsIPrompt> prompt = do_GetInterface(docShellNode);
|
2004-02-11 09:09:51 +03:00
|
|
|
|
|
|
|
if (prompt) {
|
2010-09-16 11:51:24 +04:00
|
|
|
nsXPIDLString title, message, stayLabel, leaveLabel;
|
|
|
|
rv = nsContentUtils::GetLocalizedString(nsContentUtils::eDOM_PROPERTIES,
|
|
|
|
"OnBeforeUnloadTitle",
|
|
|
|
title);
|
2004-12-17 23:40:48 +03:00
|
|
|
rv |= nsContentUtils::GetLocalizedString(nsContentUtils::eDOM_PROPERTIES,
|
2010-09-16 11:51:24 +04:00
|
|
|
"OnBeforeUnloadMessage",
|
|
|
|
message);
|
|
|
|
rv |= nsContentUtils::GetLocalizedString(nsContentUtils::eDOM_PROPERTIES,
|
|
|
|
"OnBeforeUnloadLeaveButton",
|
|
|
|
leaveLabel);
|
|
|
|
rv |= nsContentUtils::GetLocalizedString(nsContentUtils::eDOM_PROPERTIES,
|
|
|
|
"OnBeforeUnloadStayButton",
|
|
|
|
stayLabel);
|
2004-02-11 09:09:51 +03:00
|
|
|
|
2010-09-16 11:51:24 +04:00
|
|
|
if (NS_FAILED(rv) || !title || !message || !stayLabel || !leaveLabel) {
|
2004-02-11 09:09:51 +03:00
|
|
|
NS_ERROR("Failed to get strings from dom.properties!");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-05-31 22:17:57 +04:00
|
|
|
// Although the exact value is ignored, we must not pass invalid
|
2011-09-29 10:19:26 +04:00
|
|
|
// bool values through XPConnect.
|
|
|
|
bool dummy = false;
|
2010-09-16 11:51:24 +04:00
|
|
|
PRInt32 buttonPressed = 0;
|
|
|
|
PRUint32 buttonFlags = (nsIPrompt::BUTTON_POS_0_DEFAULT |
|
|
|
|
(nsIPrompt::BUTTON_TITLE_IS_STRING * nsIPrompt::BUTTON_POS_0) |
|
|
|
|
(nsIPrompt::BUTTON_TITLE_IS_STRING * nsIPrompt::BUTTON_POS_1));
|
2004-02-11 09:09:51 +03:00
|
|
|
|
2012-03-31 20:30:13 +04:00
|
|
|
nsAutoSyncOperation sync(mDocument);
|
2010-09-16 11:51:24 +04:00
|
|
|
rv = prompt->ConfirmEx(title, message, buttonFlags,
|
|
|
|
leaveLabel, stayLabel, nsnull, nsnull,
|
|
|
|
&dummy, &buttonPressed);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// Button 0 == leave, button 1 == stay
|
|
|
|
*aPermitUnload = (buttonPressed == 0);
|
2004-02-11 09:09:51 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (docShellNode) {
|
|
|
|
PRInt32 childCount;
|
|
|
|
docShellNode->GetChildCount(&childCount);
|
|
|
|
|
|
|
|
for (PRInt32 i = 0; i < childCount && *aPermitUnload; ++i) {
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> item;
|
|
|
|
docShellNode->GetChildAt(i, getter_AddRefs(item));
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(item));
|
|
|
|
|
2006-01-12 09:30:05 +03:00
|
|
|
if (docShell) {
|
|
|
|
nsCOMPtr<nsIContentViewer> cv;
|
2009-10-20 18:19:43 +04:00
|
|
|
docShell->GetContentViewer(getter_AddRefs(cv));
|
2004-02-11 09:09:51 +03:00
|
|
|
|
2009-10-20 18:19:43 +04:00
|
|
|
if (cv) {
|
|
|
|
cv->PermitUnload(aCallerClosesWindow, aPermitUnload);
|
2006-01-12 09:30:05 +03:00
|
|
|
}
|
2004-02-11 09:09:51 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-20 18:19:43 +04:00
|
|
|
if (aCallerClosesWindow && *aPermitUnload)
|
2011-10-17 18:59:28 +04:00
|
|
|
mCallerIsClosingWindow = true;
|
2009-10-20 18:19:43 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
DocumentViewerImpl::ResetCloseWindow()
|
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
mCallerIsClosingWindow = false;
|
2009-10-20 18:19:43 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDocShellTreeNode> docShellNode(do_QueryReferent(mContainer));
|
|
|
|
if (docShellNode) {
|
|
|
|
PRInt32 childCount;
|
|
|
|
docShellNode->GetChildCount(&childCount);
|
|
|
|
|
|
|
|
for (PRInt32 i = 0; i < childCount; ++i) {
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> item;
|
|
|
|
docShellNode->GetChildAt(i, getter_AddRefs(item));
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(item));
|
|
|
|
|
|
|
|
if (docShell) {
|
|
|
|
nsCOMPtr<nsIContentViewer> cv;
|
|
|
|
docShell->GetContentViewer(getter_AddRefs(cv));
|
|
|
|
|
|
|
|
if (cv) {
|
|
|
|
cv->ResetCloseWindow();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-02-11 09:09:51 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-07-18 00:17:38 +04:00
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
DocumentViewerImpl::PageHide(bool aIsUnload)
|
2001-07-18 00:17:38 +04:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
mHidden = true;
|
2001-07-18 00:17:38 +04:00
|
|
|
|
|
|
|
if (!mDocument) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
|
2009-02-27 01:05:42 +03:00
|
|
|
mDocument->OnPageHide(!aIsUnload, nsnull);
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 22:00:39 +04:00
|
|
|
|
|
|
|
// inform the window so that the focus state is reset.
|
|
|
|
NS_ENSURE_STATE(mDocument);
|
|
|
|
nsPIDOMWindow *window = mDocument->GetWindow();
|
|
|
|
if (window)
|
|
|
|
window->PageHidden();
|
|
|
|
|
2007-01-25 20:59:20 +03:00
|
|
|
if (aIsUnload) {
|
2011-02-17 02:47:12 +03:00
|
|
|
// Poke the GC. The window might be collectable garbage now.
|
2012-03-13 03:25:03 +04:00
|
|
|
nsJSContext::PokeGC(js::gcreason::PAGE_HIDE, NS_GC_DELAY * 2);
|
2011-02-17 02:47:12 +03:00
|
|
|
|
2007-01-25 20:59:20 +03:00
|
|
|
// if Destroy() was called during OnPageHide(), mDocument is nsnull.
|
|
|
|
NS_ENSURE_STATE(mDocument);
|
2005-06-16 03:52:46 +04:00
|
|
|
|
2007-01-25 20:59:20 +03:00
|
|
|
// First, get the window from the document...
|
|
|
|
nsPIDOMWindow *window = mDocument->GetWindow();
|
2006-05-25 00:31:59 +04:00
|
|
|
|
2007-01-25 20:59:20 +03:00
|
|
|
if (!window) {
|
|
|
|
// Fail if no window is available...
|
2010-03-22 01:06:12 +03:00
|
|
|
NS_WARNING("window not set for document!");
|
2007-01-25 20:59:20 +03:00
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
2001-07-18 00:17:38 +04:00
|
|
|
|
2007-01-25 20:59:20 +03:00
|
|
|
// Now, fire an Unload event to the document...
|
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
2011-10-17 18:59:28 +04:00
|
|
|
nsEvent event(true, NS_PAGE_UNLOAD);
|
2007-01-25 20:59:20 +03:00
|
|
|
event.flags |= NS_EVENT_FLAG_CANT_BUBBLE;
|
|
|
|
// XXX Dispatching to |window|, but using |document| as the target.
|
|
|
|
event.target = mDocument;
|
2001-07-18 00:17:38 +04:00
|
|
|
|
2007-01-25 20:59:20 +03:00
|
|
|
// Never permit popups from the unload handler, no matter how we get
|
|
|
|
// here.
|
2011-10-17 18:59:28 +04:00
|
|
|
nsAutoPopupStatePusher popupStatePusher(openAbused, true);
|
2001-07-18 00:17:38 +04:00
|
|
|
|
2007-01-25 20:59:20 +03:00
|
|
|
nsEventDispatcher::Dispatch(window, mPresContext, &event, nsnull, &status);
|
|
|
|
}
|
|
|
|
|
2007-07-24 04:04:36 +04:00
|
|
|
#ifdef MOZ_XUL
|
2007-04-20 22:20:03 +04:00
|
|
|
// look for open menupopups and close them after the unload event, in case
|
|
|
|
// the unload event listeners open any new popups
|
2009-10-24 00:24:47 +04:00
|
|
|
nsContentUtils::HidePopupsInDocument(mDocument);
|
2007-07-24 04:04:36 +04:00
|
|
|
#endif
|
2007-04-26 06:37:27 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
2007-03-23 02:01:14 +03:00
|
|
|
}
|
|
|
|
|
2005-11-06 22:23:03 +03:00
|
|
|
static void
|
|
|
|
AttachContainerRecurse(nsIDocShell* aShell)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIContentViewer> viewer;
|
|
|
|
aShell->GetContentViewer(getter_AddRefs(viewer));
|
2011-10-15 11:33:26 +04:00
|
|
|
if (viewer) {
|
|
|
|
nsIDocument* doc = viewer->GetDocument();
|
2005-11-06 22:23:03 +03:00
|
|
|
if (doc) {
|
|
|
|
doc->SetContainer(aShell);
|
|
|
|
}
|
2010-03-25 16:17:11 +03:00
|
|
|
nsRefPtr<nsPresContext> pc;
|
2011-10-15 11:33:26 +04:00
|
|
|
viewer->GetPresContext(getter_AddRefs(pc));
|
2005-11-06 22:23:03 +03:00
|
|
|
if (pc) {
|
|
|
|
pc->SetContainer(aShell);
|
|
|
|
pc->SetLinkHandler(nsCOMPtr<nsILinkHandler>(do_QueryInterface(aShell)));
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsIPresShell> presShell;
|
2011-10-15 11:33:26 +04:00
|
|
|
viewer->GetPresShell(getter_AddRefs(presShell));
|
2005-11-06 22:23:03 +03:00
|
|
|
if (presShell) {
|
|
|
|
presShell->SetForwardingContainer(nsnull);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now recurse through the children
|
|
|
|
nsCOMPtr<nsIDocShellTreeNode> node = do_QueryInterface(aShell);
|
|
|
|
NS_ASSERTION(node, "docshells must implement nsIDocShellTreeNode");
|
|
|
|
|
|
|
|
PRInt32 childCount;
|
|
|
|
node->GetChildCount(&childCount);
|
|
|
|
for (PRInt32 i = 0; i < childCount; ++i) {
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> childItem;
|
|
|
|
node->GetChildAt(i, getter_AddRefs(childItem));
|
|
|
|
AttachContainerRecurse(nsCOMPtr<nsIDocShell>(do_QueryInterface(childItem)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-05-05 00:22:32 +04:00
|
|
|
NS_IMETHODIMP
|
2005-11-06 22:23:03 +03:00
|
|
|
DocumentViewerImpl::Open(nsISupports *aState, nsISHEntry *aSHEntry)
|
2005-05-05 00:22:32 +04:00
|
|
|
{
|
|
|
|
NS_ENSURE_TRUE(mPresShell, NS_ERROR_NOT_INITIALIZED);
|
|
|
|
|
2008-09-30 20:51:26 +04:00
|
|
|
if (mDocument)
|
|
|
|
mDocument->SetContainer(nsCOMPtr<nsISupports>(do_QueryReferent(mContainer)));
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
nsresult rv = InitInternal(mParentWidget, aState, mBounds, false);
|
2008-10-05 00:00:09 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mHidden = false;
|
2011-04-20 01:18:17 +04:00
|
|
|
|
2005-08-22 05:55:34 +04:00
|
|
|
if (mPresShell)
|
|
|
|
mPresShell->SetForwardingContainer(nsnull);
|
|
|
|
|
2005-11-06 22:23:03 +03:00
|
|
|
// Rehook the child presentations. The child shells are still in
|
|
|
|
// session history, so get them from there.
|
|
|
|
|
2008-09-28 23:14:28 +04:00
|
|
|
if (aSHEntry) {
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> item;
|
|
|
|
PRInt32 itemIndex = 0;
|
|
|
|
while (NS_SUCCEEDED(aSHEntry->ChildShellAt(itemIndex++,
|
|
|
|
getter_AddRefs(item))) && item) {
|
|
|
|
AttachContainerRecurse(nsCOMPtr<nsIDocShell>(do_QueryInterface(item)));
|
|
|
|
}
|
2005-11-06 22:23:03 +03:00
|
|
|
}
|
|
|
|
|
2005-05-05 00:22:32 +04:00
|
|
|
SyncParentSubDocMap();
|
|
|
|
|
2007-05-14 13:11:38 +04:00
|
|
|
if (mFocusListener && mDocument) {
|
2011-06-28 21:59:14 +04:00
|
|
|
mDocument->AddEventListener(NS_LITERAL_STRING("focus"), mFocusListener,
|
2011-10-17 18:59:28 +04:00
|
|
|
false, false);
|
2011-06-28 21:59:14 +04:00
|
|
|
mDocument->AddEventListener(NS_LITERAL_STRING("blur"), mFocusListener,
|
2011-10-17 18:59:28 +04:00
|
|
|
false, false);
|
2005-11-02 00:55:34 +03:00
|
|
|
}
|
|
|
|
|
2005-05-05 00:22:32 +04:00
|
|
|
// XXX re-enable image animations once that works correctly
|
|
|
|
|
2005-07-01 11:12:02 +04:00
|
|
|
PrepareToStartLoad();
|
2011-02-09 23:13:18 +03:00
|
|
|
|
|
|
|
// When loading a page from the bfcache with puppet widgets, we do the
|
|
|
|
// widget attachment here (it is otherwise done in MakeWindow, which is
|
|
|
|
// called for non-bfcache pages in the history, but not bfcache pages).
|
|
|
|
// Attachment is necessary, since we get detached when another page
|
|
|
|
// is browsed to. That is, if we are one page A, then when we go to
|
|
|
|
// page B, we detach. So page A's view has no widget. If we then go
|
|
|
|
// back to it, and it is in the bfcache, we will use that view, which
|
|
|
|
// doesn't have a widget. The attach call here will properly attach us.
|
|
|
|
if (nsIWidget::UsePuppetWidgets() && mPresContext &&
|
|
|
|
ShouldAttachToTopLevel()) {
|
|
|
|
// If the old view is already attached to our parent, detach
|
|
|
|
DetachFromTopLevelWidget();
|
|
|
|
|
|
|
|
nsIViewManager *vm = GetViewManager();
|
|
|
|
NS_ABORT_IF_FALSE(vm, "no view manager");
|
2011-03-30 06:24:54 +04:00
|
|
|
nsIView* v = vm->GetRootView();
|
2011-02-09 23:13:18 +03:00
|
|
|
NS_ABORT_IF_FALSE(v, "no root view");
|
|
|
|
NS_ABORT_IF_FALSE(mParentWidget, "no mParentWidget to set");
|
|
|
|
v->AttachToTopLevelWidget(mParentWidget);
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mAttachedToParent = true;
|
2011-02-09 23:13:18 +03:00
|
|
|
}
|
|
|
|
|
2005-05-05 00:22:32 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-06-22 09:38:07 +04:00
|
|
|
NS_IMETHODIMP
|
2005-05-18 07:52:33 +04:00
|
|
|
DocumentViewerImpl::Close(nsISHEntry *aSHEntry)
|
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.
|
|
|
|
|
2005-05-18 07:52:33 +04:00
|
|
|
mSHEntry = aSHEntry;
|
|
|
|
|
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.
|
|
|
|
|
2005-05-05 00:22:32 +04:00
|
|
|
if (!mDocument)
|
|
|
|
return NS_OK;
|
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
#if defined(NS_PRINTING) && defined(NS_PRINT_PREVIEW)
|
2005-05-05 00:22:32 +04:00
|
|
|
// Turn scripting back on
|
|
|
|
// after PrintPreview had turned it off
|
|
|
|
if (GetIsPrintPreview() && mPrintEngine) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mPrintEngine->TurnScriptingOn(true);
|
2005-05-05 00:22:32 +04:00
|
|
|
}
|
2001-11-03 17:59:39 +03:00
|
|
|
#endif
|
|
|
|
|
2002-10-02 01:57:15 +04:00
|
|
|
#ifdef NS_PRINTING
|
2005-05-05 00:22:32 +04:00
|
|
|
// A Close was called while we were printing
|
|
|
|
// so don't clear the ScriptGlobalObject
|
|
|
|
// or clear the mDocument below
|
|
|
|
if (mPrintEngine && !mClosingWhilePrinting) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mClosingWhilePrinting = true;
|
2005-05-05 00:22:32 +04:00
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
{
|
2009-05-07 23:21:53 +04:00
|
|
|
// out of band cleanup of docshell
|
2002-10-02 01:57:15 +04:00
|
|
|
mDocument->SetScriptGlobalObject(nsnull);
|
2005-05-18 07:52:33 +04:00
|
|
|
|
2008-12-20 02:45:56 +03:00
|
|
|
if (!mSHEntry && mDocument)
|
2008-04-18 14:02:03 +04:00
|
|
|
mDocument->RemovedFromDocShell();
|
2002-10-02 01:57:15 +04:00
|
|
|
}
|
2002-04-17 08:17:16 +04:00
|
|
|
|
2007-05-14 13:11:38 +04:00
|
|
|
if (mFocusListener && mDocument) {
|
2011-06-28 21:59:14 +04:00
|
|
|
mDocument->RemoveEventListener(NS_LITERAL_STRING("focus"), mFocusListener,
|
2011-10-17 18:59:28 +04:00
|
|
|
false);
|
2011-06-28 21:59:14 +04:00
|
|
|
mDocument->RemoveEventListener(NS_LITERAL_STRING("blur"), mFocusListener,
|
2011-10-17 18:59:28 +04:00
|
|
|
false);
|
2002-04-17 08:17:16 +04:00
|
|
|
}
|
2001-03-10 06:19:36 +03:00
|
|
|
|
2001-08-01 07:15:50 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-11-06 22:23:03 +03:00
|
|
|
static void
|
|
|
|
DetachContainerRecurse(nsIDocShell *aShell)
|
|
|
|
{
|
|
|
|
// Unhook this docshell's presentation
|
|
|
|
nsCOMPtr<nsIContentViewer> viewer;
|
|
|
|
aShell->GetContentViewer(getter_AddRefs(viewer));
|
2011-10-15 11:33:26 +04:00
|
|
|
if (viewer) {
|
|
|
|
nsIDocument* doc = viewer->GetDocument();
|
2005-11-06 22:23:03 +03:00
|
|
|
if (doc) {
|
|
|
|
doc->SetContainer(nsnull);
|
|
|
|
}
|
2010-03-25 16:17:11 +03:00
|
|
|
nsRefPtr<nsPresContext> pc;
|
2011-10-15 11:33:26 +04:00
|
|
|
viewer->GetPresContext(getter_AddRefs(pc));
|
2005-11-06 22:23:03 +03:00
|
|
|
if (pc) {
|
|
|
|
pc->SetContainer(nsnull);
|
|
|
|
pc->SetLinkHandler(nsnull);
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsIPresShell> presShell;
|
2011-10-15 11:33:26 +04:00
|
|
|
viewer->GetPresShell(getter_AddRefs(presShell));
|
2005-11-06 22:23:03 +03:00
|
|
|
if (presShell) {
|
|
|
|
presShell->SetForwardingContainer(nsWeakPtr(do_GetWeakReference(aShell)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now recurse through the children
|
|
|
|
nsCOMPtr<nsIDocShellTreeNode> node = do_QueryInterface(aShell);
|
|
|
|
NS_ASSERTION(node, "docshells must implement nsIDocShellTreeNode");
|
|
|
|
|
|
|
|
PRInt32 childCount;
|
|
|
|
node->GetChildCount(&childCount);
|
|
|
|
for (PRInt32 i = 0; i < childCount; ++i) {
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> childItem;
|
|
|
|
node->GetChildAt(i, getter_AddRefs(childItem));
|
|
|
|
DetachContainerRecurse(nsCOMPtr<nsIDocShell>(do_QueryInterface(childItem)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-08-01 07:15:50 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
DocumentViewerImpl::Destroy()
|
|
|
|
{
|
2005-05-05 00:22:32 +04:00
|
|
|
NS_ASSERTION(mDocument, "No document in Destroy()!");
|
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
#ifdef NS_PRINTING
|
2009-01-17 04:35:19 +03:00
|
|
|
// Here is where we check to see if the document was still being prepared
|
2002-03-23 19:48:58 +03:00
|
|
|
// for printing when it was asked to be destroy from someone externally
|
2009-01-17 04:35:19 +03:00
|
|
|
// This usually happens if the document is unloaded while the user is in the
|
|
|
|
// Print Dialog
|
2002-03-23 19:48:58 +03:00
|
|
|
//
|
|
|
|
// 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
|
|
|
|
2005-05-05 00:22:32 +04:00
|
|
|
// Don't let the document get unloaded while we are printing.
|
|
|
|
// this could happen if we hit the back button during printing.
|
|
|
|
// We also keep the viewer from being cached in session history, since
|
|
|
|
// we require all documents there to be sanitized.
|
2001-08-06 06:27:43 +04:00
|
|
|
if (mDestroyRefCount != 0) {
|
|
|
|
--mDestroyRefCount;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-05-05 00:22:32 +04:00
|
|
|
// If we were told to put ourselves into session history instead of destroy
|
|
|
|
// the presentation, do that now.
|
|
|
|
if (mSHEntry) {
|
|
|
|
if (mPresShell)
|
|
|
|
mPresShell->Freeze();
|
|
|
|
|
|
|
|
// Make sure the presentation isn't torn down by Hide().
|
|
|
|
mSHEntry->SetSticky(mIsSticky);
|
2011-10-17 18:59:28 +04:00
|
|
|
mIsSticky = true;
|
2005-05-05 00:22:32 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool savePresentation = true;
|
2005-05-05 00:22:32 +04:00
|
|
|
|
|
|
|
// Remove our root view from the view hierarchy.
|
|
|
|
if (mPresShell) {
|
|
|
|
nsIViewManager *vm = mPresShell->GetViewManager();
|
|
|
|
if (vm) {
|
2011-03-30 06:24:54 +04:00
|
|
|
nsIView *rootView = vm->GetRootView();
|
2005-05-05 00:22:32 +04:00
|
|
|
|
|
|
|
if (rootView) {
|
2011-02-07 21:51:54 +03:00
|
|
|
// The invalidate that removing this view causes is dropped because
|
|
|
|
// the Freeze call above sets painting to be suppressed for our
|
|
|
|
// document. So we do it ourselves and make it happen.
|
2011-12-24 07:52:25 +04:00
|
|
|
vm->InvalidateViewNoSuppression(rootView,
|
2011-12-24 07:52:22 +04:00
|
|
|
rootView->GetBounds() - rootView->GetPosition());
|
2011-02-07 21:51:54 +03:00
|
|
|
|
2005-05-05 00:22:32 +04:00
|
|
|
nsIView *rootViewParent = rootView->GetParent();
|
|
|
|
if (rootViewParent) {
|
|
|
|
nsIViewManager *parentVM = rootViewParent->GetViewManager();
|
|
|
|
if (parentVM) {
|
|
|
|
parentVM->RemoveChild(rootView);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Hide();
|
|
|
|
|
|
|
|
// This is after Hide() so that the user doesn't see the inputs clear.
|
|
|
|
if (mDocument) {
|
|
|
|
nsresult rv = mDocument->Sanitize();
|
|
|
|
if (NS_FAILED(rv)) {
|
2005-10-08 00:20:52 +04:00
|
|
|
// If we failed to sanitize, don't save presentation.
|
2010-11-24 00:24:57 +03:00
|
|
|
// XXX Shouldn't we run all the stuff after the |if (mSHEntry)| then?
|
2011-10-17 18:59:28 +04:00
|
|
|
savePresentation = false;
|
2005-05-05 00:22:32 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-10-08 00:20:52 +04:00
|
|
|
// Reverse ownership. Do this *after* calling sanitize so that sanitize
|
|
|
|
// doesn't cause mutations that make the SHEntry drop the presentation
|
2011-02-12 09:12:20 +03:00
|
|
|
|
|
|
|
// Grab a reference to mSHEntry before calling into things like
|
|
|
|
// SyncPresentationState that might mess with our members.
|
2005-11-06 22:23:03 +03:00
|
|
|
nsCOMPtr<nsISHEntry> shEntry = mSHEntry; // we'll need this below
|
2005-05-05 00:22:32 +04:00
|
|
|
mSHEntry = nsnull;
|
|
|
|
|
2011-02-12 09:12:20 +03:00
|
|
|
if (savePresentation) {
|
|
|
|
shEntry->SetContentViewer(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Always sync the presentation state. That way even if someone screws up
|
|
|
|
// and shEntry has no window state at this point we'll be ok; we just won't
|
|
|
|
// cache ourselves.
|
|
|
|
shEntry->SyncPresentationState();
|
|
|
|
|
2005-05-05 00:22:32 +04:00
|
|
|
// Break the link from the document/presentation to the docshell, so that
|
|
|
|
// link traversals cannot affect the currently-loaded document.
|
|
|
|
// When the presentation is restored, Open() and InitInternal() will reset
|
|
|
|
// these pointers to their original values.
|
|
|
|
|
2010-11-24 00:24:57 +03:00
|
|
|
if (mDocument) {
|
2005-05-05 00:22:32 +04:00
|
|
|
mDocument->SetContainer(nsnull);
|
2010-11-24 00:24:57 +03:00
|
|
|
}
|
2005-06-21 06:18:57 +04:00
|
|
|
if (mPresContext) {
|
2005-05-05 00:22:32 +04:00
|
|
|
mPresContext->SetLinkHandler(nsnull);
|
2005-06-21 06:18:57 +04:00
|
|
|
mPresContext->SetContainer(nsnull);
|
|
|
|
}
|
2005-08-22 05:55:34 +04:00
|
|
|
if (mPresShell)
|
|
|
|
mPresShell->SetForwardingContainer(mContainer);
|
2005-05-05 00:22:32 +04:00
|
|
|
|
2005-11-06 22:23:03 +03:00
|
|
|
// Do the same for our children. Note that we need to get the child
|
|
|
|
// docshells from the SHEntry now; the docshell will have cleared them.
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> item;
|
|
|
|
PRInt32 itemIndex = 0;
|
|
|
|
while (NS_SUCCEEDED(shEntry->ChildShellAt(itemIndex++,
|
|
|
|
getter_AddRefs(item))) && item) {
|
|
|
|
DetachContainerRecurse(nsCOMPtr<nsIDocShell>(do_QueryInterface(item)));
|
|
|
|
}
|
|
|
|
|
2005-05-05 00:22:32 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-11-24 00:24:57 +03:00
|
|
|
// The document was not put in the bfcache
|
|
|
|
|
2005-06-02 05:02:16 +04:00
|
|
|
if (mDocument) {
|
|
|
|
mDocument->Destroy();
|
|
|
|
mDocument = nsnull;
|
|
|
|
}
|
2005-05-05 00:22:32 +04:00
|
|
|
|
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.
|
|
|
|
|
2008-04-09 09:24:13 +04:00
|
|
|
#ifdef NS_PRINTING
|
|
|
|
if (mPrintEngine) {
|
|
|
|
#ifdef NS_PRINT_PREVIEW
|
2011-09-29 10:19:26 +04:00
|
|
|
bool doingPrintPreview;
|
2008-04-09 09:24:13 +04:00
|
|
|
mPrintEngine->GetDoingPrintPreview(&doingPrintPreview);
|
|
|
|
if (doingPrintPreview) {
|
|
|
|
mPrintEngine->FinishPrintPreview();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
mPrintEngine->Destroy();
|
|
|
|
mPrintEngine = nsnull;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2001-08-01 07:15:50 +04:00
|
|
|
// Avoid leaking the old viewer.
|
|
|
|
if (mPreviousViewer) {
|
|
|
|
mPreviousViewer->Destroy();
|
|
|
|
mPreviousViewer = nsnull;
|
|
|
|
}
|
|
|
|
|
2008-01-21 05:05:38 +03:00
|
|
|
mDeviceContext = nsnull;
|
2001-03-10 06:19:36 +03:00
|
|
|
|
|
|
|
if (mPresShell) {
|
2009-01-14 15:24:10 +03:00
|
|
|
DestroyPresShell();
|
2001-03-10 06:19:36 +03:00
|
|
|
}
|
2002-04-17 08:17:16 +04:00
|
|
|
|
2004-02-11 09:48:37 +03:00
|
|
|
if (mPresContext) {
|
2011-01-21 22:09:11 +03:00
|
|
|
DestroyPresContext();
|
2004-02-11 09:48:37 +03:00
|
|
|
}
|
|
|
|
|
2010-10-27 20:57:21 +04:00
|
|
|
mWindow = nsnull;
|
|
|
|
mViewManager = nsnull;
|
2004-02-11 09:09:51 +03:00
|
|
|
mContainer = nsnull;
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2010-02-18 22:23:23 +03:00
|
|
|
if (!mHidden && (mLoaded || mStopped) && mPresContext && !mSHEntry)
|
2003-07-12 00:19:34 +04:00
|
|
|
mPresContext->SetImageAnimationMode(imgIContainer::kDontAnimMode);
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mStopped = true;
|
2001-05-02 02:50:16 +04:00
|
|
|
|
|
|
|
if (!mLoaded && mPresShell) {
|
|
|
|
// Well, we might as well paint what we have so far.
|
2007-04-27 15:06:22 +04:00
|
|
|
nsCOMPtr<nsIPresShell> shellDeathGrip(mPresShell); // bug 378682
|
2001-05-02 02:50:16 +04:00
|
|
|
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);
|
2003-03-26 10:41:30 +03:00
|
|
|
return CallQueryInterface(mDocument, aResult);
|
2000-06-22 09:38:07 +04:00
|
|
|
}
|
|
|
|
|
2010-01-23 14:41:41 +03:00
|
|
|
NS_IMETHODIMP_(nsIDocument *)
|
|
|
|
DocumentViewerImpl::GetDocument()
|
|
|
|
{
|
|
|
|
return mDocument;
|
|
|
|
}
|
|
|
|
|
2000-06-22 09:38:07 +04:00
|
|
|
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
|
|
|
|
|
|
|
if (!aDocument)
|
2000-09-02 19:32:28 +04:00
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
2010-09-16 02:54:00 +04:00
|
|
|
nsCOMPtr<nsIDocument> newDoc = do_QueryInterface(aDocument);
|
|
|
|
NS_ENSURE_TRUE(newDoc, NS_ERROR_UNEXPECTED);
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return SetDocumentInternal(newDoc, false);
|
2010-09-16 02:54:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
DocumentViewerImpl::SetDocumentInternal(nsIDocument* aDocument,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aForceReuseInnerWindow)
|
2010-09-16 02:54:00 +04:00
|
|
|
{
|
2000-09-02 19:32:28 +04:00
|
|
|
|
2005-02-05 16:41:00 +03:00
|
|
|
// Set new container
|
2005-05-15 04:30:02 +04:00
|
|
|
nsCOMPtr<nsISupports> container = do_QueryReferent(mContainer);
|
2010-09-16 02:54:00 +04:00
|
|
|
aDocument->SetContainer(container);
|
2005-02-05 16:41:00 +03:00
|
|
|
|
2010-09-16 02:54:00 +04:00
|
|
|
if (mDocument != aDocument) {
|
2011-06-16 22:20:13 +04:00
|
|
|
if (mDocument->IsStaticDocument()) {
|
|
|
|
mDocument->SetScriptGlobalObject(nsnull);
|
|
|
|
mDocument->Destroy();
|
|
|
|
}
|
2005-07-31 00:57:07 +04:00
|
|
|
// Replace the old document with the new one. Do this only when
|
|
|
|
// the new document really is a new document.
|
2010-09-16 02:54:00 +04:00
|
|
|
mDocument = aDocument;
|
2002-04-05 02:42:19 +04:00
|
|
|
|
2005-07-31 00:57:07 +04:00
|
|
|
// Set the script global object on the new document
|
2005-12-01 22:35:27 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindow> window = do_GetInterface(container);
|
|
|
|
if (window) {
|
2010-09-16 02:54:00 +04:00
|
|
|
window->SetNewDocument(aDocument, nsnull, aForceReuseInnerWindow);
|
2005-07-31 00:57:07 +04:00
|
|
|
}
|
2006-06-26 23:06:20 +04:00
|
|
|
|
2011-01-21 22:09:11 +03:00
|
|
|
// Clear the list of old child docshells. Child docshells for the new
|
2006-06-26 23:06:20 +04:00
|
|
|
// document will be constructed as frames are created.
|
2010-09-16 02:54:00 +04:00
|
|
|
if (!aDocument->IsStaticDocument()) {
|
2009-12-11 07:02:13 +03:00
|
|
|
nsCOMPtr<nsIDocShellTreeNode> node = do_QueryInterface(container);
|
|
|
|
if (node) {
|
|
|
|
PRInt32 count;
|
|
|
|
node->GetChildCount(&count);
|
|
|
|
for (PRInt32 i = 0; i < count; ++i) {
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> child;
|
|
|
|
node->GetChildAt(0, getter_AddRefs(child));
|
|
|
|
node->RemoveChild(child);
|
|
|
|
}
|
2006-06-26 23:06:20 +04:00
|
|
|
}
|
|
|
|
}
|
2002-04-17 08:17:16 +04:00
|
|
|
}
|
2002-04-05 02:42:19 +04:00
|
|
|
|
2010-09-16 02:54:00 +04:00
|
|
|
nsresult rv = SyncParentSubDocMap();
|
2005-07-31 00:57:07 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2005-02-05 16:41:00 +03:00
|
|
|
// 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) {
|
2009-01-14 15:24:10 +03:00
|
|
|
DestroyPresShell();
|
2002-04-17 08:17:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mPresContext) {
|
2011-01-21 22:09:11 +03:00
|
|
|
DestroyPresContext();
|
2004-08-25 18:17:40 +04:00
|
|
|
|
2011-02-16 00:45:02 +03:00
|
|
|
mWindow = nsnull;
|
2011-10-17 18:59:28 +04:00
|
|
|
InitInternal(mParentWidget, nsnull, mBounds, true, true, false);
|
2000-09-02 19:32:28 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
2000-06-22 09:38:07 +04:00
|
|
|
}
|
|
|
|
|
2007-11-09 13:19:12 +03:00
|
|
|
nsIPresShell*
|
|
|
|
DocumentViewerImpl::GetPresShell()
|
|
|
|
{
|
2009-12-11 07:02:13 +03:00
|
|
|
return mPresShell;
|
2007-11-09 13:19:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsPresContext*
|
|
|
|
DocumentViewerImpl::GetPresContext()
|
|
|
|
{
|
2009-12-11 07:02:13 +03:00
|
|
|
return mPresContext;
|
2007-11-09 13:19:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsIViewManager*
|
|
|
|
DocumentViewerImpl::GetViewManager()
|
|
|
|
{
|
2009-12-11 07:02:13 +03:00
|
|
|
return mViewManager;
|
2007-11-09 13:19:12 +03:00
|
|
|
}
|
|
|
|
|
1999-05-06 23:25:40 +04:00
|
|
|
NS_IMETHODIMP
|
2003-06-14 00:10:01 +04:00
|
|
|
DocumentViewerImpl::GetPresShell(nsIPresShell** aResult)
|
1999-05-06 23:25:40 +04:00
|
|
|
{
|
2007-11-09 13:19:12 +03:00
|
|
|
nsIPresShell* shell = GetPresShell();
|
|
|
|
NS_IF_ADDREF(*aResult = shell);
|
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
|
2004-08-01 03:15:21 +04:00
|
|
|
DocumentViewerImpl::GetPresContext(nsPresContext** aResult)
|
1999-05-06 23:25:40 +04:00
|
|
|
{
|
2007-11-09 13:19:12 +03:00
|
|
|
nsPresContext* pc = GetPresContext();
|
|
|
|
NS_IF_ADDREF(*aResult = pc);
|
1999-05-06 23:25:40 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2009-01-15 06:27:09 +03:00
|
|
|
DocumentViewerImpl::GetBounds(nsIntRect& aResult)
|
1999-05-06 23:25:40 +04:00
|
|
|
{
|
2001-03-10 06:19:36 +03:00
|
|
|
NS_ENSURE_TRUE(mDocument, NS_ERROR_NOT_AVAILABLE);
|
2009-07-22 04:45:10 +04:00
|
|
|
aResult = mBounds;
|
1999-05-06 23:25:40 +04:00
|
|
|
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).
|
2007-10-06 04:35:00 +04:00
|
|
|
// It's very important that if this ever gets changed the code
|
|
|
|
// before the RestorePresentation call in nsDocShell::InternalLoad
|
|
|
|
// be changed accordingly.
|
2001-05-02 02:50:16 +04:00
|
|
|
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
|
2009-01-15 06:27:09 +03:00
|
|
|
DocumentViewerImpl::SetBounds(const nsIntRect& aBounds)
|
1999-05-06 23:25:40 +04:00
|
|
|
{
|
2001-03-10 06:19:36 +03:00
|
|
|
NS_ENSURE_TRUE(mDocument, NS_ERROR_NOT_AVAILABLE);
|
2002-04-17 08:17:16 +04:00
|
|
|
|
2009-07-22 04:45:10 +04:00
|
|
|
mBounds = aBounds;
|
1999-05-06 23:25:40 +04:00
|
|
|
if (mWindow) {
|
2010-06-25 06:01:06 +04:00
|
|
|
// When attached to a top level window, change the client area, not the
|
|
|
|
// window frame.
|
1999-05-06 23:25:40 +04:00
|
|
|
// Don't have the widget repaint. Layout will generate repaint requests
|
2010-06-25 06:01:06 +04:00
|
|
|
// during reflow.
|
2011-12-02 01:35:42 +04:00
|
|
|
if (mAttachedToParent) {
|
|
|
|
if (aBounds.x != 0 || aBounds.y != 0) {
|
|
|
|
mWindow->ResizeClient(aBounds.x, aBounds.y,
|
|
|
|
aBounds.width, aBounds.height,
|
|
|
|
false);
|
|
|
|
} else {
|
|
|
|
mWindow->ResizeClient(aBounds.width, aBounds.height, false);
|
|
|
|
}
|
|
|
|
} else {
|
2010-06-25 06:01:06 +04:00
|
|
|
mWindow->Resize(aBounds.x, aBounds.y,
|
|
|
|
aBounds.width, aBounds.height,
|
2011-10-17 18:59:28 +04:00
|
|
|
false);
|
2011-12-02 01:35:42 +04:00
|
|
|
}
|
2009-07-22 04:45:10 +04:00
|
|
|
} else if (mPresContext && mViewManager) {
|
|
|
|
PRInt32 p2a = mPresContext->AppUnitsPerDevPixel();
|
|
|
|
mViewManager->SetWindowDimensions(NSIntPixelsToAppUnits(mBounds.width, p2a),
|
|
|
|
NSIntPixelsToAppUnits(mBounds.height, p2a));
|
1999-05-06 23:25:40 +04:00
|
|
|
}
|
2005-08-03 00:19:19 +04:00
|
|
|
|
|
|
|
// If there's a previous viewer, it's the one that's actually showing,
|
|
|
|
// so be sure to resize it as well so it paints over the right area.
|
|
|
|
// This may slow down the performance of the new page load, but resize
|
|
|
|
// during load is also probably a relatively unusual condition
|
|
|
|
// relating to things being hidden while something is loaded. It so
|
|
|
|
// happens that Firefox does this a good bit with its infobar, and it
|
|
|
|
// looks ugly if we don't do this.
|
|
|
|
if (mPreviousViewer)
|
|
|
|
mPreviousViewer->SetBounds(aBounds);
|
|
|
|
|
1999-05-06 23:25:40 +04:00
|
|
|
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);
|
2009-07-22 04:45:10 +04:00
|
|
|
mBounds.MoveTo(aX, aY);
|
1999-05-06 23:25:40 +04:00
|
|
|
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();
|
2005-09-23 22:16:40 +04:00
|
|
|
|
|
|
|
// Make sure we don't have too many cached ContentViewers
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> treeItem = do_QueryReferent(mContainer);
|
|
|
|
if (treeItem) {
|
|
|
|
// We need to find the root DocShell since only that object has an
|
|
|
|
// SHistory and we need the SHistory to evict content viewers
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> root;
|
|
|
|
treeItem->GetSameTypeRootTreeItem(getter_AddRefs(root));
|
|
|
|
nsCOMPtr<nsIWebNavigation> webNav = do_QueryInterface(root);
|
|
|
|
nsCOMPtr<nsISHistory> history;
|
|
|
|
webNav->GetSessionHistory(getter_AddRefs(history));
|
|
|
|
nsCOMPtr<nsISHistoryInternal> historyInt = do_QueryInterface(history);
|
|
|
|
if (historyInt) {
|
2008-09-29 22:28:15 +04:00
|
|
|
PRInt32 prevIndex,loadedIndex;
|
|
|
|
nsCOMPtr<nsIDocShell> docShell = do_QueryInterface(treeItem);
|
|
|
|
docShell->GetPreviousTransIndex(&prevIndex);
|
|
|
|
docShell->GetLoadedTransIndex(&loadedIndex);
|
2005-09-23 22:16:40 +04:00
|
|
|
#ifdef DEBUG_PAGE_CACHE
|
2008-09-29 22:28:15 +04:00
|
|
|
printf("About to evict content viewers: prev=%d, loaded=%d\n",
|
|
|
|
prevIndex, loadedIndex);
|
2005-09-23 22:16:40 +04:00
|
|
|
#endif
|
2011-10-21 19:26:34 +04:00
|
|
|
historyInt->EvictOutOfRangeContentViewers(loadedIndex);
|
2005-09-23 22:16:40 +04:00
|
|
|
}
|
|
|
|
}
|
2001-08-01 07:15:50 +04:00
|
|
|
}
|
|
|
|
|
2010-07-16 06:47:14 +04:00
|
|
|
if (mWindow) {
|
2010-10-15 17:52:29 +04:00
|
|
|
// When attached to a top level xul window, we do not need to call
|
|
|
|
// Show on the widget. Underlying window management code handles
|
|
|
|
// this when the window is initialized.
|
|
|
|
if (!mAttachedToParent) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mWindow->Show(true);
|
2010-08-04 09:36:19 +04:00
|
|
|
}
|
1999-05-06 23:25:40 +04:00
|
|
|
}
|
2002-04-17 08:17:16 +04:00
|
|
|
|
2009-07-22 04:45:10 +04:00
|
|
|
if (mDocument && !mPresShell) {
|
|
|
|
NS_ASSERTION(!mWindow, "Window already created but no presshell?");
|
|
|
|
|
2005-05-15 04:30:02 +04:00
|
|
|
nsCOMPtr<nsIBaseWindow> base_win(do_QueryReferent(mContainer));
|
2008-09-28 23:14:28 +04:00
|
|
|
if (base_win) {
|
|
|
|
base_win->GetParentWidget(&mParentWidget);
|
2009-07-22 04:45:10 +04:00
|
|
|
if (mParentWidget) {
|
|
|
|
mParentWidget->Release(); // GetParentWidget AddRefs, but mParentWidget is weak
|
|
|
|
}
|
2008-09-28 23:14:28 +04:00
|
|
|
}
|
2002-04-17 08:17:16 +04:00
|
|
|
|
2009-07-22 04:44:53 +04:00
|
|
|
nsIView* containerView = FindContainerView();
|
|
|
|
|
2009-07-22 04:45:10 +04:00
|
|
|
nsresult rv = CreateDeviceContext(containerView);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2002-04-17 08:17:16 +04:00
|
|
|
// Create presentation context
|
2004-02-11 09:48:37 +03:00
|
|
|
NS_ASSERTION(!mPresContext, "Shouldn't have a prescontext if we have no shell!");
|
2009-07-22 04:44:54 +04:00
|
|
|
mPresContext = CreatePresContext(mDocument,
|
|
|
|
nsPresContext::eContext_Galley, containerView);
|
2004-07-29 23:41:39 +04:00
|
|
|
NS_ENSURE_TRUE(mPresContext, NS_ERROR_OUT_OF_MEMORY);
|
2002-04-17 08:17:16 +04:00
|
|
|
|
2004-01-21 12:35:59 +03:00
|
|
|
rv = mPresContext->Init(mDeviceContext);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
mPresContext = nsnull;
|
|
|
|
return rv;
|
|
|
|
}
|
2002-04-17 08:17:16 +04:00
|
|
|
|
2009-07-22 04:45:10 +04:00
|
|
|
rv = MakeWindow(nsSize(mPresContext->DevPixelsToAppUnits(mBounds.width),
|
|
|
|
mPresContext->DevPixelsToAppUnits(mBounds.height)),
|
2009-07-22 04:44:53 +04:00
|
|
|
containerView);
|
2002-04-17 08:17:16 +04:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2005-05-15 04:30:02 +04:00
|
|
|
if (mPresContext && base_win) {
|
|
|
|
nsCOMPtr<nsILinkHandler> linkHandler(do_GetInterface(base_win));
|
2002-04-17 08:17:16 +04:00
|
|
|
|
|
|
|
if (linkHandler) {
|
|
|
|
mPresContext->SetLinkHandler(linkHandler);
|
|
|
|
}
|
|
|
|
|
2005-05-15 04:30:02 +04:00
|
|
|
mPresContext->SetContainer(base_win);
|
2002-04-17 08:17:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mPresContext) {
|
|
|
|
Hide();
|
|
|
|
|
2010-02-18 22:23:23 +03:00
|
|
|
rv = InitPresentationStuff(mDocument->MayStartLayout());
|
2002-04-17 08:17:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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...
|
|
|
|
|
2009-12-11 07:02:13 +03:00
|
|
|
if (mPresShell) {
|
|
|
|
nsCOMPtr<nsIPresShell> shellDeathGrip(mPresShell); // bug 378682
|
|
|
|
mPresShell->UnsuppressPainting();
|
|
|
|
}
|
2002-04-17 08:17:16 +04:00
|
|
|
}
|
|
|
|
|
2012-03-12 20:03:38 +04:00
|
|
|
// Notify observers that a new page is about to be drawn. Execute this
|
|
|
|
// as soon as it is safe to run JS, which is guaranteed to be before we
|
|
|
|
// go back to the event loop and actually draw the page.
|
|
|
|
nsContentUtils::AddScriptRunner(new nsBeforeFirstPaintDispatcher(mDocument));
|
|
|
|
|
|
|
|
// Notify observers that a new page has been shown. This will get run
|
|
|
|
// from the event loop after we actually draw the page.
|
2012-01-07 04:42:42 +04:00
|
|
|
NS_DispatchToMainThread(new nsDocumentShownDispatcher(mDocument));
|
|
|
|
|
1999-05-06 23:25:40 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
DocumentViewerImpl::Hide(void)
|
|
|
|
{
|
2010-10-22 01:59:26 +04:00
|
|
|
if (!mAttachedToParent && mWindow) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mWindow->Show(false);
|
1999-05-06 23:25:40 +04:00
|
|
|
}
|
2002-04-17 08:17:16 +04:00
|
|
|
|
2006-12-10 11:05:05 +03:00
|
|
|
if (!mPresShell)
|
2002-04-17 08:17:16 +04:00
|
|
|
return NS_OK;
|
|
|
|
|
2004-02-11 09:48:37 +03:00
|
|
|
NS_ASSERTION(mPresContext, "Can't have a presshell and no prescontext!");
|
|
|
|
|
2002-04-17 08:17:16 +04:00
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
2005-05-15 04:30:02 +04:00
|
|
|
nsCOMPtr<nsIDocShell> docShell(do_QueryReferent(mContainer));
|
2003-05-30 04:21:01 +04:00
|
|
|
if (docShell) {
|
2008-12-03 20:55:14 +03:00
|
|
|
nsCOMPtr<nsILayoutHistoryState> layoutState;
|
2011-10-17 18:59:28 +04:00
|
|
|
mPresShell->CaptureHistoryState(getter_AddRefs(layoutState), true);
|
2003-05-30 04:21:01 +04:00
|
|
|
}
|
|
|
|
|
2009-01-14 15:24:10 +03:00
|
|
|
DestroyPresShell();
|
|
|
|
|
2011-01-21 22:09:11 +03:00
|
|
|
DestroyPresContext();
|
2002-04-17 08:17:16 +04:00
|
|
|
|
|
|
|
mViewManager = nsnull;
|
|
|
|
mWindow = nsnull;
|
|
|
|
mDeviceContext = nsnull;
|
|
|
|
mParentWidget = nsnull;
|
|
|
|
|
2005-05-15 04:30:02 +04:00
|
|
|
nsCOMPtr<nsIBaseWindow> base_win(do_QueryReferent(mContainer));
|
2002-04-17 08:17:16 +04:00
|
|
|
|
2010-10-22 01:59:26 +04:00
|
|
|
if (base_win && !mAttachedToParent) {
|
2002-04-17 08:17:16 +04:00
|
|
|
base_win->SetParentWidget(nsnull);
|
|
|
|
}
|
|
|
|
|
1999-05-06 23:25:40 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-09-22 18:42:13 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
DocumentViewerImpl::GetSticky(bool *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
|
2011-09-29 10:19:26 +04:00
|
|
|
DocumentViewerImpl::SetSticky(bool aSticky)
|
2002-08-21 16:01:05 +04:00
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2003-09-27 01:45:15 +04:00
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
DocumentViewerImpl::RequestWindowClose(bool* aCanClose)
|
2003-09-27 01:45:15 +04:00
|
|
|
{
|
|
|
|
#ifdef NS_PRINTING
|
|
|
|
if (mPrintIsPending || (mPrintEngine && mPrintEngine->GetIsPrinting())) {
|
2011-10-17 18:59:28 +04:00
|
|
|
*aCanClose = false;
|
|
|
|
mDeferredWindowClose = true;
|
2003-09-27 01:45:15 +04:00
|
|
|
} else
|
|
|
|
#endif
|
2011-10-17 18:59:28 +04:00
|
|
|
*aCanClose = true;
|
2003-09-27 01:45:15 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool
|
2005-01-15 03:10:19 +03:00
|
|
|
AppendAgentSheet(nsIStyleSheet *aSheet, void *aData)
|
|
|
|
{
|
2007-07-08 11:08:04 +04:00
|
|
|
nsStyleSet *styleSet = static_cast<nsStyleSet*>(aData);
|
2005-01-15 03:10:19 +03:00
|
|
|
styleSet->AppendStyleSheet(nsStyleSet::eAgentSheet, aSheet);
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2005-01-15 03:10:19 +03:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool
|
2005-08-20 05:24:00 +04:00
|
|
|
PrependUserSheet(nsIStyleSheet *aSheet, void *aData)
|
2005-01-15 03:10:19 +03:00
|
|
|
{
|
2007-07-08 11:08:04 +04:00
|
|
|
nsStyleSet *styleSet = static_cast<nsStyleSet*>(aData);
|
2005-08-20 05:24:00 +04:00
|
|
|
styleSet->PrependStyleSheet(nsStyleSet::eUserSheet, aSheet);
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2005-01-15 03:10:19 +03:00
|
|
|
}
|
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
nsresult
|
|
|
|
DocumentViewerImpl::CreateStyleSet(nsIDocument* aDocument,
|
2004-01-08 01:30:53 +03:00
|
|
|
nsStyleSet** aStyleSet)
|
2002-02-19 14:49:27 +03:00
|
|
|
{
|
2006-06-08 18:32:20 +04:00
|
|
|
// Make sure this does the same thing as PresShell::AddSheet wrt ordering.
|
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
// this should eventually get expanded to allow for creating
|
|
|
|
// different sets for different media
|
2004-01-11 12:34:07 +03:00
|
|
|
nsStyleSet *styleSet = new nsStyleSet();
|
2001-01-27 17:09:34 +03:00
|
|
|
|
2004-01-08 01:30:53 +03:00
|
|
|
styleSet->BeginUpdate();
|
2004-07-16 00:30:30 +04:00
|
|
|
|
|
|
|
// The document will fill in the document sheets when we create the presshell
|
|
|
|
|
|
|
|
// Handle the user sheets.
|
2008-10-05 00:00:09 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
nsCOMPtr<nsISupports> debugDocContainer = aDocument->GetContainer();
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> debugDocShell(do_QueryReferent(mContainer));
|
|
|
|
NS_ASSERTION(SameCOMIdentity(debugDocContainer, debugDocShell),
|
|
|
|
"Unexpected containers");
|
|
|
|
#endif
|
2010-05-12 00:41:47 +04:00
|
|
|
nsCSSStyleSheet* sheet = nsnull;
|
2008-10-05 00:00:09 +04:00
|
|
|
if (nsContentUtils::IsInChromeDocshell(aDocument)) {
|
2004-03-09 22:59:09 +03:00
|
|
|
sheet = nsLayoutStylesheetCache::UserChromeSheet();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
sheet = nsLayoutStylesheetCache::UserContentSheet();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sheet)
|
2004-07-28 11:08:41 +04:00
|
|
|
styleSet->AppendStyleSheet(nsStyleSet::eUserSheet, sheet);
|
2004-03-09 22:59:09 +03:00
|
|
|
|
|
|
|
// Append chrome sheets (scrollbars + forms).
|
2011-09-29 10:19:26 +04:00
|
|
|
bool shouldOverride = false;
|
2008-10-05 00:00:09 +04:00
|
|
|
// We don't want a docshell here for external resource docs, so just
|
|
|
|
// look at mContainer.
|
|
|
|
nsCOMPtr<nsIDocShell> ds(do_QueryReferent(mContainer));
|
2007-02-16 02:04:33 +03:00
|
|
|
nsCOMPtr<nsIDOMEventTarget> chromeHandler;
|
2004-03-09 22:59:09 +03:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
2010-05-12 00:41:47 +04:00
|
|
|
nsRefPtr<nsCSSStyleSheet> csssheet;
|
2004-03-09 22:59:09 +03:00
|
|
|
|
2008-09-28 23:14:28 +04:00
|
|
|
if (ds) {
|
|
|
|
ds->GetChromeEventHandler(getter_AddRefs(chromeHandler));
|
|
|
|
}
|
2004-03-09 22:59:09 +03:00
|
|
|
if (chromeHandler) {
|
|
|
|
nsCOMPtr<nsIDOMElement> elt(do_QueryInterface(chromeHandler));
|
|
|
|
nsCOMPtr<nsIContent> content(do_QueryInterface(elt));
|
|
|
|
if (elt && content) {
|
|
|
|
nsCOMPtr<nsIURI> baseURI = content->GetBaseURI();
|
|
|
|
|
|
|
|
nsAutoString sheets;
|
|
|
|
elt->GetAttribute(NS_LITERAL_STRING("usechromesheets"), sheets);
|
|
|
|
if (!sheets.IsEmpty() && baseURI) {
|
2010-03-03 00:00:53 +03:00
|
|
|
nsRefPtr<mozilla::css::Loader> cssLoader = new mozilla::css::Loader();
|
2005-12-09 14:10:36 +03:00
|
|
|
|
2004-03-09 22:59:09 +03:00
|
|
|
char *str = ToNewCString(sheets);
|
2004-04-14 12:19:27 +04:00
|
|
|
char *newStr = str;
|
|
|
|
char *token;
|
|
|
|
while ( (token = nsCRT::strtok(newStr, ", ", &newStr)) ) {
|
2004-03-09 22:59:09 +03:00
|
|
|
NS_NewURI(getter_AddRefs(uri), nsDependentCString(token), nsnull,
|
|
|
|
baseURI);
|
|
|
|
if (!uri) continue;
|
|
|
|
|
2005-09-12 22:41:15 +04:00
|
|
|
cssLoader->LoadSheetSync(uri, getter_AddRefs(csssheet));
|
2010-04-29 12:37:27 +04:00
|
|
|
if (!csssheet) continue;
|
2004-03-09 22:59:09 +03:00
|
|
|
|
2004-07-28 11:08:41 +04:00
|
|
|
styleSet->PrependStyleSheet(nsStyleSet::eAgentSheet, csssheet);
|
2011-10-17 18:59:28 +04:00
|
|
|
shouldOverride = true;
|
2004-03-09 22:59:09 +03:00
|
|
|
}
|
|
|
|
nsMemory::Free(str);
|
2002-08-21 16:01:05 +04:00
|
|
|
}
|
2004-01-08 01:30:53 +03:00
|
|
|
}
|
2004-03-09 22:59:09 +03:00
|
|
|
}
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2004-03-09 22:59:09 +03:00
|
|
|
if (!shouldOverride) {
|
|
|
|
sheet = nsLayoutStylesheetCache::ScrollbarsSheet();
|
|
|
|
if (sheet) {
|
2004-07-28 11:08:41 +04:00
|
|
|
styleSet->PrependStyleSheet(nsStyleSet::eAgentSheet, sheet);
|
2001-04-12 17:04:29 +04:00
|
|
|
}
|
2004-01-08 01:30:53 +03:00
|
|
|
}
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2004-03-09 22:59:09 +03:00
|
|
|
sheet = nsLayoutStylesheetCache::FormsSheet();
|
|
|
|
if (sheet) {
|
2004-07-28 11:08:41 +04:00
|
|
|
styleSet->PrependStyleSheet(nsStyleSet::eAgentSheet, sheet);
|
2004-03-09 22:59:09 +03:00
|
|
|
}
|
|
|
|
|
2011-11-30 02:00:31 +04:00
|
|
|
sheet = nsLayoutStylesheetCache::FullScreenOverrideSheet();
|
|
|
|
if (sheet) {
|
|
|
|
styleSet->PrependStyleSheet(nsStyleSet::eOverrideSheet, sheet);
|
|
|
|
}
|
|
|
|
|
2008-11-03 05:29:51 +03:00
|
|
|
// Make sure to clone the quirk sheet so that it can be usefully
|
|
|
|
// enabled/disabled as needed.
|
2010-05-12 00:41:47 +04:00
|
|
|
nsRefPtr<nsCSSStyleSheet> quirkClone;
|
|
|
|
nsCSSStyleSheet* quirkSheet;
|
2008-11-03 05:29:51 +03:00
|
|
|
if (!nsLayoutStylesheetCache::UASheet() ||
|
2010-05-12 00:41:47 +04:00
|
|
|
!(quirkSheet = nsLayoutStylesheetCache::QuirkSheet()) ||
|
|
|
|
!(quirkClone = quirkSheet->Clone(nsnull, nsnull, nsnull, nsnull)) ||
|
2008-11-03 05:29:51 +03:00
|
|
|
!sheet) {
|
|
|
|
delete styleSet;
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2002-04-17 08:17:16 +04:00
|
|
|
}
|
2008-11-03 05:29:51 +03:00
|
|
|
// quirk.css needs to come after the regular UA sheet (or more precisely,
|
|
|
|
// after the html.css and so forth that the UA sheet imports).
|
|
|
|
styleSet->PrependStyleSheet(nsStyleSet::eAgentSheet, quirkClone);
|
|
|
|
styleSet->SetQuirkStyleSheet(quirkClone);
|
|
|
|
styleSet->PrependStyleSheet(nsStyleSet::eAgentSheet,
|
|
|
|
nsLayoutStylesheetCache::UASheet());
|
2004-01-08 01:30:53 +03:00
|
|
|
|
2005-01-15 03:10:19 +03:00
|
|
|
nsCOMPtr<nsIStyleSheetService> dummy =
|
|
|
|
do_GetService(NS_STYLESHEETSERVICE_CONTRACTID);
|
|
|
|
|
|
|
|
nsStyleSheetService *sheetService = nsStyleSheetService::gInstance;
|
|
|
|
if (sheetService) {
|
|
|
|
sheetService->AgentStyleSheets()->EnumerateForwards(AppendAgentSheet,
|
|
|
|
styleSet);
|
2005-08-20 05:24:00 +04:00
|
|
|
sheetService->UserStyleSheets()->EnumerateBackwards(PrependUserSheet,
|
|
|
|
styleSet);
|
2005-01-15 03:10:19 +03:00
|
|
|
}
|
|
|
|
|
2004-07-16 00:30:30 +04:00
|
|
|
// Caller will handle calling EndUpdate, per contract.
|
2004-01-08 01:30:53 +03:00
|
|
|
*aStyleSet = styleSet;
|
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
|
|
|
|
2005-05-18 07:52:33 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
DocumentViewerImpl::ClearHistoryEntry()
|
|
|
|
{
|
|
|
|
mSHEntry = nsnull;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-11-03 17:59:39 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
//-------------------------------------------------------
|
2001-01-27 17:09:34 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
nsresult
|
2009-07-22 04:44:53 +04:00
|
|
|
DocumentViewerImpl::MakeWindow(const nsSize& aSize, nsIView* aContainerView)
|
2002-08-21 16:01:05 +04:00
|
|
|
{
|
2009-12-11 07:02:13 +03:00
|
|
|
if (GetIsPrintPreview())
|
|
|
|
return NS_OK;
|
2001-01-27 17:09:34 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool shouldAttach = ShouldAttachToTopLevel();
|
2011-02-09 23:13:18 +03:00
|
|
|
|
|
|
|
if (shouldAttach) {
|
|
|
|
// If the old view is already attached to our parent, detach
|
|
|
|
DetachFromTopLevelWidget();
|
2010-06-25 06:01:06 +04:00
|
|
|
}
|
|
|
|
|
2009-12-11 07:02:13 +03:00
|
|
|
nsresult rv;
|
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
|
|
|
|
2011-04-17 05:22:44 +04:00
|
|
|
nsDeviceContext *dx = mPresContext->DeviceContext();
|
2001-01-27 17:09:34 +03:00
|
|
|
|
2004-05-17 20:29:13 +04:00
|
|
|
rv = mViewManager->Init(dx);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2007-12-01 13:42:12 +03:00
|
|
|
// The root view is always at 0,0.
|
|
|
|
nsRect tbounds(nsPoint(0, 0), aSize);
|
2004-11-04 18:06:50 +03:00
|
|
|
// Create a view
|
2009-07-22 04:44:53 +04:00
|
|
|
nsIView* view = mViewManager->CreateView(tbounds, aContainerView);
|
2004-11-04 18:06:50 +03:00
|
|
|
if (!view)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2002-02-12 16:33:39 +03:00
|
|
|
|
2010-08-20 23:29:02 +04:00
|
|
|
// Create a widget if we were given a parent widget or don't have a
|
2010-09-09 00:40:39 +04:00
|
|
|
// container view that we can hook up to without a widget.
|
2010-09-09 00:40:39 +04:00
|
|
|
// Don't create widgets for ResourceDocs (external resources & svg images),
|
|
|
|
// because when they're displayed, they're painted into *another* document's
|
|
|
|
// widget.
|
|
|
|
if (!mDocument->IsResourceDoc() &&
|
2010-09-09 00:40:39 +04:00
|
|
|
(mParentWidget || !aContainerView)) {
|
2009-07-22 04:45:10 +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
|
|
|
|
nsWidgetInitData initData;
|
|
|
|
nsWidgetInitData* initDataPtr;
|
|
|
|
if (!mParentWidget) {
|
|
|
|
initDataPtr = &initData;
|
|
|
|
initData.mWindowType = eWindowType_invisible;
|
|
|
|
} else {
|
|
|
|
initDataPtr = nsnull;
|
|
|
|
}
|
2010-06-25 06:01:06 +04:00
|
|
|
|
2011-02-09 23:13:18 +03:00
|
|
|
if (shouldAttach) {
|
2010-06-25 06:01:06 +04:00
|
|
|
// Reuse the top level parent widget.
|
|
|
|
rv = view->AttachToTopLevelWidget(mParentWidget);
|
2011-10-17 18:59:28 +04:00
|
|
|
mAttachedToParent = true;
|
2010-06-25 06:01:06 +04:00
|
|
|
}
|
2010-08-20 23:29:02 +04:00
|
|
|
else if (!aContainerView && mParentWidget) {
|
2010-08-20 23:29:02 +04:00
|
|
|
rv = view->CreateWidgetForParent(mParentWidget, initDataPtr,
|
2011-10-17 18:59:28 +04:00
|
|
|
true, false);
|
2010-08-20 23:29:02 +04:00
|
|
|
}
|
2010-06-25 06:01:06 +04:00
|
|
|
else {
|
2011-10-17 18:59:28 +04:00
|
|
|
rv = view->CreateWidget(initDataPtr, true, false);
|
2010-06-25 06:01:06 +04:00
|
|
|
}
|
2009-07-22 04:45:10 +04:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2008-09-28 23:14:28 +04:00
|
|
|
}
|
2002-02-12 16:33:39 +03:00
|
|
|
|
2004-05-17 20:29:13 +04:00
|
|
|
// Setup hierarchical relationship in view manager
|
|
|
|
mViewManager->SetRootView(view);
|
|
|
|
|
2003-08-06 07:07:12 +04:00
|
|
|
mWindow = view->GetWidget();
|
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
|
|
|
}
|
|
|
|
|
2010-06-25 06:01:06 +04:00
|
|
|
void
|
|
|
|
DocumentViewerImpl::DetachFromTopLevelWidget()
|
|
|
|
{
|
|
|
|
if (mViewManager) {
|
2011-03-30 06:24:54 +04:00
|
|
|
nsIView* oldView = mViewManager->GetRootView();
|
2010-06-25 06:01:06 +04:00
|
|
|
if (oldView && oldView->IsAttachedToTopLevel()) {
|
|
|
|
oldView->DetachFromTopLevelWidget();
|
|
|
|
}
|
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
mAttachedToParent = false;
|
2010-06-25 06:01:06 +04:00
|
|
|
}
|
|
|
|
|
2009-07-22 04:44:53 +04:00
|
|
|
nsIView*
|
|
|
|
DocumentViewerImpl::FindContainerView()
|
|
|
|
{
|
2009-07-22 04:45:10 +04:00
|
|
|
nsIView* containerView = nsnull;
|
|
|
|
|
2010-08-28 03:15:08 +04:00
|
|
|
if (mContainer) {
|
2010-08-28 03:15:08 +04:00
|
|
|
nsCOMPtr<nsIDocShellTreeItem> docShellItem = do_QueryReferent(mContainer);
|
|
|
|
nsCOMPtr<nsPIDOMWindow> pwin(do_GetInterface(docShellItem));
|
|
|
|
if (pwin) {
|
|
|
|
nsCOMPtr<nsIContent> containerElement = do_QueryInterface(pwin->GetFrameElementInternal());
|
2011-09-26 08:53:30 +04:00
|
|
|
if (!containerElement) {
|
|
|
|
return nsnull;
|
|
|
|
}
|
2009-07-22 04:45:10 +04:00
|
|
|
nsCOMPtr<nsIPresShell> parentPresShell;
|
|
|
|
if (docShellItem) {
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> parentDocShellItem;
|
|
|
|
docShellItem->GetParent(getter_AddRefs(parentDocShellItem));
|
|
|
|
if (parentDocShellItem) {
|
|
|
|
nsCOMPtr<nsIDocShell> parentDocShell = do_QueryInterface(parentDocShellItem);
|
|
|
|
parentDocShell->GetPresShell(getter_AddRefs(parentPresShell));
|
|
|
|
}
|
|
|
|
}
|
2011-09-26 08:53:30 +04:00
|
|
|
if (!parentPresShell) {
|
2010-08-22 04:55:55 +04:00
|
|
|
nsCOMPtr<nsIDocument> parentDoc = containerElement->GetCurrentDoc();
|
|
|
|
if (parentDoc) {
|
|
|
|
parentPresShell = parentDoc->GetShell();
|
|
|
|
}
|
|
|
|
}
|
2011-09-26 08:53:30 +04:00
|
|
|
if (!parentPresShell) {
|
2009-08-25 23:00:46 +04:00
|
|
|
NS_WARNING("Subdocument container has no presshell");
|
|
|
|
} else {
|
2010-03-05 01:52:59 +03:00
|
|
|
nsIFrame* f = parentPresShell->GetRealPrimaryFrameFor(containerElement);
|
2009-07-22 04:45:10 +04:00
|
|
|
if (f) {
|
|
|
|
nsIFrame* subdocFrame = f->GetContentInsertionFrame();
|
|
|
|
// subdocFrame might not be a subdocument frame; the frame
|
|
|
|
// constructor can treat a <frame> as an inline in some XBL
|
|
|
|
// cases. Treat that as display:none, the document is not
|
|
|
|
// displayed.
|
|
|
|
if (subdocFrame->GetType() == nsGkAtoms::subDocumentFrame) {
|
2010-09-18 15:28:50 +04:00
|
|
|
NS_ASSERTION(subdocFrame->GetView(), "Subdoc frames must have views");
|
|
|
|
nsIView* innerView =
|
|
|
|
static_cast<nsSubDocumentFrame*>(subdocFrame)->EnsureInnerView();
|
2009-07-22 04:45:10 +04:00
|
|
|
containerView = innerView;
|
2009-08-25 23:00:46 +04:00
|
|
|
} else {
|
|
|
|
NS_WARNING("Subdocument container has non-subdocument frame");
|
2009-07-22 04:45:10 +04:00
|
|
|
}
|
2009-08-25 23:00:46 +04:00
|
|
|
} else {
|
|
|
|
NS_WARNING("Subdocument container has no frame");
|
2009-07-22 04:45:10 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-28 03:15:08 +04:00
|
|
|
return containerView;
|
2009-07-22 04:44:53 +04:00
|
|
|
}
|
|
|
|
|
2008-08-18 23:22:19 +04:00
|
|
|
nsresult
|
2009-07-22 04:45:10 +04:00
|
|
|
DocumentViewerImpl::CreateDeviceContext(nsIView* aContainerView)
|
2008-08-18 23:22:19 +04:00
|
|
|
{
|
2010-03-22 17:24:18 +03:00
|
|
|
NS_PRECONDITION(!mPresShell && !mWindow,
|
2008-09-28 23:14:28 +04:00
|
|
|
"This will screw up our existing presentation");
|
2008-10-05 00:00:09 +04:00
|
|
|
NS_PRECONDITION(mDocument, "Gotta have a document here");
|
|
|
|
|
|
|
|
nsIDocument* doc = mDocument->GetDisplayDocument();
|
|
|
|
if (doc) {
|
2009-07-22 04:45:10 +04:00
|
|
|
NS_ASSERTION(!aContainerView, "External resource document embedded somewhere?");
|
2008-10-05 00:00:09 +04:00
|
|
|
// We want to use our display document's device context if possible
|
2010-06-25 17:59:57 +04:00
|
|
|
nsIPresShell* shell = doc->GetShell();
|
2008-10-05 00:00:09 +04:00
|
|
|
if (shell) {
|
|
|
|
nsPresContext* ctx = shell->GetPresContext();
|
|
|
|
if (ctx) {
|
|
|
|
mDeviceContext = ctx->DeviceContext();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-28 23:14:28 +04:00
|
|
|
// Create a device context even if we already have one, since our widget
|
|
|
|
// might have changed.
|
2009-07-22 04:45:10 +04:00
|
|
|
nsIWidget* widget = nsnull;
|
|
|
|
if (aContainerView) {
|
|
|
|
widget = aContainerView->GetNearestWidget(nsnull);
|
|
|
|
}
|
2009-08-18 07:21:07 +04:00
|
|
|
if (!widget) {
|
|
|
|
widget = mParentWidget;
|
|
|
|
}
|
|
|
|
if (widget) {
|
|
|
|
widget = widget->GetTopLevelWidget();
|
|
|
|
}
|
|
|
|
|
2011-04-17 05:22:42 +04:00
|
|
|
mDeviceContext = new nsDeviceContext();
|
2009-07-22 04:45:10 +04:00
|
|
|
mDeviceContext->Init(widget);
|
2008-08-18 23:22:19 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-08-29 19:19:13 +04:00
|
|
|
// Return the selection for the document. Note that text fields have their
|
2010-03-19 21:32:13 +03:00
|
|
|
// own selection, which cannot be accessed with this method.
|
2006-12-10 11:05:05 +03:00
|
|
|
nsresult DocumentViewerImpl::GetDocumentSelection(nsISelection **aSelection)
|
2002-08-21 16:01:05 +04:00
|
|
|
{
|
2006-12-10 11:05:05 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(aSelection);
|
|
|
|
if (!mPresShell) {
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
2002-08-21 16:01:05 +04:00
|
|
|
}
|
2002-01-08 04:17:40 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
nsCOMPtr<nsISelectionController> selcon;
|
2006-12-10 11:05:05 +03:00
|
|
|
selcon = do_QueryInterface(mPresShell);
|
2002-08-21 16:01:05 +04:00
|
|
|
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
|
|
|
/* ========================================================================================
|
|
|
|
* nsIContentViewerEdit
|
|
|
|
* ======================================================================================== */
|
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
|
|
|
|
2010-03-19 21:32:13 +03:00
|
|
|
// use nsCopySupport::GetSelectionForCopy() ?
|
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;
|
2005-08-29 19:19:13 +04:00
|
|
|
|
2010-03-19 21:32:13 +03:00
|
|
|
// use nsCopySupport::GetSelectionForCopy() ?
|
2002-08-21 16:01:05 +04:00
|
|
|
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)
|
|
|
|
{
|
2010-04-30 17:12:05 +04:00
|
|
|
bodyNode = do_QueryInterface(mDocument->GetRootElement());
|
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()
|
|
|
|
{
|
2010-03-19 21:32:13 +03:00
|
|
|
nsCopySupport::FireClipboardEvent(NS_COPY, mPresShell, nsnull);
|
|
|
|
return NS_OK;
|
2002-08-21 16:01:05 +04:00
|
|
|
}
|
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;
|
2003-02-27 04:38:20 +03:00
|
|
|
GetPopupLinkNode(getter_AddRefs(node));
|
2002-08-21 16:01:05 +04:00
|
|
|
// make noise if we're not in a link
|
|
|
|
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;
|
2003-02-27 04:38:20 +03:00
|
|
|
nsresult rv = mPresShell->GetLinkLocation(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
|
|
|
|
2005-03-11 14:12:15 +03:00
|
|
|
NS_IMETHODIMP DocumentViewerImpl::CopyImage(PRInt32 aCopyFlags)
|
2001-04-12 17:04:29 +04:00
|
|
|
{
|
2002-08-21 16:01:05 +04:00
|
|
|
NS_ENSURE_TRUE(mPresShell, NS_ERROR_NOT_INITIALIZED);
|
2004-06-05 21:57:00 +04:00
|
|
|
nsCOMPtr<nsIImageLoadingContent> node;
|
2003-02-27 04:38:20 +03:00
|
|
|
GetPopupImageNode(getter_AddRefs(node));
|
2002-08-21 16:01:05 +04:00
|
|
|
// make noise if we're not in an image
|
|
|
|
NS_ENSURE_TRUE(node, NS_ERROR_FAILURE);
|
2003-02-27 04:38:20 +03:00
|
|
|
|
2005-03-11 14:12:15 +03:00
|
|
|
return nsCopySupport::ImageCopy(node, aCopyFlags);
|
2001-04-12 17:04:29 +04:00
|
|
|
}
|
|
|
|
|
2007-09-01 12:53:07 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
NS_IMETHODIMP DocumentViewerImpl::GetCopyable(bool *aCopyable)
|
2007-09-01 12:53:07 +04:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aCopyable);
|
2010-03-19 21:32:13 +03:00
|
|
|
*aCopyable = nsCopySupport::CanCopy(mDocument);
|
2008-02-24 13:55:37 +03:00
|
|
|
return NS_OK;
|
2002-08-21 16:01:05 +04:00
|
|
|
}
|
2002-04-11 04:33:24 +04:00
|
|
|
|
2003-04-22 22:11:12 +04:00
|
|
|
/* AString getContents (in string mimeType, in boolean selectionOnly); */
|
2011-09-29 10:19:26 +04:00
|
|
|
NS_IMETHODIMP DocumentViewerImpl::GetContents(const char *mimeType, bool selectionOnly, nsAString& aOutValue)
|
2003-04-22 22:11:12 +04:00
|
|
|
{
|
2010-03-19 21:32:13 +03:00
|
|
|
aOutValue.Truncate();
|
|
|
|
|
2003-04-22 22:11:12 +04:00
|
|
|
NS_ENSURE_TRUE(mPresShell, NS_ERROR_NOT_INITIALIZED);
|
2010-03-19 21:32:13 +03:00
|
|
|
NS_ENSURE_TRUE(mDocument, NS_ERROR_NOT_INITIALIZED);
|
|
|
|
|
|
|
|
// Now we have the selection. Make sure it's nonzero:
|
|
|
|
nsCOMPtr<nsISelection> sel;
|
|
|
|
if (selectionOnly) {
|
|
|
|
nsCopySupport::GetSelectionForCopy(mDocument, getter_AddRefs(sel));
|
|
|
|
NS_ENSURE_TRUE(sel, NS_ERROR_FAILURE);
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isCollapsed;
|
2010-03-19 21:32:13 +03:00
|
|
|
sel->GetIsCollapsed(&isCollapsed);
|
|
|
|
if (isCollapsed)
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// call the copy code
|
|
|
|
return nsCopySupport::GetContents(nsDependentCString(mimeType), 0, sel,
|
|
|
|
mDocument, aOutValue);
|
2003-04-22 22:11:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* readonly attribute boolean canGetContents; */
|
2011-09-29 10:19:26 +04:00
|
|
|
NS_IMETHODIMP DocumentViewerImpl::GetCanGetContents(bool *aCanGetContents)
|
2003-04-22 22:11:12 +04:00
|
|
|
{
|
2010-03-19 21:32:13 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(aCanGetContents);
|
2011-10-17 18:59:28 +04:00
|
|
|
*aCanGetContents = false;
|
2010-03-19 21:32:13 +03:00
|
|
|
NS_ENSURE_STATE(mDocument);
|
|
|
|
*aCanGetContents = nsCopySupport::CanCopy(mDocument);
|
|
|
|
return NS_OK;
|
2003-04-22 22:11:12 +04:00
|
|
|
}
|
|
|
|
|
2002-04-11 04:33:24 +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
|
2011-09-29 10:19:26 +04:00
|
|
|
DocumentViewerImpl::Print(bool aSilent,
|
2002-08-21 16:01:05 +04:00
|
|
|
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);
|
2011-10-17 18:59:28 +04:00
|
|
|
if (printSettings) printSettings->SetShowPrintProgress(false);
|
2002-08-21 16:01:05 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
return Print(printSettings, nsnull);
|
|
|
|
#else
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
#endif
|
2001-04-12 17:04:29 +04:00
|
|
|
}
|
|
|
|
|
2011-07-15 14:31:34 +04:00
|
|
|
/* [noscript] void printWithParent (in nsIDOMWindow aParentWin, in nsIPrintSettings aThePrintSettings, in nsIWebProgressListener aWPListener); */
|
2002-10-03 14:48:59 +04:00
|
|
|
NS_IMETHODIMP
|
2011-07-15 14:31:34 +04:00
|
|
|
DocumentViewerImpl::PrintWithParent(nsIDOMWindow*, nsIPrintSettings *aThePrintSettings, nsIWebProgressListener *aWPListener)
|
2002-10-03 14:48:59 +04:00
|
|
|
{
|
2005-09-16 06:25:37 +04:00
|
|
|
#ifdef NS_PRINTING
|
2002-10-03 14:48:59 +04:00
|
|
|
return Print(aThePrintSettings, aWPListener);
|
2005-09-16 06:25:37 +04:00
|
|
|
#else
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
#endif
|
2002-10-03 14:48:59 +04:00
|
|
|
}
|
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
// nsIContentViewerFile interface
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
DocumentViewerImpl::GetPrintable(bool *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
|
|
|
//*****************************************************************************
|
|
|
|
// 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
|
|
|
{
|
2012-03-20 06:09:50 +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);
|
|
|
|
|
|
|
|
// Get the nsIContent interface, because that's what we need to
|
|
|
|
// get the primary frame
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> content(do_QueryInterface(aNode));
|
|
|
|
NS_ENSURE_TRUE(content, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
// Tell the PresShell to scroll to the primary frame of the content.
|
|
|
|
NS_ENSURE_SUCCESS(
|
|
|
|
presShell->ScrollContentIntoView(content,
|
|
|
|
nsIPresShell::ScrollAxis(
|
|
|
|
nsIPresShell::SCROLL_TOP,
|
|
|
|
nsIPresShell::SCROLL_ALWAYS),
|
|
|
|
nsIPresShell::ScrollAxis(),
|
|
|
|
nsIPresShell::SCROLL_OVERFLOW_HIDDEN),
|
|
|
|
NS_ERROR_FAILURE);
|
|
|
|
return NS_OK;
|
2001-04-12 17:04:29 +04:00
|
|
|
}
|
|
|
|
|
2004-12-01 06:28:44 +03:00
|
|
|
void
|
2002-08-21 16:01:05 +04:00
|
|
|
DocumentViewerImpl::CallChildren(CallChildFunc aFunc, void* aClosure)
|
2001-04-12 17:04:29 +04:00
|
|
|
{
|
2005-05-15 04:30:02 +04:00
|
|
|
nsCOMPtr<nsIDocShellTreeNode> docShellNode(do_QueryReferent(mContainer));
|
2002-08-21 16:01:05 +04:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2007-08-08 00:38:35 +04:00
|
|
|
struct ZoomInfo
|
2002-08-21 16:01:05 +04:00
|
|
|
{
|
2007-08-08 00:38:35 +04:00
|
|
|
float mZoom;
|
2002-08-21 16:01:05 +04:00
|
|
|
};
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
static void
|
|
|
|
SetChildTextZoom(nsIMarkupDocumentViewer* aChild, void* aClosure)
|
|
|
|
{
|
2007-08-08 00:38:35 +04:00
|
|
|
struct ZoomInfo* ZoomInfo = (struct ZoomInfo*) aClosure;
|
|
|
|
aChild->SetTextZoom(ZoomInfo->mZoom);
|
|
|
|
}
|
|
|
|
|
2011-03-11 07:33:43 +03:00
|
|
|
static void
|
|
|
|
SetChildMinFontSize(nsIMarkupDocumentViewer* aChild, void* aClosure)
|
|
|
|
{
|
2011-05-30 20:36:23 +04:00
|
|
|
nsCOMPtr<nsIMarkupDocumentViewer> branch =
|
2011-03-11 07:33:43 +03:00
|
|
|
do_QueryInterface(aChild);
|
2011-04-23 10:48:50 +04:00
|
|
|
branch->SetMinFontSize(NS_PTR_TO_INT32(aClosure));
|
2011-03-11 07:33:43 +03:00
|
|
|
}
|
|
|
|
|
2007-08-08 00:38:35 +04:00
|
|
|
static void
|
|
|
|
SetChildFullZoom(nsIMarkupDocumentViewer* aChild, void* aClosure)
|
|
|
|
{
|
|
|
|
struct ZoomInfo* ZoomInfo = (struct ZoomInfo*) aClosure;
|
|
|
|
aChild->SetFullZoom(ZoomInfo->mZoom);
|
2002-08-21 16:01:05 +04:00
|
|
|
}
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool
|
2008-10-05 00:00:09 +04:00
|
|
|
SetExtResourceTextZoom(nsIDocument* aDocument, void* aClosure)
|
|
|
|
{
|
|
|
|
// Would it be better to enumerate external resource viewers instead?
|
2010-06-25 17:59:57 +04:00
|
|
|
nsIPresShell* shell = aDocument->GetShell();
|
2008-10-05 00:00:09 +04:00
|
|
|
if (shell) {
|
|
|
|
nsPresContext* ctxt = shell->GetPresContext();
|
|
|
|
if (ctxt) {
|
|
|
|
struct ZoomInfo* ZoomInfo = static_cast<struct ZoomInfo*>(aClosure);
|
|
|
|
ctxt->SetTextZoom(ZoomInfo->mZoom);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2008-10-05 00:00:09 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool
|
2011-03-11 07:33:43 +03:00
|
|
|
SetExtResourceMinFontSize(nsIDocument* aDocument, void* aClosure)
|
|
|
|
{
|
|
|
|
nsIPresShell* shell = aDocument->GetShell();
|
|
|
|
if (shell) {
|
|
|
|
nsPresContext* ctxt = shell->GetPresContext();
|
|
|
|
if (ctxt) {
|
2011-04-23 10:48:50 +04:00
|
|
|
ctxt->SetMinFontSize(NS_PTR_TO_INT32(aClosure));
|
2011-03-11 07:33:43 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2011-03-11 07:33:43 +03:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool
|
2008-10-05 00:00:09 +04:00
|
|
|
SetExtResourceFullZoom(nsIDocument* aDocument, void* aClosure)
|
|
|
|
{
|
|
|
|
// Would it be better to enumerate external resource viewers instead?
|
2010-06-25 17:59:57 +04:00
|
|
|
nsIPresShell* shell = aDocument->GetShell();
|
2008-10-05 00:00:09 +04:00
|
|
|
if (shell) {
|
|
|
|
nsPresContext* ctxt = shell->GetPresContext();
|
|
|
|
if (ctxt) {
|
|
|
|
struct ZoomInfo* ZoomInfo = static_cast<struct ZoomInfo*>(aClosure);
|
|
|
|
ctxt->SetFullZoom(ZoomInfo->mZoom);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2008-10-05 00:00:09 +04:00
|
|
|
}
|
|
|
|
|
2004-04-30 03:34:19 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
DocumentViewerImpl::SetTextZoom(float aTextZoom)
|
2002-08-21 16:01:05 +04:00
|
|
|
{
|
2009-03-08 22:01:02 +03:00
|
|
|
if (GetIsPrintPreview()) {
|
|
|
|
return NS_OK;
|
2007-11-09 13:19:12 +03:00
|
|
|
}
|
2008-01-27 02:59:50 +03:00
|
|
|
|
2009-03-08 22:01:02 +03:00
|
|
|
mTextZoom = aTextZoom;
|
|
|
|
|
2004-12-01 06:28:44 +03:00
|
|
|
// 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).
|
|
|
|
// Do this first, in case kids are auto-sizing and post reflow commands on
|
|
|
|
// our presshell (which should be subsumed into our own style change reflow).
|
2007-08-08 00:38:35 +04:00
|
|
|
struct ZoomInfo ZoomInfo = { aTextZoom };
|
|
|
|
CallChildren(SetChildTextZoom, &ZoomInfo);
|
2004-12-01 06:28:44 +03:00
|
|
|
|
|
|
|
// Now change our own zoom
|
2007-11-09 13:19:12 +03:00
|
|
|
nsPresContext* pc = GetPresContext();
|
|
|
|
if (pc && aTextZoom != mPresContext->TextZoom()) {
|
|
|
|
pc->SetTextZoom(aTextZoom);
|
2002-08-21 16:01:05 +04:00
|
|
|
}
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2008-10-05 00:00:09 +04:00
|
|
|
// And do the external resources
|
|
|
|
mDocument->EnumerateExternalResources(SetExtResourceTextZoom, &ZoomInfo);
|
|
|
|
|
2004-12-01 06:28:44 +03:00
|
|
|
return NS_OK;
|
2001-04-12 17:04:29 +04:00
|
|
|
}
|
|
|
|
|
2004-04-30 03:34:19 +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);
|
2007-11-09 13:19:12 +03:00
|
|
|
nsPresContext* pc = GetPresContext();
|
|
|
|
*aTextZoom = pc ? pc->TextZoom() : 1.0f;
|
2007-07-26 07:34:16 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-03-11 07:33:43 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
DocumentViewerImpl::SetMinFontSize(PRInt32 aMinFontSize)
|
|
|
|
{
|
|
|
|
if (GetIsPrintPreview()) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
mMinFontSize = aMinFontSize;
|
|
|
|
|
|
|
|
// Set the min font on all children of mContainer (even if our min font didn't
|
|
|
|
// change, our children's min font may be different, though it would be unusual).
|
|
|
|
// Do this first, in case kids are auto-sizing and post reflow commands on
|
|
|
|
// our presshell (which should be subsumed into our own style change reflow).
|
2011-04-23 10:48:50 +04:00
|
|
|
CallChildren(SetChildMinFontSize, NS_INT32_TO_PTR(aMinFontSize));
|
2011-03-11 07:33:43 +03:00
|
|
|
|
|
|
|
// Now change our own min font
|
|
|
|
nsPresContext* pc = GetPresContext();
|
2012-01-26 03:52:26 +04:00
|
|
|
if (pc && aMinFontSize != mPresContext->MinFontSize(nsnull)) {
|
2011-03-11 07:33:43 +03:00
|
|
|
pc->SetMinFontSize(aMinFontSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
// And do the external resources
|
2011-04-23 10:48:50 +04:00
|
|
|
mDocument->EnumerateExternalResources(SetExtResourceMinFontSize,
|
|
|
|
NS_INT32_TO_PTR(aMinFontSize));
|
2011-03-11 07:33:43 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
DocumentViewerImpl::GetMinFontSize(PRInt32* aMinFontSize)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aMinFontSize);
|
|
|
|
nsPresContext* pc = GetPresContext();
|
2012-01-26 03:52:26 +04:00
|
|
|
*aMinFontSize = pc ? pc->MinFontSize(nsnull) : 0;
|
2011-03-11 07:33:43 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-07-26 07:34:16 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
DocumentViewerImpl::SetFullZoom(float aFullZoom)
|
|
|
|
{
|
2009-03-08 22:01:02 +03:00
|
|
|
#ifdef NS_PRINT_PREVIEW
|
|
|
|
if (GetIsPrintPreview()) {
|
|
|
|
nsPresContext* pc = GetPresContext();
|
|
|
|
NS_ENSURE_TRUE(pc, NS_OK);
|
|
|
|
nsCOMPtr<nsIPresShell> shell = pc->GetPresShell();
|
|
|
|
NS_ENSURE_TRUE(shell, NS_OK);
|
|
|
|
|
|
|
|
if (!mPrintPreviewZoomed) {
|
|
|
|
mOriginalPrintPreviewScale = pc->GetPrintPreviewScale();
|
2011-10-17 18:59:28 +04:00
|
|
|
mPrintPreviewZoomed = true;
|
2009-03-08 22:01:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
mPrintPreviewZoom = aFullZoom;
|
|
|
|
pc->SetPrintPreviewScale(aFullZoom * mOriginalPrintPreviewScale);
|
2010-03-21 00:54:19 +03:00
|
|
|
nsIPageSequenceFrame* pf = shell->GetPageSequenceFrame();
|
2009-03-08 22:01:02 +03:00
|
|
|
if (pf) {
|
|
|
|
nsIFrame* f = do_QueryFrame(pf);
|
|
|
|
shell->FrameNeedsReflow(f, nsIPresShell::eResize, NS_FRAME_IS_DIRTY);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame* rootFrame = shell->GetRootFrame();
|
|
|
|
if (rootFrame) {
|
|
|
|
nsRect rect(nsPoint(0, 0), rootFrame->GetSize());
|
|
|
|
rootFrame->Invalidate(rect);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
2007-11-09 13:19:12 +03:00
|
|
|
}
|
2009-03-08 22:01:02 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
mPageZoom = aFullZoom;
|
2007-11-09 13:19:12 +03:00
|
|
|
|
2007-08-08 00:38:35 +04:00
|
|
|
struct ZoomInfo ZoomInfo = { aFullZoom };
|
|
|
|
CallChildren(SetChildFullZoom, &ZoomInfo);
|
2007-11-09 13:19:12 +03:00
|
|
|
|
|
|
|
nsPresContext* pc = GetPresContext();
|
|
|
|
if (pc) {
|
|
|
|
pc->SetFullZoom(aFullZoom);
|
|
|
|
}
|
|
|
|
|
2008-10-05 00:00:09 +04:00
|
|
|
// And do the external resources
|
|
|
|
mDocument->EnumerateExternalResources(SetExtResourceFullZoom, &ZoomInfo);
|
|
|
|
|
2007-07-26 07:34:16 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
DocumentViewerImpl::GetFullZoom(float* aFullZoom)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aFullZoom);
|
2009-03-08 22:01:02 +03:00
|
|
|
#ifdef NS_PRINT_PREVIEW
|
|
|
|
if (GetIsPrintPreview()) {
|
|
|
|
*aFullZoom = mPrintPreviewZoom;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
#endif
|
2008-05-27 02:03:11 +04:00
|
|
|
// Check the prescontext first because it might have a temporary
|
|
|
|
// setting for print-preview
|
2007-11-09 13:19:12 +03:00
|
|
|
nsPresContext* pc = GetPresContext();
|
2008-05-27 02:03:11 +04:00
|
|
|
*aFullZoom = pc ? pc->GetFullZoom() : mPageZoom;
|
2007-07-26 07:34:16 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2004-08-05 15:38:42 +04:00
|
|
|
static void
|
|
|
|
SetChildAuthorStyleDisabled(nsIMarkupDocumentViewer* aChild, void* aClosure)
|
|
|
|
{
|
2011-09-29 10:19:26 +04:00
|
|
|
bool styleDisabled = *static_cast<bool*>(aClosure);
|
2004-08-05 15:38:42 +04:00
|
|
|
aChild->SetAuthorStyleDisabled(styleDisabled);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
DocumentViewerImpl::SetAuthorStyleDisabled(bool aStyleDisabled)
|
2004-08-05 15:38:42 +04:00
|
|
|
{
|
|
|
|
if (mPresShell) {
|
2004-08-29 07:08:44 +04:00
|
|
|
mPresShell->SetAuthorStyleDisabled(aStyleDisabled);
|
2004-08-05 15:38:42 +04:00
|
|
|
}
|
2004-12-01 06:28:44 +03:00
|
|
|
CallChildren(SetChildAuthorStyleDisabled, &aStyleDisabled);
|
|
|
|
return NS_OK;
|
2004-08-05 15:38:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
DocumentViewerImpl::GetAuthorStyleDisabled(bool* aStyleDisabled)
|
2004-08-05 15:38:42 +04:00
|
|
|
{
|
|
|
|
if (mPresShell) {
|
2004-08-29 07:08:44 +04:00
|
|
|
*aStyleDisabled = mPresShell->GetAuthorStyleDisabled();
|
|
|
|
} else {
|
2011-10-17 18:59:28 +04:00
|
|
|
*aStyleDisabled = false;
|
2004-08-05 15:38:42 +04:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2004-04-30 03:34:19 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
DocumentViewerImpl::GetDefaultCharacterSet(nsACString& aDefaultCharacterSet)
|
2002-08-21 16:01:05 +04:00
|
|
|
{
|
|
|
|
if (mDefaultCharacterSet.IsEmpty())
|
|
|
|
{
|
2011-05-28 11:03:00 +04:00
|
|
|
const nsAdoptingCString& defCharset =
|
|
|
|
Preferences::GetLocalizedCString("intl.charset.default");
|
2001-04-13 16:32:18 +04:00
|
|
|
|
2011-05-28 11:03:00 +04:00
|
|
|
if (!defCharset.IsEmpty()) {
|
|
|
|
mDefaultCharacterSet = defCharset;
|
|
|
|
} else {
|
2004-06-17 04:13:25 +04:00
|
|
|
mDefaultCharacterSet.AssignLiteral("ISO-8859-1");
|
2011-05-28 11:03:00 +04:00
|
|
|
}
|
2001-04-12 17:04:29 +04:00
|
|
|
}
|
2003-06-17 20:40:34 +04:00
|
|
|
aDefaultCharacterSet = mDefaultCharacterSet;
|
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
|
|
|
static void
|
|
|
|
SetChildDefaultCharacterSet(nsIMarkupDocumentViewer* aChild, void* aClosure)
|
2001-04-12 17:04:29 +04:00
|
|
|
{
|
2007-07-08 11:08:04 +04:00
|
|
|
const nsACString* charset = static_cast<nsACString*>(aClosure);
|
2003-06-17 20:40:34 +04:00
|
|
|
aChild->SetDefaultCharacterSet(*charset);
|
2002-08-21 16:01:05 +04:00
|
|
|
}
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2003-06-17 20:40:34 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
DocumentViewerImpl::SetDefaultCharacterSet(const nsACString& aDefaultCharacterSet)
|
2002-08-21 16:01:05 +04:00
|
|
|
{
|
|
|
|
mDefaultCharacterSet = aDefaultCharacterSet; // this does a copy of aDefaultCharacterSet
|
|
|
|
// now set the default char set on all children of mContainer
|
2004-12-01 06:28:44 +03:00
|
|
|
CallChildren(SetChildDefaultCharacterSet, (void*) &aDefaultCharacterSet);
|
|
|
|
return NS_OK;
|
2002-08-21 16:01:05 +04:00
|
|
|
}
|
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)
|
2003-06-17 20:40:34 +04:00
|
|
|
NS_IMETHODIMP DocumentViewerImpl::GetForceCharacterSet(nsACString& aForceCharacterSet)
|
2002-08-21 16:01:05 +04:00
|
|
|
{
|
2003-06-17 20:40:34 +04:00
|
|
|
aForceCharacterSet = 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
|
|
|
{
|
2007-07-08 11:08:04 +04:00
|
|
|
const nsACString* charset = static_cast<nsACString*>(aClosure);
|
2003-06-17 20:40:34 +04:00
|
|
|
aChild->SetForceCharacterSet(*charset);
|
2002-08-21 16:01:05 +04:00
|
|
|
}
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2003-06-17 20:40:34 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
DocumentViewerImpl::SetForceCharacterSet(const nsACString& aForceCharacterSet)
|
2002-08-21 16:01:05 +04:00
|
|
|
{
|
|
|
|
mForceCharacterSet = aForceCharacterSet;
|
|
|
|
// now set the force char set on all children of mContainer
|
2004-12-01 06:28:44 +03:00
|
|
|
CallChildren(SetChildForceCharacterSet, (void*) &aForceCharacterSet);
|
|
|
|
return NS_OK;
|
2002-08-21 16:01:05 +04:00
|
|
|
}
|
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)
|
2003-06-17 20:40:34 +04:00
|
|
|
NS_IMETHODIMP DocumentViewerImpl::GetHintCharacterSet(nsACString& aHintCharacterSet)
|
2002-08-21 16:01:05 +04:00
|
|
|
{
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
if(kCharsetUninitialized == mHintCharsetSource) {
|
2003-06-17 20:40:34 +04:00
|
|
|
aHintCharacterSet.Truncate();
|
2001-04-12 17:04:29 +04:00
|
|
|
} else {
|
2003-06-17 20:40:34 +04:00
|
|
|
aHintCharacterSet = mHintCharset;
|
2002-08-21 16:01:05 +04:00
|
|
|
// 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
|
|
|
|
2003-06-17 20:40:34 +04:00
|
|
|
NS_IMETHODIMP DocumentViewerImpl::GetPrevDocCharacterSet(nsACString& aPrevDocCharacterSet)
|
2002-08-27 00:13:31 +04:00
|
|
|
{
|
2003-06-17 20:40:34 +04:00
|
|
|
aPrevDocCharacterSet = mPrevDocCharacterSet;
|
2002-08-27 00:13:31 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
SetChildPrevDocCharacterSet(nsIMarkupDocumentViewer* aChild, void* aClosure)
|
|
|
|
{
|
2007-07-08 11:08:04 +04:00
|
|
|
const nsACString* charset = static_cast<nsACString*>(aClosure);
|
2003-06-17 20:40:34 +04:00
|
|
|
aChild->SetPrevDocCharacterSet(*charset);
|
2002-08-27 00:13:31 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-06-17 20:40:34 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
DocumentViewerImpl::SetPrevDocCharacterSet(const nsACString& aPrevDocCharacterSet)
|
2002-08-27 00:13:31 +04:00
|
|
|
{
|
|
|
|
mPrevDocCharacterSet = aPrevDocCharacterSet;
|
2004-12-01 06:28:44 +03:00
|
|
|
CallChildren(SetChildPrevDocCharacterSet, (void*) &aPrevDocCharacterSet);
|
|
|
|
return NS_OK;
|
2002-08-27 00:13:31 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
|
2003-06-17 20:40:34 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
DocumentViewerImpl::SetHintCharacterSetSource(PRInt32 aHintCharacterSetSource)
|
2002-08-21 16:01:05 +04:00
|
|
|
{
|
|
|
|
mHintCharsetSource = aHintCharacterSetSource;
|
|
|
|
// now set the hint char set source on all children of mContainer
|
2004-12-01 06:28:44 +03:00
|
|
|
CallChildren(SetChildHintCharacterSetSource,
|
2011-04-23 10:48:50 +04:00
|
|
|
NS_INT32_TO_PTR(aHintCharacterSetSource));
|
2004-12-01 06:28:44 +03:00
|
|
|
return NS_OK;
|
2002-08-21 16:01:05 +04:00
|
|
|
}
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
static void
|
|
|
|
SetChildHintCharacterSet(nsIMarkupDocumentViewer* aChild, void* aClosure)
|
|
|
|
{
|
2007-07-08 11:08:04 +04:00
|
|
|
const nsACString* charset = static_cast<nsACString*>(aClosure);
|
2003-06-17 20:40:34 +04:00
|
|
|
aChild->SetHintCharacterSet(*charset);
|
2002-08-21 16:01:05 +04:00
|
|
|
}
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2003-06-17 20:40:34 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
DocumentViewerImpl::SetHintCharacterSet(const nsACString& aHintCharacterSet)
|
2002-08-21 16:01:05 +04:00
|
|
|
{
|
|
|
|
mHintCharset = aHintCharacterSet;
|
|
|
|
// now set the hint char set on all children of mContainer
|
2004-12-01 06:28:44 +03:00
|
|
|
CallChildren(SetChildHintCharacterSet, (void*) &aHintCharacterSet);
|
|
|
|
return NS_OK;
|
2002-08-21 16:01:05 +04:00
|
|
|
}
|
2001-12-01 17:31:45 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
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
|
|
|
NS_IMETHODIMP DocumentViewerImpl::SetBidiTextDirection(PRUint8 aTextDirection)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
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
|
|
|
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)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
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
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
NS_IMETHODIMP DocumentViewerImpl::SetBidiNumeral(PRUint8 aNumeral)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
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
|
|
|
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)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
PRUint32 bidiOptions;
|
|
|
|
|
|
|
|
if (aSupport) {
|
|
|
|
GetBidiOptions(&bidiOptions);
|
|
|
|
*aSupport = GET_BIDI_OPTION_SUPPORT(bidiOptions);
|
2011-04-24 22:19:05 +04:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
NS_IMETHODIMP DocumentViewerImpl::SetBidiOptions(PRUint32 aBidiOptions)
|
|
|
|
{
|
|
|
|
if (mPresContext) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mPresContext->SetBidi(aBidiOptions, true); // could cause reflow
|
2001-04-12 17:04:29 +04:00
|
|
|
}
|
2002-08-21 16:01:05 +04:00
|
|
|
// now set bidi on all children of mContainer
|
2011-04-23 10:48:50 +04:00
|
|
|
CallChildren(SetChildBidiOptions, NS_INT32_TO_PTR(aBidiOptions));
|
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::GetBidiOptions(PRUint32* aBidiOptions)
|
|
|
|
{
|
|
|
|
if (aBidiOptions) {
|
|
|
|
if (mPresContext) {
|
2004-07-29 23:41:39 +04:00
|
|
|
*aBidiOptions = mPresContext->GetBidi();
|
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
|
|
|
return NS_OK;
|
2001-04-12 17:04:29 +04:00
|
|
|
}
|
|
|
|
|
2012-05-05 17:25:45 +04:00
|
|
|
static void
|
|
|
|
AppendChildSubtree(nsIMarkupDocumentViewer* aChild, void* aClosure)
|
|
|
|
{
|
|
|
|
nsTArray<nsCOMPtr<nsIMarkupDocumentViewer> >& array =
|
|
|
|
*static_cast<nsTArray<nsCOMPtr<nsIMarkupDocumentViewer> >*>(aClosure);
|
|
|
|
aChild->AppendSubtree(array);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP DocumentViewerImpl::AppendSubtree(nsTArray<nsCOMPtr<nsIMarkupDocumentViewer> >& aArray)
|
|
|
|
{
|
|
|
|
aArray.AppendElement(this);
|
|
|
|
CallChildren(AppendChildSubtree, &aArray);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2008-09-28 23:14:28 +04:00
|
|
|
// Skip doing this on docshell-less documents for now
|
2005-05-15 04:30:02 +04:00
|
|
|
nsCOMPtr<nsIDocShellTreeItem> docShellAsItem(do_QueryReferent(mContainer));
|
2008-09-28 23:14:28 +04:00
|
|
|
NS_ENSURE_TRUE(docShellAsItem, NS_ERROR_NOT_AVAILABLE);
|
|
|
|
|
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;
|
2003-06-14 00:10:01 +04:00
|
|
|
GetPresShell(getter_AddRefs(presShell));
|
2002-08-21 16:01:05 +04:00
|
|
|
NS_ENSURE_TRUE(presShell, NS_ERROR_FAILURE);
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2005-01-15 21:01:22 +03:00
|
|
|
// Flush out all content and style updates. We can't use a resize reflow
|
|
|
|
// because it won't change some sizes that a style change reflow will.
|
|
|
|
mDocument->FlushPendingNotifications(Flush_Layout);
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
|
|
|
nsIFrame *root = presShell->GetRootFrame();
|
|
|
|
NS_ENSURE_TRUE(root, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
nscoord prefWidth;
|
|
|
|
{
|
2011-04-08 05:04:40 +04:00
|
|
|
nsRefPtr<nsRenderingContext> rcx =
|
2010-08-20 23:29:01 +04:00
|
|
|
presShell->GetReferenceRenderingContext();
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
NS_ENSURE_TRUE(rcx, NS_ERROR_FAILURE);
|
|
|
|
prefWidth = root->GetPrefWidth(rcx);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv = presShell->ResizeReflow(prefWidth, NS_UNCONSTRAINEDSIZE);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2010-03-25 16:17:11 +03:00
|
|
|
nsRefPtr<nsPresContext> presContext;
|
2003-06-14 00:10:01 +04:00
|
|
|
GetPresContext(getter_AddRefs(presContext));
|
2002-08-21 16:01:05 +04:00
|
|
|
NS_ENSURE_TRUE(presContext, NS_ERROR_FAILURE);
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
PRInt32 width, height;
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
// so how big is it?
|
2004-02-01 13:09:07 +03:00
|
|
|
nsRect shellArea = presContext->GetVisibleArea();
|
2008-03-13 01:04:45 +03:00
|
|
|
// Protect against bogus returns here
|
|
|
|
NS_ENSURE_TRUE(shellArea.width != NS_UNCONSTRAINEDSIZE &&
|
|
|
|
shellArea.height != NS_UNCONSTRAINEDSIZE,
|
|
|
|
NS_ERROR_FAILURE);
|
2011-10-25 22:45:23 +04:00
|
|
|
width = presContext->AppUnitsToDevPixels(shellArea.width);
|
2007-02-07 10:46:44 +03:00
|
|
|
height = presContext->AppUnitsToDevPixels(shellArea.height);
|
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
|
|
|
|
2011-10-25 22:45:23 +04:00
|
|
|
/* presContext's size was calculated in app units 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),
|
2002-08-21 16:01:05 +04:00
|
|
|
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
|
|
|
|
2003-09-08 01:50:21 +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
|
|
|
|
2010-08-11 00:55:31 +04:00
|
|
|
*aNode = nsnull;
|
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
// get the document
|
2010-01-23 14:41:41 +03:00
|
|
|
nsIDocument* document = GetDocument();
|
2002-08-21 16:01:05 +04:00
|
|
|
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 private dom window
|
2010-02-20 19:07:03 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindow> window(document->GetWindow());
|
|
|
|
NS_ENSURE_TRUE(window, NS_ERROR_NOT_AVAILABLE);
|
|
|
|
if (window) {
|
|
|
|
nsCOMPtr<nsPIWindowRoot> root = window->GetTopWindowRoot();
|
|
|
|
NS_ENSURE_TRUE(root, NS_ERROR_FAILURE);
|
2002-08-21 16:01:05 +04:00
|
|
|
|
2010-02-20 19:07:03 +03:00
|
|
|
// get the popup node
|
2010-08-11 00:55:31 +04:00
|
|
|
nsCOMPtr<nsIDOMNode> node = root->GetPopupNode();
|
|
|
|
#ifdef MOZ_XUL
|
|
|
|
if (!node) {
|
|
|
|
nsPIDOMWindow* rootWindow = root->GetWindow();
|
|
|
|
if (rootWindow) {
|
|
|
|
nsCOMPtr<nsIDocument> rootDoc = do_QueryInterface(rootWindow->GetExtantDocument());
|
|
|
|
if (rootDoc) {
|
|
|
|
nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
|
|
|
|
if (pm) {
|
|
|
|
node = pm->GetLastTriggerPopupNode(rootDoc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
node.swap(*aNode);
|
2010-02-20 19:07:03 +03:00
|
|
|
}
|
2002-08-21 16:01:05 +04:00
|
|
|
|
2010-01-23 14:41:41 +03:00
|
|
|
return NS_OK;
|
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
|
|
|
|
2011-06-24 16:54:28 +04:00
|
|
|
nsCOMPtr<nsIContent> content(do_QueryInterface(node));
|
|
|
|
if (content) {
|
|
|
|
nsCOMPtr<nsIURI> hrefURI = content->GetHrefURI();
|
|
|
|
if (hrefURI) {
|
|
|
|
*aNode = node;
|
|
|
|
NS_IF_ADDREF(*aNode); // addref
|
|
|
|
return NS_OK;
|
2002-02-19 14:49:27 +03:00
|
|
|
}
|
|
|
|
}
|
2011-06-24 16:54:28 +04:00
|
|
|
|
|
|
|
// 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
|
2004-06-05 21:57:00 +04:00
|
|
|
DocumentViewerImpl::GetPopupImageNode(nsIImageLoadingContent** 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
|
|
|
|
2005-06-01 20:26:51 +04:00
|
|
|
if (node)
|
|
|
|
CallQueryInterface(node, aNode);
|
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
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
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
NS_IMETHODIMP DocumentViewerImpl::GetInLink(bool* aInLink)
|
2002-08-21 16:01:05 +04:00
|
|
|
{
|
|
|
|
#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
|
2011-10-17 18:59:28 +04:00
|
|
|
*aInLink = 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
|
2011-10-17 18:59:28 +04:00
|
|
|
*aInLink = true;
|
2002-08-21 16:01:05 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2002-06-20 01:51:13 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
NS_IMETHODIMP DocumentViewerImpl::GetInImage(bool* aInImage)
|
2002-08-21 16:01:05 +04:00
|
|
|
{
|
|
|
|
#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
|
2011-10-17 18:59:28 +04:00
|
|
|
*aInImage = false;
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
// get the popup image
|
2004-06-05 21:57:00 +04:00
|
|
|
nsCOMPtr<nsIImageLoadingContent> node;
|
2002-08-21 16:01:05 +04:00
|
|
|
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
|
2011-10-17 18:59:28 +04:00
|
|
|
*aInImage = true;
|
2002-08-21 16:01:05 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2002-07-09 16:39:02 +04:00
|
|
|
|
2005-02-01 02:47:26 +03:00
|
|
|
NS_IMETHODIMP nsDocViewerSelectionListener::NotifySelectionChanged(nsIDOMDocument *, nsISelection *, PRInt16)
|
2002-08-21 16:01:05 +04:00
|
|
|
{
|
|
|
|
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
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool selectionCollapsed;
|
2002-08-21 16:01:05 +04:00
|
|
|
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)
|
|
|
|
{
|
2010-01-23 14:41:41 +03:00
|
|
|
nsIDocument* theDoc = mDocViewer->GetDocument();
|
2002-08-21 16:01:05 +04:00
|
|
|
if (!theDoc) return NS_ERROR_FAILURE;
|
2002-05-07 16:03:37 +04:00
|
|
|
|
2005-11-29 02:56:44 +03:00
|
|
|
nsPIDOMWindow *domWindow = theDoc->GetWindow();
|
2002-08-21 16:01:05 +04:00
|
|
|
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"));
|
2011-10-17 18:59:28 +04:00
|
|
|
mGotSelectionState = true;
|
2002-08-21 16:01:05 +04:00
|
|
|
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
|
2011-06-28 21:59:14 +04:00
|
|
|
NS_IMPL_ISUPPORTS1(nsDocViewerFocusListener,
|
2005-12-03 10:42:40 +03:00
|
|
|
nsIDOMEventListener)
|
2002-05-07 16:03:37 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
nsDocViewerFocusListener::nsDocViewerFocusListener()
|
|
|
|
:mDocViewer(nsnull)
|
|
|
|
{
|
|
|
|
}
|
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)
|
|
|
|
{
|
2011-06-28 21:59:14 +04:00
|
|
|
NS_ENSURE_STATE(mDocViewer);
|
2001-03-27 15:56:03 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
nsCOMPtr<nsIPresShell> shell;
|
2011-09-26 08:53:30 +04:00
|
|
|
mDocViewer->GetPresShell(getter_AddRefs(shell));
|
2011-06-28 21:59:14 +04:00
|
|
|
NS_ENSURE_TRUE(shell, NS_ERROR_FAILURE);
|
2002-08-21 16:01:05 +04:00
|
|
|
|
2011-06-28 21:59:14 +04:00
|
|
|
nsCOMPtr<nsISelectionController> selCon = do_QueryInterface(shell);
|
2002-08-21 16:01:05 +04:00
|
|
|
PRInt16 selectionStatus;
|
|
|
|
selCon->GetDisplaySelection(&selectionStatus);
|
2001-02-01 23:49:10 +03:00
|
|
|
|
2011-06-28 21:59:14 +04:00
|
|
|
nsAutoString eventType;
|
|
|
|
aEvent->GetType(eventType);
|
|
|
|
if (eventType.EqualsLiteral("focus")) {
|
|
|
|
// If selection was disabled, re-enable it.
|
|
|
|
if(selectionStatus == nsISelectionController::SELECTION_DISABLED ||
|
|
|
|
selectionStatus == nsISelectionController::SELECTION_HIDDEN) {
|
|
|
|
selCon->SetDisplaySelection(nsISelectionController::SELECTION_ON);
|
|
|
|
selCon->RepaintSelection(nsISelectionController::SELECTION_NORMAL);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
NS_ABORT_IF_FALSE(eventType.EqualsLiteral("blur"),
|
|
|
|
"Unexpected event type");
|
|
|
|
// If selection was on, disable it.
|
|
|
|
if(selectionStatus == nsISelectionController::SELECTION_ON ||
|
|
|
|
selectionStatus == nsISelectionController::SELECTION_ATTENTION) {
|
|
|
|
selCon->SetDisplaySelection(nsISelectionController::SELECTION_DISABLED);
|
|
|
|
selCon->RepaintSelection(nsISelectionController::SELECTION_NORMAL);
|
|
|
|
}
|
2002-01-01 15:58:53 +03:00
|
|
|
}
|
|
|
|
|
2011-06-28 21:59:14 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
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
|
|
|
|
*/
|
2005-09-16 06:25:37 +04:00
|
|
|
|
|
|
|
#ifdef NS_PRINTING
|
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
DocumentViewerImpl::Print(nsIPrintSettings* aPrintSettings,
|
|
|
|
nsIWebProgressListener* aWebProgressListener)
|
|
|
|
{
|
2002-09-04 03:21:15 +04:00
|
|
|
|
2004-12-25 01:27:57 +03:00
|
|
|
#ifdef MOZ_XUL
|
|
|
|
// Temporary code for Bug 136185 / Bug 240490
|
|
|
|
nsCOMPtr<nsIXULDocument> xulDoc(do_QueryInterface(mDocument));
|
|
|
|
if (xulDoc) {
|
|
|
|
nsPrintEngine::ShowPrintErrorDialog(NS_ERROR_GFX_PRINTER_NO_XUL);
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-01-21 10:54:47 +03:00
|
|
|
if (!mContainer) {
|
|
|
|
PR_PL(("Container was destroyed yet we are still trying to use it!"));
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2005-05-15 04:30:02 +04:00
|
|
|
nsCOMPtr<nsIDocShell> docShell(do_QueryReferent(mContainer));
|
2011-05-10 16:55:26 +04:00
|
|
|
NS_ENSURE_STATE(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;
|
2011-10-17 18:59:28 +04:00
|
|
|
mPrintIsPending = true;
|
2002-08-21 16:01:05 +04:00
|
|
|
}
|
2004-02-20 00:58:40 +03:00
|
|
|
PR_PL(("Printing Stopped - document is still busy!"));
|
|
|
|
return NS_ERROR_GFX_PRINTER_DOC_IS_BUSY;
|
2002-08-21 16:01:05 +04:00
|
|
|
}
|
2000-10-20 01:49:12 +04:00
|
|
|
|
2011-11-18 07:53:06 +04:00
|
|
|
if (!mDocument || !mDeviceContext) {
|
2011-11-20 02:09:25 +04:00
|
|
|
PR_PL(("Can't Print without a document and a device context"));
|
2006-12-31 11:13:56 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
2002-08-21 16:01:05 +04:00
|
|
|
}
|
1999-05-14 18:40:59 +04:00
|
|
|
|
2006-12-31 11:13:56 +03:00
|
|
|
nsresult rv;
|
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
|
|
|
|
2011-05-14 16:03:58 +04:00
|
|
|
nsPrintEventDispatcher beforeAndAfterPrint(mDocument);
|
2011-07-06 15:12:26 +04:00
|
|
|
NS_ENSURE_STATE(!GetIsPrinting());
|
2003-03-22 06:20:23 +03:00
|
|
|
// If we are hosting a full-page plugin, tell it to print
|
|
|
|
// first. It shows its own native print UI.
|
|
|
|
nsCOMPtr<nsIPluginDocument> pDoc(do_QueryInterface(mDocument));
|
|
|
|
if (pDoc)
|
|
|
|
return pDoc->Print();
|
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
if (!mPrintEngine) {
|
2011-07-01 17:59:11 +04:00
|
|
|
NS_ENSURE_STATE(mDeviceContext);
|
2002-08-21 16:01:05 +04:00
|
|
|
mPrintEngine = new nsPrintEngine();
|
2002-04-04 17:04:21 +04:00
|
|
|
|
2011-05-10 16:55:26 +04:00
|
|
|
rv = mPrintEngine->Initialize(this, mContainer, mDocument,
|
2010-08-13 13:58:04 +04:00
|
|
|
float(mDeviceContext->AppUnitsPerCSSInch()) /
|
2009-08-24 13:55:28 +04:00
|
|
|
float(mDeviceContext->AppUnitsPerDevPixel()) /
|
|
|
|
mPageZoom,
|
2002-01-01 15:58:53 +03:00
|
|
|
#ifdef NS_DEBUG
|
2006-12-31 11:13:56 +03:00
|
|
|
mDebugFile
|
2002-08-21 16:01:05 +04:00
|
|
|
#else
|
2006-12-31 11:13:56 +03:00
|
|
|
nsnull
|
2002-01-01 15:58:53 +03:00
|
|
|
#endif
|
2006-12-31 11:13:56 +03:00
|
|
|
);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
mPrintEngine->Destroy();
|
|
|
|
mPrintEngine = nsnull;
|
|
|
|
return rv;
|
|
|
|
}
|
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;
|
|
|
|
}
|
2001-01-27 17:09:34 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
DocumentViewerImpl::PrintPreview(nsIPrintSettings* aPrintSettings,
|
|
|
|
nsIDOMWindow *aChildDOMWin,
|
|
|
|
nsIWebProgressListener* aWebProgressListener)
|
|
|
|
{
|
|
|
|
#if defined(NS_PRINTING) && defined(NS_PRINT_PREVIEW)
|
2009-12-11 07:02:13 +03:00
|
|
|
NS_WARN_IF_FALSE(IsInitializedForPrintPreview(),
|
|
|
|
"Using docshell.printPreview is the preferred way for print previewing!");
|
|
|
|
|
|
|
|
NS_ENSURE_ARG_POINTER(aChildDOMWin);
|
2002-08-21 16:01:05 +04:00
|
|
|
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
|
|
|
|
2004-12-25 01:27:57 +03:00
|
|
|
#ifdef MOZ_XUL
|
|
|
|
// Temporary code for Bug 136185 / Bug 240490
|
|
|
|
nsCOMPtr<nsIXULDocument> xulDoc(do_QueryInterface(mDocument));
|
|
|
|
if (xulDoc) {
|
|
|
|
nsPrintEngine::CloseProgressDialog(aWebProgressListener);
|
2011-10-17 18:59:28 +04:00
|
|
|
nsPrintEngine::ShowPrintErrorDialog(NS_ERROR_GFX_PRINTER_NO_XUL, false);
|
2004-12-25 01:27:57 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2006-12-31 11:13:56 +03:00
|
|
|
nsCOMPtr<nsIDocShell> docShell(do_QueryReferent(mContainer));
|
2010-08-28 03:15:08 +04:00
|
|
|
if (!docShell || !mDeviceContext) {
|
|
|
|
PR_PL(("Can't Print Preview without device context and docshell"));
|
2006-12-31 11:13:56 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2011-05-14 16:03:58 +04:00
|
|
|
nsCOMPtr<nsIDOMDocument> domDoc;
|
|
|
|
aChildDOMWin->GetDocument(getter_AddRefs(domDoc));
|
|
|
|
nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc);
|
|
|
|
NS_ENSURE_STATE(doc);
|
2009-12-11 07:02:13 +03:00
|
|
|
|
2011-05-14 16:03:58 +04:00
|
|
|
nsPrintEventDispatcher beforeAndAfterPrint(doc);
|
2011-07-06 15:12:26 +04:00
|
|
|
NS_ENSURE_STATE(!GetIsPrinting());
|
2011-05-14 16:03:58 +04:00
|
|
|
if (!mPrintEngine) {
|
2002-08-21 16:01:05 +04:00
|
|
|
mPrintEngine = new nsPrintEngine();
|
2002-05-09 00:11:14 +04:00
|
|
|
|
2011-05-10 16:55:26 +04:00
|
|
|
rv = mPrintEngine->Initialize(this, mContainer, doc,
|
2010-08-13 13:58:04 +04:00
|
|
|
float(mDeviceContext->AppUnitsPerCSSInch()) /
|
2009-08-24 13:55:28 +04:00
|
|
|
float(mDeviceContext->AppUnitsPerDevPixel()) /
|
|
|
|
mPageZoom,
|
2002-08-21 16:01:05 +04:00
|
|
|
#ifdef NS_DEBUG
|
2006-12-31 11:13:56 +03:00
|
|
|
mDebugFile
|
2002-08-21 16:01:05 +04:00
|
|
|
#else
|
2006-12-31 11:13:56 +03:00
|
|
|
nsnull
|
2002-08-21 16:01:05 +04:00
|
|
|
#endif
|
2006-12-31 11:13:56 +03:00
|
|
|
);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
mPrintEngine->Destroy();
|
|
|
|
mPrintEngine = nsnull;
|
|
|
|
return rv;
|
|
|
|
}
|
2001-04-12 17:04:29 +04:00
|
|
|
}
|
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
rv = mPrintEngine->PrintPreview(aPrintSettings, aChildDOMWin, aWebProgressListener);
|
2011-10-17 18:59:28 +04:00
|
|
|
mPrintPreviewZoomed = false;
|
2002-08-21 16:01:05 +04:00
|
|
|
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)
|
|
|
|
{
|
2007-01-01 13:53:11 +03:00
|
|
|
if (!GetIsPrintPreview() ||
|
|
|
|
mPrintEngine->GetIsCreatingPrintPreview())
|
|
|
|
return NS_ERROR_FAILURE;
|
2001-02-07 02:03:17 +03:00
|
|
|
|
2009-09-03 08:26:00 +04:00
|
|
|
nsIScrollableFrame* sf =
|
|
|
|
mPrintEngine->GetPrintPreviewPresShell()->GetRootScrollFrameAsScrollable();
|
|
|
|
if (!sf)
|
2007-01-01 13:53:11 +03:00
|
|
|
return NS_OK;
|
2002-08-21 16:01:05 +04:00
|
|
|
|
|
|
|
// Check to see if we can short circut scrolling to the top
|
|
|
|
if (aType == nsIWebBrowserPrint::PRINTPREVIEW_HOME ||
|
|
|
|
(aType == nsIWebBrowserPrint::PRINTPREVIEW_GOTO_PAGENUM && aPageNum == 1)) {
|
2009-09-03 08:26:00 +04:00
|
|
|
sf->ScrollTo(nsPoint(0, 0), nsIScrollableFrame::INSTANT);
|
2002-08-21 16:01:05 +04:00
|
|
|
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
|
2009-09-03 08:26:00 +04:00
|
|
|
nsPoint pt = sf->GetScrollPosition();
|
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
|
2011-08-25 00:54:30 +04:00
|
|
|
nsIFrame* pageFrame = seqFrame->GetFirstPrincipalChild();
|
2002-08-21 16:01:05 +04:00
|
|
|
while (pageFrame != nsnull) {
|
2003-08-06 07:07:12 +04:00
|
|
|
nsRect pageRect = pageFrame->GetRect();
|
2009-09-03 08:26:00 +04:00
|
|
|
if (pageRect.Contains(pageRect.x, pt.y)) {
|
2002-08-21 16:01:05 +04:00
|
|
|
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++;
|
2003-08-06 07:07:12 +04:00
|
|
|
pageFrame = pageFrame->GetNextSibling();
|
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) {
|
2004-09-14 06:28:03 +04:00
|
|
|
fndPageFrame = currentPage->GetPrevInFlow();
|
2002-08-21 16:01:05 +04:00
|
|
|
if (!fndPageFrame) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
} else if (aType == nsIWebBrowserPrint::PRINTPREVIEW_NEXT_PAGE) {
|
|
|
|
if (currentPage) {
|
2004-09-14 06:28:03 +04:00
|
|
|
fndPageFrame = currentPage->GetNextInFlow();
|
2002-08-21 16:01:05 +04:00
|
|
|
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
|
|
|
|
2009-09-03 08:26:00 +04:00
|
|
|
if (fndPageFrame) {
|
2010-08-13 13:58:04 +04:00
|
|
|
nscoord newYPosn =
|
2011-06-10 14:07:26 +04:00
|
|
|
nscoord(mPrintEngine->GetPrintPreviewScale() * fndPageFrame->GetPosition().y);
|
2009-09-03 08:26:00 +04:00
|
|
|
sf->ScrollTo(nsPoint(pt.x, newYPosn), nsIScrollableFrame::INSTANT);
|
2002-08-21 16:01:05 +04:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
|
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
|
|
|
{
|
2006-03-30 04:27:42 +04:00
|
|
|
return nsPrintEngine::GetGlobalPrintSettings(aGlobalPrintSettings);
|
2001-04-18 10:06:31 +04:00
|
|
|
}
|
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
/* readonly attribute boolean doingPrint; */
|
2011-10-17 18:59:28 +04:00
|
|
|
// XXX This always returns false for subdocuments
|
2002-08-21 16:01:05 +04:00
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
DocumentViewerImpl::GetDoingPrint(bool *aDoingPrint)
|
2001-04-18 10:06:31 +04:00
|
|
|
{
|
2002-08-21 16:01:05 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aDoingPrint);
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
*aDoingPrint = false;
|
2002-08-21 16:01:05 +04:00
|
|
|
if (mPrintEngine) {
|
2005-04-07 08:04:06 +04:00
|
|
|
// XXX shouldn't this be GetDoingPrint() ?
|
2002-08-21 16:01:05 +04:00
|
|
|
return mPrintEngine->GetDoingPrintPreview(aDoingPrint);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-04-18 10:06:31 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
/* readonly attribute boolean doingPrintPreview; */
|
2011-10-17 18:59:28 +04:00
|
|
|
// XXX This always returns false for subdocuments
|
2002-08-21 16:01:05 +04:00
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
DocumentViewerImpl::GetDoingPrintPreview(bool *aDoingPrintPreview)
|
2002-08-21 16:01:05 +04:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aDoingPrintPreview);
|
2001-04-18 10:06:31 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
*aDoingPrintPreview = false;
|
2002-08-21 16:01:05 +04:00
|
|
|
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
|
|
|
/* 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
|
|
|
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);
|
2001-04-18 10:06:31 +04:00
|
|
|
}
|
2000-02-16 04:39:30 +03:00
|
|
|
|
2005-09-16 06:25:37 +04: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()
|
|
|
|
{
|
|
|
|
NS_ENSURE_TRUE(mPrintEngine, NS_ERROR_FAILURE);
|
|
|
|
return mPrintEngine->Cancelled();
|
|
|
|
}
|
2000-02-16 04:39:30 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
/* void exitPrintPreview (); */
|
|
|
|
NS_IMETHODIMP
|
|
|
|
DocumentViewerImpl::ExitPrintPreview()
|
|
|
|
{
|
2009-10-16 03:10:27 +04:00
|
|
|
if (GetIsPrinting())
|
|
|
|
return NS_ERROR_FAILURE;
|
2002-08-21 16:01:05 +04:00
|
|
|
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;
|
|
|
|
}
|
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
|
2011-09-29 10:19:26 +04:00
|
|
|
DocumentViewerImpl::GetIsFramesetFrameSelected(bool *aIsFramesetFrameSelected)
|
2000-04-22 01:40:28 +04:00
|
|
|
{
|
2002-08-21 16:01:05 +04:00
|
|
|
#ifdef NS_PRINTING
|
2011-10-17 18:59:28 +04:00
|
|
|
*aIsFramesetFrameSelected = false;
|
2002-08-21 16:01:05 +04:00
|
|
|
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
|
2011-09-29 10:19:26 +04:00
|
|
|
DocumentViewerImpl::GetIsFramesetDocument(bool *aIsFramesetDocument)
|
2000-04-22 01:40:28 +04:00
|
|
|
{
|
2002-08-21 16:01:05 +04:00
|
|
|
#ifdef NS_PRINTING
|
2011-10-17 18:59:28 +04:00
|
|
|
*aIsFramesetDocument = false;
|
2002-08-21 16:01:05 +04:00
|
|
|
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
|
2011-09-29 10:19:26 +04:00
|
|
|
DocumentViewerImpl::GetIsIFrameSelected(bool *aIsIFrameSelected)
|
2002-08-21 16:01:05 +04:00
|
|
|
{
|
|
|
|
#ifdef NS_PRINTING
|
2011-10-17 18:59:28 +04:00
|
|
|
*aIsIFrameSelected = false;
|
2002-08-21 16:01:05 +04:00
|
|
|
NS_ENSURE_TRUE(mPrintEngine, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
return mPrintEngine->GetIsIFrameSelected(aIsIFrameSelected);
|
|
|
|
#else
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/* readonly attribute boolean isRangeSelection; */
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
DocumentViewerImpl::GetIsRangeSelection(bool *aIsRangeSelection)
|
2002-08-21 16:01:05 +04:00
|
|
|
{
|
|
|
|
#ifdef NS_PRINTING
|
2011-10-17 18:59:28 +04:00
|
|
|
*aIsRangeSelection = false;
|
2002-08-21 16:01:05 +04:00
|
|
|
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
|
|
|
|
//----------------------------------------------------------------------------------
|
|
|
|
|
2002-10-08 17:17:56 +04:00
|
|
|
//----------------------------------------------------------------------------------
|
|
|
|
// Walks the document tree and tells each DocShell whether Printing/PP is happening
|
|
|
|
void
|
|
|
|
DocumentViewerImpl::SetIsPrintingInDocShellTree(nsIDocShellTreeNode* aParentNode,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aIsPrintingOrPP,
|
|
|
|
bool aStartAtTop)
|
2002-10-08 17:17:56 +04:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> parentItem(do_QueryInterface(aParentNode));
|
|
|
|
|
|
|
|
// find top of "same parent" tree
|
|
|
|
if (aStartAtTop) {
|
2011-03-24 14:42:54 +03:00
|
|
|
if (aIsPrintingOrPP) {
|
|
|
|
while (parentItem) {
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> parent;
|
|
|
|
parentItem->GetSameTypeParent(getter_AddRefs(parent));
|
|
|
|
if (!parent) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
parentItem = do_QueryInterface(parent);
|
2002-10-08 17:17:56 +04:00
|
|
|
}
|
2011-03-24 14:42:54 +03:00
|
|
|
mTopContainerWhilePrinting = do_GetWeakReference(parentItem);
|
|
|
|
} else {
|
|
|
|
parentItem = do_QueryReferent(mTopContainerWhilePrinting);
|
2002-10-08 17:17:56 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check to see if the DocShell's ContentViewer is printing/PP
|
|
|
|
nsCOMPtr<nsIContentViewerContainer> viewerContainer(do_QueryInterface(parentItem));
|
|
|
|
if (viewerContainer) {
|
|
|
|
viewerContainer->SetIsPrinting(aIsPrintingOrPP);
|
|
|
|
}
|
|
|
|
|
2011-03-24 14:42:54 +03:00
|
|
|
if (!aParentNode) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-10-08 17:17:56 +04:00
|
|
|
// Traverse children to see if any of them are printing.
|
|
|
|
PRInt32 n;
|
|
|
|
aParentNode->GetChildCount(&n);
|
|
|
|
for (PRInt32 i=0; i < n; i++) {
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> child;
|
|
|
|
aParentNode->GetChildAt(i, getter_AddRefs(child));
|
|
|
|
nsCOMPtr<nsIDocShellTreeNode> childAsNode(do_QueryInterface(child));
|
|
|
|
NS_ASSERTION(childAsNode, "child isn't nsIDocShellTreeNode");
|
|
|
|
if (childAsNode) {
|
2011-10-17 18:59:28 +04:00
|
|
|
SetIsPrintingInDocShellTree(childAsNode, aIsPrintingOrPP, false);
|
2002-10-08 17:17:56 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
#endif // NS_PRINTING
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2011-02-09 23:13:18 +03:00
|
|
|
DocumentViewerImpl::ShouldAttachToTopLevel()
|
|
|
|
{
|
|
|
|
if (!mParentWidget)
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2011-02-09 23:13:18 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> containerItem = do_QueryReferent(mContainer);
|
|
|
|
if (!containerItem)
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2011-02-09 23:13:18 +03:00
|
|
|
|
|
|
|
// We always attach when using puppet widgets
|
|
|
|
if (nsIWidget::UsePuppetWidgets())
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2011-02-09 23:13:18 +03:00
|
|
|
|
|
|
|
#ifdef XP_WIN
|
|
|
|
// On windows, in the parent process we also attach, but just to
|
|
|
|
// chrome items
|
|
|
|
PRInt32 docType;
|
|
|
|
nsWindowType winType;
|
|
|
|
containerItem->GetItemType(&docType);
|
|
|
|
mParentWidget->GetWindowType(winType);
|
|
|
|
if ((winType == eWindowType_toplevel ||
|
|
|
|
winType == eWindowType_dialog ||
|
|
|
|
winType == eWindowType_invisible) &&
|
|
|
|
docType == nsIDocShellTreeItem::typeChrome)
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2011-02-09 23:13:18 +03:00
|
|
|
#endif
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2011-02-09 23:13:18 +03:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool CollectDocuments(nsIDocument* aDocument, void* aData)
|
2011-05-14 16:03:58 +04:00
|
|
|
{
|
|
|
|
if (aDocument) {
|
|
|
|
static_cast<nsCOMArray<nsIDocument>*>(aData)->AppendObject(aDocument);
|
|
|
|
aDocument->EnumerateSubDocuments(CollectDocuments, aData);
|
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2011-05-14 16:03:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DocumentViewerImpl::DispatchEventToWindowTree(nsIDocument* aDoc,
|
|
|
|
const nsAString& aEvent)
|
|
|
|
{
|
|
|
|
nsCOMArray<nsIDocument> targets;
|
|
|
|
CollectDocuments(aDoc, &targets);
|
|
|
|
for (PRInt32 i = 0; i < targets.Count(); ++i) {
|
|
|
|
nsIDocument* d = targets[i];
|
|
|
|
nsContentUtils::DispatchTrustedEvent(d, d->GetWindow(),
|
2011-10-17 18:59:28 +04:00
|
|
|
aEvent, false, false, nsnull);
|
2011-05-14 16:03:58 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
//------------------------------------------------------------
|
2011-10-17 18:59:28 +04:00
|
|
|
// XXX this always returns false for subdocuments
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2002-08-21 16:01:05 +04:00
|
|
|
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
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2000-04-22 02:17:14 +04:00
|
|
|
}
|
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
//------------------------------------------------------------
|
2002-10-08 17:17:56 +04:00
|
|
|
// Notification from the PrintEngine of the current Printing status
|
2002-08-21 16:01:05 +04:00
|
|
|
void
|
2011-09-29 10:19:26 +04:00
|
|
|
DocumentViewerImpl::SetIsPrinting(bool aIsPrinting)
|
2002-08-21 16:01:05 +04:00
|
|
|
{
|
|
|
|
#ifdef NS_PRINTING
|
2002-10-08 17:17:56 +04:00
|
|
|
// Set all the docShells in the docshell tree to be printing.
|
|
|
|
// that way if anyone of them tries to "navigate" it can't
|
2011-03-24 14:42:54 +03:00
|
|
|
nsCOMPtr<nsIDocShellTreeNode> docShellTreeNode(do_QueryReferent(mContainer));
|
|
|
|
if (docShellTreeNode || !aIsPrinting) {
|
2011-10-17 18:59:28 +04:00
|
|
|
SetIsPrintingInDocShellTree(docShellTreeNode, aIsPrinting, true);
|
2011-03-24 14:42:54 +03:00
|
|
|
} else {
|
|
|
|
NS_WARNING("Did you close a window before printing?");
|
2002-08-21 16:01:05 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
2001-02-01 23:49:10 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
//------------------------------------------------------------
|
2002-10-08 17:17:56 +04:00
|
|
|
// The PrintEngine holds the current value
|
2005-04-07 08:04:06 +04:00
|
|
|
// this called from inside the DocViewer.
|
2011-10-17 18:59:28 +04:00
|
|
|
// XXX it always returns false for subdocuments
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2002-08-21 16:01:05 +04:00
|
|
|
DocumentViewerImpl::GetIsPrintPreview()
|
|
|
|
{
|
|
|
|
#ifdef NS_PRINTING
|
|
|
|
if (mPrintEngine) {
|
|
|
|
return mPrintEngine->GetIsPrintPreview();
|
|
|
|
}
|
|
|
|
#endif
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2002-08-21 16:01:05 +04:00
|
|
|
}
|
2001-02-07 02:03:17 +03:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
//------------------------------------------------------------
|
2002-10-08 17:17:56 +04:00
|
|
|
// Notification from the PrintEngine of the current PP status
|
2002-08-21 16:01:05 +04:00
|
|
|
void
|
2011-09-29 10:19:26 +04:00
|
|
|
DocumentViewerImpl::SetIsPrintPreview(bool aIsPrintPreview)
|
2002-08-21 16:01:05 +04:00
|
|
|
{
|
|
|
|
#ifdef NS_PRINTING
|
2002-10-08 17:17:56 +04:00
|
|
|
// Set all the docShells in the docshell tree to be printing.
|
|
|
|
// that way if anyone of them tries to "navigate" it can't
|
2011-03-24 14:42:54 +03:00
|
|
|
nsCOMPtr<nsIDocShellTreeNode> docShellTreeNode(do_QueryReferent(mContainer));
|
|
|
|
if (docShellTreeNode || !aIsPrintPreview) {
|
2011-10-17 18:59:28 +04:00
|
|
|
SetIsPrintingInDocShellTree(docShellTreeNode, aIsPrintPreview, true);
|
2002-08-21 16:01:05 +04:00
|
|
|
}
|
|
|
|
#endif
|
2009-12-11 07:02:13 +03:00
|
|
|
if (!aIsPrintPreview) {
|
2010-02-11 14:02:38 +03:00
|
|
|
if (mPresShell) {
|
|
|
|
DestroyPresShell();
|
|
|
|
}
|
2009-12-11 07:02:13 +03:00
|
|
|
mWindow = nsnull;
|
|
|
|
mViewManager = nsnull;
|
|
|
|
mPresContext = nsnull;
|
|
|
|
mPresShell = nsnull;
|
|
|
|
}
|
2001-02-07 02:03:17 +03:00
|
|
|
}
|
|
|
|
|
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
|
|
|
//------------------------------------------------------------
|
2006-12-10 11:05:05 +03:00
|
|
|
|
|
|
|
static void ResetFocusState(nsIDocShell* aDocShell);
|
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
void
|
|
|
|
DocumentViewerImpl::ReturnToGalleyPresentation()
|
|
|
|
{
|
|
|
|
#if defined(NS_PRINTING) && defined(NS_PRINT_PREVIEW)
|
|
|
|
if (!GetIsPrintPreview()) {
|
2006-10-20 02:43:59 +04:00
|
|
|
NS_ERROR("Wow, we should never get here!");
|
2002-08-21 16:01:05 +04:00
|
|
|
return;
|
|
|
|
}
|
2002-04-17 08:17:16 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
SetIsPrintPreview(false);
|
2002-08-21 16:01:05 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mPrintEngine->TurnScriptingOn(true);
|
2006-12-10 11:05:05 +03:00
|
|
|
mPrintEngine->Destroy();
|
|
|
|
mPrintEngine = nsnull;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocShell> docShell(do_QueryReferent(mContainer));
|
|
|
|
ResetFocusState(docShell);
|
|
|
|
|
2007-11-09 13:19:12 +03:00
|
|
|
SetTextZoom(mTextZoom);
|
|
|
|
SetFullZoom(mPageZoom);
|
2011-03-11 07:33:43 +03:00
|
|
|
SetMinFontSize(mMinFontSize);
|
2002-08-21 16:01:05 +04:00
|
|
|
Show();
|
|
|
|
|
|
|
|
#endif // NS_PRINTING && NS_PRINT_PREVIEW
|
2002-04-23 03:12:18 +04:00
|
|
|
}
|
|
|
|
|
2005-07-21 04:15:27 +04:00
|
|
|
//------------------------------------------------------------
|
|
|
|
// Reset ESM focus for all descendent doc shells.
|
|
|
|
static void
|
|
|
|
ResetFocusState(nsIDocShell* aDocShell)
|
|
|
|
{
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 22:00:39 +04:00
|
|
|
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
|
|
|
|
if (!fm)
|
|
|
|
return;
|
|
|
|
|
2005-07-21 04:15:27 +04:00
|
|
|
nsCOMPtr<nsISimpleEnumerator> docShellEnumerator;
|
|
|
|
aDocShell->GetDocShellEnumerator(nsIDocShellTreeItem::typeContent,
|
|
|
|
nsIDocShell::ENUMERATE_FORWARDS,
|
|
|
|
getter_AddRefs(docShellEnumerator));
|
|
|
|
|
|
|
|
nsCOMPtr<nsISupports> currentContainer;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool hasMoreDocShells;
|
2005-07-21 04:15:27 +04:00
|
|
|
while (NS_SUCCEEDED(docShellEnumerator->HasMoreElements(&hasMoreDocShells))
|
|
|
|
&& hasMoreDocShells) {
|
|
|
|
docShellEnumerator->GetNext(getter_AddRefs(currentContainer));
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 22:00:39 +04:00
|
|
|
nsCOMPtr<nsIDOMWindow> win = do_GetInterface(currentContainer);
|
|
|
|
if (win)
|
|
|
|
fm->ClearFocus(win);
|
2005-07-21 04:15:27 +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();
|
2006-12-10 11:05:05 +03:00
|
|
|
mPrintEngine = nsnull;
|
2002-09-10 05:57:09 +04:00
|
|
|
}
|
2002-10-02 01:57:15 +04:00
|
|
|
|
|
|
|
// We are done printing, now cleanup
|
2003-09-27 01:45:15 +04:00
|
|
|
if (mDeferredWindowClose) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mDeferredWindowClose = false;
|
2005-05-15 04:30:02 +04:00
|
|
|
nsCOMPtr<nsISupports> container = do_QueryReferent(mContainer);
|
2011-07-15 14:31:34 +04:00
|
|
|
nsCOMPtr<nsIDOMWindow> win = do_GetInterface(container);
|
2003-09-27 01:45:15 +04:00
|
|
|
if (win)
|
|
|
|
win->Close();
|
|
|
|
} else if (mClosingWhilePrinting) {
|
2002-10-02 01:57:15 +04:00
|
|
|
if (mDocument) {
|
|
|
|
mDocument->SetScriptGlobalObject(nsnull);
|
2005-05-18 07:52:33 +04:00
|
|
|
mDocument->Destroy();
|
2002-10-02 01:57:15 +04:00
|
|
|
mDocument = nsnull;
|
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
mClosingWhilePrinting = false;
|
2002-10-02 01:57:15 +04:00
|
|
|
}
|
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
|
|
|
}
|
2006-04-01 05:19:28 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
NS_IMETHODIMP DocumentViewerImpl::SetPageMode(bool aPageMode, nsIPrintSettings* aPrintSettings)
|
2006-04-01 05:19:28 +04:00
|
|
|
{
|
2007-03-21 09:07:42 +03:00
|
|
|
// XXX Page mode is only partially working; it's currently used for
|
|
|
|
// reftests that require a paginated context
|
2006-04-01 05:19:28 +04:00
|
|
|
mIsPageMode = aPageMode;
|
|
|
|
|
|
|
|
if (mPresShell) {
|
2009-01-14 15:24:10 +03:00
|
|
|
DestroyPresShell();
|
2006-04-01 05:19:28 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mPresContext) {
|
2011-01-21 22:09:11 +03:00
|
|
|
DestroyPresContext();
|
2006-04-01 05:19:28 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
mViewManager = nsnull;
|
|
|
|
mWindow = nsnull;
|
|
|
|
|
2006-05-19 14:26:44 +04:00
|
|
|
NS_ENSURE_STATE(mDocument);
|
2006-04-01 05:19:28 +04:00
|
|
|
if (aPageMode)
|
|
|
|
{
|
2009-07-22 04:44:54 +04:00
|
|
|
mPresContext = CreatePresContext(mDocument,
|
|
|
|
nsPresContext::eContext_PageLayout, FindContainerView());
|
2006-05-19 14:26:44 +04:00
|
|
|
NS_ENSURE_TRUE(mPresContext, NS_ERROR_OUT_OF_MEMORY);
|
2011-10-17 18:59:28 +04:00
|
|
|
mPresContext->SetPaginatedScrolling(true);
|
2006-04-01 05:19:28 +04:00
|
|
|
mPresContext->SetPrintSettings(aPrintSettings);
|
|
|
|
nsresult rv = mPresContext->Init(mDeviceContext);
|
2006-05-19 14:26:44 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2006-04-01 05:19:28 +04:00
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
InitInternal(mParentWidget, nsnull, mBounds, true, false);
|
2006-04-01 05:19:28 +04:00
|
|
|
|
|
|
|
Show();
|
|
|
|
return NS_OK;
|
2006-04-05 08:37:44 +04:00
|
|
|
}
|
2007-10-06 04:35:00 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
DocumentViewerImpl::GetHistoryEntry(nsISHEntry **aHistoryEntry)
|
|
|
|
{
|
|
|
|
NS_IF_ADDREF(*aHistoryEntry = mSHEntry);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2009-01-14 15:24:10 +03:00
|
|
|
|
2011-02-16 03:35:28 +03:00
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
DocumentViewerImpl::GetIsTabModalPromptAllowed(bool *aAllowed)
|
2011-02-16 03:35:28 +03:00
|
|
|
{
|
|
|
|
*aAllowed = !(mInPermitUnload || mHidden);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-01-14 15:24:10 +03:00
|
|
|
void
|
|
|
|
DocumentViewerImpl::DestroyPresShell()
|
|
|
|
{
|
|
|
|
// Break circular reference (or something)
|
|
|
|
mPresShell->EndObservingDocument();
|
|
|
|
|
|
|
|
nsCOMPtr<nsISelection> selection;
|
|
|
|
GetDocumentSelection(getter_AddRefs(selection));
|
|
|
|
nsCOMPtr<nsISelectionPrivate> selPrivate = do_QueryInterface(selection);
|
|
|
|
if (selPrivate && mSelectionListener)
|
|
|
|
selPrivate->RemoveSelectionListener(mSelectionListener);
|
|
|
|
|
2009-05-15 07:08:41 +04:00
|
|
|
nsAutoScriptBlocker scriptBlocker;
|
2009-01-14 15:24:10 +03:00
|
|
|
mPresShell->Destroy();
|
|
|
|
mPresShell = nsnull;
|
|
|
|
}
|
2009-12-11 07:02:13 +03:00
|
|
|
|
2011-01-21 22:09:11 +03:00
|
|
|
void
|
|
|
|
DocumentViewerImpl::DestroyPresContext()
|
|
|
|
{
|
|
|
|
mPresContext->SetContainer(nsnull);
|
|
|
|
mPresContext->SetLinkHandler(nsnull);
|
|
|
|
mPresContext = nsnull;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2009-12-11 07:02:13 +03:00
|
|
|
DocumentViewerImpl::IsInitializedForPrintPreview()
|
|
|
|
{
|
|
|
|
return mInitializedForPrintPreview;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DocumentViewerImpl::InitializeForPrintPreview()
|
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
mInitializedForPrintPreview = true;
|
2009-12-11 07:02:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-08-28 03:15:08 +04:00
|
|
|
DocumentViewerImpl::SetPrintPreviewPresentation(nsIViewManager* aViewManager,
|
2009-12-11 07:02:13 +03:00
|
|
|
nsPresContext* aPresContext,
|
|
|
|
nsIPresShell* aPresShell)
|
|
|
|
{
|
|
|
|
if (mPresShell) {
|
|
|
|
DestroyPresShell();
|
|
|
|
}
|
|
|
|
|
2010-08-28 03:15:08 +04:00
|
|
|
mWindow = nsnull;
|
2009-12-11 07:02:13 +03:00
|
|
|
mViewManager = aViewManager;
|
|
|
|
mPresContext = aPresContext;
|
|
|
|
mPresShell = aPresShell;
|
|
|
|
}
|
2012-01-07 04:42:42 +04:00
|
|
|
|
2012-03-12 20:03:38 +04:00
|
|
|
// Fires the "before-first-paint" event so that interested parties (right now, the
|
2012-01-07 04:42:42 +04:00
|
|
|
// mobile browser) are aware of it.
|
|
|
|
NS_IMETHODIMP
|
2012-03-12 20:03:38 +04:00
|
|
|
nsBeforeFirstPaintDispatcher::Run()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIObserverService> observerService =
|
|
|
|
mozilla::services::GetObserverService();
|
|
|
|
if (observerService) {
|
|
|
|
observerService->NotifyObservers(mDocument, "before-first-paint", NULL);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fires the "document-shown" event so that interested parties are aware of it.
|
|
|
|
NS_IMETHODIMP
|
2012-01-07 04:42:42 +04:00
|
|
|
nsDocumentShownDispatcher::Run()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIObserverService> observerService =
|
|
|
|
mozilla::services::GetObserverService();
|
|
|
|
if (observerService) {
|
|
|
|
observerService->NotifyObservers(mDocument, "document-shown", NULL);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|