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