2017-10-27 17:33:53 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
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"
|
2017-06-18 11:37:50 +00:00
|
|
|
#include "mozilla/Encoding.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"
|
2017-02-10 02:42:27 +00:00
|
|
|
#include "nsIPresShellInlines.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"
|
2017-10-26 04:35:22 +00:00
|
|
|
#include "nsIDocumentInlines.h"
|
2012-07-30 04:29:41 +00:00
|
|
|
#include "nsIPrintSettings.h"
|
2015-04-03 19:39:23 +00:00
|
|
|
#include "nsLanguageAtomService.h"
|
2011-09-09 02:27:13 +00:00
|
|
|
#include "mozilla/LookAndFeel.h"
|
2001-09-05 21:28:38 +00:00
|
|
|
#include "nsIInterfaceRequestorUtils.h"
|
2017-09-16 03:45:05 +00:00
|
|
|
#include "nsHTMLDocument.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"
|
2017-02-13 03:21:30 +00:00
|
|
|
#include "mozilla/GeckoRestyleManager.h"
|
2016-02-24 07:01:12 +00:00
|
|
|
#include "mozilla/RestyleManager.h"
|
2017-02-13 03:21:33 +00:00
|
|
|
#include "mozilla/RestyleManagerInlines.h"
|
2016-08-08 22:54:10 +00:00
|
|
|
#include "SurfaceCacheUtils.h"
|
2017-11-17 07:35:26 +00:00
|
|
|
#include "nsMediaFeatures.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"
|
2018-01-27 12:17:27 +00:00
|
|
|
#include "mozilla/AnimationEventDispatcher.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"
|
2017-10-26 04:35:22 +00:00
|
|
|
#include "mozilla/dom/HTMLBodyElement.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"
|
2017-05-10 20:11:36 +00:00
|
|
|
#include "mozilla/ServoBindings.h"
|
2016-09-26 12:03:25 +00:00
|
|
|
#include "mozilla/StyleSheet.h"
|
|
|
|
#include "mozilla/StyleSheetInlines.h"
|
2016-11-08 19:30:57 +00:00
|
|
|
#include "mozilla/Telemetry.h"
|
2017-01-26 05:01:33 +00:00
|
|
|
#include "mozilla/dom/Performance.h"
|
|
|
|
#include "mozilla/dom/PerformanceTiming.h"
|
2017-02-17 02:16:15 +00:00
|
|
|
#include "mozilla/layers/APZThreadUtils.h"
|
2004-04-30 04:06:30 +00:00
|
|
|
|
2001-11-14 11:21:54 +00:00
|
|
|
// Needed for Start/Stop of Image Animation
|
|
|
|
#include "imgIContainer.h"
|
2003-03-19 03:47:09 +00:00
|
|
|
#include "nsIImageLoadingContent.h"
|
2001-11-14 11:21:54 +00:00
|
|
|
|
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"
|
2017-04-11 04:51:30 +00:00
|
|
|
#include "nsBidi.h"
|
2011-10-11 21:29:12 +00:00
|
|
|
|
2016-06-29 05:44:18 +00:00
|
|
|
#include "mozilla/dom/URL.h"
|
2017-10-16 01:06:39 +00:00
|
|
|
#include "mozilla/ServoCSSParser.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;
|
2017-08-04 04:22:49 +00:00
|
|
|
using namespace mozilla::gfx;
|
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;
|
|
|
|
|
2017-06-07 10:11:44 +00:00
|
|
|
// This preference was first introduced in Bug 232227, in order to prevent
|
|
|
|
// system colors from being exposed to CSS or canvas.
|
|
|
|
constexpr char kUseStandinsForNativeColors[] = "ui.use_standins_for_native_colors";
|
|
|
|
|
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,
|
2017-06-18 11:37:50 +00:00
|
|
|
NotNull<const Encoding*> aCharSet)
|
2017-02-11 06:11:48 +00:00
|
|
|
: Runnable("CharSetChangingRunnable"),
|
|
|
|
mPresContext(aPresContext),
|
2012-01-11 20:58:44 +00:00
|
|
|
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;
|
2017-06-18 11:37:50 +00:00
|
|
|
NotNull<const Encoding*> mCharSet;
|
2012-01-11 20:58:44 +00:00
|
|
|
};
|
|
|
|
|
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
|
|
|
{
|
2017-10-16 01:06:39 +00:00
|
|
|
bool ok;
|
|
|
|
nscolor result;
|
|
|
|
|
|
|
|
ServoStyleSet* servoStyleSet = mShell && mShell->StyleSet()
|
|
|
|
? mShell->StyleSet()->GetAsServo()
|
|
|
|
: nullptr;
|
|
|
|
|
|
|
|
if (servoStyleSet) {
|
|
|
|
ok = ServoCSSParser::ComputeColor(servoStyleSet, NS_RGB(0, 0, 0), aColor,
|
|
|
|
&result);
|
|
|
|
} else {
|
|
|
|
nsCSSParser parser;
|
|
|
|
nsCSSValue value;
|
|
|
|
ok = parser.ParseColorString(aColor, nullptr, 0, value) &&
|
|
|
|
nsRuleNode::ComputeColor(value, this, nullptr, result);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ok) {
|
2011-10-11 21:29:12 +00:00
|
|
|
// Any better choices?
|
2017-10-16 01:06:39 +00:00
|
|
|
result = NS_RGB(0, 0, 0);
|
2011-10-11 21:29:12 +00:00
|
|
|
}
|
2012-06-06 07:36:38 +00:00
|
|
|
|
2017-10-16 01:06:39 +00:00
|
|
|
return result;
|
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
|
|
|
{
|
2018-01-30 07:43:27 +00:00
|
|
|
if (mFireAfterPaintEvents) {
|
2012-10-19 04:50:34 +00:00
|
|
|
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.
|
2017-02-17 02:15:45 +00:00
|
|
|
NotifyInvalidation(drpc->mRefreshDriver->LastTransactionId() + 1, nsRect(0, 0, 0, 0));
|
2018-01-30 07:43:27 +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
|
2017-06-18 11:37:50 +00:00
|
|
|
IsVisualCharset(NotNull<const Encoding*> aCharset)
|
2001-03-09 03:13:03 +00:00
|
|
|
{
|
2017-06-18 11:37:50 +00:00
|
|
|
return aCharset == ISO_8859_8_ENCODING;
|
2001-03-09 03:13:03 +00:00
|
|
|
}
|
|
|
|
|
2006-05-19 10:26:44 +00:00
|
|
|
nsPresContext::nsPresContext(nsIDocument* aDocument, nsPresContextType aType)
|
2017-01-24 16:11:13 +00:00
|
|
|
: mType(aType),
|
|
|
|
mShell(nullptr),
|
|
|
|
mDocument(aDocument),
|
2017-01-27 18:18:05 +00:00
|
|
|
mMedium(aType == eContext_Galley ? nsGkAtoms::screen : nsGkAtoms::print),
|
|
|
|
mMediaEmulated(mMedium),
|
2017-01-24 16:11:13 +00:00
|
|
|
mLinkHandler(nullptr),
|
|
|
|
mInflationDisabledForShrinkWrap(false),
|
|
|
|
mBaseMinFontSize(0),
|
2017-02-25 12:22:52 +00:00
|
|
|
mSystemFontScale(1.0),
|
2017-01-24 16:11:13 +00:00
|
|
|
mTextZoom(1.0),
|
2017-02-25 12:22:52 +00:00
|
|
|
mEffectiveTextZoom(1.0),
|
2017-01-24 16:11:13 +00:00
|
|
|
mFullZoom(1.0),
|
|
|
|
mOverrideDPPX(0.0),
|
2015-03-10 14:28:23 +00:00
|
|
|
mLastFontInflationScreenSize(gfxSize(-1.0, -1.0)),
|
2017-01-24 16:11:13 +00:00
|
|
|
mCurAppUnitsPerDevPixel(0),
|
|
|
|
mAutoQualityMinFontSizePixelsPref(0),
|
2017-09-08 16:49:43 +00:00
|
|
|
// origin nscoord_MIN is impossible, so the first ResizeReflow always fires
|
|
|
|
mLastResizeEventVisibleArea(nsRect(nscoord_MIN, nscoord_MIN,
|
|
|
|
NS_UNCONSTRAINEDSIZE,
|
|
|
|
NS_UNCONSTRAINEDSIZE)),
|
2017-01-24 16:11:13 +00:00
|
|
|
mPageSize(-1, -1),
|
|
|
|
mPageScale(0.0),
|
|
|
|
mPPScale(1.0f),
|
|
|
|
mDefaultColor(NS_RGBA(0,0,0,0)),
|
2017-01-27 18:18:05 +00:00
|
|
|
mBackgroundColor(NS_RGB(0xFF, 0xFF, 0xFF)),
|
|
|
|
mLinkColor(NS_RGB(0x00, 0x00, 0xEE)),
|
|
|
|
mActiveLinkColor(NS_RGB(0xEE, 0x00, 0x00)),
|
|
|
|
mVisitedLinkColor(NS_RGB(0x55, 0x1A, 0x8B)),
|
|
|
|
mFocusBackgroundColor(mBackgroundColor),
|
|
|
|
mFocusTextColor(mDefaultColor),
|
|
|
|
mBodyTextColor(mDefaultColor),
|
2017-09-16 03:45:05 +00:00
|
|
|
mViewportScrollbarOverrideElement(nullptr),
|
2014-02-04 01:54:22 +00:00
|
|
|
mViewportStyleScrollbar(NS_STYLE_OVERFLOW_AUTO, NS_STYLE_OVERFLOW_AUTO),
|
2017-01-27 18:18:05 +00:00
|
|
|
mFocusRingWidth(1),
|
2017-01-24 16:11:13 +00:00
|
|
|
mExistThrottledUpdates(false),
|
2017-01-27 18:18:05 +00:00
|
|
|
// mImageAnimationMode is initialised below, in constructor body
|
2012-08-29 05:48:44 +00:00
|
|
|
mImageAnimationModePref(imgIContainer::kNormalAnimMode),
|
2017-05-20 19:47:36 +00:00
|
|
|
mFontGroupCacheDirty(true),
|
2017-01-24 16:11:13 +00:00
|
|
|
mInterruptChecksToSkip(0),
|
|
|
|
mElementsRestyled(0),
|
|
|
|
mFramesConstructed(0),
|
|
|
|
mFramesReflowed(0),
|
2017-01-27 18:18:05 +00:00
|
|
|
mInteractionTimeEnabled(true),
|
2017-03-02 05:51:40 +00:00
|
|
|
mTelemetryScrollLastY(0),
|
|
|
|
mTelemetryScrollMaxY(0),
|
|
|
|
mTelemetryScrollTotalY(0),
|
2017-01-24 16:11:13 +00:00
|
|
|
mHasPendingInterrupt(false),
|
|
|
|
mPendingInterruptFromTest(false),
|
|
|
|
mInterruptsEnabled(false),
|
2017-01-27 18:18:05 +00:00
|
|
|
mUseDocumentFonts(true),
|
|
|
|
mUseDocumentColors(true),
|
|
|
|
mUnderlineLinks(true),
|
2017-01-24 16:11:13 +00:00
|
|
|
mSendAfterPaintToContent(false),
|
|
|
|
mUseFocusColors(false),
|
|
|
|
mFocusRingOnAnything(false),
|
|
|
|
mFocusRingStyle(false),
|
2017-01-27 18:18:05 +00:00
|
|
|
mDrawImageBackground(true), // always draw the background
|
|
|
|
mDrawColorBackground(true),
|
|
|
|
// mNeverAnimate is initialised below, in constructor body
|
2017-01-24 16:11:13 +00:00
|
|
|
mIsRenderingOnlySelection(false),
|
2017-01-27 18:18:05 +00:00
|
|
|
mPaginated(aType != eContext_Galley),
|
2017-01-24 16:11:13 +00:00
|
|
|
mCanPaginatedScroll(false),
|
2017-01-27 18:18:05 +00:00
|
|
|
mDoScaledTwips(true),
|
2017-01-24 16:11:13 +00:00
|
|
|
mIsRootPaginatedDocument(false),
|
|
|
|
mPrefBidiDirection(false),
|
|
|
|
mPrefScrollbarSide(0),
|
|
|
|
mPendingSysColorChanged(false),
|
|
|
|
mPendingThemeChanged(false),
|
|
|
|
mPendingUIResolutionChanged(false),
|
|
|
|
mPendingMediaFeatureValuesChanged(false),
|
|
|
|
mPrefChangePendingNeedsReflow(false),
|
|
|
|
mIsEmulatingMedia(false),
|
|
|
|
mIsGlyph(false),
|
|
|
|
mUsesRootEMUnits(false),
|
|
|
|
mUsesExChUnits(false),
|
|
|
|
mPendingViewportChange(false),
|
2017-01-27 18:18:05 +00:00
|
|
|
mCounterStylesDirty(true),
|
2017-01-24 16:11:13 +00:00
|
|
|
mPostedFlushCounterStyles(false),
|
2017-08-24 01:05:53 +00:00
|
|
|
mFontFeatureValuesDirty(true),
|
|
|
|
mPostedFlushFontFeatureValues(false),
|
2017-01-24 16:11:13 +00:00
|
|
|
mSuppressResizeReflow(false),
|
|
|
|
mIsVisual(false),
|
2018-01-30 07:43:27 +00:00
|
|
|
mFireAfterPaintEvents(false),
|
2017-01-24 16:11:13 +00:00
|
|
|
mIsChrome(false),
|
|
|
|
mIsChromeOriginImage(false),
|
|
|
|
mPaintFlashing(false),
|
|
|
|
mPaintFlashingInitialized(false),
|
|
|
|
mHasWarnedAboutPositionedTableParts(false),
|
|
|
|
mHasWarnedAboutTooLargeDashedOrDottedRadius(false),
|
|
|
|
mQuirkSheetAdded(false),
|
|
|
|
mNeedsPrefUpdate(false),
|
|
|
|
mHadNonBlankPaint(false)
|
|
|
|
#ifdef RESTYLE_LOGGING
|
|
|
|
, mRestyleLoggingEnabled(false)
|
|
|
|
#endif
|
|
|
|
#ifdef DEBUG
|
|
|
|
, mInitialized(false)
|
|
|
|
#endif
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
2017-01-24 16:11:13 +00:00
|
|
|
PodZero(&mBorderWidthTable);
|
|
|
|
#ifdef DEBUG
|
|
|
|
PodZero(&mLayoutPhaseCount);
|
|
|
|
#endif
|
2004-04-30 04:06:30 +00:00
|
|
|
|
2006-04-01 01:19:28 +00:00
|
|
|
if (!IsDynamic()) {
|
|
|
|
mImageAnimationMode = imgIContainer::kDontAnimMode;
|
2011-10-17 14:59:28 +00:00
|
|
|
mNeverAnimate = true;
|
2006-04-01 01:19:28 +00:00
|
|
|
} else {
|
|
|
|
mImageAnimationMode = imgIContainer::kNormalAnimMode;
|
2011-10-17 14:59:28 +00:00
|
|
|
mNeverAnimate = false;
|
2006-04-01 01:19:28 +00:00
|
|
|
}
|
2006-05-19 10:26:44 +00:00
|
|
|
NS_ASSERTION(mDocument, "Null document");
|
2011-04-22 03:17:31 +00:00
|
|
|
|
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
|
2017-03-21 18:59:02 +00:00
|
|
|
Preferences::UnregisterPrefixCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"font.",
|
|
|
|
this);
|
|
|
|
Preferences::UnregisterPrefixCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"browser.display.",
|
|
|
|
this);
|
2011-05-28 23:42:57 +00:00
|
|
|
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);
|
2017-03-21 18:59:02 +00:00
|
|
|
Preferences::UnregisterPrefixCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"bidi.",
|
|
|
|
this);
|
2011-05-28 23:42:57 +00:00
|
|
|
Preferences::UnregisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"dom.send_after_paint_to_content",
|
|
|
|
this);
|
2017-03-21 18:59:02 +00:00
|
|
|
Preferences::UnregisterPrefixCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"gfx.font_rendering.",
|
|
|
|
this);
|
2011-05-28 23:42:57 +00:00
|
|
|
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);
|
2017-06-07 10:11:44 +00:00
|
|
|
Preferences::UnregisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
kUseStandinsForNativeColors,
|
|
|
|
this);
|
2017-11-21 11:02:20 +00:00
|
|
|
Preferences::UnregisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"intl.accept_languages",
|
|
|
|
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_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()
|
|
|
|
{
|
2017-11-27 15:27:27 +00:00
|
|
|
if (IsRoot()) {
|
|
|
|
static_cast<nsRootPresContext*>(this)->CancelAllDidPaintTimers();
|
|
|
|
}
|
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)
|
2018-01-27 12:17:27 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mAnimationEventDispatcher);
|
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)
|
2018-01-27 12:17:27 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mAnimationEventDispatcher);
|
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;
|
2017-06-07 10:11:44 +00:00
|
|
|
static bool sUseStandinsForNativeColors = false;
|
2014-11-27 19:06:14 +00:00
|
|
|
if (!sDocumentColorsSettingPrefCached) {
|
|
|
|
sDocumentColorsSettingPrefCached = true;
|
|
|
|
Preferences::AddIntVarCache(&sDocumentColorsSetting,
|
|
|
|
"browser.display.document_color_use",
|
|
|
|
0);
|
2017-06-07 10:11:44 +00:00
|
|
|
|
|
|
|
// The preference "ui.use_standins_for_native_colors" also affects
|
|
|
|
// default foreground and background colors.
|
|
|
|
Preferences::AddBoolVarCache(&sUseStandinsForNativeColors,
|
|
|
|
kUseStandinsForNativeColors);
|
2014-11-27 19:06:14 +00:00
|
|
|
}
|
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
|
|
|
|
2017-06-07 10:11:44 +00:00
|
|
|
if (sUseStandinsForNativeColors) {
|
|
|
|
// Once the preference "ui.use_standins_for_native_colors" is enabled,
|
|
|
|
// use fixed color values instead of prefered colors and system colors.
|
2017-06-12 05:57:17 +00:00
|
|
|
mDefaultColor = LookAndFeel::GetColorUsingStandins(
|
|
|
|
LookAndFeel::eColorID_windowtext, NS_RGB(0x00, 0x00, 0x00));
|
|
|
|
mBackgroundColor = LookAndFeel::GetColorUsingStandins(
|
|
|
|
LookAndFeel::eColorID_window, NS_RGB(0xff, 0xff, 0xff));
|
2017-06-07 10:11:44 +00:00
|
|
|
} else if (usePrefColors) {
|
2017-07-31 04:23:50 +00:00
|
|
|
nsAutoString colorStr;
|
|
|
|
Preferences::GetString("browser.display.foreground_color", colorStr);
|
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
|
|
|
|
2017-07-31 04:23:50 +00:00
|
|
|
colorStr.Truncate();
|
|
|
|
Preferences::GetString("browser.display.background_color", colorStr);
|
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
|
|
|
|
2017-07-31 04:23:50 +00:00
|
|
|
nsAutoString colorStr;
|
|
|
|
Preferences::GetString("browser.anchor_color", colorStr);
|
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
|
|
|
|
2017-07-31 04:23:50 +00:00
|
|
|
colorStr.Truncate();
|
|
|
|
Preferences::GetString("browser.active_color", colorStr);
|
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
|
|
|
|
2017-07-31 04:23:50 +00:00
|
|
|
colorStr.Truncate();
|
|
|
|
Preferences::GetString("browser.visited_color", colorStr);
|
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;
|
|
|
|
|
2017-07-31 04:23:50 +00:00
|
|
|
colorStr.Truncate();
|
|
|
|
Preferences::GetString("browser.display.focus_text_color", colorStr);
|
2004-04-30 04:06:30 +00:00
|
|
|
if (!colorStr.IsEmpty()) {
|
|
|
|
mFocusTextColor = MakeColorPref(colorStr);
|
2001-04-09 22:17:11 +00:00
|
|
|
}
|
|
|
|
|
2017-07-31 04:23:50 +00:00
|
|
|
colorStr.Truncate();
|
|
|
|
Preferences::GetString("browser.display.focus_background_color", colorStr);
|
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();
|
2017-05-20 19:47:36 +00:00
|
|
|
mFontGroupCacheDirty = true;
|
2016-03-31 19:47:20 +00:00
|
|
|
StaticPresData::Get()->ResetCachedFontPrefs();
|
2001-01-09 23:55:27 +00:00
|
|
|
|
|
|
|
// * image animation
|
2017-07-31 04:28:48 +00:00
|
|
|
nsAutoCString animatePref;
|
|
|
|
Preferences::GetCString("image.animation_mode", animatePref);
|
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
|
|
|
|
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.
|
2017-08-29 23:18:10 +00:00
|
|
|
SetBidi(bidiOptions);
|
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")) {
|
2017-04-06 14:30:09 +00:00
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2017-11-21 11:02:20 +00:00
|
|
|
if (StringBeginsWith(prefName, NS_LITERAL_CSTRING("font.")) ||
|
|
|
|
prefName.EqualsLiteral("intl.accept_languages")) {
|
2008-02-08 19:52:46 +00:00
|
|
|
// 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();
|
2017-02-13 23:45:23 +00:00
|
|
|
mPrefChangedTimer = CreateTimer(PrefChangedUpdateTimerCallback,
|
|
|
|
"PrefChangedUpdateTimerCallback", 0);
|
2015-08-04 00:13:07 +00:00
|
|
|
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
|
|
|
|
2017-07-04 00:03:42 +00:00
|
|
|
// In certain rare cases (such as changing page mode), we tear down layout
|
|
|
|
// state and re-initialize a new prescontext for a document. Given that we
|
|
|
|
// hang style state off the DOM, we detect that re-initialization case and
|
|
|
|
// lazily drop the servo data. We don't do this eagerly during layout teardown
|
|
|
|
// because that would incur an extra whole-tree traversal that's unnecessary
|
|
|
|
// most of the time.
|
|
|
|
if (mDocument->IsStyledByServo()) {
|
|
|
|
Element* root = mDocument->GetRootElement();
|
|
|
|
if (root && root->HasServoData()) {
|
|
|
|
ServoRestyleManager::ClearServoDataFromSubtree(root);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2018-01-27 12:17:27 +00:00
|
|
|
mAnimationEventDispatcher = new mozilla::AnimationEventDispatcher(this);
|
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
|
|
|
|
2015-04-03 19:39:23 +00:00
|
|
|
mLangService = nsLanguageAtomService::GetService();
|
2004-04-30 04:06:30 +00:00
|
|
|
|
|
|
|
// Register callbacks so we're notified when the preferences change
|
2017-03-21 18:59:02 +00:00
|
|
|
Preferences::RegisterPrefixCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"font.",
|
|
|
|
this);
|
|
|
|
Preferences::RegisterPrefixCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"browser.display.",
|
|
|
|
this);
|
2011-05-28 23:42:57 +00:00
|
|
|
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);
|
2017-03-21 18:59:02 +00:00
|
|
|
Preferences::RegisterPrefixCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"bidi.",
|
|
|
|
this);
|
2011-05-28 23:42:57 +00:00
|
|
|
Preferences::RegisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"dom.send_after_paint_to_content",
|
|
|
|
this);
|
2017-03-21 18:59:02 +00:00
|
|
|
Preferences::RegisterPrefixCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"gfx.font_rendering.",
|
|
|
|
this);
|
2011-05-28 23:42:57 +00:00
|
|
|
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);
|
2017-06-07 10:11:44 +00:00
|
|
|
Preferences::RegisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
kUseStandinsForNativeColors,
|
|
|
|
this);
|
2017-11-21 11:02:20 +00:00
|
|
|
Preferences::RegisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"intl.accept_languages",
|
|
|
|
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
|
2017-02-13 03:21:32 +00:00
|
|
|
mRestyleLoggingEnabled = GeckoRestyleManager::RestyleLoggingInitiallyEnabled();
|
2014-09-25 05:45:36 +00:00
|
|
|
#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
|
|
|
|
|
|
|
|
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 {
|
2017-02-13 03:21:32 +00:00
|
|
|
mRestyleManager = new GeckoRestyleManager(this);
|
2016-07-27 00:27:56 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2015-04-03 19:39:23 +00:00
|
|
|
UpdateCharSet(doc->GetDocumentCharacterSet());
|
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()
|
|
|
|
{
|
|
|
|
// 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;
|
|
|
|
|
2018-01-27 12:17:27 +00:00
|
|
|
if (mAnimationEventDispatcher) {
|
|
|
|
mAnimationEventDispatcher->Disconnect();
|
|
|
|
mAnimationEventDispatcher = nullptr;
|
|
|
|
}
|
2016-07-27 00:43:56 +00:00
|
|
|
if (mEffectCompositor) {
|
|
|
|
mEffectCompositor->Disconnect();
|
|
|
|
mEffectCompositor = nullptr;
|
|
|
|
}
|
|
|
|
if (mTransitionManager) {
|
|
|
|
mTransitionManager->Disconnect();
|
|
|
|
mTransitionManager = nullptr;
|
|
|
|
}
|
|
|
|
if (mAnimationManager) {
|
|
|
|
mAnimationManager->Disconnect();
|
|
|
|
mAnimationManager = nullptr;
|
|
|
|
}
|
|
|
|
if (mRestyleManager) {
|
|
|
|
mRestyleManager->Disconnect();
|
|
|
|
mRestyleManager = nullptr;
|
|
|
|
}
|
2016-10-12 11:27:38 +00:00
|
|
|
if (mRefreshDriver && mRefreshDriver->GetPresContext() == this) {
|
2016-07-27 00:43:56 +00:00
|
|
|
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();
|
2017-11-27 15:27:27 +00:00
|
|
|
|
|
|
|
// The did-paint timer also depends on a non-null pres shell.
|
|
|
|
thisRoot->CancelAllDidPaintTimers();
|
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
|
2017-06-18 11:37:50 +00:00
|
|
|
nsPresContext::DoChangeCharSet(NotNull<const Encoding*> aCharSet)
|
2012-01-11 20:58:44 +00:00
|
|
|
{
|
|
|
|
UpdateCharSet(aCharSet);
|
|
|
|
mDeviceContext->FlushFontCache();
|
2017-08-21 10:58:53 +00:00
|
|
|
// In Stylo, if a document contains one or more <script> elements, frame
|
|
|
|
// construction might happen earlier than the UpdateCharSet(), so we need to
|
|
|
|
// restyle descendants to make their style data up-to-date.
|
|
|
|
RebuildAllStyleData(NS_STYLE_HINT_REFLOW,
|
|
|
|
mDocument->IsStyledByServo()
|
|
|
|
? eRestyle_ForceDescendants : nsRestyleHint(0));
|
2012-01-11 20:58:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-06-18 11:37:50 +00:00
|
|
|
nsPresContext::UpdateCharSet(NotNull<const Encoding*> aCharSet)
|
2000-09-20 22:59:20 +00:00
|
|
|
{
|
2015-04-03 19:39:23 +00:00
|
|
|
mLanguage = mLangService->LookupCharSet(aCharSet);
|
|
|
|
// this will be a language group (or script) code rather than a true language code
|
2004-06-21 10:32:27 +00:00
|
|
|
|
2015-04-03 19:39:23 +00:00
|
|
|
// bug 39570: moved from nsLanguageAtomService::LookupCharSet()
|
|
|
|
if (mLanguage == nsGkAtoms::Unicode) {
|
|
|
|
mLanguage = mLangService->GetLocaleLanguage();
|
2000-09-20 22:59:20 +00:00
|
|
|
}
|
2015-04-03 19:39:23 +00:00
|
|
|
mLangGroupFontPrefs.Reset();
|
|
|
|
mFontGroupCacheDirty = true;
|
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
|
|
|
}
|
|
|
|
|
2017-09-14 14:19:22 +00:00
|
|
|
void
|
|
|
|
nsPresContext::DispatchCharSetChange(NotNull<const Encoding*> aEncoding)
|
2000-06-01 23:12:26 +00:00
|
|
|
{
|
2017-09-14 14:19:22 +00:00
|
|
|
RefPtr<CharSetChangingRunnable> runnable =
|
|
|
|
new CharSetChangingRunnable(this, aEncoding);
|
|
|
|
Document()->Dispatch(TaskCategory::Other, runnable.forget());
|
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
|
|
|
}
|
|
|
|
|
2017-06-10 14:22:23 +00:00
|
|
|
StyleSetHandle styleSet = mShell->StyleSet();
|
|
|
|
if (styleSet->IsServo()) {
|
|
|
|
styleSet->AsServo()->CompatibilityModeChanged();
|
|
|
|
}
|
|
|
|
|
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: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
|
|
|
|
2018-01-05 13:36:47 +00:00
|
|
|
for (nsIContent* childContent = aParent->GetFirstChild();
|
|
|
|
childContent; childContent = childContent->GetNextSibling()) {
|
|
|
|
SetImgAnimations(childContent, 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
|
2017-09-08 23:25:03 +00:00
|
|
|
nsPresContext::SetImageAnimationMode(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;
|
|
|
|
}
|
|
|
|
|
2017-10-02 22:05:19 +00:00
|
|
|
already_AddRefed<nsAtom>
|
2015-11-28 00:56:33 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2017-02-25 12:22:52 +00:00
|
|
|
void
|
|
|
|
nsPresContext::UpdateEffectiveTextZoom()
|
|
|
|
{
|
|
|
|
float newZoom = mSystemFontScale * mTextZoom;
|
|
|
|
float minZoom = nsLayoutUtils::MinZoom();
|
|
|
|
float maxZoom = nsLayoutUtils::MaxZoom();
|
|
|
|
|
|
|
|
if (newZoom < minZoom) {
|
|
|
|
newZoom = minZoom;
|
|
|
|
} else if (newZoom > maxZoom) {
|
|
|
|
newZoom = maxZoom;
|
|
|
|
}
|
|
|
|
|
|
|
|
mEffectiveTextZoom = newZoom;
|
|
|
|
|
2017-10-17 04:25:12 +00:00
|
|
|
// In case of servo, stylist.device might have already generated the default
|
|
|
|
// computed values with the previous effective text zoom value even if the
|
|
|
|
// pres shell has not initialized yet.
|
|
|
|
if (mDocument->IsStyledByServo() || HasCachedStyleData()) {
|
2017-02-25 12:22:52 +00:00
|
|
|
// Media queries could have changed, since we changed the meaning
|
|
|
|
// of 'em' units in them.
|
|
|
|
MediaFeatureValuesChanged(eRestyle_ForceDescendants,
|
|
|
|
NS_STYLE_HINT_REFLOW);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-27 21:06:37 +00:00
|
|
|
float
|
|
|
|
nsPresContext::GetDeviceFullZoom()
|
|
|
|
{
|
|
|
|
return mDeviceContext->GetFullZoom();
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
2017-07-18 03:21:41 +00:00
|
|
|
// SetOverrideDPPX is called during navigations, including history
|
|
|
|
// traversals. In that case, it's typically called with our current value,
|
|
|
|
// and we don't need to actually do anything.
|
|
|
|
if (aDPPX != mOverrideDPPX) {
|
|
|
|
mOverrideDPPX = aDPPX;
|
|
|
|
|
|
|
|
if (HasCachedStyleData()) {
|
|
|
|
MediaFeatureValuesChanged(nsRestyleHint(0), nsChangeHint(0));
|
|
|
|
}
|
2016-08-25 11:15:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2017-09-16 03:45:05 +00:00
|
|
|
static Element*
|
2015-09-30 00:48:41 +00:00
|
|
|
GetPropagatedScrollbarStylesForViewport(nsPresContext* aPresContext,
|
|
|
|
ScrollbarStyles *aStyles)
|
2015-09-30 00:48:41 +00:00
|
|
|
{
|
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();
|
Bug 1379505: Less fishyness when resolving the style of the document element. r=heycam
Previous to these patches, the style resolution happening on [1] made the style
data stick on the element, so we'd never think it was the initial style, even if
it was.
This was wallpapering the fact that, if that was the initial style, we'd never
have another chance of traversing the document when [2] kicked in.
This somehow just happened to work, but is a very fishy way to get it to work.
Instead, call StyleDocument() properly _before_, and rely on the fact that it
will stop when it has a non-null binding, and only if it fails explicitly style
the children.
This fixes the few XBL test-cases with this patch series that exercise
-moz-bindings on the root element without the root being styled, and makes the
-moz-binding code more consistent in both places of the frame constructor.
[1]: http://searchfox.org/mozilla-central/rev/5dadcbe55b4ddd1e448c06c77390ff6483aa009b/layout/base/nsCSSFrameConstructor.cpp#2526
[2]: https://github.com/servo/servo/blob/3330653dc80cc8947af17f1989fb7fbf390c4d2f/components/style/traversal.rs#L439
MozReview-Commit-ID: HbjsD6nYsvX
--HG--
extra : rebase_source : 0f9be9665faf6a5e32f527c12dbd00f35a89b986
2017-07-10 12:32:39 +00:00
|
|
|
RefPtr<nsStyleContext> rootStyle =
|
|
|
|
styleSet->ResolveStyleFor(docElement, nullptr, LazyComputeBehavior::Allow);
|
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
|
2017-09-16 03:45:05 +00:00
|
|
|
// with non-HTML roots.
|
2015-09-30 00:48:41 +00:00
|
|
|
// 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?
|
2017-09-16 03:45:05 +00:00
|
|
|
nsHTMLDocument* htmlDoc = document->AsHTMLDocument();
|
2015-09-30 00:48:41 +00:00
|
|
|
if (!htmlDoc || !docElement->IsHTMLElement()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2017-10-26 04:35:22 +00:00
|
|
|
Element* bodyElement = htmlDoc->GetBodyElement();
|
|
|
|
if (!bodyElement) {
|
|
|
|
// No body, nothing to do here.
|
2015-09-30 00:48:41 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2017-10-26 04:35:22 +00:00
|
|
|
MOZ_ASSERT(bodyElement->IsHTMLElement(nsGkAtoms::body),
|
|
|
|
"GetBodyElement returned something bogus");
|
|
|
|
|
Bug 1379505: Less fishyness when resolving the style of the document element. r=heycam
Previous to these patches, the style resolution happening on [1] made the style
data stick on the element, so we'd never think it was the initial style, even if
it was.
This was wallpapering the fact that, if that was the initial style, we'd never
have another chance of traversing the document when [2] kicked in.
This somehow just happened to work, but is a very fishy way to get it to work.
Instead, call StyleDocument() properly _before_, and rely on the fact that it
will stop when it has a non-null binding, and only if it fails explicitly style
the children.
This fixes the few XBL test-cases with this patch series that exercise
-moz-bindings on the root element without the root being styled, and makes the
-moz-binding code more consistent in both places of the frame constructor.
[1]: http://searchfox.org/mozilla-central/rev/5dadcbe55b4ddd1e448c06c77390ff6483aa009b/layout/base/nsCSSFrameConstructor.cpp#2526
[2]: https://github.com/servo/servo/blob/3330653dc80cc8947af17f1989fb7fbf390c4d2f/components/style/traversal.rs#L439
MozReview-Commit-ID: HbjsD6nYsvX
--HG--
extra : rebase_source : 0f9be9665faf6a5e32f527c12dbd00f35a89b986
2017-07-10 12:32:39 +00:00
|
|
|
RefPtr<nsStyleContext> bodyStyle =
|
2017-09-16 03:45:05 +00:00
|
|
|
styleSet->ResolveStyleFor(bodyElement, rootStyle,
|
Bug 1379505: Less fishyness when resolving the style of the document element. r=heycam
Previous to these patches, the style resolution happening on [1] made the style
data stick on the element, so we'd never think it was the initial style, even if
it was.
This was wallpapering the fact that, if that was the initial style, we'd never
have another chance of traversing the document when [2] kicked in.
This somehow just happened to work, but is a very fishy way to get it to work.
Instead, call StyleDocument() properly _before_, and rely on the fact that it
will stop when it has a non-null binding, and only if it fails explicitly style
the children.
This fixes the few XBL test-cases with this patch series that exercise
-moz-bindings on the root element without the root being styled, and makes the
-moz-binding code more consistent in both places of the frame constructor.
[1]: http://searchfox.org/mozilla-central/rev/5dadcbe55b4ddd1e448c06c77390ff6483aa009b/layout/base/nsCSSFrameConstructor.cpp#2526
[2]: https://github.com/servo/servo/blob/3330653dc80cc8947af17f1989fb7fbf390c4d2f/components/style/traversal.rs#L439
MozReview-Commit-ID: HbjsD6nYsvX
--HG--
extra : rebase_source : 0f9be9665faf6a5e32f527c12dbd00f35a89b986
2017-07-10 12:32:39 +00:00
|
|
|
LazyComputeBehavior::Allow);
|
2015-09-30 00:48:41 +00:00
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2017-09-16 03:45:05 +00:00
|
|
|
Element*
|
2015-09-30 00:48:41 +00:00
|
|
|
nsPresContext::UpdateViewportScrollbarStylesOverride()
|
|
|
|
{
|
2016-12-23 00:52:12 +00:00
|
|
|
// Start off with our default styles, and then update them as needed.
|
|
|
|
mViewportStyleScrollbar = ScrollbarStyles(NS_STYLE_OVERFLOW_AUTO,
|
|
|
|
NS_STYLE_OVERFLOW_AUTO);
|
2017-09-16 03:45:05 +00:00
|
|
|
mViewportScrollbarOverrideElement = nullptr;
|
2016-12-23 00:52:12 +00:00
|
|
|
// Don't propagate the scrollbar state in printing or print preview.
|
|
|
|
if (!IsPaginated()) {
|
2017-09-16 03:45:05 +00:00
|
|
|
mViewportScrollbarOverrideElement =
|
2016-12-23 00:52:12 +00:00
|
|
|
GetPropagatedScrollbarStylesForViewport(this, &mViewportStyleScrollbar);
|
|
|
|
}
|
2015-09-30 00:48:41 +00:00
|
|
|
|
|
|
|
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() &&
|
2017-09-16 03:45:05 +00:00
|
|
|
fullscreenElement != mViewportScrollbarOverrideElement) {
|
2015-09-30 00:48:41 +00:00
|
|
|
mViewportStyleScrollbar = ScrollbarStyles(NS_STYLE_OVERFLOW_HIDDEN,
|
|
|
|
NS_STYLE_OVERFLOW_HIDDEN);
|
|
|
|
}
|
|
|
|
}
|
2017-09-16 03:45:05 +00:00
|
|
|
return mViewportScrollbarOverrideElement;
|
2015-09-30 00:48:41 +00:00
|
|
|
}
|
|
|
|
|
2016-12-23 00:52:12 +00:00
|
|
|
bool
|
|
|
|
nsPresContext::ElementWouldPropagateScrollbarStyles(Element* aElement)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(IsPaginated(), "Should only be called on paginated contexts");
|
|
|
|
if (aElement->GetParent() && !aElement->IsHTMLElement(nsGkAtoms::body)) {
|
|
|
|
// We certainly won't be propagating from this element.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Go ahead and just call GetPropagatedScrollbarStylesForViewport, but update
|
|
|
|
// a dummy ScrollbarStyles we don't care about. It'll do a bit of extra work,
|
|
|
|
// but saves us having to have more complicated code or more code duplication;
|
|
|
|
// in practice we will make this call quite rarely, because we checked for all
|
|
|
|
// the common cases above.
|
|
|
|
ScrollbarStyles dummy(NS_STYLE_OVERFLOW_AUTO, NS_STYLE_OVERFLOW_AUTO);
|
|
|
|
return GetPropagatedScrollbarStylesForViewport(this, &dummy) == aElement;
|
|
|
|
}
|
|
|
|
|
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) {
|
2017-02-13 23:45:23 +00:00
|
|
|
mPrefChangedTimer = CreateTimer(PrefChangedUpdateTimerCallback,
|
|
|
|
"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*
|
2017-09-08 23:25:03 +00:00
|
|
|
nsPresContext::GetContainerWeak() 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
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2012-07-30 04:29:41 +00:00
|
|
|
bool
|
2017-09-08 23:25:03 +00:00
|
|
|
nsPresContext::BidiEnabled() const
|
2012-07-30 04:29:41 +00:00
|
|
|
{
|
|
|
|
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
|
2017-08-29 23:18:10 +00:00
|
|
|
nsPresContext::SetBidi(uint32_t aSource)
|
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;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
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()
|
|
|
|
{
|
2017-12-11 09:48:42 +00:00
|
|
|
return Document()->IsTopLevelWindowInactive();
|
2010-03-17 17:10:57 +00:00
|
|
|
}
|
|
|
|
|
2016-11-09 01:39:28 +00:00
|
|
|
void
|
2017-02-01 04:49:06 +00:00
|
|
|
nsPresContext::RecordInteractionTime(InteractionType aType,
|
|
|
|
const TimeStamp& aTimeStamp)
|
2016-11-09 01:39:28 +00:00
|
|
|
{
|
2017-02-01 04:49:06 +00:00
|
|
|
if (!mInteractionTimeEnabled || aTimeStamp.IsNull()) {
|
2016-11-09 01:39:28 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Array of references to the member variable of each time stamp
|
|
|
|
// for the different interaction types, keyed by InteractionType.
|
|
|
|
TimeStamp nsPresContext::*interactionTimes[] = {
|
|
|
|
&nsPresContext::mFirstClickTime,
|
|
|
|
&nsPresContext::mFirstKeyTime,
|
|
|
|
&nsPresContext::mFirstMouseMoveTime,
|
|
|
|
&nsPresContext::mFirstScrollTime
|
|
|
|
};
|
|
|
|
|
2016-11-08 19:30:57 +00:00
|
|
|
// Array of histogram IDs for the different interaction types,
|
|
|
|
// keyed by InteractionType.
|
2017-02-15 19:15:15 +00:00
|
|
|
Telemetry::HistogramID histogramIds[] = {
|
2017-02-01 04:49:06 +00:00
|
|
|
Telemetry::TIME_TO_FIRST_CLICK_MS,
|
|
|
|
Telemetry::TIME_TO_FIRST_KEY_INPUT_MS,
|
|
|
|
Telemetry::TIME_TO_FIRST_MOUSE_MOVE_MS,
|
|
|
|
Telemetry::TIME_TO_FIRST_SCROLL_MS
|
2016-11-08 19:30:57 +00:00
|
|
|
};
|
|
|
|
|
2016-11-09 01:39:28 +00:00
|
|
|
TimeStamp& interactionTime = this->*(
|
|
|
|
interactionTimes[static_cast<uint32_t>(aType)]);
|
|
|
|
if (!interactionTime.IsNull()) {
|
|
|
|
// We have already recorded an interaction time.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Record the interaction time if it occurs after the first paint
|
|
|
|
// of the top level content document.
|
|
|
|
nsPresContext* topContentPresContext =
|
|
|
|
GetToplevelContentDocumentPresContext();
|
|
|
|
|
|
|
|
if (!topContentPresContext) {
|
|
|
|
// There is no top content pres context so we don't care
|
|
|
|
// about the interaction time. Record a value anyways to avoid
|
|
|
|
// trying to find the top content pres context in future interactions.
|
|
|
|
interactionTime = TimeStamp::Now();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-02-01 04:49:06 +00:00
|
|
|
if (topContentPresContext->mFirstNonBlankPaintTime.IsNull() ||
|
|
|
|
topContentPresContext->mFirstNonBlankPaintTime > aTimeStamp) {
|
|
|
|
// Top content pres context has not had a non-blank paint yet
|
|
|
|
// or the event timestamp is before the first non-blank paint,
|
|
|
|
// so don't record interaction time.
|
2016-11-09 01:39:28 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-02-01 04:49:06 +00:00
|
|
|
// Check if we are recording the first of any of the interaction types.
|
|
|
|
bool isFirstInteraction = true;
|
|
|
|
for (TimeStamp nsPresContext::* memberPtr : interactionTimes) {
|
|
|
|
TimeStamp& timeStamp = this->*(memberPtr);
|
|
|
|
if (!timeStamp.IsNull()) {
|
|
|
|
isFirstInteraction = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-09 01:39:28 +00:00
|
|
|
interactionTime = TimeStamp::Now();
|
|
|
|
// Only the top level content pres context reports first interaction
|
|
|
|
// time to telemetry (if it hasn't already done so).
|
|
|
|
if (this == topContentPresContext) {
|
2016-11-08 19:30:57 +00:00
|
|
|
if (Telemetry::CanRecordExtended()) {
|
2017-02-01 04:49:06 +00:00
|
|
|
double millis =
|
|
|
|
(interactionTime - mFirstNonBlankPaintTime).ToMilliseconds();
|
2016-11-08 19:30:57 +00:00
|
|
|
Telemetry::Accumulate(histogramIds[static_cast<uint32_t>(aType)],
|
|
|
|
millis);
|
2017-02-01 04:49:06 +00:00
|
|
|
|
|
|
|
if (isFirstInteraction) {
|
|
|
|
Telemetry::Accumulate(Telemetry::TIME_TO_FIRST_INTERACTION_MS, millis);
|
|
|
|
}
|
2016-11-08 19:30:57 +00:00
|
|
|
}
|
2016-11-09 01:39:28 +00:00
|
|
|
} else {
|
2017-02-01 04:49:06 +00:00
|
|
|
topContentPresContext->RecordInteractionTime(aType, aTimeStamp);
|
2016-11-09 01:39:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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 =
|
2017-06-12 19:34:10 +00:00
|
|
|
NewRunnableMethod("nsPresContext::ThemeChangedInternal",
|
|
|
|
this,
|
|
|
|
&nsPresContext::ThemeChangedInternal);
|
2017-07-26 08:13:35 +00:00
|
|
|
nsresult rv = Document()->Dispatch(TaskCategory::Other,
|
2017-03-15 02:53:59 +00:00
|
|
|
ev.forget());
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
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
|
|
|
|
2017-07-24 14:57:29 +00:00
|
|
|
RefreshSystemMetrics();
|
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 =
|
2017-06-12 19:34:10 +00:00
|
|
|
NewRunnableMethod("nsPresContext::SysColorChangedInternal",
|
|
|
|
this,
|
|
|
|
&nsPresContext::SysColorChangedInternal);
|
2017-07-26 08:13:35 +00:00
|
|
|
nsresult rv = Document()->Dispatch(TaskCategory::Other,
|
2017-03-15 02:53:59 +00:00
|
|
|
ev.forget());
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
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
|
|
|
|
2017-07-11 16:38:45 +00:00
|
|
|
// Invalidate cached '-moz-windows-accent-color-applies' media query:
|
2017-07-24 14:57:29 +00:00
|
|
|
RefreshSystemMetrics();
|
2017-07-11 16:38:45 +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
|
|
|
}
|
|
|
|
|
2017-07-24 14:57:29 +00:00
|
|
|
void
|
|
|
|
nsPresContext::RefreshSystemMetrics()
|
|
|
|
{
|
2017-10-07 11:57:54 +00:00
|
|
|
// This will force the system metrics to be generated the next time they're
|
|
|
|
// used.
|
2017-11-17 07:35:26 +00:00
|
|
|
nsMediaFeatures::FreeSystemMetrics();
|
2017-07-24 14:57:29 +00:00
|
|
|
|
2017-10-07 11:57:54 +00:00
|
|
|
// Changes to system metrics can change media queries on them.
|
|
|
|
//
|
2017-07-24 14:57:29 +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
|
2017-10-07 11:57:54 +00:00
|
|
|
// not), so we need to recascade for the first, and reflow for the rest.
|
|
|
|
MediaFeatureValuesChanged(eRestyle_ForceDescendants, NS_STYLE_HINT_REFLOW);
|
2017-07-24 14:57:29 +00:00
|
|
|
}
|
|
|
|
|
2012-10-16 19:41:20 +00:00
|
|
|
void
|
|
|
|
nsPresContext::UIResolutionChanged()
|
|
|
|
{
|
|
|
|
if (!mPendingUIResolutionChanged) {
|
|
|
|
nsCOMPtr<nsIRunnable> ev =
|
2017-06-12 19:34:10 +00:00
|
|
|
NewRunnableMethod("nsPresContext::UIResolutionChangedInternal",
|
|
|
|
this,
|
|
|
|
&nsPresContext::UIResolutionChangedInternal);
|
2017-03-15 02:53:59 +00:00
|
|
|
nsresult rv =
|
2017-07-26 08:13:35 +00:00
|
|
|
Document()->Dispatch(TaskCategory::Other, ev.forget());
|
2017-03-15 02:53:59 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2012-10-16 19:41:20 +00:00
|
|
|
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)
|
|
|
|
{
|
2017-10-02 22:05:19 +00:00
|
|
|
nsAtom* previousMedium = Medium();
|
2013-07-17 15:39:19 +00:00
|
|
|
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()
|
|
|
|
{
|
2017-10-02 22:05:19 +00:00
|
|
|
nsAtom* previousMedium = Medium();
|
2013-07-17 15:39:19 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-20 19:47:36 +00:00
|
|
|
void
|
2017-10-02 22:05:19 +00:00
|
|
|
nsPresContext::ForceCacheLang(nsAtom *aLanguage)
|
2017-05-20 19:47:36 +00:00
|
|
|
{
|
|
|
|
// force it to be cached
|
|
|
|
GetDefaultFont(kPresContext_DefaultVariableFont_ID, aLanguage);
|
2017-06-13 23:54:26 +00:00
|
|
|
mLanguagesUsed.PutEntry(aLanguage);
|
2017-05-20 19:47:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsPresContext::CacheAllLangs()
|
|
|
|
{
|
|
|
|
if (mFontGroupCacheDirty) {
|
2017-10-02 22:05:19 +00:00
|
|
|
RefPtr<nsAtom> thisLang = nsStyleFont::GetLanguage(this);
|
2017-05-20 19:47:36 +00:00
|
|
|
GetDefaultFont(kPresContext_DefaultVariableFont_ID, thisLang.get());
|
|
|
|
GetDefaultFont(kPresContext_DefaultVariableFont_ID, nsGkAtoms::x_math);
|
|
|
|
// https://bugzilla.mozilla.org/show_bug.cgi?id=1362599#c12
|
|
|
|
GetDefaultFont(kPresContext_DefaultVariableFont_ID, nsGkAtoms::Unicode);
|
|
|
|
for (auto iter = mLanguagesUsed.Iter(); !iter.Done(); iter.Next()) {
|
|
|
|
|
|
|
|
GetDefaultFont(kPresContext_DefaultVariableFont_ID, iter.Get()->GetKey());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mFontGroupCacheDirty = false;
|
|
|
|
}
|
|
|
|
|
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;
|
2017-07-24 01:51:32 +00:00
|
|
|
if (nsStyleSet* styleSet = mShell->StyleSet()->GetAsGecko()) {
|
|
|
|
styleSet->SetUsesViewportUnits(false);
|
|
|
|
}
|
2015-06-27 01:39:54 +00:00
|
|
|
mDocument->RebuildUserFontSet();
|
2014-06-12 01:12:00 +00:00
|
|
|
RebuildCounterStyles();
|
2017-08-24 01:05:53 +00:00
|
|
|
RebuildFontFeatureValues();
|
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.
|
2017-07-24 01:27:08 +00:00
|
|
|
if (mShell) {
|
|
|
|
aRestyleHint |= mShell->
|
|
|
|
StyleSet()->MediumFeaturesChanged(mPendingViewportChange);
|
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;
|
|
|
|
|
2017-11-01 10:24:17 +00:00
|
|
|
if (!mShell || !mShell->DidInitialize()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-08-06 04:44:59 +00:00
|
|
|
if (mDocument->IsBeingUsedAsImage()) {
|
2017-04-07 00:45:16 +00:00
|
|
|
MOZ_ASSERT(mDocument->MediaQueryLists().isEmpty());
|
2011-04-22 03:17:31 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-05-11 22:07:49 +00:00
|
|
|
mDocument->NotifyMediaFeatureValuesChanged();
|
|
|
|
|
2017-11-01 10:24:17 +00:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(nsContentUtils::IsSafeToRunScript());
|
2014-08-06 04:44:59 +00:00
|
|
|
|
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.
|
|
|
|
|
2017-04-07 00:45:16 +00:00
|
|
|
if (!mDocument->MediaQueryLists().isEmpty()) {
|
2011-04-22 03:17:31 +00:00
|
|
|
// We build a list of all the notifications we're going to send
|
2017-04-10 14:29:06 +00:00
|
|
|
// before we send any of them.
|
2017-09-20 00:05:16 +00:00
|
|
|
|
|
|
|
// Copy pointers to all the lists into a new array, in case one of our
|
|
|
|
// notifications modifies the list.
|
|
|
|
nsTArray<RefPtr<mozilla::dom::MediaQueryList>> localMediaQueryLists;
|
|
|
|
for (auto* mql : mDocument->MediaQueryLists()) {
|
|
|
|
localMediaQueryLists.AppendElement(mql);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now iterate our local array of the lists.
|
2017-09-20 00:05:16 +00:00
|
|
|
for (const auto& mql : localMediaQueryLists) {
|
2017-04-10 14:29:06 +00:00
|
|
|
nsAutoMicroTask mt;
|
|
|
|
mql->MaybeNotify();
|
2011-04-22 03:17:31 +00:00
|
|
|
}
|
|
|
|
}
|
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).
|
2017-02-10 02:42:27 +00:00
|
|
|
if (!mPendingMediaFeatureValuesChanged && mShell) {
|
2008-07-26 16:14:48 +00:00
|
|
|
nsCOMPtr<nsIRunnable> ev =
|
2017-02-11 06:11:48 +00:00
|
|
|
NewRunnableMethod("nsPresContext::HandleMediaFeatureValuesChangedEvent",
|
|
|
|
this, &nsPresContext::HandleMediaFeatureValuesChangedEvent);
|
2017-03-15 02:53:59 +00:00
|
|
|
nsresult rv =
|
2017-07-26 08:13:35 +00:00
|
|
|
Document()->Dispatch(TaskCategory::Other, ev.forget());
|
2017-03-15 02:53:59 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2011-10-17 14:59:28 +00:00
|
|
|
mPendingMediaFeatureValuesChanged = true;
|
2017-02-10 02:42:27 +00:00
|
|
|
mShell->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
|
2017-05-12 15:51:32 +00:00
|
|
|
nsPresContext::HasAuthorSpecifiedRules(const nsIFrame* aFrame,
|
|
|
|
uint32_t aRuleTypeMask) const
|
2007-10-08 23:11:01 +00:00
|
|
|
{
|
2017-07-26 16:21:35 +00:00
|
|
|
if (auto* geckoStyleContext = aFrame->StyleContext()->GetAsGecko()) {
|
2017-05-10 20:11:36 +00:00
|
|
|
return
|
2017-07-26 16:21:35 +00:00
|
|
|
nsRuleNode::HasAuthorSpecifiedRules(geckoStyleContext,
|
2017-05-12 15:51:32 +00:00
|
|
|
aRuleTypeMask,
|
2017-05-10 20:11:36 +00:00
|
|
|
UseDocumentColors());
|
|
|
|
}
|
2017-05-12 15:51:32 +00:00
|
|
|
Element* elem = aFrame->GetContent()->AsElement();
|
|
|
|
|
2017-10-10 07:35:10 +00:00
|
|
|
// We need to handle non-generated content pseudos too, so we use
|
|
|
|
// the parent of generated content pseudo to be consistent.
|
|
|
|
if (elem->GetPseudoElementType() != CSSPseudoElementType::NotPseudo) {
|
|
|
|
MOZ_ASSERT(elem->GetParent(), "Pseudo element has no parent element?");
|
|
|
|
elem = elem->GetParent()->AsElement();
|
|
|
|
}
|
|
|
|
if (MOZ_UNLIKELY(!elem->HasServoData())) {
|
2017-08-07 20:48:09 +00:00
|
|
|
// Probably shouldn't happen, but does. See bug 1387953
|
|
|
|
return false;
|
|
|
|
}
|
2017-10-10 07:35:10 +00:00
|
|
|
|
|
|
|
nsStyleContext* styleContext = aFrame->StyleContext();
|
|
|
|
CSSPseudoElementType pseudoType = styleContext->GetPseudoType();
|
|
|
|
// Anonymous boxes are more complicated, and we just assume that they
|
|
|
|
// cannot have any author-specified rules here.
|
|
|
|
if (pseudoType == CSSPseudoElementType::InheritingAnonBox ||
|
|
|
|
pseudoType == CSSPseudoElementType::NonInheritingAnonBox) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return Servo_HasAuthorSpecifiedRules(styleContext->AsServo(),
|
|
|
|
elem, pseudoType,
|
|
|
|
aRuleTypeMask,
|
|
|
|
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*
|
2017-01-25 21:34:22 +00:00
|
|
|
nsPresContext::GetUserFontSet(bool aFlushUserFontSet)
|
2008-12-04 16:09:53 +00:00
|
|
|
{
|
2017-01-25 21:34:22 +00:00
|
|
|
return mDocument->GetUserFontSet(aFlushUserFontSet);
|
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
|
|
|
// 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.
|
2017-03-22 02:34:03 +00:00
|
|
|
if (!aUpdatedFont) {
|
2015-03-06 08:44:23 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2017-05-13 11:42:23 +00:00
|
|
|
class CounterStyleCleaner : public nsAPostRefreshObserver
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CounterStyleCleaner(nsRefreshDriver* aRefreshDriver,
|
|
|
|
CounterStyleManager* aCounterStyleManager)
|
|
|
|
: mRefreshDriver(aRefreshDriver)
|
|
|
|
, mCounterStyleManager(aCounterStyleManager)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
virtual ~CounterStyleCleaner() {}
|
|
|
|
|
2017-11-06 03:37:28 +00:00
|
|
|
void DidRefresh() final override
|
2017-05-13 11:42:23 +00:00
|
|
|
{
|
|
|
|
mRefreshDriver->RemovePostRefreshObserver(this);
|
|
|
|
mCounterStyleManager->CleanRetiredStyles();
|
|
|
|
delete this;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
RefPtr<nsRefreshDriver> mRefreshDriver;
|
|
|
|
RefPtr<CounterStyleManager> mCounterStyleManager;
|
|
|
|
};
|
|
|
|
|
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);
|
2017-05-20 01:26:24 +00:00
|
|
|
RefreshDriver()->AddPostRefreshObserver(
|
|
|
|
new CounterStyleCleaner(RefreshDriver(), mCounterStyleManager));
|
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;
|
2017-02-10 02:42:27 +00:00
|
|
|
if (mShell) {
|
|
|
|
mShell->SetNeedStyleFlush();
|
|
|
|
}
|
2014-06-12 01:12:00 +00:00
|
|
|
if (!mPostedFlushCounterStyles) {
|
|
|
|
nsCOMPtr<nsIRunnable> ev =
|
2017-02-11 06:11:48 +00:00
|
|
|
NewRunnableMethod("nsPresContext::HandleRebuildCounterStyles",
|
|
|
|
this, &nsPresContext::HandleRebuildCounterStyles);
|
2017-03-15 02:53:59 +00:00
|
|
|
nsresult rv =
|
2017-07-26 08:13:35 +00:00
|
|
|
Document()->Dispatch(TaskCategory::Other, ev.forget());
|
2017-03-15 02:53:59 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2014-06-12 01:12:00 +00:00
|
|
|
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()
|
|
|
|
{
|
2017-05-15 23:30:10 +00:00
|
|
|
if (!mShell->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
|
2017-02-16 22:50:58 +00:00
|
|
|
nsPresContext::FireDOMPaintEvent(nsTArray<nsRect>* aList, uint64_t aTransactionId,
|
2017-01-26 05:01:33 +00:00
|
|
|
mozilla::TimeStamp aTimeStamp /* = mozilla::TimeStamp() */)
|
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
|
|
|
}
|
2017-01-26 05:01:33 +00:00
|
|
|
|
|
|
|
if (aTimeStamp.IsNull()) {
|
|
|
|
aTimeStamp = mozilla::TimeStamp::Now();
|
|
|
|
}
|
|
|
|
DOMHighResTimeStamp timeStamp = 0;
|
2017-11-21 23:07:45 +00:00
|
|
|
if (ourWindow) {
|
2017-01-26 05:01:33 +00:00
|
|
|
mozilla::dom::Performance* perf = ourWindow->GetPerformance();
|
|
|
|
if (perf) {
|
|
|
|
timeStamp = perf->GetDOMTiming()->TimeStampToDOMHighRes(aTimeStamp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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 =
|
2017-01-26 05:01:33 +00:00
|
|
|
NS_NewDOMNotifyPaintEvent(eventTarget, this, nullptr, eAfterPaint, aList,
|
|
|
|
aTransactionId, timeStamp);
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-02-17 02:15:45 +00:00
|
|
|
nsPresContext::NotifyInvalidation(uint64_t aTransactionId, const nsIntRect& aRect)
|
2012-08-29 05:47:18 +00:00
|
|
|
{
|
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));
|
2017-02-17 02:15:45 +00:00
|
|
|
NotifyInvalidation(aTransactionId, rect);
|
2012-08-29 05:47:18 +00:00
|
|
|
}
|
|
|
|
|
2008-09-18 09:47:21 +00:00
|
|
|
void
|
2017-02-17 02:15:45 +00:00
|
|
|
nsPresContext::NotifyInvalidation(uint64_t aTransactionId, const nsRect& aRect)
|
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
|
|
|
|
2017-11-27 15:27:27 +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.
|
|
|
|
|
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()) {
|
2018-01-30 07:43:27 +00:00
|
|
|
if (pc->mFireAfterPaintEvents)
|
2011-01-15 09:40:33 +00:00
|
|
|
break;
|
2018-01-30 07:43:27 +00:00
|
|
|
pc->mFireAfterPaintEvents = true;
|
2011-01-15 09:40:33 +00:00
|
|
|
}
|
2017-11-27 15:27:27 +00:00
|
|
|
if (!pc) {
|
|
|
|
nsRootPresContext* rpc = GetRootPresContext();
|
|
|
|
if (rpc) {
|
|
|
|
rpc->EnsureEventualDidPaintEvent(aTransactionId);
|
|
|
|
}
|
|
|
|
}
|
2008-09-18 09:47:21 +00:00
|
|
|
|
2018-01-30 07:43:27 +00:00
|
|
|
TransactionInvalidations* transaction = nullptr;
|
|
|
|
for (TransactionInvalidations& t : mTransactions) {
|
|
|
|
if (t.mTransactionId == aTransactionId) {
|
|
|
|
transaction = &t;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!transaction) {
|
|
|
|
transaction = mTransactions.AppendElement();
|
|
|
|
transaction->mTransactionId = aTransactionId;
|
|
|
|
}
|
|
|
|
|
2017-02-17 02:16:15 +00:00
|
|
|
transaction->mInvalidations.AppendElement(aRect);
|
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,
|
2017-08-04 04:22:49 +00:00
|
|
|
const nsIntRegion* aRegion)
|
2012-08-29 05:47:18 +00:00
|
|
|
{
|
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;
|
|
|
|
}
|
|
|
|
|
2017-08-04 04:22:49 +00:00
|
|
|
uint64_t transactionId = aContainer->Manager()->GetLastTransactionId();
|
|
|
|
IntRect visibleBounds = aContainer->GetVisibleRegion().GetBounds().ToUnknownRect();
|
2012-08-29 05:47:18 +00:00
|
|
|
|
2017-08-04 04:22:49 +00:00
|
|
|
if (!aRegion) {
|
|
|
|
IntRect rect(IntPoint(0, 0), visibleBounds.Size());
|
|
|
|
data->mPresContext->NotifyInvalidation(transactionId, rect);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIntPoint topLeft = visibleBounds.TopLeft();
|
|
|
|
for (auto iter = aRegion->RectIter(); !iter.Done(); iter.Next()) {
|
2016-01-19 01:20:59 +00:00
|
|
|
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);
|
2017-08-04 04:22:49 +00:00
|
|
|
data->mPresContext->NotifyInvalidation(transactionId, rect);
|
2012-08-29 05:47:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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 {
|
2016-04-13 20:59:15 +00:00
|
|
|
uint64_t mTransactionId;
|
2017-01-26 05:01:33 +00:00
|
|
|
const mozilla::TimeStamp& mTimeStamp;
|
2018-01-30 07:43:27 +00:00
|
|
|
bool mNeedsAnotherDidPaintNotification;
|
2012-10-19 04:50:34 +00:00
|
|
|
};
|
2017-02-17 02:16:15 +00:00
|
|
|
/* static */ bool
|
|
|
|
nsPresContext::NotifyDidPaintSubdocumentCallback(nsIDocument* aDocument, void* aData)
|
2011-01-15 09:40:33 +00:00
|
|
|
{
|
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) {
|
2017-02-17 02:16:15 +00:00
|
|
|
pc->NotifyDidPaintForSubtree(closure->mTransactionId,
|
2017-01-26 05:01:33 +00:00
|
|
|
closure->mTimeStamp);
|
2018-01-30 07:43:27 +00:00
|
|
|
if (pc->mFireAfterPaintEvents) {
|
|
|
|
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:
|
2017-06-12 19:34:10 +00:00
|
|
|
DelayedFireDOMPaintEvent(
|
|
|
|
nsPresContext* aPresContext,
|
|
|
|
nsTArray<nsRect>* aList,
|
|
|
|
uint64_t aTransactionId,
|
|
|
|
const mozilla::TimeStamp& aTimeStamp = mozilla::TimeStamp())
|
|
|
|
: mozilla::Runnable("DelayedFireDOMPaintEvent")
|
|
|
|
, mPresContext(aPresContext)
|
2016-04-13 20:59:15 +00:00
|
|
|
, mTransactionId(aTransactionId)
|
2017-01-26 05:01:33 +00:00
|
|
|
, mTimeStamp(aTimeStamp)
|
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");
|
2017-02-16 22:50:58 +00:00
|
|
|
mList.SwapElements(*aList);
|
2012-10-19 04:50:34 +00:00
|
|
|
}
|
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()) {
|
2017-01-26 05:01:33 +00:00
|
|
|
mPresContext->FireDOMPaintEvent(&mList, mTransactionId, mTimeStamp);
|
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;
|
2017-01-26 05:01:33 +00:00
|
|
|
const mozilla::TimeStamp mTimeStamp;
|
2017-02-16 22:50:58 +00:00
|
|
|
nsTArray<nsRect> mList;
|
2012-10-19 04:50:34 +00:00
|
|
|
};
|
|
|
|
|
2011-01-15 09:40:33 +00:00
|
|
|
void
|
2017-02-17 02:16:15 +00:00
|
|
|
nsPresContext::NotifyDidPaintForSubtree(uint64_t aTransactionId,
|
2016-04-13 20:59:15 +00:00
|
|
|
const mozilla::TimeStamp& aTimeStamp)
|
2011-01-15 09:40:33 +00:00
|
|
|
{
|
2017-11-27 15:27:27 +00:00
|
|
|
if (IsRoot()) {
|
|
|
|
static_cast<nsRootPresContext*>(this)->CancelDidPaintTimers(aTransactionId);
|
|
|
|
|
2018-01-30 07:43:27 +00:00
|
|
|
if (!mFireAfterPaintEvents) {
|
2017-11-27 15:27:27 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-10-19 04:50:34 +00:00
|
|
|
}
|
2014-10-21 08:59:59 +00:00
|
|
|
|
2018-01-30 07:43:27 +00:00
|
|
|
if (!PresShell()->IsVisible() && !mFireAfterPaintEvents) {
|
2014-10-21 08:59:59 +00:00
|
|
|
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
|
|
|
|
2017-02-17 02:16:15 +00:00
|
|
|
bool sent = false;
|
|
|
|
uint32_t i = 0;
|
|
|
|
while (i < mTransactions.Length()) {
|
|
|
|
if (mTransactions[i].mTransactionId <= aTransactionId) {
|
2018-01-30 07:43:27 +00:00
|
|
|
nsCOMPtr<nsIRunnable> ev =
|
|
|
|
new DelayedFireDOMPaintEvent(this, &mTransactions[i].mInvalidations,
|
|
|
|
mTransactions[i].mTransactionId, aTimeStamp);
|
|
|
|
nsContentUtils::AddScriptRunner(ev);
|
|
|
|
sent = true;
|
2017-02-17 02:16:15 +00:00
|
|
|
mTransactions.RemoveElementAt(i);
|
|
|
|
} else {
|
|
|
|
i++;
|
|
|
|
}
|
2012-10-19 04:50:34 +00:00
|
|
|
}
|
2017-02-17 02:16:15 +00:00
|
|
|
|
|
|
|
if (!sent) {
|
|
|
|
nsTArray<nsRect> dummy;
|
2012-10-19 04:50:34 +00:00
|
|
|
nsCOMPtr<nsIRunnable> ev =
|
2017-02-17 02:16:15 +00:00
|
|
|
new DelayedFireDOMPaintEvent(this, &dummy,
|
2017-01-26 05:01:33 +00:00
|
|
|
aTransactionId, aTimeStamp);
|
2012-10-19 04:50:34 +00:00
|
|
|
nsContentUtils::AddScriptRunner(ev);
|
|
|
|
}
|
|
|
|
|
2018-01-30 07:43:27 +00:00
|
|
|
NotifyDidPaintSubdocumentCallbackClosure closure = { aTransactionId, aTimeStamp, false };
|
2017-02-17 02:16:15 +00:00
|
|
|
mDocument->EnumerateSubDocuments(nsPresContext::NotifyDidPaintSubdocumentCallback, &closure);
|
2018-01-30 07:43:27 +00:00
|
|
|
|
|
|
|
if (!closure.mNeedsAnotherDidPaintNotification &&
|
|
|
|
mTransactions.IsEmpty()) {
|
|
|
|
// Nothing more to do for the moment.
|
|
|
|
mFireAfterPaintEvents = false;
|
|
|
|
}
|
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,
|
2017-02-13 23:45:23 +00:00
|
|
|
const char* aName,
|
2015-08-04 00:13:07 +00:00
|
|
|
uint32_t aDelay)
|
2015-07-30 21:24:51 +00:00
|
|
|
{
|
2017-10-16 06:13:31 +00:00
|
|
|
nsCOMPtr<nsITimer> timer;
|
|
|
|
NS_NewTimerWithFuncCallback(getter_AddRefs(timer),
|
|
|
|
aCallback, this, aDelay,
|
|
|
|
nsITimer::TYPE_ONE_SHOT,
|
|
|
|
aName,
|
|
|
|
Document()->EventTargetFor(TaskCategory::Other));
|
|
|
|
return timer.forget();
|
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()
|
|
|
|
{
|
2017-02-10 02:42:29 +00:00
|
|
|
nsIPresShell* shell = PresShell();
|
|
|
|
return shell->NeedStyleFlush() || shell->HasPendingReflow();
|
2014-10-02 02:32:09 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2017-05-27 11:36:00 +00:00
|
|
|
return mLangGroupFontPrefs.SizeOfExcludingThis(aMallocSizeOf);
|
2012-02-21 05:02:24 +00:00
|
|
|
|
|
|
|
// 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());
|
|
|
|
}
|
|
|
|
|
2016-11-10 21:00:45 +00:00
|
|
|
void
|
|
|
|
nsPresContext::NotifyNonBlankPaint()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(!mHadNonBlankPaint);
|
|
|
|
mHadNonBlankPaint = true;
|
2016-11-10 19:26:54 +00:00
|
|
|
if (IsRootContentDocument()) {
|
|
|
|
RefPtr<nsDOMNavigationTiming> timing = mDocument->GetNavigationTiming();
|
|
|
|
if (timing) {
|
|
|
|
timing->NotifyNonBlankPaintForRootContentDocument();
|
|
|
|
}
|
2017-02-01 04:49:06 +00:00
|
|
|
|
|
|
|
mFirstNonBlankPaintTime = TimeStamp::Now();
|
2016-11-10 21:00:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2017-11-12 14:56:12 +00:00
|
|
|
nscoord
|
|
|
|
nsPresContext::PhysicalMillimetersToAppUnits(float aMM) const
|
|
|
|
{
|
|
|
|
float inches = aMM / MM_PER_INCH_FLOAT;
|
|
|
|
return NSToCoordFloorClamped(
|
|
|
|
inches * float(DeviceContext()->AppUnitsPerPhysicalInch()));
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2017-05-23 06:13:47 +00:00
|
|
|
uint64_t
|
|
|
|
nsPresContext::GetUndisplayedRestyleGeneration() const
|
|
|
|
{
|
|
|
|
if (!mRestyleManager) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return mRestyleManager->GetUndisplayedRestyleGeneration();
|
|
|
|
}
|
|
|
|
|
2017-04-11 04:51:30 +00:00
|
|
|
nsBidi&
|
|
|
|
nsPresContext::GetBidiEngine()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
if (!mBidiEngine) {
|
|
|
|
mBidiEngine.reset(new nsBidi());
|
|
|
|
}
|
|
|
|
return *mBidiEngine;
|
|
|
|
}
|
|
|
|
|
2017-08-24 01:05:53 +00:00
|
|
|
void
|
|
|
|
nsPresContext::FlushFontFeatureValues()
|
|
|
|
{
|
|
|
|
if (!mShell) {
|
|
|
|
return; // we've been torn down
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mFontFeatureValuesDirty) {
|
|
|
|
StyleSetHandle styleSet = mShell->StyleSet();
|
|
|
|
mFontFeatureValuesLookup = styleSet->BuildFontFeatureValueSet();
|
|
|
|
mFontFeatureValuesDirty = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsPresContext::RebuildFontFeatureValues()
|
|
|
|
{
|
|
|
|
if (!mShell) {
|
|
|
|
return; // we've been torn down
|
|
|
|
}
|
|
|
|
|
|
|
|
mFontFeatureValuesDirty = true;
|
|
|
|
mShell->SetNeedStyleFlush();
|
|
|
|
|
|
|
|
if (!mPostedFlushFontFeatureValues) {
|
|
|
|
nsCOMPtr<nsIRunnable> ev =
|
|
|
|
NewRunnableMethod("nsPresContext::HandleRebuildFontFeatureValues",
|
|
|
|
this, &nsPresContext::HandleRebuildFontFeatureValues);
|
|
|
|
nsresult rv =
|
|
|
|
Document()->Dispatch(TaskCategory::Other, ev.forget());
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
mPostedFlushFontFeatureValues = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-22 00:44:54 +00:00
|
|
|
nsRootPresContext::nsRootPresContext(nsIDocument* aDocument,
|
|
|
|
nsPresContextType aType)
|
2017-12-21 13:09:32 +00:00
|
|
|
: nsPresContext(aDocument, aType)
|
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");
|
2017-11-27 15:27:27 +00:00
|
|
|
CancelAllDidPaintTimers();
|
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()
|
|
|
|
{
|
2017-11-27 15:27:27 +00:00
|
|
|
CancelAllDidPaintTimers();
|
2014-02-03 23:47:57 +00:00
|
|
|
// 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
|
|
|
|
2017-01-17 17:07:05 +00:00
|
|
|
if (aBuilder) {
|
|
|
|
MOZ_ASSERT(aList);
|
|
|
|
nsIFrame* rootFrame = FrameManager()->GetRootFrame();
|
|
|
|
|
|
|
|
if (rootFrame && aBuilder->ContainsPluginItem()) {
|
2017-09-12 18:10:39 +00:00
|
|
|
aBuilder->SetForPluginGeometry(true);
|
2017-01-17 17:07:05 +00:00
|
|
|
// 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);
|
2017-09-12 18:10:39 +00:00
|
|
|
aBuilder->SetForPluginGeometry(false);
|
2017-01-17 17:07:05 +00:00
|
|
|
}
|
2012-10-18 05:34:58 +00:00
|
|
|
}
|
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,
|
2017-02-13 23:45:23 +00:00
|
|
|
"ApplyPluginGeometryUpdatesCallback",
|
2015-08-04 00:13:07 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2017-11-27 15:27:27 +00:00
|
|
|
void
|
|
|
|
nsRootPresContext::EnsureEventualDidPaintEvent(uint64_t aTransactionId)
|
|
|
|
{
|
|
|
|
for (NotifyDidPaintTimer& t : mNotifyDidPaintTimers) {
|
|
|
|
if (t.mTransactionId == aTransactionId) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsITimer> timer;
|
|
|
|
RefPtr<nsRootPresContext> self = this;
|
|
|
|
nsresult rv = NS_NewTimerWithCallback(
|
|
|
|
getter_AddRefs(timer),
|
|
|
|
NewNamedTimerCallback([self, aTransactionId](){
|
|
|
|
nsAutoScriptBlocker blockScripts;
|
|
|
|
self->NotifyDidPaintForSubtree(aTransactionId);
|
|
|
|
}, "NotifyDidPaintForSubtree"), 100, nsITimer::TYPE_ONE_SHOT,
|
|
|
|
Document()->EventTargetFor(TaskCategory::Other));
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
NotifyDidPaintTimer* t = mNotifyDidPaintTimers.AppendElement();
|
|
|
|
t->mTransactionId = aTransactionId;
|
|
|
|
t->mTimer = timer;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsRootPresContext::CancelDidPaintTimers(uint64_t aTransactionId)
|
|
|
|
{
|
|
|
|
uint32_t i = 0;
|
|
|
|
while (i < mNotifyDidPaintTimers.Length()) {
|
|
|
|
if (mNotifyDidPaintTimers[i].mTransactionId <= aTransactionId) {
|
|
|
|
mNotifyDidPaintTimers[i].mTimer->Cancel();
|
|
|
|
mNotifyDidPaintTimers.RemoveElementAt(i);
|
|
|
|
} else {
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsRootPresContext::CancelAllDidPaintTimers()
|
|
|
|
{
|
|
|
|
for (uint32_t i = 0; i < mNotifyDidPaintTimers.Length(); i++) {
|
|
|
|
mNotifyDidPaintTimers[i].mTimer->Cancel();
|
|
|
|
}
|
|
|
|
mNotifyDidPaintTimers.Clear();
|
|
|
|
}
|
|
|
|
|
2011-10-26 04:14:31 +00:00
|
|
|
void
|
|
|
|
nsRootPresContext::AddWillPaintObserver(nsIRunnable* aRunnable)
|
|
|
|
{
|
|
|
|
if (!mWillPaintFallbackEvent.IsPending()) {
|
|
|
|
mWillPaintFallbackEvent = new RunWillPaintObservers(this);
|
2017-07-26 08:13:35 +00:00
|
|
|
Document()->Dispatch(TaskCategory::Other,
|
2017-10-26 02:46:50 +00:00
|
|
|
do_AddRef(mWillPaintFallbackEvent));
|
2011-10-26 04:14:31 +00:00
|
|
|
}
|
|
|
|
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:
|
2017-11-27 15:27:27 +00:00
|
|
|
// - mNotifyDidPaintTimer
|
2012-02-21 05:02:24 +00:00
|
|
|
// - mRegisteredPlugins
|
|
|
|
// - mWillPaintObservers
|
|
|
|
// - mWillPaintFallbackEvent
|
|
|
|
}
|