2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2006-03-30 09:56:38 +04:00
|
|
|
|
|
|
|
/* a presentation of a document, part 1 */
|
|
|
|
|
2012-12-15 03:58:45 +04:00
|
|
|
#include "mozilla/DebugOnly.h"
|
|
|
|
|
2012-09-05 20:23:45 +04:00
|
|
|
#include "base/basictypes.h"
|
|
|
|
|
2002-10-16 03:40:38 +04:00
|
|
|
#include "nsCOMPtr.h"
|
2004-08-01 03:15:21 +04:00
|
|
|
#include "nsPresContext.h"
|
1998-04-14 00:24:54 +04:00
|
|
|
#include "nsIPresShell.h"
|
2005-01-20 06:39:09 +03:00
|
|
|
#include "nsIDocShell.h"
|
|
|
|
#include "nsIContentViewer.h"
|
|
|
|
#include "nsPIDOMWindow.h"
|
2004-01-08 01:30:53 +03:00
|
|
|
#include "nsStyleSet.h"
|
2000-12-30 22:22:22 +03:00
|
|
|
#include "nsIContent.h"
|
1998-04-14 00:24:54 +04:00
|
|
|
#include "nsIFrame.h"
|
1998-09-05 07:52:40 +04:00
|
|
|
#include "nsIDocument.h"
|
2012-07-30 08:29:41 +04:00
|
|
|
#include "nsIPrintSettings.h"
|
|
|
|
#include "nsILanguageAtomService.h"
|
2011-09-09 06:27:13 +04:00
|
|
|
#include "mozilla/LookAndFeel.h"
|
2001-09-06 01:28:38 +04:00
|
|
|
#include "nsIInterfaceRequestorUtils.h"
|
2002-11-07 03:59:25 +03:00
|
|
|
#include "nsIWeakReferenceUtils.h"
|
2003-02-22 03:32:13 +03:00
|
|
|
#include "nsAutoPtr.h"
|
2004-02-27 20:17:37 +03:00
|
|
|
#include "nsEventStateManager.h"
|
2006-09-12 08:36:03 +04:00
|
|
|
#include "nsThreadUtils.h"
|
2006-11-30 02:09:13 +03:00
|
|
|
#include "nsFrameManager.h"
|
|
|
|
#include "nsLayoutUtils.h"
|
2013-01-05 07:12:24 +04:00
|
|
|
#include "nsViewManager.h"
|
2013-07-20 23:14:25 +04:00
|
|
|
#include "RestyleManager.h"
|
2008-08-06 00:02:43 +04:00
|
|
|
#include "nsCSSRuleProcessor.h"
|
2007-10-09 03:11:01 +04:00
|
|
|
#include "nsRuleNode.h"
|
2008-09-18 13:47:21 +04:00
|
|
|
#include "nsEventDispatcher.h"
|
2008-11-26 02:22:38 +03:00
|
|
|
#include "gfxPlatform.h"
|
|
|
|
#include "nsCSSRules.h"
|
|
|
|
#include "nsFontFaceLoader.h"
|
2011-06-24 06:18:01 +04:00
|
|
|
#include "nsEventListenerManager.h"
|
2009-04-22 03:53:52 +04:00
|
|
|
#include "prenv.h"
|
2009-07-22 04:45:00 +04:00
|
|
|
#include "nsObjectFrame.h"
|
2009-10-08 07:22:42 +04:00
|
|
|
#include "nsTransitionManager.h"
|
2011-04-12 10:18:44 +04:00
|
|
|
#include "nsAnimationManager.h"
|
2013-06-23 16:03:39 +04:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2010-05-05 22:18:05 +04:00
|
|
|
#include "mozilla/dom/Element.h"
|
2012-08-27 18:13:02 +04:00
|
|
|
#include "nsIMessageManager.h"
|
2011-04-22 07:17:31 +04:00
|
|
|
#include "nsDOMMediaQueryList.h"
|
2009-01-15 07:38:07 +03:00
|
|
|
#include "nsSMILAnimationController.h"
|
2012-08-14 02:04:19 +04:00
|
|
|
#include "mozilla/css/ImageLoader.h"
|
2012-09-05 20:23:45 +04:00
|
|
|
#include "mozilla/dom/TabChild.h"
|
2013-08-14 15:29:51 +04:00
|
|
|
#include "nsRefreshDriver.h"
|
2013-08-14 15:33:03 +04:00
|
|
|
#include "Layers.h"
|
2009-01-15 07:38:07 +03:00
|
|
|
|
2004-04-30 08:06:30 +04:00
|
|
|
#include "nsContentUtils.h"
|
2013-05-22 20:05:26 +04:00
|
|
|
#include "nsCxPusher.h"
|
2010-03-01 17:47:27 +03:00
|
|
|
#include "nsPIWindowRoot.h"
|
2011-05-25 10:31:59 +04:00
|
|
|
#include "mozilla/Preferences.h"
|
2004-04-30 08:06:30 +04:00
|
|
|
|
2001-11-14 14:21:54 +03:00
|
|
|
// Needed for Start/Stop of Image Animation
|
|
|
|
#include "imgIContainer.h"
|
2003-03-19 06:47:09 +03:00
|
|
|
#include "nsIImageLoadingContent.h"
|
2001-11-14 14:21:54 +03:00
|
|
|
|
2011-10-12 01:29:12 +04:00
|
|
|
#include "nsCSSParser.h"
|
|
|
|
|
2011-04-12 00:57:29 +04:00
|
|
|
using namespace mozilla;
|
2010-04-30 17:12:05 +04:00
|
|
|
using namespace mozilla::dom;
|
2012-11-10 19:45:52 +04:00
|
|
|
using namespace mozilla::layers;
|
2009-10-02 22:05:32 +04:00
|
|
|
|
2012-08-29 09:47:18 +04:00
|
|
|
uint8_t gNotifySubDocInvalidationData;
|
|
|
|
|
2013-08-14 15:33:03 +04:00
|
|
|
/**
|
|
|
|
* Layer UserData for ContainerLayers that want to be notified
|
|
|
|
* of local invalidations of them and their descendant layers.
|
|
|
|
* Pass a callback to ComputeDifferences to have these called.
|
|
|
|
*/
|
|
|
|
class ContainerLayerPresContext : public LayerUserData {
|
|
|
|
public:
|
|
|
|
nsPresContext* mPresContext;
|
|
|
|
};
|
|
|
|
|
2012-01-12 00:58:44 +04: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
|
|
|
|
|
2012-06-06 11:36:38 +04:00
|
|
|
nscolor
|
|
|
|
nsPresContext::MakeColorPref(const nsString& aColor)
|
2001-05-08 05:40:09 +04:00
|
|
|
{
|
2011-10-12 01:29:12 +04:00
|
|
|
nsCSSParser parser;
|
2012-06-06 11:36:38 +04:00
|
|
|
nsCSSValue value;
|
2012-07-30 18:20:58 +04:00
|
|
|
if (!parser.ParseColorString(aColor, nullptr, 0, value)) {
|
2011-10-12 01:29:12 +04:00
|
|
|
// Any better choices?
|
2012-06-06 11:36:38 +04:00
|
|
|
return NS_RGB(0, 0, 0);
|
2011-10-12 01:29:12 +04:00
|
|
|
}
|
2012-06-06 11:36:38 +04:00
|
|
|
|
|
|
|
nscolor color;
|
2012-07-30 18:20:58 +04:00
|
|
|
return nsRuleNode::ComputeColor(value, this, nullptr, color)
|
2012-06-06 11:36:38 +04:00
|
|
|
? color
|
|
|
|
: NS_RGB(0, 0, 0);
|
2001-05-08 05:40:09 +04:00
|
|
|
}
|
|
|
|
|
2012-08-29 09:47:18 +04:00
|
|
|
bool
|
|
|
|
nsPresContext::IsDOMPaintEventPending()
|
|
|
|
{
|
2012-10-19 08:50:34 +04:00
|
|
|
if (mFireAfterPaintEvents) {
|
|
|
|
return true;
|
2012-08-29 09:47:18 +04:00
|
|
|
}
|
|
|
|
if (GetDisplayRootPresContext()->GetRootPresContext()->mRefreshDriver->ViewManagerFlushIsPending()) {
|
|
|
|
// Since we're promising that there will be a MozAfterPaint event
|
|
|
|
// fired, we record an empty invalidation in case display list
|
|
|
|
// invalidation doesn't invalidate anything further.
|
|
|
|
NotifyInvalidation(nsRect(0, 0, 0, 0), 0);
|
2012-10-19 08:50:34 +04:00
|
|
|
NS_ASSERTION(mFireAfterPaintEvents, "Why aren't we planning to fire the event?");
|
2012-08-29 09:47:18 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-10-10 19:04:34 +04:00
|
|
|
int
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::PrefChangedCallback(const char* aPrefName, void* instance_data)
|
2002-12-11 08:11:02 +03:00
|
|
|
{
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext* presContext = (nsPresContext*)instance_data;
|
2002-12-11 08:11:02 +03:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_ASSERTION(nullptr != presContext, "bad instance data");
|
|
|
|
if (nullptr != presContext) {
|
2002-12-11 08:11:02 +03:00
|
|
|
presContext->PreferenceChanged(aPrefName);
|
|
|
|
}
|
|
|
|
return 0; // PREF_OK
|
|
|
|
}
|
|
|
|
|
2005-08-24 03:52:16 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
nsPresContext::PrefChangedUpdateTimerCallback(nsITimer *aTimer, void *aClosure)
|
|
|
|
{
|
|
|
|
nsPresContext* presContext = (nsPresContext*)aClosure;
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_ASSERTION(presContext != nullptr, "bad instance data");
|
2005-08-24 03:52:16 +04:00
|
|
|
if (presContext)
|
|
|
|
presContext->UpdateAfterPreferencesChanged();
|
|
|
|
}
|
|
|
|
|
2001-03-09 06:13:03 +03:00
|
|
|
#ifdef IBMBIDI
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool
|
2004-07-29 23:41:39 +04:00
|
|
|
IsVisualCharset(const nsCString& aCharset)
|
2001-03-09 06:13:03 +03:00
|
|
|
{
|
2012-10-10 14:32:37 +04:00
|
|
|
if (aCharset.LowerCaseEqualsLiteral("ibm862") // Hebrew
|
2004-06-17 04:13:25 +04:00
|
|
|
|| aCharset.LowerCaseEqualsLiteral("iso-8859-8") ) { // Hebrew
|
2011-10-17 18:59:28 +04:00
|
|
|
return true; // visual text type
|
2001-03-09 06:13:03 +03:00
|
|
|
}
|
|
|
|
else {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false; // logical text type
|
2001-03-09 06:13:03 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif // IBMBIDI
|
|
|
|
|
2004-08-01 03:15:21 +04:00
|
|
|
// NOTE! nsPresContext::operator new() zeroes out all members, so don't
|
2004-04-30 08:06:30 +04:00
|
|
|
// bother initializing members to 0.
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2006-05-19 14:26:44 +04:00
|
|
|
nsPresContext::nsPresContext(nsIDocument* aDocument, nsPresContextType aType)
|
2011-05-24 14:36:21 +04:00
|
|
|
: mType(aType), mDocument(aDocument), mMinFontSize(0),
|
2012-05-05 17:25:45 +04:00
|
|
|
mTextZoom(1.0), mFullZoom(1.0), mLastFontInflationScreenWidth(-1.0),
|
|
|
|
mPageSize(-1, -1), mPPScale(1.0f),
|
2004-09-05 04:04:04 +04:00
|
|
|
mViewportStyleOverflow(NS_STYLE_OVERFLOW_AUTO, NS_STYLE_OVERFLOW_AUTO),
|
2012-08-29 09:48:44 +04:00
|
|
|
mImageAnimationModePref(imgIContainer::kNormalAnimMode),
|
2013-07-22 19:51:38 +04:00
|
|
|
mAllInvalidated(false),
|
|
|
|
mPaintFlashing(false), mPaintFlashingInitialized(false)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2004-08-01 03:15:21 +04:00
|
|
|
// NOTE! nsPresContext::operator new() zeroes out all members, so don't
|
2004-04-30 08:06:30 +04:00
|
|
|
// bother initializing members to 0.
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mDoScaledTwips = true;
|
2000-09-21 05:20:00 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
SetBackgroundImageDraw(true); // always draw the background
|
|
|
|
SetBackgroundColorDraw(true);
|
2001-12-11 08:57:37 +03:00
|
|
|
|
2004-02-01 01:41:40 +03:00
|
|
|
mBackgroundColor = NS_RGB(0xFF, 0xFF, 0xFF);
|
2000-10-11 12:33:01 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mUseDocumentColors = true;
|
|
|
|
mUseDocumentFonts = true;
|
2000-10-11 12:33:01 +04:00
|
|
|
|
2001-09-27 22:34:30 +04:00
|
|
|
// the minimum font-size is unconstrained by default
|
|
|
|
|
2003-10-15 05:56:12 +04:00
|
|
|
mLinkColor = NS_RGB(0x00, 0x00, 0xEE);
|
|
|
|
mActiveLinkColor = NS_RGB(0xEE, 0x00, 0x00);
|
|
|
|
mVisitedLinkColor = NS_RGB(0x55, 0x1A, 0x8B);
|
2011-10-17 18:59:28 +04:00
|
|
|
mUnderlineLinks = true;
|
|
|
|
mSendAfterPaintToContent = false;
|
2000-10-11 12:33:01 +04:00
|
|
|
|
2001-04-10 02:17:11 +04:00
|
|
|
mFocusTextColor = mDefaultColor;
|
2004-02-01 01:41:40 +03:00
|
|
|
mFocusBackgroundColor = mBackgroundColor;
|
2001-04-10 02:17:11 +04:00
|
|
|
mFocusRingWidth = 1;
|
|
|
|
|
2011-06-01 15:43:31 +04:00
|
|
|
mBodyTextColor = mDefaultColor;
|
|
|
|
|
2004-07-29 23:41:39 +04:00
|
|
|
if (aType == eContext_Galley) {
|
2006-12-26 20:47:52 +03:00
|
|
|
mMedium = nsGkAtoms::screen;
|
2004-07-29 23:41:39 +04:00
|
|
|
} else {
|
2006-12-26 20:47:52 +03:00
|
|
|
mMedium = nsGkAtoms::print;
|
2011-10-17 18:59:28 +04:00
|
|
|
mPaginated = true;
|
2004-07-29 23:41:39 +04:00
|
|
|
}
|
2013-07-17 19:39:19 +04:00
|
|
|
mMediaEmulated = mMedium;
|
2006-04-01 05:19:28 +04:00
|
|
|
|
|
|
|
if (!IsDynamic()) {
|
|
|
|
mImageAnimationMode = imgIContainer::kDontAnimMode;
|
2011-10-17 18:59:28 +04:00
|
|
|
mNeverAnimate = true;
|
2006-04-01 05:19:28 +04:00
|
|
|
} else {
|
|
|
|
mImageAnimationMode = imgIContainer::kNormalAnimMode;
|
2011-10-17 18:59:28 +04:00
|
|
|
mNeverAnimate = false;
|
2006-04-01 05:19:28 +04:00
|
|
|
}
|
2006-05-19 14:26:44 +04:00
|
|
|
NS_ASSERTION(mDocument, "Null document");
|
2012-07-30 18:20:58 +04:00
|
|
|
mUserFontSet = nullptr;
|
2011-10-17 18:59:28 +04:00
|
|
|
mUserFontSetDirty = true;
|
2011-04-22 07:17:31 +04:00
|
|
|
|
|
|
|
PR_INIT_CLIST(&mDOMMediaQueryLists);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::~nsPresContext()
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2003-04-25 02:44:48 +04:00
|
|
|
NS_PRECONDITION(!mShell, "Presshell forgot to clear our mShell pointer");
|
2012-07-30 18:20:58 +04:00
|
|
|
SetShell(nullptr);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2011-04-22 07:17:31 +04:00
|
|
|
NS_ABORT_IF_FALSE(PR_CLIST_IS_EMPTY(&mDOMMediaQueryLists),
|
|
|
|
"must not have media query lists left");
|
|
|
|
|
2009-12-23 22:10:30 +03:00
|
|
|
// Disconnect the refresh driver *after* the transition manager, which
|
|
|
|
// needs it.
|
2010-08-12 01:05:27 +04:00
|
|
|
if (mRefreshDriver && mRefreshDriver->PresContext() == this) {
|
2009-12-23 22:10:30 +03:00
|
|
|
mRefreshDriver->Disconnect();
|
|
|
|
}
|
|
|
|
|
2003-06-19 22:16:53 +04:00
|
|
|
if (mEventManager) {
|
2006-04-11 20:37:58 +04:00
|
|
|
// unclear if these are needed, but can't hurt
|
|
|
|
mEventManager->NotifyDestroyPresContext(this);
|
2012-07-30 18:20:58 +04:00
|
|
|
mEventManager->SetPresContext(nullptr);
|
2003-06-19 22:16:53 +04:00
|
|
|
}
|
1998-11-18 08:25:26 +03:00
|
|
|
|
2005-08-24 03:52:16 +04:00
|
|
|
if (mPrefChangedTimer)
|
|
|
|
{
|
|
|
|
mPrefChangedTimer->Cancel();
|
2012-07-30 18:20:58 +04:00
|
|
|
mPrefChangedTimer = nullptr;
|
2005-08-24 03:52:16 +04:00
|
|
|
}
|
|
|
|
|
2002-12-11 08:11:02 +03:00
|
|
|
// Unregister preference callbacks
|
2011-05-29 03:42:57 +04:00
|
|
|
Preferences::UnregisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"font.",
|
|
|
|
this);
|
|
|
|
Preferences::UnregisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"browser.display.",
|
|
|
|
this);
|
|
|
|
Preferences::UnregisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"browser.underline_anchors",
|
|
|
|
this);
|
|
|
|
Preferences::UnregisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"browser.anchor_color",
|
|
|
|
this);
|
|
|
|
Preferences::UnregisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"browser.active_color",
|
|
|
|
this);
|
|
|
|
Preferences::UnregisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"browser.visited_color",
|
|
|
|
this);
|
|
|
|
Preferences::UnregisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"image.animation_mode",
|
|
|
|
this);
|
2004-04-30 07:10:29 +04:00
|
|
|
#ifdef IBMBIDI
|
2011-05-29 03:42:57 +04:00
|
|
|
Preferences::UnregisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"bidi.",
|
|
|
|
this);
|
2001-03-09 06:13:03 +03:00
|
|
|
#endif // IBMBIDI
|
2011-05-29 03:42:57 +04:00
|
|
|
Preferences::UnregisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"dom.send_after_paint_to_content",
|
|
|
|
this);
|
|
|
|
Preferences::UnregisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"gfx.font_rendering.",
|
|
|
|
this);
|
|
|
|
Preferences::UnregisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"layout.css.dpi",
|
|
|
|
this);
|
|
|
|
Preferences::UnregisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"layout.css.devPixelsPerPx",
|
|
|
|
this);
|
2013-07-22 19:51:38 +04:00
|
|
|
Preferences::UnregisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"nglayout.debug.paint_flashing",
|
|
|
|
this);
|
|
|
|
Preferences::UnregisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"nglayout.debug.paint_flashing_chrome",
|
|
|
|
this);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2007-08-11 01:25:24 +04:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsPresContext)
|
2010-03-25 16:17:11 +03:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
2007-08-11 01:25:24 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIObserver)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsPresContext)
|
2013-07-09 21:30:58 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE_WITH_LAST_RELEASE(nsPresContext, LastRelease())
|
|
|
|
|
|
|
|
void
|
|
|
|
nsPresContext::LastRelease()
|
|
|
|
{
|
|
|
|
if (IsRoot()) {
|
|
|
|
static_cast<nsRootPresContext*>(this)->CancelDidPaintTimer();
|
|
|
|
}
|
|
|
|
}
|
2007-08-11 01:25:24 +04:00
|
|
|
|
2013-08-02 05:29:05 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(nsPresContext)
|
|
|
|
|
2007-08-11 01:25:24 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsPresContext)
|
2012-11-15 11:32:40 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDocument);
|
2011-04-17 05:22:42 +04:00
|
|
|
// NS_IMPL_CYCLE_COLLECTION_TRAVERSE_RAWPTR(mDeviceContext); // not xpcom
|
2012-11-15 11:32:40 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mEventManager);
|
2010-02-24 20:57:44 +03:00
|
|
|
// NS_IMPL_CYCLE_COLLECTION_TRAVERSE_RAWPTR(mLanguage); // an atom
|
2007-08-11 01:25:24 +04:00
|
|
|
|
2012-03-01 08:47:55 +04: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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-15 11:32:40 +04:00
|
|
|
// NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mTheme); // a service
|
|
|
|
// NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mLangService); // a service
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mPrintSettings);
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mPrefChangedTimer);
|
2007-08-11 01:25:24 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsPresContext)
|
2012-11-15 11:32:40 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mDocument);
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mDeviceContext); // worth bothering?
|
2007-08-11 01:25:24 +04:00
|
|
|
if (tmp->mEventManager) {
|
|
|
|
// unclear if these are needed, but can't hurt
|
|
|
|
tmp->mEventManager->NotifyDestroyPresContext(tmp);
|
2012-07-30 18:20:58 +04:00
|
|
|
tmp->mEventManager->SetPresContext(nullptr);
|
2012-07-30 18:28:15 +04:00
|
|
|
tmp->mEventManager = nullptr;
|
2007-08-11 01:25:24 +04:00
|
|
|
}
|
|
|
|
|
2012-03-01 08:47:55 +04: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 20:57:44 +03:00
|
|
|
// NS_RELEASE(tmp->mLanguage); // an atom
|
2007-08-11 01:25:24 +04:00
|
|
|
|
2012-11-15 11:32:40 +04:00
|
|
|
// NS_IMPL_CYCLE_COLLECTION_UNLINK(mTheme); // a service
|
|
|
|
// NS_IMPL_CYCLE_COLLECTION_UNLINK(mLangService); // a service
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mPrintSettings);
|
2007-08-11 01:25:24 +04:00
|
|
|
if (tmp->mPrefChangedTimer)
|
|
|
|
{
|
|
|
|
tmp->mPrefChangedTimer->Cancel();
|
2012-07-30 18:20:58 +04:00
|
|
|
tmp->mPrefChangedTimer = nullptr;
|
2007-08-11 01:25:24 +04:00
|
|
|
}
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2001-09-27 22:34:30 +04:00
|
|
|
#define MAKE_FONT_PREF_KEY(_pref, _s0, _s1) \
|
|
|
|
_pref.Assign(_s0); \
|
|
|
|
_pref.Append(_s1);
|
|
|
|
|
|
|
|
static const char* const kGenericFont[] = {
|
|
|
|
".variable.",
|
|
|
|
".fixed.",
|
|
|
|
".serif.",
|
|
|
|
".sans-serif.",
|
|
|
|
".monospace.",
|
|
|
|
".cursive.",
|
|
|
|
".fantasy."
|
|
|
|
};
|
|
|
|
|
2009-02-26 23:02:00 +03:00
|
|
|
// whether no native theme service exists;
|
|
|
|
// if this gets set to true, we'll stop asking for it.
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool sNoTheme = false;
|
2009-02-26 23:02:00 +03:00
|
|
|
|
2006-09-12 08:36:03 +04:00
|
|
|
// Set to true when LookAndFeelChanged needs to be called. This is used
|
|
|
|
// because the look and feel is a service, so there's no need to notify it from
|
|
|
|
// more than one prescontext.
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool sLookAndFeelChanged;
|
2006-09-12 08:36:03 +04:00
|
|
|
|
|
|
|
// Set to true when ThemeChanged needs to be called on mTheme. This is used
|
|
|
|
// because mTheme is a service, so there's no need to notify it from more than
|
|
|
|
// one prescontext.
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool sThemeChanged;
|
2006-09-12 08:36:03 +04:00
|
|
|
|
2012-01-26 03:52:26 +04:00
|
|
|
const nsPresContext::LangGroupFontPrefs*
|
|
|
|
nsPresContext::GetFontPrefsForLang(nsIAtom *aLanguage) const
|
2000-01-12 19:10:48 +03:00
|
|
|
{
|
2012-01-26 03:52:26 +04:00
|
|
|
// Get language group for aLanguage:
|
|
|
|
|
2012-11-21 00:59:36 +04:00
|
|
|
nsresult rv = NS_OK;
|
2012-07-30 18:20:58 +04:00
|
|
|
nsIAtom *langGroupAtom = nullptr;
|
2012-01-26 03:52:26 +04:00
|
|
|
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
|
2012-08-22 19:56:38 +04:00
|
|
|
DebugOnly<uint32_t> count = 0;
|
2012-01-26 03:52:26 +04:00
|
|
|
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 22:34:30 +04:00
|
|
|
/* Fetch the font prefs to be used -- see bug 61883 for details.
|
|
|
|
Not all prefs are needed upfront. Some are fallback prefs intended
|
|
|
|
for the GFX font sub-system...
|
|
|
|
|
|
|
|
1) unit : assumed to be the same for all language groups -------------
|
|
|
|
font.size.unit = px | pt XXX could be folded in the size... bug 90440
|
|
|
|
|
|
|
|
2) attributes for generic fonts --------------------------------------
|
2012-01-26 03:52:26 +04:00
|
|
|
font.default.[langGroup] = serif | sans-serif - fallback generic font
|
2001-09-27 22:34:30 +04: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
|
|
|
|
*/
|
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString langGroup;
|
2012-01-26 03:52:26 +04:00
|
|
|
langGroupAtom->ToUTF8String(langGroup);
|
|
|
|
|
|
|
|
prefs->mDefaultVariableFont.size = CSSPixelsToAppUnits(16);
|
|
|
|
prefs->mDefaultFixedFont.size = CSSPixelsToAppUnits(13);
|
2001-09-27 22:34:30 +04:00
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString pref;
|
2001-09-27 22:34:30 +04:00
|
|
|
|
|
|
|
// get the current applicable font-size unit
|
|
|
|
enum {eUnit_unknown = -1, eUnit_px, eUnit_pt};
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t unit = eUnit_px;
|
2004-04-30 08:06:30 +04:00
|
|
|
|
|
|
|
nsAdoptingCString cvalue =
|
2011-05-28 11:03:00 +04:00
|
|
|
Preferences::GetCString("font.size.unit");
|
2004-04-30 08:06:30 +04:00
|
|
|
|
|
|
|
if (!cvalue.IsEmpty()) {
|
|
|
|
if (cvalue.Equals("px")) {
|
2001-09-27 22:34:30 +04:00
|
|
|
unit = eUnit_px;
|
2000-01-12 19:10:48 +03:00
|
|
|
}
|
2004-04-30 08:06:30 +04:00
|
|
|
else if (cvalue.Equals("pt")) {
|
2001-09-27 22:34:30 +04:00
|
|
|
unit = eUnit_pt;
|
|
|
|
}
|
|
|
|
else {
|
2012-01-26 03:52:26 +04:00
|
|
|
// XXX should really send this warning to the user (Error Console?).
|
|
|
|
// And just default to unit = eUnit_px?
|
2001-09-27 22:34:30 +04:00
|
|
|
NS_WARNING("unexpected font-size unit -- expected: 'px' or 'pt'");
|
|
|
|
unit = eUnit_unknown;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// get font.minimum-size.[langGroup]
|
2003-06-24 05:46:50 +04:00
|
|
|
|
2012-01-26 03:52:26 +04:00
|
|
|
MAKE_FONT_PREF_KEY(pref, "font.minimum-size.", langGroup);
|
2003-06-24 05:46:50 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t size = Preferences::GetInt(pref.get());
|
2006-08-08 20:43:20 +04:00
|
|
|
if (unit == eUnit_px) {
|
2012-01-26 03:52:26 +04:00
|
|
|
prefs->mMinimumFontSize = CSSPixelsToAppUnits(size);
|
2006-08-08 20:43:20 +04:00
|
|
|
}
|
|
|
|
else if (unit == eUnit_pt) {
|
2012-01-26 03:52:26 +04:00
|
|
|
prefs->mMinimumFontSize = CSSPointsToAppUnits(size);
|
2001-09-27 22:34:30 +04:00
|
|
|
}
|
|
|
|
|
2011-12-20 07:46:39 +04:00
|
|
|
nsFont* fontTypes[] = {
|
2012-01-26 03:52:26 +04:00
|
|
|
&prefs->mDefaultVariableFont,
|
|
|
|
&prefs->mDefaultFixedFont,
|
|
|
|
&prefs->mDefaultSerifFont,
|
|
|
|
&prefs->mDefaultSansSerifFont,
|
|
|
|
&prefs->mDefaultMonospaceFont,
|
|
|
|
&prefs->mDefaultCursiveFont,
|
|
|
|
&prefs->mDefaultFantasyFont
|
2011-12-20 07:46:39 +04:00
|
|
|
};
|
2013-07-18 21:59:53 +04:00
|
|
|
static_assert(NS_ARRAY_LENGTH(fontTypes) == eDefaultFont_COUNT,
|
|
|
|
"FontTypes array count is not correct");
|
2011-12-20 07:46:39 +04:00
|
|
|
|
2012-01-26 03:52:26 +04: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.
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString generic_dot_langGroup;
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t eType = 0; eType < ArrayLength(fontTypes); ++eType) {
|
2001-09-27 22:34:30 +04:00
|
|
|
generic_dot_langGroup.Assign(kGenericFont[eType]);
|
2004-06-09 03:53:59 +04:00
|
|
|
generic_dot_langGroup.Append(langGroup);
|
2001-09-27 22:34:30 +04:00
|
|
|
|
2011-12-20 07:46:39 +04:00
|
|
|
nsFont* font = fontTypes[eType];
|
2001-09-27 22:34:30 +04: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-26 03:52:26 +04:00
|
|
|
MAKE_FONT_PREF_KEY(pref, "font.name.variable.", langGroup);
|
2004-04-30 08:06:30 +04:00
|
|
|
|
2011-05-28 11:03:00 +04:00
|
|
|
nsAdoptingString value = Preferences::GetString(pref.get());
|
2004-04-30 08:06:30 +04:00
|
|
|
if (!value.IsEmpty()) {
|
2012-01-26 03:52:26 +04:00
|
|
|
prefs->mDefaultVariableFont.name.Assign(value);
|
2000-01-15 19:30:13 +03:00
|
|
|
}
|
2001-09-27 22:34:30 +04:00
|
|
|
else {
|
2005-01-24 02:58:32 +03:00
|
|
|
MAKE_FONT_PREF_KEY(pref, "font.default.", langGroup);
|
2011-05-28 11:03:00 +04:00
|
|
|
value = Preferences::GetString(pref.get());
|
2004-04-30 08:06:30 +04:00
|
|
|
if (!value.IsEmpty()) {
|
2012-01-26 03:52:26 +04:00
|
|
|
prefs->mDefaultVariableFont.name.Assign(value);
|
2001-09-27 22:34:30 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (eType == eDefaultFont_Monospace) {
|
|
|
|
// This takes care of the confusion whereby people often expect "monospace"
|
|
|
|
// to have the same default font-size as "-moz-fixed" (this tentative
|
|
|
|
// size may be overwritten with the specific value for "monospace" when
|
|
|
|
// "font.size.monospace.[langGroup]" is read -- see below)
|
2012-01-26 03:52:26 +04:00
|
|
|
prefs->mDefaultMonospaceFont.size = prefs->mDefaultFixedFont.size;
|
2000-01-15 19:30:13 +03:00
|
|
|
}
|
2001-09-27 22:34:30 +04:00
|
|
|
else if (eType != eDefaultFont_Fixed) {
|
|
|
|
// all the other generic fonts are initialized with the size of the
|
|
|
|
// variable font, but their specific size can supersede later -- see below
|
2012-01-26 03:52:26 +04:00
|
|
|
font->size = prefs->mDefaultVariableFont.size;
|
2000-01-15 19:30:13 +03:00
|
|
|
}
|
2001-09-27 22:34:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Bug 84398: for spec purists, a different font-size only applies to the
|
|
|
|
// .variable. and .fixed. fonts and the other fonts should get |font-size-adjust|.
|
|
|
|
// The problem is that only GfxWin has the support for |font-size-adjust|. So for
|
|
|
|
// parity, we enable the ability to set a different font-size on all platforms.
|
|
|
|
|
|
|
|
// get font.size.[generic].[langGroup]
|
|
|
|
// size=0 means 'Auto', i.e., generic fonts retain the size of the variable font
|
|
|
|
MAKE_FONT_PREF_KEY(pref, "font.size", generic_dot_langGroup);
|
2011-05-25 10:32:00 +04:00
|
|
|
size = Preferences::GetInt(pref.get());
|
2004-04-30 08:06:30 +04:00
|
|
|
if (size > 0) {
|
2001-09-27 22:34:30 +04:00
|
|
|
if (unit == eUnit_px) {
|
2010-08-13 13:58:04 +04:00
|
|
|
font->size = CSSPixelsToAppUnits(size);
|
2000-01-15 19:30:13 +03:00
|
|
|
}
|
2001-09-27 22:34:30 +04:00
|
|
|
else if (unit == eUnit_pt) {
|
2010-08-13 13:58:04 +04:00
|
|
|
font->size = CSSPointsToAppUnits(size);
|
2000-01-15 19:30:13 +03:00
|
|
|
}
|
2000-01-12 19:10:48 +03:00
|
|
|
}
|
2001-09-27 22:34:30 +04:00
|
|
|
|
|
|
|
// get font.size-adjust.[generic].[langGroup]
|
|
|
|
// XXX only applicable on GFX ports that handle |font-size-adjust|
|
|
|
|
MAKE_FONT_PREF_KEY(pref, "font.size-adjust", generic_dot_langGroup);
|
2011-05-28 11:03:00 +04:00
|
|
|
cvalue = Preferences::GetCString(pref.get());
|
2004-04-30 08:06:30 +04:00
|
|
|
if (!cvalue.IsEmpty()) {
|
2001-09-27 22:34:30 +04:00
|
|
|
font->sizeAdjust = (float)atof(cvalue.get());
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG_rbs
|
|
|
|
printf("%s Family-list:%s size:%d sizeAdjust:%.2f\n",
|
2004-04-30 08:06:30 +04:00
|
|
|
generic_dot_langGroup.get(),
|
2006-02-03 17:18:39 +03:00
|
|
|
NS_ConvertUTF16toUTF8(font->name).get(), font->size,
|
2003-06-24 05:46:50 +04:00
|
|
|
font->sizeAdjust);
|
2001-09-27 22:34:30 +04:00
|
|
|
#endif
|
2000-01-12 19:10:48 +03:00
|
|
|
}
|
2012-01-26 03:52:26 +04:00
|
|
|
|
|
|
|
return prefs;
|
2000-01-12 19:10:48 +03:00
|
|
|
}
|
|
|
|
|
2001-10-17 03:59:25 +04:00
|
|
|
void
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::GetDocumentColorPreferences()
|
2001-10-17 03:59:25 +04:00
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t useAccessibilityTheme = 0;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool usePrefColors = true;
|
2002-11-07 03:59:25 +03:00
|
|
|
nsCOMPtr<nsIDocShellTreeItem> docShell(do_QueryReferent(mContainer));
|
2001-10-17 03:59:25 +04:00
|
|
|
if (docShell) {
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t docShellType;
|
2001-10-17 03:59:25 +04:00
|
|
|
docShell->GetItemType(&docShellType);
|
2004-06-08 23:34:55 +04:00
|
|
|
if (nsIDocShellTreeItem::typeChrome == docShellType) {
|
2011-10-17 18:59:28 +04:00
|
|
|
usePrefColors = false;
|
2004-06-08 23:34:55 +04:00
|
|
|
}
|
|
|
|
else {
|
2011-09-09 06:27:13 +04:00
|
|
|
useAccessibilityTheme =
|
|
|
|
LookAndFeel::GetInt(LookAndFeel::eIntID_UseAccessibilityTheme, 0);
|
2004-06-08 23:34:55 +04:00
|
|
|
usePrefColors = !useAccessibilityTheme;
|
|
|
|
}
|
|
|
|
|
2001-10-17 03:59:25 +04:00
|
|
|
}
|
|
|
|
if (usePrefColors) {
|
2004-04-30 08:06:30 +04:00
|
|
|
usePrefColors =
|
2011-09-29 10:19:26 +04:00
|
|
|
!Preferences::GetBool("browser.display.use_system_colors", false);
|
2001-10-17 03:59:25 +04:00
|
|
|
}
|
2004-04-30 08:06:30 +04:00
|
|
|
|
2001-10-17 03:59:25 +04:00
|
|
|
if (usePrefColors) {
|
2011-10-12 01:29:12 +04:00
|
|
|
nsAdoptingString colorStr =
|
|
|
|
Preferences::GetString("browser.display.foreground_color");
|
2004-04-30 08:06:30 +04:00
|
|
|
|
|
|
|
if (!colorStr.IsEmpty()) {
|
2001-10-17 03:59:25 +04:00
|
|
|
mDefaultColor = MakeColorPref(colorStr);
|
|
|
|
}
|
2004-04-30 08:06:30 +04:00
|
|
|
|
2011-10-12 01:29:12 +04:00
|
|
|
colorStr = Preferences::GetString("browser.display.background_color");
|
2004-04-30 08:06:30 +04:00
|
|
|
|
|
|
|
if (!colorStr.IsEmpty()) {
|
2004-02-01 01:41:40 +03:00
|
|
|
mBackgroundColor = MakeColorPref(colorStr);
|
2001-10-17 03:59:25 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2011-09-09 06:27:13 +04:00
|
|
|
mDefaultColor =
|
|
|
|
LookAndFeel::GetColor(LookAndFeel::eColorID_WindowForeground,
|
|
|
|
NS_RGB(0x00, 0x00, 0x00));
|
|
|
|
mBackgroundColor =
|
|
|
|
LookAndFeel::GetColor(LookAndFeel::eColorID_WindowBackground,
|
|
|
|
NS_RGB(0xFF, 0xFF, 0xFF));
|
2001-10-17 03:59:25 +04:00
|
|
|
}
|
|
|
|
|
2008-09-19 21:06:46 +04:00
|
|
|
// Wherever we got the default background color from, ensure it is
|
|
|
|
// opaque.
|
|
|
|
mBackgroundColor = NS_ComposeColors(NS_RGB(0xFF, 0xFF, 0xFF),
|
|
|
|
mBackgroundColor);
|
|
|
|
|
2004-06-08 23:34:55 +04:00
|
|
|
mUseDocumentColors = !useAccessibilityTheme &&
|
2011-05-25 10:31:59 +04:00
|
|
|
Preferences::GetBool("browser.display.use_document_colors",
|
|
|
|
mUseDocumentColors);
|
2001-10-17 03:59:25 +04:00
|
|
|
}
|
|
|
|
|
1998-11-06 19:16:01 +03:00
|
|
|
void
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::GetUserPreferences()
|
1998-11-06 19:16:01 +03:00
|
|
|
{
|
2005-11-09 01:45:49 +03:00
|
|
|
if (!GetPresShell()) {
|
|
|
|
// No presshell means nothing to do here. We'll do this when we
|
|
|
|
// get a presshell.
|
|
|
|
return;
|
|
|
|
}
|
2008-02-08 22:52:46 +03:00
|
|
|
|
|
|
|
mAutoQualityMinFontSizePixelsPref =
|
2011-05-25 10:32:00 +04:00
|
|
|
Preferences::GetInt("browser.display.auto_quality_min_font_size");
|
2008-02-08 22:52:46 +03:00
|
|
|
|
2000-10-11 12:33:01 +04:00
|
|
|
// * document colors
|
2001-10-17 03:59:25 +04:00
|
|
|
GetDocumentColorPreferences();
|
2001-03-29 11:16:06 +04:00
|
|
|
|
2011-01-25 03:23:08 +03:00
|
|
|
mSendAfterPaintToContent =
|
2011-05-25 10:31:59 +04:00
|
|
|
Preferences::GetBool("dom.send_after_paint_to_content",
|
|
|
|
mSendAfterPaintToContent);
|
2011-01-25 03:23:08 +03:00
|
|
|
|
2000-10-11 12:33:01 +04:00
|
|
|
// * link colors
|
2004-04-30 08:06:30 +04:00
|
|
|
mUnderlineLinks =
|
2011-05-25 10:31:59 +04:00
|
|
|
Preferences::GetBool("browser.underline_anchors", mUnderlineLinks);
|
2004-04-30 08:06:30 +04:00
|
|
|
|
2011-10-12 01:29:12 +04:00
|
|
|
nsAdoptingString colorStr = Preferences::GetString("browser.anchor_color");
|
2004-04-30 08:06:30 +04:00
|
|
|
|
|
|
|
if (!colorStr.IsEmpty()) {
|
2002-12-11 08:11:02 +03:00
|
|
|
mLinkColor = MakeColorPref(colorStr);
|
2000-10-11 12:33:01 +04:00
|
|
|
}
|
2004-04-30 08:06:30 +04:00
|
|
|
|
2011-10-12 01:29:12 +04:00
|
|
|
colorStr = Preferences::GetString("browser.active_color");
|
2004-04-30 08:06:30 +04:00
|
|
|
|
|
|
|
if (!colorStr.IsEmpty()) {
|
2003-10-15 05:56:12 +04:00
|
|
|
mActiveLinkColor = MakeColorPref(colorStr);
|
|
|
|
}
|
2004-04-30 08:06:30 +04:00
|
|
|
|
2011-10-12 01:29:12 +04:00
|
|
|
colorStr = Preferences::GetString("browser.visited_color");
|
2004-04-30 08:06:30 +04:00
|
|
|
|
|
|
|
if (!colorStr.IsEmpty()) {
|
2002-12-11 08:11:02 +03:00
|
|
|
mVisitedLinkColor = MakeColorPref(colorStr);
|
2000-10-11 12:33:01 +04:00
|
|
|
}
|
|
|
|
|
2004-04-30 08:06:30 +04:00
|
|
|
mUseFocusColors =
|
2011-05-25 10:31:59 +04:00
|
|
|
Preferences::GetBool("browser.display.use_focus_colors", mUseFocusColors);
|
2001-04-10 02:17:11 +04:00
|
|
|
|
2004-04-30 08:06:30 +04:00
|
|
|
mFocusTextColor = mDefaultColor;
|
|
|
|
mFocusBackgroundColor = mBackgroundColor;
|
|
|
|
|
2011-10-12 01:29:12 +04:00
|
|
|
colorStr = Preferences::GetString("browser.display.focus_text_color");
|
2001-04-10 02:17:11 +04:00
|
|
|
|
2004-04-30 08:06:30 +04:00
|
|
|
if (!colorStr.IsEmpty()) {
|
|
|
|
mFocusTextColor = MakeColorPref(colorStr);
|
2001-04-10 02:17:11 +04:00
|
|
|
}
|
|
|
|
|
2011-10-12 01:29:12 +04:00
|
|
|
colorStr = Preferences::GetString("browser.display.focus_background_color");
|
2004-04-30 08:06:30 +04:00
|
|
|
|
|
|
|
if (!colorStr.IsEmpty()) {
|
|
|
|
mFocusBackgroundColor = MakeColorPref(colorStr);
|
2004-04-30 07:10:29 +04:00
|
|
|
}
|
2004-04-30 03:34:19 +04:00
|
|
|
|
2004-04-30 08:06:30 +04:00
|
|
|
mFocusRingWidth =
|
2011-05-25 10:32:00 +04:00
|
|
|
Preferences::GetInt("browser.display.focus_ring_width", mFocusRingWidth);
|
2004-04-30 08:06:30 +04:00
|
|
|
|
|
|
|
mFocusRingOnAnything =
|
2011-05-25 10:31:59 +04:00
|
|
|
Preferences::GetBool("browser.display.focus_ring_on_anything",
|
|
|
|
mFocusRingOnAnything);
|
2004-04-30 08:06:30 +04:00
|
|
|
|
2008-10-09 03:28:31 +04:00
|
|
|
mFocusRingStyle =
|
2011-05-25 10:32:00 +04:00
|
|
|
Preferences::GetInt("browser.display.focus_ring_style", mFocusRingStyle);
|
2011-06-01 15:43:31 +04:00
|
|
|
|
|
|
|
mBodyTextColor = mDefaultColor;
|
|
|
|
|
2000-10-11 12:33:01 +04:00
|
|
|
// * use fonts?
|
2004-04-30 08:06:30 +04:00
|
|
|
mUseDocumentFonts =
|
2011-05-25 10:32:00 +04:00
|
|
|
Preferences::GetInt("browser.display.use_document_fonts") != 0;
|
2004-04-30 08:06:30 +04:00
|
|
|
|
2004-06-21 14:32:27 +04:00
|
|
|
// * replace backslashes with Yen signs? (bug 245770)
|
|
|
|
mEnableJapaneseTransform =
|
2011-05-25 10:31:59 +04:00
|
|
|
Preferences::GetBool("layout.enable_japanese_specific_transform");
|
2004-06-21 14:32:27 +04:00
|
|
|
|
2011-05-25 10:32:00 +04:00
|
|
|
mPrefScrollbarSide = Preferences::GetInt("layout.scrollbar.side");
|
2006-03-26 04:48:03 +04:00
|
|
|
|
2012-01-26 03:52:26 +04:00
|
|
|
ResetCachedFontPrefs();
|
2001-01-10 02:55:27 +03:00
|
|
|
|
|
|
|
// * image animation
|
2004-04-30 08:06:30 +04:00
|
|
|
const nsAdoptingCString& animatePref =
|
2011-05-28 11:03:00 +04:00
|
|
|
Preferences::GetCString("image.animation_mode");
|
2004-04-30 08:06:30 +04:00
|
|
|
if (animatePref.Equals("normal"))
|
|
|
|
mImageAnimationModePref = imgIContainer::kNormalAnimMode;
|
|
|
|
else if (animatePref.Equals("none"))
|
|
|
|
mImageAnimationModePref = imgIContainer::kDontAnimMode;
|
|
|
|
else if (animatePref.Equals("once"))
|
|
|
|
mImageAnimationModePref = imgIContainer::kLoopOnceAnimMode;
|
2008-02-08 22:52:46 +03:00
|
|
|
else // dynamic change to invalid value should act like it does initially
|
|
|
|
mImageAnimationModePref = imgIContainer::kNormalAnimMode;
|
2001-11-01 08:49:45 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t bidiOptions = GetBidi();
|
2005-11-09 01:45:49 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t prefInt =
|
2011-05-25 10:32:00 +04:00
|
|
|
Preferences::GetInt(IBMBIDI_TEXTDIRECTION_STR,
|
|
|
|
GET_BIDI_OPTION_DIRECTION(bidiOptions));
|
2005-11-09 01:45:49 +03:00
|
|
|
SET_BIDI_OPTION_DIRECTION(bidiOptions, prefInt);
|
2006-03-26 04:48:03 +04:00
|
|
|
mPrefBidiDirection = prefInt;
|
2004-04-30 08:06:30 +04:00
|
|
|
|
|
|
|
prefInt =
|
2011-05-25 10:32:00 +04:00
|
|
|
Preferences::GetInt(IBMBIDI_TEXTTYPE_STR,
|
|
|
|
GET_BIDI_OPTION_TEXTTYPE(bidiOptions));
|
2005-11-09 01:45:49 +03:00
|
|
|
SET_BIDI_OPTION_TEXTTYPE(bidiOptions, prefInt);
|
2004-04-30 08:06:30 +04:00
|
|
|
|
|
|
|
prefInt =
|
2011-05-25 10:32:00 +04:00
|
|
|
Preferences::GetInt(IBMBIDI_NUMERAL_STR,
|
|
|
|
GET_BIDI_OPTION_NUMERAL(bidiOptions));
|
2005-11-09 01:45:49 +03:00
|
|
|
SET_BIDI_OPTION_NUMERAL(bidiOptions, prefInt);
|
2004-04-30 08:06:30 +04:00
|
|
|
|
|
|
|
prefInt =
|
2011-05-25 10:32:00 +04:00
|
|
|
Preferences::GetInt(IBMBIDI_SUPPORTMODE_STR,
|
|
|
|
GET_BIDI_OPTION_SUPPORT(bidiOptions));
|
2005-11-09 01:45:49 +03:00
|
|
|
SET_BIDI_OPTION_SUPPORT(bidiOptions, prefInt);
|
2004-04-30 08:06:30 +04:00
|
|
|
|
2005-11-13 12:55:09 +03:00
|
|
|
// We don't need to force reflow: either we are initializing a new
|
|
|
|
// prescontext or we are being called from UpdateAfterPreferencesChanged()
|
|
|
|
// which triggers a reflow anyway.
|
2011-10-17 18:59:28 +04:00
|
|
|
SetBidi(bidiOptions, false);
|
1998-11-06 19:16:01 +03:00
|
|
|
}
|
|
|
|
|
2011-04-12 00:57:29 +04:00
|
|
|
void
|
2011-06-09 11:13:05 +04:00
|
|
|
nsPresContext::InvalidateThebesLayers()
|
2011-04-12 00:57:29 +04:00
|
|
|
{
|
2011-06-09 11:13:05 +04:00
|
|
|
if (!mShell)
|
|
|
|
return;
|
2011-04-12 00:57:29 +04:00
|
|
|
nsIFrame* rootFrame = mShell->FrameManager()->GetRootFrame();
|
|
|
|
if (rootFrame) {
|
|
|
|
// FrameLayerBuilder caches invalidation-related values that depend on the
|
|
|
|
// appunits-per-dev-pixel ratio, so ensure that all ThebesLayer drawing
|
|
|
|
// is completely flushed.
|
2012-08-29 09:39:31 +04:00
|
|
|
rootFrame->InvalidateFrameSubtree();
|
2011-04-12 00:57:29 +04:00
|
|
|
}
|
2011-06-09 11:13:05 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsPresContext::AppUnitsPerDevPixelChanged()
|
|
|
|
{
|
|
|
|
InvalidateThebesLayers();
|
2011-04-12 00:57:29 +04:00
|
|
|
|
|
|
|
mDeviceContext->FlushFontCache();
|
|
|
|
|
|
|
|
if (HasCachedStyleData()) {
|
2012-11-09 10:40:41 +04:00
|
|
|
// All cached style data must be recomputed.
|
|
|
|
MediaFeatureValuesChanged(eAlwaysRebuildStyle, NS_STYLE_HINT_REFLOW);
|
2011-04-12 00:57:29 +04:00
|
|
|
}
|
2013-02-07 04:19:01 +04:00
|
|
|
|
|
|
|
mCurAppUnitsPerDevPixel = AppUnitsPerDevPixel();
|
2011-04-12 00:57:29 +04:00
|
|
|
}
|
|
|
|
|
2000-04-03 01:52:17 +04:00
|
|
|
void
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::PreferenceChanged(const char* aPrefName)
|
2000-04-03 01:52:17 +04:00
|
|
|
{
|
2008-02-08 22:52:46 +03:00
|
|
|
nsDependentCString prefName(aPrefName);
|
2009-05-18 02:09:53 +04:00
|
|
|
if (prefName.EqualsLiteral("layout.css.dpi") ||
|
|
|
|
prefName.EqualsLiteral("layout.css.devPixelsPerPx")) {
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t oldAppUnitsPerDevPixel = AppUnitsPerDevPixel();
|
2007-02-15 12:04:25 +03:00
|
|
|
if (mDeviceContext->CheckDPIChange() && mShell) {
|
2007-12-17 07:59:59 +03:00
|
|
|
// Re-fetch the view manager's window dimensions in case there's a deferred
|
|
|
|
// resize which hasn't affected our mVisibleArea yet
|
|
|
|
nscoord oldWidthAppUnits, oldHeightAppUnits;
|
2013-01-05 07:12:24 +04:00
|
|
|
nsViewManager* vm = mShell->GetViewManager();
|
2007-12-17 07:59:59 +03:00
|
|
|
vm->GetWindowDimensions(&oldWidthAppUnits, &oldHeightAppUnits);
|
|
|
|
float oldWidthDevPixels = oldWidthAppUnits/oldAppUnitsPerDevPixel;
|
|
|
|
float oldHeightDevPixels = oldHeightAppUnits/oldAppUnitsPerDevPixel;
|
|
|
|
|
2007-12-12 05:27:00 +03:00
|
|
|
nscoord width = NSToCoordRound(oldWidthDevPixels*AppUnitsPerDevPixel());
|
|
|
|
nscoord height = NSToCoordRound(oldHeightDevPixels*AppUnitsPerDevPixel());
|
2007-02-15 12:04:25 +03:00
|
|
|
vm->SetWindowDimensions(width, height);
|
|
|
|
|
2011-04-12 00:57:29 +04:00
|
|
|
AppUnitsPerDevPixelChanged();
|
2007-02-15 12:04:25 +03:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2008-02-08 22:52:46 +03:00
|
|
|
if (StringBeginsWith(prefName, NS_LITERAL_CSTRING("font."))) {
|
|
|
|
// Changes to font family preferences don't change anything in the
|
|
|
|
// computed style data, so the style system won't generate a reflow
|
|
|
|
// hint for us. We need to do that manually.
|
|
|
|
|
|
|
|
// FIXME We could probably also handle changes to
|
|
|
|
// browser.display.auto_quality_min_font_size here, but that
|
|
|
|
// probably also requires clearing the text run cache, so don't
|
|
|
|
// bother (yet, anyway).
|
2011-10-17 18:59:28 +04:00
|
|
|
mPrefChangePendingNeedsReflow = true;
|
2007-07-26 13:47:43 +04:00
|
|
|
}
|
2008-12-18 23:12:53 +03:00
|
|
|
if (StringBeginsWith(prefName, NS_LITERAL_CSTRING("bidi."))) {
|
|
|
|
// Changes to bidi prefs need to trigger a reflow (see bug 443629)
|
2011-10-17 18:59:28 +04:00
|
|
|
mPrefChangePendingNeedsReflow = true;
|
2008-12-18 23:12:53 +03:00
|
|
|
|
|
|
|
// Changes to bidi.numeral also needs to empty the text run cache.
|
|
|
|
// This is handled in gfxTextRunWordCache.cpp.
|
|
|
|
}
|
2010-06-09 04:33:13 +04:00
|
|
|
if (StringBeginsWith(prefName, NS_LITERAL_CSTRING("gfx.font_rendering."))) {
|
|
|
|
// Changes to font_rendering prefs need to trigger a reflow
|
2011-10-17 18:59:28 +04:00
|
|
|
mPrefChangePendingNeedsReflow = true;
|
2010-06-09 04:33:13 +04:00
|
|
|
}
|
2005-08-24 03:52:16 +04:00
|
|
|
// we use a zero-delay timer to coalesce multiple pref updates
|
|
|
|
if (!mPrefChangedTimer)
|
|
|
|
{
|
|
|
|
mPrefChangedTimer = do_CreateInstance("@mozilla.org/timer;1");
|
|
|
|
if (!mPrefChangedTimer)
|
|
|
|
return;
|
|
|
|
mPrefChangedTimer->InitWithFuncCallback(nsPresContext::PrefChangedUpdateTimerCallback, (void*)this, 0, nsITimer::TYPE_ONE_SHOT);
|
|
|
|
}
|
2013-07-22 19:51:38 +04:00
|
|
|
if (prefName.EqualsLiteral("nglayout.debug.paint_flashing") ||
|
|
|
|
prefName.EqualsLiteral("nglayout.debug.paint_flashing_chrome")) {
|
|
|
|
mPaintFlashingInitialized = false;
|
|
|
|
return;
|
|
|
|
}
|
2005-08-24 03:52:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsPresContext::UpdateAfterPreferencesChanged()
|
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
mPrefChangedTimer = nullptr;
|
2005-08-24 03:52:16 +04:00
|
|
|
|
2002-11-07 03:59:25 +03:00
|
|
|
nsCOMPtr<nsIDocShellTreeItem> docShell(do_QueryReferent(mContainer));
|
2001-07-25 10:33:06 +04:00
|
|
|
if (docShell) {
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t docShellType;
|
2001-07-25 10:33:06 +04:00
|
|
|
docShell->GetItemType(&docShellType);
|
|
|
|
if (nsIDocShellTreeItem::typeChrome == docShellType)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2000-04-03 01:52:17 +04:00
|
|
|
// Initialize our state from the user preferences
|
|
|
|
GetUserPreferences();
|
2000-10-11 12:33:01 +04:00
|
|
|
|
|
|
|
// update the presShell: tell it to set the preference style rules up
|
|
|
|
if (mShell) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mShell->SetPreferenceStyleRules(true);
|
2000-10-11 12:33:01 +04:00
|
|
|
}
|
|
|
|
|
2011-06-09 11:13:05 +04:00
|
|
|
InvalidateThebesLayers();
|
2004-02-03 01:17:21 +03:00
|
|
|
mDeviceContext->FlushFontCache();
|
2008-02-08 22:52:46 +03:00
|
|
|
|
|
|
|
nsChangeHint hint = nsChangeHint(0);
|
|
|
|
|
|
|
|
if (mPrefChangePendingNeedsReflow) {
|
|
|
|
NS_UpdateHint(hint, NS_STYLE_HINT_REFLOW);
|
|
|
|
}
|
|
|
|
|
|
|
|
RebuildAllStyleData(hint);
|
1998-11-06 19:16:01 +03:00
|
|
|
}
|
|
|
|
|
2004-07-29 23:41:39 +04:00
|
|
|
nsresult
|
2011-04-17 05:22:44 +04:00
|
|
|
nsPresContext::Init(nsDeviceContext* aDeviceContext)
|
1998-06-25 08:24:45 +04:00
|
|
|
{
|
2010-02-07 18:52:43 +03:00
|
|
|
NS_ASSERTION(!mInitialized, "attempt to reinit pres context");
|
2004-02-03 01:17:21 +03:00
|
|
|
NS_ENSURE_ARG(aDeviceContext);
|
1998-06-25 08:24:45 +04:00
|
|
|
|
2003-06-19 22:16:53 +04:00
|
|
|
mDeviceContext = aDeviceContext;
|
1998-07-31 09:54:59 +04:00
|
|
|
|
2007-11-27 07:54:30 +03:00
|
|
|
if (mDeviceContext->SetPixelScale(mFullZoom))
|
|
|
|
mDeviceContext->FlushFontCache();
|
2007-08-24 21:46:59 +04:00
|
|
|
mCurAppUnitsPerDevPixel = AppUnitsPerDevPixel();
|
|
|
|
|
2004-02-27 20:17:37 +03:00
|
|
|
mEventManager = new nsEventStateManager();
|
2004-02-27 21:24:36 +03:00
|
|
|
|
2009-10-08 07:22:42 +04:00
|
|
|
mTransitionManager = new nsTransitionManager(this);
|
2009-12-23 22:10:30 +03:00
|
|
|
|
2011-04-12 10:18:44 +04:00
|
|
|
mAnimationManager = new nsAnimationManager(this);
|
|
|
|
|
2013-07-20 23:14:24 +04:00
|
|
|
// FIXME: Why is mozilla:: needed?
|
|
|
|
mRestyleManager = new mozilla::RestyleManager(this);
|
|
|
|
|
2010-08-12 01:05:27 +04:00
|
|
|
if (mDocument->GetDisplayDocument()) {
|
|
|
|
NS_ASSERTION(mDocument->GetDisplayDocument()->GetShell() &&
|
|
|
|
mDocument->GetDisplayDocument()->GetShell()->GetPresContext(),
|
|
|
|
"Why are we being initialized?");
|
|
|
|
mRefreshDriver = mDocument->GetDisplayDocument()->GetShell()->
|
|
|
|
GetPresContext()->RefreshDriver();
|
|
|
|
} else {
|
2010-09-07 23:10:41 +04:00
|
|
|
nsIDocument* parent = mDocument->GetParentDocument();
|
|
|
|
// Unfortunately, sometimes |parent| here has no presshell because
|
|
|
|
// printing screws up things. Assert that in other cases it does,
|
|
|
|
// but whenever the shell is null just fall back on using our own
|
|
|
|
// refresh driver.
|
|
|
|
NS_ASSERTION(!parent || mDocument->IsStaticDocument() || parent->GetShell(),
|
|
|
|
"How did we end up with a presshell if our parent doesn't "
|
|
|
|
"have one?");
|
|
|
|
if (parent && parent->GetShell()) {
|
|
|
|
NS_ASSERTION(parent->GetShell()->GetPresContext(),
|
|
|
|
"How did we get a presshell?");
|
|
|
|
|
|
|
|
// We don't have our container set yet at this point
|
|
|
|
nsCOMPtr<nsISupports> ourContainer = mDocument->GetContainer();
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> ourItem = do_QueryInterface(ourContainer);
|
|
|
|
if (ourItem) {
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> parentItem;
|
|
|
|
ourItem->GetSameTypeParent(getter_AddRefs(parentItem));
|
|
|
|
if (parentItem) {
|
2013-02-22 18:56:28 +04:00
|
|
|
Element* containingElement =
|
|
|
|
parent->FindContentForSubDocument(mDocument);
|
|
|
|
if (!containingElement->IsXUL() ||
|
|
|
|
!containingElement->
|
|
|
|
HasAttr(kNameSpaceID_None,
|
|
|
|
nsGkAtoms::forceOwnRefreshDriver)) {
|
|
|
|
mRefreshDriver = parent->GetShell()->GetPresContext()->RefreshDriver();
|
|
|
|
}
|
2010-08-12 01:05:27 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mRefreshDriver) {
|
|
|
|
mRefreshDriver = new nsRefreshDriver(this);
|
|
|
|
}
|
|
|
|
}
|
2009-10-08 07:22:42 +04:00
|
|
|
|
2012-12-12 01:12:43 +04:00
|
|
|
// Initialise refresh tick counters for OMTA
|
|
|
|
mLastStyleUpdateForAllAnimations =
|
|
|
|
mLastUpdateThrottledStyle = mRefreshDriver->MostRecentRefresh();
|
|
|
|
|
2004-04-30 08:06:30 +04:00
|
|
|
mLangService = do_GetService(NS_LANGUAGEATOMSERVICE_CONTRACTID);
|
|
|
|
|
|
|
|
// Register callbacks so we're notified when the preferences change
|
2011-05-29 03:42:57 +04:00
|
|
|
Preferences::RegisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"font.",
|
|
|
|
this);
|
|
|
|
Preferences::RegisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"browser.display.",
|
|
|
|
this);
|
|
|
|
Preferences::RegisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"browser.underline_anchors",
|
|
|
|
this);
|
|
|
|
Preferences::RegisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"browser.anchor_color",
|
|
|
|
this);
|
|
|
|
Preferences::RegisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"browser.active_color",
|
|
|
|
this);
|
|
|
|
Preferences::RegisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"browser.visited_color",
|
|
|
|
this);
|
|
|
|
Preferences::RegisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"image.animation_mode",
|
|
|
|
this);
|
2004-04-30 08:06:30 +04:00
|
|
|
#ifdef IBMBIDI
|
2011-05-29 03:42:57 +04:00
|
|
|
Preferences::RegisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"bidi.",
|
|
|
|
this);
|
2004-04-30 08:06:30 +04:00
|
|
|
#endif
|
2011-05-29 03:42:57 +04:00
|
|
|
Preferences::RegisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"dom.send_after_paint_to_content",
|
|
|
|
this);
|
|
|
|
Preferences::RegisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"gfx.font_rendering.",
|
|
|
|
this);
|
|
|
|
Preferences::RegisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"layout.css.dpi",
|
|
|
|
this);
|
|
|
|
Preferences::RegisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"layout.css.devPixelsPerPx",
|
|
|
|
this);
|
2013-07-22 19:51:38 +04:00
|
|
|
Preferences::RegisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"nglayout.debug.paint_flashing",
|
|
|
|
this);
|
|
|
|
Preferences::RegisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"nglayout.debug.paint_flashing_chrome",
|
|
|
|
this);
|
2004-04-30 08:06:30 +04:00
|
|
|
|
2011-09-09 06:27:13 +04:00
|
|
|
nsresult rv = mEventManager->Init();
|
2004-02-27 20:17:37 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
mEventManager->SetPresContext(this);
|
|
|
|
|
1998-06-25 08:24:45 +04:00
|
|
|
#ifdef DEBUG
|
2011-10-17 18:59:28 +04:00
|
|
|
mInitialized = true;
|
1998-06-25 08:24:45 +04:00
|
|
|
#endif
|
|
|
|
|
2007-02-07 10:46:44 +03:00
|
|
|
mBorderWidthTable[NS_STYLE_BORDER_WIDTH_THIN] = CSSPixelsToAppUnits(1);
|
|
|
|
mBorderWidthTable[NS_STYLE_BORDER_WIDTH_MEDIUM] = CSSPixelsToAppUnits(3);
|
|
|
|
mBorderWidthTable[NS_STYLE_BORDER_WIDTH_THICK] = CSSPixelsToAppUnits(5);
|
2004-11-26 21:40:58 +03:00
|
|
|
|
1998-06-25 08:24:45 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
// Note: We don't hold a reference on the shell; it has a reference to
|
|
|
|
// us
|
2004-07-29 23:41:39 +04:00
|
|
|
void
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::SetShell(nsIPresShell* aShell)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2009-01-19 12:21:29 +03:00
|
|
|
if (mUserFontSet) {
|
|
|
|
// Clear out user font set if we have one
|
|
|
|
mUserFontSet->Destroy();
|
|
|
|
NS_RELEASE(mUserFontSet);
|
|
|
|
}
|
|
|
|
|
2003-04-25 02:44:48 +04:00
|
|
|
if (mShell) {
|
|
|
|
// Remove ourselves as the charset observer from the shell's doc, because
|
|
|
|
// this shell may be going away for good.
|
2004-08-02 08:52:55 +04:00
|
|
|
nsIDocument *doc = mShell->GetDocument();
|
2003-04-25 02:44:48 +04:00
|
|
|
if (doc) {
|
|
|
|
doc->RemoveCharSetObserver(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
mShell = aShell;
|
2003-04-25 02:44:48 +04:00
|
|
|
|
|
|
|
if (mShell) {
|
2006-07-28 10:22:19 +04:00
|
|
|
nsIDocument *doc = mShell->GetDocument();
|
|
|
|
NS_ASSERTION(doc, "expect document here");
|
|
|
|
if (doc) {
|
|
|
|
// Have to update PresContext's mDocument before calling any other methods.
|
|
|
|
mDocument = doc;
|
|
|
|
}
|
2005-11-09 01:45:49 +03:00
|
|
|
// Initialize our state from the user preferences, now that we
|
|
|
|
// have a presshell, and hence a document.
|
|
|
|
GetUserPreferences();
|
|
|
|
|
2004-08-02 08:52:55 +04:00
|
|
|
if (doc) {
|
2006-03-24 03:09:50 +03:00
|
|
|
nsIURI *docURI = doc->GetDocumentURI();
|
2004-08-02 08:52:55 +04:00
|
|
|
|
2006-04-01 05:19:28 +04:00
|
|
|
if (IsDynamic() && docURI) {
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isChrome = false;
|
|
|
|
bool isRes = false;
|
2006-03-24 03:09:50 +03:00
|
|
|
docURI->SchemeIs("chrome", &isChrome);
|
|
|
|
docURI->SchemeIs("resource", &isRes);
|
2004-08-02 08:52:55 +04:00
|
|
|
|
|
|
|
if (!isChrome && !isRes)
|
|
|
|
mImageAnimationMode = mImageAnimationModePref;
|
|
|
|
else
|
|
|
|
mImageAnimationMode = imgIContainer::kNormalAnimMode;
|
|
|
|
}
|
2001-01-10 02:55:27 +03:00
|
|
|
|
2004-08-02 08:52:55 +04:00
|
|
|
if (mLangService) {
|
|
|
|
doc->AddCharSetObserver(this);
|
2004-08-10 01:19:15 +04:00
|
|
|
UpdateCharSet(doc->GetDocumentCharacterSet());
|
1999-02-12 20:45:58 +03:00
|
|
|
}
|
1998-09-05 07:52:40 +04:00
|
|
|
}
|
2010-01-14 05:30:05 +03:00
|
|
|
} else {
|
2010-12-18 07:45:18 +03:00
|
|
|
if (mTransitionManager) {
|
|
|
|
mTransitionManager->Disconnect();
|
2012-07-30 18:20:58 +04:00
|
|
|
mTransitionManager = nullptr;
|
2010-12-18 07:45:18 +03:00
|
|
|
}
|
2011-04-12 10:18:44 +04:00
|
|
|
if (mAnimationManager) {
|
|
|
|
mAnimationManager->Disconnect();
|
2012-07-30 18:20:58 +04:00
|
|
|
mAnimationManager = nullptr;
|
2011-04-12 10:18:44 +04:00
|
|
|
}
|
2013-07-20 23:14:24 +04:00
|
|
|
if (mRestyleManager) {
|
|
|
|
mRestyleManager->Disconnect();
|
|
|
|
mRestyleManager = nullptr;
|
|
|
|
}
|
2011-12-24 07:52:26 +04:00
|
|
|
|
|
|
|
if (IsRoot()) {
|
|
|
|
// Have to cancel our plugin geometry timer, because the
|
|
|
|
// callback for that depends on a non-null presshell.
|
2012-10-06 17:03:23 +04:00
|
|
|
static_cast<nsRootPresContext*>(this)->CancelApplyPluginGeometryTimer();
|
2011-12-24 07:52:26 +04:00
|
|
|
}
|
1998-09-05 07:52:40 +04:00
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2000-09-21 02:59:20 +04:00
|
|
|
void
|
2012-01-12 00:58:44 +04:00
|
|
|
nsPresContext::DoChangeCharSet(const nsCString& aCharSet)
|
|
|
|
{
|
|
|
|
UpdateCharSet(aCharSet);
|
|
|
|
mDeviceContext->FlushFontCache();
|
|
|
|
RebuildAllStyleData(NS_STYLE_HINT_REFLOW);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsPresContext::UpdateCharSet(const nsCString& aCharSet)
|
2000-09-21 02:59:20 +04:00
|
|
|
{
|
|
|
|
if (mLangService) {
|
2012-07-30 08:29:23 +04:00
|
|
|
mLanguage = mLangService->LookupCharSet(aCharSet.get());
|
2010-02-24 20:57:44 +03:00
|
|
|
// this will be a language group (or script) code rather than a true language code
|
2004-06-21 14:32:27 +04:00
|
|
|
|
|
|
|
// bug 39570: moved from nsLanguageAtomService::LookupCharSet()
|
2010-02-24 20:57:44 +03:00
|
|
|
if (mLanguage == nsGkAtoms::Unicode) {
|
2012-07-30 08:29:23 +04:00
|
|
|
mLanguage = mLangService->GetLocaleLanguage();
|
2004-06-21 14:32:27 +04:00
|
|
|
}
|
2012-01-26 03:52:26 +04:00
|
|
|
ResetCachedFontPrefs();
|
2000-09-21 02:59:20 +04:00
|
|
|
}
|
2001-03-09 06:13:03 +03:00
|
|
|
#ifdef IBMBIDI
|
|
|
|
//ahmed
|
|
|
|
|
2005-11-09 01:45:49 +03:00
|
|
|
switch (GET_BIDI_OPTION_TEXTTYPE(GetBidi())) {
|
2004-08-06 01:38:08 +04:00
|
|
|
|
|
|
|
case IBMBIDI_TEXTTYPE_LOGICAL:
|
2011-10-17 18:59:28 +04:00
|
|
|
SetVisualMode(false);
|
2004-08-06 01:38:08 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case IBMBIDI_TEXTTYPE_VISUAL:
|
2011-10-17 18:59:28 +04:00
|
|
|
SetVisualMode(true);
|
2004-08-06 01:38:08 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case IBMBIDI_TEXTTYPE_CHARSET:
|
|
|
|
default:
|
2004-08-10 01:19:15 +04:00
|
|
|
SetVisualMode(IsVisualCharset(aCharSet));
|
2004-08-06 01:38:08 +04:00
|
|
|
}
|
2001-03-09 06:13:03 +03:00
|
|
|
#endif // IBMBIDI
|
2000-09-21 02:59:20 +04:00
|
|
|
}
|
|
|
|
|
2000-06-02 03:12:26 +04:00
|
|
|
NS_IMETHODIMP
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::Observe(nsISupports* aSubject,
|
2004-07-29 23:41:39 +04:00
|
|
|
const char* aTopic,
|
|
|
|
const PRUnichar* aData)
|
2000-06-02 03:12:26 +04:00
|
|
|
{
|
2001-10-20 00:52:59 +04:00
|
|
|
if (!nsCRT::strcmp(aTopic, "charset")) {
|
2012-01-12 00:58:44 +04:00
|
|
|
nsRefPtr<CharSetChangingRunnable> runnable =
|
|
|
|
new CharSetChangingRunnable(this, NS_LossyConvertUTF16toASCII(aData));
|
|
|
|
return NS_DispatchToCurrentThread(runnable);
|
2000-09-21 02:59:20 +04:00
|
|
|
}
|
|
|
|
|
2004-08-01 03:15:21 +04:00
|
|
|
NS_WARNING("unrecognized topic in nsPresContext::Observe");
|
2001-10-20 00:52:59 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2000-06-02 03:12:26 +04:00
|
|
|
}
|
|
|
|
|
2012-05-04 09:00:57 +04:00
|
|
|
nsPresContext*
|
|
|
|
nsPresContext::GetParentPresContext()
|
2011-01-15 12:40:33 +03:00
|
|
|
{
|
2012-05-04 09:00:57 +04:00
|
|
|
nsIPresShell* shell = GetPresShell();
|
2011-01-15 12:40:33 +03:00
|
|
|
if (shell) {
|
2013-02-28 00:52:06 +04:00
|
|
|
nsViewManager* viewManager = shell->GetViewManager();
|
|
|
|
if (viewManager) {
|
|
|
|
nsView* view = viewManager->GetRootView();
|
|
|
|
if (view) {
|
|
|
|
view = view->GetParent(); // anonymous inner view
|
|
|
|
if (view) {
|
|
|
|
view = view->GetParent(); // subdocumentframe's view
|
|
|
|
if (view) {
|
|
|
|
nsIFrame* f = view->GetFrame();
|
|
|
|
if (f) {
|
|
|
|
return f->PresContext();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-01-15 12:40:33 +03:00
|
|
|
}
|
|
|
|
}
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2011-01-15 12:40:33 +03:00
|
|
|
}
|
|
|
|
|
2012-05-04 09:00:57 +04:00
|
|
|
nsPresContext*
|
|
|
|
nsPresContext::GetToplevelContentDocumentPresContext()
|
|
|
|
{
|
|
|
|
if (IsChrome())
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2012-05-04 09:00:57 +04:00
|
|
|
nsPresContext* pc = this;
|
|
|
|
for (;;) {
|
|
|
|
nsPresContext* parent = pc->GetParentPresContext();
|
|
|
|
if (!parent || parent->IsChrome())
|
|
|
|
return pc;
|
|
|
|
pc = parent;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-26 09:47:45 +04:00
|
|
|
nsIWidget*
|
|
|
|
nsPresContext::GetNearestWidget(nsPoint* aOffset)
|
|
|
|
{
|
|
|
|
NS_ENSURE_TRUE(mShell, nullptr);
|
|
|
|
nsIFrame* frame = mShell->GetRootFrame();
|
|
|
|
NS_ENSURE_TRUE(frame, nullptr);
|
|
|
|
return frame->GetView()->GetNearestWidget(aOffset);
|
|
|
|
}
|
|
|
|
|
2013-02-06 06:50:02 +04:00
|
|
|
nsIWidget*
|
|
|
|
nsPresContext::GetRootWidget()
|
|
|
|
{
|
|
|
|
NS_ENSURE_TRUE(mShell, nullptr);
|
|
|
|
nsViewManager* vm = mShell->GetViewManager();
|
|
|
|
if (!vm) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsIWidget> widget;
|
|
|
|
vm->GetRootWidget(getter_AddRefs(widget));
|
|
|
|
return widget.get();
|
|
|
|
}
|
|
|
|
|
2006-11-30 02:09:13 +03:00
|
|
|
// We may want to replace this with something faster, maybe caching the root prescontext
|
2009-07-22 04:44:54 +04:00
|
|
|
nsRootPresContext*
|
2010-01-26 16:10:12 +03:00
|
|
|
nsPresContext::GetRootPresContext()
|
2006-11-30 02:09:13 +03:00
|
|
|
{
|
|
|
|
nsPresContext* pc = this;
|
|
|
|
for (;;) {
|
2012-05-04 09:00:57 +04:00
|
|
|
nsPresContext* parent = pc->GetParentPresContext();
|
2012-07-04 04:31:07 +04:00
|
|
|
if (!parent)
|
2011-01-15 12:40:33 +03:00
|
|
|
break;
|
|
|
|
pc = parent;
|
2006-11-30 02:09:13 +03:00
|
|
|
}
|
2012-07-30 18:20:58 +04:00
|
|
|
return pc->IsRoot() ? static_cast<nsRootPresContext*>(pc) : nullptr;
|
2006-11-30 02:09:13 +03:00
|
|
|
}
|
|
|
|
|
2012-07-17 21:03:51 +04:00
|
|
|
nsRootPresContext*
|
|
|
|
nsPresContext::GetDisplayRootPresContext()
|
|
|
|
{
|
|
|
|
nsPresContext* pc = this;
|
|
|
|
for (;;) {
|
|
|
|
nsPresContext* parent = pc->GetParentPresContext();
|
|
|
|
if (!parent) {
|
|
|
|
// Not sure if this is always strictly the parent, but it works for GetRootPresContext
|
|
|
|
// where the current pres context has no frames.
|
|
|
|
nsIDocument *doc = pc->Document();
|
|
|
|
if (doc) {
|
|
|
|
doc = doc->GetParentDocument();
|
|
|
|
if (doc) {
|
|
|
|
nsIPresShell* shell = doc->GetShell();
|
|
|
|
if (shell) {
|
|
|
|
parent = shell->GetPresContext();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!parent || parent == pc)
|
|
|
|
break;
|
|
|
|
pc = parent;
|
|
|
|
}
|
2012-07-30 18:20:58 +04:00
|
|
|
return pc->IsRoot() ? static_cast<nsRootPresContext*>(pc) : nullptr;
|
2012-07-17 21:03:51 +04:00
|
|
|
}
|
|
|
|
|
2003-12-25 00:51:50 +03:00
|
|
|
void
|
2006-12-05 18:46:18 +03:00
|
|
|
nsPresContext::CompatibilityModeChanged()
|
1998-07-31 09:54:59 +04:00
|
|
|
{
|
2003-12-25 00:51:50 +03:00
|
|
|
if (!mShell)
|
|
|
|
return;
|
2000-06-03 01:45:06 +04:00
|
|
|
|
2000-06-22 00:44:59 +04:00
|
|
|
// enable/disable the QuirkSheet
|
2004-01-08 01:30:53 +03:00
|
|
|
mShell->StyleSet()->
|
2006-12-05 18:46:18 +03:00
|
|
|
EnableQuirkStyleSheet(CompatibilityMode() == eCompatibility_NavQuirks);
|
1998-07-31 09:54:59 +04:00
|
|
|
}
|
|
|
|
|
2001-11-14 14:21:54 +03:00
|
|
|
// Helper function for setting Anim Mode on image
|
2012-08-22 19:56:38 +04:00
|
|
|
static void SetImgAnimModeOnImgReq(imgIRequest* aImgReq, uint16_t aMode)
|
2001-11-14 14:21:54 +03:00
|
|
|
{
|
2003-03-19 06:47:09 +03:00
|
|
|
if (aImgReq) {
|
2001-11-14 14:21:54 +03:00
|
|
|
nsCOMPtr<imgIContainer> imgCon;
|
|
|
|
aImgReq->GetImage(getter_AddRefs(imgCon));
|
|
|
|
if (imgCon) {
|
|
|
|
imgCon->SetAnimationMode(aMode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
2012-08-22 19:56:38 +04:00
|
|
|
void nsPresContext::SetImgAnimations(nsIContent *aParent, uint16_t aMode)
|
2001-11-14 14:21:54 +03:00
|
|
|
{
|
2003-03-19 06:47:09 +03:00
|
|
|
nsCOMPtr<nsIImageLoadingContent> imgContent(do_QueryInterface(aParent));
|
2001-11-14 14:21:54 +03:00
|
|
|
if (imgContent) {
|
2003-03-19 06:47:09 +03:00
|
|
|
nsCOMPtr<imgIRequest> imgReq;
|
|
|
|
imgContent->GetRequest(nsIImageLoadingContent::CURRENT_REQUEST,
|
|
|
|
getter_AddRefs(imgReq));
|
|
|
|
SetImgAnimModeOnImgReq(imgReq, aMode);
|
2001-11-14 14:21:54 +03:00
|
|
|
}
|
2003-03-19 06:47:09 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t count = aParent->GetChildCount();
|
|
|
|
for (uint32_t i = 0; i < count; ++i) {
|
2003-09-27 08:18:26 +04:00
|
|
|
SetImgAnimations(aParent->GetChildAt(i), aMode);
|
2001-11-14 14:21:54 +03:00
|
|
|
}
|
|
|
|
}
|
2000-05-13 05:39:20 +04:00
|
|
|
|
2009-01-15 07:38:07 +03:00
|
|
|
void
|
2012-08-22 19:56:38 +04:00
|
|
|
nsPresContext::SetSMILAnimations(nsIDocument *aDoc, uint16_t aNewMode,
|
|
|
|
uint16_t aOldMode)
|
2009-01-15 07:38:07 +03:00
|
|
|
{
|
2010-03-03 10:09:51 +03:00
|
|
|
if (aDoc->HasAnimationController()) {
|
|
|
|
nsSMILAnimationController* controller = aDoc->GetAnimationController();
|
2009-01-15 07:38:07 +03:00
|
|
|
switch (aNewMode)
|
|
|
|
{
|
|
|
|
case imgIContainer::kNormalAnimMode:
|
|
|
|
case imgIContainer::kLoopOnceAnimMode:
|
|
|
|
if (aOldMode == imgIContainer::kDontAnimMode)
|
|
|
|
controller->Resume(nsSMILTimeContainer::PAUSE_USERPREF);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case imgIContainer::kDontAnimMode:
|
|
|
|
if (aOldMode != imgIContainer::kDontAnimMode)
|
|
|
|
controller->Pause(nsSMILTimeContainer::PAUSE_USERPREF);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-12-26 07:24:11 +03:00
|
|
|
void
|
2012-08-22 19:56:38 +04:00
|
|
|
nsPresContext::SetImageAnimationModeInternal(uint16_t aMode)
|
2000-05-13 05:39:20 +04:00
|
|
|
{
|
2001-11-14 17:03:09 +03:00
|
|
|
NS_ASSERTION(aMode == imgIContainer::kNormalAnimMode ||
|
|
|
|
aMode == imgIContainer::kDontAnimMode ||
|
|
|
|
aMode == imgIContainer::kLoopOnceAnimMode, "Wrong Animation Mode is being set!");
|
|
|
|
|
2004-07-29 23:41:39 +04:00
|
|
|
// Image animation mode cannot be changed when rendering to a printer.
|
2006-04-01 05:19:28 +04:00
|
|
|
if (!IsDynamic())
|
2004-07-29 23:41:39 +04:00
|
|
|
return;
|
|
|
|
|
2001-11-14 14:21:54 +03:00
|
|
|
// Now walk the content tree and set the animation mode
|
2008-10-29 00:38:37 +03:00
|
|
|
// on all the images.
|
2012-07-30 18:20:58 +04:00
|
|
|
if (mShell != nullptr) {
|
2004-08-02 08:52:55 +04:00
|
|
|
nsIDocument *doc = mShell->GetDocument();
|
2001-11-14 14:21:54 +03:00
|
|
|
if (doc) {
|
2012-08-14 02:04:19 +04:00
|
|
|
doc->StyleImageLoader()->SetAnimationMode(aMode);
|
|
|
|
|
2010-04-30 17:12:05 +04:00
|
|
|
Element *rootElement = doc->GetRootElement();
|
|
|
|
if (rootElement) {
|
|
|
|
SetImgAnimations(rootElement, aMode);
|
2001-11-14 14:21:54 +03:00
|
|
|
}
|
2009-01-15 07:38:07 +03:00
|
|
|
SetSMILAnimations(doc, aMode, mImageAnimationMode);
|
2001-11-14 14:21:54 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-05-13 05:39:20 +04:00
|
|
|
mImageAnimationMode = aMode;
|
|
|
|
}
|
|
|
|
|
2004-07-29 23:41:39 +04:00
|
|
|
void
|
2012-08-22 19:56:38 +04:00
|
|
|
nsPresContext::SetImageAnimationModeExternal(uint16_t aMode)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2004-07-29 23:41:39 +04:00
|
|
|
SetImageAnimationModeInternal(aMode);
|
|
|
|
}
|
1998-08-28 00:43:04 +04:00
|
|
|
|
2004-02-01 01:41:40 +03:00
|
|
|
const nsFont*
|
2012-08-22 19:56:38 +04:00
|
|
|
nsPresContext::GetDefaultFont(uint8_t aFontID, nsIAtom *aLanguage) const
|
1999-02-12 20:45:58 +03:00
|
|
|
{
|
2012-01-26 03:52:26 +04:00
|
|
|
const LangGroupFontPrefs *prefs = GetFontPrefsForLang(aLanguage);
|
|
|
|
|
2004-02-01 01:41:40 +03:00
|
|
|
const nsFont *font;
|
2001-09-27 22:34:30 +04:00
|
|
|
switch (aFontID) {
|
|
|
|
// Special (our default variable width font and fixed width font)
|
|
|
|
case kPresContext_DefaultVariableFont_ID:
|
2012-01-26 03:52:26 +04:00
|
|
|
font = &prefs->mDefaultVariableFont;
|
2001-09-27 22:34:30 +04:00
|
|
|
break;
|
|
|
|
case kPresContext_DefaultFixedFont_ID:
|
2012-01-26 03:52:26 +04:00
|
|
|
font = &prefs->mDefaultFixedFont;
|
2001-09-27 22:34:30 +04:00
|
|
|
break;
|
|
|
|
// CSS
|
|
|
|
case kGenericFont_serif:
|
2012-01-26 03:52:26 +04:00
|
|
|
font = &prefs->mDefaultSerifFont;
|
2001-09-27 22:34:30 +04:00
|
|
|
break;
|
|
|
|
case kGenericFont_sans_serif:
|
2012-01-26 03:52:26 +04:00
|
|
|
font = &prefs->mDefaultSansSerifFont;
|
2001-09-27 22:34:30 +04:00
|
|
|
break;
|
|
|
|
case kGenericFont_monospace:
|
2012-01-26 03:52:26 +04:00
|
|
|
font = &prefs->mDefaultMonospaceFont;
|
2001-09-27 22:34:30 +04:00
|
|
|
break;
|
|
|
|
case kGenericFont_cursive:
|
2012-01-26 03:52:26 +04:00
|
|
|
font = &prefs->mDefaultCursiveFont;
|
2001-09-27 22:34:30 +04:00
|
|
|
break;
|
|
|
|
case kGenericFont_fantasy:
|
2012-01-26 03:52:26 +04:00
|
|
|
font = &prefs->mDefaultFantasyFont;
|
2001-09-27 22:34:30 +04:00
|
|
|
break;
|
|
|
|
default:
|
2012-07-30 18:20:58 +04:00
|
|
|
font = nullptr;
|
2001-09-27 22:34:30 +04:00
|
|
|
NS_ERROR("invalid arg");
|
|
|
|
break;
|
|
|
|
}
|
2004-02-01 01:41:40 +03:00
|
|
|
return font;
|
1998-07-17 09:41:41 +04:00
|
|
|
}
|
|
|
|
|
2005-08-13 15:54:22 +04:00
|
|
|
void
|
2007-07-26 07:34:16 +04:00
|
|
|
nsPresContext::SetFullZoom(float aZoom)
|
2005-08-13 15:54:22 +04:00
|
|
|
{
|
2009-12-11 07:02:13 +03:00
|
|
|
if (!mShell || mFullZoom == aZoom) {
|
2007-07-26 07:34:16 +04:00
|
|
|
return;
|
|
|
|
}
|
2011-04-12 00:57:29 +04:00
|
|
|
|
2007-12-12 05:27:00 +03:00
|
|
|
// Re-fetch the view manager's window dimensions in case there's a deferred
|
|
|
|
// resize which hasn't affected our mVisibleArea yet
|
|
|
|
nscoord oldWidthAppUnits, oldHeightAppUnits;
|
2009-03-11 18:43:08 +03:00
|
|
|
mShell->GetViewManager()->GetWindowDimensions(&oldWidthAppUnits, &oldHeightAppUnits);
|
2007-12-12 05:27:00 +03:00
|
|
|
float oldWidthDevPixels = oldWidthAppUnits / float(mCurAppUnitsPerDevPixel);
|
|
|
|
float oldHeightDevPixels = oldHeightAppUnits / float(mCurAppUnitsPerDevPixel);
|
2011-04-12 00:57:29 +04:00
|
|
|
mDeviceContext->SetPixelScale(aZoom);
|
2008-01-29 07:10:59 +03:00
|
|
|
|
2010-02-07 18:52:43 +03:00
|
|
|
NS_ASSERTION(!mSupressResizeReflow, "two zooms happening at the same time? impossible!");
|
2011-10-17 18:59:28 +04:00
|
|
|
mSupressResizeReflow = true;
|
2008-01-29 07:10:59 +03:00
|
|
|
|
2007-11-26 11:35:22 +03:00
|
|
|
mFullZoom = aZoom;
|
2009-03-11 18:43:08 +03:00
|
|
|
mShell->GetViewManager()->
|
|
|
|
SetWindowDimensions(NSToCoordRound(oldWidthDevPixels * AppUnitsPerDevPixel()),
|
|
|
|
NSToCoordRound(oldHeightDevPixels * AppUnitsPerDevPixel()));
|
2011-04-12 00:57:29 +04:00
|
|
|
|
|
|
|
AppUnitsPerDevPixelChanged();
|
2008-01-29 07:10:59 +03:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mSupressResizeReflow = false;
|
2005-08-13 15:54:22 +04:00
|
|
|
}
|
|
|
|
|
2012-05-05 17:25:45 +04:00
|
|
|
float
|
|
|
|
nsPresContext::ScreenWidthInchesForFontInflation(bool* aChanged)
|
|
|
|
{
|
|
|
|
if (aChanged) {
|
|
|
|
*aChanged = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsDeviceContext *dx = DeviceContext();
|
|
|
|
nsRect clientRect;
|
|
|
|
dx->GetClientRect(clientRect); // FIXME: GetClientRect looks expensive
|
|
|
|
float deviceWidthInches =
|
|
|
|
float(clientRect.width) / float(dx->AppUnitsPerPhysicalInch());
|
|
|
|
|
2012-06-12 09:43:31 +04:00
|
|
|
if (mLastFontInflationScreenWidth == -1.0) {
|
|
|
|
mLastFontInflationScreenWidth = deviceWidthInches;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (deviceWidthInches != mLastFontInflationScreenWidth && aChanged) {
|
|
|
|
*aChanged = true;
|
2012-05-05 17:25:45 +04:00
|
|
|
mLastFontInflationScreenWidth = deviceWidthInches;
|
|
|
|
}
|
|
|
|
|
|
|
|
return deviceWidthInches;
|
|
|
|
}
|
|
|
|
|
2004-02-01 13:09:07 +03:00
|
|
|
void
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::SetContainer(nsISupports* aHandler)
|
1999-04-30 13:04:36 +04:00
|
|
|
{
|
2002-11-07 03:59:25 +03:00
|
|
|
mContainer = do_GetWeakReference(aHandler);
|
2010-05-22 22:55:41 +04:00
|
|
|
InvalidateIsChromeCache();
|
2001-10-17 03:59:25 +04:00
|
|
|
if (mContainer) {
|
|
|
|
GetDocumentColorPreferences();
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2004-02-01 13:09:07 +03:00
|
|
|
already_AddRefed<nsISupports>
|
2007-11-16 06:46:42 +03:00
|
|
|
nsPresContext::GetContainerInternal() const
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2013-04-22 15:15:59 +04:00
|
|
|
nsCOMPtr<nsISupports> result = do_QueryReferent(mContainer);
|
|
|
|
return result.forget();
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
1998-06-24 01:53:02 +04:00
|
|
|
|
2004-07-29 23:41:39 +04:00
|
|
|
already_AddRefed<nsISupports>
|
2007-11-16 06:46:42 +03:00
|
|
|
nsPresContext::GetContainerExternal() const
|
2004-07-29 23:41:39 +04:00
|
|
|
{
|
|
|
|
return GetContainerInternal();
|
|
|
|
}
|
|
|
|
|
2013-08-14 15:29:51 +04:00
|
|
|
bool
|
|
|
|
nsPresContext::ThrottledStyleIsUpToDate() const
|
|
|
|
{
|
|
|
|
return mLastUpdateThrottledStyle == mRefreshDriver->MostRecentRefresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsPresContext::TickLastUpdateThrottledStyle()
|
|
|
|
{
|
|
|
|
mLastUpdateThrottledStyle = mRefreshDriver->MostRecentRefresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsPresContext::StyleUpdateForAllAnimationsIsUpToDate()
|
|
|
|
{
|
|
|
|
return mLastStyleUpdateForAllAnimations == mRefreshDriver->MostRecentRefresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsPresContext::TickLastStyleUpdateForAllAnimations()
|
|
|
|
{
|
|
|
|
mLastStyleUpdateForAllAnimations = mRefreshDriver->MostRecentRefresh();
|
|
|
|
}
|
|
|
|
|
2001-03-09 06:13:03 +03:00
|
|
|
#ifdef IBMBIDI
|
2012-07-30 08:29:41 +04:00
|
|
|
bool
|
|
|
|
nsPresContext::BidiEnabledExternal() const
|
|
|
|
{
|
|
|
|
return BidiEnabledInternal();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsPresContext::BidiEnabledInternal() const
|
|
|
|
{
|
|
|
|
return Document()->GetBidiEnabled();
|
|
|
|
}
|
|
|
|
|
2004-04-13 04:28:44 +04:00
|
|
|
void
|
2008-06-16 13:28:17 +04:00
|
|
|
nsPresContext::SetBidiEnabled() const
|
2001-03-09 06:13:03 +03:00
|
|
|
{
|
|
|
|
if (mShell) {
|
2004-08-02 08:52:55 +04:00
|
|
|
nsIDocument *doc = mShell->GetDocument();
|
2001-03-09 06:13:03 +03:00
|
|
|
if (doc) {
|
2008-06-16 13:28:17 +04:00
|
|
|
doc->SetBidiEnabled();
|
2001-03-09 06:13:03 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-07-29 23:41:39 +04:00
|
|
|
void
|
2012-08-22 19:56:38 +04:00
|
|
|
nsPresContext::SetBidi(uint32_t aSource, bool aForceRestyle)
|
2001-03-09 06:13:03 +03:00
|
|
|
{
|
2005-11-13 12:55:09 +03:00
|
|
|
// Don't do all this stuff unless the options have changed.
|
|
|
|
if (aSource == GetBidi()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-01-09 12:38:28 +03:00
|
|
|
NS_ASSERTION(!(aForceRestyle && (GetBidi() == 0)),
|
2005-11-13 12:55:09 +03:00
|
|
|
"ForceReflow on new prescontext");
|
|
|
|
|
2006-05-19 14:26:44 +04:00
|
|
|
Document()->SetBidiOptions(aSource);
|
2005-11-09 01:45:49 +03:00
|
|
|
if (IBMBIDI_TEXTDIRECTION_RTL == GET_BIDI_OPTION_DIRECTION(aSource)
|
|
|
|
|| IBMBIDI_NUMERAL_HINDI == GET_BIDI_OPTION_NUMERAL(aSource)) {
|
2008-06-16 13:28:17 +04:00
|
|
|
SetBidiEnabled();
|
2001-03-09 06:13:03 +03:00
|
|
|
}
|
2005-11-09 01:45:49 +03:00
|
|
|
if (IBMBIDI_TEXTTYPE_VISUAL == GET_BIDI_OPTION_TEXTTYPE(aSource)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
SetVisualMode(true);
|
2001-03-09 06:13:03 +03:00
|
|
|
}
|
2005-11-09 01:45:49 +03:00
|
|
|
else if (IBMBIDI_TEXTTYPE_LOGICAL == GET_BIDI_OPTION_TEXTTYPE(aSource)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
SetVisualMode(false);
|
2001-03-09 06:13:03 +03:00
|
|
|
}
|
|
|
|
else {
|
2004-08-10 01:19:15 +04:00
|
|
|
nsIDocument* doc = mShell->GetDocument();
|
|
|
|
if (doc) {
|
|
|
|
SetVisualMode(IsVisualCharset(doc->GetDocumentCharacterSet()));
|
|
|
|
}
|
2001-03-09 06:13:03 +03:00
|
|
|
}
|
2010-12-15 23:26:54 +03:00
|
|
|
if (aForceRestyle && mShell) {
|
|
|
|
// Reconstruct the root document element's frame and its children,
|
|
|
|
// because we need to trigger frame reconstruction for direction change.
|
|
|
|
RebuildUserFontSet();
|
|
|
|
mShell->ReconstructFrames();
|
2001-03-09 06:13:03 +03:00
|
|
|
}
|
|
|
|
}
|
2005-11-09 01:45:49 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t
|
2005-11-09 01:45:49 +03:00
|
|
|
nsPresContext::GetBidi() const
|
|
|
|
{
|
2006-05-19 14:26:44 +04:00
|
|
|
return Document()->GetBidiOptions();
|
2005-11-09 01:45:49 +03:00
|
|
|
}
|
2010-06-01 06:19:35 +04:00
|
|
|
|
2001-03-09 06:13:03 +03:00
|
|
|
#endif //IBMBIDI
|
2000-03-21 18:51:59 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2010-03-17 20:10:57 +03:00
|
|
|
nsPresContext::IsTopLevelWindowInactive()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> treeItem(do_QueryReferent(mContainer));
|
|
|
|
if (!treeItem)
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2010-03-17 20:10:57 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> rootItem;
|
|
|
|
treeItem->GetRootTreeItem(getter_AddRefs(rootItem));
|
|
|
|
nsCOMPtr<nsPIDOMWindow> domWindow(do_GetInterface(rootItem));
|
|
|
|
|
|
|
|
return domWindow && !domWindow->IsActive();
|
|
|
|
}
|
|
|
|
|
2004-07-29 23:41:39 +04:00
|
|
|
nsITheme*
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::GetTheme()
|
2001-12-18 01:51:39 +03:00
|
|
|
{
|
2009-02-26 23:02:00 +03:00
|
|
|
if (!sNoTheme && !mTheme) {
|
2001-12-18 01:51:39 +03:00
|
|
|
mTheme = do_GetService("@mozilla.org/chrome/chrome-native-theme;1");
|
|
|
|
if (!mTheme)
|
2011-10-17 18:59:28 +04:00
|
|
|
sNoTheme = true;
|
2001-12-18 01:51:39 +03:00
|
|
|
}
|
|
|
|
|
2004-07-29 23:41:39 +04:00
|
|
|
return mTheme;
|
2001-12-18 01:51:39 +03:00
|
|
|
}
|
|
|
|
|
2004-07-29 23:41:39 +04:00
|
|
|
void
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::ThemeChanged()
|
2001-12-18 01:51:39 +03:00
|
|
|
{
|
2006-09-12 08:36:03 +04:00
|
|
|
if (!mPendingThemeChanged) {
|
2011-10-17 18:59:28 +04:00
|
|
|
sLookAndFeelChanged = true;
|
|
|
|
sThemeChanged = true;
|
2006-09-12 08:36:03 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsIRunnable> ev =
|
2010-04-21 03:21:35 +04:00
|
|
|
NS_NewRunnableMethod(this, &nsPresContext::ThemeChangedInternal);
|
2006-09-12 08:36:03 +04:00
|
|
|
if (NS_SUCCEEDED(NS_DispatchToCurrentThread(ev))) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mPendingThemeChanged = true;
|
2006-09-12 08:36:03 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsPresContext::ThemeChangedInternal()
|
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
mPendingThemeChanged = false;
|
2006-09-12 08:36:03 +04:00
|
|
|
|
2001-12-18 01:51:39 +03:00
|
|
|
// Tell the theme that it changed, so it can flush any handles to stale theme
|
|
|
|
// data.
|
2006-09-12 08:36:03 +04:00
|
|
|
if (mTheme && sThemeChanged) {
|
2001-12-18 01:51:39 +03:00
|
|
|
mTheme->ThemeChanged();
|
2011-10-17 18:59:28 +04:00
|
|
|
sThemeChanged = false;
|
2006-09-12 08:36:03 +04:00
|
|
|
}
|
2001-12-18 01:51:39 +03:00
|
|
|
|
2011-09-09 06:27:13 +04:00
|
|
|
// Clear all cached LookAndFeel colors.
|
|
|
|
if (sLookAndFeelChanged) {
|
|
|
|
LookAndFeel::Refresh();
|
2011-10-17 18:59:28 +04:00
|
|
|
sLookAndFeelChanged = false;
|
2006-09-12 08:36:03 +04:00
|
|
|
}
|
2004-09-17 10:27:01 +04:00
|
|
|
|
2008-08-06 00:02:43 +04:00
|
|
|
// This will force the system metrics to be generated the next time they're used
|
|
|
|
nsCSSRuleProcessor::FreeSystemMetrics();
|
|
|
|
|
2009-10-16 04:23:19 +04:00
|
|
|
// Changes to system metrics can change media queries on them.
|
2008-02-08 22:52:46 +03:00
|
|
|
// Changes in theme can change system colors (whose changes are
|
|
|
|
// properly reflected in computed style data), system fonts (whose
|
|
|
|
// changes are not), and -moz-appearance (whose changes likewise are
|
|
|
|
// not), so we need to reflow.
|
2012-11-09 10:40:41 +04:00
|
|
|
MediaFeatureValuesChanged(eAlwaysRebuildStyle, NS_STYLE_HINT_REFLOW);
|
2001-12-18 01:51:39 +03:00
|
|
|
}
|
|
|
|
|
2004-07-29 23:41:39 +04:00
|
|
|
void
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::SysColorChanged()
|
2002-06-04 21:47:54 +04:00
|
|
|
{
|
2006-09-12 08:36:03 +04:00
|
|
|
if (!mPendingSysColorChanged) {
|
2011-10-17 18:59:28 +04:00
|
|
|
sLookAndFeelChanged = true;
|
2006-09-12 08:36:03 +04:00
|
|
|
nsCOMPtr<nsIRunnable> ev =
|
2010-04-21 03:21:35 +04:00
|
|
|
NS_NewRunnableMethod(this, &nsPresContext::SysColorChangedInternal);
|
2006-09-12 08:36:03 +04:00
|
|
|
if (NS_SUCCEEDED(NS_DispatchToCurrentThread(ev))) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mPendingSysColorChanged = true;
|
2006-09-12 08:36:03 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsPresContext::SysColorChangedInternal()
|
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
mPendingSysColorChanged = false;
|
2006-09-12 08:36:03 +04:00
|
|
|
|
2011-09-09 06:27:13 +04:00
|
|
|
if (sLookAndFeelChanged) {
|
2002-06-04 21:47:54 +04:00
|
|
|
// Don't use the cached values for the system colors
|
2011-09-09 06:27:13 +04:00
|
|
|
LookAndFeel::Refresh();
|
2011-10-17 18:59:28 +04:00
|
|
|
sLookAndFeelChanged = false;
|
2002-06-04 21:47:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Reset default background and foreground colors for the document since
|
|
|
|
// they may be using system colors
|
|
|
|
GetDocumentColorPreferences();
|
|
|
|
|
2008-02-08 22:52:46 +03:00
|
|
|
// The system color values are computed to colors in the style data,
|
|
|
|
// so normal style data comparison is sufficient here.
|
|
|
|
RebuildAllStyleData(nsChangeHint(0));
|
2008-01-09 12:38:28 +03:00
|
|
|
}
|
|
|
|
|
2012-10-16 23:41:20 +04:00
|
|
|
void
|
|
|
|
nsPresContext::UIResolutionChanged()
|
|
|
|
{
|
|
|
|
if (!mPendingUIResolutionChanged) {
|
|
|
|
nsCOMPtr<nsIRunnable> ev =
|
|
|
|
NS_NewRunnableMethod(this, &nsPresContext::UIResolutionChangedInternal);
|
|
|
|
if (NS_SUCCEEDED(NS_DispatchToCurrentThread(ev))) {
|
|
|
|
mPendingUIResolutionChanged = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*static*/ bool
|
|
|
|
nsPresContext::UIResolutionChangedSubdocumentCallback(nsIDocument* aDocument,
|
|
|
|
void* aData)
|
|
|
|
{
|
|
|
|
nsIPresShell* shell = aDocument->GetShell();
|
|
|
|
if (shell) {
|
|
|
|
nsPresContext* pc = shell->GetPresContext();
|
|
|
|
if (pc) {
|
|
|
|
pc->UIResolutionChangedInternal();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsPresContext::UIResolutionChangedInternal()
|
|
|
|
{
|
|
|
|
mPendingUIResolutionChanged = false;
|
|
|
|
|
2013-01-30 16:04:19 +04:00
|
|
|
mDeviceContext->CheckDPIChange();
|
2013-02-20 01:46:27 +04:00
|
|
|
if (mCurAppUnitsPerDevPixel != AppUnitsPerDevPixel()) {
|
2013-02-18 01:27:24 +04:00
|
|
|
AppUnitsPerDevPixelChanged();
|
|
|
|
}
|
2012-10-16 23:41:20 +04:00
|
|
|
|
|
|
|
mDocument->EnumerateSubDocuments(UIResolutionChangedSubdocumentCallback,
|
|
|
|
nullptr);
|
|
|
|
}
|
|
|
|
|
2013-07-17 19:39:19 +04:00
|
|
|
void
|
|
|
|
nsPresContext::EmulateMedium(const nsAString& aMediaType)
|
|
|
|
{
|
|
|
|
nsIAtom* previousMedium = Medium();
|
|
|
|
mIsEmulatingMedia = true;
|
|
|
|
|
|
|
|
nsAutoString mediaType;
|
|
|
|
nsContentUtils::ASCIIToLower(aMediaType, mediaType);
|
|
|
|
|
|
|
|
mMediaEmulated = do_GetAtom(mediaType);
|
|
|
|
if (mMediaEmulated != previousMedium && mShell) {
|
|
|
|
MediaFeatureValuesChanged(eRebuildStyleIfNeeded, nsChangeHint(0));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsPresContext::StopEmulatingMedium()
|
|
|
|
{
|
|
|
|
nsIAtom* previousMedium = Medium();
|
|
|
|
mIsEmulatingMedia = false;
|
|
|
|
if (Medium() != previousMedium) {
|
|
|
|
MediaFeatureValuesChanged(eRebuildStyleIfNeeded, nsChangeHint(0));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-09 12:38:28 +03:00
|
|
|
void
|
2008-02-08 22:52:46 +03:00
|
|
|
nsPresContext::RebuildAllStyleData(nsChangeHint aExtraHint)
|
2008-01-09 12:38:28 +03:00
|
|
|
{
|
|
|
|
if (!mShell) {
|
|
|
|
// We must have been torn down. Nothing to do here.
|
|
|
|
return;
|
|
|
|
}
|
2008-11-26 02:22:38 +03:00
|
|
|
|
2012-10-26 21:04:20 +04:00
|
|
|
mUsesRootEMUnits = false;
|
2012-10-20 03:21:06 +04:00
|
|
|
mUsesViewportUnits = false;
|
2008-11-26 02:22:38 +03:00
|
|
|
RebuildUserFontSet();
|
|
|
|
|
2013-07-20 23:14:25 +04:00
|
|
|
RestyleManager()->RebuildAllStyleData(aExtraHint);
|
2008-01-09 12:38:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-12-04 19:09:53 +03:00
|
|
|
nsPresContext::PostRebuildAllStyleDataEvent(nsChangeHint aExtraHint)
|
2008-01-09 12:38:28 +03:00
|
|
|
{
|
|
|
|
if (!mShell) {
|
|
|
|
// We must have been torn down. Nothing to do here.
|
|
|
|
return;
|
|
|
|
}
|
2013-07-20 23:14:25 +04:00
|
|
|
RestyleManager()->PostRebuildAllStyleDataEvent(aExtraHint);
|
2004-07-29 23:41:39 +04:00
|
|
|
}
|
|
|
|
|
2008-07-26 20:14:48 +04:00
|
|
|
void
|
2012-11-09 10:40:41 +04:00
|
|
|
nsPresContext::MediaFeatureValuesChanged(StyleRebuildType aShouldRebuild,
|
|
|
|
nsChangeHint aChangeHint)
|
2008-07-26 20:14:48 +04:00
|
|
|
{
|
2012-11-09 10:40:41 +04:00
|
|
|
NS_ASSERTION(aShouldRebuild == eAlwaysRebuildStyle || aChangeHint == 0,
|
|
|
|
"If you don't know if we need a rebuild, how can you provide a hint?");
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mPendingMediaFeatureValuesChanged = false;
|
2012-10-20 03:21:06 +04:00
|
|
|
|
|
|
|
// MediumFeaturesChanged updates the applied rules, so it always gets called.
|
|
|
|
bool mediaFeaturesDidChange = mShell ? mShell->StyleSet()->MediumFeaturesChanged(this)
|
|
|
|
: false;
|
|
|
|
|
2012-11-09 10:40:41 +04:00
|
|
|
if (aShouldRebuild == eAlwaysRebuildStyle ||
|
|
|
|
mediaFeaturesDidChange ||
|
|
|
|
(mUsesViewportUnits && mPendingViewportChange)) {
|
|
|
|
RebuildAllStyleData(aChangeHint);
|
2008-07-26 20:14:48 +04:00
|
|
|
}
|
2011-04-22 07:17:31 +04:00
|
|
|
|
2012-10-20 03:21:06 +04:00
|
|
|
mPendingViewportChange = false;
|
|
|
|
|
2011-04-22 07:17:31 +04:00
|
|
|
if (!nsContentUtils::IsSafeToRunScript()) {
|
|
|
|
NS_ABORT_IF_FALSE(mDocument->IsBeingUsedAsImage(),
|
|
|
|
"How did we get here? Are we failing to notify "
|
|
|
|
"listeners that we should notify?");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Media query list listeners should be notified from a queued task
|
|
|
|
// (in HTML5 terms), although we also want to notify them on certain
|
|
|
|
// flushes. (We're already running off an event.)
|
|
|
|
//
|
|
|
|
// Note that we do this after the new style from media queries in
|
|
|
|
// style sheets has been computed.
|
|
|
|
|
|
|
|
if (!PR_CLIST_IS_EMPTY(&mDOMMediaQueryLists)) {
|
|
|
|
// We build a list of all the notifications we're going to send
|
|
|
|
// before we send any of them. (The spec says the notifications
|
|
|
|
// should be a queued task, so any removals that happen during the
|
|
|
|
// notifications shouldn't affect what gets notified.) Furthermore,
|
|
|
|
// we hold strong pointers to everything we're going to make
|
|
|
|
// notification calls to, since each notification involves calling
|
|
|
|
// arbitrary script that might otherwise destroy these objects, or,
|
|
|
|
// for that matter, |this|.
|
|
|
|
//
|
|
|
|
// Note that we intentionally send the notifications to media query
|
|
|
|
// list in the order they were created and, for each list, to the
|
|
|
|
// listeners in the order added.
|
|
|
|
nsDOMMediaQueryList::NotifyList notifyList;
|
|
|
|
for (PRCList *l = PR_LIST_HEAD(&mDOMMediaQueryLists);
|
|
|
|
l != &mDOMMediaQueryLists; l = PR_NEXT_LINK(l)) {
|
|
|
|
nsDOMMediaQueryList *mql = static_cast<nsDOMMediaQueryList*>(l);
|
|
|
|
mql->MediumFeaturesChanged(notifyList);
|
|
|
|
}
|
|
|
|
|
2011-04-24 00:19:01 +04:00
|
|
|
if (!notifyList.IsEmpty()) {
|
|
|
|
nsPIDOMWindow *win = mDocument->GetInnerWindow();
|
2013-04-06 04:44:26 +04:00
|
|
|
nsCOMPtr<EventTarget> et = do_QueryInterface(win);
|
2011-04-24 00:19:01 +04:00
|
|
|
nsCxPusher pusher;
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0, i_end = notifyList.Length(); i != i_end; ++i) {
|
2011-04-24 00:19:01 +04:00
|
|
|
if (pusher.RePush(et)) {
|
2012-04-04 10:23:45 +04:00
|
|
|
nsAutoMicroTask mt;
|
2011-04-24 00:19:01 +04:00
|
|
|
nsDOMMediaQueryList::HandleChangeData &d = notifyList[i];
|
|
|
|
d.listener->HandleChange(d.mql);
|
|
|
|
}
|
|
|
|
}
|
2011-04-22 07:17:31 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// NOTE: When |notifyList| goes out of scope, our destructor could run.
|
|
|
|
}
|
2008-07-26 20:14:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsPresContext::PostMediaFeatureValuesChangedEvent()
|
|
|
|
{
|
2011-04-22 07:17:31 +04:00
|
|
|
// FIXME: We should probably replace this event with use of
|
|
|
|
// nsRefreshDriver::AddStyleFlushObserver (except the pres shell would
|
|
|
|
// need to track whether it's been added).
|
2008-07-26 20:14:48 +04:00
|
|
|
if (!mPendingMediaFeatureValuesChanged) {
|
|
|
|
nsCOMPtr<nsIRunnable> ev =
|
2010-04-21 03:21:35 +04:00
|
|
|
NS_NewRunnableMethod(this, &nsPresContext::HandleMediaFeatureValuesChangedEvent);
|
2008-07-26 20:14:48 +04:00
|
|
|
if (NS_SUCCEEDED(NS_DispatchToCurrentThread(ev))) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mPendingMediaFeatureValuesChanged = true;
|
2011-12-15 08:42:15 +04:00
|
|
|
mDocument->SetNeedStyleFlush();
|
2008-07-26 20:14:48 +04: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) {
|
2012-11-09 10:40:41 +04:00
|
|
|
MediaFeatureValuesChanged(eRebuildStyleIfNeeded);
|
2008-07-26 20:14:48 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-22 07:17:31 +04:00
|
|
|
void
|
|
|
|
nsPresContext::MatchMedia(const nsAString& aMediaQueryList,
|
|
|
|
nsIDOMMediaQueryList** aResult)
|
|
|
|
{
|
|
|
|
nsRefPtr<nsDOMMediaQueryList> result =
|
|
|
|
new nsDOMMediaQueryList(this, aMediaQueryList);
|
|
|
|
|
|
|
|
// Insert the new item at the end of the linked list.
|
|
|
|
PR_INSERT_BEFORE(result, &mDOMMediaQueryLists);
|
|
|
|
|
|
|
|
result.forget(aResult);
|
|
|
|
}
|
|
|
|
|
2012-07-30 08:29:41 +04:00
|
|
|
nsCompatibility
|
|
|
|
nsPresContext::CompatibilityMode() const
|
|
|
|
{
|
|
|
|
return Document()->GetCompatibilityMode();
|
|
|
|
}
|
|
|
|
|
2004-07-29 23:41:39 +04:00
|
|
|
void
|
2011-09-29 10:19:26 +04:00
|
|
|
nsPresContext::SetPaginatedScrolling(bool aPaginated)
|
2004-07-29 23:41:39 +04:00
|
|
|
{
|
2006-04-01 05:19:28 +04:00
|
|
|
if (mType == eContext_PrintPreview || mType == eContext_PageLayout)
|
2004-07-29 23:41:39 +04:00
|
|
|
mCanPaginatedScroll = aPaginated;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::SetPrintSettings(nsIPrintSettings *aPrintSettings)
|
2004-07-29 23:41:39 +04:00
|
|
|
{
|
2006-12-26 20:47:52 +03:00
|
|
|
if (mMedium == nsGkAtoms::print)
|
2004-07-29 23:41:39 +04:00
|
|
|
mPrintSettings = aPrintSettings;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 22:00:39 +04:00
|
|
|
nsPresContext::EnsureVisible()
|
2005-01-20 06:39:09 +03:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDocShell> docShell(do_QueryReferent(mContainer));
|
|
|
|
if (docShell) {
|
|
|
|
nsCOMPtr<nsIContentViewer> cv;
|
|
|
|
docShell->GetContentViewer(getter_AddRefs(cv));
|
|
|
|
// Make sure this is the content viewer we belong with
|
2011-10-15 11:33:26 +04:00
|
|
|
if (cv) {
|
2010-03-31 15:09:11 +04:00
|
|
|
nsRefPtr<nsPresContext> currentPresContext;
|
2011-10-15 11:33:26 +04:00
|
|
|
cv->GetPresContext(getter_AddRefs(currentPresContext));
|
2005-01-20 06:39:09 +03: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 22:00:39 +04:00
|
|
|
// OK, this is us. We want to call Show() on the content viewer.
|
2012-06-04 20:26:03 +04:00
|
|
|
nsresult result = cv->Show();
|
|
|
|
if (NS_SUCCEEDED(result)) {
|
|
|
|
return true;
|
|
|
|
}
|
2005-01-20 06:39:09 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2005-01-20 06:39:09 +03:00
|
|
|
}
|
|
|
|
|
2000-04-21 18:59:47 +04:00
|
|
|
#ifdef MOZ_REFLOW_PERF
|
2004-07-29 23:41:39 +04:00
|
|
|
void
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
nsPresContext::CountReflows(const char * aName, nsIFrame * aFrame)
|
2000-04-21 18:59:47 +04:00
|
|
|
{
|
|
|
|
if (mShell) {
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
mShell->CountReflows(aName, aFrame);
|
2000-04-21 18:59:47 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2007-05-17 01:10:31 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2010-05-22 22:55:41 +04:00
|
|
|
nsPresContext::IsChromeSlow() const
|
2007-05-17 01:10:31 +04:00
|
|
|
{
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isChrome = false;
|
2007-05-17 01:10:31 +04:00
|
|
|
nsCOMPtr<nsISupports> container = GetContainer();
|
|
|
|
if (container) {
|
|
|
|
nsresult result;
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> docShell(do_QueryInterface(container, &result));
|
|
|
|
if (NS_SUCCEEDED(result) && docShell) {
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t docShellType;
|
2007-05-17 01:10:31 +04:00
|
|
|
result = docShell->GetItemType(&docShellType);
|
|
|
|
if (NS_SUCCEEDED(result)) {
|
|
|
|
isChrome = nsIDocShellTreeItem::typeChrome == docShellType;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-04-10 22:03:40 +04:00
|
|
|
mIsChrome = isChrome;
|
2011-10-17 18:59:28 +04:00
|
|
|
mIsChromeIsCached = true;
|
2010-04-10 22:03:40 +04:00
|
|
|
return mIsChrome;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsPresContext::InvalidateIsChromeCacheExternal()
|
|
|
|
{
|
|
|
|
InvalidateIsChromeCacheInternal();
|
2007-05-17 01:10:31 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
/* virtual */ bool
|
2012-08-22 19:56:38 +04:00
|
|
|
nsPresContext::HasAuthorSpecifiedRules(nsIFrame *aFrame, uint32_t ruleTypeMask) const
|
2007-10-09 03:11:01 +04:00
|
|
|
{
|
2009-01-06 22:17:05 +03:00
|
|
|
return
|
2013-02-16 09:38:33 +04:00
|
|
|
nsRuleNode::HasAuthorSpecifiedRules(aFrame->StyleContext(),
|
2009-06-17 02:05:12 +04:00
|
|
|
ruleTypeMask,
|
|
|
|
UseDocumentColors());
|
2007-10-09 03:11:01 +04:00
|
|
|
}
|
2008-09-18 13:47:21 +04:00
|
|
|
|
2008-11-26 02:22:38 +03:00
|
|
|
gfxUserFontSet*
|
2008-12-04 19:09:53 +03:00
|
|
|
nsPresContext::GetUserFontSetInternal()
|
2008-10-01 07:01:53 +04:00
|
|
|
{
|
2008-11-26 02:22:38 +03:00
|
|
|
// We want to initialize the user font set lazily the first time the
|
|
|
|
// user asks for it, rather than building it too early and forcing
|
|
|
|
// rule cascade creation. Thus we try to enforce the invariant that
|
|
|
|
// we *never* build the user font set until the first call to
|
|
|
|
// GetUserFontSet. However, once it's been requested, we can't wait
|
|
|
|
// for somebody to call GetUserFontSet in order to rebuild it (see
|
|
|
|
// comments below in RebuildUserFontSet for why).
|
2009-01-28 03:31:26 +03:00
|
|
|
#ifdef DEBUG
|
2011-09-29 10:19:26 +04:00
|
|
|
bool userFontSetGottenBefore = mGetUserFontSetCalled;
|
2009-01-28 03:31:26 +03:00
|
|
|
#endif
|
|
|
|
// Set mGetUserFontSetCalled up front, so that FlushUserFontSet will actually
|
|
|
|
// flush.
|
2011-10-17 18:59:28 +04:00
|
|
|
mGetUserFontSetCalled = true;
|
2008-11-26 02:22:38 +03:00
|
|
|
if (mUserFontSetDirty) {
|
2008-11-26 02:22:38 +03:00
|
|
|
// If this assertion fails, and there have actually been changes to
|
|
|
|
// @font-face rules, then we will call StyleChangeReflow in
|
2008-11-27 23:31:04 +03:00
|
|
|
// FlushUserFontSet. If we're in the middle of reflow,
|
|
|
|
// that's a bad thing to do, and the caller was responsible for
|
|
|
|
// flushing first. If we're not (e.g., in frame construction), it's
|
|
|
|
// ok.
|
2010-04-11 00:15:22 +04:00
|
|
|
NS_ASSERTION(!userFontSetGottenBefore || !mShell->IsReflowLocked(),
|
|
|
|
"FlushUserFontSet should have been called first");
|
2008-11-26 02:22:38 +03:00
|
|
|
FlushUserFontSet();
|
|
|
|
}
|
|
|
|
|
|
|
|
return mUserFontSet;
|
|
|
|
}
|
|
|
|
|
2008-12-04 19:09:53 +03:00
|
|
|
gfxUserFontSet*
|
|
|
|
nsPresContext::GetUserFontSetExternal()
|
|
|
|
{
|
|
|
|
return GetUserFontSetInternal();
|
|
|
|
}
|
|
|
|
|
2008-11-26 02:22:38 +03:00
|
|
|
void
|
|
|
|
nsPresContext::FlushUserFontSet()
|
|
|
|
{
|
2011-04-12 14:53:20 +04:00
|
|
|
if (!mShell) {
|
2008-11-26 02:22:38 +03:00
|
|
|
return; // we've been torn down
|
2011-04-12 14:53:20 +04:00
|
|
|
}
|
2008-11-26 02:22:38 +03:00
|
|
|
|
2009-01-28 03:31:26 +03:00
|
|
|
if (!mGetUserFontSetCalled) {
|
|
|
|
return; // No one cares about this font set yet, but we want to be careful
|
|
|
|
// to not unset our mUserFontSetDirty bit, so when someone really
|
|
|
|
// does we'll create it.
|
|
|
|
}
|
|
|
|
|
2008-11-26 02:22:38 +03:00
|
|
|
if (mUserFontSetDirty) {
|
2008-11-26 02:22:38 +03:00
|
|
|
if (gfxPlatform::GetPlatform()->DownloadableFontsEnabled()) {
|
2008-11-27 06:50:16 +03:00
|
|
|
nsTArray<nsFontFaceRuleContainer> rules;
|
2011-04-12 14:53:20 +04:00
|
|
|
if (!mShell->StyleSet()->AppendFontFaceRules(this, rules)) {
|
|
|
|
if (mUserFontSet) {
|
|
|
|
mUserFontSet->Destroy();
|
|
|
|
NS_RELEASE(mUserFontSet);
|
2011-04-12 16:28:53 +04:00
|
|
|
}
|
2011-04-12 14:53:20 +04:00
|
|
|
return;
|
2011-04-12 16:28:53 +04:00
|
|
|
}
|
2011-04-12 14:53:20 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool changed = false;
|
2011-04-12 14:53:20 +04:00
|
|
|
|
|
|
|
if (rules.Length() == 0) {
|
2009-01-19 12:21:29 +03:00
|
|
|
if (mUserFontSet) {
|
|
|
|
mUserFontSet->Destroy();
|
|
|
|
NS_RELEASE(mUserFontSet);
|
2011-10-17 18:59:28 +04:00
|
|
|
changed = true;
|
2009-01-19 12:21:29 +03:00
|
|
|
}
|
2011-04-12 14:53:20 +04:00
|
|
|
} else {
|
|
|
|
if (!mUserFontSet) {
|
|
|
|
mUserFontSet = new nsUserFontSet(this);
|
2011-04-12 16:28:53 +04:00
|
|
|
NS_ADDREF(mUserFontSet);
|
|
|
|
}
|
2011-04-12 14:53:20 +04:00
|
|
|
changed = mUserFontSet->UpdateRules(rules);
|
2008-11-26 02:22:38 +03:00
|
|
|
}
|
2008-11-26 02:22:38 +03:00
|
|
|
|
2011-04-12 14:53:20 +04:00
|
|
|
// We need to enqueue a style change reflow (for later) to
|
|
|
|
// reflect that we're modifying @font-face rules. (However,
|
|
|
|
// without a reflow, nothing will happen to start any downloads
|
|
|
|
// that are needed.)
|
|
|
|
if (changed) {
|
2008-12-08 19:08:05 +03:00
|
|
|
UserFontSetUpdated();
|
2008-11-26 02:22:38 +03:00
|
|
|
}
|
2008-11-26 02:22:38 +03:00
|
|
|
}
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mUserFontSetDirty = false;
|
2008-11-26 02:22:38 +03:00
|
|
|
}
|
2008-11-26 02:22:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsPresContext::RebuildUserFontSet()
|
|
|
|
{
|
|
|
|
if (!mGetUserFontSetCalled) {
|
|
|
|
// We want to lazily build the user font set the first time it's
|
|
|
|
// requested (so we don't force creation of rule cascades too
|
|
|
|
// early), so don't do anything now.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mUserFontSetDirty = true;
|
2011-12-15 08:42:15 +04:00
|
|
|
mDocument->SetNeedStyleFlush();
|
2008-11-26 02:22:38 +03: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-21 03:21:35 +04:00
|
|
|
NS_NewRunnableMethod(this, &nsPresContext::HandleRebuildUserFontSet);
|
2008-11-26 02:22:38 +03:00
|
|
|
if (NS_SUCCEEDED(NS_DispatchToCurrentThread(ev))) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mPostedFlushUserFontSet = true;
|
2008-11-26 02:22:38 +03:00
|
|
|
}
|
|
|
|
}
|
2008-10-01 07:01:53 +04:00
|
|
|
}
|
|
|
|
|
2008-12-08 19:08:05 +03:00
|
|
|
void
|
|
|
|
nsPresContext::UserFontSetUpdated()
|
|
|
|
{
|
|
|
|
if (!mShell)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Changes to the set of available fonts can cause updates to layout by:
|
|
|
|
//
|
|
|
|
// 1. Changing the font used for text, which changes anything that
|
|
|
|
// depends on text measurement, including line breaking and
|
|
|
|
// intrinsic widths, and any other parts of layout that depend on
|
|
|
|
// font metrics. This requires a style change reflow to update.
|
|
|
|
//
|
|
|
|
// 2. Changing the value of the 'ex' and 'ch' units in style data,
|
|
|
|
// which also depend on font metrics. Updating this information
|
|
|
|
// requires rebuilding the rule tree from the top, avoiding the
|
|
|
|
// reuse of cached data even when no style rules have changed.
|
|
|
|
|
|
|
|
PostRebuildAllStyleDataEvent(NS_STYLE_HINT_REFLOW);
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2009-12-31 18:56:33 +03:00
|
|
|
nsPresContext::EnsureSafeToHandOutCSSRules()
|
|
|
|
{
|
|
|
|
nsCSSStyleSheet::EnsureUniqueInnerResult res =
|
|
|
|
mShell->StyleSet()->EnsureUniqueInnerOnCSSSheets();
|
|
|
|
if (res == nsCSSStyleSheet::eUniqueInner_AlreadyUnique) {
|
|
|
|
// Nothing to do.
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2009-12-31 18:56:33 +03:00
|
|
|
}
|
|
|
|
if (res == nsCSSStyleSheet::eUniqueInner_CloneFailed) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2009-12-31 18:56:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_ABORT_IF_FALSE(res == nsCSSStyleSheet::eUniqueInner_ClonedInner,
|
|
|
|
"unexpected result");
|
|
|
|
RebuildAllStyleData(nsChangeHint(0));
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2009-12-31 18:56:33 +03:00
|
|
|
}
|
|
|
|
|
2008-09-18 13:47:21 +04:00
|
|
|
void
|
2012-10-19 08:50:34 +04:00
|
|
|
nsPresContext::FireDOMPaintEvent(nsInvalidateRequestList* aList)
|
2008-09-18 13:47:21 +04:00
|
|
|
{
|
2009-06-23 13:09:05 +04:00
|
|
|
nsPIDOMWindow* ourWindow = mDocument->GetWindow();
|
2008-10-16 01:06:32 +04:00
|
|
|
if (!ourWindow)
|
2008-09-18 13:47:21 +04:00
|
|
|
return;
|
2008-10-16 01:06:32 +04:00
|
|
|
|
2013-03-09 15:34:29 +04:00
|
|
|
nsCOMPtr<EventTarget> dispatchTarget = do_QueryInterface(ourWindow);
|
|
|
|
nsCOMPtr<EventTarget> eventTarget = dispatchTarget;
|
2012-08-29 09:47:18 +04:00
|
|
|
if (!IsChrome() && !mSendAfterPaintToContent) {
|
|
|
|
// Don't tell the window about this event, it should not know that
|
|
|
|
// something happened in a subdocument. Tell only the chrome event handler.
|
|
|
|
// (Events sent to the window get propagated to the chrome event handler
|
|
|
|
// automatically.)
|
|
|
|
dispatchTarget = do_QueryInterface(ourWindow->GetParentTarget());
|
|
|
|
if (!dispatchTarget) {
|
|
|
|
return;
|
2008-10-19 00:10:19 +04:00
|
|
|
}
|
2008-09-18 13:47:21 +04:00
|
|
|
}
|
|
|
|
// Events sent to the window get propagated to the chrome event handler
|
|
|
|
// automatically.
|
2009-06-23 13:09:05 +04:00
|
|
|
nsCOMPtr<nsIDOMEvent> event;
|
2009-09-04 08:49:18 +04:00
|
|
|
// This will empty our list in case dispatching the event causes more damage
|
|
|
|
// (hopefully it won't, or we're likely to get an infinite loop! At least
|
|
|
|
// it won't be blocking app execution though).
|
2013-03-09 15:34:29 +04:00
|
|
|
NS_NewDOMNotifyPaintEvent(getter_AddRefs(event), eventTarget, this, nullptr,
|
2012-10-19 08:50:34 +04:00
|
|
|
NS_AFTERPAINT, aList);
|
2012-06-11 03:44:50 +04:00
|
|
|
if (!event) {
|
|
|
|
return;
|
|
|
|
}
|
2008-09-18 13:47:21 +04:00
|
|
|
|
|
|
|
// Even if we're not telling the window about the event (so eventTarget is
|
|
|
|
// the chrome event handler, not the window), the window is still
|
|
|
|
// logically the event target.
|
2012-06-11 03:44:50 +04:00
|
|
|
event->SetTarget(eventTarget);
|
|
|
|
event->SetTrusted(true);
|
2012-07-30 18:20:58 +04:00
|
|
|
nsEventDispatcher::DispatchDOMEvent(dispatchTarget, nullptr, event, this, nullptr);
|
2008-09-18 13:47:21 +04:00
|
|
|
}
|
|
|
|
|
2012-08-29 09:47:18 +04:00
|
|
|
static bool
|
|
|
|
MayHavePaintEventListenerSubdocumentCallback(nsIDocument* aDocument, void* aData)
|
|
|
|
{
|
|
|
|
bool *result = static_cast<bool*>(aData);
|
|
|
|
nsIPresShell* shell = aDocument->GetShell();
|
|
|
|
if (shell) {
|
|
|
|
nsPresContext* pc = shell->GetPresContext();
|
|
|
|
if (pc) {
|
2012-08-29 09:47:18 +04:00
|
|
|
*result = pc->MayHavePaintEventListenerInSubDocument();
|
2012-08-29 09:47:18 +04:00
|
|
|
|
|
|
|
// If we found a paint event listener, then we can stop enumerating
|
|
|
|
// sub documents.
|
|
|
|
return !*result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool
|
2009-09-04 08:49:18 +04:00
|
|
|
MayHavePaintEventListener(nsPIDOMWindow* aInnerWindow)
|
2008-10-16 01:06:32 +04:00
|
|
|
{
|
|
|
|
if (!aInnerWindow)
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2008-10-16 01:06:32 +04:00
|
|
|
if (aInnerWindow->HasPaintEventListeners())
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2008-10-16 01:06:32 +04:00
|
|
|
|
2013-04-20 02:18:33 +04:00
|
|
|
EventTarget* parentTarget = aInnerWindow->GetParentTarget();
|
2010-06-16 15:43:36 +04:00
|
|
|
if (!parentTarget)
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2008-10-16 01:06:32 +04:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
nsEventListenerManager* manager = nullptr;
|
2011-10-17 18:59:28 +04:00
|
|
|
if ((manager = parentTarget->GetListenerManager(false)) &&
|
2010-06-16 15:43:36 +04:00
|
|
|
manager->MayHavePaintEventListener()) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2010-06-16 15:43:36 +04:00
|
|
|
}
|
|
|
|
|
2010-05-18 16:28:37 +04:00
|
|
|
nsCOMPtr<nsINode> node;
|
2010-06-16 15:43:36 +04:00
|
|
|
if (parentTarget != aInnerWindow->GetChromeEventHandler()) {
|
|
|
|
nsCOMPtr<nsIInProcessContentFrameMessageManager> mm =
|
|
|
|
do_QueryInterface(parentTarget);
|
|
|
|
if (mm) {
|
|
|
|
node = mm->GetOwnerContent();
|
2010-05-18 16:28:37 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!node) {
|
2010-06-16 15:43:36 +04:00
|
|
|
node = do_QueryInterface(parentTarget);
|
2010-05-18 16:28:37 +04:00
|
|
|
}
|
2008-10-16 01:06:32 +04:00
|
|
|
if (node)
|
2011-10-18 14:53:36 +04:00
|
|
|
return MayHavePaintEventListener(node->OwnerDoc()->GetInnerWindow());
|
2008-10-16 01:06:32 +04:00
|
|
|
|
2010-06-16 15:43:36 +04:00
|
|
|
nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(parentTarget);
|
2008-10-16 01:06:32 +04:00
|
|
|
if (window)
|
|
|
|
return MayHavePaintEventListener(window);
|
|
|
|
|
2010-07-01 08:04:29 +04:00
|
|
|
nsCOMPtr<nsPIWindowRoot> root = do_QueryInterface(parentTarget);
|
2013-04-20 02:18:33 +04:00
|
|
|
EventTarget* tabChildGlobal;
|
2010-07-01 08:04:29 +04:00
|
|
|
return root &&
|
|
|
|
(tabChildGlobal = root->GetParentTarget()) &&
|
2011-10-17 18:59:28 +04:00
|
|
|
(manager = tabChildGlobal->GetListenerManager(false)) &&
|
2010-07-01 08:04:29 +04:00
|
|
|
manager->MayHavePaintEventListener();
|
2008-10-16 01:06:32 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2009-09-04 08:49:18 +04:00
|
|
|
nsPresContext::MayHavePaintEventListener()
|
|
|
|
{
|
|
|
|
return ::MayHavePaintEventListener(mDocument->GetInnerWindow());
|
|
|
|
}
|
|
|
|
|
2012-08-29 09:47:18 +04:00
|
|
|
bool
|
|
|
|
nsPresContext::MayHavePaintEventListenerInSubDocument()
|
|
|
|
{
|
|
|
|
if (MayHavePaintEventListener()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool result = false;
|
|
|
|
mDocument->EnumerateSubDocuments(MayHavePaintEventListenerSubdocumentCallback, &result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2012-08-29 09:48:44 +04:00
|
|
|
void
|
|
|
|
nsPresContext::NotifyInvalidation(uint32_t aFlags)
|
|
|
|
{
|
|
|
|
nsIFrame* rootFrame = PresShell()->FrameManager()->GetRootFrame();
|
|
|
|
NotifyInvalidation(rootFrame->GetVisualOverflowRect(), aFlags);
|
|
|
|
mAllInvalidated = true;
|
|
|
|
}
|
|
|
|
|
2012-08-29 09:47:18 +04:00
|
|
|
void
|
|
|
|
nsPresContext::NotifyInvalidation(const nsIntRect& aRect, uint32_t aFlags)
|
|
|
|
{
|
|
|
|
nsRect rect(DevPixelsToAppUnits(aRect.x),
|
|
|
|
DevPixelsToAppUnits(aRect.y),
|
|
|
|
DevPixelsToAppUnits(aRect.width),
|
|
|
|
DevPixelsToAppUnits(aRect.height));
|
|
|
|
NotifyInvalidation(rect, aFlags);
|
|
|
|
}
|
|
|
|
|
2008-09-18 13:47:21 +04:00
|
|
|
void
|
2012-08-22 19:56:38 +04:00
|
|
|
nsPresContext::NotifyInvalidation(const nsRect& aRect, uint32_t aFlags)
|
2008-09-18 13:47:21 +04:00
|
|
|
{
|
2008-10-16 01:06:32 +04:00
|
|
|
// If there is no paint event listener, then we don't need to fire
|
|
|
|
// the asynchronous event. We don't even need to record invalidation.
|
|
|
|
// MayHavePaintEventListener is pretty cheap and we could make it
|
|
|
|
// even cheaper by providing a more efficient
|
|
|
|
// nsPIDOMWindow::GetListenerManager.
|
2012-08-29 09:48:44 +04:00
|
|
|
|
|
|
|
if (mAllInvalidated) {
|
|
|
|
return;
|
|
|
|
}
|
2008-09-18 13:47:21 +04:00
|
|
|
|
2011-01-15 12:40:33 +03:00
|
|
|
nsPresContext* pc;
|
2012-05-04 09:00:57 +04:00
|
|
|
for (pc = this; pc; pc = pc->GetParentPresContext()) {
|
2011-01-15 12:40:33 +03:00
|
|
|
if (pc->mFireAfterPaintEvents)
|
|
|
|
break;
|
2011-10-17 18:59:28 +04:00
|
|
|
pc->mFireAfterPaintEvents = true;
|
2011-01-15 12:40:33 +03:00
|
|
|
}
|
|
|
|
if (!pc) {
|
|
|
|
nsRootPresContext* rpc = GetRootPresContext();
|
|
|
|
if (rpc) {
|
|
|
|
rpc->EnsureEventualDidPaintEvent();
|
|
|
|
}
|
2008-09-18 13:47:21 +04:00
|
|
|
}
|
|
|
|
|
2009-09-04 08:49:18 +04:00
|
|
|
nsInvalidateRequestList::Request* request =
|
2012-10-19 08:50:34 +04:00
|
|
|
mInvalidateRequestsSinceLastPaint.mRequests.AppendElement();
|
2009-09-04 08:49:18 +04:00
|
|
|
if (!request)
|
|
|
|
return;
|
|
|
|
|
|
|
|
request->mRect = aRect;
|
|
|
|
request->mFlags = aFlags;
|
2008-09-18 13:47:21 +04:00
|
|
|
}
|
2008-12-29 18:07:36 +03:00
|
|
|
|
2012-08-29 09:47:18 +04:00
|
|
|
/* static */ void
|
|
|
|
nsPresContext::NotifySubDocInvalidation(ContainerLayer* aContainer,
|
|
|
|
const nsIntRegion& aRegion)
|
|
|
|
{
|
|
|
|
ContainerLayerPresContext *data =
|
|
|
|
static_cast<ContainerLayerPresContext*>(
|
|
|
|
aContainer->GetUserData(&gNotifySubDocInvalidationData));
|
|
|
|
if (!data) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIntPoint topLeft = aContainer->GetVisibleRegion().GetBounds().TopLeft();
|
|
|
|
|
|
|
|
nsIntRegionRectIterator iter(aRegion);
|
|
|
|
while (const nsIntRect* r = iter.Next()) {
|
|
|
|
nsIntRect rect = *r;
|
|
|
|
//PresContext coordinate space is relative to the start of our visible
|
|
|
|
// region. Is this really true? This feels like the wrong way to get the right
|
|
|
|
// answer.
|
|
|
|
rect.MoveBy(-topLeft);
|
|
|
|
data->mPresContext->NotifyInvalidation(rect, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-14 15:33:03 +04:00
|
|
|
void
|
|
|
|
nsPresContext::SetNotifySubDocInvalidationData(ContainerLayer* aContainer)
|
|
|
|
{
|
|
|
|
ContainerLayerPresContext* pres = new ContainerLayerPresContext;
|
|
|
|
pres->mPresContext = this;
|
|
|
|
aContainer->SetUserData(&gNotifySubDocInvalidationData, pres);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ void
|
|
|
|
nsPresContext::ClearNotifySubDocInvalidationData(ContainerLayer* aContainer)
|
|
|
|
{
|
|
|
|
aContainer->SetUserData(&gNotifySubDocInvalidationData, nullptr);
|
|
|
|
}
|
|
|
|
|
2012-10-19 08:50:34 +04:00
|
|
|
struct NotifyDidPaintSubdocumentCallbackClosure {
|
|
|
|
uint32_t mFlags;
|
|
|
|
bool mNeedsAnotherDidPaintNotification;
|
|
|
|
};
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool
|
2011-01-15 12:40:33 +03:00
|
|
|
NotifyDidPaintSubdocumentCallback(nsIDocument* aDocument, void* aData)
|
|
|
|
{
|
2012-10-19 08:50:34 +04:00
|
|
|
NotifyDidPaintSubdocumentCallbackClosure* closure =
|
|
|
|
static_cast<NotifyDidPaintSubdocumentCallbackClosure*>(aData);
|
2011-01-15 12:40:33 +03:00
|
|
|
nsIPresShell* shell = aDocument->GetShell();
|
|
|
|
if (shell) {
|
|
|
|
nsPresContext* pc = shell->GetPresContext();
|
|
|
|
if (pc) {
|
2012-10-19 08:50:34 +04:00
|
|
|
pc->NotifyDidPaintForSubtree(closure->mFlags);
|
|
|
|
if (pc->IsDOMPaintEventPending()) {
|
|
|
|
closure->mNeedsAnotherDidPaintNotification = true;
|
|
|
|
}
|
2011-01-15 12:40:33 +03:00
|
|
|
}
|
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2011-01-15 12:40:33 +03:00
|
|
|
}
|
|
|
|
|
2012-10-19 08:50:34 +04:00
|
|
|
class DelayedFireDOMPaintEvent : public nsRunnable {
|
|
|
|
public:
|
|
|
|
DelayedFireDOMPaintEvent(nsPresContext* aPresContext,
|
|
|
|
nsInvalidateRequestList* aList)
|
|
|
|
: mPresContext(aPresContext)
|
|
|
|
{
|
|
|
|
mList.TakeFrom(aList);
|
|
|
|
}
|
|
|
|
NS_IMETHOD Run()
|
|
|
|
{
|
|
|
|
mPresContext->FireDOMPaintEvent(&mList);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<nsPresContext> mPresContext;
|
|
|
|
nsInvalidateRequestList mList;
|
|
|
|
};
|
|
|
|
|
2011-01-15 12:40:33 +03:00
|
|
|
void
|
2012-10-19 08:50:34 +04:00
|
|
|
nsPresContext::NotifyDidPaintForSubtree(uint32_t aFlags)
|
2011-01-15 12:40:33 +03:00
|
|
|
{
|
2012-09-27 19:34:46 +04:00
|
|
|
if (IsRoot()) {
|
2011-01-15 12:40:33 +03:00
|
|
|
static_cast<nsRootPresContext*>(this)->CancelDidPaintTimer();
|
|
|
|
|
2012-10-23 05:52:48 +04:00
|
|
|
if (!mFireAfterPaintEvents) {
|
|
|
|
return;
|
|
|
|
}
|
2012-10-19 08:50:34 +04:00
|
|
|
}
|
2012-10-23 05:52:48 +04:00
|
|
|
// Non-root prescontexts fire MozAfterPaint to all their descendants
|
|
|
|
// unconditionally, even if no invalidations have been collected. This is
|
|
|
|
// because we don't want to eat the cost of collecting invalidations for
|
|
|
|
// every subdocument (which would require putting every subdocument in its
|
|
|
|
// own layer).
|
2012-08-29 09:47:18 +04:00
|
|
|
|
2012-10-19 08:50:34 +04:00
|
|
|
if (aFlags & nsIPresShell::PAINT_LAYERS) {
|
|
|
|
mUndeliveredInvalidateRequestsBeforeLastPaint.TakeFrom(
|
|
|
|
&mInvalidateRequestsSinceLastPaint);
|
|
|
|
mAllInvalidated = false;
|
|
|
|
}
|
|
|
|
if (aFlags & nsIPresShell::PAINT_COMPOSITE) {
|
|
|
|
nsCOMPtr<nsIRunnable> ev =
|
|
|
|
new DelayedFireDOMPaintEvent(this, &mUndeliveredInvalidateRequestsBeforeLastPaint);
|
|
|
|
nsContentUtils::AddScriptRunner(ev);
|
|
|
|
}
|
|
|
|
|
|
|
|
NotifyDidPaintSubdocumentCallbackClosure closure = { aFlags, false };
|
|
|
|
mDocument->EnumerateSubDocuments(NotifyDidPaintSubdocumentCallback, &closure);
|
2011-01-15 12:40:33 +03:00
|
|
|
|
2012-10-19 08:50:34 +04:00
|
|
|
if (!closure.mNeedsAnotherDidPaintNotification &&
|
|
|
|
mInvalidateRequestsSinceLastPaint.IsEmpty() &&
|
|
|
|
mUndeliveredInvalidateRequestsBeforeLastPaint.IsEmpty()) {
|
|
|
|
// Nothing more to do for the moment.
|
|
|
|
mFireAfterPaintEvents = false;
|
|
|
|
} else {
|
|
|
|
if (IsRoot()) {
|
|
|
|
static_cast<nsRootPresContext*>(this)->EnsureEventualDidPaintEvent();
|
|
|
|
}
|
|
|
|
}
|
2011-01-15 12:40:33 +03:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2008-12-29 18:07:36 +03:00
|
|
|
nsPresContext::HasCachedStyleData()
|
|
|
|
{
|
|
|
|
return mShell && mShell->StyleSet()->HasCachedStyleData();
|
|
|
|
}
|
2009-04-22 03:53:52 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool sGotInterruptEnv = false;
|
2009-04-22 03:53:52 +04:00
|
|
|
enum InterruptMode {
|
|
|
|
ModeRandom,
|
|
|
|
ModeCounter,
|
|
|
|
ModeEvent
|
|
|
|
};
|
2009-10-02 22:05:32 +04:00
|
|
|
// Controlled by the GECKO_REFLOW_INTERRUPT_MODE env var; allowed values are
|
|
|
|
// "random" (except on Windows) or "counter". If neither is used, the mode is
|
|
|
|
// ModeEvent.
|
2009-04-22 03:53:52 +04:00
|
|
|
static InterruptMode sInterruptMode = ModeEvent;
|
2013-01-10 11:04:09 +04:00
|
|
|
#ifndef XP_WIN
|
2009-10-02 22:05:32 +04:00
|
|
|
// Used for the "random" mode. Controlled by the GECKO_REFLOW_INTERRUPT_SEED
|
|
|
|
// env var.
|
2012-08-22 19:56:38 +04:00
|
|
|
static uint32_t sInterruptSeed = 1;
|
2013-01-10 11:04:09 +04:00
|
|
|
#endif
|
2009-10-02 22:05:32 +04:00
|
|
|
// 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.
|
2012-08-22 19:56:38 +04:00
|
|
|
static uint32_t sInterruptMaxCounter = 10;
|
2009-10-02 22:05:32 +04:00
|
|
|
// Used for the "counter" mode. This counts up to sInterruptMaxCounter and is
|
|
|
|
// then reset to 0.
|
2012-08-22 19:56:38 +04:00
|
|
|
static uint32_t sInterruptCounter;
|
2009-10-02 22:05:32 +04:00
|
|
|
// Number of interrupt checks to skip before really trying to interrupt.
|
|
|
|
// Controlled by the GECKO_REFLOW_INTERRUPT_CHECKS_TO_SKIP env var.
|
2012-08-22 19:56:38 +04:00
|
|
|
static uint32_t sInterruptChecksToSkip = 200;
|
2009-10-02 22:05:32 +04:00
|
|
|
// Number of milliseconds that a reflow should be allowed to run for before we
|
|
|
|
// actually allow interruption. Controlled by the
|
2011-10-12 01:29:12 +04: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-22 03:53:52 +04:00
|
|
|
|
|
|
|
static void GetInterruptEnv()
|
|
|
|
{
|
|
|
|
char *ev = PR_GetEnv("GECKO_REFLOW_INTERRUPT_MODE");
|
|
|
|
if (ev) {
|
|
|
|
#ifndef XP_WIN
|
|
|
|
if (PL_strcasecmp(ev, "random") == 0) {
|
|
|
|
ev = PR_GetEnv("GECKO_REFLOW_INTERRUPT_SEED");
|
|
|
|
if (ev) {
|
|
|
|
sInterruptSeed = atoi(ev);
|
|
|
|
}
|
|
|
|
srandom(sInterruptSeed);
|
|
|
|
sInterruptMode = ModeRandom;
|
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
if (PL_strcasecmp(ev, "counter") == 0) {
|
|
|
|
ev = PR_GetEnv("GECKO_REFLOW_INTERRUPT_FREQUENCY");
|
|
|
|
if (ev) {
|
|
|
|
sInterruptMaxCounter = atoi(ev);
|
|
|
|
}
|
|
|
|
sInterruptCounter = 0;
|
|
|
|
sInterruptMode = ModeCounter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ev = PR_GetEnv("GECKO_REFLOW_INTERRUPT_CHECKS_TO_SKIP");
|
|
|
|
if (ev) {
|
|
|
|
sInterruptChecksToSkip = atoi(ev);
|
|
|
|
}
|
2009-10-02 22:05:32 +04:00
|
|
|
|
|
|
|
ev = PR_GetEnv("GECKO_REFLOW_MIN_NOINTERRUPT_DURATION");
|
2011-10-12 01:29:12 +04:00
|
|
|
int duration_ms = ev ? atoi(ev) : 100;
|
|
|
|
sInterruptTimeout = TimeDuration::FromMilliseconds(duration_ms);
|
2009-04-22 03:53:52 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2009-04-22 03:53:52 +04:00
|
|
|
nsPresContext::HavePendingInputEvent()
|
|
|
|
{
|
|
|
|
switch (sInterruptMode) {
|
|
|
|
#ifndef XP_WIN
|
|
|
|
case ModeRandom:
|
|
|
|
return (random() & 1);
|
|
|
|
#endif
|
|
|
|
case ModeCounter:
|
|
|
|
if (sInterruptCounter < sInterruptMaxCounter) {
|
|
|
|
++sInterruptCounter;
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2009-04-22 03:53:52 +04:00
|
|
|
}
|
|
|
|
sInterruptCounter = 0;
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2009-04-22 03:53:52 +04:00
|
|
|
default:
|
|
|
|
case ModeEvent: {
|
|
|
|
nsIFrame* f = PresShell()->GetRootFrame();
|
|
|
|
if (f) {
|
2010-07-02 23:11:04 +04:00
|
|
|
nsIWidget* w = f->GetNearestWidget();
|
2009-04-22 03:53:52 +04:00
|
|
|
if (w) {
|
|
|
|
return w->HasPendingInputEvent();
|
|
|
|
}
|
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2009-04-22 03:53:52 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-09-29 10:19:26 +04:00
|
|
|
nsPresContext::ReflowStarted(bool aInterruptible)
|
2009-04-22 03:53:52 +04:00
|
|
|
{
|
2009-10-02 22:05:32 +04:00
|
|
|
#ifdef NOISY_INTERRUPTIBLE_REFLOW
|
|
|
|
if (!aInterruptible) {
|
|
|
|
printf("STARTING NONINTERRUPTIBLE REFLOW\n");
|
|
|
|
}
|
|
|
|
#endif
|
2009-04-22 03:53:52 +04:00
|
|
|
// We don't support interrupting in paginated contexts, since page
|
|
|
|
// sequences only handle initial reflow
|
|
|
|
mInterruptsEnabled = aInterruptible && !IsPaginated();
|
|
|
|
|
|
|
|
// Don't set mHasPendingInterrupt based on HavePendingInputEvent() here. If
|
|
|
|
// we ever change that, then we need to update the code in
|
|
|
|
// PresShell::DoReflow to only add the just-reflown root to dirty roots if
|
|
|
|
// it's actually dirty. Otherwise we can end up adding a root that has no
|
|
|
|
// interruptible descendants, just because we detected an interrupt at reflow
|
|
|
|
// start.
|
2011-10-17 18:59:28 +04:00
|
|
|
mHasPendingInterrupt = false;
|
2009-04-22 03:53:52 +04:00
|
|
|
|
|
|
|
mInterruptChecksToSkip = sInterruptChecksToSkip;
|
2009-10-02 22:05:32 +04:00
|
|
|
|
|
|
|
if (mInterruptsEnabled) {
|
|
|
|
mReflowStartTime = TimeStamp::Now();
|
|
|
|
}
|
2009-04-22 03:53:52 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2009-04-22 03:53:52 +04:00
|
|
|
nsPresContext::CheckForInterrupt(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
if (mHasPendingInterrupt) {
|
|
|
|
mShell->FrameNeedsToContinueReflow(aFrame);
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2009-04-22 03:53:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!sGotInterruptEnv) {
|
2011-10-17 18:59:28 +04:00
|
|
|
sGotInterruptEnv = true;
|
2009-04-22 03:53:52 +04:00
|
|
|
GetInterruptEnv();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mInterruptsEnabled) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2009-04-22 03:53:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mInterruptChecksToSkip > 0) {
|
|
|
|
--mInterruptChecksToSkip;
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2009-04-22 03:53:52 +04:00
|
|
|
}
|
|
|
|
mInterruptChecksToSkip = sInterruptChecksToSkip;
|
|
|
|
|
2009-10-02 22:05:32 +04:00
|
|
|
// Don't interrupt if it's been less than sInterruptTimeout since we started
|
|
|
|
// the reflow.
|
|
|
|
mHasPendingInterrupt =
|
|
|
|
TimeStamp::Now() - mReflowStartTime > sInterruptTimeout &&
|
|
|
|
HavePendingInputEvent() &&
|
|
|
|
!IsChrome();
|
2009-04-22 03:53:52 +04:00
|
|
|
if (mHasPendingInterrupt) {
|
|
|
|
#ifdef NOISY_INTERRUPTIBLE_REFLOW
|
|
|
|
printf("*** DETECTED pending interrupt (time=%lld)\n", PR_Now());
|
|
|
|
#endif /* NOISY_INTERRUPTIBLE_REFLOW */
|
|
|
|
mShell->FrameNeedsToContinueReflow(aFrame);
|
|
|
|
}
|
|
|
|
return mHasPendingInterrupt;
|
|
|
|
}
|
2009-07-22 04:44:54 +04:00
|
|
|
|
2012-07-30 08:29:41 +04:00
|
|
|
nsIFrame*
|
|
|
|
nsPresContext::GetPrimaryFrameFor(nsIContent* aContent)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aContent, "Don't do that");
|
|
|
|
if (GetPresShell() &&
|
|
|
|
GetPresShell()->GetDocument() == aContent->GetCurrentDoc()) {
|
|
|
|
return aContent->GetPrimaryFrame();
|
|
|
|
}
|
2012-07-30 18:28:15 +04:00
|
|
|
return nullptr;
|
2012-07-30 08:29:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-21 09:02:24 +04:00
|
|
|
size_t
|
2013-06-23 16:03:39 +04:00
|
|
|
nsPresContext::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const
|
2012-02-21 09:02:24 +04:00
|
|
|
{
|
|
|
|
return mPropertyTable.SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
mLangGroupFontPrefs.SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
|
|
|
|
// Measurement of other members may be added later if DMD finds it is
|
|
|
|
// worthwhile.
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2010-09-11 22:24:50 +04:00
|
|
|
nsPresContext::IsRootContentDocument()
|
|
|
|
{
|
2010-10-09 23:09:22 +04:00
|
|
|
// We are a root content document if: we are not a resource doc, we are
|
|
|
|
// not chrome, and we either have no parent or our parent is chrome.
|
|
|
|
if (mDocument->IsResourceDoc()) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2010-10-09 23:09:22 +04:00
|
|
|
}
|
2010-09-11 22:24:50 +04:00
|
|
|
if (IsChrome()) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2010-09-11 22:24:50 +04:00
|
|
|
}
|
|
|
|
// We may not have a root frame, so use views.
|
2013-01-03 17:23:11 +04:00
|
|
|
nsView* view = PresShell()->GetViewManager()->GetRootView();
|
2011-03-30 06:24:54 +04:00
|
|
|
if (!view) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2010-09-11 22:24:50 +04:00
|
|
|
}
|
|
|
|
view = view->GetParent(); // anonymous inner view
|
|
|
|
if (!view) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2010-09-11 22:24:50 +04:00
|
|
|
}
|
|
|
|
view = view->GetParent(); // subdocumentframe's view
|
|
|
|
if (!view) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2010-09-11 22:24:50 +04:00
|
|
|
}
|
|
|
|
|
2011-11-21 21:53:20 +04:00
|
|
|
nsIFrame* f = view->GetFrame();
|
2010-09-11 22:24:50 +04:00
|
|
|
return (f && f->PresContext()->IsChrome());
|
|
|
|
}
|
|
|
|
|
2012-09-05 20:23:45 +04:00
|
|
|
bool
|
|
|
|
nsPresContext::IsCrossProcessRootContentDocument()
|
|
|
|
{
|
|
|
|
if (!IsRootContentDocument()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (XRE_GetProcessType() == GeckoProcessType_Default) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
TabChild* tabChild = GetTabChildFrom(mShell);
|
|
|
|
return (tabChild && tabChild->IsRootContentDocument());
|
|
|
|
}
|
|
|
|
|
2013-07-22 19:51:38 +04:00
|
|
|
bool nsPresContext::GetPaintFlashing() const
|
|
|
|
{
|
|
|
|
if (!mPaintFlashingInitialized) {
|
|
|
|
bool pref = Preferences::GetBool("nglayout.debug.paint_flashing");
|
|
|
|
if (!pref && IsChrome()) {
|
|
|
|
pref = Preferences::GetBool("nglayout.debug.paint_flashing_chrome");
|
|
|
|
}
|
|
|
|
mPaintFlashing = pref;
|
|
|
|
mPaintFlashingInitialized = true;
|
|
|
|
}
|
|
|
|
return mPaintFlashing;
|
|
|
|
}
|
|
|
|
|
2009-07-22 04:44:54 +04:00
|
|
|
nsRootPresContext::nsRootPresContext(nsIDocument* aDocument,
|
|
|
|
nsPresContextType aType)
|
2010-07-16 01:08:08 +04:00
|
|
|
: nsPresContext(aDocument, aType),
|
2012-10-06 17:03:23 +04:00
|
|
|
mDOMGeneration(0)
|
2009-07-22 04:44:54 +04:00
|
|
|
{
|
2010-07-16 01:08:08 +04:00
|
|
|
}
|
2009-07-22 04:45:00 +04:00
|
|
|
|
|
|
|
nsRootPresContext::~nsRootPresContext()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mRegisteredPlugins.Count() == 0,
|
|
|
|
"All plugins should have been unregistered");
|
2011-01-15 12:40:33 +03:00
|
|
|
CancelDidPaintTimer();
|
2012-10-06 17:03:23 +04:00
|
|
|
CancelApplyPluginGeometryTimer();
|
2009-07-22 04:45:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-08-14 08:06:42 +04:00
|
|
|
nsRootPresContext::RegisterPluginForGeometryUpdates(nsIContent* aPlugin)
|
2009-07-22 04:45:00 +04:00
|
|
|
{
|
|
|
|
mRegisteredPlugins.PutEntry(aPlugin);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-08-14 08:06:42 +04:00
|
|
|
nsRootPresContext::UnregisterPluginForGeometryUpdates(nsIContent* aPlugin)
|
2009-07-22 04:45:00 +04:00
|
|
|
{
|
|
|
|
mRegisteredPlugins.RemoveEntry(aPlugin);
|
|
|
|
}
|
|
|
|
|
|
|
|
static PLDHashOperator
|
2012-10-06 17:03:23 +04:00
|
|
|
SetPluginHidden(nsRefPtrHashKey<nsIContent>* aEntry, void* userArg)
|
2009-07-22 04:45:00 +04:00
|
|
|
{
|
2012-10-06 17:03:23 +04:00
|
|
|
nsIFrame* root = static_cast<nsIFrame*>(userArg);
|
2012-08-14 08:06:42 +04:00
|
|
|
nsObjectFrame* f = static_cast<nsObjectFrame*>(aEntry->GetKey()->GetPrimaryFrame());
|
|
|
|
if (!f) {
|
2012-10-06 17:03:23 +04:00
|
|
|
NS_WARNING("Null frame in SetPluginHidden");
|
2012-08-14 08:06:42 +04:00
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
2012-10-06 17:03:23 +04:00
|
|
|
if (!nsLayoutUtils::IsAncestorFrameCrossDoc(root, f)) {
|
|
|
|
// f is not managed by this frame so we should ignore it.
|
|
|
|
return PL_DHASH_NEXT;
|
2009-07-22 04:45:00 +04:00
|
|
|
}
|
2012-10-06 17:03:23 +04:00
|
|
|
f->SetEmptyWidgetConfiguration();
|
2009-07-22 04:45:00 +04:00
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
2012-10-06 17:03:23 +04:00
|
|
|
void
|
|
|
|
nsRootPresContext::ComputePluginGeometryUpdates(nsIFrame* aFrame,
|
|
|
|
nsDisplayListBuilder* aBuilder,
|
|
|
|
nsDisplayList* aList)
|
2009-07-22 04:45:00 +04:00
|
|
|
{
|
2012-10-06 17:03:23 +04:00
|
|
|
if (mRegisteredPlugins.Count() == 0) {
|
|
|
|
return;
|
2009-07-22 04:45:00 +04:00
|
|
|
}
|
|
|
|
|
2012-10-06 17:03:23 +04:00
|
|
|
// Initially make the next state for each plugin descendant of aFrame be
|
|
|
|
// "hidden". Plugins that are visible will have their next state set to
|
|
|
|
// unhidden by nsDisplayPlugin::ComputeVisibility.
|
|
|
|
mRegisteredPlugins.EnumerateEntries(SetPluginHidden, aFrame);
|
2009-07-22 04:45:00 +04:00
|
|
|
|
2012-10-06 17:03:23 +04:00
|
|
|
nsIFrame* rootFrame = FrameManager()->GetRootFrame();
|
2009-07-22 04:45:00 +04:00
|
|
|
|
2012-10-18 09:34:58 +04:00
|
|
|
if (rootFrame && aBuilder->ContainsPluginItem()) {
|
|
|
|
aBuilder->SetForPluginGeometry();
|
|
|
|
aBuilder->SetAccurateVisibleRegions();
|
|
|
|
// Merging and flattening has already been done and we should not do it
|
|
|
|
// again. nsDisplayScroll(Info)Layer doesn't support trying to flatten
|
|
|
|
// again.
|
|
|
|
aBuilder->SetAllowMergingAndFlattening(false);
|
|
|
|
nsRegion region = rootFrame->GetVisualOverflowRectRelativeToSelf();
|
|
|
|
// nsDisplayPlugin::ComputeVisibility will automatically set a non-hidden
|
|
|
|
// widget configuration for the plugin, if it's visible.
|
|
|
|
aList->ComputeVisibilityForRoot(aBuilder, ®ion);
|
|
|
|
}
|
2009-07-22 04:45:00 +04:00
|
|
|
|
2012-11-07 00:38:11 +04:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
// We control painting of Mac plugins, so just apply geometry updates now.
|
|
|
|
// This is not happening during a paint event.
|
|
|
|
ApplyPluginGeometryUpdates();
|
|
|
|
#else
|
2012-10-06 17:03:23 +04:00
|
|
|
InitApplyPluginGeometryTimer();
|
2012-11-07 00:38:11 +04:00
|
|
|
#endif
|
2012-10-06 17:03:23 +04:00
|
|
|
}
|
2009-08-21 01:52:48 +04:00
|
|
|
|
2012-10-06 17:03:23 +04:00
|
|
|
static void
|
|
|
|
ApplyPluginGeometryUpdatesCallback(nsITimer *aTimer, void *aClosure)
|
|
|
|
{
|
|
|
|
static_cast<nsRootPresContext*>(aClosure)->ApplyPluginGeometryUpdates();
|
|
|
|
}
|
2009-07-22 04:45:00 +04:00
|
|
|
|
2012-10-06 17:03:23 +04:00
|
|
|
void
|
|
|
|
nsRootPresContext::InitApplyPluginGeometryTimer()
|
|
|
|
{
|
|
|
|
if (mApplyPluginGeometryTimer) {
|
|
|
|
return;
|
|
|
|
}
|
2009-07-22 04:45:00 +04:00
|
|
|
|
2012-10-06 17:03:23 +04:00
|
|
|
// We'll apply the plugin geometry updates during the next compositing paint in this
|
|
|
|
// presContext (either from nsPresShell::WillPaintWindow or from
|
|
|
|
// nsPresShell::DidPaintWindow, depending on the platform). But paints might
|
|
|
|
// get optimized away if the old plugin geometry covers the invalid region,
|
|
|
|
// 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.
|
|
|
|
mApplyPluginGeometryTimer = do_CreateInstance("@mozilla.org/timer;1");
|
|
|
|
if (mApplyPluginGeometryTimer) {
|
|
|
|
mApplyPluginGeometryTimer->
|
|
|
|
InitWithFuncCallback(ApplyPluginGeometryUpdatesCallback, this,
|
|
|
|
nsRefreshDriver::DefaultInterval() * 2,
|
|
|
|
nsITimer::TYPE_ONE_SHOT);
|
2009-07-22 04:45:00 +04:00
|
|
|
}
|
2012-10-06 17:03:23 +04:00
|
|
|
}
|
2009-07-22 04:45:00 +04:00
|
|
|
|
2012-10-06 17:03:23 +04:00
|
|
|
void
|
|
|
|
nsRootPresContext::CancelApplyPluginGeometryTimer()
|
|
|
|
{
|
|
|
|
if (mApplyPluginGeometryTimer) {
|
|
|
|
mApplyPluginGeometryTimer->Cancel();
|
|
|
|
mApplyPluginGeometryTimer = nullptr;
|
|
|
|
}
|
2009-07-22 04:45:00 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool
|
2010-07-16 01:08:08 +04:00
|
|
|
HasOverlap(const nsIntPoint& aOffset1, const nsTArray<nsIntRect>& aClipRects1,
|
|
|
|
const nsIntPoint& aOffset2, const nsTArray<nsIntRect>& aClipRects2)
|
|
|
|
{
|
|
|
|
nsIntPoint offsetDelta = aOffset1 - aOffset2;
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0; i < aClipRects1.Length(); ++i) {
|
|
|
|
for (uint32_t j = 0; j < aClipRects2.Length(); ++j) {
|
2010-07-16 01:08:08 +04:00
|
|
|
if ((aClipRects1[i] + offsetDelta).Intersects(aClipRects2[j]))
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2010-07-16 01:08:08 +04:00
|
|
|
}
|
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2010-07-16 01:08:08 +04: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
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t i;
|
2010-07-16 01:08:08 +04:00
|
|
|
for (i = 0; i + 1 < pluginsToMove.Length(); ++i) {
|
|
|
|
nsIWidget::Configuration* config = &pluginsToMove[i];
|
2011-09-29 10:19:26 +04:00
|
|
|
bool foundOverlap = false;
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t j = 0; j < pluginsToMove.Length(); ++j) {
|
2010-07-16 01:08:08 +04:00
|
|
|
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 18:59:28 +04:00
|
|
|
foundOverlap = true;
|
2010-07-16 01:08:08 +04: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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-06 17:03:23 +04:00
|
|
|
static PLDHashOperator
|
|
|
|
PluginDidSetGeometryEnumerator(nsRefPtrHashKey<nsIContent>* aEntry, void* userArg)
|
2010-07-16 01:08:08 +04:00
|
|
|
{
|
2012-10-06 17:03:23 +04:00
|
|
|
nsObjectFrame* f = static_cast<nsObjectFrame*>(aEntry->GetKey()->GetPrimaryFrame());
|
|
|
|
if (!f) {
|
|
|
|
NS_WARNING("Null frame in PluginDidSetGeometryEnumerator");
|
|
|
|
return PL_DHASH_NEXT;
|
2010-07-16 01:08:08 +04:00
|
|
|
}
|
2012-10-06 17:03:23 +04:00
|
|
|
f->DidSetWidgetGeometry();
|
|
|
|
return PL_DHASH_NEXT;
|
2010-07-16 01:08:08 +04:00
|
|
|
}
|
|
|
|
|
2012-10-06 17:03:23 +04:00
|
|
|
struct PluginGetGeometryUpdateClosure {
|
|
|
|
nsTArray<nsIWidget::Configuration> mConfigurations;
|
|
|
|
};
|
2009-07-22 04:45:02 +04:00
|
|
|
static PLDHashOperator
|
2012-10-06 17:03:23 +04:00
|
|
|
PluginGetGeometryUpdate(nsRefPtrHashKey<nsIContent>* aEntry, void* userArg)
|
2009-07-22 04:45:02 +04:00
|
|
|
{
|
2012-10-06 17:03:23 +04:00
|
|
|
PluginGetGeometryUpdateClosure* closure =
|
|
|
|
static_cast<PluginGetGeometryUpdateClosure*>(userArg);
|
2012-08-14 08:06:42 +04:00
|
|
|
nsObjectFrame* f = static_cast<nsObjectFrame*>(aEntry->GetKey()->GetPrimaryFrame());
|
|
|
|
if (!f) {
|
2012-10-06 17:03:23 +04:00
|
|
|
NS_WARNING("Null frame in GetPluginGeometryUpdate");
|
2012-08-14 08:06:42 +04:00
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
2012-10-06 17:03:23 +04:00
|
|
|
f->GetWidgetConfiguration(&closure->mConfigurations);
|
2009-07-22 04:45:02 +04:00
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-10-06 17:03:23 +04:00
|
|
|
nsRootPresContext::ApplyPluginGeometryUpdates()
|
2009-07-22 04:45:02 +04:00
|
|
|
{
|
2012-10-06 17:03:23 +04:00
|
|
|
CancelApplyPluginGeometryTimer();
|
|
|
|
|
|
|
|
PluginGetGeometryUpdateClosure closure;
|
|
|
|
mRegisteredPlugins.EnumerateEntries(PluginGetGeometryUpdate, &closure);
|
|
|
|
// Walk mRegisteredPlugins and ask each plugin for its configuration
|
|
|
|
if (!closure.mConfigurations.IsEmpty()) {
|
|
|
|
nsIWidget* widget = closure.mConfigurations[0].mChild->GetParent();
|
|
|
|
NS_ASSERTION(widget, "Plugins must have a parent window");
|
|
|
|
SortConfigurations(&closure.mConfigurations);
|
|
|
|
widget->ConfigureChildren(closure.mConfigurations);
|
|
|
|
}
|
2012-07-30 18:20:58 +04:00
|
|
|
mRegisteredPlugins.EnumerateEntries(PluginDidSetGeometryEnumerator, nullptr);
|
2009-07-22 04:45:00 +04:00
|
|
|
}
|
2010-07-16 01:08:08 +04:00
|
|
|
|
2011-01-15 12:40:33 +03:00
|
|
|
static void
|
|
|
|
NotifyDidPaintForSubtreeCallback(nsITimer *aTimer, void *aClosure)
|
|
|
|
{
|
|
|
|
nsPresContext* presContext = (nsPresContext*)aClosure;
|
|
|
|
nsAutoScriptBlocker blockScripts;
|
2012-10-19 08:50:34 +04:00
|
|
|
// This is a fallback if we don't get paint events for some reason
|
|
|
|
// so we'll just pretend both layer painting and compositing happened.
|
|
|
|
presContext->NotifyDidPaintForSubtree(
|
|
|
|
nsIPresShell::PAINT_LAYERS | nsIPresShell::PAINT_COMPOSITE);
|
2011-01-15 12:40:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
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 08:14:31 +04: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()
|
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
mWillPaintFallbackEvent = nullptr;
|
2011-10-26 08:14:31 +04:00
|
|
|
nsTArray<nsCOMPtr<nsIRunnable> > observers;
|
|
|
|
observers.SwapElements(mWillPaintObservers);
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0; i < observers.Length(); ++i) {
|
2011-10-26 08:14:31 +04:00
|
|
|
observers[i]->Run();
|
|
|
|
}
|
|
|
|
}
|
2012-02-21 09:02:24 +04:00
|
|
|
|
|
|
|
size_t
|
2013-06-23 16:03:39 +04:00
|
|
|
nsRootPresContext::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const
|
2012-02-21 09:02:24 +04:00
|
|
|
{
|
|
|
|
return nsPresContext::SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
|
|
|
|
// Measurement of the following members may be added later if DMD finds it is
|
|
|
|
// worthwhile:
|
|
|
|
// - mNotifyDidPaintTimer
|
|
|
|
// - mRegisteredPlugins
|
|
|
|
// - mWillPaintObservers
|
|
|
|
// - mWillPaintFallbackEvent
|
|
|
|
}
|