1998-04-13 20:24:54 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
2006-04-17 23:16:46 +00:00
|
|
|
* vim: set ts=2 sw=2 et tw=78:
|
2004-04-18 14:30:37 +00:00
|
|
|
* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1998-04-13 20:24:54 +00:00
|
|
|
*
|
2004-04-18 14:30:37 +00: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/
|
|
|
|
*
|
|
|
|
* 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.
|
1998-04-13 20:24:54 +00:00
|
|
|
*
|
1999-11-06 03:40:37 +00:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2004-04-18 14:30:37 +00:00
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 03:40:37 +00:00
|
|
|
*
|
2004-04-18 14:30:37 +00:00
|
|
|
* Contributor(s):
|
2001-04-18 06:06:31 +00:00
|
|
|
* Steve Clark <buster@netscape.com>
|
2007-08-22 11:13:46 +00:00
|
|
|
* Håkan Waara <hwaara@chello.se>
|
2001-04-18 06:06:31 +00:00
|
|
|
* Dan Rosen <dr@netscape.com>
|
2001-08-02 14:34:55 +00:00
|
|
|
* Daniel Glazman <glazman@netscape.com>
|
2010-02-09 16:09:59 +00:00
|
|
|
* Mats Palmgren <matspal@gmail.com>
|
2000-05-15 03:37:21 +00:00
|
|
|
*
|
2004-04-18 14:30:37 +00:00
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* 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"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK *****
|
2000-05-15 03:37:21 +00:00
|
|
|
*
|
|
|
|
* This Original Code has been modified by IBM Corporation.
|
|
|
|
* Modifications made by IBM described herein are
|
|
|
|
* Copyright (c) International Business Machines
|
|
|
|
* Corporation, 2000
|
|
|
|
*
|
|
|
|
* Modifications to Mozilla code or documentation
|
|
|
|
* identified per MPL Section 3.3
|
|
|
|
*
|
|
|
|
* Date Modified by Description of modification
|
|
|
|
* 05/03/2000 IBM Corp. Observer events for reflow states
|
2009-08-18 03:21:06 +00:00
|
|
|
*/
|
2001-04-18 06:06:31 +00:00
|
|
|
|
2006-03-30 05:56:38 +00:00
|
|
|
/* a presentation of a document, part 2 */
|
|
|
|
|
1998-04-13 20:24:54 +00:00
|
|
|
#include "nsIPresShell.h"
|
2004-07-31 23:15:21 +00:00
|
|
|
#include "nsPresContext.h"
|
1998-04-13 20:24:54 +00:00
|
|
|
#include "nsIContent.h"
|
2010-05-05 18:18:05 +00:00
|
|
|
#include "mozilla/dom/Element.h"
|
1998-04-13 20:24:54 +00:00
|
|
|
#include "nsIDocument.h"
|
2003-03-06 23:07:00 +00:00
|
|
|
#include "nsIDOMXULDocument.h"
|
2004-01-29 01:45:34 +00:00
|
|
|
#include "nsStubDocumentObserver.h"
|
2004-01-07 22:30:53 +00:00
|
|
|
#include "nsStyleSet.h"
|
2010-05-11 20:41:47 +00:00
|
|
|
#include "nsCSSStyleSheet.h" // XXX for UA sheet loading hack, can this go away please?
|
2000-10-11 08:33:01 +00:00
|
|
|
#include "nsIDOMCSSStyleSheet.h" // for Pref-related rule management (bugs 22963,20760,31816)
|
|
|
|
#include "nsINameSpaceManager.h" // for Pref-related rule management (bugs 22963,20760,31816)
|
1999-08-05 20:17:44 +00:00
|
|
|
#include "nsIServiceManager.h"
|
1998-05-20 16:24:54 +00:00
|
|
|
#include "nsFrame.h"
|
1998-04-13 20:24:54 +00:00
|
|
|
#include "nsIViewManager.h"
|
|
|
|
#include "nsCRT.h"
|
2006-11-17 01:49:06 +00:00
|
|
|
#include "nsCRTGlue.h"
|
1998-06-03 15:46:54 +00:00
|
|
|
#include "prlog.h"
|
2000-04-01 08:35:40 +00:00
|
|
|
#include "prmem.h"
|
2004-01-18 14:44:43 +00:00
|
|
|
#include "prprf.h"
|
1998-12-12 19:21:05 +00:00
|
|
|
#include "prinrval.h"
|
2009-02-03 14:42:18 +00:00
|
|
|
#include "nsTArray.h"
|
2004-09-13 03:22:46 +00:00
|
|
|
#include "nsCOMArray.h"
|
2000-10-09 03:08:41 +00:00
|
|
|
#include "nsHashtable.h"
|
1998-08-28 02:54:06 +00:00
|
|
|
#include "nsIViewObserver.h"
|
1998-09-19 03:24:26 +00:00
|
|
|
#include "nsContainerFrame.h"
|
1998-10-02 01:12:39 +00:00
|
|
|
#include "nsIDeviceContext.h"
|
2004-09-04 19:28:46 +00:00
|
|
|
#include "nsEventStateManager.h"
|
|
|
|
#include "nsDOMEvent.h"
|
2001-07-16 02:40:48 +00:00
|
|
|
#include "nsGUIEvent.h"
|
1998-11-17 02:14:38 +00:00
|
|
|
#include "nsHTMLParts.h"
|
2004-04-29 23:34:19 +00:00
|
|
|
#include "nsContentUtils.h"
|
2000-09-14 11:45:01 +00:00
|
|
|
#include "nsISelection.h"
|
1999-12-02 21:45:21 +00:00
|
|
|
#include "nsISelectionController.h"
|
2007-03-20 12:14:52 +00:00
|
|
|
#include "nsISelectionPrivate.h"
|
1998-12-08 18:26:06 +00:00
|
|
|
#include "nsLayoutCID.h"
|
2007-01-30 00:06:41 +00:00
|
|
|
#include "nsGkAtoms.h"
|
1998-12-14 18:34:14 +00:00
|
|
|
#include "nsIDOMRange.h"
|
|
|
|
#include "nsIDOMDocument.h"
|
|
|
|
#include "nsIDOMNode.h"
|
2003-06-16 11:17:18 +00:00
|
|
|
#include "nsIDOM3Node.h"
|
2000-09-14 11:45:01 +00:00
|
|
|
#include "nsIDOMNodeList.h"
|
1998-12-14 18:34:14 +00:00
|
|
|
#include "nsIDOMElement.h"
|
2007-03-20 12:14:52 +00:00
|
|
|
#include "nsRange.h"
|
2002-11-17 15:37:56 +00:00
|
|
|
#include "nsCSSPseudoElements.h"
|
1999-01-22 18:58:14 +00:00
|
|
|
#include "nsCOMPtr.h"
|
2003-02-22 00:32:13 +00:00
|
|
|
#include "nsAutoPtr.h"
|
2001-09-29 08:28:41 +00:00
|
|
|
#include "nsReadableUtils.h"
|
2001-12-17 07:14:49 +00:00
|
|
|
#include "nsUnicharUtils.h"
|
1999-08-25 10:51:55 +00:00
|
|
|
#include "nsWeakReference.h"
|
2000-01-04 20:24:09 +00:00
|
|
|
#include "nsIPageSequenceFrame.h"
|
2008-07-16 10:52:01 +00:00
|
|
|
#include "nsCaret.h"
|
1999-02-12 05:39:33 +00:00
|
|
|
#include "nsIDOMHTMLDocument.h"
|
2003-03-19 23:45:42 +00:00
|
|
|
#include "nsIXPointer.h"
|
2001-12-20 05:15:52 +00:00
|
|
|
#include "nsIDOMXMLDocument.h"
|
1999-03-01 19:21:01 +00:00
|
|
|
#include "nsIParser.h"
|
|
|
|
#include "nsParserCIID.h"
|
2006-04-26 02:01:07 +00:00
|
|
|
#include "nsFrameSelection.h"
|
2000-06-14 02:57:26 +00:00
|
|
|
#include "nsIDOMNSHTMLInputElement.h" //optimization for ::DoXXX commands
|
2000-06-29 22:33:36 +00:00
|
|
|
#include "nsIDOMNSHTMLTextAreaElement.h"
|
1999-04-03 18:58:04 +00:00
|
|
|
#include "nsViewsCID.h"
|
2009-08-18 03:21:06 +00:00
|
|
|
#include "nsPresArena.h"
|
2004-02-23 21:29:06 +00:00
|
|
|
#include "nsFrameManager.h"
|
2002-09-03 23:36:13 +00:00
|
|
|
#include "nsXPCOM.h"
|
1999-08-25 08:35:06 +00:00
|
|
|
#include "nsISupportsPrimitives.h"
|
1999-08-30 22:38:58 +00:00
|
|
|
#include "nsILayoutHistoryState.h"
|
2007-03-07 19:08:36 +00:00
|
|
|
#include "nsILineIterator.h" // for ScrollContentIntoView
|
1999-11-09 03:23:26 +00:00
|
|
|
#include "nsWeakPtr.h"
|
2004-05-02 18:07:12 +00:00
|
|
|
#include "pldhash.h"
|
2004-07-18 01:16:27 +00:00
|
|
|
#include "nsIObserverService.h"
|
|
|
|
#include "nsIObserver.h"
|
2000-08-30 00:35:43 +00:00
|
|
|
#include "nsIDocShell.h" // for reflow observation
|
2004-10-14 21:51:00 +00:00
|
|
|
#include "nsIBaseWindow.h"
|
2002-11-25 11:21:22 +00:00
|
|
|
#include "nsLayoutErrors.h"
|
2003-01-05 05:05:17 +00:00
|
|
|
#include "nsLayoutUtils.h"
|
2003-01-17 09:33:52 +00:00
|
|
|
#include "nsCSSRendering.h"
|
2001-10-26 05:12:25 +00:00
|
|
|
// for |#ifdef DEBUG| code
|
2001-06-27 04:04:04 +00:00
|
|
|
#include "prenv.h"
|
2005-02-20 09:55:02 +00:00
|
|
|
#include "nsIAttribute.h"
|
2005-08-23 22:26:10 +00:00
|
|
|
#include "nsIGlobalHistory2.h"
|
2006-01-26 02:29:17 +00:00
|
|
|
#include "nsDisplayList.h"
|
2007-03-20 12:14:52 +00:00
|
|
|
#include "nsIRegion.h"
|
2006-01-26 02:29:17 +00:00
|
|
|
#include "nsRegion.h"
|
1999-02-19 23:47:36 +00:00
|
|
|
|
2009-05-04 01:35:33 +00:00
|
|
|
#ifdef MOZ_REFLOW_PERF
|
2001-03-13 01:47:22 +00:00
|
|
|
#include "nsIRenderingContext.h"
|
|
|
|
#include "nsIFontMetrics.h"
|
|
|
|
#endif
|
|
|
|
|
2000-07-13 23:00:59 +00:00
|
|
|
#include "nsIReflowCallback.h"
|
|
|
|
|
2000-02-13 06:07:38 +00:00
|
|
|
#include "nsPIDOMWindow.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 18:00:39 +00:00
|
|
|
#include "nsFocusManager.h"
|
2005-05-04 20:22:32 +00:00
|
|
|
#include "nsIPluginInstance.h"
|
|
|
|
#include "nsIObjectFrame.h"
|
2005-12-03 11:27:42 +00:00
|
|
|
#include "nsIObjectLoadingContent.h"
|
2005-11-01 11:37:25 +00:00
|
|
|
#include "nsNetUtil.h"
|
2006-03-07 17:08:51 +00:00
|
|
|
#include "nsEventDispatcher.h"
|
2006-05-10 17:30:15 +00:00
|
|
|
#include "nsThreadUtils.h"
|
2006-06-08 14:32:20 +00:00
|
|
|
#include "nsStyleSheetService.h"
|
2007-03-20 12:14:52 +00:00
|
|
|
#include "gfxImageSurface.h"
|
|
|
|
#include "gfxContext.h"
|
2008-07-09 08:56:02 +00:00
|
|
|
#ifdef MOZ_MEDIA
|
2008-10-28 18:48:39 +00:00
|
|
|
#include "nsHTMLMediaElement.h"
|
2008-07-09 08:56:02 +00:00
|
|
|
#endif
|
2010-03-02 15:36:33 +00:00
|
|
|
#ifdef MOZ_SMIL
|
|
|
|
#include "nsSMILAnimationController.h"
|
|
|
|
#endif
|
2000-02-13 06:07:38 +00:00
|
|
|
|
1999-03-23 21:32:48 +00:00
|
|
|
// Drag & Drop, Clipboard
|
|
|
|
#include "nsWidgetsCID.h"
|
|
|
|
#include "nsIClipboard.h"
|
2001-05-10 02:35:00 +00:00
|
|
|
#include "nsIClipboardHelper.h"
|
1999-12-18 02:09:29 +00:00
|
|
|
#include "nsIDocShellTreeItem.h"
|
1999-11-09 03:23:26 +00:00
|
|
|
#include "nsIURI.h"
|
1999-12-07 05:28:32 +00:00
|
|
|
#include "nsIScrollableFrame.h"
|
1999-12-23 02:02:33 +00:00
|
|
|
#include "prtime.h"
|
|
|
|
#include "prlong.h"
|
2000-06-14 23:18:54 +00:00
|
|
|
#include "nsIDragService.h"
|
2001-02-15 13:22:26 +00:00
|
|
|
#include "nsCopySupport.h"
|
2001-04-18 06:06:31 +00:00
|
|
|
#include "nsIDOMHTMLAnchorElement.h"
|
2001-09-12 23:31:37 +00:00
|
|
|
#include "nsIDOMHTMLAreaElement.h"
|
|
|
|
#include "nsIDOMHTMLLinkElement.h"
|
2001-04-17 23:25:21 +00:00
|
|
|
#include "nsITimer.h"
|
2003-04-15 08:45:55 +00:00
|
|
|
#ifdef ACCESSIBILITY
|
|
|
|
#include "nsIAccessibilityService.h"
|
2010-05-12 06:47:35 +00:00
|
|
|
#include "nsAccessible.h"
|
2003-04-15 08:45:55 +00:00
|
|
|
#endif
|
2000-06-14 23:18:54 +00:00
|
|
|
|
2001-12-17 22:51:39 +00:00
|
|
|
// For style data reconstruction
|
|
|
|
#include "nsStyleChangeList.h"
|
2004-01-07 22:30:53 +00:00
|
|
|
#include "nsCSSFrameConstructor.h"
|
2003-04-11 00:56:27 +00:00
|
|
|
#ifdef MOZ_XUL
|
2007-07-04 15:49:38 +00:00
|
|
|
#include "nsMenuFrame.h"
|
2008-10-28 04:47:19 +00:00
|
|
|
#include "nsTreeBodyFrame.h"
|
2009-01-17 20:50:00 +00:00
|
|
|
#include "nsIBoxObject.h"
|
|
|
|
#include "nsITreeBoxObject.h"
|
|
|
|
#include "nsMenuPopupFrame.h"
|
|
|
|
#include "nsITreeColumns.h"
|
|
|
|
#include "nsIDOMXULMultSelectCntrlEl.h"
|
|
|
|
#include "nsIDOMXULSelectCntrlItemEl.h"
|
|
|
|
#include "nsIDOMXULMenuListElement.h"
|
|
|
|
|
2003-04-11 00:56:27 +00:00
|
|
|
#endif
|
2001-12-17 22:51:39 +00:00
|
|
|
#include "nsPlaceholderFrame.h"
|
2009-10-08 06:18:18 +00:00
|
|
|
#include "nsCanvasFrame.h"
|
2001-12-17 22:51:39 +00:00
|
|
|
|
2001-05-01 22:54:11 +00:00
|
|
|
// Content viewer interfaces
|
|
|
|
#include "nsIContentViewer.h"
|
2007-05-23 00:11:05 +00:00
|
|
|
#include "imgIEncoder.h"
|
|
|
|
#include "gfxPlatform.h"
|
2001-05-01 22:54:11 +00:00
|
|
|
|
2010-05-19 23:22:19 +00:00
|
|
|
#include "mozilla/FunctionTimer.h"
|
|
|
|
|
|
|
|
#ifdef NS_FUNCTION_TIMER
|
|
|
|
#define NS_TIME_FUNCTION_DECLARE_DOCURL \
|
|
|
|
nsCAutoString docURL__("N/A"); \
|
|
|
|
nsIURI *uri__ = mDocument->GetDocumentURI(); \
|
|
|
|
if (uri__) uri__->GetSpec(docURL__);
|
|
|
|
#define NS_TIME_FUNCTION_WITH_DOCURL \
|
|
|
|
NS_TIME_FUNCTION_DECLARE_DOCURL \
|
|
|
|
NS_TIME_FUNCTION_MIN_FMT(1.0, \
|
|
|
|
"%s (line %d) (document: %s)", MOZ_FUNCTION_NAME, \
|
|
|
|
__LINE__, docURL__.get())
|
|
|
|
#else
|
|
|
|
#define NS_TIME_FUNCTION_WITH_DOCURL do{} while(0)
|
|
|
|
#endif
|
|
|
|
|
2001-02-19 21:50:04 +00:00
|
|
|
#include "nsContentCID.h"
|
2001-03-27 23:59:56 +00:00
|
|
|
static NS_DEFINE_IID(kRangeCID, NS_RANGE_CID);
|
2001-02-19 21:50:04 +00:00
|
|
|
|
2010-03-01 08:03:49 +00:00
|
|
|
using namespace mozilla::layers;
|
2010-04-30 13:12:05 +00:00
|
|
|
using namespace mozilla::dom;
|
2010-03-01 08:03:49 +00:00
|
|
|
|
2007-05-04 02:19:18 +00:00
|
|
|
PRBool nsIPresShell::gIsAccessibilityActive = PR_FALSE;
|
2009-09-13 13:13:16 +00:00
|
|
|
CapturingContentInfo nsIPresShell::gCaptureInfo;
|
2007-05-04 02:19:18 +00:00
|
|
|
|
2000-10-11 08:33:01 +00:00
|
|
|
// convert a color value to a string, in the CSS format #RRGGBB
|
|
|
|
// * - initially created for bugs 31816, 20760, 22963
|
|
|
|
static void ColorToString(nscolor aColor, nsAutoString &aString);
|
|
|
|
|
2000-01-04 20:24:09 +00:00
|
|
|
// Class ID's
|
|
|
|
static NS_DEFINE_CID(kFrameSelectionCID, NS_FRAMESELECTION_CID);
|
1999-03-23 21:32:48 +00:00
|
|
|
|
2007-03-20 12:14:52 +00:00
|
|
|
// RangePaintInfo is used to paint ranges to offscreen buffers
|
|
|
|
struct RangePaintInfo {
|
|
|
|
nsCOMPtr<nsIRange> mRange;
|
|
|
|
nsDisplayListBuilder mBuilder;
|
|
|
|
nsDisplayList mList;
|
|
|
|
|
|
|
|
// offset of builder's reference frame to the root frame
|
|
|
|
nsPoint mRootOffset;
|
|
|
|
|
|
|
|
RangePaintInfo(nsIRange* aRange, nsIFrame* aFrame)
|
|
|
|
: mRange(aRange), mBuilder(aFrame, PR_FALSE, PR_FALSE)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
~RangePaintInfo()
|
|
|
|
{
|
|
|
|
mList.DeleteAll();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
1998-04-13 20:24:54 +00:00
|
|
|
#undef NOISY
|
|
|
|
|
2002-05-10 18:22:41 +00:00
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
|
|
|
|
#ifdef NS_DEBUG
|
|
|
|
// Set the environment variable GECKO_VERIFY_REFLOW_FLAGS to one or
|
|
|
|
// more of the following flags (comma separated) for handy debug
|
|
|
|
// output.
|
|
|
|
static PRUint32 gVerifyReflowFlags;
|
|
|
|
|
|
|
|
struct VerifyReflowFlags {
|
2004-01-21 04:15:00 +00:00
|
|
|
const char* name;
|
2002-05-10 18:22:41 +00:00
|
|
|
PRUint32 bit;
|
|
|
|
};
|
|
|
|
|
2004-01-21 04:15:00 +00:00
|
|
|
static const VerifyReflowFlags gFlags[] = {
|
2002-05-10 18:22:41 +00:00
|
|
|
{ "verify", VERIFY_REFLOW_ON },
|
|
|
|
{ "reflow", VERIFY_REFLOW_NOISY },
|
|
|
|
{ "all", VERIFY_REFLOW_ALL },
|
|
|
|
{ "list-commands", VERIFY_REFLOW_DUMP_COMMANDS },
|
|
|
|
{ "noisy-commands", VERIFY_REFLOW_NOISY_RC },
|
|
|
|
{ "really-noisy-commands", VERIFY_REFLOW_REALLY_NOISY_RC },
|
|
|
|
{ "resize", VERIFY_REFLOW_DURING_RESIZE_REFLOW },
|
|
|
|
};
|
|
|
|
|
|
|
|
#define NUM_VERIFY_REFLOW_FLAGS (sizeof(gFlags) / sizeof(gFlags[0]))
|
|
|
|
|
|
|
|
static void
|
|
|
|
ShowVerifyReflowFlags()
|
|
|
|
{
|
|
|
|
printf("Here are the available GECKO_VERIFY_REFLOW_FLAGS:\n");
|
2004-01-21 04:15:00 +00:00
|
|
|
const VerifyReflowFlags* flag = gFlags;
|
|
|
|
const VerifyReflowFlags* limit = gFlags + NUM_VERIFY_REFLOW_FLAGS;
|
2002-05-10 18:22:41 +00:00
|
|
|
while (flag < limit) {
|
|
|
|
printf(" %s\n", flag->name);
|
|
|
|
++flag;
|
|
|
|
}
|
|
|
|
printf("Note: GECKO_VERIFY_REFLOW_FLAGS is a comma separated list of flag\n");
|
|
|
|
printf("names (no whitespace)\n");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2001-03-13 01:47:22 +00:00
|
|
|
//========================================================================
|
|
|
|
//========================================================================
|
2000-04-26 21:01:57 +00:00
|
|
|
//========================================================================
|
|
|
|
#ifdef MOZ_REFLOW_PERF
|
|
|
|
class ReflowCountMgr;
|
|
|
|
|
2003-05-27 03:52:33 +00:00
|
|
|
static const char kGrandTotalsStr[] = "Grand Totals";
|
2000-04-26 21:01:57 +00:00
|
|
|
|
|
|
|
// Counting Class
|
|
|
|
class ReflowCounter {
|
|
|
|
public:
|
2001-02-22 13:58:17 +00:00
|
|
|
ReflowCounter(ReflowCountMgr * aMgr = nsnull);
|
2000-04-26 21:01:57 +00:00
|
|
|
~ReflowCounter();
|
|
|
|
|
|
|
|
void ClearTotals();
|
|
|
|
void DisplayTotals(const char * aStr);
|
2000-04-28 23:32:04 +00:00
|
|
|
void DisplayDiffTotals(const char * aStr);
|
2000-04-26 21:01:57 +00:00
|
|
|
void DisplayHTMLTotals(const char * aStr);
|
|
|
|
|
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 05:38:33 +00:00
|
|
|
void Add() { mTotal++; }
|
|
|
|
void Add(PRUint32 aTotal) { mTotal += aTotal; }
|
2000-04-28 23:32:04 +00:00
|
|
|
|
|
|
|
void CalcDiffInTotals();
|
|
|
|
void SetTotalsCache();
|
|
|
|
|
|
|
|
void SetMgr(ReflowCountMgr * aMgr) { mMgr = aMgr; }
|
2000-04-26 21:01:57 +00:00
|
|
|
|
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 05:38:33 +00:00
|
|
|
PRUint32 GetTotal() { return mTotal; }
|
2001-02-22 13:58:17 +00:00
|
|
|
|
2000-04-26 21:01:57 +00:00
|
|
|
protected:
|
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 05:38:33 +00:00
|
|
|
void DisplayTotals(PRUint32 aTotal, const char * aTitle);
|
|
|
|
void DisplayHTMLTotals(PRUint32 aTotal, const char * aTitle);
|
2000-04-26 21:01:57 +00:00
|
|
|
|
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 05:38:33 +00:00
|
|
|
PRUint32 mTotal;
|
|
|
|
PRUint32 mCacheTotal;
|
2000-04-28 23:32:04 +00:00
|
|
|
|
2001-03-13 01:47:22 +00:00
|
|
|
ReflowCountMgr * mMgr; // weak reference (don't delete)
|
2000-04-26 21:01:57 +00:00
|
|
|
};
|
|
|
|
|
2001-02-22 13:58:17 +00:00
|
|
|
// Counting Class
|
|
|
|
class IndiReflowCounter {
|
|
|
|
public:
|
2001-10-25 03:21:53 +00:00
|
|
|
IndiReflowCounter(ReflowCountMgr * aMgr = nsnull)
|
|
|
|
: mFrame(nsnull),
|
|
|
|
mCount(0),
|
|
|
|
mMgr(aMgr),
|
|
|
|
mCounter(aMgr),
|
|
|
|
mHasBeenOutput(PR_FALSE)
|
|
|
|
{}
|
2001-02-22 13:58:17 +00:00
|
|
|
virtual ~IndiReflowCounter() {}
|
|
|
|
|
|
|
|
nsAutoString mName;
|
2001-03-13 01:47:22 +00:00
|
|
|
nsIFrame * mFrame; // weak reference (don't delete)
|
2001-02-22 13:58:17 +00:00
|
|
|
PRInt32 mCount;
|
|
|
|
|
2001-03-13 01:47:22 +00:00
|
|
|
ReflowCountMgr * mMgr; // weak reference (don't delete)
|
2001-02-22 13:58:17 +00:00
|
|
|
|
|
|
|
ReflowCounter mCounter;
|
|
|
|
PRBool mHasBeenOutput;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2001-03-13 01:47:22 +00:00
|
|
|
//--------------------
|
2000-04-26 21:01:57 +00:00
|
|
|
// Manager Class
|
2001-03-13 01:47:22 +00:00
|
|
|
//--------------------
|
2000-04-26 21:01:57 +00:00
|
|
|
class ReflowCountMgr {
|
|
|
|
public:
|
|
|
|
ReflowCountMgr();
|
2001-03-13 01:47:22 +00:00
|
|
|
virtual ~ReflowCountMgr();
|
2000-04-26 21:01:57 +00:00
|
|
|
|
|
|
|
void ClearTotals();
|
2000-04-28 23:32:04 +00:00
|
|
|
void ClearGrandTotals();
|
2000-04-26 21:01:57 +00:00
|
|
|
void DisplayTotals(const char * aStr);
|
|
|
|
void DisplayHTMLTotals(const char * aStr);
|
2000-04-28 23:32:04 +00:00
|
|
|
void DisplayDiffsInTotals(const char * aStr);
|
2000-04-26 21:01:57 +00:00
|
|
|
|
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 05:38:33 +00:00
|
|
|
void Add(const char * aName, nsIFrame * aFrame);
|
2000-04-26 21:01:57 +00:00
|
|
|
ReflowCounter * LookUp(const char * aName);
|
|
|
|
|
2004-07-31 23:15:21 +00:00
|
|
|
void PaintCount(const char * aName, nsIRenderingContext* aRenderingContext, nsPresContext* aPresContext, nsIFrame * aFrame, PRUint32 aColor);
|
2001-03-13 01:47:22 +00:00
|
|
|
|
2000-04-26 21:01:57 +00:00
|
|
|
FILE * GetOutFile() { return mFD; }
|
|
|
|
|
2001-02-22 13:58:17 +00:00
|
|
|
PLHashTable * GetIndiFrameHT() { return mIndiFrameCounts; }
|
|
|
|
|
2004-07-31 23:15:21 +00:00
|
|
|
void SetPresContext(nsPresContext * aPresContext) { mPresContext = aPresContext; } // weak reference
|
2001-03-13 01:47:22 +00:00
|
|
|
void SetPresShell(nsIPresShell* aPresShell) { mPresShell= aPresShell; } // weak reference
|
|
|
|
|
|
|
|
void SetDumpFrameCounts(PRBool aVal) { mDumpFrameCounts = aVal; }
|
|
|
|
void SetDumpFrameByFrameCounts(PRBool aVal) { mDumpFrameByFrameCounts = aVal; }
|
|
|
|
void SetPaintFrameCounts(PRBool aVal) { mPaintFrameByFrameCounts = aVal; }
|
2001-02-22 13:58:17 +00:00
|
|
|
|
2009-07-22 00:44:52 +00:00
|
|
|
PRBool IsPaintingFrameCounts() { return mPaintFrameByFrameCounts; }
|
|
|
|
|
2000-04-26 21:01:57 +00:00
|
|
|
protected:
|
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 05:38:33 +00:00
|
|
|
void DisplayTotals(PRUint32 aTotal, PRUint32 * aDupArray, char * aTitle);
|
|
|
|
void DisplayHTMLTotals(PRUint32 aTotal, PRUint32 * aDupArray, char * aTitle);
|
2000-04-26 21:01:57 +00:00
|
|
|
|
2008-10-10 15:04:34 +00:00
|
|
|
static PRIntn RemoveItems(PLHashEntry *he, PRIntn i, void *arg);
|
|
|
|
static PRIntn RemoveIndiItems(PLHashEntry *he, PRIntn i, void *arg);
|
2000-04-26 21:01:57 +00:00
|
|
|
void CleanUp();
|
|
|
|
|
|
|
|
// stdout Output Methods
|
2008-10-10 15:04:34 +00:00
|
|
|
static PRIntn DoSingleTotal(PLHashEntry *he, PRIntn i, void *arg);
|
|
|
|
static PRIntn DoSingleIndi(PLHashEntry *he, PRIntn i, void *arg);
|
2001-02-22 13:58:17 +00:00
|
|
|
|
2000-04-26 21:01:57 +00:00
|
|
|
void DoGrandTotals();
|
2001-02-22 13:58:17 +00:00
|
|
|
void DoIndiTotalsTree();
|
2000-04-26 21:01:57 +00:00
|
|
|
|
|
|
|
// HTML Output Methods
|
2008-10-10 15:04:34 +00:00
|
|
|
static PRIntn DoSingleHTMLTotal(PLHashEntry *he, PRIntn i, void *arg);
|
2000-04-26 21:01:57 +00:00
|
|
|
void DoGrandHTMLTotals();
|
|
|
|
|
2000-04-28 23:32:04 +00:00
|
|
|
// Zero Out the Totals
|
2008-10-10 15:04:34 +00:00
|
|
|
static PRIntn DoClearTotals(PLHashEntry *he, PRIntn i, void *arg);
|
2000-04-28 23:32:04 +00:00
|
|
|
|
|
|
|
// Displays the Diff Totals
|
2008-10-10 15:04:34 +00:00
|
|
|
static PRIntn DoDisplayDiffTotals(PLHashEntry *he, PRIntn i, void *arg);
|
2000-04-28 23:32:04 +00:00
|
|
|
|
2000-04-26 21:01:57 +00:00
|
|
|
PLHashTable * mCounts;
|
2001-02-22 13:58:17 +00:00
|
|
|
PLHashTable * mIndiFrameCounts;
|
2000-04-26 21:01:57 +00:00
|
|
|
FILE * mFD;
|
2001-02-22 13:58:17 +00:00
|
|
|
|
2001-03-13 01:47:22 +00:00
|
|
|
PRBool mDumpFrameCounts;
|
|
|
|
PRBool mDumpFrameByFrameCounts;
|
|
|
|
PRBool mPaintFrameByFrameCounts;
|
|
|
|
|
2000-04-28 23:32:04 +00:00
|
|
|
PRBool mCycledOnce;
|
|
|
|
|
2001-02-22 13:58:17 +00:00
|
|
|
// Root Frame for Individual Tracking
|
2004-07-31 23:15:21 +00:00
|
|
|
nsPresContext * mPresContext;
|
2001-02-22 13:58:17 +00:00
|
|
|
nsIPresShell* mPresShell;
|
|
|
|
|
2000-04-26 21:01:57 +00:00
|
|
|
// ReflowCountMgr gReflowCountMgr;
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
//========================================================================
|
|
|
|
|
1999-02-12 00:02:56 +00:00
|
|
|
// comment out to hide caret
|
1999-03-02 04:26:49 +00:00
|
|
|
#define SHOW_CARET
|
1999-02-12 00:02:56 +00:00
|
|
|
|
2002-05-10 18:22:41 +00:00
|
|
|
// The upper bound on the amount of time to spend reflowing, in
|
|
|
|
// microseconds. When this bound is exceeded and reflow commands are
|
|
|
|
// still queued up, a reflow event is posted. The idea is for reflow
|
|
|
|
// to not hog the processor beyond the time specifed in
|
|
|
|
// gMaxRCProcessingTime. This data member is initialized from the
|
|
|
|
// layout.reflow.timeslice pref.
|
1999-12-23 02:02:33 +00:00
|
|
|
#define NS_MAX_REFLOW_TIME 1000000
|
1999-12-23 03:47:02 +00:00
|
|
|
static PRInt32 gMaxRCProcessingTime = -1;
|
1999-12-23 02:02:33 +00:00
|
|
|
|
2000-03-31 07:02:06 +00:00
|
|
|
#define MARK_INCREMENT 50
|
2002-08-06 13:51:07 +00:00
|
|
|
#define BLOCK_INCREMENT 4044 /* a bit under 4096, for malloc overhead */
|
2000-03-31 07:02:06 +00:00
|
|
|
|
|
|
|
/**A block of memory that the stack will
|
|
|
|
* chop up and hand out
|
|
|
|
*/
|
|
|
|
struct StackBlock {
|
|
|
|
|
2002-08-06 13:51:07 +00:00
|
|
|
// a block of memory. Note that this must be first so that it will
|
|
|
|
// be aligned.
|
|
|
|
char mBlock[BLOCK_INCREMENT];
|
2000-03-31 07:02:06 +00:00
|
|
|
|
|
|
|
// another block of memory that would only be created
|
|
|
|
// if our stack overflowed. Yes we have the ability
|
|
|
|
// to grow on a stack overflow
|
|
|
|
StackBlock* mNext;
|
2002-08-06 13:51:07 +00:00
|
|
|
|
|
|
|
StackBlock() : mNext(nsnull) { }
|
|
|
|
~StackBlock() { }
|
2000-03-31 07:02:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* we hold an array of marks. A push pushes a mark on the stack
|
|
|
|
* a pop pops it off.
|
|
|
|
*/
|
|
|
|
struct StackMark {
|
|
|
|
// the block of memory we are currently handing out chunks of
|
|
|
|
StackBlock* mBlock;
|
|
|
|
|
|
|
|
// our current position in the memory
|
|
|
|
size_t mPos;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* A stack arena allows a stack based interface to a block of memory.
|
|
|
|
* It should be used when you need to allocate some temporary memory that
|
|
|
|
* you will immediately return.
|
|
|
|
*/
|
|
|
|
class StackArena {
|
|
|
|
public:
|
|
|
|
StackArena();
|
|
|
|
~StackArena();
|
|
|
|
|
2007-01-17 23:53:47 +00:00
|
|
|
nsresult Init() { return mBlocks ? NS_OK : NS_ERROR_OUT_OF_MEMORY; }
|
|
|
|
|
2000-03-31 07:02:06 +00:00
|
|
|
// Memory management functions
|
2007-01-17 23:53:47 +00:00
|
|
|
void* Allocate(size_t aSize);
|
|
|
|
void Push();
|
|
|
|
void Pop();
|
2000-03-31 07:02:06 +00:00
|
|
|
|
2010-06-01 02:19:35 +00:00
|
|
|
PRUint32 Size() {
|
|
|
|
PRUint32 result = 0;
|
|
|
|
StackBlock *block = mBlocks;
|
|
|
|
while (block) {
|
|
|
|
result += sizeof(StackBlock);
|
|
|
|
block = block->mNext;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2000-03-31 07:02:06 +00:00
|
|
|
private:
|
|
|
|
// our current position in memory
|
|
|
|
size_t mPos;
|
|
|
|
|
|
|
|
// a list of memory block. Usually there is only one
|
|
|
|
// but if we overrun our stack size we can get more memory.
|
|
|
|
StackBlock* mBlocks;
|
|
|
|
|
|
|
|
// the current block of memory we are passing our chucks of
|
|
|
|
StackBlock* mCurBlock;
|
|
|
|
|
|
|
|
// our stack of mark where push has been called
|
|
|
|
StackMark* mMarks;
|
|
|
|
|
2005-11-20 22:05:24 +00:00
|
|
|
// the current top of the mark list
|
2000-03-31 07:02:06 +00:00
|
|
|
PRUint32 mStackTop;
|
|
|
|
|
|
|
|
// the size of the mark array
|
|
|
|
PRUint32 mMarkLength;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
StackArena::StackArena()
|
|
|
|
{
|
2007-01-17 23:53:47 +00:00
|
|
|
mMarkLength = 0;
|
|
|
|
mMarks = nsnull;
|
2000-03-31 07:02:06 +00:00
|
|
|
|
|
|
|
// allocate our stack memory
|
|
|
|
mBlocks = new StackBlock();
|
|
|
|
mCurBlock = mBlocks;
|
|
|
|
|
|
|
|
mStackTop = 0;
|
|
|
|
mPos = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
StackArena::~StackArena()
|
|
|
|
{
|
|
|
|
// free up our data
|
|
|
|
delete[] mMarks;
|
|
|
|
while(mBlocks)
|
|
|
|
{
|
|
|
|
StackBlock* toDelete = mBlocks;
|
|
|
|
mBlocks = mBlocks->mNext;
|
|
|
|
delete toDelete;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-17 23:53:47 +00:00
|
|
|
void
|
2000-03-31 07:02:06 +00:00
|
|
|
StackArena::Push()
|
|
|
|
{
|
2007-01-17 23:53:47 +00:00
|
|
|
// Resize the mark array if we overrun it. Failure to allocate the
|
|
|
|
// mark array is not fatal; we just won't free to that mark. This
|
|
|
|
// allows callers not to worry about error checking.
|
|
|
|
if (mStackTop >= mMarkLength)
|
2000-03-31 07:02:06 +00:00
|
|
|
{
|
2007-01-17 23:53:47 +00:00
|
|
|
PRUint32 newLength = mStackTop + MARK_INCREMENT;
|
|
|
|
StackMark* newMarks = new StackMark[newLength];
|
|
|
|
if (newMarks) {
|
|
|
|
if (mMarkLength)
|
|
|
|
memcpy(newMarks, mMarks, sizeof(StackMark)*mMarkLength);
|
|
|
|
// Fill in any marks that we couldn't allocate during a prior call
|
|
|
|
// to Push().
|
|
|
|
for (; mMarkLength < mStackTop; ++mMarkLength) {
|
|
|
|
NS_NOTREACHED("should only hit this on out-of-memory");
|
|
|
|
newMarks[mMarkLength].mBlock = mCurBlock;
|
|
|
|
newMarks[mMarkLength].mPos = mPos;
|
|
|
|
}
|
|
|
|
delete [] mMarks;
|
|
|
|
mMarks = newMarks;
|
|
|
|
mMarkLength = newLength;
|
|
|
|
}
|
2000-03-31 07:02:06 +00:00
|
|
|
}
|
|
|
|
|
2007-01-17 23:53:47 +00:00
|
|
|
// set a mark at the top (if we can)
|
|
|
|
NS_ASSERTION(mStackTop < mMarkLength, "out of memory");
|
|
|
|
if (mStackTop < mMarkLength) {
|
|
|
|
mMarks[mStackTop].mBlock = mCurBlock;
|
|
|
|
mMarks[mStackTop].mPos = mPos;
|
|
|
|
}
|
2000-03-31 07:02:06 +00:00
|
|
|
|
|
|
|
mStackTop++;
|
|
|
|
}
|
|
|
|
|
2007-01-17 23:53:47 +00:00
|
|
|
void*
|
|
|
|
StackArena::Allocate(size_t aSize)
|
2000-03-31 07:02:06 +00:00
|
|
|
{
|
2007-01-17 23:53:47 +00:00
|
|
|
NS_ASSERTION(mStackTop > 0, "Allocate called without Push");
|
2000-03-31 07:02:06 +00:00
|
|
|
|
|
|
|
// make sure we are aligned. Beard said 8 was safer then 4.
|
|
|
|
// Round size to multiple of 8
|
|
|
|
aSize = PR_ROUNDUP(aSize, 8);
|
|
|
|
|
|
|
|
// if the size makes the stack overflow. Grab another block for the stack
|
|
|
|
if (mPos + aSize >= BLOCK_INCREMENT)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aSize <= BLOCK_INCREMENT,"Requested memory is greater that our block size!!");
|
|
|
|
if (mCurBlock->mNext == nsnull)
|
|
|
|
mCurBlock->mNext = new StackBlock();
|
|
|
|
|
|
|
|
mCurBlock = mCurBlock->mNext;
|
|
|
|
mPos = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// return the chunk they need.
|
2007-01-17 23:53:47 +00:00
|
|
|
void *result = mCurBlock->mBlock + mPos;
|
2000-03-31 07:02:06 +00:00
|
|
|
mPos += aSize;
|
|
|
|
|
2007-01-17 23:53:47 +00:00
|
|
|
return result;
|
2000-03-31 07:02:06 +00:00
|
|
|
}
|
|
|
|
|
2007-01-17 23:53:47 +00:00
|
|
|
void
|
2000-03-31 07:02:06 +00:00
|
|
|
StackArena::Pop()
|
|
|
|
{
|
|
|
|
// pop off the mark
|
2007-01-17 23:53:47 +00:00
|
|
|
NS_ASSERTION(mStackTop > 0, "unmatched pop");
|
2000-03-31 07:02:06 +00:00
|
|
|
mStackTop--;
|
2002-08-14 12:49:24 +00:00
|
|
|
|
2007-01-17 23:53:47 +00:00
|
|
|
if (mStackTop >= mMarkLength) {
|
|
|
|
// We couldn't allocate the marks array at the time of the push, so
|
|
|
|
// we don't know where we're freeing to.
|
|
|
|
NS_NOTREACHED("out of memory");
|
|
|
|
if (mStackTop == 0) {
|
|
|
|
// But we do know if we've completely pushed the stack.
|
|
|
|
mCurBlock = mBlocks;
|
|
|
|
mPos = 0;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-08-14 12:49:24 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
// Mark the "freed" memory with 0xdd to help with debugging of memory
|
|
|
|
// allocation problems.
|
|
|
|
{
|
|
|
|
StackBlock *block = mMarks[mStackTop].mBlock, *block_end = mCurBlock;
|
|
|
|
size_t pos = mMarks[mStackTop].mPos;
|
|
|
|
for (; block != block_end; block = block->mNext, pos = 0) {
|
|
|
|
memset(block->mBlock + pos, 0xdd, sizeof(block->mBlock) - pos);
|
|
|
|
}
|
|
|
|
memset(block->mBlock + pos, 0xdd, mPos - pos);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2000-03-31 07:02:06 +00:00
|
|
|
mCurBlock = mMarks[mStackTop].mBlock;
|
|
|
|
mPos = mMarks[mStackTop].mPos;
|
|
|
|
}
|
|
|
|
|
2000-07-13 23:00:59 +00:00
|
|
|
struct nsCallbackEventRequest
|
|
|
|
{
|
|
|
|
nsIReflowCallback* callback;
|
|
|
|
nsCallbackEventRequest* next;
|
|
|
|
};
|
|
|
|
|
2004-05-02 18:07:12 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
2010-02-19 17:11:40 +00:00
|
|
|
#define ASSERT_REFLOW_SCHEDULED_STATE() \
|
|
|
|
NS_ASSERTION(mReflowScheduled == \
|
|
|
|
GetPresContext()->RefreshDriver()-> \
|
|
|
|
IsRefreshObserver(this, Flush_Layout), "Unexpected state")
|
|
|
|
|
2006-03-07 17:08:51 +00:00
|
|
|
class nsPresShellEventCB;
|
2009-06-28 20:04:35 +00:00
|
|
|
class nsAutoCauseReflowNotifier;
|
2004-05-02 18:07:12 +00:00
|
|
|
|
1998-08-28 02:54:06 +00:00
|
|
|
class PresShell : public nsIPresShell, public nsIViewObserver,
|
2004-09-01 05:16:00 +00:00
|
|
|
public nsStubDocumentObserver,
|
2004-07-18 01:16:27 +00:00
|
|
|
public nsISelectionController, public nsIObserver,
|
2010-02-19 17:11:40 +00:00
|
|
|
public nsSupportsWeakReference,
|
|
|
|
public nsARefreshObserver
|
1998-08-28 02:54:06 +00:00
|
|
|
{
|
1998-04-13 20:24:54 +00:00
|
|
|
public:
|
|
|
|
PresShell();
|
|
|
|
|
1999-02-26 20:02:06 +00:00
|
|
|
NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
|
1999-02-26 17:08:48 +00:00
|
|
|
|
1998-04-13 20:24:54 +00:00
|
|
|
// nsISupports
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
// nsIPresShell
|
2010-03-20 21:54:19 +00:00
|
|
|
virtual NS_HIDDEN_(nsresult) Init(nsIDocument* aDocument,
|
|
|
|
nsPresContext* aPresContext,
|
|
|
|
nsIViewManager* aViewManager,
|
|
|
|
nsStyleSet* aStyleSet,
|
|
|
|
nsCompatibility aCompatMode);
|
|
|
|
virtual NS_HIDDEN_(void) Destroy();
|
1999-12-04 23:49:50 +00:00
|
|
|
|
2009-09-15 22:00:04 +00:00
|
|
|
virtual NS_HIDDEN_(void*) AllocateFrame(nsQueryFrame::FrameIID aCode,
|
|
|
|
size_t aSize);
|
|
|
|
virtual NS_HIDDEN_(void) FreeFrame(nsQueryFrame::FrameIID aCode,
|
2009-08-18 03:21:06 +00:00
|
|
|
void* aChunk);
|
|
|
|
|
|
|
|
virtual NS_HIDDEN_(void*) AllocateMisc(size_t aSize);
|
|
|
|
virtual NS_HIDDEN_(void) FreeMisc(size_t aSize, void* aChunk);
|
2000-03-31 07:02:06 +00:00
|
|
|
|
|
|
|
// Dynamic stack memory allocation
|
2007-01-17 23:53:47 +00:00
|
|
|
virtual NS_HIDDEN_(void) PushStackMemory();
|
|
|
|
virtual NS_HIDDEN_(void) PopStackMemory();
|
|
|
|
virtual NS_HIDDEN_(void*) AllocateStackMemory(size_t aSize);
|
2000-03-31 07:02:06 +00:00
|
|
|
|
2010-03-20 21:54:19 +00:00
|
|
|
virtual NS_HIDDEN_(nsresult) SetPreferenceStyleRules(PRBool aForceReflow);
|
|
|
|
|
2002-08-26 20:55:30 +00:00
|
|
|
NS_IMETHOD GetSelection(SelectionType aType, nsISelection** aSelection);
|
2006-04-26 02:01:07 +00:00
|
|
|
virtual nsISelection* GetCurrentSelection(SelectionType aType);
|
2002-08-26 20:55:30 +00:00
|
|
|
|
2000-04-28 06:21:31 +00:00
|
|
|
NS_IMETHOD SetDisplaySelection(PRInt16 aToggle);
|
|
|
|
NS_IMETHOD GetDisplaySelection(PRInt16 *aToggle);
|
2002-06-13 20:35:12 +00:00
|
|
|
NS_IMETHOD ScrollSelectionIntoView(SelectionType aType, SelectionRegion aRegion, PRBool aIsSynchronous);
|
1999-08-30 21:54:40 +00:00
|
|
|
NS_IMETHOD RepaintSelection(SelectionType aType);
|
1999-11-09 03:23:26 +00:00
|
|
|
|
2010-03-20 21:54:19 +00:00
|
|
|
virtual NS_HIDDEN_(void) BeginObservingDocument();
|
|
|
|
virtual NS_HIDDEN_(void) EndObservingDocument();
|
|
|
|
virtual NS_HIDDEN_(nsresult) InitialReflow(nscoord aWidth, nscoord aHeight);
|
|
|
|
virtual NS_HIDDEN_(nsresult) ResizeReflow(nscoord aWidth, nscoord aHeight);
|
|
|
|
virtual NS_HIDDEN_(void) StyleChangeReflow();
|
|
|
|
virtual NS_HIDDEN_(nsIPageSequenceFrame*) GetPageSequenceFrame() const;
|
2008-01-30 04:17:57 +00:00
|
|
|
virtual NS_HIDDEN_(nsIFrame*) GetRealPrimaryFrameFor(nsIContent* aContent) const;
|
2002-08-26 20:55:30 +00:00
|
|
|
|
2010-03-20 21:54:19 +00:00
|
|
|
virtual NS_HIDDEN_(nsIFrame*) GetPlaceholderFrameFor(nsIFrame* aFrame) const;
|
|
|
|
virtual NS_HIDDEN_(void) FrameNeedsReflow(nsIFrame *aFrame, IntrinsicDirty aIntrinsicDirty,
|
|
|
|
nsFrameState aBitToAdd);
|
|
|
|
virtual NS_HIDDEN_(void) FrameNeedsToContinueReflow(nsIFrame *aFrame);
|
|
|
|
virtual NS_HIDDEN_(void) CancelAllPendingReflows();
|
2010-03-31 12:38:52 +00:00
|
|
|
virtual NS_HIDDEN_(PRBool) IsSafeToFlush() const;
|
2010-03-20 21:54:19 +00:00
|
|
|
virtual NS_HIDDEN_(void) FlushPendingNotifications(mozFlushType aType);
|
2000-04-17 07:13:57 +00:00
|
|
|
|
2002-10-22 06:07:52 +00:00
|
|
|
/**
|
|
|
|
* Recreates the frames for a node
|
|
|
|
*/
|
2010-03-31 12:41:54 +00:00
|
|
|
virtual NS_HIDDEN_(nsresult) RecreateFramesFor(nsIContent* aContent);
|
2002-10-22 06:07:52 +00:00
|
|
|
|
2000-07-13 23:00:59 +00:00
|
|
|
/**
|
|
|
|
* Post a callback that should be handled after reflow has finished.
|
|
|
|
*/
|
2010-03-31 12:41:54 +00:00
|
|
|
virtual NS_HIDDEN_(nsresult) PostReflowCallback(nsIReflowCallback* aCallback);
|
|
|
|
virtual NS_HIDDEN_(void) CancelReflowCallback(nsIReflowCallback* aCallback);
|
|
|
|
|
|
|
|
virtual NS_HIDDEN_(void) ClearFrameRefs(nsIFrame* aFrame);
|
|
|
|
virtual NS_HIDDEN_(nsresult) CreateRenderingContext(nsIFrame *aFrame,
|
|
|
|
nsIRenderingContext** aContext);
|
|
|
|
virtual NS_HIDDEN_(nsresult) GoToAnchor(const nsAString& aAnchorName, PRBool aScroll);
|
|
|
|
virtual NS_HIDDEN_(nsresult) ScrollToAnchor();
|
|
|
|
|
|
|
|
virtual NS_HIDDEN_(nsresult) ScrollContentIntoView(nsIContent* aContent,
|
|
|
|
PRIntn aVPercent,
|
|
|
|
PRIntn aHPercent);
|
2010-01-11 21:45:16 +00:00
|
|
|
virtual PRBool ScrollFrameRectIntoView(nsIFrame* aFrame,
|
|
|
|
const nsRect& aRect,
|
|
|
|
PRIntn aVPercent,
|
|
|
|
PRIntn aHPercent,
|
|
|
|
PRUint32 aFlags);
|
2009-09-09 05:40:02 +00:00
|
|
|
virtual nsRectVisibility GetRectVisibility(nsIFrame *aFrame,
|
2010-03-31 12:47:25 +00:00
|
|
|
const nsRect &aRect,
|
|
|
|
nscoord aMinTwips) const;
|
2007-03-06 09:53:56 +00:00
|
|
|
|
2010-03-31 12:41:54 +00:00
|
|
|
virtual NS_HIDDEN_(void) SetIgnoreFrameDestruction(PRBool aIgnore);
|
|
|
|
virtual NS_HIDDEN_(void) NotifyDestroyingFrame(nsIFrame* aFrame);
|
1999-08-31 14:35:50 +00:00
|
|
|
|
2010-03-31 12:47:25 +00:00
|
|
|
virtual NS_HIDDEN_(nsresult) GetLinkLocation(nsIDOMNode* aNode, nsAString& aLocationString) const;
|
1999-08-30 22:38:58 +00:00
|
|
|
|
2010-03-31 12:41:54 +00:00
|
|
|
virtual NS_HIDDEN_(nsresult) CaptureHistoryState(nsILayoutHistoryState** aLayoutHistoryState, PRBool aLeavingPage);
|
2010-03-28 23:21:11 +00:00
|
|
|
|
2010-03-31 12:43:49 +00:00
|
|
|
virtual NS_HIDDEN_(void) UnsuppressPainting();
|
2010-03-31 12:41:54 +00:00
|
|
|
|
2004-01-07 22:30:53 +00:00
|
|
|
virtual nsresult GetAgentStyleSheets(nsCOMArray<nsIStyleSheet>& aSheets);
|
|
|
|
virtual nsresult SetAgentStyleSheets(const nsCOMArray<nsIStyleSheet>& aSheets);
|
|
|
|
|
|
|
|
virtual nsresult AddOverrideStyleSheet(nsIStyleSheet *aSheet);
|
|
|
|
virtual nsresult RemoveOverrideStyleSheet(nsIStyleSheet *aSheet);
|
|
|
|
|
2010-03-31 12:50:20 +00:00
|
|
|
virtual NS_HIDDEN_(nsresult) HandleEventWithTarget(nsEvent* aEvent, nsIFrame* aFrame,
|
|
|
|
nsIContent* aContent,
|
|
|
|
nsEventStatus* aStatus);
|
2010-03-31 12:43:01 +00:00
|
|
|
virtual NS_HIDDEN_(nsIFrame*) GetEventTargetFrame();
|
|
|
|
virtual NS_HIDDEN_(already_AddRefed<nsIContent>) GetEventTargetContent(nsEvent* aEvent);
|
2000-03-23 00:34:54 +00:00
|
|
|
|
2004-01-21 23:05:10 +00:00
|
|
|
|
|
|
|
virtual nsresult ReconstructFrames(void);
|
2005-05-04 20:22:32 +00:00
|
|
|
virtual void Freeze();
|
2005-07-19 17:07:40 +00:00
|
|
|
virtual void Thaw();
|
2009-03-03 20:11:14 +00:00
|
|
|
virtual void FireOrClearDelayedEvents(PRBool aFireEvents);
|
2007-09-05 08:00:40 +00:00
|
|
|
|
|
|
|
virtual nsIFrame* GetFrameForPoint(nsIFrame* aFrame, nsPoint aPt);
|
|
|
|
|
2010-03-31 12:45:32 +00:00
|
|
|
virtual NS_HIDDEN_(nsresult) RenderDocument(const nsRect& aRect, PRUint32 aFlags,
|
|
|
|
nscolor aBackgroundColor,
|
|
|
|
gfxContext* aThebesContext);
|
2004-01-21 23:05:10 +00:00
|
|
|
|
2007-03-20 12:14:52 +00:00
|
|
|
virtual already_AddRefed<gfxASurface> RenderNode(nsIDOMNode* aNode,
|
2010-06-05 20:29:49 +00:00
|
|
|
nsIntRegion* aRegion,
|
2009-01-15 03:27:09 +00:00
|
|
|
nsIntPoint& aPoint,
|
|
|
|
nsIntRect* aScreenRect);
|
2007-03-20 12:14:52 +00:00
|
|
|
|
|
|
|
virtual already_AddRefed<gfxASurface> RenderSelection(nsISelection* aSelection,
|
2009-01-15 03:27:09 +00:00
|
|
|
nsIntPoint& aPoint,
|
|
|
|
nsIntRect* aScreenRect);
|
2007-03-20 12:14:52 +00:00
|
|
|
|
1998-08-28 02:54:06 +00:00
|
|
|
//nsIViewObserver interface
|
|
|
|
|
2010-03-01 08:03:49 +00:00
|
|
|
NS_IMETHOD Paint(nsIView* aDisplayRoot,
|
|
|
|
nsIView* aViewToPaint,
|
|
|
|
nsIWidget* aWidget,
|
|
|
|
const nsRegion& aDirtyRegion,
|
|
|
|
PRBool aPaintDefaultBackground);
|
2006-01-26 02:29:17 +00:00
|
|
|
NS_IMETHOD ComputeRepaintRegionForCopy(nsIView* aRootView,
|
|
|
|
nsIView* aMovingView,
|
|
|
|
nsPoint aDelta,
|
2009-08-14 02:09:51 +00:00
|
|
|
const nsRect& aUpdateRect,
|
|
|
|
nsRegion* aBlitRegion,
|
2006-01-26 02:29:17 +00:00
|
|
|
nsRegion* aRepaintRegion);
|
1998-08-28 02:54:06 +00:00
|
|
|
NS_IMETHOD HandleEvent(nsIView* aView,
|
|
|
|
nsGUIEvent* aEvent,
|
2006-01-26 02:29:17 +00:00
|
|
|
nsEventStatus* aEventStatus);
|
2010-03-31 12:50:20 +00:00
|
|
|
virtual NS_HIDDEN_(nsresult) HandleDOMEventWithTarget(nsIContent* aTargetContent,
|
|
|
|
nsEvent* aEvent,
|
|
|
|
nsEventStatus* aStatus);
|
|
|
|
virtual NS_HIDDEN_(nsresult) HandleDOMEventWithTarget(nsIContent* aTargetContent,
|
|
|
|
nsIDOMEvent* aEvent,
|
|
|
|
nsEventStatus* aStatus);
|
1998-08-28 02:54:06 +00:00
|
|
|
NS_IMETHOD ResizeReflow(nsIView *aView, nscoord aWidth, nscoord aHeight);
|
2004-10-14 21:51:00 +00:00
|
|
|
NS_IMETHOD_(PRBool) IsVisible();
|
2005-01-20 03:39:09 +00:00
|
|
|
NS_IMETHOD_(void) WillPaint();
|
2008-12-07 21:58:07 +00:00
|
|
|
NS_IMETHOD_(void) DispatchSynthMouseMove(nsGUIEvent *aEvent,
|
|
|
|
PRBool aFlushOnHoverChange);
|
2009-09-13 13:13:16 +00:00
|
|
|
NS_IMETHOD_(void) ClearMouseCapture(nsIView* aView);
|
1998-08-28 02:54:06 +00:00
|
|
|
|
1999-02-13 04:45:44 +00:00
|
|
|
// caret handling
|
2010-03-31 12:47:25 +00:00
|
|
|
virtual NS_HIDDEN_(already_AddRefed<nsCaret>) GetCaret() const;
|
2010-03-31 12:39:31 +00:00
|
|
|
virtual NS_HIDDEN_(void) MaybeInvalidateCaretPosition();
|
2000-05-11 04:25:43 +00:00
|
|
|
NS_IMETHOD SetCaretEnabled(PRBool aInEnable);
|
|
|
|
NS_IMETHOD SetCaretReadOnly(PRBool aReadOnly);
|
1999-08-04 20:46:16 +00:00
|
|
|
NS_IMETHOD GetCaretEnabled(PRBool *aOutEnabled);
|
2003-06-25 01:14:25 +00:00
|
|
|
NS_IMETHOD SetCaretVisibilityDuringSelection(PRBool aVisibility);
|
2008-04-08 18:52:48 +00:00
|
|
|
NS_IMETHOD GetCaretVisible(PRBool *_retval);
|
2008-07-16 10:52:01 +00:00
|
|
|
virtual void SetCaret(nsCaret *aNewCaret);
|
2007-09-22 21:06:58 +00:00
|
|
|
virtual void RestoreCaret();
|
1999-02-13 04:45:44 +00:00
|
|
|
|
2001-12-18 01:29:49 +00:00
|
|
|
NS_IMETHOD SetSelectionFlags(PRInt16 aInEnable);
|
|
|
|
NS_IMETHOD GetSelectionFlags(PRInt16 *aOutEnable);
|
1999-05-17 00:21:18 +00:00
|
|
|
|
1999-12-02 21:45:21 +00:00
|
|
|
// nsISelectionController
|
1999-10-22 00:19:18 +00:00
|
|
|
|
|
|
|
NS_IMETHOD CharacterMove(PRBool aForward, PRBool aExtend);
|
2008-10-16 07:44:32 +00:00
|
|
|
NS_IMETHOD CharacterExtendForDelete();
|
2010-06-04 17:28:19 +00:00
|
|
|
NS_IMETHOD CharacterExtendForBackspace();
|
1999-10-22 00:19:18 +00:00
|
|
|
NS_IMETHOD WordMove(PRBool aForward, PRBool aExtend);
|
2006-07-18 07:28:38 +00:00
|
|
|
NS_IMETHOD WordExtendForDelete(PRBool aForward);
|
1999-10-22 00:19:18 +00:00
|
|
|
NS_IMETHOD LineMove(PRBool aForward, PRBool aExtend);
|
|
|
|
NS_IMETHOD IntraLineMove(PRBool aForward, PRBool aExtend);
|
|
|
|
NS_IMETHOD PageMove(PRBool aForward, PRBool aExtend);
|
|
|
|
NS_IMETHOD ScrollPage(PRBool aForward);
|
1999-12-15 03:54:52 +00:00
|
|
|
NS_IMETHOD ScrollLine(PRBool aForward);
|
|
|
|
NS_IMETHOD ScrollHorizontal(PRBool aLeft);
|
1999-12-11 00:02:08 +00:00
|
|
|
NS_IMETHOD CompleteScroll(PRBool aForward);
|
|
|
|
NS_IMETHOD CompleteMove(PRBool aForward, PRBool aExtend);
|
1999-10-22 00:19:18 +00:00
|
|
|
NS_IMETHOD SelectAll();
|
2000-07-26 11:31:12 +00:00
|
|
|
NS_IMETHOD CheckVisibility(nsIDOMNode *node, PRInt16 startOffset, PRInt16 EndOffset, PRBool *_retval);
|
1999-02-13 04:45:44 +00:00
|
|
|
|
1999-07-14 17:30:07 +00:00
|
|
|
// nsIDocumentObserver
|
2004-01-29 01:45:34 +00:00
|
|
|
virtual void BeginUpdate(nsIDocument* aDocument, nsUpdateType aUpdateType);
|
|
|
|
virtual void EndUpdate(nsIDocument* aDocument, nsUpdateType aUpdateType);
|
|
|
|
virtual void BeginLoad(nsIDocument* aDocument);
|
|
|
|
virtual void EndLoad(nsIDocument* aDocument);
|
|
|
|
virtual void ContentStatesChanged(nsIDocument* aDocument,
|
|
|
|
nsIContent* aContent1,
|
|
|
|
nsIContent* aContent2,
|
|
|
|
PRInt32 aStateMask);
|
2010-03-17 17:10:57 +00:00
|
|
|
virtual void DocumentStatesChanged(nsIDocument* aDocument,
|
|
|
|
PRInt32 aStateMask);
|
2004-01-29 01:45:34 +00:00
|
|
|
virtual void StyleSheetAdded(nsIDocument* aDocument,
|
2004-07-28 07:08:41 +00:00
|
|
|
nsIStyleSheet* aStyleSheet,
|
|
|
|
PRBool aDocumentSheet);
|
2004-01-29 01:45:34 +00:00
|
|
|
virtual void StyleSheetRemoved(nsIDocument* aDocument,
|
2004-07-28 07:08:41 +00:00
|
|
|
nsIStyleSheet* aStyleSheet,
|
|
|
|
PRBool aDocumentSheet);
|
2004-01-29 01:45:34 +00:00
|
|
|
virtual void StyleSheetApplicableStateChanged(nsIDocument* aDocument,
|
|
|
|
nsIStyleSheet* aStyleSheet,
|
|
|
|
PRBool aApplicable);
|
|
|
|
virtual void StyleRuleChanged(nsIDocument* aDocument,
|
|
|
|
nsIStyleSheet* aStyleSheet,
|
|
|
|
nsIStyleRule* aOldStyleRule,
|
|
|
|
nsIStyleRule* aNewStyleRule);
|
|
|
|
virtual void StyleRuleAdded(nsIDocument* aDocument,
|
|
|
|
nsIStyleSheet* aStyleSheet,
|
|
|
|
nsIStyleRule* aStyleRule);
|
|
|
|
virtual void StyleRuleRemoved(nsIDocument* aDocument,
|
|
|
|
nsIStyleSheet* aStyleSheet,
|
|
|
|
nsIStyleRule* aStyleRule);
|
1999-12-23 02:02:33 +00:00
|
|
|
|
2007-07-12 20:05:45 +00:00
|
|
|
// nsIMutationObserver
|
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_CHARACTERDATACHANGED
|
2009-12-10 22:36:03 +00:00
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTEWILLCHANGE
|
2007-07-12 20:05:45 +00:00
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTECHANGED
|
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED
|
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED
|
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED
|
|
|
|
|
2004-07-18 01:16:27 +00:00
|
|
|
NS_DECL_NSIOBSERVER
|
|
|
|
|
2010-02-19 17:11:40 +00:00
|
|
|
// nsARefreshObserver
|
|
|
|
virtual void WillRefresh(mozilla::TimeStamp aTime);
|
|
|
|
|
2000-04-21 14:59:47 +00:00
|
|
|
#ifdef MOZ_REFLOW_PERF
|
2010-03-31 12:45:32 +00:00
|
|
|
virtual NS_HIDDEN_(void) DumpReflows();
|
|
|
|
virtual NS_HIDDEN_(void) CountReflows(const char * aName, nsIFrame * aFrame);
|
|
|
|
virtual NS_HIDDEN_(void) PaintCount(const char * aName,
|
|
|
|
nsIRenderingContext* aRenderingContext,
|
|
|
|
nsPresContext* aPresContext,
|
|
|
|
nsIFrame * aFrame,
|
|
|
|
PRUint32 aColor);
|
|
|
|
virtual NS_HIDDEN_(void) SetPaintFrameCount(PRBool aOn);
|
2009-07-22 00:44:52 +00:00
|
|
|
virtual PRBool IsPaintingFrameCounts();
|
2000-04-21 14:59:47 +00:00
|
|
|
#endif
|
|
|
|
|
2004-01-07 22:30:53 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
virtual void ListStyleContexts(nsIFrame *aRootFrame, FILE *out,
|
|
|
|
PRInt32 aIndent = 0);
|
|
|
|
|
|
|
|
virtual void ListStyleSheets(FILE *out, PRInt32 aIndent = 0);
|
2005-11-06 18:01:17 +00:00
|
|
|
virtual void VerifyStyleTree();
|
2004-01-07 22:30:53 +00:00
|
|
|
#endif
|
|
|
|
|
2001-04-11 03:07:50 +00:00
|
|
|
#ifdef PR_LOGGING
|
|
|
|
static PRLogModuleInfo* gLog;
|
|
|
|
#endif
|
|
|
|
|
2010-03-31 12:45:32 +00:00
|
|
|
virtual NS_HIDDEN_(void) DisableNonTestMouseEvents(PRBool aDisable);
|
2009-02-12 10:44:38 +00:00
|
|
|
|
2009-04-25 08:19:23 +00:00
|
|
|
virtual void UpdateCanvasBackground();
|
|
|
|
|
2009-07-04 09:30:59 +00:00
|
|
|
virtual nsresult AddCanvasBackgroundColorItem(nsDisplayListBuilder& aBuilder,
|
|
|
|
nsDisplayList& aList,
|
|
|
|
nsIFrame* aFrame,
|
|
|
|
nsRect* aBounds,
|
2009-12-01 08:49:53 +00:00
|
|
|
nscolor aBackstopColor,
|
|
|
|
PRBool aForceDraw);
|
2009-07-04 09:30:59 +00:00
|
|
|
|
1998-04-13 20:24:54 +00:00
|
|
|
protected:
|
1999-02-12 17:45:58 +00:00
|
|
|
virtual ~PresShell();
|
1998-04-13 20:24:54 +00:00
|
|
|
|
2009-04-21 23:53:52 +00:00
|
|
|
void HandlePostedReflowCallbacks(PRBool aInterruptible);
|
2007-12-01 07:22:44 +00:00
|
|
|
void CancelPostedReflowCallbacks();
|
2000-06-23 05:15:04 +00:00
|
|
|
|
2001-04-25 19:52:49 +00:00
|
|
|
void UnsuppressAndInvalidate();
|
2000-05-15 03:37:21 +00:00
|
|
|
|
2009-06-28 20:04:35 +00:00
|
|
|
void WillCauseReflow() {
|
|
|
|
nsContentUtils::AddScriptBlocker();
|
|
|
|
++mChangeNestCount;
|
|
|
|
}
|
|
|
|
nsresult DidCauseReflow();
|
|
|
|
friend class nsAutoCauseReflowNotifier;
|
|
|
|
|
2006-04-28 04:33:41 +00:00
|
|
|
void WillDoReflow();
|
2009-04-21 23:53:52 +00:00
|
|
|
void DidDoReflow(PRBool aInterruptible);
|
|
|
|
// ProcessReflowCommands returns whether we processed all our dirty roots
|
|
|
|
// without interruptions.
|
|
|
|
PRBool ProcessReflowCommands(PRBool aInterruptible);
|
2010-02-19 17:11:40 +00:00
|
|
|
// MaybeScheduleReflow checks if posting a reflow is needed, then checks if
|
|
|
|
// the last reflow was interrupted. In the interrupted case ScheduleReflow is
|
2009-06-13 01:28:41 +00:00
|
|
|
// called off a timer, otherwise it is called directly.
|
2010-02-19 17:11:40 +00:00
|
|
|
void MaybeScheduleReflow();
|
|
|
|
// Actually schedules a reflow. This should only be called by
|
|
|
|
// MaybeScheduleReflow and the reflow timer ScheduleReflowOffTimer
|
|
|
|
// sets up.
|
|
|
|
void ScheduleReflow();
|
2009-04-21 23:53:52 +00:00
|
|
|
|
|
|
|
// DoReflow returns whether the reflow finished without interruption
|
|
|
|
PRBool DoReflow(nsIFrame* aFrame, PRBool aInterruptible);
|
2007-04-25 15:49:55 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
void DoVerifyReflow();
|
2007-04-30 06:43:03 +00:00
|
|
|
void VerifyHasDirtyRootAncestor(nsIFrame* aFrame);
|
2007-04-25 15:49:55 +00:00
|
|
|
#endif
|
2004-05-02 18:07:12 +00:00
|
|
|
|
2009-04-21 23:53:52 +00:00
|
|
|
// Helper for ScrollContentIntoView
|
2009-05-10 03:57:53 +00:00
|
|
|
void DoScrollContentIntoView(nsIContent* aContent,
|
|
|
|
PRIntn aVPercent,
|
|
|
|
PRIntn aHPercent);
|
2009-04-21 23:53:52 +00:00
|
|
|
|
2006-03-07 17:08:51 +00:00
|
|
|
friend class nsPresShellEventCB;
|
1999-11-01 22:12:45 +00:00
|
|
|
|
2003-03-12 03:22:11 +00:00
|
|
|
PRBool mCaretEnabled;
|
1999-11-01 22:12:45 +00:00
|
|
|
#ifdef NS_DEBUG
|
2004-01-07 22:30:53 +00:00
|
|
|
nsresult CloneStyleSet(nsStyleSet* aSet, nsStyleSet** aResult);
|
1999-09-10 18:49:23 +00:00
|
|
|
PRBool VerifyIncrementalReflow();
|
1998-11-26 18:11:02 +00:00
|
|
|
PRBool mInVerifyReflow;
|
2006-01-26 02:29:17 +00:00
|
|
|
void ShowEventTargetDebug();
|
1998-07-13 19:49:42 +00:00
|
|
|
#endif
|
1998-05-20 16:24:54 +00:00
|
|
|
|
2000-10-11 08:33:01 +00:00
|
|
|
/**
|
|
|
|
* methods that manage rules that are used to implement the associated preferences
|
|
|
|
* - initially created for bugs 31816, 20760, 22963
|
|
|
|
*/
|
|
|
|
nsresult ClearPreferenceStyleRules(void);
|
|
|
|
nsresult CreatePreferenceStyleSheet(void);
|
|
|
|
nsresult SetPrefLinkRules(void);
|
2001-04-09 22:17:11 +00:00
|
|
|
nsresult SetPrefFocusRules(void);
|
2003-06-26 06:10:03 +00:00
|
|
|
nsresult SetPrefNoScriptRule();
|
2005-03-03 18:04:38 +00:00
|
|
|
nsresult SetPrefNoFramesRule(void);
|
|
|
|
|
2007-03-20 12:14:52 +00:00
|
|
|
// methods for painting a range to an offscreen buffer
|
|
|
|
|
|
|
|
// given a display list, clip the items within the list to
|
|
|
|
// the range
|
|
|
|
nsRect ClipListToRange(nsDisplayListBuilder *aBuilder,
|
|
|
|
nsDisplayList* aList,
|
2007-08-17 03:43:00 +00:00
|
|
|
nsIRange* aRange);
|
2007-03-20 12:14:52 +00:00
|
|
|
|
|
|
|
// create a RangePaintInfo for the range aRange containing the
|
|
|
|
// display list needed to paint the range to a surface
|
|
|
|
RangePaintInfo* CreateRangePaintInfo(nsIDOMRange* aRange,
|
|
|
|
nsRect& aSurfaceRect);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Paint the items to a new surface and return it.
|
|
|
|
*
|
|
|
|
* aSelection - selection being painted, if any
|
|
|
|
* aRegion - clip region, if any
|
|
|
|
* aArea - area that the surface occupies, relative to the root frame
|
|
|
|
* aPoint - reference point, typically the mouse position
|
|
|
|
* aScreenRect - [out] set to the area of the screen the painted area should
|
|
|
|
* be displayed at
|
|
|
|
*/
|
|
|
|
already_AddRefed<gfxASurface>
|
|
|
|
PaintRangePaintInfo(nsTArray<nsAutoPtr<RangePaintInfo> >* aItems,
|
|
|
|
nsISelection* aSelection,
|
2010-06-05 20:29:49 +00:00
|
|
|
nsIntRegion* aRegion,
|
2007-03-20 12:14:52 +00:00
|
|
|
nsRect aArea,
|
2009-01-15 03:27:09 +00:00
|
|
|
nsIntPoint& aPoint,
|
|
|
|
nsIntRect* aScreenRect);
|
2007-03-20 12:14:52 +00:00
|
|
|
|
2006-06-08 14:32:20 +00:00
|
|
|
/**
|
|
|
|
* Methods to handle changes to user and UA sheet lists that we get
|
|
|
|
* notified about.
|
|
|
|
*/
|
|
|
|
void AddUserSheet(nsISupports* aSheet);
|
|
|
|
void AddAgentSheet(nsISupports* aSheet);
|
|
|
|
void RemoveSheet(nsStyleSet::sheetType aType, nsISupports* aSheet);
|
|
|
|
|
2007-04-20 18:20:03 +00:00
|
|
|
// Hide a view if it is a popup
|
|
|
|
void HideViewIfPopup(nsIView* aView);
|
|
|
|
|
2007-04-26 02:33:02 +00:00
|
|
|
// Utility method to restore the root scrollframe state
|
|
|
|
void RestoreRootScrollPosition();
|
|
|
|
|
2009-12-10 18:58:33 +00:00
|
|
|
void MaybeReleaseCapturingContent()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsFrameSelection> frameSelection = FrameSelection();
|
|
|
|
if (frameSelection) {
|
|
|
|
frameSelection->SetMouseDownState(PR_FALSE);
|
|
|
|
}
|
|
|
|
if (gCaptureInfo.mContent &&
|
|
|
|
gCaptureInfo.mContent->GetOwnerDoc() == mDocument) {
|
|
|
|
SetCapturingContent(nsnull, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-11 20:41:47 +00:00
|
|
|
nsRefPtr<nsCSSStyleSheet> mPrefStyleSheet; // mStyleSet owns it but we
|
|
|
|
// maintain a ref, may be null
|
2004-12-02 01:26:20 +00:00
|
|
|
#ifdef DEBUG
|
2001-12-14 23:13:08 +00:00
|
|
|
PRUint32 mUpdateCount;
|
2004-12-02 01:26:20 +00:00
|
|
|
#endif
|
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 05:38:33 +00:00
|
|
|
// reflow roots that need to be reflowed, as both a queue and a hashtable
|
2009-02-03 14:42:18 +00:00
|
|
|
nsTArray<nsIFrame*> mDirtyRoots;
|
2001-03-13 06:38:59 +00:00
|
|
|
|
2000-05-16 01:11:29 +00:00
|
|
|
PRPackedBool mDocumentLoading;
|
2001-12-14 23:13:08 +00:00
|
|
|
|
2001-12-01 00:22:00 +00:00
|
|
|
PRPackedBool mIgnoreFrameDestruction;
|
2004-02-25 09:10:06 +00:00
|
|
|
PRPackedBool mHaveShutDown;
|
2009-06-28 20:04:35 +00:00
|
|
|
|
|
|
|
// This is used to protect ourselves from triggering reflow while in the
|
|
|
|
// middle of frame construction and the like... it really shouldn't be
|
|
|
|
// needed, one hopes, but it is for now.
|
|
|
|
PRUint32 mChangeNestCount;
|
2005-01-20 03:39:09 +00:00
|
|
|
|
2001-12-14 23:13:08 +00:00
|
|
|
nsIFrame* mCurrentEventFrame;
|
2004-09-13 03:22:46 +00:00
|
|
|
nsCOMPtr<nsIContent> mCurrentEventContent;
|
2009-02-03 14:42:18 +00:00
|
|
|
nsTArray<nsIFrame*> mCurrentEventFrameStack;
|
2004-09-13 03:22:46 +00:00
|
|
|
nsCOMArray<nsIContent> mCurrentEventContentStack;
|
2000-04-24 04:41:27 +00:00
|
|
|
|
2008-02-27 10:01:17 +00:00
|
|
|
nsCOMPtr<nsIContent> mLastAnchorScrolledTo;
|
|
|
|
nscoord mLastAnchorScrollPositionY;
|
2008-07-16 10:52:01 +00:00
|
|
|
nsRefPtr<nsCaret> mCaret;
|
|
|
|
nsRefPtr<nsCaret> mOriginalCaret;
|
2009-08-18 03:21:06 +00:00
|
|
|
nsPresArena mFrameArena;
|
2007-01-17 23:53:47 +00:00
|
|
|
StackArena mStackArena;
|
2000-06-14 23:18:54 +00:00
|
|
|
nsCOMPtr<nsIDragService> mDragService;
|
2006-05-10 17:30:15 +00:00
|
|
|
|
2009-04-21 23:53:52 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
// The reflow root under which we're currently reflowing. Null when
|
|
|
|
// not in reflow.
|
|
|
|
nsIFrame* mCurrentReflowRoot;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Set of frames that we should mark with NS_FRAME_HAS_DIRTY_CHILDREN after
|
|
|
|
// we finish reflowing mCurrentReflowRoot.
|
|
|
|
nsTHashtable< nsPtrHashKey<nsIFrame> > mFramesToDirty;
|
|
|
|
|
|
|
|
// Information needed to properly handle scrolling content into view if the
|
|
|
|
// pre-scroll reflow flush can be interrupted. mContentToScrollTo is
|
|
|
|
// non-null between the initial scroll attempt and the first time we finish
|
|
|
|
// processing all our dirty roots. mContentScrollVPosition and
|
|
|
|
// mContentScrollHPosition are only used when it's non-null.
|
|
|
|
nsCOMPtr<nsIContent> mContentToScrollTo;
|
|
|
|
PRIntn mContentScrollVPosition;
|
|
|
|
PRIntn mContentScrollHPosition;
|
|
|
|
|
2009-05-18 09:17:45 +00:00
|
|
|
class nsDelayedEvent
|
2009-03-03 20:20:11 +00:00
|
|
|
{
|
2009-05-18 09:17:45 +00:00
|
|
|
public:
|
|
|
|
virtual ~nsDelayedEvent() {};
|
|
|
|
virtual void Dispatch(PresShell* aShell) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
class nsDelayedInputEvent : public nsDelayedEvent
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual void Dispatch(PresShell* aShell)
|
|
|
|
{
|
|
|
|
if (mEvent && mEvent->widget) {
|
|
|
|
nsCOMPtr<nsIWidget> w = mEvent->widget;
|
|
|
|
nsEventStatus status;
|
|
|
|
w->DispatchEvent(mEvent, status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void Init(nsInputEvent* aEvent)
|
|
|
|
{
|
|
|
|
mEvent->time = aEvent->time;
|
|
|
|
mEvent->refPoint = aEvent->refPoint;
|
|
|
|
mEvent->isShift = aEvent->isShift;
|
|
|
|
mEvent->isControl = aEvent->isControl;
|
|
|
|
mEvent->isAlt = aEvent->isAlt;
|
|
|
|
mEvent->isMeta = aEvent->isMeta;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsDelayedInputEvent()
|
|
|
|
: nsDelayedEvent(), mEvent(nsnull) {}
|
|
|
|
|
|
|
|
nsInputEvent* mEvent;
|
|
|
|
};
|
|
|
|
|
|
|
|
class nsDelayedMouseEvent : public nsDelayedInputEvent
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsDelayedMouseEvent(nsMouseEvent* aEvent) : nsDelayedInputEvent()
|
|
|
|
{
|
|
|
|
mEvent = new nsMouseEvent(NS_IS_TRUSTED_EVENT(aEvent),
|
|
|
|
aEvent->message,
|
|
|
|
aEvent->widget,
|
|
|
|
aEvent->reason,
|
|
|
|
aEvent->context);
|
|
|
|
if (mEvent) {
|
|
|
|
Init(aEvent);
|
|
|
|
static_cast<nsMouseEvent*>(mEvent)->clickCount = aEvent->clickCount;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~nsDelayedMouseEvent()
|
|
|
|
{
|
|
|
|
delete static_cast<nsMouseEvent*>(mEvent);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class nsDelayedKeyEvent : public nsDelayedInputEvent
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsDelayedKeyEvent(nsKeyEvent* aEvent) : nsDelayedInputEvent()
|
|
|
|
{
|
|
|
|
mEvent = new nsKeyEvent(NS_IS_TRUSTED_EVENT(aEvent),
|
|
|
|
aEvent->message,
|
|
|
|
aEvent->widget);
|
|
|
|
if (mEvent) {
|
|
|
|
Init(aEvent);
|
|
|
|
static_cast<nsKeyEvent*>(mEvent)->keyCode = aEvent->keyCode;
|
|
|
|
static_cast<nsKeyEvent*>(mEvent)->charCode = aEvent->charCode;
|
|
|
|
static_cast<nsKeyEvent*>(mEvent)->alternativeCharCodes =
|
|
|
|
aEvent->alternativeCharCodes;
|
|
|
|
static_cast<nsKeyEvent*>(mEvent)->isChar = aEvent->isChar;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~nsDelayedKeyEvent()
|
|
|
|
{
|
|
|
|
delete static_cast<nsKeyEvent*>(mEvent);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
PRPackedBool mNoDelayedMouseEvents;
|
|
|
|
PRPackedBool mNoDelayedKeyEvents;
|
|
|
|
nsTArray<nsAutoPtr<nsDelayedEvent> > mDelayedEvents;
|
2009-03-03 20:11:14 +00:00
|
|
|
|
2000-07-13 23:00:59 +00:00
|
|
|
nsCallbackEventRequest* mFirstCallbackEventRequest;
|
|
|
|
nsCallbackEventRequest* mLastCallbackEventRequest;
|
2000-06-23 05:15:04 +00:00
|
|
|
|
2009-04-21 23:53:52 +00:00
|
|
|
PRPackedBool mSuppressInterruptibleReflows;
|
|
|
|
|
2001-12-14 23:13:08 +00:00
|
|
|
PRPackedBool mIsDocumentGone; // We've been disconnected from the document.
|
|
|
|
// We will refuse to paint the document until either
|
|
|
|
// (a) our timer fires or (b) all frames are constructed.
|
|
|
|
PRPackedBool mShouldUnsuppressPainting; // Indicates that it is safe to unlock painting once all pending
|
|
|
|
// reflows have been processed.
|
2010-02-19 17:11:40 +00:00
|
|
|
PRPackedBool mReflowScheduled; // If true, we have a reflow scheduled.
|
|
|
|
// Guaranteed to be false if
|
|
|
|
// mReflowContinueTimer is non-null.
|
2001-04-25 19:52:49 +00:00
|
|
|
nsCOMPtr<nsITimer> mPaintSuppressionTimer; // This timer controls painting suppression. Until it fires
|
|
|
|
// or all frames are constructed, we won't paint anything but
|
|
|
|
// our <body> background and scrollbars.
|
2002-12-26 21:03:23 +00:00
|
|
|
#define PAINTLOCK_EVENT_DELAY 250 // 250ms. This is actually
|
|
|
|
// pref-controlled, but we use this
|
|
|
|
// value if we fail to get the pref
|
|
|
|
// for any reason.
|
2001-04-25 19:52:49 +00:00
|
|
|
|
|
|
|
static void sPaintSuppressionCallback(nsITimer* aTimer, void* aPresShell); // A callback for the timer.
|
|
|
|
|
2010-02-19 17:11:40 +00:00
|
|
|
// At least on Win32 and Mac after interupting a reflow we need to post
|
|
|
|
// the resume reflow event off a timer to avoid event starvation because
|
|
|
|
// posted messages are processed before other messages when the modal
|
|
|
|
// moving/sizing loop is running, see bug 491700 for details.
|
2009-06-13 01:28:41 +00:00
|
|
|
nsCOMPtr<nsITimer> mReflowContinueTimer;
|
|
|
|
static void sReflowContinueCallback(nsITimer* aTimer, void* aPresShell);
|
2010-02-19 17:11:40 +00:00
|
|
|
PRBool ScheduleReflowOffTimer();
|
2009-08-28 18:03:51 +00:00
|
|
|
|
2000-04-21 14:59:47 +00:00
|
|
|
#ifdef MOZ_REFLOW_PERF
|
|
|
|
ReflowCountMgr * mReflowCountMgr;
|
|
|
|
#endif
|
|
|
|
|
2009-02-12 10:44:38 +00:00
|
|
|
static PRBool sDisableNonTestMouseEvents;
|
|
|
|
|
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 18:00:39 +00:00
|
|
|
// false if a check should be done for key/ime events that should be
|
|
|
|
// retargeted to the currently focused presshell
|
|
|
|
static PRBool sDontRetargetEvents;
|
|
|
|
|
2001-04-18 06:06:31 +00:00
|
|
|
private:
|
|
|
|
|
2003-01-07 02:09:06 +00:00
|
|
|
PRBool InZombieDocument(nsIContent *aContent);
|
2006-10-27 00:01:19 +00:00
|
|
|
nsresult RetargetEventToParent(nsGUIEvent* aEvent,
|
|
|
|
nsEventStatus* aEventStatus);
|
2003-01-07 02:09:06 +00:00
|
|
|
|
1999-09-02 18:14:01 +00:00
|
|
|
//helper funcs for event handling
|
2006-03-07 17:08:51 +00:00
|
|
|
protected:
|
|
|
|
//protected because nsPresShellEventCB needs this.
|
1999-06-15 03:14:28 +00:00
|
|
|
nsIFrame* GetCurrentEventFrame();
|
2006-03-07 17:08:51 +00:00
|
|
|
private:
|
2000-04-24 04:41:27 +00:00
|
|
|
void PushCurrentEventInfo(nsIFrame* aFrame, nsIContent* aContent);
|
|
|
|
void PopCurrentEventInfo();
|
2006-03-07 17:08:51 +00:00
|
|
|
nsresult HandleEventInternal(nsEvent* aEvent, nsIView* aView,
|
|
|
|
nsEventStatus *aStatus);
|
2006-01-26 02:29:17 +00:00
|
|
|
nsresult HandlePositionedEvent(nsIView* aView,
|
|
|
|
nsIFrame* aTargetFrame,
|
|
|
|
nsGUIEvent* aEvent,
|
|
|
|
nsEventStatus* aEventStatus);
|
2009-12-17 18:42:02 +00:00
|
|
|
// This returns the focused DOM window under our top level window.
|
|
|
|
// I.e., when we are deactive, this returns the *last* focused DOM window.
|
|
|
|
already_AddRefed<nsPIDOMWindow> GetFocusedDOMWindowInOurWindow();
|
2001-04-17 23:25:21 +00:00
|
|
|
|
2009-01-17 20:50:00 +00:00
|
|
|
/*
|
|
|
|
* This and the next two helper methods are used to target and position the
|
|
|
|
* context menu when the keyboard shortcut is used to open it.
|
|
|
|
*
|
|
|
|
* If another menu is open, the context menu is opened relative to the
|
|
|
|
* active menuitem within the menu, or the menu itself if no item is active.
|
|
|
|
* Otherwise, if the caret is visible, the menu is opened near the caret.
|
|
|
|
* Otherwise, if a selectable list such as a listbox is focused, the
|
|
|
|
* current item within the menu is opened relative to this item.
|
|
|
|
* Otherwise, the context menu is opened at the topleft corner of the
|
|
|
|
* view.
|
|
|
|
*
|
|
|
|
* Returns true if the context menu event should fire and false if it should
|
|
|
|
* not.
|
|
|
|
*/
|
|
|
|
PRBool AdjustContextMenuKeyEvent(nsMouseEvent* aEvent);
|
|
|
|
|
|
|
|
//
|
2009-01-17 21:14:18 +00:00
|
|
|
PRBool PrepareToUseCaretPosition(nsIWidget* aEventWidget, nsIntPoint& aTargetPt);
|
2009-01-17 20:50:00 +00:00
|
|
|
|
|
|
|
// Get the selected item and coordinates in device pixels relative to root
|
2009-07-22 00:45:08 +00:00
|
|
|
// document's root view for element, first ensuring the element is onscreen
|
2009-01-17 20:50:00 +00:00
|
|
|
void GetCurrentItemAndPositionForElement(nsIDOMElement *aCurrentEl,
|
|
|
|
nsIContent **aTargetToUse,
|
2009-01-17 21:14:18 +00:00
|
|
|
nsIntPoint& aTargetPt);
|
2009-01-17 20:50:00 +00:00
|
|
|
|
2001-04-17 23:25:21 +00:00
|
|
|
void FireResizeEvent();
|
2009-08-15 08:49:20 +00:00
|
|
|
static void AsyncResizeEventCallback(nsITimer* aTimer, void* aPresShell);
|
2009-01-14 20:42:25 +00:00
|
|
|
nsRevocableEventPtr<nsRunnableMethod<PresShell> > mResizeEvent;
|
2009-08-15 08:49:20 +00:00
|
|
|
nsCOMPtr<nsITimer> mAsyncResizeEventTimer;
|
|
|
|
PRPackedBool mAsyncResizeTimerIsActive;
|
|
|
|
PRPackedBool mInResize;
|
2005-05-04 20:22:32 +00:00
|
|
|
|
2009-07-04 09:30:59 +00:00
|
|
|
private:
|
|
|
|
/*
|
|
|
|
* Computes the backstop color for the view: transparent if in a transparent
|
|
|
|
* widget, otherwise the PresContext default background color. This color is
|
|
|
|
* only visible if the contents of the view as a whole are translucent.
|
|
|
|
*/
|
2010-03-01 08:03:49 +00:00
|
|
|
nscolor ComputeBackstopColor(nsIView* aDisplayRoot);
|
2009-09-15 22:00:04 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
// Ensure that every allocation from the PresArena is eventually freed.
|
|
|
|
PRUint32 mPresArenaAllocCount;
|
|
|
|
#endif
|
2010-06-01 02:19:35 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
PRUint32 EstimateMemoryUsed() {
|
|
|
|
PRUint32 result = 0;
|
|
|
|
|
|
|
|
result += sizeof(PresShell);
|
|
|
|
result += mStackArena.Size();
|
|
|
|
result += mFrameArena.Size();
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static PLDHashOperator LiveShellSizeEnumerator(PresShellPtrKey *aEntry,
|
|
|
|
void *userArg)
|
|
|
|
{
|
|
|
|
PresShell *aShell = static_cast<PresShell*>(aEntry->GetKey());
|
|
|
|
PRUint32 *val = (PRUint32*)userArg;
|
|
|
|
*val += aShell->EstimateMemoryUsed();
|
|
|
|
*val += aShell->mPresContext->EstimateMemoryUsed();
|
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
|
|
|
static PLDHashOperator LiveShellBidiSizeEnumerator(PresShellPtrKey *aEntry,
|
|
|
|
void *userArg)
|
|
|
|
{
|
|
|
|
PresShell *aShell = static_cast<PresShell*>(aEntry->GetKey());
|
|
|
|
PRUint32 *val = (PRUint32*)userArg;
|
|
|
|
*val += aShell->mPresContext->GetBidiMemoryUsed();
|
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
|
|
|
static PRUint32
|
|
|
|
EstimateShellsMemory(nsTHashtable<PresShellPtrKey>::Enumerator aEnumerator)
|
|
|
|
{
|
|
|
|
PRUint32 result = 0;
|
|
|
|
sLiveShells->EnumerateEntries(aEnumerator, &result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static PRInt64 SizeOfLayoutMemoryReporter(void *) {
|
|
|
|
return EstimateShellsMemory(LiveShellSizeEnumerator);
|
|
|
|
}
|
|
|
|
|
|
|
|
static PRInt64 SizeOfBidiMemoryReporter(void *) {
|
|
|
|
return EstimateShellsMemory(LiveShellBidiSizeEnumerator);
|
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
};
|
|
|
|
|
2009-06-28 20:04:35 +00:00
|
|
|
class nsAutoCauseReflowNotifier
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsAutoCauseReflowNotifier(PresShell* aShell)
|
|
|
|
: mShell(aShell)
|
|
|
|
{
|
|
|
|
mShell->WillCauseReflow();
|
|
|
|
}
|
|
|
|
~nsAutoCauseReflowNotifier()
|
|
|
|
{
|
|
|
|
// This check should not be needed. Currently the only place that seem
|
|
|
|
// to need it is the code that deals with bug 337586.
|
|
|
|
if (!mShell->mHaveShutDown) {
|
|
|
|
mShell->DidCauseReflow();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
nsContentUtils::RemoveScriptBlocker();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PresShell* mShell;
|
|
|
|
};
|
|
|
|
|
2008-07-01 01:03:50 +00:00
|
|
|
class NS_STACK_CLASS nsPresShellEventCB : public nsDispatchingCallback
|
2006-03-07 17:08:51 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsPresShellEventCB(PresShell* aPresShell) : mPresShell(aPresShell) {}
|
|
|
|
|
|
|
|
virtual void HandleEvent(nsEventChainPostVisitor& aVisitor)
|
|
|
|
{
|
|
|
|
if (aVisitor.mPresContext && aVisitor.mEvent->eventStructType != NS_EVENT) {
|
|
|
|
nsIFrame* frame = mPresShell->GetCurrentEventFrame();
|
|
|
|
if (frame) {
|
|
|
|
frame->HandleEvent(aVisitor.mPresContext,
|
|
|
|
(nsGUIEvent*) aVisitor.mEvent,
|
|
|
|
&aVisitor.mEventStatus);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<PresShell> mPresShell;
|
|
|
|
};
|
|
|
|
|
2009-02-12 10:44:38 +00:00
|
|
|
PRBool PresShell::sDisableNonTestMouseEvents = PR_FALSE;
|
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 18:00:39 +00:00
|
|
|
PRBool PresShell::sDontRetargetEvents = PR_FALSE;
|
2009-02-12 10:44:38 +00:00
|
|
|
|
2001-04-11 03:07:50 +00:00
|
|
|
#ifdef PR_LOGGING
|
|
|
|
PRLogModuleInfo* PresShell::gLog;
|
|
|
|
#endif
|
|
|
|
|
1999-09-21 07:53:49 +00:00
|
|
|
#ifdef NS_DEBUG
|
|
|
|
static void
|
2004-07-31 23:15:21 +00:00
|
|
|
VerifyStyleTree(nsPresContext* aPresContext, nsFrameManager* aFrameManager)
|
1999-09-21 07:53:49 +00:00
|
|
|
{
|
2009-08-20 21:52:48 +00:00
|
|
|
if (nsFrame::GetVerifyStyleTreeEnable()) {
|
2004-02-23 21:29:06 +00:00
|
|
|
nsIFrame* rootFrame = aFrameManager->GetRootFrame();
|
2003-06-20 01:05:04 +00:00
|
|
|
aFrameManager->DebugVerifyStyleTree(rootFrame);
|
1999-09-21 07:53:49 +00:00
|
|
|
}
|
|
|
|
}
|
2005-11-06 18:01:17 +00:00
|
|
|
#define VERIFY_STYLE_TREE ::VerifyStyleTree(mPresContext, FrameManager())
|
1999-09-21 07:53:49 +00:00
|
|
|
#else
|
|
|
|
#define VERIFY_STYLE_TREE
|
|
|
|
#endif
|
|
|
|
|
1999-09-10 18:49:23 +00:00
|
|
|
static PRBool gVerifyReflowEnabled;
|
|
|
|
|
2001-10-23 01:37:21 +00:00
|
|
|
PRBool
|
1998-07-13 19:49:42 +00:00
|
|
|
nsIPresShell::GetVerifyReflowEnable()
|
|
|
|
{
|
|
|
|
#ifdef NS_DEBUG
|
1999-09-10 18:49:23 +00:00
|
|
|
static PRBool firstTime = PR_TRUE;
|
|
|
|
if (firstTime) {
|
|
|
|
firstTime = PR_FALSE;
|
2001-06-27 04:04:04 +00:00
|
|
|
char* flags = PR_GetEnv("GECKO_VERIFY_REFLOW_FLAGS");
|
|
|
|
if (flags) {
|
|
|
|
PRBool error = PR_FALSE;
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
char* comma = PL_strchr(flags, ',');
|
|
|
|
if (comma)
|
|
|
|
*comma = '\0';
|
|
|
|
|
|
|
|
PRBool found = PR_FALSE;
|
2004-01-21 04:15:00 +00:00
|
|
|
const VerifyReflowFlags* flag = gFlags;
|
|
|
|
const VerifyReflowFlags* limit = gFlags + NUM_VERIFY_REFLOW_FLAGS;
|
2001-06-27 04:04:04 +00:00
|
|
|
while (flag < limit) {
|
|
|
|
if (PL_strcasecmp(flag->name, flags) == 0) {
|
|
|
|
gVerifyReflowFlags |= flag->bit;
|
|
|
|
found = PR_TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
++flag;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! found)
|
|
|
|
error = PR_TRUE;
|
|
|
|
|
|
|
|
if (! comma)
|
|
|
|
break;
|
|
|
|
|
|
|
|
*comma = ',';
|
|
|
|
flags = comma + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (error)
|
|
|
|
ShowVerifyReflowFlags();
|
|
|
|
}
|
|
|
|
|
1999-09-10 18:49:23 +00:00
|
|
|
if (VERIFY_REFLOW_ON & gVerifyReflowFlags) {
|
|
|
|
gVerifyReflowEnabled = PR_TRUE;
|
2007-07-07 23:52:59 +00:00
|
|
|
|
|
|
|
printf("Note: verifyreflow is enabled");
|
|
|
|
if (VERIFY_REFLOW_NOISY & gVerifyReflowFlags) {
|
|
|
|
printf(" (noisy)");
|
|
|
|
}
|
|
|
|
if (VERIFY_REFLOW_ALL & gVerifyReflowFlags) {
|
|
|
|
printf(" (all)");
|
|
|
|
}
|
|
|
|
if (VERIFY_REFLOW_DUMP_COMMANDS & gVerifyReflowFlags) {
|
|
|
|
printf(" (show reflow commands)");
|
|
|
|
}
|
|
|
|
if (VERIFY_REFLOW_NOISY_RC & gVerifyReflowFlags) {
|
|
|
|
printf(" (noisy reflow commands)");
|
|
|
|
if (VERIFY_REFLOW_REALLY_NOISY_RC & gVerifyReflowFlags) {
|
|
|
|
printf(" (REALLY noisy reflow commands)");
|
|
|
|
}
|
1999-10-05 14:51:12 +00:00
|
|
|
}
|
2007-07-07 23:52:59 +00:00
|
|
|
printf("\n");
|
1999-09-15 00:27:05 +00:00
|
|
|
}
|
1998-07-13 19:49:42 +00:00
|
|
|
}
|
|
|
|
#endif
|
1999-09-10 18:49:23 +00:00
|
|
|
return gVerifyReflowEnabled;
|
1998-07-13 19:49:42 +00:00
|
|
|
}
|
|
|
|
|
2001-10-23 01:37:21 +00:00
|
|
|
void
|
1998-07-13 19:49:42 +00:00
|
|
|
nsIPresShell::SetVerifyReflowEnable(PRBool aEnabled)
|
|
|
|
{
|
1999-09-10 18:49:23 +00:00
|
|
|
gVerifyReflowEnabled = aEnabled;
|
1998-07-13 19:49:42 +00:00
|
|
|
}
|
|
|
|
|
2009-11-16 14:03:53 +00:00
|
|
|
/* virtual */ void
|
|
|
|
nsIPresShell::AddWeakFrameExternal(nsWeakFrame* aWeakFrame)
|
|
|
|
{
|
|
|
|
AddWeakFrameInternal(aWeakFrame);
|
|
|
|
}
|
|
|
|
|
2006-07-12 07:41:11 +00:00
|
|
|
void
|
2009-11-16 14:03:53 +00:00
|
|
|
nsIPresShell::AddWeakFrameInternal(nsWeakFrame* aWeakFrame)
|
2006-07-12 07:41:11 +00:00
|
|
|
{
|
|
|
|
if (aWeakFrame->GetFrame()) {
|
|
|
|
aWeakFrame->GetFrame()->AddStateBits(NS_FRAME_EXTERNAL_REFERENCE);
|
|
|
|
}
|
|
|
|
aWeakFrame->SetPreviousWeakFrame(mWeakFrames);
|
|
|
|
mWeakFrames = aWeakFrame;
|
|
|
|
}
|
|
|
|
|
2009-11-16 14:03:53 +00:00
|
|
|
/* virtual */ void
|
|
|
|
nsIPresShell::RemoveWeakFrameExternal(nsWeakFrame* aWeakFrame)
|
|
|
|
{
|
|
|
|
RemoveWeakFrameInternal(aWeakFrame);
|
|
|
|
}
|
|
|
|
|
2006-07-12 07:41:11 +00:00
|
|
|
void
|
2009-11-16 14:03:53 +00:00
|
|
|
nsIPresShell::RemoveWeakFrameInternal(nsWeakFrame* aWeakFrame)
|
2006-07-12 07:41:11 +00:00
|
|
|
{
|
|
|
|
if (mWeakFrames == aWeakFrame) {
|
|
|
|
mWeakFrames = aWeakFrame->GetPreviousWeakFrame();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
nsWeakFrame* nextWeak = mWeakFrames;
|
|
|
|
while (nextWeak && nextWeak->GetPreviousWeakFrame() != aWeakFrame) {
|
|
|
|
nextWeak = nextWeak->GetPreviousWeakFrame();
|
|
|
|
}
|
|
|
|
if (nextWeak) {
|
|
|
|
nextWeak->SetPreviousWeakFrame(aWeakFrame->GetPreviousWeakFrame());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-22 20:47:33 +00:00
|
|
|
already_AddRefed<nsFrameSelection>
|
|
|
|
nsIPresShell::FrameSelection()
|
|
|
|
{
|
|
|
|
NS_IF_ADDREF(mSelection);
|
|
|
|
return mSelection;
|
|
|
|
}
|
|
|
|
|
1998-04-13 20:24:54 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2001-10-23 01:37:21 +00:00
|
|
|
nsresult
|
1998-07-13 19:49:42 +00:00
|
|
|
NS_NewPresShell(nsIPresShell** aInstancePtrResult)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aInstancePtrResult, "null ptr");
|
2010-03-31 12:47:25 +00:00
|
|
|
|
|
|
|
if (!aInstancePtrResult)
|
1998-07-13 19:49:42 +00:00
|
|
|
return NS_ERROR_NULL_POINTER;
|
2010-03-31 12:47:25 +00:00
|
|
|
|
|
|
|
*aInstancePtrResult = new PresShell();
|
|
|
|
if (!*aInstancePtrResult)
|
1998-07-13 19:49:42 +00:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2010-03-31 12:47:25 +00:00
|
|
|
|
|
|
|
NS_ADDREF(*aInstancePtrResult);
|
|
|
|
return NS_OK;
|
1998-07-13 19:49:42 +00:00
|
|
|
}
|
|
|
|
|
2010-06-01 02:19:35 +00:00
|
|
|
nsTHashtable<PresShell::PresShellPtrKey> *nsIPresShell::sLiveShells = 0;
|
|
|
|
|
|
|
|
NS_MEMORY_REPORTER_IMPLEMENT(LayoutPresShell,
|
|
|
|
"layout/all",
|
|
|
|
"Memory in use by layout PresShell, PresContext, and other related areas.",
|
|
|
|
PresShell::SizeOfLayoutMemoryReporter,
|
2010-06-01 02:47:42 +00:00
|
|
|
nsnull)
|
2010-06-01 02:19:35 +00:00
|
|
|
|
|
|
|
NS_MEMORY_REPORTER_IMPLEMENT(LayoutBidi,
|
|
|
|
"layout/bidi",
|
|
|
|
"Memory in use by layout Bidi processor.",
|
|
|
|
PresShell::SizeOfBidiMemoryReporter,
|
2010-06-01 02:47:42 +00:00
|
|
|
nsnull)
|
2010-06-01 02:19:35 +00:00
|
|
|
|
2004-08-29 03:08:44 +00:00
|
|
|
PresShell::PresShell()
|
2001-12-01 00:22:00 +00:00
|
|
|
{
|
2004-08-29 03:08:44 +00:00
|
|
|
mSelection = nsnull;
|
2000-04-21 14:59:47 +00:00
|
|
|
#ifdef MOZ_REFLOW_PERF
|
|
|
|
mReflowCountMgr = new ReflowCountMgr();
|
2001-02-22 13:58:17 +00:00
|
|
|
mReflowCountMgr->SetPresContext(mPresContext);
|
|
|
|
mReflowCountMgr->SetPresShell(this);
|
2000-04-21 14:59:47 +00:00
|
|
|
#endif
|
2001-04-11 03:07:50 +00:00
|
|
|
#ifdef PR_LOGGING
|
|
|
|
if (! gLog)
|
|
|
|
gLog = PR_NewLogModule("PresShell");
|
|
|
|
#endif
|
2002-09-11 03:03:49 +00:00
|
|
|
mSelectionFlags = nsISelectionDisplay::DISPLAY_TEXT | nsISelectionDisplay::DISPLAY_IMAGES;
|
2002-09-21 01:03:38 +00:00
|
|
|
mIsThemeSupportDisabled = PR_FALSE;
|
2009-09-15 22:00:04 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
mPresArenaAllocCount = 0;
|
|
|
|
#endif
|
2004-03-06 04:46:11 +00:00
|
|
|
|
2010-06-01 02:19:35 +00:00
|
|
|
static bool registeredReporter = false;
|
|
|
|
if (!registeredReporter) {
|
|
|
|
NS_RegisterMemoryReporter(new NS_MEMORY_REPORTER_NAME(LayoutPresShell));
|
|
|
|
NS_RegisterMemoryReporter(new NS_MEMORY_REPORTER_NAME(LayoutBidi));
|
|
|
|
registeredReporter = true;
|
|
|
|
}
|
|
|
|
|
2004-03-06 04:46:11 +00:00
|
|
|
new (this) nsFrameManager();
|
2010-06-01 02:19:35 +00:00
|
|
|
|
|
|
|
sLiveShells->PutEntry(this);
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
2006-07-02 07:23:10 +00:00
|
|
|
NS_IMPL_ISUPPORTS8(PresShell, nsIPresShell, nsIDocumentObserver,
|
2004-09-01 05:16:00 +00:00
|
|
|
nsIViewObserver, nsISelectionController,
|
2006-07-02 07:23:10 +00:00
|
|
|
nsISelectionDisplay, nsIObserver, nsISupportsWeakReference,
|
|
|
|
nsIMutationObserver)
|
1998-04-13 20:24:54 +00:00
|
|
|
|
|
|
|
PresShell::~PresShell()
|
|
|
|
{
|
2010-06-01 02:19:35 +00:00
|
|
|
sLiveShells->RemoveEntry(this);
|
|
|
|
|
2004-02-25 09:10:06 +00:00
|
|
|
if (!mHaveShutDown) {
|
2001-08-01 03:15:50 +00:00
|
|
|
NS_NOTREACHED("Someone did not call nsIPresShell::destroy");
|
|
|
|
Destroy();
|
2001-07-26 20:53:21 +00:00
|
|
|
}
|
|
|
|
|
2002-06-20 20:14:59 +00:00
|
|
|
NS_ASSERTION(mCurrentEventContentStack.Count() == 0,
|
|
|
|
"Huh, event content left on the stack in pres shell dtor!");
|
2007-03-05 01:39:53 +00:00
|
|
|
NS_ASSERTION(mFirstCallbackEventRequest == nsnull &&
|
2004-01-21 04:15:00 +00:00
|
|
|
mLastCallbackEventRequest == nsnull,
|
|
|
|
"post-reflow queues not empty. This means we're leaking");
|
2009-09-15 22:00:04 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
NS_ASSERTION(mPresArenaAllocCount == 0,
|
|
|
|
"Some pres arena objects were not freed");
|
|
|
|
#endif
|
|
|
|
|
2004-02-25 09:10:06 +00:00
|
|
|
delete mStyleSet;
|
2009-12-31 19:07:57 +00:00
|
|
|
NS_IF_RELEASE(mFrameConstructor);
|
2004-01-21 23:05:10 +00:00
|
|
|
|
2004-09-13 03:22:46 +00:00
|
|
|
mCurrentEventContent = nsnull;
|
2002-06-20 20:14:59 +00:00
|
|
|
|
2003-06-19 18:16:53 +00:00
|
|
|
NS_IF_RELEASE(mPresContext);
|
|
|
|
NS_IF_RELEASE(mDocument);
|
2008-04-03 02:42:20 +00:00
|
|
|
NS_IF_RELEASE(mSelection);
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize the presentation shell. Create view manager and style
|
|
|
|
* manager.
|
|
|
|
*/
|
2010-03-20 21:54:19 +00:00
|
|
|
nsresult
|
1998-05-09 03:22:41 +00:00
|
|
|
PresShell::Init(nsIDocument* aDocument,
|
2004-07-31 23:15:21 +00:00
|
|
|
nsPresContext* aPresContext,
|
1998-05-09 03:22:41 +00:00
|
|
|
nsIViewManager* aViewManager,
|
2004-01-07 22:30:53 +00:00
|
|
|
nsStyleSet* aStyleSet,
|
2002-06-25 21:16:17 +00:00
|
|
|
nsCompatibility aCompatMode)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
2010-05-19 23:22:19 +00:00
|
|
|
NS_TIME_FUNCTION_MIN(1.0);
|
|
|
|
|
1998-04-13 20:24:54 +00:00
|
|
|
NS_PRECONDITION(nsnull != aDocument, "null ptr");
|
|
|
|
NS_PRECONDITION(nsnull != aPresContext, "null ptr");
|
|
|
|
NS_PRECONDITION(nsnull != aViewManager, "null ptr");
|
2007-01-17 23:53:47 +00:00
|
|
|
nsresult result;
|
1999-12-04 23:49:50 +00:00
|
|
|
|
1998-04-13 20:24:54 +00:00
|
|
|
if ((nsnull == aDocument) || (nsnull == aPresContext) ||
|
|
|
|
(nsnull == aViewManager)) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
1999-05-04 23:27:42 +00:00
|
|
|
if (mDocument) {
|
2006-03-30 00:27:42 +00:00
|
|
|
NS_WARNING("PresShell double init'ed");
|
1998-04-13 20:24:54 +00:00
|
|
|
return NS_ERROR_ALREADY_INITIALIZED;
|
|
|
|
}
|
2007-01-17 23:53:47 +00:00
|
|
|
result = mStackArena.Init();
|
|
|
|
NS_ENSURE_SUCCESS(result, result);
|
1998-04-13 20:24:54 +00:00
|
|
|
|
2009-04-21 23:53:52 +00:00
|
|
|
if (!mFramesToDirty.Init()) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
2003-06-19 18:16:53 +00:00
|
|
|
mDocument = aDocument;
|
|
|
|
NS_ADDREF(mDocument);
|
1998-04-13 20:24:54 +00:00
|
|
|
mViewManager = aViewManager;
|
|
|
|
|
2004-01-07 22:30:53 +00:00
|
|
|
// Create our frame constructor.
|
2005-02-18 16:11:53 +00:00
|
|
|
mFrameConstructor = new nsCSSFrameConstructor(mDocument, this);
|
2004-01-21 23:05:10 +00:00
|
|
|
NS_ENSURE_TRUE(mFrameConstructor, NS_ERROR_OUT_OF_MEMORY);
|
2009-12-31 19:07:57 +00:00
|
|
|
NS_ADDREF(mFrameConstructor);
|
2004-01-07 22:30:53 +00:00
|
|
|
|
2002-04-11 03:24:18 +00:00
|
|
|
// The document viewer owns both view manager and pres shell.
|
|
|
|
mViewManager->SetViewObserver(this);
|
1998-08-28 02:54:06 +00:00
|
|
|
|
1998-04-13 20:24:54 +00:00
|
|
|
// Bind the context to the presentation shell.
|
2002-05-23 23:09:31 +00:00
|
|
|
mPresContext = aPresContext;
|
2003-06-19 18:16:53 +00:00
|
|
|
NS_ADDREF(mPresContext);
|
1998-04-13 20:24:54 +00:00
|
|
|
aPresContext->SetShell(this);
|
|
|
|
|
2004-01-07 22:30:53 +00:00
|
|
|
// Now we can initialize the style set.
|
2007-01-17 23:53:47 +00:00
|
|
|
result = aStyleSet->Init(aPresContext);
|
2004-01-07 22:30:53 +00:00
|
|
|
NS_ENSURE_SUCCESS(result, result);
|
|
|
|
|
2004-04-13 00:27:29 +00:00
|
|
|
// From this point on, any time we return an error we need to make
|
|
|
|
// sure to null out mStyleSet first, since an error return from this
|
|
|
|
// method will cause the caller to delete the style set, so we don't
|
|
|
|
// want to delete it in our destructor.
|
2001-08-01 03:15:50 +00:00
|
|
|
mStyleSet = aStyleSet;
|
1998-04-13 20:24:54 +00:00
|
|
|
|
2006-12-05 15:46:18 +00:00
|
|
|
// Notify our prescontext that it now has a compatibility mode. Note that
|
|
|
|
// this MUST happen after we set up our style set but before we create any
|
|
|
|
// frames.
|
|
|
|
mPresContext->CompatibilityModeChanged();
|
2002-05-23 23:09:31 +00:00
|
|
|
|
2002-06-25 21:21:48 +00:00
|
|
|
// setup the preference style rules (no forced reflow), and do it
|
|
|
|
// before creating any frames.
|
|
|
|
SetPreferenceStyleRules(PR_FALSE);
|
|
|
|
|
2004-08-29 03:08:44 +00:00
|
|
|
result = CallCreateInstance(kFrameSelectionCID, &mSelection);
|
2004-04-13 00:27:29 +00:00
|
|
|
if (NS_FAILED(result)) {
|
|
|
|
mStyleSet = nsnull;
|
1998-12-14 18:34:14 +00:00
|
|
|
return result;
|
2004-04-13 00:27:29 +00:00
|
|
|
}
|
1999-04-26 04:02:04 +00:00
|
|
|
|
1999-08-04 04:02:40 +00:00
|
|
|
// Create and initialize the frame manager
|
2004-03-06 04:46:11 +00:00
|
|
|
result = FrameManager()->Init(this, mStyleSet);
|
2004-04-13 00:27:29 +00:00
|
|
|
if (NS_FAILED(result)) {
|
|
|
|
NS_WARNING("Frame manager initialization failed");
|
|
|
|
mStyleSet = nsnull;
|
|
|
|
return result;
|
|
|
|
}
|
1999-08-04 04:02:40 +00:00
|
|
|
|
2006-04-26 02:01:07 +00:00
|
|
|
mSelection->Init(this, nsnull);
|
|
|
|
|
1999-02-12 00:02:56 +00:00
|
|
|
// Important: this has to happen after the selection has been set up
|
|
|
|
#ifdef SHOW_CARET
|
|
|
|
// make the caret
|
|
|
|
nsresult err = NS_NewCaret(getter_AddRefs(mCaret));
|
|
|
|
if (NS_SUCCEEDED(err))
|
1999-04-01 23:58:11 +00:00
|
|
|
{
|
1999-07-14 22:18:29 +00:00
|
|
|
mCaret->Init(this);
|
2007-09-22 21:06:58 +00:00
|
|
|
mOriginalCaret = mCaret;
|
1999-04-01 23:58:11 +00:00
|
|
|
}
|
|
|
|
|
2003-03-12 03:22:11 +00:00
|
|
|
//SetCaretEnabled(PR_TRUE); // make it show in browser windows
|
1999-02-12 00:02:56 +00:00
|
|
|
#endif
|
2005-09-06 03:37:15 +00:00
|
|
|
//set up selection to be displayed in document
|
2006-02-07 02:52:40 +00:00
|
|
|
// Don't enable selection for print media
|
|
|
|
nsPresContext::nsPresContextType type = aPresContext->Type();
|
|
|
|
if (type != nsPresContext::eContext_PrintPreview &&
|
|
|
|
type != nsPresContext::eContext_Print)
|
|
|
|
SetDisplaySelection(nsISelectionController::SELECTION_DISABLED);
|
1999-11-30 00:32:43 +00:00
|
|
|
|
1999-12-23 03:47:02 +00:00
|
|
|
if (gMaxRCProcessingTime == -1) {
|
2004-04-29 23:34:19 +00:00
|
|
|
gMaxRCProcessingTime =
|
|
|
|
nsContentUtils::GetIntPref("layout.reflow.timeslice",
|
|
|
|
NS_MAX_REFLOW_TIME);
|
1999-12-23 02:02:33 +00:00
|
|
|
}
|
|
|
|
|
2004-07-18 01:16:27 +00:00
|
|
|
{
|
Bug 560095 - Use mozilla::services::GetObserverService(). r=biesi,dveditz,gavin,josh,jst,mrbkap,roc,sdwilsh,shaver,sicking,smontagu,surkov
2010-04-29 16:59:13 +00:00
|
|
|
nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
|
2005-08-10 20:21:44 +00:00
|
|
|
if (os) {
|
2006-06-08 14:32:20 +00:00
|
|
|
os->AddObserver(this, "agent-sheet-added", PR_FALSE);
|
|
|
|
os->AddObserver(this, "user-sheet-added", PR_FALSE);
|
|
|
|
os->AddObserver(this, "agent-sheet-removed", PR_FALSE);
|
|
|
|
os->AddObserver(this, "user-sheet-removed", PR_FALSE);
|
2005-08-10 20:21:44 +00:00
|
|
|
#ifdef MOZ_XUL
|
2004-07-18 01:16:27 +00:00
|
|
|
os->AddObserver(this, "chrome-flush-skin-caches", PR_FALSE);
|
2007-05-04 02:19:18 +00:00
|
|
|
#endif
|
|
|
|
#ifdef ACCESSIBILITY
|
|
|
|
os->AddObserver(this, "a11y-init-or-shutdown", PR_FALSE);
|
2004-07-18 01:16:27 +00:00
|
|
|
#endif
|
2005-08-10 20:21:44 +00:00
|
|
|
}
|
|
|
|
}
|
2000-05-15 03:37:21 +00:00
|
|
|
|
2000-06-14 23:18:54 +00:00
|
|
|
// cache the drag service so we can check it during reflows
|
2000-09-13 23:57:52 +00:00
|
|
|
mDragService = do_GetService("@mozilla.org/widget/dragservice;1");
|
2000-06-14 23:18:54 +00:00
|
|
|
|
2001-03-13 01:47:22 +00:00
|
|
|
#ifdef MOZ_REFLOW_PERF
|
2002-12-11 14:05:41 +00:00
|
|
|
if (mReflowCountMgr) {
|
2004-04-29 23:34:19 +00:00
|
|
|
PRBool paintFrameCounts =
|
|
|
|
nsContentUtils::GetBoolPref("layout.reflow.showframecounts");
|
|
|
|
|
|
|
|
PRBool dumpFrameCounts =
|
|
|
|
nsContentUtils::GetBoolPref("layout.reflow.dumpframecounts");
|
|
|
|
|
|
|
|
PRBool dumpFrameByFrameCounts =
|
|
|
|
nsContentUtils::GetBoolPref("layout.reflow.dumpframebyframecounts");
|
|
|
|
|
|
|
|
mReflowCountMgr->SetDumpFrameCounts(dumpFrameCounts);
|
|
|
|
mReflowCountMgr->SetDumpFrameByFrameCounts(dumpFrameByFrameCounts);
|
|
|
|
mReflowCountMgr->SetPaintFrameCounts(paintFrameCounts);
|
2001-03-13 01:47:22 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-03-22 06:42:53 +00:00
|
|
|
#ifdef MOZ_SMIL
|
|
|
|
if (mDocument->HasAnimationController()) {
|
|
|
|
nsSMILAnimationController* animCtrl = mDocument->GetAnimationController();
|
|
|
|
if (!animCtrl->IsPaused()) {
|
|
|
|
animCtrl->StartSampling(GetPresContext()->RefreshDriver());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif // MOZ_SMIL
|
|
|
|
|
2001-08-01 03:15:50 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-03-20 21:54:19 +00:00
|
|
|
void
|
2001-08-01 03:15:50 +00:00
|
|
|
PresShell::Destroy()
|
|
|
|
{
|
2010-05-19 23:22:19 +00:00
|
|
|
NS_TIME_FUNCTION_MIN(1.0);
|
|
|
|
|
2009-05-15 03:08:41 +00:00
|
|
|
NS_ASSERTION(!nsContentUtils::IsSafeToRunScript(),
|
|
|
|
"destroy called on presshell while scripts not blocked");
|
|
|
|
|
2001-08-01 03:15:50 +00:00
|
|
|
#ifdef MOZ_REFLOW_PERF
|
|
|
|
DumpReflows();
|
|
|
|
if (mReflowCountMgr) {
|
|
|
|
delete mReflowCountMgr;
|
|
|
|
mReflowCountMgr = nsnull;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2004-02-25 09:10:06 +00:00
|
|
|
if (mHaveShutDown)
|
2010-03-20 21:54:19 +00:00
|
|
|
return;
|
2004-02-25 09:10:06 +00:00
|
|
|
|
2009-12-10 18:58:33 +00:00
|
|
|
MaybeReleaseCapturingContent();
|
|
|
|
|
2009-04-21 23:53:52 +00:00
|
|
|
mContentToScrollTo = nsnull;
|
|
|
|
|
2006-04-11 16:37:58 +00:00
|
|
|
if (mPresContext) {
|
|
|
|
// We need to notify the destroying the nsPresContext to ESM for
|
|
|
|
// suppressing to use from ESM.
|
|
|
|
mPresContext->EventStateManager()->NotifyDestroyPresContext(mPresContext);
|
|
|
|
}
|
|
|
|
|
2004-07-18 01:16:27 +00:00
|
|
|
{
|
Bug 560095 - Use mozilla::services::GetObserverService(). r=biesi,dveditz,gavin,josh,jst,mrbkap,roc,sdwilsh,shaver,sicking,smontagu,surkov
2010-04-29 16:59:13 +00:00
|
|
|
nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
|
2005-08-11 03:59:04 +00:00
|
|
|
if (os) {
|
2006-06-08 14:32:20 +00:00
|
|
|
os->RemoveObserver(this, "agent-sheet-added");
|
|
|
|
os->RemoveObserver(this, "user-sheet-added");
|
|
|
|
os->RemoveObserver(this, "agent-sheet-removed");
|
|
|
|
os->RemoveObserver(this, "user-sheet-removed");
|
2005-08-11 03:59:04 +00:00
|
|
|
#ifdef MOZ_XUL
|
2004-07-18 01:16:27 +00:00
|
|
|
os->RemoveObserver(this, "chrome-flush-skin-caches");
|
2007-05-04 18:09:02 +00:00
|
|
|
#endif
|
|
|
|
#ifdef ACCESSIBILITY
|
|
|
|
os->RemoveObserver(this, "a11y-init-or-shutdown");
|
2004-07-18 01:16:27 +00:00
|
|
|
#endif
|
2005-08-11 03:59:04 +00:00
|
|
|
}
|
|
|
|
}
|
2004-07-18 01:16:27 +00:00
|
|
|
|
2001-08-01 03:15:50 +00:00
|
|
|
// If our paint suppression timer is still active, kill it.
|
|
|
|
if (mPaintSuppressionTimer) {
|
|
|
|
mPaintSuppressionTimer->Cancel();
|
|
|
|
mPaintSuppressionTimer = nsnull;
|
|
|
|
}
|
|
|
|
|
2009-06-13 01:28:41 +00:00
|
|
|
// Same for our reflow continuation timer
|
|
|
|
if (mReflowContinueTimer) {
|
|
|
|
mReflowContinueTimer->Cancel();
|
|
|
|
mReflowContinueTimer = nsnull;
|
|
|
|
}
|
|
|
|
|
2003-02-27 23:09:51 +00:00
|
|
|
if (mCaret) {
|
|
|
|
mCaret->Terminate();
|
|
|
|
mCaret = nsnull;
|
|
|
|
}
|
2010-03-20 21:54:19 +00:00
|
|
|
|
2008-04-03 02:42:20 +00:00
|
|
|
if (mSelection) {
|
|
|
|
mSelection->DisconnectFromPresShell();
|
|
|
|
}
|
|
|
|
|
2001-08-01 03:15:50 +00:00
|
|
|
// release our pref style sheet, if we have one still
|
|
|
|
ClearPreferenceStyleRules();
|
|
|
|
|
|
|
|
mIsDestroying = PR_TRUE;
|
|
|
|
|
2002-06-20 20:14:59 +00:00
|
|
|
// We can't release all the event content in
|
|
|
|
// mCurrentEventContentStack here since there might be code on the
|
|
|
|
// stack that will release the event content too. Double release
|
|
|
|
// bad!
|
|
|
|
|
|
|
|
// The frames will be torn down, so remove them from the current
|
|
|
|
// event frame stack (since they'd be dangling references if we'd
|
|
|
|
// leave them in) and null out the mCurrentEventFrame pointer as
|
|
|
|
// well.
|
|
|
|
|
|
|
|
mCurrentEventFrame = nsnull;
|
2001-08-01 03:15:50 +00:00
|
|
|
|
2009-02-03 14:42:18 +00:00
|
|
|
PRInt32 i, count = mCurrentEventFrameStack.Length();
|
2001-08-01 03:15:50 +00:00
|
|
|
for (i = 0; i < count; i++) {
|
2009-02-03 14:42:18 +00:00
|
|
|
mCurrentEventFrameStack[i] = nsnull;
|
2001-08-01 03:15:50 +00:00
|
|
|
}
|
|
|
|
|
2009-11-26 09:12:20 +00:00
|
|
|
mFramesToDirty.Clear();
|
|
|
|
|
2001-08-01 03:15:50 +00:00
|
|
|
if (mViewManager) {
|
2002-04-11 03:24:18 +00:00
|
|
|
// Clear the view manager's weak pointer back to |this| in case it
|
|
|
|
// was leaked.
|
|
|
|
mViewManager->SetViewObserver(nsnull);
|
2001-08-01 03:15:50 +00:00
|
|
|
mViewManager = nsnull;
|
|
|
|
}
|
|
|
|
|
2003-03-06 19:14:17 +00:00
|
|
|
mStyleSet->BeginShutdown(mPresContext);
|
|
|
|
|
2001-08-01 03:15:50 +00:00
|
|
|
// This shell must be removed from the document before the frame
|
|
|
|
// hierarchy is torn down to avoid finding deleted frames through
|
|
|
|
// this presshell while the frames are being torn down
|
|
|
|
if (mDocument) {
|
2010-01-07 10:36:11 +00:00
|
|
|
NS_ASSERTION(mDocument->GetPrimaryShell() == this, "Wrong shell?");
|
|
|
|
mDocument->DeleteShell();
|
2001-08-01 03:15:50 +00:00
|
|
|
}
|
|
|
|
|
2010-03-22 06:42:53 +00:00
|
|
|
nsRefreshDriver* rd = GetPresContext()->RefreshDriver();
|
2010-06-06 17:45:18 +00:00
|
|
|
#ifdef MOZ_SMIL
|
2010-03-22 06:42:53 +00:00
|
|
|
if (mDocument->HasAnimationController()) {
|
|
|
|
mDocument->GetAnimationController()->StopSampling(rd);
|
|
|
|
}
|
2010-06-06 17:45:18 +00:00
|
|
|
#endif // MOZ_SMIL
|
2010-03-22 06:42:53 +00:00
|
|
|
|
2010-02-19 17:11:40 +00:00
|
|
|
// Revoke any pending events. We need to do this and cancel pending reflows
|
|
|
|
// before we destroy the frame manager, since apparently frame destruction
|
|
|
|
// sometimes spins the event queue when plug-ins are involved(!).
|
2010-03-22 06:42:53 +00:00
|
|
|
rd->RemoveRefreshObserver(this, Flush_Layout);
|
2009-01-14 20:42:25 +00:00
|
|
|
mResizeEvent.Revoke();
|
2009-08-15 08:49:20 +00:00
|
|
|
if (mAsyncResizeTimerIsActive) {
|
|
|
|
mAsyncResizeEventTimer->Cancel();
|
|
|
|
mAsyncResizeTimerIsActive = PR_FALSE;
|
|
|
|
}
|
2007-02-13 04:46:57 +00:00
|
|
|
|
|
|
|
CancelAllPendingReflows();
|
2007-12-01 07:22:44 +00:00
|
|
|
CancelPostedReflowCallbacks();
|
2007-02-13 04:46:57 +00:00
|
|
|
|
2001-08-01 03:15:50 +00:00
|
|
|
// Destroy the frame manager. This will destroy the frame hierarchy
|
2009-04-01 01:08:34 +00:00
|
|
|
mFrameConstructor->WillDestroyFrameTree();
|
2004-03-06 04:46:11 +00:00
|
|
|
FrameManager()->Destroy();
|
2001-08-01 03:15:50 +00:00
|
|
|
|
2009-07-23 11:40:18 +00:00
|
|
|
// Destroy all frame properties (whose destruction was suppressed
|
|
|
|
// while destroying the frame tree, but which might contain more
|
|
|
|
// frames within the properties.
|
|
|
|
if (mPresContext) {
|
|
|
|
// Clear out the prescontext's property table -- since our frame tree is
|
|
|
|
// now dead, we shouldn't be looking up any more properties in that table.
|
|
|
|
// We want to do this before we call SetShell() on the prescontext, so
|
|
|
|
// property destructors can usefully call GetPresShell() on the
|
|
|
|
// prescontext.
|
2010-03-29 01:46:55 +00:00
|
|
|
mPresContext->PropertyTable()->DeleteAll();
|
2009-07-23 11:40:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-07-12 07:41:11 +00:00
|
|
|
NS_WARN_IF_FALSE(!mWeakFrames, "Weak frames alive after destroying FrameManager");
|
|
|
|
while (mWeakFrames) {
|
|
|
|
mWeakFrames->Clear(this);
|
|
|
|
}
|
|
|
|
|
2001-08-01 03:15:50 +00:00
|
|
|
// Let the style set do its cleanup.
|
2003-03-06 19:14:17 +00:00
|
|
|
mStyleSet->Shutdown(mPresContext);
|
2004-01-07 22:30:53 +00:00
|
|
|
|
2001-08-01 03:15:50 +00:00
|
|
|
if (mPresContext) {
|
2005-12-06 04:53:03 +00:00
|
|
|
// We hold a reference to the pres context, and it holds a weak link back
|
|
|
|
// to us. To avoid the pres context having a dangling reference, set its
|
|
|
|
// pres shell to NULL
|
2001-08-01 03:15:50 +00:00
|
|
|
mPresContext->SetShell(nsnull);
|
2004-08-18 22:13:10 +00:00
|
|
|
|
|
|
|
// Clear the link handler (weak reference) as well
|
|
|
|
mPresContext->SetLinkHandler(nsnull);
|
2001-08-01 03:15:50 +00:00
|
|
|
}
|
|
|
|
|
2004-02-25 09:10:06 +00:00
|
|
|
mHaveShutDown = PR_TRUE;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
2000-03-31 07:02:06 +00:00
|
|
|
// Dynamic stack memory allocation
|
2007-01-17 23:53:47 +00:00
|
|
|
/* virtual */ void
|
2000-03-31 07:02:06 +00:00
|
|
|
PresShell::PushStackMemory()
|
|
|
|
{
|
2007-01-17 23:53:47 +00:00
|
|
|
mStackArena.Push();
|
2000-03-31 07:02:06 +00:00
|
|
|
}
|
|
|
|
|
2007-01-17 23:53:47 +00:00
|
|
|
/* virtual */ void
|
2000-03-31 07:02:06 +00:00
|
|
|
PresShell::PopStackMemory()
|
|
|
|
{
|
2007-01-17 23:53:47 +00:00
|
|
|
mStackArena.Pop();
|
2000-03-31 07:02:06 +00:00
|
|
|
}
|
|
|
|
|
2007-01-17 23:53:47 +00:00
|
|
|
/* virtual */ void*
|
|
|
|
PresShell::AllocateStackMemory(size_t aSize)
|
2000-03-31 07:02:06 +00:00
|
|
|
{
|
2007-01-17 23:53:47 +00:00
|
|
|
return mStackArena.Allocate(aSize);
|
2000-03-31 07:02:06 +00:00
|
|
|
}
|
|
|
|
|
2004-04-13 00:28:44 +00:00
|
|
|
void
|
2009-09-15 22:00:04 +00:00
|
|
|
PresShell::FreeFrame(nsQueryFrame::FrameIID aCode, void* aPtr)
|
2009-08-18 03:21:06 +00:00
|
|
|
{
|
2009-09-15 22:00:04 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
mPresArenaAllocCount--;
|
|
|
|
#endif
|
|
|
|
if (PRESARENA_MUST_FREE_DURING_DESTROY || !mIsDestroying)
|
|
|
|
mFrameArena.FreeByCode(aCode, aPtr);
|
2009-08-18 03:21:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void*
|
2009-09-15 22:00:04 +00:00
|
|
|
PresShell::AllocateFrame(nsQueryFrame::FrameIID aCode, size_t aSize)
|
2009-08-18 03:21:06 +00:00
|
|
|
{
|
2009-09-15 22:00:04 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
mPresArenaAllocCount++;
|
|
|
|
#endif
|
|
|
|
void* result = mFrameArena.AllocateByCode(aCode, aSize);
|
2009-08-18 03:21:06 +00:00
|
|
|
|
|
|
|
if (result) {
|
|
|
|
memset(result, 0, aSize);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PresShell::FreeMisc(size_t aSize, void* aPtr)
|
1999-12-04 23:49:50 +00:00
|
|
|
{
|
2009-09-15 22:00:04 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
mPresArenaAllocCount--;
|
|
|
|
#endif
|
|
|
|
if (PRESARENA_MUST_FREE_DURING_DESTROY || !mIsDestroying)
|
|
|
|
mFrameArena.FreeBySize(aSize, aPtr);
|
1999-12-04 23:49:50 +00:00
|
|
|
}
|
|
|
|
|
2004-04-13 00:28:44 +00:00
|
|
|
void*
|
2009-08-18 03:21:06 +00:00
|
|
|
PresShell::AllocateMisc(size_t aSize)
|
1999-12-04 23:49:50 +00:00
|
|
|
{
|
2009-09-15 22:00:04 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
mPresArenaAllocCount++;
|
|
|
|
#endif
|
|
|
|
return mFrameArena.AllocateBySize(aSize);
|
1999-12-04 23:49:50 +00:00
|
|
|
}
|
|
|
|
|
2004-08-29 03:08:44 +00:00
|
|
|
void
|
|
|
|
nsIPresShell::SetAuthorStyleDisabled(PRBool aStyleDisabled)
|
2004-08-05 11:38:42 +00:00
|
|
|
{
|
|
|
|
if (aStyleDisabled != mStyleSet->GetAuthorStyleDisabled()) {
|
2004-08-29 03:08:44 +00:00
|
|
|
mStyleSet->SetAuthorStyleDisabled(aStyleDisabled);
|
|
|
|
ReconstructStyleData();
|
2004-08-05 11:38:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-08-29 03:08:44 +00:00
|
|
|
PRBool
|
2010-03-31 12:47:25 +00:00
|
|
|
nsIPresShell::GetAuthorStyleDisabled() const
|
2000-10-11 08:33:01 +00:00
|
|
|
{
|
2004-08-29 03:08:44 +00:00
|
|
|
return mStyleSet->GetAuthorStyleDisabled();
|
2000-10-11 08:33:01 +00:00
|
|
|
}
|
|
|
|
|
2010-03-20 21:54:19 +00:00
|
|
|
nsresult
|
2000-10-11 08:33:01 +00:00
|
|
|
PresShell::SetPreferenceStyleRules(PRBool aForceReflow)
|
|
|
|
{
|
2010-05-19 23:22:19 +00:00
|
|
|
NS_TIME_FUNCTION_MIN(1.0);
|
|
|
|
|
2001-11-01 04:40:59 +00:00
|
|
|
if (!mDocument) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
|
2005-11-28 23:56:44 +00:00
|
|
|
nsPIDOMWindow *window = mDocument->GetWindow();
|
2001-11-01 04:40:59 +00:00
|
|
|
|
2005-11-28 23:56:44 +00:00
|
|
|
// If the document doesn't have a window there's no need to notify
|
|
|
|
// its presshell about changes to preferences since the document is
|
|
|
|
// in a state where it doesn't matter any more (see
|
2001-11-01 04:40:59 +00:00
|
|
|
// DocumentViewerImpl::Close()).
|
|
|
|
|
2005-11-28 23:56:44 +00:00
|
|
|
if (!window) {
|
2001-11-01 04:40:59 +00:00
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
|
2000-10-11 08:33:01 +00:00
|
|
|
NS_PRECONDITION(mPresContext, "presContext cannot be null");
|
|
|
|
if (mPresContext) {
|
|
|
|
// first, make sure this is not a chrome shell
|
2008-09-28 19:14:28 +00:00
|
|
|
if (nsContentUtils::IsInChromeDocshell(mDocument)) {
|
|
|
|
return NS_OK;
|
2000-10-11 08:33:01 +00:00
|
|
|
}
|
2008-09-28 19:14:28 +00:00
|
|
|
|
2000-11-13 08:27:01 +00:00
|
|
|
#ifdef DEBUG_attinasi
|
2008-09-28 19:14:28 +00:00
|
|
|
printf("Setting Preference Style Rules:\n");
|
2000-10-28 22:17:53 +00:00
|
|
|
#endif
|
2008-09-28 19:14:28 +00:00
|
|
|
// if here, we need to create rules for the prefs
|
|
|
|
// - this includes the background-color, the text-color,
|
|
|
|
// the link color, the visited link color and the link-underlining
|
2000-10-11 08:33:01 +00:00
|
|
|
|
2008-09-28 19:14:28 +00:00
|
|
|
// first clear any exising rules
|
|
|
|
nsresult result = ClearPreferenceStyleRules();
|
2000-10-11 08:33:01 +00:00
|
|
|
|
2008-09-28 19:14:28 +00:00
|
|
|
// now the link rules (must come after the color rules, or links will not be correct color!)
|
|
|
|
// XXX - when there is both an override and agent pref stylesheet this won't matter,
|
|
|
|
// as the color rules will be overrides and the links rules will be agent
|
|
|
|
if (NS_SUCCEEDED(result)) {
|
|
|
|
result = SetPrefLinkRules();
|
|
|
|
}
|
|
|
|
if (NS_SUCCEEDED(result)) {
|
|
|
|
result = SetPrefFocusRules();
|
|
|
|
}
|
|
|
|
if (NS_SUCCEEDED(result)) {
|
|
|
|
result = SetPrefNoScriptRule();
|
|
|
|
}
|
|
|
|
if (NS_SUCCEEDED(result)) {
|
|
|
|
result = SetPrefNoFramesRule();
|
2000-10-11 08:33:01 +00:00
|
|
|
}
|
2000-11-13 08:27:01 +00:00
|
|
|
#ifdef DEBUG_attinasi
|
2000-10-28 22:17:53 +00:00
|
|
|
printf( "Preference Style Rules set: error=%ld\n", (long)result);
|
2007-07-25 17:14:13 +00:00
|
|
|
#endif
|
2000-10-11 08:33:01 +00:00
|
|
|
|
2007-07-25 17:14:13 +00:00
|
|
|
// Note that this method never needs to force any calculation; the caller
|
|
|
|
// will recalculate style if needed
|
2000-10-11 08:33:01 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2001-11-01 04:40:59 +00:00
|
|
|
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
2000-10-11 08:33:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult PresShell::ClearPreferenceStyleRules(void)
|
|
|
|
{
|
|
|
|
nsresult result = NS_OK;
|
|
|
|
if (mPrefStyleSheet) {
|
|
|
|
NS_ASSERTION(mStyleSet, "null styleset entirely unexpected!");
|
|
|
|
if (mStyleSet) {
|
|
|
|
// remove the sheet from the styleset:
|
|
|
|
// - note that we have to check for success by comparing the count before and after...
|
|
|
|
#ifdef NS_DEBUG
|
2004-01-07 22:30:53 +00:00
|
|
|
PRInt32 numBefore = mStyleSet->SheetCount(nsStyleSet::eUserSheet);
|
2002-01-14 14:47:21 +00:00
|
|
|
NS_ASSERTION(numBefore > 0, "no user stylesheets in styleset, but we have one!");
|
2000-10-11 08:33:01 +00:00
|
|
|
#endif
|
2004-01-07 22:30:53 +00:00
|
|
|
mStyleSet->RemoveStyleSheet(nsStyleSet::eUserSheet, mPrefStyleSheet);
|
2000-10-11 08:33:01 +00:00
|
|
|
|
2000-11-13 08:27:01 +00:00
|
|
|
#ifdef DEBUG_attinasi
|
2002-01-14 14:47:21 +00:00
|
|
|
NS_ASSERTION((numBefore - 1) == mStyleSet->GetNumberOfUserStyleSheets(),
|
2000-10-11 08:33:01 +00:00
|
|
|
"Pref stylesheet was not removed");
|
2000-10-28 22:17:53 +00:00
|
|
|
printf("PrefStyleSheet removed\n");
|
|
|
|
#endif
|
2000-10-11 08:33:01 +00:00
|
|
|
// clear the sheet pointer: it is strictly historical now
|
2008-01-18 05:23:44 +00:00
|
|
|
mPrefStyleSheet = nsnull;
|
2000-10-11 08:33:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult PresShell::CreatePreferenceStyleSheet(void)
|
|
|
|
{
|
2010-05-19 23:22:19 +00:00
|
|
|
NS_TIME_FUNCTION_MIN(1.0);
|
|
|
|
|
2003-07-18 01:26:47 +00:00
|
|
|
NS_ASSERTION(!mPrefStyleSheet, "prefStyleSheet already exists");
|
2010-01-07 13:51:16 +00:00
|
|
|
nsresult result = NS_NewCSSStyleSheet(getter_AddRefs(mPrefStyleSheet));
|
2000-10-11 08:33:01 +00:00
|
|
|
if (NS_SUCCEEDED(result)) {
|
|
|
|
NS_ASSERTION(mPrefStyleSheet, "null but no error");
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
result = NS_NewURI(getter_AddRefs(uri), "about:PreferenceStyleSheet", nsnull);
|
|
|
|
if (NS_SUCCEEDED(result)) {
|
|
|
|
NS_ASSERTION(uri, "null but no error");
|
2010-05-11 20:41:47 +00:00
|
|
|
mPrefStyleSheet->SetURIs(uri, uri, uri);
|
|
|
|
mPrefStyleSheet->SetComplete();
|
|
|
|
PRUint32 index;
|
|
|
|
result =
|
|
|
|
mPrefStyleSheet->InsertRuleInternal(NS_LITERAL_STRING("@namespace url(http://www.w3.org/1999/xhtml);"),
|
|
|
|
0, &index);
|
2000-10-11 08:33:01 +00:00
|
|
|
if (NS_SUCCEEDED(result)) {
|
2010-05-11 20:41:47 +00:00
|
|
|
mStyleSet->AppendStyleSheet(nsStyleSet::eUserSheet, mPrefStyleSheet);
|
2000-10-11 08:33:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-11-13 08:27:01 +00:00
|
|
|
#ifdef DEBUG_attinasi
|
2000-10-28 22:17:53 +00:00
|
|
|
printf("CreatePrefStyleSheet completed: error=%ld\n",(long)result);
|
|
|
|
#endif
|
2000-10-11 08:33:01 +00:00
|
|
|
|
2008-01-18 05:23:44 +00:00
|
|
|
if (NS_FAILED(result)) {
|
|
|
|
mPrefStyleSheet = nsnull;
|
|
|
|
}
|
|
|
|
|
2000-10-11 08:33:01 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2003-07-18 01:26:47 +00:00
|
|
|
// XXX We want these after the @namespace rule. Does order matter
|
|
|
|
// for these rules, or can we call nsICSSStyleRule::StyleRuleCount()
|
|
|
|
// and just "append"?
|
|
|
|
static PRUint32 sInsertPrefSheetRulesAt = 1;
|
|
|
|
|
2003-06-26 06:10:03 +00:00
|
|
|
nsresult
|
|
|
|
PresShell::SetPrefNoScriptRule()
|
|
|
|
{
|
2010-05-19 23:22:19 +00:00
|
|
|
NS_TIME_FUNCTION_MIN(1.0);
|
|
|
|
|
2005-01-03 19:37:54 +00:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
2006-07-25 00:29:26 +00:00
|
|
|
// also handle the case where print is done from print preview
|
|
|
|
// see bug #342439 for more details
|
2009-12-19 10:35:54 +00:00
|
|
|
nsIDocument* doc = mDocument;
|
|
|
|
if (mPresContext->Type() == nsPresContext::eContext_PrintPreview ||
|
|
|
|
mPresContext->Type() == nsPresContext::eContext_Print) {
|
|
|
|
while (doc->GetOriginalDocument()) {
|
|
|
|
doc = doc->GetOriginalDocument();
|
|
|
|
}
|
|
|
|
}
|
2006-04-22 00:06:30 +00:00
|
|
|
|
2009-12-19 10:35:54 +00:00
|
|
|
PRBool scriptEnabled = doc->IsScriptEnabled();
|
2006-04-22 00:06:30 +00:00
|
|
|
if (scriptEnabled) {
|
2003-06-26 06:10:03 +00:00
|
|
|
if (!mPrefStyleSheet) {
|
|
|
|
rv = CreatePreferenceStyleSheet();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2008-01-18 05:23:44 +00:00
|
|
|
|
2003-06-26 06:10:03 +00:00
|
|
|
PRUint32 index = 0;
|
2008-01-18 05:23:44 +00:00
|
|
|
mPrefStyleSheet->
|
|
|
|
InsertRuleInternal(NS_LITERAL_STRING("noscript{display:none!important}"),
|
|
|
|
sInsertPrefSheetRulesAt, &index);
|
2003-06-26 06:10:03 +00:00
|
|
|
}
|
2005-01-03 19:37:54 +00:00
|
|
|
|
|
|
|
return rv;
|
2003-06-26 06:10:03 +00:00
|
|
|
}
|
|
|
|
|
2005-03-03 18:04:38 +00:00
|
|
|
nsresult PresShell::SetPrefNoFramesRule(void)
|
|
|
|
{
|
2010-05-19 23:22:19 +00:00
|
|
|
NS_TIME_FUNCTION_MIN(1.0);
|
|
|
|
|
2005-03-03 18:04:38 +00:00
|
|
|
NS_ASSERTION(mPresContext,"null prescontext not allowed");
|
|
|
|
if (!mPresContext) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
if (!mPrefStyleSheet) {
|
|
|
|
rv = CreatePreferenceStyleSheet();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(mPrefStyleSheet, "prefstylesheet should not be null");
|
|
|
|
|
|
|
|
PRBool allowSubframes = PR_TRUE;
|
|
|
|
nsCOMPtr<nsISupports> container = mPresContext->GetContainer();
|
|
|
|
nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(container));
|
|
|
|
if (docShell) {
|
|
|
|
docShell->GetAllowSubframes(&allowSubframes);
|
|
|
|
}
|
|
|
|
if (!allowSubframes) {
|
|
|
|
PRUint32 index = 0;
|
2008-01-18 05:23:44 +00:00
|
|
|
rv = mPrefStyleSheet->
|
|
|
|
InsertRuleInternal(NS_LITERAL_STRING("noframes{display:block}"),
|
|
|
|
sInsertPrefSheetRulesAt, &index);
|
2005-03-03 18:04:38 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2008-01-18 05:23:44 +00:00
|
|
|
rv = mPrefStyleSheet->
|
|
|
|
InsertRuleInternal(NS_LITERAL_STRING("frame, frameset, iframe {display:none!important}"),
|
|
|
|
sInsertPrefSheetRulesAt, &index);
|
2005-03-03 18:04:38 +00:00
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2000-10-11 08:33:01 +00:00
|
|
|
nsresult PresShell::SetPrefLinkRules(void)
|
|
|
|
{
|
2010-05-19 23:22:19 +00:00
|
|
|
NS_TIME_FUNCTION_MIN(1.0);
|
|
|
|
|
2000-10-11 08:33:01 +00:00
|
|
|
NS_ASSERTION(mPresContext,"null prescontext not allowed");
|
2003-10-15 01:56:12 +00:00
|
|
|
if (!mPresContext) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2000-10-11 08:33:01 +00:00
|
|
|
|
2003-10-15 01:56:12 +00:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
if (!mPrefStyleSheet) {
|
|
|
|
rv = CreatePreferenceStyleSheet();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(mPrefStyleSheet, "prefstylesheet should not be null");
|
|
|
|
|
|
|
|
// support default link colors:
|
|
|
|
// this means the link colors need to be overridable,
|
|
|
|
// which they are if we put them in the agent stylesheet,
|
|
|
|
// though if using an override sheet this will cause authors grief still
|
|
|
|
// In the agent stylesheet, they are !important when we are ignoring document colors
|
|
|
|
|
2004-01-31 22:41:40 +00:00
|
|
|
nscolor linkColor(mPresContext->DefaultLinkColor());
|
|
|
|
nscolor activeColor(mPresContext->DefaultActiveLinkColor());
|
|
|
|
nscolor visitedColor(mPresContext->DefaultVisitedLinkColor());
|
2003-10-15 01:56:12 +00:00
|
|
|
|
2007-05-16 21:10:31 +00:00
|
|
|
NS_NAMED_LITERAL_STRING(ruleClose, "}");
|
2003-10-15 01:56:12 +00:00
|
|
|
PRUint32 index = 0;
|
|
|
|
nsAutoString strColor;
|
|
|
|
|
|
|
|
// insert a rule to color links: '*|*:link {color: #RRGGBB [!important];}'
|
|
|
|
ColorToString(linkColor, strColor);
|
2008-01-18 05:23:44 +00:00
|
|
|
rv = mPrefStyleSheet->
|
|
|
|
InsertRuleInternal(NS_LITERAL_STRING("*|*:link{color:") +
|
|
|
|
strColor + ruleClose,
|
|
|
|
sInsertPrefSheetRulesAt, &index);
|
2003-10-15 01:56:12 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// - visited links: '*|*:visited {color: #RRGGBB [!important];}'
|
|
|
|
ColorToString(visitedColor, strColor);
|
2008-01-18 05:23:44 +00:00
|
|
|
rv = mPrefStyleSheet->
|
|
|
|
InsertRuleInternal(NS_LITERAL_STRING("*|*:visited{color:") +
|
|
|
|
strColor + ruleClose,
|
|
|
|
sInsertPrefSheetRulesAt, &index);
|
2003-10-15 01:56:12 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// - active links: '*|*:-moz-any-link:active {color: #RRGGBB [!important];}'
|
|
|
|
ColorToString(activeColor, strColor);
|
2008-01-18 05:23:44 +00:00
|
|
|
rv = mPrefStyleSheet->
|
|
|
|
InsertRuleInternal(NS_LITERAL_STRING("*|*:-moz-any-link:active{color:") +
|
|
|
|
strColor + ruleClose,
|
|
|
|
sInsertPrefSheetRulesAt, &index);
|
2003-10-15 01:56:12 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2004-02-20 17:49:01 +00:00
|
|
|
PRBool underlineLinks =
|
|
|
|
mPresContext->GetCachedBoolPref(kPresContext_UnderlineLinks);
|
2003-10-15 01:56:12 +00:00
|
|
|
|
|
|
|
if (underlineLinks) {
|
|
|
|
// create a rule to make underlining happen
|
|
|
|
// '*|*:-moz-any-link {text-decoration:[underline|none];}'
|
|
|
|
// no need for important, we want these to be overridable
|
|
|
|
// NOTE: these must go in the agent stylesheet or they cannot be
|
|
|
|
// overridden by authors
|
2008-01-18 05:23:44 +00:00
|
|
|
rv = mPrefStyleSheet->
|
|
|
|
InsertRuleInternal(NS_LITERAL_STRING("*|*:-moz-any-link{text-decoration:underline}"),
|
|
|
|
sInsertPrefSheetRulesAt, &index);
|
2000-10-11 08:33:01 +00:00
|
|
|
} else {
|
2008-01-18 05:23:44 +00:00
|
|
|
rv = mPrefStyleSheet->
|
|
|
|
InsertRuleInternal(NS_LITERAL_STRING("*|*:-moz-any-link{text-decoration:none}"),
|
|
|
|
sInsertPrefSheetRulesAt, &index);
|
2000-10-11 08:33:01 +00:00
|
|
|
}
|
2003-10-15 01:56:12 +00:00
|
|
|
|
|
|
|
return rv;
|
2000-10-11 08:33:01 +00:00
|
|
|
}
|
|
|
|
|
2001-04-09 22:17:11 +00:00
|
|
|
nsresult PresShell::SetPrefFocusRules(void)
|
|
|
|
{
|
2010-05-19 23:22:19 +00:00
|
|
|
NS_TIME_FUNCTION_MIN(1.0);
|
|
|
|
|
2001-04-09 22:17:11 +00:00
|
|
|
NS_ASSERTION(mPresContext,"null prescontext not allowed");
|
|
|
|
nsresult result = NS_OK;
|
|
|
|
|
|
|
|
if (!mPresContext)
|
|
|
|
result = NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(result) && !mPrefStyleSheet)
|
|
|
|
result = CreatePreferenceStyleSheet();
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(result)) {
|
|
|
|
NS_ASSERTION(mPrefStyleSheet, "prefstylesheet should not be null");
|
|
|
|
|
2008-01-18 05:23:44 +00:00
|
|
|
if (mPresContext->GetUseFocusColors()) {
|
|
|
|
nscolor focusBackground(mPresContext->FocusBackgroundColor());
|
|
|
|
nscolor focusText(mPresContext->FocusTextColor());
|
|
|
|
|
|
|
|
// insert a rule to make focus the preferred color
|
|
|
|
PRUint32 index = 0;
|
|
|
|
nsAutoString strRule, strColor;
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////
|
|
|
|
// - focus: '*:focus
|
|
|
|
ColorToString(focusText,strColor);
|
|
|
|
strRule.AppendLiteral("*:focus,*:focus>font {color: ");
|
|
|
|
strRule.Append(strColor);
|
|
|
|
strRule.AppendLiteral(" !important; background-color: ");
|
|
|
|
ColorToString(focusBackground,strColor);
|
|
|
|
strRule.Append(strColor);
|
|
|
|
strRule.AppendLiteral(" !important; } ");
|
|
|
|
// insert the rules
|
|
|
|
result = mPrefStyleSheet->
|
|
|
|
InsertRuleInternal(strRule, sInsertPrefSheetRulesAt, &index);
|
|
|
|
}
|
|
|
|
PRUint8 focusRingWidth = mPresContext->FocusRingWidth();
|
|
|
|
PRBool focusRingOnAnything = mPresContext->GetFocusRingOnAnything();
|
2008-10-08 23:28:31 +00:00
|
|
|
PRUint8 focusRingStyle = mPresContext->GetFocusRingStyle();
|
2008-01-18 05:23:44 +00:00
|
|
|
|
|
|
|
if ((NS_SUCCEEDED(result) && focusRingWidth != 1 && focusRingWidth <= 4 ) || focusRingOnAnything) {
|
|
|
|
PRUint32 index = 0;
|
|
|
|
nsAutoString strRule;
|
|
|
|
if (!focusRingOnAnything)
|
|
|
|
strRule.AppendLiteral("*|*:link:focus, *|*:visited"); // If we only want focus rings on the normal things like links
|
|
|
|
strRule.AppendLiteral(":focus {outline: "); // For example 3px dotted WindowText (maximum 4)
|
|
|
|
strRule.AppendInt(focusRingWidth);
|
2008-10-08 23:28:31 +00:00
|
|
|
if (focusRingStyle == 0) // solid
|
2008-10-29 05:11:40 +00:00
|
|
|
strRule.AppendLiteral("px solid -moz-mac-focusring !important; -moz-outline-radius: 3px; outline-offset: 1px; } ");
|
2008-10-08 23:28:31 +00:00
|
|
|
else // dotted
|
|
|
|
strRule.AppendLiteral("px dotted WindowText !important; } ");
|
2008-01-18 05:23:44 +00:00
|
|
|
// insert the rules
|
|
|
|
result = mPrefStyleSheet->
|
|
|
|
InsertRuleInternal(strRule, sInsertPrefSheetRulesAt, &index);
|
|
|
|
NS_ENSURE_SUCCESS(result, result);
|
|
|
|
if (focusRingWidth != 1) {
|
|
|
|
// If the focus ring width is different from the default, fix buttons with rings
|
|
|
|
strRule.AssignLiteral("button::-moz-focus-inner, input[type=\"reset\"]::-moz-focus-inner,");
|
|
|
|
strRule.AppendLiteral("input[type=\"button\"]::-moz-focus-inner, ");
|
|
|
|
strRule.AppendLiteral("input[type=\"submit\"]::-moz-focus-inner { padding: 1px 2px 1px 2px; border: ");
|
2001-04-09 22:17:11 +00:00
|
|
|
strRule.AppendInt(focusRingWidth);
|
2008-10-08 23:28:31 +00:00
|
|
|
if (focusRingStyle == 0) // solid
|
|
|
|
strRule.AppendLiteral("px solid transparent !important; } ");
|
|
|
|
else
|
|
|
|
strRule.AppendLiteral("px dotted transparent !important; } ");
|
2008-01-18 05:23:44 +00:00
|
|
|
result = mPrefStyleSheet->
|
|
|
|
InsertRuleInternal(strRule, sInsertPrefSheetRulesAt, &index);
|
2001-09-08 21:42:02 +00:00
|
|
|
NS_ENSURE_SUCCESS(result, result);
|
|
|
|
|
2008-01-18 05:23:44 +00:00
|
|
|
strRule.AssignLiteral("button:focus::-moz-focus-inner, input[type=\"reset\"]:focus::-moz-focus-inner,");
|
|
|
|
strRule.AppendLiteral("input[type=\"button\"]:focus::-moz-focus-inner, input[type=\"submit\"]:focus::-moz-focus-inner {");
|
|
|
|
strRule.AppendLiteral("border-color: ButtonText !important; }");
|
|
|
|
result = mPrefStyleSheet->
|
|
|
|
InsertRuleInternal(strRule, sInsertPrefSheetRulesAt, &index);
|
2001-04-09 22:17:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2006-06-08 14:32:20 +00:00
|
|
|
void
|
|
|
|
PresShell::AddUserSheet(nsISupports* aSheet)
|
|
|
|
{
|
|
|
|
// Make sure this does what DocumentViewerImpl::CreateStyleSet does wrt
|
|
|
|
// ordering. We want this new sheet to come after all the existing stylesheet
|
|
|
|
// service sheets, but before other user sheets; see nsIStyleSheetService.idl
|
|
|
|
// for the ordering. Just remove and readd all the nsStyleSheetService
|
|
|
|
// sheets.
|
|
|
|
nsCOMPtr<nsIStyleSheetService> dummy =
|
|
|
|
do_GetService(NS_STYLESHEETSERVICE_CONTRACTID);
|
|
|
|
|
|
|
|
mStyleSet->BeginUpdate();
|
|
|
|
|
|
|
|
nsStyleSheetService *sheetService = nsStyleSheetService::gInstance;
|
|
|
|
nsCOMArray<nsIStyleSheet> & userSheets = *sheetService->UserStyleSheets();
|
|
|
|
PRInt32 i;
|
|
|
|
// Iterate forwards when removing so the searches for RemoveStyleSheet are as
|
|
|
|
// short as possible.
|
|
|
|
for (i = 0; i < userSheets.Count(); ++i) {
|
|
|
|
mStyleSet->RemoveStyleSheet(nsStyleSet::eUserSheet, userSheets[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now iterate backwards, so that the order of userSheets will be the same as
|
|
|
|
// the order of sheets from it in the style set.
|
|
|
|
for (i = userSheets.Count() - 1; i >= 0; --i) {
|
|
|
|
mStyleSet->PrependStyleSheet(nsStyleSet::eUserSheet, userSheets[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
mStyleSet->EndUpdate();
|
|
|
|
|
|
|
|
ReconstructStyleData();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PresShell::AddAgentSheet(nsISupports* aSheet)
|
|
|
|
{
|
|
|
|
// Make sure this does what DocumentViewerImpl::CreateStyleSet does
|
|
|
|
// wrt ordering.
|
|
|
|
nsCOMPtr<nsIStyleSheet> sheet = do_QueryInterface(aSheet);
|
|
|
|
if (!sheet) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mStyleSet->AppendStyleSheet(nsStyleSet::eAgentSheet, sheet);
|
|
|
|
ReconstructStyleData();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PresShell::RemoveSheet(nsStyleSet::sheetType aType, nsISupports* aSheet)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIStyleSheet> sheet = do_QueryInterface(aSheet);
|
|
|
|
if (!sheet) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mStyleSet->RemoveStyleSheet(aType, sheet);
|
|
|
|
ReconstructStyleData();
|
|
|
|
}
|
2001-04-09 22:17:11 +00:00
|
|
|
|
2000-04-28 06:21:31 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
PresShell::SetDisplaySelection(PRInt16 aToggle)
|
|
|
|
{
|
2006-04-26 02:01:07 +00:00
|
|
|
mSelection->SetDisplaySelection(aToggle);
|
|
|
|
return NS_OK;
|
2000-04-28 06:21:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
PresShell::GetDisplaySelection(PRInt16 *aToggle)
|
|
|
|
{
|
2006-04-26 02:01:07 +00:00
|
|
|
*aToggle = mSelection->GetDisplaySelection();
|
|
|
|
return NS_OK;
|
2000-04-28 06:21:31 +00:00
|
|
|
}
|
|
|
|
|
1999-02-12 17:45:58 +00:00
|
|
|
NS_IMETHODIMP
|
2000-09-14 11:45:01 +00:00
|
|
|
PresShell::GetSelection(SelectionType aType, nsISelection **aSelection)
|
1998-12-08 18:26:06 +00:00
|
|
|
{
|
|
|
|
if (!aSelection || !mSelection)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
2006-04-26 02:01:07 +00:00
|
|
|
|
|
|
|
*aSelection = mSelection->GetSelection(aType);
|
|
|
|
|
|
|
|
if (!(*aSelection))
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
|
|
|
NS_ADDREF(*aSelection);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsISelection*
|
|
|
|
PresShell::GetCurrentSelection(SelectionType aType)
|
|
|
|
{
|
|
|
|
if (!mSelection)
|
|
|
|
return nsnull;
|
|
|
|
|
|
|
|
return mSelection->GetSelection(aType);
|
1998-12-08 18:26:06 +00:00
|
|
|
}
|
|
|
|
|
1999-08-30 21:54:40 +00:00
|
|
|
NS_IMETHODIMP
|
2002-06-13 20:35:12 +00:00
|
|
|
PresShell::ScrollSelectionIntoView(SelectionType aType, SelectionRegion aRegion, PRBool aIsSynchronous)
|
1999-08-30 21:54:40 +00:00
|
|
|
{
|
|
|
|
if (!mSelection)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
2002-06-13 20:35:12 +00:00
|
|
|
return mSelection->ScrollSelectionIntoView(aType, aRegion, aIsSynchronous);
|
1999-08-30 21:54:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
PresShell::RepaintSelection(SelectionType aType)
|
|
|
|
{
|
|
|
|
if (!mSelection)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
2006-04-26 02:01:07 +00:00
|
|
|
return mSelection->RepaintSelection(aType);
|
1999-08-30 21:54:40 +00:00
|
|
|
}
|
|
|
|
|
1998-04-13 20:24:54 +00:00
|
|
|
// Make shell be a document observer
|
2010-03-20 21:54:19 +00:00
|
|
|
void
|
1998-05-09 03:22:41 +00:00
|
|
|
PresShell::BeginObservingDocument()
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
2007-05-14 03:52:48 +00:00
|
|
|
if (mDocument && !mIsDestroying) {
|
2009-12-11 04:02:13 +00:00
|
|
|
mDocument->AddObserver(this);
|
2005-03-25 04:27:21 +00:00
|
|
|
if (mIsDocumentGone) {
|
|
|
|
NS_WARNING("Adding a presshell that was disconnected from the document "
|
|
|
|
"as a document observer? Sounds wrong...");
|
|
|
|
mIsDocumentGone = PR_FALSE;
|
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make shell stop being a document observer
|
2010-03-20 21:54:19 +00:00
|
|
|
void
|
1998-05-09 03:22:41 +00:00
|
|
|
PresShell::EndObservingDocument()
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
2005-02-18 16:11:53 +00:00
|
|
|
// XXXbz do we need to tell the frame constructor that the document
|
|
|
|
// is gone, perhaps? Except for printing it's NOT gone, sometimes.
|
2001-05-01 22:54:11 +00:00
|
|
|
mIsDocumentGone = PR_TRUE;
|
1999-05-04 23:27:42 +00:00
|
|
|
if (mDocument) {
|
2009-12-11 04:02:13 +00:00
|
|
|
mDocument->RemoveObserver(this);
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-08-27 21:50:37 +00:00
|
|
|
#ifdef DEBUG_kipp
|
|
|
|
char* nsPresShell_ReflowStackPointerTop;
|
|
|
|
#endif
|
|
|
|
|
2010-03-20 21:54:19 +00:00
|
|
|
nsresult
|
1998-09-10 19:32:14 +00:00
|
|
|
PresShell::InitialReflow(nscoord aWidth, nscoord aHeight)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
2007-05-01 17:15:08 +00:00
|
|
|
if (mIsDestroying) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-05-12 02:04:58 +00:00
|
|
|
if (!mDocument) {
|
|
|
|
// Nothing to do
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-05-19 23:22:19 +00:00
|
|
|
NS_TIME_FUNCTION_WITH_DOCURL;
|
|
|
|
|
2008-10-10 17:44:43 +00:00
|
|
|
NS_ASSERTION(!mDidInitialReflow, "Why are we being called?");
|
|
|
|
|
2006-05-15 17:51:35 +00:00
|
|
|
nsCOMPtr<nsIPresShell> kungFuDeathGrip(this);
|
2001-08-07 18:57:15 +00:00
|
|
|
mDidInitialReflow = PR_TRUE;
|
1998-09-10 19:32:14 +00:00
|
|
|
|
1999-12-23 02:02:33 +00:00
|
|
|
#ifdef NS_DEBUG
|
|
|
|
if (VERIFY_REFLOW_NOISY_RC & gVerifyReflowFlags) {
|
|
|
|
if (mDocument) {
|
2004-01-09 23:54:21 +00:00
|
|
|
nsIURI *uri = mDocument->GetDocumentURI();
|
1999-12-23 02:02:33 +00:00
|
|
|
if (uri) {
|
2002-03-06 07:48:55 +00:00
|
|
|
nsCAutoString url;
|
|
|
|
uri->GetSpec(url);
|
|
|
|
printf("*** PresShell::InitialReflow (this=%p, url='%s')\n", (void*)this, url.get());
|
1999-12-23 02:02:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2003-02-27 23:09:51 +00:00
|
|
|
if (mCaret)
|
|
|
|
mCaret->EraseCaret();
|
2004-10-09 01:39:21 +00:00
|
|
|
|
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 05:38:33 +00:00
|
|
|
// XXX Do a full invalidate at the beginning so that invalidates along
|
|
|
|
// the way don't have region accumulation issues?
|
|
|
|
|
2007-05-01 17:15:08 +00:00
|
|
|
mPresContext->SetVisibleArea(nsRect(0, 0, aWidth, aHeight));
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1999-10-18 22:20:37 +00:00
|
|
|
// Get the root frame from the frame manager
|
2009-05-12 02:04:58 +00:00
|
|
|
// XXXbz it would be nice to move this somewhere else... like frame manager
|
|
|
|
// Init(), say. But we need to make sure our views are all set up by the
|
|
|
|
// time we do this!
|
2004-03-06 04:46:11 +00:00
|
|
|
nsIFrame* rootFrame = FrameManager()->GetRootFrame();
|
2009-05-12 02:04:58 +00:00
|
|
|
NS_ASSERTION(!rootFrame, "How did that happen, exactly?");
|
|
|
|
if (!rootFrame) {
|
|
|
|
nsAutoScriptBlocker scriptBlocker;
|
|
|
|
mFrameConstructor->BeginUpdate();
|
|
|
|
mFrameConstructor->ConstructRootFrame(&rootFrame);
|
|
|
|
FrameManager()->SetRootFrame(rootFrame);
|
|
|
|
mFrameConstructor->EndUpdate();
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ENSURE_STATE(!mHaveShutDown);
|
|
|
|
|
|
|
|
if (!rootFrame) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
2010-04-30 13:12:05 +00:00
|
|
|
Element *root = mDocument->GetRootElement();
|
2009-05-12 02:04:58 +00:00
|
|
|
|
2001-06-20 03:27:48 +00:00
|
|
|
if (root) {
|
2008-03-14 23:08:57 +00:00
|
|
|
{
|
2009-06-28 20:04:35 +00:00
|
|
|
nsAutoCauseReflowNotifier reflowNotifier(this);
|
2008-03-14 23:08:57 +00:00
|
|
|
mFrameConstructor->BeginUpdate();
|
|
|
|
|
|
|
|
// Have the style sheet processor construct frame for the root
|
|
|
|
// content object down
|
2010-01-18 09:26:40 +00:00
|
|
|
mFrameConstructor->ContentInserted(nsnull, root, 0, nsnull, PR_FALSE);
|
2008-03-14 23:08:57 +00:00
|
|
|
VERIFY_STYLE_TREE;
|
2007-05-14 03:52:48 +00:00
|
|
|
|
2008-03-14 23:08:57 +00:00
|
|
|
// Something in mFrameConstructor->ContentInserted may have caused
|
|
|
|
// Destroy() to get called, bug 337586.
|
|
|
|
NS_ENSURE_STATE(!mHaveShutDown);
|
2008-03-11 02:18:15 +00:00
|
|
|
|
2008-03-14 23:08:57 +00:00
|
|
|
mFrameConstructor->EndUpdate();
|
|
|
|
}
|
2007-10-02 04:37:36 +00:00
|
|
|
|
2009-05-12 02:04:58 +00:00
|
|
|
// nsAutoScriptBlocker going out of scope may have killed us too
|
2008-03-14 23:08:57 +00:00
|
|
|
NS_ENSURE_STATE(!mHaveShutDown);
|
2008-03-11 02:18:15 +00:00
|
|
|
|
2007-05-14 03:52:48 +00:00
|
|
|
// Run the XBL binding constructors for any new frames we've constructed
|
|
|
|
mDocument->BindingManager()->ProcessAttachedQueue();
|
|
|
|
|
2010-05-19 23:22:19 +00:00
|
|
|
NS_TIME_FUNCTION_MARK("XBL binding constructors fired");
|
|
|
|
|
2007-05-14 03:52:48 +00:00
|
|
|
// Constructors may have killed us too
|
|
|
|
NS_ENSURE_STATE(!mHaveShutDown);
|
|
|
|
|
|
|
|
// Now flush out pending restyles before we actually reflow, in
|
|
|
|
// case XBL constructors changed styles somewhere.
|
2009-01-02 15:41:43 +00:00
|
|
|
{
|
|
|
|
nsAutoScriptBlocker scriptBlocker;
|
2010-01-18 09:26:40 +00:00
|
|
|
mFrameConstructor->CreateNeededFrames();
|
2009-01-02 15:41:43 +00:00
|
|
|
mFrameConstructor->ProcessPendingRestyles();
|
|
|
|
}
|
2007-05-14 03:52:48 +00:00
|
|
|
|
|
|
|
// And that might have run _more_ XBL constructors
|
|
|
|
NS_ENSURE_STATE(!mHaveShutDown);
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
2009-05-12 02:04:58 +00:00
|
|
|
NS_ASSERTION(rootFrame, "How did that happen?");
|
2007-05-06 19:16:51 +00:00
|
|
|
|
2009-05-12 02:04:58 +00:00
|
|
|
// Note: Because the frame just got created, it has the NS_FRAME_IS_DIRTY
|
|
|
|
// bit set. Unset it so that FrameNeedsReflow() will work right.
|
|
|
|
NS_ASSERTION(!mDirtyRoots.Contains(rootFrame),
|
|
|
|
"Why is the root in mDirtyRoots already?");
|
2007-05-06 19:16:51 +00:00
|
|
|
|
2009-05-12 02:04:58 +00:00
|
|
|
rootFrame->RemoveStateBits(NS_FRAME_IS_DIRTY |
|
|
|
|
NS_FRAME_HAS_DIRTY_CHILDREN);
|
|
|
|
FrameNeedsReflow(rootFrame, eResize, NS_FRAME_IS_DIRTY);
|
|
|
|
|
|
|
|
NS_ASSERTION(mDirtyRoots.Contains(rootFrame),
|
|
|
|
"Should be in mDirtyRoots now");
|
2010-02-19 17:11:40 +00:00
|
|
|
NS_ASSERTION(mReflowScheduled, "Why no reflow scheduled?");
|
1998-09-10 19:32:14 +00:00
|
|
|
|
2007-04-26 02:33:02 +00:00
|
|
|
// Restore our root scroll position now if we're getting here after EndLoad
|
2007-05-01 17:15:08 +00:00
|
|
|
// got called, since this is our one chance to do it. Note that we need not
|
|
|
|
// have reflowed for this to work; when the scrollframe is finally reflowed
|
|
|
|
// it'll puick up the position we store in it here.
|
2007-04-26 02:33:02 +00:00
|
|
|
if (!mDocumentLoading) {
|
|
|
|
RestoreRootScrollPosition();
|
|
|
|
}
|
1999-10-15 04:29:30 +00:00
|
|
|
|
2001-05-03 01:41:10 +00:00
|
|
|
// For printing, we just immediately unsuppress.
|
2004-03-03 18:24:20 +00:00
|
|
|
if (!mPresContext->IsPaginated()) {
|
2001-05-03 01:41:10 +00:00
|
|
|
// Kick off a one-shot timer based off our pref value. When this timer
|
|
|
|
// fires, if painting is still locked down, then we will go ahead and
|
|
|
|
// trigger a full invalidate and allow painting to proceed normally.
|
|
|
|
mPaintingSuppressed = PR_TRUE;
|
|
|
|
mPaintSuppressionTimer = do_CreateInstance("@mozilla.org/timer;1");
|
|
|
|
if (!mPaintSuppressionTimer)
|
|
|
|
// Uh-oh. We must be out of memory. No point in keeping painting locked down.
|
|
|
|
mPaintingSuppressed = PR_FALSE;
|
|
|
|
else {
|
|
|
|
// Initialize the timer.
|
2004-04-29 23:34:19 +00:00
|
|
|
|
|
|
|
// Default to PAINTLOCK_EVENT_DELAY if we can't get the pref value.
|
|
|
|
PRInt32 delay =
|
|
|
|
nsContentUtils::GetIntPref("nglayout.initialpaint.delay",
|
|
|
|
PAINTLOCK_EVENT_DELAY);
|
2002-09-07 05:38:16 +00:00
|
|
|
|
2004-04-29 23:34:19 +00:00
|
|
|
mPaintSuppressionTimer->InitWithFuncCallback(sPaintSuppressionCallback,
|
|
|
|
this, delay,
|
2002-09-07 05:38:16 +00:00
|
|
|
nsITimer::TYPE_ONE_SHOT);
|
2001-05-03 01:41:10 +00:00
|
|
|
}
|
2001-04-25 19:52:49 +00:00
|
|
|
}
|
|
|
|
|
1998-09-10 19:32:14 +00:00
|
|
|
return NS_OK; //XXX this needs to be real. MMP
|
|
|
|
}
|
|
|
|
|
2001-04-25 19:52:49 +00:00
|
|
|
void
|
|
|
|
PresShell::sPaintSuppressionCallback(nsITimer *aTimer, void* aPresShell)
|
|
|
|
{
|
2009-05-12 19:07:08 +00:00
|
|
|
nsRefPtr<PresShell> self = static_cast<PresShell*>(aPresShell);
|
2001-04-25 19:52:49 +00:00
|
|
|
if (self)
|
2001-05-01 22:54:11 +00:00
|
|
|
self->UnsuppressPainting();
|
2001-04-25 19:52:49 +00:00
|
|
|
}
|
|
|
|
|
2009-08-15 08:49:20 +00:00
|
|
|
void
|
|
|
|
PresShell::AsyncResizeEventCallback(nsITimer* aTimer, void* aPresShell)
|
|
|
|
{
|
|
|
|
static_cast<PresShell*>(aPresShell)->FireResizeEvent();
|
|
|
|
}
|
|
|
|
|
2010-03-20 21:54:19 +00:00
|
|
|
nsresult
|
1998-09-10 19:32:14 +00:00
|
|
|
PresShell::ResizeReflow(nscoord aWidth, nscoord aHeight)
|
|
|
|
{
|
2007-05-16 03:22:45 +00:00
|
|
|
NS_PRECONDITION(!mIsReflowing, "Shouldn't be in reflow here!");
|
2008-03-12 22:04:45 +00:00
|
|
|
NS_PRECONDITION(aWidth != NS_UNCONSTRAINEDSIZE,
|
|
|
|
"shouldn't use unconstrained widths anymore");
|
2007-05-16 03:22:45 +00:00
|
|
|
|
2005-05-13 19:47:38 +00:00
|
|
|
// If we don't have a root frame yet, that means we haven't had our initial
|
|
|
|
// reflow... If that's the case, and aWidth or aHeight is unconstrained,
|
|
|
|
// ignore them altogether.
|
|
|
|
nsIFrame* rootFrame = FrameManager()->GetRootFrame();
|
|
|
|
|
2008-03-12 22:04:45 +00:00
|
|
|
if (!rootFrame && aHeight == NS_UNCONSTRAINEDSIZE) {
|
|
|
|
// We can't do the work needed for SizeToContent without a root
|
|
|
|
// frame, and we want to return before setting the visible area.
|
2005-05-13 19:47:38 +00:00
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
1998-09-10 19:32:14 +00:00
|
|
|
|
2007-04-25 15:49:55 +00:00
|
|
|
mPresContext->SetVisibleArea(nsRect(0, 0, aWidth, aHeight));
|
1999-11-01 22:12:45 +00:00
|
|
|
|
2007-04-25 15:49:55 +00:00
|
|
|
// There isn't anything useful we can do if the initial reflow hasn't happened
|
|
|
|
if (!rootFrame)
|
|
|
|
return NS_OK;
|
1998-10-02 01:12:39 +00:00
|
|
|
|
2009-01-05 16:26:59 +00:00
|
|
|
NS_ASSERTION(mViewManager, "Must have view manager");
|
|
|
|
nsCOMPtr<nsIViewManager> viewManagerDeathGrip = mViewManager;
|
|
|
|
// Take this ref after viewManager so it'll make sure to go away first
|
|
|
|
nsCOMPtr<nsIPresShell> kungFuDeathGrip(this);
|
2008-01-29 04:10:59 +00:00
|
|
|
if (!GetPresContext()->SupressingResizeReflow())
|
|
|
|
{
|
|
|
|
nsIViewManager::UpdateViewBatch batch(mViewManager);
|
2007-04-26 01:34:28 +00:00
|
|
|
|
2009-12-23 00:09:10 +00:00
|
|
|
// Have to make sure that the content notifications are flushed before we
|
|
|
|
// start messing with the frame model; otherwise we can get content doubling.
|
|
|
|
mDocument->FlushPendingNotifications(Flush_ContentAndNotify);
|
|
|
|
|
2008-01-29 04:10:59 +00:00
|
|
|
// Make sure style is up to date
|
2009-01-02 15:41:43 +00:00
|
|
|
{
|
|
|
|
nsAutoScriptBlocker scriptBlocker;
|
2010-01-18 09:26:40 +00:00
|
|
|
mFrameConstructor->CreateNeededFrames();
|
2009-01-02 15:41:43 +00:00
|
|
|
mFrameConstructor->ProcessPendingRestyles();
|
|
|
|
}
|
2007-09-20 02:46:28 +00:00
|
|
|
|
2008-01-29 04:10:59 +00:00
|
|
|
if (!mIsDestroying) {
|
|
|
|
// XXX Do a full invalidate at the beginning so that invalidates along
|
|
|
|
// the way don't have region accumulation issues?
|
2007-09-20 02:46:28 +00:00
|
|
|
|
2008-03-11 02:18:15 +00:00
|
|
|
{
|
2009-06-28 20:04:35 +00:00
|
|
|
nsAutoCauseReflowNotifier crNotifier(this);
|
2008-03-14 23:08:57 +00:00
|
|
|
WillDoReflow();
|
|
|
|
|
2008-01-29 04:10:59 +00:00
|
|
|
// Kick off a top-down reflow
|
|
|
|
AUTO_LAYOUT_PHASE_ENTRY_POINT(GetPresContext(), Reflow);
|
|
|
|
|
|
|
|
mDirtyRoots.RemoveElement(rootFrame);
|
2009-04-21 23:53:52 +00:00
|
|
|
DoReflow(rootFrame, PR_TRUE);
|
2008-01-29 04:10:59 +00:00
|
|
|
}
|
|
|
|
|
2009-04-21 23:53:52 +00:00
|
|
|
DidDoReflow(PR_TRUE);
|
2007-09-20 23:28:26 +00:00
|
|
|
}
|
|
|
|
|
2008-01-29 04:10:59 +00:00
|
|
|
batch.EndUpdateViewBatch(NS_VMREFRESH_NO_SYNC);
|
2007-04-25 10:44:29 +00:00
|
|
|
}
|
2007-04-25 15:49:55 +00:00
|
|
|
|
2008-03-12 22:04:45 +00:00
|
|
|
if (aHeight == NS_UNCONSTRAINEDSIZE) {
|
|
|
|
mPresContext->SetVisibleArea(
|
|
|
|
nsRect(0, 0, aWidth, rootFrame->GetRect().height));
|
|
|
|
}
|
|
|
|
|
2009-08-15 08:49:20 +00:00
|
|
|
if (!mIsDestroying && !mResizeEvent.IsPending() &&
|
|
|
|
!mAsyncResizeTimerIsActive) {
|
|
|
|
if (mInResize) {
|
|
|
|
if (!mAsyncResizeEventTimer) {
|
|
|
|
mAsyncResizeEventTimer = do_CreateInstance("@mozilla.org/timer;1");
|
|
|
|
}
|
|
|
|
if (mAsyncResizeEventTimer) {
|
|
|
|
mAsyncResizeTimerIsActive = PR_TRUE;
|
|
|
|
mAsyncResizeEventTimer->InitWithFuncCallback(AsyncResizeEventCallback,
|
|
|
|
this, 15,
|
|
|
|
nsITimer::TYPE_ONE_SHOT);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
nsRefPtr<nsRunnableMethod<PresShell> > resizeEvent =
|
2010-04-20 23:21:35 +00:00
|
|
|
NS_NewRunnableMethod(this, &PresShell::FireResizeEvent);
|
2009-08-15 08:49:20 +00:00
|
|
|
if (NS_SUCCEEDED(NS_DispatchToCurrentThread(resizeEvent))) {
|
|
|
|
mResizeEvent = resizeEvent;
|
|
|
|
}
|
2009-01-14 20:42:25 +00:00
|
|
|
}
|
2007-09-20 23:28:26 +00:00
|
|
|
}
|
2007-04-25 15:49:55 +00:00
|
|
|
|
2001-04-17 23:25:21 +00:00
|
|
|
return NS_OK; //XXX this needs to be real. MMP
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PresShell::FireResizeEvent()
|
|
|
|
{
|
2009-08-15 08:49:20 +00:00
|
|
|
if (mAsyncResizeTimerIsActive) {
|
|
|
|
mAsyncResizeTimerIsActive = PR_FALSE;
|
|
|
|
mAsyncResizeEventTimer->Cancel();
|
|
|
|
}
|
2009-01-14 20:42:25 +00:00
|
|
|
mResizeEvent.Revoke();
|
|
|
|
|
2001-05-01 22:54:11 +00:00
|
|
|
if (mIsDocumentGone)
|
|
|
|
return;
|
|
|
|
|
2000-05-17 05:27:22 +00:00
|
|
|
//Send resize event from here.
|
2005-04-28 23:48:28 +00:00
|
|
|
nsEvent event(PR_TRUE, NS_RESIZE_EVENT);
|
2000-11-08 00:31:06 +00:00
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
2000-05-17 05:27:22 +00:00
|
|
|
|
2005-11-28 23:56:44 +00:00
|
|
|
nsPIDOMWindow *window = mDocument->GetWindow();
|
|
|
|
if (window) {
|
2009-08-15 08:49:20 +00:00
|
|
|
nsCOMPtr<nsIPresShell> kungFuDeathGrip(this);
|
|
|
|
mInResize = PR_TRUE;
|
2006-03-07 17:08:51 +00:00
|
|
|
nsEventDispatcher::Dispatch(window, mPresContext, &event, nsnull, &status);
|
2009-08-15 08:49:20 +00:00
|
|
|
mInResize = PR_FALSE;
|
2001-05-04 03:04:40 +00:00
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
2010-03-31 12:41:54 +00:00
|
|
|
void
|
2001-12-01 00:22:00 +00:00
|
|
|
PresShell::SetIgnoreFrameDestruction(PRBool aIgnore)
|
|
|
|
{
|
|
|
|
mIgnoreFrameDestruction = aIgnore;
|
|
|
|
}
|
|
|
|
|
2010-03-31 12:41:54 +00:00
|
|
|
void
|
1999-07-16 23:27:46 +00:00
|
|
|
PresShell::NotifyDestroyingFrame(nsIFrame* aFrame)
|
|
|
|
{
|
2010-05-19 23:22:19 +00:00
|
|
|
NS_TIME_FUNCTION_MIN(1.0);
|
|
|
|
|
2001-12-01 00:22:00 +00:00
|
|
|
if (!mIgnoreFrameDestruction) {
|
2010-01-14 02:30:05 +00:00
|
|
|
mPresContext->StopImagesFor(aFrame);
|
|
|
|
|
2005-04-01 23:07:00 +00:00
|
|
|
mFrameConstructor->NotifyDestroyingFrame(aFrame);
|
|
|
|
|
2009-02-03 14:42:18 +00:00
|
|
|
for (PRInt32 idx = mDirtyRoots.Length(); idx; ) {
|
2007-05-16 03:22:45 +00:00
|
|
|
--idx;
|
|
|
|
if (mDirtyRoots[idx] == aFrame) {
|
|
|
|
mDirtyRoots.RemoveElementAt(idx);
|
|
|
|
}
|
|
|
|
}
|
1999-07-16 23:27:46 +00:00
|
|
|
|
2001-12-01 00:22:00 +00:00
|
|
|
// Notify the frame manager
|
2004-03-06 04:46:11 +00:00
|
|
|
FrameManager()->NotifyDestroyingFrame(aFrame);
|
2004-08-24 18:50:29 +00:00
|
|
|
|
|
|
|
// Remove frame properties
|
2010-03-29 01:46:55 +00:00
|
|
|
mPresContext->PropertyTable()->DeleteAllFor(aFrame);
|
2009-11-26 09:12:20 +00:00
|
|
|
|
|
|
|
if (aFrame == mCurrentEventFrame) {
|
|
|
|
mCurrentEventContent = aFrame->GetContent();
|
|
|
|
mCurrentEventFrame = nsnull;
|
|
|
|
}
|
2010-03-31 12:41:54 +00:00
|
|
|
|
2009-11-26 09:12:20 +00:00
|
|
|
#ifdef NS_DEBUG
|
|
|
|
if (aFrame == mDrawEventTargetFrame) {
|
|
|
|
mDrawEventTargetFrame = nsnull;
|
|
|
|
}
|
|
|
|
#endif
|
2010-03-31 12:41:54 +00:00
|
|
|
|
2009-11-26 09:12:20 +00:00
|
|
|
for (unsigned int i=0; i < mCurrentEventFrameStack.Length(); i++) {
|
|
|
|
if (aFrame == mCurrentEventFrameStack.ElementAt(i)) {
|
|
|
|
//One of our stack frames was deleted. Get its content so that when we
|
|
|
|
//pop it we can still get its new frame from its content
|
|
|
|
nsIContent *currentEventContent = aFrame->GetContent();
|
|
|
|
mCurrentEventContentStack.ReplaceObjectAt(currentEventContent, i);
|
|
|
|
mCurrentEventFrameStack[i] = nsnull;
|
|
|
|
}
|
|
|
|
}
|
2010-03-30 23:56:44 +00:00
|
|
|
|
2009-11-26 09:12:20 +00:00
|
|
|
mFramesToDirty.RemoveEntry(aFrame);
|
1999-08-05 20:17:44 +00:00
|
|
|
}
|
1999-07-16 23:27:46 +00:00
|
|
|
}
|
1999-02-13 04:45:44 +00:00
|
|
|
|
2010-03-31 13:21:17 +00:00
|
|
|
already_AddRefed<nsCaret> PresShell::GetCaret() const
|
1999-02-13 04:45:44 +00:00
|
|
|
{
|
2010-03-31 12:39:31 +00:00
|
|
|
nsCaret* caret = mCaret;
|
|
|
|
NS_IF_ADDREF(caret);
|
|
|
|
return caret;
|
1999-02-13 04:45:44 +00:00
|
|
|
}
|
|
|
|
|
2010-03-31 12:39:31 +00:00
|
|
|
void PresShell::MaybeInvalidateCaretPosition()
|
2006-11-07 01:35:36 +00:00
|
|
|
{
|
|
|
|
if (mCaret) {
|
|
|
|
mCaret->InvalidateOutsideCaret();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-16 10:52:01 +00:00
|
|
|
void PresShell::SetCaret(nsCaret *aNewCaret)
|
2006-04-17 23:16:46 +00:00
|
|
|
{
|
|
|
|
mCaret = aNewCaret;
|
2007-09-22 21:06:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PresShell::RestoreCaret()
|
|
|
|
{
|
|
|
|
mCaret = mOriginalCaret;
|
2006-04-17 23:16:46 +00:00
|
|
|
}
|
|
|
|
|
1999-08-04 20:46:16 +00:00
|
|
|
NS_IMETHODIMP PresShell::SetCaretEnabled(PRBool aInEnable)
|
1999-04-01 23:58:11 +00:00
|
|
|
{
|
2008-09-20 13:42:03 +00:00
|
|
|
PRBool oldEnabled = mCaretEnabled;
|
2003-03-12 03:22:11 +00:00
|
|
|
|
2000-06-16 14:05:03 +00:00
|
|
|
mCaretEnabled = aInEnable;
|
2003-03-12 03:22:11 +00:00
|
|
|
|
2000-06-16 14:05:03 +00:00
|
|
|
if (mCaret && (mCaretEnabled != oldEnabled))
|
|
|
|
{
|
2000-09-07 05:26:25 +00:00
|
|
|
/* Don't change the caret's selection here! This was an evil side-effect of SetCaretEnabled()
|
2000-06-01 02:39:52 +00:00
|
|
|
nsCOMPtr<nsIDOMSelection> domSel;
|
|
|
|
if (NS_SUCCEEDED(GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(domSel))) && domSel)
|
|
|
|
mCaret->SetCaretDOMSelection(domSel);
|
2000-09-07 05:26:25 +00:00
|
|
|
*/
|
2008-07-16 10:52:01 +00:00
|
|
|
mCaret->SetCaretVisible(mCaretEnabled);
|
2000-06-16 14:05:03 +00:00
|
|
|
}
|
2003-03-12 03:22:11 +00:00
|
|
|
|
2008-07-16 10:52:01 +00:00
|
|
|
return NS_OK;
|
1999-04-01 23:58:11 +00:00
|
|
|
}
|
|
|
|
|
2000-05-11 04:25:43 +00:00
|
|
|
NS_IMETHODIMP PresShell::SetCaretReadOnly(PRBool aReadOnly)
|
|
|
|
{
|
2003-02-27 23:09:51 +00:00
|
|
|
if (mCaret)
|
|
|
|
mCaret->SetCaretReadOnly(aReadOnly);
|
|
|
|
return NS_OK;
|
2000-05-11 04:25:43 +00:00
|
|
|
}
|
|
|
|
|
1999-08-04 20:46:16 +00:00
|
|
|
NS_IMETHODIMP PresShell::GetCaretEnabled(PRBool *aOutEnabled)
|
|
|
|
{
|
2003-02-27 23:09:51 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aOutEnabled);
|
1999-08-04 20:46:16 +00:00
|
|
|
*aOutEnabled = mCaretEnabled;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-06-25 01:14:25 +00:00
|
|
|
NS_IMETHODIMP PresShell::SetCaretVisibilityDuringSelection(PRBool aVisibility)
|
|
|
|
{
|
|
|
|
if (mCaret)
|
|
|
|
mCaret->SetVisibilityDuringSelection(aVisibility);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-04-08 18:52:48 +00:00
|
|
|
NS_IMETHODIMP PresShell::GetCaretVisible(PRBool *aOutIsVisible)
|
|
|
|
{
|
|
|
|
*aOutIsVisible = PR_FALSE;
|
|
|
|
if (mCaret) {
|
|
|
|
nsresult rv = mCaret->GetCaretVisible(aOutIsVisible);
|
|
|
|
NS_ENSURE_SUCCESS(rv,rv);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-12-18 01:29:49 +00:00
|
|
|
NS_IMETHODIMP PresShell::SetSelectionFlags(PRInt16 aInEnable)
|
1999-05-17 00:21:18 +00:00
|
|
|
{
|
2001-12-18 21:05:55 +00:00
|
|
|
mSelectionFlags = aInEnable;
|
1999-05-17 00:21:18 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-12-18 01:29:49 +00:00
|
|
|
NS_IMETHODIMP PresShell::GetSelectionFlags(PRInt16 *aOutEnable)
|
1999-05-17 00:21:18 +00:00
|
|
|
{
|
1999-08-04 20:46:16 +00:00
|
|
|
if (!aOutEnable)
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
2001-12-18 21:05:55 +00:00
|
|
|
*aOutEnable = mSelectionFlags;
|
1999-05-17 00:21:18 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-12-02 21:45:21 +00:00
|
|
|
//implementation of nsISelectionController
|
1999-04-01 23:58:11 +00:00
|
|
|
|
1999-10-22 00:19:18 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
PresShell::CharacterMove(PRBool aForward, PRBool aExtend)
|
1999-02-19 23:47:36 +00:00
|
|
|
{
|
1999-12-11 00:02:08 +00:00
|
|
|
return mSelection->CharacterMove(aForward, aExtend);
|
1999-10-22 00:19:18 +00:00
|
|
|
}
|
|
|
|
|
2008-10-16 07:44:32 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
PresShell::CharacterExtendForDelete()
|
|
|
|
{
|
|
|
|
return mSelection->CharacterExtendForDelete();
|
|
|
|
}
|
|
|
|
|
2010-06-04 17:28:19 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
PresShell::CharacterExtendForBackspace()
|
|
|
|
{
|
|
|
|
return mSelection->CharacterExtendForBackspace();
|
|
|
|
}
|
|
|
|
|
1999-10-22 00:19:18 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
PresShell::WordMove(PRBool aForward, PRBool aExtend)
|
|
|
|
{
|
1999-12-11 00:02:08 +00:00
|
|
|
return mSelection->WordMove(aForward, aExtend);
|
1999-10-22 00:19:18 +00:00
|
|
|
}
|
|
|
|
|
2006-07-18 07:28:38 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
PresShell::WordExtendForDelete(PRBool aForward)
|
|
|
|
{
|
|
|
|
return mSelection->WordExtendForDelete(aForward);
|
|
|
|
}
|
|
|
|
|
1999-10-22 00:19:18 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
PresShell::LineMove(PRBool aForward, PRBool aExtend)
|
|
|
|
{
|
2001-06-20 04:48:10 +00:00
|
|
|
nsresult result = mSelection->LineMove(aForward, aExtend);
|
2005-11-20 22:05:24 +00:00
|
|
|
// if we can't go down/up any more we must then move caret completely to
|
2001-06-20 04:48:10 +00:00
|
|
|
// end/beginning respectively.
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
result = CompleteMove(aForward,aExtend);
|
|
|
|
return result;
|
1999-10-22 00:19:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
PresShell::IntraLineMove(PRBool aForward, PRBool aExtend)
|
|
|
|
{
|
1999-12-11 00:02:08 +00:00
|
|
|
return mSelection->IntraLineMove(aForward, aExtend);
|
1999-10-22 00:19:18 +00:00
|
|
|
}
|
|
|
|
|
2002-08-26 20:55:30 +00:00
|
|
|
|
|
|
|
|
1999-10-22 00:19:18 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
PresShell::PageMove(PRBool aForward, PRBool aExtend)
|
|
|
|
{
|
2010-03-11 05:25:29 +00:00
|
|
|
nsIScrollableFrame *scrollableFrame =
|
|
|
|
GetFrameToScrollAsScrollable(nsIPresShell::eVertical);
|
2009-09-01 11:29:27 +00:00
|
|
|
if (!scrollableFrame)
|
|
|
|
return NS_OK;
|
2009-08-03 02:18:57 +00:00
|
|
|
|
2009-09-03 05:23:47 +00:00
|
|
|
mSelection->CommonPageMove(aForward, aExtend, scrollableFrame);
|
2008-02-28 15:28:37 +00:00
|
|
|
// After ScrollSelectionIntoView(), the pending notifications might be
|
|
|
|
// flushed and PresShell/PresContext/Frames may be dead. See bug 418470.
|
2002-08-26 20:55:30 +00:00
|
|
|
return ScrollSelectionIntoView(nsISelectionController::SELECTION_NORMAL, nsISelectionController::SELECTION_FOCUS_REGION, PR_TRUE);
|
1999-10-22 00:19:18 +00:00
|
|
|
}
|
|
|
|
|
2002-08-26 20:55:30 +00:00
|
|
|
|
|
|
|
|
1999-10-22 00:19:18 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
PresShell::ScrollPage(PRBool aForward)
|
1999-12-11 00:02:08 +00:00
|
|
|
{
|
2010-03-11 05:25:29 +00:00
|
|
|
nsIScrollableFrame* scrollFrame =
|
|
|
|
GetFrameToScrollAsScrollable(nsIPresShell::eVertical);
|
2009-09-01 11:29:27 +00:00
|
|
|
if (scrollFrame) {
|
|
|
|
scrollFrame->ScrollBy(nsIntPoint(0, aForward ? 1 : -1),
|
|
|
|
nsIScrollableFrame::PAGES,
|
|
|
|
nsIScrollableFrame::SMOOTH);
|
1999-12-11 00:02:08 +00:00
|
|
|
}
|
2004-08-06 15:55:17 +00:00
|
|
|
return NS_OK;
|
1999-12-11 00:02:08 +00:00
|
|
|
}
|
|
|
|
|
1999-12-15 03:54:52 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
PresShell::ScrollLine(PRBool aForward)
|
|
|
|
{
|
2010-03-11 05:25:29 +00:00
|
|
|
nsIScrollableFrame* scrollFrame =
|
|
|
|
GetFrameToScrollAsScrollable(nsIPresShell::eVertical);
|
2009-09-01 11:29:27 +00:00
|
|
|
if (scrollFrame) {
|
|
|
|
PRInt32 lineCount = 1;
|
2002-04-12 02:05:12 +00:00
|
|
|
#ifdef MOZ_WIDGET_COCOA
|
2004-08-06 15:55:17 +00:00
|
|
|
// Emulate the Mac IE behavior of scrolling a minimum of 2 lines
|
|
|
|
// rather than 1. This vastly improves scrolling speed.
|
2009-09-01 11:29:27 +00:00
|
|
|
lineCount = 2;
|
2002-04-12 02:05:12 +00:00
|
|
|
#endif
|
2009-09-01 11:29:27 +00:00
|
|
|
scrollFrame->ScrollBy(nsIntPoint(0, aForward ? lineCount : -lineCount),
|
|
|
|
nsIScrollableFrame::LINES,
|
|
|
|
nsIScrollableFrame::SMOOTH);
|
2002-04-12 02:05:12 +00:00
|
|
|
|
1999-12-15 03:54:52 +00:00
|
|
|
//NEW FOR LINES
|
2004-08-06 15:55:17 +00:00
|
|
|
// force the update to happen now, otherwise multiple scrolls can
|
|
|
|
// occur before the update is processed. (bug #7354)
|
1999-12-15 03:54:52 +00:00
|
|
|
|
2004-08-06 15:55:17 +00:00
|
|
|
// I'd use Composite here, but it doesn't always work.
|
|
|
|
// vm->Composite();
|
|
|
|
nsIViewManager* viewManager = GetViewManager();
|
|
|
|
if (viewManager) {
|
2000-01-26 23:04:40 +00:00
|
|
|
viewManager->ForceUpdate();
|
1999-12-15 03:54:52 +00:00
|
|
|
}
|
|
|
|
}
|
2004-08-06 15:55:17 +00:00
|
|
|
return NS_OK;
|
1999-12-15 03:54:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
PresShell::ScrollHorizontal(PRBool aLeft)
|
|
|
|
{
|
2010-03-11 05:25:29 +00:00
|
|
|
nsIScrollableFrame* scrollFrame =
|
|
|
|
GetFrameToScrollAsScrollable(nsIPresShell::eHorizontal);
|
2009-09-01 11:29:27 +00:00
|
|
|
if (scrollFrame) {
|
|
|
|
scrollFrame->ScrollBy(nsIntPoint(aLeft ? -1 : 1, 0),
|
|
|
|
nsIScrollableFrame::LINES,
|
|
|
|
nsIScrollableFrame::SMOOTH);
|
2000-05-16 11:35:12 +00:00
|
|
|
//NEW FOR LINES
|
2004-08-06 15:55:17 +00:00
|
|
|
// force the update to happen now, otherwise multiple scrolls can
|
|
|
|
// occur before the update is processed. (bug #7354)
|
2000-05-16 11:35:12 +00:00
|
|
|
|
2004-08-06 15:55:17 +00:00
|
|
|
// I'd use Composite here, but it doesn't always work.
|
|
|
|
// vm->Composite();
|
|
|
|
nsIViewManager* viewManager = GetViewManager();
|
|
|
|
if (viewManager) {
|
2000-05-16 11:35:12 +00:00
|
|
|
viewManager->ForceUpdate();
|
|
|
|
}
|
|
|
|
}
|
2004-08-06 15:55:17 +00:00
|
|
|
return NS_OK;
|
1999-12-15 03:54:52 +00:00
|
|
|
}
|
|
|
|
|
1999-12-11 00:02:08 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
PresShell::CompleteScroll(PRBool aForward)
|
|
|
|
{
|
2010-03-11 05:25:29 +00:00
|
|
|
nsIScrollableFrame* scrollFrame =
|
|
|
|
GetFrameToScrollAsScrollable(nsIPresShell::eVertical);
|
2009-09-01 11:29:27 +00:00
|
|
|
if (scrollFrame) {
|
|
|
|
scrollFrame->ScrollBy(nsIntPoint(0, aForward ? 1 : -1),
|
|
|
|
nsIScrollableFrame::WHOLE,
|
|
|
|
nsIScrollableFrame::INSTANT);
|
1999-12-16 22:48:02 +00:00
|
|
|
}
|
2004-08-06 15:55:17 +00:00
|
|
|
return NS_OK;
|
1999-12-11 00:02:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
PresShell::CompleteMove(PRBool aForward, PRBool aExtend)
|
2007-04-14 16:51:20 +00:00
|
|
|
{
|
2008-02-28 15:28:37 +00:00
|
|
|
// Beware! This may flush notifications via synchronous
|
|
|
|
// ScrollSelectionIntoView.
|
2010-02-09 16:09:59 +00:00
|
|
|
nsIContent* limiter = mSelection->GetAncestorLimiter();
|
|
|
|
nsIFrame* frame = limiter ? limiter->GetPrimaryFrame()
|
|
|
|
: FrameConstructor()->GetRootElementFrame();
|
2002-08-26 20:55:30 +00:00
|
|
|
if (!frame)
|
2000-09-14 11:45:01 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
2004-11-29 20:28:46 +00:00
|
|
|
nsPeekOffsetStruct pos = frame->GetExtremeCaretPosition(!aForward);
|
2010-02-09 16:09:59 +00:00
|
|
|
mSelection->HandleClick(pos.mResultContent, pos.mContentOffset,
|
|
|
|
pos.mContentOffset, aExtend, PR_FALSE, aForward);
|
|
|
|
if (limiter) {
|
|
|
|
// HandleClick resets ancestorLimiter, so set it again.
|
|
|
|
mSelection->SetAncestorLimiter(limiter);
|
|
|
|
}
|
|
|
|
|
2008-04-22 20:48:37 +00:00
|
|
|
// After ScrollSelectionIntoView(), the pending notifications might be
|
|
|
|
// flushed and PresShell/PresContext/Frames may be dead. See bug 418470.
|
|
|
|
return ScrollSelectionIntoView(nsISelectionController::SELECTION_NORMAL,
|
|
|
|
nsISelectionController::SELECTION_FOCUS_REGION,
|
|
|
|
PR_TRUE);
|
1999-10-22 00:19:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
PresShell::SelectAll()
|
|
|
|
{
|
1999-12-11 00:02:08 +00:00
|
|
|
return mSelection->SelectAll();
|
1999-02-19 23:47:36 +00:00
|
|
|
}
|
|
|
|
|
2000-07-26 11:31:12 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
PresShell::CheckVisibility(nsIDOMNode *node, PRInt16 startOffset, PRInt16 EndOffset, PRBool *_retval)
|
|
|
|
{
|
|
|
|
if (!node || startOffset>EndOffset || !_retval || startOffset<0 || EndOffset<0)
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
*_retval = PR_FALSE; //initialize return parameter
|
|
|
|
nsCOMPtr<nsIContent> content(do_QueryInterface(node));
|
|
|
|
if (!content)
|
|
|
|
return NS_ERROR_FAILURE;
|
2009-12-24 21:20:06 +00:00
|
|
|
nsIFrame *frame = content->GetPrimaryFrame();
|
2000-08-17 23:55:32 +00:00
|
|
|
if (!frame) //no frame to look at so it must not be visible
|
|
|
|
return NS_OK;
|
2000-07-26 11:31:12 +00:00
|
|
|
//start process now to go through all frames to find startOffset. then check chars after that to see
|
|
|
|
//if anything until EndOffset is visible.
|
|
|
|
PRBool finished = PR_FALSE;
|
|
|
|
frame->CheckVisibility(mPresContext,startOffset,EndOffset,PR_TRUE,&finished, _retval);
|
|
|
|
return NS_OK;//dont worry about other return val
|
|
|
|
}
|
|
|
|
|
1999-12-02 21:45:21 +00:00
|
|
|
//end implementations nsISelectionController
|
1999-10-22 00:19:18 +00:00
|
|
|
|
|
|
|
|
2010-03-20 21:54:19 +00:00
|
|
|
void
|
1998-11-06 16:16:01 +00:00
|
|
|
PresShell::StyleChangeReflow()
|
|
|
|
{
|
2007-04-25 10:44:29 +00:00
|
|
|
nsIFrame* rootFrame = FrameManager()->GetRootFrame();
|
2007-04-25 15:49:55 +00:00
|
|
|
// At the moment at least, we don't have a root frame before the initial
|
|
|
|
// reflow; it's safe to just ignore the request in that case
|
|
|
|
if (!rootFrame)
|
2010-03-20 21:54:19 +00:00
|
|
|
return;
|
2007-04-25 10:44:29 +00:00
|
|
|
|
2010-03-20 21:54:19 +00:00
|
|
|
FrameNeedsReflow(rootFrame, eStyleChange, NS_FRAME_IS_DIRTY);
|
1998-11-06 16:16:01 +00:00
|
|
|
}
|
|
|
|
|
2004-09-02 03:08:51 +00:00
|
|
|
nsIFrame*
|
2010-03-31 12:48:04 +00:00
|
|
|
nsIPresShell::GetRootFrameExternal() const
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
2004-09-02 03:08:51 +00:00
|
|
|
return FrameManager()->GetRootFrame();
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
2006-02-01 19:55:35 +00:00
|
|
|
nsIFrame*
|
|
|
|
nsIPresShell::GetRootScrollFrame() const
|
|
|
|
{
|
|
|
|
nsIFrame* rootFrame = FrameManager()->GetRootFrame();
|
|
|
|
// Ensure root frame is a viewport frame
|
2006-12-26 17:47:52 +00:00
|
|
|
if (!rootFrame || nsGkAtoms::viewportFrame != rootFrame->GetType())
|
2006-02-01 19:55:35 +00:00
|
|
|
return nsnull;
|
|
|
|
nsIFrame* theFrame = rootFrame->GetFirstChild(nsnull);
|
2006-12-26 17:47:52 +00:00
|
|
|
if (!theFrame || nsGkAtoms::scrollFrame != theFrame->GetType())
|
2006-02-01 19:55:35 +00:00
|
|
|
return nsnull;
|
|
|
|
return theFrame;
|
|
|
|
}
|
|
|
|
|
2007-02-18 10:43:12 +00:00
|
|
|
nsIScrollableFrame*
|
|
|
|
nsIPresShell::GetRootScrollFrameAsScrollable() const
|
|
|
|
{
|
|
|
|
nsIFrame* frame = GetRootScrollFrame();
|
|
|
|
if (!frame)
|
|
|
|
return nsnull;
|
2009-01-12 19:20:59 +00:00
|
|
|
nsIScrollableFrame* scrollableFrame = do_QueryFrame(frame);
|
2007-05-23 00:11:05 +00:00
|
|
|
NS_ASSERTION(scrollableFrame,
|
|
|
|
"All scroll frames must implement nsIScrollableFrame");
|
2007-02-18 10:43:12 +00:00
|
|
|
return scrollableFrame;
|
|
|
|
}
|
|
|
|
|
2009-11-03 02:55:35 +00:00
|
|
|
nsIScrollableFrame*
|
|
|
|
nsIPresShell::GetRootScrollFrameAsScrollableExternal() const
|
|
|
|
{
|
|
|
|
return GetRootScrollFrameAsScrollable();
|
|
|
|
}
|
|
|
|
|
2010-03-20 21:54:19 +00:00
|
|
|
nsIPageSequenceFrame*
|
|
|
|
PresShell::GetPageSequenceFrame() const
|
1998-12-07 03:43:02 +00:00
|
|
|
{
|
2005-04-05 22:46:56 +00:00
|
|
|
nsIFrame* frame = mFrameConstructor->GetPageSequenceFrame();
|
2010-03-20 21:54:19 +00:00
|
|
|
return do_QueryFrame(frame);
|
1998-12-07 03:43:02 +00:00
|
|
|
}
|
|
|
|
|
2007-09-05 08:00:40 +00:00
|
|
|
nsIFrame*
|
|
|
|
PresShell::GetFrameForPoint(nsIFrame* aFrame, nsPoint aPt)
|
|
|
|
{
|
|
|
|
return nsLayoutUtils::GetFrameForPoint(aFrame, aPt);
|
|
|
|
}
|
|
|
|
|
2004-01-24 00:46:17 +00:00
|
|
|
void
|
2003-10-02 21:29:40 +00:00
|
|
|
PresShell::BeginUpdate(nsIDocument *aDocument, nsUpdateType aUpdateType)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
2004-12-02 01:26:20 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
mUpdateCount++;
|
|
|
|
#endif
|
2004-04-12 21:53:22 +00:00
|
|
|
mFrameConstructor->BeginUpdate();
|
|
|
|
|
2004-12-02 01:26:20 +00:00
|
|
|
if (aUpdateType & UPDATE_STYLE)
|
2004-01-08 19:23:12 +00:00
|
|
|
mStyleSet->BeginUpdate();
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
2004-01-24 00:46:17 +00:00
|
|
|
void
|
2003-10-02 21:29:40 +00:00
|
|
|
PresShell::EndUpdate(nsIDocument *aDocument, nsUpdateType aUpdateType)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
2004-12-02 01:26:20 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
NS_PRECONDITION(0 != mUpdateCount, "too many EndUpdate's");
|
|
|
|
--mUpdateCount;
|
|
|
|
#endif
|
|
|
|
|
2004-04-12 21:53:22 +00:00
|
|
|
if (aUpdateType & UPDATE_STYLE) {
|
2004-01-08 19:23:12 +00:00
|
|
|
mStyleSet->EndUpdate();
|
2004-12-02 01:26:20 +00:00
|
|
|
if (mStylesHaveChanged)
|
2004-04-12 21:53:22 +00:00
|
|
|
ReconstructStyleData();
|
|
|
|
}
|
2004-01-08 19:23:12 +00:00
|
|
|
|
2004-04-12 21:53:22 +00:00
|
|
|
mFrameConstructor->EndUpdate();
|
1998-06-03 15:46:54 +00:00
|
|
|
}
|
|
|
|
|
2004-01-24 00:46:17 +00:00
|
|
|
void
|
2007-04-26 02:33:02 +00:00
|
|
|
PresShell::RestoreRootScrollPosition()
|
1998-06-03 15:46:54 +00:00
|
|
|
{
|
2000-06-15 00:35:46 +00:00
|
|
|
// Restore frame state for the root scroll frame
|
2005-05-12 20:53:33 +00:00
|
|
|
nsCOMPtr<nsILayoutHistoryState> historyState =
|
2007-04-26 02:33:02 +00:00
|
|
|
mDocument->GetLayoutHistoryState();
|
2005-01-27 21:18:30 +00:00
|
|
|
// Make sure we don't reenter reflow via the sync paint that happens while
|
|
|
|
// we're scrolling to our restored position. Entering reflow for the
|
|
|
|
// scrollable frame will cause it to reenter ScrollToRestoredPosition(), and
|
|
|
|
// it'll get all confused.
|
2008-03-14 23:08:57 +00:00
|
|
|
nsAutoScriptBlocker scriptBlocker;
|
2009-06-28 20:04:35 +00:00
|
|
|
++mChangeNestCount;
|
2005-01-27 21:18:30 +00:00
|
|
|
|
2006-02-01 19:55:35 +00:00
|
|
|
if (historyState) {
|
|
|
|
nsIFrame* scrollFrame = GetRootScrollFrame();
|
2000-06-15 00:35:46 +00:00
|
|
|
if (scrollFrame) {
|
2009-01-12 19:20:59 +00:00
|
|
|
nsIScrollableFrame* scrollableFrame = do_QueryFrame(scrollFrame);
|
2004-07-23 21:39:47 +00:00
|
|
|
if (scrollableFrame) {
|
2004-09-13 02:10:29 +00:00
|
|
|
FrameManager()->RestoreFrameStateFor(scrollFrame, historyState,
|
|
|
|
nsIStatefulFrame::eDocumentScrollState);
|
2004-07-23 21:39:47 +00:00
|
|
|
scrollableFrame->ScrollToRestoredPosition();
|
|
|
|
}
|
2000-06-15 00:35:46 +00:00
|
|
|
}
|
|
|
|
}
|
2009-06-28 20:04:35 +00:00
|
|
|
|
|
|
|
--mChangeNestCount;
|
2007-04-26 02:33:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PresShell::BeginLoad(nsIDocument *aDocument)
|
|
|
|
{
|
|
|
|
mDocumentLoading = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PresShell::EndLoad(nsIDocument *aDocument)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aDocument == mDocument, "Wrong document");
|
|
|
|
|
|
|
|
RestoreRootScrollPosition();
|
2005-01-27 21:18:30 +00:00
|
|
|
|
2000-05-16 01:11:29 +00:00
|
|
|
mDocumentLoading = PR_FALSE;
|
1998-06-03 15:46:54 +00:00
|
|
|
}
|
|
|
|
|
2007-04-30 06:17:03 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
void
|
|
|
|
PresShell::VerifyHasDirtyRootAncestor(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
// XXXbz due to bug 372769, can't actually assert anything here...
|
|
|
|
return;
|
|
|
|
|
|
|
|
// XXXbz shouldn't need this part; remove it once FrameNeedsReflow
|
|
|
|
// handles the root frame correctly.
|
|
|
|
if (!aFrame->GetParent()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure that there is a reflow root ancestor of |aFrame| that's
|
|
|
|
// in mDirtyRoots already.
|
|
|
|
while (aFrame && (aFrame->GetStateBits() & NS_FRAME_HAS_DIRTY_CHILDREN)) {
|
|
|
|
if (((aFrame->GetStateBits() & NS_FRAME_REFLOW_ROOT) ||
|
|
|
|
!aFrame->GetParent()) &&
|
2009-02-03 14:42:18 +00:00
|
|
|
mDirtyRoots.Contains(aFrame)) {
|
2007-04-30 06:17:03 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
aFrame = aFrame->GetParent();
|
|
|
|
}
|
|
|
|
NS_NOTREACHED("Frame has dirty bits set but isn't scheduled to be "
|
|
|
|
"reflowed?");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-03-20 21:54:19 +00:00
|
|
|
void
|
2007-05-06 19:16:51 +00:00
|
|
|
PresShell::FrameNeedsReflow(nsIFrame *aFrame, IntrinsicDirty aIntrinsicDirty,
|
2007-05-06 22:50:21 +00:00
|
|
|
nsFrameState aBitToAdd)
|
2004-05-02 18:07:12 +00:00
|
|
|
{
|
2010-05-19 23:22:19 +00:00
|
|
|
#ifdef NS_FUNCTION_TIMER
|
|
|
|
NS_TIME_FUNCTION_DECLARE_DOCURL;
|
|
|
|
nsCAutoString frameType__("N/A");
|
|
|
|
nsIAtom *atomType__ = aFrame ? aFrame->GetType() : nsnull;
|
|
|
|
if (atomType__) atomType__->ToUTF8String(frameType__);
|
|
|
|
NS_TIME_FUNCTION_MIN_FMT(1.0, "%s (line %d) (document: %s, frame type: %s)", MOZ_FUNCTION_NAME,
|
|
|
|
__LINE__, docURL__.get(), frameType__.get());
|
|
|
|
#endif
|
|
|
|
|
2007-05-06 22:50:21 +00:00
|
|
|
NS_PRECONDITION(aBitToAdd == NS_FRAME_IS_DIRTY ||
|
|
|
|
aBitToAdd == NS_FRAME_HAS_DIRTY_CHILDREN,
|
2007-05-06 19:16:51 +00:00
|
|
|
"Unexpected bits being added");
|
2009-02-04 21:24:18 +00:00
|
|
|
NS_PRECONDITION(aIntrinsicDirty != eStyleChange ||
|
|
|
|
aBitToAdd == NS_FRAME_IS_DIRTY,
|
|
|
|
"bits don't correspond to style change reason");
|
2004-05-02 18:07:12 +00:00
|
|
|
|
2007-05-16 03:22:45 +00:00
|
|
|
NS_ASSERTION(!mIsReflowing, "can't mark frame dirty during reflow");
|
2004-05-02 18:07:12 +00:00
|
|
|
|
2001-08-07 18:57:15 +00:00
|
|
|
// If we've not yet done the initial reflow, then don't bother
|
|
|
|
// enqueuing a reflow command yet.
|
|
|
|
if (! mDidInitialReflow)
|
2010-03-20 21:54:19 +00:00
|
|
|
return;
|
2001-08-07 18:57:15 +00:00
|
|
|
|
2005-07-07 17:10:40 +00:00
|
|
|
// If we're already destroying, don't bother with this either.
|
|
|
|
if (mIsDestroying)
|
2010-03-20 21:54:19 +00:00
|
|
|
return;
|
2005-07-07 17:10:40 +00:00
|
|
|
|
1999-09-15 00:27:05 +00:00
|
|
|
#ifdef DEBUG
|
2000-10-28 22:17:53 +00:00
|
|
|
//printf("gShellCounter: %d\n", gShellCounter++);
|
2010-03-20 21:54:19 +00:00
|
|
|
if (mInVerifyReflow)
|
|
|
|
return;
|
2007-05-23 00:11:05 +00:00
|
|
|
|
1999-12-23 02:02:33 +00:00
|
|
|
if (VERIFY_REFLOW_NOISY_RC & gVerifyReflowFlags) {
|
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 05:38:33 +00:00
|
|
|
printf("\nPresShell@%p: frame %p needs reflow\n", (void*)this, (void*)aFrame);
|
1999-12-23 02:02:33 +00:00
|
|
|
if (VERIFY_REFLOW_REALLY_NOISY_RC & gVerifyReflowFlags) {
|
2000-10-28 22:17:53 +00:00
|
|
|
printf("Current content model:\n");
|
2010-04-30 13:12:05 +00:00
|
|
|
Element *rootElement = mDocument->GetRootElement();
|
|
|
|
if (rootElement) {
|
|
|
|
rootElement->List(stdout, 0);
|
1999-09-15 00:27:05 +00:00
|
|
|
}
|
|
|
|
}
|
1999-12-23 02:02:33 +00:00
|
|
|
}
|
1998-11-26 18:11:02 +00:00
|
|
|
#endif
|
2000-09-12 00:35:11 +00:00
|
|
|
|
2009-02-04 21:24:18 +00:00
|
|
|
nsAutoTArray<nsIFrame*, 4> subtrees;
|
|
|
|
subtrees.AppendElement(aFrame);
|
2007-06-16 05:12:58 +00:00
|
|
|
|
2009-02-04 21:24:18 +00:00
|
|
|
do {
|
|
|
|
nsIFrame *subtreeRoot = subtrees.ElementAt(subtrees.Length() - 1);
|
|
|
|
subtrees.RemoveElementAt(subtrees.Length() - 1);
|
|
|
|
|
|
|
|
// Grab |wasDirty| now so we can go ahead and update the bits on
|
|
|
|
// subtreeRoot.
|
|
|
|
PRBool wasDirty = NS_SUBTREE_DIRTY(subtreeRoot);
|
|
|
|
subtreeRoot->AddStateBits(aBitToAdd);
|
|
|
|
|
|
|
|
// Now if subtreeRoot is a reflow root we can cut off this reflow at it if
|
|
|
|
// the bit being added is NS_FRAME_HAS_DIRTY_CHILDREN.
|
|
|
|
PRBool targetFrameDirty = (aBitToAdd == NS_FRAME_IS_DIRTY);
|
2007-06-16 05:12:58 +00:00
|
|
|
|
2007-05-06 19:16:51 +00:00
|
|
|
#define FRAME_IS_REFLOW_ROOT(_f) \
|
|
|
|
((_f->GetStateBits() & NS_FRAME_REFLOW_ROOT) && \
|
2009-02-04 21:24:18 +00:00
|
|
|
(_f != subtreeRoot || !targetFrameDirty))
|
2007-05-06 19:16:51 +00:00
|
|
|
|
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 05:38:33 +00:00
|
|
|
|
2009-02-04 21:24:18 +00:00
|
|
|
// Mark the intrinsic widths as dirty on the frame, all of its ancestors,
|
|
|
|
// and all of its descendants, if needed:
|
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 05:38:33 +00:00
|
|
|
|
2009-02-04 21:24:18 +00:00
|
|
|
if (aIntrinsicDirty != eResize) {
|
|
|
|
// Mark argument and all ancestors dirty. (Unless we hit a reflow
|
|
|
|
// root that should contain the reflow. That root could be
|
|
|
|
// subtreeRoot itself if it's not dirty, or it could be some
|
|
|
|
// ancestor of subtreeRoot.)
|
|
|
|
for (nsIFrame *a = subtreeRoot;
|
|
|
|
a && !FRAME_IS_REFLOW_ROOT(a);
|
|
|
|
a = a->GetParent())
|
|
|
|
a->MarkIntrinsicWidthsDirty();
|
|
|
|
}
|
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 05:38:33 +00:00
|
|
|
|
2009-02-04 21:24:18 +00:00
|
|
|
if (aIntrinsicDirty == eStyleChange) {
|
|
|
|
// Mark all descendants dirty (using an nsTArray stack rather than
|
|
|
|
// recursion).
|
|
|
|
nsAutoTArray<nsIFrame*, 32> stack;
|
|
|
|
stack.AppendElement(subtreeRoot);
|
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 05:38:33 +00:00
|
|
|
|
|
|
|
do {
|
2009-02-04 21:24:18 +00:00
|
|
|
nsIFrame *f = stack.ElementAt(stack.Length() - 1);
|
|
|
|
stack.RemoveElementAt(stack.Length() - 1);
|
|
|
|
|
|
|
|
if (f->GetType() == nsGkAtoms::placeholderFrame) {
|
|
|
|
nsIFrame *oof = nsPlaceholderFrame::GetRealFrameForPlaceholder(f);
|
|
|
|
if (!nsLayoutUtils::IsProperAncestorFrame(subtreeRoot, oof)) {
|
|
|
|
// We have another distinct subtree we need to mark.
|
|
|
|
subtrees.AppendElement(oof);
|
|
|
|
}
|
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 05:38:33 +00:00
|
|
|
}
|
2009-02-04 21:24:18 +00:00
|
|
|
|
|
|
|
PRInt32 childListIndex = 0;
|
|
|
|
nsIAtom *childListName;
|
|
|
|
do {
|
|
|
|
childListName = f->GetAdditionalChildListName(childListIndex++);
|
|
|
|
for (nsIFrame *kid = f->GetFirstChild(childListName); kid;
|
|
|
|
kid = kid->GetNextSibling()) {
|
|
|
|
kid->MarkIntrinsicWidthsDirty();
|
|
|
|
stack.AppendElement(kid);
|
|
|
|
}
|
|
|
|
} while (childListName);
|
|
|
|
} while (stack.Length() != 0);
|
2004-05-02 18:07:12 +00:00
|
|
|
}
|
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 05:38:33 +00:00
|
|
|
|
2009-02-04 21:24:18 +00:00
|
|
|
// Set NS_FRAME_HAS_DIRTY_CHILDREN bits (via nsIFrame::ChildIsDirty)
|
|
|
|
// up the tree until we reach either a frame that's already dirty or
|
|
|
|
// a reflow root.
|
|
|
|
nsIFrame *f = subtreeRoot;
|
|
|
|
for (;;) {
|
|
|
|
if (FRAME_IS_REFLOW_ROOT(f) || !f->GetParent()) {
|
|
|
|
// we've hit a reflow root or the root frame
|
|
|
|
if (!wasDirty) {
|
|
|
|
mDirtyRoots.AppendElement(f);
|
|
|
|
}
|
2007-04-30 06:17:03 +00:00
|
|
|
#ifdef DEBUG
|
2009-02-04 21:24:18 +00:00
|
|
|
else {
|
|
|
|
VerifyHasDirtyRootAncestor(f);
|
|
|
|
}
|
2007-04-30 06:17:03 +00:00
|
|
|
#endif
|
2009-02-04 21:24:18 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
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 05:38:33 +00:00
|
|
|
|
2009-02-04 21:24:18 +00:00
|
|
|
nsIFrame *child = f;
|
|
|
|
f = f->GetParent();
|
|
|
|
wasDirty = NS_SUBTREE_DIRTY(f);
|
|
|
|
f->ChildIsDirty(child);
|
|
|
|
NS_ASSERTION(f->GetStateBits() & NS_FRAME_HAS_DIRTY_CHILDREN,
|
|
|
|
"ChildIsDirty didn't do its job");
|
|
|
|
if (wasDirty) {
|
|
|
|
// This frame was already marked dirty.
|
2007-04-30 06:17:03 +00:00
|
|
|
#ifdef DEBUG
|
2009-02-04 21:24:18 +00:00
|
|
|
VerifyHasDirtyRootAncestor(f);
|
2007-04-30 06:17:03 +00:00
|
|
|
#endif
|
2009-02-04 21:24:18 +00:00
|
|
|
break;
|
|
|
|
}
|
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 05:38:33 +00:00
|
|
|
}
|
2009-02-04 21:24:18 +00:00
|
|
|
} while (subtrees.Length() != 0);
|
1999-11-09 03:23:26 +00:00
|
|
|
|
2010-02-19 17:11:40 +00:00
|
|
|
MaybeScheduleReflow();
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
2010-03-20 21:54:19 +00:00
|
|
|
void
|
2009-04-21 23:53:52 +00:00
|
|
|
PresShell::FrameNeedsToContinueReflow(nsIFrame *aFrame)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mIsReflowing, "Must be in reflow when marking path dirty.");
|
|
|
|
NS_PRECONDITION(mCurrentReflowRoot, "Must have a current reflow root here");
|
|
|
|
NS_ASSERTION(aFrame == mCurrentReflowRoot ||
|
|
|
|
nsLayoutUtils::IsProperAncestorFrame(mCurrentReflowRoot, aFrame),
|
|
|
|
"Frame passed in is not the descendant of mCurrentReflowRoot");
|
|
|
|
NS_ASSERTION(aFrame->GetStateBits() & NS_FRAME_IN_REFLOW,
|
|
|
|
"Frame passed in not in reflow?");
|
|
|
|
|
|
|
|
mFramesToDirty.PutEntry(aFrame);
|
|
|
|
}
|
|
|
|
|
2009-09-01 11:29:27 +00:00
|
|
|
nsIScrollableFrame*
|
2010-03-11 05:25:29 +00:00
|
|
|
nsIPresShell::GetFrameToScrollAsScrollable(
|
|
|
|
nsIPresShell::ScrollDirection aDirection)
|
2004-08-06 15:55:17 +00:00
|
|
|
{
|
2009-09-01 11:29:27 +00:00
|
|
|
nsIScrollableFrame* scrollFrame = 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 18:00:39 +00:00
|
|
|
|
2004-09-01 14:58:34 +00:00
|
|
|
nsCOMPtr<nsIContent> focusedContent;
|
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 18:00:39 +00:00
|
|
|
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
|
|
|
|
if (fm && mDocument) {
|
|
|
|
nsCOMPtr<nsIDOMWindow> window = do_QueryInterface(mDocument->GetWindow());
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMElement> focusedElement;
|
|
|
|
fm->GetFocusedElementForWindow(window, PR_FALSE, nsnull, getter_AddRefs(focusedElement));
|
|
|
|
focusedContent = do_QueryInterface(focusedElement);
|
|
|
|
}
|
2004-10-19 02:24:27 +00:00
|
|
|
if (!focusedContent && mSelection) {
|
2006-04-26 02:01:07 +00:00
|
|
|
nsISelection* domSelection = mSelection->
|
|
|
|
GetSelection(nsISelectionController::SELECTION_NORMAL);
|
2004-10-19 02:24:27 +00:00
|
|
|
if (domSelection) {
|
|
|
|
nsCOMPtr<nsIDOMNode> focusedNode;
|
|
|
|
domSelection->GetFocusNode(getter_AddRefs(focusedNode));
|
|
|
|
focusedContent = do_QueryInterface(focusedNode);
|
|
|
|
}
|
|
|
|
}
|
2004-09-01 14:58:34 +00:00
|
|
|
if (focusedContent) {
|
2009-12-24 21:20:06 +00:00
|
|
|
nsIFrame* startFrame = focusedContent->GetPrimaryFrame();
|
2004-09-01 14:58:34 +00:00
|
|
|
if (startFrame) {
|
2009-09-01 11:29:27 +00:00
|
|
|
scrollFrame = startFrame->GetScrollTargetFrame();
|
|
|
|
if (scrollFrame) {
|
|
|
|
startFrame = scrollFrame->GetScrolledFrame();
|
|
|
|
}
|
2010-03-11 05:25:29 +00:00
|
|
|
if (aDirection == nsIPresShell::eEither) {
|
|
|
|
scrollFrame =
|
|
|
|
nsLayoutUtils::GetNearestScrollableFrame(startFrame);
|
|
|
|
} else {
|
|
|
|
scrollFrame =
|
|
|
|
nsLayoutUtils::GetNearestScrollableFrameForDirection(startFrame,
|
|
|
|
aDirection == eVertical ? nsLayoutUtils::eVertical :
|
|
|
|
nsLayoutUtils::eHorizontal);
|
|
|
|
}
|
2004-08-06 15:55:17 +00:00
|
|
|
}
|
|
|
|
}
|
2009-09-01 11:29:27 +00:00
|
|
|
if (!scrollFrame) {
|
|
|
|
scrollFrame = GetRootScrollFrameAsScrollable();
|
|
|
|
}
|
|
|
|
return scrollFrame;
|
2004-08-06 15:55:17 +00:00
|
|
|
}
|
2000-06-14 23:18:54 +00:00
|
|
|
|
2010-03-20 21:54:19 +00:00
|
|
|
void
|
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 05:38:33 +00:00
|
|
|
PresShell::CancelAllPendingReflows()
|
2001-03-13 06:38:59 +00:00
|
|
|
{
|
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 05:38:33 +00:00
|
|
|
mDirtyRoots.Clear();
|
2001-03-14 07:47:00 +00:00
|
|
|
|
2010-02-19 17:11:40 +00:00
|
|
|
if (mReflowScheduled) {
|
|
|
|
GetPresContext()->RefreshDriver()->RemoveRefreshObserver(this, Flush_Layout);
|
|
|
|
mReflowScheduled = PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
ASSERT_REFLOW_SCHEDULED_STATE();
|
2000-09-20 07:20:23 +00:00
|
|
|
}
|
|
|
|
|
2005-06-10 13:57:27 +00:00
|
|
|
#ifdef ACCESSIBILITY
|
|
|
|
void nsIPresShell::InvalidateAccessibleSubtree(nsIContent *aContent)
|
|
|
|
{
|
2007-05-04 02:19:18 +00:00
|
|
|
if (gIsAccessibilityActive) {
|
2005-06-10 13:57:27 +00:00
|
|
|
nsCOMPtr<nsIAccessibilityService> accService =
|
|
|
|
do_GetService("@mozilla.org/accessibilityService;1");
|
|
|
|
if (accService) {
|
|
|
|
accService->InvalidateSubtreeFor(this, aContent,
|
2009-09-09 09:03:14 +00:00
|
|
|
nsIAccessibilityService::FRAME_SIGNIFICANT_CHANGE);
|
2005-06-10 13:57:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-03-31 12:41:54 +00:00
|
|
|
nsresult
|
2002-10-22 06:07:52 +00:00
|
|
|
PresShell::RecreateFramesFor(nsIContent* aContent)
|
|
|
|
{
|
2010-05-19 23:22:19 +00:00
|
|
|
NS_TIME_FUNCTION_MIN(1.0);
|
|
|
|
|
2002-10-22 06:07:52 +00:00
|
|
|
NS_ENSURE_TRUE(mPresContext, NS_ERROR_FAILURE);
|
2007-05-08 04:46:55 +00:00
|
|
|
if (!mDidInitialReflow) {
|
|
|
|
// Nothing to do here. In fact, if we proceed and aContent is the
|
|
|
|
// root we will crash.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2002-10-22 06:07:52 +00:00
|
|
|
|
|
|
|
// Don't call RecreateFramesForContent since that is not exported and we want
|
|
|
|
// to keep the number of entrypoints down.
|
|
|
|
|
2005-10-25 22:32:13 +00:00
|
|
|
NS_ASSERTION(mViewManager, "Should have view manager");
|
2008-01-26 23:59:50 +00:00
|
|
|
nsIViewManager::UpdateViewBatch batch(mViewManager);
|
2005-10-25 22:32:13 +00:00
|
|
|
|
|
|
|
// Have to make sure that the content notifications are flushed before we
|
|
|
|
// start messing with the frame model; otherwise we can get content doubling.
|
|
|
|
mDocument->FlushPendingNotifications(Flush_ContentAndNotify);
|
|
|
|
|
2008-03-14 23:08:57 +00:00
|
|
|
nsAutoScriptBlocker scriptBlocker;
|
|
|
|
|
2002-10-22 06:07:52 +00:00
|
|
|
nsStyleChangeList changeList;
|
|
|
|
changeList.AppendChange(nsnull, aContent, nsChangeHint_ReconstructFrame);
|
2004-10-09 01:39:21 +00:00
|
|
|
|
2009-06-28 20:04:35 +00:00
|
|
|
// Mark ourselves as not safe to flush while we're doing frame construction.
|
|
|
|
++mChangeNestCount;
|
2005-02-18 16:11:53 +00:00
|
|
|
nsresult rv = mFrameConstructor->ProcessRestyledFrames(changeList);
|
2009-06-28 20:04:35 +00:00
|
|
|
--mChangeNestCount;
|
2007-10-19 03:51:15 +00:00
|
|
|
|
2008-01-26 23:59:50 +00:00
|
|
|
batch.EndUpdateViewBatch(NS_VMREFRESH_NO_SYNC);
|
2005-06-10 13:57:27 +00:00
|
|
|
#ifdef ACCESSIBILITY
|
|
|
|
InvalidateAccessibleSubtree(aContent);
|
|
|
|
#endif
|
2004-10-09 01:39:21 +00:00
|
|
|
return rv;
|
2002-10-22 06:07:52 +00:00
|
|
|
}
|
|
|
|
|
2008-06-25 22:41:04 +00:00
|
|
|
void
|
2010-05-14 17:04:51 +00:00
|
|
|
nsIPresShell::PostRecreateFramesFor(Element* aElement)
|
2008-06-25 22:41:04 +00:00
|
|
|
{
|
2010-05-14 17:04:51 +00:00
|
|
|
FrameConstructor()->PostRestyleEvent(aElement, eRestyle_Self,
|
2009-09-11 10:46:36 +00:00
|
|
|
nsChangeHint_ReconstructFrame);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-05-14 17:04:51 +00:00
|
|
|
nsIPresShell::RestyleForAnimation(Element* aElement)
|
2009-09-11 10:46:36 +00:00
|
|
|
{
|
2010-05-14 17:04:51 +00:00
|
|
|
FrameConstructor()->PostAnimationRestyleEvent(aElement, eRestyle_Self,
|
2009-09-11 10:46:36 +00:00
|
|
|
NS_STYLE_HINT_NONE);
|
2008-06-25 22:41:04 +00:00
|
|
|
}
|
|
|
|
|
2010-03-31 12:41:54 +00:00
|
|
|
void
|
1998-11-19 00:43:36 +00:00
|
|
|
PresShell::ClearFrameRefs(nsIFrame* aFrame)
|
|
|
|
{
|
2004-02-27 17:17:37 +00:00
|
|
|
mPresContext->EventStateManager()->ClearFrameRefs(aFrame);
|
2009-04-21 23:53:52 +00:00
|
|
|
|
2006-07-12 07:41:11 +00:00
|
|
|
nsWeakFrame* weakFrame = mWeakFrames;
|
|
|
|
while (weakFrame) {
|
|
|
|
nsWeakFrame* prev = weakFrame->GetPreviousWeakFrame();
|
|
|
|
if (weakFrame->GetFrame() == aFrame) {
|
|
|
|
// This removes weakFrame from mWeakFrames.
|
|
|
|
weakFrame->Clear(this);
|
|
|
|
}
|
|
|
|
weakFrame = prev;
|
|
|
|
}
|
1998-11-19 00:43:36 +00:00
|
|
|
}
|
|
|
|
|
2010-03-31 12:41:54 +00:00
|
|
|
nsresult
|
1999-02-12 17:45:58 +00:00
|
|
|
PresShell::CreateRenderingContext(nsIFrame *aFrame,
|
|
|
|
nsIRenderingContext** aResult)
|
1998-10-02 01:12:39 +00:00
|
|
|
{
|
2010-05-19 23:22:19 +00:00
|
|
|
NS_TIME_FUNCTION_MIN(1.0);
|
|
|
|
|
1999-02-12 17:45:58 +00:00
|
|
|
NS_PRECONDITION(nsnull != aResult, "null ptr");
|
|
|
|
if (nsnull == aResult) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
|
2006-06-15 03:19:32 +00:00
|
|
|
nsIWidget* widget = nsnull;
|
2007-02-18 04:44:21 +00:00
|
|
|
nsPoint offset(0,0);
|
|
|
|
if (mPresContext->IsScreen()) {
|
|
|
|
// Get the widget to create the rendering context for and calculate
|
2010-06-05 20:29:49 +00:00
|
|
|
// the offset from the frame to it.
|
2007-02-18 04:44:21 +00:00
|
|
|
nsPoint viewOffset;
|
|
|
|
nsIView* view = aFrame->GetClosestView(&viewOffset);
|
|
|
|
nsPoint widgetOffset;
|
|
|
|
widget = view->GetNearestWidget(&widgetOffset);
|
|
|
|
offset = viewOffset + widgetOffset;
|
|
|
|
} else {
|
|
|
|
nsIFrame* pageFrame = nsLayoutUtils::GetPageFrame(aFrame);
|
|
|
|
// This might not always come up with a frame, i.e. during reflow;
|
|
|
|
// that's fine, because the translation doesn't matter during reflow.
|
|
|
|
if (pageFrame)
|
|
|
|
offset = aFrame->GetOffsetTo(pageFrame);
|
|
|
|
}
|
1998-10-02 01:12:39 +00:00
|
|
|
|
2006-06-15 03:19:32 +00:00
|
|
|
nsresult rv;
|
1999-02-12 17:45:58 +00:00
|
|
|
nsIRenderingContext* result = nsnull;
|
2004-02-02 22:17:21 +00:00
|
|
|
nsIDeviceContext *deviceContext = mPresContext->DeviceContext();
|
|
|
|
if (widget) {
|
2004-05-18 01:13:45 +00:00
|
|
|
rv = deviceContext->CreateRenderingContext(widget, result);
|
2004-02-02 22:17:21 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
rv = deviceContext->CreateRenderingContext(result);
|
1999-02-12 17:45:58 +00:00
|
|
|
}
|
|
|
|
*aResult = result;
|
1998-10-02 01:12:39 +00:00
|
|
|
|
2007-05-12 13:06:16 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
result->Translate(offset.x, offset.y);
|
|
|
|
}
|
2007-02-18 04:44:21 +00:00
|
|
|
|
1998-10-02 01:12:39 +00:00
|
|
|
return rv;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
2010-03-31 12:41:54 +00:00
|
|
|
nsresult
|
2003-01-13 23:10:53 +00:00
|
|
|
PresShell::GoToAnchor(const nsAString& aAnchorName, PRBool aScroll)
|
1999-02-12 05:39:33 +00:00
|
|
|
{
|
2004-05-27 22:08:42 +00:00
|
|
|
if (!mDocument) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2010-05-12 02:24:02 +00:00
|
|
|
|
2004-02-27 17:17:37 +00:00
|
|
|
// Hold a reference to the ESM in case event dispatch tears us down.
|
|
|
|
nsCOMPtr<nsIEventStateManager> esm = mPresContext->EventStateManager();
|
|
|
|
|
2003-01-13 23:10:53 +00:00
|
|
|
if (aAnchorName.IsEmpty()) {
|
|
|
|
NS_ASSERTION(!aScroll, "can't scroll to empty anchor name");
|
2004-02-27 17:17:37 +00:00
|
|
|
esm->SetContentState(nsnull, NS_EVENT_STATE_URLTARGET);
|
2003-01-13 23:10:53 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-10-11 13:50:45 +00:00
|
|
|
nsCOMPtr<nsIDOMDocument> doc = do_QueryInterface(mDocument);
|
|
|
|
nsCOMPtr<nsIDOMHTMLDocument> htmlDoc = do_QueryInterface(mDocument);
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
nsCOMPtr<nsIContent> content;
|
1999-02-12 05:39:33 +00:00
|
|
|
|
2000-10-11 13:50:45 +00:00
|
|
|
// Search for an element with a matching "id" attribute
|
|
|
|
if (doc) {
|
1999-02-12 05:39:33 +00:00
|
|
|
nsCOMPtr<nsIDOMElement> element;
|
2000-07-28 21:48:08 +00:00
|
|
|
rv = doc->GetElementById(aAnchorName, getter_AddRefs(element));
|
1999-04-09 04:28:15 +00:00
|
|
|
if (NS_SUCCEEDED(rv) && element) {
|
1999-02-12 05:39:33 +00:00
|
|
|
// Get the nsIContent interface, because that's what we need to
|
|
|
|
// get the primary frame
|
2000-10-11 13:50:45 +00:00
|
|
|
content = do_QueryInterface(element);
|
1999-03-20 01:51:00 +00:00
|
|
|
}
|
|
|
|
}
|
1999-02-12 05:39:33 +00:00
|
|
|
|
2000-10-11 13:50:45 +00:00
|
|
|
// Search for an anchor element with a matching "name" attribute
|
|
|
|
if (!content && htmlDoc) {
|
|
|
|
nsCOMPtr<nsIDOMNodeList> list;
|
|
|
|
// Find a matching list of named nodes
|
|
|
|
rv = htmlDoc->GetElementsByName(aAnchorName, getter_AddRefs(list));
|
|
|
|
if (NS_SUCCEEDED(rv) && list) {
|
|
|
|
PRUint32 i;
|
|
|
|
// Loop through the named nodes looking for the first anchor
|
2003-03-15 16:30:09 +00:00
|
|
|
for (i = 0; PR_TRUE; i++) {
|
2000-10-11 13:50:45 +00:00
|
|
|
nsCOMPtr<nsIDOMNode> node;
|
|
|
|
rv = list->Item(i, getter_AddRefs(node));
|
2003-03-15 16:30:09 +00:00
|
|
|
if (!node) { // End of list
|
2000-10-11 13:50:45 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
// Ensure it's an anchor element
|
2003-03-15 16:30:09 +00:00
|
|
|
content = do_QueryInterface(node);
|
|
|
|
if (content) {
|
2009-08-24 20:02:07 +00:00
|
|
|
if (content->Tag() == nsGkAtoms::a && content->IsHTML()) {
|
2000-10-11 13:50:45 +00:00
|
|
|
break;
|
|
|
|
}
|
2003-03-15 16:30:09 +00:00
|
|
|
content = nsnull;
|
2000-10-11 13:50:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Search for anchor in the HTML namespace with a matching name
|
|
|
|
if (!content && !htmlDoc)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMNodeList> list;
|
|
|
|
NS_NAMED_LITERAL_STRING(nameSpace, "http://www.w3.org/1999/xhtml");
|
|
|
|
// Get the list of anchor elements
|
|
|
|
rv = doc->GetElementsByTagNameNS(nameSpace, NS_LITERAL_STRING("a"), getter_AddRefs(list));
|
|
|
|
if (NS_SUCCEEDED(rv) && list) {
|
|
|
|
PRUint32 i;
|
|
|
|
// Loop through the named nodes looking for the first anchor
|
2003-03-15 16:30:09 +00:00
|
|
|
for (i = 0; PR_TRUE; i++) {
|
2000-10-11 13:50:45 +00:00
|
|
|
nsCOMPtr<nsIDOMNode> node;
|
|
|
|
rv = list->Item(i, getter_AddRefs(node));
|
2003-03-15 16:30:09 +00:00
|
|
|
if (!node) { // End of list
|
2000-10-11 13:50:45 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
// Compare the name attribute
|
|
|
|
nsCOMPtr<nsIDOMElement> element = do_QueryInterface(node);
|
|
|
|
nsAutoString value;
|
|
|
|
if (element && NS_SUCCEEDED(element->GetAttribute(NS_LITERAL_STRING("name"), value))) {
|
2002-02-19 22:49:12 +00:00
|
|
|
if (value.Equals(aAnchorName)) {
|
2000-10-11 13:50:45 +00:00
|
|
|
content = do_QueryInterface(element);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Fixes bug 66597, bug 103284, bug 114440, bug 120023, bug 128741, bug 19259. Cleans up browse with caret, makes it work with XML content docs, creates keyboard toggle for it (Accel+shift+K), synchronizes focus and document selection so that users can tab navigate relative to their last find or click in text, or vice versa, makes tabbing move relative to named anchor that has been jumped to. r=bryner, sr=alecf, a=asa
2002-03-10 06:21:48 +00:00
|
|
|
nsCOMPtr<nsIDOMRange> jumpToRange;
|
2003-03-19 23:45:42 +00:00
|
|
|
nsCOMPtr<nsIXPointerResult> xpointerResult;
|
|
|
|
if (!content) {
|
|
|
|
nsCOMPtr<nsIDOMXMLDocument> xmldoc = do_QueryInterface(mDocument);
|
|
|
|
if (xmldoc) {
|
2005-02-20 09:55:02 +00:00
|
|
|
// Try XPointer
|
2003-03-19 23:45:42 +00:00
|
|
|
xmldoc->EvaluateXPointer(aAnchorName, getter_AddRefs(xpointerResult));
|
|
|
|
if (xpointerResult) {
|
|
|
|
xpointerResult->Item(0, getter_AddRefs(jumpToRange));
|
|
|
|
if (!jumpToRange) {
|
|
|
|
// We know it was an XPointer, so there is no point in
|
|
|
|
// trying any other pointer types, let's just return
|
|
|
|
// an error.
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-02-20 09:55:02 +00:00
|
|
|
// Finally try FIXptr
|
|
|
|
if (!jumpToRange) {
|
|
|
|
xmldoc->EvaluateFIXptr(aAnchorName,getter_AddRefs(jumpToRange));
|
|
|
|
}
|
|
|
|
|
Fixes bug 66597, bug 103284, bug 114440, bug 120023, bug 128741, bug 19259. Cleans up browse with caret, makes it work with XML content docs, creates keyboard toggle for it (Accel+shift+K), synchronizes focus and document selection so that users can tab navigate relative to their last find or click in text, or vice versa, makes tabbing move relative to named anchor that has been jumped to. r=bryner, sr=alecf, a=asa
2002-03-10 06:21:48 +00:00
|
|
|
if (jumpToRange) {
|
2001-12-20 05:15:52 +00:00
|
|
|
nsCOMPtr<nsIDOMNode> node;
|
Fixes bug 66597, bug 103284, bug 114440, bug 120023, bug 128741, bug 19259. Cleans up browse with caret, makes it work with XML content docs, creates keyboard toggle for it (Accel+shift+K), synchronizes focus and document selection so that users can tab navigate relative to their last find or click in text, or vice versa, makes tabbing move relative to named anchor that has been jumped to. r=bryner, sr=alecf, a=asa
2002-03-10 06:21:48 +00:00
|
|
|
jumpToRange->GetStartContainer(getter_AddRefs(node));
|
2001-12-20 05:15:52 +00:00
|
|
|
if (node) {
|
2005-02-20 09:55:02 +00:00
|
|
|
PRUint16 nodeType;
|
|
|
|
node->GetNodeType(&nodeType);
|
|
|
|
PRInt32 offset = -1;
|
|
|
|
jumpToRange->GetStartOffset(&offset);
|
|
|
|
switch (nodeType) {
|
|
|
|
case nsIDOMNode::ATTRIBUTE_NODE:
|
|
|
|
{
|
|
|
|
// XXX Assuming jumping to the ownerElement is the sanest action.
|
|
|
|
nsCOMPtr<nsIAttribute> attr = do_QueryInterface(node);
|
|
|
|
content = attr->GetContent();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case nsIDOMNode::DOCUMENT_NODE:
|
|
|
|
{
|
|
|
|
if (offset >= 0) {
|
|
|
|
nsCOMPtr<nsIDocument> document = do_QueryInterface(node);
|
|
|
|
content = document->GetChildAt(offset);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case nsIDOMNode::DOCUMENT_FRAGMENT_NODE:
|
|
|
|
case nsIDOMNode::ELEMENT_NODE:
|
|
|
|
case nsIDOMNode::ENTITY_REFERENCE_NODE:
|
|
|
|
{
|
|
|
|
if (offset >= 0) {
|
|
|
|
nsCOMPtr<nsIContent> parent = do_QueryInterface(node);
|
|
|
|
content = parent->GetChildAt(offset);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case nsIDOMNode::CDATA_SECTION_NODE:
|
|
|
|
case nsIDOMNode::COMMENT_NODE:
|
|
|
|
case nsIDOMNode::TEXT_NODE:
|
|
|
|
case nsIDOMNode::PROCESSING_INSTRUCTION_NODE:
|
|
|
|
{
|
|
|
|
// XXX This should scroll to a specific position in the text.
|
|
|
|
content = do_QueryInterface(node);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2001-12-20 05:15:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-02-20 09:55:02 +00:00
|
|
|
|
2004-02-27 17:17:37 +00:00
|
|
|
esm->SetContentState(content, NS_EVENT_STATE_URLTARGET);
|
2000-10-11 13:50:45 +00:00
|
|
|
|
2009-11-02 01:02:09 +00:00
|
|
|
#ifdef ACCESSIBILITY
|
|
|
|
nsIContent *anchorTarget = content;
|
|
|
|
#endif
|
|
|
|
|
2003-01-13 23:10:53 +00:00
|
|
|
if (content) {
|
2003-05-06 05:46:46 +00:00
|
|
|
if (aScroll) {
|
2007-03-06 09:53:56 +00:00
|
|
|
rv = ScrollContentIntoView(content, NS_PRESSHELL_SCROLL_TOP,
|
|
|
|
NS_PRESSHELL_SCROLL_ANYWHERE);
|
2004-11-12 21:58:12 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2008-02-27 10:01:17 +00:00
|
|
|
|
|
|
|
nsIScrollableFrame* rootScroll = GetRootScrollFrameAsScrollable();
|
|
|
|
if (rootScroll) {
|
|
|
|
mLastAnchorScrolledTo = content;
|
|
|
|
mLastAnchorScrollPositionY = rootScroll->GetScrollPosition().y;
|
|
|
|
}
|
2004-11-12 21:58:12 +00:00
|
|
|
}
|
2001-03-27 23:59:56 +00:00
|
|
|
|
2004-11-12 21:58:12 +00:00
|
|
|
// Should we select the target? This action is controlled by a
|
|
|
|
// preference: the default is to not select.
|
|
|
|
PRBool selectAnchor = nsContentUtils::GetBoolPref("layout.selectanchor");
|
2004-04-29 23:34:19 +00:00
|
|
|
|
2004-11-12 21:58:12 +00:00
|
|
|
// Even if select anchor pref is false, we must still move the
|
|
|
|
// caret there. That way tabbing will start from the new
|
|
|
|
// location
|
|
|
|
if (!jumpToRange) {
|
|
|
|
jumpToRange = do_CreateInstance(kRangeCID);
|
|
|
|
if (jumpToRange) {
|
|
|
|
while (content && content->GetChildCount() > 0) {
|
|
|
|
content = content->GetChildAt(0);
|
Fixes bug 66597, bug 103284, bug 114440, bug 120023, bug 128741, bug 19259. Cleans up browse with caret, makes it work with XML content docs, creates keyboard toggle for it (Accel+shift+K), synchronizes focus and document selection so that users can tab navigate relative to their last find or click in text, or vice versa, makes tabbing move relative to named anchor that has been jumped to. r=bryner, sr=alecf, a=asa
2002-03-10 06:21:48 +00:00
|
|
|
}
|
2004-11-12 21:58:12 +00:00
|
|
|
nsCOMPtr<nsIDOMNode> node(do_QueryInterface(content));
|
2005-11-20 22:05:24 +00:00
|
|
|
NS_ASSERTION(node, "No nsIDOMNode for descendant of anchor");
|
2004-11-12 21:58:12 +00:00
|
|
|
jumpToRange->SelectNodeContents(node);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (jumpToRange) {
|
|
|
|
// Select the anchor
|
2006-04-26 02:01:07 +00:00
|
|
|
nsISelection* sel = mSelection->
|
|
|
|
GetSelection(nsISelectionController::SELECTION_NORMAL);
|
|
|
|
if (sel) {
|
2004-11-12 21:58:12 +00:00
|
|
|
sel->RemoveAllRanges();
|
|
|
|
sel->AddRange(jumpToRange);
|
|
|
|
if (!selectAnchor) {
|
|
|
|
// Use a caret (collapsed selection) at the start of the anchor
|
|
|
|
sel->CollapseToStart();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (selectAnchor && xpointerResult) {
|
|
|
|
// Select the rest (if any) of the ranges in XPointerResult
|
|
|
|
PRUint32 count, i;
|
|
|
|
xpointerResult->GetLength(&count);
|
|
|
|
for (i = 1; i < count; i++) { // jumpToRange is i = 0
|
|
|
|
nsCOMPtr<nsIDOMRange> range;
|
|
|
|
xpointerResult->Item(i, getter_AddRefs(range));
|
|
|
|
sel->AddRange(range);
|
Fixes bug 66597, bug 103284, bug 114440, bug 120023, bug 128741, bug 19259. Cleans up browse with caret, makes it work with XML content docs, creates keyboard toggle for it (Accel+shift+K), synchronizes focus and document selection so that users can tab navigate relative to their last find or click in text, or vice versa, makes tabbing move relative to named anchor that has been jumped to. r=bryner, sr=alecf, a=asa
2002-03-10 06:21:48 +00:00
|
|
|
}
|
2001-03-27 23:59:56 +00:00
|
|
|
}
|
2005-04-12 20:25:49 +00:00
|
|
|
// Selection is at anchor.
|
|
|
|
// Now focus the document itself if focus is on an element within it.
|
2005-08-12 04:11:00 +00:00
|
|
|
nsPIDOMWindow *win = mDocument->GetWindow();
|
2005-07-30 20:57:07 +00:00
|
|
|
|
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 18:00:39 +00:00
|
|
|
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
|
|
|
|
if (fm && win) {
|
|
|
|
nsCOMPtr<nsIDOMWindow> focusedWindow;
|
|
|
|
fm->GetFocusedWindow(getter_AddRefs(focusedWindow));
|
|
|
|
if (SameCOMIdentity(win, focusedWindow))
|
|
|
|
fm->ClearFocus(focusedWindow);
|
2005-04-12 20:25:49 +00:00
|
|
|
}
|
1999-02-12 05:39:33 +00:00
|
|
|
}
|
|
|
|
} else {
|
2001-10-17 01:06:19 +00:00
|
|
|
rv = NS_ERROR_FAILURE; //changed to NS_OK in quirks mode if ScrollTo is called
|
2009-11-02 01:02:09 +00:00
|
|
|
|
2001-10-17 01:06:19 +00:00
|
|
|
// Scroll to the top/left if the anchor can not be
|
2001-10-20 03:12:33 +00:00
|
|
|
// found and it is labelled top (quirks mode only). @see bug 80784
|
2006-02-03 14:18:39 +00:00
|
|
|
if ((NS_LossyConvertUTF16toASCII(aAnchorName).LowerCaseEqualsLiteral("top")) &&
|
2003-12-24 21:51:50 +00:00
|
|
|
(mPresContext->CompatibilityMode() == eCompatibility_NavQuirks)) {
|
2003-01-13 23:10:53 +00:00
|
|
|
rv = NS_OK;
|
2009-09-09 05:40:02 +00:00
|
|
|
nsIScrollableFrame* sf = GetRootScrollFrameAsScrollable();
|
2003-01-13 23:10:53 +00:00
|
|
|
// Check |aScroll| after setting |rv| so we set |rv| to the same
|
|
|
|
// thing whether or not |aScroll| is true.
|
2009-09-09 05:40:02 +00:00
|
|
|
if (aScroll && sf) {
|
|
|
|
// Scroll to the top of the page
|
|
|
|
sf->ScrollTo(nsPoint(0, 0), nsIScrollableFrame::INSTANT);
|
2001-10-17 01:06:19 +00:00
|
|
|
}
|
|
|
|
}
|
1999-02-12 05:39:33 +00:00
|
|
|
}
|
|
|
|
|
2009-11-02 01:02:09 +00:00
|
|
|
#ifdef ACCESSIBILITY
|
|
|
|
if (anchorTarget && gIsAccessibilityActive) {
|
|
|
|
nsCOMPtr<nsIAccessibilityService> accService =
|
|
|
|
do_GetService("@mozilla.org/accessibilityService;1");
|
|
|
|
if (accService)
|
|
|
|
accService->NotifyOfAnchorJumpTo(anchorTarget);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1999-02-12 05:39:33 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2010-03-31 12:41:54 +00:00
|
|
|
nsresult
|
2008-02-27 10:01:17 +00:00
|
|
|
PresShell::ScrollToAnchor()
|
|
|
|
{
|
|
|
|
if (!mLastAnchorScrolledTo)
|
|
|
|
return NS_OK;
|
|
|
|
|
2010-05-12 00:30:40 +00:00
|
|
|
NS_ASSERTION(mDidInitialReflow, "should have done initial reflow by now");
|
|
|
|
|
2008-02-27 10:01:17 +00:00
|
|
|
nsIScrollableFrame* rootScroll = GetRootScrollFrameAsScrollable();
|
|
|
|
if (!rootScroll ||
|
|
|
|
mLastAnchorScrollPositionY != rootScroll->GetScrollPosition().y)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
nsresult rv = ScrollContentIntoView(mLastAnchorScrolledTo, NS_PRESSHELL_SCROLL_TOP,
|
|
|
|
NS_PRESSHELL_SCROLL_ANYWHERE);
|
|
|
|
mLastAnchorScrolledTo = nsnull;
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2007-07-16 05:53:19 +00:00
|
|
|
/*
|
|
|
|
* Helper (per-continuation) for ScrollContentIntoView.
|
|
|
|
*
|
2009-09-09 05:40:02 +00:00
|
|
|
* @param aContainerFrame [in] the frame which aRect is relative to
|
2007-07-16 05:53:19 +00:00
|
|
|
* @param aFrame [in] Frame whose bounds should be unioned
|
2009-09-09 05:40:02 +00:00
|
|
|
* @param aUseWholeLineHeightForInlines [in] if true, then for inline frames
|
|
|
|
* we should include the top of the line in the added rectangle
|
2007-07-16 05:53:19 +00:00
|
|
|
* @param aRect [inout] rect into which its bounds should be unioned
|
2007-07-16 05:55:04 +00:00
|
|
|
* @param aHaveRect [inout] whether aRect contains data yet
|
2007-07-16 05:53:19 +00:00
|
|
|
*/
|
|
|
|
static void
|
2009-09-09 05:40:02 +00:00
|
|
|
AccumulateFrameBounds(nsIFrame* aContainerFrame,
|
|
|
|
nsIFrame* aFrame,
|
|
|
|
PRBool aUseWholeLineHeightForInlines,
|
|
|
|
nsRect& aRect,
|
|
|
|
PRBool& aHaveRect)
|
2007-07-16 05:53:19 +00:00
|
|
|
{
|
2009-09-09 05:40:02 +00:00
|
|
|
nsRect frameBounds = aFrame->GetRect() +
|
|
|
|
aFrame->GetParent()->GetOffsetTo(aContainerFrame);
|
2007-07-16 05:53:19 +00:00
|
|
|
|
|
|
|
// If this is an inline frame and either the bounds height is 0 (quirks
|
2009-09-09 05:40:02 +00:00
|
|
|
// layout model) or aUseWholeLineHeightForInlines is set, we need to
|
2007-07-16 05:53:19 +00:00
|
|
|
// change the top of the bounds to include the whole line.
|
2009-09-09 05:40:02 +00:00
|
|
|
if (frameBounds.height == 0 || aUseWholeLineHeightForInlines) {
|
2007-07-16 05:53:19 +00:00
|
|
|
nsIAtom* frameType = NULL;
|
|
|
|
nsIFrame *prevFrame = aFrame;
|
|
|
|
nsIFrame *f = aFrame;
|
|
|
|
|
|
|
|
while (f &&
|
|
|
|
(frameType = f->GetType()) == nsGkAtoms::inlineFrame) {
|
|
|
|
prevFrame = f;
|
|
|
|
f = prevFrame->GetParent();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (f != aFrame &&
|
|
|
|
f &&
|
|
|
|
frameType == nsGkAtoms::blockFrame) {
|
|
|
|
// find the line containing aFrame and increase the top of |offset|.
|
2008-10-30 19:17:59 +00:00
|
|
|
nsAutoLineIterator lines = f->GetLineIterator();
|
2007-07-16 05:53:19 +00:00
|
|
|
if (lines) {
|
2008-10-30 19:17:59 +00:00
|
|
|
PRInt32 index = lines->FindLineContaining(prevFrame);
|
2007-07-16 05:53:19 +00:00
|
|
|
if (index >= 0) {
|
|
|
|
nsIFrame *trash1;
|
|
|
|
PRInt32 trash2;
|
|
|
|
nsRect lineBounds;
|
|
|
|
PRUint32 trash3;
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(lines->GetLine(index, &trash1, &trash2,
|
|
|
|
lineBounds, &trash3))) {
|
2009-09-09 05:40:02 +00:00
|
|
|
lineBounds += f->GetOffsetTo(aContainerFrame);
|
|
|
|
if (lineBounds.y < frameBounds.y) {
|
|
|
|
frameBounds.height = frameBounds.YMost() - lineBounds.y;
|
|
|
|
frameBounds.y = lineBounds.y;
|
2007-07-16 05:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-09 05:40:02 +00:00
|
|
|
if (aHaveRect) {
|
|
|
|
// We can't use nsRect::UnionRect since it drops empty rects on
|
|
|
|
// the floor, and we need to include them. (Thus we need
|
|
|
|
// aHaveRect to know when to drop the initial value on the floor.)
|
|
|
|
aRect.UnionRectIncludeEmpty(aRect, frameBounds);
|
|
|
|
} else {
|
|
|
|
aHaveRect = PR_TRUE;
|
|
|
|
aRect = frameBounds;
|
2007-07-16 05:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-11-12 04:38:28 +00:00
|
|
|
/**
|
2009-09-09 05:40:02 +00:00
|
|
|
* This function takes a scrollable frame, a rect in the coordinate system
|
|
|
|
* of the scrolled frame, and a desired percentage-based scroll
|
|
|
|
* position and attempts to scroll the rect to that position in the
|
|
|
|
* scrollport.
|
2010-01-11 21:45:16 +00:00
|
|
|
*
|
|
|
|
* This needs to work even if aRect has a width or height of zero.
|
2002-11-12 04:38:28 +00:00
|
|
|
*/
|
2009-09-09 05:40:02 +00:00
|
|
|
static void ScrollToShowRect(nsIScrollableFrame* aScrollFrame,
|
|
|
|
const nsRect& aRect,
|
|
|
|
PRIntn aVPercent,
|
2010-01-11 21:45:16 +00:00
|
|
|
PRIntn aHPercent,
|
|
|
|
PRUint32 aFlags)
|
2002-11-12 04:38:28 +00:00
|
|
|
{
|
2009-09-09 05:40:02 +00:00
|
|
|
nsPoint scrollPt = aScrollFrame->GetScrollPosition();
|
|
|
|
nsRect visibleRect(scrollPt, aScrollFrame->GetScrollPortRect().Size());
|
|
|
|
nsSize lineSize = aScrollFrame->GetLineScrollAmount();
|
2010-01-11 21:45:16 +00:00
|
|
|
nsPresContext::ScrollbarStyles ss = aScrollFrame->GetScrollbarStyles();
|
|
|
|
|
|
|
|
if ((aFlags & nsIPresShell::SCROLL_OVERFLOW_HIDDEN) ||
|
|
|
|
ss.mVertical != NS_STYLE_OVERFLOW_HIDDEN) {
|
|
|
|
// See how the rect should be positioned vertically
|
|
|
|
if (NS_PRESSHELL_SCROLL_ANYWHERE == aVPercent ||
|
|
|
|
(NS_PRESSHELL_SCROLL_IF_NOT_VISIBLE == aVPercent &&
|
|
|
|
aRect.height < lineSize.height)) {
|
|
|
|
// The caller doesn't care where the frame is positioned vertically,
|
|
|
|
// so long as it's fully visible
|
|
|
|
if (aRect.y < visibleRect.y) {
|
|
|
|
// Scroll up so the frame's top edge is visible
|
2009-09-09 05:40:02 +00:00
|
|
|
scrollPt.y = aRect.y;
|
2010-01-11 21:45:16 +00:00
|
|
|
} else if (aRect.YMost() > visibleRect.YMost()) {
|
|
|
|
// Scroll down so the frame's bottom edge is visible. Make sure the
|
|
|
|
// frame's top edge is still visible
|
|
|
|
scrollPt.y += aRect.YMost() - visibleRect.YMost();
|
|
|
|
if (scrollPt.y > aRect.y) {
|
|
|
|
scrollPt.y = aRect.y;
|
|
|
|
}
|
2002-11-12 04:38:28 +00:00
|
|
|
}
|
2010-01-11 21:45:16 +00:00
|
|
|
} else if (NS_PRESSHELL_SCROLL_IF_NOT_VISIBLE == aVPercent) {
|
|
|
|
// Scroll only if no part of the frame is visible in this view
|
|
|
|
if (aRect.YMost() - lineSize.height < visibleRect.y) {
|
|
|
|
// Scroll up so the frame's top edge is visible
|
2009-09-09 05:40:02 +00:00
|
|
|
scrollPt.y = aRect.y;
|
2010-01-11 21:45:16 +00:00
|
|
|
} else if (aRect.y + lineSize.height > visibleRect.YMost()) {
|
|
|
|
// Scroll down so the frame's bottom edge is visible. Make sure the
|
|
|
|
// frame's top edge is still visible
|
|
|
|
scrollPt.y += aRect.YMost() - visibleRect.YMost();
|
|
|
|
if (scrollPt.y > aRect.y) {
|
|
|
|
scrollPt.y = aRect.y;
|
|
|
|
}
|
2002-11-12 04:38:28 +00:00
|
|
|
}
|
2010-01-11 21:45:16 +00:00
|
|
|
} else {
|
|
|
|
// Align the frame edge according to the specified percentage
|
|
|
|
nscoord frameAlignY =
|
|
|
|
NSToCoordRound(aRect.y + aRect.height * (aVPercent / 100.0f));
|
|
|
|
scrollPt.y =
|
|
|
|
NSToCoordRound(frameAlignY - visibleRect.height * (aVPercent / 100.0f));
|
2002-11-12 04:38:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-11 21:45:16 +00:00
|
|
|
if ((aFlags & nsIPresShell::SCROLL_OVERFLOW_HIDDEN) ||
|
|
|
|
ss.mHorizontal != NS_STYLE_OVERFLOW_HIDDEN) {
|
|
|
|
// See how the frame should be positioned horizontally
|
|
|
|
if (NS_PRESSHELL_SCROLL_ANYWHERE == aHPercent ||
|
|
|
|
(NS_PRESSHELL_SCROLL_IF_NOT_VISIBLE == aHPercent &&
|
|
|
|
aRect.width < lineSize.width)) {
|
|
|
|
// The caller doesn't care where the frame is positioned horizontally,
|
|
|
|
// so long as it's fully visible
|
|
|
|
if (aRect.x < visibleRect.x) {
|
|
|
|
// Scroll left so the frame's left edge is visible
|
2009-09-09 05:40:02 +00:00
|
|
|
scrollPt.x = aRect.x;
|
2010-01-11 21:45:16 +00:00
|
|
|
} else if (aRect.XMost() > visibleRect.XMost()) {
|
|
|
|
// Scroll right so the frame's right edge is visible. Make sure the
|
|
|
|
// frame's left edge is still visible
|
|
|
|
scrollPt.x += aRect.XMost() - visibleRect.XMost();
|
|
|
|
if (scrollPt.x > aRect.x) {
|
|
|
|
scrollPt.x = aRect.x;
|
|
|
|
}
|
2002-11-12 04:38:28 +00:00
|
|
|
}
|
2010-01-11 21:45:16 +00:00
|
|
|
} else if (NS_PRESSHELL_SCROLL_IF_NOT_VISIBLE == aHPercent) {
|
|
|
|
// Scroll only if no part of the frame is visible in this view
|
|
|
|
if (aRect.XMost() - lineSize.width < visibleRect.x) {
|
|
|
|
// Scroll left so the frame's left edge is visible
|
2009-09-09 05:40:02 +00:00
|
|
|
scrollPt.x = aRect.x;
|
2010-01-11 21:45:16 +00:00
|
|
|
} else if (aRect.x + lineSize.width > visibleRect.XMost()) {
|
|
|
|
// Scroll right so the frame's right edge is visible. Make sure the
|
|
|
|
// frame's left edge is still visible
|
|
|
|
scrollPt.x += aRect.XMost() - visibleRect.XMost();
|
|
|
|
if (scrollPt.x > aRect.x) {
|
|
|
|
scrollPt.x = aRect.x;
|
|
|
|
}
|
2002-11-12 04:38:28 +00:00
|
|
|
}
|
2010-01-11 21:45:16 +00:00
|
|
|
} else {
|
|
|
|
// Align the frame edge according to the specified percentage
|
|
|
|
nscoord frameAlignX =
|
|
|
|
NSToCoordRound(aRect.x + (aRect.width) * (aHPercent / 100.0f));
|
|
|
|
scrollPt.x =
|
|
|
|
NSToCoordRound(frameAlignX - visibleRect.width * (aHPercent / 100.0f));
|
2002-11-12 04:38:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-09 05:40:02 +00:00
|
|
|
aScrollFrame->ScrollTo(scrollPt, nsIScrollableFrame::INSTANT);
|
2002-11-12 04:38:28 +00:00
|
|
|
}
|
|
|
|
|
2010-03-31 12:41:54 +00:00
|
|
|
nsresult
|
2007-03-07 19:08:36 +00:00
|
|
|
PresShell::ScrollContentIntoView(nsIContent* aContent,
|
|
|
|
PRIntn aVPercent,
|
2009-04-21 23:53:52 +00:00
|
|
|
PRIntn aHPercent)
|
1999-02-18 22:52:21 +00:00
|
|
|
{
|
2007-03-07 19:08:36 +00:00
|
|
|
nsCOMPtr<nsIContent> content = aContent; // Keep content alive while flushing.
|
|
|
|
NS_ENSURE_TRUE(content, NS_ERROR_NULL_POINTER);
|
|
|
|
nsCOMPtr<nsIDocument> currentDoc = content->GetCurrentDoc();
|
|
|
|
NS_ENSURE_STATE(currentDoc);
|
2000-11-04 08:21:20 +00:00
|
|
|
|
2010-05-12 00:30:40 +00:00
|
|
|
NS_ASSERTION(mDidInitialReflow, "should have done initial reflow by now");
|
|
|
|
|
2009-05-10 03:57:53 +00:00
|
|
|
mContentToScrollTo = aContent;
|
|
|
|
mContentScrollVPosition = aVPercent;
|
|
|
|
mContentScrollHPosition = aHPercent;
|
|
|
|
|
|
|
|
// Flush layout and attempt to scroll in the process.
|
|
|
|
currentDoc->FlushPendingNotifications(Flush_InterruptibleLayout);
|
|
|
|
|
|
|
|
// If mContentToScrollTo is non-null, that means we interrupted the reflow
|
|
|
|
// (or suppressed it altogether because we're suppressing interruptible
|
|
|
|
// flushes right now) and won't necessarily get the position correct, but do
|
|
|
|
// a best-effort scroll here. The other option would be to do this inside
|
|
|
|
// FlushPendingNotifications, but I'm not sure the repeated scrolling that
|
|
|
|
// could trigger if reflows keep getting interrupted would be more desirable
|
|
|
|
// than a single best-effort scroll followed by one final scroll on the first
|
|
|
|
// completed reflow.
|
|
|
|
if (mContentToScrollTo) {
|
|
|
|
DoScrollContentIntoView(content, aVPercent, aHPercent);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
2009-04-21 23:53:52 +00:00
|
|
|
}
|
|
|
|
|
2009-05-10 03:57:53 +00:00
|
|
|
void
|
2009-04-21 23:53:52 +00:00
|
|
|
PresShell::DoScrollContentIntoView(nsIContent* aContent,
|
|
|
|
PRIntn aVPercent,
|
|
|
|
PRIntn aHPercent)
|
|
|
|
{
|
2010-05-12 00:30:40 +00:00
|
|
|
NS_ASSERTION(mDidInitialReflow, "should have done initial reflow by now");
|
|
|
|
|
2009-12-24 21:20:06 +00:00
|
|
|
nsIFrame* frame = aContent->GetPrimaryFrame();
|
2009-04-21 23:53:52 +00:00
|
|
|
if (!frame) {
|
|
|
|
mContentToScrollTo = nsnull;
|
2009-05-10 03:57:53 +00:00
|
|
|
return;
|
2009-04-21 23:53:52 +00:00
|
|
|
}
|
|
|
|
|
2009-05-15 01:40:28 +00:00
|
|
|
if (frame->GetStateBits() & NS_FRAME_FIRST_REFLOW) {
|
|
|
|
// The reflow flush before this scroll got interrupted, and this frame's
|
|
|
|
// coords and size are all zero, and it has no content showing anyway.
|
|
|
|
// Don't bother scrolling to it. We'll try again when we finish up layout.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-09-09 05:40:02 +00:00
|
|
|
nsIFrame* container =
|
|
|
|
nsLayoutUtils::GetClosestFrameOfType(frame, nsGkAtoms::scrollFrame);
|
|
|
|
if (!container) {
|
|
|
|
// nothing can be scrolled
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-11-12 04:38:28 +00:00
|
|
|
// This is a two-step process.
|
|
|
|
// Step 1: Find the bounds of the rect we want to scroll into view. For
|
2003-10-10 02:35:05 +00:00
|
|
|
// example, for an inline frame we may want to scroll in the whole
|
2009-09-09 05:40:02 +00:00
|
|
|
// line, or we may want to scroll multiple lines into view.
|
|
|
|
// Step 2: Walk container frame and its ancestors and scroll them
|
2002-11-12 04:38:28 +00:00
|
|
|
// appropriately.
|
2009-09-09 05:40:02 +00:00
|
|
|
// frameBounds is relative to container. We're assuming
|
|
|
|
// that scrollframes don't split so every continuation of frame will
|
|
|
|
// be a descendant of container. (Things would still mostly work
|
|
|
|
// even if that assumption was false.)
|
2007-07-16 05:53:19 +00:00
|
|
|
nsRect frameBounds;
|
2007-07-16 05:55:04 +00:00
|
|
|
PRBool haveRect = PR_FALSE;
|
2009-09-09 05:40:02 +00:00
|
|
|
PRBool useWholeLineHeightForInlines = aVPercent != NS_PRESSHELL_SCROLL_ANYWHERE;
|
2007-07-16 05:53:19 +00:00
|
|
|
do {
|
2009-09-09 05:40:02 +00:00
|
|
|
AccumulateFrameBounds(container, frame, useWholeLineHeightForInlines,
|
|
|
|
frameBounds, haveRect);
|
2007-07-16 05:53:19 +00:00
|
|
|
} while ((frame = frame->GetNextContinuation()));
|
2007-07-14 05:18:09 +00:00
|
|
|
|
2010-01-11 21:45:16 +00:00
|
|
|
ScrollFrameRectIntoView(container, frameBounds, aVPercent, aHPercent,
|
|
|
|
SCROLL_OVERFLOW_HIDDEN);
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
PresShell::ScrollFrameRectIntoView(nsIFrame* aFrame,
|
|
|
|
const nsRect& aRect,
|
|
|
|
PRIntn aVPercent,
|
|
|
|
PRIntn aHPercent,
|
|
|
|
PRUint32 aFlags)
|
|
|
|
{
|
|
|
|
PRBool didScroll = PR_FALSE;
|
|
|
|
// This function needs to work even if rect has a width or height of 0.
|
|
|
|
nsRect rect = aRect;
|
|
|
|
nsIFrame* container = aFrame;
|
|
|
|
// Walk up the frame hierarchy scrolling the rect into view and
|
|
|
|
// keeping rect relative to container
|
|
|
|
do {
|
2009-09-09 05:40:02 +00:00
|
|
|
nsIScrollableFrame* sf = do_QueryFrame(container);
|
|
|
|
if (sf) {
|
|
|
|
nsPoint oldPosition = sf->GetScrollPosition();
|
2010-01-11 21:45:16 +00:00
|
|
|
ScrollToShowRect(sf, rect - sf->GetScrolledFrame()->GetPosition(),
|
|
|
|
aVPercent, aHPercent, aFlags);
|
2009-09-09 05:40:02 +00:00
|
|
|
nsPoint newPosition = sf->GetScrollPosition();
|
2010-04-23 02:41:37 +00:00
|
|
|
// If the scroll position increased, that means our content moved up,
|
|
|
|
// so our rect's offset should decrease
|
|
|
|
rect += oldPosition - newPosition;
|
2010-01-11 21:45:16 +00:00
|
|
|
|
|
|
|
if (oldPosition != newPosition) {
|
|
|
|
didScroll = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2010-03-02 14:21:23 +00:00
|
|
|
// only scroll one container when this flag is set
|
|
|
|
if (aFlags & SCROLL_FIRST_ANCESTOR_ONLY) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-01-11 21:45:16 +00:00
|
|
|
nsRect scrollPort = sf->GetScrollPortRect();
|
|
|
|
if (rect.XMost() < scrollPort.x ||
|
|
|
|
rect.x > scrollPort.XMost() ||
|
|
|
|
rect.YMost() < scrollPort.y ||
|
|
|
|
rect.y > scrollPort.YMost()) {
|
|
|
|
// We tried to show the rectangle, but none of it is visible,
|
|
|
|
// not even an edge.
|
|
|
|
// Stop trying to scroll ancestors into view.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Restrict rect to the area that is actually visible through
|
|
|
|
// the scrollport. We don't want to try to scroll some clipped-out
|
|
|
|
// part of 'rect' into view in some ancestor.
|
|
|
|
rect.IntersectRect(rect, sf->GetScrollPortRect());
|
1999-02-18 22:52:21 +00:00
|
|
|
}
|
2010-01-11 21:45:16 +00:00
|
|
|
rect += container->GetPosition();
|
2010-03-29 01:46:59 +00:00
|
|
|
nsPoint extraOffset(0,0);
|
|
|
|
container = nsLayoutUtils::GetCrossDocParentFrame(container, &extraOffset);
|
|
|
|
rect += extraOffset;
|
2010-03-02 14:21:23 +00:00
|
|
|
} while (container);
|
2010-01-11 21:45:16 +00:00
|
|
|
|
|
|
|
return didScroll;
|
1999-02-18 22:52:21 +00:00
|
|
|
}
|
|
|
|
|
2009-09-09 05:40:02 +00:00
|
|
|
nsRectVisibility
|
|
|
|
PresShell::GetRectVisibility(nsIFrame* aFrame,
|
2010-03-31 12:47:25 +00:00
|
|
|
const nsRect &aRect,
|
|
|
|
nscoord aMinTwips) const
|
2009-09-09 05:40:02 +00:00
|
|
|
{
|
|
|
|
nsIFrame* rootFrame = FrameManager()->GetRootFrame();
|
|
|
|
NS_ASSERTION(rootFrame,
|
|
|
|
"How can someone have a frame for this presshell when there's no root?");
|
|
|
|
nsIScrollableFrame* sf = GetRootScrollFrameAsScrollable();
|
|
|
|
nsRect scrollPortRect;
|
|
|
|
if (sf) {
|
|
|
|
scrollPortRect = sf->GetScrollPortRect();
|
|
|
|
nsIFrame* f = do_QueryFrame(sf);
|
|
|
|
scrollPortRect += f->GetOffsetTo(rootFrame);
|
|
|
|
} else {
|
|
|
|
scrollPortRect = nsRect(nsPoint(0,0), rootFrame->GetSize());
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRect r = aRect + aFrame->GetOffsetTo(rootFrame);
|
|
|
|
// If aRect is entirely visible then we don't need to ensure that
|
|
|
|
// at least aMinTwips of it is visible
|
|
|
|
if (scrollPortRect.Contains(r))
|
|
|
|
return nsRectVisibility_kVisible;
|
|
|
|
|
|
|
|
nsRect insetRect = scrollPortRect;
|
|
|
|
insetRect.Deflate(aMinTwips, aMinTwips);
|
|
|
|
if (r.YMost() <= insetRect.y)
|
|
|
|
return nsRectVisibility_kAboveViewport;
|
|
|
|
if (r.y >= insetRect.YMost())
|
|
|
|
return nsRectVisibility_kBelowViewport;
|
|
|
|
if (r.XMost() <= insetRect.x)
|
|
|
|
return nsRectVisibility_kLeftOfViewport;
|
|
|
|
if (r.x >= insetRect.XMost())
|
|
|
|
return nsRectVisibility_kRightOfViewport;
|
|
|
|
|
|
|
|
return nsRectVisibility_kVisible;
|
|
|
|
}
|
|
|
|
|
2002-08-01 21:36:02 +00:00
|
|
|
// GetLinkLocation: copy link location to clipboard
|
2010-03-31 12:47:25 +00:00
|
|
|
nsresult PresShell::GetLinkLocation(nsIDOMNode* aNode, nsAString& aLocationString) const
|
2001-04-18 06:06:31 +00:00
|
|
|
{
|
|
|
|
#ifdef DEBUG_dr
|
2002-08-01 21:36:02 +00:00
|
|
|
printf("dr :: PresShell::GetLinkLocation\n");
|
2001-04-18 06:06:31 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
NS_ENSURE_ARG_POINTER(aNode);
|
|
|
|
nsresult rv;
|
2001-09-12 23:31:37 +00:00
|
|
|
nsAutoString anchorText;
|
2002-03-12 05:29:31 +00:00
|
|
|
static char strippedChars[] = {'\t','\r','\n'};
|
2001-04-18 06:06:31 +00:00
|
|
|
|
|
|
|
// are we an anchor?
|
2001-09-12 23:31:37 +00:00
|
|
|
nsCOMPtr<nsIDOMHTMLAnchorElement> anchor(do_QueryInterface(aNode));
|
|
|
|
nsCOMPtr<nsIDOMHTMLAreaElement> area;
|
|
|
|
nsCOMPtr<nsIDOMHTMLLinkElement> link;
|
|
|
|
nsAutoString xlinkType;
|
2001-04-18 06:06:31 +00:00
|
|
|
if (anchor) {
|
|
|
|
rv = anchor->GetHref(anchorText);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2001-09-12 23:31:37 +00:00
|
|
|
} else {
|
|
|
|
// area?
|
|
|
|
area = do_QueryInterface(aNode);
|
|
|
|
if (area) {
|
|
|
|
rv = area->GetHref(anchorText);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
} else {
|
|
|
|
// link?
|
|
|
|
link = do_QueryInterface(aNode);
|
|
|
|
if (link) {
|
|
|
|
rv = link->GetHref(anchorText);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
} else {
|
|
|
|
// Xlink?
|
|
|
|
nsCOMPtr<nsIDOMElement> element(do_QueryInterface(aNode));
|
|
|
|
if (element) {
|
|
|
|
NS_NAMED_LITERAL_STRING(xlinkNS,"http://www.w3.org/1999/xlink");
|
|
|
|
element->GetAttributeNS(xlinkNS,NS_LITERAL_STRING("type"),xlinkType);
|
2004-04-28 17:48:02 +00:00
|
|
|
if (xlinkType.EqualsLiteral("simple")) {
|
2001-09-12 23:31:37 +00:00
|
|
|
element->GetAttributeNS(xlinkNS,NS_LITERAL_STRING("href"),anchorText);
|
|
|
|
if (!anchorText.IsEmpty()) {
|
|
|
|
// Resolve the full URI using baseURI property
|
|
|
|
|
|
|
|
nsAutoString base;
|
|
|
|
nsCOMPtr<nsIDOM3Node> node(do_QueryInterface(aNode,&rv));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
node->GetBaseURI(base);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIIOService>
|
|
|
|
ios(do_GetService("@mozilla.org/network/io-service;1", &rv));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> baseURI;
|
2006-02-03 14:18:39 +00:00
|
|
|
rv = ios->NewURI(NS_ConvertUTF16toUTF8(base),nsnull,nsnull,getter_AddRefs(baseURI));
|
2001-09-12 23:31:37 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2001-11-18 06:04:17 +00:00
|
|
|
|
2002-03-06 07:48:55 +00:00
|
|
|
nsCAutoString spec;
|
2006-02-03 14:18:39 +00:00
|
|
|
rv = baseURI->Resolve(NS_ConvertUTF16toUTF8(anchorText),spec);
|
2001-09-12 23:31:37 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2003-06-24 01:46:50 +00:00
|
|
|
CopyUTF8toUTF16(spec, anchorText);
|
2001-09-12 23:31:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-05-10 02:35:00 +00:00
|
|
|
|
2004-04-30 13:23:43 +00:00
|
|
|
if (anchor || area || link || xlinkType.EqualsLiteral("simple")) {
|
2002-03-12 05:29:31 +00:00
|
|
|
//Remove all the '\t', '\r' and '\n' from 'anchorText'
|
|
|
|
anchorText.StripChars(strippedChars);
|
2001-05-10 02:35:00 +00:00
|
|
|
|
2002-08-01 21:36:02 +00:00
|
|
|
aLocationString = anchorText;
|
|
|
|
|
|
|
|
return NS_OK;
|
2001-04-18 06:06:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// if no link, fail.
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2008-12-07 21:58:07 +00:00
|
|
|
NS_IMETHODIMP_(void)
|
|
|
|
PresShell::DispatchSynthMouseMove(nsGUIEvent *aEvent,
|
|
|
|
PRBool aFlushOnHoverChange)
|
|
|
|
{
|
|
|
|
PRUint32 hoverGenerationBefore = mFrameConstructor->GetHoverGeneration();
|
|
|
|
nsEventStatus status;
|
2009-09-26 23:35:05 +00:00
|
|
|
nsIView* targetView;
|
|
|
|
targetView = nsIView::GetViewFor(aEvent->widget);
|
|
|
|
mViewManager->DispatchEvent(aEvent, targetView, &status);
|
2008-12-07 21:58:07 +00:00
|
|
|
if (aFlushOnHoverChange &&
|
|
|
|
hoverGenerationBefore != mFrameConstructor->GetHoverGeneration()) {
|
|
|
|
// Flush so that the resulting reflow happens now so that our caller
|
|
|
|
// can suppress any synthesized mouse moves caused by that reflow.
|
|
|
|
FlushPendingNotifications(Flush_Layout);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-13 13:13:16 +00:00
|
|
|
NS_IMETHODIMP_(void)
|
|
|
|
PresShell::ClearMouseCapture(nsIView* aView)
|
|
|
|
{
|
|
|
|
if (gCaptureInfo.mContent) {
|
|
|
|
if (aView) {
|
2009-09-17 16:59:42 +00:00
|
|
|
// if a view was specified, ensure that the captured content is within
|
2009-12-31 17:36:56 +00:00
|
|
|
// this view.
|
|
|
|
nsIFrame* frame = gCaptureInfo.mContent->GetPrimaryFrame();
|
2009-09-13 13:13:16 +00:00
|
|
|
if (frame) {
|
|
|
|
nsIView* view = frame->GetClosestView();
|
2009-10-05 14:00:05 +00:00
|
|
|
// if there is no view, capturing won't be handled any more, so
|
|
|
|
// just release the capture.
|
|
|
|
if (view) {
|
|
|
|
do {
|
|
|
|
if (view == aView) {
|
|
|
|
NS_RELEASE(gCaptureInfo.mContent);
|
|
|
|
// the view containing the captured content likely disappeared so
|
|
|
|
// disable capture for now.
|
|
|
|
gCaptureInfo.mAllowed = PR_FALSE;
|
|
|
|
break;
|
|
|
|
}
|
2009-09-13 13:13:16 +00:00
|
|
|
|
2009-10-05 14:00:05 +00:00
|
|
|
view = view->GetParent();
|
|
|
|
} while (view);
|
|
|
|
// return if the view wasn't found
|
|
|
|
return;
|
2009-09-13 13:13:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_RELEASE(gCaptureInfo.mContent);
|
|
|
|
}
|
|
|
|
|
|
|
|
// disable mouse capture until the next mousedown as a dialog has opened
|
|
|
|
// or a drag has started. Otherwise, someone could start capture during
|
|
|
|
// the modal dialog or drag.
|
|
|
|
gCaptureInfo.mAllowed = PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2010-03-31 12:41:54 +00:00
|
|
|
nsresult
|
2000-06-15 00:35:46 +00:00
|
|
|
PresShell::CaptureHistoryState(nsILayoutHistoryState** aState, PRBool aLeavingPage)
|
1999-08-30 22:38:58 +00:00
|
|
|
{
|
2010-05-19 23:22:19 +00:00
|
|
|
NS_TIME_FUNCTION_MIN(1.0);
|
|
|
|
|
1999-08-30 22:38:58 +00:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
NS_PRECONDITION(nsnull != aState, "null state pointer");
|
|
|
|
|
2005-05-12 20:53:33 +00:00
|
|
|
// We actually have to mess with the docshell here, since we want to
|
|
|
|
// store the state back in it.
|
|
|
|
// XXXbz this isn't really right, since this is being called in the
|
|
|
|
// content viewer's Hide() method... by that point the docshell's
|
|
|
|
// state could be wrong. We should sort out a better ownership
|
|
|
|
// model for the layout history state.
|
2004-02-01 10:09:07 +00:00
|
|
|
nsCOMPtr<nsISupports> container = mPresContext->GetContainer();
|
2003-05-30 00:21:01 +00:00
|
|
|
if (!container)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(container));
|
|
|
|
if (!docShell)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsILayoutHistoryState> historyState;
|
|
|
|
docShell->GetLayoutHistoryState(getter_AddRefs(historyState));
|
2001-05-12 15:52:06 +00:00
|
|
|
if (!historyState) {
|
2000-01-14 09:28:54 +00:00
|
|
|
// Create the document state object
|
2001-05-12 15:52:06 +00:00
|
|
|
rv = NS_NewLayoutHistoryState(getter_AddRefs(historyState));
|
1999-08-30 22:38:58 +00:00
|
|
|
|
2000-01-14 09:28:54 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
*aState = nsnull;
|
|
|
|
return rv;
|
2000-02-11 22:54:37 +00:00
|
|
|
}
|
1999-08-30 22:38:58 +00:00
|
|
|
|
2003-05-30 00:21:01 +00:00
|
|
|
docShell->SetLayoutHistoryState(historyState);
|
2000-01-14 09:28:54 +00:00
|
|
|
}
|
2001-05-12 15:52:06 +00:00
|
|
|
|
|
|
|
*aState = historyState;
|
|
|
|
NS_IF_ADDREF(*aState);
|
2000-01-14 09:28:54 +00:00
|
|
|
|
2000-02-11 22:54:37 +00:00
|
|
|
// Capture frame state for the entire frame hierarchy
|
2004-03-06 04:46:11 +00:00
|
|
|
nsIFrame* rootFrame = FrameManager()->GetRootFrame();
|
2004-02-23 21:29:06 +00:00
|
|
|
if (!rootFrame) return NS_OK;
|
2000-06-15 00:35:46 +00:00
|
|
|
// Capture frame state for the root scroll frame
|
2005-11-20 22:05:24 +00:00
|
|
|
// Don't capture state when first creating doc element hierarchy
|
2009-07-27 08:47:02 +00:00
|
|
|
// As the scroll position is 0 and this will cause us to lose
|
2000-06-15 00:35:46 +00:00
|
|
|
// our previously saved place!
|
|
|
|
if (aLeavingPage) {
|
2006-02-01 19:55:35 +00:00
|
|
|
nsIFrame* scrollFrame = GetRootScrollFrame();
|
2000-06-15 00:35:46 +00:00
|
|
|
if (scrollFrame) {
|
2004-09-13 02:10:29 +00:00
|
|
|
FrameManager()->CaptureFrameStateFor(scrollFrame, historyState,
|
|
|
|
nsIStatefulFrame::eDocumentScrollState);
|
2000-06-15 00:35:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-03-06 04:46:11 +00:00
|
|
|
FrameManager()->CaptureFrameState(rootFrame, historyState);
|
2000-01-14 09:28:54 +00:00
|
|
|
|
2004-02-23 21:29:06 +00:00
|
|
|
return NS_OK;
|
1999-08-30 22:38:58 +00:00
|
|
|
}
|
|
|
|
|
2001-04-25 19:52:49 +00:00
|
|
|
void
|
|
|
|
PresShell::UnsuppressAndInvalidate()
|
|
|
|
{
|
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 18:00:39 +00:00
|
|
|
if (!mPresContext->EnsureVisible() || mHaveShutDown) {
|
2005-01-20 03:39:09 +00:00
|
|
|
// No point; we're about to be torn down anyway.
|
|
|
|
return;
|
2001-05-01 22:54:11 +00:00
|
|
|
}
|
2005-01-20 03:39:09 +00:00
|
|
|
|
2004-02-23 21:29:06 +00:00
|
|
|
mPaintingSuppressed = PR_FALSE;
|
2004-03-06 04:46:11 +00:00
|
|
|
nsIFrame* rootFrame = FrameManager()->GetRootFrame();
|
2004-02-23 21:29:06 +00:00
|
|
|
if (rootFrame) {
|
2004-03-10 03:09:05 +00:00
|
|
|
// let's assume that outline on a root frame is not supported
|
|
|
|
nsRect rect(nsPoint(0, 0), rootFrame->GetSize());
|
2008-09-18 09:47:21 +00:00
|
|
|
rootFrame->Invalidate(rect);
|
2001-05-31 22:19:43 +00:00
|
|
|
|
2009-10-16 10:55:32 +00:00
|
|
|
if (mCaretEnabled && mCaret) {
|
|
|
|
mCaret->CheckCaretDrawingState();
|
|
|
|
}
|
|
|
|
|
2010-01-26 13:10:12 +00:00
|
|
|
nsRootPresContext* rootPC = mPresContext->GetRootPresContext();
|
|
|
|
if (rootPC) {
|
|
|
|
rootPC->UpdatePluginGeometry(rootFrame);
|
|
|
|
}
|
2009-09-23 14:38:57 +00:00
|
|
|
}
|
2009-07-22 00:45:00 +00:00
|
|
|
|
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 18:00:39 +00:00
|
|
|
// now that painting is unsuppressed, focus may be set on the document
|
|
|
|
nsPIDOMWindow *win = mDocument->GetWindow();
|
|
|
|
if (win)
|
|
|
|
win->SetReadyForFocus();
|
2004-06-22 04:32:52 +00:00
|
|
|
|
2009-05-12 19:07:08 +00:00
|
|
|
if (!mHaveShutDown && mViewManager)
|
2004-06-24 21:56:29 +00:00
|
|
|
mViewManager->SynthesizeMouseMove(PR_FALSE);
|
2001-04-25 19:52:49 +00:00
|
|
|
}
|
|
|
|
|
2010-03-31 12:43:49 +00:00
|
|
|
void
|
2001-05-01 22:54:11 +00:00
|
|
|
PresShell::UnsuppressPainting()
|
2001-04-25 19:52:49 +00:00
|
|
|
{
|
2001-05-01 22:54:11 +00:00
|
|
|
if (mPaintSuppressionTimer) {
|
2001-04-25 19:52:49 +00:00
|
|
|
mPaintSuppressionTimer->Cancel();
|
|
|
|
mPaintSuppressionTimer = nsnull;
|
|
|
|
}
|
|
|
|
|
2001-05-01 22:54:11 +00:00
|
|
|
if (mIsDocumentGone || !mPaintingSuppressed)
|
2010-03-31 12:43:49 +00:00
|
|
|
return;
|
2001-04-25 19:52:49 +00:00
|
|
|
|
|
|
|
// If we have reflows pending, just wait until we process
|
|
|
|
// the reflows and get all the frames where we want them
|
|
|
|
// before actually unlocking the painting. Otherwise
|
|
|
|
// go ahead and unlock now.
|
2009-02-03 14:42:18 +00:00
|
|
|
if (mDirtyRoots.Length() > 0)
|
2001-04-25 19:52:49 +00:00
|
|
|
mShouldUnsuppressPainting = PR_TRUE;
|
|
|
|
else
|
|
|
|
UnsuppressAndInvalidate();
|
|
|
|
}
|
2000-10-09 03:08:41 +00:00
|
|
|
|
2000-07-13 23:00:59 +00:00
|
|
|
// Post a request to handle an arbitrary callback after reflow has finished.
|
2010-03-31 12:41:54 +00:00
|
|
|
nsresult
|
2000-07-13 23:00:59 +00:00
|
|
|
PresShell::PostReflowCallback(nsIReflowCallback* aCallback)
|
|
|
|
{
|
2009-08-18 03:21:06 +00:00
|
|
|
void* result = AllocateMisc(sizeof(nsCallbackEventRequest));
|
2006-02-11 04:14:48 +00:00
|
|
|
if (NS_UNLIKELY(!result)) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
nsCallbackEventRequest* request = (nsCallbackEventRequest*)result;
|
2000-07-13 23:00:59 +00:00
|
|
|
|
|
|
|
request->callback = aCallback;
|
|
|
|
request->next = nsnull;
|
|
|
|
|
|
|
|
if (mLastCallbackEventRequest) {
|
|
|
|
mLastCallbackEventRequest = mLastCallbackEventRequest->next = request;
|
|
|
|
} else {
|
|
|
|
mFirstCallbackEventRequest = request;
|
|
|
|
mLastCallbackEventRequest = request;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-03-31 12:41:54 +00:00
|
|
|
void
|
2000-10-07 00:49:08 +00:00
|
|
|
PresShell::CancelReflowCallback(nsIReflowCallback* aCallback)
|
|
|
|
{
|
|
|
|
nsCallbackEventRequest* before = nsnull;
|
|
|
|
nsCallbackEventRequest* node = mFirstCallbackEventRequest;
|
|
|
|
while(node)
|
|
|
|
{
|
|
|
|
nsIReflowCallback* callback = node->callback;
|
|
|
|
|
|
|
|
if (callback == aCallback)
|
|
|
|
{
|
|
|
|
nsCallbackEventRequest* toFree = node;
|
|
|
|
if (node == mFirstCallbackEventRequest) {
|
2003-10-14 23:29:07 +00:00
|
|
|
node = node->next;
|
|
|
|
mFirstCallbackEventRequest = node;
|
|
|
|
NS_ASSERTION(before == nsnull, "impossible");
|
2000-10-07 00:49:08 +00:00
|
|
|
} else {
|
2003-10-14 23:29:07 +00:00
|
|
|
node = node->next;
|
|
|
|
before->next = node;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (toFree == mLastCallbackEventRequest) {
|
|
|
|
mLastCallbackEventRequest = before;
|
2000-10-07 00:49:08 +00:00
|
|
|
}
|
|
|
|
|
2009-08-18 03:21:06 +00:00
|
|
|
FreeMisc(sizeof(nsCallbackEventRequest), toFree);
|
2000-10-07 00:49:08 +00:00
|
|
|
} else {
|
|
|
|
before = node;
|
|
|
|
node = node->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-01 07:22:44 +00:00
|
|
|
void
|
|
|
|
PresShell::CancelPostedReflowCallbacks()
|
|
|
|
{
|
|
|
|
while (mFirstCallbackEventRequest) {
|
|
|
|
nsCallbackEventRequest* node = mFirstCallbackEventRequest;
|
|
|
|
mFirstCallbackEventRequest = node->next;
|
|
|
|
if (!mFirstCallbackEventRequest) {
|
|
|
|
mLastCallbackEventRequest = nsnull;
|
|
|
|
}
|
|
|
|
nsIReflowCallback* callback = node->callback;
|
2009-08-18 03:21:06 +00:00
|
|
|
FreeMisc(sizeof(nsCallbackEventRequest), node);
|
2007-12-01 07:22:44 +00:00
|
|
|
if (callback) {
|
|
|
|
callback->ReflowCallbackCanceled();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-07-13 23:00:59 +00:00
|
|
|
void
|
2009-04-21 23:53:52 +00:00
|
|
|
PresShell::HandlePostedReflowCallbacks(PRBool aInterruptible)
|
2000-07-13 23:00:59 +00:00
|
|
|
{
|
|
|
|
PRBool shouldFlush = PR_FALSE;
|
|
|
|
|
2003-10-14 23:29:07 +00:00
|
|
|
while (mFirstCallbackEventRequest) {
|
|
|
|
nsCallbackEventRequest* node = mFirstCallbackEventRequest;
|
|
|
|
mFirstCallbackEventRequest = node->next;
|
|
|
|
if (!mFirstCallbackEventRequest) {
|
|
|
|
mLastCallbackEventRequest = nsnull;
|
|
|
|
}
|
|
|
|
nsIReflowCallback* callback = node->callback;
|
2009-08-18 03:21:06 +00:00
|
|
|
FreeMisc(sizeof(nsCallbackEventRequest), node);
|
2007-03-05 01:39:53 +00:00
|
|
|
if (callback) {
|
|
|
|
if (callback->ReflowFinished()) {
|
|
|
|
shouldFlush = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
2003-10-14 23:29:07 +00:00
|
|
|
}
|
2000-07-13 23:00:59 +00:00
|
|
|
|
2009-04-21 23:53:52 +00:00
|
|
|
mozFlushType flushType =
|
|
|
|
aInterruptible ? Flush_InterruptibleLayout : Flush_Layout;
|
2000-07-13 23:00:59 +00:00
|
|
|
if (shouldFlush)
|
2009-04-21 23:53:52 +00:00
|
|
|
FlushPendingNotifications(flushType);
|
2000-07-13 23:00:59 +00:00
|
|
|
}
|
|
|
|
|
2010-03-20 21:54:19 +00:00
|
|
|
PRBool
|
2010-03-31 12:38:52 +00:00
|
|
|
PresShell::IsSafeToFlush() const
|
2000-10-17 05:07:39 +00:00
|
|
|
{
|
2008-03-14 23:08:57 +00:00
|
|
|
// Not safe if we are reflowing or in the middle of frame construction
|
2010-03-20 21:54:19 +00:00
|
|
|
PRBool isSafeToFlush = !mIsReflowing &&
|
|
|
|
!mChangeNestCount;
|
2009-06-28 20:04:35 +00:00
|
|
|
|
2010-03-20 21:54:19 +00:00
|
|
|
if (isSafeToFlush) {
|
2009-06-28 20:04:35 +00:00
|
|
|
// Not safe if we are painting
|
|
|
|
nsIViewManager* viewManager = GetViewManager();
|
|
|
|
if (viewManager) {
|
|
|
|
PRBool isPainting = PR_FALSE;
|
|
|
|
viewManager->IsPainting(isPainting);
|
|
|
|
if (isPainting) {
|
2010-03-20 21:54:19 +00:00
|
|
|
isSafeToFlush = PR_FALSE;
|
2009-06-28 20:04:35 +00:00
|
|
|
}
|
2000-10-17 05:07:39 +00:00
|
|
|
}
|
|
|
|
}
|
2009-06-28 20:04:35 +00:00
|
|
|
|
2010-03-20 21:54:19 +00:00
|
|
|
return isSafeToFlush;
|
2000-10-17 05:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-20 21:54:19 +00:00
|
|
|
void
|
2004-05-27 22:08:42 +00:00
|
|
|
PresShell::FlushPendingNotifications(mozFlushType aType)
|
2007-08-22 02:57:06 +00:00
|
|
|
{
|
2010-05-19 23:22:19 +00:00
|
|
|
#ifdef NS_FUNCTION_TIMER
|
|
|
|
NS_TIME_FUNCTION_DECLARE_DOCURL;
|
|
|
|
static const char *flushTypeNames[] = {
|
|
|
|
"Flush_Content",
|
|
|
|
"Flush_ContentAndNotify",
|
|
|
|
"Flush_Styles",
|
|
|
|
"Flush_InterruptibleLayout",
|
|
|
|
"Flush_Layout",
|
|
|
|
"Flush_Display"
|
|
|
|
};
|
|
|
|
NS_TIME_FUNCTION_MIN_FMT(1.0, "%s (line %d) (document: %s, type: %s)", MOZ_FUNCTION_NAME,
|
|
|
|
__LINE__, docURL__.get(), flushTypeNames[aType - 1]);
|
|
|
|
#endif
|
|
|
|
|
2007-08-22 02:57:06 +00:00
|
|
|
NS_ASSERTION(aType >= Flush_Frames, "Why did we get called?");
|
2010-03-20 21:54:19 +00:00
|
|
|
|
|
|
|
PRBool isSafeToFlush = IsSafeToFlush();
|
2009-06-28 20:04:35 +00:00
|
|
|
isSafeToFlush = isSafeToFlush && nsContentUtils::IsSafeToRunScript();
|
2000-10-17 05:07:39 +00:00
|
|
|
|
2004-10-09 01:39:21 +00:00
|
|
|
NS_ASSERTION(!isSafeToFlush || mViewManager, "Must have view manager");
|
2007-08-21 21:45:00 +00:00
|
|
|
// Make sure the view manager stays alive while batching view updates.
|
2008-01-26 23:59:50 +00:00
|
|
|
nsCOMPtr<nsIViewManager> viewManagerDeathGrip = mViewManager;
|
|
|
|
if (isSafeToFlush && mViewManager) {
|
2007-04-23 05:53:27 +00:00
|
|
|
// Processing pending notifications can kill us, and some callers only
|
|
|
|
// hold weak refs when calling FlushPendingNotifications(). :(
|
|
|
|
nsCOMPtr<nsIPresShell> kungFuDeathGrip(this);
|
|
|
|
|
2009-01-14 20:42:25 +00:00
|
|
|
if (mResizeEvent.IsPending()) {
|
|
|
|
FireResizeEvent();
|
|
|
|
if (mIsDestroying) {
|
2010-03-20 21:54:19 +00:00
|
|
|
return;
|
2009-01-14 20:42:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-10-09 01:39:21 +00:00
|
|
|
// Style reresolves not in conjunction with reflows can't cause
|
|
|
|
// painting or geometry changes, so don't bother with view update
|
|
|
|
// batching if we only have style reresolve
|
2008-01-26 23:59:50 +00:00
|
|
|
nsIViewManager::UpdateViewBatch batch(mViewManager);
|
2001-08-31 04:28:26 +00:00
|
|
|
|
2010-04-10 18:03:40 +00:00
|
|
|
// We need to make sure external resource documents are flushed too (for
|
|
|
|
// example, svg filters that reference a filter in an external document
|
|
|
|
// need the frames in the external document to be constructed for the
|
|
|
|
// filter to work). We only need external resources to be flushed when the
|
|
|
|
// main document is flushing >= Flush_Frames, so we flush external
|
|
|
|
// resources here instead of nsDocument::FlushPendingNotifications.
|
|
|
|
mDocument->FlushExternalResources(aType);
|
|
|
|
|
2007-09-04 08:31:01 +00:00
|
|
|
// Force flushing of any pending content notifications that might have
|
|
|
|
// queued up while our event was pending. That will ensure that we don't
|
|
|
|
// construct frames for content right now that's still waiting to be
|
|
|
|
// notified on,
|
|
|
|
mDocument->FlushPendingNotifications(Flush_ContentAndNotify);
|
2007-09-18 01:16:39 +00:00
|
|
|
|
|
|
|
// Process pending restyles, since any flush of the presshell wants
|
|
|
|
// up-to-date style data.
|
2007-09-04 08:31:01 +00:00
|
|
|
if (!mIsDestroying) {
|
2008-07-26 16:14:48 +00:00
|
|
|
mPresContext->FlushPendingMediaFeatureValuesChanged();
|
|
|
|
|
2008-12-08 16:08:05 +00:00
|
|
|
// Flush any pending update of the user font set, since that could
|
|
|
|
// cause style changes (for updating ex/ch units, and to cause a
|
|
|
|
// reflow).
|
|
|
|
mPresContext->FlushUserFontSet();
|
|
|
|
|
2010-03-02 15:36:33 +00:00
|
|
|
#ifdef MOZ_SMIL
|
|
|
|
// Flush any requested SMIL samples.
|
|
|
|
if (mDocument->HasAnimationController()) {
|
|
|
|
mDocument->GetAnimationController()->FlushResampleRequests();
|
|
|
|
}
|
|
|
|
#endif // MOZ_SMIL
|
|
|
|
|
2009-01-02 15:41:43 +00:00
|
|
|
nsAutoScriptBlocker scriptBlocker;
|
2010-01-18 09:26:40 +00:00
|
|
|
mFrameConstructor->CreateNeededFrames();
|
2007-09-04 08:31:01 +00:00
|
|
|
mFrameConstructor->ProcessPendingRestyles();
|
|
|
|
}
|
2004-08-10 03:24:41 +00:00
|
|
|
|
2007-09-18 01:16:39 +00:00
|
|
|
// Process whatever XBL constructors those restyles queued up. This
|
|
|
|
// ensures that onload doesn't fire too early and that we won't do extra
|
|
|
|
// reflows after those constructors run.
|
2007-09-14 19:15:44 +00:00
|
|
|
if (!mIsDestroying) {
|
|
|
|
mDocument->BindingManager()->ProcessAttachedQueue();
|
|
|
|
}
|
|
|
|
|
2007-09-18 01:16:39 +00:00
|
|
|
// Now those constructors might have posted restyle events. At the same
|
|
|
|
// time, we still need up-to-date style data. In particular, reflow
|
|
|
|
// depends on style being completely up to date. If it's not, then style
|
|
|
|
// context reparenting, which can happen during reflow, might suddenly pick
|
|
|
|
// up the new rules and we'll end up with frames whose style doesn't match
|
|
|
|
// the frame type.
|
|
|
|
if (!mIsDestroying) {
|
2009-01-02 15:41:43 +00:00
|
|
|
nsAutoScriptBlocker scriptBlocker;
|
2010-01-18 09:26:40 +00:00
|
|
|
mFrameConstructor->CreateNeededFrames();
|
2007-09-18 01:16:39 +00:00
|
|
|
mFrameConstructor->ProcessPendingRestyles();
|
|
|
|
}
|
|
|
|
|
2008-11-25 23:22:38 +00:00
|
|
|
|
2007-09-18 01:16:39 +00:00
|
|
|
// There might be more pending constructors now, but we're not going to
|
|
|
|
// worry about them. They can't be triggered during reflow, so we should
|
|
|
|
// be good.
|
2009-04-21 23:53:52 +00:00
|
|
|
|
|
|
|
if (aType >= (mSuppressInterruptibleReflows ? Flush_Layout : Flush_InterruptibleLayout) &&
|
|
|
|
!mIsDestroying) {
|
2007-04-16 00:11:34 +00:00
|
|
|
mFrameConstructor->RecalcQuotesAndCounters();
|
2008-09-09 13:43:10 +00:00
|
|
|
mViewManager->FlushDelayedResize();
|
2009-04-21 23:53:52 +00:00
|
|
|
if (ProcessReflowCommands(aType < Flush_Layout) && mContentToScrollTo) {
|
|
|
|
// We didn't get interrupted. Go ahead and scroll to our content
|
|
|
|
DoScrollContentIntoView(mContentToScrollTo, mContentScrollVPosition,
|
|
|
|
mContentScrollHPosition);
|
|
|
|
mContentToScrollTo = nsnull;
|
|
|
|
}
|
2004-05-27 22:08:42 +00:00
|
|
|
}
|
2001-08-31 04:28:26 +00:00
|
|
|
|
2004-10-09 01:39:21 +00:00
|
|
|
PRUint32 updateFlags = NS_VMREFRESH_NO_SYNC;
|
2007-08-22 02:57:06 +00:00
|
|
|
if (aType >= Flush_Display) {
|
2004-10-09 01:39:21 +00:00
|
|
|
// Flushing paints, so perform the invalidates and drawing
|
|
|
|
// immediately
|
|
|
|
updateFlags = NS_VMREFRESH_IMMEDIATE;
|
2001-08-31 04:28:26 +00:00
|
|
|
}
|
2009-04-21 23:53:52 +00:00
|
|
|
else if (aType < Flush_InterruptibleLayout) {
|
2005-01-27 21:17:08 +00:00
|
|
|
// Not flushing reflows, so do deferred invalidates. This will keep us
|
|
|
|
// from possibly flushing out reflows due to invalidates being processed
|
|
|
|
// at the end of this view batch.
|
|
|
|
updateFlags = NS_VMREFRESH_DEFERRED;
|
|
|
|
}
|
2008-01-26 23:59:50 +00:00
|
|
|
batch.EndUpdateViewBatch(updateFlags);
|
2000-01-28 22:58:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-01-24 00:46:17 +00:00
|
|
|
void
|
2004-02-20 21:38:31 +00:00
|
|
|
PresShell::CharacterDataChanged(nsIDocument *aDocument,
|
|
|
|
nsIContent* aContent,
|
2006-11-03 21:51:01 +00:00
|
|
|
CharacterDataChangeInfo* aInfo)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
2005-03-25 04:27:21 +00:00
|
|
|
NS_PRECONDITION(!mIsDocumentGone, "Unexpected CharacterDataChanged");
|
2005-02-18 16:11:53 +00:00
|
|
|
NS_PRECONDITION(aDocument == mDocument, "Unexpected aDocument");
|
|
|
|
|
2009-06-28 20:04:35 +00:00
|
|
|
nsAutoCauseReflowNotifier crNotifier(this);
|
2008-03-14 23:08:57 +00:00
|
|
|
|
2006-08-17 20:58:31 +00:00
|
|
|
if (mCaret) {
|
|
|
|
// Invalidate the caret's current location before we call into the frame
|
|
|
|
// constructor. It is important to do this now, and not wait until the
|
|
|
|
// resulting reflow, because this call causes continuation frames of the
|
|
|
|
// text frame the caret is in to forget what part of the content they
|
|
|
|
// refer to, making it hard for them to return the correct continuation
|
|
|
|
// frame to the caret.
|
|
|
|
mCaret->InvalidateOutsideCaret();
|
|
|
|
}
|
2008-02-19 06:17:07 +00:00
|
|
|
|
|
|
|
// Call this here so it only happens for real content mutations and
|
|
|
|
// not cases when the frame constructor calls its own methods to force
|
|
|
|
// frame reconstruction.
|
|
|
|
nsIContent *container = aContent->GetParent();
|
|
|
|
PRUint32 selectorFlags =
|
|
|
|
container ? (container->GetFlags() & NODE_ALL_SELECTOR_FLAGS) : 0;
|
2008-07-23 04:50:20 +00:00
|
|
|
if (selectorFlags != 0 && !aContent->IsRootOfAnonymousSubtree()) {
|
2010-05-14 17:04:51 +00:00
|
|
|
Element* element = container->AsElement();
|
|
|
|
if (aInfo->mAppend && !aContent->GetNextSibling())
|
|
|
|
mFrameConstructor->RestyleForAppend(element, aContent);
|
2008-02-19 06:17:07 +00:00
|
|
|
else
|
2010-05-14 17:04:51 +00:00
|
|
|
mFrameConstructor->RestyleForInsertOrChange(element, aContent);
|
2008-02-19 06:17:07 +00:00
|
|
|
}
|
|
|
|
|
2009-08-05 01:38:10 +00:00
|
|
|
mFrameConstructor->CharacterDataChanged(aContent, aInfo);
|
1999-09-21 07:53:49 +00:00
|
|
|
VERIFY_STYLE_TREE;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
2004-01-24 00:46:17 +00:00
|
|
|
void
|
1999-04-20 00:06:58 +00:00
|
|
|
PresShell::ContentStatesChanged(nsIDocument* aDocument,
|
|
|
|
nsIContent* aContent1,
|
2002-03-07 03:34:29 +00:00
|
|
|
nsIContent* aContent2,
|
2002-04-11 03:49:30 +00:00
|
|
|
PRInt32 aStateMask)
|
1999-02-27 07:15:09 +00:00
|
|
|
{
|
2005-02-18 16:11:53 +00:00
|
|
|
NS_PRECONDITION(!mIsDocumentGone, "Unexpected ContentStatesChanged");
|
|
|
|
NS_PRECONDITION(aDocument == mDocument, "Unexpected aDocument");
|
|
|
|
|
2007-07-12 20:05:45 +00:00
|
|
|
if (mDidInitialReflow) {
|
2009-06-28 20:04:35 +00:00
|
|
|
nsAutoCauseReflowNotifier crNotifier(this);
|
2007-07-12 20:05:45 +00:00
|
|
|
mFrameConstructor->ContentStatesChanged(aContent1, aContent2, aStateMask);
|
|
|
|
VERIFY_STYLE_TREE;
|
|
|
|
}
|
1999-02-27 07:15:09 +00:00
|
|
|
}
|
|
|
|
|
2010-03-17 17:10:57 +00:00
|
|
|
void
|
|
|
|
PresShell::DocumentStatesChanged(nsIDocument* aDocument,
|
|
|
|
PRInt32 aStateMask)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(!mIsDocumentGone, "Unexpected DocumentStatesChanged");
|
|
|
|
NS_PRECONDITION(aDocument == mDocument, "Unexpected aDocument");
|
|
|
|
|
|
|
|
if (mDidInitialReflow &&
|
|
|
|
mStyleSet->HasDocumentStateDependentStyle(mPresContext,
|
2010-04-30 13:12:05 +00:00
|
|
|
mDocument->GetRootElement(),
|
2010-03-17 17:10:57 +00:00
|
|
|
aStateMask)) {
|
2010-04-30 13:12:05 +00:00
|
|
|
mFrameConstructor->PostRestyleEvent(mDocument->GetRootElement(),
|
2010-04-01 00:43:32 +00:00
|
|
|
eRestyle_Self, NS_STYLE_HINT_NONE);
|
2010-03-17 17:10:57 +00:00
|
|
|
VERIFY_STYLE_TREE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-10 22:36:03 +00:00
|
|
|
void
|
|
|
|
PresShell::AttributeWillChange(nsIDocument* aDocument,
|
|
|
|
nsIContent* aContent,
|
|
|
|
PRInt32 aNameSpaceID,
|
|
|
|
nsIAtom* aAttribute,
|
|
|
|
PRInt32 aModType)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(!mIsDocumentGone, "Unexpected AttributeChanged");
|
|
|
|
NS_PRECONDITION(aDocument == mDocument, "Unexpected aDocument");
|
|
|
|
|
|
|
|
// XXXwaterson it might be more elegant to wait until after the
|
|
|
|
// initial reflow to begin observing the document. That would
|
|
|
|
// squelch any other inappropriate notifications as well.
|
|
|
|
if (mDidInitialReflow) {
|
|
|
|
nsAutoCauseReflowNotifier crNotifier(this);
|
|
|
|
mFrameConstructor->AttributeWillChange(aContent, aNameSpaceID,
|
|
|
|
aAttribute, aModType);
|
|
|
|
VERIFY_STYLE_TREE;
|
|
|
|
}
|
|
|
|
}
|
1999-02-27 07:15:09 +00:00
|
|
|
|
2004-01-24 00:46:17 +00:00
|
|
|
void
|
2005-11-02 00:41:51 +00:00
|
|
|
PresShell::AttributeChanged(nsIDocument* aDocument,
|
|
|
|
nsIContent* aContent,
|
|
|
|
PRInt32 aNameSpaceID,
|
|
|
|
nsIAtom* aAttribute,
|
2009-12-10 22:36:04 +00:00
|
|
|
PRInt32 aModType)
|
1998-09-18 19:53:27 +00:00
|
|
|
{
|
2005-03-25 04:27:21 +00:00
|
|
|
NS_PRECONDITION(!mIsDocumentGone, "Unexpected AttributeChanged");
|
2005-02-18 16:11:53 +00:00
|
|
|
NS_PRECONDITION(aDocument == mDocument, "Unexpected aDocument");
|
|
|
|
|
2001-10-17 05:34:35 +00:00
|
|
|
// XXXwaterson it might be more elegant to wait until after the
|
|
|
|
// initial reflow to begin observing the document. That would
|
|
|
|
// squelch any other inappropriate notifications as well.
|
|
|
|
if (mDidInitialReflow) {
|
2009-06-28 20:04:35 +00:00
|
|
|
nsAutoCauseReflowNotifier crNotifier(this);
|
2005-02-18 16:11:53 +00:00
|
|
|
mFrameConstructor->AttributeChanged(aContent, aNameSpaceID,
|
2009-12-10 22:36:04 +00:00
|
|
|
aAttribute, aModType);
|
2001-10-17 05:34:35 +00:00
|
|
|
VERIFY_STYLE_TREE;
|
|
|
|
}
|
1998-09-18 19:53:27 +00:00
|
|
|
}
|
|
|
|
|
2004-01-24 00:46:17 +00:00
|
|
|
void
|
1998-07-22 23:32:19 +00:00
|
|
|
PresShell::ContentAppended(nsIDocument *aDocument,
|
1998-09-10 19:32:14 +00:00
|
|
|
nsIContent* aContainer,
|
2010-05-11 01:12:34 +00:00
|
|
|
nsIContent* aFirstNewContent,
|
1998-09-10 19:32:14 +00:00
|
|
|
PRInt32 aNewIndexInContainer)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
2005-02-18 16:11:53 +00:00
|
|
|
NS_PRECONDITION(!mIsDocumentGone, "Unexpected ContentAppended");
|
|
|
|
NS_PRECONDITION(aDocument == mDocument, "Unexpected aDocument");
|
2008-02-19 06:17:07 +00:00
|
|
|
NS_PRECONDITION(aContainer, "must have container");
|
2005-02-18 16:11:53 +00:00
|
|
|
|
2003-10-11 00:27:45 +00:00
|
|
|
if (!mDidInitialReflow) {
|
2004-01-24 00:46:17 +00:00
|
|
|
return;
|
2003-10-11 00:27:45 +00:00
|
|
|
}
|
|
|
|
|
2009-06-28 20:04:35 +00:00
|
|
|
nsAutoCauseReflowNotifier crNotifier(this);
|
2001-05-01 22:54:11 +00:00
|
|
|
|
2008-02-19 06:17:07 +00:00
|
|
|
// Call this here so it only happens for real content mutations and
|
|
|
|
// not cases when the frame constructor calls its own methods to force
|
|
|
|
// frame reconstruction.
|
2010-05-14 17:04:51 +00:00
|
|
|
mFrameConstructor->RestyleForAppend(aContainer->AsElement(), aFirstNewContent);
|
2008-02-19 06:17:07 +00:00
|
|
|
|
2010-05-11 01:12:34 +00:00
|
|
|
mFrameConstructor->ContentAppended(aContainer, aFirstNewContent,
|
|
|
|
aNewIndexInContainer, PR_TRUE);
|
1999-09-21 07:53:49 +00:00
|
|
|
VERIFY_STYLE_TREE;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
2004-01-24 00:46:17 +00:00
|
|
|
void
|
1998-09-10 19:32:14 +00:00
|
|
|
PresShell::ContentInserted(nsIDocument* aDocument,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
nsIContent* aChild,
|
|
|
|
PRInt32 aIndexInContainer)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
2005-03-25 04:27:21 +00:00
|
|
|
NS_PRECONDITION(!mIsDocumentGone, "Unexpected ContentInserted");
|
2005-02-18 16:11:53 +00:00
|
|
|
NS_PRECONDITION(aDocument == mDocument, "Unexpected aDocument");
|
|
|
|
|
2003-10-11 00:27:45 +00:00
|
|
|
if (!mDidInitialReflow) {
|
2004-01-24 00:46:17 +00:00
|
|
|
return;
|
2003-10-11 00:27:45 +00:00
|
|
|
}
|
|
|
|
|
2009-06-28 20:04:35 +00:00
|
|
|
nsAutoCauseReflowNotifier crNotifier(this);
|
2008-02-19 06:17:07 +00:00
|
|
|
|
|
|
|
// Call this here so it only happens for real content mutations and
|
|
|
|
// not cases when the frame constructor calls its own methods to force
|
|
|
|
// frame reconstruction.
|
|
|
|
if (aContainer)
|
2010-05-14 17:04:51 +00:00
|
|
|
mFrameConstructor->RestyleForInsertOrChange(aContainer->AsElement(), aChild);
|
2008-02-19 06:17:07 +00:00
|
|
|
|
2005-08-16 21:35:58 +00:00
|
|
|
mFrameConstructor->ContentInserted(aContainer, aChild,
|
2010-01-18 09:26:40 +00:00
|
|
|
aIndexInContainer, nsnull, PR_TRUE);
|
1999-09-21 07:53:49 +00:00
|
|
|
VERIFY_STYLE_TREE;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
2004-01-24 00:46:17 +00:00
|
|
|
void
|
1998-09-24 21:39:47 +00:00
|
|
|
PresShell::ContentRemoved(nsIDocument *aDocument,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
nsIContent* aChild,
|
|
|
|
PRInt32 aIndexInContainer)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
2005-03-25 04:27:21 +00:00
|
|
|
NS_PRECONDITION(!mIsDocumentGone, "Unexpected ContentRemoved");
|
2005-02-18 16:11:53 +00:00
|
|
|
NS_PRECONDITION(aDocument == mDocument, "Unexpected aDocument");
|
|
|
|
|
2006-04-17 23:16:46 +00:00
|
|
|
// Make sure that the caret doesn't leave a turd where the child used to be.
|
2005-08-22 00:25:20 +00:00
|
|
|
if (mCaret) {
|
2006-04-28 04:33:41 +00:00
|
|
|
mCaret->InvalidateOutsideCaret();
|
2005-08-22 00:25:20 +00:00
|
|
|
}
|
|
|
|
|
2001-11-29 00:04:31 +00:00
|
|
|
// Notify the ESM that the content has been removed, so that
|
|
|
|
// it can clean up any state related to the content.
|
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 18:00:39 +00:00
|
|
|
mPresContext->EventStateManager()->ContentRemoved(aDocument, aChild);
|
2001-11-29 00:04:31 +00:00
|
|
|
|
2009-06-28 20:04:35 +00:00
|
|
|
nsAutoCauseReflowNotifier crNotifier(this);
|
2008-02-19 06:17:07 +00:00
|
|
|
|
|
|
|
// Call this here so it only happens for real content mutations and
|
|
|
|
// not cases when the frame constructor calls its own methods to force
|
|
|
|
// frame reconstruction.
|
|
|
|
if (aContainer)
|
2010-05-14 17:04:51 +00:00
|
|
|
mFrameConstructor->RestyleForRemove(aContainer->AsElement(), aChild,
|
|
|
|
aContainer->GetChildAt(aIndexInContainer));
|
2008-02-19 06:17:07 +00:00
|
|
|
|
2007-11-08 04:39:02 +00:00
|
|
|
PRBool didReconstruct;
|
2009-06-13 09:16:34 +00:00
|
|
|
mFrameConstructor->ContentRemoved(aContainer, aChild, aIndexInContainer,
|
|
|
|
nsCSSFrameConstructor::REMOVE_CONTENT,
|
|
|
|
&didReconstruct);
|
2002-09-10 04:36:00 +00:00
|
|
|
|
1999-09-21 07:53:49 +00:00
|
|
|
VERIFY_STYLE_TREE;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1998-11-26 01:34:53 +00:00
|
|
|
nsresult
|
|
|
|
PresShell::ReconstructFrames(void)
|
1998-11-17 02:14:38 +00:00
|
|
|
{
|
2009-12-23 00:09:10 +00:00
|
|
|
nsCOMPtr<nsIPresShell> kungFuDeathGrip(this);
|
|
|
|
|
|
|
|
// Have to make sure that the content notifications are flushed before we
|
|
|
|
// start messing with the frame model; otherwise we can get content doubling.
|
|
|
|
mDocument->FlushPendingNotifications(Flush_ContentAndNotify);
|
|
|
|
|
2009-06-28 20:04:35 +00:00
|
|
|
nsAutoCauseReflowNotifier crNotifier(this);
|
2008-07-11 21:15:11 +00:00
|
|
|
mFrameConstructor->BeginUpdate();
|
2008-03-14 23:08:57 +00:00
|
|
|
nsresult rv = mFrameConstructor->ReconstructDocElementHierarchy();
|
1999-09-21 07:53:49 +00:00
|
|
|
VERIFY_STYLE_TREE;
|
2008-07-11 21:15:11 +00:00
|
|
|
mFrameConstructor->EndUpdate();
|
1999-03-01 16:57:35 +00:00
|
|
|
|
1998-11-17 02:14:38 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2004-08-29 03:08:44 +00:00
|
|
|
void
|
|
|
|
nsIPresShell::ReconstructStyleDataInternal()
|
2001-12-17 22:51:39 +00:00
|
|
|
{
|
2004-01-07 22:30:53 +00:00
|
|
|
mStylesHaveChanged = PR_FALSE;
|
|
|
|
|
2008-11-25 23:08:51 +00:00
|
|
|
if (mIsDestroying) {
|
|
|
|
// We don't want to mess with restyles at this point
|
2008-11-25 21:27:54 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-11-25 23:22:38 +00:00
|
|
|
if (mPresContext) {
|
|
|
|
mPresContext->RebuildUserFontSet();
|
|
|
|
}
|
|
|
|
|
2010-04-30 13:12:05 +00:00
|
|
|
Element* root = mDocument->GetRootElement();
|
2008-11-25 23:22:38 +00:00
|
|
|
if (!mDidInitialReflow) {
|
|
|
|
// Nothing to do here, since we have no frames yet
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-11-06 18:01:17 +00:00
|
|
|
if (!root) {
|
|
|
|
// No content to restyle
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-04-01 00:43:32 +00:00
|
|
|
mFrameConstructor->PostRestyleEvent(root, eRestyle_Self, NS_STYLE_HINT_NONE);
|
2005-06-10 13:57:27 +00:00
|
|
|
|
|
|
|
#ifdef ACCESSIBILITY
|
|
|
|
InvalidateAccessibleSubtree(nsnull);
|
|
|
|
#endif
|
2004-08-29 03:08:44 +00:00
|
|
|
}
|
2004-01-24 00:46:17 +00:00
|
|
|
|
2004-08-29 03:08:44 +00:00
|
|
|
void
|
|
|
|
nsIPresShell::ReconstructStyleDataExternal()
|
|
|
|
{
|
|
|
|
ReconstructStyleDataInternal();
|
2001-12-17 22:51:39 +00:00
|
|
|
}
|
|
|
|
|
2004-01-24 00:46:17 +00:00
|
|
|
void
|
1998-11-26 01:34:53 +00:00
|
|
|
PresShell::StyleSheetAdded(nsIDocument *aDocument,
|
2004-07-28 07:08:41 +00:00
|
|
|
nsIStyleSheet* aStyleSheet,
|
|
|
|
PRBool aDocumentSheet)
|
1998-11-26 01:34:53 +00:00
|
|
|
{
|
2002-12-03 05:48:14 +00:00
|
|
|
// We only care when enabled sheets are added
|
|
|
|
NS_PRECONDITION(aStyleSheet, "Must have a style sheet!");
|
|
|
|
|
2010-05-14 19:05:14 +00:00
|
|
|
if (aStyleSheet->IsApplicable() && aStyleSheet->HasRules()) {
|
2003-10-02 21:29:40 +00:00
|
|
|
mStylesHaveChanged = PR_TRUE;
|
2003-07-04 01:44:24 +00:00
|
|
|
}
|
1998-11-26 01:34:53 +00:00
|
|
|
}
|
|
|
|
|
2004-01-24 00:46:17 +00:00
|
|
|
void
|
1999-02-03 19:38:16 +00:00
|
|
|
PresShell::StyleSheetRemoved(nsIDocument *aDocument,
|
2004-07-28 07:08:41 +00:00
|
|
|
nsIStyleSheet* aStyleSheet,
|
|
|
|
PRBool aDocumentSheet)
|
1999-02-03 19:38:16 +00:00
|
|
|
{
|
2002-12-03 05:48:14 +00:00
|
|
|
// We only care when enabled sheets are removed
|
|
|
|
NS_PRECONDITION(aStyleSheet, "Must have a style sheet!");
|
2010-05-12 20:18:47 +00:00
|
|
|
|
2010-05-14 19:05:14 +00:00
|
|
|
if (aStyleSheet->IsApplicable() && aStyleSheet->HasRules()) {
|
2003-10-02 21:29:40 +00:00
|
|
|
mStylesHaveChanged = PR_TRUE;
|
2002-12-03 05:48:14 +00:00
|
|
|
}
|
1999-02-03 19:38:16 +00:00
|
|
|
}
|
|
|
|
|
2004-01-24 00:46:17 +00:00
|
|
|
void
|
2002-12-03 05:48:14 +00:00
|
|
|
PresShell::StyleSheetApplicableStateChanged(nsIDocument *aDocument,
|
|
|
|
nsIStyleSheet* aStyleSheet,
|
|
|
|
PRBool aApplicable)
|
1998-11-26 01:34:53 +00:00
|
|
|
{
|
2003-10-02 21:29:40 +00:00
|
|
|
if (aStyleSheet->HasRules()) {
|
|
|
|
mStylesHaveChanged = PR_TRUE;
|
2003-07-04 01:44:24 +00:00
|
|
|
}
|
1998-11-26 01:34:53 +00:00
|
|
|
}
|
|
|
|
|
2004-01-24 00:46:17 +00:00
|
|
|
void
|
1998-11-26 01:34:53 +00:00
|
|
|
PresShell::StyleRuleChanged(nsIDocument *aDocument,
|
|
|
|
nsIStyleSheet* aStyleSheet,
|
2003-06-18 01:59:57 +00:00
|
|
|
nsIStyleRule* aOldStyleRule,
|
|
|
|
nsIStyleRule* aNewStyleRule)
|
1998-11-26 01:34:53 +00:00
|
|
|
{
|
2003-10-02 21:29:40 +00:00
|
|
|
mStylesHaveChanged = PR_TRUE;
|
1998-11-26 01:34:53 +00:00
|
|
|
}
|
|
|
|
|
2004-01-24 00:46:17 +00:00
|
|
|
void
|
1998-11-26 01:34:53 +00:00
|
|
|
PresShell::StyleRuleAdded(nsIDocument *aDocument,
|
|
|
|
nsIStyleSheet* aStyleSheet,
|
|
|
|
nsIStyleRule* aStyleRule)
|
2003-10-02 21:29:40 +00:00
|
|
|
{
|
|
|
|
mStylesHaveChanged = PR_TRUE;
|
1998-11-26 01:34:53 +00:00
|
|
|
}
|
|
|
|
|
2004-01-24 00:46:17 +00:00
|
|
|
void
|
1998-11-26 01:34:53 +00:00
|
|
|
PresShell::StyleRuleRemoved(nsIDocument *aDocument,
|
|
|
|
nsIStyleSheet* aStyleSheet,
|
|
|
|
nsIStyleRule* aStyleRule)
|
2003-10-02 21:29:40 +00:00
|
|
|
{
|
|
|
|
mStylesHaveChanged = PR_TRUE;
|
1998-11-26 01:34:53 +00:00
|
|
|
}
|
|
|
|
|
2008-01-30 04:17:57 +00:00
|
|
|
nsIFrame*
|
|
|
|
PresShell::GetRealPrimaryFrameFor(nsIContent* aContent) const
|
|
|
|
{
|
2009-12-24 21:20:06 +00:00
|
|
|
if (aContent->GetDocument() != GetDocument()) {
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
nsIFrame *primaryFrame = aContent->GetPrimaryFrame();
|
2008-01-30 04:17:57 +00:00
|
|
|
if (!primaryFrame)
|
|
|
|
return nsnull;
|
|
|
|
return nsPlaceholderFrame::GetRealFrameFor(primaryFrame);
|
|
|
|
}
|
|
|
|
|
2010-03-20 21:54:19 +00:00
|
|
|
nsIFrame*
|
|
|
|
PresShell::GetPlaceholderFrameFor(nsIFrame* aFrame) const
|
1998-12-29 03:38:16 +00:00
|
|
|
{
|
2010-03-20 21:54:19 +00:00
|
|
|
return FrameManager()->GetPlaceholderFrameFor(aFrame);
|
1998-12-29 03:38:16 +00:00
|
|
|
}
|
2001-12-06 05:45:07 +00:00
|
|
|
|
1998-08-28 02:54:06 +00:00
|
|
|
//nsIViewObserver
|
|
|
|
|
2006-01-26 02:29:17 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
PresShell::ComputeRepaintRegionForCopy(nsIView* aRootView,
|
|
|
|
nsIView* aMovingView,
|
|
|
|
nsPoint aDelta,
|
2009-08-14 02:09:51 +00:00
|
|
|
const nsRect& aUpdateRect,
|
|
|
|
nsRegion* aBlitRegion,
|
2006-01-26 02:29:17 +00:00
|
|
|
nsRegion* aRepaintRegion)
|
|
|
|
{
|
|
|
|
return nsLayoutUtils::ComputeRepaintRegionForCopy(
|
2007-07-08 07:08:04 +00:00
|
|
|
static_cast<nsIFrame*>(aRootView->GetClientData()),
|
|
|
|
static_cast<nsIFrame*>(aMovingView->GetClientData()),
|
2009-08-14 02:09:51 +00:00
|
|
|
aDelta, aUpdateRect, aBlitRegion, aRepaintRegion);
|
2006-01-26 02:29:17 +00:00
|
|
|
}
|
2000-04-25 04:43:11 +00:00
|
|
|
|
2009-10-31 19:44:57 +00:00
|
|
|
/*
|
|
|
|
* Fill with background color and set up paint operator for an arbitrary gfxContext
|
|
|
|
*
|
|
|
|
* @param aFillRegion clip region for background filling
|
|
|
|
* partial clipping is not implemented yet,
|
|
|
|
* nsnull or IsEmpty - then whole aRect painted
|
|
|
|
*/
|
|
|
|
static inline PRBool
|
|
|
|
PrepareContext(const nsRect& aRect, nscolor aBackgroundColor,
|
|
|
|
gfxContext* aThebesContext, nsRegion *aFillRegion = nsnull)
|
2006-01-26 02:29:17 +00:00
|
|
|
{
|
2010-05-19 23:22:19 +00:00
|
|
|
NS_TIME_FUNCTION_MIN(1.0);
|
|
|
|
|
2007-11-08 04:43:36 +00:00
|
|
|
gfxRect r(0, 0,
|
|
|
|
nsPresContext::AppUnitsToFloatCSSPixels(aRect.width),
|
|
|
|
nsPresContext::AppUnitsToFloatCSSPixels(aRect.height));
|
|
|
|
aThebesContext->Save();
|
|
|
|
|
2008-10-09 21:49:15 +00:00
|
|
|
aThebesContext->NewPath();
|
2008-10-10 22:30:52 +00:00
|
|
|
#ifdef MOZ_GFX_OPTIMIZE_MOBILE
|
2008-10-09 21:49:15 +00:00
|
|
|
aThebesContext->Rectangle(r, PR_TRUE);
|
|
|
|
#else
|
|
|
|
aThebesContext->Rectangle(r);
|
|
|
|
#endif
|
|
|
|
aThebesContext->Clip();
|
2006-01-26 02:29:17 +00:00
|
|
|
|
2008-10-09 21:49:15 +00:00
|
|
|
// we can avoid using a temporary surface if we're using OPERATOR_OVER
|
|
|
|
// and our background color has no alpha (so we'll be compositing on top
|
|
|
|
// of a fully opaque solid color region)
|
|
|
|
PRBool needsGroup = PR_TRUE;
|
|
|
|
if (aThebesContext->CurrentOperator() == gfxContext::OPERATOR_OVER &&
|
|
|
|
NS_GET_A(aBackgroundColor) == 0xff)
|
|
|
|
needsGroup = PR_FALSE;
|
|
|
|
|
|
|
|
if (needsGroup) {
|
|
|
|
aThebesContext->PushGroup(NS_GET_A(aBackgroundColor) == 0xff ?
|
|
|
|
gfxASurface::CONTENT_COLOR :
|
|
|
|
gfxASurface::CONTENT_COLOR_ALPHA);
|
|
|
|
|
|
|
|
aThebesContext->Save();
|
|
|
|
}
|
2006-01-26 02:29:17 +00:00
|
|
|
|
2007-05-23 00:11:05 +00:00
|
|
|
// draw background color
|
2009-10-31 19:44:57 +00:00
|
|
|
if (NS_GET_A(aBackgroundColor) > 0 &&
|
|
|
|
!(aFillRegion && aFillRegion->IsEmpty())) {
|
2007-05-23 00:11:05 +00:00
|
|
|
aThebesContext->SetColor(gfxRGBA(aBackgroundColor));
|
|
|
|
aThebesContext->SetOperator(gfxContext::OPERATOR_SOURCE);
|
|
|
|
aThebesContext->Paint();
|
2002-03-07 07:03:03 +00:00
|
|
|
}
|
|
|
|
|
2009-10-31 19:44:57 +00:00
|
|
|
aThebesContext->SetOperator(gfxContext::OPERATOR_OVER);
|
|
|
|
return needsGroup;
|
|
|
|
}
|
|
|
|
|
2010-03-31 12:45:32 +00:00
|
|
|
nsresult
|
2009-10-31 19:44:57 +00:00
|
|
|
PresShell::RenderDocument(const nsRect& aRect, PRUint32 aFlags,
|
|
|
|
nscolor aBackgroundColor,
|
|
|
|
gfxContext* aThebesContext)
|
|
|
|
{
|
2010-05-19 23:22:19 +00:00
|
|
|
NS_TIME_FUNCTION_WITH_DOCURL;
|
|
|
|
|
2009-10-31 19:44:57 +00:00
|
|
|
NS_ENSURE_TRUE(!(aFlags & RENDER_IS_UNTRUSTED), NS_ERROR_NOT_IMPLEMENTED);
|
|
|
|
|
2007-05-23 00:11:05 +00:00
|
|
|
// we want the window to be composited as a single image using
|
2008-10-09 21:49:15 +00:00
|
|
|
// whatever operator was set; set OPERATOR_OVER here, which is
|
|
|
|
// either already the case, or overrides the operator in a group.
|
|
|
|
// the original operator will be present when we PopGroup.
|
2002-03-07 07:03:03 +00:00
|
|
|
|
2009-10-31 19:44:57 +00:00
|
|
|
PRBool needsGroup = PR_TRUE;
|
|
|
|
PRBool didPrepareContext = PR_FALSE;
|
2006-01-26 02:29:17 +00:00
|
|
|
nsIFrame* rootFrame = FrameManager()->GetRootFrame();
|
2007-05-23 00:11:05 +00:00
|
|
|
if (rootFrame) {
|
2008-12-12 10:50:31 +00:00
|
|
|
nsDisplayListBuilder builder(rootFrame, PR_FALSE,
|
|
|
|
(aFlags & RENDER_CARET) != 0);
|
2007-05-23 00:11:05 +00:00
|
|
|
nsDisplayList list;
|
|
|
|
|
2009-09-19 10:20:42 +00:00
|
|
|
nsRect canvasArea(
|
|
|
|
builder.ToReferenceFrame(rootFrame), rootFrame->GetSize());
|
|
|
|
|
2007-05-23 00:11:05 +00:00
|
|
|
nsRect rect(aRect);
|
|
|
|
nsIFrame* rootScrollFrame = GetRootScrollFrame();
|
2008-12-12 10:50:31 +00:00
|
|
|
if ((aFlags & RENDER_IGNORE_VIEWPORT_SCROLLING) && rootScrollFrame) {
|
2009-09-19 10:20:42 +00:00
|
|
|
nsIScrollableFrame* rootScrollableFrame =
|
|
|
|
GetRootScrollFrameAsScrollable();
|
|
|
|
nsPoint pos = rootScrollableFrame->GetScrollPosition();
|
2007-05-23 00:11:05 +00:00
|
|
|
rect.MoveBy(-pos);
|
|
|
|
builder.SetIgnoreScrollFrame(rootScrollFrame);
|
2009-09-19 10:20:42 +00:00
|
|
|
|
2009-10-08 06:18:18 +00:00
|
|
|
nsCanvasFrame* canvasFrame =
|
2009-09-19 10:20:42 +00:00
|
|
|
do_QueryFrame(rootScrollableFrame->GetScrolledFrame());
|
|
|
|
if (canvasFrame) {
|
2009-09-29 01:40:24 +00:00
|
|
|
canvasArea =
|
|
|
|
canvasFrame->CanvasArea() + builder.ToReferenceFrame(canvasFrame);
|
2009-09-19 10:20:42 +00:00
|
|
|
}
|
2007-05-23 00:11:05 +00:00
|
|
|
}
|
2000-04-25 04:43:11 +00:00
|
|
|
|
2008-08-18 19:09:17 +00:00
|
|
|
builder.SetBackgroundOnly(PR_FALSE);
|
2009-09-12 22:44:18 +00:00
|
|
|
builder.SetSyncDecodeImages(PR_TRUE);
|
2007-05-23 00:11:05 +00:00
|
|
|
builder.EnterPresShell(rootFrame, rect);
|
2006-04-17 23:16:46 +00:00
|
|
|
|
2009-07-04 09:30:59 +00:00
|
|
|
// Add the canvas background color.
|
|
|
|
nsresult rv =
|
|
|
|
rootFrame->PresContext()->PresShell()->AddCanvasBackgroundColorItem(
|
2009-09-19 10:20:42 +00:00
|
|
|
builder, list, rootFrame, &canvasArea);
|
2009-07-04 09:30:59 +00:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
rv = rootFrame->BuildDisplayListForStackingContext(&builder, rect, &list);
|
|
|
|
}
|
2006-04-17 23:16:46 +00:00
|
|
|
|
2007-05-23 00:11:05 +00:00
|
|
|
builder.LeavePresShell(rootFrame, rect);
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2009-10-31 19:44:57 +00:00
|
|
|
nsRegion region(rect);
|
|
|
|
list.ComputeVisibility(&builder, ®ion, nsnull);
|
|
|
|
|
|
|
|
didPrepareContext = PR_TRUE;
|
|
|
|
needsGroup = PrepareContext(aRect, aBackgroundColor, aThebesContext, ®ion);
|
|
|
|
|
2007-05-23 00:11:05 +00:00
|
|
|
// Ensure that r.x,r.y gets drawn at (0,0)
|
|
|
|
aThebesContext->Save();
|
2007-11-08 04:43:36 +00:00
|
|
|
aThebesContext->Translate(gfxPoint(-nsPresContext::AppUnitsToFloatCSSPixels(rect.x),
|
|
|
|
-nsPresContext::AppUnitsToFloatCSSPixels(rect.y)));
|
2007-05-23 00:11:05 +00:00
|
|
|
|
|
|
|
nsIDeviceContext* devCtx = mPresContext->DeviceContext();
|
2007-11-08 04:43:36 +00:00
|
|
|
gfxFloat scale = gfxFloat(devCtx->AppUnitsPerDevPixel())/nsPresContext::AppUnitsPerCSSPixel();
|
|
|
|
aThebesContext->Scale(scale, scale);
|
|
|
|
|
2007-05-23 00:11:05 +00:00
|
|
|
nsCOMPtr<nsIRenderingContext> rc;
|
|
|
|
devCtx->CreateRenderingContextInstance(*getter_AddRefs(rc));
|
|
|
|
rc->Init(devCtx, aThebesContext);
|
2000-04-25 04:43:11 +00:00
|
|
|
|
2010-03-01 08:03:49 +00:00
|
|
|
PRUint32 flags = nsDisplayList::PAINT_DEFAULT;
|
|
|
|
if (aFlags & RENDER_USE_WIDGET_LAYERS) {
|
|
|
|
flags |= nsDisplayList::PAINT_USE_WIDGET_LAYERS;
|
|
|
|
}
|
2010-03-10 20:55:05 +00:00
|
|
|
list.PaintRoot(&builder, rc, flags);
|
2007-05-23 00:11:05 +00:00
|
|
|
// Flush the list so we don't trigger the IsEmpty-on-destruction assertion
|
|
|
|
list.DeleteAll();
|
|
|
|
|
|
|
|
aThebesContext->Restore();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-31 19:44:57 +00:00
|
|
|
if (!didPrepareContext)
|
|
|
|
needsGroup = PrepareContext(aRect, aBackgroundColor, aThebesContext, nsnull);
|
|
|
|
|
2008-10-09 21:49:15 +00:00
|
|
|
// if we had to use a group, paint it to the destination now
|
|
|
|
if (needsGroup) {
|
|
|
|
aThebesContext->Restore();
|
|
|
|
aThebesContext->PopGroupToSource();
|
|
|
|
aThebesContext->Paint();
|
|
|
|
}
|
2002-03-07 07:03:03 +00:00
|
|
|
|
2007-11-08 04:43:36 +00:00
|
|
|
aThebesContext->Restore();
|
|
|
|
|
2006-01-26 02:29:17 +00:00
|
|
|
return NS_OK;
|
2002-03-07 07:03:03 +00:00
|
|
|
}
|
|
|
|
|
2007-03-20 12:14:52 +00:00
|
|
|
/*
|
|
|
|
* Clip the display list aList to a range. Returns the clipped
|
|
|
|
* rectangle surrounding the range.
|
|
|
|
*/
|
|
|
|
nsRect
|
|
|
|
PresShell::ClipListToRange(nsDisplayListBuilder *aBuilder,
|
|
|
|
nsDisplayList* aList,
|
2007-08-17 03:43:00 +00:00
|
|
|
nsIRange* aRange)
|
2007-03-20 12:14:52 +00:00
|
|
|
{
|
2010-05-19 23:22:19 +00:00
|
|
|
NS_TIME_FUNCTION_WITH_DOCURL;
|
|
|
|
|
2007-03-20 12:14:52 +00:00
|
|
|
// iterate though the display items and add up the bounding boxes of each.
|
|
|
|
// This will allow the total area of the frames within the range to be
|
|
|
|
// determined. To do this, remove an item from the bottom of the list, check
|
|
|
|
// whether it should be part of the range, and if so, append it to the top
|
|
|
|
// of the temporary list tmpList. If the item is a text frame at the end of
|
|
|
|
// the selection range, wrap it in an nsDisplayClip to clip the display to
|
|
|
|
// the portion of the text frame that is part of the selection. Then, append
|
|
|
|
// the wrapper to the top of the list. Otherwise, just delete the item and
|
|
|
|
// don't append it.
|
|
|
|
nsRect surfaceRect;
|
|
|
|
nsDisplayList tmpList;
|
|
|
|
|
|
|
|
nsDisplayItem* i;
|
|
|
|
while ((i = aList->RemoveBottom())) {
|
|
|
|
// itemToInsert indiciates the item that should be inserted into the
|
|
|
|
// temporary list. If null, no item should be inserted.
|
|
|
|
nsDisplayItem* itemToInsert = nsnull;
|
|
|
|
nsIFrame* frame = i->GetUnderlyingFrame();
|
|
|
|
if (frame) {
|
|
|
|
nsIContent* content = frame->GetContent();
|
|
|
|
if (content) {
|
|
|
|
PRBool atStart = (content == aRange->GetStartParent());
|
|
|
|
PRBool atEnd = (content == aRange->GetEndParent());
|
|
|
|
if ((atStart || atEnd) && frame->GetType() == nsGkAtoms::textFrame) {
|
|
|
|
PRInt32 frameStartOffset, frameEndOffset;
|
|
|
|
frame->GetOffsets(frameStartOffset, frameEndOffset);
|
|
|
|
|
|
|
|
PRInt32 hilightStart =
|
2009-09-16 15:01:36 +00:00
|
|
|
atStart ? NS_MAX(aRange->StartOffset(), frameStartOffset) : frameStartOffset;
|
2007-03-20 12:14:52 +00:00
|
|
|
PRInt32 hilightEnd =
|
2009-09-16 15:01:36 +00:00
|
|
|
atEnd ? NS_MIN(aRange->EndOffset(), frameEndOffset) : frameEndOffset;
|
2007-03-20 12:14:52 +00:00
|
|
|
if (hilightStart < hilightEnd) {
|
|
|
|
// determine the location of the start and end edges of the range.
|
|
|
|
nsPoint startPoint, endPoint;
|
2007-08-17 03:43:00 +00:00
|
|
|
frame->GetPointFromOffset(hilightStart, &startPoint);
|
|
|
|
frame->GetPointFromOffset(hilightEnd, &endPoint);
|
2007-03-20 12:14:52 +00:00
|
|
|
|
|
|
|
// the clip rectangle is determined by taking the the start and
|
|
|
|
// end points of the range, offset from the reference frame.
|
|
|
|
// Because of rtl, the end point may be to the left of the
|
|
|
|
// start point, so x is set to the lowest value
|
|
|
|
nsRect textRect(aBuilder->ToReferenceFrame(frame), frame->GetSize());
|
2009-09-16 15:01:36 +00:00
|
|
|
nscoord x = NS_MIN(startPoint.x, endPoint.x);
|
2007-03-20 12:14:52 +00:00
|
|
|
textRect.x += x;
|
2009-09-16 15:01:36 +00:00
|
|
|
textRect.width = NS_MAX(startPoint.x, endPoint.x) - x;
|
2007-03-20 12:14:52 +00:00
|
|
|
surfaceRect.UnionRect(surfaceRect, textRect);
|
|
|
|
|
|
|
|
// wrap the item in an nsDisplayClip so that it can be clipped to
|
|
|
|
// the selection. If the allocation fails, fall through and delete
|
|
|
|
// the item below.
|
2008-04-18 09:21:21 +00:00
|
|
|
itemToInsert = new (aBuilder)nsDisplayClip(frame, frame, i, textRect);
|
2007-03-20 12:14:52 +00:00
|
|
|
}
|
|
|
|
}
|
2010-06-05 20:29:49 +00:00
|
|
|
// Don't try to descend into subdocuments.
|
|
|
|
// If this ever changes we'd need to add handling for subdocuments with
|
|
|
|
// different zoom levels.
|
|
|
|
else if (content->GetCurrentDoc() ==
|
|
|
|
aRange->GetStartParent()->GetCurrentDoc()) {
|
2007-03-20 12:14:52 +00:00
|
|
|
// if the node is within the range, append it to the temporary list
|
|
|
|
PRBool before, after;
|
2010-06-05 20:29:49 +00:00
|
|
|
nsresult rv =
|
|
|
|
nsRange::CompareNodeToRange(content, aRange, &before, &after);
|
|
|
|
if (NS_SUCCEEDED(rv) && !before && !after) {
|
2007-03-20 12:14:52 +00:00
|
|
|
itemToInsert = i;
|
|
|
|
surfaceRect.UnionRect(surfaceRect, i->GetBounds(aBuilder));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// insert the item into the list if necessary. If the item has a child
|
|
|
|
// list, insert that as well
|
|
|
|
nsDisplayList* sublist = i->GetList();
|
|
|
|
if (itemToInsert || sublist) {
|
|
|
|
tmpList.AppendToTop(itemToInsert ? itemToInsert : i);
|
|
|
|
// if the item is a list, iterate over it as well
|
|
|
|
if (sublist)
|
|
|
|
surfaceRect.UnionRect(surfaceRect,
|
2007-08-17 03:43:00 +00:00
|
|
|
ClipListToRange(aBuilder, sublist, aRange));
|
2007-03-20 12:14:52 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// otherwise, just delete the item and don't readd it to the list
|
|
|
|
i->~nsDisplayItem();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// now add all the items back onto the original list again
|
|
|
|
aList->AppendToTop(&tmpList);
|
|
|
|
|
|
|
|
return surfaceRect;
|
|
|
|
}
|
|
|
|
|
2010-06-05 20:29:49 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
static PRBool gDumpRangePaintList = PR_FALSE;
|
|
|
|
#endif
|
|
|
|
|
2007-03-20 12:14:52 +00:00
|
|
|
RangePaintInfo*
|
|
|
|
PresShell::CreateRangePaintInfo(nsIDOMRange* aRange,
|
|
|
|
nsRect& aSurfaceRect)
|
|
|
|
{
|
2010-05-19 23:22:19 +00:00
|
|
|
NS_TIME_FUNCTION_WITH_DOCURL;
|
|
|
|
|
2007-03-20 12:14:52 +00:00
|
|
|
RangePaintInfo* info = nsnull;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIRange> range = do_QueryInterface(aRange);
|
|
|
|
if (!range)
|
|
|
|
return nsnull;
|
|
|
|
|
2007-03-29 23:58:59 +00:00
|
|
|
nsIFrame* ancestorFrame;
|
|
|
|
nsIFrame* rootFrame = GetRootFrame();
|
|
|
|
|
|
|
|
// If the start or end of the range is the document, just use the root
|
|
|
|
// frame, otherwise get the common ancestor of the two endpoints of the
|
|
|
|
// range.
|
|
|
|
nsINode* startParent = range->GetStartParent();
|
|
|
|
nsINode* endParent = range->GetEndParent();
|
|
|
|
nsIDocument* doc = startParent->GetCurrentDoc();
|
|
|
|
if (startParent == doc || endParent == doc) {
|
|
|
|
ancestorFrame = rootFrame;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
nsINode* ancestor = nsContentUtils::GetCommonAncestor(startParent, endParent);
|
|
|
|
NS_ASSERTION(!ancestor || ancestor->IsNodeOfType(nsINode::eCONTENT),
|
|
|
|
"common ancestor is not content");
|
|
|
|
if (!ancestor || !ancestor->IsNodeOfType(nsINode::eCONTENT))
|
|
|
|
return nsnull;
|
2007-03-20 12:14:52 +00:00
|
|
|
|
2007-07-08 07:08:04 +00:00
|
|
|
nsIContent* ancestorContent = static_cast<nsIContent*>(ancestor);
|
2009-12-24 21:20:06 +00:00
|
|
|
ancestorFrame = ancestorContent->GetPrimaryFrame();
|
2007-03-20 12:14:52 +00:00
|
|
|
|
2007-03-29 23:58:59 +00:00
|
|
|
// use the nearest ancestor frame that includes all continuations as the
|
|
|
|
// root for building the display list
|
|
|
|
while (ancestorFrame &&
|
|
|
|
nsLayoutUtils::GetNextContinuationOrSpecialSibling(ancestorFrame))
|
|
|
|
ancestorFrame = ancestorFrame->GetParent();
|
|
|
|
}
|
2007-03-20 12:14:52 +00:00
|
|
|
|
|
|
|
if (!ancestorFrame)
|
|
|
|
return nsnull;
|
|
|
|
|
|
|
|
info = new RangePaintInfo(range, ancestorFrame);
|
|
|
|
if (!info)
|
|
|
|
return nsnull;
|
|
|
|
|
|
|
|
nsRect ancestorRect = ancestorFrame->GetOverflowRect();
|
|
|
|
|
|
|
|
// get a display list containing the range
|
|
|
|
info->mBuilder.SetPaintAllFrames();
|
|
|
|
info->mBuilder.EnterPresShell(ancestorFrame, ancestorRect);
|
|
|
|
ancestorFrame->BuildDisplayListForStackingContext(&info->mBuilder,
|
|
|
|
ancestorRect, &info->mList);
|
|
|
|
info->mBuilder.LeavePresShell(ancestorFrame, ancestorRect);
|
|
|
|
|
2010-06-05 20:29:49 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
if (gDumpRangePaintList) {
|
|
|
|
fprintf(stderr, "CreateRangePaintInfo --- before ClipListToRange:\n");
|
|
|
|
nsFrame::PrintDisplayList(&(info->mBuilder), info->mList);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-08-17 03:43:00 +00:00
|
|
|
nsRect rangeRect = ClipListToRange(&info->mBuilder, &info->mList, range);
|
2007-03-20 12:14:52 +00:00
|
|
|
|
2010-06-05 20:29:49 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
if (gDumpRangePaintList) {
|
|
|
|
fprintf(stderr, "CreateRangePaintInfo --- after ClipListToRange:\n");
|
|
|
|
nsFrame::PrintDisplayList(&(info->mBuilder), info->mList);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-03-20 12:14:52 +00:00
|
|
|
// determine the offset of the reference frame for the display list
|
|
|
|
// to the root frame. This will allow the coordinates used when painting
|
|
|
|
// to all be offset from the same point
|
2007-03-29 23:58:59 +00:00
|
|
|
info->mRootOffset = ancestorFrame->GetOffsetTo(rootFrame);
|
2007-03-20 12:14:52 +00:00
|
|
|
rangeRect.MoveBy(info->mRootOffset);
|
|
|
|
aSurfaceRect.UnionRect(aSurfaceRect, rangeRect);
|
|
|
|
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<gfxASurface>
|
|
|
|
PresShell::PaintRangePaintInfo(nsTArray<nsAutoPtr<RangePaintInfo> >* aItems,
|
|
|
|
nsISelection* aSelection,
|
2010-06-05 20:29:49 +00:00
|
|
|
nsIntRegion* aRegion,
|
2007-03-20 12:14:52 +00:00
|
|
|
nsRect aArea,
|
2009-01-15 03:27:09 +00:00
|
|
|
nsIntPoint& aPoint,
|
|
|
|
nsIntRect* aScreenRect)
|
2007-03-20 12:14:52 +00:00
|
|
|
{
|
2010-05-19 23:22:19 +00:00
|
|
|
NS_TIME_FUNCTION_WITH_DOCURL;
|
|
|
|
|
2007-03-20 12:14:52 +00:00
|
|
|
nsPresContext* pc = GetPresContext();
|
2007-05-17 10:14:35 +00:00
|
|
|
if (!pc || aArea.width == 0 || aArea.height == 0)
|
2007-03-20 12:14:52 +00:00
|
|
|
return nsnull;
|
|
|
|
|
|
|
|
nsIDeviceContext* deviceContext = pc->DeviceContext();
|
|
|
|
|
|
|
|
// use the rectangle to create the surface
|
2009-05-08 02:31:04 +00:00
|
|
|
nsIntRect pixelArea = aArea.ToOutsidePixels(pc->AppUnitsPerDevPixel());
|
2007-03-20 12:14:52 +00:00
|
|
|
|
|
|
|
// if the area of the image is larger than the maximum area, scale it down
|
|
|
|
float scale = 0.0;
|
|
|
|
nsIntRect rootScreenRect = GetRootFrame()->GetScreenRect();
|
|
|
|
|
|
|
|
// if the image is larger in one or both directions than half the size of
|
|
|
|
// the available screen area, scale the image down to that size.
|
|
|
|
nsRect maxSize;
|
|
|
|
deviceContext->GetClientRect(maxSize);
|
|
|
|
nscoord maxWidth = pc->AppUnitsToDevPixels(maxSize.width >> 1);
|
|
|
|
nscoord maxHeight = pc->AppUnitsToDevPixels(maxSize.height >> 1);
|
|
|
|
PRBool resize = (pixelArea.width > maxWidth || pixelArea.height > maxHeight);
|
|
|
|
if (resize) {
|
|
|
|
scale = 1.0;
|
|
|
|
// divide the maximum size by the image size in both directions. Whichever
|
|
|
|
// direction produces the smallest result determines how much should be
|
|
|
|
// scaled.
|
|
|
|
if (pixelArea.width > maxWidth)
|
2009-09-16 15:01:36 +00:00
|
|
|
scale = NS_MIN(scale, float(maxWidth) / pixelArea.width);
|
2007-03-20 12:14:52 +00:00
|
|
|
if (pixelArea.height > maxHeight)
|
2009-09-16 15:01:36 +00:00
|
|
|
scale = NS_MIN(scale, float(maxHeight) / pixelArea.height);
|
2007-03-20 12:14:52 +00:00
|
|
|
|
|
|
|
pixelArea.width = NSToIntFloor(float(pixelArea.width) * scale);
|
|
|
|
pixelArea.height = NSToIntFloor(float(pixelArea.height) * scale);
|
|
|
|
|
|
|
|
// adjust the screen position based on the rescaled size
|
|
|
|
nscoord left = rootScreenRect.x + pixelArea.x;
|
|
|
|
nscoord top = rootScreenRect.y + pixelArea.y;
|
|
|
|
aScreenRect->x = NSToIntFloor(aPoint.x - float(aPoint.x - left) * scale);
|
|
|
|
aScreenRect->y = NSToIntFloor(aPoint.y - float(aPoint.y - top) * scale);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// move aScreenRect to the position of the surface in screen coordinates
|
|
|
|
aScreenRect->MoveTo(rootScreenRect.x + pixelArea.x, rootScreenRect.y + pixelArea.y);
|
|
|
|
}
|
|
|
|
aScreenRect->width = pixelArea.width;
|
|
|
|
aScreenRect->height = pixelArea.height;
|
|
|
|
|
|
|
|
gfxImageSurface* surface =
|
|
|
|
new gfxImageSurface(gfxIntSize(pixelArea.width, pixelArea.height),
|
|
|
|
gfxImageSurface::ImageFormatARGB32);
|
2007-05-17 10:14:35 +00:00
|
|
|
if (!surface || surface->CairoStatus()) {
|
|
|
|
delete surface;
|
2007-03-20 12:14:52 +00:00
|
|
|
return nsnull;
|
2007-05-17 10:14:35 +00:00
|
|
|
}
|
2007-03-20 12:14:52 +00:00
|
|
|
|
|
|
|
// clear the image
|
|
|
|
gfxContext context(surface);
|
|
|
|
context.SetOperator(gfxContext::OPERATOR_CLEAR);
|
|
|
|
context.Rectangle(gfxRect(0, 0, pixelArea.width, pixelArea.height));
|
|
|
|
context.Fill();
|
|
|
|
|
|
|
|
nsCOMPtr<nsIRenderingContext> rc;
|
|
|
|
deviceContext->CreateRenderingContextInstance(*getter_AddRefs(rc));
|
|
|
|
rc->Init(deviceContext, surface);
|
|
|
|
|
2010-06-05 20:29:49 +00:00
|
|
|
if (aRegion) {
|
|
|
|
// Convert aRegion from CSS pixels to dev pixels
|
|
|
|
nsIntRegion region =
|
|
|
|
aRegion->ToAppUnits(nsPresContext::AppUnitsPerCSSPixel())
|
|
|
|
.ToOutsidePixels(pc->AppUnitsPerDevPixel());
|
|
|
|
rc->SetClipRegion(region, nsClipCombine_kReplace);
|
|
|
|
}
|
2007-03-20 12:14:52 +00:00
|
|
|
|
|
|
|
if (resize)
|
|
|
|
rc->Scale(scale, scale);
|
|
|
|
|
|
|
|
// translate so that points are relative to the surface area
|
|
|
|
rc->Translate(-aArea.x, -aArea.y);
|
|
|
|
|
|
|
|
// temporarily hide the selection so that text is drawn normally. If a
|
|
|
|
// selection is being rendered, use that, otherwise use the presshell's
|
|
|
|
// selection.
|
|
|
|
nsCOMPtr<nsFrameSelection> frameSelection;
|
|
|
|
if (aSelection) {
|
|
|
|
nsCOMPtr<nsISelectionPrivate> selpriv = do_QueryInterface(aSelection);
|
|
|
|
selpriv->GetFrameSelection(getter_AddRefs(frameSelection));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
frameSelection = FrameSelection();
|
|
|
|
}
|
|
|
|
PRInt16 oldDisplaySelection = frameSelection->GetDisplaySelection();
|
|
|
|
frameSelection->SetDisplaySelection(nsISelectionController::SELECTION_HIDDEN);
|
|
|
|
|
|
|
|
// next, paint each range in the selection
|
|
|
|
PRInt32 count = aItems->Length();
|
|
|
|
for (PRInt32 i = 0; i < count; i++) {
|
|
|
|
RangePaintInfo* rangeInfo = (*aItems)[i];
|
|
|
|
// the display lists paint relative to the offset from the reference
|
|
|
|
// frame, so translate the rendering context
|
|
|
|
nsIRenderingContext::AutoPushTranslation
|
|
|
|
translate(rc, rangeInfo->mRootOffset.x, rangeInfo->mRootOffset.y);
|
|
|
|
|
|
|
|
aArea.MoveBy(-rangeInfo->mRootOffset.x, -rangeInfo->mRootOffset.y);
|
2009-09-07 00:35:14 +00:00
|
|
|
nsRegion visible(aArea);
|
2009-10-07 04:28:41 +00:00
|
|
|
rangeInfo->mList.ComputeVisibility(&rangeInfo->mBuilder, &visible, nsnull);
|
2010-03-10 20:55:05 +00:00
|
|
|
rangeInfo->mList.PaintRoot(&rangeInfo->mBuilder, rc, nsDisplayList::PAINT_DEFAULT);
|
2007-03-20 12:14:52 +00:00
|
|
|
aArea.MoveBy(rangeInfo->mRootOffset.x, rangeInfo->mRootOffset.y);
|
|
|
|
}
|
|
|
|
|
|
|
|
// restore the old selection display state
|
|
|
|
frameSelection->SetDisplaySelection(oldDisplaySelection);
|
|
|
|
|
|
|
|
NS_ADDREF(surface);
|
|
|
|
return surface;
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<gfxASurface>
|
|
|
|
PresShell::RenderNode(nsIDOMNode* aNode,
|
2010-06-05 20:29:49 +00:00
|
|
|
nsIntRegion* aRegion,
|
2009-01-15 03:27:09 +00:00
|
|
|
nsIntPoint& aPoint,
|
|
|
|
nsIntRect* aScreenRect)
|
2007-03-20 12:14:52 +00:00
|
|
|
{
|
|
|
|
// area will hold the size of the surface needed to draw the node, measured
|
|
|
|
// from the root frame.
|
|
|
|
nsRect area;
|
|
|
|
nsTArray<nsAutoPtr<RangePaintInfo> > rangeItems;
|
|
|
|
|
2008-08-27 14:46:29 +00:00
|
|
|
// nothing to draw if the node isn't in a document
|
|
|
|
nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
|
|
|
|
if (!node->IsInDoc())
|
|
|
|
return nsnull;
|
|
|
|
|
2007-03-20 12:14:52 +00:00
|
|
|
nsCOMPtr<nsIDOMRange> range;
|
|
|
|
NS_NewRange(getter_AddRefs(range));
|
2008-10-06 03:30:09 +00:00
|
|
|
if (NS_FAILED(range->SelectNode(aNode)))
|
|
|
|
return nsnull;
|
2007-03-20 12:14:52 +00:00
|
|
|
|
2007-08-17 03:43:00 +00:00
|
|
|
RangePaintInfo* info = CreateRangePaintInfo(range, area);
|
2007-03-20 12:14:52 +00:00
|
|
|
if (info && !rangeItems.AppendElement(info)) {
|
|
|
|
delete info;
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aRegion) {
|
|
|
|
// combine the area with the supplied region
|
2010-06-05 20:29:49 +00:00
|
|
|
nsIntRect rrectPixels = aRegion->GetBounds();
|
2007-03-20 12:14:52 +00:00
|
|
|
|
2009-05-08 02:31:04 +00:00
|
|
|
nsRect rrect = rrectPixels.ToAppUnits(nsPresContext::AppUnitsPerCSSPixel());
|
2007-03-20 12:14:52 +00:00
|
|
|
area.IntersectRect(area, rrect);
|
|
|
|
|
|
|
|
nsPresContext* pc = GetPresContext();
|
|
|
|
if (!pc)
|
|
|
|
return nsnull;
|
|
|
|
|
|
|
|
// move the region so that it is offset from the topleft corner of the surface
|
2010-06-05 20:29:49 +00:00
|
|
|
aRegion->MoveBy(-pc->AppUnitsToDevPixels(area.x),
|
|
|
|
-pc->AppUnitsToDevPixels(area.y));
|
2007-03-20 12:14:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return PaintRangePaintInfo(&rangeItems, nsnull, aRegion, area, aPoint,
|
|
|
|
aScreenRect);
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<gfxASurface>
|
|
|
|
PresShell::RenderSelection(nsISelection* aSelection,
|
2009-01-15 03:27:09 +00:00
|
|
|
nsIntPoint& aPoint,
|
|
|
|
nsIntRect* aScreenRect)
|
2007-03-20 12:14:52 +00:00
|
|
|
{
|
|
|
|
// area will hold the size of the surface needed to draw the selection,
|
|
|
|
// measured from the root frame.
|
|
|
|
nsRect area;
|
|
|
|
nsTArray<nsAutoPtr<RangePaintInfo> > rangeItems;
|
|
|
|
|
|
|
|
// iterate over each range and collect them into the rangeItems array.
|
|
|
|
// This is done so that the size of selection can be determined so as
|
|
|
|
// to allocate a surface area
|
|
|
|
PRInt32 numRanges;
|
|
|
|
aSelection->GetRangeCount(&numRanges);
|
2007-05-17 10:14:35 +00:00
|
|
|
NS_ASSERTION(numRanges > 0, "RenderSelection called with no selection");
|
|
|
|
|
2007-03-20 12:14:52 +00:00
|
|
|
for (PRInt32 r = 0; r < numRanges; r++)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMRange> range;
|
|
|
|
aSelection->GetRangeAt(r, getter_AddRefs(range));
|
|
|
|
|
2007-08-17 03:43:00 +00:00
|
|
|
RangePaintInfo* info = CreateRangePaintInfo(range, area);
|
2007-03-20 12:14:52 +00:00
|
|
|
if (info && !rangeItems.AppendElement(info)) {
|
|
|
|
delete info;
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return PaintRangePaintInfo(&rangeItems, aSelection, nsnull, area, aPoint,
|
|
|
|
aScreenRect);
|
|
|
|
}
|
|
|
|
|
2009-07-04 09:30:59 +00:00
|
|
|
nsresult PresShell::AddCanvasBackgroundColorItem(nsDisplayListBuilder& aBuilder,
|
|
|
|
nsDisplayList& aList,
|
|
|
|
nsIFrame* aFrame,
|
|
|
|
nsRect* aBounds,
|
2009-12-01 08:49:53 +00:00
|
|
|
nscolor aBackstopColor,
|
|
|
|
PRBool aForceDraw)
|
2009-07-04 09:30:59 +00:00
|
|
|
{
|
2009-07-09 09:16:11 +00:00
|
|
|
// We don't want to add an item for the canvas background color if the frame
|
|
|
|
// (sub)tree we are painting doesn't include any canvas frames. There isn't
|
|
|
|
// an easy way to check this directly, but if we check if the root of the
|
|
|
|
// (sub)tree we are painting is a canvas frame that should cover us in all
|
|
|
|
// cases (it will usually be a viewport frame when we have a canvas frame in
|
|
|
|
// the (sub)tree).
|
2009-12-01 08:49:53 +00:00
|
|
|
if (!aForceDraw && !nsCSSRendering::IsCanvasFrame(aFrame))
|
2009-07-09 09:16:11 +00:00
|
|
|
return NS_OK;
|
|
|
|
|
2009-07-04 09:30:59 +00:00
|
|
|
nscolor bgcolor = NS_ComposeColors(aBackstopColor, mCanvasBackgroundColor);
|
|
|
|
nsRect bounds = aBounds == nsnull ?
|
|
|
|
nsRect(aBuilder.ToReferenceFrame(aFrame), aFrame->GetSize()) : *aBounds;
|
|
|
|
return aList.AppendNewToBottom(new (&aBuilder) nsDisplaySolidColor(
|
|
|
|
aFrame,
|
|
|
|
bounds,
|
|
|
|
bgcolor));
|
|
|
|
}
|
|
|
|
|
2009-04-25 08:19:23 +00:00
|
|
|
void PresShell::UpdateCanvasBackground()
|
2009-04-18 07:11:29 +00:00
|
|
|
{
|
2009-04-18 08:53:27 +00:00
|
|
|
// If we have a frame tree and it has style information that
|
|
|
|
// specifies the background color of the canvas, update our local
|
|
|
|
// cache of that color.
|
|
|
|
nsIFrame* rootFrame = FrameConstructor()->GetRootElementStyleFrame();
|
|
|
|
if (rootFrame) {
|
2010-04-03 01:58:26 +00:00
|
|
|
nsStyleContext* bgStyle =
|
2009-04-18 08:53:27 +00:00
|
|
|
nsCSSRendering::FindRootFrameBackground(rootFrame);
|
2009-07-04 09:30:59 +00:00
|
|
|
// XXX We should really be passing the canvasframe, not the root element
|
|
|
|
// style frame but we don't have access to the canvasframe here. It isn't
|
|
|
|
// a problem because only a few frames can return something other than true
|
|
|
|
// and none of them would be a canvas frame or root element style frame.
|
|
|
|
mCanvasBackgroundColor =
|
2010-04-03 01:58:26 +00:00
|
|
|
nsCSSRendering::DetermineBackgroundColor(GetPresContext(), bgStyle,
|
2009-07-04 09:30:59 +00:00
|
|
|
rootFrame);
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the root element of the document (ie html) has style 'display: none'
|
|
|
|
// then the document's background color does not get drawn; cache the
|
|
|
|
// color we actually draw.
|
|
|
|
if (!FrameConstructor()->GetRootElementFrame()) {
|
|
|
|
mCanvasBackgroundColor = mPresContext->DefaultBackgroundColor();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-01 08:03:49 +00:00
|
|
|
nscolor PresShell::ComputeBackstopColor(nsIView* aDisplayRoot)
|
2009-07-04 09:30:59 +00:00
|
|
|
{
|
2010-03-01 08:03:49 +00:00
|
|
|
nsIWidget* widget = aDisplayRoot->GetWidget();
|
2009-07-04 09:30:59 +00:00
|
|
|
if (widget && widget->GetTransparencyMode() != eTransparencyOpaque) {
|
|
|
|
// Within a transparent widget, so the backstop color must be
|
|
|
|
// totally transparent.
|
|
|
|
return NS_RGBA(0,0,0,0);
|
2009-04-18 08:53:27 +00:00
|
|
|
}
|
2009-07-04 09:30:59 +00:00
|
|
|
// Within an opaque widget (or no widget at all), so the backstop
|
|
|
|
// color must be totally opaque. The user's default background
|
|
|
|
// as reported by the prescontext is guaranteed to be opaque.
|
|
|
|
return GetPresContext()->DefaultBackgroundColor();
|
2009-04-25 08:19:23 +00:00
|
|
|
}
|
|
|
|
|
2010-05-21 03:20:48 +00:00
|
|
|
struct PaintParams {
|
|
|
|
nsIFrame* mFrame;
|
|
|
|
nsPoint mOffsetToRoot;
|
|
|
|
nsPoint mOffsetToWidget;
|
|
|
|
const nsRegion* mDirtyRegion;
|
|
|
|
nscolor mBackgroundColor;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void DrawThebesLayer(ThebesLayer* aLayer,
|
|
|
|
gfxContext* aContext,
|
|
|
|
const nsIntRegion& aRegionToDraw,
|
|
|
|
void* aCallbackData)
|
|
|
|
{
|
|
|
|
PaintParams* params = static_cast<PaintParams*>(aCallbackData);
|
|
|
|
nsIFrame* frame = params->mFrame;
|
|
|
|
if (frame) {
|
|
|
|
// We're drawing into a child window. Don't pass
|
|
|
|
// nsLayoutUtils::PAINT_WIDGET_LAYERS, since that will draw into
|
|
|
|
// the widget for the display root.
|
|
|
|
nsIDeviceContext* devCtx = frame->PresContext()->DeviceContext();
|
|
|
|
nsCOMPtr<nsIRenderingContext> rc;
|
|
|
|
nsresult rv = devCtx->CreateRenderingContextInstance(*getter_AddRefs(rc));
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
rc->Init(devCtx, aContext);
|
|
|
|
nsRegion dirtyRegion = *params->mDirtyRegion;
|
|
|
|
dirtyRegion.MoveBy(params->mOffsetToRoot);
|
|
|
|
nsIRenderingContext::AutoPushTranslation
|
|
|
|
push(rc, -params->mOffsetToWidget.x, -params->mOffsetToWidget.y);
|
|
|
|
nsLayoutUtils::PaintFrame(rc, frame, dirtyRegion,
|
|
|
|
params->mBackgroundColor);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
aContext->NewPath();
|
|
|
|
aContext->SetColor(gfxRGBA(params->mBackgroundColor));
|
|
|
|
nsIntRect dirtyRect = aRegionToDraw.GetBounds();
|
|
|
|
aContext->Rectangle(
|
|
|
|
gfxRect(dirtyRect.x, dirtyRect.y, dirtyRect.width, dirtyRect.height));
|
|
|
|
aContext->Fill();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-25 08:19:23 +00:00
|
|
|
NS_IMETHODIMP
|
2010-03-01 08:03:49 +00:00
|
|
|
PresShell::Paint(nsIView* aDisplayRoot,
|
|
|
|
nsIView* aViewToPaint,
|
|
|
|
nsIWidget* aWidgetToPaint,
|
|
|
|
const nsRegion& aDirtyRegion,
|
|
|
|
PRBool aPaintDefaultBackground)
|
2009-04-25 08:19:23 +00:00
|
|
|
{
|
2010-05-19 23:22:19 +00:00
|
|
|
#ifdef NS_FUNCTION_TIMER
|
|
|
|
NS_TIME_FUNCTION_DECLARE_DOCURL;
|
|
|
|
const nsRect& bounds__ = aDirtyRegion.GetBounds();
|
|
|
|
NS_TIME_FUNCTION_MIN_FMT(1.0, "%s (line %d) (document: %s, dirty rect: (<%f, %f>, <%f, %f>)",
|
|
|
|
MOZ_FUNCTION_NAME, __LINE__, docURL__.get(),
|
|
|
|
NSCoordToFloat(bounds__.x),
|
|
|
|
NSCoordToFloat(bounds__.y),
|
|
|
|
NSCoordToFloat(bounds__.XMost()),
|
|
|
|
NSCoordToFloat(bounds__.YMost()));
|
|
|
|
#endif
|
|
|
|
|
2010-03-01 08:03:49 +00:00
|
|
|
nsPresContext* presContext = GetPresContext();
|
|
|
|
AUTO_LAYOUT_PHASE_ENTRY_POINT(presContext, Paint);
|
2009-04-25 08:19:23 +00:00
|
|
|
|
|
|
|
NS_ASSERTION(!mIsDestroying, "painting a destroyed PresShell");
|
2010-03-01 08:03:49 +00:00
|
|
|
NS_ASSERTION(aDisplayRoot, "null view");
|
|
|
|
NS_ASSERTION(aViewToPaint, "null view");
|
|
|
|
NS_ASSERTION(aWidgetToPaint, "Can't paint without a widget");
|
|
|
|
|
|
|
|
nscolor bgcolor = ComputeBackstopColor(aDisplayRoot);
|
|
|
|
|
|
|
|
nsIFrame* frame = aPaintDefaultBackground
|
|
|
|
? nsnull : static_cast<nsIFrame*>(aDisplayRoot->GetClientData());
|
|
|
|
|
|
|
|
if (frame && aViewToPaint == aDisplayRoot) {
|
|
|
|
// We can paint directly into the widget using its layer manager.
|
|
|
|
// When we get rid of child widgets, this will be the only path we
|
|
|
|
// need. (aPaintDefaultBackground will never be needed since the
|
|
|
|
// chrome can always paint a default background.)
|
|
|
|
nsLayoutUtils::PaintFrame(nsnull, frame, aDirtyRegion, bgcolor,
|
|
|
|
nsLayoutUtils::PAINT_WIDGET_LAYERS);
|
|
|
|
return NS_OK;
|
2009-02-23 01:10:23 +00:00
|
|
|
}
|
|
|
|
|
2010-03-01 08:03:49 +00:00
|
|
|
LayerManager* layerManager = aWidgetToPaint->GetLayerManager();
|
|
|
|
NS_ASSERTION(layerManager, "Must be in paint event");
|
2009-07-04 09:30:59 +00:00
|
|
|
|
2010-03-01 08:03:49 +00:00
|
|
|
layerManager->BeginTransaction();
|
|
|
|
nsRefPtr<ThebesLayer> root = layerManager->CreateThebesLayer();
|
|
|
|
nsIntRect dirtyRect = aDirtyRegion.GetBounds().
|
|
|
|
ToOutsidePixels(presContext->AppUnitsPerDevPixel());
|
|
|
|
if (root) {
|
|
|
|
root->SetVisibleRegion(dirtyRect);
|
|
|
|
layerManager->SetRoot(root);
|
|
|
|
}
|
2010-05-21 03:20:48 +00:00
|
|
|
if (!frame) {
|
|
|
|
bgcolor = NS_ComposeColors(bgcolor, mCanvasBackgroundColor);
|
|
|
|
}
|
|
|
|
nsPoint offsetToRoot = aViewToPaint->GetOffsetTo(aDisplayRoot);
|
|
|
|
PaintParams params =
|
|
|
|
{ frame,
|
|
|
|
offsetToRoot,
|
|
|
|
offsetToRoot - aViewToPaint->ViewToWidgetOffset(),
|
|
|
|
&aDirtyRegion,
|
|
|
|
bgcolor };
|
|
|
|
layerManager->EndTransaction(DrawThebesLayer, ¶ms);
|
2009-02-23 01:10:23 +00:00
|
|
|
|
2008-12-13 16:07:08 +00:00
|
|
|
return NS_OK;
|
1998-08-28 02:54:06 +00:00
|
|
|
}
|
|
|
|
|
2009-09-13 13:13:16 +00:00
|
|
|
// static
|
|
|
|
void
|
|
|
|
nsIPresShell::SetCapturingContent(nsIContent* aContent, PRUint8 aFlags)
|
|
|
|
{
|
|
|
|
NS_IF_RELEASE(gCaptureInfo.mContent);
|
|
|
|
|
|
|
|
// only set capturing content if allowed or the CAPTURE_IGNOREALLOWED flag
|
|
|
|
// is used
|
|
|
|
if ((aFlags & CAPTURE_IGNOREALLOWED) || gCaptureInfo.mAllowed) {
|
|
|
|
if (aContent) {
|
|
|
|
NS_ADDREF(gCaptureInfo.mContent = aContent);
|
|
|
|
}
|
|
|
|
gCaptureInfo.mRetargetToElement = (aFlags & CAPTURE_RETARGETTOELEMENT) != 0;
|
2010-02-03 02:07:08 +00:00
|
|
|
gCaptureInfo.mPreventDrag = (aFlags & CAPTURE_PREVENTDRAG) != 0;
|
2009-09-13 13:13:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-06-15 03:14:28 +00:00
|
|
|
nsIFrame*
|
|
|
|
PresShell::GetCurrentEventFrame()
|
|
|
|
{
|
2008-12-07 23:10:31 +00:00
|
|
|
if (NS_UNLIKELY(mIsDestroying)) {
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
1999-06-15 03:14:28 +00:00
|
|
|
if (!mCurrentEventFrame && mCurrentEventContent) {
|
1999-11-03 07:11:45 +00:00
|
|
|
// Make sure the content still has a document reference. If not,
|
|
|
|
// then we assume it is no longer in the content tree and the
|
|
|
|
// frame shouldn't get an event, nor should we even assume its
|
|
|
|
// safe to try and find the frame.
|
2003-07-28 21:25:13 +00:00
|
|
|
if (mCurrentEventContent->GetDocument()) {
|
2009-12-24 21:20:06 +00:00
|
|
|
mCurrentEventFrame = mCurrentEventContent->GetPrimaryFrame();
|
1999-11-03 07:11:45 +00:00
|
|
|
}
|
1999-06-15 03:14:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return mCurrentEventFrame;
|
|
|
|
}
|
|
|
|
|
2010-03-31 12:43:01 +00:00
|
|
|
nsIFrame*
|
|
|
|
PresShell::GetEventTargetFrame()
|
2000-06-24 03:58:13 +00:00
|
|
|
{
|
2010-03-31 12:43:01 +00:00
|
|
|
return GetCurrentEventFrame();
|
2000-06-24 03:58:13 +00:00
|
|
|
}
|
|
|
|
|
2010-03-31 12:43:01 +00:00
|
|
|
already_AddRefed<nsIContent>
|
|
|
|
PresShell::GetEventTargetContent(nsEvent* aEvent)
|
2003-02-14 21:43:06 +00:00
|
|
|
{
|
2010-03-31 12:43:01 +00:00
|
|
|
nsIContent* content = nsnull;
|
|
|
|
|
2003-02-14 21:43:06 +00:00
|
|
|
if (mCurrentEventContent) {
|
2010-03-31 12:43:01 +00:00
|
|
|
content = mCurrentEventContent;
|
|
|
|
NS_IF_ADDREF(content);
|
2003-02-14 21:43:06 +00:00
|
|
|
} else {
|
|
|
|
nsIFrame* currentEventFrame = GetCurrentEventFrame();
|
|
|
|
if (currentEventFrame) {
|
2010-03-31 12:43:01 +00:00
|
|
|
currentEventFrame->GetContentForEvent(mPresContext, aEvent, &content);
|
2003-02-14 21:43:06 +00:00
|
|
|
} else {
|
2010-03-31 12:43:01 +00:00
|
|
|
content = nsnull;
|
2003-02-14 21:43:06 +00:00
|
|
|
}
|
|
|
|
}
|
2010-03-31 12:43:01 +00:00
|
|
|
return content;
|
2003-02-14 21:43:06 +00:00
|
|
|
}
|
|
|
|
|
1999-09-02 18:14:01 +00:00
|
|
|
void
|
2000-04-24 04:41:27 +00:00
|
|
|
PresShell::PushCurrentEventInfo(nsIFrame* aFrame, nsIContent* aContent)
|
1999-09-02 18:14:01 +00:00
|
|
|
{
|
2000-04-24 04:41:27 +00:00
|
|
|
if (mCurrentEventFrame || mCurrentEventContent) {
|
2009-02-03 14:42:18 +00:00
|
|
|
mCurrentEventFrameStack.InsertElementAt(0, mCurrentEventFrame);
|
2004-09-13 03:22:46 +00:00
|
|
|
mCurrentEventContentStack.InsertObjectAt(mCurrentEventContent, 0);
|
1999-09-02 18:14:01 +00:00
|
|
|
}
|
2000-04-24 04:41:27 +00:00
|
|
|
mCurrentEventFrame = aFrame;
|
|
|
|
mCurrentEventContent = aContent;
|
1999-09-02 18:14:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-04-24 04:41:27 +00:00
|
|
|
PresShell::PopCurrentEventInfo()
|
1999-09-02 18:14:01 +00:00
|
|
|
{
|
|
|
|
mCurrentEventFrame = nsnull;
|
2004-09-13 03:22:46 +00:00
|
|
|
mCurrentEventContent = nsnull;
|
1999-09-02 18:14:01 +00:00
|
|
|
|
2009-02-03 14:42:18 +00:00
|
|
|
if (0 != mCurrentEventFrameStack.Length()) {
|
|
|
|
mCurrentEventFrame = mCurrentEventFrameStack.ElementAt(0);
|
1999-09-02 18:14:01 +00:00
|
|
|
mCurrentEventFrameStack.RemoveElementAt(0);
|
2004-09-13 03:22:46 +00:00
|
|
|
mCurrentEventContent = mCurrentEventContentStack.ObjectAt(0);
|
|
|
|
mCurrentEventContentStack.RemoveObjectAt(0);
|
1999-09-02 18:14:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-01-07 02:09:06 +00:00
|
|
|
PRBool PresShell::InZombieDocument(nsIContent *aContent)
|
|
|
|
{
|
2005-08-05 20:01:52 +00:00
|
|
|
// If a content node points to a null document, or the document is not
|
|
|
|
// attached to a window, then it is possibly in a zombie document,
|
|
|
|
// about to be replaced by a newly loading document.
|
2003-01-07 02:09:06 +00:00
|
|
|
// Such documents cannot handle DOM events.
|
|
|
|
// It might actually be in a node not attached to any document,
|
|
|
|
// in which case there is not parent presshell to retarget it to.
|
2005-08-05 20:01:52 +00:00
|
|
|
nsIDocument *doc = aContent->GetDocument();
|
2005-11-28 23:56:44 +00:00
|
|
|
return !doc || !doc->GetWindow();
|
2003-01-07 02:09:06 +00:00
|
|
|
}
|
|
|
|
|
2006-10-27 00:01:19 +00:00
|
|
|
nsresult PresShell::RetargetEventToParent(nsGUIEvent* aEvent,
|
|
|
|
nsEventStatus* aEventStatus)
|
2003-01-07 02:09:06 +00:00
|
|
|
{
|
2005-02-05 17:00:46 +00:00
|
|
|
// Send this events straight up to the parent pres shell.
|
2006-10-27 00:01:19 +00:00
|
|
|
// We do this for keystroke events in zombie documents or if either a frame
|
|
|
|
// or a root content is not present.
|
2003-01-07 02:09:06 +00:00
|
|
|
// That way at least the UI key bindings can work.
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPresShell> kungFuDeathGrip(this);
|
2004-02-01 10:09:07 +00:00
|
|
|
nsCOMPtr<nsISupports> container = mPresContext->GetContainer();
|
2005-08-22 01:55:34 +00:00
|
|
|
if (!container)
|
|
|
|
container = do_QueryReferent(mForwardingContainer);
|
2003-01-07 02:09:06 +00:00
|
|
|
|
|
|
|
// Now, find the parent pres shell and send the event there
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> treeItem =
|
|
|
|
do_QueryInterface(container);
|
2008-09-28 19:14:28 +00:00
|
|
|
if (!treeItem) {
|
|
|
|
// Might have gone away, or never been around to start with
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2003-01-07 02:09:06 +00:00
|
|
|
nsCOMPtr<nsIDocShellTreeItem> parentTreeItem;
|
|
|
|
treeItem->GetParent(getter_AddRefs(parentTreeItem));
|
|
|
|
nsCOMPtr<nsIDocShell> parentDocShell =
|
|
|
|
do_QueryInterface(parentTreeItem);
|
|
|
|
if (!parentDocShell || treeItem == parentTreeItem) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPresShell> parentPresShell;
|
|
|
|
parentDocShell->GetPresShell(getter_AddRefs(parentPresShell));
|
|
|
|
nsCOMPtr<nsIViewObserver> parentViewObserver =
|
|
|
|
do_QueryInterface(parentPresShell);
|
|
|
|
if (!parentViewObserver) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2006-10-27 00:01:19 +00:00
|
|
|
// Fake the event as though it'ss from the parent pres shell's root view.
|
|
|
|
nsIView *parentRootView;
|
|
|
|
parentPresShell->GetViewManager()->GetRootView(parentRootView);
|
|
|
|
|
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 18:00:39 +00:00
|
|
|
sDontRetargetEvents = PR_TRUE;
|
|
|
|
nsresult rv = parentViewObserver->HandleEvent(parentRootView, aEvent, aEventStatus);
|
|
|
|
sDontRetargetEvents = PR_FALSE;
|
|
|
|
return rv;
|
2003-01-07 02:09:06 +00:00
|
|
|
}
|
|
|
|
|
2010-03-31 12:45:32 +00:00
|
|
|
void
|
2009-02-12 10:44:38 +00:00
|
|
|
PresShell::DisableNonTestMouseEvents(PRBool aDisable)
|
|
|
|
{
|
|
|
|
sDisableNonTestMouseEvents = aDisable;
|
|
|
|
}
|
|
|
|
|
2009-12-17 18:42:02 +00:00
|
|
|
already_AddRefed<nsPIDOMWindow>
|
|
|
|
PresShell::GetFocusedDOMWindowInOurWindow()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsPIDOMWindow> window =
|
|
|
|
do_QueryInterface(mDocument->GetWindow());
|
|
|
|
NS_ENSURE_TRUE(window, nsnull);
|
|
|
|
|
|
|
|
nsCOMPtr<nsPIDOMWindow> rootWindow = window->GetPrivateRoot();
|
|
|
|
NS_ENSURE_TRUE(rootWindow, nsnull);
|
|
|
|
nsPIDOMWindow* focusedWindow;
|
2010-01-08 05:01:42 +00:00
|
|
|
nsFocusManager::GetFocusedDescendant(rootWindow, PR_TRUE, &focusedWindow);
|
2009-12-17 18:42:02 +00:00
|
|
|
return focusedWindow;
|
|
|
|
}
|
|
|
|
|
1998-12-18 15:54:23 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
PresShell::HandleEvent(nsIView *aView,
|
|
|
|
nsGUIEvent* aEvent,
|
2006-01-26 02:29:17 +00:00
|
|
|
nsEventStatus* aEventStatus)
|
1998-08-28 02:54:06 +00:00
|
|
|
{
|
2003-05-12 07:11:16 +00:00
|
|
|
NS_ASSERTION(aView, "null view");
|
2000-03-22 02:43:08 +00:00
|
|
|
|
2009-02-12 10:44:38 +00:00
|
|
|
if (mIsDestroying || !nsContentUtils::IsSafeToRunScript() ||
|
|
|
|
(sDisableNonTestMouseEvents && NS_IS_MOUSE_EVENT(aEvent) &&
|
2009-10-02 21:06:42 +00:00
|
|
|
!(aEvent->flags & NS_EVENT_FLAG_SYNTHETIC_TEST_EVENT))) {
|
1998-11-18 05:25:26 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-05-19 23:22:19 +00:00
|
|
|
NS_TIME_FUNCTION_MIN(1.0);
|
|
|
|
|
2001-08-17 03:13:07 +00:00
|
|
|
#ifdef ACCESSIBILITY
|
2003-05-12 07:11:16 +00:00
|
|
|
if (aEvent->eventStructType == NS_ACCESSIBLE_EVENT) {
|
2008-03-19 01:37:09 +00:00
|
|
|
// Accessibility events come through OS requests and not from scripts,
|
|
|
|
// so it is safe to handle here
|
2006-03-07 17:08:51 +00:00
|
|
|
return HandleEventInternal(aEvent, aView, aEventStatus);
|
2003-05-12 07:11:16 +00:00
|
|
|
}
|
2001-08-17 03:13:07 +00:00
|
|
|
#endif
|
2008-04-18 17:20:11 +00:00
|
|
|
|
2009-09-28 14:17:01 +00:00
|
|
|
nsIContent* capturingContent =
|
|
|
|
NS_IS_MOUSE_EVENT(aEvent) ? GetCapturingContent() : nsnull;
|
|
|
|
|
2009-09-13 13:13:16 +00:00
|
|
|
nsCOMPtr<nsIDocument> retargetEventDoc;
|
|
|
|
if (!sDontRetargetEvents) {
|
2010-06-15 05:05:37 +00:00
|
|
|
// key and IME related events should not cross top level window boundary.
|
|
|
|
// Basically, such input events should be fired only on focused widget.
|
|
|
|
// However, some IMEs might need to clean up composition after focused
|
|
|
|
// window is deactivated. And also some tests on MozMill want to test key
|
|
|
|
// handling on deactivated window because MozMill window can be activated
|
|
|
|
// during tests. So, there is no merit the events should be redirected to
|
|
|
|
// active window. So, the events should be handled on the last focused
|
|
|
|
// content in the last focused DOM window in same top level window.
|
|
|
|
// Note, if no DOM window has been focused yet, we can discard the events.
|
2009-09-13 13:13:16 +00:00
|
|
|
if (NS_IsEventTargetedAtFocusedWindow(aEvent)) {
|
2010-06-15 05:05:37 +00:00
|
|
|
nsCOMPtr<nsPIDOMWindow> window = GetFocusedDOMWindowInOurWindow();
|
|
|
|
// No DOM window in same top level window has not been focused yet,
|
|
|
|
// discard the events.
|
|
|
|
if (!window) {
|
2009-09-13 13:13:16 +00:00
|
|
|
return NS_OK;
|
2010-06-15 05:05:37 +00:00
|
|
|
}
|
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 18:00:39 +00:00
|
|
|
|
2010-06-15 05:05:37 +00:00
|
|
|
retargetEventDoc = do_QueryInterface(window->GetExtantDocument());
|
2009-09-13 13:13:16 +00:00
|
|
|
if (!retargetEventDoc)
|
|
|
|
return NS_OK;
|
2009-09-28 14:17:01 +00:00
|
|
|
} else if (capturingContent) {
|
2009-09-13 13:13:16 +00:00
|
|
|
// if the mouse is being captured then retarget the mouse event at the
|
|
|
|
// document that is being captured.
|
2009-09-28 14:17:01 +00:00
|
|
|
retargetEventDoc = capturingContent->GetCurrentDoc();
|
2009-09-13 13:13:16 +00:00
|
|
|
}
|
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 18:00:39 +00:00
|
|
|
|
2009-09-13 13:13:16 +00:00
|
|
|
if (retargetEventDoc) {
|
|
|
|
nsIPresShell* presShell = retargetEventDoc->GetPrimaryShell();
|
|
|
|
if (!presShell)
|
|
|
|
return NS_OK;
|
2009-09-10 12:51:36 +00:00
|
|
|
|
2009-09-13 13:13:16 +00:00
|
|
|
if (presShell != this) {
|
|
|
|
nsCOMPtr<nsIViewObserver> viewObserver = do_QueryInterface(presShell);
|
|
|
|
if (!viewObserver)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsIView *view;
|
|
|
|
presShell->GetViewManager()->GetRootView(view);
|
|
|
|
sDontRetargetEvents = PR_TRUE;
|
|
|
|
nsresult rv = viewObserver->HandleEvent(view, aEvent, aEventStatus);
|
|
|
|
sDontRetargetEvents = PR_FALSE;
|
|
|
|
return rv;
|
|
|
|
}
|
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 18:00:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-12-17 22:51:39 +00:00
|
|
|
// Check for a theme change up front, since the frame type is irrelevant
|
2003-05-12 07:11:16 +00:00
|
|
|
if (aEvent->message == NS_THEMECHANGED && mPresContext) {
|
2004-07-29 19:41:39 +00:00
|
|
|
mPresContext->ThemeChanged();
|
|
|
|
return NS_OK;
|
2003-05-12 07:11:16 +00:00
|
|
|
}
|
2001-04-01 01:01:33 +00:00
|
|
|
|
2010-04-21 14:53:42 +00:00
|
|
|
if (aEvent->message == NS_UISTATECHANGED && mDocument) {
|
|
|
|
nsPIDOMWindow* win = mDocument->GetWindow();
|
|
|
|
if (win) {
|
|
|
|
nsUIStateChangeEvent* event = (nsUIStateChangeEvent*)aEvent;
|
|
|
|
win->SetKeyboardIndicators(event->showAccelerators, event->showFocusRings);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-05-12 07:11:16 +00:00
|
|
|
// Check for a system color change up front, since the frame type is
|
|
|
|
// irrelevant
|
2002-06-04 17:47:54 +00:00
|
|
|
if ((aEvent->message == NS_SYSCOLORCHANGED) && mPresContext) {
|
2003-06-30 10:46:59 +00:00
|
|
|
nsIViewManager* vm = GetViewManager();
|
|
|
|
if (vm) {
|
2002-06-04 17:47:54 +00:00
|
|
|
// Only dispatch system color change when the message originates from
|
|
|
|
// from the root views widget. This is necessary to prevent us from
|
|
|
|
// dispatching the SysColorChanged notification for each child window
|
|
|
|
// which may be redundant.
|
2004-05-17 16:29:13 +00:00
|
|
|
nsIView *view;
|
|
|
|
vm->GetRootView(view);
|
|
|
|
if (view == aView) {
|
2002-06-04 17:47:54 +00:00
|
|
|
*aEventStatus = nsEventStatus_eConsumeDoDefault;
|
2004-07-29 19:41:39 +00:00
|
|
|
mPresContext->SysColorChanged();
|
|
|
|
return NS_OK;
|
2002-06-04 17:47:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2009-03-03 20:20:11 +00:00
|
|
|
|
2010-03-05 00:10:32 +00:00
|
|
|
if (aEvent->eventStructType == NS_KEY_EVENT &&
|
|
|
|
mDocument && mDocument->EventHandlingSuppressed()) {
|
|
|
|
if (aEvent->message == NS_KEY_DOWN) {
|
|
|
|
mNoDelayedKeyEvents = PR_TRUE;
|
|
|
|
} else if (!mNoDelayedKeyEvents) {
|
|
|
|
nsDelayedEvent* event =
|
|
|
|
new nsDelayedKeyEvent(static_cast<nsKeyEvent*>(aEvent));
|
|
|
|
if (event && !mDelayedEvents.AppendElement(event)) {
|
|
|
|
delete event;
|
2009-05-18 09:17:45 +00:00
|
|
|
}
|
2009-03-03 20:11:14 +00:00
|
|
|
}
|
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 18:00:39 +00:00
|
|
|
return NS_OK;
|
2009-03-03 20:11:14 +00:00
|
|
|
}
|
|
|
|
|
2007-07-08 07:08:04 +00:00
|
|
|
nsIFrame* frame = static_cast<nsIFrame*>(aView->GetClientData());
|
2009-08-07 15:11:17 +00:00
|
|
|
PRBool dispatchUsingCoordinates = NS_IsEventUsingCoordinates(aEvent);
|
2006-02-27 02:47:13 +00:00
|
|
|
|
|
|
|
// if this event has no frame, we need to retarget it at a parent
|
|
|
|
// view that has a frame.
|
|
|
|
if (!frame &&
|
|
|
|
(dispatchUsingCoordinates || NS_IS_KEY_EVENT(aEvent) ||
|
2010-04-21 06:21:46 +00:00
|
|
|
NS_IS_IME_RELATED_EVENT(aEvent) || NS_IS_NON_RETARGETED_PLUGIN_EVENT(aEvent) ||
|
2009-12-17 18:42:02 +00:00
|
|
|
aEvent->message == NS_PLUGIN_ACTIVATE)) {
|
2006-02-27 02:47:13 +00:00
|
|
|
nsIView* targetView = aView;
|
|
|
|
while (targetView && !targetView->GetClientData()) {
|
|
|
|
targetView = targetView->GetParent();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (targetView) {
|
|
|
|
aView = targetView;
|
2007-07-08 07:08:04 +00:00
|
|
|
frame = static_cast<nsIFrame*>(aView->GetClientData());
|
2006-02-27 02:47:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dispatchUsingCoordinates) {
|
2009-04-22 12:55:54 +00:00
|
|
|
NS_WARN_IF_FALSE(frame, "Nothing to handle this event!");
|
2006-02-27 02:47:13 +00:00
|
|
|
if (!frame)
|
|
|
|
return NS_OK;
|
2006-11-29 23:09:13 +00:00
|
|
|
|
2007-03-30 21:11:41 +00:00
|
|
|
nsPresContext* framePresContext = frame->PresContext();
|
2010-01-26 13:10:12 +00:00
|
|
|
nsPresContext* rootPresContext = framePresContext->GetRootPresContext();
|
|
|
|
NS_ASSERTION(rootPresContext == mPresContext->GetRootPresContext(),
|
2006-11-29 23:09:13 +00:00
|
|
|
"How did we end up outside the connected prescontext/viewmanager hierarchy?");
|
|
|
|
// If we aren't starting our event dispatch from the root frame of the root prescontext,
|
|
|
|
// then someone must be capturing the mouse. In that case we don't want to search the popup
|
|
|
|
// list.
|
|
|
|
if (framePresContext == rootPresContext &&
|
|
|
|
frame == FrameManager()->GetRootFrame()) {
|
2010-03-19 05:02:53 +00:00
|
|
|
nsIFrame* popupFrame =
|
|
|
|
nsLayoutUtils::GetPopupFrameForEventCoordinates(aEvent);
|
|
|
|
// If the popupFrame is an ancestor of the 'frame', the frame should
|
|
|
|
// handle the event, otherwise, the popup should handle it.
|
|
|
|
if (popupFrame &&
|
|
|
|
!nsContentUtils::ContentIsCrossDocDescendantOf(
|
|
|
|
framePresContext->GetPresShell()->GetDocument(),
|
|
|
|
popupFrame->GetContent())) {
|
|
|
|
frame = popupFrame;
|
2006-11-29 23:09:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-28 14:17:01 +00:00
|
|
|
PRBool captureRetarget = PR_FALSE;
|
|
|
|
if (capturingContent) {
|
2010-02-20 16:06:58 +00:00
|
|
|
// If a capture is active, determine if the docshell is visible. If not,
|
|
|
|
// clear the capture and target the mouse event normally instead. This
|
|
|
|
// would occur if the mouse button is held down while a tab change occurs.
|
|
|
|
// If the docshell is visible, look for a scrolling container.
|
|
|
|
PRBool vis;
|
|
|
|
nsCOMPtr<nsISupports> supports = mPresContext->GetContainer();
|
|
|
|
nsCOMPtr<nsIBaseWindow> baseWin(do_QueryInterface(supports));
|
|
|
|
if (baseWin && NS_SUCCEEDED(baseWin->GetVisibility(&vis)) && vis) {
|
|
|
|
captureRetarget = gCaptureInfo.mRetargetToElement;
|
|
|
|
if (!captureRetarget) {
|
|
|
|
// A check was already done above to ensure that capturingContent is
|
|
|
|
// in this presshell.
|
|
|
|
NS_ASSERTION(capturingContent->GetCurrentDoc() == GetDocument(),
|
|
|
|
"Unexpected document");
|
|
|
|
nsIFrame* captureFrame = capturingContent->GetPrimaryFrame();
|
|
|
|
if (captureFrame) {
|
|
|
|
if (capturingContent->Tag() == nsGkAtoms::select &&
|
|
|
|
capturingContent->IsHTML()) {
|
|
|
|
// a dropdown <select> has a child in its selectPopupList and we should
|
|
|
|
// capture on that instead.
|
|
|
|
nsIFrame* childFrame = captureFrame->GetChildList(nsGkAtoms::selectPopupList).FirstChild();
|
|
|
|
if (childFrame) {
|
|
|
|
captureFrame = childFrame;
|
|
|
|
}
|
2009-10-09 13:35:20 +00:00
|
|
|
}
|
|
|
|
|
2010-02-20 16:06:58 +00:00
|
|
|
// scrollable frames should use the scrolling container as
|
|
|
|
// the root instead of the document
|
|
|
|
nsIScrollableFrame* scrollFrame = do_QueryFrame(captureFrame);
|
|
|
|
if (scrollFrame) {
|
|
|
|
frame = scrollFrame->GetScrolledFrame();
|
|
|
|
}
|
2009-09-28 14:17:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-02-20 16:06:58 +00:00
|
|
|
else {
|
|
|
|
ClearMouseCapture(nsnull);
|
|
|
|
capturingContent = nsnull;
|
|
|
|
}
|
2009-09-28 14:17:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Get the frame at the event point. However, don't do this if we're
|
|
|
|
// capturing and retargeting the event because the captured frame will
|
|
|
|
// be used instead below.
|
|
|
|
if (!captureRetarget) {
|
2009-09-13 13:13:16 +00:00
|
|
|
nsPoint eventPoint
|
|
|
|
= nsLayoutUtils::GetEventCoordinatesRelativeTo(aEvent, frame);
|
|
|
|
{
|
|
|
|
PRBool ignoreRootScrollFrame = PR_FALSE;
|
|
|
|
if (aEvent->eventStructType == NS_MOUSE_EVENT) {
|
|
|
|
ignoreRootScrollFrame = static_cast<nsMouseEvent*>(aEvent)->ignoreRootScrollFrame;
|
|
|
|
}
|
2010-03-05 00:10:32 +00:00
|
|
|
nsIFrame* target = nsLayoutUtils::GetFrameForPoint(frame, eventPoint,
|
|
|
|
PR_FALSE, ignoreRootScrollFrame);
|
|
|
|
if (target) {
|
|
|
|
frame = target;
|
|
|
|
}
|
2008-10-27 20:16:23 +00:00
|
|
|
}
|
2008-01-30 04:53:46 +00:00
|
|
|
}
|
|
|
|
|
2009-09-28 14:17:01 +00:00
|
|
|
// if a node is capturing the mouse, check if the event needs to be
|
|
|
|
// retargeted at the capturing content instead. This will be the case when
|
|
|
|
// capture retargeting is being used, no frame was found or the frame's
|
|
|
|
// content is not a descendant of the capturing content.
|
|
|
|
if (capturingContent &&
|
2010-03-05 00:10:32 +00:00
|
|
|
(gCaptureInfo.mRetargetToElement || !frame->GetContent() ||
|
|
|
|
!nsContentUtils::ContentIsCrossDocDescendantOf(frame->GetContent(),
|
2009-09-28 14:17:01 +00:00
|
|
|
capturingContent))) {
|
|
|
|
// A check was already done above to ensure that capturingContent is
|
2010-02-20 16:06:58 +00:00
|
|
|
// in this presshell.
|
2009-12-24 21:20:06 +00:00
|
|
|
NS_ASSERTION(capturingContent->GetCurrentDoc() == GetDocument(),
|
|
|
|
"Unexpected document");
|
|
|
|
nsIFrame* capturingFrame = capturingContent->GetPrimaryFrame();
|
2009-09-28 14:17:01 +00:00
|
|
|
if (capturingFrame) {
|
2010-03-05 00:10:32 +00:00
|
|
|
frame = capturingFrame;
|
|
|
|
aView = frame->GetClosestView();
|
2009-09-28 14:17:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-05 00:10:32 +00:00
|
|
|
// Suppress mouse event if it's being targeted at an element inside
|
|
|
|
// a document which needs events suppressed
|
|
|
|
if (aEvent->eventStructType == NS_MOUSE_EVENT &&
|
|
|
|
frame->PresContext()->Document()->EventHandlingSuppressed()) {
|
|
|
|
if (aEvent->message == NS_MOUSE_BUTTON_DOWN) {
|
|
|
|
mNoDelayedMouseEvents = PR_TRUE;
|
|
|
|
} else if (!mNoDelayedMouseEvents && aEvent->message == NS_MOUSE_BUTTON_UP) {
|
|
|
|
nsDelayedEvent* event =
|
|
|
|
new nsDelayedMouseEvent(static_cast<nsMouseEvent*>(aEvent));
|
|
|
|
if (!mDelayedEvents.AppendElement(event)) {
|
|
|
|
delete event;
|
|
|
|
}
|
2006-01-26 02:29:17 +00:00
|
|
|
}
|
2010-03-05 00:10:32 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
2006-01-26 02:29:17 +00:00
|
|
|
}
|
2010-03-05 00:10:32 +00:00
|
|
|
|
|
|
|
PresShell* shell =
|
|
|
|
static_cast<PresShell*>(frame->PresContext()->PresShell());
|
|
|
|
if (shell != this) {
|
|
|
|
// Handle the event in the correct shell.
|
|
|
|
// Prevent deletion until we're done with event handling (bug 336582).
|
|
|
|
nsCOMPtr<nsIPresShell> kungFuDeathGrip(shell);
|
|
|
|
nsIView* subshellRootView;
|
|
|
|
shell->GetViewManager()->GetRootView(subshellRootView);
|
|
|
|
// We pass the subshell's root view as the view to start from. This is
|
|
|
|
// the only correct alternative; if the event was captured then it
|
|
|
|
// must have been captured by us or some ancestor shell and we
|
|
|
|
// now ask the subshell to dispatch it normally.
|
|
|
|
return shell->HandlePositionedEvent(subshellRootView, frame,
|
|
|
|
aEvent, aEventStatus);
|
2006-01-26 02:29:17 +00:00
|
|
|
}
|
2010-03-05 00:10:32 +00:00
|
|
|
|
|
|
|
return HandlePositionedEvent(aView, frame, aEvent, aEventStatus);
|
2006-01-26 02:29:17 +00:00
|
|
|
}
|
|
|
|
|
2003-05-12 07:11:16 +00:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
if (frame) {
|
2000-04-24 04:41:27 +00:00
|
|
|
PushCurrentEventInfo(nsnull, nsnull);
|
1999-05-20 23:16:53 +00:00
|
|
|
|
2010-06-15 05:05:37 +00:00
|
|
|
// key and IME related events go to the focused frame in this DOM window.
|
|
|
|
if (NS_IsEventTargetedAtFocusedContent(aEvent)) {
|
|
|
|
NS_ASSERTION(mDocument, "mDocument is null");
|
|
|
|
nsCOMPtr<nsPIDOMWindow> window =
|
|
|
|
do_QueryInterface(mDocument->GetWindow());
|
|
|
|
nsCOMPtr<nsPIDOMWindow> focusedWindow;
|
|
|
|
mCurrentEventContent =
|
|
|
|
nsFocusManager::GetFocusedDescendant(window, PR_FALSE,
|
|
|
|
getter_AddRefs(focusedWindow));
|
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 18:00:39 +00:00
|
|
|
|
|
|
|
// otherwise, if there is no focused content or the focused content has
|
|
|
|
// no frame, just use the root content. This ensures that key events
|
|
|
|
// still get sent to the window properly if nothing is focused or if a
|
|
|
|
// frame goes away while it is focused.
|
|
|
|
if (!mCurrentEventContent || !GetCurrentEventFrame())
|
2010-04-30 13:12:05 +00:00
|
|
|
mCurrentEventContent = mDocument->GetRootElement();
|
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 18:00:39 +00:00
|
|
|
mCurrentEventFrame = nsnull;
|
|
|
|
|
2010-01-28 04:12:29 +00:00
|
|
|
if (!mCurrentEventContent || !GetCurrentEventFrame() ||
|
|
|
|
InZombieDocument(mCurrentEventContent)) {
|
2006-10-27 00:01:19 +00:00
|
|
|
rv = RetargetEventToParent(aEvent, aEventStatus);
|
|
|
|
PopCurrentEventInfo();
|
|
|
|
return rv;
|
2003-05-12 07:11:16 +00:00
|
|
|
}
|
|
|
|
} else {
|
2006-01-26 02:29:17 +00:00
|
|
|
mCurrentEventFrame = frame;
|
1998-11-18 05:25:26 +00:00
|
|
|
}
|
2003-05-12 07:11:16 +00:00
|
|
|
if (GetCurrentEventFrame()) {
|
2006-03-07 17:08:51 +00:00
|
|
|
rv = HandleEventInternal(aEvent, aView, aEventStatus);
|
2003-05-12 07:11:16 +00:00
|
|
|
}
|
2006-01-26 02:29:17 +00:00
|
|
|
|
2000-02-03 02:49:58 +00:00
|
|
|
#ifdef NS_DEBUG
|
2006-01-26 02:29:17 +00:00
|
|
|
ShowEventTargetDebug();
|
2000-02-03 02:49:58 +00:00
|
|
|
#endif
|
2000-04-24 04:41:27 +00:00
|
|
|
PopCurrentEventInfo();
|
2006-01-26 02:29:17 +00:00
|
|
|
} else {
|
2009-10-01 17:53:10 +00:00
|
|
|
// Activation events need to be dispatched even if no frame was found, since
|
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 18:00:39 +00:00
|
|
|
// we don't want the focus to be out of sync.
|
2003-05-12 07:11:16 +00:00
|
|
|
|
|
|
|
if (!NS_EVENT_NEEDS_FRAME(aEvent)) {
|
|
|
|
mCurrentEventFrame = nsnull;
|
2006-03-07 17:08:51 +00:00
|
|
|
return HandleEventInternal(aEvent, aView, aEventStatus);
|
2003-05-12 07:11:16 +00:00
|
|
|
}
|
2003-07-24 08:48:59 +00:00
|
|
|
else if (NS_IS_KEY_EVENT(aEvent)) {
|
|
|
|
// Keypress events in new blank tabs should not be completely thrown away.
|
|
|
|
// Retarget them -- the parent chrome shell might make use of them.
|
2006-10-27 00:01:19 +00:00
|
|
|
return RetargetEventToParent(aEvent, aEventStatus);
|
2003-07-24 08:48:59 +00:00
|
|
|
}
|
2006-01-26 02:29:17 +00:00
|
|
|
}
|
2003-05-12 07:11:16 +00:00
|
|
|
|
2006-01-26 02:29:17 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef NS_DEBUG
|
|
|
|
void
|
|
|
|
PresShell::ShowEventTargetDebug()
|
|
|
|
{
|
2009-08-20 21:52:48 +00:00
|
|
|
if (nsFrame::GetShowEventTargetFrameBorder() &&
|
2007-02-20 20:22:19 +00:00
|
|
|
GetCurrentEventFrame()) {
|
|
|
|
if (mDrawEventTargetFrame) {
|
|
|
|
mDrawEventTargetFrame->Invalidate(
|
|
|
|
nsRect(nsPoint(0, 0), mDrawEventTargetFrame->GetSize()));
|
2006-01-26 02:29:17 +00:00
|
|
|
}
|
2007-02-20 20:22:19 +00:00
|
|
|
|
|
|
|
mDrawEventTargetFrame = mCurrentEventFrame;
|
|
|
|
mDrawEventTargetFrame->Invalidate(
|
|
|
|
nsRect(nsPoint(0, 0), mDrawEventTargetFrame->GetSize()));
|
2006-01-26 02:29:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
PresShell::HandlePositionedEvent(nsIView* aView,
|
|
|
|
nsIFrame* aTargetFrame,
|
|
|
|
nsGUIEvent* aEvent,
|
|
|
|
nsEventStatus* aEventStatus)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
PushCurrentEventInfo(nsnull, nsnull);
|
|
|
|
|
|
|
|
mCurrentEventFrame = aTargetFrame;
|
|
|
|
|
|
|
|
if (mCurrentEventFrame) {
|
|
|
|
nsCOMPtr<nsIContent> targetElement;
|
|
|
|
mCurrentEventFrame->GetContentForEvent(mPresContext, aEvent,
|
|
|
|
getter_AddRefs(targetElement));
|
|
|
|
|
|
|
|
// If there is no content for this frame, target it anyway. Some
|
|
|
|
// frames can be targeted but do not have content, particularly
|
|
|
|
// windows with scrolling off.
|
|
|
|
if (targetElement) {
|
|
|
|
// Bug 103055, bug 185889: mouse events apply to *elements*, not all
|
|
|
|
// nodes. Thus we get the nearest element parent here.
|
|
|
|
// XXX we leave the frame the same even if we find an element
|
|
|
|
// parent, so that the text frame will receive the event (selection
|
|
|
|
// and friends are the ones who care about that anyway)
|
|
|
|
//
|
|
|
|
// We use weak pointers because during this tight loop, the node
|
|
|
|
// will *not* go away. And this happens on every mousemove.
|
2010-04-30 13:12:06 +00:00
|
|
|
while (targetElement && !targetElement->IsElement()) {
|
2006-01-26 02:29:17 +00:00
|
|
|
targetElement = targetElement->GetParent();
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we found an element, target it. Otherwise, target *nothing*.
|
|
|
|
if (!targetElement) {
|
|
|
|
mCurrentEventContent = nsnull;
|
|
|
|
mCurrentEventFrame = nsnull;
|
|
|
|
} else if (targetElement != mCurrentEventContent) {
|
|
|
|
mCurrentEventContent = targetElement;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GetCurrentEventFrame()) {
|
2006-03-07 17:08:51 +00:00
|
|
|
rv = HandleEventInternal(aEvent, aView, aEventStatus);
|
1998-11-21 00:19:36 +00:00
|
|
|
}
|
1998-08-28 02:54:06 +00:00
|
|
|
|
2006-01-26 02:29:17 +00:00
|
|
|
#ifdef NS_DEBUG
|
|
|
|
ShowEventTargetDebug();
|
|
|
|
#endif
|
|
|
|
PopCurrentEventInfo();
|
1998-08-28 02:54:06 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2010-03-31 12:50:20 +00:00
|
|
|
nsresult
|
2006-03-07 17:08:51 +00:00
|
|
|
PresShell::HandleEventWithTarget(nsEvent* aEvent, nsIFrame* aFrame,
|
|
|
|
nsIContent* aContent, nsEventStatus* aStatus)
|
2000-04-24 04:41:27 +00:00
|
|
|
{
|
|
|
|
PushCurrentEventInfo(aFrame, aContent);
|
2010-03-31 12:50:20 +00:00
|
|
|
nsresult rv = HandleEventInternal(aEvent, nsnull, aStatus);
|
2000-04-24 04:41:27 +00:00
|
|
|
PopCurrentEventInfo();
|
2010-03-31 12:50:20 +00:00
|
|
|
return rv;
|
2000-04-24 04:41:27 +00:00
|
|
|
}
|
|
|
|
|
2010-03-24 03:36:27 +00:00
|
|
|
static inline PRBool
|
|
|
|
IsSynthesizedMouseEvent(nsEvent* aEvent)
|
2004-06-22 04:32:52 +00:00
|
|
|
{
|
|
|
|
return aEvent->eventStructType == NS_MOUSE_EVENT &&
|
2007-07-08 07:08:04 +00:00
|
|
|
static_cast<nsMouseEvent*>(aEvent)->reason != nsMouseEvent::eReal;
|
2004-06-22 04:32:52 +00:00
|
|
|
}
|
|
|
|
|
2009-08-13 09:11:42 +00:00
|
|
|
static PRBool CanHandleContextMenuEvent(nsMouseEvent* aMouseEvent,
|
|
|
|
nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
#if defined(XP_MACOSX) && defined(MOZ_XUL)
|
|
|
|
nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
|
|
|
|
if (pm) {
|
|
|
|
nsIFrame* popupFrame = pm->GetTopPopup(ePopupTypeMenu);
|
|
|
|
if (popupFrame) {
|
|
|
|
// context menus should not be opened while another menu is open on Mac,
|
|
|
|
// so return false so that the event is not fired.
|
|
|
|
if (aMouseEvent->context == nsMouseEvent::eContextMenuKey) {
|
|
|
|
return PR_FALSE;
|
|
|
|
} else if (aMouseEvent->widget) {
|
|
|
|
nsWindowType windowType;
|
|
|
|
aMouseEvent->widget->GetWindowType(windowType);
|
|
|
|
if (windowType == eWindowType_popup) {
|
|
|
|
for (nsIFrame* current = aFrame; current;
|
|
|
|
current = nsLayoutUtils::GetCrossDocParentFrame(current)) {
|
|
|
|
if (current->GetType() == nsGkAtoms::menuPopupFrame) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2000-04-24 04:41:27 +00:00
|
|
|
nsresult
|
2003-05-12 07:11:16 +00:00
|
|
|
PresShell::HandleEventInternal(nsEvent* aEvent, nsIView *aView,
|
2006-03-07 17:08:51 +00:00
|
|
|
nsEventStatus* aStatus)
|
2000-04-24 04:41:27 +00:00
|
|
|
{
|
2010-05-19 23:22:19 +00:00
|
|
|
NS_TIME_FUNCTION_MIN(1.0);
|
|
|
|
|
2001-08-17 03:13:07 +00:00
|
|
|
#ifdef ACCESSIBILITY
|
2001-04-01 01:01:33 +00:00
|
|
|
if (aEvent->eventStructType == NS_ACCESSIBLE_EVENT)
|
|
|
|
{
|
2010-05-12 06:47:35 +00:00
|
|
|
nsAccessibleEvent *accEvent = static_cast<nsAccessibleEvent*>(aEvent);
|
|
|
|
accEvent->mAccessible = nsnull;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIAccessibilityService> accService =
|
2003-04-15 08:45:55 +00:00
|
|
|
do_GetService("@mozilla.org/accessibilityService;1");
|
|
|
|
if (accService) {
|
2005-07-15 02:35:19 +00:00
|
|
|
nsCOMPtr<nsISupports> container = mPresContext->GetContainer();
|
|
|
|
if (!container) {
|
|
|
|
// This presshell is not active. This often happens when a
|
|
|
|
// preshell is being held onto for fastback.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2010-05-12 06:47:35 +00:00
|
|
|
|
2003-04-15 08:45:55 +00:00
|
|
|
nsCOMPtr<nsIDOMNode> domNode(do_QueryInterface(mDocument));
|
|
|
|
NS_ASSERTION(domNode, "No dom node for doc");
|
2010-05-12 06:47:35 +00:00
|
|
|
|
|
|
|
accEvent->mAccessible = accService->GetAccessibleInShell(domNode, this);
|
|
|
|
|
2007-05-04 18:09:02 +00:00
|
|
|
// Ensure this is set in case a11y was activated before any
|
|
|
|
// nsPresShells existed to observe "a11y-init-or-shutdown" topic
|
|
|
|
gIsAccessibilityActive = PR_TRUE;
|
2003-04-15 08:45:55 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-04-01 01:01:33 +00:00
|
|
|
}
|
2001-08-17 03:13:07 +00:00
|
|
|
#endif
|
2001-04-01 01:01:33 +00:00
|
|
|
|
2004-02-27 17:17:37 +00:00
|
|
|
nsCOMPtr<nsIEventStateManager> manager = mPresContext->EventStateManager();
|
|
|
|
nsresult rv = NS_OK;
|
2000-04-24 04:41:27 +00:00
|
|
|
|
2004-02-27 17:17:37 +00:00
|
|
|
if (!NS_EVENT_NEEDS_FRAME(aEvent) || GetCurrentEventFrame()) {
|
2004-09-04 19:28:46 +00:00
|
|
|
PRBool isHandlingUserInput = PR_FALSE;
|
|
|
|
|
2006-04-10 17:04:54 +00:00
|
|
|
if (NS_IS_TRUSTED_EVENT(aEvent)) {
|
2004-09-04 19:28:46 +00:00
|
|
|
switch (aEvent->message) {
|
2006-11-16 21:35:39 +00:00
|
|
|
case NS_MOUSE_BUTTON_DOWN:
|
|
|
|
case NS_MOUSE_BUTTON_UP:
|
2004-09-04 19:28:46 +00:00
|
|
|
case NS_KEY_PRESS:
|
|
|
|
case NS_KEY_DOWN:
|
|
|
|
case NS_KEY_UP:
|
|
|
|
isHandlingUserInput = PR_TRUE;
|
2009-10-29 11:11:02 +00:00
|
|
|
break;
|
|
|
|
case NS_DRAGDROP_DROP:
|
|
|
|
nsCOMPtr<nsIDragSession> session = nsContentUtils::GetDragSession();
|
|
|
|
if (session) {
|
|
|
|
PRBool onlyChromeDrop = PR_FALSE;
|
|
|
|
session->GetOnlyChromeDrop(&onlyChromeDrop);
|
|
|
|
if (onlyChromeDrop) {
|
|
|
|
aEvent->flags |= NS_EVENT_FLAG_ONLY_CHROME_DISPATCH;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2004-09-04 19:28:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-13 09:11:42 +00:00
|
|
|
if (aEvent->message == NS_CONTEXTMENU) {
|
|
|
|
nsMouseEvent* me = static_cast<nsMouseEvent*>(aEvent);
|
|
|
|
if (!CanHandleContextMenuEvent(me, GetCurrentEventFrame())) {
|
2009-01-17 20:50:00 +00:00
|
|
|
return NS_OK;
|
2009-08-13 09:11:42 +00:00
|
|
|
}
|
|
|
|
if (me->context == nsMouseEvent::eContextMenuKey &&
|
|
|
|
!AdjustContextMenuKeyEvent(me)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
2009-01-17 20:50:00 +00:00
|
|
|
|
2009-09-13 13:13:16 +00:00
|
|
|
nsAutoHandlingUserInputStatePusher userInpStatePusher(isHandlingUserInput,
|
|
|
|
aEvent->message == NS_MOUSE_BUTTON_DOWN);
|
2004-09-04 19:28:46 +00:00
|
|
|
|
|
|
|
nsAutoPopupStatePusher popupStatePusher(nsDOMEvent::GetEventPopupControlState(aEvent));
|
2000-04-24 04:41:27 +00:00
|
|
|
|
2006-03-12 20:12:36 +00:00
|
|
|
// FIXME. If the event was reused, we need to clear the old target,
|
|
|
|
// bug 329430
|
|
|
|
aEvent->target = nsnull;
|
|
|
|
|
2007-11-22 15:08:13 +00:00
|
|
|
nsWeakView weakView(aView);
|
2003-05-12 07:11:16 +00:00
|
|
|
// 1. Give event to event manager for pre event state changes and
|
|
|
|
// generation of synthetic events.
|
|
|
|
rv = manager->PreHandleEvent(mPresContext, aEvent, mCurrentEventFrame,
|
|
|
|
aStatus, aView);
|
|
|
|
|
|
|
|
// 2. Give event to the DOM for third party and JS use.
|
2008-12-12 08:34:43 +00:00
|
|
|
if (GetCurrentEventFrame() && NS_SUCCEEDED(rv)) {
|
2010-04-24 10:40:48 +00:00
|
|
|
PRBool wasHandlingKeyBoardEvent =
|
|
|
|
nsContentUtils::IsHandlingKeyBoardEvent();
|
|
|
|
if (aEvent->eventStructType == NS_KEY_EVENT) {
|
|
|
|
nsContentUtils::SetIsHandlingKeyBoardEvent(PR_TRUE);
|
|
|
|
}
|
2005-09-16 06:04:25 +00:00
|
|
|
// We want synthesized mouse moves to cause mouseover and mouseout
|
|
|
|
// DOM events (PreHandleEvent above), but not mousemove DOM events.
|
2010-03-24 03:36:27 +00:00
|
|
|
// Synthesized button up events also do not cause DOM events
|
|
|
|
// because they do not have a reliable refPoint.
|
|
|
|
if (!IsSynthesizedMouseEvent(aEvent)) {
|
2006-03-07 17:08:51 +00:00
|
|
|
nsPresShellEventCB eventCB(this);
|
2005-09-16 06:04:25 +00:00
|
|
|
if (mCurrentEventContent) {
|
2006-03-07 17:08:51 +00:00
|
|
|
nsEventDispatcher::Dispatch(mCurrentEventContent, mPresContext,
|
|
|
|
aEvent, nsnull, aStatus, &eventCB);
|
2005-09-16 06:04:25 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
nsCOMPtr<nsIContent> targetContent;
|
|
|
|
rv = mCurrentEventFrame->GetContentForEvent(mPresContext, aEvent,
|
|
|
|
getter_AddRefs(targetContent));
|
|
|
|
if (NS_SUCCEEDED(rv) && targetContent) {
|
2006-03-07 17:08:51 +00:00
|
|
|
nsEventDispatcher::Dispatch(targetContent, mPresContext, aEvent,
|
|
|
|
nsnull, aStatus, &eventCB);
|
2006-12-01 11:09:53 +00:00
|
|
|
} else if (mDocument) {
|
|
|
|
nsEventDispatcher::Dispatch(mDocument, mPresContext, aEvent,
|
|
|
|
nsnull, aStatus, nsnull);
|
2005-09-16 06:04:25 +00:00
|
|
|
}
|
2002-11-09 00:25:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-24 10:40:48 +00:00
|
|
|
nsContentUtils::SetIsHandlingKeyBoardEvent(wasHandlingKeyBoardEvent);
|
|
|
|
|
2006-03-07 17:08:51 +00:00
|
|
|
// 3. Give event to event manager for post event state changes and
|
2003-05-12 07:11:16 +00:00
|
|
|
// generation of synthetic events.
|
2008-12-12 08:34:43 +00:00
|
|
|
if (!mIsDestroying && NS_SUCCEEDED(rv)) {
|
2007-11-20 22:30:27 +00:00
|
|
|
rv = manager->PostHandleEvent(mPresContext, aEvent,
|
2007-11-22 15:08:13 +00:00
|
|
|
GetCurrentEventFrame(), aStatus,
|
|
|
|
weakView.GetView());
|
2000-04-24 04:41:27 +00:00
|
|
|
}
|
|
|
|
}
|
2009-09-13 13:13:16 +00:00
|
|
|
|
|
|
|
if (aEvent->message == NS_MOUSE_BUTTON_UP) {
|
|
|
|
// reset the capturing content now that the mouse button is up
|
|
|
|
SetCapturingContent(nsnull, 0);
|
|
|
|
}
|
2000-04-24 04:41:27 +00:00
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2000-06-29 02:02:43 +00:00
|
|
|
// Dispatch event to content only (NOT full processing)
|
|
|
|
// See also HandleEventWithTarget which does full event processing.
|
2010-03-31 12:50:20 +00:00
|
|
|
nsresult
|
2006-03-07 17:08:51 +00:00
|
|
|
PresShell::HandleDOMEventWithTarget(nsIContent* aTargetContent, nsEvent* aEvent,
|
|
|
|
nsEventStatus* aStatus)
|
2000-06-29 02:02:43 +00:00
|
|
|
{
|
2010-03-31 12:50:20 +00:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
2000-06-29 02:02:43 +00:00
|
|
|
PushCurrentEventInfo(nsnull, aTargetContent);
|
|
|
|
|
|
|
|
// Bug 41013: Check if the event should be dispatched to content.
|
|
|
|
// It's possible that we are in the middle of destroying the window
|
|
|
|
// and the js context is out of date. This check detects the case
|
|
|
|
// that caused a crash in bug 41013, but there may be a better way
|
|
|
|
// to handle this situation!
|
2004-02-01 10:09:07 +00:00
|
|
|
nsCOMPtr<nsISupports> container = mPresContext->GetContainer();
|
|
|
|
if (container) {
|
2000-06-29 02:02:43 +00:00
|
|
|
|
|
|
|
// Dispatch event to content
|
2010-03-31 12:50:20 +00:00
|
|
|
rv = nsEventDispatcher::Dispatch(aTargetContent, mPresContext, aEvent, nsnull,
|
|
|
|
aStatus);
|
2000-06-29 02:02:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PopCurrentEventInfo();
|
2010-03-31 12:50:20 +00:00
|
|
|
return rv;
|
2000-06-29 02:02:43 +00:00
|
|
|
}
|
|
|
|
|
2009-06-30 07:56:40 +00:00
|
|
|
// See the method above.
|
2010-03-31 12:50:20 +00:00
|
|
|
nsresult
|
2009-06-30 07:56:40 +00:00
|
|
|
PresShell::HandleDOMEventWithTarget(nsIContent* aTargetContent,
|
|
|
|
nsIDOMEvent* aEvent,
|
|
|
|
nsEventStatus* aStatus)
|
|
|
|
{
|
2010-03-31 12:50:20 +00:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
2009-06-30 07:56:40 +00:00
|
|
|
PushCurrentEventInfo(nsnull, aTargetContent);
|
|
|
|
nsCOMPtr<nsISupports> container = mPresContext->GetContainer();
|
|
|
|
if (container) {
|
2010-03-31 12:50:20 +00:00
|
|
|
rv = nsEventDispatcher::DispatchDOMEvent(aTargetContent, nsnull, aEvent,
|
|
|
|
mPresContext, aStatus);
|
2009-06-30 07:56:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PopCurrentEventInfo();
|
2010-03-31 12:50:20 +00:00
|
|
|
return rv;
|
2009-06-30 07:56:40 +00:00
|
|
|
}
|
|
|
|
|
2009-01-17 20:50:00 +00:00
|
|
|
PRBool
|
|
|
|
PresShell::AdjustContextMenuKeyEvent(nsMouseEvent* aEvent)
|
|
|
|
{
|
|
|
|
#ifdef MOZ_XUL
|
2009-08-13 09:11:42 +00:00
|
|
|
// if a menu is open, open the context menu relative to the active item on the menu.
|
2009-01-17 20:50:00 +00:00
|
|
|
nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
|
|
|
|
if (pm) {
|
|
|
|
nsIFrame* popupFrame = pm->GetTopPopup(ePopupTypeMenu);
|
|
|
|
if (popupFrame) {
|
|
|
|
nsIFrame* itemFrame =
|
|
|
|
(static_cast<nsMenuPopupFrame *>(popupFrame))->GetCurrentMenuItem();
|
|
|
|
if (!itemFrame)
|
|
|
|
itemFrame = popupFrame;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIWidget> widget = popupFrame->GetWindow();
|
|
|
|
aEvent->widget = widget;
|
2009-02-19 00:11:49 +00:00
|
|
|
nsIntPoint widgetPoint = widget->WidgetToScreenOffset();
|
|
|
|
aEvent->refPoint = itemFrame->GetScreenRect().BottomLeft() - widgetPoint;
|
2009-01-17 20:50:00 +00:00
|
|
|
|
|
|
|
mCurrentEventContent = itemFrame->GetContent();
|
|
|
|
mCurrentEventFrame = itemFrame;
|
|
|
|
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// If we're here because of the key-equiv for showing context menus, we
|
|
|
|
// have to twiddle with the NS event to make sure the context menu comes
|
|
|
|
// up in the upper left of the relevant content area before we create
|
|
|
|
// the DOM event. Since we never call InitMouseEvent() on the event,
|
|
|
|
// the client X/Y will be 0,0. We can make use of that if the widget is null.
|
2009-07-22 00:45:08 +00:00
|
|
|
// Use the root view manager's widget since it's most likely to have one,
|
|
|
|
// and the coordinates returned by GetCurrentItemAndPositionForElement
|
|
|
|
// are relative to the root of the root view manager.
|
2010-01-26 13:10:12 +00:00
|
|
|
nsRootPresContext* rootPC = mPresContext->GetRootPresContext();
|
|
|
|
if (rootPC) {
|
|
|
|
rootPC->PresShell()->GetViewManager()->
|
|
|
|
GetRootWidget(getter_AddRefs(aEvent->widget));
|
|
|
|
} else {
|
|
|
|
aEvent->widget = nsnull;
|
|
|
|
}
|
2009-01-17 20:50:00 +00:00
|
|
|
aEvent->refPoint.x = 0;
|
|
|
|
aEvent->refPoint.y = 0;
|
|
|
|
|
|
|
|
// see if we should use the caret position for the popup
|
2009-01-17 21:14:18 +00:00
|
|
|
nsIntPoint caretPoint;
|
2009-01-17 20:50:00 +00:00
|
|
|
// Beware! This may flush notifications via synchronous
|
|
|
|
// ScrollSelectionIntoView.
|
|
|
|
if (PrepareToUseCaretPosition(aEvent->widget, caretPoint)) {
|
|
|
|
// caret position is good
|
|
|
|
aEvent->refPoint = caretPoint;
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we're here because of the key-equiv for showing context menus, we
|
|
|
|
// have to reset the event target to the currently focused element. Get it
|
|
|
|
// from the focus controller.
|
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 18:00:39 +00:00
|
|
|
nsCOMPtr<nsIDOMElement> currentFocus;
|
|
|
|
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
|
|
|
|
if (fm)
|
|
|
|
fm->GetFocusedElement(getter_AddRefs(currentFocus));
|
|
|
|
|
|
|
|
// Reset event coordinates relative to focused frame in view
|
|
|
|
if (currentFocus) {
|
|
|
|
nsCOMPtr<nsIContent> currentPointElement;
|
|
|
|
GetCurrentItemAndPositionForElement(currentFocus,
|
|
|
|
getter_AddRefs(currentPointElement),
|
|
|
|
aEvent->refPoint);
|
|
|
|
if (currentPointElement) {
|
|
|
|
mCurrentEventContent = currentPointElement;
|
|
|
|
mCurrentEventFrame = nsnull;
|
|
|
|
GetCurrentEventFrame();
|
2009-01-17 20:50:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// nsEventListenerManager::PrepareToUseCaretPosition
|
|
|
|
//
|
|
|
|
// This checks to see if we should use the caret position for popup context
|
|
|
|
// menus. Returns true if the caret position should be used, and the
|
|
|
|
// coordinates of that position is returned in aTargetPt. This function
|
|
|
|
// will also scroll the window as needed to make the caret visible.
|
|
|
|
//
|
|
|
|
// The event widget should be the widget that generated the event, and
|
|
|
|
// whose coordinate system the resulting event's refPoint should be
|
|
|
|
// relative to. The returned point is in device pixels realtive to the
|
|
|
|
// widget passed in.
|
|
|
|
PRBool
|
|
|
|
PresShell::PrepareToUseCaretPosition(nsIWidget* aEventWidget, nsIntPoint& aTargetPt)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
// check caret visibility
|
2010-03-31 12:39:31 +00:00
|
|
|
nsRefPtr<nsCaret> caret = GetCaret();
|
2009-01-17 20:50:00 +00:00
|
|
|
NS_ENSURE_TRUE(caret, PR_FALSE);
|
|
|
|
|
|
|
|
PRBool caretVisible = PR_FALSE;
|
|
|
|
rv = caret->GetCaretVisible(&caretVisible);
|
|
|
|
if (NS_FAILED(rv) || ! caretVisible)
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
// caret selection, this is a temporary weak reference, so no refcounting is
|
|
|
|
// needed
|
|
|
|
nsISelection* domSelection = caret->GetCaretDOMSelection();
|
|
|
|
NS_ENSURE_TRUE(domSelection, PR_FALSE);
|
|
|
|
|
|
|
|
// since the match could be an anonymous textnode inside a
|
|
|
|
// <textarea> or text <input>, we need to get the outer frame
|
|
|
|
// note: frames are not refcounted
|
|
|
|
nsIFrame* frame = nsnull; // may be NULL
|
|
|
|
nsCOMPtr<nsIDOMNode> node;
|
|
|
|
rv = domSelection->GetFocusNode(getter_AddRefs(node));
|
|
|
|
NS_ENSURE_SUCCESS(rv, PR_FALSE);
|
|
|
|
NS_ENSURE_TRUE(node, PR_FALSE);
|
|
|
|
nsCOMPtr<nsIContent> content(do_QueryInterface(node));
|
|
|
|
if (content) {
|
|
|
|
nsIContent* nonNative = content->FindFirstNonNativeAnonymous();
|
|
|
|
content = nonNative;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (content) {
|
|
|
|
// It seems like ScrollSelectionIntoView should be enough, but it's
|
|
|
|
// not. The problem is that scrolling the selection into view when it is
|
|
|
|
// below the current viewport will align the top line of the frame exactly
|
|
|
|
// with the bottom of the window. This is fine, BUT, the popup event causes
|
|
|
|
// the control to be re-focused which does this exact call to
|
|
|
|
// ScrollContentIntoView, which has a one-pixel disagreement of whether the
|
|
|
|
// frame is actually in view. The result is that the frame is aligned with
|
|
|
|
// the top of the window, but the menu is still at the bottom.
|
|
|
|
//
|
|
|
|
// Doing this call first forces the frame to be in view, eliminating the
|
|
|
|
// problem. The only difference in the result is that if your cursor is in
|
|
|
|
// an edit box below the current view, you'll get the edit box aligned with
|
|
|
|
// the top of the window. This is arguably better behavior anyway.
|
|
|
|
rv = ScrollContentIntoView(content, NS_PRESSHELL_SCROLL_IF_NOT_VISIBLE,
|
|
|
|
NS_PRESSHELL_SCROLL_IF_NOT_VISIBLE);
|
|
|
|
NS_ENSURE_SUCCESS(rv, PR_FALSE);
|
2009-12-24 21:20:06 +00:00
|
|
|
frame = content->GetPrimaryFrame();
|
2009-01-17 20:50:00 +00:00
|
|
|
NS_WARN_IF_FALSE(frame, "No frame for focused content?");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Actually scroll the selection (ie caret) into view. Note that this must
|
|
|
|
// be synchronous since we will be checking the caret position on the screen.
|
|
|
|
//
|
|
|
|
// Be easy about errors, and just don't scroll in those cases. Better to have
|
|
|
|
// the correct menu at a weird place than the wrong menu.
|
|
|
|
// After ScrollSelectionIntoView(), the pending notifications might be
|
|
|
|
// flushed and PresShell/PresContext/Frames may be dead. See bug 418470.
|
|
|
|
nsCOMPtr<nsISelectionController> selCon;
|
|
|
|
if (frame)
|
|
|
|
frame->GetSelectionController(GetPresContext(), getter_AddRefs(selCon));
|
|
|
|
else
|
|
|
|
selCon = static_cast<nsISelectionController *>(this);
|
|
|
|
if (selCon) {
|
|
|
|
rv = selCon->ScrollSelectionIntoView(nsISelectionController::SELECTION_NORMAL,
|
|
|
|
nsISelectionController::SELECTION_FOCUS_REGION, PR_TRUE);
|
|
|
|
NS_ENSURE_SUCCESS(rv, PR_FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
// get caret position relative to some view (normally the same as the
|
|
|
|
// event widget view, but this is not guaranteed)
|
|
|
|
nsRect caretCoords;
|
2010-03-14 22:52:07 +00:00
|
|
|
nsIFrame* caretFrame = caret->GetGeometry(domSelection, &caretCoords);
|
|
|
|
if (!caretFrame)
|
|
|
|
return PR_FALSE;
|
|
|
|
nsPoint windowOffset;
|
|
|
|
nsIWidget* widget = caretFrame->GetWindowOffset(windowOffset);
|
|
|
|
if (!widget)
|
|
|
|
return PR_FALSE;
|
|
|
|
caretCoords.MoveBy(windowOffset);
|
|
|
|
nsIView* caretView = nsIView::GetViewFor(widget);
|
2009-01-17 20:50:00 +00:00
|
|
|
|
|
|
|
// in case the view used for caret coordinates was something else, we need
|
|
|
|
// to bring those coordinates into the space of the widget view
|
|
|
|
nsIView* widgetView = nsIView::GetViewFor(aEventWidget);
|
|
|
|
NS_ENSURE_TRUE(widgetView, PR_FALSE);
|
|
|
|
nsPoint viewToWidget;
|
|
|
|
widgetView->GetNearestWidget(&viewToWidget);
|
2010-03-14 22:52:07 +00:00
|
|
|
nsPoint viewDelta = caretView->GetOffsetTo(widgetView) + viewToWidget;
|
2009-01-17 20:50:00 +00:00
|
|
|
|
|
|
|
// caret coordinates are in app units, convert to pixels
|
|
|
|
nsPresContext* presContext = GetPresContext();
|
|
|
|
aTargetPt.x = presContext->AppUnitsToDevPixels(viewDelta.x + caretCoords.x + caretCoords.width);
|
|
|
|
aTargetPt.y = presContext->AppUnitsToDevPixels(viewDelta.y + caretCoords.y + caretCoords.height);
|
|
|
|
|
2010-01-09 15:51:00 +00:00
|
|
|
// make sure rounding doesn't return a pixel which is outside the caret
|
|
|
|
// (e.g. one line lower)
|
|
|
|
aTargetPt.y -= 1;
|
|
|
|
|
2009-01-17 20:50:00 +00:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PresShell::GetCurrentItemAndPositionForElement(nsIDOMElement *aCurrentEl,
|
|
|
|
nsIContent** aTargetToUse,
|
|
|
|
nsIntPoint& aTargetPt)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIContent> focusedContent(do_QueryInterface(aCurrentEl));
|
|
|
|
ScrollContentIntoView(focusedContent, NS_PRESSHELL_SCROLL_ANYWHERE,
|
|
|
|
NS_PRESSHELL_SCROLL_ANYWHERE);
|
|
|
|
|
|
|
|
PRBool istree = PR_FALSE, checkLineHeight = PR_TRUE;
|
|
|
|
PRInt32 extraPixelsY = 0, extraTreeY = 0;
|
|
|
|
|
|
|
|
#ifdef MOZ_XUL
|
|
|
|
// Set the position to just underneath the current item for multi-select
|
|
|
|
// lists or just underneath the selected item for single-select lists. If
|
|
|
|
// the element is not a list, or there is no selection, leave the position
|
|
|
|
// as is.
|
|
|
|
nsCOMPtr<nsIDOMXULSelectControlItemElement> item;
|
|
|
|
nsCOMPtr<nsIDOMXULMultiSelectControlElement> multiSelect =
|
|
|
|
do_QueryInterface(aCurrentEl);
|
|
|
|
if (multiSelect) {
|
|
|
|
checkLineHeight = PR_FALSE;
|
|
|
|
|
|
|
|
PRInt32 currentIndex;
|
|
|
|
multiSelect->GetCurrentIndex(¤tIndex);
|
|
|
|
if (currentIndex >= 0) {
|
|
|
|
nsCOMPtr<nsIDOMXULElement> xulElement(do_QueryInterface(aCurrentEl));
|
|
|
|
if (xulElement) {
|
|
|
|
nsCOMPtr<nsIBoxObject> box;
|
|
|
|
xulElement->GetBoxObject(getter_AddRefs(box));
|
|
|
|
nsCOMPtr<nsITreeBoxObject> treeBox(do_QueryInterface(box));
|
|
|
|
// Tree view special case (tree items have no frames)
|
|
|
|
// Get the focused row and add its coordinates, which are already in pixels
|
|
|
|
// XXX Boris, should we create a new interface so that this doesn't
|
|
|
|
// need to know about trees? Something like nsINodelessChildCreator which
|
|
|
|
// could provide the current focus coordinates?
|
|
|
|
if (treeBox) {
|
|
|
|
treeBox->EnsureRowIsVisible(currentIndex);
|
|
|
|
PRInt32 firstVisibleRow, rowHeight;
|
|
|
|
treeBox->GetFirstVisibleRow(&firstVisibleRow);
|
|
|
|
treeBox->GetRowHeight(&rowHeight);
|
|
|
|
|
|
|
|
extraPixelsY = (currentIndex - firstVisibleRow + 1) * rowHeight;
|
|
|
|
istree = PR_TRUE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsITreeColumns> cols;
|
|
|
|
treeBox->GetColumns(getter_AddRefs(cols));
|
|
|
|
if (cols) {
|
|
|
|
nsCOMPtr<nsITreeColumn> col;
|
|
|
|
cols->GetFirstColumn(getter_AddRefs(col));
|
|
|
|
if (col) {
|
|
|
|
nsCOMPtr<nsIDOMElement> colElement;
|
|
|
|
col->GetElement(getter_AddRefs(colElement));
|
|
|
|
nsCOMPtr<nsIContent> colContent(do_QueryInterface(colElement));
|
|
|
|
if (colContent) {
|
2009-12-24 21:20:06 +00:00
|
|
|
nsIFrame* frame = colContent->GetPrimaryFrame();
|
2009-01-17 20:50:00 +00:00
|
|
|
if (frame) {
|
|
|
|
extraTreeY = frame->GetSize().height;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
multiSelect->GetCurrentItem(getter_AddRefs(item));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// don't check menulists as the selected item will be inside a popup.
|
|
|
|
nsCOMPtr<nsIDOMXULMenuListElement> menulist = do_QueryInterface(aCurrentEl);
|
|
|
|
if (!menulist) {
|
|
|
|
checkLineHeight = PR_FALSE;
|
|
|
|
nsCOMPtr<nsIDOMXULSelectControlElement> select =
|
|
|
|
do_QueryInterface(aCurrentEl);
|
|
|
|
if (select)
|
|
|
|
select->GetSelectedItem(getter_AddRefs(item));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (item)
|
|
|
|
focusedContent = do_QueryInterface(item);
|
|
|
|
#endif
|
|
|
|
|
2009-12-24 21:20:06 +00:00
|
|
|
nsIFrame *frame = focusedContent->GetPrimaryFrame();
|
2009-01-17 20:50:00 +00:00
|
|
|
if (frame) {
|
|
|
|
nsPoint frameOrigin(0, 0);
|
|
|
|
|
|
|
|
// Get the frame's origin within its view
|
|
|
|
nsIView *view = frame->GetClosestView(&frameOrigin);
|
|
|
|
NS_ASSERTION(view, "No view for frame");
|
|
|
|
|
2009-07-22 00:45:08 +00:00
|
|
|
// View's origin within the view manager tree
|
|
|
|
frameOrigin += view->GetOffsetTo(nsnull);
|
2009-01-17 20:50:00 +00:00
|
|
|
|
|
|
|
// Start context menu down and to the right from top left of frame
|
|
|
|
// use the lineheight. This is a good distance to move the context
|
|
|
|
// menu away from the top left corner of the frame. If we always
|
|
|
|
// used the frame height, the context menu could end up far away,
|
|
|
|
// for example when we're focused on linked images.
|
|
|
|
// On the other hand, we want to use the frame height if it's less
|
|
|
|
// than the current line height, so that the context menu appears
|
|
|
|
// associated with the correct frame.
|
|
|
|
nscoord extra = 0;
|
|
|
|
if (!istree) {
|
|
|
|
extra = frame->GetSize().height;
|
|
|
|
if (checkLineHeight) {
|
2009-09-01 11:29:27 +00:00
|
|
|
nsIScrollableFrame *scrollFrame =
|
|
|
|
nsLayoutUtils::GetNearestScrollableFrame(frame);
|
|
|
|
if (scrollFrame) {
|
|
|
|
nscoord scrollFrameLineHeight =
|
|
|
|
scrollFrame->GetLineScrollAmount().height;
|
|
|
|
if (extra > scrollFrameLineHeight) {
|
|
|
|
extra = scrollFrameLineHeight;
|
2009-01-17 20:50:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsPresContext* presContext = GetPresContext();
|
|
|
|
aTargetPt.x = presContext->AppUnitsToDevPixels(frameOrigin.x);
|
|
|
|
aTargetPt.y = presContext->AppUnitsToDevPixels(
|
|
|
|
frameOrigin.y + extra + extraTreeY) + extraPixelsY;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IF_ADDREF(*aTargetToUse = focusedContent);
|
|
|
|
}
|
|
|
|
|
1998-12-18 15:54:23 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
PresShell::ResizeReflow(nsIView *aView, nscoord aWidth, nscoord aHeight)
|
1998-08-28 02:54:06 +00:00
|
|
|
{
|
|
|
|
return ResizeReflow(aWidth, aHeight);
|
|
|
|
}
|
|
|
|
|
2004-10-14 21:51:00 +00:00
|
|
|
NS_IMETHODIMP_(PRBool)
|
|
|
|
PresShell::IsVisible()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsISupports> container = mPresContext->GetContainer();
|
|
|
|
nsCOMPtr<nsIBaseWindow> bw = do_QueryInterface(container);
|
|
|
|
if (!bw)
|
|
|
|
return PR_FALSE;
|
|
|
|
PRBool res = PR_TRUE;
|
|
|
|
bw->GetVisibility(&res);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2005-01-20 03:39:09 +00:00
|
|
|
NS_IMETHODIMP_(void)
|
|
|
|
PresShell::WillPaint()
|
|
|
|
{
|
2008-12-20 14:28:19 +00:00
|
|
|
// Don't bother reflowing if some viewmanager in our tree is painting while
|
2005-02-25 04:03:13 +00:00
|
|
|
// we still have painting suppressed.
|
2008-12-20 14:28:19 +00:00
|
|
|
if (mPaintingSuppressed) {
|
2005-01-20 03:39:09 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Process reflows, if we have them, to reduce flicker due to invalidates and
|
|
|
|
// reflow being interspersed. Note that we _do_ allow this to be
|
|
|
|
// interruptible; if we can't do all the reflows it's better to flicker a bit
|
|
|
|
// than to freeze up.
|
2009-04-21 23:53:52 +00:00
|
|
|
FlushPendingNotifications(Flush_InterruptibleLayout);
|
2005-01-20 03:39:09 +00:00
|
|
|
}
|
|
|
|
|
2004-01-07 22:30:53 +00:00
|
|
|
nsresult
|
|
|
|
PresShell::GetAgentStyleSheets(nsCOMArray<nsIStyleSheet>& aSheets)
|
|
|
|
{
|
|
|
|
aSheets.Clear();
|
|
|
|
PRInt32 sheetCount = mStyleSet->SheetCount(nsStyleSet::eAgentSheet);
|
|
|
|
|
|
|
|
for (PRInt32 i = 0; i < sheetCount; ++i) {
|
|
|
|
nsIStyleSheet *sheet = mStyleSet->StyleSheetAt(nsStyleSet::eAgentSheet, i);
|
|
|
|
if (!aSheets.AppendObject(sheet))
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
PresShell::SetAgentStyleSheets(const nsCOMArray<nsIStyleSheet>& aSheets)
|
|
|
|
{
|
|
|
|
return mStyleSet->ReplaceSheets(nsStyleSet::eAgentSheet, aSheets);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
PresShell::AddOverrideStyleSheet(nsIStyleSheet *aSheet)
|
|
|
|
{
|
2004-07-28 07:08:41 +00:00
|
|
|
return mStyleSet->PrependStyleSheet(nsStyleSet::eOverrideSheet, aSheet);
|
2004-01-07 22:30:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
PresShell::RemoveOverrideStyleSheet(nsIStyleSheet *aSheet)
|
|
|
|
{
|
|
|
|
return mStyleSet->RemoveStyleSheet(nsStyleSet::eOverrideSheet, aSheet);
|
|
|
|
}
|
|
|
|
|
2005-05-04 20:22:32 +00:00
|
|
|
static void
|
2009-12-24 21:20:06 +00:00
|
|
|
FreezeElement(nsIContent *aContent, void * /* unused */)
|
2005-05-04 20:22:32 +00:00
|
|
|
{
|
2009-12-24 21:20:06 +00:00
|
|
|
nsIFrame *frame = aContent->GetPrimaryFrame();
|
2009-05-08 01:32:32 +00:00
|
|
|
nsIObjectFrame *objectFrame = do_QueryFrame(frame);
|
|
|
|
if (objectFrame) {
|
|
|
|
objectFrame->StopPlugin();
|
|
|
|
}
|
2008-07-09 08:22:20 +00:00
|
|
|
}
|
|
|
|
|
2008-10-10 15:04:34 +00:00
|
|
|
static PRBool
|
2005-05-04 20:22:32 +00:00
|
|
|
FreezeSubDocument(nsIDocument *aDocument, void *aData)
|
|
|
|
{
|
2007-05-01 22:24:20 +00:00
|
|
|
nsIPresShell *shell = aDocument->GetPrimaryShell();
|
2005-05-04 20:22:32 +00:00
|
|
|
if (shell)
|
|
|
|
shell->Freeze();
|
|
|
|
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PresShell::Freeze()
|
|
|
|
{
|
2009-12-10 18:58:33 +00:00
|
|
|
MaybeReleaseCapturingContent();
|
|
|
|
|
2009-12-24 21:20:06 +00:00
|
|
|
mDocument->EnumerateFreezableElements(FreezeElement, nsnull);
|
2005-05-04 20:22:32 +00:00
|
|
|
|
|
|
|
if (mCaret)
|
|
|
|
mCaret->SetCaretVisible(PR_FALSE);
|
|
|
|
|
2005-07-01 07:12:02 +00:00
|
|
|
mPaintingSuppressed = PR_TRUE;
|
|
|
|
|
2005-05-04 20:22:32 +00:00
|
|
|
if (mDocument)
|
|
|
|
mDocument->EnumerateSubDocuments(FreezeSubDocument, nsnull);
|
2010-02-03 21:17:55 +00:00
|
|
|
|
|
|
|
nsPresContext* presContext = GetPresContext();
|
|
|
|
if (presContext) {
|
|
|
|
presContext->RefreshDriver()->Freeze();
|
|
|
|
}
|
2005-05-04 20:22:32 +00:00
|
|
|
}
|
|
|
|
|
2009-03-03 20:11:14 +00:00
|
|
|
void
|
|
|
|
PresShell::FireOrClearDelayedEvents(PRBool aFireEvents)
|
|
|
|
{
|
2009-05-18 09:17:45 +00:00
|
|
|
mNoDelayedMouseEvents = PR_FALSE;
|
|
|
|
mNoDelayedKeyEvents = PR_FALSE;
|
2009-03-03 20:11:14 +00:00
|
|
|
if (!aFireEvents) {
|
2009-05-18 09:17:45 +00:00
|
|
|
mDelayedEvents.Clear();
|
2009-03-03 20:11:14 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-06-16 18:46:24 +00:00
|
|
|
if (mDocument) {
|
2009-03-03 20:11:14 +00:00
|
|
|
nsCOMPtr<nsIDocument> doc = mDocument;
|
2009-06-16 18:46:24 +00:00
|
|
|
while (!mIsDestroying && mDelayedEvents.Length() &&
|
|
|
|
!doc->EventHandlingSuppressed()) {
|
|
|
|
nsAutoPtr<nsDelayedEvent> ev(mDelayedEvents[0].forget());
|
2009-05-18 09:17:45 +00:00
|
|
|
mDelayedEvents.RemoveElementAt(0);
|
2009-06-16 18:46:24 +00:00
|
|
|
ev->Dispatch(this);
|
2009-03-03 20:11:14 +00:00
|
|
|
}
|
2009-03-03 20:20:11 +00:00
|
|
|
if (!doc->EventHandlingSuppressed()) {
|
2009-05-18 09:17:45 +00:00
|
|
|
mDelayedEvents.Clear();
|
2009-03-03 20:11:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-05-04 20:22:32 +00:00
|
|
|
static void
|
2009-05-08 01:32:32 +00:00
|
|
|
ThawElement(nsIContent *aContent, void *aShell)
|
2005-05-04 20:22:32 +00:00
|
|
|
{
|
2009-05-08 01:32:32 +00:00
|
|
|
nsCOMPtr<nsIObjectLoadingContent> objlc(do_QueryInterface(aContent));
|
|
|
|
if (objlc) {
|
|
|
|
nsCOMPtr<nsIPluginInstance> inst;
|
|
|
|
objlc->EnsureInstantiation(getter_AddRefs(inst));
|
|
|
|
}
|
2008-07-09 08:22:20 +00:00
|
|
|
}
|
|
|
|
|
2008-10-10 15:04:34 +00:00
|
|
|
static PRBool
|
2005-05-04 20:22:32 +00:00
|
|
|
ThawSubDocument(nsIDocument *aDocument, void *aData)
|
|
|
|
{
|
2007-05-01 22:24:20 +00:00
|
|
|
nsIPresShell *shell = aDocument->GetPrimaryShell();
|
2005-05-04 20:22:32 +00:00
|
|
|
if (shell)
|
2005-07-19 17:07:40 +00:00
|
|
|
shell->Thaw();
|
2005-05-04 20:22:32 +00:00
|
|
|
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2005-07-19 17:07:40 +00:00
|
|
|
PresShell::Thaw()
|
2005-05-04 20:22:32 +00:00
|
|
|
{
|
2010-02-03 21:17:55 +00:00
|
|
|
nsPresContext* presContext = GetPresContext();
|
|
|
|
if (presContext) {
|
|
|
|
presContext->RefreshDriver()->Thaw();
|
|
|
|
}
|
|
|
|
|
2009-05-08 01:32:32 +00:00
|
|
|
mDocument->EnumerateFreezableElements(ThawElement, this);
|
2005-05-04 20:22:32 +00:00
|
|
|
|
|
|
|
if (mDocument)
|
|
|
|
mDocument->EnumerateSubDocuments(ThawSubDocument, nsnull);
|
2005-07-01 07:12:02 +00:00
|
|
|
|
2005-07-19 17:07:40 +00:00
|
|
|
UnsuppressPainting();
|
2005-05-04 20:22:32 +00:00
|
|
|
}
|
|
|
|
|
2010-02-19 17:11:40 +00:00
|
|
|
void
|
|
|
|
PresShell::WillRefresh(mozilla::TimeStamp aTime)
|
|
|
|
{
|
|
|
|
// Remove ourselves as a refresh observer; we'll readd during the
|
|
|
|
// flush if needed.
|
|
|
|
GetPresContext()->RefreshDriver()->RemoveRefreshObserver(this, Flush_Layout);
|
|
|
|
mReflowScheduled = PR_FALSE;
|
|
|
|
// Allow interruptible reflows now, since that's what the refresh
|
|
|
|
// driver will issue.
|
|
|
|
mSuppressInterruptibleReflows = PR_FALSE;
|
2007-01-17 22:28:33 +00:00
|
|
|
|
2010-02-19 17:11:40 +00:00
|
|
|
ASSERT_REFLOW_SCHEDULED_STATE();
|
2000-04-17 07:13:57 +00:00
|
|
|
}
|
|
|
|
|
2010-02-19 17:11:40 +00:00
|
|
|
//--------------------------------------------------------
|
|
|
|
// Start of protected and private methods on the PresShell
|
|
|
|
//--------------------------------------------------------
|
2000-04-17 07:13:57 +00:00
|
|
|
|
|
|
|
void
|
2010-02-19 17:11:40 +00:00
|
|
|
PresShell::MaybeScheduleReflow()
|
2000-04-17 07:13:57 +00:00
|
|
|
{
|
2010-02-19 17:11:40 +00:00
|
|
|
ASSERT_REFLOW_SCHEDULED_STATE();
|
|
|
|
if (mReflowScheduled || mIsDestroying || mIsReflowing ||
|
2009-02-03 14:42:18 +00:00
|
|
|
mDirtyRoots.Length() == 0)
|
2006-05-10 17:30:15 +00:00
|
|
|
return;
|
|
|
|
|
2010-02-19 17:11:40 +00:00
|
|
|
if (!mPresContext->HasPendingInterrupt() || !ScheduleReflowOffTimer()) {
|
|
|
|
ScheduleReflow();
|
2009-06-13 01:28:41 +00:00
|
|
|
}
|
2010-02-19 17:11:40 +00:00
|
|
|
|
|
|
|
ASSERT_REFLOW_SCHEDULED_STATE();
|
2009-06-13 01:28:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-02-19 17:11:40 +00:00
|
|
|
PresShell::ScheduleReflow()
|
2009-06-13 01:28:41 +00:00
|
|
|
{
|
2010-02-19 17:11:40 +00:00
|
|
|
NS_PRECONDITION(!mReflowScheduled, "Why are we trying to schedule a reflow?");
|
|
|
|
ASSERT_REFLOW_SCHEDULED_STATE();
|
|
|
|
|
|
|
|
if (GetPresContext()->RefreshDriver()->AddRefreshObserver(this, Flush_Layout)) {
|
|
|
|
mReflowScheduled = PR_TRUE;
|
2000-04-17 07:13:57 +00:00
|
|
|
}
|
2010-02-19 17:11:40 +00:00
|
|
|
|
|
|
|
ASSERT_REFLOW_SCHEDULED_STATE();
|
2000-04-17 07:13:57 +00:00
|
|
|
}
|
|
|
|
|
2009-06-28 20:04:35 +00:00
|
|
|
nsresult
|
|
|
|
PresShell::DidCauseReflow()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mChangeNestCount != 0, "Unexpected call to DidCauseReflow()");
|
|
|
|
--mChangeNestCount;
|
|
|
|
nsContentUtils::RemoveScriptBlocker();
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-04-28 04:33:41 +00:00
|
|
|
void
|
|
|
|
PresShell::WillDoReflow()
|
|
|
|
{
|
|
|
|
// We just reflowed, tell the caret that its frame might have moved.
|
2007-10-02 04:37:36 +00:00
|
|
|
// XXXbz that comment makes no sense
|
2006-04-28 04:33:41 +00:00
|
|
|
if (mCaret) {
|
|
|
|
mCaret->InvalidateOutsideCaret();
|
2006-08-23 02:06:39 +00:00
|
|
|
mCaret->UpdateCaretPosition();
|
2006-04-28 04:33:41 +00:00
|
|
|
}
|
2007-10-02 04:37:36 +00:00
|
|
|
|
2008-11-25 23:22:38 +00:00
|
|
|
mPresContext->FlushUserFontSet();
|
|
|
|
|
2007-10-02 04:37:36 +00:00
|
|
|
mFrameConstructor->BeginUpdate();
|
2006-04-28 04:33:41 +00:00
|
|
|
}
|
|
|
|
|
2004-02-04 00:11:59 +00:00
|
|
|
void
|
2009-04-21 23:53:52 +00:00
|
|
|
PresShell::DidDoReflow(PRBool aInterruptible)
|
2004-02-04 00:11:59 +00:00
|
|
|
{
|
2007-10-02 04:37:36 +00:00
|
|
|
mFrameConstructor->EndUpdate();
|
|
|
|
|
2009-04-21 23:53:52 +00:00
|
|
|
HandlePostedReflowCallbacks(aInterruptible);
|
2004-06-22 04:32:52 +00:00
|
|
|
// Null-check mViewManager in case this happens during Destroy. See
|
|
|
|
// bugs 244435 and 238546.
|
|
|
|
if (!mPaintingSuppressed && mViewManager)
|
|
|
|
mViewManager->SynthesizeMouseMove(PR_FALSE);
|
2006-08-23 02:06:39 +00:00
|
|
|
if (mCaret) {
|
|
|
|
// Update the caret's position now to account for any changes created by
|
|
|
|
// the reflow.
|
2006-04-28 04:33:41 +00:00
|
|
|
mCaret->InvalidateOutsideCaret();
|
2006-08-23 02:06:39 +00:00
|
|
|
mCaret->UpdateCaretPosition();
|
|
|
|
}
|
2004-02-04 00:11:59 +00:00
|
|
|
}
|
|
|
|
|
2009-04-21 23:53:52 +00:00
|
|
|
static PLDHashOperator
|
|
|
|
MarkFramesDirtyToRoot(nsPtrHashKey<nsIFrame>* p, void* closure)
|
|
|
|
{
|
|
|
|
nsIFrame* target = static_cast<nsIFrame*>(closure);
|
|
|
|
for (nsIFrame* f = p->GetKey(); f && !NS_SUBTREE_DIRTY(f);
|
|
|
|
f = f->GetParent()) {
|
|
|
|
f->AddStateBits(NS_FRAME_HAS_DIRTY_CHILDREN);
|
|
|
|
|
|
|
|
if (f == target) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
2009-06-13 01:28:41 +00:00
|
|
|
void
|
|
|
|
PresShell::sReflowContinueCallback(nsITimer* aTimer, void* aPresShell)
|
|
|
|
{
|
|
|
|
nsRefPtr<PresShell> self = static_cast<PresShell*>(aPresShell);
|
|
|
|
|
|
|
|
NS_PRECONDITION(aTimer == self->mReflowContinueTimer, "Unexpected timer");
|
|
|
|
self->mReflowContinueTimer = nsnull;
|
2010-02-19 17:11:40 +00:00
|
|
|
self->ScheduleReflow();
|
2009-06-13 01:28:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
2010-02-19 17:11:40 +00:00
|
|
|
PresShell::ScheduleReflowOffTimer()
|
2009-06-13 01:28:41 +00:00
|
|
|
{
|
2010-02-19 17:11:40 +00:00
|
|
|
NS_PRECONDITION(!mReflowScheduled, "Shouldn't get here");
|
|
|
|
ASSERT_REFLOW_SCHEDULED_STATE();
|
|
|
|
|
2009-06-13 01:28:41 +00:00
|
|
|
if (!mReflowContinueTimer) {
|
|
|
|
mReflowContinueTimer = do_CreateInstance("@mozilla.org/timer;1");
|
|
|
|
if (!mReflowContinueTimer ||
|
|
|
|
NS_FAILED(mReflowContinueTimer->
|
2009-10-02 18:05:31 +00:00
|
|
|
InitWithFuncCallback(sReflowContinueCallback, this, 30,
|
2009-06-13 01:28:41 +00:00
|
|
|
nsITimer::TYPE_ONE_SHOT))) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2009-04-21 23:53:52 +00:00
|
|
|
PRBool
|
|
|
|
PresShell::DoReflow(nsIFrame* target, PRBool aInterruptible)
|
2007-04-25 15:49:55 +00:00
|
|
|
{
|
2010-05-19 23:22:19 +00:00
|
|
|
NS_TIME_FUNCTION_WITH_DOCURL;
|
|
|
|
|
2009-10-02 18:05:32 +00:00
|
|
|
if (mReflowContinueTimer) {
|
|
|
|
mReflowContinueTimer->Cancel();
|
|
|
|
mReflowContinueTimer = nsnull;
|
|
|
|
}
|
|
|
|
|
2007-04-25 15:49:55 +00:00
|
|
|
nsIFrame* rootFrame = FrameManager()->GetRootFrame();
|
|
|
|
|
|
|
|
nsCOMPtr<nsIRenderingContext> rcx;
|
|
|
|
// Always create the rendering context relative to the root frame during
|
|
|
|
// reflow; otherwise, it crashes on the mac (I'm not quite sure why)
|
|
|
|
nsresult rv = CreateRenderingContext(rootFrame, getter_AddRefs(rcx));
|
|
|
|
if (NS_FAILED(rv)) {
|
2009-04-21 23:53:52 +00:00
|
|
|
NS_NOTREACHED("CreateRenderingContext failure");
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
mCurrentReflowRoot = target;
|
|
|
|
#endif
|
2007-04-25 15:49:55 +00:00
|
|
|
|
|
|
|
target->WillReflow(mPresContext);
|
|
|
|
|
|
|
|
// If the target frame is the root of the frame hierarchy, then
|
|
|
|
// use all the available space. If it's simply a `reflow root',
|
|
|
|
// then use the target frame's size as the available space.
|
|
|
|
nsSize size;
|
|
|
|
if (target == rootFrame)
|
|
|
|
size = mPresContext->GetVisibleArea().Size();
|
|
|
|
else
|
|
|
|
size = target->GetSize();
|
|
|
|
|
|
|
|
NS_ASSERTION(!target->GetNextInFlow() && !target->GetPrevInFlow(),
|
|
|
|
"reflow roots should never split");
|
|
|
|
|
|
|
|
// Don't pass size directly to the reflow state, since a
|
|
|
|
// constrained height implies page/column breaking.
|
2009-01-29 20:39:22 +00:00
|
|
|
nsSize reflowSize(size.width, NS_UNCONSTRAINEDSIZE);
|
2007-04-25 15:49:55 +00:00
|
|
|
nsHTMLReflowState reflowState(mPresContext, target, rcx, reflowSize);
|
|
|
|
|
|
|
|
// fix the computed height
|
|
|
|
NS_ASSERTION(reflowState.mComputedMargin == nsMargin(0, 0, 0, 0),
|
|
|
|
"reflow state should not set margin for reflow roots");
|
2007-05-01 17:15:08 +00:00
|
|
|
if (size.height != NS_UNCONSTRAINEDSIZE) {
|
2007-08-02 18:08:05 +00:00
|
|
|
nscoord computedHeight =
|
2007-05-01 17:15:08 +00:00
|
|
|
size.height - reflowState.mComputedBorderPadding.TopBottom();
|
2009-09-16 15:01:36 +00:00
|
|
|
computedHeight = NS_MAX(computedHeight, 0);
|
2007-08-02 18:08:05 +00:00
|
|
|
reflowState.SetComputedHeight(computedHeight);
|
2007-05-01 17:15:08 +00:00
|
|
|
}
|
2007-04-25 15:49:55 +00:00
|
|
|
NS_ASSERTION(reflowState.ComputedWidth() ==
|
|
|
|
size.width -
|
|
|
|
reflowState.mComputedBorderPadding.LeftRight(),
|
|
|
|
"reflow state computed incorrect width");
|
|
|
|
|
2009-04-21 23:53:52 +00:00
|
|
|
mPresContext->ReflowStarted(aInterruptible);
|
|
|
|
mIsReflowing = PR_TRUE;
|
|
|
|
|
2007-04-25 15:49:55 +00:00
|
|
|
nsReflowStatus status;
|
|
|
|
nsHTMLReflowMetrics desiredSize;
|
|
|
|
target->Reflow(mPresContext, desiredSize, reflowState, status);
|
|
|
|
|
|
|
|
// If an incremental reflow is initiated at a frame other than the
|
2007-05-01 17:15:08 +00:00
|
|
|
// root frame, then its desired size had better not change! If it's
|
|
|
|
// initiated at the root, then the size better not change unless its
|
|
|
|
// height was unconstrained to start with.
|
|
|
|
NS_ASSERTION((target == rootFrame && size.height == NS_UNCONSTRAINEDSIZE) ||
|
2007-04-25 15:49:55 +00:00
|
|
|
(desiredSize.width == size.width &&
|
|
|
|
desiredSize.height == size.height),
|
|
|
|
"non-root frame's desired size changed during an "
|
|
|
|
"incremental reflow");
|
|
|
|
NS_ASSERTION(desiredSize.mOverflowArea ==
|
|
|
|
nsRect(nsPoint(0, 0),
|
|
|
|
nsSize(desiredSize.width, desiredSize.height)),
|
|
|
|
"reflow roots must not have visible overflow");
|
|
|
|
NS_ASSERTION(status == NS_FRAME_COMPLETE,
|
|
|
|
"reflow roots should never split");
|
|
|
|
|
|
|
|
target->SetSize(nsSize(desiredSize.width, desiredSize.height));
|
|
|
|
|
|
|
|
nsContainerFrame::SyncFrameViewAfterReflow(mPresContext, target,
|
|
|
|
target->GetView(),
|
|
|
|
&desiredSize.mOverflowArea);
|
2009-08-12 20:48:30 +00:00
|
|
|
nsContainerFrame::SyncWindowProperties(mPresContext, target,
|
|
|
|
target->GetView());
|
2007-04-25 15:49:55 +00:00
|
|
|
|
|
|
|
target->DidReflow(mPresContext, nsnull, NS_FRAME_REFLOW_FINISHED);
|
2007-05-01 17:15:08 +00:00
|
|
|
if (target == rootFrame && size.height == NS_UNCONSTRAINEDSIZE) {
|
|
|
|
mPresContext->SetVisibleArea(nsRect(0, 0, desiredSize.width,
|
|
|
|
desiredSize.height));
|
|
|
|
}
|
2009-04-21 23:53:52 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
mCurrentReflowRoot = nsnull;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
NS_ASSERTION(mPresContext->HasPendingInterrupt() ||
|
|
|
|
mFramesToDirty.Count() == 0,
|
|
|
|
"Why do we need to dirty anything if not interrupted?");
|
|
|
|
|
|
|
|
mIsReflowing = PR_FALSE;
|
|
|
|
PRBool interrupted = mPresContext->HasPendingInterrupt();
|
|
|
|
if (interrupted) {
|
|
|
|
// Make sure target gets reflowed again.
|
|
|
|
mFramesToDirty.EnumerateEntries(&MarkFramesDirtyToRoot, target);
|
|
|
|
NS_ASSERTION(NS_SUBTREE_DIRTY(target), "Why is the target not dirty?");
|
|
|
|
mDirtyRoots.AppendElement(target);
|
|
|
|
|
|
|
|
// Clear mFramesToDirty after we've done the NS_SUBTREE_DIRTY(target)
|
|
|
|
// assertion so that if it fails it's easier to see what's going on.
|
|
|
|
#ifdef NOISY_INTERRUPTIBLE_REFLOW
|
|
|
|
printf("mFramesToDirty.Count() == %u\n", mFramesToDirty.Count());
|
|
|
|
#endif /* NOISY_INTERRUPTIBLE_REFLOW */
|
|
|
|
mFramesToDirty.Clear();
|
|
|
|
|
|
|
|
// Any FlushPendingNotifications with interruptible reflows
|
|
|
|
// should be suppressed now. We don't want to do extra reflow work
|
|
|
|
// before our reflow event happens.
|
|
|
|
mSuppressInterruptibleReflows = PR_TRUE;
|
2010-02-19 17:11:40 +00:00
|
|
|
MaybeScheduleReflow();
|
2009-04-21 23:53:52 +00:00
|
|
|
}
|
|
|
|
|
2010-01-26 13:10:12 +00:00
|
|
|
nsRootPresContext* rootPC = mPresContext->GetRootPresContext();
|
|
|
|
if (rootPC) {
|
|
|
|
rootPC->UpdatePluginGeometry(target);
|
|
|
|
}
|
2009-07-22 00:45:00 +00:00
|
|
|
|
2009-04-21 23:53:52 +00:00
|
|
|
return !interrupted;
|
2007-04-25 15:49:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
void
|
|
|
|
PresShell::DoVerifyReflow()
|
|
|
|
{
|
|
|
|
if (GetVerifyReflowEnable()) {
|
|
|
|
// First synchronously render what we have so far so that we can
|
|
|
|
// see it.
|
|
|
|
nsIView* rootView;
|
|
|
|
mViewManager->GetRootView(rootView);
|
|
|
|
mViewManager->UpdateView(rootView, NS_VMREFRESH_IMMEDIATE);
|
|
|
|
|
|
|
|
FlushPendingNotifications(Flush_Layout);
|
|
|
|
mInVerifyReflow = PR_TRUE;
|
|
|
|
PRBool ok = VerifyIncrementalReflow();
|
|
|
|
mInVerifyReflow = PR_FALSE;
|
|
|
|
if (VERIFY_REFLOW_ALL & gVerifyReflowFlags) {
|
|
|
|
printf("ProcessReflowCommands: finished (%s)\n",
|
|
|
|
ok ? "ok" : "failed");
|
|
|
|
}
|
|
|
|
|
2009-02-03 14:42:18 +00:00
|
|
|
if (0 != mDirtyRoots.Length()) {
|
2007-04-25 15:49:55 +00:00
|
|
|
printf("XXX yikes! reflow commands queued during verify-reflow\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-04-21 23:53:52 +00:00
|
|
|
PRBool
|
2000-04-17 07:13:57 +00:00
|
|
|
PresShell::ProcessReflowCommands(PRBool aInterruptible)
|
|
|
|
{
|
2010-05-19 23:22:19 +00:00
|
|
|
NS_TIME_FUNCTION_WITH_DOCURL;
|
|
|
|
|
2009-04-21 23:53:52 +00:00
|
|
|
PRBool interrupted = PR_FALSE;
|
2009-02-03 14:42:18 +00:00
|
|
|
if (0 != mDirtyRoots.Length()) {
|
2000-04-17 07:13:57 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2007-04-25 15:49:55 +00:00
|
|
|
if (VERIFY_REFLOW_DUMP_COMMANDS & gVerifyReflowFlags) {
|
|
|
|
printf("ProcessReflowCommands: begin incremental reflow\n");
|
2000-04-17 07:13:57 +00:00
|
|
|
}
|
|
|
|
#endif
|
2002-05-10 18:22:41 +00:00
|
|
|
|
|
|
|
// If reflow is interruptible, then make a note of our deadline.
|
2004-04-13 03:13:46 +00:00
|
|
|
const PRIntervalTime deadline = aInterruptible
|
|
|
|
? PR_IntervalNow() + PR_MicrosecondsToInterval(gMaxRCProcessingTime)
|
|
|
|
: (PRIntervalTime)0;
|
2002-05-10 18:22:41 +00:00
|
|
|
|
2007-09-21 02:47:19 +00:00
|
|
|
// Scope for the reflow entry point
|
|
|
|
{
|
2008-03-14 23:08:57 +00:00
|
|
|
nsAutoScriptBlocker scriptBlocker;
|
2009-06-11 17:09:34 +00:00
|
|
|
WillDoReflow();
|
2006-04-18 21:48:12 +00:00
|
|
|
AUTO_LAYOUT_PHASE_ENTRY_POINT(GetPresContext(), Reflow);
|
|
|
|
|
|
|
|
do {
|
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 05:38:33 +00:00
|
|
|
// Send an incremental reflow notification to the target frame.
|
2009-02-03 14:42:18 +00:00
|
|
|
PRInt32 idx = mDirtyRoots.Length() - 1;
|
|
|
|
nsIFrame *target = mDirtyRoots[idx];
|
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 05:38:33 +00:00
|
|
|
mDirtyRoots.RemoveElementAt(idx);
|
|
|
|
|
2007-05-06 19:16:51 +00:00
|
|
|
if (!NS_SUBTREE_DIRTY(target)) {
|
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 05:38:33 +00:00
|
|
|
// It's not dirty anymore, which probably means the notification
|
|
|
|
// was posted in the middle of a reflow (perhaps with a reflow
|
|
|
|
// root in the middle). Don't do anything.
|
|
|
|
continue;
|
2002-05-10 18:22:41 +00:00
|
|
|
}
|
|
|
|
|
2009-04-21 23:53:52 +00:00
|
|
|
interrupted = !DoReflow(target, aInterruptible);
|
2002-05-10 18:22:41 +00:00
|
|
|
|
2006-04-18 21:48:12 +00:00
|
|
|
// Keep going until we're out of reflow commands, or we've run
|
2009-04-21 23:53:52 +00:00
|
|
|
// past our deadline, or we're interrupted.
|
|
|
|
} while (!interrupted && mDirtyRoots.Length() &&
|
2006-04-18 21:48:12 +00:00
|
|
|
(!aInterruptible || PR_IntervalNow() < deadline));
|
2002-05-10 18:22:41 +00:00
|
|
|
|
2009-04-21 23:53:52 +00:00
|
|
|
interrupted = mDirtyRoots.Length() != 0;
|
2006-04-18 21:48:12 +00:00
|
|
|
}
|
2002-05-10 18:22:41 +00:00
|
|
|
|
2008-03-14 23:08:57 +00:00
|
|
|
// Exiting the scriptblocker might have killed us
|
|
|
|
if (!mIsDestroying) {
|
2009-04-21 23:53:52 +00:00
|
|
|
DidDoReflow(aInterruptible);
|
2008-03-14 23:08:57 +00:00
|
|
|
}
|
2007-04-25 15:49:55 +00:00
|
|
|
|
2007-09-20 23:28:26 +00:00
|
|
|
// DidDoReflow might have killed us
|
|
|
|
if (!mIsDestroying) {
|
2000-04-17 07:13:57 +00:00
|
|
|
#ifdef DEBUG
|
2007-09-20 23:28:26 +00:00
|
|
|
if (VERIFY_REFLOW_DUMP_COMMANDS & gVerifyReflowFlags) {
|
|
|
|
printf("\nPresShell::ProcessReflowCommands() finished: this=%p\n",
|
|
|
|
(void*)this);
|
|
|
|
}
|
|
|
|
DoVerifyReflow();
|
2000-04-17 07:13:57 +00:00
|
|
|
#endif
|
2001-05-30 19:28:37 +00:00
|
|
|
|
2007-09-20 23:28:26 +00:00
|
|
|
// If any new reflow commands were enqueued during the reflow, schedule
|
|
|
|
// another reflow event to process them. Note that we want to do this
|
|
|
|
// after DidDoReflow(), since that method can change whether there are
|
|
|
|
// dirty roots around by flushing, and there's no point in posting a
|
|
|
|
// reflow event just to have the flush revoke it.
|
2009-02-03 14:42:18 +00:00
|
|
|
if (mDirtyRoots.Length())
|
2010-02-19 17:11:40 +00:00
|
|
|
MaybeScheduleReflow();
|
2007-09-20 23:28:26 +00:00
|
|
|
}
|
2000-04-17 07:13:57 +00:00
|
|
|
}
|
|
|
|
|
2007-09-20 23:28:26 +00:00
|
|
|
if (!mIsDestroying && mShouldUnsuppressPainting &&
|
2009-02-03 14:42:18 +00:00
|
|
|
mDirtyRoots.Length() == 0) {
|
2001-04-25 19:52:49 +00:00
|
|
|
// We only unlock if we're out of reflows. It's pointless
|
|
|
|
// to unlock if reflows are still pending, since reflows
|
|
|
|
// are just going to thrash the frames around some more. By
|
|
|
|
// waiting we avoid an overeager "jitter" effect.
|
|
|
|
mShouldUnsuppressPainting = PR_FALSE;
|
|
|
|
UnsuppressAndInvalidate();
|
|
|
|
}
|
|
|
|
|
2009-04-21 23:53:52 +00:00
|
|
|
return !interrupted;
|
2000-04-17 07:13:57 +00:00
|
|
|
}
|
|
|
|
|
2004-07-18 01:16:27 +00:00
|
|
|
#ifdef MOZ_XUL
|
|
|
|
/*
|
|
|
|
* It's better to add stuff to the |DidSetStyleContext| method of the
|
|
|
|
* relevant frames than adding it here. These methods should (ideally,
|
|
|
|
* anyway) go away.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Return value says whether to walk children.
|
2008-10-10 15:04:34 +00:00
|
|
|
typedef PRBool (* frameWalkerFn)(nsIFrame *aFrame, void *aClosure);
|
2004-07-18 01:16:27 +00:00
|
|
|
|
2008-10-10 15:04:34 +00:00
|
|
|
static PRBool
|
2004-07-18 01:16:27 +00:00
|
|
|
ReResolveMenusAndTrees(nsIFrame *aFrame, void *aClosure)
|
|
|
|
{
|
|
|
|
// Trees have a special style cache that needs to be flushed when
|
|
|
|
// the theme changes.
|
2009-01-12 19:20:59 +00:00
|
|
|
nsTreeBodyFrame *treeBody = do_QueryFrame(aFrame);
|
2008-10-28 04:47:19 +00:00
|
|
|
if (treeBody)
|
|
|
|
treeBody->ClearStyleAndImageCaches();
|
2004-07-18 01:16:27 +00:00
|
|
|
|
|
|
|
// We deliberately don't re-resolve style on a menu's popup
|
|
|
|
// sub-content, since doing so slows menus to a crawl. That means we
|
|
|
|
// have to special-case them on a skin switch, and ensure that the
|
|
|
|
// popup frames just get destroyed completely.
|
2007-07-04 15:49:38 +00:00
|
|
|
if (aFrame && aFrame->GetType() == nsGkAtoms::menuFrame)
|
2007-07-08 07:08:04 +00:00
|
|
|
(static_cast<nsMenuFrame *>(aFrame))->CloseMenu(PR_TRUE);
|
2004-07-18 01:16:27 +00:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2008-10-10 15:04:34 +00:00
|
|
|
static PRBool
|
2004-12-02 01:26:20 +00:00
|
|
|
ReframeImageBoxes(nsIFrame *aFrame, void *aClosure)
|
|
|
|
{
|
2007-07-08 07:08:04 +00:00
|
|
|
nsStyleChangeList *list = static_cast<nsStyleChangeList*>(aClosure);
|
2006-12-26 17:47:52 +00:00
|
|
|
if (aFrame->GetType() == nsGkAtoms::imageBoxFrame) {
|
2004-12-02 01:26:20 +00:00
|
|
|
list->AppendChange(aFrame, aFrame->GetContent(),
|
|
|
|
NS_STYLE_HINT_FRAMECHANGE);
|
|
|
|
return PR_FALSE; // don't walk descendants
|
2004-07-27 23:31:08 +00:00
|
|
|
}
|
|
|
|
return PR_TRUE; // walk descendants
|
|
|
|
}
|
|
|
|
|
2004-07-18 01:16:27 +00:00
|
|
|
static void
|
2004-07-31 23:15:21 +00:00
|
|
|
WalkFramesThroughPlaceholders(nsPresContext *aPresContext, nsIFrame *aFrame,
|
2004-07-18 01:16:27 +00:00
|
|
|
frameWalkerFn aFunc, void *aClosure)
|
|
|
|
{
|
|
|
|
PRBool walkChildren = (*aFunc)(aFrame, aClosure);
|
|
|
|
if (!walkChildren)
|
|
|
|
return;
|
|
|
|
|
|
|
|
PRInt32 listIndex = 0;
|
|
|
|
nsIAtom* childList = nsnull;
|
|
|
|
|
|
|
|
do {
|
|
|
|
nsIFrame *child = aFrame->GetFirstChild(childList);
|
|
|
|
while (child) {
|
|
|
|
if (!(child->GetStateBits() & NS_FRAME_OUT_OF_FLOW)) {
|
2005-04-14 15:30:35 +00:00
|
|
|
// only do frames that are in flow, and recur through the
|
|
|
|
// out-of-flows of placeholders.
|
|
|
|
WalkFramesThroughPlaceholders(aPresContext,
|
|
|
|
nsPlaceholderFrame::GetRealFrameFor(child),
|
|
|
|
aFunc, aClosure);
|
2004-07-18 01:16:27 +00:00
|
|
|
}
|
|
|
|
child = child->GetNextSibling();
|
|
|
|
}
|
|
|
|
|
|
|
|
childList = aFrame->GetAdditionalChildListName(listIndex++);
|
|
|
|
} while (childList);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
PresShell::Observe(nsISupports* aSubject,
|
|
|
|
const char* aTopic,
|
|
|
|
const PRUnichar* aData)
|
|
|
|
{
|
|
|
|
#ifdef MOZ_XUL
|
|
|
|
if (!nsCRT::strcmp(aTopic, "chrome-flush-skin-caches")) {
|
2004-09-02 03:08:51 +00:00
|
|
|
nsIFrame *rootFrame = FrameManager()->GetRootFrame();
|
2004-07-18 21:55:24 +00:00
|
|
|
// Need to null-check because "chrome-flush-skin-caches" can happen
|
|
|
|
// at interesting times during startup.
|
2004-07-27 23:31:08 +00:00
|
|
|
if (rootFrame) {
|
2004-10-09 01:39:21 +00:00
|
|
|
NS_ASSERTION(mViewManager, "View manager must exist");
|
2008-01-26 23:59:50 +00:00
|
|
|
nsIViewManager::UpdateViewBatch batch(mViewManager);
|
2004-10-09 01:39:21 +00:00
|
|
|
|
2009-12-23 00:09:10 +00:00
|
|
|
nsWeakFrame weakRoot(rootFrame);
|
|
|
|
// Have to make sure that the content notifications are flushed before we
|
|
|
|
// start messing with the frame model; otherwise we can get content doubling.
|
|
|
|
mDocument->FlushPendingNotifications(Flush_ContentAndNotify);
|
|
|
|
|
|
|
|
if (weakRoot.IsAlive()) {
|
|
|
|
WalkFramesThroughPlaceholders(mPresContext, rootFrame,
|
|
|
|
&ReResolveMenusAndTrees, nsnull);
|
|
|
|
|
|
|
|
// Because "chrome:" URL equality is messy, reframe image box
|
|
|
|
// frames (hack!).
|
|
|
|
nsStyleChangeList changeList;
|
|
|
|
WalkFramesThroughPlaceholders(mPresContext, rootFrame,
|
|
|
|
ReframeImageBoxes, &changeList);
|
|
|
|
// Mark ourselves as not safe to flush while we're doing frame
|
|
|
|
// construction.
|
|
|
|
{
|
|
|
|
nsAutoScriptBlocker scriptBlocker;
|
|
|
|
++mChangeNestCount;
|
|
|
|
mFrameConstructor->ProcessRestyledFrames(changeList);
|
|
|
|
--mChangeNestCount;
|
|
|
|
}
|
2008-03-14 23:08:57 +00:00
|
|
|
}
|
2008-01-26 23:59:50 +00:00
|
|
|
batch.EndUpdateViewBatch(NS_VMREFRESH_NO_SYNC);
|
2005-06-10 13:57:27 +00:00
|
|
|
#ifdef ACCESSIBILITY
|
|
|
|
InvalidateAccessibleSubtree(nsnull);
|
|
|
|
#endif
|
2004-07-27 23:31:08 +00:00
|
|
|
}
|
2004-07-18 01:16:27 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2006-06-08 14:32:20 +00:00
|
|
|
if (!nsCRT::strcmp(aTopic, "agent-sheet-added") && mStyleSet) {
|
|
|
|
AddAgentSheet(aSubject);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!nsCRT::strcmp(aTopic, "user-sheet-added") && mStyleSet) {
|
|
|
|
AddUserSheet(aSubject);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!nsCRT::strcmp(aTopic, "agent-sheet-removed") && mStyleSet) {
|
|
|
|
RemoveSheet(nsStyleSet::eAgentSheet, aSubject);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!nsCRT::strcmp(aTopic, "user-sheet-removed") && mStyleSet) {
|
|
|
|
RemoveSheet(nsStyleSet::eUserSheet, aSubject);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-05-04 02:19:18 +00:00
|
|
|
#ifdef ACCESSIBILITY
|
|
|
|
if (!nsCRT::strcmp(aTopic, "a11y-init-or-shutdown")) {
|
|
|
|
gIsAccessibilityActive = aData && *aData == '1';
|
|
|
|
}
|
|
|
|
#endif
|
2004-07-18 01:16:27 +00:00
|
|
|
NS_WARNING("unrecognized topic in PresShell::Observe");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2000-04-17 07:13:57 +00:00
|
|
|
//------------------------------------------------------
|
|
|
|
// End of protected and private methods on the PresShell
|
|
|
|
//------------------------------------------------------
|
|
|
|
|
|
|
|
// Start of DEBUG only code
|
|
|
|
|
1998-07-13 19:49:42 +00:00
|
|
|
#ifdef NS_DEBUG
|
|
|
|
#include "nsViewsCID.h"
|
|
|
|
#include "nsWidgetsCID.h"
|
|
|
|
#include "nsIDeviceContext.h"
|
|
|
|
#include "nsIURL.h"
|
1999-04-03 21:54:32 +00:00
|
|
|
#include "nsILinkHandler.h"
|
1998-07-13 19:49:42 +00:00
|
|
|
|
2000-01-04 20:24:09 +00:00
|
|
|
static NS_DEFINE_CID(kViewManagerCID, NS_VIEW_MANAGER_CID);
|
|
|
|
static NS_DEFINE_CID(kWidgetCID, NS_CHILD_CID);
|
1998-07-13 19:49:42 +00:00
|
|
|
|
|
|
|
static void
|
1998-11-25 18:41:02 +00:00
|
|
|
LogVerifyMessage(nsIFrame* k1, nsIFrame* k2, const char* aMsg)
|
|
|
|
{
|
2009-08-20 21:52:48 +00:00
|
|
|
nsAutoString n1, n2;
|
|
|
|
if (k1) {
|
|
|
|
k1->GetFrameName(n1);
|
|
|
|
} else {
|
|
|
|
n1.Assign(NS_LITERAL_STRING("(null)"));
|
1998-11-25 18:41:02 +00:00
|
|
|
}
|
|
|
|
|
2009-08-20 21:52:48 +00:00
|
|
|
if (k2) {
|
|
|
|
k2->GetFrameName(n2);
|
|
|
|
} else {
|
|
|
|
n2.Assign(NS_LITERAL_STRING("(null)"));
|
1998-11-25 18:41:02 +00:00
|
|
|
}
|
2007-04-25 15:49:55 +00:00
|
|
|
|
2009-08-20 21:52:48 +00:00
|
|
|
printf("verifyreflow: %s %p != %s %p %s\n",
|
|
|
|
NS_LossyConvertUTF16toASCII(n1).get(), (void*)k1,
|
|
|
|
NS_LossyConvertUTF16toASCII(n2).get(), (void*)k2, aMsg);
|
1998-11-25 18:41:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
LogVerifyMessage(nsIFrame* k1, nsIFrame* k2, const char* aMsg,
|
|
|
|
const nsRect& r1, const nsRect& r2)
|
1998-07-13 19:49:42 +00:00
|
|
|
{
|
2000-10-28 22:17:53 +00:00
|
|
|
printf("VerifyReflow Error:\n");
|
1998-11-19 17:22:29 +00:00
|
|
|
nsAutoString name;
|
1998-11-25 18:41:02 +00:00
|
|
|
|
2009-08-20 21:52:48 +00:00
|
|
|
if (k1) {
|
|
|
|
k1->GetFrameName(name);
|
|
|
|
printf(" %s %p ", NS_LossyConvertUTF16toASCII(name).get(), (void*)k1);
|
1999-11-01 22:12:45 +00:00
|
|
|
}
|
2009-08-20 21:52:48 +00:00
|
|
|
printf("{%d, %d, %d, %d} != \n", r1.x, r1.y, r1.width, r1.height);
|
1998-11-25 18:41:02 +00:00
|
|
|
|
2009-08-20 21:52:48 +00:00
|
|
|
if (k2) {
|
|
|
|
k2->GetFrameName(name);
|
|
|
|
printf(" %s %p ", NS_LossyConvertUTF16toASCII(name).get(), (void*)k2);
|
|
|
|
}
|
|
|
|
printf("{%d, %d, %d, %d}\n %s\n",
|
|
|
|
r2.x, r2.y, r2.width, r2.height, aMsg);
|
1998-07-13 19:49:42 +00:00
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
|
2009-01-15 03:27:09 +00:00
|
|
|
static void
|
|
|
|
LogVerifyMessage(nsIFrame* k1, nsIFrame* k2, const char* aMsg,
|
|
|
|
const nsIntRect& r1, const nsIntRect& r2)
|
|
|
|
{
|
|
|
|
printf("VerifyReflow Error:\n");
|
|
|
|
nsAutoString name;
|
|
|
|
|
2009-08-20 21:52:48 +00:00
|
|
|
if (k1) {
|
|
|
|
k1->GetFrameName(name);
|
|
|
|
printf(" %s %p ", NS_LossyConvertUTF16toASCII(name).get(), (void*)k1);
|
2009-01-15 03:27:09 +00:00
|
|
|
}
|
2009-08-20 21:52:48 +00:00
|
|
|
printf("{%d, %d, %d, %d} != \n", r1.x, r1.y, r1.width, r1.height);
|
2009-01-15 03:27:09 +00:00
|
|
|
|
2009-08-20 21:52:48 +00:00
|
|
|
if (k2) {
|
|
|
|
k2->GetFrameName(name);
|
|
|
|
printf(" %s %p ", NS_LossyConvertUTF16toASCII(name).get(), (void*)k2);
|
|
|
|
}
|
|
|
|
printf("{%d, %d, %d, %d}\n %s\n",
|
|
|
|
r2.x, r2.y, r2.width, r2.height, aMsg);
|
2009-01-15 03:27:09 +00:00
|
|
|
}
|
|
|
|
|
1999-04-03 18:58:04 +00:00
|
|
|
static PRBool
|
2004-07-31 23:15:21 +00:00
|
|
|
CompareTrees(nsPresContext* aFirstPresContext, nsIFrame* aFirstFrame,
|
|
|
|
nsPresContext* aSecondPresContext, nsIFrame* aSecondFrame)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
2000-03-22 23:19:10 +00:00
|
|
|
if (!aFirstPresContext || !aFirstFrame || !aSecondPresContext || !aSecondFrame)
|
|
|
|
return PR_TRUE;
|
2007-05-23 00:11:05 +00:00
|
|
|
// XXX Evil hack to reduce false positives; I can't seem to figure
|
|
|
|
// out how to flush scrollbar changes correctly
|
|
|
|
//if (aFirstFrame->GetType() == nsGkAtoms::scrollbarFrame)
|
|
|
|
// return PR_TRUE;
|
1999-04-03 18:58:04 +00:00
|
|
|
PRBool ok = PR_TRUE;
|
1998-11-25 18:41:02 +00:00
|
|
|
nsIAtom* listName = nsnull;
|
|
|
|
PRInt32 listIndex = 0;
|
|
|
|
do {
|
2009-07-28 12:53:18 +00:00
|
|
|
const nsFrameList& kids1 = aFirstFrame->GetChildList(listName);
|
|
|
|
const nsFrameList& kids2 = aSecondFrame->GetChildList(listName);
|
|
|
|
PRInt32 l1 = kids1.GetLength();
|
|
|
|
PRInt32 l2 = kids2.GetLength();;
|
1998-11-25 18:41:02 +00:00
|
|
|
if (l1 != l2) {
|
1999-04-03 18:58:04 +00:00
|
|
|
ok = PR_FALSE;
|
2009-07-28 12:53:18 +00:00
|
|
|
LogVerifyMessage(kids1.FirstChild(), kids2.FirstChild(),
|
|
|
|
"child counts don't match: ");
|
2000-10-28 22:17:53 +00:00
|
|
|
printf("%d != %d\n", l1, l2);
|
1999-09-10 18:49:23 +00:00
|
|
|
if (0 == (VERIFY_REFLOW_ALL & gVerifyReflowFlags)) {
|
1998-11-25 18:41:02 +00:00
|
|
|
break;
|
1998-07-13 19:49:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-15 03:27:09 +00:00
|
|
|
nsIntRect r1, r2;
|
1998-11-25 18:41:02 +00:00
|
|
|
nsIView* v1, *v2;
|
2009-07-28 12:53:18 +00:00
|
|
|
for (nsFrameList::Enumerator e1(kids1), e2(kids2);
|
|
|
|
;
|
|
|
|
e1.Next(), e2.Next()) {
|
|
|
|
nsIFrame* k1 = e1.get();
|
|
|
|
nsIFrame* k2 = e2.get();
|
1998-11-25 18:41:02 +00:00
|
|
|
if (((nsnull == k1) && (nsnull != k2)) ||
|
|
|
|
((nsnull != k1) && (nsnull == k2))) {
|
1999-04-03 18:58:04 +00:00
|
|
|
ok = PR_FALSE;
|
1998-11-25 18:41:02 +00:00
|
|
|
LogVerifyMessage(k1, k2, "child lists are different\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if (nsnull != k1) {
|
|
|
|
// Verify that the frames are the same size
|
2003-06-30 10:46:59 +00:00
|
|
|
if (k1->GetRect() != k2->GetRect()) {
|
1999-04-03 18:58:04 +00:00
|
|
|
ok = PR_FALSE;
|
2003-06-30 10:46:59 +00:00
|
|
|
LogVerifyMessage(k1, k2, "(frame rects)", k1->GetRect(), k2->GetRect());
|
1998-11-25 18:41:02 +00:00
|
|
|
}
|
1998-07-13 19:49:42 +00:00
|
|
|
|
1998-11-25 18:41:02 +00:00
|
|
|
// Make sure either both have views or neither have views; if they
|
|
|
|
// do have views, make sure the views are the same size. If the
|
|
|
|
// views have widgets, make sure they both do or neither does. If
|
|
|
|
// they do, make sure the widgets are the same size.
|
2003-06-30 10:46:59 +00:00
|
|
|
v1 = k1->GetView();
|
|
|
|
v2 = k2->GetView();
|
1998-11-25 18:41:02 +00:00
|
|
|
if (((nsnull == v1) && (nsnull != v2)) ||
|
|
|
|
((nsnull != v1) && (nsnull == v2))) {
|
1999-04-03 18:58:04 +00:00
|
|
|
ok = PR_FALSE;
|
1998-11-25 18:41:02 +00:00
|
|
|
LogVerifyMessage(k1, k2, "child views are not matched\n");
|
|
|
|
}
|
|
|
|
else if (nsnull != v1) {
|
2003-06-30 10:46:59 +00:00
|
|
|
if (v1->GetBounds() != v2->GetBounds()) {
|
|
|
|
LogVerifyMessage(k1, k2, "(view rects)", v1->GetBounds(), v2->GetBounds());
|
1998-11-25 18:41:02 +00:00
|
|
|
}
|
1998-07-13 19:49:42 +00:00
|
|
|
|
2003-06-30 10:46:59 +00:00
|
|
|
nsIWidget* w1 = v1->GetWidget();
|
|
|
|
nsIWidget* w2 = v2->GetWidget();
|
1998-11-25 18:41:02 +00:00
|
|
|
if (((nsnull == w1) && (nsnull != w2)) ||
|
|
|
|
((nsnull != w1) && (nsnull == w2))) {
|
1999-04-03 18:58:04 +00:00
|
|
|
ok = PR_FALSE;
|
1998-11-25 18:41:02 +00:00
|
|
|
LogVerifyMessage(k1, k2, "child widgets are not matched\n");
|
|
|
|
}
|
|
|
|
else if (nsnull != w1) {
|
|
|
|
w1->GetBounds(r1);
|
|
|
|
w2->GetBounds(r2);
|
|
|
|
if (r1 != r2) {
|
|
|
|
LogVerifyMessage(k1, k2, "(widget rects)", r1, r2);
|
|
|
|
}
|
1998-07-13 19:49:42 +00:00
|
|
|
}
|
|
|
|
}
|
1999-09-10 18:49:23 +00:00
|
|
|
if (!ok && (0 == (VERIFY_REFLOW_ALL & gVerifyReflowFlags))) {
|
1998-11-25 18:41:02 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-01-04 19:52:38 +00:00
|
|
|
// XXX Should perhaps compare their float managers.
|
2000-03-22 23:19:10 +00:00
|
|
|
|
1998-11-25 18:41:02 +00:00
|
|
|
// Compare the sub-trees too
|
2000-03-17 01:50:54 +00:00
|
|
|
if (!CompareTrees(aFirstPresContext, k1, aSecondPresContext, k2)) {
|
1999-09-10 18:49:23 +00:00
|
|
|
ok = PR_FALSE;
|
|
|
|
if (0 == (VERIFY_REFLOW_ALL & gVerifyReflowFlags)) {
|
1999-04-03 18:58:04 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
1998-07-13 19:49:42 +00:00
|
|
|
}
|
|
|
|
else {
|
1998-11-25 18:41:02 +00:00
|
|
|
break;
|
1998-07-13 19:49:42 +00:00
|
|
|
}
|
|
|
|
}
|
1999-09-10 18:49:23 +00:00
|
|
|
if (!ok && (0 == (VERIFY_REFLOW_ALL & gVerifyReflowFlags))) {
|
1998-11-25 18:41:02 +00:00
|
|
|
break;
|
1998-07-13 19:49:42 +00:00
|
|
|
}
|
1998-11-25 18:41:02 +00:00
|
|
|
|
2004-01-09 14:20:53 +00:00
|
|
|
nsIAtom* listName1 = aFirstFrame->GetAdditionalChildListName(listIndex);
|
|
|
|
nsIAtom* listName2 = aSecondFrame->GetAdditionalChildListName(listIndex);
|
1998-11-25 18:41:02 +00:00
|
|
|
listIndex++;
|
|
|
|
if (listName1 != listName2) {
|
1999-09-10 18:49:23 +00:00
|
|
|
if (0 == (VERIFY_REFLOW_ALL & gVerifyReflowFlags)) {
|
|
|
|
ok = PR_FALSE;
|
|
|
|
}
|
2009-07-28 12:53:18 +00:00
|
|
|
LogVerifyMessage(kids1.FirstChild(), kids2.FirstChild(),
|
|
|
|
"child list names are not matched: ");
|
1998-11-25 18:41:02 +00:00
|
|
|
nsAutoString tmp;
|
|
|
|
if (nsnull != listName1) {
|
|
|
|
listName1->ToString(tmp);
|
2006-02-03 14:18:39 +00:00
|
|
|
fputs(NS_LossyConvertUTF16toASCII(tmp).get(), stdout);
|
1998-11-25 18:41:02 +00:00
|
|
|
}
|
|
|
|
else
|
2000-10-28 22:17:53 +00:00
|
|
|
fputs("(null)", stdout);
|
|
|
|
printf(" != ");
|
1998-11-25 18:41:02 +00:00
|
|
|
if (nsnull != listName2) {
|
|
|
|
listName2->ToString(tmp);
|
2006-02-03 14:18:39 +00:00
|
|
|
fputs(NS_LossyConvertUTF16toASCII(tmp).get(), stdout);
|
1998-11-25 18:41:02 +00:00
|
|
|
}
|
|
|
|
else
|
2000-10-28 22:17:53 +00:00
|
|
|
fputs("(null)", stdout);
|
|
|
|
printf("\n");
|
1998-11-25 18:41:02 +00:00
|
|
|
break;
|
1998-07-13 19:49:42 +00:00
|
|
|
}
|
1998-11-25 18:41:02 +00:00
|
|
|
listName = listName1;
|
1999-04-03 18:58:04 +00:00
|
|
|
} while (ok && (listName != nsnull));
|
|
|
|
|
|
|
|
return ok;
|
|
|
|
}
|
1999-11-01 22:12:45 +00:00
|
|
|
#endif
|
1999-04-03 18:58:04 +00:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
static nsIFrame*
|
|
|
|
FindTopFrame(nsIFrame* aRoot)
|
|
|
|
{
|
2003-06-30 10:46:59 +00:00
|
|
|
if (aRoot) {
|
|
|
|
nsIContent* content = aRoot->GetContent();
|
|
|
|
if (content) {
|
1999-04-03 18:58:04 +00:00
|
|
|
nsIAtom* tag;
|
|
|
|
content->GetTag(tag);
|
|
|
|
if (nsnull != tag) {
|
|
|
|
NS_RELEASE(tag);
|
|
|
|
return aRoot;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Try one of the children
|
2004-01-09 14:20:53 +00:00
|
|
|
nsIFrame* kid = aRoot->GetFirstChild(nsnull);
|
1999-04-03 18:58:04 +00:00
|
|
|
while (nsnull != kid) {
|
|
|
|
nsIFrame* result = FindTopFrame(kid);
|
|
|
|
if (nsnull != result) {
|
|
|
|
return result;
|
|
|
|
}
|
2003-06-30 10:46:59 +00:00
|
|
|
kid = kid->GetNextSibling();
|
1999-04-03 18:58:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1998-07-13 19:49:42 +00:00
|
|
|
|
1999-11-01 22:12:45 +00:00
|
|
|
#ifdef DEBUG
|
2004-01-07 22:30:53 +00:00
|
|
|
|
|
|
|
nsresult
|
|
|
|
PresShell::CloneStyleSet(nsStyleSet* aSet, nsStyleSet** aResult)
|
|
|
|
{
|
|
|
|
nsStyleSet *clone = new nsStyleSet();
|
|
|
|
if (!clone) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32 i, n = aSet->SheetCount(nsStyleSet::eOverrideSheet);
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
nsIStyleSheet* ss = aSet->StyleSheetAt(nsStyleSet::eOverrideSheet, i);
|
|
|
|
if (ss)
|
|
|
|
clone->AppendStyleSheet(nsStyleSet::eOverrideSheet, ss);
|
|
|
|
}
|
|
|
|
|
2007-05-23 00:11:05 +00:00
|
|
|
// The document expects to insert document stylesheets itself
|
|
|
|
#if 0
|
2004-01-07 22:30:53 +00:00
|
|
|
n = aSet->SheetCount(nsStyleSet::eDocSheet);
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
nsIStyleSheet* ss = aSet->StyleSheetAt(nsStyleSet::eDocSheet, i);
|
|
|
|
if (ss)
|
|
|
|
clone->AddDocStyleSheet(ss, mDocument);
|
|
|
|
}
|
2007-05-23 00:11:05 +00:00
|
|
|
#endif
|
|
|
|
|
2004-01-07 22:30:53 +00:00
|
|
|
n = aSet->SheetCount(nsStyleSet::eUserSheet);
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
nsIStyleSheet* ss = aSet->StyleSheetAt(nsStyleSet::eUserSheet, i);
|
|
|
|
if (ss)
|
|
|
|
clone->AppendStyleSheet(nsStyleSet::eUserSheet, ss);
|
|
|
|
}
|
|
|
|
|
|
|
|
n = aSet->SheetCount(nsStyleSet::eAgentSheet);
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
nsIStyleSheet* ss = aSet->StyleSheetAt(nsStyleSet::eAgentSheet, i);
|
|
|
|
if (ss)
|
|
|
|
clone->AppendStyleSheet(nsStyleSet::eAgentSheet, ss);
|
|
|
|
}
|
|
|
|
*aResult = clone;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-05-23 00:11:05 +00:00
|
|
|
#ifdef DEBUG_Eli
|
|
|
|
static nsresult
|
|
|
|
DumpToPNG(nsIPresShell* shell, nsAString& name) {
|
|
|
|
PRInt32 width=1000, height=1000;
|
|
|
|
nsRect r(0, 0, shell->GetPresContext()->DevPixelsToAppUnits(width),
|
|
|
|
shell->GetPresContext()->DevPixelsToAppUnits(height));
|
|
|
|
|
|
|
|
nsRefPtr<gfxImageSurface> imgSurface =
|
|
|
|
new gfxImageSurface(gfxIntSize(width, height),
|
|
|
|
gfxImageSurface::ImageFormatARGB32);
|
|
|
|
NS_ENSURE_TRUE(imgSurface, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
|
|
|
nsRefPtr<gfxContext> imgContext = new gfxContext(imgSurface);
|
|
|
|
|
|
|
|
nsRefPtr<gfxASurface> surface =
|
|
|
|
gfxPlatform::GetPlatform()->
|
|
|
|
CreateOffscreenSurface(gfxIntSize(width, height),
|
|
|
|
gfxASurface::ImageFormatARGB32);
|
|
|
|
NS_ENSURE_TRUE(surface, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
|
|
|
nsRefPtr<gfxContext> context = new gfxContext(surface);
|
|
|
|
NS_ENSURE_TRUE(context, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
2010-03-31 12:45:32 +00:00
|
|
|
shell->RenderDocument(r, 0, NS_RGB(255, 255, 0), context);
|
2007-05-23 00:11:05 +00:00
|
|
|
|
|
|
|
imgContext->DrawSurface(surface, gfxSize(width, height));
|
|
|
|
|
|
|
|
nsCOMPtr<imgIEncoder> encoder = do_CreateInstance("@mozilla.org/image/encoder;2?type=image/png");
|
|
|
|
NS_ENSURE_TRUE(encoder, NS_ERROR_FAILURE);
|
|
|
|
encoder->InitFromData(imgSurface->Data(), imgSurface->Stride() * height,
|
|
|
|
width, height, imgSurface->Stride(),
|
|
|
|
imgIEncoder::INPUT_FORMAT_HOSTARGB, EmptyString());
|
|
|
|
|
|
|
|
// XXX not sure if this is the right way to write to a file
|
|
|
|
nsCOMPtr<nsILocalFile> file = do_CreateInstance("@mozilla.org/file/local;1");
|
|
|
|
NS_ENSURE_TRUE(file, NS_ERROR_FAILURE);
|
|
|
|
rv = file->InitWithPath(name);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
PRUint32 length;
|
|
|
|
encoder->Available(&length);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIOutputStream> outputStream;
|
|
|
|
rv = NS_NewLocalFileOutputStream(getter_AddRefs(outputStream), file);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIOutputStream> bufferedOutputStream;
|
|
|
|
rv = NS_NewBufferedOutputStream(getter_AddRefs(bufferedOutputStream),
|
|
|
|
outputStream, length);
|
|
|
|
|
|
|
|
PRUint32 numWritten;
|
|
|
|
rv = bufferedOutputStream->WriteFrom(encoder, length, &numWritten);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1998-07-13 19:49:42 +00:00
|
|
|
// After an incremental reflow, we verify the correctness by doing a
|
|
|
|
// full reflow into a fresh frame tree.
|
1999-09-10 18:49:23 +00:00
|
|
|
PRBool
|
1998-07-13 19:49:42 +00:00
|
|
|
PresShell::VerifyIncrementalReflow()
|
|
|
|
{
|
2000-04-17 14:40:46 +00:00
|
|
|
if (VERIFY_REFLOW_NOISY & gVerifyReflowFlags) {
|
2000-10-28 22:17:53 +00:00
|
|
|
printf("Building Verification Tree...\n");
|
2000-04-17 14:40:46 +00:00
|
|
|
}
|
1998-07-13 19:49:42 +00:00
|
|
|
|
|
|
|
// Create a presentation context to view the new frame tree
|
2010-03-25 13:17:11 +00:00
|
|
|
nsRefPtr<nsPresContext> cx =
|
2009-07-22 00:44:54 +00:00
|
|
|
new nsRootPresContext(mDocument, mPresContext->IsPaginated() ?
|
2007-04-25 15:49:55 +00:00
|
|
|
nsPresContext::eContext_PrintPreview :
|
|
|
|
nsPresContext::eContext_Galley);
|
|
|
|
NS_ENSURE_TRUE(cx, PR_FALSE);
|
2000-04-17 07:13:57 +00:00
|
|
|
|
2004-02-02 22:17:21 +00:00
|
|
|
nsIDeviceContext *dc = mPresContext->DeviceContext();
|
2004-07-29 19:41:39 +00:00
|
|
|
nsresult rv = cx->Init(dc);
|
2007-04-25 15:49:55 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, PR_FALSE);
|
1998-07-13 19:49:42 +00:00
|
|
|
|
2004-05-17 16:29:13 +00:00
|
|
|
// Get our scrolling preference
|
|
|
|
nsIView* rootView;
|
|
|
|
mViewManager->GetRootView(rootView);
|
2009-07-22 00:45:09 +00:00
|
|
|
NS_ENSURE_TRUE(rootView->HasWidget(), PR_FALSE);
|
2004-05-17 16:29:13 +00:00
|
|
|
void* nativeParentWidget = rootView->GetWidget()->GetNativeData(NS_NATIVE_WIDGET);
|
1998-07-13 19:49:42 +00:00
|
|
|
|
|
|
|
// Create a new view manager.
|
2007-04-25 15:49:55 +00:00
|
|
|
nsCOMPtr<nsIViewManager> vm = do_CreateInstance(kViewManagerCID);
|
|
|
|
NS_ENSURE_TRUE(vm, PR_FALSE);
|
2004-05-17 16:29:13 +00:00
|
|
|
rv = vm->Init(dc);
|
2007-04-25 15:49:55 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, PR_FALSE);
|
1998-08-28 02:54:06 +00:00
|
|
|
|
1998-07-13 19:49:42 +00:00
|
|
|
// Create a child window of the parent that is our "root view/window"
|
|
|
|
// Create a view
|
2004-02-01 10:09:07 +00:00
|
|
|
nsRect tbounds = mPresContext->GetVisibleArea();
|
2004-11-04 15:06:50 +00:00
|
|
|
nsIView* view = vm->CreateView(tbounds, nsnull);
|
2007-04-25 15:49:55 +00:00
|
|
|
NS_ENSURE_TRUE(view, PR_FALSE);
|
1998-11-04 04:14:10 +00:00
|
|
|
|
|
|
|
//now create the widget for the view
|
2004-05-17 16:29:13 +00:00
|
|
|
rv = view->CreateWidget(kWidgetCID, nsnull, nativeParentWidget, PR_TRUE);
|
2007-04-25 15:49:55 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, PR_FALSE);
|
1998-11-04 04:14:10 +00:00
|
|
|
|
2004-05-17 16:29:13 +00:00
|
|
|
// Setup hierarchical relationship in view manager
|
|
|
|
vm->SetRootView(view);
|
|
|
|
|
1998-07-13 19:49:42 +00:00
|
|
|
// Make the new presentation context the same size as our
|
|
|
|
// presentation context.
|
2004-02-01 10:09:07 +00:00
|
|
|
nsRect r = mPresContext->GetVisibleArea();
|
1998-07-13 19:49:42 +00:00
|
|
|
cx->SetVisibleArea(r);
|
1999-04-03 18:58:04 +00:00
|
|
|
|
1998-11-25 18:41:02 +00:00
|
|
|
// Create a new presentation shell to view the document. Use the
|
|
|
|
// exact same style information that this document has.
|
2004-01-08 19:23:12 +00:00
|
|
|
nsAutoPtr<nsStyleSet> newSet;
|
2004-01-08 21:10:33 +00:00
|
|
|
rv = CloneStyleSet(mStyleSet, getter_Transfers(newSet));
|
2007-04-25 15:49:55 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, PR_FALSE);
|
|
|
|
nsCOMPtr<nsIPresShell> sh;
|
|
|
|
rv = mDocument->CreateShell(cx, vm, newSet, getter_AddRefs(sh));
|
|
|
|
NS_ENSURE_SUCCESS(rv, PR_FALSE);
|
|
|
|
newSet.forget();
|
|
|
|
// Note that after we create the shell, we must make sure to destroy it
|
2000-03-17 01:50:54 +00:00
|
|
|
sh->SetVerifyReflowEnable(PR_FALSE); // turn off verify reflow while we're reflowing the test frame tree
|
2007-04-25 15:49:55 +00:00
|
|
|
vm->SetViewObserver((nsIViewObserver *)((PresShell*)sh.get()));
|
2008-12-20 14:28:19 +00:00
|
|
|
{
|
2009-06-28 20:04:35 +00:00
|
|
|
nsAutoCauseReflowNotifier crNotifier(this);
|
2008-12-20 14:28:19 +00:00
|
|
|
sh->InitialReflow(r.width, r.height);
|
|
|
|
}
|
2007-04-25 15:49:55 +00:00
|
|
|
mDocument->BindingManager()->ProcessAttachedQueue();
|
|
|
|
sh->FlushPendingNotifications(Flush_Layout);
|
2000-03-17 01:50:54 +00:00
|
|
|
sh->SetVerifyReflowEnable(PR_TRUE); // turn on verify reflow again now that we're done reflowing the test frame tree
|
2007-05-23 00:11:05 +00:00
|
|
|
// Force the non-primary presshell to unsuppress; it doesn't want to normally
|
|
|
|
// because it thinks it's hidden
|
|
|
|
((PresShell*)sh.get())->mPaintingSuppressed = PR_FALSE;
|
2000-04-17 14:40:46 +00:00
|
|
|
if (VERIFY_REFLOW_NOISY & gVerifyReflowFlags) {
|
2000-10-28 22:17:53 +00:00
|
|
|
printf("Verification Tree built, comparing...\n");
|
2000-04-17 14:40:46 +00:00
|
|
|
}
|
1998-07-13 19:49:42 +00:00
|
|
|
|
|
|
|
// Now that the document has been reflowed, use its frame tree to
|
|
|
|
// compare against our frame tree.
|
2004-03-06 04:46:11 +00:00
|
|
|
nsIFrame* root1 = FrameManager()->GetRootFrame();
|
2004-09-02 03:08:51 +00:00
|
|
|
nsIFrame* root2 = sh->FrameManager()->GetRootFrame();
|
2000-03-17 01:50:54 +00:00
|
|
|
PRBool ok = CompareTrees(mPresContext, root1, cx, root2);
|
1999-09-10 18:49:23 +00:00
|
|
|
if (!ok && (VERIFY_REFLOW_NOISY & gVerifyReflowFlags)) {
|
2000-10-28 22:17:53 +00:00
|
|
|
printf("Verify reflow failed, primary tree:\n");
|
2009-08-20 21:52:48 +00:00
|
|
|
root1->List(stdout, 0);
|
2000-10-28 22:17:53 +00:00
|
|
|
printf("Verification tree:\n");
|
2009-08-20 21:52:48 +00:00
|
|
|
root2->List(stdout, 0);
|
1999-04-03 18:58:04 +00:00
|
|
|
}
|
1998-07-13 19:49:42 +00:00
|
|
|
|
2007-05-23 00:11:05 +00:00
|
|
|
#ifdef DEBUG_Eli
|
|
|
|
// Sample code for dumping page to png
|
|
|
|
// XXX Needs to be made more flexible
|
|
|
|
if (!ok) {
|
|
|
|
nsString stra;
|
|
|
|
static int num = 0;
|
|
|
|
stra.AppendLiteral("C:\\mozilla\\mozilla\\debug\\filea");
|
|
|
|
stra.AppendInt(num);
|
|
|
|
stra.AppendLiteral(".png");
|
|
|
|
DumpToPNG(sh, stra);
|
|
|
|
nsString strb;
|
|
|
|
strb.AppendLiteral("C:\\mozilla\\mozilla\\debug\\fileb");
|
|
|
|
strb.AppendInt(num);
|
|
|
|
strb.AppendLiteral(".png");
|
|
|
|
DumpToPNG(this, strb);
|
|
|
|
++num;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1999-04-03 18:58:04 +00:00
|
|
|
sh->EndObservingDocument();
|
2007-04-25 15:49:55 +00:00
|
|
|
sh->Destroy();
|
2000-04-17 14:40:46 +00:00
|
|
|
if (VERIFY_REFLOW_NOISY & gVerifyReflowFlags) {
|
2000-10-28 22:17:53 +00:00
|
|
|
printf("Finished Verifying Reflow...\n");
|
2000-04-17 14:40:46 +00:00
|
|
|
}
|
1999-09-10 18:49:23 +00:00
|
|
|
|
|
|
|
return ok;
|
1998-07-13 19:49:42 +00:00
|
|
|
}
|
2004-01-07 22:30:53 +00:00
|
|
|
|
|
|
|
// Layout debugging hooks
|
|
|
|
void
|
|
|
|
PresShell::ListStyleContexts(nsIFrame *aRootFrame, FILE *out, PRInt32 aIndent)
|
|
|
|
{
|
|
|
|
nsStyleContext *sc = aRootFrame->GetStyleContext();
|
|
|
|
if (sc)
|
|
|
|
sc->List(out, aIndent);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PresShell::ListStyleSheets(FILE *out, PRInt32 aIndent)
|
|
|
|
{
|
|
|
|
PRInt32 sheetCount = mStyleSet->SheetCount(nsStyleSet::eDocSheet);
|
|
|
|
for (PRInt32 i = 0; i < sheetCount; ++i) {
|
|
|
|
mStyleSet->StyleSheetAt(nsStyleSet::eDocSheet, i)->List(out, aIndent);
|
|
|
|
fputs("\n", out);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-11-06 18:01:17 +00:00
|
|
|
void
|
|
|
|
PresShell::VerifyStyleTree()
|
|
|
|
{
|
|
|
|
VERIFY_STYLE_TREE;
|
|
|
|
}
|
1998-07-13 19:49:42 +00:00
|
|
|
#endif
|
1999-10-15 04:29:30 +00:00
|
|
|
|
2001-03-13 01:47:22 +00:00
|
|
|
//=============================================================
|
|
|
|
//=============================================================
|
|
|
|
//-- Debug Reflow Counts
|
|
|
|
//=============================================================
|
|
|
|
//=============================================================
|
2000-04-21 14:59:47 +00:00
|
|
|
#ifdef MOZ_REFLOW_PERF
|
2000-04-28 23:32:04 +00:00
|
|
|
//-------------------------------------------------------------
|
2010-03-31 12:45:32 +00:00
|
|
|
void
|
2000-04-28 23:32:04 +00:00
|
|
|
PresShell::DumpReflows()
|
|
|
|
{
|
|
|
|
if (mReflowCountMgr) {
|
2002-03-06 07:48:55 +00:00
|
|
|
nsCAutoString uriStr;
|
2000-04-28 23:32:04 +00:00
|
|
|
if (mDocument) {
|
2004-01-09 23:54:21 +00:00
|
|
|
nsIURI *uri = mDocument->GetDocumentURI();
|
2000-04-28 23:32:04 +00:00
|
|
|
if (uri) {
|
2002-03-06 07:48:55 +00:00
|
|
|
uri->GetPath(uriStr);
|
2000-04-28 23:32:04 +00:00
|
|
|
}
|
|
|
|
}
|
2002-03-06 07:48:55 +00:00
|
|
|
mReflowCountMgr->DisplayTotals(uriStr.get());
|
|
|
|
mReflowCountMgr->DisplayHTMLTotals(uriStr.get());
|
2000-04-28 23:32:04 +00:00
|
|
|
mReflowCountMgr->DisplayDiffsInTotals("Differences");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-04-21 14:59:47 +00:00
|
|
|
//-------------------------------------------------------------
|
2010-03-31 12:45:32 +00:00
|
|
|
void
|
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 05:38:33 +00:00
|
|
|
PresShell::CountReflows(const char * aName, nsIFrame * aFrame)
|
2000-04-21 14:59:47 +00:00
|
|
|
{
|
|
|
|
if (mReflowCountMgr) {
|
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 05:38:33 +00:00
|
|
|
mReflowCountMgr->Add(aName, aFrame);
|
2000-04-21 14:59:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-03-13 01:47:22 +00:00
|
|
|
//-------------------------------------------------------------
|
2010-03-31 12:45:32 +00:00
|
|
|
void
|
|
|
|
PresShell::PaintCount(const char * aName,
|
|
|
|
nsIRenderingContext* aRenderingContext,
|
|
|
|
nsPresContext* aPresContext,
|
|
|
|
nsIFrame * aFrame,
|
|
|
|
PRUint32 aColor)
|
2001-03-13 01:47:22 +00:00
|
|
|
{
|
|
|
|
if (mReflowCountMgr) {
|
|
|
|
mReflowCountMgr->PaintCount(aName, aRenderingContext, aPresContext, aFrame, aColor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//-------------------------------------------------------------
|
2010-03-31 12:45:32 +00:00
|
|
|
void
|
2001-03-13 01:47:22 +00:00
|
|
|
PresShell::SetPaintFrameCount(PRBool aPaintFrameCounts)
|
2010-03-31 12:45:32 +00:00
|
|
|
{
|
2001-03-13 01:47:22 +00:00
|
|
|
if (mReflowCountMgr) {
|
|
|
|
mReflowCountMgr->SetPaintFrameCounts(aPaintFrameCounts);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-22 00:44:52 +00:00
|
|
|
PRBool
|
|
|
|
PresShell::IsPaintingFrameCounts()
|
2010-03-31 12:45:32 +00:00
|
|
|
{
|
2009-07-22 00:44:52 +00:00
|
|
|
if (mReflowCountMgr)
|
|
|
|
return mReflowCountMgr->IsPaintingFrameCounts();
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2000-04-21 14:59:47 +00:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//-- Reflow Counter Classes Impls
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
ReflowCounter::ReflowCounter(ReflowCountMgr * aMgr) :
|
|
|
|
mMgr(aMgr)
|
|
|
|
{
|
|
|
|
ClearTotals();
|
2000-04-28 23:32:04 +00:00
|
|
|
SetTotalsCache();
|
2000-04-21 14:59:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
ReflowCounter::~ReflowCounter()
|
|
|
|
{
|
2001-03-13 01:47:22 +00:00
|
|
|
|
2000-04-21 14:59:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void ReflowCounter::ClearTotals()
|
|
|
|
{
|
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 05:38:33 +00:00
|
|
|
mTotal = 0;
|
2000-04-21 14:59:47 +00:00
|
|
|
}
|
|
|
|
|
2000-04-28 23:32:04 +00:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
void ReflowCounter::SetTotalsCache()
|
|
|
|
{
|
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 05:38:33 +00:00
|
|
|
mCacheTotal = mTotal;
|
2000-04-28 23:32:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void ReflowCounter::CalcDiffInTotals()
|
|
|
|
{
|
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 05:38:33 +00:00
|
|
|
mCacheTotal = mTotal - mCacheTotal;
|
2000-04-28 23:32:04 +00:00
|
|
|
}
|
|
|
|
|
2000-04-21 14:59:47 +00:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
void ReflowCounter::DisplayTotals(const char * aStr)
|
|
|
|
{
|
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 05:38:33 +00:00
|
|
|
DisplayTotals(mTotal, aStr?aStr:"Totals");
|
2000-04-28 23:32:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void ReflowCounter::DisplayDiffTotals(const char * aStr)
|
|
|
|
{
|
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 05:38:33 +00:00
|
|
|
DisplayTotals(mCacheTotal, aStr?aStr:"Diff Totals");
|
2000-04-21 14:59:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void ReflowCounter::DisplayHTMLTotals(const char * aStr)
|
|
|
|
{
|
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 05:38:33 +00:00
|
|
|
DisplayHTMLTotals(mTotal, aStr?aStr:"Totals");
|
2000-04-21 14:59:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
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 05:38:33 +00:00
|
|
|
void ReflowCounter::DisplayTotals(PRUint32 aTotal, const char * aTitle)
|
2000-04-21 14:59:47 +00:00
|
|
|
{
|
2000-04-28 23:32:04 +00:00
|
|
|
// figure total
|
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 05:38:33 +00:00
|
|
|
if (aTotal == 0) {
|
2000-04-21 14:59:47 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
ReflowCounter * gTots = (ReflowCounter *)mMgr->LookUp(kGrandTotalsStr);
|
|
|
|
|
2000-10-28 22:17:53 +00:00
|
|
|
printf("%25s\t", aTitle);
|
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 05:38:33 +00:00
|
|
|
printf("%d\t", aTotal);
|
|
|
|
if (gTots != this && aTotal > 0) {
|
|
|
|
gTots->Add(aTotal);
|
2000-04-21 14:59:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
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 05:38:33 +00:00
|
|
|
void ReflowCounter::DisplayHTMLTotals(PRUint32 aTotal, const char * aTitle)
|
2000-04-21 14:59:47 +00:00
|
|
|
{
|
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 05:38:33 +00:00
|
|
|
if (aTotal == 0) {
|
2000-04-21 14:59:47 +00:00
|
|
|
return;
|
|
|
|
}
|
2000-04-28 23:32:04 +00:00
|
|
|
|
2000-04-21 14:59:47 +00:00
|
|
|
ReflowCounter * gTots = (ReflowCounter *)mMgr->LookUp(kGrandTotalsStr);
|
|
|
|
FILE * fd = mMgr->GetOutFile();
|
|
|
|
if (!fd) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(fd, "<tr><td><center>%s</center></td>", aTitle);
|
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 05:38:33 +00:00
|
|
|
fprintf(fd, "<td><center>%d</center></td></tr>\n", aTotal);
|
|
|
|
|
|
|
|
if (gTots != this && aTotal > 0) {
|
|
|
|
gTots->Add(aTotal);
|
2000-04-21 14:59:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-03-13 01:47:22 +00:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//-- ReflowCountMgr
|
2000-04-21 14:59:47 +00:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
ReflowCountMgr::ReflowCountMgr()
|
|
|
|
{
|
|
|
|
mCounts = PL_NewHashTable(10, PL_HashString, PL_CompareStrings,
|
|
|
|
PL_CompareValues, nsnull, nsnull);
|
2001-02-22 13:58:17 +00:00
|
|
|
mIndiFrameCounts = PL_NewHashTable(10, PL_HashString, PL_CompareStrings,
|
|
|
|
PL_CompareValues, nsnull, nsnull);
|
2001-03-13 01:47:22 +00:00
|
|
|
mCycledOnce = PR_FALSE;
|
|
|
|
mDumpFrameCounts = PR_FALSE;
|
|
|
|
mDumpFrameByFrameCounts = PR_FALSE;
|
|
|
|
mPaintFrameByFrameCounts = PR_FALSE;
|
2000-04-21 14:59:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
ReflowCountMgr::~ReflowCountMgr()
|
|
|
|
{
|
|
|
|
CleanUp();
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
ReflowCounter * ReflowCountMgr::LookUp(const char * aName)
|
|
|
|
{
|
|
|
|
if (nsnull != mCounts) {
|
|
|
|
ReflowCounter * counter = (ReflowCounter *)PL_HashTableLookup(mCounts, aName);
|
|
|
|
return counter;
|
|
|
|
}
|
|
|
|
return nsnull;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
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 05:38:33 +00:00
|
|
|
void ReflowCountMgr::Add(const char * aName, nsIFrame * aFrame)
|
2000-04-21 14:59:47 +00:00
|
|
|
{
|
2001-02-22 13:58:17 +00:00
|
|
|
NS_ASSERTION(aName != nsnull, "Name shouldn't be null!");
|
|
|
|
|
2001-03-13 01:47:22 +00:00
|
|
|
if (mDumpFrameCounts && nsnull != mCounts) {
|
2000-04-21 14:59:47 +00:00
|
|
|
ReflowCounter * counter = (ReflowCounter *)PL_HashTableLookup(mCounts, aName);
|
|
|
|
if (counter == nsnull) {
|
|
|
|
counter = new ReflowCounter(this);
|
|
|
|
NS_ASSERTION(counter != nsnull, "null ptr");
|
2006-11-17 01:49:06 +00:00
|
|
|
char * name = NS_strdup(aName);
|
2000-04-21 14:59:47 +00:00
|
|
|
NS_ASSERTION(name != nsnull, "null ptr");
|
|
|
|
PL_HashTableAdd(mCounts, name, counter);
|
|
|
|
}
|
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 05:38:33 +00:00
|
|
|
counter->Add();
|
2000-04-21 14:59:47 +00:00
|
|
|
}
|
2001-02-22 13:58:17 +00:00
|
|
|
|
2001-03-13 01:47:22 +00:00
|
|
|
if ((mDumpFrameByFrameCounts || mPaintFrameByFrameCounts) &&
|
|
|
|
nsnull != mIndiFrameCounts &&
|
|
|
|
aFrame != nsnull) {
|
2001-02-22 13:58:17 +00:00
|
|
|
char * key = new char[16];
|
2002-08-24 14:41:28 +00:00
|
|
|
sprintf(key, "%p", (void*)aFrame);
|
2001-02-22 13:58:17 +00:00
|
|
|
IndiReflowCounter * counter = (IndiReflowCounter *)PL_HashTableLookup(mIndiFrameCounts, key);
|
|
|
|
if (counter == nsnull) {
|
|
|
|
counter = new IndiReflowCounter(this);
|
|
|
|
NS_ASSERTION(counter != nsnull, "null ptr");
|
|
|
|
counter->mFrame = aFrame;
|
2004-07-25 12:18:04 +00:00
|
|
|
counter->mName.AssignASCII(aName);
|
2001-02-22 13:58:17 +00:00
|
|
|
PL_HashTableAdd(mIndiFrameCounts, key, counter);
|
|
|
|
}
|
|
|
|
// this eliminates extra counts from super classes
|
2004-07-21 20:18:39 +00:00
|
|
|
if (counter != nsnull && counter->mName.EqualsASCII(aName)) {
|
2001-02-22 13:58:17 +00:00
|
|
|
counter->mCount++;
|
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 05:38:33 +00:00
|
|
|
counter->mCounter.Add(1);
|
2001-02-22 13:58:17 +00:00
|
|
|
}
|
|
|
|
}
|
2000-04-21 14:59:47 +00:00
|
|
|
}
|
|
|
|
|
2001-03-13 01:47:22 +00:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
void ReflowCountMgr::PaintCount(const char * aName,
|
|
|
|
nsIRenderingContext* aRenderingContext,
|
2004-07-31 23:15:21 +00:00
|
|
|
nsPresContext* aPresContext,
|
2001-03-13 01:47:22 +00:00
|
|
|
nsIFrame* aFrame,
|
|
|
|
PRUint32 aColor)
|
|
|
|
{
|
|
|
|
if (mPaintFrameByFrameCounts &&
|
|
|
|
nsnull != mIndiFrameCounts &&
|
|
|
|
aFrame != nsnull) {
|
|
|
|
char * key = new char[16];
|
2002-08-24 14:41:28 +00:00
|
|
|
sprintf(key, "%p", (void*)aFrame);
|
2001-03-13 01:47:22 +00:00
|
|
|
IndiReflowCounter * counter = (IndiReflowCounter *)PL_HashTableLookup(mIndiFrameCounts, key);
|
2004-07-21 20:18:39 +00:00
|
|
|
if (counter != nsnull && counter->mName.EqualsASCII(aName)) {
|
2001-03-13 01:47:22 +00:00
|
|
|
aRenderingContext->PushState();
|
2007-02-07 07:46:44 +00:00
|
|
|
nsFont font("Times", NS_FONT_STYLE_NORMAL, NS_FONT_VARIANT_NORMAL,
|
2009-01-29 20:39:18 +00:00
|
|
|
NS_FONT_WEIGHT_NORMAL, NS_FONT_STRETCH_NORMAL, 0,
|
2007-02-07 07:46:44 +00:00
|
|
|
nsPresContext::CSSPixelsToAppUnits(11));
|
2001-03-13 01:47:22 +00:00
|
|
|
|
2004-07-29 19:41:39 +00:00
|
|
|
nsCOMPtr<nsIFontMetrics> fm = aPresContext->GetMetricsFor(font);
|
2001-03-13 01:47:22 +00:00
|
|
|
aRenderingContext->SetFont(fm);
|
|
|
|
char buf[16];
|
|
|
|
sprintf(buf, "%d", counter->mCount);
|
2001-10-30 22:58:00 +00:00
|
|
|
nscoord x = 0, y;
|
2001-03-13 01:47:22 +00:00
|
|
|
nscoord width, height;
|
2007-01-23 02:58:55 +00:00
|
|
|
aRenderingContext->SetTextRunRTL(PR_FALSE);
|
2001-03-13 01:47:22 +00:00
|
|
|
aRenderingContext->GetWidth((char*)buf, width);
|
|
|
|
fm->GetHeight(height);
|
2001-10-30 22:58:00 +00:00
|
|
|
fm->GetMaxAscent(y);
|
2001-03-13 01:47:22 +00:00
|
|
|
|
|
|
|
PRUint32 color;
|
|
|
|
PRUint32 color2;
|
|
|
|
if (aColor != 0) {
|
|
|
|
color = aColor;
|
|
|
|
color2 = NS_RGB(0,0,0);
|
|
|
|
} else {
|
2003-05-30 19:47:39 +00:00
|
|
|
PRUint8 rc = 0, gc = 0, bc = 0;
|
2001-03-13 01:47:22 +00:00
|
|
|
if (counter->mCount < 5) {
|
|
|
|
rc = 255;
|
|
|
|
gc = 255;
|
|
|
|
} else if ( counter->mCount < 11) {
|
|
|
|
gc = 255;
|
|
|
|
} else {
|
|
|
|
rc = 255;
|
|
|
|
}
|
|
|
|
color = NS_RGB(rc,gc,bc);
|
|
|
|
color2 = NS_RGB(rc/2,gc/2,bc/2);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRect rect(0,0, width+15, height+15);
|
|
|
|
aRenderingContext->SetColor(NS_RGB(0,0,0));
|
|
|
|
aRenderingContext->FillRect(rect);
|
|
|
|
aRenderingContext->SetColor(color2);
|
2001-10-30 22:58:00 +00:00
|
|
|
aRenderingContext->DrawString(buf, strlen(buf), x+15,y+15);
|
2001-03-13 01:47:22 +00:00
|
|
|
aRenderingContext->SetColor(color);
|
2001-10-30 22:58:00 +00:00
|
|
|
aRenderingContext->DrawString(buf, strlen(buf), x,y);
|
2001-03-13 01:47:22 +00:00
|
|
|
|
2004-04-18 13:13:35 +00:00
|
|
|
aRenderingContext->PopState();
|
2001-03-13 01:47:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-04-21 14:59:47 +00:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
PRIntn ReflowCountMgr::RemoveItems(PLHashEntry *he, PRIntn i, void *arg)
|
|
|
|
{
|
|
|
|
char *str = (char *)he->key;
|
|
|
|
ReflowCounter * counter = (ReflowCounter *)he->value;
|
|
|
|
delete counter;
|
2006-11-17 01:49:06 +00:00
|
|
|
NS_Free(str);
|
2000-04-21 14:59:47 +00:00
|
|
|
|
|
|
|
return HT_ENUMERATE_REMOVE;
|
|
|
|
}
|
|
|
|
|
2001-02-22 13:58:17 +00:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
PRIntn ReflowCountMgr::RemoveIndiItems(PLHashEntry *he, PRIntn i, void *arg)
|
|
|
|
{
|
|
|
|
char *str = (char *)he->key;
|
|
|
|
IndiReflowCounter * counter = (IndiReflowCounter *)he->value;
|
|
|
|
delete counter;
|
2006-11-17 01:49:06 +00:00
|
|
|
NS_Free(str);
|
2001-02-22 13:58:17 +00:00
|
|
|
|
|
|
|
return HT_ENUMERATE_REMOVE;
|
|
|
|
}
|
|
|
|
|
2000-04-21 14:59:47 +00:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
void ReflowCountMgr::CleanUp()
|
|
|
|
{
|
|
|
|
if (nsnull != mCounts) {
|
|
|
|
PL_HashTableEnumerateEntries(mCounts, RemoveItems, nsnull);
|
|
|
|
PL_HashTableDestroy(mCounts);
|
|
|
|
mCounts = nsnull;
|
2001-03-13 01:47:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (nsnull != mIndiFrameCounts) {
|
|
|
|
PL_HashTableEnumerateEntries(mIndiFrameCounts, RemoveIndiItems, nsnull);
|
|
|
|
PL_HashTableDestroy(mIndiFrameCounts);
|
|
|
|
mIndiFrameCounts = nsnull;
|
2000-04-21 14:59:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
PRIntn ReflowCountMgr::DoSingleTotal(PLHashEntry *he, PRIntn i, void *arg)
|
|
|
|
{
|
|
|
|
char *str = (char *)he->key;
|
|
|
|
ReflowCounter * counter = (ReflowCounter *)he->value;
|
|
|
|
|
|
|
|
counter->DisplayTotals(str);
|
|
|
|
|
|
|
|
return HT_ENUMERATE_NEXT;
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void ReflowCountMgr::DoGrandTotals()
|
|
|
|
{
|
|
|
|
if (nsnull != mCounts) {
|
|
|
|
ReflowCounter * gTots = (ReflowCounter *)PL_HashTableLookup(mCounts, kGrandTotalsStr);
|
|
|
|
if (gTots == nsnull) {
|
|
|
|
gTots = new ReflowCounter(this);
|
2006-11-17 01:49:06 +00:00
|
|
|
PL_HashTableAdd(mCounts, NS_strdup(kGrandTotalsStr), gTots);
|
2000-04-21 14:59:47 +00:00
|
|
|
} else {
|
|
|
|
gTots->ClearTotals();
|
|
|
|
}
|
|
|
|
|
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 05:38:33 +00:00
|
|
|
printf("\t\t\t\tTotal\n");
|
|
|
|
for (PRUint32 i=0;i<78;i++) {
|
2000-10-28 22:17:53 +00:00
|
|
|
printf("-");
|
2000-04-21 14:59:47 +00:00
|
|
|
}
|
2000-10-28 22:17:53 +00:00
|
|
|
printf("\n");
|
2000-04-21 14:59:47 +00:00
|
|
|
PL_HashTableEnumerateEntries(mCounts, DoSingleTotal, this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-07-31 23:15:21 +00:00
|
|
|
static void RecurseIndiTotals(nsPresContext* aPresContext,
|
2001-02-22 13:58:17 +00:00
|
|
|
PLHashTable * aHT,
|
|
|
|
nsIFrame * aParentFrame,
|
|
|
|
PRInt32 aLevel)
|
|
|
|
{
|
|
|
|
if (aParentFrame == nsnull) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
char key[16];
|
2002-08-24 14:41:28 +00:00
|
|
|
sprintf(key, "%p", (void*)aParentFrame);
|
2001-02-22 13:58:17 +00:00
|
|
|
IndiReflowCounter * counter = (IndiReflowCounter *)PL_HashTableLookup(aHT, key);
|
|
|
|
if (counter) {
|
|
|
|
counter->mHasBeenOutput = PR_TRUE;
|
2001-09-29 08:28:41 +00:00
|
|
|
char * name = ToNewCString(counter->mName);
|
2001-02-22 13:58:17 +00:00
|
|
|
for (PRInt32 i=0;i<aLevel;i++) printf(" ");
|
2002-08-24 14:41:28 +00:00
|
|
|
printf("%s - %p [%d][", name, (void*)aParentFrame, counter->mCount);
|
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 05:38:33 +00:00
|
|
|
printf("%d", counter->mCounter.GetTotal());
|
2001-02-22 13:58:17 +00:00
|
|
|
printf("]\n");
|
|
|
|
nsMemory::Free(name);
|
|
|
|
}
|
|
|
|
|
2004-01-09 14:20:53 +00:00
|
|
|
nsIFrame* child = aParentFrame->GetFirstChild(nsnull);
|
2001-02-22 13:58:17 +00:00
|
|
|
while (child) {
|
|
|
|
RecurseIndiTotals(aPresContext, aHT, child, aLevel+1);
|
2003-06-30 10:46:59 +00:00
|
|
|
child = child->GetNextSibling();
|
2001-02-22 13:58:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
PRIntn ReflowCountMgr::DoSingleIndi(PLHashEntry *he, PRIntn i, void *arg)
|
|
|
|
{
|
|
|
|
IndiReflowCounter * counter = (IndiReflowCounter *)he->value;
|
|
|
|
if (counter && !counter->mHasBeenOutput) {
|
2001-09-29 08:28:41 +00:00
|
|
|
char * name = ToNewCString(counter->mName);
|
2002-08-24 14:41:28 +00:00
|
|
|
printf("%s - %p [%d][", name, (void*)counter->mFrame, counter->mCount);
|
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 05:38:33 +00:00
|
|
|
printf("%d", counter->mCounter.GetTotal());
|
2001-02-22 13:58:17 +00:00
|
|
|
printf("]\n");
|
|
|
|
nsMemory::Free(name);
|
|
|
|
}
|
|
|
|
return HT_ENUMERATE_NEXT;
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void ReflowCountMgr::DoIndiTotalsTree()
|
|
|
|
{
|
|
|
|
if (nsnull != mCounts) {
|
|
|
|
printf("\n------------------------------------------------\n");
|
|
|
|
printf("-- Individual Frame Counts\n");
|
|
|
|
printf("------------------------------------------------\n");
|
|
|
|
|
|
|
|
if (mPresShell) {
|
2004-09-02 03:08:51 +00:00
|
|
|
nsIFrame * rootFrame = mPresShell->FrameManager()->GetRootFrame();
|
2001-02-22 13:58:17 +00:00
|
|
|
RecurseIndiTotals(mPresContext, mIndiFrameCounts, rootFrame, 0);
|
|
|
|
printf("------------------------------------------------\n");
|
|
|
|
printf("-- Individual Counts of Frames not in Root Tree\n");
|
|
|
|
printf("------------------------------------------------\n");
|
|
|
|
PL_HashTableEnumerateEntries(mIndiFrameCounts, DoSingleIndi, this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-04-21 14:59:47 +00:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
PRIntn ReflowCountMgr::DoSingleHTMLTotal(PLHashEntry *he, PRIntn i, void *arg)
|
|
|
|
{
|
|
|
|
char *str = (char *)he->key;
|
|
|
|
ReflowCounter * counter = (ReflowCounter *)he->value;
|
|
|
|
|
|
|
|
counter->DisplayHTMLTotals(str);
|
|
|
|
|
|
|
|
return HT_ENUMERATE_NEXT;
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void ReflowCountMgr::DoGrandHTMLTotals()
|
|
|
|
{
|
|
|
|
if (nsnull != mCounts) {
|
|
|
|
ReflowCounter * gTots = (ReflowCounter *)PL_HashTableLookup(mCounts, kGrandTotalsStr);
|
|
|
|
if (gTots == nsnull) {
|
|
|
|
gTots = new ReflowCounter(this);
|
2006-11-17 01:49:06 +00:00
|
|
|
PL_HashTableAdd(mCounts, NS_strdup(kGrandTotalsStr), gTots);
|
2000-04-21 14:59:47 +00:00
|
|
|
} else {
|
|
|
|
gTots->ClearTotals();
|
|
|
|
}
|
|
|
|
|
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 05:38:33 +00:00
|
|
|
static const char * title[] = {"Class", "Reflows"};
|
2000-04-21 14:59:47 +00:00
|
|
|
fprintf(mFD, "<tr>");
|
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 05:38:33 +00:00
|
|
|
for (PRUint32 i=0; i < NS_ARRAY_LENGTH(title); i++) {
|
2000-04-21 14:59:47 +00:00
|
|
|
fprintf(mFD, "<td><center><b>%s<b></center></td>", title[i]);
|
|
|
|
}
|
|
|
|
fprintf(mFD, "</tr>\n");
|
|
|
|
PL_HashTableEnumerateEntries(mCounts, DoSingleHTMLTotal, this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------
|
|
|
|
void ReflowCountMgr::DisplayTotals(const char * aStr)
|
|
|
|
{
|
2001-07-18 04:29:14 +00:00
|
|
|
#ifdef DEBUG_rods
|
2000-10-28 22:17:53 +00:00
|
|
|
printf("%s\n", aStr?aStr:"No name");
|
2001-07-18 04:29:14 +00:00
|
|
|
#endif
|
2001-03-13 01:47:22 +00:00
|
|
|
if (mDumpFrameCounts) {
|
|
|
|
DoGrandTotals();
|
|
|
|
}
|
|
|
|
if (mDumpFrameByFrameCounts) {
|
|
|
|
DoIndiTotalsTree();
|
|
|
|
}
|
2000-04-21 14:59:47 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
//------------------------------------
|
|
|
|
void ReflowCountMgr::DisplayHTMLTotals(const char * aStr)
|
|
|
|
{
|
2000-04-28 23:32:04 +00:00
|
|
|
#ifdef WIN32x // XXX NOT XP!
|
2000-04-21 14:59:47 +00:00
|
|
|
char name[1024];
|
|
|
|
|
|
|
|
char * sptr = strrchr(aStr, '/');
|
|
|
|
if (sptr) {
|
|
|
|
sptr++;
|
|
|
|
strcpy(name, sptr);
|
|
|
|
char * eptr = strrchr(name, '.');
|
|
|
|
if (eptr) {
|
|
|
|
*eptr = 0;
|
|
|
|
}
|
|
|
|
strcat(name, "_stats.html");
|
|
|
|
}
|
|
|
|
mFD = fopen(name, "w");
|
|
|
|
if (mFD) {
|
|
|
|
fprintf(mFD, "<html><head><title>Reflow Stats</title></head><body>\n");
|
|
|
|
const char * title = aStr?aStr:"No name";
|
|
|
|
fprintf(mFD, "<center><b>%s</b><br><table border=1 style=\"background-color:#e0e0e0\">", title);
|
|
|
|
DoGrandHTMLTotals();
|
|
|
|
fprintf(mFD, "</center></table>\n");
|
|
|
|
fprintf(mFD, "</body></html>\n");
|
|
|
|
fclose(mFD);
|
|
|
|
mFD = nsnull;
|
|
|
|
}
|
|
|
|
#endif // not XP!
|
|
|
|
}
|
2000-04-28 23:32:04 +00:00
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
PRIntn ReflowCountMgr::DoClearTotals(PLHashEntry *he, PRIntn i, void *arg)
|
|
|
|
{
|
|
|
|
ReflowCounter * counter = (ReflowCounter *)he->value;
|
|
|
|
counter->ClearTotals();
|
|
|
|
|
|
|
|
return HT_ENUMERATE_NEXT;
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void ReflowCountMgr::ClearTotals()
|
|
|
|
{
|
|
|
|
PL_HashTableEnumerateEntries(mCounts, DoClearTotals, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void ReflowCountMgr::ClearGrandTotals()
|
|
|
|
{
|
|
|
|
if (nsnull != mCounts) {
|
|
|
|
ReflowCounter * gTots = (ReflowCounter *)PL_HashTableLookup(mCounts, kGrandTotalsStr);
|
|
|
|
if (gTots == nsnull) {
|
|
|
|
gTots = new ReflowCounter(this);
|
2006-11-17 01:49:06 +00:00
|
|
|
PL_HashTableAdd(mCounts, NS_strdup(kGrandTotalsStr), gTots);
|
2000-04-28 23:32:04 +00:00
|
|
|
} else {
|
|
|
|
gTots->ClearTotals();
|
|
|
|
gTots->SetTotalsCache();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
PRIntn ReflowCountMgr::DoDisplayDiffTotals(PLHashEntry *he, PRIntn i, void *arg)
|
|
|
|
{
|
2001-08-15 01:33:22 +00:00
|
|
|
PRBool cycledOnce = (arg != 0);
|
2000-04-28 23:32:04 +00:00
|
|
|
|
|
|
|
char *str = (char *)he->key;
|
|
|
|
ReflowCounter * counter = (ReflowCounter *)he->value;
|
|
|
|
|
|
|
|
if (cycledOnce) {
|
|
|
|
counter->CalcDiffInTotals();
|
|
|
|
counter->DisplayDiffTotals(str);
|
|
|
|
}
|
|
|
|
counter->SetTotalsCache();
|
|
|
|
|
|
|
|
return HT_ENUMERATE_NEXT;
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void ReflowCountMgr::DisplayDiffsInTotals(const char * aStr)
|
|
|
|
{
|
|
|
|
if (mCycledOnce) {
|
2000-10-28 22:17:53 +00:00
|
|
|
printf("Differences\n");
|
2000-04-28 23:32:04 +00:00
|
|
|
for (PRInt32 i=0;i<78;i++) {
|
2000-10-28 22:17:53 +00:00
|
|
|
printf("-");
|
2000-04-28 23:32:04 +00:00
|
|
|
}
|
2000-10-28 22:17:53 +00:00
|
|
|
printf("\n");
|
2000-04-28 23:32:04 +00:00
|
|
|
ClearGrandTotals();
|
|
|
|
}
|
|
|
|
PL_HashTableEnumerateEntries(mCounts, DoDisplayDiffTotals, (void *)mCycledOnce);
|
|
|
|
|
|
|
|
mCycledOnce = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2000-04-21 14:59:47 +00:00
|
|
|
#endif // MOZ_REFLOW_PERF
|
2000-10-11 08:33:01 +00:00
|
|
|
|
|
|
|
// make a color string like #RRGGBB
|
|
|
|
void ColorToString(nscolor aColor, nsAutoString &aString)
|
|
|
|
{
|
2004-01-18 14:44:43 +00:00
|
|
|
char buf[8];
|
2000-10-11 08:33:01 +00:00
|
|
|
|
2004-01-18 14:44:43 +00:00
|
|
|
PR_snprintf(buf, sizeof(buf), "#%02x%02x%02x",
|
|
|
|
NS_GET_R(aColor), NS_GET_G(aColor), NS_GET_B(aColor));
|
|
|
|
CopyASCIItoUTF16(buf, aString);
|
2000-10-11 08:33:01 +00:00
|
|
|
}
|
2008-01-22 07:39:06 +00:00
|
|
|
|
|
|
|
nsIFrame* nsIPresShell::GetAbsoluteContainingBlock(nsIFrame *aFrame)
|
|
|
|
{
|
|
|
|
return FrameConstructor()->GetAbsoluteContainingBlock(aFrame);
|
|
|
|
}
|
2010-06-01 02:19:35 +00:00
|
|
|
|
|
|
|
void nsIPresShell::InitializeStatics()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(sLiveShells == nsnull, "InitializeStatics called multiple times!");
|
|
|
|
sLiveShells = new nsTHashtable<PresShellPtrKey>();
|
|
|
|
sLiveShells->Init();
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsIPresShell::ReleaseStatics()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(sLiveShells, "ReleaseStatics called without Initialize!");
|
|
|
|
delete sLiveShells;
|
|
|
|
sLiveShells = nsnull;
|
|
|
|
}
|