2001-09-28 20:14:13 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00: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 05:56:38 +00:00
|
|
|
|
|
|
|
/* a presentation of a document, part 1 */
|
|
|
|
|
2014-01-30 18:26:54 +00:00
|
|
|
#include "mozilla/ArrayUtils.h"
|
2012-12-14 23:58:45 +00:00
|
|
|
#include "mozilla/DebugOnly.h"
|
2014-03-18 04:48:21 +00:00
|
|
|
#include "mozilla/EventDispatcher.h"
|
2014-04-01 04:09:23 +00:00
|
|
|
#include "mozilla/EventStateManager.h"
|
2012-12-14 23:58:45 +00:00
|
|
|
|
2012-09-05 16:23:45 +00:00
|
|
|
#include "base/basictypes.h"
|
|
|
|
|
2002-10-15 23:40:38 +00:00
|
|
|
#include "nsCOMPtr.h"
|
2004-07-31 23:15:21 +00:00
|
|
|
#include "nsPresContext.h"
|
1998-04-13 20:24:54 +00:00
|
|
|
#include "nsIPresShell.h"
|
2013-11-20 19:18:25 +00:00
|
|
|
#include "nsDocShell.h"
|
2005-01-20 03:39:09 +00:00
|
|
|
#include "nsIContentViewer.h"
|
|
|
|
#include "nsPIDOMWindow.h"
|
2016-02-24 07:01:11 +00:00
|
|
|
#include "mozilla/StyleSetHandle.h"
|
|
|
|
#include "mozilla/StyleSetHandleInlines.h"
|
2000-12-30 19:22:22 +00:00
|
|
|
#include "nsIContent.h"
|
1998-04-13 20:24:54 +00:00
|
|
|
#include "nsIFrame.h"
|
1998-09-05 03:52:40 +00:00
|
|
|
#include "nsIDocument.h"
|
2012-07-30 04:29:41 +00:00
|
|
|
#include "nsIPrintSettings.h"
|
|
|
|
#include "nsILanguageAtomService.h"
|
2011-09-09 02:27:13 +00:00
|
|
|
#include "mozilla/LookAndFeel.h"
|
2001-09-05 21:28:38 +00:00
|
|
|
#include "nsIInterfaceRequestorUtils.h"
|
2015-09-10 10:24:34 +00:00
|
|
|
#include "nsIDOMHTMLDocument.h"
|
|
|
|
#include "nsIDOMHTMLElement.h"
|
2002-11-07 00:59:25 +00:00
|
|
|
#include "nsIWeakReferenceUtils.h"
|
2006-09-12 04:36:03 +00:00
|
|
|
#include "nsThreadUtils.h"
|
2006-11-29 23:09:13 +00:00
|
|
|
#include "nsFrameManager.h"
|
|
|
|
#include "nsLayoutUtils.h"
|
2013-01-05 03:12:24 +00:00
|
|
|
#include "nsViewManager.h"
|
2016-02-24 07:01:12 +00:00
|
|
|
#include "mozilla/RestyleManager.h"
|
2016-02-24 07:01:12 +00:00
|
|
|
#include "mozilla/RestyleManagerHandle.h"
|
|
|
|
#include "mozilla/RestyleManagerHandleInlines.h"
|
2016-08-08 22:54:10 +00:00
|
|
|
#include "SurfaceCacheUtils.h"
|
2008-08-05 20:02:43 +00:00
|
|
|
#include "nsCSSRuleProcessor.h"
|
2007-10-08 23:11:01 +00:00
|
|
|
#include "nsRuleNode.h"
|
2008-11-25 23:22:38 +00:00
|
|
|
#include "gfxPlatform.h"
|
|
|
|
#include "nsCSSRules.h"
|
|
|
|
#include "nsFontFaceLoader.h"
|
2016-01-12 22:54:53 +00:00
|
|
|
#include "mozilla/EffectCompositor.h"
|
2014-03-17 06:56:53 +00:00
|
|
|
#include "mozilla/EventListenerManager.h"
|
2009-04-21 23:53:52 +00:00
|
|
|
#include "prenv.h"
|
2014-09-24 04:33:00 +00:00
|
|
|
#include "nsPluginFrame.h"
|
2009-10-08 03:22:42 +00:00
|
|
|
#include "nsTransitionManager.h"
|
2011-04-12 06:18:44 +00:00
|
|
|
#include "nsAnimationManager.h"
|
2014-06-12 01:11:00 +00:00
|
|
|
#include "CounterStyleManager.h"
|
2013-06-23 12:03:39 +00:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2010-05-05 18:18:05 +00:00
|
|
|
#include "mozilla/dom/Element.h"
|
2012-08-27 14:13:02 +00:00
|
|
|
#include "nsIMessageManager.h"
|
2013-12-16 14:03:19 +00:00
|
|
|
#include "mozilla/dom/MediaQueryList.h"
|
2009-01-15 04:38:07 +00:00
|
|
|
#include "nsSMILAnimationController.h"
|
2012-08-13 22:04:19 +00:00
|
|
|
#include "mozilla/css/ImageLoader.h"
|
2014-05-23 14:36:50 +00:00
|
|
|
#include "mozilla/dom/PBrowserParent.h"
|
2012-09-05 16:23:45 +00:00
|
|
|
#include "mozilla/dom/TabChild.h"
|
2014-05-23 14:36:50 +00:00
|
|
|
#include "mozilla/dom/TabParent.h"
|
2013-08-14 11:29:51 +00:00
|
|
|
#include "nsRefreshDriver.h"
|
2013-08-14 11:33:03 +00:00
|
|
|
#include "Layers.h"
|
2015-10-22 20:04:35 +00:00
|
|
|
#include "LayerUserData.h"
|
2015-01-29 19:41:54 +00:00
|
|
|
#include "ClientLayerManager.h"
|
2015-08-12 11:39:31 +00:00
|
|
|
#include "mozilla/dom/NotifyPaintEvent.h"
|
2014-03-04 17:26:33 +00:00
|
|
|
#include "gfxPrefs.h"
|
2014-05-23 14:36:50 +00:00
|
|
|
#include "nsIDOMChromeWindow.h"
|
|
|
|
#include "nsFrameLoader.h"
|
2014-10-02 02:32:05 +00:00
|
|
|
#include "mozilla/dom/FontFaceSet.h"
|
2004-04-30 04:06:30 +00:00
|
|
|
#include "nsContentUtils.h"
|
2010-03-01 14:47:27 +00:00
|
|
|
#include "nsPIWindowRoot.h"
|
2011-05-25 06:31:59 +00:00
|
|
|
#include "mozilla/Preferences.h"
|
2014-12-22 16:35:54 +00:00
|
|
|
#include "gfxTextRun.h"
|
2015-03-06 08:44:23 +00:00
|
|
|
#include "nsFontFaceUtils.h"
|
2015-06-16 01:34:48 +00:00
|
|
|
#include "nsLayoutStylesheetCache.h"
|
2016-09-26 12:03:25 +00:00
|
|
|
#include "mozilla/StyleSheet.h"
|
|
|
|
#include "mozilla/StyleSheetInlines.h"
|
2004-04-30 04:06:30 +00:00
|
|
|
|
2015-05-13 05:11:25 +00:00
|
|
|
#if defined(MOZ_WIDGET_GTK)
|
|
|
|
#include "gfxPlatformGtk.h" // xxx - for UseFcFontList
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2001-11-14 11:21:54 +00:00
|
|
|
// Needed for Start/Stop of Image Animation
|
|
|
|
#include "imgIContainer.h"
|
2003-03-19 03:47:09 +00:00
|
|
|
#include "nsIImageLoadingContent.h"
|
2001-11-14 11:21:54 +00:00
|
|
|
|
2011-10-11 21:29:12 +00:00
|
|
|
#include "nsCSSParser.h"
|
2013-10-07 23:15:59 +00:00
|
|
|
#include "nsBidiUtils.h"
|
|
|
|
#include "nsServiceManagerUtils.h"
|
2011-10-11 21:29:12 +00:00
|
|
|
|
2016-06-29 05:44:18 +00:00
|
|
|
#include "mozilla/dom/URL.h"
|
2014-03-07 04:02:59 +00:00
|
|
|
|
2011-04-11 20:57:29 +00:00
|
|
|
using namespace mozilla;
|
2010-04-30 13:12:05 +00:00
|
|
|
using namespace mozilla::dom;
|
2012-11-10 15:45:52 +00:00
|
|
|
using namespace mozilla::layers;
|
2009-10-02 18:05:32 +00:00
|
|
|
|
2012-08-29 05:47:18 +00:00
|
|
|
uint8_t gNotifySubDocInvalidationData;
|
|
|
|
|
2013-08-14 11:33:03 +00: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-11 20:58:44 +00:00
|
|
|
namespace {
|
|
|
|
|
2016-04-26 00:23:21 +00:00
|
|
|
class CharSetChangingRunnable : public Runnable
|
2012-01-11 20:58:44 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
CharSetChangingRunnable(nsPresContext* aPresContext,
|
|
|
|
const nsCString& aCharSet)
|
|
|
|
: mPresContext(aPresContext),
|
|
|
|
mCharSet(aCharSet)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-08-08 02:18:10 +00:00
|
|
|
NS_IMETHOD Run() override
|
2012-01-11 20:58:44 +00:00
|
|
|
{
|
|
|
|
mPresContext->DoChangeCharSet(mCharSet);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<nsPresContext> mPresContext;
|
2012-01-11 20:58:44 +00:00
|
|
|
nsCString mCharSet;
|
|
|
|
};
|
|
|
|
|
2015-07-13 15:25:42 +00:00
|
|
|
} // namespace
|
2012-01-11 20:58:44 +00:00
|
|
|
|
2012-06-06 07:36:38 +00:00
|
|
|
nscolor
|
|
|
|
nsPresContext::MakeColorPref(const nsString& aColor)
|
2001-05-08 01:40:09 +00:00
|
|
|
{
|
2011-10-11 21:29:12 +00:00
|
|
|
nsCSSParser parser;
|
2012-06-06 07:36:38 +00:00
|
|
|
nsCSSValue value;
|
2012-07-30 14:20:58 +00:00
|
|
|
if (!parser.ParseColorString(aColor, nullptr, 0, value)) {
|
2011-10-11 21:29:12 +00:00
|
|
|
// Any better choices?
|
2012-06-06 07:36:38 +00:00
|
|
|
return NS_RGB(0, 0, 0);
|
2011-10-11 21:29:12 +00:00
|
|
|
}
|
2012-06-06 07:36:38 +00:00
|
|
|
|
|
|
|
nscolor color;
|
2012-07-30 14:20:58 +00:00
|
|
|
return nsRuleNode::ComputeColor(value, this, nullptr, color)
|
2012-06-06 07:36:38 +00:00
|
|
|
? color
|
|
|
|
: NS_RGB(0, 0, 0);
|
2001-05-08 01:40:09 +00:00
|
|
|
}
|
|
|
|
|
2012-08-29 05:47:18 +00:00
|
|
|
bool
|
2014-03-20 06:49:25 +00:00
|
|
|
nsPresContext::IsDOMPaintEventPending()
|
2012-08-29 05:47:18 +00:00
|
|
|
{
|
2012-10-19 04:50:34 +00:00
|
|
|
if (mFireAfterPaintEvents) {
|
|
|
|
return true;
|
2012-08-29 05:47:18 +00:00
|
|
|
}
|
2016-01-22 01:09:04 +00:00
|
|
|
nsRootPresContext* drpc = GetRootPresContext();
|
2014-11-27 11:21:48 +00:00
|
|
|
if (drpc && drpc->mRefreshDriver->ViewManagerFlushIsPending()) {
|
2012-08-29 05:47:18 +00:00
|
|
|
// 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 04:50:34 +00:00
|
|
|
NS_ASSERTION(mFireAfterPaintEvents, "Why aren't we planning to fire the event?");
|
2012-08-29 05:47:18 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-12-10 23:10:01 +00:00
|
|
|
void
|
2004-07-31 23:15:21 +00:00
|
|
|
nsPresContext::PrefChangedCallback(const char* aPrefName, void* instance_data)
|
2002-12-11 05:11:02 +00:00
|
|
|
{
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<nsPresContext> presContext =
|
2013-11-17 20:49:52 +00:00
|
|
|
static_cast<nsPresContext*>(instance_data);
|
2002-12-11 05:11:02 +00:00
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
NS_ASSERTION(nullptr != presContext, "bad instance data");
|
|
|
|
if (nullptr != presContext) {
|
2002-12-11 05:11:02 +00:00
|
|
|
presContext->PreferenceChanged(aPrefName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-08-23 23:52:16 +00:00
|
|
|
void
|
|
|
|
nsPresContext::PrefChangedUpdateTimerCallback(nsITimer *aTimer, void *aClosure)
|
|
|
|
{
|
|
|
|
nsPresContext* presContext = (nsPresContext*)aClosure;
|
2012-07-30 14:20:58 +00:00
|
|
|
NS_ASSERTION(presContext != nullptr, "bad instance data");
|
2005-08-23 23:52:16 +00:00
|
|
|
if (presContext)
|
|
|
|
presContext->UpdateAfterPreferencesChanged();
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
static bool
|
2004-07-29 19:41:39 +00:00
|
|
|
IsVisualCharset(const nsCString& aCharset)
|
2001-03-09 03:13:03 +00:00
|
|
|
{
|
2012-10-10 10:32:37 +00:00
|
|
|
if (aCharset.LowerCaseEqualsLiteral("ibm862") // Hebrew
|
2004-06-17 00:13:25 +00:00
|
|
|
|| aCharset.LowerCaseEqualsLiteral("iso-8859-8") ) { // Hebrew
|
2011-10-17 14:59:28 +00:00
|
|
|
return true; // visual text type
|
2001-03-09 03:13:03 +00:00
|
|
|
}
|
|
|
|
else {
|
2011-10-17 14:59:28 +00:00
|
|
|
return false; // logical text type
|
2001-03-09 03:13:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-07-31 23:15:21 +00:00
|
|
|
// NOTE! nsPresContext::operator new() zeroes out all members, so don't
|
2004-04-30 04:06:30 +00:00
|
|
|
// bother initializing members to 0.
|
1998-04-13 20:24:54 +00:00
|
|
|
|
2006-05-19 10:26:44 +00:00
|
|
|
nsPresContext::nsPresContext(nsIDocument* aDocument, nsPresContextType aType)
|
2014-02-25 19:07:47 +00:00
|
|
|
: mType(aType), mDocument(aDocument), mBaseMinFontSize(0),
|
2016-08-25 11:15:19 +00:00
|
|
|
mTextZoom(1.0), mFullZoom(1.0), mOverrideDPPX(0.0),
|
2015-03-10 14:28:23 +00:00
|
|
|
mLastFontInflationScreenSize(gfxSize(-1.0, -1.0)),
|
2012-05-05 13:25:45 +00:00
|
|
|
mPageSize(-1, -1), mPPScale(1.0f),
|
2014-02-04 01:54:22 +00:00
|
|
|
mViewportStyleScrollbar(NS_STYLE_OVERFLOW_AUTO, NS_STYLE_OVERFLOW_AUTO),
|
2012-08-29 05:48:44 +00:00
|
|
|
mImageAnimationModePref(imgIContainer::kNormalAnimMode),
|
2016-09-23 10:20:33 +00:00
|
|
|
mAllInvalidated(false),
|
2013-07-22 15:51:38 +00:00
|
|
|
mPaintFlashing(false), mPaintFlashingInitialized(false)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
2004-07-31 23:15:21 +00:00
|
|
|
// NOTE! nsPresContext::operator new() zeroes out all members, so don't
|
2004-04-30 04:06:30 +00:00
|
|
|
// bother initializing members to 0.
|
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
mDoScaledTwips = true;
|
2000-09-21 01:20:00 +00:00
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
SetBackgroundImageDraw(true); // always draw the background
|
|
|
|
SetBackgroundColorDraw(true);
|
2001-12-11 05:57:37 +00:00
|
|
|
|
2004-01-31 22:41:40 +00:00
|
|
|
mBackgroundColor = NS_RGB(0xFF, 0xFF, 0xFF);
|
2014-03-20 06:49:25 +00:00
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
mUseDocumentColors = true;
|
|
|
|
mUseDocumentFonts = true;
|
2000-10-11 08:33:01 +00:00
|
|
|
|
2001-09-27 18:34:30 +00:00
|
|
|
// the minimum font-size is unconstrained by default
|
|
|
|
|
2003-10-15 01:56:12 +00:00
|
|
|
mLinkColor = NS_RGB(0x00, 0x00, 0xEE);
|
|
|
|
mActiveLinkColor = NS_RGB(0xEE, 0x00, 0x00);
|
|
|
|
mVisitedLinkColor = NS_RGB(0x55, 0x1A, 0x8B);
|
2011-10-17 14:59:28 +00:00
|
|
|
mUnderlineLinks = true;
|
|
|
|
mSendAfterPaintToContent = false;
|
2000-10-11 08:33:01 +00:00
|
|
|
|
2001-04-09 22:17:11 +00:00
|
|
|
mFocusTextColor = mDefaultColor;
|
2004-01-31 22:41:40 +00:00
|
|
|
mFocusBackgroundColor = mBackgroundColor;
|
2001-04-09 22:17:11 +00:00
|
|
|
mFocusRingWidth = 1;
|
|
|
|
|
2011-06-01 11:43:31 +00:00
|
|
|
mBodyTextColor = mDefaultColor;
|
|
|
|
|
2004-07-29 19:41:39 +00:00
|
|
|
if (aType == eContext_Galley) {
|
2006-12-26 17:47:52 +00:00
|
|
|
mMedium = nsGkAtoms::screen;
|
2004-07-29 19:41:39 +00:00
|
|
|
} else {
|
2006-12-26 17:47:52 +00:00
|
|
|
mMedium = nsGkAtoms::print;
|
2011-10-17 14:59:28 +00:00
|
|
|
mPaginated = true;
|
2004-07-29 19:41:39 +00:00
|
|
|
}
|
2013-07-17 15:39:19 +00:00
|
|
|
mMediaEmulated = mMedium;
|
2006-04-01 01:19:28 +00:00
|
|
|
|
|
|
|
if (!IsDynamic()) {
|
|
|
|
mImageAnimationMode = imgIContainer::kDontAnimMode;
|
2011-10-17 14:59:28 +00:00
|
|
|
mNeverAnimate = true;
|
2006-04-01 01:19:28 +00:00
|
|
|
} else {
|
|
|
|
mImageAnimationMode = imgIContainer::kNormalAnimMode;
|
2011-10-17 14:59:28 +00:00
|
|
|
mNeverAnimate = false;
|
2006-04-01 01:19:28 +00:00
|
|
|
}
|
2006-05-19 10:26:44 +00:00
|
|
|
NS_ASSERTION(mDocument, "Null document");
|
2011-04-22 03:17:31 +00:00
|
|
|
|
2014-06-12 01:12:00 +00:00
|
|
|
mCounterStylesDirty = true;
|
|
|
|
|
2013-11-25 04:59:56 +00:00
|
|
|
// if text perf logging enabled, init stats struct
|
2016-05-06 13:11:17 +00:00
|
|
|
if (MOZ_LOG_TEST(gfxPlatform::GetLog(eGfxLog_textperf), LogLevel::Warning)) {
|
2013-11-25 04:59:56 +00:00
|
|
|
mTextPerf = new gfxTextPerfMetrics();
|
|
|
|
}
|
2014-12-22 16:35:54 +00:00
|
|
|
|
|
|
|
if (Preferences::GetBool(GFX_MISSING_FONTS_NOTIFY_PREF)) {
|
|
|
|
mMissingFonts = new gfxMissingFontRecorder();
|
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
2014-10-29 20:24:02 +00:00
|
|
|
void
|
|
|
|
nsPresContext::Destroy()
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
2003-06-19 18:16:53 +00:00
|
|
|
if (mEventManager) {
|
2006-04-11 16:37:58 +00:00
|
|
|
// unclear if these are needed, but can't hurt
|
|
|
|
mEventManager->NotifyDestroyPresContext(this);
|
2012-07-30 14:20:58 +00:00
|
|
|
mEventManager->SetPresContext(nullptr);
|
2014-10-29 20:24:02 +00:00
|
|
|
mEventManager = nullptr;
|
2003-06-19 18:16:53 +00:00
|
|
|
}
|
1998-11-18 05:25:26 +00:00
|
|
|
|
2005-08-23 23:52:16 +00:00
|
|
|
if (mPrefChangedTimer)
|
|
|
|
{
|
|
|
|
mPrefChangedTimer->Cancel();
|
2012-07-30 14:20:58 +00:00
|
|
|
mPrefChangedTimer = nullptr;
|
2005-08-23 23:52:16 +00:00
|
|
|
}
|
|
|
|
|
2002-12-11 05:11:02 +00:00
|
|
|
// Unregister preference callbacks
|
2011-05-28 23:42:57 +00:00
|
|
|
Preferences::UnregisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"font.",
|
|
|
|
this);
|
|
|
|
Preferences::UnregisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"browser.display.",
|
|
|
|
this);
|
|
|
|
Preferences::UnregisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"browser.underline_anchors",
|
|
|
|
this);
|
|
|
|
Preferences::UnregisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"browser.anchor_color",
|
|
|
|
this);
|
|
|
|
Preferences::UnregisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"browser.active_color",
|
|
|
|
this);
|
|
|
|
Preferences::UnregisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"browser.visited_color",
|
|
|
|
this);
|
|
|
|
Preferences::UnregisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"image.animation_mode",
|
|
|
|
this);
|
|
|
|
Preferences::UnregisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"bidi.",
|
|
|
|
this);
|
|
|
|
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 15:51:38 +00:00
|
|
|
Preferences::UnregisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"nglayout.debug.paint_flashing",
|
|
|
|
this);
|
|
|
|
Preferences::UnregisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"nglayout.debug.paint_flashing_chrome",
|
|
|
|
this);
|
2014-10-29 20:24:02 +00:00
|
|
|
|
2016-06-06 13:51:15 +00:00
|
|
|
mRefreshDriver = nullptr;
|
2014-10-29 20:24:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsPresContext::~nsPresContext()
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(!mShell, "Presshell forgot to clear our mShell pointer");
|
2016-07-27 00:43:56 +00:00
|
|
|
DetachShell();
|
2014-10-29 20:24:02 +00:00
|
|
|
|
|
|
|
Destroy();
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
2007-08-10 21:25:24 +00:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsPresContext)
|
2010-03-25 13:17:11 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
2007-08-10 21:25:24 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIObserver)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsPresContext)
|
2013-07-09 17:30:58 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE_WITH_LAST_RELEASE(nsPresContext, LastRelease())
|
|
|
|
|
|
|
|
void
|
|
|
|
nsPresContext::LastRelease()
|
|
|
|
{
|
|
|
|
if (IsRoot()) {
|
|
|
|
static_cast<nsRootPresContext*>(this)->CancelDidPaintTimer();
|
|
|
|
}
|
2014-12-22 16:35:54 +00:00
|
|
|
if (mMissingFonts) {
|
|
|
|
mMissingFonts->Clear();
|
|
|
|
}
|
2013-07-09 17:30:58 +00:00
|
|
|
}
|
2007-08-10 21:25:24 +00:00
|
|
|
|
2013-08-02 01:29:05 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(nsPresContext)
|
|
|
|
|
2007-08-10 21:25:24 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsPresContext)
|
2015-07-29 01:57:39 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mAnimationManager);
|
2012-11-15 07:32:40 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDocument);
|
2011-04-17 01:22:42 +00:00
|
|
|
// NS_IMPL_CYCLE_COLLECTION_TRAVERSE_RAWPTR(mDeviceContext); // not xpcom
|
2016-01-12 22:54:53 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mEffectCompositor);
|
2012-11-15 07:32:40 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mEventManager);
|
2010-02-24 17:57:44 +00:00
|
|
|
// NS_IMPL_CYCLE_COLLECTION_TRAVERSE_RAWPTR(mLanguage); // an atom
|
2007-08-10 21:25:24 +00:00
|
|
|
|
2012-11-15 07:32:40 +00: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-10 21:25:24 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsPresContext)
|
2015-07-29 01:57:39 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mAnimationManager);
|
2012-11-15 07:32:40 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mDocument);
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mDeviceContext); // worth bothering?
|
2016-01-12 22:54:53 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mEffectCompositor);
|
2010-02-24 17:57:44 +00:00
|
|
|
// NS_RELEASE(tmp->mLanguage); // an atom
|
2012-11-15 07:32:40 +00:00
|
|
|
// NS_IMPL_CYCLE_COLLECTION_UNLINK(mTheme); // a service
|
|
|
|
// NS_IMPL_CYCLE_COLLECTION_UNLINK(mLangService); // a service
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mPrintSettings);
|
2014-10-29 20:24:02 +00:00
|
|
|
|
|
|
|
tmp->Destroy();
|
2007-08-10 21:25:24 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
2009-02-26 20:02:00 +00:00
|
|
|
// whether no native theme service exists;
|
|
|
|
// if this gets set to true, we'll stop asking for it.
|
2011-09-29 06:19:26 +00:00
|
|
|
static bool sNoTheme = false;
|
2009-02-26 20:02:00 +00:00
|
|
|
|
2006-09-12 04:36:03 +00:00
|
|
|
// Set to true when LookAndFeelChanged needs to be called. This is used
|
|
|
|
// because the look and feel is a service, so there's no need to notify it from
|
|
|
|
// more than one prescontext.
|
2011-09-29 06:19:26 +00:00
|
|
|
static bool sLookAndFeelChanged;
|
2006-09-12 04:36:03 +00:00
|
|
|
|
|
|
|
// Set to true when ThemeChanged needs to be called on mTheme. This is used
|
|
|
|
// because mTheme is a service, so there's no need to notify it from more than
|
|
|
|
// one prescontext.
|
2011-09-29 06:19:26 +00:00
|
|
|
static bool sThemeChanged;
|
2006-09-12 04:36:03 +00:00
|
|
|
|
2001-10-16 23:59:25 +00:00
|
|
|
void
|
2004-07-31 23:15:21 +00:00
|
|
|
nsPresContext::GetDocumentColorPreferences()
|
2001-10-16 23:59:25 +00:00
|
|
|
{
|
2014-03-04 17:26:33 +00:00
|
|
|
// Make sure the preferences are initialized. In the normal run,
|
|
|
|
// they would already be, because gfxPlatform would have been created,
|
|
|
|
// but in some reference tests, that is not the case.
|
|
|
|
gfxPrefs::GetSingleton();
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t useAccessibilityTheme = 0;
|
2011-09-29 06:19:26 +00:00
|
|
|
bool usePrefColors = true;
|
2014-03-07 04:02:59 +00:00
|
|
|
bool isChromeDocShell = false;
|
2014-11-27 19:06:14 +00:00
|
|
|
static int32_t sDocumentColorsSetting;
|
|
|
|
static bool sDocumentColorsSettingPrefCached = false;
|
|
|
|
if (!sDocumentColorsSettingPrefCached) {
|
|
|
|
sDocumentColorsSettingPrefCached = true;
|
|
|
|
Preferences::AddIntVarCache(&sDocumentColorsSetting,
|
|
|
|
"browser.display.document_color_use",
|
|
|
|
0);
|
|
|
|
}
|
2014-03-07 04:02:59 +00:00
|
|
|
|
|
|
|
nsIDocument* doc = mDocument->GetDisplayDocument();
|
|
|
|
if (doc && doc->GetDocShell()) {
|
|
|
|
isChromeDocShell = nsIDocShellTreeItem::typeChrome ==
|
|
|
|
doc->GetDocShell()->ItemType();
|
|
|
|
} else {
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> docShell(mContainer);
|
|
|
|
if (docShell) {
|
|
|
|
isChromeDocShell = nsIDocShellTreeItem::typeChrome == docShell->ItemType();
|
2004-06-08 19:34:55 +00:00
|
|
|
}
|
2014-03-07 04:02:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
mIsChromeOriginImage = mDocument->IsBeingUsedAsImage() &&
|
|
|
|
IsChromeURI(mDocument->GetDocumentURI());
|
2004-06-08 19:34:55 +00:00
|
|
|
|
2014-03-07 04:02:59 +00:00
|
|
|
if (isChromeDocShell || mIsChromeOriginImage) {
|
|
|
|
usePrefColors = false;
|
|
|
|
} else {
|
|
|
|
useAccessibilityTheme =
|
|
|
|
LookAndFeel::GetInt(LookAndFeel::eIntID_UseAccessibilityTheme, 0);
|
|
|
|
usePrefColors = !useAccessibilityTheme;
|
2001-10-16 23:59:25 +00:00
|
|
|
}
|
|
|
|
if (usePrefColors) {
|
2004-04-30 04:06:30 +00:00
|
|
|
usePrefColors =
|
2011-09-29 06:19:26 +00:00
|
|
|
!Preferences::GetBool("browser.display.use_system_colors", false);
|
2001-10-16 23:59:25 +00:00
|
|
|
}
|
2004-04-30 04:06:30 +00:00
|
|
|
|
2001-10-16 23:59:25 +00:00
|
|
|
if (usePrefColors) {
|
2011-10-11 21:29:12 +00:00
|
|
|
nsAdoptingString colorStr =
|
|
|
|
Preferences::GetString("browser.display.foreground_color");
|
2004-04-30 04:06:30 +00:00
|
|
|
|
|
|
|
if (!colorStr.IsEmpty()) {
|
2001-10-16 23:59:25 +00:00
|
|
|
mDefaultColor = MakeColorPref(colorStr);
|
|
|
|
}
|
2004-04-30 04:06:30 +00:00
|
|
|
|
2011-10-11 21:29:12 +00:00
|
|
|
colorStr = Preferences::GetString("browser.display.background_color");
|
2004-04-30 04:06:30 +00:00
|
|
|
|
|
|
|
if (!colorStr.IsEmpty()) {
|
2004-01-31 22:41:40 +00:00
|
|
|
mBackgroundColor = MakeColorPref(colorStr);
|
2001-10-16 23:59:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2011-09-09 02:27:13 +00:00
|
|
|
mDefaultColor =
|
|
|
|
LookAndFeel::GetColor(LookAndFeel::eColorID_WindowForeground,
|
|
|
|
NS_RGB(0x00, 0x00, 0x00));
|
|
|
|
mBackgroundColor =
|
|
|
|
LookAndFeel::GetColor(LookAndFeel::eColorID_WindowBackground,
|
|
|
|
NS_RGB(0xFF, 0xFF, 0xFF));
|
2001-10-16 23:59:25 +00:00
|
|
|
}
|
|
|
|
|
2008-09-19 17:06:46 +00:00
|
|
|
// Wherever we got the default background color from, ensure it is
|
|
|
|
// opaque.
|
|
|
|
mBackgroundColor = NS_ComposeColors(NS_RGB(0xFF, 0xFF, 0xFF),
|
|
|
|
mBackgroundColor);
|
|
|
|
|
2014-11-27 19:06:14 +00:00
|
|
|
|
|
|
|
// Now deal with the pref:
|
|
|
|
// 0 = default: always, except in high contrast mode
|
|
|
|
// 1 = always
|
|
|
|
// 2 = never
|
2015-10-20 12:12:36 +00:00
|
|
|
if (sDocumentColorsSetting == 1 || mDocument->IsBeingUsedAsImage()) {
|
2014-11-27 19:06:14 +00:00
|
|
|
mUseDocumentColors = true;
|
|
|
|
} else if (sDocumentColorsSetting == 2) {
|
|
|
|
mUseDocumentColors = isChromeDocShell || mIsChromeOriginImage;
|
|
|
|
} else {
|
|
|
|
MOZ_ASSERT(!useAccessibilityTheme ||
|
|
|
|
!(isChromeDocShell || mIsChromeOriginImage),
|
|
|
|
"The accessibility theme should only be on for non-chrome");
|
|
|
|
mUseDocumentColors = !useAccessibilityTheme;
|
|
|
|
}
|
2001-10-16 23:59:25 +00:00
|
|
|
}
|
|
|
|
|
1998-11-06 16:16:01 +00:00
|
|
|
void
|
2004-07-31 23:15:21 +00:00
|
|
|
nsPresContext::GetUserPreferences()
|
1998-11-06 16:16:01 +00:00
|
|
|
{
|
2005-11-08 22:45:49 +00:00
|
|
|
if (!GetPresShell()) {
|
|
|
|
// No presshell means nothing to do here. We'll do this when we
|
|
|
|
// get a presshell.
|
|
|
|
return;
|
|
|
|
}
|
2008-02-08 19:52:46 +00:00
|
|
|
|
|
|
|
mAutoQualityMinFontSizePixelsPref =
|
2011-05-25 06:32:00 +00:00
|
|
|
Preferences::GetInt("browser.display.auto_quality_min_font_size");
|
2008-02-08 19:52:46 +00:00
|
|
|
|
2000-10-11 08:33:01 +00:00
|
|
|
// * document colors
|
2001-10-16 23:59:25 +00:00
|
|
|
GetDocumentColorPreferences();
|
2001-03-29 07:16:06 +00:00
|
|
|
|
2011-01-25 00:23:08 +00:00
|
|
|
mSendAfterPaintToContent =
|
2011-05-25 06:31:59 +00:00
|
|
|
Preferences::GetBool("dom.send_after_paint_to_content",
|
|
|
|
mSendAfterPaintToContent);
|
2011-01-25 00:23:08 +00:00
|
|
|
|
2000-10-11 08:33:01 +00:00
|
|
|
// * link colors
|
2004-04-30 04:06:30 +00:00
|
|
|
mUnderlineLinks =
|
2011-05-25 06:31:59 +00:00
|
|
|
Preferences::GetBool("browser.underline_anchors", mUnderlineLinks);
|
2004-04-30 04:06:30 +00:00
|
|
|
|
2011-10-11 21:29:12 +00:00
|
|
|
nsAdoptingString colorStr = Preferences::GetString("browser.anchor_color");
|
2004-04-30 04:06:30 +00:00
|
|
|
|
|
|
|
if (!colorStr.IsEmpty()) {
|
2002-12-11 05:11:02 +00:00
|
|
|
mLinkColor = MakeColorPref(colorStr);
|
2000-10-11 08:33:01 +00:00
|
|
|
}
|
2004-04-30 04:06:30 +00:00
|
|
|
|
2011-10-11 21:29:12 +00:00
|
|
|
colorStr = Preferences::GetString("browser.active_color");
|
2004-04-30 04:06:30 +00:00
|
|
|
|
|
|
|
if (!colorStr.IsEmpty()) {
|
2003-10-15 01:56:12 +00:00
|
|
|
mActiveLinkColor = MakeColorPref(colorStr);
|
|
|
|
}
|
2004-04-30 04:06:30 +00:00
|
|
|
|
2011-10-11 21:29:12 +00:00
|
|
|
colorStr = Preferences::GetString("browser.visited_color");
|
2004-04-30 04:06:30 +00:00
|
|
|
|
|
|
|
if (!colorStr.IsEmpty()) {
|
2002-12-11 05:11:02 +00:00
|
|
|
mVisitedLinkColor = MakeColorPref(colorStr);
|
2000-10-11 08:33:01 +00:00
|
|
|
}
|
|
|
|
|
2004-04-30 04:06:30 +00:00
|
|
|
mUseFocusColors =
|
2011-05-25 06:31:59 +00:00
|
|
|
Preferences::GetBool("browser.display.use_focus_colors", mUseFocusColors);
|
2001-04-09 22:17:11 +00:00
|
|
|
|
2004-04-30 04:06:30 +00:00
|
|
|
mFocusTextColor = mDefaultColor;
|
|
|
|
mFocusBackgroundColor = mBackgroundColor;
|
|
|
|
|
2011-10-11 21:29:12 +00:00
|
|
|
colorStr = Preferences::GetString("browser.display.focus_text_color");
|
2001-04-09 22:17:11 +00:00
|
|
|
|
2004-04-30 04:06:30 +00:00
|
|
|
if (!colorStr.IsEmpty()) {
|
|
|
|
mFocusTextColor = MakeColorPref(colorStr);
|
2001-04-09 22:17:11 +00:00
|
|
|
}
|
|
|
|
|
2011-10-11 21:29:12 +00:00
|
|
|
colorStr = Preferences::GetString("browser.display.focus_background_color");
|
2004-04-30 04:06:30 +00:00
|
|
|
|
|
|
|
if (!colorStr.IsEmpty()) {
|
|
|
|
mFocusBackgroundColor = MakeColorPref(colorStr);
|
2004-04-30 03:10:29 +00:00
|
|
|
}
|
2004-04-29 23:34:19 +00:00
|
|
|
|
2004-04-30 04:06:30 +00:00
|
|
|
mFocusRingWidth =
|
2011-05-25 06:32:00 +00:00
|
|
|
Preferences::GetInt("browser.display.focus_ring_width", mFocusRingWidth);
|
2004-04-30 04:06:30 +00:00
|
|
|
|
|
|
|
mFocusRingOnAnything =
|
2011-05-25 06:31:59 +00:00
|
|
|
Preferences::GetBool("browser.display.focus_ring_on_anything",
|
|
|
|
mFocusRingOnAnything);
|
2004-04-30 04:06:30 +00:00
|
|
|
|
2008-10-08 23:28:31 +00:00
|
|
|
mFocusRingStyle =
|
2011-05-25 06:32:00 +00:00
|
|
|
Preferences::GetInt("browser.display.focus_ring_style", mFocusRingStyle);
|
2011-06-01 11:43:31 +00:00
|
|
|
|
|
|
|
mBodyTextColor = mDefaultColor;
|
2014-03-20 06:49:25 +00:00
|
|
|
|
2000-10-11 08:33:01 +00:00
|
|
|
// * use fonts?
|
2004-04-30 04:06:30 +00:00
|
|
|
mUseDocumentFonts =
|
2011-05-25 06:32:00 +00:00
|
|
|
Preferences::GetInt("browser.display.use_document_fonts") != 0;
|
2004-04-30 04:06:30 +00:00
|
|
|
|
2011-05-25 06:32:00 +00:00
|
|
|
mPrefScrollbarSide = Preferences::GetInt("layout.scrollbar.side");
|
2006-03-26 00:48:03 +00:00
|
|
|
|
2016-03-31 19:47:20 +00:00
|
|
|
mLangGroupFontPrefs.Reset();
|
|
|
|
StaticPresData::Get()->ResetCachedFontPrefs();
|
2001-01-09 23:55:27 +00:00
|
|
|
|
|
|
|
// * image animation
|
2004-04-30 04:06:30 +00:00
|
|
|
const nsAdoptingCString& animatePref =
|
2011-05-28 07:03:00 +00:00
|
|
|
Preferences::GetCString("image.animation_mode");
|
2014-05-22 03:48:51 +00:00
|
|
|
if (animatePref.EqualsLiteral("normal"))
|
2004-04-30 04:06:30 +00:00
|
|
|
mImageAnimationModePref = imgIContainer::kNormalAnimMode;
|
2014-05-22 03:48:51 +00:00
|
|
|
else if (animatePref.EqualsLiteral("none"))
|
2004-04-30 04:06:30 +00:00
|
|
|
mImageAnimationModePref = imgIContainer::kDontAnimMode;
|
2014-05-22 03:48:51 +00:00
|
|
|
else if (animatePref.EqualsLiteral("once"))
|
2004-04-30 04:06:30 +00:00
|
|
|
mImageAnimationModePref = imgIContainer::kLoopOnceAnimMode;
|
2008-02-08 19:52:46 +00:00
|
|
|
else // dynamic change to invalid value should act like it does initially
|
|
|
|
mImageAnimationModePref = imgIContainer::kNormalAnimMode;
|
2001-11-01 05:49:45 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t bidiOptions = GetBidi();
|
2005-11-08 22:45:49 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t prefInt =
|
2011-05-25 06:32:00 +00:00
|
|
|
Preferences::GetInt(IBMBIDI_TEXTDIRECTION_STR,
|
|
|
|
GET_BIDI_OPTION_DIRECTION(bidiOptions));
|
2005-11-08 22:45:49 +00:00
|
|
|
SET_BIDI_OPTION_DIRECTION(bidiOptions, prefInt);
|
2006-03-26 00:48:03 +00:00
|
|
|
mPrefBidiDirection = prefInt;
|
2004-04-30 04:06:30 +00:00
|
|
|
|
|
|
|
prefInt =
|
2011-05-25 06:32:00 +00:00
|
|
|
Preferences::GetInt(IBMBIDI_TEXTTYPE_STR,
|
|
|
|
GET_BIDI_OPTION_TEXTTYPE(bidiOptions));
|
2005-11-08 22:45:49 +00:00
|
|
|
SET_BIDI_OPTION_TEXTTYPE(bidiOptions, prefInt);
|
2004-04-30 04:06:30 +00:00
|
|
|
|
|
|
|
prefInt =
|
2011-05-25 06:32:00 +00:00
|
|
|
Preferences::GetInt(IBMBIDI_NUMERAL_STR,
|
|
|
|
GET_BIDI_OPTION_NUMERAL(bidiOptions));
|
2005-11-08 22:45:49 +00:00
|
|
|
SET_BIDI_OPTION_NUMERAL(bidiOptions, prefInt);
|
2004-04-30 04:06:30 +00:00
|
|
|
|
|
|
|
prefInt =
|
2011-05-25 06:32:00 +00:00
|
|
|
Preferences::GetInt(IBMBIDI_SUPPORTMODE_STR,
|
|
|
|
GET_BIDI_OPTION_SUPPORT(bidiOptions));
|
2005-11-08 22:45:49 +00:00
|
|
|
SET_BIDI_OPTION_SUPPORT(bidiOptions, prefInt);
|
2004-04-30 04:06:30 +00:00
|
|
|
|
2005-11-13 09:55:09 +00:00
|
|
|
// We don't need to force reflow: either we are initializing a new
|
|
|
|
// prescontext or we are being called from UpdateAfterPreferencesChanged()
|
|
|
|
// which triggers a reflow anyway.
|
2011-10-17 14:59:28 +00:00
|
|
|
SetBidi(bidiOptions, false);
|
1998-11-06 16:16:01 +00:00
|
|
|
}
|
|
|
|
|
2011-04-11 20:57:29 +00:00
|
|
|
void
|
2014-09-26 17:06:08 +00:00
|
|
|
nsPresContext::InvalidatePaintedLayers()
|
2011-04-11 20:57:29 +00:00
|
|
|
{
|
2011-06-09 07:13:05 +00:00
|
|
|
if (!mShell)
|
|
|
|
return;
|
2011-04-11 20:57:29 +00:00
|
|
|
nsIFrame* rootFrame = mShell->FrameManager()->GetRootFrame();
|
|
|
|
if (rootFrame) {
|
|
|
|
// FrameLayerBuilder caches invalidation-related values that depend on the
|
2014-09-26 17:06:08 +00:00
|
|
|
// appunits-per-dev-pixel ratio, so ensure that all PaintedLayer drawing
|
2011-04-11 20:57:29 +00:00
|
|
|
// is completely flushed.
|
2012-08-29 05:39:31 +00:00
|
|
|
rootFrame->InvalidateFrameSubtree();
|
2011-04-11 20:57:29 +00:00
|
|
|
}
|
2011-06-09 07:13:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsPresContext::AppUnitsPerDevPixelChanged()
|
|
|
|
{
|
2014-09-26 17:06:08 +00:00
|
|
|
InvalidatePaintedLayers();
|
2011-04-11 20:57:29 +00:00
|
|
|
|
2013-11-17 20:49:52 +00:00
|
|
|
if (mDeviceContext) {
|
|
|
|
mDeviceContext->FlushFontCache();
|
|
|
|
}
|
2011-04-11 20:57:29 +00:00
|
|
|
|
|
|
|
if (HasCachedStyleData()) {
|
2012-11-09 06:40:41 +00:00
|
|
|
// All cached style data must be recomputed.
|
2014-10-08 21:27:04 +00:00
|
|
|
MediaFeatureValuesChanged(eRestyle_ForceDescendants, NS_STYLE_HINT_REFLOW);
|
2011-04-11 20:57:29 +00:00
|
|
|
}
|
2013-02-07 00:19:01 +00:00
|
|
|
|
|
|
|
mCurAppUnitsPerDevPixel = AppUnitsPerDevPixel();
|
2011-04-11 20:57:29 +00:00
|
|
|
}
|
|
|
|
|
2000-04-02 21:52:17 +00:00
|
|
|
void
|
2004-07-31 23:15:21 +00:00
|
|
|
nsPresContext::PreferenceChanged(const char* aPrefName)
|
2000-04-02 21:52:17 +00:00
|
|
|
{
|
2008-02-08 19:52:46 +00:00
|
|
|
nsDependentCString prefName(aPrefName);
|
2009-05-17 22:09:53 +00:00
|
|
|
if (prefName.EqualsLiteral("layout.css.dpi") ||
|
|
|
|
prefName.EqualsLiteral("layout.css.devPixelsPerPx")) {
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t oldAppUnitsPerDevPixel = AppUnitsPerDevPixel();
|
2007-02-15 09:04:25 +00:00
|
|
|
if (mDeviceContext->CheckDPIChange() && mShell) {
|
2013-11-17 20:49:52 +00:00
|
|
|
nsCOMPtr<nsIPresShell> shell = mShell;
|
2007-12-17 04:59:59 +00:00
|
|
|
// Re-fetch the view manager's window dimensions in case there's a deferred
|
|
|
|
// resize which hasn't affected our mVisibleArea yet
|
|
|
|
nscoord oldWidthAppUnits, oldHeightAppUnits;
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<nsViewManager> vm = shell->GetViewManager();
|
2013-11-17 20:49:52 +00:00
|
|
|
if (!vm) {
|
|
|
|
return;
|
|
|
|
}
|
2007-12-17 04:59:59 +00:00
|
|
|
vm->GetWindowDimensions(&oldWidthAppUnits, &oldHeightAppUnits);
|
|
|
|
float oldWidthDevPixels = oldWidthAppUnits/oldAppUnitsPerDevPixel;
|
|
|
|
float oldHeightDevPixels = oldHeightAppUnits/oldAppUnitsPerDevPixel;
|
|
|
|
|
2007-12-12 02:27:00 +00:00
|
|
|
nscoord width = NSToCoordRound(oldWidthDevPixels*AppUnitsPerDevPixel());
|
|
|
|
nscoord height = NSToCoordRound(oldHeightDevPixels*AppUnitsPerDevPixel());
|
2007-02-15 09:04:25 +00:00
|
|
|
vm->SetWindowDimensions(width, height);
|
|
|
|
|
2011-04-11 20:57:29 +00:00
|
|
|
AppUnitsPerDevPixelChanged();
|
2007-02-15 09:04:25 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2014-12-22 16:35:54 +00:00
|
|
|
if (prefName.EqualsLiteral(GFX_MISSING_FONTS_NOTIFY_PREF)) {
|
|
|
|
if (Preferences::GetBool(GFX_MISSING_FONTS_NOTIFY_PREF)) {
|
|
|
|
if (!mMissingFonts) {
|
|
|
|
mMissingFonts = new gfxMissingFontRecorder();
|
|
|
|
// trigger reflow to detect missing fonts on the current page
|
|
|
|
mPrefChangePendingNeedsReflow = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (mMissingFonts) {
|
|
|
|
mMissingFonts->Clear();
|
|
|
|
}
|
|
|
|
mMissingFonts = nullptr;
|
|
|
|
}
|
|
|
|
}
|
2008-02-08 19:52:46 +00:00
|
|
|
if (StringBeginsWith(prefName, NS_LITERAL_CSTRING("font."))) {
|
|
|
|
// Changes to font family preferences don't change anything in the
|
|
|
|
// computed style data, so the style system won't generate a reflow
|
|
|
|
// hint for us. We need to do that manually.
|
|
|
|
|
|
|
|
// FIXME We could probably also handle changes to
|
|
|
|
// browser.display.auto_quality_min_font_size here, but that
|
|
|
|
// probably also requires clearing the text run cache, so don't
|
|
|
|
// bother (yet, anyway).
|
2011-10-17 14:59:28 +00:00
|
|
|
mPrefChangePendingNeedsReflow = true;
|
2007-07-26 09:47:43 +00:00
|
|
|
}
|
2008-12-18 20:12:53 +00:00
|
|
|
if (StringBeginsWith(prefName, NS_LITERAL_CSTRING("bidi."))) {
|
|
|
|
// Changes to bidi prefs need to trigger a reflow (see bug 443629)
|
2011-10-17 14:59:28 +00:00
|
|
|
mPrefChangePendingNeedsReflow = true;
|
2008-12-18 20:12:53 +00:00
|
|
|
|
|
|
|
// Changes to bidi.numeral also needs to empty the text run cache.
|
|
|
|
// This is handled in gfxTextRunWordCache.cpp.
|
|
|
|
}
|
2010-06-09 00:33:13 +00:00
|
|
|
if (StringBeginsWith(prefName, NS_LITERAL_CSTRING("gfx.font_rendering."))) {
|
|
|
|
// Changes to font_rendering prefs need to trigger a reflow
|
2011-10-17 14:59:28 +00:00
|
|
|
mPrefChangePendingNeedsReflow = true;
|
2010-06-09 00:33:13 +00:00
|
|
|
}
|
2005-08-23 23:52:16 +00:00
|
|
|
// we use a zero-delay timer to coalesce multiple pref updates
|
|
|
|
if (!mPrefChangedTimer)
|
|
|
|
{
|
2015-06-16 01:34:48 +00:00
|
|
|
// We will end up calling InvalidatePreferenceSheets one from each pres
|
|
|
|
// context, but all it's doing is clearing its cached sheet pointers,
|
|
|
|
// so it won't be wastefully recreating the sheet multiple times.
|
|
|
|
// The first pres context that has its mPrefChangedTimer called will
|
|
|
|
// be the one to cause the reconstruction of the pref style sheet.
|
|
|
|
nsLayoutStylesheetCache::InvalidatePreferenceSheets();
|
2015-08-04 00:13:07 +00:00
|
|
|
mPrefChangedTimer = CreateTimer(PrefChangedUpdateTimerCallback, 0);
|
|
|
|
if (!mPrefChangedTimer) {
|
2015-07-30 21:24:51 +00:00
|
|
|
return;
|
|
|
|
}
|
2005-08-23 23:52:16 +00:00
|
|
|
}
|
2013-07-22 15:51:38 +00:00
|
|
|
if (prefName.EqualsLiteral("nglayout.debug.paint_flashing") ||
|
|
|
|
prefName.EqualsLiteral("nglayout.debug.paint_flashing_chrome")) {
|
|
|
|
mPaintFlashingInitialized = false;
|
|
|
|
return;
|
|
|
|
}
|
2005-08-23 23:52:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsPresContext::UpdateAfterPreferencesChanged()
|
|
|
|
{
|
2012-07-30 14:20:58 +00:00
|
|
|
mPrefChangedTimer = nullptr;
|
2005-08-23 23:52:16 +00:00
|
|
|
|
2015-07-31 03:47:26 +00:00
|
|
|
if (!mContainer) {
|
|
|
|
// Delay updating until there is a container
|
|
|
|
mNeedsPrefUpdate = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-11-20 19:18:25 +00:00
|
|
|
nsCOMPtr<nsIDocShellTreeItem> docShell(mContainer);
|
2014-01-20 07:58:26 +00:00
|
|
|
if (docShell && nsIDocShellTreeItem::typeChrome == docShell->ItemType()) {
|
|
|
|
return;
|
2001-07-25 06:33:06 +00:00
|
|
|
}
|
|
|
|
|
2000-04-02 21:52:17 +00:00
|
|
|
// Initialize our state from the user preferences
|
|
|
|
GetUserPreferences();
|
2000-10-11 08:33:01 +00:00
|
|
|
|
|
|
|
// update the presShell: tell it to set the preference style rules up
|
|
|
|
if (mShell) {
|
2015-06-16 01:34:48 +00:00
|
|
|
mShell->UpdatePreferenceStyles();
|
2000-10-11 08:33:01 +00:00
|
|
|
}
|
|
|
|
|
2014-09-26 17:06:08 +00:00
|
|
|
InvalidatePaintedLayers();
|
2004-02-02 22:17:21 +00:00
|
|
|
mDeviceContext->FlushFontCache();
|
2008-02-08 19:52:46 +00:00
|
|
|
|
|
|
|
nsChangeHint hint = nsChangeHint(0);
|
|
|
|
|
|
|
|
if (mPrefChangePendingNeedsReflow) {
|
2016-05-23 03:26:03 +00:00
|
|
|
hint |= NS_STYLE_HINT_REFLOW;
|
2008-02-08 19:52:46 +00:00
|
|
|
}
|
|
|
|
|
2014-10-08 21:27:02 +00:00
|
|
|
// Preferences require rerunning selector matching because we rebuild
|
|
|
|
// the pref style sheet for some preference changes.
|
2014-10-08 21:26:57 +00:00
|
|
|
RebuildAllStyleData(hint, eRestyle_Subtree);
|
1998-11-06 16:16:01 +00:00
|
|
|
}
|
|
|
|
|
2004-07-29 19:41:39 +00:00
|
|
|
nsresult
|
2011-04-17 01:22:44 +00:00
|
|
|
nsPresContext::Init(nsDeviceContext* aDeviceContext)
|
1998-06-25 04:24:45 +00:00
|
|
|
{
|
2010-02-07 15:52:43 +00:00
|
|
|
NS_ASSERTION(!mInitialized, "attempt to reinit pres context");
|
2004-02-02 22:17:21 +00:00
|
|
|
NS_ENSURE_ARG(aDeviceContext);
|
1998-06-25 04:24:45 +00:00
|
|
|
|
2003-06-19 18:16:53 +00:00
|
|
|
mDeviceContext = aDeviceContext;
|
1998-07-31 05:54:59 +00:00
|
|
|
|
2014-11-10 02:47:55 +00:00
|
|
|
if (mDeviceContext->SetFullZoom(mFullZoom))
|
2007-11-27 04:54:30 +00:00
|
|
|
mDeviceContext->FlushFontCache();
|
2007-08-24 17:46:59 +00:00
|
|
|
mCurAppUnitsPerDevPixel = AppUnitsPerDevPixel();
|
|
|
|
|
2014-04-01 04:09:23 +00:00
|
|
|
mEventManager = new mozilla::EventStateManager();
|
2004-02-27 18:24:36 +00:00
|
|
|
|
2016-01-12 22:54:53 +00:00
|
|
|
mEffectCompositor = new mozilla::EffectCompositor(this);
|
2009-10-08 03:22:42 +00:00
|
|
|
mTransitionManager = new nsTransitionManager(this);
|
2011-04-12 06:18:44 +00:00
|
|
|
mAnimationManager = new nsAnimationManager(this);
|
|
|
|
|
2010-08-11 21:05:27 +00:00
|
|
|
if (mDocument->GetDisplayDocument()) {
|
|
|
|
NS_ASSERTION(mDocument->GetDisplayDocument()->GetShell() &&
|
|
|
|
mDocument->GetDisplayDocument()->GetShell()->GetPresContext(),
|
|
|
|
"Why are we being initialized?");
|
|
|
|
mRefreshDriver = mDocument->GetDisplayDocument()->GetShell()->
|
|
|
|
GetPresContext()->RefreshDriver();
|
|
|
|
} else {
|
2010-09-07 19:10:41 +00:00
|
|
|
nsIDocument* parent = mDocument->GetParentDocument();
|
|
|
|
// Unfortunately, sometimes |parent| here has no presshell because
|
|
|
|
// printing screws up things. Assert that in other cases it does,
|
|
|
|
// but whenever the shell is null just fall back on using our own
|
|
|
|
// refresh driver.
|
|
|
|
NS_ASSERTION(!parent || mDocument->IsStaticDocument() || parent->GetShell(),
|
|
|
|
"How did we end up with a presshell if our parent doesn't "
|
|
|
|
"have one?");
|
|
|
|
if (parent && parent->GetShell()) {
|
|
|
|
NS_ASSERTION(parent->GetShell()->GetPresContext(),
|
|
|
|
"How did we get a presshell?");
|
|
|
|
|
|
|
|
// We don't have our container set yet at this point
|
2013-11-15 16:32:12 +00:00
|
|
|
nsCOMPtr<nsIDocShellTreeItem> ourItem = mDocument->GetDocShell();
|
2010-09-07 19:10:41 +00:00
|
|
|
if (ourItem) {
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> parentItem;
|
|
|
|
ourItem->GetSameTypeParent(getter_AddRefs(parentItem));
|
|
|
|
if (parentItem) {
|
2013-02-22 14:56:28 +00:00
|
|
|
Element* containingElement =
|
|
|
|
parent->FindContentForSubDocument(mDocument);
|
2015-03-03 11:08:59 +00:00
|
|
|
if (!containingElement->IsXULElement() ||
|
2013-02-22 14:56:28 +00:00
|
|
|
!containingElement->
|
|
|
|
HasAttr(kNameSpaceID_None,
|
|
|
|
nsGkAtoms::forceOwnRefreshDriver)) {
|
|
|
|
mRefreshDriver = parent->GetShell()->GetPresContext()->RefreshDriver();
|
|
|
|
}
|
2010-08-11 21:05:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mRefreshDriver) {
|
|
|
|
mRefreshDriver = new nsRefreshDriver(this);
|
|
|
|
}
|
|
|
|
}
|
2009-10-08 03:22:42 +00:00
|
|
|
|
2004-04-30 04:06:30 +00:00
|
|
|
mLangService = do_GetService(NS_LANGUAGEATOMSERVICE_CONTRACTID);
|
|
|
|
|
|
|
|
// Register callbacks so we're notified when the preferences change
|
2011-05-28 23:42:57 +00:00
|
|
|
Preferences::RegisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"font.",
|
|
|
|
this);
|
|
|
|
Preferences::RegisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"browser.display.",
|
|
|
|
this);
|
|
|
|
Preferences::RegisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"browser.underline_anchors",
|
|
|
|
this);
|
|
|
|
Preferences::RegisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"browser.anchor_color",
|
|
|
|
this);
|
|
|
|
Preferences::RegisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"browser.active_color",
|
|
|
|
this);
|
|
|
|
Preferences::RegisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"browser.visited_color",
|
|
|
|
this);
|
|
|
|
Preferences::RegisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"image.animation_mode",
|
|
|
|
this);
|
|
|
|
Preferences::RegisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"bidi.",
|
|
|
|
this);
|
|
|
|
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 15:51:38 +00:00
|
|
|
Preferences::RegisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"nglayout.debug.paint_flashing",
|
|
|
|
this);
|
|
|
|
Preferences::RegisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"nglayout.debug.paint_flashing_chrome",
|
|
|
|
this);
|
2004-04-30 04:06:30 +00:00
|
|
|
|
2011-09-09 02:27:13 +00:00
|
|
|
nsresult rv = mEventManager->Init();
|
2004-02-27 17:17:37 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
mEventManager->SetPresContext(this);
|
|
|
|
|
2014-09-25 05:45:36 +00:00
|
|
|
#ifdef RESTYLE_LOGGING
|
|
|
|
mRestyleLoggingEnabled = RestyleManager::RestyleLoggingInitiallyEnabled();
|
|
|
|
#endif
|
|
|
|
|
1998-06-25 04:24:45 +00:00
|
|
|
#ifdef DEBUG
|
2011-10-17 14:59:28 +00:00
|
|
|
mInitialized = true;
|
1998-06-25 04:24:45 +00:00
|
|
|
#endif
|
|
|
|
|
2007-02-07 07:46:44 +00:00
|
|
|
mBorderWidthTable[NS_STYLE_BORDER_WIDTH_THIN] = CSSPixelsToAppUnits(1);
|
|
|
|
mBorderWidthTable[NS_STYLE_BORDER_WIDTH_MEDIUM] = CSSPixelsToAppUnits(3);
|
|
|
|
mBorderWidthTable[NS_STYLE_BORDER_WIDTH_THICK] = CSSPixelsToAppUnits(5);
|
2004-11-26 18:40:58 +00:00
|
|
|
|
1998-06-25 04:24:45 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-04-13 20:24:54 +00:00
|
|
|
// Note: We don't hold a reference on the shell; it has a reference to
|
|
|
|
// us
|
2004-07-29 19:41:39 +00:00
|
|
|
void
|
2016-07-27 00:27:56 +00:00
|
|
|
nsPresContext::AttachShell(nsIPresShell* aShell, StyleBackendType aBackendType)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
2016-07-27 00:43:56 +00:00
|
|
|
MOZ_ASSERT(!mShell);
|
|
|
|
mShell = aShell;
|
2009-01-19 09:21:29 +00:00
|
|
|
|
2016-07-27 00:27:56 +00:00
|
|
|
if (aBackendType == StyleBackendType::Servo) {
|
|
|
|
mRestyleManager = new ServoRestyleManager(this);
|
|
|
|
} else {
|
|
|
|
// Since RestyleManager is also the name of a method of nsPresContext,
|
|
|
|
// it is necessary to prefix the class with the mozilla namespace
|
|
|
|
// here.
|
|
|
|
mRestyleManager = new mozilla::RestyleManager(this);
|
|
|
|
}
|
|
|
|
|
2016-07-27 00:43:56 +00:00
|
|
|
// Since CounterStyleManager is also the name of a method of
|
|
|
|
// nsPresContext, it is necessary to prefix the class with the mozilla
|
|
|
|
// namespace here.
|
|
|
|
mCounterStyleManager = new mozilla::CounterStyleManager(this);
|
|
|
|
|
|
|
|
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;
|
2014-03-20 06:49:25 +00:00
|
|
|
}
|
2016-07-27 00:43:56 +00:00
|
|
|
// Initialize our state from the user preferences, now that we
|
|
|
|
// have a presshell, and hence a document.
|
|
|
|
GetUserPreferences();
|
2003-04-24 22:44:48 +00:00
|
|
|
|
2016-07-27 00:43:56 +00:00
|
|
|
if (doc) {
|
|
|
|
nsIURI *docURI = doc->GetDocumentURI();
|
2003-04-24 22:44:48 +00:00
|
|
|
|
2016-07-27 00:43:56 +00:00
|
|
|
if (IsDynamic() && docURI) {
|
|
|
|
bool isChrome = false;
|
|
|
|
bool isRes = false;
|
|
|
|
docURI->SchemeIs("chrome", &isChrome);
|
|
|
|
docURI->SchemeIs("resource", &isRes);
|
2001-01-09 23:55:27 +00:00
|
|
|
|
2016-07-27 00:43:56 +00:00
|
|
|
if (!isChrome && !isRes)
|
|
|
|
mImageAnimationMode = mImageAnimationModePref;
|
|
|
|
else
|
|
|
|
mImageAnimationMode = imgIContainer::kNormalAnimMode;
|
2011-04-12 06:18:44 +00:00
|
|
|
}
|
2016-07-27 00:43:56 +00:00
|
|
|
|
|
|
|
if (mLangService) {
|
|
|
|
doc->AddCharSetObserver(this);
|
|
|
|
UpdateCharSet(doc->GetDocumentCharacterSet());
|
2016-06-06 13:51:15 +00:00
|
|
|
}
|
2016-07-27 00:43:56 +00:00
|
|
|
}
|
|
|
|
}
|
2011-12-24 03:52:26 +00:00
|
|
|
|
2016-07-27 00:43:56 +00:00
|
|
|
void
|
|
|
|
nsPresContext::DetachShell()
|
|
|
|
{
|
|
|
|
// Remove ourselves as the charset observer from the shell's doc, because
|
|
|
|
// this shell may be going away for good.
|
|
|
|
nsIDocument *doc = mShell ? mShell->GetDocument() : nullptr;
|
|
|
|
if (doc) {
|
|
|
|
doc->RemoveCharSetObserver(this);
|
|
|
|
}
|
2016-03-16 20:47:41 +00:00
|
|
|
|
2016-07-27 00:43:56 +00:00
|
|
|
// The counter style manager's destructor needs to deallocate with the
|
|
|
|
// presshell arena. Disconnect it before nulling out the shell.
|
|
|
|
//
|
|
|
|
// XXXbholley: Given recent refactorings, it probably makes more sense to
|
|
|
|
// just null our mShell at the bottom of this function. I'm leaving it
|
|
|
|
// this way to preserve the old ordering, but I doubt anything would break.
|
|
|
|
if (mCounterStyleManager) {
|
|
|
|
mCounterStyleManager->Disconnect();
|
|
|
|
mCounterStyleManager = nullptr;
|
|
|
|
}
|
2016-03-16 20:47:41 +00:00
|
|
|
|
2016-07-27 00:43:56 +00:00
|
|
|
mShell = nullptr;
|
|
|
|
|
|
|
|
if (mEffectCompositor) {
|
|
|
|
mEffectCompositor->Disconnect();
|
|
|
|
mEffectCompositor = nullptr;
|
|
|
|
}
|
|
|
|
if (mTransitionManager) {
|
|
|
|
mTransitionManager->Disconnect();
|
|
|
|
mTransitionManager = nullptr;
|
|
|
|
}
|
|
|
|
if (mAnimationManager) {
|
|
|
|
mAnimationManager->Disconnect();
|
|
|
|
mAnimationManager = nullptr;
|
|
|
|
}
|
|
|
|
if (mRestyleManager) {
|
|
|
|
mRestyleManager->Disconnect();
|
|
|
|
mRestyleManager = nullptr;
|
|
|
|
}
|
|
|
|
if (mRefreshDriver && mRefreshDriver->PresContext() == this) {
|
|
|
|
mRefreshDriver->Disconnect();
|
|
|
|
// Can't null out the refresh driver here.
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IsRoot()) {
|
|
|
|
nsRootPresContext* thisRoot = static_cast<nsRootPresContext*>(this);
|
|
|
|
|
|
|
|
// Have to cancel our plugin geometry timer, because the
|
|
|
|
// callback for that depends on a non-null presshell.
|
|
|
|
thisRoot->CancelApplyPluginGeometryTimer();
|
|
|
|
|
|
|
|
// The did-paint timer also depends on a non-null pres shell.
|
|
|
|
thisRoot->CancelDidPaintTimer();
|
1998-09-05 03:52:40 +00:00
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
2000-09-20 22:59:20 +00:00
|
|
|
void
|
2012-01-11 20:58:44 +00:00
|
|
|
nsPresContext::DoChangeCharSet(const nsCString& aCharSet)
|
|
|
|
{
|
|
|
|
UpdateCharSet(aCharSet);
|
|
|
|
mDeviceContext->FlushFontCache();
|
2014-10-08 21:26:59 +00:00
|
|
|
RebuildAllStyleData(NS_STYLE_HINT_REFLOW, nsRestyleHint(0));
|
2012-01-11 20:58:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsPresContext::UpdateCharSet(const nsCString& aCharSet)
|
2000-09-20 22:59:20 +00:00
|
|
|
{
|
|
|
|
if (mLangService) {
|
2014-05-08 09:32:00 +00:00
|
|
|
mLanguage = mLangService->LookupCharSet(aCharSet);
|
2010-02-24 17:57:44 +00:00
|
|
|
// this will be a language group (or script) code rather than a true language code
|
2004-06-21 10:32:27 +00:00
|
|
|
|
|
|
|
// bug 39570: moved from nsLanguageAtomService::LookupCharSet()
|
2010-02-24 17:57:44 +00:00
|
|
|
if (mLanguage == nsGkAtoms::Unicode) {
|
2012-07-30 04:29:23 +00:00
|
|
|
mLanguage = mLangService->GetLocaleLanguage();
|
2004-06-21 10:32:27 +00:00
|
|
|
}
|
2016-03-31 19:47:20 +00:00
|
|
|
mLangGroupFontPrefs.Reset();
|
2000-09-20 22:59:20 +00:00
|
|
|
}
|
2001-03-09 03:13:03 +00:00
|
|
|
|
2005-11-08 22:45:49 +00:00
|
|
|
switch (GET_BIDI_OPTION_TEXTTYPE(GetBidi())) {
|
2004-08-05 21:38:08 +00:00
|
|
|
|
|
|
|
case IBMBIDI_TEXTTYPE_LOGICAL:
|
2011-10-17 14:59:28 +00:00
|
|
|
SetVisualMode(false);
|
2004-08-05 21:38:08 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case IBMBIDI_TEXTTYPE_VISUAL:
|
2011-10-17 14:59:28 +00:00
|
|
|
SetVisualMode(true);
|
2004-08-05 21:38:08 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case IBMBIDI_TEXTTYPE_CHARSET:
|
|
|
|
default:
|
2004-08-09 21:19:15 +00:00
|
|
|
SetVisualMode(IsVisualCharset(aCharSet));
|
2004-08-05 21:38:08 +00:00
|
|
|
}
|
2000-09-20 22:59:20 +00:00
|
|
|
}
|
|
|
|
|
2000-06-01 23:12:26 +00:00
|
|
|
NS_IMETHODIMP
|
2014-03-20 06:49:25 +00:00
|
|
|
nsPresContext::Observe(nsISupports* aSubject,
|
2004-07-29 19:41:39 +00:00
|
|
|
const char* aTopic,
|
2014-01-04 15:02:17 +00:00
|
|
|
const char16_t* aData)
|
2000-06-01 23:12:26 +00:00
|
|
|
{
|
2001-10-19 20:52:59 +00:00
|
|
|
if (!nsCRT::strcmp(aTopic, "charset")) {
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<CharSetChangingRunnable> runnable =
|
2012-01-11 20:58:44 +00:00
|
|
|
new CharSetChangingRunnable(this, NS_LossyConvertUTF16toASCII(aData));
|
|
|
|
return NS_DispatchToCurrentThread(runnable);
|
2000-09-20 22:59:20 +00:00
|
|
|
}
|
|
|
|
|
2004-07-31 23:15:21 +00:00
|
|
|
NS_WARNING("unrecognized topic in nsPresContext::Observe");
|
2001-10-19 20:52:59 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
2000-06-01 23:12:26 +00:00
|
|
|
}
|
|
|
|
|
2012-05-04 05:00:57 +00:00
|
|
|
nsPresContext*
|
|
|
|
nsPresContext::GetParentPresContext()
|
2011-01-15 09:40:33 +00:00
|
|
|
{
|
2012-05-04 05:00:57 +00:00
|
|
|
nsIPresShell* shell = GetPresShell();
|
2011-01-15 09:40:33 +00:00
|
|
|
if (shell) {
|
2013-02-27 20:52:06 +00: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 09:40:33 +00:00
|
|
|
}
|
|
|
|
}
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2011-01-15 09:40:33 +00:00
|
|
|
}
|
|
|
|
|
2012-05-04 05:00:57 +00:00
|
|
|
nsPresContext*
|
|
|
|
nsPresContext::GetToplevelContentDocumentPresContext()
|
|
|
|
{
|
|
|
|
if (IsChrome())
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2012-05-04 05:00:57 +00:00
|
|
|
nsPresContext* pc = this;
|
|
|
|
for (;;) {
|
|
|
|
nsPresContext* parent = pc->GetParentPresContext();
|
|
|
|
if (!parent || parent->IsChrome())
|
|
|
|
return pc;
|
|
|
|
pc = parent;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-26 05:47:45 +00: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 02:50:02 +00: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-29 23:09:13 +00:00
|
|
|
// We may want to replace this with something faster, maybe caching the root prescontext
|
2009-07-22 00:44:54 +00:00
|
|
|
nsRootPresContext*
|
2010-01-26 13:10:12 +00:00
|
|
|
nsPresContext::GetRootPresContext()
|
2006-11-29 23:09:13 +00:00
|
|
|
{
|
|
|
|
nsPresContext* pc = this;
|
|
|
|
for (;;) {
|
2012-05-04 05:00:57 +00:00
|
|
|
nsPresContext* parent = pc->GetParentPresContext();
|
2012-07-04 00:31:07 +00:00
|
|
|
if (!parent)
|
2011-01-15 09:40:33 +00:00
|
|
|
break;
|
|
|
|
pc = parent;
|
2006-11-29 23:09:13 +00:00
|
|
|
}
|
2012-07-30 14:20:58 +00:00
|
|
|
return pc->IsRoot() ? static_cast<nsRootPresContext*>(pc) : nullptr;
|
2006-11-29 23:09:13 +00:00
|
|
|
}
|
|
|
|
|
2003-12-24 21:51:50 +00:00
|
|
|
void
|
2006-12-05 15:46:18 +00:00
|
|
|
nsPresContext::CompatibilityModeChanged()
|
1998-07-31 05:54:59 +00:00
|
|
|
{
|
2015-06-26 03:49:58 +00:00
|
|
|
if (!mShell) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIDocument* doc = mShell->GetDocument();
|
|
|
|
if (!doc) {
|
2003-12-24 21:51:50 +00:00
|
|
|
return;
|
2015-06-26 03:49:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (doc->IsSVGDocument()) {
|
|
|
|
// SVG documents never load quirk.css.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool needsQuirkSheet = CompatibilityMode() == eCompatibility_NavQuirks;
|
|
|
|
if (mQuirkSheetAdded == needsQuirkSheet) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-02-24 07:01:11 +00:00
|
|
|
StyleSetHandle styleSet = mShell->StyleSet();
|
2016-02-24 07:01:12 +00:00
|
|
|
auto cache = nsLayoutStylesheetCache::For(styleSet->BackendType());
|
2016-09-26 12:03:25 +00:00
|
|
|
StyleSheet* sheet = cache->QuirkSheet();
|
2015-06-26 03:49:58 +00:00
|
|
|
|
|
|
|
if (needsQuirkSheet) {
|
|
|
|
// quirk.css needs to come after html.css; we just keep it at the end.
|
|
|
|
DebugOnly<nsresult> rv =
|
2015-10-19 23:16:20 +00:00
|
|
|
styleSet->AppendStyleSheet(SheetType::Agent, sheet);
|
2016-09-01 05:01:16 +00:00
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "failed to insert quirk.css");
|
2015-06-26 03:49:58 +00:00
|
|
|
} else {
|
|
|
|
DebugOnly<nsresult> rv =
|
2015-10-19 23:16:20 +00:00
|
|
|
styleSet->RemoveStyleSheet(SheetType::Agent, sheet);
|
2016-09-01 05:01:16 +00:00
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "failed to remove quirk.css");
|
2015-06-26 03:49:58 +00:00
|
|
|
}
|
2000-06-02 21:45:06 +00:00
|
|
|
|
2015-06-26 03:49:58 +00:00
|
|
|
mQuirkSheetAdded = needsQuirkSheet;
|
1998-07-31 05:54:59 +00:00
|
|
|
}
|
|
|
|
|
2001-11-14 11:21:54 +00:00
|
|
|
// Helper function for setting Anim Mode on image
|
2012-08-22 15:56:38 +00:00
|
|
|
static void SetImgAnimModeOnImgReq(imgIRequest* aImgReq, uint16_t aMode)
|
2001-11-14 11:21:54 +00:00
|
|
|
{
|
2003-03-19 03:47:09 +00:00
|
|
|
if (aImgReq) {
|
2001-11-14 11:21:54 +00:00
|
|
|
nsCOMPtr<imgIContainer> imgCon;
|
|
|
|
aImgReq->GetImage(getter_AddRefs(imgCon));
|
|
|
|
if (imgCon) {
|
|
|
|
imgCon->SetAnimationMode(aMode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-20 06:49:25 +00:00
|
|
|
// IMPORTANT: Assumption is that all images for a Presentation
|
2001-11-14 11:21:54 +00:00
|
|
|
// 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 15:56:38 +00:00
|
|
|
void nsPresContext::SetImgAnimations(nsIContent *aParent, uint16_t aMode)
|
2001-11-14 11:21:54 +00:00
|
|
|
{
|
2003-03-19 03:47:09 +00:00
|
|
|
nsCOMPtr<nsIImageLoadingContent> imgContent(do_QueryInterface(aParent));
|
2001-11-14 11:21:54 +00:00
|
|
|
if (imgContent) {
|
2003-03-19 03:47:09 +00:00
|
|
|
nsCOMPtr<imgIRequest> imgReq;
|
|
|
|
imgContent->GetRequest(nsIImageLoadingContent::CURRENT_REQUEST,
|
|
|
|
getter_AddRefs(imgReq));
|
|
|
|
SetImgAnimModeOnImgReq(imgReq, aMode);
|
2001-11-14 11:21:54 +00:00
|
|
|
}
|
2014-03-20 06:49:25 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t count = aParent->GetChildCount();
|
|
|
|
for (uint32_t i = 0; i < count; ++i) {
|
2003-09-27 04:18:26 +00:00
|
|
|
SetImgAnimations(aParent->GetChildAt(i), aMode);
|
2001-11-14 11:21:54 +00:00
|
|
|
}
|
|
|
|
}
|
2000-05-13 01:39:20 +00:00
|
|
|
|
2009-01-15 04:38:07 +00:00
|
|
|
void
|
2012-08-22 15:56:38 +00:00
|
|
|
nsPresContext::SetSMILAnimations(nsIDocument *aDoc, uint16_t aNewMode,
|
|
|
|
uint16_t aOldMode)
|
2009-01-15 04:38:07 +00:00
|
|
|
{
|
2010-03-03 07:09:51 +00:00
|
|
|
if (aDoc->HasAnimationController()) {
|
|
|
|
nsSMILAnimationController* controller = aDoc->GetAnimationController();
|
2009-01-15 04:38:07 +00:00
|
|
|
switch (aNewMode)
|
|
|
|
{
|
|
|
|
case imgIContainer::kNormalAnimMode:
|
|
|
|
case imgIContainer::kLoopOnceAnimMode:
|
|
|
|
if (aOldMode == imgIContainer::kDontAnimMode)
|
|
|
|
controller->Resume(nsSMILTimeContainer::PAUSE_USERPREF);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case imgIContainer::kDontAnimMode:
|
|
|
|
if (aOldMode != imgIContainer::kDontAnimMode)
|
|
|
|
controller->Pause(nsSMILTimeContainer::PAUSE_USERPREF);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-12-26 04:24:11 +00:00
|
|
|
void
|
2012-08-22 15:56:38 +00:00
|
|
|
nsPresContext::SetImageAnimationModeInternal(uint16_t aMode)
|
2000-05-13 01:39:20 +00:00
|
|
|
{
|
2001-11-14 14:03:09 +00:00
|
|
|
NS_ASSERTION(aMode == imgIContainer::kNormalAnimMode ||
|
|
|
|
aMode == imgIContainer::kDontAnimMode ||
|
|
|
|
aMode == imgIContainer::kLoopOnceAnimMode, "Wrong Animation Mode is being set!");
|
|
|
|
|
2004-07-29 19:41:39 +00:00
|
|
|
// Image animation mode cannot be changed when rendering to a printer.
|
2006-04-01 01:19:28 +00:00
|
|
|
if (!IsDynamic())
|
2004-07-29 19:41:39 +00:00
|
|
|
return;
|
|
|
|
|
2014-03-20 06:49:25 +00:00
|
|
|
// Now walk the content tree and set the animation mode
|
2008-10-28 21:38:37 +00:00
|
|
|
// on all the images.
|
2012-07-30 14:20:58 +00:00
|
|
|
if (mShell != nullptr) {
|
2004-08-02 04:52:55 +00:00
|
|
|
nsIDocument *doc = mShell->GetDocument();
|
2001-11-14 11:21:54 +00:00
|
|
|
if (doc) {
|
2012-08-13 22:04:19 +00:00
|
|
|
doc->StyleImageLoader()->SetAnimationMode(aMode);
|
|
|
|
|
2010-04-30 13:12:05 +00:00
|
|
|
Element *rootElement = doc->GetRootElement();
|
|
|
|
if (rootElement) {
|
|
|
|
SetImgAnimations(rootElement, aMode);
|
2001-11-14 11:21:54 +00:00
|
|
|
}
|
2009-01-15 04:38:07 +00:00
|
|
|
SetSMILAnimations(doc, aMode, mImageAnimationMode);
|
2001-11-14 11:21:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-05-13 01:39:20 +00:00
|
|
|
mImageAnimationMode = aMode;
|
|
|
|
}
|
|
|
|
|
2004-07-29 19:41:39 +00:00
|
|
|
void
|
2012-08-22 15:56:38 +00:00
|
|
|
nsPresContext::SetImageAnimationModeExternal(uint16_t aMode)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
2004-07-29 19:41:39 +00:00
|
|
|
SetImageAnimationModeInternal(aMode);
|
|
|
|
}
|
1998-08-27 20:43:04 +00:00
|
|
|
|
2015-11-28 00:56:33 +00:00
|
|
|
already_AddRefed<nsIAtom>
|
|
|
|
nsPresContext::GetContentLanguage() const
|
|
|
|
{
|
|
|
|
nsAutoString language;
|
|
|
|
Document()->GetContentLanguage(language);
|
|
|
|
language.StripWhitespace();
|
|
|
|
|
|
|
|
// Content-Language may be a comma-separated list of language codes,
|
|
|
|
// in which case the HTML5 spec says to treat it as unknown
|
|
|
|
if (!language.IsEmpty() &&
|
|
|
|
!language.Contains(char16_t(','))) {
|
2016-03-28 23:09:43 +00:00
|
|
|
return NS_Atomize(language);
|
2015-11-28 00:56:33 +00:00
|
|
|
// NOTE: This does *not* count as an explicit language; in other
|
|
|
|
// words, it doesn't trigger language-specific hyphenation.
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2005-08-13 11:54:22 +00:00
|
|
|
void
|
2007-07-26 03:34:16 +00:00
|
|
|
nsPresContext::SetFullZoom(float aZoom)
|
2005-08-13 11:54:22 +00:00
|
|
|
{
|
2009-12-11 04:02:13 +00:00
|
|
|
if (!mShell || mFullZoom == aZoom) {
|
2007-07-26 03:34:16 +00:00
|
|
|
return;
|
|
|
|
}
|
2011-04-11 20:57:29 +00:00
|
|
|
|
2007-12-12 02:27:00 +00:00
|
|
|
// Re-fetch the view manager's window dimensions in case there's a deferred
|
|
|
|
// resize which hasn't affected our mVisibleArea yet
|
|
|
|
nscoord oldWidthAppUnits, oldHeightAppUnits;
|
2009-03-11 15:43:08 +00:00
|
|
|
mShell->GetViewManager()->GetWindowDimensions(&oldWidthAppUnits, &oldHeightAppUnits);
|
2007-12-12 02:27:00 +00:00
|
|
|
float oldWidthDevPixels = oldWidthAppUnits / float(mCurAppUnitsPerDevPixel);
|
|
|
|
float oldHeightDevPixels = oldHeightAppUnits / float(mCurAppUnitsPerDevPixel);
|
2014-11-10 02:47:55 +00:00
|
|
|
mDeviceContext->SetFullZoom(aZoom);
|
2008-01-29 04:10:59 +00:00
|
|
|
|
2015-05-07 00:56:00 +00:00
|
|
|
NS_ASSERTION(!mSuppressResizeReflow, "two zooms happening at the same time? impossible!");
|
|
|
|
mSuppressResizeReflow = true;
|
2008-01-29 04:10:59 +00:00
|
|
|
|
2007-11-26 08:35:22 +00:00
|
|
|
mFullZoom = aZoom;
|
2009-03-11 15:43:08 +00:00
|
|
|
mShell->GetViewManager()->
|
|
|
|
SetWindowDimensions(NSToCoordRound(oldWidthDevPixels * AppUnitsPerDevPixel()),
|
|
|
|
NSToCoordRound(oldHeightDevPixels * AppUnitsPerDevPixel()));
|
2011-04-11 20:57:29 +00:00
|
|
|
|
|
|
|
AppUnitsPerDevPixelChanged();
|
2008-01-29 04:10:59 +00:00
|
|
|
|
2015-05-07 00:56:00 +00:00
|
|
|
mSuppressResizeReflow = false;
|
2005-08-13 11:54:22 +00:00
|
|
|
}
|
|
|
|
|
2016-08-25 11:15:19 +00:00
|
|
|
void
|
|
|
|
nsPresContext::SetOverrideDPPX(float aDPPX)
|
|
|
|
{
|
|
|
|
mOverrideDPPX = aDPPX;
|
|
|
|
|
|
|
|
if (HasCachedStyleData()) {
|
|
|
|
MediaFeatureValuesChanged(nsRestyleHint(0), nsChangeHint(0));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-10 14:28:23 +00:00
|
|
|
gfxSize
|
|
|
|
nsPresContext::ScreenSizeInchesForFontInflation(bool* aChanged)
|
2012-05-05 13:25:45 +00:00
|
|
|
{
|
|
|
|
if (aChanged) {
|
|
|
|
*aChanged = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsDeviceContext *dx = DeviceContext();
|
|
|
|
nsRect clientRect;
|
|
|
|
dx->GetClientRect(clientRect); // FIXME: GetClientRect looks expensive
|
2015-03-10 14:28:23 +00:00
|
|
|
float unitsPerInch = dx->AppUnitsPerPhysicalInch();
|
|
|
|
gfxSize deviceSizeInches(float(clientRect.width) / unitsPerInch,
|
|
|
|
float(clientRect.height) / unitsPerInch);
|
2012-05-05 13:25:45 +00:00
|
|
|
|
2015-03-10 14:28:23 +00:00
|
|
|
if (mLastFontInflationScreenSize == gfxSize(-1.0, -1.0)) {
|
|
|
|
mLastFontInflationScreenSize = deviceSizeInches;
|
2012-06-12 05:43:31 +00:00
|
|
|
}
|
|
|
|
|
2015-03-10 14:28:23 +00:00
|
|
|
if (deviceSizeInches != mLastFontInflationScreenSize && aChanged) {
|
2012-06-12 05:43:31 +00:00
|
|
|
*aChanged = true;
|
2015-03-10 14:28:23 +00:00
|
|
|
mLastFontInflationScreenSize = deviceSizeInches;
|
2012-05-05 13:25:45 +00:00
|
|
|
}
|
|
|
|
|
2015-03-10 14:28:23 +00:00
|
|
|
return deviceSizeInches;
|
2012-05-05 13:25:45 +00:00
|
|
|
}
|
|
|
|
|
2015-09-30 00:48:41 +00:00
|
|
|
static bool
|
2015-09-30 00:48:41 +00:00
|
|
|
CheckOverflow(const nsStyleDisplay* aDisplay, ScrollbarStyles* aStyles)
|
2015-09-30 00:48:41 +00:00
|
|
|
{
|
|
|
|
if (aDisplay->mOverflowX == NS_STYLE_OVERFLOW_VISIBLE &&
|
|
|
|
aDisplay->mScrollBehavior == NS_STYLE_SCROLL_BEHAVIOR_AUTO &&
|
|
|
|
aDisplay->mScrollSnapTypeX == NS_STYLE_SCROLL_SNAP_TYPE_NONE &&
|
|
|
|
aDisplay->mScrollSnapTypeY == NS_STYLE_SCROLL_SNAP_TYPE_NONE &&
|
|
|
|
aDisplay->mScrollSnapPointsX == nsStyleCoord(eStyleUnit_None) &&
|
|
|
|
aDisplay->mScrollSnapPointsY == nsStyleCoord(eStyleUnit_None) &&
|
|
|
|
!aDisplay->mScrollSnapDestination.mXPosition.mHasPercent &&
|
|
|
|
!aDisplay->mScrollSnapDestination.mYPosition.mHasPercent &&
|
|
|
|
aDisplay->mScrollSnapDestination.mXPosition.mLength == 0 &&
|
|
|
|
aDisplay->mScrollSnapDestination.mYPosition.mLength == 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aDisplay->mOverflowX == NS_STYLE_OVERFLOW_CLIP) {
|
2015-09-30 00:48:41 +00:00
|
|
|
*aStyles = ScrollbarStyles(NS_STYLE_OVERFLOW_HIDDEN,
|
|
|
|
NS_STYLE_OVERFLOW_HIDDEN, aDisplay);
|
2015-09-30 00:48:41 +00:00
|
|
|
} else {
|
2015-09-30 00:48:41 +00:00
|
|
|
*aStyles = ScrollbarStyles(aDisplay);
|
2015-09-30 00:48:41 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-09-30 00:48:41 +00:00
|
|
|
static nsIContent*
|
|
|
|
GetPropagatedScrollbarStylesForViewport(nsPresContext* aPresContext,
|
|
|
|
ScrollbarStyles *aStyles)
|
2015-09-30 00:48:41 +00:00
|
|
|
{
|
|
|
|
// Set default
|
2015-09-30 00:48:41 +00:00
|
|
|
*aStyles = ScrollbarStyles(NS_STYLE_OVERFLOW_AUTO, NS_STYLE_OVERFLOW_AUTO);
|
2015-09-30 00:48:41 +00:00
|
|
|
|
|
|
|
// We never mess with the viewport scroll state
|
|
|
|
// when printing or in print preview
|
2015-09-30 00:48:41 +00:00
|
|
|
if (aPresContext->IsPaginated()) {
|
2015-09-30 00:48:41 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-09-30 00:48:41 +00:00
|
|
|
nsIDocument* document = aPresContext->Document();
|
|
|
|
Element* docElement = document->GetRootElement();
|
2015-09-30 00:48:41 +00:00
|
|
|
|
2015-12-08 19:55:50 +00:00
|
|
|
// docElement might be null if we're doing this after removing it.
|
|
|
|
if (!docElement) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-09-30 00:48:41 +00:00
|
|
|
// Check the style on the document root element
|
2016-02-24 07:01:11 +00:00
|
|
|
StyleSetHandle styleSet = aPresContext->StyleSet();
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<nsStyleContext> rootStyle;
|
2015-09-30 00:48:41 +00:00
|
|
|
rootStyle = styleSet->ResolveStyleFor(docElement, nullptr);
|
2015-09-30 00:48:41 +00:00
|
|
|
if (CheckOverflow(rootStyle->StyleDisplay(), aStyles)) {
|
2015-09-30 00:48:41 +00:00
|
|
|
// tell caller we stole the overflow style from the root element
|
|
|
|
return docElement;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Don't look in the BODY for non-HTML documents or HTML documents
|
|
|
|
// with non-HTML roots
|
|
|
|
// XXX this should be earlier; we shouldn't even look at the document root
|
|
|
|
// for non-HTML documents. Fix this once we support explicit CSS styling
|
|
|
|
// of the viewport
|
|
|
|
// XXX what about XHTML?
|
2015-09-30 00:48:41 +00:00
|
|
|
nsCOMPtr<nsIDOMHTMLDocument> htmlDoc(do_QueryInterface(document));
|
2015-09-30 00:48:41 +00:00
|
|
|
if (!htmlDoc || !docElement->IsHTMLElement()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMHTMLElement> body;
|
|
|
|
htmlDoc->GetBody(getter_AddRefs(body));
|
|
|
|
nsCOMPtr<nsIContent> bodyElement = do_QueryInterface(body);
|
|
|
|
|
|
|
|
if (!bodyElement ||
|
|
|
|
!bodyElement->NodeInfo()->Equals(nsGkAtoms::body)) {
|
|
|
|
// The body is not a <body> tag, it's a <frameset>.
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<nsStyleContext> bodyStyle;
|
2015-09-30 00:48:41 +00:00
|
|
|
bodyStyle = styleSet->ResolveStyleFor(bodyElement->AsElement(), rootStyle);
|
|
|
|
|
2015-09-30 00:48:41 +00:00
|
|
|
if (CheckOverflow(bodyStyle->StyleDisplay(), aStyles)) {
|
2015-09-30 00:48:41 +00:00
|
|
|
// tell caller we stole the overflow style from the body element
|
|
|
|
return bodyElement;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-09-30 00:48:41 +00:00
|
|
|
nsIContent*
|
|
|
|
nsPresContext::UpdateViewportScrollbarStylesOverride()
|
|
|
|
{
|
|
|
|
nsIContent* propagatedFrom =
|
|
|
|
GetPropagatedScrollbarStylesForViewport(this, &mViewportStyleScrollbar);
|
|
|
|
|
|
|
|
nsIDocument* document = Document();
|
2016-02-17 00:47:11 +00:00
|
|
|
if (Element* fullscreenElement = document->GetFullscreenElement()) {
|
2015-09-30 00:48:41 +00:00
|
|
|
// If the document is in fullscreen, but the fullscreen element is
|
|
|
|
// not the root element, we should explicitly suppress the scrollbar
|
|
|
|
// here. Note that, we still need to return the original element
|
|
|
|
// the styles are from, so that the state of those elements is not
|
|
|
|
// affected across fullscreen change.
|
|
|
|
if (fullscreenElement != document->GetRootElement() &&
|
|
|
|
fullscreenElement != propagatedFrom) {
|
|
|
|
mViewportStyleScrollbar = ScrollbarStyles(NS_STYLE_OVERFLOW_HIDDEN,
|
|
|
|
NS_STYLE_OVERFLOW_HIDDEN);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return propagatedFrom;
|
|
|
|
}
|
|
|
|
|
2004-02-01 10:09:07 +00:00
|
|
|
void
|
2013-11-20 19:18:25 +00:00
|
|
|
nsPresContext::SetContainer(nsIDocShell* aDocShell)
|
1999-04-30 09:04:36 +00:00
|
|
|
{
|
2013-11-20 19:18:25 +00:00
|
|
|
if (aDocShell) {
|
2015-08-04 00:13:08 +00:00
|
|
|
NS_ASSERTION(!(mContainer && mNeedsPrefUpdate),
|
2015-07-31 03:47:26 +00:00
|
|
|
"Should only need pref update if mContainer is null.");
|
2014-07-30 19:52:05 +00:00
|
|
|
mContainer = static_cast<nsDocShell*>(aDocShell);
|
2015-07-31 03:47:26 +00:00
|
|
|
if (mNeedsPrefUpdate) {
|
|
|
|
if (!mPrefChangedTimer) {
|
2015-08-04 00:13:07 +00:00
|
|
|
mPrefChangedTimer = CreateTimer(PrefChangedUpdateTimerCallback, 0);
|
2015-07-31 03:47:26 +00:00
|
|
|
}
|
|
|
|
mNeedsPrefUpdate = false;
|
|
|
|
}
|
2013-11-20 19:18:25 +00:00
|
|
|
} else {
|
|
|
|
mContainer = WeakPtr<nsDocShell>();
|
|
|
|
}
|
2014-02-07 03:08:49 +00:00
|
|
|
UpdateIsChrome();
|
2001-10-16 23:59:25 +00:00
|
|
|
if (mContainer) {
|
|
|
|
GetDocumentColorPreferences();
|
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
2013-11-20 19:18:25 +00:00
|
|
|
nsISupports*
|
|
|
|
nsPresContext::GetContainerWeakInternal() const
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
2013-11-20 19:18:25 +00:00
|
|
|
return static_cast<nsIDocShell*>(mContainer);
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
1998-06-23 21:53:02 +00:00
|
|
|
|
2013-11-20 19:18:25 +00:00
|
|
|
nsISupports*
|
|
|
|
nsPresContext::GetContainerWeakExternal() const
|
2004-07-29 19:41:39 +00:00
|
|
|
{
|
2013-11-20 19:18:25 +00:00
|
|
|
return GetContainerWeakInternal();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIDocShell*
|
|
|
|
nsPresContext::GetDocShell() const
|
|
|
|
{
|
|
|
|
return mContainer;
|
2004-07-29 19:41:39 +00:00
|
|
|
}
|
|
|
|
|
2014-02-03 23:47:57 +00:00
|
|
|
/* virtual */ void
|
|
|
|
nsPresContext::Detach()
|
|
|
|
{
|
|
|
|
SetContainer(nullptr);
|
|
|
|
SetLinkHandler(nullptr);
|
2016-09-23 10:20:33 +00:00
|
|
|
if (mShell) {
|
|
|
|
mShell->CancelInvalidatePresShellIfHidden();
|
|
|
|
}
|
2014-02-03 23:47:57 +00:00
|
|
|
}
|
|
|
|
|
2012-07-30 04:29:41 +00:00
|
|
|
bool
|
|
|
|
nsPresContext::BidiEnabledExternal() const
|
|
|
|
{
|
|
|
|
return BidiEnabledInternal();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsPresContext::BidiEnabledInternal() const
|
|
|
|
{
|
|
|
|
return Document()->GetBidiEnabled();
|
|
|
|
}
|
|
|
|
|
2004-04-13 00:28:44 +00:00
|
|
|
void
|
2008-06-16 09:28:17 +00:00
|
|
|
nsPresContext::SetBidiEnabled() const
|
2001-03-09 03:13:03 +00:00
|
|
|
{
|
|
|
|
if (mShell) {
|
2004-08-02 04:52:55 +00:00
|
|
|
nsIDocument *doc = mShell->GetDocument();
|
2001-03-09 03:13:03 +00:00
|
|
|
if (doc) {
|
2008-06-16 09:28:17 +00:00
|
|
|
doc->SetBidiEnabled();
|
2001-03-09 03:13:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-07-29 19:41:39 +00:00
|
|
|
void
|
2012-08-22 15:56:38 +00:00
|
|
|
nsPresContext::SetBidi(uint32_t aSource, bool aForceRestyle)
|
2001-03-09 03:13:03 +00:00
|
|
|
{
|
2005-11-13 09:55:09 +00:00
|
|
|
// Don't do all this stuff unless the options have changed.
|
|
|
|
if (aSource == GetBidi()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-03-20 06:49:25 +00:00
|
|
|
NS_ASSERTION(!(aForceRestyle && (GetBidi() == 0)),
|
2005-11-13 09:55:09 +00:00
|
|
|
"ForceReflow on new prescontext");
|
|
|
|
|
2006-05-19 10:26:44 +00:00
|
|
|
Document()->SetBidiOptions(aSource);
|
2005-11-08 22:45:49 +00:00
|
|
|
if (IBMBIDI_TEXTDIRECTION_RTL == GET_BIDI_OPTION_DIRECTION(aSource)
|
|
|
|
|| IBMBIDI_NUMERAL_HINDI == GET_BIDI_OPTION_NUMERAL(aSource)) {
|
2008-06-16 09:28:17 +00:00
|
|
|
SetBidiEnabled();
|
2001-03-09 03:13:03 +00:00
|
|
|
}
|
2005-11-08 22:45:49 +00:00
|
|
|
if (IBMBIDI_TEXTTYPE_VISUAL == GET_BIDI_OPTION_TEXTTYPE(aSource)) {
|
2011-10-17 14:59:28 +00:00
|
|
|
SetVisualMode(true);
|
2001-03-09 03:13:03 +00:00
|
|
|
}
|
2005-11-08 22:45:49 +00:00
|
|
|
else if (IBMBIDI_TEXTTYPE_LOGICAL == GET_BIDI_OPTION_TEXTTYPE(aSource)) {
|
2011-10-17 14:59:28 +00:00
|
|
|
SetVisualMode(false);
|
2001-03-09 03:13:03 +00:00
|
|
|
}
|
|
|
|
else {
|
2004-08-09 21:19:15 +00:00
|
|
|
nsIDocument* doc = mShell->GetDocument();
|
|
|
|
if (doc) {
|
|
|
|
SetVisualMode(IsVisualCharset(doc->GetDocumentCharacterSet()));
|
|
|
|
}
|
2001-03-09 03:13:03 +00:00
|
|
|
}
|
2010-12-15 20:26:54 +00:00
|
|
|
if (aForceRestyle && mShell) {
|
|
|
|
// Reconstruct the root document element's frame and its children,
|
|
|
|
// because we need to trigger frame reconstruction for direction change.
|
2015-06-27 01:39:54 +00:00
|
|
|
mDocument->RebuildUserFontSet();
|
2010-12-15 20:26:54 +00:00
|
|
|
mShell->ReconstructFrames();
|
2001-03-09 03:13:03 +00:00
|
|
|
}
|
|
|
|
}
|
2005-11-08 22:45:49 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t
|
2005-11-08 22:45:49 +00:00
|
|
|
nsPresContext::GetBidi() const
|
|
|
|
{
|
2006-05-19 10:26:44 +00:00
|
|
|
return Document()->GetBidiOptions();
|
2005-11-08 22:45:49 +00:00
|
|
|
}
|
2010-06-01 02:19:35 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2010-03-17 17:10:57 +00:00
|
|
|
nsPresContext::IsTopLevelWindowInactive()
|
|
|
|
{
|
2013-11-20 19:18:25 +00:00
|
|
|
nsCOMPtr<nsIDocShellTreeItem> treeItem(mContainer);
|
2010-03-17 17:10:57 +00:00
|
|
|
if (!treeItem)
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2010-03-17 17:10:57 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> rootItem;
|
|
|
|
treeItem->GetRootTreeItem(getter_AddRefs(rootItem));
|
2014-01-10 02:03:47 +00:00
|
|
|
if (!rootItem) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-01-30 17:05:36 +00:00
|
|
|
nsCOMPtr<nsPIDOMWindowOuter> domWindow = rootItem->GetWindow();
|
2010-03-17 17:10:57 +00:00
|
|
|
|
|
|
|
return domWindow && !domWindow->IsActive();
|
|
|
|
}
|
|
|
|
|
2004-07-29 19:41:39 +00:00
|
|
|
nsITheme*
|
2004-07-31 23:15:21 +00:00
|
|
|
nsPresContext::GetTheme()
|
2001-12-17 22:51:39 +00:00
|
|
|
{
|
2009-02-26 20:02:00 +00:00
|
|
|
if (!sNoTheme && !mTheme) {
|
2001-12-17 22:51:39 +00:00
|
|
|
mTheme = do_GetService("@mozilla.org/chrome/chrome-native-theme;1");
|
|
|
|
if (!mTheme)
|
2011-10-17 14:59:28 +00:00
|
|
|
sNoTheme = true;
|
2001-12-17 22:51:39 +00:00
|
|
|
}
|
|
|
|
|
2004-07-29 19:41:39 +00:00
|
|
|
return mTheme;
|
2001-12-17 22:51:39 +00:00
|
|
|
}
|
|
|
|
|
2004-07-29 19:41:39 +00:00
|
|
|
void
|
2004-07-31 23:15:21 +00:00
|
|
|
nsPresContext::ThemeChanged()
|
2001-12-17 22:51:39 +00:00
|
|
|
{
|
2006-09-12 04:36:03 +00:00
|
|
|
if (!mPendingThemeChanged) {
|
2011-10-17 14:59:28 +00:00
|
|
|
sLookAndFeelChanged = true;
|
|
|
|
sThemeChanged = true;
|
2006-09-12 04:36:03 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIRunnable> ev =
|
2016-05-05 08:45:00 +00:00
|
|
|
NewRunnableMethod(this, &nsPresContext::ThemeChangedInternal);
|
2006-09-12 04:36:03 +00:00
|
|
|
if (NS_SUCCEEDED(NS_DispatchToCurrentThread(ev))) {
|
2011-10-17 14:59:28 +00:00
|
|
|
mPendingThemeChanged = true;
|
2006-09-12 04:36:03 +00:00
|
|
|
}
|
2014-03-20 06:49:25 +00:00
|
|
|
}
|
2006-09-12 04:36:03 +00:00
|
|
|
}
|
|
|
|
|
2016-05-11 12:56:42 +00:00
|
|
|
static bool
|
2015-04-22 14:58:33 +00:00
|
|
|
NotifyThemeChanged(TabParent* aTabParent, void* aArg)
|
|
|
|
{
|
|
|
|
aTabParent->ThemeChanged();
|
2016-05-11 12:56:42 +00:00
|
|
|
return false;
|
2015-04-22 14:58:33 +00:00
|
|
|
}
|
|
|
|
|
2006-09-12 04:36:03 +00:00
|
|
|
void
|
|
|
|
nsPresContext::ThemeChangedInternal()
|
|
|
|
{
|
2011-10-17 14:59:28 +00:00
|
|
|
mPendingThemeChanged = false;
|
2014-03-20 06:49:25 +00:00
|
|
|
|
2001-12-17 22:51:39 +00:00
|
|
|
// Tell the theme that it changed, so it can flush any handles to stale theme
|
|
|
|
// data.
|
2006-09-12 04:36:03 +00:00
|
|
|
if (mTheme && sThemeChanged) {
|
2001-12-17 22:51:39 +00:00
|
|
|
mTheme->ThemeChanged();
|
2011-10-17 14:59:28 +00:00
|
|
|
sThemeChanged = false;
|
2006-09-12 04:36:03 +00:00
|
|
|
}
|
2001-12-17 22:51:39 +00:00
|
|
|
|
2011-09-09 02:27:13 +00:00
|
|
|
if (sLookAndFeelChanged) {
|
2014-06-25 12:04:36 +00:00
|
|
|
// Clear all cached LookAndFeel colors.
|
2011-09-09 02:27:13 +00:00
|
|
|
LookAndFeel::Refresh();
|
2011-10-17 14:59:28 +00:00
|
|
|
sLookAndFeelChanged = false;
|
2014-06-25 12:04:36 +00:00
|
|
|
|
|
|
|
// Vector images (SVG) may be using theme colors so we discard all cached
|
|
|
|
// surfaces. (We could add a vector image only version of DiscardAll, but
|
|
|
|
// in bug 940625 we decided theme changes are rare enough not to bother.)
|
2016-08-08 22:54:10 +00:00
|
|
|
image::SurfaceCacheUtils::DiscardAll();
|
2006-09-12 04:36:03 +00:00
|
|
|
}
|
2004-09-17 06:27:01 +00:00
|
|
|
|
2008-08-05 20:02:43 +00:00
|
|
|
// This will force the system metrics to be generated the next time they're used
|
|
|
|
nsCSSRuleProcessor::FreeSystemMetrics();
|
|
|
|
|
2014-10-08 21:27:04 +00:00
|
|
|
// Changes to system metrics can change media queries on them, or
|
|
|
|
// :-moz-system-metric selectors (which requires eRestyle_Subtree).
|
2008-02-08 19:52:46 +00:00
|
|
|
// Changes in theme can change system colors (whose changes are
|
|
|
|
// properly reflected in computed style data), system fonts (whose
|
|
|
|
// changes are not), and -moz-appearance (whose changes likewise are
|
|
|
|
// not), so we need to reflow.
|
2014-10-08 21:27:03 +00:00
|
|
|
MediaFeatureValuesChanged(eRestyle_Subtree, NS_STYLE_HINT_REFLOW);
|
2015-04-22 14:58:33 +00:00
|
|
|
|
|
|
|
// Recursively notify all remote leaf descendants that the
|
|
|
|
// system theme has changed.
|
|
|
|
nsContentUtils::CallOnAllRemoteChildren(mDocument->GetWindow(),
|
|
|
|
NotifyThemeChanged, nullptr);
|
2001-12-17 22:51:39 +00:00
|
|
|
}
|
|
|
|
|
2004-07-29 19:41:39 +00:00
|
|
|
void
|
2004-07-31 23:15:21 +00:00
|
|
|
nsPresContext::SysColorChanged()
|
2002-06-04 17:47:54 +00:00
|
|
|
{
|
2006-09-12 04:36:03 +00:00
|
|
|
if (!mPendingSysColorChanged) {
|
2011-10-17 14:59:28 +00:00
|
|
|
sLookAndFeelChanged = true;
|
2006-09-12 04:36:03 +00:00
|
|
|
nsCOMPtr<nsIRunnable> ev =
|
2016-05-05 08:45:00 +00:00
|
|
|
NewRunnableMethod(this, &nsPresContext::SysColorChangedInternal);
|
2006-09-12 04:36:03 +00:00
|
|
|
if (NS_SUCCEEDED(NS_DispatchToCurrentThread(ev))) {
|
2011-10-17 14:59:28 +00:00
|
|
|
mPendingSysColorChanged = true;
|
2006-09-12 04:36:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsPresContext::SysColorChangedInternal()
|
|
|
|
{
|
2011-10-17 14:59:28 +00:00
|
|
|
mPendingSysColorChanged = false;
|
2014-03-20 06:49:25 +00:00
|
|
|
|
2011-09-09 02:27:13 +00:00
|
|
|
if (sLookAndFeelChanged) {
|
2002-06-04 17:47:54 +00:00
|
|
|
// Don't use the cached values for the system colors
|
2011-09-09 02:27:13 +00:00
|
|
|
LookAndFeel::Refresh();
|
2011-10-17 14:59:28 +00:00
|
|
|
sLookAndFeelChanged = false;
|
2002-06-04 17:47:54 +00:00
|
|
|
}
|
2014-03-20 06:49:25 +00:00
|
|
|
|
2002-06-04 17:47:54 +00:00
|
|
|
// Reset default background and foreground colors for the document since
|
|
|
|
// they may be using system colors
|
|
|
|
GetDocumentColorPreferences();
|
|
|
|
|
2008-02-08 19:52:46 +00:00
|
|
|
// The system color values are computed to colors in the style data,
|
|
|
|
// so normal style data comparison is sufficient here.
|
2014-10-08 21:26:59 +00:00
|
|
|
RebuildAllStyleData(nsChangeHint(0), nsRestyleHint(0));
|
2008-01-09 09:38:28 +00:00
|
|
|
}
|
|
|
|
|
2012-10-16 19:41:20 +00:00
|
|
|
void
|
|
|
|
nsPresContext::UIResolutionChanged()
|
|
|
|
{
|
|
|
|
if (!mPendingUIResolutionChanged) {
|
|
|
|
nsCOMPtr<nsIRunnable> ev =
|
2016-05-05 08:45:00 +00:00
|
|
|
NewRunnableMethod(this, &nsPresContext::UIResolutionChangedInternal);
|
2012-10-16 19:41:20 +00:00
|
|
|
if (NS_SUCCEEDED(NS_DispatchToCurrentThread(ev))) {
|
|
|
|
mPendingUIResolutionChanged = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-08 05:39:28 +00:00
|
|
|
void
|
|
|
|
nsPresContext::UIResolutionChangedSync()
|
|
|
|
{
|
|
|
|
if (!mPendingUIResolutionChanged) {
|
|
|
|
mPendingUIResolutionChanged = true;
|
2016-04-07 09:01:30 +00:00
|
|
|
UIResolutionChangedInternalScale(0.0);
|
2015-06-08 05:39:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-16 19:41:20 +00:00
|
|
|
/*static*/ bool
|
|
|
|
nsPresContext::UIResolutionChangedSubdocumentCallback(nsIDocument* aDocument,
|
|
|
|
void* aData)
|
|
|
|
{
|
|
|
|
nsIPresShell* shell = aDocument->GetShell();
|
|
|
|
if (shell) {
|
|
|
|
nsPresContext* pc = shell->GetPresContext();
|
|
|
|
if (pc) {
|
2016-04-07 09:01:30 +00:00
|
|
|
// For subdocuments, we want to apply the parent's scale, because there
|
|
|
|
// are cases where the subdoc's device context is connected to a widget
|
|
|
|
// that has an out-of-date resolution (it's on a different screen, but
|
|
|
|
// currently hidden, and will not be updated until shown): bug 1249279.
|
|
|
|
double scale = *static_cast<double*>(aData);
|
|
|
|
pc->UIResolutionChangedInternalScale(scale);
|
2012-10-16 19:41:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-11-27 13:28:26 +00:00
|
|
|
static void
|
2015-06-08 05:39:39 +00:00
|
|
|
NotifyTabUIResolutionChanged(TabParent* aTab, void *aArg)
|
2015-06-08 05:39:39 +00:00
|
|
|
{
|
2015-06-08 05:39:39 +00:00
|
|
|
aTab->UIResolutionChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2016-01-30 17:05:36 +00:00
|
|
|
NotifyChildrenUIResolutionChanged(nsPIDOMWindowOuter* aWindow)
|
2015-06-08 05:39:39 +00:00
|
|
|
{
|
2016-01-30 17:05:36 +00:00
|
|
|
nsCOMPtr<nsIDocument> doc = aWindow->GetExtantDoc();
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<nsPIWindowRoot> topLevelWin = nsContentUtils::GetWindowRoot(doc);
|
2015-06-08 05:39:39 +00:00
|
|
|
if (!topLevelWin) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
topLevelWin->EnumerateBrowsers(NotifyTabUIResolutionChanged, nullptr);
|
2014-11-27 13:28:26 +00:00
|
|
|
}
|
|
|
|
|
2012-10-16 19:41:20 +00:00
|
|
|
void
|
|
|
|
nsPresContext::UIResolutionChangedInternal()
|
2016-04-07 09:01:30 +00:00
|
|
|
{
|
|
|
|
UIResolutionChangedInternalScale(0.0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsPresContext::UIResolutionChangedInternalScale(double aScale)
|
2012-10-16 19:41:20 +00:00
|
|
|
{
|
|
|
|
mPendingUIResolutionChanged = false;
|
|
|
|
|
2016-04-07 09:01:30 +00:00
|
|
|
mDeviceContext->CheckDPIChange(&aScale);
|
2013-02-19 21:46:27 +00:00
|
|
|
if (mCurAppUnitsPerDevPixel != AppUnitsPerDevPixel()) {
|
2013-02-17 21:27:24 +00:00
|
|
|
AppUnitsPerDevPixelChanged();
|
|
|
|
}
|
2012-10-16 19:41:20 +00:00
|
|
|
|
2015-06-08 05:39:39 +00:00
|
|
|
// Recursively notify all remote leaf descendants of the change.
|
2016-01-30 17:05:36 +00:00
|
|
|
if (nsPIDOMWindowOuter* window = mDocument->GetWindow()) {
|
|
|
|
NotifyChildrenUIResolutionChanged(window);
|
|
|
|
}
|
2014-05-23 14:36:50 +00:00
|
|
|
|
2012-10-16 19:41:20 +00:00
|
|
|
mDocument->EnumerateSubDocuments(UIResolutionChangedSubdocumentCallback,
|
2016-04-07 09:01:30 +00:00
|
|
|
&aScale);
|
2012-10-16 19:41:20 +00:00
|
|
|
}
|
|
|
|
|
2013-07-17 15:39:19 +00:00
|
|
|
void
|
|
|
|
nsPresContext::EmulateMedium(const nsAString& aMediaType)
|
|
|
|
{
|
|
|
|
nsIAtom* previousMedium = Medium();
|
|
|
|
mIsEmulatingMedia = true;
|
|
|
|
|
|
|
|
nsAutoString mediaType;
|
|
|
|
nsContentUtils::ASCIIToLower(aMediaType, mediaType);
|
|
|
|
|
2016-03-28 23:09:43 +00:00
|
|
|
mMediaEmulated = NS_Atomize(mediaType);
|
2013-07-17 15:39:19 +00:00
|
|
|
if (mMediaEmulated != previousMedium && mShell) {
|
2014-10-08 21:27:03 +00:00
|
|
|
MediaFeatureValuesChanged(nsRestyleHint(0), nsChangeHint(0));
|
2013-07-17 15:39:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsPresContext::StopEmulatingMedium()
|
|
|
|
{
|
|
|
|
nsIAtom* previousMedium = Medium();
|
|
|
|
mIsEmulatingMedia = false;
|
|
|
|
if (Medium() != previousMedium) {
|
2014-10-08 21:27:03 +00:00
|
|
|
MediaFeatureValuesChanged(nsRestyleHint(0), nsChangeHint(0));
|
2013-07-17 15:39:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-09 09:38:28 +00:00
|
|
|
void
|
2014-10-08 21:26:57 +00:00
|
|
|
nsPresContext::RebuildAllStyleData(nsChangeHint aExtraHint,
|
|
|
|
nsRestyleHint aRestyleHint)
|
2008-01-09 09:38:28 +00:00
|
|
|
{
|
|
|
|
if (!mShell) {
|
|
|
|
// We must have been torn down. Nothing to do here.
|
|
|
|
return;
|
|
|
|
}
|
2008-11-25 23:22:38 +00:00
|
|
|
|
2012-10-26 17:04:20 +00:00
|
|
|
mUsesRootEMUnits = false;
|
2015-03-06 08:44:14 +00:00
|
|
|
mUsesExChUnits = false;
|
2012-10-19 23:21:06 +00:00
|
|
|
mUsesViewportUnits = false;
|
2015-06-27 01:39:54 +00:00
|
|
|
mDocument->RebuildUserFontSet();
|
2014-06-12 01:12:00 +00:00
|
|
|
RebuildCounterStyles();
|
2008-11-25 23:22:38 +00:00
|
|
|
|
2014-10-08 21:26:57 +00:00
|
|
|
RestyleManager()->RebuildAllStyleData(aExtraHint, aRestyleHint);
|
2008-01-09 09:38:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-10-08 21:27:02 +00:00
|
|
|
nsPresContext::PostRebuildAllStyleDataEvent(nsChangeHint aExtraHint,
|
|
|
|
nsRestyleHint aRestyleHint)
|
2008-01-09 09:38:28 +00:00
|
|
|
{
|
|
|
|
if (!mShell) {
|
|
|
|
// We must have been torn down. Nothing to do here.
|
|
|
|
return;
|
|
|
|
}
|
2014-10-08 21:27:02 +00:00
|
|
|
RestyleManager()->PostRebuildAllStyleDataEvent(aExtraHint, aRestyleHint);
|
2004-07-29 19:41:39 +00:00
|
|
|
}
|
|
|
|
|
2016-02-23 16:10:00 +00:00
|
|
|
struct MediaFeatureHints
|
|
|
|
{
|
|
|
|
nsRestyleHint restyleHint;
|
|
|
|
nsChangeHint changeHint;
|
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
MediaFeatureValuesChangedAllDocumentsCallback(nsIDocument* aDocument, void* aHints)
|
|
|
|
{
|
|
|
|
MediaFeatureHints* hints = static_cast<MediaFeatureHints*>(aHints);
|
|
|
|
if (nsIPresShell* shell = aDocument->GetShell()) {
|
|
|
|
if (nsPresContext* pc = shell->GetPresContext()) {
|
|
|
|
pc->MediaFeatureValuesChangedAllDocuments(hints->restyleHint,
|
|
|
|
hints->changeHint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsPresContext::MediaFeatureValuesChangedAllDocuments(nsRestyleHint aRestyleHint,
|
|
|
|
nsChangeHint aChangeHint)
|
|
|
|
{
|
|
|
|
MediaFeatureValuesChanged(aRestyleHint, aChangeHint);
|
|
|
|
MediaFeatureHints hints = {
|
|
|
|
aRestyleHint,
|
|
|
|
aChangeHint
|
|
|
|
};
|
|
|
|
|
|
|
|
mDocument->EnumerateSubDocuments(MediaFeatureValuesChangedAllDocumentsCallback,
|
|
|
|
&hints);
|
|
|
|
}
|
|
|
|
|
2008-07-26 16:14:48 +00:00
|
|
|
void
|
2014-10-08 21:27:03 +00:00
|
|
|
nsPresContext::MediaFeatureValuesChanged(nsRestyleHint aRestyleHint,
|
2012-11-09 06:40:41 +00:00
|
|
|
nsChangeHint aChangeHint)
|
2008-07-26 16:14:48 +00:00
|
|
|
{
|
2011-10-17 14:59:28 +00:00
|
|
|
mPendingMediaFeatureValuesChanged = false;
|
2012-10-19 23:21:06 +00:00
|
|
|
|
|
|
|
// MediumFeaturesChanged updates the applied rules, so it always gets called.
|
2016-02-24 07:01:11 +00:00
|
|
|
if (mShell) {
|
|
|
|
// XXXheycam ServoStyleSets don't support responding to medium
|
|
|
|
// changes yet.
|
|
|
|
if (mShell->StyleSet()->IsGecko()) {
|
|
|
|
if (mShell->StyleSet()->AsGecko()->MediumFeaturesChanged()) {
|
|
|
|
aRestyleHint |= eRestyle_Subtree;
|
|
|
|
}
|
|
|
|
} else {
|
2016-07-28 19:57:40 +00:00
|
|
|
NS_WARNING("stylo: ServoStyleSets don't support responding to medium "
|
|
|
|
"changes yet. See bug 1290228.");
|
2016-02-24 07:01:11 +00:00
|
|
|
}
|
2014-10-08 21:27:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mUsesViewportUnits && mPendingViewportChange) {
|
|
|
|
// Rebuild all style data without rerunning selector matching.
|
|
|
|
aRestyleHint |= eRestyle_ForceDescendants;
|
|
|
|
}
|
2012-10-19 23:21:06 +00:00
|
|
|
|
2014-10-08 21:27:03 +00:00
|
|
|
if (aRestyleHint || aChangeHint) {
|
|
|
|
RebuildAllStyleData(aChangeHint, aRestyleHint);
|
2008-07-26 16:14:48 +00:00
|
|
|
}
|
2011-04-22 03:17:31 +00:00
|
|
|
|
2012-10-19 23:21:06 +00:00
|
|
|
mPendingViewportChange = false;
|
|
|
|
|
2014-08-06 04:44:59 +00:00
|
|
|
if (mDocument->IsBeingUsedAsImage()) {
|
2014-10-03 18:15:25 +00:00
|
|
|
MOZ_ASSERT(PR_CLIST_IS_EMPTY(mDocument->MediaQueryLists()));
|
2011-04-22 03:17:31 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-05-11 22:07:49 +00:00
|
|
|
mDocument->NotifyMediaFeatureValuesChanged();
|
|
|
|
|
2014-08-06 04:44:59 +00:00
|
|
|
MOZ_ASSERT(nsContentUtils::IsSafeToRunScript());
|
|
|
|
|
2011-04-22 03:17:31 +00:00
|
|
|
// 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.
|
|
|
|
|
2014-10-03 18:15:25 +00:00
|
|
|
if (!PR_CLIST_IS_EMPTY(mDocument->MediaQueryLists())) {
|
2011-04-22 03:17:31 +00:00
|
|
|
// 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.
|
2015-07-13 06:46:04 +00:00
|
|
|
nsTArray<MediaQueryList::HandleChangeData> notifyList;
|
2014-10-03 18:15:25 +00:00
|
|
|
for (PRCList *l = PR_LIST_HEAD(mDocument->MediaQueryLists());
|
|
|
|
l != mDocument->MediaQueryLists(); l = PR_NEXT_LINK(l)) {
|
2013-12-16 14:03:19 +00:00
|
|
|
MediaQueryList *mql = static_cast<MediaQueryList*>(l);
|
2011-04-22 03:17:31 +00:00
|
|
|
mql->MediumFeaturesChanged(notifyList);
|
|
|
|
}
|
|
|
|
|
2011-04-23 20:19:01 +00:00
|
|
|
if (!notifyList.IsEmpty()) {
|
2012-08-22 15:56:38 +00:00
|
|
|
for (uint32_t i = 0, i_end = notifyList.Length(); i != i_end; ++i) {
|
2014-08-07 18:44:03 +00:00
|
|
|
nsAutoMicroTask mt;
|
|
|
|
MediaQueryList::HandleChangeData &d = notifyList[i];
|
Bug 1270626 - Don't leave an unhandled ErrorResult and assert when media query listeners throw exceptions. r=bzbarsky
I'm acting under the assumption that this is what's closest to what the
code does now, except without asserting in ~ErrorResult. It also seems
closest to what event listeners will do, both based on examining code
(EventListenerManager::HandleEventSubType, which I'm hoping is the right
code to look at, calls StealNSResult, and then stores it in a member
that's ignored by most callers) and based on testing (for both click
events, and for media query listeners with this patch, the exception
gets reported to the console as an unhandled exception). That said, I'm
not particularly well versed in the current error handling rules so I
may well be off here.
This code should presumably go away when we change this code to use
EventListeners in bug 1265622, so I don't think there's any spec that
covers this.
Without the patch, the mochitest hits the fatal assertion (after
reporting hitting the expected uncaught exception). With the
patch the test passes. (Tested locally.)
MozReview-Commit-ID: 5kxp6jzGzX8
--HG--
extra : transplant_source : n%B4%AE%99D%FB%B9NM%C0%A2%F0%D4%B7%8C%E7%DE4E%60
2016-05-06 04:33:47 +00:00
|
|
|
d.callback->Call(*d.mql);
|
2011-04-23 20:19:01 +00:00
|
|
|
}
|
2011-04-22 03:17:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NOTE: When |notifyList| goes out of scope, our destructor could run.
|
|
|
|
}
|
2008-07-26 16:14:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsPresContext::PostMediaFeatureValuesChangedEvent()
|
|
|
|
{
|
2011-04-22 03:17:31 +00:00
|
|
|
// FIXME: We should probably replace this event with use of
|
|
|
|
// nsRefreshDriver::AddStyleFlushObserver (except the pres shell would
|
|
|
|
// need to track whether it's been added).
|
2008-07-26 16:14:48 +00:00
|
|
|
if (!mPendingMediaFeatureValuesChanged) {
|
|
|
|
nsCOMPtr<nsIRunnable> ev =
|
2016-05-05 08:45:00 +00:00
|
|
|
NewRunnableMethod(this, &nsPresContext::HandleMediaFeatureValuesChangedEvent);
|
2008-07-26 16:14:48 +00:00
|
|
|
if (NS_SUCCEEDED(NS_DispatchToCurrentThread(ev))) {
|
2011-10-17 14:59:28 +00:00
|
|
|
mPendingMediaFeatureValuesChanged = true;
|
2011-12-15 04:42:15 +00:00
|
|
|
mDocument->SetNeedStyleFlush();
|
2008-07-26 16:14:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsPresContext::HandleMediaFeatureValuesChangedEvent()
|
|
|
|
{
|
|
|
|
// Null-check mShell in case the shell has been destroyed (and the
|
|
|
|
// event is the only thing holding the pres context alive).
|
|
|
|
if (mPendingMediaFeatureValuesChanged && mShell) {
|
2014-10-08 21:27:03 +00:00
|
|
|
MediaFeatureValuesChanged(nsRestyleHint(0));
|
2008-07-26 16:14:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-11 12:56:42 +00:00
|
|
|
static bool
|
2016-02-23 16:10:00 +00:00
|
|
|
NotifyTabSizeModeChanged(TabParent* aTab, void* aArg)
|
|
|
|
{
|
|
|
|
nsSizeMode* sizeMode = static_cast<nsSizeMode*>(aArg);
|
|
|
|
aTab->SizeModeChanged(*sizeMode);
|
2016-05-11 12:56:42 +00:00
|
|
|
return false;
|
2016-02-23 16:10:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsPresContext::SizeModeChanged(nsSizeMode aSizeMode)
|
|
|
|
{
|
|
|
|
if (HasCachedStyleData()) {
|
|
|
|
nsContentUtils::CallOnAllRemoteChildren(mDocument->GetWindow(),
|
|
|
|
NotifyTabSizeModeChanged,
|
|
|
|
&aSizeMode);
|
2016-03-23 21:56:00 +00:00
|
|
|
MediaFeatureValuesChangedAllDocuments(nsRestyleHint(0));
|
2016-02-23 16:10:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-30 04:29:41 +00:00
|
|
|
nsCompatibility
|
|
|
|
nsPresContext::CompatibilityMode() const
|
|
|
|
{
|
|
|
|
return Document()->GetCompatibilityMode();
|
|
|
|
}
|
|
|
|
|
2004-07-29 19:41:39 +00:00
|
|
|
void
|
2011-09-29 06:19:26 +00:00
|
|
|
nsPresContext::SetPaginatedScrolling(bool aPaginated)
|
2004-07-29 19:41:39 +00:00
|
|
|
{
|
2006-04-01 01:19:28 +00:00
|
|
|
if (mType == eContext_PrintPreview || mType == eContext_PageLayout)
|
2004-07-29 19:41:39 +00:00
|
|
|
mCanPaginatedScroll = aPaginated;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2004-07-31 23:15:21 +00:00
|
|
|
nsPresContext::SetPrintSettings(nsIPrintSettings *aPrintSettings)
|
2004-07-29 19:41:39 +00:00
|
|
|
{
|
2006-12-26 17:47:52 +00:00
|
|
|
if (mMedium == nsGkAtoms::print)
|
2004-07-29 19:41:39 +00:00
|
|
|
mPrintSettings = aPrintSettings;
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 18:00:39 +00:00
|
|
|
nsPresContext::EnsureVisible()
|
2005-01-20 03:39:09 +00:00
|
|
|
{
|
2013-11-20 19:18:25 +00:00
|
|
|
nsCOMPtr<nsIDocShell> docShell(mContainer);
|
2005-01-20 03:39:09 +00:00
|
|
|
if (docShell) {
|
|
|
|
nsCOMPtr<nsIContentViewer> cv;
|
|
|
|
docShell->GetContentViewer(getter_AddRefs(cv));
|
|
|
|
// Make sure this is the content viewer we belong with
|
2011-10-15 07:33:26 +00:00
|
|
|
if (cv) {
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<nsPresContext> currentPresContext;
|
2011-10-15 07:33:26 +00:00
|
|
|
cv->GetPresContext(getter_AddRefs(currentPresContext));
|
2005-01-20 03:39:09 +00:00
|
|
|
if (currentPresContext == this) {
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 18:00:39 +00:00
|
|
|
// OK, this is us. We want to call Show() on the content viewer.
|
2012-06-04 16:26:03 +00:00
|
|
|
nsresult result = cv->Show();
|
|
|
|
if (NS_SUCCEEDED(result)) {
|
|
|
|
return true;
|
|
|
|
}
|
2005-01-20 03:39:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2005-01-20 03:39:09 +00:00
|
|
|
}
|
|
|
|
|
2000-04-21 14:59:47 +00:00
|
|
|
#ifdef MOZ_REFLOW_PERF
|
2004-07-29 19:41:39 +00:00
|
|
|
void
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 05:38:33 +00:00
|
|
|
nsPresContext::CountReflows(const char * aName, nsIFrame * aFrame)
|
2000-04-21 14:59:47 +00:00
|
|
|
{
|
|
|
|
if (mShell) {
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 05:38:33 +00:00
|
|
|
mShell->CountReflows(aName, aFrame);
|
2000-04-21 14:59:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2007-05-16 21:10:31 +00:00
|
|
|
|
2014-02-07 03:08:49 +00:00
|
|
|
void
|
|
|
|
nsPresContext::UpdateIsChrome()
|
2007-05-16 21:10:31 +00:00
|
|
|
{
|
2014-01-20 07:58:26 +00:00
|
|
|
mIsChrome = mContainer &&
|
|
|
|
nsIDocShellTreeItem::typeChrome == mContainer->ItemType();
|
2007-05-16 21:10:31 +00:00
|
|
|
}
|
|
|
|
|
2016-08-25 22:14:44 +00:00
|
|
|
bool
|
2015-08-18 22:41:24 +00:00
|
|
|
nsPresContext::HasAuthorSpecifiedRules(const nsIFrame *aFrame,
|
|
|
|
uint32_t ruleTypeMask) const
|
2007-10-08 23:11:01 +00:00
|
|
|
{
|
2009-01-06 19:17:05 +00:00
|
|
|
return
|
2013-02-16 05:38:33 +00:00
|
|
|
nsRuleNode::HasAuthorSpecifiedRules(aFrame->StyleContext(),
|
2009-06-16 22:05:12 +00:00
|
|
|
ruleTypeMask,
|
|
|
|
UseDocumentColors());
|
2007-10-08 23:11:01 +00:00
|
|
|
}
|
2008-09-18 09:47:21 +00:00
|
|
|
|
2008-11-25 23:22:38 +00:00
|
|
|
gfxUserFontSet*
|
2015-06-27 01:39:54 +00:00
|
|
|
nsPresContext::GetUserFontSet()
|
2008-12-04 16:09:53 +00:00
|
|
|
{
|
2015-06-27 01:39:54 +00:00
|
|
|
return mDocument->GetUserFontSet();
|
2008-10-01 03:01:53 +00:00
|
|
|
}
|
|
|
|
|
2008-12-08 16:08:05 +00:00
|
|
|
void
|
2015-03-06 08:44:23 +00:00
|
|
|
nsPresContext::UserFontSetUpdated(gfxUserFontEntry* aUpdatedFont)
|
2008-12-08 16:08:05 +00:00
|
|
|
{
|
|
|
|
if (!mShell)
|
|
|
|
return;
|
|
|
|
|
2015-03-06 08:44:23 +00:00
|
|
|
bool usePlatformFontList = true;
|
2015-05-13 05:11:25 +00:00
|
|
|
#if defined(MOZ_WIDGET_GTK)
|
2016-07-11 23:16:45 +00:00
|
|
|
usePlatformFontList = gfxPlatformGtk::UseFcFontList();
|
2015-03-06 08:44:23 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// xxx - until the Linux platform font list is always used, use full
|
|
|
|
// restyle to force updates with gfxPangoFontGroup usage
|
|
|
|
// Note: this method is called without a font when rules in the userfont set
|
|
|
|
// are updated, which may occur during reflow as a result of the lazy
|
|
|
|
// initialization of the userfont set. It would be better to avoid a full
|
|
|
|
// restyle but until this method is only called outside of reflow, schedule a
|
|
|
|
// full restyle in these cases.
|
|
|
|
if (!usePlatformFontList || !aUpdatedFont) {
|
|
|
|
PostRebuildAllStyleDataEvent(NS_STYLE_HINT_REFLOW, eRestyle_ForceDescendants);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Special case - if either the 'ex' or 'ch' units are used, these
|
|
|
|
// depend upon 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.
|
|
|
|
if (UsesExChUnits()) {
|
2015-03-10 04:55:11 +00:00
|
|
|
PostRebuildAllStyleDataEvent(nsChangeHint(0), eRestyle_ForceDescendants);
|
2015-03-06 08:44:23 +00:00
|
|
|
}
|
2008-12-08 16:08:05 +00:00
|
|
|
|
2015-03-06 08:44:23 +00:00
|
|
|
// Iterate over the frame tree looking for frames associated with the
|
|
|
|
// downloadable font family in question. If a frame's nsStyleFont has
|
|
|
|
// the name, check the font group associated with the metrics to see if
|
|
|
|
// it contains that specific font (i.e. the one chosen within the family
|
|
|
|
// given the weight, width, and slant from the nsStyleFont). If it does,
|
|
|
|
// mark that frame dirty and skip inspecting its descendants.
|
2015-04-08 03:01:38 +00:00
|
|
|
nsIFrame* root = mShell->GetRootFrame();
|
|
|
|
if (root) {
|
|
|
|
nsFontFaceUtils::MarkDirtyForFontChange(root, aUpdatedFont);
|
|
|
|
}
|
2008-12-08 16:08:05 +00:00
|
|
|
}
|
|
|
|
|
2014-06-12 01:12:00 +00:00
|
|
|
void
|
|
|
|
nsPresContext::FlushCounterStyles()
|
|
|
|
{
|
|
|
|
if (!mShell) {
|
|
|
|
return; // we've been torn down
|
|
|
|
}
|
|
|
|
if (mCounterStyleManager->IsInitial()) {
|
|
|
|
// Still in its initial state, no need to clean.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mCounterStylesDirty) {
|
|
|
|
bool changed = mCounterStyleManager->NotifyRuleChanged();
|
|
|
|
if (changed) {
|
|
|
|
PresShell()->NotifyCounterStylesAreDirty();
|
2014-10-08 21:27:03 +00:00
|
|
|
PostRebuildAllStyleDataEvent(NS_STYLE_HINT_REFLOW,
|
|
|
|
eRestyle_ForceDescendants);
|
2014-06-12 01:12:00 +00:00
|
|
|
}
|
|
|
|
mCounterStylesDirty = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsPresContext::RebuildCounterStyles()
|
|
|
|
{
|
|
|
|
if (mCounterStyleManager->IsInitial()) {
|
|
|
|
// Still in its initial state, no need to reset.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mCounterStylesDirty = true;
|
|
|
|
mDocument->SetNeedStyleFlush();
|
|
|
|
if (!mPostedFlushCounterStyles) {
|
|
|
|
nsCOMPtr<nsIRunnable> ev =
|
2016-05-05 08:45:00 +00:00
|
|
|
NewRunnableMethod(this, &nsPresContext::HandleRebuildCounterStyles);
|
2014-06-12 01:12:00 +00:00
|
|
|
if (NS_SUCCEEDED(NS_DispatchToCurrentThread(ev))) {
|
|
|
|
mPostedFlushCounterStyles = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-22 16:35:54 +00:00
|
|
|
void
|
|
|
|
nsPresContext::NotifyMissingFonts()
|
|
|
|
{
|
|
|
|
if (mMissingFonts) {
|
|
|
|
mMissingFonts->Flush();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-11 08:00:33 +00:00
|
|
|
void
|
2009-12-31 15:56:33 +00:00
|
|
|
nsPresContext::EnsureSafeToHandOutCSSRules()
|
|
|
|
{
|
2016-02-24 07:01:11 +00:00
|
|
|
nsStyleSet* styleSet = mShell->StyleSet()->GetAsGecko();
|
|
|
|
if (!styleSet) {
|
|
|
|
// ServoStyleSets do not need to handle copy-on-write style sheet
|
|
|
|
// innards like with CSSStyleSheets.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!styleSet->EnsureUniqueInnerOnCSSSheets()) {
|
2009-12-31 15:56:33 +00:00
|
|
|
// Nothing to do.
|
2013-11-11 08:00:33 +00:00
|
|
|
return;
|
2009-12-31 15:56:33 +00:00
|
|
|
}
|
|
|
|
|
2014-10-08 21:26:57 +00:00
|
|
|
RebuildAllStyleData(nsChangeHint(0), eRestyle_Subtree);
|
2009-12-31 15:56:33 +00:00
|
|
|
}
|
|
|
|
|
2008-09-18 09:47:21 +00:00
|
|
|
void
|
2016-04-13 20:59:15 +00:00
|
|
|
nsPresContext::FireDOMPaintEvent(nsInvalidateRequestList* aList, uint64_t aTransactionId)
|
2008-09-18 09:47:21 +00:00
|
|
|
{
|
2016-01-30 17:05:36 +00:00
|
|
|
nsPIDOMWindowInner* ourWindow = mDocument->GetInnerWindow();
|
2008-10-15 21:06:32 +00:00
|
|
|
if (!ourWindow)
|
2008-09-18 09:47:21 +00:00
|
|
|
return;
|
2008-10-15 21:06:32 +00:00
|
|
|
|
2013-03-09 11:34:29 +00:00
|
|
|
nsCOMPtr<EventTarget> dispatchTarget = do_QueryInterface(ourWindow);
|
|
|
|
nsCOMPtr<EventTarget> eventTarget = dispatchTarget;
|
2012-08-29 05:47:18 +00: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-18 20:10:19 +00:00
|
|
|
}
|
2008-09-18 09:47:21 +00:00
|
|
|
}
|
|
|
|
// Events sent to the window get propagated to the chrome event handler
|
|
|
|
// automatically.
|
2015-08-12 11:39:31 +00:00
|
|
|
//
|
2009-09-04 04:49:18 +00:00
|
|
|
// This will empty our list in case dispatching the event causes more damage
|
|
|
|
// (hopefully it won't, or we're likely to get an infinite loop! At least
|
|
|
|
// it won't be blocking app execution though).
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<NotifyPaintEvent> event =
|
2016-04-13 20:59:15 +00:00
|
|
|
NS_NewDOMNotifyPaintEvent(eventTarget, this, nullptr, eAfterPaint, aList, aTransactionId);
|
2008-09-18 09:47:21 +00:00
|
|
|
|
|
|
|
// Even if we're not telling the window about the event (so eventTarget is
|
|
|
|
// the chrome event handler, not the window), the window is still
|
|
|
|
// logically the event target.
|
2012-06-10 23:44:50 +00:00
|
|
|
event->SetTarget(eventTarget);
|
|
|
|
event->SetTrusted(true);
|
2015-08-12 11:39:31 +00:00
|
|
|
EventDispatcher::DispatchDOMEvent(dispatchTarget, nullptr,
|
|
|
|
static_cast<Event*>(event), this, nullptr);
|
2008-09-18 09:47:21 +00:00
|
|
|
}
|
|
|
|
|
2012-08-29 05:47:18 +00: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 05:47:18 +00:00
|
|
|
*result = pc->MayHavePaintEventListenerInSubDocument();
|
2012-08-29 05:47:18 +00:00
|
|
|
|
|
|
|
// If we found a paint event listener, then we can stop enumerating
|
|
|
|
// sub documents.
|
|
|
|
return !*result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
static bool
|
2016-01-30 17:05:36 +00:00
|
|
|
MayHavePaintEventListener(nsPIDOMWindowInner* aInnerWindow)
|
2008-10-15 21:06:32 +00:00
|
|
|
{
|
|
|
|
if (!aInnerWindow)
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2008-10-15 21:06:32 +00:00
|
|
|
if (aInnerWindow->HasPaintEventListeners())
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2008-10-15 21:06:32 +00:00
|
|
|
|
2013-04-19 22:18:33 +00:00
|
|
|
EventTarget* parentTarget = aInnerWindow->GetParentTarget();
|
2010-06-16 11:43:36 +00:00
|
|
|
if (!parentTarget)
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2008-10-15 21:06:32 +00:00
|
|
|
|
2014-03-17 06:56:53 +00:00
|
|
|
EventListenerManager* manager = nullptr;
|
2013-10-22 23:32:04 +00:00
|
|
|
if ((manager = parentTarget->GetExistingListenerManager()) &&
|
2010-06-16 11:43:36 +00:00
|
|
|
manager->MayHavePaintEventListener()) {
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2010-06-16 11:43:36 +00:00
|
|
|
}
|
|
|
|
|
2010-05-18 12:28:37 +00:00
|
|
|
nsCOMPtr<nsINode> node;
|
2010-06-16 11:43:36 +00:00
|
|
|
if (parentTarget != aInnerWindow->GetChromeEventHandler()) {
|
|
|
|
nsCOMPtr<nsIInProcessContentFrameMessageManager> mm =
|
|
|
|
do_QueryInterface(parentTarget);
|
|
|
|
if (mm) {
|
|
|
|
node = mm->GetOwnerContent();
|
2010-05-18 12:28:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!node) {
|
2010-06-16 11:43:36 +00:00
|
|
|
node = do_QueryInterface(parentTarget);
|
2010-05-18 12:28:37 +00:00
|
|
|
}
|
2008-10-15 21:06:32 +00:00
|
|
|
if (node)
|
2011-10-18 10:53:36 +00:00
|
|
|
return MayHavePaintEventListener(node->OwnerDoc()->GetInnerWindow());
|
2008-10-15 21:06:32 +00:00
|
|
|
|
2016-01-30 17:05:36 +00:00
|
|
|
nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface(parentTarget);
|
2008-10-15 21:06:32 +00:00
|
|
|
if (window)
|
|
|
|
return MayHavePaintEventListener(window);
|
|
|
|
|
2010-07-01 04:04:29 +00:00
|
|
|
nsCOMPtr<nsPIWindowRoot> root = do_QueryInterface(parentTarget);
|
2013-04-19 22:18:33 +00:00
|
|
|
EventTarget* tabChildGlobal;
|
2010-07-01 04:04:29 +00:00
|
|
|
return root &&
|
|
|
|
(tabChildGlobal = root->GetParentTarget()) &&
|
2013-10-22 23:32:04 +00:00
|
|
|
(manager = tabChildGlobal->GetExistingListenerManager()) &&
|
2010-07-01 04:04:29 +00:00
|
|
|
manager->MayHavePaintEventListener();
|
2008-10-15 21:06:32 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2009-09-04 04:49:18 +00:00
|
|
|
nsPresContext::MayHavePaintEventListener()
|
|
|
|
{
|
|
|
|
return ::MayHavePaintEventListener(mDocument->GetInnerWindow());
|
|
|
|
}
|
|
|
|
|
2012-08-29 05:47:18 +00:00
|
|
|
bool
|
|
|
|
nsPresContext::MayHavePaintEventListenerInSubDocument()
|
|
|
|
{
|
|
|
|
if (MayHavePaintEventListener()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool result = false;
|
|
|
|
mDocument->EnumerateSubDocuments(MayHavePaintEventListenerSubdocumentCallback, &result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2012-08-29 05:48:44 +00:00
|
|
|
void
|
|
|
|
nsPresContext::NotifyInvalidation(uint32_t aFlags)
|
|
|
|
{
|
|
|
|
nsIFrame* rootFrame = PresShell()->FrameManager()->GetRootFrame();
|
|
|
|
NotifyInvalidation(rootFrame->GetVisualOverflowRect(), aFlags);
|
2016-09-23 10:20:33 +00:00
|
|
|
mAllInvalidated = true;
|
2012-08-29 05:48:44 +00:00
|
|
|
}
|
|
|
|
|
2012-08-29 05:47:18 +00:00
|
|
|
void
|
|
|
|
nsPresContext::NotifyInvalidation(const nsIntRect& aRect, uint32_t aFlags)
|
|
|
|
{
|
2016-02-11 22:35:17 +00:00
|
|
|
// Prevent values from overflow after DevPixelsToAppUnits().
|
|
|
|
//
|
|
|
|
// DevPixelsTopAppUnits() will multiple a factor (60) to the value,
|
|
|
|
// it may make the result value over the edge (overflow) of max or
|
|
|
|
// min value of int32_t. Compute the max sized dev pixel rect that
|
|
|
|
// we can support and intersect with it.
|
|
|
|
nsIntRect clampedRect = nsIntRect::MaxIntRect();
|
|
|
|
clampedRect.ScaleInverseRoundIn(AppUnitsPerDevPixel());
|
|
|
|
|
|
|
|
clampedRect = clampedRect.Intersect(aRect);
|
|
|
|
|
|
|
|
nsRect rect(DevPixelsToAppUnits(clampedRect.x),
|
|
|
|
DevPixelsToAppUnits(clampedRect.y),
|
|
|
|
DevPixelsToAppUnits(clampedRect.width),
|
|
|
|
DevPixelsToAppUnits(clampedRect.height));
|
2012-08-29 05:47:18 +00:00
|
|
|
NotifyInvalidation(rect, aFlags);
|
|
|
|
}
|
|
|
|
|
2008-09-18 09:47:21 +00:00
|
|
|
void
|
2012-08-22 15:56:38 +00:00
|
|
|
nsPresContext::NotifyInvalidation(const nsRect& aRect, uint32_t aFlags)
|
2008-09-18 09:47:21 +00:00
|
|
|
{
|
2014-02-10 02:14:38 +00:00
|
|
|
MOZ_ASSERT(GetContainerWeak(), "Invalidation in detached pres context");
|
2014-02-03 23:47:57 +00:00
|
|
|
|
2008-10-15 21:06:32 +00:00
|
|
|
// If there is no paint event listener, then we don't need to fire
|
|
|
|
// the asynchronous event. We don't even need to record invalidation.
|
|
|
|
// MayHavePaintEventListener is pretty cheap and we could make it
|
|
|
|
// even cheaper by providing a more efficient
|
|
|
|
// nsPIDOMWindow::GetListenerManager.
|
2014-03-20 06:49:25 +00:00
|
|
|
|
2016-09-23 10:20:33 +00:00
|
|
|
if (mAllInvalidated) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-01-15 09:40:33 +00:00
|
|
|
nsPresContext* pc;
|
2012-05-04 05:00:57 +00:00
|
|
|
for (pc = this; pc; pc = pc->GetParentPresContext()) {
|
2011-01-15 09:40:33 +00:00
|
|
|
if (pc->mFireAfterPaintEvents)
|
|
|
|
break;
|
2011-10-17 14:59:28 +00:00
|
|
|
pc->mFireAfterPaintEvents = true;
|
2011-01-15 09:40:33 +00:00
|
|
|
}
|
|
|
|
if (!pc) {
|
|
|
|
nsRootPresContext* rpc = GetRootPresContext();
|
|
|
|
if (rpc) {
|
|
|
|
rpc->EnsureEventualDidPaintEvent();
|
|
|
|
}
|
2008-09-18 09:47:21 +00:00
|
|
|
}
|
|
|
|
|
2009-09-04 04:49:18 +00:00
|
|
|
nsInvalidateRequestList::Request* request =
|
2012-10-19 04:50:34 +00:00
|
|
|
mInvalidateRequestsSinceLastPaint.mRequests.AppendElement();
|
2009-09-04 04:49:18 +00:00
|
|
|
if (!request)
|
|
|
|
return;
|
|
|
|
|
|
|
|
request->mRect = aRect;
|
|
|
|
request->mFlags = aFlags;
|
2008-09-18 09:47:21 +00:00
|
|
|
}
|
2008-12-29 15:07:36 +00:00
|
|
|
|
2014-03-20 06:49:25 +00:00
|
|
|
/* static */ void
|
2012-08-29 05:47:18 +00:00
|
|
|
nsPresContext::NotifySubDocInvalidation(ContainerLayer* aContainer,
|
|
|
|
const nsIntRegion& aRegion)
|
|
|
|
{
|
2014-03-20 06:49:25 +00:00
|
|
|
ContainerLayerPresContext *data =
|
2012-08-29 05:47:18 +00:00
|
|
|
static_cast<ContainerLayerPresContext*>(
|
|
|
|
aContainer->GetUserData(&gNotifySubDocInvalidationData));
|
|
|
|
if (!data) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-11-29 07:07:55 +00:00
|
|
|
nsIntPoint topLeft = aContainer->GetVisibleRegion().ToUnknownRegion().GetBounds().TopLeft();
|
2012-08-29 05:47:18 +00:00
|
|
|
|
2016-01-19 01:20:59 +00:00
|
|
|
for (auto iter = aRegion.RectIter(); !iter.Done(); iter.Next()) {
|
|
|
|
nsIntRect rect(iter.Get());
|
2012-08-29 05:47:18 +00:00
|
|
|
//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 11:33:03 +00: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 04:50:34 +00:00
|
|
|
struct NotifyDidPaintSubdocumentCallbackClosure {
|
|
|
|
uint32_t mFlags;
|
2016-04-13 20:59:15 +00:00
|
|
|
uint64_t mTransactionId;
|
2012-10-19 04:50:34 +00:00
|
|
|
bool mNeedsAnotherDidPaintNotification;
|
|
|
|
};
|
2011-09-29 06:19:26 +00:00
|
|
|
static bool
|
2011-01-15 09:40:33 +00:00
|
|
|
NotifyDidPaintSubdocumentCallback(nsIDocument* aDocument, void* aData)
|
|
|
|
{
|
2012-10-19 04:50:34 +00:00
|
|
|
NotifyDidPaintSubdocumentCallbackClosure* closure =
|
|
|
|
static_cast<NotifyDidPaintSubdocumentCallbackClosure*>(aData);
|
2011-01-15 09:40:33 +00:00
|
|
|
nsIPresShell* shell = aDocument->GetShell();
|
|
|
|
if (shell) {
|
|
|
|
nsPresContext* pc = shell->GetPresContext();
|
|
|
|
if (pc) {
|
2016-04-13 20:59:15 +00:00
|
|
|
pc->NotifyDidPaintForSubtree(closure->mFlags, closure->mTransactionId);
|
2012-10-19 04:50:34 +00:00
|
|
|
if (pc->IsDOMPaintEventPending()) {
|
|
|
|
closure->mNeedsAnotherDidPaintNotification = true;
|
|
|
|
}
|
2011-01-15 09:40:33 +00:00
|
|
|
}
|
|
|
|
}
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2011-01-15 09:40:33 +00:00
|
|
|
}
|
|
|
|
|
2016-04-26 00:23:21 +00:00
|
|
|
class DelayedFireDOMPaintEvent : public Runnable {
|
2012-10-19 04:50:34 +00:00
|
|
|
public:
|
|
|
|
DelayedFireDOMPaintEvent(nsPresContext* aPresContext,
|
2016-04-13 20:59:15 +00:00
|
|
|
nsInvalidateRequestList* aList,
|
|
|
|
uint64_t aTransactionId)
|
2012-10-19 04:50:34 +00:00
|
|
|
: mPresContext(aPresContext)
|
2016-04-13 20:59:15 +00:00
|
|
|
, mTransactionId(aTransactionId)
|
2012-10-19 04:50:34 +00:00
|
|
|
{
|
2014-02-03 23:47:57 +00:00
|
|
|
MOZ_ASSERT(mPresContext->GetContainerWeak(),
|
|
|
|
"DOMPaintEvent requested for a detached pres context");
|
2012-10-19 04:50:34 +00:00
|
|
|
mList.TakeFrom(aList);
|
|
|
|
}
|
2015-03-21 16:28:04 +00:00
|
|
|
NS_IMETHOD Run() override
|
2012-10-19 04:50:34 +00:00
|
|
|
{
|
2014-02-03 23:47:57 +00:00
|
|
|
// The pres context might have been detached during the delay -
|
|
|
|
// that's fine, just don't fire the event.
|
|
|
|
if (mPresContext->GetContainerWeak()) {
|
2016-04-13 20:59:15 +00:00
|
|
|
mPresContext->FireDOMPaintEvent(&mList, mTransactionId);
|
2014-02-03 23:47:57 +00:00
|
|
|
}
|
2012-10-19 04:50:34 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<nsPresContext> mPresContext;
|
2016-04-13 20:59:15 +00:00
|
|
|
uint64_t mTransactionId;
|
2012-10-19 04:50:34 +00:00
|
|
|
nsInvalidateRequestList mList;
|
|
|
|
};
|
|
|
|
|
2011-01-15 09:40:33 +00:00
|
|
|
void
|
2016-04-13 20:59:15 +00:00
|
|
|
nsPresContext::NotifyDidPaintForSubtree(uint32_t aFlags, uint64_t aTransactionId,
|
|
|
|
const mozilla::TimeStamp& aTimeStamp)
|
2011-01-15 09:40:33 +00:00
|
|
|
{
|
2012-09-27 15:34:46 +00:00
|
|
|
if (IsRoot()) {
|
2011-01-15 09:40:33 +00:00
|
|
|
static_cast<nsRootPresContext*>(this)->CancelDidPaintTimer();
|
|
|
|
|
2012-10-23 01:52:48 +00:00
|
|
|
if (!mFireAfterPaintEvents) {
|
|
|
|
return;
|
|
|
|
}
|
2012-10-19 04:50:34 +00:00
|
|
|
}
|
2014-10-21 08:59:59 +00:00
|
|
|
|
|
|
|
if (!PresShell()->IsVisible() && !mFireAfterPaintEvents) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-10-23 01:52:48 +00: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 05:47:18 +00:00
|
|
|
|
2012-10-19 04:50:34 +00:00
|
|
|
if (aFlags & nsIPresShell::PAINT_LAYERS) {
|
|
|
|
mUndeliveredInvalidateRequestsBeforeLastPaint.TakeFrom(
|
|
|
|
&mInvalidateRequestsSinceLastPaint);
|
2016-09-23 10:20:33 +00:00
|
|
|
mAllInvalidated = false;
|
2012-10-19 04:50:34 +00:00
|
|
|
}
|
|
|
|
if (aFlags & nsIPresShell::PAINT_COMPOSITE) {
|
|
|
|
nsCOMPtr<nsIRunnable> ev =
|
2016-04-13 20:59:15 +00:00
|
|
|
new DelayedFireDOMPaintEvent(this, &mUndeliveredInvalidateRequestsBeforeLastPaint,
|
|
|
|
aTransactionId);
|
2012-10-19 04:50:34 +00:00
|
|
|
nsContentUtils::AddScriptRunner(ev);
|
|
|
|
}
|
|
|
|
|
2016-04-13 20:59:15 +00:00
|
|
|
NotifyDidPaintSubdocumentCallbackClosure closure = { aFlags, aTransactionId, false };
|
2012-10-19 04:50:34 +00:00
|
|
|
mDocument->EnumerateSubDocuments(NotifyDidPaintSubdocumentCallback, &closure);
|
2011-01-15 09:40:33 +00:00
|
|
|
|
2012-10-19 04:50:34 +00: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 09:40:33 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2008-12-29 15:07:36 +00:00
|
|
|
nsPresContext::HasCachedStyleData()
|
|
|
|
{
|
2016-02-24 07:01:11 +00:00
|
|
|
if (!mShell) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsStyleSet* styleSet = mShell->StyleSet()->GetAsGecko();
|
|
|
|
if (!styleSet) {
|
|
|
|
// XXXheycam ServoStyleSets do not use the rule tree, so just assume for now
|
2016-08-31 21:59:21 +00:00
|
|
|
// that we need to restyle when e.g. dppx changes assuming we're sufficiently
|
|
|
|
// bootstrapped.
|
|
|
|
return mShell->DidInitialize();
|
2016-02-24 07:01:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return styleSet->HasCachedStyleData();
|
2008-12-29 15:07:36 +00:00
|
|
|
}
|
2009-04-21 23:53:52 +00:00
|
|
|
|
2015-08-04 00:13:07 +00:00
|
|
|
already_AddRefed<nsITimer>
|
|
|
|
nsPresContext::CreateTimer(nsTimerCallbackFunc aCallback,
|
|
|
|
uint32_t aDelay)
|
2015-07-30 21:24:51 +00:00
|
|
|
{
|
2015-08-04 00:13:07 +00:00
|
|
|
nsCOMPtr<nsITimer> timer = do_CreateInstance("@mozilla.org/timer;1");
|
|
|
|
if (timer) {
|
|
|
|
nsresult rv = timer->InitWithFuncCallback(aCallback, this, aDelay,
|
|
|
|
nsITimer::TYPE_ONE_SHOT);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
return timer.forget();
|
|
|
|
}
|
2015-07-30 21:24:51 +00:00
|
|
|
}
|
|
|
|
|
2015-08-04 00:13:07 +00:00
|
|
|
return nullptr;
|
2015-07-30 21:24:51 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
static bool sGotInterruptEnv = false;
|
2009-04-21 23:53:52 +00:00
|
|
|
enum InterruptMode {
|
|
|
|
ModeRandom,
|
|
|
|
ModeCounter,
|
|
|
|
ModeEvent
|
|
|
|
};
|
2009-10-02 18:05:32 +00:00
|
|
|
// Controlled by the GECKO_REFLOW_INTERRUPT_MODE env var; allowed values are
|
|
|
|
// "random" (except on Windows) or "counter". If neither is used, the mode is
|
|
|
|
// ModeEvent.
|
2009-04-21 23:53:52 +00:00
|
|
|
static InterruptMode sInterruptMode = ModeEvent;
|
2013-01-10 07:04:09 +00:00
|
|
|
#ifndef XP_WIN
|
2009-10-02 18:05:32 +00:00
|
|
|
// Used for the "random" mode. Controlled by the GECKO_REFLOW_INTERRUPT_SEED
|
|
|
|
// env var.
|
2012-08-22 15:56:38 +00:00
|
|
|
static uint32_t sInterruptSeed = 1;
|
2013-01-10 07:04:09 +00:00
|
|
|
#endif
|
2009-10-02 18:05:32 +00: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 15:56:38 +00:00
|
|
|
static uint32_t sInterruptMaxCounter = 10;
|
2009-10-02 18:05:32 +00:00
|
|
|
// Used for the "counter" mode. This counts up to sInterruptMaxCounter and is
|
|
|
|
// then reset to 0.
|
2012-08-22 15:56:38 +00:00
|
|
|
static uint32_t sInterruptCounter;
|
2009-10-02 18:05:32 +00: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 15:56:38 +00:00
|
|
|
static uint32_t sInterruptChecksToSkip = 200;
|
2009-10-02 18:05:32 +00:00
|
|
|
// Number of milliseconds that a reflow should be allowed to run for before we
|
|
|
|
// actually allow interruption. Controlled by the
|
2011-10-11 21:29:12 +00:00
|
|
|
// GECKO_REFLOW_MIN_NOINTERRUPT_DURATION env var. Can't be initialized here,
|
|
|
|
// because TimeDuration/TimeStamp is not safe to use in static constructors..
|
|
|
|
static TimeDuration sInterruptTimeout;
|
2009-04-21 23:53:52 +00:00
|
|
|
|
|
|
|
static void GetInterruptEnv()
|
|
|
|
{
|
|
|
|
char *ev = PR_GetEnv("GECKO_REFLOW_INTERRUPT_MODE");
|
|
|
|
if (ev) {
|
|
|
|
#ifndef XP_WIN
|
|
|
|
if (PL_strcasecmp(ev, "random") == 0) {
|
|
|
|
ev = PR_GetEnv("GECKO_REFLOW_INTERRUPT_SEED");
|
|
|
|
if (ev) {
|
|
|
|
sInterruptSeed = atoi(ev);
|
|
|
|
}
|
|
|
|
srandom(sInterruptSeed);
|
|
|
|
sInterruptMode = ModeRandom;
|
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
if (PL_strcasecmp(ev, "counter") == 0) {
|
|
|
|
ev = PR_GetEnv("GECKO_REFLOW_INTERRUPT_FREQUENCY");
|
|
|
|
if (ev) {
|
|
|
|
sInterruptMaxCounter = atoi(ev);
|
|
|
|
}
|
|
|
|
sInterruptCounter = 0;
|
|
|
|
sInterruptMode = ModeCounter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ev = PR_GetEnv("GECKO_REFLOW_INTERRUPT_CHECKS_TO_SKIP");
|
|
|
|
if (ev) {
|
|
|
|
sInterruptChecksToSkip = atoi(ev);
|
|
|
|
}
|
2009-10-02 18:05:32 +00:00
|
|
|
|
|
|
|
ev = PR_GetEnv("GECKO_REFLOW_MIN_NOINTERRUPT_DURATION");
|
2011-10-11 21:29:12 +00:00
|
|
|
int duration_ms = ev ? atoi(ev) : 100;
|
|
|
|
sInterruptTimeout = TimeDuration::FromMilliseconds(duration_ms);
|
2009-04-21 23:53:52 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2009-04-21 23:53:52 +00:00
|
|
|
nsPresContext::HavePendingInputEvent()
|
|
|
|
{
|
|
|
|
switch (sInterruptMode) {
|
|
|
|
#ifndef XP_WIN
|
|
|
|
case ModeRandom:
|
|
|
|
return (random() & 1);
|
|
|
|
#endif
|
|
|
|
case ModeCounter:
|
|
|
|
if (sInterruptCounter < sInterruptMaxCounter) {
|
|
|
|
++sInterruptCounter;
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2009-04-21 23:53:52 +00:00
|
|
|
}
|
|
|
|
sInterruptCounter = 0;
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2009-04-21 23:53:52 +00:00
|
|
|
default:
|
|
|
|
case ModeEvent: {
|
|
|
|
nsIFrame* f = PresShell()->GetRootFrame();
|
|
|
|
if (f) {
|
2010-07-02 19:11:04 +00:00
|
|
|
nsIWidget* w = f->GetNearestWidget();
|
2009-04-21 23:53:52 +00:00
|
|
|
if (w) {
|
|
|
|
return w->HasPendingInputEvent();
|
|
|
|
}
|
|
|
|
}
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2009-04-21 23:53:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-02 02:32:09 +00:00
|
|
|
void
|
|
|
|
nsPresContext::NotifyFontFaceSetOnRefresh()
|
|
|
|
{
|
2015-06-27 01:39:54 +00:00
|
|
|
FontFaceSet* set = mDocument->GetFonts();
|
|
|
|
if (set) {
|
|
|
|
set->DidRefresh();
|
2014-10-02 02:32:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsPresContext::HasPendingRestyleOrReflow()
|
|
|
|
{
|
|
|
|
return (mRestyleManager && mRestyleManager->HasPendingRestyles()) ||
|
|
|
|
PresShell()->HasPendingReflow();
|
|
|
|
}
|
|
|
|
|
2009-04-21 23:53:52 +00:00
|
|
|
void
|
2011-09-29 06:19:26 +00:00
|
|
|
nsPresContext::ReflowStarted(bool aInterruptible)
|
2009-04-21 23:53:52 +00:00
|
|
|
{
|
2009-10-02 18:05:32 +00:00
|
|
|
#ifdef NOISY_INTERRUPTIBLE_REFLOW
|
|
|
|
if (!aInterruptible) {
|
|
|
|
printf("STARTING NONINTERRUPTIBLE REFLOW\n");
|
|
|
|
}
|
|
|
|
#endif
|
2009-04-21 23:53:52 +00:00
|
|
|
// We don't support interrupting in paginated contexts, since page
|
|
|
|
// sequences only handle initial reflow
|
2014-04-10 04:47:58 +00:00
|
|
|
mInterruptsEnabled = aInterruptible && !IsPaginated() &&
|
|
|
|
nsLayoutUtils::InterruptibleReflowEnabled();
|
2009-04-21 23:53:52 +00:00
|
|
|
|
|
|
|
// Don't set mHasPendingInterrupt based on HavePendingInputEvent() here. If
|
|
|
|
// we ever change that, then we need to update the code in
|
|
|
|
// PresShell::DoReflow to only add the just-reflown root to dirty roots if
|
|
|
|
// it's actually dirty. Otherwise we can end up adding a root that has no
|
|
|
|
// interruptible descendants, just because we detected an interrupt at reflow
|
|
|
|
// start.
|
2011-10-17 14:59:28 +00:00
|
|
|
mHasPendingInterrupt = false;
|
2009-04-21 23:53:52 +00:00
|
|
|
|
|
|
|
mInterruptChecksToSkip = sInterruptChecksToSkip;
|
2009-10-02 18:05:32 +00:00
|
|
|
|
|
|
|
if (mInterruptsEnabled) {
|
|
|
|
mReflowStartTime = TimeStamp::Now();
|
|
|
|
}
|
2009-04-21 23:53:52 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2009-04-21 23:53:52 +00:00
|
|
|
nsPresContext::CheckForInterrupt(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
if (mHasPendingInterrupt) {
|
|
|
|
mShell->FrameNeedsToContinueReflow(aFrame);
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2009-04-21 23:53:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!sGotInterruptEnv) {
|
2011-10-17 14:59:28 +00:00
|
|
|
sGotInterruptEnv = true;
|
2009-04-21 23:53:52 +00:00
|
|
|
GetInterruptEnv();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mInterruptsEnabled) {
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2009-04-21 23:53:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mInterruptChecksToSkip > 0) {
|
|
|
|
--mInterruptChecksToSkip;
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2009-04-21 23:53:52 +00:00
|
|
|
}
|
|
|
|
mInterruptChecksToSkip = sInterruptChecksToSkip;
|
|
|
|
|
2009-10-02 18:05:32 +00:00
|
|
|
// Don't interrupt if it's been less than sInterruptTimeout since we started
|
|
|
|
// the reflow.
|
|
|
|
mHasPendingInterrupt =
|
|
|
|
TimeStamp::Now() - mReflowStartTime > sInterruptTimeout &&
|
|
|
|
HavePendingInputEvent() &&
|
|
|
|
!IsChrome();
|
2016-08-24 13:15:42 +00:00
|
|
|
|
|
|
|
if (mPendingInterruptFromTest) {
|
|
|
|
mPendingInterruptFromTest = false;
|
|
|
|
mHasPendingInterrupt = true;
|
|
|
|
}
|
|
|
|
|
2009-04-21 23:53:52 +00:00
|
|
|
if (mHasPendingInterrupt) {
|
|
|
|
#ifdef NOISY_INTERRUPTIBLE_REFLOW
|
|
|
|
printf("*** DETECTED pending interrupt (time=%lld)\n", PR_Now());
|
|
|
|
#endif /* NOISY_INTERRUPTIBLE_REFLOW */
|
|
|
|
mShell->FrameNeedsToContinueReflow(aFrame);
|
|
|
|
}
|
|
|
|
return mHasPendingInterrupt;
|
|
|
|
}
|
2009-07-22 00:44:54 +00:00
|
|
|
|
2012-07-30 04:29:41 +00:00
|
|
|
nsIFrame*
|
|
|
|
nsPresContext::GetPrimaryFrameFor(nsIContent* aContent)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aContent, "Don't do that");
|
|
|
|
if (GetPresShell() &&
|
2014-08-05 23:23:02 +00:00
|
|
|
GetPresShell()->GetDocument() == aContent->GetComposedDoc()) {
|
2012-07-30 04:29:41 +00:00
|
|
|
return aContent->GetPrimaryFrame();
|
|
|
|
}
|
2012-07-30 14:28:15 +00:00
|
|
|
return nullptr;
|
2012-07-30 04:29:41 +00:00
|
|
|
}
|
|
|
|
|
2012-02-21 05:02:24 +00:00
|
|
|
size_t
|
2013-06-23 12:03:39 +00:00
|
|
|
nsPresContext::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const
|
2012-02-21 05:02:24 +00:00
|
|
|
{
|
2015-11-14 08:06:58 +00:00
|
|
|
return mPropertyTable.SizeOfExcludingThis(aMallocSizeOf) +
|
2012-02-21 05:02:24 +00:00
|
|
|
mLangGroupFontPrefs.SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
|
|
|
|
// Measurement of other members may be added later if DMD finds it is
|
|
|
|
// worthwhile.
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2016-02-24 14:57:43 +00:00
|
|
|
nsPresContext::IsRootContentDocument() const
|
2010-09-11 18:24:50 +00:00
|
|
|
{
|
2010-10-09 19:09:22 +00:00
|
|
|
// We are a root content document if: we are not a resource doc, we are
|
|
|
|
// not chrome, and we either have no parent or our parent is chrome.
|
|
|
|
if (mDocument->IsResourceDoc()) {
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2010-10-09 19:09:22 +00:00
|
|
|
}
|
2010-09-11 18:24:50 +00:00
|
|
|
if (IsChrome()) {
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2010-09-11 18:24:50 +00:00
|
|
|
}
|
|
|
|
// We may not have a root frame, so use views.
|
2013-01-03 13:23:11 +00:00
|
|
|
nsView* view = PresShell()->GetViewManager()->GetRootView();
|
2011-03-30 02:24:54 +00:00
|
|
|
if (!view) {
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2010-09-11 18:24:50 +00:00
|
|
|
}
|
|
|
|
view = view->GetParent(); // anonymous inner view
|
|
|
|
if (!view) {
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2010-09-11 18:24:50 +00:00
|
|
|
}
|
|
|
|
view = view->GetParent(); // subdocumentframe's view
|
|
|
|
if (!view) {
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2010-09-11 18:24:50 +00:00
|
|
|
}
|
|
|
|
|
2011-11-21 17:53:20 +00:00
|
|
|
nsIFrame* f = view->GetFrame();
|
2010-09-11 18:24:50 +00:00
|
|
|
return (f && f->PresContext()->IsChrome());
|
|
|
|
}
|
|
|
|
|
2013-07-22 15:51:38 +00: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;
|
|
|
|
}
|
|
|
|
|
2013-09-23 11:52:25 +00:00
|
|
|
int32_t
|
|
|
|
nsPresContext::AppUnitsPerDevPixel() const
|
|
|
|
{
|
|
|
|
return mDeviceContext->AppUnitsPerDevPixel();
|
|
|
|
}
|
|
|
|
|
|
|
|
nscoord
|
|
|
|
nsPresContext::GfxUnitsToAppUnits(gfxFloat aGfxUnits) const
|
|
|
|
{
|
|
|
|
return mDeviceContext->GfxUnitsToAppUnits(aGfxUnits);
|
|
|
|
}
|
|
|
|
|
|
|
|
gfxFloat
|
|
|
|
nsPresContext::AppUnitsToGfxUnits(nscoord aAppUnits) const
|
|
|
|
{
|
|
|
|
return mDeviceContext->AppUnitsToGfxUnits(aAppUnits);
|
|
|
|
}
|
|
|
|
|
2013-11-07 13:40:23 +00:00
|
|
|
bool
|
|
|
|
nsPresContext::IsDeviceSizePageSize()
|
|
|
|
{
|
|
|
|
bool isDeviceSizePageSize = false;
|
2013-11-20 19:18:25 +00:00
|
|
|
nsCOMPtr<nsIDocShell> docShell(mContainer);
|
2013-11-07 13:40:23 +00:00
|
|
|
if (docShell) {
|
|
|
|
isDeviceSizePageSize = docShell->GetDeviceSizeIsPageSize();
|
|
|
|
}
|
|
|
|
return isDeviceSizePageSize;
|
|
|
|
}
|
2015-09-17 02:08:20 +00:00
|
|
|
|
|
|
|
uint64_t
|
|
|
|
nsPresContext::GetRestyleGeneration() const
|
|
|
|
{
|
|
|
|
if (!mRestyleManager) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return mRestyleManager->GetRestyleGeneration();
|
|
|
|
}
|
2013-11-07 13:40:23 +00:00
|
|
|
|
2009-07-22 00:44:54 +00:00
|
|
|
nsRootPresContext::nsRootPresContext(nsIDocument* aDocument,
|
|
|
|
nsPresContextType aType)
|
2010-07-15 21:08:08 +00:00
|
|
|
: nsPresContext(aDocument, aType),
|
2012-10-06 13:03:23 +00:00
|
|
|
mDOMGeneration(0)
|
2009-07-22 00:44:54 +00:00
|
|
|
{
|
2010-07-15 21:08:08 +00:00
|
|
|
}
|
2009-07-22 00:45:00 +00:00
|
|
|
|
|
|
|
nsRootPresContext::~nsRootPresContext()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mRegisteredPlugins.Count() == 0,
|
|
|
|
"All plugins should have been unregistered");
|
2011-01-15 09:40:33 +00:00
|
|
|
CancelDidPaintTimer();
|
2012-10-06 13:03:23 +00:00
|
|
|
CancelApplyPluginGeometryTimer();
|
2009-07-22 00:45:00 +00:00
|
|
|
}
|
|
|
|
|
2014-02-03 23:47:57 +00:00
|
|
|
/* virtual */ void
|
|
|
|
nsRootPresContext::Detach()
|
|
|
|
{
|
|
|
|
CancelDidPaintTimer();
|
|
|
|
// XXXmats maybe also CancelApplyPluginGeometryTimer(); ?
|
|
|
|
nsPresContext::Detach();
|
|
|
|
}
|
|
|
|
|
2009-07-22 00:45:00 +00:00
|
|
|
void
|
2012-08-14 04:06:42 +00:00
|
|
|
nsRootPresContext::RegisterPluginForGeometryUpdates(nsIContent* aPlugin)
|
2009-07-22 00:45:00 +00:00
|
|
|
{
|
|
|
|
mRegisteredPlugins.PutEntry(aPlugin);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-08-14 04:06:42 +00:00
|
|
|
nsRootPresContext::UnregisterPluginForGeometryUpdates(nsIContent* aPlugin)
|
2009-07-22 00:45:00 +00:00
|
|
|
{
|
|
|
|
mRegisteredPlugins.RemoveEntry(aPlugin);
|
|
|
|
}
|
|
|
|
|
2012-10-06 13:03:23 +00:00
|
|
|
void
|
|
|
|
nsRootPresContext::ComputePluginGeometryUpdates(nsIFrame* aFrame,
|
|
|
|
nsDisplayListBuilder* aBuilder,
|
|
|
|
nsDisplayList* aList)
|
2009-07-22 00:45:00 +00:00
|
|
|
{
|
2012-10-06 13:03:23 +00:00
|
|
|
if (mRegisteredPlugins.Count() == 0) {
|
|
|
|
return;
|
2009-07-22 00:45:00 +00:00
|
|
|
}
|
|
|
|
|
2012-10-06 13:03:23 +00: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.
|
2015-07-15 09:05:07 +00:00
|
|
|
for (auto iter = mRegisteredPlugins.Iter(); !iter.Done(); iter.Next()) {
|
|
|
|
auto f = static_cast<nsPluginFrame*>(iter.Get()->GetKey()->GetPrimaryFrame());
|
|
|
|
if (!f) {
|
|
|
|
NS_WARNING("Null frame in ComputePluginGeometryUpdates");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!nsLayoutUtils::IsAncestorFrameCrossDoc(aFrame, f)) {
|
|
|
|
// f is not managed by this frame so we should ignore it.
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
f->SetEmptyWidgetConfiguration();
|
|
|
|
}
|
2009-07-22 00:45:00 +00:00
|
|
|
|
2012-10-06 13:03:23 +00:00
|
|
|
nsIFrame* rootFrame = FrameManager()->GetRootFrame();
|
2009-07-22 00:45:00 +00:00
|
|
|
|
2012-10-18 05:34:58 +00: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 00:45:00 +00:00
|
|
|
|
2012-11-06 20:38:11 +00: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
|
2015-07-04 01:29:00 +00:00
|
|
|
if (XRE_IsParentProcess()) {
|
2015-03-02 11:01:58 +00:00
|
|
|
InitApplyPluginGeometryTimer();
|
|
|
|
}
|
2012-11-06 20:38:11 +00:00
|
|
|
#endif
|
2012-10-06 13:03:23 +00:00
|
|
|
}
|
2009-08-20 21:52:48 +00:00
|
|
|
|
2012-10-06 13:03:23 +00:00
|
|
|
static void
|
|
|
|
ApplyPluginGeometryUpdatesCallback(nsITimer *aTimer, void *aClosure)
|
|
|
|
{
|
|
|
|
static_cast<nsRootPresContext*>(aClosure)->ApplyPluginGeometryUpdates();
|
|
|
|
}
|
2009-07-22 00:45:00 +00:00
|
|
|
|
2012-10-06 13:03:23 +00:00
|
|
|
void
|
|
|
|
nsRootPresContext::InitApplyPluginGeometryTimer()
|
|
|
|
{
|
|
|
|
if (mApplyPluginGeometryTimer) {
|
|
|
|
return;
|
|
|
|
}
|
2009-07-22 00:45:00 +00:00
|
|
|
|
2012-10-06 13:03:23 +00: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.
|
2015-08-04 00:13:07 +00:00
|
|
|
mApplyPluginGeometryTimer = CreateTimer(ApplyPluginGeometryUpdatesCallback,
|
|
|
|
nsRefreshDriver::DefaultInterval() * 2);
|
2012-10-06 13:03:23 +00:00
|
|
|
}
|
2009-07-22 00:45:00 +00:00
|
|
|
|
2012-10-06 13:03:23 +00:00
|
|
|
void
|
|
|
|
nsRootPresContext::CancelApplyPluginGeometryTimer()
|
|
|
|
{
|
|
|
|
if (mApplyPluginGeometryTimer) {
|
|
|
|
mApplyPluginGeometryTimer->Cancel();
|
|
|
|
mApplyPluginGeometryTimer = nullptr;
|
|
|
|
}
|
2009-07-22 00:45:00 +00:00
|
|
|
}
|
|
|
|
|
2014-12-11 14:44:07 +00:00
|
|
|
#ifndef XP_MACOSX
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
static bool
|
2015-11-26 04:32:47 +00:00
|
|
|
HasOverlap(const LayoutDeviceIntPoint& aOffset1,
|
2015-12-02 22:32:55 +00:00
|
|
|
const nsTArray<LayoutDeviceIntRect>& aClipRects1,
|
2015-11-26 04:32:47 +00:00
|
|
|
const LayoutDeviceIntPoint& aOffset2,
|
2015-12-02 22:32:55 +00:00
|
|
|
const nsTArray<LayoutDeviceIntRect>& aClipRects2)
|
2010-07-15 21:08:08 +00:00
|
|
|
{
|
2015-12-02 22:32:55 +00:00
|
|
|
LayoutDeviceIntPoint offsetDelta = aOffset1 - aOffset2;
|
2012-08-22 15:56:38 +00:00
|
|
|
for (uint32_t i = 0; i < aClipRects1.Length(); ++i) {
|
|
|
|
for (uint32_t j = 0; j < aClipRects2.Length(); ++j) {
|
2015-11-26 04:32:47 +00:00
|
|
|
if ((aClipRects1[i] + offsetDelta).Intersects(aClipRects2[j])) {
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2015-11-26 04:32:47 +00:00
|
|
|
}
|
2010-07-15 21:08:08 +00:00
|
|
|
}
|
|
|
|
}
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2010-07-15 21:08:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Given a list of plugin windows to move to new locations, sort the list
|
|
|
|
* so that for each window move, the window moves to a location that
|
|
|
|
* does not intersect other windows. This minimizes flicker and repainting.
|
|
|
|
* It's not always possible to do this perfectly, since in general
|
|
|
|
* we might have cycles. But we do our best.
|
|
|
|
* We need to take into account that windows are clipped to particular
|
|
|
|
* regions and the clip regions change as the windows are moved.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
SortConfigurations(nsTArray<nsIWidget::Configuration>* aConfigurations)
|
|
|
|
{
|
|
|
|
if (aConfigurations->Length() > 10) {
|
|
|
|
// Give up, we don't want to get bogged down here
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsTArray<nsIWidget::Configuration> pluginsToMove;
|
|
|
|
pluginsToMove.SwapElements(*aConfigurations);
|
|
|
|
|
|
|
|
// Our algorithm is quite naive. At each step we try to identify
|
|
|
|
// a window that can be moved to its new location that won't overlap
|
|
|
|
// any other windows at the new location. If there is no such
|
|
|
|
// window, we just move the last window in the list anyway.
|
|
|
|
while (!pluginsToMove.IsEmpty()) {
|
|
|
|
// Find a window whose destination does not overlap any other window
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t i;
|
2010-07-15 21:08:08 +00:00
|
|
|
for (i = 0; i + 1 < pluginsToMove.Length(); ++i) {
|
|
|
|
nsIWidget::Configuration* config = &pluginsToMove[i];
|
2011-09-29 06:19:26 +00:00
|
|
|
bool foundOverlap = false;
|
2012-08-22 15:56:38 +00:00
|
|
|
for (uint32_t j = 0; j < pluginsToMove.Length(); ++j) {
|
2010-07-15 21:08:08 +00:00
|
|
|
if (i == j)
|
|
|
|
continue;
|
2016-08-18 23:03:04 +00:00
|
|
|
LayoutDeviceIntRect bounds = pluginsToMove[j].mChild->GetBounds();
|
2016-02-02 15:36:30 +00:00
|
|
|
AutoTArray<LayoutDeviceIntRect,1> clipRects;
|
2010-07-15 21:08:08 +00:00
|
|
|
pluginsToMove[j].mChild->GetWindowClipRegion(&clipRects);
|
|
|
|
if (HasOverlap(bounds.TopLeft(), clipRects,
|
2015-11-26 04:32:47 +00:00
|
|
|
config->mBounds.TopLeft(),
|
2010-07-15 21:08:08 +00:00
|
|
|
config->mClipRegion)) {
|
2011-10-17 14:59:28 +00:00
|
|
|
foundOverlap = true;
|
2010-07-15 21:08:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!foundOverlap)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// Note that we always move the last plugin in pluginsToMove, if we
|
|
|
|
// can't find any other plugin to move
|
|
|
|
aConfigurations->AppendElement(pluginsToMove[i]);
|
|
|
|
pluginsToMove.RemoveElementAt(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-15 09:05:07 +00:00
|
|
|
static void
|
|
|
|
PluginGetGeometryUpdate(nsTHashtable<nsRefPtrHashKey<nsIContent>>& aPlugins,
|
|
|
|
nsTArray<nsIWidget::Configuration>* aConfigurations)
|
|
|
|
{
|
|
|
|
for (auto iter = aPlugins.Iter(); !iter.Done(); iter.Next()) {
|
|
|
|
auto f = static_cast<nsPluginFrame*>(iter.Get()->GetKey()->GetPrimaryFrame());
|
|
|
|
if (!f) {
|
|
|
|
NS_WARNING("Null frame in PluginGeometryUpdate");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
f->GetWidgetConfiguration(aConfigurations);
|
2010-07-15 21:08:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-11 14:44:07 +00:00
|
|
|
#endif // #ifndef XP_MACOSX
|
|
|
|
|
2015-07-15 09:05:07 +00:00
|
|
|
static void
|
|
|
|
PluginDidSetGeometry(nsTHashtable<nsRefPtrHashKey<nsIContent>>& aPlugins)
|
2009-07-22 00:45:02 +00:00
|
|
|
{
|
2015-07-15 09:05:07 +00:00
|
|
|
for (auto iter = aPlugins.Iter(); !iter.Done(); iter.Next()) {
|
|
|
|
auto f = static_cast<nsPluginFrame*>(iter.Get()->GetKey()->GetPrimaryFrame());
|
|
|
|
if (!f) {
|
|
|
|
NS_WARNING("Null frame in PluginDidSetGeometry");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
f->DidSetWidgetGeometry();
|
2012-08-14 04:06:42 +00:00
|
|
|
}
|
2009-07-22 00:45:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-10-06 13:03:23 +00:00
|
|
|
nsRootPresContext::ApplyPluginGeometryUpdates()
|
2009-07-22 00:45:02 +00:00
|
|
|
{
|
2014-12-11 14:44:07 +00:00
|
|
|
#ifndef XP_MACOSX
|
2012-10-06 13:03:23 +00:00
|
|
|
CancelApplyPluginGeometryTimer();
|
|
|
|
|
2015-07-15 09:05:07 +00:00
|
|
|
nsTArray<nsIWidget::Configuration> configurations;
|
|
|
|
PluginGetGeometryUpdate(mRegisteredPlugins, &configurations);
|
2012-10-06 13:03:23 +00:00
|
|
|
// Walk mRegisteredPlugins and ask each plugin for its configuration
|
2015-07-15 09:05:07 +00:00
|
|
|
if (!configurations.IsEmpty()) {
|
|
|
|
nsIWidget* widget = configurations[0].mChild->GetParent();
|
2012-10-06 13:03:23 +00:00
|
|
|
NS_ASSERTION(widget, "Plugins must have a parent window");
|
2015-07-15 09:05:07 +00:00
|
|
|
SortConfigurations(&configurations);
|
|
|
|
widget->ConfigureChildren(configurations);
|
2012-10-06 13:03:23 +00:00
|
|
|
}
|
2014-12-11 14:44:07 +00:00
|
|
|
#endif // #ifndef XP_MACOSX
|
|
|
|
|
2015-07-15 09:05:07 +00:00
|
|
|
PluginDidSetGeometry(mRegisteredPlugins);
|
2009-07-22 00:45:00 +00:00
|
|
|
}
|
2010-07-15 21:08:08 +00:00
|
|
|
|
2015-01-29 19:41:54 +00:00
|
|
|
void
|
|
|
|
nsRootPresContext::CollectPluginGeometryUpdates(LayerManager* aLayerManager)
|
|
|
|
{
|
|
|
|
#ifndef XP_MACOSX
|
|
|
|
// Collect and pass plugin widget configurations down to the compositor
|
|
|
|
// for transmission to the chrome process.
|
|
|
|
NS_ASSERTION(aLayerManager, "layer manager is invalid!");
|
|
|
|
mozilla::layers::ClientLayerManager* clm = aLayerManager->AsClientLayerManager();
|
2015-07-15 09:05:07 +00:00
|
|
|
|
|
|
|
nsTArray<nsIWidget::Configuration> configurations;
|
2015-11-25 18:11:00 +00:00
|
|
|
// If there aren't any plugins to configure, clear the plugin data cache
|
|
|
|
// in the layer system.
|
|
|
|
if (!mRegisteredPlugins.Count() && clm) {
|
|
|
|
clm->StorePluginWidgetConfigurations(configurations);
|
|
|
|
return;
|
|
|
|
}
|
2015-07-15 09:05:07 +00:00
|
|
|
PluginGetGeometryUpdate(mRegisteredPlugins, &configurations);
|
|
|
|
if (configurations.IsEmpty()) {
|
|
|
|
PluginDidSetGeometry(mRegisteredPlugins);
|
2015-01-29 19:41:54 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-07-15 09:05:07 +00:00
|
|
|
SortConfigurations(&configurations);
|
2015-01-29 19:41:54 +00:00
|
|
|
if (clm) {
|
2015-07-15 09:05:07 +00:00
|
|
|
clm->StorePluginWidgetConfigurations(configurations);
|
2015-01-29 19:41:54 +00:00
|
|
|
}
|
2015-07-15 09:05:07 +00:00
|
|
|
PluginDidSetGeometry(mRegisteredPlugins);
|
2015-01-29 19:41:54 +00:00
|
|
|
#endif // #ifndef XP_MACOSX
|
|
|
|
}
|
|
|
|
|
2011-01-15 09:40:33 +00:00
|
|
|
static void
|
|
|
|
NotifyDidPaintForSubtreeCallback(nsITimer *aTimer, void *aClosure)
|
|
|
|
{
|
|
|
|
nsPresContext* presContext = (nsPresContext*)aClosure;
|
|
|
|
nsAutoScriptBlocker blockScripts;
|
2012-10-19 04:50:34 +00: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 09:40:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsRootPresContext::EnsureEventualDidPaintEvent()
|
|
|
|
{
|
|
|
|
if (mNotifyDidPaintTimer)
|
|
|
|
return;
|
2015-07-30 21:24:51 +00:00
|
|
|
|
2015-08-04 00:13:07 +00:00
|
|
|
mNotifyDidPaintTimer = CreateTimer(NotifyDidPaintForSubtreeCallback, 100);
|
2011-01-15 09:40:33 +00:00
|
|
|
}
|
2011-10-26 04:14:31 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
nsRootPresContext::AddWillPaintObserver(nsIRunnable* aRunnable)
|
|
|
|
{
|
|
|
|
if (!mWillPaintFallbackEvent.IsPending()) {
|
|
|
|
mWillPaintFallbackEvent = new RunWillPaintObservers(this);
|
|
|
|
NS_DispatchToMainThread(mWillPaintFallbackEvent.get());
|
|
|
|
}
|
|
|
|
mWillPaintObservers.AppendElement(aRunnable);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Run all runnables that need to get called before the next paint.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
nsRootPresContext::FlushWillPaintObservers()
|
|
|
|
{
|
2012-07-30 14:20:58 +00:00
|
|
|
mWillPaintFallbackEvent = nullptr;
|
2011-10-26 04:14:31 +00:00
|
|
|
nsTArray<nsCOMPtr<nsIRunnable> > observers;
|
|
|
|
observers.SwapElements(mWillPaintObservers);
|
2012-08-22 15:56:38 +00:00
|
|
|
for (uint32_t i = 0; i < observers.Length(); ++i) {
|
2011-10-26 04:14:31 +00:00
|
|
|
observers[i]->Run();
|
|
|
|
}
|
|
|
|
}
|
2012-02-21 05:02:24 +00:00
|
|
|
|
|
|
|
size_t
|
2013-06-23 12:03:39 +00:00
|
|
|
nsRootPresContext::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const
|
2012-02-21 05:02:24 +00:00
|
|
|
{
|
|
|
|
return nsPresContext::SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
|
|
|
|
// Measurement of the following members may be added later if DMD finds it is
|
|
|
|
// worthwhile:
|
|
|
|
// - mNotifyDidPaintTimer
|
|
|
|
// - mRegisteredPlugins
|
|
|
|
// - mWillPaintObservers
|
|
|
|
// - mWillPaintFallbackEvent
|
|
|
|
}
|