2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-18 18:30:37 +04:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1998-04-14 00:24:54 +04:00
|
|
|
*
|
2004-04-18 18:30:37 +04:00
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
1998-04-14 00:24:54 +04:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
1998-04-14 00:24:54 +04:00
|
|
|
*
|
1999-11-06 06:40:37 +03:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2004-04-18 18:30:37 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-29 00:14:13 +04:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 06:40:37 +03:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* Contributor(s):
|
2008-07-26 20:14:48 +04:00
|
|
|
* L. David Baron <dbaron@dbaron.org>, Mozilla Corporation
|
2008-12-18 23:12:53 +03:00
|
|
|
* Ehsan Akhgari <ehsan.akhgari@gmail.com>
|
2001-09-29 00:14:13 +04:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-18 18:30:37 +04:00
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
2001-09-29 00:14:13 +04:00
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
2004-04-18 18:30:37 +04:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-29 00:14:13 +04:00
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
2004-04-18 18:30:37 +04:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-29 00:14:13 +04:00
|
|
|
*
|
2002-10-16 03:40:38 +04:00
|
|
|
* ***** END LICENSE BLOCK ***** */
|
2006-03-30 09:56:38 +04:00
|
|
|
|
|
|
|
/* a presentation of a document, part 1 */
|
|
|
|
|
2002-10-16 03:40:38 +04:00
|
|
|
#include "nsCOMPtr.h"
|
2004-08-01 03:15:21 +04:00
|
|
|
#include "nsPresContext.h"
|
1998-04-14 00:24:54 +04:00
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsILinkHandler.h"
|
2001-07-25 10:33:06 +04:00
|
|
|
#include "nsIDocShellTreeItem.h"
|
2005-01-20 06:39:09 +03:00
|
|
|
#include "nsIDocShell.h"
|
|
|
|
#include "nsIContentViewer.h"
|
|
|
|
#include "nsIDocumentViewer.h"
|
|
|
|
#include "nsPIDOMWindow.h"
|
2004-01-08 01:30:53 +03:00
|
|
|
#include "nsStyleSet.h"
|
2008-10-29 00:34:03 +03:00
|
|
|
#include "nsImageLoader.h"
|
2000-12-30 22:22:22 +03:00
|
|
|
#include "nsIContent.h"
|
1998-04-14 00:24:54 +04:00
|
|
|
#include "nsIFrame.h"
|
1998-09-05 07:52:40 +04:00
|
|
|
#include "nsIURL.h"
|
|
|
|
#include "nsIDocument.h"
|
2003-02-22 03:32:13 +03:00
|
|
|
#include "nsStyleContext.h"
|
2011-09-09 06:27:13 +04:00
|
|
|
#include "mozilla/LookAndFeel.h"
|
1999-09-10 09:51:08 +04:00
|
|
|
#include "nsIComponentManager.h"
|
2000-02-15 07:49:32 +03:00
|
|
|
#include "nsIURIContentListener.h"
|
|
|
|
#include "nsIInterfaceRequestor.h"
|
2001-09-06 01:28:38 +04:00
|
|
|
#include "nsIInterfaceRequestorUtils.h"
|
2000-03-02 10:13:02 +03:00
|
|
|
#include "nsIServiceManager.h"
|
2000-05-16 02:05:45 +04:00
|
|
|
#include "nsIDOMElement.h"
|
|
|
|
#include "nsContentPolicyUtils.h"
|
2001-05-22 02:40:10 +04:00
|
|
|
#include "nsIDOMWindow.h"
|
2001-05-08 05:40:09 +04:00
|
|
|
#include "nsXPIDLString.h"
|
2002-11-07 03:59:25 +03:00
|
|
|
#include "nsIWeakReferenceUtils.h"
|
2003-01-09 09:49:07 +03:00
|
|
|
#include "nsCSSRendering.h"
|
2001-05-08 05:40:09 +04:00
|
|
|
#include "prprf.h"
|
2002-02-15 02:31:54 +03:00
|
|
|
#include "nsContentPolicyUtils.h"
|
|
|
|
#include "nsIDOMDocument.h"
|
2003-02-22 03:32:13 +03:00
|
|
|
#include "nsAutoPtr.h"
|
2004-02-27 20:17:37 +03:00
|
|
|
#include "nsEventStateManager.h"
|
2006-09-12 08:36:03 +04:00
|
|
|
#include "nsThreadUtils.h"
|
2006-11-30 02:09:13 +03:00
|
|
|
#include "nsFrameManager.h"
|
|
|
|
#include "nsLayoutUtils.h"
|
2007-02-15 12:04:25 +03:00
|
|
|
#include "nsIViewManager.h"
|
2007-07-25 21:14:13 +04:00
|
|
|
#include "nsCSSFrameConstructor.h"
|
2008-08-06 00:02:43 +04:00
|
|
|
#include "nsCSSRuleProcessor.h"
|
2007-07-25 21:14:13 +04:00
|
|
|
#include "nsStyleChangeList.h"
|
2007-10-09 03:11:01 +04:00
|
|
|
#include "nsRuleNode.h"
|
2008-09-18 13:47:21 +04:00
|
|
|
#include "nsEventDispatcher.h"
|
2008-10-01 07:01:53 +04:00
|
|
|
#include "gfxUserFontSet.h"
|
2008-11-26 02:22:38 +03:00
|
|
|
#include "gfxPlatform.h"
|
|
|
|
#include "nsCSSRules.h"
|
|
|
|
#include "nsFontFaceLoader.h"
|
2011-06-24 06:18:01 +04:00
|
|
|
#include "nsEventListenerManager.h"
|
2009-02-19 22:03:28 +03:00
|
|
|
#include "nsStyleStructInlines.h"
|
2009-04-22 03:53:52 +04:00
|
|
|
#include "nsIAppShell.h"
|
|
|
|
#include "prenv.h"
|
2009-06-23 13:09:05 +04:00
|
|
|
#include "nsIPrivateDOMEvent.h"
|
|
|
|
#include "nsIDOMEventTarget.h"
|
2009-07-22 04:45:00 +04:00
|
|
|
#include "nsObjectFrame.h"
|
2009-10-08 07:22:42 +04:00
|
|
|
#include "nsTransitionManager.h"
|
2011-04-12 10:18:44 +04:00
|
|
|
#include "nsAnimationManager.h"
|
2010-05-05 22:18:05 +04:00
|
|
|
#include "mozilla/dom/Element.h"
|
2010-05-18 16:28:37 +04:00
|
|
|
#include "nsIFrameMessageManager.h"
|
2011-04-12 00:57:29 +04:00
|
|
|
#include "FrameLayerBuilder.h"
|
2011-04-22 07:17:31 +04:00
|
|
|
#include "nsDOMMediaQueryList.h"
|
2006-09-12 08:36:03 +04:00
|
|
|
|
2009-01-15 07:38:07 +03:00
|
|
|
#ifdef MOZ_SMIL
|
|
|
|
#include "nsSMILAnimationController.h"
|
|
|
|
#endif // MOZ_SMIL
|
|
|
|
|
2001-03-09 06:13:03 +03:00
|
|
|
#ifdef IBMBIDI
|
|
|
|
#include "nsBidiPresUtils.h"
|
|
|
|
#endif // IBMBIDI
|
2000-02-15 07:49:32 +03:00
|
|
|
|
2004-04-30 08:06:30 +04:00
|
|
|
#include "nsContentUtils.h"
|
2010-03-01 17:47:27 +03:00
|
|
|
#include "nsPIWindowRoot.h"
|
2011-05-25 10:31:59 +04:00
|
|
|
#include "mozilla/Preferences.h"
|
2004-04-30 08:06:30 +04:00
|
|
|
|
2001-11-14 14:21:54 +03:00
|
|
|
// Needed for Start/Stop of Image Animation
|
|
|
|
#include "imgIContainer.h"
|
2003-03-19 06:47:09 +03:00
|
|
|
#include "nsIImageLoadingContent.h"
|
2001-11-14 14:21:54 +03:00
|
|
|
|
2002-09-11 07:03:49 +04:00
|
|
|
//needed for resetting of image service color
|
|
|
|
#include "nsLayoutCID.h"
|
2007-08-24 04:13:43 +04:00
|
|
|
|
2011-04-12 00:57:29 +04:00
|
|
|
using namespace mozilla;
|
2010-04-30 17:12:05 +04:00
|
|
|
using namespace mozilla::dom;
|
2009-10-02 22:05:32 +04:00
|
|
|
|
2001-05-08 05:40:09 +04:00
|
|
|
static nscolor
|
2011-05-28 11:03:00 +04:00
|
|
|
MakeColorPref(const nsCString& aColor)
|
2001-05-08 05:40:09 +04:00
|
|
|
{
|
|
|
|
PRUint32 red, green, blue;
|
|
|
|
nscolor colorref;
|
|
|
|
|
|
|
|
// 4.x stored RGB color values as a string rather than as an int,
|
|
|
|
// thus we need to do this conversion
|
2011-05-28 11:03:00 +04:00
|
|
|
PR_sscanf(aColor.get(), "#%02x%02x%02x", &red, &green, &blue);
|
2001-05-08 05:40:09 +04:00
|
|
|
colorref = NS_RGB(red, green, blue);
|
|
|
|
return colorref;
|
|
|
|
}
|
|
|
|
|
2008-10-10 19:04:34 +04:00
|
|
|
int
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::PrefChangedCallback(const char* aPrefName, void* instance_data)
|
2002-12-11 08:11:02 +03:00
|
|
|
{
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext* presContext = (nsPresContext*)instance_data;
|
2002-12-11 08:11:02 +03:00
|
|
|
|
|
|
|
NS_ASSERTION(nsnull != presContext, "bad instance data");
|
|
|
|
if (nsnull != presContext) {
|
|
|
|
presContext->PreferenceChanged(aPrefName);
|
|
|
|
}
|
|
|
|
return 0; // PREF_OK
|
|
|
|
}
|
|
|
|
|
2005-08-24 03:52:16 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
nsPresContext::PrefChangedUpdateTimerCallback(nsITimer *aTimer, void *aClosure)
|
|
|
|
{
|
|
|
|
nsPresContext* presContext = (nsPresContext*)aClosure;
|
|
|
|
NS_ASSERTION(presContext != nsnull, "bad instance data");
|
|
|
|
if (presContext)
|
|
|
|
presContext->UpdateAfterPreferencesChanged();
|
|
|
|
}
|
|
|
|
|
2001-03-09 06:13:03 +03:00
|
|
|
#ifdef IBMBIDI
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool
|
2004-07-29 23:41:39 +04:00
|
|
|
IsVisualCharset(const nsCString& aCharset)
|
2001-03-09 06:13:03 +03:00
|
|
|
{
|
2004-06-17 04:13:25 +04:00
|
|
|
if (aCharset.LowerCaseEqualsLiteral("ibm864") // Arabic//ahmed
|
|
|
|
|| aCharset.LowerCaseEqualsLiteral("ibm862") // Hebrew
|
|
|
|
|| aCharset.LowerCaseEqualsLiteral("iso-8859-8") ) { // Hebrew
|
2001-03-09 06:13:03 +03:00
|
|
|
return PR_TRUE; // visual text type
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return PR_FALSE; // logical text type
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif // IBMBIDI
|
|
|
|
|
2001-08-10 00:22:39 +04:00
|
|
|
|
2008-10-10 19:04:34 +04:00
|
|
|
static PLDHashOperator
|
2009-02-19 22:03:28 +03:00
|
|
|
destroy_loads(const void * aKey, nsRefPtr<nsImageLoader>& aData, void* closure)
|
2001-08-10 00:22:39 +04:00
|
|
|
{
|
2007-02-07 10:46:44 +03:00
|
|
|
aData->Destroy();
|
|
|
|
return PL_DHASH_NEXT;
|
2001-08-10 00:22:39 +04:00
|
|
|
}
|
|
|
|
|
2001-02-20 00:50:04 +03:00
|
|
|
#include "nsContentCID.h"
|
2002-09-11 07:03:49 +04:00
|
|
|
|
2004-08-01 03:15:21 +04:00
|
|
|
// NOTE! nsPresContext::operator new() zeroes out all members, so don't
|
2004-04-30 08:06:30 +04:00
|
|
|
// bother initializing members to 0.
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2006-05-19 14:26:44 +04:00
|
|
|
nsPresContext::nsPresContext(nsIDocument* aDocument, nsPresContextType aType)
|
2011-05-24 14:36:21 +04:00
|
|
|
: mType(aType), mDocument(aDocument), mMinFontSize(0),
|
|
|
|
mTextZoom(1.0), mFullZoom(1.0), mPageSize(-1, -1), mPPScale(1.0f),
|
2004-09-05 04:04:04 +04:00
|
|
|
mViewportStyleOverflow(NS_STYLE_OVERFLOW_AUTO, NS_STYLE_OVERFLOW_AUTO),
|
2004-07-29 23:41:39 +04:00
|
|
|
mImageAnimationModePref(imgIContainer::kNormalAnimMode),
|
2007-02-07 10:46:44 +03:00
|
|
|
// Font sizes default to zero; they will be set in GetFontPreferences
|
2004-07-29 23:41:39 +04:00
|
|
|
mDefaultVariableFont("serif", NS_FONT_STYLE_NORMAL, NS_FONT_VARIANT_NORMAL,
|
2009-01-29 23:39:18 +03:00
|
|
|
NS_FONT_WEIGHT_NORMAL, NS_FONT_STRETCH_NORMAL, 0, 0),
|
2007-04-19 23:11:42 +04:00
|
|
|
mDefaultFixedFont("monospace", NS_FONT_STYLE_NORMAL,
|
2009-01-29 23:39:18 +03:00
|
|
|
NS_FONT_VARIANT_NORMAL, NS_FONT_WEIGHT_NORMAL,
|
|
|
|
NS_FONT_STRETCH_NORMAL, 0, 0),
|
2001-09-27 22:34:30 +04:00
|
|
|
mDefaultSerifFont("serif", NS_FONT_STYLE_NORMAL, NS_FONT_VARIANT_NORMAL,
|
2009-01-29 23:39:18 +03:00
|
|
|
NS_FONT_WEIGHT_NORMAL, NS_FONT_STRETCH_NORMAL, 0, 0),
|
2007-04-19 23:11:42 +04:00
|
|
|
mDefaultSansSerifFont("sans-serif", NS_FONT_STYLE_NORMAL,
|
2009-01-29 23:39:18 +03:00
|
|
|
NS_FONT_VARIANT_NORMAL, NS_FONT_WEIGHT_NORMAL,
|
|
|
|
NS_FONT_STRETCH_NORMAL, 0, 0),
|
2007-04-19 23:11:42 +04:00
|
|
|
mDefaultMonospaceFont("monospace", NS_FONT_STYLE_NORMAL,
|
2009-01-29 23:39:18 +03:00
|
|
|
NS_FONT_VARIANT_NORMAL, NS_FONT_WEIGHT_NORMAL,
|
|
|
|
NS_FONT_STRETCH_NORMAL, 0, 0),
|
2007-04-19 23:11:42 +04:00
|
|
|
mDefaultCursiveFont("cursive", NS_FONT_STYLE_NORMAL,
|
2009-01-29 23:39:18 +03:00
|
|
|
NS_FONT_VARIANT_NORMAL, NS_FONT_WEIGHT_NORMAL,
|
|
|
|
NS_FONT_STRETCH_NORMAL, 0, 0),
|
2007-04-19 23:11:42 +04:00
|
|
|
mDefaultFantasyFont("fantasy", NS_FONT_STYLE_NORMAL,
|
2009-01-29 23:39:18 +03:00
|
|
|
NS_FONT_VARIANT_NORMAL, NS_FONT_WEIGHT_NORMAL,
|
2010-03-01 22:31:45 +03:00
|
|
|
NS_FONT_STRETCH_NORMAL, 0, 0)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2004-08-01 03:15:21 +04:00
|
|
|
// NOTE! nsPresContext::operator new() zeroes out all members, so don't
|
2004-04-30 08:06:30 +04:00
|
|
|
// bother initializing members to 0.
|
|
|
|
|
2004-07-29 23:41:39 +04:00
|
|
|
mDoScaledTwips = PR_TRUE;
|
2000-09-21 05:20:00 +04:00
|
|
|
|
2002-02-15 17:48:12 +03:00
|
|
|
SetBackgroundImageDraw(PR_TRUE); // always draw the background
|
|
|
|
SetBackgroundColorDraw(PR_TRUE);
|
2001-12-11 08:57:37 +03:00
|
|
|
|
2004-02-01 01:41:40 +03:00
|
|
|
mBackgroundColor = NS_RGB(0xFF, 0xFF, 0xFF);
|
2000-10-11 12:33:01 +04:00
|
|
|
|
|
|
|
mUseDocumentColors = PR_TRUE;
|
|
|
|
mUseDocumentFonts = PR_TRUE;
|
|
|
|
|
2001-09-27 22:34:30 +04:00
|
|
|
// the minimum font-size is unconstrained by default
|
|
|
|
|
2003-10-15 05:56:12 +04:00
|
|
|
mLinkColor = NS_RGB(0x00, 0x00, 0xEE);
|
|
|
|
mActiveLinkColor = NS_RGB(0xEE, 0x00, 0x00);
|
|
|
|
mVisitedLinkColor = NS_RGB(0x55, 0x1A, 0x8B);
|
2000-10-11 12:33:01 +04:00
|
|
|
mUnderlineLinks = PR_TRUE;
|
2011-01-25 03:23:08 +03:00
|
|
|
mSendAfterPaintToContent = PR_FALSE;
|
2000-10-11 12:33:01 +04:00
|
|
|
|
2001-04-10 02:17:11 +04:00
|
|
|
mFocusTextColor = mDefaultColor;
|
2004-02-01 01:41:40 +03:00
|
|
|
mFocusBackgroundColor = mBackgroundColor;
|
2001-04-10 02:17:11 +04:00
|
|
|
mFocusRingWidth = 1;
|
|
|
|
|
2011-06-01 15:43:31 +04:00
|
|
|
mBodyTextColor = mDefaultColor;
|
|
|
|
|
2004-07-29 23:41:39 +04:00
|
|
|
if (aType == eContext_Galley) {
|
2006-12-26 20:47:52 +03:00
|
|
|
mMedium = nsGkAtoms::screen;
|
2004-07-29 23:41:39 +04:00
|
|
|
} else {
|
2006-12-26 20:47:52 +03:00
|
|
|
mMedium = nsGkAtoms::print;
|
2004-07-29 23:41:39 +04:00
|
|
|
mPaginated = PR_TRUE;
|
|
|
|
}
|
2006-04-01 05:19:28 +04:00
|
|
|
|
|
|
|
if (!IsDynamic()) {
|
|
|
|
mImageAnimationMode = imgIContainer::kDontAnimMode;
|
|
|
|
mNeverAnimate = PR_TRUE;
|
|
|
|
} else {
|
|
|
|
mImageAnimationMode = imgIContainer::kNormalAnimMode;
|
|
|
|
mNeverAnimate = PR_FALSE;
|
|
|
|
}
|
2006-05-19 14:26:44 +04:00
|
|
|
NS_ASSERTION(mDocument, "Null document");
|
2008-10-01 07:01:53 +04:00
|
|
|
mUserFontSet = nsnull;
|
2008-11-26 02:22:38 +03:00
|
|
|
mUserFontSetDirty = PR_TRUE;
|
2011-04-22 07:17:31 +04:00
|
|
|
|
|
|
|
PR_INIT_CLIST(&mDOMMediaQueryLists);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::~nsPresContext()
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2003-04-25 02:44:48 +04:00
|
|
|
NS_PRECONDITION(!mShell, "Presshell forgot to clear our mShell pointer");
|
|
|
|
SetShell(nsnull);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2011-04-22 07:17:31 +04:00
|
|
|
NS_ABORT_IF_FALSE(PR_CLIST_IS_EMPTY(&mDOMMediaQueryLists),
|
|
|
|
"must not have media query lists left");
|
|
|
|
|
2009-12-23 22:10:30 +03:00
|
|
|
// Disconnect the refresh driver *after* the transition manager, which
|
|
|
|
// needs it.
|
2010-08-12 01:05:27 +04:00
|
|
|
if (mRefreshDriver && mRefreshDriver->PresContext() == this) {
|
2009-12-23 22:10:30 +03:00
|
|
|
mRefreshDriver->Disconnect();
|
|
|
|
}
|
|
|
|
|
2003-06-19 22:16:53 +04:00
|
|
|
if (mEventManager) {
|
2006-04-11 20:37:58 +04:00
|
|
|
// unclear if these are needed, but can't hurt
|
|
|
|
mEventManager->NotifyDestroyPresContext(this);
|
|
|
|
mEventManager->SetPresContext(nsnull);
|
|
|
|
|
2003-06-19 22:16:53 +04:00
|
|
|
NS_RELEASE(mEventManager);
|
|
|
|
}
|
1998-11-18 08:25:26 +03:00
|
|
|
|
2005-08-24 03:52:16 +04:00
|
|
|
if (mPrefChangedTimer)
|
|
|
|
{
|
|
|
|
mPrefChangedTimer->Cancel();
|
|
|
|
mPrefChangedTimer = nsnull;
|
|
|
|
}
|
|
|
|
|
2002-12-11 08:11:02 +03:00
|
|
|
// Unregister preference callbacks
|
2011-05-29 03:42:57 +04:00
|
|
|
Preferences::UnregisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"font.",
|
|
|
|
this);
|
|
|
|
Preferences::UnregisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"browser.display.",
|
|
|
|
this);
|
|
|
|
Preferences::UnregisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"browser.underline_anchors",
|
|
|
|
this);
|
|
|
|
Preferences::UnregisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"browser.anchor_color",
|
|
|
|
this);
|
|
|
|
Preferences::UnregisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"browser.active_color",
|
|
|
|
this);
|
|
|
|
Preferences::UnregisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"browser.visited_color",
|
|
|
|
this);
|
|
|
|
Preferences::UnregisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"image.animation_mode",
|
|
|
|
this);
|
2004-04-30 07:10:29 +04:00
|
|
|
#ifdef IBMBIDI
|
2011-05-29 03:42:57 +04:00
|
|
|
Preferences::UnregisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"bidi.",
|
|
|
|
this);
|
2001-03-09 06:13:03 +03:00
|
|
|
#endif // IBMBIDI
|
2011-05-29 03:42:57 +04:00
|
|
|
Preferences::UnregisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"dom.send_after_paint_to_content",
|
|
|
|
this);
|
|
|
|
Preferences::UnregisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"gfx.font_rendering.",
|
|
|
|
this);
|
|
|
|
Preferences::UnregisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"layout.css.dpi",
|
|
|
|
this);
|
|
|
|
Preferences::UnregisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"layout.css.devPixelsPerPx",
|
|
|
|
this);
|
2003-06-19 22:16:53 +04:00
|
|
|
|
|
|
|
NS_IF_RELEASE(mDeviceContext);
|
2010-02-24 20:57:44 +03:00
|
|
|
NS_IF_RELEASE(mLanguage);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2007-08-11 01:25:24 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(nsPresContext)
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsPresContext)
|
2010-03-25 16:17:11 +03:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
2007-08-11 01:25:24 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIObserver)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsPresContext)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsPresContext)
|
|
|
|
|
2008-10-10 19:04:34 +04:00
|
|
|
static PLDHashOperator
|
2009-02-19 22:03:28 +03:00
|
|
|
TraverseImageLoader(const void * aKey, nsRefPtr<nsImageLoader>& aData,
|
2007-08-11 01:25:24 +04:00
|
|
|
void* aClosure)
|
|
|
|
{
|
|
|
|
nsCycleCollectionTraversalCallback *cb =
|
|
|
|
static_cast<nsCycleCollectionTraversalCallback*>(aClosure);
|
|
|
|
|
|
|
|
cb->NoteXPCOMChild(aData);
|
|
|
|
|
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsPresContext)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mDocument);
|
2011-04-17 05:22:42 +04:00
|
|
|
// NS_IMPL_CYCLE_COLLECTION_TRAVERSE_RAWPTR(mDeviceContext); // not xpcom
|
2011-04-21 21:35:52 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR_AMBIGUOUS(mEventManager, nsIObserver);
|
2010-02-24 20:57:44 +03:00
|
|
|
// NS_IMPL_CYCLE_COLLECTION_TRAVERSE_RAWPTR(mLanguage); // an atom
|
2007-08-11 01:25:24 +04:00
|
|
|
|
2009-02-19 22:03:28 +03:00
|
|
|
for (PRUint32 i = 0; i < IMAGE_LOAD_TYPE_COUNT; ++i)
|
|
|
|
tmp->mImageLoaders[i].Enumerate(TraverseImageLoader, &cb);
|
2007-08-11 01:25:24 +04:00
|
|
|
|
|
|
|
// NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mTheme); // a service
|
|
|
|
// NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mLangService); // a service
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mPrintSettings);
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mPrefChangedTimer);
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsPresContext)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mDocument);
|
|
|
|
NS_RELEASE(tmp->mDeviceContext); // worth bothering?
|
|
|
|
if (tmp->mEventManager) {
|
|
|
|
// unclear if these are needed, but can't hurt
|
|
|
|
tmp->mEventManager->NotifyDestroyPresContext(tmp);
|
|
|
|
tmp->mEventManager->SetPresContext(nsnull);
|
|
|
|
|
|
|
|
NS_RELEASE(tmp->mEventManager);
|
|
|
|
}
|
|
|
|
|
2010-02-24 20:57:44 +03:00
|
|
|
// NS_RELEASE(tmp->mLanguage); // an atom
|
2007-08-11 01:25:24 +04:00
|
|
|
|
|
|
|
// NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mTheme); // a service
|
|
|
|
// NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mLangService); // a service
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mPrintSettings);
|
|
|
|
if (tmp->mPrefChangedTimer)
|
|
|
|
{
|
|
|
|
tmp->mPrefChangedTimer->Cancel();
|
|
|
|
tmp->mPrefChangedTimer = nsnull;
|
|
|
|
}
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2001-09-27 22:34:30 +04:00
|
|
|
#define MAKE_FONT_PREF_KEY(_pref, _s0, _s1) \
|
|
|
|
_pref.Assign(_s0); \
|
|
|
|
_pref.Append(_s1);
|
|
|
|
|
|
|
|
static const char* const kGenericFont[] = {
|
|
|
|
".variable.",
|
|
|
|
".fixed.",
|
|
|
|
".serif.",
|
|
|
|
".sans-serif.",
|
|
|
|
".monospace.",
|
|
|
|
".cursive.",
|
|
|
|
".fantasy."
|
|
|
|
};
|
|
|
|
|
2009-02-26 23:02:00 +03:00
|
|
|
// whether no native theme service exists;
|
|
|
|
// if this gets set to true, we'll stop asking for it.
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool sNoTheme = false;
|
2009-02-26 23:02:00 +03:00
|
|
|
|
2006-09-12 08:36:03 +04:00
|
|
|
// Set to true when LookAndFeelChanged needs to be called. This is used
|
|
|
|
// because the look and feel is a service, so there's no need to notify it from
|
|
|
|
// more than one prescontext.
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool sLookAndFeelChanged;
|
2006-09-12 08:36:03 +04:00
|
|
|
|
|
|
|
// Set to true when ThemeChanged needs to be called on mTheme. This is used
|
|
|
|
// because mTheme is a service, so there's no need to notify it from more than
|
|
|
|
// one prescontext.
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool sThemeChanged;
|
2006-09-12 08:36:03 +04:00
|
|
|
|
2000-01-12 19:10:48 +03:00
|
|
|
void
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::GetFontPreferences()
|
2000-01-12 19:10:48 +03:00
|
|
|
{
|
2001-09-27 22:34:30 +04:00
|
|
|
/* Fetch the font prefs to be used -- see bug 61883 for details.
|
|
|
|
Not all prefs are needed upfront. Some are fallback prefs intended
|
|
|
|
for the GFX font sub-system...
|
|
|
|
|
|
|
|
1) unit : assumed to be the same for all language groups -------------
|
|
|
|
font.size.unit = px | pt XXX could be folded in the size... bug 90440
|
|
|
|
|
|
|
|
2) attributes for generic fonts --------------------------------------
|
|
|
|
font.default = serif | sans-serif - fallback generic font
|
|
|
|
font.name.[generic].[langGroup] = current user' selected font on the pref dialog
|
|
|
|
font.name-list.[generic].[langGroup] = fontname1, fontname2, ... [factory pre-built list]
|
|
|
|
font.size.[generic].[langGroup] = integer - settable by the user
|
|
|
|
font.size-adjust.[generic].[langGroup] = "float" - settable by the user
|
|
|
|
font.minimum-size.[langGroup] = integer - settable by the user
|
|
|
|
*/
|
|
|
|
|
2007-02-07 10:46:44 +03:00
|
|
|
mDefaultVariableFont.size = CSSPixelsToAppUnits(16);
|
|
|
|
mDefaultFixedFont.size = CSSPixelsToAppUnits(13);
|
2001-09-27 22:34:30 +04:00
|
|
|
|
2010-02-24 20:57:44 +03:00
|
|
|
// the font prefs are based on langGroup, not actual language
|
2010-03-08 18:45:00 +03:00
|
|
|
nsCAutoString langGroup;
|
2010-02-24 20:57:44 +03:00
|
|
|
if (mLanguage && mLangService) {
|
|
|
|
nsresult rv;
|
|
|
|
nsIAtom *group = mLangService->GetLanguageGroup(mLanguage, &rv);
|
|
|
|
if (NS_SUCCEEDED(rv) && group) {
|
2010-03-08 18:45:00 +03:00
|
|
|
group->ToUTF8String(langGroup);
|
2010-02-24 20:57:44 +03:00
|
|
|
}
|
2010-03-08 18:45:00 +03:00
|
|
|
else {
|
|
|
|
langGroup.AssignLiteral("x-western"); // Assume x-western is safe...
|
2010-02-24 20:57:44 +03:00
|
|
|
}
|
2007-10-12 02:54:18 +04:00
|
|
|
}
|
2010-03-08 18:45:00 +03:00
|
|
|
else {
|
|
|
|
langGroup.AssignLiteral("x-western"); // Assume x-western is safe...
|
2007-10-12 02:54:18 +04:00
|
|
|
}
|
2001-09-27 22:34:30 +04:00
|
|
|
|
|
|
|
nsCAutoString pref;
|
|
|
|
|
|
|
|
// get the current applicable font-size unit
|
|
|
|
enum {eUnit_unknown = -1, eUnit_px, eUnit_pt};
|
|
|
|
PRInt32 unit = eUnit_px;
|
2004-04-30 08:06:30 +04:00
|
|
|
|
|
|
|
nsAdoptingCString cvalue =
|
2011-05-28 11:03:00 +04:00
|
|
|
Preferences::GetCString("font.size.unit");
|
2004-04-30 08:06:30 +04:00
|
|
|
|
|
|
|
if (!cvalue.IsEmpty()) {
|
|
|
|
if (cvalue.Equals("px")) {
|
2001-09-27 22:34:30 +04:00
|
|
|
unit = eUnit_px;
|
2000-01-12 19:10:48 +03:00
|
|
|
}
|
2004-04-30 08:06:30 +04:00
|
|
|
else if (cvalue.Equals("pt")) {
|
2001-09-27 22:34:30 +04:00
|
|
|
unit = eUnit_pt;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
NS_WARNING("unexpected font-size unit -- expected: 'px' or 'pt'");
|
|
|
|
unit = eUnit_unknown;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// get font.minimum-size.[langGroup]
|
2003-06-24 05:46:50 +04:00
|
|
|
|
|
|
|
pref.Assign("font.minimum-size.");
|
2004-06-09 03:53:59 +04:00
|
|
|
pref.Append(langGroup);
|
2003-06-24 05:46:50 +04:00
|
|
|
|
2011-05-25 10:32:00 +04:00
|
|
|
PRInt32 size = Preferences::GetInt(pref.get());
|
2006-08-08 20:43:20 +04:00
|
|
|
if (unit == eUnit_px) {
|
2011-03-11 07:33:43 +03:00
|
|
|
mMinimumFontSizePref = CSSPixelsToAppUnits(size);
|
2006-08-08 20:43:20 +04:00
|
|
|
}
|
|
|
|
else if (unit == eUnit_pt) {
|
2011-03-11 07:33:43 +03:00
|
|
|
mMinimumFontSizePref = CSSPointsToAppUnits(size);
|
2001-09-27 22:34:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// get attributes specific to each generic font
|
|
|
|
nsCAutoString generic_dot_langGroup;
|
|
|
|
for (PRInt32 eType = eDefaultFont_Variable; eType < eDefaultFont_COUNT; ++eType) {
|
|
|
|
generic_dot_langGroup.Assign(kGenericFont[eType]);
|
2004-06-09 03:53:59 +04:00
|
|
|
generic_dot_langGroup.Append(langGroup);
|
2001-09-27 22:34:30 +04:00
|
|
|
|
2002-12-11 08:11:02 +03:00
|
|
|
nsFont* font;
|
2001-09-27 22:34:30 +04:00
|
|
|
switch (eType) {
|
|
|
|
case eDefaultFont_Variable: font = &mDefaultVariableFont; break;
|
|
|
|
case eDefaultFont_Fixed: font = &mDefaultFixedFont; break;
|
|
|
|
case eDefaultFont_Serif: font = &mDefaultSerifFont; break;
|
|
|
|
case eDefaultFont_SansSerif: font = &mDefaultSansSerifFont; break;
|
|
|
|
case eDefaultFont_Monospace: font = &mDefaultMonospaceFont; break;
|
|
|
|
case eDefaultFont_Cursive: font = &mDefaultCursiveFont; break;
|
|
|
|
case eDefaultFont_Fantasy: font = &mDefaultFantasyFont; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// set the default variable font (the other fonts are seen as 'generic' fonts
|
|
|
|
// in GFX and will be queried there when hunting for alternative fonts)
|
|
|
|
if (eType == eDefaultFont_Variable) {
|
|
|
|
MAKE_FONT_PREF_KEY(pref, "font.name", generic_dot_langGroup);
|
2004-04-30 08:06:30 +04:00
|
|
|
|
2011-05-28 11:03:00 +04:00
|
|
|
nsAdoptingString value = Preferences::GetString(pref.get());
|
2004-04-30 08:06:30 +04:00
|
|
|
if (!value.IsEmpty()) {
|
2002-12-11 08:11:02 +03:00
|
|
|
font->name.Assign(value);
|
2000-01-15 19:30:13 +03:00
|
|
|
}
|
2001-09-27 22:34:30 +04:00
|
|
|
else {
|
2005-01-24 02:58:32 +03:00
|
|
|
MAKE_FONT_PREF_KEY(pref, "font.default.", langGroup);
|
2011-05-28 11:03:00 +04:00
|
|
|
value = Preferences::GetString(pref.get());
|
2004-04-30 08:06:30 +04:00
|
|
|
if (!value.IsEmpty()) {
|
2002-12-11 08:11:02 +03:00
|
|
|
mDefaultVariableFont.name.Assign(value);
|
2001-09-27 22:34:30 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (eType == eDefaultFont_Monospace) {
|
|
|
|
// This takes care of the confusion whereby people often expect "monospace"
|
|
|
|
// to have the same default font-size as "-moz-fixed" (this tentative
|
|
|
|
// size may be overwritten with the specific value for "monospace" when
|
|
|
|
// "font.size.monospace.[langGroup]" is read -- see below)
|
|
|
|
font->size = mDefaultFixedFont.size;
|
2000-01-15 19:30:13 +03:00
|
|
|
}
|
2001-09-27 22:34:30 +04:00
|
|
|
else if (eType != eDefaultFont_Fixed) {
|
|
|
|
// all the other generic fonts are initialized with the size of the
|
|
|
|
// variable font, but their specific size can supersede later -- see below
|
|
|
|
font->size = mDefaultVariableFont.size;
|
2000-01-15 19:30:13 +03:00
|
|
|
}
|
2001-09-27 22:34:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Bug 84398: for spec purists, a different font-size only applies to the
|
|
|
|
// .variable. and .fixed. fonts and the other fonts should get |font-size-adjust|.
|
|
|
|
// The problem is that only GfxWin has the support for |font-size-adjust|. So for
|
|
|
|
// parity, we enable the ability to set a different font-size on all platforms.
|
|
|
|
|
|
|
|
// get font.size.[generic].[langGroup]
|
|
|
|
// size=0 means 'Auto', i.e., generic fonts retain the size of the variable font
|
|
|
|
MAKE_FONT_PREF_KEY(pref, "font.size", generic_dot_langGroup);
|
2011-05-25 10:32:00 +04:00
|
|
|
size = Preferences::GetInt(pref.get());
|
2004-04-30 08:06:30 +04:00
|
|
|
if (size > 0) {
|
2001-09-27 22:34:30 +04:00
|
|
|
if (unit == eUnit_px) {
|
2010-08-13 13:58:04 +04:00
|
|
|
font->size = CSSPixelsToAppUnits(size);
|
2000-01-15 19:30:13 +03:00
|
|
|
}
|
2001-09-27 22:34:30 +04:00
|
|
|
else if (unit == eUnit_pt) {
|
2010-08-13 13:58:04 +04:00
|
|
|
font->size = CSSPointsToAppUnits(size);
|
2000-01-15 19:30:13 +03:00
|
|
|
}
|
2000-01-12 19:10:48 +03:00
|
|
|
}
|
2001-09-27 22:34:30 +04:00
|
|
|
|
|
|
|
// get font.size-adjust.[generic].[langGroup]
|
|
|
|
// XXX only applicable on GFX ports that handle |font-size-adjust|
|
|
|
|
MAKE_FONT_PREF_KEY(pref, "font.size-adjust", generic_dot_langGroup);
|
2011-05-28 11:03:00 +04:00
|
|
|
cvalue = Preferences::GetCString(pref.get());
|
2004-04-30 08:06:30 +04:00
|
|
|
if (!cvalue.IsEmpty()) {
|
2001-09-27 22:34:30 +04:00
|
|
|
font->sizeAdjust = (float)atof(cvalue.get());
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG_rbs
|
|
|
|
printf("%s Family-list:%s size:%d sizeAdjust:%.2f\n",
|
2004-04-30 08:06:30 +04:00
|
|
|
generic_dot_langGroup.get(),
|
2006-02-03 17:18:39 +03:00
|
|
|
NS_ConvertUTF16toUTF8(font->name).get(), font->size,
|
2003-06-24 05:46:50 +04:00
|
|
|
font->sizeAdjust);
|
2001-09-27 22:34:30 +04:00
|
|
|
#endif
|
2000-01-12 19:10:48 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-10-17 03:59:25 +04:00
|
|
|
void
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::GetDocumentColorPreferences()
|
2001-10-17 03:59:25 +04:00
|
|
|
{
|
2004-06-08 23:34:55 +04:00
|
|
|
PRInt32 useAccessibilityTheme = 0;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool usePrefColors = true;
|
2002-11-07 03:59:25 +03:00
|
|
|
nsCOMPtr<nsIDocShellTreeItem> docShell(do_QueryReferent(mContainer));
|
2001-10-17 03:59:25 +04:00
|
|
|
if (docShell) {
|
|
|
|
PRInt32 docShellType;
|
|
|
|
docShell->GetItemType(&docShellType);
|
2004-06-08 23:34:55 +04:00
|
|
|
if (nsIDocShellTreeItem::typeChrome == docShellType) {
|
2001-10-17 03:59:25 +04:00
|
|
|
usePrefColors = PR_FALSE;
|
2004-06-08 23:34:55 +04:00
|
|
|
}
|
|
|
|
else {
|
2011-09-09 06:27:13 +04:00
|
|
|
useAccessibilityTheme =
|
|
|
|
LookAndFeel::GetInt(LookAndFeel::eIntID_UseAccessibilityTheme, 0);
|
2004-06-08 23:34:55 +04:00
|
|
|
usePrefColors = !useAccessibilityTheme;
|
|
|
|
}
|
|
|
|
|
2001-10-17 03:59:25 +04:00
|
|
|
}
|
|
|
|
if (usePrefColors) {
|
2004-04-30 08:06:30 +04:00
|
|
|
usePrefColors =
|
2011-09-29 10:19:26 +04:00
|
|
|
!Preferences::GetBool("browser.display.use_system_colors", false);
|
2001-10-17 03:59:25 +04:00
|
|
|
}
|
2004-04-30 08:06:30 +04:00
|
|
|
|
2001-10-17 03:59:25 +04:00
|
|
|
if (usePrefColors) {
|
2004-04-30 08:06:30 +04:00
|
|
|
nsAdoptingCString colorStr =
|
2011-05-28 11:03:00 +04:00
|
|
|
Preferences::GetCString("browser.display.foreground_color");
|
2004-04-30 08:06:30 +04:00
|
|
|
|
|
|
|
if (!colorStr.IsEmpty()) {
|
2001-10-17 03:59:25 +04:00
|
|
|
mDefaultColor = MakeColorPref(colorStr);
|
|
|
|
}
|
2004-04-30 08:06:30 +04:00
|
|
|
|
2011-05-28 11:03:00 +04:00
|
|
|
colorStr = Preferences::GetCString("browser.display.background_color");
|
2004-04-30 08:06:30 +04:00
|
|
|
|
|
|
|
if (!colorStr.IsEmpty()) {
|
2004-02-01 01:41:40 +03:00
|
|
|
mBackgroundColor = MakeColorPref(colorStr);
|
2001-10-17 03:59:25 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2011-09-09 06:27:13 +04:00
|
|
|
mDefaultColor =
|
|
|
|
LookAndFeel::GetColor(LookAndFeel::eColorID_WindowForeground,
|
|
|
|
NS_RGB(0x00, 0x00, 0x00));
|
|
|
|
mBackgroundColor =
|
|
|
|
LookAndFeel::GetColor(LookAndFeel::eColorID_WindowBackground,
|
|
|
|
NS_RGB(0xFF, 0xFF, 0xFF));
|
2001-10-17 03:59:25 +04:00
|
|
|
}
|
|
|
|
|
2008-09-19 21:06:46 +04:00
|
|
|
// Wherever we got the default background color from, ensure it is
|
|
|
|
// opaque.
|
|
|
|
mBackgroundColor = NS_ComposeColors(NS_RGB(0xFF, 0xFF, 0xFF),
|
|
|
|
mBackgroundColor);
|
|
|
|
|
2004-06-08 23:34:55 +04:00
|
|
|
mUseDocumentColors = !useAccessibilityTheme &&
|
2011-05-25 10:31:59 +04:00
|
|
|
Preferences::GetBool("browser.display.use_document_colors",
|
|
|
|
mUseDocumentColors);
|
2001-10-17 03:59:25 +04:00
|
|
|
}
|
|
|
|
|
1998-11-06 19:16:01 +03:00
|
|
|
void
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::GetUserPreferences()
|
1998-11-06 19:16:01 +03:00
|
|
|
{
|
2005-11-09 01:45:49 +03:00
|
|
|
if (!GetPresShell()) {
|
|
|
|
// No presshell means nothing to do here. We'll do this when we
|
|
|
|
// get a presshell.
|
|
|
|
return;
|
|
|
|
}
|
2008-02-08 22:52:46 +03:00
|
|
|
|
|
|
|
mAutoQualityMinFontSizePixelsPref =
|
2011-05-25 10:32:00 +04:00
|
|
|
Preferences::GetInt("browser.display.auto_quality_min_font_size");
|
2008-02-08 22:52:46 +03:00
|
|
|
|
2000-10-11 12:33:01 +04:00
|
|
|
// * document colors
|
2001-10-17 03:59:25 +04:00
|
|
|
GetDocumentColorPreferences();
|
2001-03-29 11:16:06 +04:00
|
|
|
|
2011-01-25 03:23:08 +03:00
|
|
|
mSendAfterPaintToContent =
|
2011-05-25 10:31:59 +04:00
|
|
|
Preferences::GetBool("dom.send_after_paint_to_content",
|
|
|
|
mSendAfterPaintToContent);
|
2011-01-25 03:23:08 +03:00
|
|
|
|
2000-10-11 12:33:01 +04:00
|
|
|
// * link colors
|
2004-04-30 08:06:30 +04:00
|
|
|
mUnderlineLinks =
|
2011-05-25 10:31:59 +04:00
|
|
|
Preferences::GetBool("browser.underline_anchors", mUnderlineLinks);
|
2004-04-30 08:06:30 +04:00
|
|
|
|
2011-05-28 11:03:00 +04:00
|
|
|
nsAdoptingCString colorStr = Preferences::GetCString("browser.anchor_color");
|
2004-04-30 08:06:30 +04:00
|
|
|
|
|
|
|
if (!colorStr.IsEmpty()) {
|
2002-12-11 08:11:02 +03:00
|
|
|
mLinkColor = MakeColorPref(colorStr);
|
2000-10-11 12:33:01 +04:00
|
|
|
}
|
2004-04-30 08:06:30 +04:00
|
|
|
|
2011-05-28 11:03:00 +04:00
|
|
|
colorStr = Preferences::GetCString("browser.active_color");
|
2004-04-30 08:06:30 +04:00
|
|
|
|
|
|
|
if (!colorStr.IsEmpty()) {
|
2003-10-15 05:56:12 +04:00
|
|
|
mActiveLinkColor = MakeColorPref(colorStr);
|
|
|
|
}
|
2004-04-30 08:06:30 +04:00
|
|
|
|
2011-05-28 11:03:00 +04:00
|
|
|
colorStr = Preferences::GetCString("browser.visited_color");
|
2004-04-30 08:06:30 +04:00
|
|
|
|
|
|
|
if (!colorStr.IsEmpty()) {
|
2002-12-11 08:11:02 +03:00
|
|
|
mVisitedLinkColor = MakeColorPref(colorStr);
|
2000-10-11 12:33:01 +04:00
|
|
|
}
|
|
|
|
|
2004-04-30 08:06:30 +04:00
|
|
|
mUseFocusColors =
|
2011-05-25 10:31:59 +04:00
|
|
|
Preferences::GetBool("browser.display.use_focus_colors", mUseFocusColors);
|
2001-04-10 02:17:11 +04:00
|
|
|
|
2004-04-30 08:06:30 +04:00
|
|
|
mFocusTextColor = mDefaultColor;
|
|
|
|
mFocusBackgroundColor = mBackgroundColor;
|
|
|
|
|
2011-05-28 11:03:00 +04:00
|
|
|
colorStr = Preferences::GetCString("browser.display.focus_text_color");
|
2001-04-10 02:17:11 +04:00
|
|
|
|
2004-04-30 08:06:30 +04:00
|
|
|
if (!colorStr.IsEmpty()) {
|
|
|
|
mFocusTextColor = MakeColorPref(colorStr);
|
2001-04-10 02:17:11 +04:00
|
|
|
}
|
|
|
|
|
2011-05-28 11:03:00 +04:00
|
|
|
colorStr = Preferences::GetCString("browser.display.focus_background_color");
|
2004-04-30 08:06:30 +04:00
|
|
|
|
|
|
|
if (!colorStr.IsEmpty()) {
|
|
|
|
mFocusBackgroundColor = MakeColorPref(colorStr);
|
2004-04-30 07:10:29 +04:00
|
|
|
}
|
2004-04-30 03:34:19 +04:00
|
|
|
|
2004-04-30 08:06:30 +04:00
|
|
|
mFocusRingWidth =
|
2011-05-25 10:32:00 +04:00
|
|
|
Preferences::GetInt("browser.display.focus_ring_width", mFocusRingWidth);
|
2004-04-30 08:06:30 +04:00
|
|
|
|
|
|
|
mFocusRingOnAnything =
|
2011-05-25 10:31:59 +04:00
|
|
|
Preferences::GetBool("browser.display.focus_ring_on_anything",
|
|
|
|
mFocusRingOnAnything);
|
2004-04-30 08:06:30 +04:00
|
|
|
|
2008-10-09 03:28:31 +04:00
|
|
|
mFocusRingStyle =
|
2011-05-25 10:32:00 +04:00
|
|
|
Preferences::GetInt("browser.display.focus_ring_style", mFocusRingStyle);
|
2011-06-01 15:43:31 +04:00
|
|
|
|
|
|
|
mBodyTextColor = mDefaultColor;
|
|
|
|
|
2000-10-11 12:33:01 +04:00
|
|
|
// * use fonts?
|
2004-04-30 08:06:30 +04:00
|
|
|
mUseDocumentFonts =
|
2011-05-25 10:32:00 +04:00
|
|
|
Preferences::GetInt("browser.display.use_document_fonts") != 0;
|
2004-04-30 08:06:30 +04:00
|
|
|
|
2004-06-21 14:32:27 +04:00
|
|
|
// * replace backslashes with Yen signs? (bug 245770)
|
|
|
|
mEnableJapaneseTransform =
|
2011-05-25 10:31:59 +04:00
|
|
|
Preferences::GetBool("layout.enable_japanese_specific_transform");
|
2004-06-21 14:32:27 +04:00
|
|
|
|
2011-05-25 10:32:00 +04:00
|
|
|
mPrefScrollbarSide = Preferences::GetInt("layout.scrollbar.side");
|
2006-03-26 04:48:03 +04:00
|
|
|
|
2000-01-12 19:10:48 +03:00
|
|
|
GetFontPreferences();
|
2001-01-10 02:55:27 +03:00
|
|
|
|
|
|
|
// * image animation
|
2004-04-30 08:06:30 +04:00
|
|
|
const nsAdoptingCString& animatePref =
|
2011-05-28 11:03:00 +04:00
|
|
|
Preferences::GetCString("image.animation_mode");
|
2004-04-30 08:06:30 +04:00
|
|
|
if (animatePref.Equals("normal"))
|
|
|
|
mImageAnimationModePref = imgIContainer::kNormalAnimMode;
|
|
|
|
else if (animatePref.Equals("none"))
|
|
|
|
mImageAnimationModePref = imgIContainer::kDontAnimMode;
|
|
|
|
else if (animatePref.Equals("once"))
|
|
|
|
mImageAnimationModePref = imgIContainer::kLoopOnceAnimMode;
|
2008-02-08 22:52:46 +03:00
|
|
|
else // dynamic change to invalid value should act like it does initially
|
|
|
|
mImageAnimationModePref = imgIContainer::kNormalAnimMode;
|
2001-11-01 08:49:45 +03:00
|
|
|
|
2005-11-09 01:45:49 +03:00
|
|
|
PRUint32 bidiOptions = GetBidi();
|
|
|
|
|
2004-04-30 08:06:30 +04:00
|
|
|
PRInt32 prefInt =
|
2011-05-25 10:32:00 +04:00
|
|
|
Preferences::GetInt(IBMBIDI_TEXTDIRECTION_STR,
|
|
|
|
GET_BIDI_OPTION_DIRECTION(bidiOptions));
|
2005-11-09 01:45:49 +03:00
|
|
|
SET_BIDI_OPTION_DIRECTION(bidiOptions, prefInt);
|
2006-03-26 04:48:03 +04:00
|
|
|
mPrefBidiDirection = prefInt;
|
2004-04-30 08:06:30 +04:00
|
|
|
|
|
|
|
prefInt =
|
2011-05-25 10:32:00 +04:00
|
|
|
Preferences::GetInt(IBMBIDI_TEXTTYPE_STR,
|
|
|
|
GET_BIDI_OPTION_TEXTTYPE(bidiOptions));
|
2005-11-09 01:45:49 +03:00
|
|
|
SET_BIDI_OPTION_TEXTTYPE(bidiOptions, prefInt);
|
2004-04-30 08:06:30 +04:00
|
|
|
|
|
|
|
prefInt =
|
2011-05-25 10:32:00 +04:00
|
|
|
Preferences::GetInt(IBMBIDI_NUMERAL_STR,
|
|
|
|
GET_BIDI_OPTION_NUMERAL(bidiOptions));
|
2005-11-09 01:45:49 +03:00
|
|
|
SET_BIDI_OPTION_NUMERAL(bidiOptions, prefInt);
|
2004-04-30 08:06:30 +04:00
|
|
|
|
|
|
|
prefInt =
|
2011-05-25 10:32:00 +04:00
|
|
|
Preferences::GetInt(IBMBIDI_SUPPORTMODE_STR,
|
|
|
|
GET_BIDI_OPTION_SUPPORT(bidiOptions));
|
2005-11-09 01:45:49 +03:00
|
|
|
SET_BIDI_OPTION_SUPPORT(bidiOptions, prefInt);
|
2004-04-30 08:06:30 +04:00
|
|
|
|
2005-11-13 12:55:09 +03:00
|
|
|
// We don't need to force reflow: either we are initializing a new
|
|
|
|
// prescontext or we are being called from UpdateAfterPreferencesChanged()
|
|
|
|
// which triggers a reflow anyway.
|
|
|
|
SetBidi(bidiOptions, PR_FALSE);
|
1998-11-06 19:16:01 +03:00
|
|
|
}
|
|
|
|
|
2011-04-12 00:57:29 +04:00
|
|
|
void
|
2011-06-09 11:13:05 +04:00
|
|
|
nsPresContext::InvalidateThebesLayers()
|
2011-04-12 00:57:29 +04:00
|
|
|
{
|
2011-06-09 11:13:05 +04:00
|
|
|
if (!mShell)
|
|
|
|
return;
|
2011-04-12 00:57:29 +04:00
|
|
|
nsIFrame* rootFrame = mShell->FrameManager()->GetRootFrame();
|
|
|
|
if (rootFrame) {
|
|
|
|
// FrameLayerBuilder caches invalidation-related values that depend on the
|
|
|
|
// appunits-per-dev-pixel ratio, so ensure that all ThebesLayer drawing
|
|
|
|
// is completely flushed.
|
|
|
|
FrameLayerBuilder::InvalidateThebesLayersInSubtree(rootFrame);
|
|
|
|
}
|
2011-06-09 11:13:05 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsPresContext::AppUnitsPerDevPixelChanged()
|
|
|
|
{
|
|
|
|
InvalidateThebesLayers();
|
2011-04-12 00:57:29 +04:00
|
|
|
|
|
|
|
mDeviceContext->FlushFontCache();
|
|
|
|
|
|
|
|
// All cached style data must be recomputed.
|
|
|
|
if (HasCachedStyleData()) {
|
|
|
|
MediaFeatureValuesChanged(PR_TRUE);
|
|
|
|
RebuildAllStyleData(NS_STYLE_HINT_REFLOW);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-04-03 01:52:17 +04:00
|
|
|
void
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::PreferenceChanged(const char* aPrefName)
|
2000-04-03 01:52:17 +04:00
|
|
|
{
|
2008-02-08 22:52:46 +03:00
|
|
|
nsDependentCString prefName(aPrefName);
|
2009-05-18 02:09:53 +04:00
|
|
|
if (prefName.EqualsLiteral("layout.css.dpi") ||
|
|
|
|
prefName.EqualsLiteral("layout.css.devPixelsPerPx")) {
|
2007-12-17 07:59:59 +03:00
|
|
|
PRInt32 oldAppUnitsPerDevPixel = AppUnitsPerDevPixel();
|
2007-02-15 12:04:25 +03:00
|
|
|
if (mDeviceContext->CheckDPIChange() && mShell) {
|
2007-12-17 07:59:59 +03:00
|
|
|
// Re-fetch the view manager's window dimensions in case there's a deferred
|
|
|
|
// resize which hasn't affected our mVisibleArea yet
|
|
|
|
nscoord oldWidthAppUnits, oldHeightAppUnits;
|
2009-03-11 18:43:08 +03:00
|
|
|
nsIViewManager* vm = mShell->GetViewManager();
|
2007-12-17 07:59:59 +03:00
|
|
|
vm->GetWindowDimensions(&oldWidthAppUnits, &oldHeightAppUnits);
|
|
|
|
float oldWidthDevPixels = oldWidthAppUnits/oldAppUnitsPerDevPixel;
|
|
|
|
float oldHeightDevPixels = oldHeightAppUnits/oldAppUnitsPerDevPixel;
|
|
|
|
|
2007-12-12 05:27:00 +03:00
|
|
|
nscoord width = NSToCoordRound(oldWidthDevPixels*AppUnitsPerDevPixel());
|
|
|
|
nscoord height = NSToCoordRound(oldHeightDevPixels*AppUnitsPerDevPixel());
|
2007-02-15 12:04:25 +03:00
|
|
|
vm->SetWindowDimensions(width, height);
|
|
|
|
|
2011-04-12 00:57:29 +04:00
|
|
|
AppUnitsPerDevPixelChanged();
|
2007-02-15 12:04:25 +03:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2008-02-08 22:52:46 +03:00
|
|
|
if (StringBeginsWith(prefName, NS_LITERAL_CSTRING("font."))) {
|
|
|
|
// Changes to font family preferences don't change anything in the
|
|
|
|
// computed style data, so the style system won't generate a reflow
|
|
|
|
// hint for us. We need to do that manually.
|
|
|
|
|
|
|
|
// FIXME We could probably also handle changes to
|
|
|
|
// browser.display.auto_quality_min_font_size here, but that
|
|
|
|
// probably also requires clearing the text run cache, so don't
|
|
|
|
// bother (yet, anyway).
|
|
|
|
mPrefChangePendingNeedsReflow = PR_TRUE;
|
2007-07-26 13:47:43 +04:00
|
|
|
}
|
2008-12-18 23:12:53 +03:00
|
|
|
if (StringBeginsWith(prefName, NS_LITERAL_CSTRING("bidi."))) {
|
|
|
|
// Changes to bidi prefs need to trigger a reflow (see bug 443629)
|
|
|
|
mPrefChangePendingNeedsReflow = PR_TRUE;
|
|
|
|
|
|
|
|
// Changes to bidi.numeral also needs to empty the text run cache.
|
|
|
|
// This is handled in gfxTextRunWordCache.cpp.
|
|
|
|
}
|
2010-06-09 04:33:13 +04:00
|
|
|
if (StringBeginsWith(prefName, NS_LITERAL_CSTRING("gfx.font_rendering."))) {
|
|
|
|
// Changes to font_rendering prefs need to trigger a reflow
|
|
|
|
mPrefChangePendingNeedsReflow = PR_TRUE;
|
|
|
|
}
|
2005-08-24 03:52:16 +04:00
|
|
|
// we use a zero-delay timer to coalesce multiple pref updates
|
|
|
|
if (!mPrefChangedTimer)
|
|
|
|
{
|
|
|
|
mPrefChangedTimer = do_CreateInstance("@mozilla.org/timer;1");
|
|
|
|
if (!mPrefChangedTimer)
|
|
|
|
return;
|
|
|
|
mPrefChangedTimer->InitWithFuncCallback(nsPresContext::PrefChangedUpdateTimerCallback, (void*)this, 0, nsITimer::TYPE_ONE_SHOT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsPresContext::UpdateAfterPreferencesChanged()
|
|
|
|
{
|
|
|
|
mPrefChangedTimer = nsnull;
|
|
|
|
|
2002-11-07 03:59:25 +03:00
|
|
|
nsCOMPtr<nsIDocShellTreeItem> docShell(do_QueryReferent(mContainer));
|
2001-07-25 10:33:06 +04:00
|
|
|
if (docShell) {
|
|
|
|
PRInt32 docShellType;
|
|
|
|
docShell->GetItemType(&docShellType);
|
|
|
|
if (nsIDocShellTreeItem::typeChrome == docShellType)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2000-04-03 01:52:17 +04:00
|
|
|
// Initialize our state from the user preferences
|
|
|
|
GetUserPreferences();
|
2000-10-11 12:33:01 +04:00
|
|
|
|
|
|
|
// update the presShell: tell it to set the preference style rules up
|
|
|
|
if (mShell) {
|
|
|
|
mShell->SetPreferenceStyleRules(PR_TRUE);
|
|
|
|
}
|
|
|
|
|
2011-06-09 11:13:05 +04:00
|
|
|
InvalidateThebesLayers();
|
2004-02-03 01:17:21 +03:00
|
|
|
mDeviceContext->FlushFontCache();
|
2008-02-08 22:52:46 +03:00
|
|
|
|
|
|
|
nsChangeHint hint = nsChangeHint(0);
|
|
|
|
|
|
|
|
if (mPrefChangePendingNeedsReflow) {
|
|
|
|
NS_UpdateHint(hint, NS_STYLE_HINT_REFLOW);
|
|
|
|
}
|
|
|
|
|
|
|
|
RebuildAllStyleData(hint);
|
1998-11-06 19:16:01 +03:00
|
|
|
}
|
|
|
|
|
2004-07-29 23:41:39 +04:00
|
|
|
nsresult
|
2011-04-17 05:22:44 +04:00
|
|
|
nsPresContext::Init(nsDeviceContext* aDeviceContext)
|
1998-06-25 08:24:45 +04:00
|
|
|
{
|
2010-02-07 18:52:43 +03:00
|
|
|
NS_ASSERTION(!mInitialized, "attempt to reinit pres context");
|
2004-02-03 01:17:21 +03:00
|
|
|
NS_ENSURE_ARG(aDeviceContext);
|
1998-06-25 08:24:45 +04:00
|
|
|
|
2003-06-19 22:16:53 +04:00
|
|
|
mDeviceContext = aDeviceContext;
|
2004-02-03 01:17:21 +03:00
|
|
|
NS_ADDREF(mDeviceContext);
|
1998-07-31 09:54:59 +04:00
|
|
|
|
2007-11-27 07:54:30 +03:00
|
|
|
if (mDeviceContext->SetPixelScale(mFullZoom))
|
|
|
|
mDeviceContext->FlushFontCache();
|
2007-08-24 21:46:59 +04:00
|
|
|
mCurAppUnitsPerDevPixel = AppUnitsPerDevPixel();
|
|
|
|
|
2009-02-19 22:03:28 +03:00
|
|
|
for (PRUint32 i = 0; i < IMAGE_LOAD_TYPE_COUNT; ++i)
|
|
|
|
if (!mImageLoaders[i].Init())
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2004-01-21 12:35:59 +03:00
|
|
|
|
2004-02-27 20:17:37 +03:00
|
|
|
mEventManager = new nsEventStateManager();
|
2004-02-27 21:24:36 +03:00
|
|
|
NS_ADDREF(mEventManager);
|
|
|
|
|
2009-10-08 07:22:42 +04:00
|
|
|
mTransitionManager = new nsTransitionManager(this);
|
2009-12-23 22:10:30 +03:00
|
|
|
|
2011-04-12 10:18:44 +04:00
|
|
|
mAnimationManager = new nsAnimationManager(this);
|
|
|
|
|
2010-08-12 01:05:27 +04:00
|
|
|
if (mDocument->GetDisplayDocument()) {
|
|
|
|
NS_ASSERTION(mDocument->GetDisplayDocument()->GetShell() &&
|
|
|
|
mDocument->GetDisplayDocument()->GetShell()->GetPresContext(),
|
|
|
|
"Why are we being initialized?");
|
|
|
|
mRefreshDriver = mDocument->GetDisplayDocument()->GetShell()->
|
|
|
|
GetPresContext()->RefreshDriver();
|
|
|
|
} else {
|
2010-09-07 23:10:41 +04:00
|
|
|
nsIDocument* parent = mDocument->GetParentDocument();
|
|
|
|
// Unfortunately, sometimes |parent| here has no presshell because
|
|
|
|
// printing screws up things. Assert that in other cases it does,
|
|
|
|
// but whenever the shell is null just fall back on using our own
|
|
|
|
// refresh driver.
|
|
|
|
NS_ASSERTION(!parent || mDocument->IsStaticDocument() || parent->GetShell(),
|
|
|
|
"How did we end up with a presshell if our parent doesn't "
|
|
|
|
"have one?");
|
|
|
|
if (parent && parent->GetShell()) {
|
|
|
|
NS_ASSERTION(parent->GetShell()->GetPresContext(),
|
|
|
|
"How did we get a presshell?");
|
|
|
|
|
|
|
|
// We don't have our container set yet at this point
|
|
|
|
nsCOMPtr<nsISupports> ourContainer = mDocument->GetContainer();
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> ourItem = do_QueryInterface(ourContainer);
|
|
|
|
if (ourItem) {
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> parentItem;
|
|
|
|
ourItem->GetSameTypeParent(getter_AddRefs(parentItem));
|
|
|
|
if (parentItem) {
|
|
|
|
mRefreshDriver = parent->GetShell()->GetPresContext()->RefreshDriver();
|
2010-08-12 01:05:27 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mRefreshDriver) {
|
|
|
|
mRefreshDriver = new nsRefreshDriver(this);
|
|
|
|
}
|
|
|
|
}
|
2009-10-08 07:22:42 +04:00
|
|
|
|
2004-04-30 08:06:30 +04:00
|
|
|
mLangService = do_GetService(NS_LANGUAGEATOMSERVICE_CONTRACTID);
|
|
|
|
|
|
|
|
// Register callbacks so we're notified when the preferences change
|
2011-05-29 03:42:57 +04:00
|
|
|
Preferences::RegisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"font.",
|
|
|
|
this);
|
|
|
|
Preferences::RegisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"browser.display.",
|
|
|
|
this);
|
|
|
|
Preferences::RegisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"browser.underline_anchors",
|
|
|
|
this);
|
|
|
|
Preferences::RegisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"browser.anchor_color",
|
|
|
|
this);
|
|
|
|
Preferences::RegisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"browser.active_color",
|
|
|
|
this);
|
|
|
|
Preferences::RegisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"browser.visited_color",
|
|
|
|
this);
|
|
|
|
Preferences::RegisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"image.animation_mode",
|
|
|
|
this);
|
2004-04-30 08:06:30 +04:00
|
|
|
#ifdef IBMBIDI
|
2011-05-29 03:42:57 +04:00
|
|
|
Preferences::RegisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"bidi.",
|
|
|
|
this);
|
2004-04-30 08:06:30 +04:00
|
|
|
#endif
|
2011-05-29 03:42:57 +04:00
|
|
|
Preferences::RegisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"dom.send_after_paint_to_content",
|
|
|
|
this);
|
|
|
|
Preferences::RegisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"gfx.font_rendering.",
|
|
|
|
this);
|
|
|
|
Preferences::RegisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"layout.css.dpi",
|
|
|
|
this);
|
|
|
|
Preferences::RegisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"layout.css.devPixelsPerPx",
|
|
|
|
this);
|
2004-04-30 08:06:30 +04:00
|
|
|
|
2011-09-09 06:27:13 +04:00
|
|
|
nsresult rv = mEventManager->Init();
|
2004-02-27 20:17:37 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
mEventManager->SetPresContext(this);
|
|
|
|
|
1998-06-25 08:24:45 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
mInitialized = PR_TRUE;
|
|
|
|
#endif
|
|
|
|
|
2007-02-07 10:46:44 +03:00
|
|
|
mBorderWidthTable[NS_STYLE_BORDER_WIDTH_THIN] = CSSPixelsToAppUnits(1);
|
|
|
|
mBorderWidthTable[NS_STYLE_BORDER_WIDTH_MEDIUM] = CSSPixelsToAppUnits(3);
|
|
|
|
mBorderWidthTable[NS_STYLE_BORDER_WIDTH_THICK] = CSSPixelsToAppUnits(5);
|
2004-11-26 21:40:58 +03:00
|
|
|
|
1998-06-25 08:24:45 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
// Note: We don't hold a reference on the shell; it has a reference to
|
|
|
|
// us
|
2004-07-29 23:41:39 +04:00
|
|
|
void
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::SetShell(nsIPresShell* aShell)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2009-01-19 12:21:29 +03:00
|
|
|
if (mUserFontSet) {
|
|
|
|
// Clear out user font set if we have one
|
|
|
|
mUserFontSet->Destroy();
|
|
|
|
NS_RELEASE(mUserFontSet);
|
|
|
|
}
|
|
|
|
|
2003-04-25 02:44:48 +04:00
|
|
|
if (mShell) {
|
|
|
|
// Remove ourselves as the charset observer from the shell's doc, because
|
|
|
|
// this shell may be going away for good.
|
2004-08-02 08:52:55 +04:00
|
|
|
nsIDocument *doc = mShell->GetDocument();
|
2003-04-25 02:44:48 +04:00
|
|
|
if (doc) {
|
|
|
|
doc->RemoveCharSetObserver(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
mShell = aShell;
|
2003-04-25 02:44:48 +04:00
|
|
|
|
|
|
|
if (mShell) {
|
2006-07-28 10:22:19 +04:00
|
|
|
nsIDocument *doc = mShell->GetDocument();
|
|
|
|
NS_ASSERTION(doc, "expect document here");
|
|
|
|
if (doc) {
|
|
|
|
// Have to update PresContext's mDocument before calling any other methods.
|
|
|
|
mDocument = doc;
|
|
|
|
}
|
2005-11-09 01:45:49 +03:00
|
|
|
// Initialize our state from the user preferences, now that we
|
|
|
|
// have a presshell, and hence a document.
|
|
|
|
GetUserPreferences();
|
|
|
|
|
2004-08-02 08:52:55 +04:00
|
|
|
if (doc) {
|
2006-03-24 03:09:50 +03:00
|
|
|
nsIURI *docURI = doc->GetDocumentURI();
|
2004-08-02 08:52:55 +04:00
|
|
|
|
2006-04-01 05:19:28 +04:00
|
|
|
if (IsDynamic() && docURI) {
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isChrome = false;
|
|
|
|
bool isRes = false;
|
2006-03-24 03:09:50 +03:00
|
|
|
docURI->SchemeIs("chrome", &isChrome);
|
|
|
|
docURI->SchemeIs("resource", &isRes);
|
2004-08-02 08:52:55 +04:00
|
|
|
|
|
|
|
if (!isChrome && !isRes)
|
|
|
|
mImageAnimationMode = mImageAnimationModePref;
|
|
|
|
else
|
|
|
|
mImageAnimationMode = imgIContainer::kNormalAnimMode;
|
|
|
|
}
|
2001-01-10 02:55:27 +03:00
|
|
|
|
2004-08-02 08:52:55 +04:00
|
|
|
if (mLangService) {
|
|
|
|
doc->AddCharSetObserver(this);
|
2004-08-10 01:19:15 +04:00
|
|
|
UpdateCharSet(doc->GetDocumentCharacterSet());
|
1999-02-12 20:45:58 +03:00
|
|
|
}
|
1998-09-05 07:52:40 +04:00
|
|
|
}
|
2010-01-14 05:30:05 +03:00
|
|
|
} else {
|
2010-12-18 07:45:18 +03:00
|
|
|
if (mTransitionManager) {
|
|
|
|
mTransitionManager->Disconnect();
|
|
|
|
mTransitionManager = nsnull;
|
|
|
|
}
|
2011-04-12 10:18:44 +04:00
|
|
|
if (mAnimationManager) {
|
|
|
|
mAnimationManager->Disconnect();
|
|
|
|
mAnimationManager = nsnull;
|
|
|
|
}
|
1998-09-05 07:52:40 +04:00
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2011-08-15 22:44:15 +04:00
|
|
|
void
|
|
|
|
nsPresContext::DestroyImageLoaders()
|
|
|
|
{
|
|
|
|
// Destroy image loaders. This is important to do when frames are being
|
|
|
|
// destroyed because imageloaders can have pointers to frames and we don't
|
|
|
|
// want those pointers to outlive the destruction of the frame arena.
|
|
|
|
for (PRUint32 i = 0; i < IMAGE_LOAD_TYPE_COUNT; ++i) {
|
|
|
|
mImageLoaders[i].Enumerate(destroy_loads, nsnull);
|
|
|
|
mImageLoaders[i].Clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-09-21 02:59:20 +04:00
|
|
|
void
|
2004-08-10 01:19:15 +04:00
|
|
|
nsPresContext::UpdateCharSet(const nsAFlatCString& aCharSet)
|
2000-09-21 02:59:20 +04:00
|
|
|
{
|
|
|
|
if (mLangService) {
|
2010-02-24 20:57:44 +03:00
|
|
|
NS_IF_RELEASE(mLanguage);
|
|
|
|
mLanguage = mLangService->LookupCharSet(aCharSet.get()).get(); // addrefs
|
|
|
|
// this will be a language group (or script) code rather than a true language code
|
2004-06-21 14:32:27 +04:00
|
|
|
|
|
|
|
// bug 39570: moved from nsLanguageAtomService::LookupCharSet()
|
2010-02-24 20:57:44 +03:00
|
|
|
if (mLanguage == nsGkAtoms::Unicode) {
|
|
|
|
NS_RELEASE(mLanguage);
|
|
|
|
NS_IF_ADDREF(mLanguage = mLangService->GetLocaleLanguage());
|
2004-06-21 14:32:27 +04:00
|
|
|
}
|
|
|
|
GetFontPreferences();
|
2000-09-21 02:59:20 +04:00
|
|
|
}
|
2001-03-09 06:13:03 +03:00
|
|
|
#ifdef IBMBIDI
|
|
|
|
//ahmed
|
|
|
|
|
2005-11-09 01:45:49 +03:00
|
|
|
switch (GET_BIDI_OPTION_TEXTTYPE(GetBidi())) {
|
2004-08-06 01:38:08 +04:00
|
|
|
|
|
|
|
case IBMBIDI_TEXTTYPE_LOGICAL:
|
|
|
|
SetVisualMode(PR_FALSE);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IBMBIDI_TEXTTYPE_VISUAL:
|
|
|
|
SetVisualMode(PR_TRUE);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IBMBIDI_TEXTTYPE_CHARSET:
|
|
|
|
default:
|
2004-08-10 01:19:15 +04:00
|
|
|
SetVisualMode(IsVisualCharset(aCharSet));
|
2004-08-06 01:38:08 +04:00
|
|
|
}
|
2001-03-09 06:13:03 +03:00
|
|
|
#endif // IBMBIDI
|
2000-09-21 02:59:20 +04:00
|
|
|
}
|
|
|
|
|
2000-06-02 03:12:26 +04:00
|
|
|
NS_IMETHODIMP
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::Observe(nsISupports* aSubject,
|
2004-07-29 23:41:39 +04:00
|
|
|
const char* aTopic,
|
|
|
|
const PRUnichar* aData)
|
2000-06-02 03:12:26 +04:00
|
|
|
{
|
2001-10-20 00:52:59 +04:00
|
|
|
if (!nsCRT::strcmp(aTopic, "charset")) {
|
2006-02-03 17:18:39 +03:00
|
|
|
UpdateCharSet(NS_LossyConvertUTF16toASCII(aData));
|
2004-02-03 01:17:21 +03:00
|
|
|
mDeviceContext->FlushFontCache();
|
2008-02-08 22:52:46 +03:00
|
|
|
RebuildAllStyleData(NS_STYLE_HINT_REFLOW);
|
2001-10-20 00:52:59 +04:00
|
|
|
return NS_OK;
|
2000-09-21 02:59:20 +04:00
|
|
|
}
|
|
|
|
|
2004-08-01 03:15:21 +04:00
|
|
|
NS_WARNING("unrecognized topic in nsPresContext::Observe");
|
2001-10-20 00:52:59 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2000-06-02 03:12:26 +04:00
|
|
|
}
|
|
|
|
|
2011-01-15 12:40:33 +03:00
|
|
|
static nsPresContext*
|
|
|
|
GetParentPresContext(nsPresContext* aPresContext)
|
|
|
|
{
|
|
|
|
nsIPresShell* shell = aPresContext->GetPresShell();
|
|
|
|
if (shell) {
|
|
|
|
nsIFrame* rootFrame = shell->FrameManager()->GetRootFrame();
|
|
|
|
if (rootFrame) {
|
|
|
|
nsIFrame* f = nsLayoutUtils::GetCrossDocParentFrame(rootFrame);
|
|
|
|
if (f)
|
|
|
|
return f->PresContext();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
2006-11-30 02:09:13 +03:00
|
|
|
// We may want to replace this with something faster, maybe caching the root prescontext
|
2009-07-22 04:44:54 +04:00
|
|
|
nsRootPresContext*
|
2010-01-26 16:10:12 +03:00
|
|
|
nsPresContext::GetRootPresContext()
|
2006-11-30 02:09:13 +03:00
|
|
|
{
|
|
|
|
nsPresContext* pc = this;
|
|
|
|
for (;;) {
|
2011-01-15 12:40:33 +03:00
|
|
|
nsPresContext* parent = GetParentPresContext(pc);
|
|
|
|
if (!parent)
|
|
|
|
break;
|
|
|
|
pc = parent;
|
2006-11-30 02:09:13 +03:00
|
|
|
}
|
2011-01-15 12:40:33 +03:00
|
|
|
return pc->IsRoot() ? static_cast<nsRootPresContext*>(pc) : nsnull;
|
2006-11-30 02:09:13 +03:00
|
|
|
}
|
|
|
|
|
2003-12-25 00:51:50 +03:00
|
|
|
void
|
2006-12-05 18:46:18 +03:00
|
|
|
nsPresContext::CompatibilityModeChanged()
|
1998-07-31 09:54:59 +04:00
|
|
|
{
|
2003-12-25 00:51:50 +03:00
|
|
|
if (!mShell)
|
|
|
|
return;
|
2000-06-03 01:45:06 +04:00
|
|
|
|
2000-06-22 00:44:59 +04:00
|
|
|
// enable/disable the QuirkSheet
|
2004-01-08 01:30:53 +03:00
|
|
|
mShell->StyleSet()->
|
2006-12-05 18:46:18 +03:00
|
|
|
EnableQuirkStyleSheet(CompatibilityMode() == eCompatibility_NavQuirks);
|
1998-07-31 09:54:59 +04:00
|
|
|
}
|
|
|
|
|
2001-11-14 14:21:54 +03:00
|
|
|
// Helper function for setting Anim Mode on image
|
|
|
|
static void SetImgAnimModeOnImgReq(imgIRequest* aImgReq, PRUint16 aMode)
|
|
|
|
{
|
2003-03-19 06:47:09 +03:00
|
|
|
if (aImgReq) {
|
2001-11-14 14:21:54 +03:00
|
|
|
nsCOMPtr<imgIContainer> imgCon;
|
|
|
|
aImgReq->GetImage(getter_AddRefs(imgCon));
|
|
|
|
if (imgCon) {
|
|
|
|
imgCon->SetAnimationMode(aMode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Enumeration call back for HashTable
|
2008-10-10 19:04:34 +04:00
|
|
|
static PLDHashOperator
|
2009-02-19 22:03:28 +03:00
|
|
|
set_animation_mode(const void * aKey, nsRefPtr<nsImageLoader>& aData, void* closure)
|
2001-11-14 14:21:54 +03:00
|
|
|
{
|
2009-02-19 22:03:28 +03:00
|
|
|
for (nsImageLoader *loader = aData; loader;
|
|
|
|
loader = loader->GetNextLoader()) {
|
|
|
|
imgIRequest* imgReq = loader->GetRequest();
|
|
|
|
SetImgAnimModeOnImgReq(imgReq, (PRUint16)NS_PTR_TO_INT32(closure));
|
|
|
|
}
|
2007-02-07 10:46:44 +03:00
|
|
|
return PL_DHASH_NEXT;
|
2001-11-14 14:21:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// IMPORTANT: Assumption is that all images for a Presentation
|
|
|
|
// have the same Animation Mode (pavlov said this was OK)
|
|
|
|
//
|
|
|
|
// Walks content and set the animation mode
|
|
|
|
// this is a way to turn on/off image animations
|
2004-08-01 03:15:21 +04:00
|
|
|
void nsPresContext::SetImgAnimations(nsIContent *aParent, PRUint16 aMode)
|
2001-11-14 14:21:54 +03:00
|
|
|
{
|
2003-03-19 06:47:09 +03:00
|
|
|
nsCOMPtr<nsIImageLoadingContent> imgContent(do_QueryInterface(aParent));
|
2001-11-14 14:21:54 +03:00
|
|
|
if (imgContent) {
|
2003-03-19 06:47:09 +03:00
|
|
|
nsCOMPtr<imgIRequest> imgReq;
|
|
|
|
imgContent->GetRequest(nsIImageLoadingContent::CURRENT_REQUEST,
|
|
|
|
getter_AddRefs(imgReq));
|
|
|
|
SetImgAnimModeOnImgReq(imgReq, aMode);
|
2001-11-14 14:21:54 +03:00
|
|
|
}
|
2003-03-19 06:47:09 +03:00
|
|
|
|
2003-09-27 08:18:26 +04:00
|
|
|
PRUint32 count = aParent->GetChildCount();
|
|
|
|
for (PRUint32 i = 0; i < count; ++i) {
|
|
|
|
SetImgAnimations(aParent->GetChildAt(i), aMode);
|
2001-11-14 14:21:54 +03:00
|
|
|
}
|
|
|
|
}
|
2000-05-13 05:39:20 +04:00
|
|
|
|
2009-01-15 07:38:07 +03:00
|
|
|
#ifdef MOZ_SMIL
|
|
|
|
void
|
|
|
|
nsPresContext::SetSMILAnimations(nsIDocument *aDoc, PRUint16 aNewMode,
|
|
|
|
PRUint16 aOldMode)
|
|
|
|
{
|
2010-03-03 10:09:51 +03:00
|
|
|
if (aDoc->HasAnimationController()) {
|
|
|
|
nsSMILAnimationController* controller = aDoc->GetAnimationController();
|
2009-01-15 07:38:07 +03:00
|
|
|
switch (aNewMode)
|
|
|
|
{
|
|
|
|
case imgIContainer::kNormalAnimMode:
|
|
|
|
case imgIContainer::kLoopOnceAnimMode:
|
|
|
|
if (aOldMode == imgIContainer::kDontAnimMode)
|
|
|
|
controller->Resume(nsSMILTimeContainer::PAUSE_USERPREF);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case imgIContainer::kDontAnimMode:
|
|
|
|
if (aOldMode != imgIContainer::kDontAnimMode)
|
|
|
|
controller->Pause(nsSMILTimeContainer::PAUSE_USERPREF);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif // MOZ_SMIL
|
|
|
|
|
2003-12-26 07:24:11 +03:00
|
|
|
void
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::SetImageAnimationModeInternal(PRUint16 aMode)
|
2000-05-13 05:39:20 +04:00
|
|
|
{
|
2001-11-14 17:03:09 +03:00
|
|
|
NS_ASSERTION(aMode == imgIContainer::kNormalAnimMode ||
|
|
|
|
aMode == imgIContainer::kDontAnimMode ||
|
|
|
|
aMode == imgIContainer::kLoopOnceAnimMode, "Wrong Animation Mode is being set!");
|
|
|
|
|
2004-07-29 23:41:39 +04:00
|
|
|
// Image animation mode cannot be changed when rendering to a printer.
|
2006-04-01 05:19:28 +04:00
|
|
|
if (!IsDynamic())
|
2004-07-29 23:41:39 +04:00
|
|
|
return;
|
|
|
|
|
2008-10-29 00:38:37 +03:00
|
|
|
// Set the mode on the image loaders.
|
2009-02-19 22:03:28 +03:00
|
|
|
for (PRUint32 i = 0; i < IMAGE_LOAD_TYPE_COUNT; ++i)
|
|
|
|
mImageLoaders[i].Enumerate(set_animation_mode, NS_INT32_TO_PTR(aMode));
|
2001-11-14 14:21:54 +03:00
|
|
|
|
|
|
|
// Now walk the content tree and set the animation mode
|
2008-10-29 00:38:37 +03:00
|
|
|
// on all the images.
|
2001-11-14 14:21:54 +03:00
|
|
|
if (mShell != nsnull) {
|
2004-08-02 08:52:55 +04:00
|
|
|
nsIDocument *doc = mShell->GetDocument();
|
2001-11-14 14:21:54 +03:00
|
|
|
if (doc) {
|
2010-04-30 17:12:05 +04:00
|
|
|
Element *rootElement = doc->GetRootElement();
|
|
|
|
if (rootElement) {
|
|
|
|
SetImgAnimations(rootElement, aMode);
|
2001-11-14 14:21:54 +03:00
|
|
|
}
|
2009-01-15 07:38:07 +03:00
|
|
|
|
|
|
|
#ifdef MOZ_SMIL
|
|
|
|
SetSMILAnimations(doc, aMode, mImageAnimationMode);
|
|
|
|
#endif // MOZ_SMIL
|
2001-11-14 14:21:54 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-05-13 05:39:20 +04:00
|
|
|
mImageAnimationMode = aMode;
|
|
|
|
}
|
|
|
|
|
2004-07-29 23:41:39 +04:00
|
|
|
void
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::SetImageAnimationModeExternal(PRUint16 aMode)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2004-07-29 23:41:39 +04:00
|
|
|
SetImageAnimationModeInternal(aMode);
|
|
|
|
}
|
1998-08-28 00:43:04 +04:00
|
|
|
|
2004-02-01 01:41:40 +03:00
|
|
|
const nsFont*
|
2008-10-10 00:46:43 +04:00
|
|
|
nsPresContext::GetDefaultFont(PRUint8 aFontID) const
|
1999-02-12 20:45:58 +03:00
|
|
|
{
|
2004-02-01 01:41:40 +03:00
|
|
|
const nsFont *font;
|
2001-09-27 22:34:30 +04:00
|
|
|
switch (aFontID) {
|
|
|
|
// Special (our default variable width font and fixed width font)
|
|
|
|
case kPresContext_DefaultVariableFont_ID:
|
2004-02-01 01:41:40 +03:00
|
|
|
font = &mDefaultVariableFont;
|
2001-09-27 22:34:30 +04:00
|
|
|
break;
|
|
|
|
case kPresContext_DefaultFixedFont_ID:
|
2004-02-01 01:41:40 +03:00
|
|
|
font = &mDefaultFixedFont;
|
2001-09-27 22:34:30 +04:00
|
|
|
break;
|
|
|
|
// CSS
|
|
|
|
case kGenericFont_serif:
|
2004-02-01 01:41:40 +03:00
|
|
|
font = &mDefaultSerifFont;
|
2001-09-27 22:34:30 +04:00
|
|
|
break;
|
|
|
|
case kGenericFont_sans_serif:
|
2004-02-01 01:41:40 +03:00
|
|
|
font = &mDefaultSansSerifFont;
|
2001-09-27 22:34:30 +04:00
|
|
|
break;
|
|
|
|
case kGenericFont_monospace:
|
2004-02-01 01:41:40 +03:00
|
|
|
font = &mDefaultMonospaceFont;
|
2001-09-27 22:34:30 +04:00
|
|
|
break;
|
|
|
|
case kGenericFont_cursive:
|
2004-02-01 01:41:40 +03:00
|
|
|
font = &mDefaultCursiveFont;
|
2001-09-27 22:34:30 +04:00
|
|
|
break;
|
|
|
|
case kGenericFont_fantasy:
|
2004-02-01 01:41:40 +03:00
|
|
|
font = &mDefaultFantasyFont;
|
2001-09-27 22:34:30 +04:00
|
|
|
break;
|
|
|
|
default:
|
2004-02-01 01:41:40 +03:00
|
|
|
font = nsnull;
|
2001-09-27 22:34:30 +04:00
|
|
|
NS_ERROR("invalid arg");
|
|
|
|
break;
|
|
|
|
}
|
2004-02-01 01:41:40 +03:00
|
|
|
return font;
|
1998-07-17 09:41:41 +04:00
|
|
|
}
|
|
|
|
|
2005-08-13 15:54:22 +04:00
|
|
|
void
|
2007-07-26 07:34:16 +04:00
|
|
|
nsPresContext::SetFullZoom(float aZoom)
|
2005-08-13 15:54:22 +04:00
|
|
|
{
|
2009-12-11 07:02:13 +03:00
|
|
|
if (!mShell || mFullZoom == aZoom) {
|
2007-07-26 07:34:16 +04:00
|
|
|
return;
|
|
|
|
}
|
2011-04-12 00:57:29 +04:00
|
|
|
|
2007-12-12 05:27:00 +03:00
|
|
|
// Re-fetch the view manager's window dimensions in case there's a deferred
|
|
|
|
// resize which hasn't affected our mVisibleArea yet
|
|
|
|
nscoord oldWidthAppUnits, oldHeightAppUnits;
|
2009-03-11 18:43:08 +03:00
|
|
|
mShell->GetViewManager()->GetWindowDimensions(&oldWidthAppUnits, &oldHeightAppUnits);
|
2007-12-12 05:27:00 +03:00
|
|
|
float oldWidthDevPixels = oldWidthAppUnits / float(mCurAppUnitsPerDevPixel);
|
|
|
|
float oldHeightDevPixels = oldHeightAppUnits / float(mCurAppUnitsPerDevPixel);
|
2011-04-12 00:57:29 +04:00
|
|
|
mDeviceContext->SetPixelScale(aZoom);
|
2008-01-29 07:10:59 +03:00
|
|
|
|
2010-02-07 18:52:43 +03:00
|
|
|
NS_ASSERTION(!mSupressResizeReflow, "two zooms happening at the same time? impossible!");
|
2008-01-29 07:10:59 +03:00
|
|
|
mSupressResizeReflow = PR_TRUE;
|
|
|
|
|
2007-11-26 11:35:22 +03:00
|
|
|
mFullZoom = aZoom;
|
2009-03-11 18:43:08 +03:00
|
|
|
mShell->GetViewManager()->
|
|
|
|
SetWindowDimensions(NSToCoordRound(oldWidthDevPixels * AppUnitsPerDevPixel()),
|
|
|
|
NSToCoordRound(oldHeightDevPixels * AppUnitsPerDevPixel()));
|
2011-04-12 00:57:29 +04:00
|
|
|
|
|
|
|
AppUnitsPerDevPixelChanged();
|
2008-01-29 07:10:59 +03:00
|
|
|
|
|
|
|
mSupressResizeReflow = PR_FALSE;
|
|
|
|
|
2007-08-24 21:46:59 +04:00
|
|
|
mCurAppUnitsPerDevPixel = AppUnitsPerDevPixel();
|
2005-08-13 15:54:22 +04:00
|
|
|
}
|
|
|
|
|
2009-02-19 22:03:28 +03:00
|
|
|
void
|
|
|
|
nsPresContext::SetImageLoaders(nsIFrame* aTargetFrame,
|
|
|
|
ImageLoadType aType,
|
|
|
|
nsImageLoader* aImageLoaders)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2010-01-14 05:30:05 +03:00
|
|
|
NS_ASSERTION(mShell || !aImageLoaders,
|
|
|
|
"Shouldn't add new image loader after the shell is gone");
|
|
|
|
|
2009-02-19 22:03:28 +03:00
|
|
|
nsRefPtr<nsImageLoader> oldLoaders;
|
|
|
|
mImageLoaders[aType].Get(aTargetFrame, getter_AddRefs(oldLoaders));
|
2000-02-15 07:49:32 +03:00
|
|
|
|
2009-02-19 22:03:28 +03:00
|
|
|
if (aImageLoaders) {
|
|
|
|
mImageLoaders[aType].Put(aTargetFrame, aImageLoaders);
|
|
|
|
} else if (oldLoaders) {
|
|
|
|
mImageLoaders[aType].Remove(aTargetFrame);
|
1998-11-26 21:10:10 +03:00
|
|
|
}
|
1998-11-23 20:18:34 +03:00
|
|
|
|
2009-02-19 22:03:28 +03:00
|
|
|
if (oldLoaders)
|
|
|
|
oldLoaders->Destroy();
|
2008-10-29 00:36:17 +03:00
|
|
|
}
|
|
|
|
|
2009-02-19 22:03:28 +03:00
|
|
|
void
|
|
|
|
nsPresContext::SetupBackgroundImageLoaders(nsIFrame* aFrame,
|
|
|
|
const nsStyleBackground* aStyleBackground)
|
2008-10-29 00:36:17 +03:00
|
|
|
{
|
2009-02-20 08:29:21 +03:00
|
|
|
nsRefPtr<nsImageLoader> loaders;
|
|
|
|
NS_FOR_VISIBLE_BACKGROUND_LAYERS_BACK_TO_FRONT(i, aStyleBackground) {
|
2009-08-22 00:39:25 +04:00
|
|
|
if (aStyleBackground->mLayers[i].mImage.GetType() == eStyleImageType_Image) {
|
2009-09-13 02:44:18 +04:00
|
|
|
PRUint32 actions = nsImageLoader::ACTION_REDRAW_ON_DECODE;
|
2009-08-01 19:53:40 +04:00
|
|
|
imgIRequest *image = aStyleBackground->mLayers[i].mImage.GetImageData();
|
2009-09-13 02:44:18 +04:00
|
|
|
loaders = nsImageLoader::Create(aFrame, image, actions, loaders);
|
2009-08-01 19:53:40 +04:00
|
|
|
}
|
2009-02-20 08:29:21 +03:00
|
|
|
}
|
|
|
|
SetImageLoaders(aFrame, BACKGROUND_IMAGE, loaders);
|
2008-10-29 00:36:17 +03:00
|
|
|
}
|
|
|
|
|
2009-02-19 22:03:28 +03:00
|
|
|
void
|
|
|
|
nsPresContext::SetupBorderImageLoaders(nsIFrame* aFrame,
|
|
|
|
const nsStyleBorder* aStyleBorder)
|
2008-10-29 00:36:17 +03:00
|
|
|
{
|
2011-04-23 05:36:23 +04:00
|
|
|
// We get called the first time we try to draw a border-image, and
|
|
|
|
// also when the border image changes (including when it changes from
|
|
|
|
// non-null to null).
|
|
|
|
imgIRequest *borderImage = aStyleBorder->GetBorderImage();
|
|
|
|
if (!borderImage) {
|
|
|
|
SetImageLoaders(aFrame, BORDER_IMAGE, nsnull);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-09-13 02:44:18 +04:00
|
|
|
PRUint32 actions = nsImageLoader::ACTION_REDRAW_ON_LOAD;
|
|
|
|
if (aStyleBorder->ImageBorderDiffers())
|
|
|
|
actions |= nsImageLoader::ACTION_REFLOW_ON_LOAD;
|
2009-02-19 22:03:28 +03:00
|
|
|
nsRefPtr<nsImageLoader> loader =
|
2011-04-23 05:36:23 +04:00
|
|
|
nsImageLoader::Create(aFrame, borderImage, actions, nsnull);
|
2009-02-19 22:03:28 +03:00
|
|
|
SetImageLoaders(aFrame, BORDER_IMAGE, loader);
|
2008-07-17 10:30:25 +04:00
|
|
|
}
|
2001-08-10 00:22:39 +04:00
|
|
|
|
2004-02-01 13:09:07 +03:00
|
|
|
void
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::StopImagesFor(nsIFrame* aTargetFrame)
|
1998-11-26 21:10:10 +03:00
|
|
|
{
|
2009-02-19 22:03:28 +03:00
|
|
|
for (PRUint32 i = 0; i < IMAGE_LOAD_TYPE_COUNT; ++i)
|
|
|
|
SetImageLoaders(aTargetFrame, ImageLoadType(i), nsnull);
|
2008-07-26 20:14:49 +04:00
|
|
|
}
|
2000-09-22 00:17:04 +04:00
|
|
|
|
2004-02-01 13:09:07 +03:00
|
|
|
void
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::SetContainer(nsISupports* aHandler)
|
1999-04-30 13:04:36 +04:00
|
|
|
{
|
2002-11-07 03:59:25 +03:00
|
|
|
mContainer = do_GetWeakReference(aHandler);
|
2010-05-22 22:55:41 +04:00
|
|
|
InvalidateIsChromeCache();
|
2001-10-17 03:59:25 +04:00
|
|
|
if (mContainer) {
|
|
|
|
GetDocumentColorPreferences();
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2004-02-01 13:09:07 +03:00
|
|
|
already_AddRefed<nsISupports>
|
2007-11-16 06:46:42 +03:00
|
|
|
nsPresContext::GetContainerInternal() const
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2007-02-23 01:09:14 +03:00
|
|
|
nsISupports *result = nsnull;
|
2004-02-01 13:09:07 +03:00
|
|
|
if (mContainer)
|
|
|
|
CallQueryReferent(mContainer.get(), &result);
|
2002-11-07 03:59:25 +03:00
|
|
|
|
2004-02-01 13:09:07 +03:00
|
|
|
return result;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
1998-06-24 01:53:02 +04:00
|
|
|
|
2004-07-29 23:41:39 +04:00
|
|
|
already_AddRefed<nsISupports>
|
2007-11-16 06:46:42 +03:00
|
|
|
nsPresContext::GetContainerExternal() const
|
2004-07-29 23:41:39 +04:00
|
|
|
{
|
|
|
|
return GetContainerInternal();
|
|
|
|
}
|
|
|
|
|
2001-03-09 06:13:03 +03:00
|
|
|
#ifdef IBMBIDI
|
2004-04-13 04:28:44 +04:00
|
|
|
void
|
2008-06-16 13:28:17 +04:00
|
|
|
nsPresContext::SetBidiEnabled() const
|
2001-03-09 06:13:03 +03:00
|
|
|
{
|
|
|
|
if (mShell) {
|
2004-08-02 08:52:55 +04:00
|
|
|
nsIDocument *doc = mShell->GetDocument();
|
2001-03-09 06:13:03 +03:00
|
|
|
if (doc) {
|
2008-06-16 13:28:17 +04:00
|
|
|
doc->SetBidiEnabled();
|
2001-03-09 06:13:03 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-07-29 23:41:39 +04:00
|
|
|
void
|
2011-09-29 10:19:26 +04:00
|
|
|
nsPresContext::SetBidi(PRUint32 aSource, bool aForceRestyle)
|
2001-03-09 06:13:03 +03:00
|
|
|
{
|
2005-11-13 12:55:09 +03:00
|
|
|
// Don't do all this stuff unless the options have changed.
|
|
|
|
if (aSource == GetBidi()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-01-09 12:38:28 +03:00
|
|
|
NS_ASSERTION(!(aForceRestyle && (GetBidi() == 0)),
|
2005-11-13 12:55:09 +03:00
|
|
|
"ForceReflow on new prescontext");
|
|
|
|
|
2006-05-19 14:26:44 +04:00
|
|
|
Document()->SetBidiOptions(aSource);
|
2005-11-09 01:45:49 +03:00
|
|
|
if (IBMBIDI_TEXTDIRECTION_RTL == GET_BIDI_OPTION_DIRECTION(aSource)
|
|
|
|
|| IBMBIDI_NUMERAL_HINDI == GET_BIDI_OPTION_NUMERAL(aSource)) {
|
2008-06-16 13:28:17 +04:00
|
|
|
SetBidiEnabled();
|
2001-03-09 06:13:03 +03:00
|
|
|
}
|
2005-11-09 01:45:49 +03:00
|
|
|
if (IBMBIDI_TEXTTYPE_VISUAL == GET_BIDI_OPTION_TEXTTYPE(aSource)) {
|
2001-03-09 06:13:03 +03:00
|
|
|
SetVisualMode(PR_TRUE);
|
|
|
|
}
|
2005-11-09 01:45:49 +03:00
|
|
|
else if (IBMBIDI_TEXTTYPE_LOGICAL == GET_BIDI_OPTION_TEXTTYPE(aSource)) {
|
2001-03-09 06:13:03 +03:00
|
|
|
SetVisualMode(PR_FALSE);
|
|
|
|
}
|
|
|
|
else {
|
2004-08-10 01:19:15 +04:00
|
|
|
nsIDocument* doc = mShell->GetDocument();
|
|
|
|
if (doc) {
|
|
|
|
SetVisualMode(IsVisualCharset(doc->GetDocumentCharacterSet()));
|
|
|
|
}
|
2001-03-09 06:13:03 +03:00
|
|
|
}
|
2010-12-15 23:26:54 +03:00
|
|
|
if (aForceRestyle && mShell) {
|
|
|
|
// Reconstruct the root document element's frame and its children,
|
|
|
|
// because we need to trigger frame reconstruction for direction change.
|
|
|
|
RebuildUserFontSet();
|
|
|
|
mShell->ReconstructFrames();
|
2001-03-09 06:13:03 +03:00
|
|
|
}
|
|
|
|
}
|
2005-11-09 01:45:49 +03:00
|
|
|
|
|
|
|
PRUint32
|
|
|
|
nsPresContext::GetBidi() const
|
|
|
|
{
|
2006-05-19 14:26:44 +04:00
|
|
|
return Document()->GetBidiOptions();
|
2005-11-09 01:45:49 +03:00
|
|
|
}
|
2010-06-01 06:19:35 +04:00
|
|
|
|
2001-03-09 06:13:03 +03:00
|
|
|
#endif //IBMBIDI
|
2000-03-21 18:51:59 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2010-03-17 20:10:57 +03:00
|
|
|
nsPresContext::IsTopLevelWindowInactive()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> treeItem(do_QueryReferent(mContainer));
|
|
|
|
if (!treeItem)
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> rootItem;
|
|
|
|
treeItem->GetRootTreeItem(getter_AddRefs(rootItem));
|
|
|
|
nsCOMPtr<nsPIDOMWindow> domWindow(do_GetInterface(rootItem));
|
|
|
|
|
|
|
|
return domWindow && !domWindow->IsActive();
|
|
|
|
}
|
|
|
|
|
2004-07-29 23:41:39 +04:00
|
|
|
nsITheme*
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::GetTheme()
|
2001-12-18 01:51:39 +03:00
|
|
|
{
|
2009-02-26 23:02:00 +03:00
|
|
|
if (!sNoTheme && !mTheme) {
|
2001-12-18 01:51:39 +03:00
|
|
|
mTheme = do_GetService("@mozilla.org/chrome/chrome-native-theme;1");
|
|
|
|
if (!mTheme)
|
2009-02-26 23:02:00 +03:00
|
|
|
sNoTheme = PR_TRUE;
|
2001-12-18 01:51:39 +03:00
|
|
|
}
|
|
|
|
|
2004-07-29 23:41:39 +04:00
|
|
|
return mTheme;
|
2001-12-18 01:51:39 +03:00
|
|
|
}
|
|
|
|
|
2004-07-29 23:41:39 +04:00
|
|
|
void
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::ThemeChanged()
|
2001-12-18 01:51:39 +03:00
|
|
|
{
|
2006-09-12 08:36:03 +04:00
|
|
|
if (!mPendingThemeChanged) {
|
|
|
|
sLookAndFeelChanged = PR_TRUE;
|
|
|
|
sThemeChanged = PR_TRUE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIRunnable> ev =
|
2010-04-21 03:21:35 +04:00
|
|
|
NS_NewRunnableMethod(this, &nsPresContext::ThemeChangedInternal);
|
2006-09-12 08:36:03 +04:00
|
|
|
if (NS_SUCCEEDED(NS_DispatchToCurrentThread(ev))) {
|
|
|
|
mPendingThemeChanged = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsPresContext::ThemeChangedInternal()
|
|
|
|
{
|
|
|
|
mPendingThemeChanged = PR_FALSE;
|
|
|
|
|
2001-12-18 01:51:39 +03:00
|
|
|
// Tell the theme that it changed, so it can flush any handles to stale theme
|
|
|
|
// data.
|
2006-09-12 08:36:03 +04:00
|
|
|
if (mTheme && sThemeChanged) {
|
2001-12-18 01:51:39 +03:00
|
|
|
mTheme->ThemeChanged();
|
2006-09-12 08:36:03 +04:00
|
|
|
sThemeChanged = PR_FALSE;
|
|
|
|
}
|
2001-12-18 01:51:39 +03:00
|
|
|
|
2011-09-09 06:27:13 +04:00
|
|
|
// Clear all cached LookAndFeel colors.
|
|
|
|
if (sLookAndFeelChanged) {
|
|
|
|
LookAndFeel::Refresh();
|
2006-09-12 08:36:03 +04:00
|
|
|
sLookAndFeelChanged = PR_FALSE;
|
|
|
|
}
|
2004-09-17 10:27:01 +04:00
|
|
|
|
2008-08-06 00:02:43 +04:00
|
|
|
// This will force the system metrics to be generated the next time they're used
|
|
|
|
nsCSSRuleProcessor::FreeSystemMetrics();
|
|
|
|
|
2009-10-16 04:23:19 +04:00
|
|
|
// Changes to system metrics can change media queries on them.
|
|
|
|
MediaFeatureValuesChanged(PR_TRUE);
|
|
|
|
|
2008-02-08 22:52:46 +03:00
|
|
|
// Changes in theme can change system colors (whose changes are
|
|
|
|
// properly reflected in computed style data), system fonts (whose
|
|
|
|
// changes are not), and -moz-appearance (whose changes likewise are
|
|
|
|
// not), so we need to reflow.
|
|
|
|
RebuildAllStyleData(NS_STYLE_HINT_REFLOW);
|
2001-12-18 01:51:39 +03:00
|
|
|
}
|
|
|
|
|
2004-07-29 23:41:39 +04:00
|
|
|
void
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::SysColorChanged()
|
2002-06-04 21:47:54 +04:00
|
|
|
{
|
2006-09-12 08:36:03 +04:00
|
|
|
if (!mPendingSysColorChanged) {
|
|
|
|
sLookAndFeelChanged = PR_TRUE;
|
|
|
|
nsCOMPtr<nsIRunnable> ev =
|
2010-04-21 03:21:35 +04:00
|
|
|
NS_NewRunnableMethod(this, &nsPresContext::SysColorChangedInternal);
|
2006-09-12 08:36:03 +04:00
|
|
|
if (NS_SUCCEEDED(NS_DispatchToCurrentThread(ev))) {
|
|
|
|
mPendingSysColorChanged = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsPresContext::SysColorChangedInternal()
|
|
|
|
{
|
|
|
|
mPendingSysColorChanged = PR_FALSE;
|
|
|
|
|
2011-09-09 06:27:13 +04:00
|
|
|
if (sLookAndFeelChanged) {
|
2002-06-04 21:47:54 +04:00
|
|
|
// Don't use the cached values for the system colors
|
2011-09-09 06:27:13 +04:00
|
|
|
LookAndFeel::Refresh();
|
2006-09-12 08:36:03 +04:00
|
|
|
sLookAndFeelChanged = PR_FALSE;
|
2002-06-04 21:47:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Reset default background and foreground colors for the document since
|
|
|
|
// they may be using system colors
|
|
|
|
GetDocumentColorPreferences();
|
|
|
|
|
2008-02-08 22:52:46 +03:00
|
|
|
// The system color values are computed to colors in the style data,
|
|
|
|
// so normal style data comparison is sufficient here.
|
|
|
|
RebuildAllStyleData(nsChangeHint(0));
|
2008-01-09 12:38:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-02-08 22:52:46 +03:00
|
|
|
nsPresContext::RebuildAllStyleData(nsChangeHint aExtraHint)
|
2008-01-09 12:38:28 +03:00
|
|
|
{
|
|
|
|
if (!mShell) {
|
|
|
|
// We must have been torn down. Nothing to do here.
|
|
|
|
return;
|
|
|
|
}
|
2008-11-26 02:22:38 +03:00
|
|
|
|
|
|
|
RebuildUserFontSet();
|
2011-04-12 10:18:44 +04:00
|
|
|
AnimationManager()->KeyframesListIsDirty();
|
2008-11-26 02:22:38 +03:00
|
|
|
|
2008-02-08 22:52:46 +03:00
|
|
|
mShell->FrameConstructor()->RebuildAllStyleData(aExtraHint);
|
2008-01-09 12:38:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-12-04 19:09:53 +03:00
|
|
|
nsPresContext::PostRebuildAllStyleDataEvent(nsChangeHint aExtraHint)
|
2008-01-09 12:38:28 +03:00
|
|
|
{
|
|
|
|
if (!mShell) {
|
|
|
|
// We must have been torn down. Nothing to do here.
|
|
|
|
return;
|
|
|
|
}
|
2008-12-04 19:09:53 +03:00
|
|
|
mShell->FrameConstructor()->PostRebuildAllStyleDataEvent(aExtraHint);
|
2004-07-29 23:41:39 +04:00
|
|
|
}
|
|
|
|
|
2008-07-26 20:14:48 +04:00
|
|
|
void
|
2011-09-29 10:19:26 +04:00
|
|
|
nsPresContext::MediaFeatureValuesChanged(bool aCallerWillRebuildStyleData)
|
2008-07-26 20:14:48 +04:00
|
|
|
{
|
|
|
|
mPendingMediaFeatureValuesChanged = PR_FALSE;
|
2009-11-18 00:11:15 +03:00
|
|
|
if (mShell &&
|
|
|
|
mShell->StyleSet()->MediumFeaturesChanged(this) &&
|
2008-07-26 20:14:48 +04:00
|
|
|
!aCallerWillRebuildStyleData) {
|
|
|
|
RebuildAllStyleData(nsChangeHint(0));
|
|
|
|
}
|
2011-04-22 07:17:31 +04:00
|
|
|
|
|
|
|
if (!nsContentUtils::IsSafeToRunScript()) {
|
|
|
|
NS_ABORT_IF_FALSE(mDocument->IsBeingUsedAsImage(),
|
|
|
|
"How did we get here? Are we failing to notify "
|
|
|
|
"listeners that we should notify?");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Media query list listeners should be notified from a queued task
|
|
|
|
// (in HTML5 terms), although we also want to notify them on certain
|
|
|
|
// flushes. (We're already running off an event.)
|
|
|
|
//
|
|
|
|
// Note that we do this after the new style from media queries in
|
|
|
|
// style sheets has been computed.
|
|
|
|
|
|
|
|
if (!PR_CLIST_IS_EMPTY(&mDOMMediaQueryLists)) {
|
|
|
|
// We build a list of all the notifications we're going to send
|
|
|
|
// before we send any of them. (The spec says the notifications
|
|
|
|
// should be a queued task, so any removals that happen during the
|
|
|
|
// notifications shouldn't affect what gets notified.) Furthermore,
|
|
|
|
// we hold strong pointers to everything we're going to make
|
|
|
|
// notification calls to, since each notification involves calling
|
|
|
|
// arbitrary script that might otherwise destroy these objects, or,
|
|
|
|
// for that matter, |this|.
|
|
|
|
//
|
|
|
|
// Note that we intentionally send the notifications to media query
|
|
|
|
// list in the order they were created and, for each list, to the
|
|
|
|
// listeners in the order added.
|
|
|
|
nsDOMMediaQueryList::NotifyList notifyList;
|
|
|
|
for (PRCList *l = PR_LIST_HEAD(&mDOMMediaQueryLists);
|
|
|
|
l != &mDOMMediaQueryLists; l = PR_NEXT_LINK(l)) {
|
|
|
|
nsDOMMediaQueryList *mql = static_cast<nsDOMMediaQueryList*>(l);
|
|
|
|
mql->MediumFeaturesChanged(notifyList);
|
|
|
|
}
|
|
|
|
|
2011-04-24 00:19:01 +04:00
|
|
|
if (!notifyList.IsEmpty()) {
|
|
|
|
nsPIDOMWindow *win = mDocument->GetInnerWindow();
|
2011-06-24 06:18:00 +04:00
|
|
|
nsCOMPtr<nsIDOMEventTarget> et = do_QueryInterface(win);
|
2011-04-24 00:19:01 +04:00
|
|
|
nsCxPusher pusher;
|
|
|
|
|
|
|
|
for (PRUint32 i = 0, i_end = notifyList.Length(); i != i_end; ++i) {
|
|
|
|
if (pusher.RePush(et)) {
|
|
|
|
nsDOMMediaQueryList::HandleChangeData &d = notifyList[i];
|
|
|
|
d.listener->HandleChange(d.mql);
|
|
|
|
}
|
|
|
|
}
|
2011-04-22 07:17:31 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// NOTE: When |notifyList| goes out of scope, our destructor could run.
|
|
|
|
}
|
2008-07-26 20:14:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsPresContext::PostMediaFeatureValuesChangedEvent()
|
|
|
|
{
|
2011-04-22 07:17:31 +04:00
|
|
|
// FIXME: We should probably replace this event with use of
|
|
|
|
// nsRefreshDriver::AddStyleFlushObserver (except the pres shell would
|
|
|
|
// need to track whether it's been added).
|
2008-07-26 20:14:48 +04:00
|
|
|
if (!mPendingMediaFeatureValuesChanged) {
|
|
|
|
nsCOMPtr<nsIRunnable> ev =
|
2010-04-21 03:21:35 +04:00
|
|
|
NS_NewRunnableMethod(this, &nsPresContext::HandleMediaFeatureValuesChangedEvent);
|
2008-07-26 20:14:48 +04:00
|
|
|
if (NS_SUCCEEDED(NS_DispatchToCurrentThread(ev))) {
|
|
|
|
mPendingMediaFeatureValuesChanged = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsPresContext::HandleMediaFeatureValuesChangedEvent()
|
|
|
|
{
|
|
|
|
// Null-check mShell in case the shell has been destroyed (and the
|
|
|
|
// event is the only thing holding the pres context alive).
|
|
|
|
if (mPendingMediaFeatureValuesChanged && mShell) {
|
|
|
|
MediaFeatureValuesChanged(PR_FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-22 07:17:31 +04:00
|
|
|
void
|
|
|
|
nsPresContext::MatchMedia(const nsAString& aMediaQueryList,
|
|
|
|
nsIDOMMediaQueryList** aResult)
|
|
|
|
{
|
|
|
|
nsRefPtr<nsDOMMediaQueryList> result =
|
|
|
|
new nsDOMMediaQueryList(this, aMediaQueryList);
|
|
|
|
|
|
|
|
// Insert the new item at the end of the linked list.
|
|
|
|
PR_INSERT_BEFORE(result, &mDOMMediaQueryLists);
|
|
|
|
|
|
|
|
result.forget(aResult);
|
|
|
|
}
|
|
|
|
|
2004-07-29 23:41:39 +04:00
|
|
|
void
|
2011-09-29 10:19:26 +04:00
|
|
|
nsPresContext::SetPaginatedScrolling(bool aPaginated)
|
2004-07-29 23:41:39 +04:00
|
|
|
{
|
2006-04-01 05:19:28 +04:00
|
|
|
if (mType == eContext_PrintPreview || mType == eContext_PageLayout)
|
2004-07-29 23:41:39 +04:00
|
|
|
mCanPaginatedScroll = aPaginated;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::SetPrintSettings(nsIPrintSettings *aPrintSettings)
|
2004-07-29 23:41:39 +04:00
|
|
|
{
|
2006-12-26 20:47:52 +03:00
|
|
|
if (mMedium == nsGkAtoms::print)
|
2004-07-29 23:41:39 +04:00
|
|
|
mPrintSettings = aPrintSettings;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 22:00:39 +04:00
|
|
|
nsPresContext::EnsureVisible()
|
2005-01-20 06:39:09 +03:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDocShell> docShell(do_QueryReferent(mContainer));
|
|
|
|
if (docShell) {
|
|
|
|
nsCOMPtr<nsIContentViewer> cv;
|
|
|
|
docShell->GetContentViewer(getter_AddRefs(cv));
|
|
|
|
// Make sure this is the content viewer we belong with
|
|
|
|
nsCOMPtr<nsIDocumentViewer> docV(do_QueryInterface(cv));
|
|
|
|
if (docV) {
|
2010-03-31 15:09:11 +04:00
|
|
|
nsRefPtr<nsPresContext> currentPresContext;
|
2005-01-20 06:39:09 +03:00
|
|
|
docV->GetPresContext(getter_AddRefs(currentPresContext));
|
|
|
|
if (currentPresContext == this) {
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 22:00:39 +04:00
|
|
|
// OK, this is us. We want to call Show() on the content viewer.
|
2005-01-20 06:39:09 +03:00
|
|
|
cv->Show();
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2000-04-21 18:59:47 +04:00
|
|
|
#ifdef MOZ_REFLOW_PERF
|
2004-07-29 23:41:39 +04: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 08:38:33 +03:00
|
|
|
nsPresContext::CountReflows(const char * aName, nsIFrame * aFrame)
|
2000-04-21 18:59:47 +04:00
|
|
|
{
|
|
|
|
if (mShell) {
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
mShell->CountReflows(aName, aFrame);
|
2000-04-21 18:59:47 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2007-05-17 01:10:31 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2010-05-22 22:55:41 +04:00
|
|
|
nsPresContext::IsChromeSlow() const
|
2007-05-17 01:10:31 +04:00
|
|
|
{
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isChrome = false;
|
2007-05-17 01:10:31 +04:00
|
|
|
nsCOMPtr<nsISupports> container = GetContainer();
|
|
|
|
if (container) {
|
|
|
|
nsresult result;
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> docShell(do_QueryInterface(container, &result));
|
|
|
|
if (NS_SUCCEEDED(result) && docShell) {
|
|
|
|
PRInt32 docShellType;
|
|
|
|
result = docShell->GetItemType(&docShellType);
|
|
|
|
if (NS_SUCCEEDED(result)) {
|
|
|
|
isChrome = nsIDocShellTreeItem::typeChrome == docShellType;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-04-10 22:03:40 +04:00
|
|
|
mIsChrome = isChrome;
|
|
|
|
mIsChromeIsCached = PR_TRUE;
|
|
|
|
return mIsChrome;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsPresContext::InvalidateIsChromeCacheExternal()
|
|
|
|
{
|
|
|
|
InvalidateIsChromeCacheInternal();
|
2007-05-17 01:10:31 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
/* virtual */ bool
|
2010-05-22 22:55:41 +04:00
|
|
|
nsPresContext::HasAuthorSpecifiedRules(nsIFrame *aFrame, PRUint32 ruleTypeMask) const
|
2007-10-09 03:11:01 +04:00
|
|
|
{
|
2009-01-06 22:17:05 +03:00
|
|
|
return
|
|
|
|
nsRuleNode::HasAuthorSpecifiedRules(aFrame->GetStyleContext(),
|
2009-06-17 02:05:12 +04:00
|
|
|
ruleTypeMask,
|
|
|
|
UseDocumentColors());
|
2007-10-09 03:11:01 +04:00
|
|
|
}
|
2008-09-18 13:47:21 +04:00
|
|
|
|
2008-11-26 02:22:38 +03:00
|
|
|
gfxUserFontSet*
|
2008-12-04 19:09:53 +03:00
|
|
|
nsPresContext::GetUserFontSetInternal()
|
2008-10-01 07:01:53 +04:00
|
|
|
{
|
2008-11-26 02:22:38 +03:00
|
|
|
// We want to initialize the user font set lazily the first time the
|
|
|
|
// user asks for it, rather than building it too early and forcing
|
|
|
|
// rule cascade creation. Thus we try to enforce the invariant that
|
|
|
|
// we *never* build the user font set until the first call to
|
|
|
|
// GetUserFontSet. However, once it's been requested, we can't wait
|
|
|
|
// for somebody to call GetUserFontSet in order to rebuild it (see
|
|
|
|
// comments below in RebuildUserFontSet for why).
|
2009-01-28 03:31:26 +03:00
|
|
|
#ifdef DEBUG
|
2011-09-29 10:19:26 +04:00
|
|
|
bool userFontSetGottenBefore = mGetUserFontSetCalled;
|
2009-01-28 03:31:26 +03:00
|
|
|
#endif
|
|
|
|
// Set mGetUserFontSetCalled up front, so that FlushUserFontSet will actually
|
|
|
|
// flush.
|
|
|
|
mGetUserFontSetCalled = PR_TRUE;
|
2008-11-26 02:22:38 +03:00
|
|
|
if (mUserFontSetDirty) {
|
2008-11-26 02:22:38 +03:00
|
|
|
// If this assertion fails, and there have actually been changes to
|
|
|
|
// @font-face rules, then we will call StyleChangeReflow in
|
2008-11-27 23:31:04 +03:00
|
|
|
// FlushUserFontSet. If we're in the middle of reflow,
|
|
|
|
// that's a bad thing to do, and the caller was responsible for
|
|
|
|
// flushing first. If we're not (e.g., in frame construction), it's
|
|
|
|
// ok.
|
2010-04-11 00:15:22 +04:00
|
|
|
NS_ASSERTION(!userFontSetGottenBefore || !mShell->IsReflowLocked(),
|
|
|
|
"FlushUserFontSet should have been called first");
|
2008-11-26 02:22:38 +03:00
|
|
|
FlushUserFontSet();
|
|
|
|
}
|
|
|
|
|
|
|
|
return mUserFontSet;
|
|
|
|
}
|
|
|
|
|
2008-12-04 19:09:53 +03:00
|
|
|
gfxUserFontSet*
|
|
|
|
nsPresContext::GetUserFontSetExternal()
|
|
|
|
{
|
|
|
|
return GetUserFontSetInternal();
|
|
|
|
}
|
|
|
|
|
2008-11-26 02:22:38 +03:00
|
|
|
void
|
|
|
|
nsPresContext::FlushUserFontSet()
|
|
|
|
{
|
2011-04-12 14:53:20 +04:00
|
|
|
if (!mShell) {
|
2008-11-26 02:22:38 +03:00
|
|
|
return; // we've been torn down
|
2011-04-12 14:53:20 +04:00
|
|
|
}
|
2008-11-26 02:22:38 +03:00
|
|
|
|
2009-01-28 03:31:26 +03:00
|
|
|
if (!mGetUserFontSetCalled) {
|
|
|
|
return; // No one cares about this font set yet, but we want to be careful
|
|
|
|
// to not unset our mUserFontSetDirty bit, so when someone really
|
|
|
|
// does we'll create it.
|
|
|
|
}
|
|
|
|
|
2008-11-26 02:22:38 +03:00
|
|
|
if (mUserFontSetDirty) {
|
2008-11-26 02:22:38 +03:00
|
|
|
if (gfxPlatform::GetPlatform()->DownloadableFontsEnabled()) {
|
2008-11-27 06:50:16 +03:00
|
|
|
nsTArray<nsFontFaceRuleContainer> rules;
|
2011-04-12 14:53:20 +04:00
|
|
|
if (!mShell->StyleSet()->AppendFontFaceRules(this, rules)) {
|
|
|
|
if (mUserFontSet) {
|
|
|
|
mUserFontSet->Destroy();
|
|
|
|
NS_RELEASE(mUserFontSet);
|
2011-04-12 16:28:53 +04:00
|
|
|
}
|
2011-04-12 14:53:20 +04:00
|
|
|
return;
|
2011-04-12 16:28:53 +04:00
|
|
|
}
|
2011-04-12 14:53:20 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool changed = false;
|
2011-04-12 14:53:20 +04:00
|
|
|
|
|
|
|
if (rules.Length() == 0) {
|
2009-01-19 12:21:29 +03:00
|
|
|
if (mUserFontSet) {
|
|
|
|
mUserFontSet->Destroy();
|
|
|
|
NS_RELEASE(mUserFontSet);
|
2011-04-12 14:53:20 +04:00
|
|
|
changed = PR_TRUE;
|
2009-01-19 12:21:29 +03:00
|
|
|
}
|
2011-04-12 14:53:20 +04:00
|
|
|
} else {
|
|
|
|
if (!mUserFontSet) {
|
|
|
|
mUserFontSet = new nsUserFontSet(this);
|
2011-04-12 16:28:53 +04:00
|
|
|
NS_ADDREF(mUserFontSet);
|
|
|
|
}
|
2011-04-12 14:53:20 +04:00
|
|
|
changed = mUserFontSet->UpdateRules(rules);
|
2008-11-26 02:22:38 +03:00
|
|
|
}
|
2008-11-26 02:22:38 +03:00
|
|
|
|
2011-04-12 14:53:20 +04:00
|
|
|
// We need to enqueue a style change reflow (for later) to
|
|
|
|
// reflect that we're modifying @font-face rules. (However,
|
|
|
|
// without a reflow, nothing will happen to start any downloads
|
|
|
|
// that are needed.)
|
|
|
|
if (changed) {
|
2008-12-08 19:08:05 +03:00
|
|
|
UserFontSetUpdated();
|
2008-11-26 02:22:38 +03:00
|
|
|
}
|
2008-11-26 02:22:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
mUserFontSetDirty = PR_FALSE;
|
|
|
|
}
|
2008-11-26 02:22:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsPresContext::RebuildUserFontSet()
|
|
|
|
{
|
|
|
|
if (!mGetUserFontSetCalled) {
|
|
|
|
// We want to lazily build the user font set the first time it's
|
|
|
|
// requested (so we don't force creation of rule cascades too
|
|
|
|
// early), so don't do anything now.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mUserFontSetDirty = PR_TRUE;
|
|
|
|
|
|
|
|
// Somebody has already asked for the user font set, so we need to
|
|
|
|
// post an event to rebuild it. Setting the user font set to be dirty
|
|
|
|
// and lazily rebuilding it isn't sufficient, since it is only the act
|
|
|
|
// of rebuilding it that will trigger the style change reflow that
|
|
|
|
// calls GetUserFontSet. (This reflow causes rebuilding of text runs,
|
|
|
|
// which starts font loads, whose completion causes another style
|
|
|
|
// change reflow).
|
|
|
|
if (!mPostedFlushUserFontSet) {
|
|
|
|
nsCOMPtr<nsIRunnable> ev =
|
2010-04-21 03:21:35 +04:00
|
|
|
NS_NewRunnableMethod(this, &nsPresContext::HandleRebuildUserFontSet);
|
2008-11-26 02:22:38 +03:00
|
|
|
if (NS_SUCCEEDED(NS_DispatchToCurrentThread(ev))) {
|
|
|
|
mPostedFlushUserFontSet = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
2008-10-01 07:01:53 +04:00
|
|
|
}
|
|
|
|
|
2008-12-08 19:08:05 +03:00
|
|
|
void
|
|
|
|
nsPresContext::UserFontSetUpdated()
|
|
|
|
{
|
|
|
|
if (!mShell)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Changes to the set of available fonts can cause updates to layout by:
|
|
|
|
//
|
|
|
|
// 1. Changing the font used for text, which changes anything that
|
|
|
|
// depends on text measurement, including line breaking and
|
|
|
|
// intrinsic widths, and any other parts of layout that depend on
|
|
|
|
// font metrics. This requires a style change reflow to update.
|
|
|
|
//
|
|
|
|
// 2. Changing the value of the 'ex' and 'ch' units in style data,
|
|
|
|
// which also depend on font metrics. Updating this information
|
|
|
|
// requires rebuilding the rule tree from the top, avoiding the
|
|
|
|
// reuse of cached data even when no style rules have changed.
|
|
|
|
|
|
|
|
PostRebuildAllStyleDataEvent(NS_STYLE_HINT_REFLOW);
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2009-12-31 18:56:33 +03:00
|
|
|
nsPresContext::EnsureSafeToHandOutCSSRules()
|
|
|
|
{
|
|
|
|
nsCSSStyleSheet::EnsureUniqueInnerResult res =
|
|
|
|
mShell->StyleSet()->EnsureUniqueInnerOnCSSSheets();
|
|
|
|
if (res == nsCSSStyleSheet::eUniqueInner_AlreadyUnique) {
|
|
|
|
// Nothing to do.
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
if (res == nsCSSStyleSheet::eUniqueInner_CloneFailed) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ABORT_IF_FALSE(res == nsCSSStyleSheet::eUniqueInner_ClonedInner,
|
|
|
|
"unexpected result");
|
|
|
|
RebuildAllStyleData(nsChangeHint(0));
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2008-09-18 13:47:21 +04:00
|
|
|
void
|
|
|
|
nsPresContext::FireDOMPaintEvent()
|
|
|
|
{
|
2009-06-23 13:09:05 +04:00
|
|
|
nsPIDOMWindow* ourWindow = mDocument->GetWindow();
|
2008-10-16 01:06:32 +04:00
|
|
|
if (!ourWindow)
|
2008-09-18 13:47:21 +04:00
|
|
|
return;
|
2008-10-16 01:06:32 +04:00
|
|
|
|
2009-06-23 13:09:05 +04:00
|
|
|
nsCOMPtr<nsIDOMEventTarget> dispatchTarget = do_QueryInterface(ourWindow);
|
|
|
|
nsCOMPtr<nsIDOMEventTarget> eventTarget = dispatchTarget;
|
2009-09-04 08:49:18 +04:00
|
|
|
if (!IsChrome()) {
|
2011-09-29 10:19:26 +04:00
|
|
|
bool notifyContent = mSendAfterPaintToContent;
|
2011-01-25 03:23:08 +03:00
|
|
|
|
|
|
|
if (notifyContent) {
|
|
|
|
// If the pref is set, we still don't post events when they're
|
|
|
|
// entirely cross-doc.
|
|
|
|
notifyContent = PR_FALSE;
|
|
|
|
for (PRUint32 i = 0; i < mInvalidateRequests.mRequests.Length(); ++i) {
|
|
|
|
if (!(mInvalidateRequests.mRequests[i].mFlags &
|
|
|
|
nsIFrame::INVALIDATE_CROSS_DOC)) {
|
|
|
|
notifyContent = PR_TRUE;
|
|
|
|
}
|
2009-09-04 08:49:18 +04:00
|
|
|
}
|
|
|
|
}
|
2011-01-25 03:23:08 +03:00
|
|
|
if (!notifyContent) {
|
2009-09-04 08:49:18 +04:00
|
|
|
// Don't tell the window about this event, it should not know that
|
|
|
|
// something happened in a subdocument. Tell only the chrome event handler.
|
|
|
|
// (Events sent to the window get propagated to the chrome event handler
|
|
|
|
// automatically.)
|
2010-12-20 04:37:43 +03:00
|
|
|
dispatchTarget = do_QueryInterface(ourWindow->GetParentTarget());
|
2009-09-04 08:49:18 +04:00
|
|
|
if (!dispatchTarget) {
|
|
|
|
return;
|
|
|
|
}
|
2008-10-19 00:10:19 +04:00
|
|
|
}
|
2008-09-18 13:47:21 +04:00
|
|
|
}
|
|
|
|
// Events sent to the window get propagated to the chrome event handler
|
|
|
|
// automatically.
|
2009-06-23 13:09:05 +04:00
|
|
|
nsCOMPtr<nsIDOMEvent> event;
|
2009-09-04 08:49:18 +04:00
|
|
|
// This will empty our list in case dispatching the event causes more damage
|
|
|
|
// (hopefully it won't, or we're likely to get an infinite loop! At least
|
|
|
|
// it won't be blocking app execution though).
|
2009-06-23 13:09:05 +04:00
|
|
|
NS_NewDOMNotifyPaintEvent(getter_AddRefs(event), this, nsnull,
|
|
|
|
NS_AFTERPAINT,
|
2009-09-04 08:49:18 +04:00
|
|
|
&mInvalidateRequests);
|
2009-06-23 13:09:05 +04:00
|
|
|
nsCOMPtr<nsIPrivateDOMEvent> pEvent = do_QueryInterface(event);
|
|
|
|
if (!pEvent) return;
|
2008-09-18 13:47:21 +04:00
|
|
|
|
|
|
|
// Even if we're not telling the window about the event (so eventTarget is
|
|
|
|
// the chrome event handler, not the window), the window is still
|
|
|
|
// logically the event target.
|
2009-06-23 13:09:05 +04:00
|
|
|
pEvent->SetTarget(eventTarget);
|
|
|
|
pEvent->SetTrusted(PR_TRUE);
|
|
|
|
nsEventDispatcher::DispatchDOMEvent(dispatchTarget, nsnull, event, this, nsnull);
|
2008-09-18 13:47:21 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool
|
2009-09-04 08:49:18 +04:00
|
|
|
MayHavePaintEventListener(nsPIDOMWindow* aInnerWindow)
|
2008-10-16 01:06:32 +04:00
|
|
|
{
|
|
|
|
if (!aInnerWindow)
|
|
|
|
return PR_FALSE;
|
|
|
|
if (aInnerWindow->HasPaintEventListeners())
|
|
|
|
return PR_TRUE;
|
|
|
|
|
2011-06-24 06:18:00 +04:00
|
|
|
nsIDOMEventTarget* parentTarget = aInnerWindow->GetParentTarget();
|
2010-06-16 15:43:36 +04:00
|
|
|
if (!parentTarget)
|
2008-10-16 01:06:32 +04:00
|
|
|
return PR_FALSE;
|
|
|
|
|
2011-06-24 06:18:01 +04:00
|
|
|
nsEventListenerManager* manager = nsnull;
|
2010-06-16 15:43:36 +04:00
|
|
|
if ((manager = parentTarget->GetListenerManager(PR_FALSE)) &&
|
|
|
|
manager->MayHavePaintEventListener()) {
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2010-05-18 16:28:37 +04:00
|
|
|
nsCOMPtr<nsINode> node;
|
2010-06-16 15:43:36 +04:00
|
|
|
if (parentTarget != aInnerWindow->GetChromeEventHandler()) {
|
|
|
|
nsCOMPtr<nsIInProcessContentFrameMessageManager> mm =
|
|
|
|
do_QueryInterface(parentTarget);
|
|
|
|
if (mm) {
|
|
|
|
node = mm->GetOwnerContent();
|
2010-05-18 16:28:37 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!node) {
|
2010-06-16 15:43:36 +04:00
|
|
|
node = do_QueryInterface(parentTarget);
|
2010-05-18 16:28:37 +04:00
|
|
|
}
|
2008-10-16 01:06:32 +04:00
|
|
|
if (node)
|
|
|
|
return MayHavePaintEventListener(node->GetOwnerDoc()->GetInnerWindow());
|
|
|
|
|
2010-06-16 15:43:36 +04:00
|
|
|
nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(parentTarget);
|
2008-10-16 01:06:32 +04:00
|
|
|
if (window)
|
|
|
|
return MayHavePaintEventListener(window);
|
|
|
|
|
2010-07-01 08:04:29 +04:00
|
|
|
nsCOMPtr<nsPIWindowRoot> root = do_QueryInterface(parentTarget);
|
2011-06-24 06:18:00 +04:00
|
|
|
nsIDOMEventTarget* tabChildGlobal;
|
2010-07-01 08:04:29 +04:00
|
|
|
return root &&
|
|
|
|
(tabChildGlobal = root->GetParentTarget()) &&
|
|
|
|
(manager = tabChildGlobal->GetListenerManager(PR_FALSE)) &&
|
|
|
|
manager->MayHavePaintEventListener();
|
2008-10-16 01:06:32 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2009-09-04 08:49:18 +04:00
|
|
|
nsPresContext::MayHavePaintEventListener()
|
|
|
|
{
|
|
|
|
return ::MayHavePaintEventListener(mDocument->GetInnerWindow());
|
|
|
|
}
|
|
|
|
|
2008-09-18 13:47:21 +04:00
|
|
|
void
|
2009-09-04 08:49:18 +04:00
|
|
|
nsPresContext::NotifyInvalidation(const nsRect& aRect, PRUint32 aFlags)
|
2008-09-18 13:47:21 +04:00
|
|
|
{
|
2008-10-16 01:06:32 +04:00
|
|
|
// If there is no paint event listener, then we don't need to fire
|
|
|
|
// the asynchronous event. We don't even need to record invalidation.
|
|
|
|
// MayHavePaintEventListener is pretty cheap and we could make it
|
|
|
|
// even cheaper by providing a more efficient
|
|
|
|
// nsPIDOMWindow::GetListenerManager.
|
2009-09-04 08:49:18 +04:00
|
|
|
if (aRect.IsEmpty() || !MayHavePaintEventListener())
|
2008-09-18 13:47:21 +04:00
|
|
|
return;
|
|
|
|
|
2011-01-15 12:40:33 +03:00
|
|
|
nsPresContext* pc;
|
|
|
|
for (pc = this; pc; pc = GetParentPresContext(pc)) {
|
|
|
|
if (pc->mFireAfterPaintEvents)
|
|
|
|
break;
|
|
|
|
pc->mFireAfterPaintEvents = PR_TRUE;
|
|
|
|
}
|
|
|
|
if (!pc) {
|
|
|
|
nsRootPresContext* rpc = GetRootPresContext();
|
|
|
|
if (rpc) {
|
|
|
|
rpc->EnsureEventualDidPaintEvent();
|
|
|
|
}
|
2008-09-18 13:47:21 +04:00
|
|
|
}
|
|
|
|
|
2009-09-04 08:49:18 +04:00
|
|
|
nsInvalidateRequestList::Request* request =
|
|
|
|
mInvalidateRequests.mRequests.AppendElement();
|
|
|
|
if (!request)
|
|
|
|
return;
|
|
|
|
|
|
|
|
request->mRect = aRect;
|
|
|
|
request->mFlags = aFlags;
|
2008-09-18 13:47:21 +04:00
|
|
|
}
|
2008-12-29 18:07:36 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool
|
2011-01-15 12:40:33 +03:00
|
|
|
NotifyDidPaintSubdocumentCallback(nsIDocument* aDocument, void* aData)
|
|
|
|
{
|
|
|
|
nsIPresShell* shell = aDocument->GetShell();
|
|
|
|
if (shell) {
|
|
|
|
nsPresContext* pc = shell->GetPresContext();
|
|
|
|
if (pc) {
|
|
|
|
pc->NotifyDidPaintForSubtree();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsPresContext::NotifyDidPaintForSubtree()
|
|
|
|
{
|
|
|
|
if (!mFireAfterPaintEvents)
|
|
|
|
return;
|
|
|
|
mFireAfterPaintEvents = PR_FALSE;
|
|
|
|
|
|
|
|
if (IsRoot()) {
|
|
|
|
static_cast<nsRootPresContext*>(this)->CancelDidPaintTimer();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mInvalidateRequests.mRequests.IsEmpty()) {
|
|
|
|
nsCOMPtr<nsIRunnable> ev =
|
|
|
|
NS_NewRunnableMethod(this, &nsPresContext::FireDOMPaintEvent);
|
|
|
|
nsContentUtils::AddScriptRunner(ev);
|
|
|
|
}
|
|
|
|
|
|
|
|
mDocument->EnumerateSubDocuments(NotifyDidPaintSubdocumentCallback, nsnull);
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2008-12-29 18:07:36 +03:00
|
|
|
nsPresContext::HasCachedStyleData()
|
|
|
|
{
|
|
|
|
return mShell && mShell->StyleSet()->HasCachedStyleData();
|
|
|
|
}
|
2009-04-22 03:53:52 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool sGotInterruptEnv = false;
|
2009-04-22 03:53:52 +04:00
|
|
|
enum InterruptMode {
|
|
|
|
ModeRandom,
|
|
|
|
ModeCounter,
|
|
|
|
ModeEvent
|
|
|
|
};
|
2009-10-02 22:05:32 +04:00
|
|
|
// Controlled by the GECKO_REFLOW_INTERRUPT_MODE env var; allowed values are
|
|
|
|
// "random" (except on Windows) or "counter". If neither is used, the mode is
|
|
|
|
// ModeEvent.
|
2009-04-22 03:53:52 +04:00
|
|
|
static InterruptMode sInterruptMode = ModeEvent;
|
2009-10-02 22:05:32 +04:00
|
|
|
// Used for the "random" mode. Controlled by the GECKO_REFLOW_INTERRUPT_SEED
|
|
|
|
// env var.
|
|
|
|
static PRUint32 sInterruptSeed = 1;
|
|
|
|
// Used for the "counter" mode. This is the number of unskipped interrupt
|
|
|
|
// checks that have to happen before we interrupt. Controlled by the
|
|
|
|
// GECKO_REFLOW_INTERRUPT_FREQUENCY env var.
|
2009-04-22 03:53:52 +04:00
|
|
|
static PRUint32 sInterruptMaxCounter = 10;
|
2009-10-02 22:05:32 +04:00
|
|
|
// Used for the "counter" mode. This counts up to sInterruptMaxCounter and is
|
|
|
|
// then reset to 0.
|
|
|
|
static PRUint32 sInterruptCounter;
|
|
|
|
// Number of interrupt checks to skip before really trying to interrupt.
|
|
|
|
// Controlled by the GECKO_REFLOW_INTERRUPT_CHECKS_TO_SKIP env var.
|
|
|
|
static PRUint32 sInterruptChecksToSkip = 200;
|
|
|
|
// Number of milliseconds that a reflow should be allowed to run for before we
|
|
|
|
// actually allow interruption. Controlled by the
|
|
|
|
// GECKO_REFLOW_MIN_NOINTERRUPT_DURATION env var.
|
|
|
|
static TimeDuration sInterruptTimeout = TimeDuration::FromMilliseconds(100);
|
2009-04-22 03:53:52 +04:00
|
|
|
|
|
|
|
static void GetInterruptEnv()
|
|
|
|
{
|
|
|
|
char *ev = PR_GetEnv("GECKO_REFLOW_INTERRUPT_MODE");
|
|
|
|
if (ev) {
|
|
|
|
#ifndef XP_WIN
|
|
|
|
if (PL_strcasecmp(ev, "random") == 0) {
|
|
|
|
ev = PR_GetEnv("GECKO_REFLOW_INTERRUPT_SEED");
|
|
|
|
if (ev) {
|
|
|
|
sInterruptSeed = atoi(ev);
|
|
|
|
}
|
|
|
|
srandom(sInterruptSeed);
|
|
|
|
sInterruptMode = ModeRandom;
|
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
if (PL_strcasecmp(ev, "counter") == 0) {
|
|
|
|
ev = PR_GetEnv("GECKO_REFLOW_INTERRUPT_FREQUENCY");
|
|
|
|
if (ev) {
|
|
|
|
sInterruptMaxCounter = atoi(ev);
|
|
|
|
}
|
|
|
|
sInterruptCounter = 0;
|
|
|
|
sInterruptMode = ModeCounter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ev = PR_GetEnv("GECKO_REFLOW_INTERRUPT_CHECKS_TO_SKIP");
|
|
|
|
if (ev) {
|
|
|
|
sInterruptChecksToSkip = atoi(ev);
|
|
|
|
}
|
2009-10-02 22:05:32 +04:00
|
|
|
|
|
|
|
ev = PR_GetEnv("GECKO_REFLOW_MIN_NOINTERRUPT_DURATION");
|
|
|
|
if (ev) {
|
|
|
|
sInterruptTimeout = TimeDuration::FromMilliseconds(atoi(ev));
|
|
|
|
}
|
2009-04-22 03:53:52 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2009-04-22 03:53:52 +04:00
|
|
|
nsPresContext::HavePendingInputEvent()
|
|
|
|
{
|
|
|
|
switch (sInterruptMode) {
|
|
|
|
#ifndef XP_WIN
|
|
|
|
case ModeRandom:
|
|
|
|
return (random() & 1);
|
|
|
|
#endif
|
|
|
|
case ModeCounter:
|
|
|
|
if (sInterruptCounter < sInterruptMaxCounter) {
|
|
|
|
++sInterruptCounter;
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
sInterruptCounter = 0;
|
|
|
|
return PR_TRUE;
|
|
|
|
default:
|
|
|
|
case ModeEvent: {
|
|
|
|
nsIFrame* f = PresShell()->GetRootFrame();
|
|
|
|
if (f) {
|
2010-07-02 23:11:04 +04:00
|
|
|
nsIWidget* w = f->GetNearestWidget();
|
2009-04-22 03:53:52 +04:00
|
|
|
if (w) {
|
|
|
|
return w->HasPendingInputEvent();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-09-29 10:19:26 +04:00
|
|
|
nsPresContext::ReflowStarted(bool aInterruptible)
|
2009-04-22 03:53:52 +04:00
|
|
|
{
|
2009-10-02 22:05:32 +04:00
|
|
|
#ifdef NOISY_INTERRUPTIBLE_REFLOW
|
|
|
|
if (!aInterruptible) {
|
|
|
|
printf("STARTING NONINTERRUPTIBLE REFLOW\n");
|
|
|
|
}
|
|
|
|
#endif
|
2009-04-22 03:53:52 +04:00
|
|
|
// We don't support interrupting in paginated contexts, since page
|
|
|
|
// sequences only handle initial reflow
|
|
|
|
mInterruptsEnabled = aInterruptible && !IsPaginated();
|
|
|
|
|
|
|
|
// Don't set mHasPendingInterrupt based on HavePendingInputEvent() here. If
|
|
|
|
// we ever change that, then we need to update the code in
|
|
|
|
// PresShell::DoReflow to only add the just-reflown root to dirty roots if
|
|
|
|
// it's actually dirty. Otherwise we can end up adding a root that has no
|
|
|
|
// interruptible descendants, just because we detected an interrupt at reflow
|
|
|
|
// start.
|
|
|
|
mHasPendingInterrupt = PR_FALSE;
|
|
|
|
|
|
|
|
mInterruptChecksToSkip = sInterruptChecksToSkip;
|
2009-10-02 22:05:32 +04:00
|
|
|
|
|
|
|
if (mInterruptsEnabled) {
|
|
|
|
mReflowStartTime = TimeStamp::Now();
|
|
|
|
}
|
2009-04-22 03:53:52 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2009-04-22 03:53:52 +04:00
|
|
|
nsPresContext::CheckForInterrupt(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
if (mHasPendingInterrupt) {
|
|
|
|
mShell->FrameNeedsToContinueReflow(aFrame);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!sGotInterruptEnv) {
|
|
|
|
sGotInterruptEnv = PR_TRUE;
|
|
|
|
GetInterruptEnv();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mInterruptsEnabled) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mInterruptChecksToSkip > 0) {
|
|
|
|
--mInterruptChecksToSkip;
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
mInterruptChecksToSkip = sInterruptChecksToSkip;
|
|
|
|
|
2009-10-02 22:05:32 +04:00
|
|
|
// Don't interrupt if it's been less than sInterruptTimeout since we started
|
|
|
|
// the reflow.
|
|
|
|
mHasPendingInterrupt =
|
|
|
|
TimeStamp::Now() - mReflowStartTime > sInterruptTimeout &&
|
|
|
|
HavePendingInputEvent() &&
|
|
|
|
!IsChrome();
|
2009-04-22 03:53:52 +04:00
|
|
|
if (mHasPendingInterrupt) {
|
|
|
|
#ifdef NOISY_INTERRUPTIBLE_REFLOW
|
|
|
|
printf("*** DETECTED pending interrupt (time=%lld)\n", PR_Now());
|
|
|
|
#endif /* NOISY_INTERRUPTIBLE_REFLOW */
|
|
|
|
mShell->FrameNeedsToContinueReflow(aFrame);
|
|
|
|
}
|
|
|
|
return mHasPendingInterrupt;
|
|
|
|
}
|
2009-07-22 04:44:54 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2010-09-11 22:24:50 +04:00
|
|
|
nsPresContext::IsRootContentDocument()
|
|
|
|
{
|
2010-10-09 23:09:22 +04:00
|
|
|
// We are a root content document if: we are not a resource doc, we are
|
|
|
|
// not chrome, and we either have no parent or our parent is chrome.
|
|
|
|
if (mDocument->IsResourceDoc()) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2010-09-11 22:24:50 +04:00
|
|
|
if (IsChrome()) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
// We may not have a root frame, so use views.
|
2011-03-30 06:24:54 +04:00
|
|
|
nsIView* view = PresShell()->GetViewManager()->GetRootView();
|
|
|
|
if (!view) {
|
2010-09-11 22:24:50 +04:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
view = view->GetParent(); // anonymous inner view
|
|
|
|
if (!view) {
|
2010-10-09 23:09:22 +04:00
|
|
|
return PR_TRUE;
|
2010-09-11 22:24:50 +04:00
|
|
|
}
|
|
|
|
view = view->GetParent(); // subdocumentframe's view
|
|
|
|
if (!view) {
|
2010-10-09 23:09:22 +04:00
|
|
|
return PR_TRUE;
|
2010-09-11 22:24:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame* f = static_cast<nsIFrame*>(view->GetClientData());
|
|
|
|
return (f && f->PresContext()->IsChrome());
|
|
|
|
}
|
|
|
|
|
2009-07-22 04:44:54 +04:00
|
|
|
nsRootPresContext::nsRootPresContext(nsIDocument* aDocument,
|
|
|
|
nsPresContextType aType)
|
2010-07-16 01:08:08 +04:00
|
|
|
: nsPresContext(aDocument, aType),
|
|
|
|
mUpdatePluginGeometryForFrame(nsnull),
|
2010-09-17 23:09:08 +04:00
|
|
|
mDOMGeneration(0),
|
2010-12-14 03:14:07 +03:00
|
|
|
mNeedsToUpdatePluginGeometry(PR_FALSE)
|
2009-07-22 04:44:54 +04:00
|
|
|
{
|
2009-07-22 04:45:00 +04:00
|
|
|
mRegisteredPlugins.Init();
|
2010-07-16 01:08:08 +04:00
|
|
|
}
|
2009-07-22 04:45:00 +04:00
|
|
|
|
|
|
|
nsRootPresContext::~nsRootPresContext()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mRegisteredPlugins.Count() == 0,
|
|
|
|
"All plugins should have been unregistered");
|
2011-01-15 12:40:33 +03:00
|
|
|
CancelDidPaintTimer();
|
2009-07-22 04:45:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsRootPresContext::RegisterPluginForGeometryUpdates(nsObjectFrame* aPlugin)
|
|
|
|
{
|
|
|
|
mRegisteredPlugins.PutEntry(aPlugin);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsRootPresContext::UnregisterPluginForGeometryUpdates(nsObjectFrame* aPlugin)
|
|
|
|
{
|
|
|
|
mRegisteredPlugins.RemoveEntry(aPlugin);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct PluginGeometryClosure {
|
|
|
|
nsIFrame* mRootFrame;
|
2010-07-19 06:23:48 +04:00
|
|
|
PRInt32 mRootAPD;
|
2009-07-22 04:45:00 +04:00
|
|
|
nsIFrame* mChangedSubtree;
|
|
|
|
nsRect mChangedRect;
|
|
|
|
nsTHashtable<nsPtrHashKey<nsObjectFrame> > mAffectedPlugins;
|
|
|
|
nsRect mAffectedPluginBounds;
|
|
|
|
nsTArray<nsIWidget::Configuration>* mOutputConfigurations;
|
|
|
|
};
|
|
|
|
static PLDHashOperator
|
|
|
|
PluginBoundsEnumerator(nsPtrHashKey<nsObjectFrame>* aEntry, void* userArg)
|
|
|
|
{
|
|
|
|
PluginGeometryClosure* closure = static_cast<PluginGeometryClosure*>(userArg);
|
|
|
|
nsObjectFrame* f = aEntry->GetKey();
|
|
|
|
nsRect fBounds = f->GetContentRect() +
|
2010-07-19 06:23:48 +04:00
|
|
|
f->GetParent()->GetOffsetToCrossDoc(closure->mRootFrame);
|
|
|
|
PRInt32 APD = f->PresContext()->AppUnitsPerDevPixel();
|
|
|
|
fBounds = fBounds.ConvertAppUnitsRoundOut(APD, closure->mRootAPD);
|
2009-07-22 04:45:00 +04:00
|
|
|
// We're identifying the plugins that may have been affected by changes
|
|
|
|
// to the frame subtree rooted at aChangedRoot. Any plugin that overlaps
|
|
|
|
// the overflow area of aChangedRoot could have its clip region affected
|
|
|
|
// because it might be covered (or uncovered) by changes to the subtree.
|
|
|
|
// Plugins in the subtree might have changed position and/or size, and
|
|
|
|
// they might not be in aChangedRoot's overflow area (because they're
|
|
|
|
// being clipped by an ancestor in the subtree).
|
|
|
|
if (fBounds.Intersects(closure->mChangedRect) ||
|
|
|
|
nsLayoutUtils::IsAncestorFrameCrossDoc(closure->mChangedSubtree, f)) {
|
|
|
|
closure->mAffectedPluginBounds.UnionRect(
|
|
|
|
closure->mAffectedPluginBounds, fBounds);
|
|
|
|
closure->mAffectedPlugins.PutEntry(f);
|
|
|
|
}
|
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
|
|
|
static PLDHashOperator
|
|
|
|
PluginHideEnumerator(nsPtrHashKey<nsObjectFrame>* aEntry, void* userArg)
|
|
|
|
{
|
|
|
|
PluginGeometryClosure* closure = static_cast<PluginGeometryClosure*>(userArg);
|
|
|
|
nsObjectFrame* f = aEntry->GetKey();
|
|
|
|
f->GetEmptyClipConfiguration(closure->mOutputConfigurations);
|
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
RecoverPluginGeometry(nsDisplayListBuilder* aBuilder,
|
2011-09-29 10:19:26 +04:00
|
|
|
nsDisplayList* aList, bool aInTransform, PluginGeometryClosure* aClosure)
|
2009-07-22 04:45:00 +04:00
|
|
|
{
|
|
|
|
for (nsDisplayItem* i = aList->GetBottom(); i; i = i->GetAbove()) {
|
|
|
|
switch (i->GetType()) {
|
|
|
|
case nsDisplayItem::TYPE_PLUGIN: {
|
|
|
|
nsDisplayPlugin* displayPlugin = static_cast<nsDisplayPlugin*>(i);
|
|
|
|
nsObjectFrame* f = static_cast<nsObjectFrame*>(
|
|
|
|
displayPlugin->GetUnderlyingFrame());
|
|
|
|
// Ignore plugins which aren't supposed to be affected by this
|
|
|
|
// operation --- their bounds will not have been included in the
|
|
|
|
// display list computations so the visible region computed for them
|
|
|
|
// would be incorrect
|
|
|
|
nsPtrHashKey<nsObjectFrame>* entry =
|
|
|
|
aClosure->mAffectedPlugins.GetEntry(f);
|
2011-04-01 01:33:46 +04:00
|
|
|
// Windowed plugins in transforms are always ignored, we don't
|
|
|
|
// create configurations for them
|
|
|
|
if (entry && (!aInTransform || !f->GetWidget())) {
|
2009-07-22 04:45:00 +04:00
|
|
|
displayPlugin->GetWidgetConfiguration(aBuilder,
|
|
|
|
aClosure->mOutputConfigurations);
|
|
|
|
// we've dealt with this plugin now
|
|
|
|
aClosure->mAffectedPlugins.RawRemoveEntry(entry);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2011-04-01 01:33:46 +04:00
|
|
|
case nsDisplayItem::TYPE_TRANSFORM: {
|
|
|
|
nsDisplayList* sublist =
|
|
|
|
static_cast<nsDisplayTransform*>(i)->GetStoredList()->GetList();
|
|
|
|
RecoverPluginGeometry(aBuilder, sublist, PR_TRUE, aClosure);
|
|
|
|
break;
|
|
|
|
}
|
2009-07-22 04:45:00 +04:00
|
|
|
default: {
|
|
|
|
nsDisplayList* sublist = i->GetList();
|
|
|
|
if (sublist) {
|
2011-04-01 01:33:46 +04:00
|
|
|
RecoverPluginGeometry(aBuilder, sublist, aInTransform, aClosure);
|
2009-07-22 04:45:00 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool gDumpPluginList = false;
|
2009-07-22 04:45:00 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
void
|
|
|
|
nsRootPresContext::GetPluginGeometryUpdates(nsIFrame* aChangedSubtree,
|
|
|
|
nsTArray<nsIWidget::Configuration>* aConfigurations)
|
|
|
|
{
|
|
|
|
if (mRegisteredPlugins.Count() == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
PluginGeometryClosure closure;
|
|
|
|
closure.mRootFrame = mShell->FrameManager()->GetRootFrame();
|
2010-07-19 06:23:48 +04:00
|
|
|
closure.mRootAPD = closure.mRootFrame->PresContext()->AppUnitsPerDevPixel();
|
2009-07-22 04:45:00 +04:00
|
|
|
closure.mChangedSubtree = aChangedSubtree;
|
2010-10-07 08:25:47 +04:00
|
|
|
closure.mChangedRect = aChangedSubtree->GetVisualOverflowRect() +
|
2010-07-19 06:23:48 +04:00
|
|
|
aChangedSubtree->GetOffsetToCrossDoc(closure.mRootFrame);
|
|
|
|
PRInt32 subtreeAPD = aChangedSubtree->PresContext()->AppUnitsPerDevPixel();
|
|
|
|
closure.mChangedRect =
|
|
|
|
closure.mChangedRect.ConvertAppUnitsRoundOut(subtreeAPD, closure.mRootAPD);
|
2009-07-22 04:45:00 +04:00
|
|
|
closure.mAffectedPlugins.Init();
|
|
|
|
closure.mOutputConfigurations = aConfigurations;
|
|
|
|
// Fill in closure.mAffectedPlugins and closure.mAffectedPluginBounds
|
|
|
|
mRegisteredPlugins.EnumerateEntries(PluginBoundsEnumerator, &closure);
|
|
|
|
|
|
|
|
nsRect bounds;
|
|
|
|
if (bounds.IntersectRect(closure.mAffectedPluginBounds,
|
|
|
|
closure.mRootFrame->GetRect())) {
|
2010-11-08 12:06:14 +03:00
|
|
|
nsDisplayListBuilder builder(closure.mRootFrame,
|
|
|
|
nsDisplayListBuilder::PLUGIN_GEOMETRY, PR_FALSE);
|
2009-07-22 04:45:00 +04:00
|
|
|
builder.SetAccurateVisibleRegions();
|
|
|
|
nsDisplayList list;
|
|
|
|
|
|
|
|
builder.EnterPresShell(closure.mRootFrame, bounds);
|
|
|
|
closure.mRootFrame->BuildDisplayListForStackingContext(
|
|
|
|
&builder, bounds, &list);
|
|
|
|
builder.LeavePresShell(closure.mRootFrame, bounds);
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (gDumpPluginList) {
|
|
|
|
fprintf(stderr, "Plugins --- before optimization (bounds %d,%d,%d,%d):\n",
|
|
|
|
bounds.x, bounds.y, bounds.width, bounds.height);
|
2009-08-21 01:52:48 +04:00
|
|
|
nsFrame::PrintDisplayList(&builder, list);
|
2009-07-22 04:45:00 +04:00
|
|
|
}
|
|
|
|
#endif
|
2009-08-21 01:52:48 +04:00
|
|
|
|
2009-07-22 04:45:00 +04:00
|
|
|
nsRegion visibleRegion(bounds);
|
2010-08-28 03:15:08 +04:00
|
|
|
list.ComputeVisibilityForRoot(&builder, &visibleRegion);
|
2009-07-22 04:45:00 +04:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (gDumpPluginList) {
|
|
|
|
fprintf(stderr, "Plugins --- after optimization:\n");
|
2009-08-21 01:52:48 +04:00
|
|
|
nsFrame::PrintDisplayList(&builder, list);
|
2009-07-22 04:45:00 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-04-01 01:33:46 +04:00
|
|
|
RecoverPluginGeometry(&builder, &list, PR_FALSE, &closure);
|
2009-07-22 04:45:00 +04:00
|
|
|
list.DeleteAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Plugins that we didn't find in the display list are not visible
|
|
|
|
closure.mAffectedPlugins.EnumerateEntries(PluginHideEnumerator, &closure);
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool
|
2010-07-16 01:08:08 +04:00
|
|
|
HasOverlap(const nsIntPoint& aOffset1, const nsTArray<nsIntRect>& aClipRects1,
|
|
|
|
const nsIntPoint& aOffset2, const nsTArray<nsIntRect>& aClipRects2)
|
|
|
|
{
|
|
|
|
nsIntPoint offsetDelta = aOffset1 - aOffset2;
|
|
|
|
for (PRUint32 i = 0; i < aClipRects1.Length(); ++i) {
|
|
|
|
for (PRUint32 j = 0; j < aClipRects2.Length(); ++j) {
|
|
|
|
if ((aClipRects1[i] + offsetDelta).Intersects(aClipRects2[j]))
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Given a list of plugin windows to move to new locations, sort the list
|
|
|
|
* so that for each window move, the window moves to a location that
|
|
|
|
* does not intersect other windows. This minimizes flicker and repainting.
|
|
|
|
* It's not always possible to do this perfectly, since in general
|
|
|
|
* we might have cycles. But we do our best.
|
|
|
|
* We need to take into account that windows are clipped to particular
|
|
|
|
* regions and the clip regions change as the windows are moved.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
SortConfigurations(nsTArray<nsIWidget::Configuration>* aConfigurations)
|
|
|
|
{
|
|
|
|
if (aConfigurations->Length() > 10) {
|
|
|
|
// Give up, we don't want to get bogged down here
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsTArray<nsIWidget::Configuration> pluginsToMove;
|
|
|
|
pluginsToMove.SwapElements(*aConfigurations);
|
|
|
|
|
|
|
|
// Our algorithm is quite naive. At each step we try to identify
|
|
|
|
// a window that can be moved to its new location that won't overlap
|
|
|
|
// any other windows at the new location. If there is no such
|
|
|
|
// window, we just move the last window in the list anyway.
|
|
|
|
while (!pluginsToMove.IsEmpty()) {
|
|
|
|
// Find a window whose destination does not overlap any other window
|
|
|
|
PRUint32 i;
|
|
|
|
for (i = 0; i + 1 < pluginsToMove.Length(); ++i) {
|
|
|
|
nsIWidget::Configuration* config = &pluginsToMove[i];
|
2011-09-29 10:19:26 +04:00
|
|
|
bool foundOverlap = false;
|
2010-07-16 01:08:08 +04:00
|
|
|
for (PRUint32 j = 0; j < pluginsToMove.Length(); ++j) {
|
|
|
|
if (i == j)
|
|
|
|
continue;
|
|
|
|
nsIntRect bounds;
|
|
|
|
pluginsToMove[j].mChild->GetBounds(bounds);
|
|
|
|
nsAutoTArray<nsIntRect,1> clipRects;
|
|
|
|
pluginsToMove[j].mChild->GetWindowClipRegion(&clipRects);
|
|
|
|
if (HasOverlap(bounds.TopLeft(), clipRects,
|
|
|
|
config->mBounds.TopLeft(),
|
|
|
|
config->mClipRegion)) {
|
|
|
|
foundOverlap = PR_TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!foundOverlap)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// Note that we always move the last plugin in pluginsToMove, if we
|
|
|
|
// can't find any other plugin to move
|
|
|
|
aConfigurations->AppendElement(pluginsToMove[i]);
|
|
|
|
pluginsToMove.RemoveElementAt(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-22 04:45:00 +04:00
|
|
|
void
|
2010-07-16 01:08:08 +04:00
|
|
|
nsRootPresContext::UpdatePluginGeometry()
|
2009-07-22 04:45:00 +04:00
|
|
|
{
|
2010-07-16 01:08:08 +04:00
|
|
|
if (!mNeedsToUpdatePluginGeometry)
|
|
|
|
return;
|
|
|
|
mNeedsToUpdatePluginGeometry = PR_FALSE;
|
|
|
|
|
|
|
|
nsIFrame* f = mUpdatePluginGeometryForFrame;
|
|
|
|
if (f) {
|
|
|
|
mUpdatePluginGeometryForFrame->PresContext()->
|
|
|
|
SetContainsUpdatePluginGeometryFrame(PR_FALSE);
|
|
|
|
mUpdatePluginGeometryForFrame = nsnull;
|
|
|
|
} else {
|
|
|
|
f = FrameManager()->GetRootFrame();
|
|
|
|
}
|
|
|
|
|
2009-07-22 04:45:00 +04:00
|
|
|
nsTArray<nsIWidget::Configuration> configurations;
|
2010-07-16 01:08:08 +04:00
|
|
|
GetPluginGeometryUpdates(f, &configurations);
|
2009-07-22 04:45:00 +04:00
|
|
|
if (configurations.IsEmpty())
|
|
|
|
return;
|
2010-07-16 01:08:08 +04:00
|
|
|
SortConfigurations(&configurations);
|
2010-07-02 23:11:04 +04:00
|
|
|
nsIWidget* widget = FrameManager()->GetRootFrame()->GetNearestWidget();
|
2009-09-30 02:18:20 +04:00
|
|
|
NS_ASSERTION(widget, "Plugins must have a parent window");
|
2009-07-22 04:45:00 +04:00
|
|
|
widget->ConfigureChildren(configurations);
|
2009-07-22 04:45:02 +04:00
|
|
|
DidApplyPluginGeometryUpdates();
|
|
|
|
}
|
|
|
|
|
2010-07-16 01:08:08 +04:00
|
|
|
void
|
2010-10-11 04:58:21 +04:00
|
|
|
nsRootPresContext::SynchronousPluginGeometryUpdate()
|
2010-07-16 01:08:08 +04:00
|
|
|
{
|
2010-10-11 04:58:21 +04:00
|
|
|
if (!mNeedsToUpdatePluginGeometry) {
|
|
|
|
// Nothing to do
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-07-16 01:08:08 +04:00
|
|
|
// Force synchronous paint
|
|
|
|
nsIPresShell* shell = GetPresShell();
|
|
|
|
if (!shell)
|
|
|
|
return;
|
|
|
|
nsIFrame* rootFrame = shell->GetRootFrame();
|
|
|
|
if (!rootFrame)
|
|
|
|
return;
|
|
|
|
nsCOMPtr<nsIWidget> widget = rootFrame->GetNearestWidget();
|
|
|
|
if (!widget)
|
|
|
|
return;
|
|
|
|
// Force synchronous paint of a single pixel, just to force plugin
|
|
|
|
// updates to be flushed. Doing plugin updates during paint is the best
|
|
|
|
// way to ensure that plugin updates are in sync with our content.
|
|
|
|
widget->Invalidate(nsIntRect(0,0,1,1), PR_TRUE);
|
|
|
|
|
|
|
|
// Update plugin geometry just in case that invalidate didn't work
|
|
|
|
// (e.g. if none of the widget is visible, it might not have processed
|
|
|
|
// a paint event). Normally this won't need to do anything.
|
|
|
|
UpdatePluginGeometry();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsRootPresContext::RequestUpdatePluginGeometry(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
if (mRegisteredPlugins.Count() == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!mNeedsToUpdatePluginGeometry) {
|
2010-07-20 05:29:29 +04:00
|
|
|
mNeedsToUpdatePluginGeometry = PR_TRUE;
|
|
|
|
|
2010-07-16 01:08:08 +04:00
|
|
|
// Dispatch a Gecko event to ensure plugin geometry gets updated
|
2010-10-11 04:58:21 +04:00
|
|
|
// XXX this really should be done through the refresh driver, once
|
|
|
|
// all painting happens in the refresh driver
|
2010-07-16 01:08:08 +04:00
|
|
|
nsCOMPtr<nsIRunnable> event =
|
2010-10-11 04:58:21 +04:00
|
|
|
NS_NewRunnableMethod(this, &nsRootPresContext::SynchronousPluginGeometryUpdate);
|
2010-07-16 01:08:08 +04:00
|
|
|
NS_DispatchToMainThread(event);
|
|
|
|
|
|
|
|
mUpdatePluginGeometryForFrame = aFrame;
|
|
|
|
mUpdatePluginGeometryForFrame->PresContext()->
|
|
|
|
SetContainsUpdatePluginGeometryFrame(PR_TRUE);
|
|
|
|
} else {
|
2010-07-20 05:29:29 +04:00
|
|
|
if (!mUpdatePluginGeometryForFrame ||
|
|
|
|
aFrame == mUpdatePluginGeometryForFrame)
|
|
|
|
return;
|
2010-07-16 01:08:08 +04:00
|
|
|
mUpdatePluginGeometryForFrame->PresContext()->
|
|
|
|
SetContainsUpdatePluginGeometryFrame(PR_FALSE);
|
|
|
|
mUpdatePluginGeometryForFrame = nsnull;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-22 04:45:02 +04:00
|
|
|
static PLDHashOperator
|
|
|
|
PluginDidSetGeometryEnumerator(nsPtrHashKey<nsObjectFrame>* aEntry, void* userArg)
|
|
|
|
{
|
|
|
|
nsObjectFrame* f = aEntry->GetKey();
|
|
|
|
f->DidSetWidgetGeometry();
|
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsRootPresContext::DidApplyPluginGeometryUpdates()
|
|
|
|
{
|
|
|
|
mRegisteredPlugins.EnumerateEntries(PluginDidSetGeometryEnumerator, nsnull);
|
2009-07-22 04:45:00 +04:00
|
|
|
}
|
2010-07-16 01:08:08 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
nsRootPresContext::RootForgetUpdatePluginGeometryFrame(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
if (aFrame == mUpdatePluginGeometryForFrame) {
|
|
|
|
mUpdatePluginGeometryForFrame->PresContext()->
|
|
|
|
SetContainsUpdatePluginGeometryFrame(PR_FALSE);
|
|
|
|
mUpdatePluginGeometryForFrame = nsnull;
|
|
|
|
}
|
|
|
|
}
|
2011-01-15 12:40:33 +03:00
|
|
|
|
2011-04-06 22:00:02 +04:00
|
|
|
void
|
|
|
|
nsRootPresContext::RootForgetUpdatePluginGeometryFrameForPresContext(
|
|
|
|
nsPresContext* aPresContext)
|
|
|
|
{
|
|
|
|
if (aPresContext->GetContainsUpdatePluginGeometryFrame()) {
|
|
|
|
aPresContext->SetContainsUpdatePluginGeometryFrame(PR_FALSE);
|
|
|
|
mUpdatePluginGeometryForFrame = nsnull;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-15 12:40:33 +03:00
|
|
|
static void
|
|
|
|
NotifyDidPaintForSubtreeCallback(nsITimer *aTimer, void *aClosure)
|
|
|
|
{
|
|
|
|
nsPresContext* presContext = (nsPresContext*)aClosure;
|
|
|
|
nsAutoScriptBlocker blockScripts;
|
|
|
|
presContext->NotifyDidPaintForSubtree();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsRootPresContext::EnsureEventualDidPaintEvent()
|
|
|
|
{
|
|
|
|
if (mNotifyDidPaintTimer)
|
|
|
|
return;
|
|
|
|
mNotifyDidPaintTimer = do_CreateInstance("@mozilla.org/timer;1");
|
|
|
|
if (!mNotifyDidPaintTimer)
|
|
|
|
return;
|
|
|
|
mNotifyDidPaintTimer->InitWithFuncCallback(NotifyDidPaintForSubtreeCallback,
|
|
|
|
(void*)this, 100, nsITimer::TYPE_ONE_SHOT);
|
|
|
|
}
|