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"
|
|
|
|
#include "nsIRenderingContext.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"
|
1999-09-10 09:51:08 +04:00
|
|
|
#include "nsILookAndFeel.h"
|
|
|
|
#include "nsWidgetsCID.h"
|
|
|
|
#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"
|
2008-10-16 01:06:32 +04:00
|
|
|
#include "nsIEventListenerManager.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"
|
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"
|
|
|
|
|
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
|
|
|
|
2009-10-02 22:05:32 +04:00
|
|
|
using mozilla::TimeDuration;
|
|
|
|
using mozilla::TimeStamp;
|
|
|
|
|
2001-05-08 05:40:09 +04:00
|
|
|
static nscolor
|
|
|
|
MakeColorPref(const char *colstr)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
PR_sscanf(colstr, "#%02x%02x%02x", &red, &green, &blue);
|
|
|
|
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
|
2004-04-13 04:28:44 +04:00
|
|
|
static PRBool
|
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
|
|
|
}
|
|
|
|
|
2000-07-29 02:12:45 +04:00
|
|
|
static NS_DEFINE_CID(kLookAndFeelCID, NS_LOOKANDFEEL_CID);
|
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)
|
2007-08-08 00:38:35 +04:00
|
|
|
: mType(aType), mDocument(aDocument), mTextZoom(1.0), mFullZoom(1.0),
|
2007-04-19 23:11:42 +04:00
|
|
|
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,
|
|
|
|
NS_FONT_STRETCH_NORMAL, 0, 0),
|
2006-09-12 08:36:03 +04:00
|
|
|
mCanPaginatedScroll(PR_FALSE),
|
2008-01-29 07:10:59 +03:00
|
|
|
mIsRootPaginatedDocument(PR_FALSE), mSupressResizeReflow(PR_FALSE)
|
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;
|
|
|
|
|
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;
|
|
|
|
|
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;
|
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
|
|
|
{
|
2009-02-19 22:03:28 +03:00
|
|
|
for (PRUint32 i = 0; i < IMAGE_LOAD_TYPE_COUNT; ++i)
|
|
|
|
mImageLoaders[i].Enumerate(destroy_loads, nsnull);
|
2001-08-10 00:22:39 +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
|
|
|
|
2009-12-22 23:46:23 +03:00
|
|
|
delete mTransitionManager;
|
2009-10-08 07:22:42 +04:00
|
|
|
|
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
|
2004-04-30 08:06:30 +04:00
|
|
|
nsContentUtils::UnregisterPrefCallback("font.",
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::PrefChangedCallback,
|
2004-04-30 08:06:30 +04:00
|
|
|
this);
|
|
|
|
nsContentUtils::UnregisterPrefCallback("browser.display.",
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::PrefChangedCallback,
|
2004-04-30 08:06:30 +04:00
|
|
|
this);
|
|
|
|
nsContentUtils::UnregisterPrefCallback("browser.underline_anchors",
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::PrefChangedCallback,
|
2004-04-30 08:06:30 +04:00
|
|
|
this);
|
|
|
|
nsContentUtils::UnregisterPrefCallback("browser.anchor_color",
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::PrefChangedCallback,
|
2004-04-30 08:06:30 +04:00
|
|
|
this);
|
|
|
|
nsContentUtils::UnregisterPrefCallback("browser.active_color",
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::PrefChangedCallback,
|
2004-04-30 08:06:30 +04:00
|
|
|
this);
|
|
|
|
nsContentUtils::UnregisterPrefCallback("browser.visited_color",
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::PrefChangedCallback,
|
2004-04-30 08:06:30 +04:00
|
|
|
this);
|
|
|
|
nsContentUtils::UnregisterPrefCallback("image.animation_mode",
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::PrefChangedCallback,
|
2004-04-30 08:06:30 +04:00
|
|
|
this);
|
2004-04-30 07:10:29 +04:00
|
|
|
#ifdef IBMBIDI
|
2004-04-30 08:06:30 +04:00
|
|
|
nsContentUtils::UnregisterPrefCallback("bidi.", PrefChangedCallback, this);
|
|
|
|
|
|
|
|
delete mBidiUtils;
|
2001-03-09 06:13:03 +03:00
|
|
|
#endif // IBMBIDI
|
2007-02-15 12:04:25 +03:00
|
|
|
nsContentUtils::UnregisterPrefCallback("layout.css.dpi",
|
|
|
|
nsPresContext::PrefChangedCallback,
|
|
|
|
this);
|
2009-05-18 02:09:53 +04:00
|
|
|
nsContentUtils::UnregisterPrefCallback("layout.css.devPixelsPerPx",
|
|
|
|
nsPresContext::PrefChangedCallback,
|
|
|
|
this);
|
2003-06-19 22:16:53 +04:00
|
|
|
|
|
|
|
NS_IF_RELEASE(mDeviceContext);
|
2004-01-21 12:35:59 +03:00
|
|
|
NS_IF_RELEASE(mLookAndFeel);
|
2004-06-09 03:53:59 +04:00
|
|
|
NS_IF_RELEASE(mLangGroup);
|
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)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIObserver)
|
|
|
|
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);
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_RAWPTR(mDeviceContext); // worth bothering?
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_RAWPTR(mEventManager);
|
|
|
|
// NS_IMPL_CYCLE_COLLECTION_TRAVERSE_RAWPTR(mLookAndFeel); // a service
|
|
|
|
// NS_IMPL_CYCLE_COLLECTION_TRAVERSE_RAWPTR(mLangGroup); // an atom
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
// NS_RELEASE(tmp->mLookAndFeel); // a service
|
|
|
|
// NS_RELEASE(tmp->mLangGroup); // an atom
|
|
|
|
|
2009-02-19 22:03:28 +03:00
|
|
|
for (PRUint32 i = 0; i < IMAGE_LOAD_TYPE_COUNT; ++i) {
|
|
|
|
tmp->mImageLoaders[i].Enumerate(destroy_loads, nsnull);
|
|
|
|
tmp->mImageLoaders[i].Clear();
|
|
|
|
}
|
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.
|
|
|
|
static PRBool sNoTheme = PR_FALSE;
|
|
|
|
|
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.
|
|
|
|
static PRBool sLookAndFeelChanged;
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
static PRBool sThemeChanged;
|
|
|
|
|
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
|
|
|
|
2007-10-12 02:54:18 +04:00
|
|
|
const char *langGroup = "x-western"; // Assume x-western is safe...
|
|
|
|
if (mLangGroup) {
|
|
|
|
mLangGroup->GetUTF8String(&langGroup);
|
|
|
|
}
|
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 =
|
|
|
|
nsContentUtils::GetCharPref("font.size.unit");
|
|
|
|
|
|
|
|
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
|
|
|
|
2004-04-30 08:06:30 +04:00
|
|
|
PRInt32 size = nsContentUtils::GetIntPref(pref.get());
|
2006-08-08 20:43:20 +04:00
|
|
|
if (unit == eUnit_px) {
|
2007-02-07 10:46:44 +03:00
|
|
|
mMinimumFontSize = CSSPixelsToAppUnits(size);
|
2006-08-08 20:43:20 +04:00
|
|
|
}
|
|
|
|
else if (unit == eUnit_pt) {
|
2007-02-07 10:46:44 +03:00
|
|
|
mMinimumFontSize = this->PointsToAppUnits(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
|
|
|
|
|
|
|
nsAdoptingString value =
|
|
|
|
nsContentUtils::GetStringPref(pref.get());
|
|
|
|
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);
|
|
|
|
value = nsContentUtils::GetStringPref(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);
|
2004-04-30 08:06:30 +04:00
|
|
|
size = nsContentUtils::GetIntPref(pref.get());
|
|
|
|
if (size > 0) {
|
2001-09-27 22:34:30 +04:00
|
|
|
if (unit == eUnit_px) {
|
2007-02-07 10:46:44 +03:00
|
|
|
font->size = nsPresContext::CSSPixelsToAppUnits(size);
|
2000-01-15 19:30:13 +03:00
|
|
|
}
|
2001-09-27 22:34:30 +04:00
|
|
|
else if (unit == eUnit_pt) {
|
2007-02-07 10:46:44 +03:00
|
|
|
font->size = this->PointsToAppUnits(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);
|
2004-04-30 08:06:30 +04:00
|
|
|
cvalue = nsContentUtils::GetCharPref(pref.get());
|
|
|
|
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;
|
2001-10-17 03:59:25 +04:00
|
|
|
PRBool usePrefColors = PR_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 {
|
|
|
|
mLookAndFeel->GetMetric(nsILookAndFeel::eMetric_UseAccessibilityTheme, useAccessibilityTheme);
|
|
|
|
usePrefColors = !useAccessibilityTheme;
|
|
|
|
}
|
|
|
|
|
2001-10-17 03:59:25 +04:00
|
|
|
}
|
|
|
|
if (usePrefColors) {
|
2004-04-30 08:06:30 +04:00
|
|
|
usePrefColors =
|
|
|
|
!nsContentUtils::GetBoolPref("browser.display.use_system_colors",
|
|
|
|
PR_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 =
|
|
|
|
nsContentUtils::GetCharPref("browser.display.foreground_color");
|
|
|
|
|
|
|
|
if (!colorStr.IsEmpty()) {
|
2001-10-17 03:59:25 +04:00
|
|
|
mDefaultColor = MakeColorPref(colorStr);
|
|
|
|
}
|
2004-04-30 08:06:30 +04:00
|
|
|
|
|
|
|
colorStr =
|
|
|
|
nsContentUtils::GetCharPref("browser.display.background_color");
|
|
|
|
|
|
|
|
if (!colorStr.IsEmpty()) {
|
2004-02-01 01:41:40 +03:00
|
|
|
mBackgroundColor = MakeColorPref(colorStr);
|
2001-10-17 03:59:25 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mDefaultColor = NS_RGB(0x00, 0x00, 0x00);
|
2004-02-01 01:41:40 +03:00
|
|
|
mBackgroundColor = NS_RGB(0xFF, 0xFF, 0xFF);
|
2004-01-21 12:35:59 +03:00
|
|
|
mLookAndFeel->GetColor(nsILookAndFeel::eColor_WindowForeground,
|
|
|
|
mDefaultColor);
|
|
|
|
mLookAndFeel->GetColor(nsILookAndFeel::eColor_WindowBackground,
|
2004-02-01 01:41:40 +03:00
|
|
|
mBackgroundColor);
|
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 &&
|
2004-04-30 08:06:30 +04:00
|
|
|
nsContentUtils::GetBoolPref("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;
|
|
|
|
}
|
|
|
|
|
2004-04-30 08:06:30 +04:00
|
|
|
mFontScaler =
|
|
|
|
nsContentUtils::GetIntPref("browser.display.base_font_scaler",
|
|
|
|
mFontScaler);
|
1998-11-06 19:16:01 +03:00
|
|
|
|
2008-02-08 22:52:46 +03:00
|
|
|
|
|
|
|
mAutoQualityMinFontSizePixelsPref =
|
|
|
|
nsContentUtils::GetIntPref("browser.display.auto_quality_min_font_size");
|
|
|
|
|
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
|
|
|
|
2000-10-11 12:33:01 +04:00
|
|
|
// * link colors
|
2004-04-30 08:06:30 +04:00
|
|
|
mUnderlineLinks =
|
|
|
|
nsContentUtils::GetBoolPref("browser.underline_anchors", mUnderlineLinks);
|
|
|
|
|
|
|
|
nsAdoptingCString colorStr =
|
|
|
|
nsContentUtils::GetCharPref("browser.anchor_color");
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
colorStr =
|
|
|
|
nsContentUtils::GetCharPref("browser.active_color");
|
|
|
|
|
|
|
|
if (!colorStr.IsEmpty()) {
|
2003-10-15 05:56:12 +04:00
|
|
|
mActiveLinkColor = MakeColorPref(colorStr);
|
|
|
|
}
|
2004-04-30 08:06:30 +04:00
|
|
|
|
|
|
|
colorStr = nsContentUtils::GetCharPref("browser.visited_color");
|
|
|
|
|
|
|
|
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 =
|
|
|
|
nsContentUtils::GetBoolPref("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;
|
|
|
|
|
|
|
|
colorStr = nsContentUtils::GetCharPref("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
|
|
|
}
|
|
|
|
|
2004-04-30 08:06:30 +04:00
|
|
|
colorStr =
|
|
|
|
nsContentUtils::GetCharPref("browser.display.focus_background_color");
|
|
|
|
|
|
|
|
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 =
|
|
|
|
nsContentUtils::GetIntPref("browser.display.focus_ring_width",
|
|
|
|
mFocusRingWidth);
|
|
|
|
|
|
|
|
mFocusRingOnAnything =
|
|
|
|
nsContentUtils::GetBoolPref("browser.display.focus_ring_on_anything",
|
|
|
|
mFocusRingOnAnything);
|
|
|
|
|
2008-10-09 03:28:31 +04:00
|
|
|
mFocusRingStyle =
|
|
|
|
nsContentUtils::GetIntPref("browser.display.focus_ring_style",
|
|
|
|
mFocusRingStyle);
|
2000-10-11 12:33:01 +04:00
|
|
|
// * use fonts?
|
2004-04-30 08:06:30 +04:00
|
|
|
mUseDocumentFonts =
|
|
|
|
nsContentUtils::GetIntPref("browser.display.use_document_fonts") != 0;
|
|
|
|
|
2004-06-21 14:32:27 +04:00
|
|
|
// * replace backslashes with Yen signs? (bug 245770)
|
|
|
|
mEnableJapaneseTransform =
|
|
|
|
nsContentUtils::GetBoolPref("layout.enable_japanese_specific_transform");
|
|
|
|
|
2006-03-26 04:48:03 +04:00
|
|
|
mPrefScrollbarSide =
|
|
|
|
nsContentUtils::GetIntPref("layout.scrollbar.side");
|
|
|
|
|
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 =
|
|
|
|
nsContentUtils::GetCharPref("image.animation_mode");
|
|
|
|
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 =
|
2006-03-26 04:48:03 +04:00
|
|
|
nsContentUtils::GetIntPref(IBMBIDI_TEXTDIRECTION_STR,
|
2005-11-09 01:45:49 +03:00
|
|
|
GET_BIDI_OPTION_DIRECTION(bidiOptions));
|
|
|
|
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 =
|
2006-03-26 04:48:03 +04:00
|
|
|
nsContentUtils::GetIntPref(IBMBIDI_TEXTTYPE_STR,
|
2005-11-09 01:45:49 +03:00
|
|
|
GET_BIDI_OPTION_TEXTTYPE(bidiOptions));
|
|
|
|
SET_BIDI_OPTION_TEXTTYPE(bidiOptions, prefInt);
|
2004-04-30 08:06:30 +04:00
|
|
|
|
|
|
|
prefInt =
|
2006-03-26 04:48:03 +04:00
|
|
|
nsContentUtils::GetIntPref(IBMBIDI_CONTROLSTEXTMODE_STR,
|
2005-11-09 01:45:49 +03:00
|
|
|
GET_BIDI_OPTION_CONTROLSTEXTMODE(bidiOptions));
|
|
|
|
SET_BIDI_OPTION_CONTROLSTEXTMODE(bidiOptions, prefInt);
|
2004-04-30 08:06:30 +04:00
|
|
|
|
|
|
|
prefInt =
|
2006-03-26 04:48:03 +04:00
|
|
|
nsContentUtils::GetIntPref(IBMBIDI_NUMERAL_STR,
|
2005-11-09 01:45:49 +03:00
|
|
|
GET_BIDI_OPTION_NUMERAL(bidiOptions));
|
|
|
|
SET_BIDI_OPTION_NUMERAL(bidiOptions, prefInt);
|
2004-04-30 08:06:30 +04:00
|
|
|
|
|
|
|
prefInt =
|
2006-03-26 04:48:03 +04:00
|
|
|
nsContentUtils::GetIntPref(IBMBIDI_SUPPORTMODE_STR,
|
2005-11-09 01:45:49 +03:00
|
|
|
GET_BIDI_OPTION_SUPPORT(bidiOptions));
|
|
|
|
SET_BIDI_OPTION_SUPPORT(bidiOptions, prefInt);
|
2004-04-30 08:06:30 +04:00
|
|
|
|
|
|
|
prefInt =
|
2006-03-26 04:48:03 +04:00
|
|
|
nsContentUtils::GetIntPref(IBMBIDI_CHARSET_STR,
|
2005-11-09 01:45:49 +03:00
|
|
|
GET_BIDI_OPTION_CHARACTERSET(bidiOptions));
|
|
|
|
SET_BIDI_OPTION_CHARACTERSET(bidiOptions, prefInt);
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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) {
|
|
|
|
mDeviceContext->FlushFontCache();
|
|
|
|
|
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);
|
|
|
|
|
2008-07-26 20:14:48 +04:00
|
|
|
MediaFeatureValuesChanged(PR_TRUE);
|
2008-02-08 22:52:46 +03:00
|
|
|
RebuildAllStyleData(NS_STYLE_HINT_REFLOW);
|
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.
|
|
|
|
}
|
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);
|
|
|
|
}
|
|
|
|
|
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
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::Init(nsIDeviceContext* aDeviceContext)
|
1998-06-25 08:24:45 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(!(mInitialized == PR_TRUE), "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;
|
2008-10-29 00:36:17 +03:00
|
|
|
|
2004-01-21 12:35:59 +03:00
|
|
|
// Get the look and feel service here; default colors will be initialized
|
2005-11-09 01:45:49 +03:00
|
|
|
// from calling GetUserPreferences() when we get a presshell.
|
2004-01-21 12:35:59 +03:00
|
|
|
nsresult rv = CallGetService(kLookAndFeelCID, &mLookAndFeel);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_ERROR("LookAndFeel service must be implemented for this toolkit");
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2004-02-27 20:17:37 +03:00
|
|
|
mEventManager = new nsEventStateManager();
|
|
|
|
if (!mEventManager)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
2004-02-27 21:24:36 +03:00
|
|
|
NS_ADDREF(mEventManager);
|
|
|
|
|
2009-10-08 07:22:42 +04:00
|
|
|
mTransitionManager = new nsTransitionManager(this);
|
|
|
|
|
2004-04-30 08:06:30 +04:00
|
|
|
mLangService = do_GetService(NS_LANGUAGEATOMSERVICE_CONTRACTID);
|
|
|
|
|
|
|
|
// Register callbacks so we're notified when the preferences change
|
|
|
|
nsContentUtils::RegisterPrefCallback("font.",
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::PrefChangedCallback,
|
2004-04-30 08:06:30 +04:00
|
|
|
this);
|
|
|
|
nsContentUtils::RegisterPrefCallback("browser.display.",
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::PrefChangedCallback,
|
2004-04-30 08:06:30 +04:00
|
|
|
this);
|
|
|
|
nsContentUtils::RegisterPrefCallback("browser.underline_anchors",
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::PrefChangedCallback,
|
2004-04-30 08:06:30 +04:00
|
|
|
this);
|
|
|
|
nsContentUtils::RegisterPrefCallback("browser.anchor_color",
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::PrefChangedCallback,
|
2004-04-30 08:06:30 +04:00
|
|
|
this);
|
|
|
|
nsContentUtils::RegisterPrefCallback("browser.active_color",
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::PrefChangedCallback,
|
2004-04-30 08:06:30 +04:00
|
|
|
this);
|
|
|
|
nsContentUtils::RegisterPrefCallback("browser.visited_color",
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::PrefChangedCallback,
|
2004-04-30 08:06:30 +04:00
|
|
|
this);
|
|
|
|
nsContentUtils::RegisterPrefCallback("image.animation_mode",
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::PrefChangedCallback,
|
2004-04-30 08:06:30 +04:00
|
|
|
this);
|
|
|
|
#ifdef IBMBIDI
|
|
|
|
nsContentUtils::RegisterPrefCallback("bidi.", PrefChangedCallback,
|
|
|
|
this);
|
|
|
|
#endif
|
2007-02-15 12:04:25 +03:00
|
|
|
nsContentUtils::RegisterPrefCallback("layout.css.dpi",
|
|
|
|
nsPresContext::PrefChangedCallback,
|
|
|
|
this);
|
2009-05-18 02:09:53 +04:00
|
|
|
nsContentUtils::RegisterPrefCallback("layout.css.devPixelsPerPx",
|
|
|
|
nsPresContext::PrefChangedCallback,
|
|
|
|
this);
|
2004-04-30 08:06:30 +04:00
|
|
|
|
2004-02-27 20:17:37 +03:00
|
|
|
rv = mEventManager->Init();
|
|
|
|
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) {
|
2004-08-02 08:52:55 +04:00
|
|
|
PRBool isChrome = PR_FALSE;
|
|
|
|
PRBool isRes = PR_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
|
|
|
}
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
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) {
|
2004-06-09 03:53:59 +04:00
|
|
|
NS_IF_RELEASE(mLangGroup);
|
2004-08-10 01:19:15 +04:00
|
|
|
mLangGroup = mLangService->LookupCharSet(aCharSet.get()).get(); // addrefs
|
2004-06-21 14:32:27 +04:00
|
|
|
|
|
|
|
// bug 39570: moved from nsLanguageAtomService::LookupCharSet()
|
|
|
|
#if !defined(XP_BEOS)
|
2006-12-26 20:47:52 +03:00
|
|
|
if (mLangGroup == nsGkAtoms::Unicode) {
|
2004-06-21 14:32:27 +04:00
|
|
|
NS_RELEASE(mLangGroup);
|
|
|
|
NS_IF_ADDREF(mLangGroup = mLangService->GetLocaleLanguageGroup());
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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*
|
2006-11-30 02:09:13 +03:00
|
|
|
nsPresContext::RootPresContext()
|
|
|
|
{
|
|
|
|
nsPresContext* pc = this;
|
|
|
|
for (;;) {
|
|
|
|
if (pc->mShell) {
|
|
|
|
nsIFrame* rootFrame = pc->mShell->FrameManager()->GetRootFrame();
|
|
|
|
if (rootFrame) {
|
|
|
|
nsIFrame* f = nsLayoutUtils::GetCrossDocParentFrame(rootFrame);
|
|
|
|
if (f) {
|
2007-03-31 01:11:41 +04:00
|
|
|
pc = f->PresContext();
|
2006-11-30 02:09:13 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-07-22 04:44:54 +04:00
|
|
|
return static_cast<nsRootPresContext*>(pc);
|
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)
|
|
|
|
{
|
|
|
|
nsSMILAnimationController *controller = aDoc->GetAnimationController();
|
|
|
|
if (controller) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-09-03 04:28:37 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
nsPresContext::SMILOverrideStyleChanged(nsIContent* aContent)
|
|
|
|
{
|
|
|
|
mShell->FrameConstructor()->PostRestyleEvent(aContent, eReStyle_Self,
|
|
|
|
NS_STYLE_HINT_NONE);
|
|
|
|
}
|
2009-01-15 07:38:07 +03:00
|
|
|
#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) {
|
2003-10-22 10:09:48 +04:00
|
|
|
nsIContent *rootContent = doc->GetRootContent();
|
2001-11-14 14:21:54 +03:00
|
|
|
if (rootContent) {
|
|
|
|
SetImgAnimations(rootContent, aMode);
|
|
|
|
}
|
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-07-29 23:41:39 +04:00
|
|
|
already_AddRefed<nsIFontMetrics>
|
2009-01-17 06:44:21 +03:00
|
|
|
nsPresContext::GetMetricsFor(const nsFont& aFont, PRBool aUseUserFontSet)
|
2004-07-29 23:41:39 +04:00
|
|
|
{
|
1999-02-12 20:45:58 +03:00
|
|
|
nsIFontMetrics* metrics = nsnull;
|
2009-01-17 06:44:21 +03:00
|
|
|
mDeviceContext->GetMetricsFor(aFont, mLangGroup,
|
|
|
|
aUseUserFontSet ? GetUserFontSet() : nsnull,
|
|
|
|
metrics);
|
2004-07-29 23:41:39 +04:00
|
|
|
return metrics;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
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);
|
2007-08-08 00:38:35 +04:00
|
|
|
if (mDeviceContext->SetPixelScale(aZoom)) {
|
|
|
|
mDeviceContext->FlushFontCache();
|
|
|
|
}
|
2008-01-29 07:10:59 +03:00
|
|
|
|
|
|
|
NS_ASSERTION(mSupressResizeReflow == PR_FALSE, "two zooms happening at the same time? impossible!");
|
|
|
|
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()));
|
2008-12-29 18:07:36 +03:00
|
|
|
if (HasCachedStyleData()) {
|
|
|
|
MediaFeatureValuesChanged(PR_TRUE);
|
|
|
|
RebuildAllStyleData(NS_STYLE_HINT_REFLOW);
|
|
|
|
}
|
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
|
|
|
{
|
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
|
|
|
{
|
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 =
|
|
|
|
nsImageLoader::Create(aFrame, aStyleBorder->GetBorderImage(),
|
2009-09-13 02:44:18 +04:00
|
|
|
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);
|
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
|
|
|
PRBool
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::BidiEnabledInternal() const
|
2001-03-09 06:13:03 +03:00
|
|
|
{
|
2004-04-13 04:28:44 +04:00
|
|
|
PRBool bidiEnabled = PR_FALSE;
|
2004-08-01 03:15:21 +04:00
|
|
|
NS_ASSERTION(mShell, "PresShell must be set on PresContext before calling nsPresContext::GetBidiEnabled");
|
2001-03-09 06:13:03 +03:00
|
|
|
if (mShell) {
|
2004-08-02 08:52:55 +04:00
|
|
|
nsIDocument *doc = mShell->GetDocument();
|
2004-08-01 03:15:21 +04:00
|
|
|
NS_ASSERTION(doc, "PresShell has no document in nsPresContext::GetBidiEnabled");
|
2001-03-09 06:13:03 +03:00
|
|
|
if (doc) {
|
2004-04-13 04:28:44 +04:00
|
|
|
bidiEnabled = doc->GetBidiEnabled();
|
2001-03-09 06:13:03 +03:00
|
|
|
}
|
|
|
|
}
|
2004-04-13 04:28:44 +04:00
|
|
|
return bidiEnabled;
|
2001-03-09 06:13:03 +03:00
|
|
|
}
|
|
|
|
|
2004-07-29 23:41:39 +04:00
|
|
|
PRBool
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::BidiEnabledExternal() const
|
2004-07-29 23:41:39 +04:00
|
|
|
{
|
|
|
|
return BidiEnabledInternal();
|
|
|
|
}
|
|
|
|
|
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
|
|
|
nsBidiPresUtils*
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::GetBidiUtils()
|
2001-03-09 06:13:03 +03:00
|
|
|
{
|
2004-07-29 23:41:39 +04:00
|
|
|
if (!mBidiUtils)
|
2001-03-09 06:13:03 +03:00
|
|
|
mBidiUtils = new nsBidiPresUtils;
|
2004-07-29 23:41:39 +04:00
|
|
|
|
|
|
|
return mBidiUtils;
|
2001-03-09 06:13:03 +03:00
|
|
|
}
|
|
|
|
|
2004-07-29 23:41:39 +04:00
|
|
|
void
|
2008-01-09 12:38:28 +03:00
|
|
|
nsPresContext::SetBidi(PRUint32 aSource, PRBool 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
|
|
|
}
|
2008-01-09 12:38:28 +03:00
|
|
|
if (aForceRestyle) {
|
2008-02-08 22:52:46 +03:00
|
|
|
RebuildAllStyleData(NS_STYLE_HINT_REFLOW);
|
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
|
|
|
}
|
2001-03-09 06:13:03 +03:00
|
|
|
#endif //IBMBIDI
|
2000-03-21 18:51:59 +03:00
|
|
|
|
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 =
|
|
|
|
new nsRunnableMethod<nsPresContext>(this,
|
|
|
|
&nsPresContext::ThemeChangedInternal);
|
|
|
|
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
|
|
|
|
|
|
|
// Clear all cached nsILookAndFeel colors.
|
2006-09-12 08:36:03 +04:00
|
|
|
if (mLookAndFeel && sLookAndFeelChanged) {
|
2001-12-18 01:51:39 +03:00
|
|
|
mLookAndFeel->LookAndFeelChanged();
|
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 =
|
|
|
|
new nsRunnableMethod<nsPresContext>(this,
|
|
|
|
&nsPresContext::SysColorChangedInternal);
|
|
|
|
if (NS_SUCCEEDED(NS_DispatchToCurrentThread(ev))) {
|
|
|
|
mPendingSysColorChanged = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsPresContext::SysColorChangedInternal()
|
|
|
|
{
|
|
|
|
mPendingSysColorChanged = PR_FALSE;
|
|
|
|
|
|
|
|
if (mLookAndFeel && sLookAndFeelChanged) {
|
2002-06-04 21:47:54 +04:00
|
|
|
// Don't use the cached values for the system colors
|
|
|
|
mLookAndFeel->LookAndFeelChanged();
|
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();
|
|
|
|
|
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
|
|
|
|
nsPresContext::MediaFeatureValuesChanged(PRBool aCallerWillRebuildStyleData)
|
|
|
|
{
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsPresContext::PostMediaFeatureValuesChangedEvent()
|
|
|
|
{
|
|
|
|
if (!mPendingMediaFeatureValuesChanged) {
|
|
|
|
nsCOMPtr<nsIRunnable> ev =
|
|
|
|
new nsRunnableMethod<nsPresContext>(this,
|
|
|
|
&nsPresContext::HandleMediaFeatureValuesChangedEvent);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-07-29 23:41:39 +04:00
|
|
|
void
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::SetPaginatedScrolling(PRBool 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;
|
|
|
|
}
|
|
|
|
|
2005-01-20 06:39:09 +03:00
|
|
|
PRBool
|
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) {
|
|
|
|
nsCOMPtr<nsPresContext> currentPresContext;
|
|
|
|
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
|
|
|
|
|
|
|
PRBool
|
2007-11-16 06:46:42 +03:00
|
|
|
nsPresContext::IsChrome() const
|
2007-05-17 01:10:31 +04:00
|
|
|
{
|
|
|
|
PRBool isChrome = PR_FALSE;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return isChrome;
|
|
|
|
}
|
|
|
|
|
2007-10-09 03:11:01 +04:00
|
|
|
/* virtual */ PRBool
|
2008-04-26 03:12:45 +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
|
|
|
static void
|
2008-11-27 06:50:16 +03:00
|
|
|
InsertFontFaceRule(nsCSSFontFaceRule *aRule, gfxUserFontSet* aFontSet,
|
|
|
|
PRUint8 aSheetType)
|
2008-11-26 02:22:38 +03:00
|
|
|
{
|
|
|
|
PRInt32 type;
|
|
|
|
NS_ABORT_IF_FALSE(NS_SUCCEEDED(aRule->GetType(type))
|
|
|
|
&& type == nsICSSRule::FONT_FACE_RULE,
|
|
|
|
"InsertFontFaceRule passed a non-fontface CSS rule");
|
2008-12-05 08:01:37 +03:00
|
|
|
|
2008-11-26 02:22:38 +03:00
|
|
|
// aRule->List();
|
2008-12-05 08:01:37 +03:00
|
|
|
|
2008-11-26 02:22:38 +03:00
|
|
|
nsAutoString fontfamily;
|
|
|
|
nsCSSValue val;
|
2008-12-05 08:01:37 +03:00
|
|
|
|
2008-11-26 02:22:38 +03:00
|
|
|
PRUint32 unit;
|
|
|
|
PRUint32 weight = NS_STYLE_FONT_WEIGHT_NORMAL;
|
|
|
|
PRUint32 stretch = NS_STYLE_FONT_STRETCH_NORMAL;
|
|
|
|
PRUint32 italicStyle = FONT_STYLE_NORMAL;
|
2008-12-05 08:01:37 +03:00
|
|
|
|
2008-11-26 02:22:38 +03:00
|
|
|
// set up family name
|
|
|
|
aRule->GetDesc(eCSSFontDesc_Family, val);
|
|
|
|
unit = val.GetUnit();
|
|
|
|
if (unit == eCSSUnit_String) {
|
|
|
|
val.GetStringValue(fontfamily);
|
|
|
|
} else {
|
2008-12-05 08:01:37 +03:00
|
|
|
NS_ASSERTION(unit == eCSSUnit_Null,
|
|
|
|
"@font-face family name has unexpected unit");
|
|
|
|
// If there is no family name, this rule cannot contribute a
|
|
|
|
// usable font, so there is no point in processing it further.
|
2008-11-26 02:22:38 +03:00
|
|
|
return;
|
|
|
|
}
|
2008-12-05 08:01:37 +03:00
|
|
|
|
2008-11-26 02:22:38 +03:00
|
|
|
// set up weight
|
|
|
|
aRule->GetDesc(eCSSFontDesc_Weight, val);
|
|
|
|
unit = val.GetUnit();
|
2008-12-05 08:01:37 +03:00
|
|
|
if (unit == eCSSUnit_Integer || unit == eCSSUnit_Enumerated) {
|
|
|
|
weight = val.GetIntValue();
|
|
|
|
} else if (unit == eCSSUnit_Normal) {
|
|
|
|
weight = NS_STYLE_FONT_WEIGHT_NORMAL;
|
|
|
|
} else {
|
|
|
|
NS_ASSERTION(unit == eCSSUnit_Null,
|
|
|
|
"@font-face weight has unexpected unit");
|
2008-11-26 02:22:38 +03:00
|
|
|
}
|
2008-12-05 08:01:37 +03:00
|
|
|
|
2008-11-26 02:22:38 +03:00
|
|
|
// set up stretch
|
|
|
|
aRule->GetDesc(eCSSFontDesc_Stretch, val);
|
|
|
|
unit = val.GetUnit();
|
2008-12-05 08:01:37 +03:00
|
|
|
if (unit == eCSSUnit_Enumerated) {
|
|
|
|
stretch = val.GetIntValue();
|
|
|
|
} else if (unit == eCSSUnit_Normal) {
|
|
|
|
stretch = NS_STYLE_FONT_STRETCH_NORMAL;
|
|
|
|
} else {
|
|
|
|
NS_ASSERTION(unit == eCSSUnit_Null,
|
|
|
|
"@font-face stretch has unexpected unit");
|
2008-11-26 02:22:38 +03:00
|
|
|
}
|
2008-12-05 08:01:37 +03:00
|
|
|
|
2008-11-26 02:22:38 +03:00
|
|
|
// set up font style
|
|
|
|
aRule->GetDesc(eCSSFontDesc_Style, val);
|
2008-12-05 08:01:37 +03:00
|
|
|
unit = val.GetUnit();
|
|
|
|
if (unit == eCSSUnit_Enumerated) {
|
|
|
|
italicStyle = val.GetIntValue();
|
|
|
|
} else if (unit == eCSSUnit_Normal) {
|
|
|
|
italicStyle = FONT_STYLE_NORMAL;
|
|
|
|
} else {
|
|
|
|
NS_ASSERTION(unit == eCSSUnit_Null,
|
|
|
|
"@font-face style has unexpected unit");
|
2008-11-26 02:22:38 +03:00
|
|
|
}
|
2008-12-05 08:01:37 +03:00
|
|
|
|
2008-11-26 02:22:38 +03:00
|
|
|
// set up src array
|
|
|
|
nsTArray<gfxFontFaceSrc> srcArray;
|
|
|
|
|
|
|
|
aRule->GetDesc(eCSSFontDesc_Src, val);
|
|
|
|
unit = val.GetUnit();
|
|
|
|
if (unit == eCSSUnit_Array) {
|
|
|
|
nsCSSValue::Array *srcArr = val.GetArrayValue();
|
|
|
|
PRUint32 i, numSrc = srcArr->Count();
|
|
|
|
|
|
|
|
for (i = 0; i < numSrc; i++) {
|
|
|
|
val = srcArr->Item(i);
|
|
|
|
unit = val.GetUnit();
|
|
|
|
gfxFontFaceSrc *face = srcArray.AppendElements(1);
|
|
|
|
if (!face)
|
|
|
|
return;
|
|
|
|
|
|
|
|
switch (unit) {
|
|
|
|
|
|
|
|
case eCSSUnit_Local_Font:
|
|
|
|
val.GetStringValue(face->mLocalName);
|
|
|
|
face->mIsLocal = PR_TRUE;
|
|
|
|
face->mURI = nsnull;
|
|
|
|
face->mFormatFlags = 0;
|
|
|
|
break;
|
|
|
|
case eCSSUnit_URL:
|
|
|
|
face->mIsLocal = PR_FALSE;
|
|
|
|
face->mURI = val.GetURLValue();
|
|
|
|
NS_ASSERTION(face->mURI, "null url in @font-face rule");
|
|
|
|
face->mReferrer = val.GetURLStructValue()->mReferrer;
|
2008-11-27 06:50:16 +03:00
|
|
|
face->mOriginPrincipal = val.GetURLStructValue()->mOriginPrincipal;
|
|
|
|
NS_ASSERTION(face->mOriginPrincipal, "null origin principal in @font-face rule");
|
|
|
|
|
|
|
|
// agent and user stylesheets are treated slightly differently,
|
|
|
|
// the same-site origin check and access control headers are
|
|
|
|
// enforced against the sheet principal rather than the document
|
|
|
|
// principal to allow user stylesheets to include @font-face rules
|
|
|
|
face->mUseOriginPrincipal = (aSheetType == nsStyleSet::eUserSheet ||
|
|
|
|
aSheetType == nsStyleSet::eAgentSheet);
|
|
|
|
|
2008-11-26 02:22:38 +03:00
|
|
|
face->mLocalName.Truncate();
|
|
|
|
face->mFormatFlags = 0;
|
|
|
|
while (i + 1 < numSrc && (val = srcArr->Item(i+1),
|
|
|
|
val.GetUnit() == eCSSUnit_Font_Format)) {
|
|
|
|
nsDependentString valueString(val.GetStringBufferValue());
|
2009-09-17 15:03:12 +04:00
|
|
|
if (valueString.LowerCaseEqualsASCII("woff")) {
|
|
|
|
face->mFormatFlags |= gfxUserFontSet::FLAG_FORMAT_WOFF;
|
|
|
|
} else if (valueString.LowerCaseEqualsASCII("opentype")) {
|
2008-11-26 02:22:38 +03:00
|
|
|
face->mFormatFlags |= gfxUserFontSet::FLAG_FORMAT_OPENTYPE;
|
|
|
|
} else if (valueString.LowerCaseEqualsASCII("truetype")) {
|
|
|
|
face->mFormatFlags |= gfxUserFontSet::FLAG_FORMAT_TRUETYPE;
|
|
|
|
} else if (valueString.LowerCaseEqualsASCII("truetype-aat")) {
|
|
|
|
face->mFormatFlags |= gfxUserFontSet::FLAG_FORMAT_TRUETYPE_AAT;
|
|
|
|
} else if (valueString.LowerCaseEqualsASCII("embedded-opentype")) {
|
|
|
|
face->mFormatFlags |= gfxUserFontSet::FLAG_FORMAT_EOT;
|
|
|
|
} else if (valueString.LowerCaseEqualsASCII("svg")) {
|
|
|
|
face->mFormatFlags |= gfxUserFontSet::FLAG_FORMAT_SVG;
|
2009-01-13 08:16:58 +03:00
|
|
|
} else {
|
|
|
|
// unknown format specified, mark to distinguish from the
|
|
|
|
// case where no format hints are specified
|
|
|
|
face->mFormatFlags |= gfxUserFontSet::FLAG_FORMAT_UNKNOWN;
|
2008-11-26 02:22:38 +03:00
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NS_ASSERTION(unit == eCSSUnit_Local_Font || unit == eCSSUnit_URL,
|
|
|
|
"strange unit type in font-face src array");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-12-05 08:01:37 +03:00
|
|
|
} else {
|
|
|
|
NS_ASSERTION(unit == eCSSUnit_Null, "@font-face src has unexpected unit");
|
2008-11-26 02:22:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!fontfamily.IsEmpty() && srcArray.Length() > 0) {
|
|
|
|
aFontSet->AddFontFace(fontfamily, srcArray, weight, stretch, italicStyle);
|
|
|
|
}
|
2008-10-01 07:01:53 +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
|
|
|
|
PRBool userFontSetGottenBefore = mGetUserFontSetCalled;
|
|
|
|
#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.
|
|
|
|
#ifdef DEBUG
|
|
|
|
{
|
|
|
|
PRBool inReflow;
|
2009-01-28 03:31:26 +03:00
|
|
|
NS_ASSERTION(!userFontSetGottenBefore ||
|
2008-11-27 23:31:04 +03:00
|
|
|
(NS_SUCCEEDED(mShell->IsReflowLocked(&inReflow)) &&
|
|
|
|
!inReflow),
|
|
|
|
"FlushUserFontSet should have been called first");
|
|
|
|
}
|
|
|
|
#endif
|
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()
|
|
|
|
{
|
|
|
|
if (!mShell)
|
|
|
|
return; // we've been torn down
|
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-26 02:22:38 +03:00
|
|
|
nsRefPtr<gfxUserFontSet> oldUserFontSet = mUserFontSet;
|
|
|
|
|
2008-11-27 06:50:16 +03:00
|
|
|
nsTArray<nsFontFaceRuleContainer> rules;
|
2008-11-26 02:22:38 +03:00
|
|
|
if (!mShell->StyleSet()->AppendFontFaceRules(this, rules))
|
2008-11-26 02:22:38 +03:00
|
|
|
return;
|
2008-11-26 02:22:38 +03:00
|
|
|
|
2008-11-26 02:22:38 +03:00
|
|
|
PRBool differ;
|
|
|
|
if (rules.Length() == mFontFaceRules.Length()) {
|
|
|
|
differ = PR_FALSE;
|
2008-11-26 02:22:38 +03:00
|
|
|
for (PRUint32 i = 0, i_end = rules.Length(); i < i_end; ++i) {
|
2008-11-27 06:50:16 +03:00
|
|
|
if (rules[i].mRule != mFontFaceRules[i].mRule ||
|
|
|
|
rules[i].mSheetType != mFontFaceRules[i].mSheetType) {
|
2008-11-26 02:22:38 +03:00
|
|
|
differ = PR_TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
differ = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Only rebuild things if the set of @font-face rules is different.
|
|
|
|
if (differ) {
|
2009-01-19 12:21:29 +03:00
|
|
|
if (mUserFontSet) {
|
|
|
|
mUserFontSet->Destroy();
|
|
|
|
NS_RELEASE(mUserFontSet);
|
|
|
|
}
|
2008-11-26 02:22:38 +03:00
|
|
|
|
|
|
|
if (rules.Length() > 0) {
|
2009-01-19 12:21:29 +03:00
|
|
|
nsUserFontSet *fs = new nsUserFontSet(this);
|
2008-12-12 10:31:51 +03:00
|
|
|
if (!fs)
|
2008-11-26 02:22:38 +03:00
|
|
|
return;
|
|
|
|
mUserFontSet = fs;
|
|
|
|
NS_ADDREF(mUserFontSet);
|
|
|
|
|
|
|
|
for (PRUint32 i = 0, i_end = rules.Length(); i < i_end; ++i) {
|
2008-11-27 06:50:16 +03:00
|
|
|
InsertFontFaceRule(rules[i].mRule, fs, rules[i].mSheetType);
|
2008-11-26 02:22:38 +03:00
|
|
|
}
|
2008-11-26 02:22:38 +03:00
|
|
|
}
|
|
|
|
}
|
2008-11-26 02:22:38 +03:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
PRBool success =
|
|
|
|
#endif
|
|
|
|
rules.SwapElements(mFontFaceRules);
|
|
|
|
NS_ASSERTION(success, "should never fail given both are heap arrays");
|
|
|
|
|
|
|
|
if (mGetUserFontSetCalled && oldUserFontSet != mUserFontSet) {
|
|
|
|
// If we've changed, created, or destroyed a user font set, we
|
|
|
|
// need to trigger a style change reflow.
|
|
|
|
// We need to enqueue a style change reflow (for later) to
|
2008-12-08 19:08:05 +03:00
|
|
|
// reflect that we're dropping @font-face rules. (However,
|
|
|
|
// without a reflow, nothing will happen to start any downloads
|
|
|
|
// that are needed.)
|
|
|
|
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 =
|
|
|
|
new nsRunnableMethod<nsPresContext>(this,
|
|
|
|
&nsPresContext::HandleRebuildUserFontSet);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
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()) {
|
|
|
|
PRBool isCrossDocOnly = PR_TRUE;
|
|
|
|
for (PRUint32 i = 0; i < mInvalidateRequests.mRequests.Length(); ++i) {
|
|
|
|
if (!(mInvalidateRequests.mRequests[i].mFlags & nsIFrame::INVALIDATE_CROSS_DOC)) {
|
|
|
|
isCrossDocOnly = PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (isCrossDocOnly) {
|
|
|
|
// 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.)
|
|
|
|
dispatchTarget = do_QueryInterface(ourWindow->GetChromeEventHandler());
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2009-09-04 08:49:18 +04:00
|
|
|
static PRBool
|
|
|
|
MayHavePaintEventListener(nsPIDOMWindow* aInnerWindow)
|
2008-10-16 01:06:32 +04:00
|
|
|
{
|
|
|
|
if (!aInnerWindow)
|
|
|
|
return PR_FALSE;
|
|
|
|
if (aInnerWindow->HasPaintEventListeners())
|
|
|
|
return PR_TRUE;
|
|
|
|
|
|
|
|
nsPIDOMEventTarget* chromeEventHandler = aInnerWindow->GetChromeEventHandler();
|
|
|
|
if (!chromeEventHandler)
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsINode> node = do_QueryInterface(chromeEventHandler);
|
|
|
|
if (node)
|
|
|
|
return MayHavePaintEventListener(node->GetOwnerDoc()->GetInnerWindow());
|
|
|
|
|
|
|
|
nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(chromeEventHandler);
|
|
|
|
if (window)
|
|
|
|
return MayHavePaintEventListener(window);
|
|
|
|
|
2009-06-23 15:23:52 +04:00
|
|
|
nsIEventListenerManager* manager =
|
|
|
|
chromeEventHandler->GetListenerManager(PR_FALSE);
|
2009-03-21 22:29:29 +03:00
|
|
|
if (manager && manager->MayHavePaintEventListener())
|
|
|
|
return PR_TRUE;
|
|
|
|
|
2008-10-16 01:06:32 +04:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2009-09-04 08:49:18 +04:00
|
|
|
PRBool
|
|
|
|
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;
|
|
|
|
|
2009-01-06 04:15:13 +03:00
|
|
|
if (!IsDOMPaintEventPending()) {
|
2008-09-18 13:47:21 +04:00
|
|
|
// No event is pending. Dispatch one now.
|
|
|
|
nsCOMPtr<nsIRunnable> ev =
|
|
|
|
new nsRunnableMethod<nsPresContext>(this,
|
|
|
|
&nsPresContext::FireDOMPaintEvent);
|
|
|
|
NS_DispatchToCurrentThread(ev);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsPresContext::HasCachedStyleData()
|
|
|
|
{
|
|
|
|
return mShell && mShell->StyleSet()->HasCachedStyleData();
|
|
|
|
}
|
2009-04-22 03:53:52 +04:00
|
|
|
|
|
|
|
static PRBool sGotInterruptEnv = PR_FALSE;
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
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) {
|
|
|
|
nsIWidget* w = f->GetWindow();
|
|
|
|
if (w) {
|
|
|
|
return w->HasPendingInputEvent();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsPresContext::ReflowStarted(PRBool aInterruptible)
|
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
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
|
|
|
|
|
|
|
nsRootPresContext::nsRootPresContext(nsIDocument* aDocument,
|
|
|
|
nsPresContextType aType)
|
|
|
|
: nsPresContext(aDocument, aType)
|
|
|
|
{
|
2009-07-22 04:45:00 +04:00
|
|
|
mRegisteredPlugins.Init();
|
2009-07-22 04:44:54 +04:00
|
|
|
}
|
2009-07-22 04:45:00 +04:00
|
|
|
|
|
|
|
nsRootPresContext::~nsRootPresContext()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mRegisteredPlugins.Count() == 0,
|
|
|
|
"All plugins should have been unregistered");
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsRootPresContext::RegisterPluginForGeometryUpdates(nsObjectFrame* aPlugin)
|
|
|
|
{
|
|
|
|
mRegisteredPlugins.PutEntry(aPlugin);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsRootPresContext::UnregisterPluginForGeometryUpdates(nsObjectFrame* aPlugin)
|
|
|
|
{
|
|
|
|
mRegisteredPlugins.RemoveEntry(aPlugin);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct PluginGeometryClosure {
|
|
|
|
nsIFrame* mRootFrame;
|
|
|
|
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() +
|
|
|
|
f->GetParent()->GetOffsetTo(closure->mRootFrame);
|
|
|
|
// 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,
|
|
|
|
nsDisplayList* aList, PluginGeometryClosure* aClosure)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
if (entry) {
|
|
|
|
displayPlugin->GetWidgetConfiguration(aBuilder,
|
|
|
|
aClosure->mOutputConfigurations);
|
|
|
|
// we've dealt with this plugin now
|
|
|
|
aClosure->mAffectedPlugins.RawRemoveEntry(entry);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
nsDisplayList* sublist = i->GetList();
|
|
|
|
if (sublist) {
|
|
|
|
RecoverPluginGeometry(aBuilder, sublist, aClosure);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
static PRBool gDumpPluginList = PR_FALSE;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void
|
|
|
|
nsRootPresContext::GetPluginGeometryUpdates(nsIFrame* aChangedSubtree,
|
|
|
|
nsTArray<nsIWidget::Configuration>* aConfigurations)
|
|
|
|
{
|
|
|
|
if (mRegisteredPlugins.Count() == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
PluginGeometryClosure closure;
|
|
|
|
closure.mRootFrame = mShell->FrameManager()->GetRootFrame();
|
|
|
|
closure.mChangedSubtree = aChangedSubtree;
|
|
|
|
closure.mChangedRect = aChangedSubtree->GetOverflowRect() +
|
|
|
|
aChangedSubtree->GetOffsetTo(closure.mRootFrame);
|
|
|
|
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())) {
|
|
|
|
// It's OK to disable GetUsedX assertions because after a reflow,
|
|
|
|
// any changed geometry will cause UpdatePluginGeometry to happen
|
|
|
|
// again.
|
|
|
|
nsAutoDisableGetUsedXAssertions disableAssertions;
|
|
|
|
|
|
|
|
nsDisplayListBuilder builder(closure.mRootFrame, PR_FALSE, PR_FALSE);
|
|
|
|
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);
|
2009-10-07 08:28:41 +04:00
|
|
|
list.ComputeVisibility(&builder, &visibleRegion, nsnull);
|
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
|
|
|
|
|
|
|
|
RecoverPluginGeometry(&builder, &list, &closure);
|
|
|
|
list.DeleteAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Plugins that we didn't find in the display list are not visible
|
|
|
|
closure.mAffectedPlugins.EnumerateEntries(PluginHideEnumerator, &closure);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsRootPresContext::UpdatePluginGeometry(nsIFrame* aChangedSubtree)
|
|
|
|
{
|
|
|
|
nsTArray<nsIWidget::Configuration> configurations;
|
|
|
|
GetPluginGeometryUpdates(aChangedSubtree, &configurations);
|
|
|
|
if (configurations.IsEmpty())
|
|
|
|
return;
|
2009-09-30 02:18:20 +04:00
|
|
|
nsIWidget* widget = FrameManager()->GetRootFrame()->GetWindow();
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|