2001-09-28 20:14:13 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2006-03-30 05:56:38 +00:00
|
|
|
|
|
|
|
/* a presentation of a document, part 1 */
|
|
|
|
|
2014-01-30 18:26:54 +00:00
|
|
|
#include "mozilla/ArrayUtils.h"
|
2012-12-14 23:58:45 +00:00
|
|
|
#include "mozilla/DebugOnly.h"
|
2014-03-18 04:48:21 +00:00
|
|
|
#include "mozilla/EventDispatcher.h"
|
2014-04-01 04:09:23 +00:00
|
|
|
#include "mozilla/EventStateManager.h"
|
2012-12-14 23:58:45 +00:00
|
|
|
|
2012-09-05 16:23:45 +00:00
|
|
|
#include "base/basictypes.h"
|
|
|
|
|
2002-10-15 23:40:38 +00:00
|
|
|
#include "nsCOMPtr.h"
|
2004-07-31 23:15:21 +00:00
|
|
|
#include "nsPresContext.h"
|
1998-04-13 20:24:54 +00:00
|
|
|
#include "nsIPresShell.h"
|
2013-11-20 19:18:25 +00:00
|
|
|
#include "nsDocShell.h"
|
2005-01-20 03:39:09 +00:00
|
|
|
#include "nsIContentViewer.h"
|
|
|
|
#include "nsPIDOMWindow.h"
|
2016-02-24 07:01:11 +00:00
|
|
|
#include "mozilla/StyleSetHandle.h"
|
|
|
|
#include "mozilla/StyleSetHandleInlines.h"
|
2000-12-30 19:22:22 +00:00
|
|
|
#include "nsIContent.h"
|
1998-04-13 20:24:54 +00:00
|
|
|
#include "nsIFrame.h"
|
1998-09-05 03:52:40 +00:00
|
|
|
#include "nsIDocument.h"
|
2012-07-30 04:29:41 +00:00
|
|
|
#include "nsIPrintSettings.h"
|
|
|
|
#include "nsILanguageAtomService.h"
|
2011-09-09 02:27:13 +00:00
|
|
|
#include "mozilla/LookAndFeel.h"
|
2001-09-05 21:28:38 +00:00
|
|
|
#include "nsIInterfaceRequestorUtils.h"
|
2015-09-10 10:24:34 +00:00
|
|
|
#include "nsIDOMHTMLDocument.h"
|
|
|
|
#include "nsIDOMHTMLElement.h"
|
2002-11-07 00:59:25 +00:00
|
|
|
#include "nsIWeakReferenceUtils.h"
|
2003-02-22 00:32:13 +00:00
|
|
|
#include "nsAutoPtr.h"
|
2006-09-12 04:36:03 +00:00
|
|
|
#include "nsThreadUtils.h"
|
2006-11-29 23:09:13 +00:00
|
|
|
#include "nsFrameManager.h"
|
|
|
|
#include "nsLayoutUtils.h"
|
2013-01-05 03:12:24 +00:00
|
|
|
#include "nsViewManager.h"
|
2016-02-24 07:01:12 +00:00
|
|
|
#include "mozilla/RestyleManager.h"
|
2016-02-24 07:01:12 +00:00
|
|
|
#include "mozilla/RestyleManagerHandle.h"
|
|
|
|
#include "mozilla/RestyleManagerHandleInlines.h"
|
2014-06-25 12:04:36 +00:00
|
|
|
#include "SurfaceCache.h"
|
2008-08-05 20:02:43 +00:00
|
|
|
#include "nsCSSRuleProcessor.h"
|
2007-10-08 23:11:01 +00:00
|
|
|
#include "nsRuleNode.h"
|
2008-11-25 23:22:38 +00:00
|
|
|
#include "gfxPlatform.h"
|
|
|
|
#include "nsCSSRules.h"
|
|
|
|
#include "nsFontFaceLoader.h"
|
2016-01-12 22:54:53 +00:00
|
|
|
#include "mozilla/EffectCompositor.h"
|
2014-03-17 06:56:53 +00:00
|
|
|
#include "mozilla/EventListenerManager.h"
|
2009-04-21 23:53:52 +00:00
|
|
|
#include "prenv.h"
|
2014-09-24 04:33:00 +00:00
|
|
|
#include "nsPluginFrame.h"
|
2009-10-08 03:22:42 +00:00
|
|
|
#include "nsTransitionManager.h"
|
2011-04-12 06:18:44 +00:00
|
|
|
#include "nsAnimationManager.h"
|
2014-06-12 01:11:00 +00:00
|
|
|
#include "CounterStyleManager.h"
|
2013-06-23 12:03:39 +00:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2010-05-05 18:18:05 +00:00
|
|
|
#include "mozilla/dom/Element.h"
|
2012-08-27 14:13:02 +00:00
|
|
|
#include "nsIMessageManager.h"
|
2013-12-16 14:03:19 +00:00
|
|
|
#include "mozilla/dom/MediaQueryList.h"
|
2009-01-15 04:38:07 +00:00
|
|
|
#include "nsSMILAnimationController.h"
|
2012-08-13 22:04:19 +00:00
|
|
|
#include "mozilla/css/ImageLoader.h"
|
2014-05-23 14:36:50 +00:00
|
|
|
#include "mozilla/dom/PBrowserParent.h"
|
2012-09-05 16:23:45 +00:00
|
|
|
#include "mozilla/dom/TabChild.h"
|
2014-05-23 14:36:50 +00:00
|
|
|
#include "mozilla/dom/TabParent.h"
|
2013-08-14 11:29:51 +00:00
|
|
|
#include "nsRefreshDriver.h"
|
2013-08-14 11:33:03 +00:00
|
|
|
#include "Layers.h"
|
2015-10-22 20:04:35 +00:00
|
|
|
#include "LayerUserData.h"
|
2015-01-29 19:41:54 +00:00
|
|
|
#include "ClientLayerManager.h"
|
2015-08-12 11:39:31 +00:00
|
|
|
#include "mozilla/dom/NotifyPaintEvent.h"
|
2014-03-04 17:26:33 +00:00
|
|
|
#include "gfxPrefs.h"
|
2014-05-23 14:36:50 +00:00
|
|
|
#include "nsIDOMChromeWindow.h"
|
|
|
|
#include "nsFrameLoader.h"
|
2014-10-02 02:32:05 +00:00
|
|
|
#include "mozilla/dom/FontFaceSet.h"
|
2004-04-30 04:06:30 +00:00
|
|
|
#include "nsContentUtils.h"
|
2010-03-01 14:47:27 +00:00
|
|
|
#include "nsPIWindowRoot.h"
|
2011-05-25 06:31:59 +00:00
|
|
|
#include "mozilla/Preferences.h"
|
2014-12-22 16:35:54 +00:00
|
|
|
#include "gfxTextRun.h"
|
2015-03-06 08:44:23 +00:00
|
|
|
#include "nsFontFaceUtils.h"
|
2015-06-16 01:34:48 +00:00
|
|
|
#include "nsLayoutStylesheetCache.h"
|
2016-02-24 07:01:12 +00:00
|
|
|
#include "mozilla/StyleSheetHandle.h"
|
|
|
|
#include "mozilla/StyleSheetHandleInlines.h"
|
2004-04-30 04:06:30 +00:00
|
|
|
|
2015-05-13 05:11:25 +00:00
|
|
|
#if defined(MOZ_WIDGET_GTK)
|
|
|
|
#include "gfxPlatformGtk.h" // xxx - for UseFcFontList
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2001-11-14 11:21:54 +00:00
|
|
|
// Needed for Start/Stop of Image Animation
|
|
|
|
#include "imgIContainer.h"
|
2003-03-19 03:47:09 +00:00
|
|
|
#include "nsIImageLoadingContent.h"
|
2001-11-14 11:21:54 +00:00
|
|
|
|
2011-10-11 21:29:12 +00:00
|
|
|
#include "nsCSSParser.h"
|
2013-10-07 23:15:59 +00:00
|
|
|
#include "nsBidiUtils.h"
|
|
|
|
#include "nsServiceManagerUtils.h"
|
2011-10-11 21:29:12 +00:00
|
|
|
|
2014-03-07 04:02:59 +00:00
|
|
|
#include "URL.h"
|
|
|
|
|
2011-04-11 20:57:29 +00:00
|
|
|
using namespace mozilla;
|
2010-04-30 13:12:05 +00:00
|
|
|
using namespace mozilla::dom;
|
2012-11-10 15:45:52 +00:00
|
|
|
using namespace mozilla::layers;
|
2009-10-02 18:05:32 +00:00
|
|
|
|
2012-08-29 05:47:18 +00:00
|
|
|
uint8_t gNotifySubDocInvalidationData;
|
|
|
|
|
2013-08-14 11:33:03 +00:00
|
|
|
/**
|
|
|
|
* Layer UserData for ContainerLayers that want to be notified
|
|
|
|
* of local invalidations of them and their descendant layers.
|
|
|
|
* Pass a callback to ComputeDifferences to have these called.
|
|
|
|
*/
|
|
|
|
class ContainerLayerPresContext : public LayerUserData {
|
|
|
|
public:
|
|
|
|
nsPresContext* mPresContext;
|
|
|
|
};
|
|
|
|
|
2012-01-11 20:58:44 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
class CharSetChangingRunnable : public nsRunnable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CharSetChangingRunnable(nsPresContext* aPresContext,
|
|
|
|
const nsCString& aCharSet)
|
|
|
|
: mPresContext(aPresContext),
|
|
|
|
mCharSet(aCharSet)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD Run()
|
|
|
|
{
|
|
|
|
mPresContext->DoChangeCharSet(mCharSet);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<nsPresContext> mPresContext;
|
2012-01-11 20:58:44 +00:00
|
|
|
nsCString mCharSet;
|
|
|
|
};
|
|
|
|
|
2015-07-13 15:25:42 +00:00
|
|
|
} // namespace
|
2012-01-11 20:58:44 +00:00
|
|
|
|
2012-06-06 07:36:38 +00:00
|
|
|
nscolor
|
|
|
|
nsPresContext::MakeColorPref(const nsString& aColor)
|
2001-05-08 01:40:09 +00:00
|
|
|
{
|
2011-10-11 21:29:12 +00:00
|
|
|
nsCSSParser parser;
|
2012-06-06 07:36:38 +00:00
|
|
|
nsCSSValue value;
|
2012-07-30 14:20:58 +00:00
|
|
|
if (!parser.ParseColorString(aColor, nullptr, 0, value)) {
|
2011-10-11 21:29:12 +00:00
|
|
|
// Any better choices?
|
2012-06-06 07:36:38 +00:00
|
|
|
return NS_RGB(0, 0, 0);
|
2011-10-11 21:29:12 +00:00
|
|
|
}
|
2012-06-06 07:36:38 +00:00
|
|
|
|
|
|
|
nscolor color;
|
2012-07-30 14:20:58 +00:00
|
|
|
return nsRuleNode::ComputeColor(value, this, nullptr, color)
|
2012-06-06 07:36:38 +00:00
|
|
|
? color
|
|
|
|
: NS_RGB(0, 0, 0);
|
2001-05-08 01:40:09 +00:00
|
|
|
}
|
|
|
|
|
2012-08-29 05:47:18 +00:00
|
|
|
bool
|
2014-03-20 06:49:25 +00:00
|
|
|
nsPresContext::IsDOMPaintEventPending()
|
2012-08-29 05:47:18 +00:00
|
|
|
{
|
2012-10-19 04:50:34 +00:00
|
|
|
if (mFireAfterPaintEvents) {
|
|
|
|
return true;
|
2012-08-29 05:47:18 +00:00
|
|
|
}
|
2016-01-22 01:09:04 +00:00
|
|
|
nsRootPresContext* drpc = GetRootPresContext();
|
2014-11-27 11:21:48 +00:00
|
|
|
if (drpc && drpc->mRefreshDriver->ViewManagerFlushIsPending()) {
|
2012-08-29 05:47:18 +00:00
|
|
|
// Since we're promising that there will be a MozAfterPaint event
|
|
|
|
// fired, we record an empty invalidation in case display list
|
|
|
|
// invalidation doesn't invalidate anything further.
|
|
|
|
NotifyInvalidation(nsRect(0, 0, 0, 0), 0);
|
2012-10-19 04:50:34 +00:00
|
|
|
NS_ASSERTION(mFireAfterPaintEvents, "Why aren't we planning to fire the event?");
|
2012-08-29 05:47:18 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-12-10 23:10:01 +00:00
|
|
|
void
|
2004-07-31 23:15:21 +00:00
|
|
|
nsPresContext::PrefChangedCallback(const char* aPrefName, void* instance_data)
|
2002-12-11 05:11:02 +00:00
|
|
|
{
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<nsPresContext> presContext =
|
2013-11-17 20:49:52 +00:00
|
|
|
static_cast<nsPresContext*>(instance_data);
|
2002-12-11 05:11:02 +00:00
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
NS_ASSERTION(nullptr != presContext, "bad instance data");
|
|
|
|
if (nullptr != presContext) {
|
2002-12-11 05:11:02 +00:00
|
|
|
presContext->PreferenceChanged(aPrefName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-08-23 23:52:16 +00:00
|
|
|
void
|
|
|
|
nsPresContext::PrefChangedUpdateTimerCallback(nsITimer *aTimer, void *aClosure)
|
|
|
|
{
|
|
|
|
nsPresContext* presContext = (nsPresContext*)aClosure;
|
2012-07-30 14:20:58 +00:00
|
|
|
NS_ASSERTION(presContext != nullptr, "bad instance data");
|
2005-08-23 23:52:16 +00:00
|
|
|
if (presContext)
|
|
|
|
presContext->UpdateAfterPreferencesChanged();
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
static bool
|
2004-07-29 19:41:39 +00:00
|
|
|
IsVisualCharset(const nsCString& aCharset)
|
2001-03-09 03:13:03 +00:00
|
|
|
{
|
2012-10-10 10:32:37 +00:00
|
|
|
if (aCharset.LowerCaseEqualsLiteral("ibm862") // Hebrew
|
2004-06-17 00:13:25 +00:00
|
|
|
|| aCharset.LowerCaseEqualsLiteral("iso-8859-8") ) { // Hebrew
|
2011-10-17 14:59:28 +00:00
|
|
|
return true; // visual text type
|
2001-03-09 03:13:03 +00:00
|
|
|
}
|
|
|
|
else {
|
2011-10-17 14:59:28 +00:00
|
|
|
return false; // logical text type
|
2001-03-09 03:13:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-07-31 23:15:21 +00:00
|
|
|
// NOTE! nsPresContext::operator new() zeroes out all members, so don't
|
2004-04-30 04:06:30 +00:00
|
|
|
// bother initializing members to 0.
|
1998-04-13 20:24:54 +00:00
|
|
|
|
2006-05-19 10:26:44 +00:00
|
|
|
nsPresContext::nsPresContext(nsIDocument* aDocument, nsPresContextType aType)
|
2014-02-25 19:07:47 +00:00
|
|
|
: mType(aType), mDocument(aDocument), mBaseMinFontSize(0),
|
2015-03-10 14:28:23 +00:00
|
|
|
mTextZoom(1.0), mFullZoom(1.0),
|
|
|
|
mLastFontInflationScreenSize(gfxSize(-1.0, -1.0)),
|
2012-05-05 13:25:45 +00:00
|
|
|
mPageSize(-1, -1), mPPScale(1.0f),
|
2014-02-04 01:54:22 +00:00
|
|
|
mViewportStyleScrollbar(NS_STYLE_OVERFLOW_AUTO, NS_STYLE_OVERFLOW_AUTO),
|
2012-08-29 05:48:44 +00:00
|
|
|
mImageAnimationModePref(imgIContainer::kNormalAnimMode),
|
2013-07-22 15:51:38 +00:00
|
|
|
mAllInvalidated(false),
|
|
|
|
mPaintFlashing(false), mPaintFlashingInitialized(false)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
2004-07-31 23:15:21 +00:00
|
|
|
// NOTE! nsPresContext::operator new() zeroes out all members, so don't
|
2004-04-30 04:06:30 +00:00
|
|
|
// bother initializing members to 0.
|
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
mDoScaledTwips = true;
|
2000-09-21 01:20:00 +00:00
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
SetBackgroundImageDraw(true); // always draw the background
|
|
|
|
SetBackgroundColorDraw(true);
|
2001-12-11 05:57:37 +00:00
|
|
|
|
2004-01-31 22:41:40 +00:00
|
|
|
mBackgroundColor = NS_RGB(0xFF, 0xFF, 0xFF);
|
2014-03-20 06:49:25 +00:00
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
mUseDocumentColors = true;
|
|
|
|
mUseDocumentFonts = true;
|
2000-10-11 08:33:01 +00:00
|
|
|
|
2001-09-27 18:34:30 +00:00
|
|
|
// the minimum font-size is unconstrained by default
|
|
|
|
|
2003-10-15 01:56:12 +00:00
|
|
|
mLinkColor = NS_RGB(0x00, 0x00, 0xEE);
|
|
|
|
mActiveLinkColor = NS_RGB(0xEE, 0x00, 0x00);
|
|
|
|
mVisitedLinkColor = NS_RGB(0x55, 0x1A, 0x8B);
|
2011-10-17 14:59:28 +00:00
|
|
|
mUnderlineLinks = true;
|
|
|
|
mSendAfterPaintToContent = false;
|
2000-10-11 08:33:01 +00:00
|
|
|
|
2001-04-09 22:17:11 +00:00
|
|
|
mFocusTextColor = mDefaultColor;
|
2004-01-31 22:41:40 +00:00
|
|
|
mFocusBackgroundColor = mBackgroundColor;
|
2001-04-09 22:17:11 +00:00
|
|
|
mFocusRingWidth = 1;
|
|
|
|
|
2011-06-01 11:43:31 +00:00
|
|
|
mBodyTextColor = mDefaultColor;
|
|
|
|
|
2004-07-29 19:41:39 +00:00
|
|
|
if (aType == eContext_Galley) {
|
2006-12-26 17:47:52 +00:00
|
|
|
mMedium = nsGkAtoms::screen;
|
2004-07-29 19:41:39 +00:00
|
|
|
} else {
|
2006-12-26 17:47:52 +00:00
|
|
|
mMedium = nsGkAtoms::print;
|
2011-10-17 14:59:28 +00:00
|
|
|
mPaginated = true;
|
2004-07-29 19:41:39 +00:00
|
|
|
}
|
2013-07-17 15:39:19 +00:00
|
|
|
mMediaEmulated = mMedium;
|
2006-04-01 01:19:28 +00:00
|
|
|
|
|
|
|
if (!IsDynamic()) {
|
|
|
|
mImageAnimationMode = imgIContainer::kDontAnimMode;
|
2011-10-17 14:59:28 +00:00
|
|
|
mNeverAnimate = true;
|
2006-04-01 01:19:28 +00:00
|
|
|
} else {
|
|
|
|
mImageAnimationMode = imgIContainer::kNormalAnimMode;
|
2011-10-17 14:59:28 +00:00
|
|
|
mNeverAnimate = false;
|
2006-04-01 01:19:28 +00:00
|
|
|
}
|
2006-05-19 10:26:44 +00:00
|
|
|
NS_ASSERTION(mDocument, "Null document");
|
2011-04-22 03:17:31 +00:00
|
|
|
|
2014-06-12 01:12:00 +00:00
|
|
|
mCounterStylesDirty = true;
|
|
|
|
|
2013-11-25 04:59:56 +00:00
|
|
|
// if text perf logging enabled, init stats struct
|
2015-10-29 22:58:24 +00:00
|
|
|
LogModule* log = gfxPlatform::GetLog(eGfxLog_textperf);
|
2015-06-03 22:25:57 +00:00
|
|
|
if (MOZ_LOG_TEST(log, LogLevel::Warning)) {
|
2013-11-25 04:59:56 +00:00
|
|
|
mTextPerf = new gfxTextPerfMetrics();
|
|
|
|
}
|
2014-12-22 16:35:54 +00:00
|
|
|
|
|
|
|
if (Preferences::GetBool(GFX_MISSING_FONTS_NOTIFY_PREF)) {
|
|
|
|
mMissingFonts = new gfxMissingFontRecorder();
|
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
2014-10-29 20:24:02 +00:00
|
|
|
void
|
|
|
|
nsPresContext::Destroy()
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
2003-06-19 18:16:53 +00:00
|
|
|
if (mEventManager) {
|
2006-04-11 16:37:58 +00:00
|
|
|
// unclear if these are needed, but can't hurt
|
|
|
|
mEventManager->NotifyDestroyPresContext(this);
|
2012-07-30 14:20:58 +00:00
|
|
|
mEventManager->SetPresContext(nullptr);
|
2014-10-29 20:24:02 +00:00
|
|
|
mEventManager = nullptr;
|
2003-06-19 18:16:53 +00:00
|
|
|
}
|
1998-11-18 05:25:26 +00:00
|
|
|
|
2005-08-23 23:52:16 +00:00
|
|
|
if (mPrefChangedTimer)
|
|
|
|
{
|
|
|
|
mPrefChangedTimer->Cancel();
|
2012-07-30 14:20:58 +00:00
|
|
|
mPrefChangedTimer = nullptr;
|
2005-08-23 23:52:16 +00:00
|
|
|
}
|
|
|
|
|
2002-12-11 05:11:02 +00:00
|
|
|
// Unregister preference callbacks
|
2011-05-28 23:42:57 +00:00
|
|
|
Preferences::UnregisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"font.",
|
|
|
|
this);
|
|
|
|
Preferences::UnregisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"browser.display.",
|
|
|
|
this);
|
|
|
|
Preferences::UnregisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"browser.underline_anchors",
|
|
|
|
this);
|
|
|
|
Preferences::UnregisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"browser.anchor_color",
|
|
|
|
this);
|
|
|
|
Preferences::UnregisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"browser.active_color",
|
|
|
|
this);
|
|
|
|
Preferences::UnregisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"browser.visited_color",
|
|
|
|
this);
|
|
|
|
Preferences::UnregisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"image.animation_mode",
|
|
|
|
this);
|
|
|
|
Preferences::UnregisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"bidi.",
|
|
|
|
this);
|
|
|
|
Preferences::UnregisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"dom.send_after_paint_to_content",
|
|
|
|
this);
|
|
|
|
Preferences::UnregisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"gfx.font_rendering.",
|
|
|
|
this);
|
|
|
|
Preferences::UnregisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"layout.css.dpi",
|
|
|
|
this);
|
|
|
|
Preferences::UnregisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"layout.css.devPixelsPerPx",
|
|
|
|
this);
|
2013-07-22 15:51:38 +00:00
|
|
|
Preferences::UnregisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"nglayout.debug.paint_flashing",
|
|
|
|
this);
|
|
|
|
Preferences::UnregisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"nglayout.debug.paint_flashing_chrome",
|
|
|
|
this);
|
2014-10-29 20:24:02 +00:00
|
|
|
|
|
|
|
// Disconnect the refresh driver *after* the transition manager, which
|
|
|
|
// needs it.
|
|
|
|
if (mRefreshDriver && mRefreshDriver->PresContext() == this) {
|
|
|
|
mRefreshDriver->Disconnect();
|
|
|
|
mRefreshDriver = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsPresContext::~nsPresContext()
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(!mShell, "Presshell forgot to clear our mShell pointer");
|
|
|
|
SetShell(nullptr);
|
|
|
|
|
|
|
|
Destroy();
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
2007-08-10 21:25:24 +00:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsPresContext)
|
2010-03-25 13:17:11 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
2007-08-10 21:25:24 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIObserver)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsPresContext)
|
2013-07-09 17:30:58 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE_WITH_LAST_RELEASE(nsPresContext, LastRelease())
|
|
|
|
|
|
|
|
void
|
|
|
|
nsPresContext::LastRelease()
|
|
|
|
{
|
|
|
|
if (IsRoot()) {
|
|
|
|
static_cast<nsRootPresContext*>(this)->CancelDidPaintTimer();
|
|
|
|
}
|
2014-12-22 16:35:54 +00:00
|
|
|
if (mMissingFonts) {
|
|
|
|
mMissingFonts->Clear();
|
|
|
|
}
|
2013-07-09 17:30:58 +00:00
|
|
|
}
|
2007-08-10 21:25:24 +00:00
|
|
|
|
2013-08-02 01:29:05 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(nsPresContext)
|
|
|
|
|
2007-08-10 21:25:24 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsPresContext)
|
2015-07-29 01:57:39 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mAnimationManager);
|
2012-11-15 07:32:40 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDocument);
|
2011-04-17 01:22:42 +00:00
|
|
|
// NS_IMPL_CYCLE_COLLECTION_TRAVERSE_RAWPTR(mDeviceContext); // not xpcom
|
2016-01-12 22:54:53 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mEffectCompositor);
|
2012-11-15 07:32:40 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mEventManager);
|
2010-02-24 17:57:44 +00:00
|
|
|
// NS_IMPL_CYCLE_COLLECTION_TRAVERSE_RAWPTR(mLanguage); // an atom
|
2007-08-10 21:25:24 +00:00
|
|
|
|
2012-11-15 07:32:40 +00:00
|
|
|
// NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mTheme); // a service
|
|
|
|
// NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mLangService); // a service
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mPrintSettings);
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mPrefChangedTimer);
|
2007-08-10 21:25:24 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsPresContext)
|
2015-07-29 01:57:39 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mAnimationManager);
|
2012-11-15 07:32:40 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mDocument);
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mDeviceContext); // worth bothering?
|
2016-01-12 22:54:53 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mEffectCompositor);
|
2010-02-24 17:57:44 +00:00
|
|
|
// NS_RELEASE(tmp->mLanguage); // an atom
|
2012-11-15 07:32:40 +00:00
|
|
|
// NS_IMPL_CYCLE_COLLECTION_UNLINK(mTheme); // a service
|
|
|
|
// NS_IMPL_CYCLE_COLLECTION_UNLINK(mLangService); // a service
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mPrintSettings);
|
2014-10-29 20:24:02 +00:00
|
|
|
|
|
|
|
tmp->Destroy();
|
2007-08-10 21:25:24 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
1998-04-13 20:24:54 +00:00
|
|
|
|
2001-09-27 18:34:30 +00:00
|
|
|
#define MAKE_FONT_PREF_KEY(_pref, _s0, _s1) \
|
|
|
|
_pref.Assign(_s0); \
|
|
|
|
_pref.Append(_s1);
|
|
|
|
|
|
|
|
static const char* const kGenericFont[] = {
|
|
|
|
".variable.",
|
|
|
|
".fixed.",
|
2014-03-20 06:49:25 +00:00
|
|
|
".serif.",
|
|
|
|
".sans-serif.",
|
2001-09-27 18:34:30 +00:00
|
|
|
".monospace.",
|
|
|
|
".cursive.",
|
|
|
|
".fantasy."
|
|
|
|
};
|
|
|
|
|
2009-02-26 20:02:00 +00:00
|
|
|
// whether no native theme service exists;
|
|
|
|
// if this gets set to true, we'll stop asking for it.
|
2011-09-29 06:19:26 +00:00
|
|
|
static bool sNoTheme = false;
|
2009-02-26 20:02:00 +00:00
|
|
|
|
2006-09-12 04:36:03 +00:00
|
|
|
// Set to true when LookAndFeelChanged needs to be called. This is used
|
|
|
|
// because the look and feel is a service, so there's no need to notify it from
|
|
|
|
// more than one prescontext.
|
2011-09-29 06:19:26 +00:00
|
|
|
static bool sLookAndFeelChanged;
|
2006-09-12 04:36:03 +00:00
|
|
|
|
|
|
|
// Set to true when ThemeChanged needs to be called on mTheme. This is used
|
|
|
|
// because mTheme is a service, so there's no need to notify it from more than
|
|
|
|
// one prescontext.
|
2011-09-29 06:19:26 +00:00
|
|
|
static bool sThemeChanged;
|
2006-09-12 04:36:03 +00:00
|
|
|
|
2012-01-25 23:52:26 +00:00
|
|
|
const nsPresContext::LangGroupFontPrefs*
|
|
|
|
nsPresContext::GetFontPrefsForLang(nsIAtom *aLanguage) const
|
2000-01-12 16:10:48 +00:00
|
|
|
{
|
2012-01-25 23:52:26 +00:00
|
|
|
// Get language group for aLanguage:
|
|
|
|
|
2012-11-20 20:59:36 +00:00
|
|
|
nsresult rv = NS_OK;
|
2012-07-30 14:20:58 +00:00
|
|
|
nsIAtom *langGroupAtom = nullptr;
|
2012-01-25 23:52:26 +00:00
|
|
|
if (!aLanguage) {
|
|
|
|
aLanguage = mLanguage;
|
|
|
|
}
|
|
|
|
if (aLanguage && mLangService) {
|
|
|
|
langGroupAtom = mLangService->GetLanguageGroup(aLanguage, &rv);
|
|
|
|
}
|
|
|
|
if (NS_FAILED(rv) || !langGroupAtom) {
|
|
|
|
langGroupAtom = nsGkAtoms::x_western; // Assume x-western is safe...
|
|
|
|
}
|
|
|
|
|
|
|
|
// Look for cached prefs for this lang group.
|
|
|
|
// Most documents will only use one (or very few) language groups. Rather
|
|
|
|
// than have the overhead of a hash lookup, we simply look along what will
|
|
|
|
// typically be a very short (usually of length 1) linked list. There are 31
|
|
|
|
// language groups, so in the worst case scenario we'll need to traverse 31
|
|
|
|
// link items.
|
|
|
|
|
|
|
|
LangGroupFontPrefs *prefs =
|
|
|
|
const_cast<LangGroupFontPrefs*>(&mLangGroupFontPrefs);
|
|
|
|
if (prefs->mLangGroup) { // if initialized
|
2012-08-22 15:56:38 +00:00
|
|
|
DebugOnly<uint32_t> count = 0;
|
2012-01-25 23:52:26 +00:00
|
|
|
for (;;) {
|
|
|
|
NS_ASSERTION(++count < 35, "Lang group count exceeded!!!");
|
|
|
|
if (prefs->mLangGroup == langGroupAtom) {
|
|
|
|
return prefs;
|
|
|
|
}
|
|
|
|
if (!prefs->mNext) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
prefs = prefs->mNext;
|
|
|
|
}
|
|
|
|
|
|
|
|
// nothing cached, so go on and fetch the prefs for this lang group:
|
|
|
|
prefs = prefs->mNext = new LangGroupFontPrefs;
|
|
|
|
}
|
|
|
|
|
|
|
|
prefs->mLangGroup = langGroupAtom;
|
|
|
|
|
2001-09-27 18:34:30 +00:00
|
|
|
/* Fetch the font prefs to be used -- see bug 61883 for details.
|
|
|
|
Not all prefs are needed upfront. Some are fallback prefs intended
|
|
|
|
for the GFX font sub-system...
|
|
|
|
|
|
|
|
1) unit : assumed to be the same for all language groups -------------
|
|
|
|
font.size.unit = px | pt XXX could be folded in the size... bug 90440
|
|
|
|
|
|
|
|
2) attributes for generic fonts --------------------------------------
|
2012-01-25 23:52:26 +00:00
|
|
|
font.default.[langGroup] = serif | sans-serif - fallback generic font
|
2001-09-27 18:34:30 +00:00
|
|
|
font.name.[generic].[langGroup] = current user' selected font on the pref dialog
|
|
|
|
font.name-list.[generic].[langGroup] = fontname1, fontname2, ... [factory pre-built list]
|
|
|
|
font.size.[generic].[langGroup] = integer - settable by the user
|
|
|
|
font.size-adjust.[generic].[langGroup] = "float" - settable by the user
|
|
|
|
font.minimum-size.[langGroup] = integer - settable by the user
|
|
|
|
*/
|
|
|
|
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString langGroup;
|
2012-01-25 23:52:26 +00:00
|
|
|
langGroupAtom->ToUTF8String(langGroup);
|
|
|
|
|
|
|
|
prefs->mDefaultVariableFont.size = CSSPixelsToAppUnits(16);
|
|
|
|
prefs->mDefaultFixedFont.size = CSSPixelsToAppUnits(13);
|
2001-09-27 18:34:30 +00:00
|
|
|
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString pref;
|
2001-09-27 18:34:30 +00:00
|
|
|
|
|
|
|
// get the current applicable font-size unit
|
|
|
|
enum {eUnit_unknown = -1, eUnit_px, eUnit_pt};
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t unit = eUnit_px;
|
2004-04-30 04:06:30 +00:00
|
|
|
|
|
|
|
nsAdoptingCString cvalue =
|
2011-05-28 07:03:00 +00:00
|
|
|
Preferences::GetCString("font.size.unit");
|
2004-04-30 04:06:30 +00:00
|
|
|
|
|
|
|
if (!cvalue.IsEmpty()) {
|
2014-05-22 03:48:51 +00:00
|
|
|
if (cvalue.EqualsLiteral("px")) {
|
2001-09-27 18:34:30 +00:00
|
|
|
unit = eUnit_px;
|
2000-01-12 16:10:48 +00:00
|
|
|
}
|
2014-05-22 03:48:51 +00:00
|
|
|
else if (cvalue.EqualsLiteral("pt")) {
|
2001-09-27 18:34:30 +00:00
|
|
|
unit = eUnit_pt;
|
|
|
|
}
|
|
|
|
else {
|
2012-01-25 23:52:26 +00:00
|
|
|
// XXX should really send this warning to the user (Error Console?).
|
|
|
|
// And just default to unit = eUnit_px?
|
2001-09-27 18:34:30 +00:00
|
|
|
NS_WARNING("unexpected font-size unit -- expected: 'px' or 'pt'");
|
|
|
|
unit = eUnit_unknown;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// get font.minimum-size.[langGroup]
|
2003-06-24 01:46:50 +00:00
|
|
|
|
2012-01-25 23:52:26 +00:00
|
|
|
MAKE_FONT_PREF_KEY(pref, "font.minimum-size.", langGroup);
|
2003-06-24 01:46:50 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t size = Preferences::GetInt(pref.get());
|
2006-08-08 16:43:20 +00:00
|
|
|
if (unit == eUnit_px) {
|
2012-01-25 23:52:26 +00:00
|
|
|
prefs->mMinimumFontSize = CSSPixelsToAppUnits(size);
|
2006-08-08 16:43:20 +00:00
|
|
|
}
|
|
|
|
else if (unit == eUnit_pt) {
|
2012-01-25 23:52:26 +00:00
|
|
|
prefs->mMinimumFontSize = CSSPointsToAppUnits(size);
|
2001-09-27 18:34:30 +00:00
|
|
|
}
|
|
|
|
|
2011-12-20 03:46:39 +00:00
|
|
|
nsFont* fontTypes[] = {
|
2012-01-25 23:52:26 +00:00
|
|
|
&prefs->mDefaultVariableFont,
|
|
|
|
&prefs->mDefaultFixedFont,
|
|
|
|
&prefs->mDefaultSerifFont,
|
|
|
|
&prefs->mDefaultSansSerifFont,
|
|
|
|
&prefs->mDefaultMonospaceFont,
|
|
|
|
&prefs->mDefaultCursiveFont,
|
|
|
|
&prefs->mDefaultFantasyFont
|
2011-12-20 03:46:39 +00:00
|
|
|
};
|
2014-01-30 18:26:54 +00:00
|
|
|
static_assert(MOZ_ARRAY_LENGTH(fontTypes) == eDefaultFont_COUNT,
|
2013-07-18 17:59:53 +00:00
|
|
|
"FontTypes array count is not correct");
|
2011-12-20 03:46:39 +00:00
|
|
|
|
2012-01-25 23:52:26 +00:00
|
|
|
// Get attributes specific to each generic font. We do not get the user's
|
|
|
|
// generic-font-name-to-specific-family-name preferences because its the
|
|
|
|
// generic name that should be fed into the cascade. It is up to the GFX
|
|
|
|
// code to look up the font prefs to convert generic names to specific
|
|
|
|
// family names as necessary.
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString generic_dot_langGroup;
|
2012-08-22 15:56:38 +00:00
|
|
|
for (uint32_t eType = 0; eType < ArrayLength(fontTypes); ++eType) {
|
2001-09-27 18:34:30 +00:00
|
|
|
generic_dot_langGroup.Assign(kGenericFont[eType]);
|
2004-06-08 23:53:59 +00:00
|
|
|
generic_dot_langGroup.Append(langGroup);
|
2001-09-27 18:34:30 +00:00
|
|
|
|
2011-12-20 03:46:39 +00:00
|
|
|
nsFont* font = fontTypes[eType];
|
2001-09-27 18:34:30 +00:00
|
|
|
|
|
|
|
// set the default variable font (the other fonts are seen as 'generic' fonts
|
|
|
|
// in GFX and will be queried there when hunting for alternative fonts)
|
|
|
|
if (eType == eDefaultFont_Variable) {
|
2012-01-25 23:52:26 +00:00
|
|
|
MAKE_FONT_PREF_KEY(pref, "font.name.variable.", langGroup);
|
2004-04-30 04:06:30 +00:00
|
|
|
|
2011-05-28 07:03:00 +00:00
|
|
|
nsAdoptingString value = Preferences::GetString(pref.get());
|
2004-04-30 04:06:30 +00:00
|
|
|
if (!value.IsEmpty()) {
|
2014-06-06 06:09:23 +00:00
|
|
|
FontFamilyName defaultVariableName = FontFamilyName::Convert(value);
|
|
|
|
FontFamilyType defaultType = defaultVariableName.mType;
|
|
|
|
NS_ASSERTION(defaultType == eFamily_serif ||
|
|
|
|
defaultType == eFamily_sans_serif,
|
|
|
|
"default type must be serif or sans-serif");
|
|
|
|
prefs->mDefaultVariableFont.fontlist = FontFamilyList(defaultType);
|
2000-01-15 16:30:13 +00:00
|
|
|
}
|
2001-09-27 18:34:30 +00:00
|
|
|
else {
|
2005-01-23 23:58:32 +00:00
|
|
|
MAKE_FONT_PREF_KEY(pref, "font.default.", langGroup);
|
2011-05-28 07:03:00 +00:00
|
|
|
value = Preferences::GetString(pref.get());
|
2004-04-30 04:06:30 +00:00
|
|
|
if (!value.IsEmpty()) {
|
2014-06-06 06:09:23 +00:00
|
|
|
FontFamilyName defaultVariableName = FontFamilyName::Convert(value);
|
|
|
|
FontFamilyType defaultType = defaultVariableName.mType;
|
|
|
|
NS_ASSERTION(defaultType == eFamily_serif ||
|
|
|
|
defaultType == eFamily_sans_serif,
|
|
|
|
"default type must be serif or sans-serif");
|
|
|
|
prefs->mDefaultVariableFont.fontlist = FontFamilyList(defaultType);
|
2001-09-27 18:34:30 +00:00
|
|
|
}
|
2014-03-20 06:49:25 +00:00
|
|
|
}
|
2001-09-27 18:34:30 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (eType == eDefaultFont_Monospace) {
|
2014-03-20 06:49:25 +00:00
|
|
|
// This takes care of the confusion whereby people often expect "monospace"
|
2001-09-27 18:34:30 +00:00
|
|
|
// to have the same default font-size as "-moz-fixed" (this tentative
|
|
|
|
// size may be overwritten with the specific value for "monospace" when
|
|
|
|
// "font.size.monospace.[langGroup]" is read -- see below)
|
2012-01-25 23:52:26 +00:00
|
|
|
prefs->mDefaultMonospaceFont.size = prefs->mDefaultFixedFont.size;
|
2000-01-15 16:30:13 +00:00
|
|
|
}
|
2001-09-27 18:34:30 +00:00
|
|
|
else if (eType != eDefaultFont_Fixed) {
|
|
|
|
// all the other generic fonts are initialized with the size of the
|
|
|
|
// variable font, but their specific size can supersede later -- see below
|
2012-01-25 23:52:26 +00:00
|
|
|
font->size = prefs->mDefaultVariableFont.size;
|
2000-01-15 16:30:13 +00:00
|
|
|
}
|
2001-09-27 18:34:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Bug 84398: for spec purists, a different font-size only applies to the
|
|
|
|
// .variable. and .fixed. fonts and the other fonts should get |font-size-adjust|.
|
|
|
|
// The problem is that only GfxWin has the support for |font-size-adjust|. So for
|
|
|
|
// parity, we enable the ability to set a different font-size on all platforms.
|
|
|
|
|
|
|
|
// get font.size.[generic].[langGroup]
|
|
|
|
// size=0 means 'Auto', i.e., generic fonts retain the size of the variable font
|
|
|
|
MAKE_FONT_PREF_KEY(pref, "font.size", generic_dot_langGroup);
|
2011-05-25 06:32:00 +00:00
|
|
|
size = Preferences::GetInt(pref.get());
|
2004-04-30 04:06:30 +00:00
|
|
|
if (size > 0) {
|
2001-09-27 18:34:30 +00:00
|
|
|
if (unit == eUnit_px) {
|
2010-08-13 09:58:04 +00:00
|
|
|
font->size = CSSPixelsToAppUnits(size);
|
2000-01-15 16:30:13 +00:00
|
|
|
}
|
2001-09-27 18:34:30 +00:00
|
|
|
else if (unit == eUnit_pt) {
|
2010-08-13 09:58:04 +00:00
|
|
|
font->size = CSSPointsToAppUnits(size);
|
2000-01-15 16:30:13 +00:00
|
|
|
}
|
2000-01-12 16:10:48 +00:00
|
|
|
}
|
2001-09-27 18:34:30 +00:00
|
|
|
|
|
|
|
// get font.size-adjust.[generic].[langGroup]
|
|
|
|
// XXX only applicable on GFX ports that handle |font-size-adjust|
|
|
|
|
MAKE_FONT_PREF_KEY(pref, "font.size-adjust", generic_dot_langGroup);
|
2011-05-28 07:03:00 +00:00
|
|
|
cvalue = Preferences::GetCString(pref.get());
|
2004-04-30 04:06:30 +00:00
|
|
|
if (!cvalue.IsEmpty()) {
|
2001-09-27 18:34:30 +00:00
|
|
|
font->sizeAdjust = (float)atof(cvalue.get());
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG_rbs
|
|
|
|
printf("%s Family-list:%s size:%d sizeAdjust:%.2f\n",
|
2004-04-30 04:06:30 +00:00
|
|
|
generic_dot_langGroup.get(),
|
2006-02-03 14:18:39 +00:00
|
|
|
NS_ConvertUTF16toUTF8(font->name).get(), font->size,
|
2003-06-24 01:46:50 +00:00
|
|
|
font->sizeAdjust);
|
2001-09-27 18:34:30 +00:00
|
|
|
#endif
|
2000-01-12 16:10:48 +00:00
|
|
|
}
|
2012-01-25 23:52:26 +00:00
|
|
|
|
|
|
|
return prefs;
|
2000-01-12 16:10:48 +00:00
|
|
|
}
|
|
|
|
|
2001-10-16 23:59:25 +00:00
|
|
|
void
|
2004-07-31 23:15:21 +00:00
|
|
|
nsPresContext::GetDocumentColorPreferences()
|
2001-10-16 23:59:25 +00:00
|
|
|
{
|
2014-03-04 17:26:33 +00:00
|
|
|
// Make sure the preferences are initialized. In the normal run,
|
|
|
|
// they would already be, because gfxPlatform would have been created,
|
|
|
|
// but in some reference tests, that is not the case.
|
|
|
|
gfxPrefs::GetSingleton();
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t useAccessibilityTheme = 0;
|
2011-09-29 06:19:26 +00:00
|
|
|
bool usePrefColors = true;
|
2014-03-07 04:02:59 +00:00
|
|
|
bool isChromeDocShell = false;
|
2014-11-27 19:06:14 +00:00
|
|
|
static int32_t sDocumentColorsSetting;
|
|
|
|
static bool sDocumentColorsSettingPrefCached = false;
|
|
|
|
if (!sDocumentColorsSettingPrefCached) {
|
|
|
|
sDocumentColorsSettingPrefCached = true;
|
|
|
|
Preferences::AddIntVarCache(&sDocumentColorsSetting,
|
|
|
|
"browser.display.document_color_use",
|
|
|
|
0);
|
|
|
|
}
|
2014-03-07 04:02:59 +00:00
|
|
|
|
|
|
|
nsIDocument* doc = mDocument->GetDisplayDocument();
|
|
|
|
if (doc && doc->GetDocShell()) {
|
|
|
|
isChromeDocShell = nsIDocShellTreeItem::typeChrome ==
|
|
|
|
doc->GetDocShell()->ItemType();
|
|
|
|
} else {
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> docShell(mContainer);
|
|
|
|
if (docShell) {
|
|
|
|
isChromeDocShell = nsIDocShellTreeItem::typeChrome == docShell->ItemType();
|
2004-06-08 19:34:55 +00:00
|
|
|
}
|
2014-03-07 04:02:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
mIsChromeOriginImage = mDocument->IsBeingUsedAsImage() &&
|
|
|
|
IsChromeURI(mDocument->GetDocumentURI());
|
2004-06-08 19:34:55 +00:00
|
|
|
|
2014-03-07 04:02:59 +00:00
|
|
|
if (isChromeDocShell || mIsChromeOriginImage) {
|
|
|
|
usePrefColors = false;
|
|
|
|
} else {
|
|
|
|
useAccessibilityTheme =
|
|
|
|
LookAndFeel::GetInt(LookAndFeel::eIntID_UseAccessibilityTheme, 0);
|
|
|
|
usePrefColors = !useAccessibilityTheme;
|
2001-10-16 23:59:25 +00:00
|
|
|
}
|
|
|
|
if (usePrefColors) {
|
2004-04-30 04:06:30 +00:00
|
|
|
usePrefColors =
|
2011-09-29 06:19:26 +00:00
|
|
|
!Preferences::GetBool("browser.display.use_system_colors", false);
|
2001-10-16 23:59:25 +00:00
|
|
|
}
|
2004-04-30 04:06:30 +00:00
|
|
|
|
2001-10-16 23:59:25 +00:00
|
|
|
if (usePrefColors) {
|
2011-10-11 21:29:12 +00:00
|
|
|
nsAdoptingString colorStr =
|
|
|
|
Preferences::GetString("browser.display.foreground_color");
|
2004-04-30 04:06:30 +00:00
|
|
|
|
|
|
|
if (!colorStr.IsEmpty()) {
|
2001-10-16 23:59:25 +00:00
|
|
|
mDefaultColor = MakeColorPref(colorStr);
|
|
|
|
}
|
2004-04-30 04:06:30 +00:00
|
|
|
|
2011-10-11 21:29:12 +00:00
|
|
|
colorStr = Preferences::GetString("browser.display.background_color");
|
2004-04-30 04:06:30 +00:00
|
|
|
|
|
|
|
if (!colorStr.IsEmpty()) {
|
2004-01-31 22:41:40 +00:00
|
|
|
mBackgroundColor = MakeColorPref(colorStr);
|
2001-10-16 23:59:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2011-09-09 02:27:13 +00:00
|
|
|
mDefaultColor =
|
|
|
|
LookAndFeel::GetColor(LookAndFeel::eColorID_WindowForeground,
|
|
|
|
NS_RGB(0x00, 0x00, 0x00));
|
|
|
|
mBackgroundColor =
|
|
|
|
LookAndFeel::GetColor(LookAndFeel::eColorID_WindowBackground,
|
|
|
|
NS_RGB(0xFF, 0xFF, 0xFF));
|
2001-10-16 23:59:25 +00:00
|
|
|
}
|
|
|
|
|
2008-09-19 17:06:46 +00:00
|
|
|
// Wherever we got the default background color from, ensure it is
|
|
|
|
// opaque.
|
|
|
|
mBackgroundColor = NS_ComposeColors(NS_RGB(0xFF, 0xFF, 0xFF),
|
|
|
|
mBackgroundColor);
|
|
|
|
|
2014-11-27 19:06:14 +00:00
|
|
|
|
|
|
|
// Now deal with the pref:
|
|
|
|
// 0 = default: always, except in high contrast mode
|
|
|
|
// 1 = always
|
|
|
|
// 2 = never
|
2015-10-20 12:12:36 +00:00
|
|
|
if (sDocumentColorsSetting == 1 || mDocument->IsBeingUsedAsImage()) {
|
2014-11-27 19:06:14 +00:00
|
|
|
mUseDocumentColors = true;
|
|
|
|
} else if (sDocumentColorsSetting == 2) {
|
|
|
|
mUseDocumentColors = isChromeDocShell || mIsChromeOriginImage;
|
|
|
|
} else {
|
|
|
|
MOZ_ASSERT(!useAccessibilityTheme ||
|
|
|
|
!(isChromeDocShell || mIsChromeOriginImage),
|
|
|
|
"The accessibility theme should only be on for non-chrome");
|
|
|
|
mUseDocumentColors = !useAccessibilityTheme;
|
|
|
|
}
|
2001-10-16 23:59:25 +00:00
|
|
|
}
|
|
|
|
|
1998-11-06 16:16:01 +00:00
|
|
|
void
|
2004-07-31 23:15:21 +00:00
|
|
|
nsPresContext::GetUserPreferences()
|
1998-11-06 16:16:01 +00:00
|
|
|
{
|
2005-11-08 22:45:49 +00:00
|
|
|
if (!GetPresShell()) {
|
|
|
|
// No presshell means nothing to do here. We'll do this when we
|
|
|
|
// get a presshell.
|
|
|
|
return;
|
|
|
|
}
|
2008-02-08 19:52:46 +00:00
|
|
|
|
|
|
|
mAutoQualityMinFontSizePixelsPref =
|
2011-05-25 06:32:00 +00:00
|
|
|
Preferences::GetInt("browser.display.auto_quality_min_font_size");
|
2008-02-08 19:52:46 +00:00
|
|
|
|
2000-10-11 08:33:01 +00:00
|
|
|
// * document colors
|
2001-10-16 23:59:25 +00:00
|
|
|
GetDocumentColorPreferences();
|
2001-03-29 07:16:06 +00:00
|
|
|
|
2011-01-25 00:23:08 +00:00
|
|
|
mSendAfterPaintToContent =
|
2011-05-25 06:31:59 +00:00
|
|
|
Preferences::GetBool("dom.send_after_paint_to_content",
|
|
|
|
mSendAfterPaintToContent);
|
2011-01-25 00:23:08 +00:00
|
|
|
|
2000-10-11 08:33:01 +00:00
|
|
|
// * link colors
|
2004-04-30 04:06:30 +00:00
|
|
|
mUnderlineLinks =
|
2011-05-25 06:31:59 +00:00
|
|
|
Preferences::GetBool("browser.underline_anchors", mUnderlineLinks);
|
2004-04-30 04:06:30 +00:00
|
|
|
|
2011-10-11 21:29:12 +00:00
|
|
|
nsAdoptingString colorStr = Preferences::GetString("browser.anchor_color");
|
2004-04-30 04:06:30 +00:00
|
|
|
|
|
|
|
if (!colorStr.IsEmpty()) {
|
2002-12-11 05:11:02 +00:00
|
|
|
mLinkColor = MakeColorPref(colorStr);
|
2000-10-11 08:33:01 +00:00
|
|
|
}
|
2004-04-30 04:06:30 +00:00
|
|
|
|
2011-10-11 21:29:12 +00:00
|
|
|
colorStr = Preferences::GetString("browser.active_color");
|
2004-04-30 04:06:30 +00:00
|
|
|
|
|
|
|
if (!colorStr.IsEmpty()) {
|
2003-10-15 01:56:12 +00:00
|
|
|
mActiveLinkColor = MakeColorPref(colorStr);
|
|
|
|
}
|
2004-04-30 04:06:30 +00:00
|
|
|
|
2011-10-11 21:29:12 +00:00
|
|
|
colorStr = Preferences::GetString("browser.visited_color");
|
2004-04-30 04:06:30 +00:00
|
|
|
|
|
|
|
if (!colorStr.IsEmpty()) {
|
2002-12-11 05:11:02 +00:00
|
|
|
mVisitedLinkColor = MakeColorPref(colorStr);
|
2000-10-11 08:33:01 +00:00
|
|
|
}
|
|
|
|
|
2004-04-30 04:06:30 +00:00
|
|
|
mUseFocusColors =
|
2011-05-25 06:31:59 +00:00
|
|
|
Preferences::GetBool("browser.display.use_focus_colors", mUseFocusColors);
|
2001-04-09 22:17:11 +00:00
|
|
|
|
2004-04-30 04:06:30 +00:00
|
|
|
mFocusTextColor = mDefaultColor;
|
|
|
|
mFocusBackgroundColor = mBackgroundColor;
|
|
|
|
|
2011-10-11 21:29:12 +00:00
|
|
|
colorStr = Preferences::GetString("browser.display.focus_text_color");
|
2001-04-09 22:17:11 +00:00
|
|
|
|
2004-04-30 04:06:30 +00:00
|
|
|
if (!colorStr.IsEmpty()) {
|
|
|
|
mFocusTextColor = MakeColorPref(colorStr);
|
2001-04-09 22:17:11 +00:00
|
|
|
}
|
|
|
|
|
2011-10-11 21:29:12 +00:00
|
|
|
colorStr = Preferences::GetString("browser.display.focus_background_color");
|
2004-04-30 04:06:30 +00:00
|
|
|
|
|
|
|
if (!colorStr.IsEmpty()) {
|
|
|
|
mFocusBackgroundColor = MakeColorPref(colorStr);
|
2004-04-30 03:10:29 +00:00
|
|
|
}
|
2004-04-29 23:34:19 +00:00
|
|
|
|
2004-04-30 04:06:30 +00:00
|
|
|
mFocusRingWidth =
|
2011-05-25 06:32:00 +00:00
|
|
|
Preferences::GetInt("browser.display.focus_ring_width", mFocusRingWidth);
|
2004-04-30 04:06:30 +00:00
|
|
|
|
|
|
|
mFocusRingOnAnything =
|
2011-05-25 06:31:59 +00:00
|
|
|
Preferences::GetBool("browser.display.focus_ring_on_anything",
|
|
|
|
mFocusRingOnAnything);
|
2004-04-30 04:06:30 +00:00
|
|
|
|
2008-10-08 23:28:31 +00:00
|
|
|
mFocusRingStyle =
|
2011-05-25 06:32:00 +00:00
|
|
|
Preferences::GetInt("browser.display.focus_ring_style", mFocusRingStyle);
|
2011-06-01 11:43:31 +00:00
|
|
|
|
|
|
|
mBodyTextColor = mDefaultColor;
|
2014-03-20 06:49:25 +00:00
|
|
|
|
2000-10-11 08:33:01 +00:00
|
|
|
// * use fonts?
|
2004-04-30 04:06:30 +00:00
|
|
|
mUseDocumentFonts =
|
2011-05-25 06:32:00 +00:00
|
|
|
Preferences::GetInt("browser.display.use_document_fonts") != 0;
|
2004-04-30 04:06:30 +00:00
|
|
|
|
2011-05-25 06:32:00 +00:00
|
|
|
mPrefScrollbarSide = Preferences::GetInt("layout.scrollbar.side");
|
2006-03-26 00:48:03 +00:00
|
|
|
|
2012-01-25 23:52:26 +00:00
|
|
|
ResetCachedFontPrefs();
|
2001-01-09 23:55:27 +00:00
|
|
|
|
|
|
|
// * image animation
|
2004-04-30 04:06:30 +00:00
|
|
|
const nsAdoptingCString& animatePref =
|
2011-05-28 07:03:00 +00:00
|
|
|
Preferences::GetCString("image.animation_mode");
|
2014-05-22 03:48:51 +00:00
|
|
|
if (animatePref.EqualsLiteral("normal"))
|
2004-04-30 04:06:30 +00:00
|
|
|
mImageAnimationModePref = imgIContainer::kNormalAnimMode;
|
2014-05-22 03:48:51 +00:00
|
|
|
else if (animatePref.EqualsLiteral("none"))
|
2004-04-30 04:06:30 +00:00
|
|
|
mImageAnimationModePref = imgIContainer::kDontAnimMode;
|
2014-05-22 03:48:51 +00:00
|
|
|
else if (animatePref.EqualsLiteral("once"))
|
2004-04-30 04:06:30 +00:00
|
|
|
mImageAnimationModePref = imgIContainer::kLoopOnceAnimMode;
|
2008-02-08 19:52:46 +00:00
|
|
|
else // dynamic change to invalid value should act like it does initially
|
|
|
|
mImageAnimationModePref = imgIContainer::kNormalAnimMode;
|
2001-11-01 05:49:45 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t bidiOptions = GetBidi();
|
2005-11-08 22:45:49 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t prefInt =
|
2011-05-25 06:32:00 +00:00
|
|
|
Preferences::GetInt(IBMBIDI_TEXTDIRECTION_STR,
|
|
|
|
GET_BIDI_OPTION_DIRECTION(bidiOptions));
|
2005-11-08 22:45:49 +00:00
|
|
|
SET_BIDI_OPTION_DIRECTION(bidiOptions, prefInt);
|
2006-03-26 00:48:03 +00:00
|
|
|
mPrefBidiDirection = prefInt;
|
2004-04-30 04:06:30 +00:00
|
|
|
|
|
|
|
prefInt =
|
2011-05-25 06:32:00 +00:00
|
|
|
Preferences::GetInt(IBMBIDI_TEXTTYPE_STR,
|
|
|
|
GET_BIDI_OPTION_TEXTTYPE(bidiOptions));
|
2005-11-08 22:45:49 +00:00
|
|
|
SET_BIDI_OPTION_TEXTTYPE(bidiOptions, prefInt);
|
2004-04-30 04:06:30 +00:00
|
|
|
|
|
|
|
prefInt =
|
2011-05-25 06:32:00 +00:00
|
|
|
Preferences::GetInt(IBMBIDI_NUMERAL_STR,
|
|
|
|
GET_BIDI_OPTION_NUMERAL(bidiOptions));
|
2005-11-08 22:45:49 +00:00
|
|
|
SET_BIDI_OPTION_NUMERAL(bidiOptions, prefInt);
|
2004-04-30 04:06:30 +00:00
|
|
|
|
|
|
|
prefInt =
|
2011-05-25 06:32:00 +00:00
|
|
|
Preferences::GetInt(IBMBIDI_SUPPORTMODE_STR,
|
|
|
|
GET_BIDI_OPTION_SUPPORT(bidiOptions));
|
2005-11-08 22:45:49 +00:00
|
|
|
SET_BIDI_OPTION_SUPPORT(bidiOptions, prefInt);
|
2004-04-30 04:06:30 +00:00
|
|
|
|
2005-11-13 09:55:09 +00:00
|
|
|
// We don't need to force reflow: either we are initializing a new
|
|
|
|
// prescontext or we are being called from UpdateAfterPreferencesChanged()
|
|
|
|
// which triggers a reflow anyway.
|
2011-10-17 14:59:28 +00:00
|
|
|
SetBidi(bidiOptions, false);
|
1998-11-06 16:16:01 +00:00
|
|
|
}
|
|
|
|
|
2011-04-11 20:57:29 +00:00
|
|
|
void
|
2014-09-26 17:06:08 +00:00
|
|
|
nsPresContext::InvalidatePaintedLayers()
|
2011-04-11 20:57:29 +00:00
|
|
|
{
|
2011-06-09 07:13:05 +00:00
|
|
|
if (!mShell)
|
|
|
|
return;
|
2011-04-11 20:57:29 +00:00
|
|
|
nsIFrame* rootFrame = mShell->FrameManager()->GetRootFrame();
|
|
|
|
if (rootFrame) {
|
|
|
|
// FrameLayerBuilder caches invalidation-related values that depend on the
|
2014-09-26 17:06:08 +00:00
|
|
|
// appunits-per-dev-pixel ratio, so ensure that all PaintedLayer drawing
|
2011-04-11 20:57:29 +00:00
|
|
|
// is completely flushed.
|
2012-08-29 05:39:31 +00:00
|
|
|
rootFrame->InvalidateFrameSubtree();
|
2011-04-11 20:57:29 +00:00
|
|
|
}
|
2011-06-09 07:13:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsPresContext::AppUnitsPerDevPixelChanged()
|
|
|
|
{
|
2014-09-26 17:06:08 +00:00
|
|
|
InvalidatePaintedLayers();
|
2011-04-11 20:57:29 +00:00
|
|
|
|
2013-11-17 20:49:52 +00:00
|
|
|
if (mDeviceContext) {
|
|
|
|
mDeviceContext->FlushFontCache();
|
|
|
|
}
|
2011-04-11 20:57:29 +00:00
|
|
|
|
|
|
|
if (HasCachedStyleData()) {
|
2012-11-09 06:40:41 +00:00
|
|
|
// All cached style data must be recomputed.
|
2014-10-08 21:27:04 +00:00
|
|
|
MediaFeatureValuesChanged(eRestyle_ForceDescendants, NS_STYLE_HINT_REFLOW);
|
2011-04-11 20:57:29 +00:00
|
|
|
}
|
2013-02-07 00:19:01 +00:00
|
|
|
|
|
|
|
mCurAppUnitsPerDevPixel = AppUnitsPerDevPixel();
|
2011-04-11 20:57:29 +00:00
|
|
|
}
|
|
|
|
|
2000-04-02 21:52:17 +00:00
|
|
|
void
|
2004-07-31 23:15:21 +00:00
|
|
|
nsPresContext::PreferenceChanged(const char* aPrefName)
|
2000-04-02 21:52:17 +00:00
|
|
|
{
|
2008-02-08 19:52:46 +00:00
|
|
|
nsDependentCString prefName(aPrefName);
|
2009-05-17 22:09:53 +00:00
|
|
|
if (prefName.EqualsLiteral("layout.css.dpi") ||
|
|
|
|
prefName.EqualsLiteral("layout.css.devPixelsPerPx")) {
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t oldAppUnitsPerDevPixel = AppUnitsPerDevPixel();
|
2007-02-15 09:04:25 +00:00
|
|
|
if (mDeviceContext->CheckDPIChange() && mShell) {
|
2013-11-17 20:49:52 +00:00
|
|
|
nsCOMPtr<nsIPresShell> shell = mShell;
|
2007-12-17 04:59:59 +00:00
|
|
|
// Re-fetch the view manager's window dimensions in case there's a deferred
|
|
|
|
// resize which hasn't affected our mVisibleArea yet
|
|
|
|
nscoord oldWidthAppUnits, oldHeightAppUnits;
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<nsViewManager> vm = shell->GetViewManager();
|
2013-11-17 20:49:52 +00:00
|
|
|
if (!vm) {
|
|
|
|
return;
|
|
|
|
}
|
2007-12-17 04:59:59 +00:00
|
|
|
vm->GetWindowDimensions(&oldWidthAppUnits, &oldHeightAppUnits);
|
|
|
|
float oldWidthDevPixels = oldWidthAppUnits/oldAppUnitsPerDevPixel;
|
|
|
|
float oldHeightDevPixels = oldHeightAppUnits/oldAppUnitsPerDevPixel;
|
|
|
|
|
2007-12-12 02:27:00 +00:00
|
|
|
nscoord width = NSToCoordRound(oldWidthDevPixels*AppUnitsPerDevPixel());
|
|
|
|
nscoord height = NSToCoordRound(oldHeightDevPixels*AppUnitsPerDevPixel());
|
2007-02-15 09:04:25 +00:00
|
|
|
vm->SetWindowDimensions(width, height);
|
|
|
|
|
2011-04-11 20:57:29 +00:00
|
|
|
AppUnitsPerDevPixelChanged();
|
2007-02-15 09:04:25 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2014-12-22 16:35:54 +00:00
|
|
|
if (prefName.EqualsLiteral(GFX_MISSING_FONTS_NOTIFY_PREF)) {
|
|
|
|
if (Preferences::GetBool(GFX_MISSING_FONTS_NOTIFY_PREF)) {
|
|
|
|
if (!mMissingFonts) {
|
|
|
|
mMissingFonts = new gfxMissingFontRecorder();
|
|
|
|
// trigger reflow to detect missing fonts on the current page
|
|
|
|
mPrefChangePendingNeedsReflow = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (mMissingFonts) {
|
|
|
|
mMissingFonts->Clear();
|
|
|
|
}
|
|
|
|
mMissingFonts = nullptr;
|
|
|
|
}
|
|
|
|
}
|
2008-02-08 19:52:46 +00:00
|
|
|
if (StringBeginsWith(prefName, NS_LITERAL_CSTRING("font."))) {
|
|
|
|
// Changes to font family preferences don't change anything in the
|
|
|
|
// computed style data, so the style system won't generate a reflow
|
|
|
|
// hint for us. We need to do that manually.
|
|
|
|
|
|
|
|
// FIXME We could probably also handle changes to
|
|
|
|
// browser.display.auto_quality_min_font_size here, but that
|
|
|
|
// probably also requires clearing the text run cache, so don't
|
|
|
|
// bother (yet, anyway).
|
2011-10-17 14:59:28 +00:00
|
|
|
mPrefChangePendingNeedsReflow = true;
|
2007-07-26 09:47:43 +00:00
|
|
|
}
|
2008-12-18 20:12:53 +00:00
|
|
|
if (StringBeginsWith(prefName, NS_LITERAL_CSTRING("bidi."))) {
|
|
|
|
// Changes to bidi prefs need to trigger a reflow (see bug 443629)
|
2011-10-17 14:59:28 +00:00
|
|
|
mPrefChangePendingNeedsReflow = true;
|
2008-12-18 20:12:53 +00:00
|
|
|
|
|
|
|
// Changes to bidi.numeral also needs to empty the text run cache.
|
|
|
|
// This is handled in gfxTextRunWordCache.cpp.
|
|
|
|
}
|
2010-06-09 00:33:13 +00:00
|
|
|
if (StringBeginsWith(prefName, NS_LITERAL_CSTRING("gfx.font_rendering."))) {
|
|
|
|
// Changes to font_rendering prefs need to trigger a reflow
|
2011-10-17 14:59:28 +00:00
|
|
|
mPrefChangePendingNeedsReflow = true;
|
2010-06-09 00:33:13 +00:00
|
|
|
}
|
2005-08-23 23:52:16 +00:00
|
|
|
// we use a zero-delay timer to coalesce multiple pref updates
|
|
|
|
if (!mPrefChangedTimer)
|
|
|
|
{
|
2015-06-16 01:34:48 +00:00
|
|
|
// We will end up calling InvalidatePreferenceSheets one from each pres
|
|
|
|
// context, but all it's doing is clearing its cached sheet pointers,
|
|
|
|
// so it won't be wastefully recreating the sheet multiple times.
|
|
|
|
// The first pres context that has its mPrefChangedTimer called will
|
|
|
|
// be the one to cause the reconstruction of the pref style sheet.
|
|
|
|
nsLayoutStylesheetCache::InvalidatePreferenceSheets();
|
2015-08-04 00:13:07 +00:00
|
|
|
mPrefChangedTimer = CreateTimer(PrefChangedUpdateTimerCallback, 0);
|
|
|
|
if (!mPrefChangedTimer) {
|
2015-07-30 21:24:51 +00:00
|
|
|
return;
|
|
|
|
}
|
2005-08-23 23:52:16 +00:00
|
|
|
}
|
2013-07-22 15:51:38 +00:00
|
|
|
if (prefName.EqualsLiteral("nglayout.debug.paint_flashing") ||
|
|
|
|
prefName.EqualsLiteral("nglayout.debug.paint_flashing_chrome")) {
|
|
|
|
mPaintFlashingInitialized = false;
|
|
|
|
return;
|
|
|
|
}
|
2005-08-23 23:52:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsPresContext::UpdateAfterPreferencesChanged()
|
|
|
|
{
|
2012-07-30 14:20:58 +00:00
|
|
|
mPrefChangedTimer = nullptr;
|
2005-08-23 23:52:16 +00:00
|
|
|
|
2015-07-31 03:47:26 +00:00
|
|
|
if (!mContainer) {
|
|
|
|
// Delay updating until there is a container
|
|
|
|
mNeedsPrefUpdate = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-11-20 19:18:25 +00:00
|
|
|
nsCOMPtr<nsIDocShellTreeItem> docShell(mContainer);
|
2014-01-20 07:58:26 +00:00
|
|
|
if (docShell && nsIDocShellTreeItem::typeChrome == docShell->ItemType()) {
|
|
|
|
return;
|
2001-07-25 06:33:06 +00:00
|
|
|
}
|
|
|
|
|
2000-04-02 21:52:17 +00:00
|
|
|
// Initialize our state from the user preferences
|
|
|
|
GetUserPreferences();
|
2000-10-11 08:33:01 +00:00
|
|
|
|
|
|
|
// update the presShell: tell it to set the preference style rules up
|
|
|
|
if (mShell) {
|
2015-06-16 01:34:48 +00:00
|
|
|
mShell->UpdatePreferenceStyles();
|
2000-10-11 08:33:01 +00:00
|
|
|
}
|
|
|
|
|
2014-09-26 17:06:08 +00:00
|
|
|
InvalidatePaintedLayers();
|
2004-02-02 22:17:21 +00:00
|
|
|
mDeviceContext->FlushFontCache();
|
2008-02-08 19:52:46 +00:00
|
|
|
|
|
|
|
nsChangeHint hint = nsChangeHint(0);
|
|
|
|
|
|
|
|
if (mPrefChangePendingNeedsReflow) {
|
|
|
|
NS_UpdateHint(hint, NS_STYLE_HINT_REFLOW);
|
|
|
|
}
|
|
|
|
|
2014-10-08 21:27:02 +00:00
|
|
|
// Preferences require rerunning selector matching because we rebuild
|
|
|
|
// the pref style sheet for some preference changes.
|
2014-10-08 21:26:57 +00:00
|
|
|
RebuildAllStyleData(hint, eRestyle_Subtree);
|
1998-11-06 16:16:01 +00:00
|
|
|
}
|
|
|
|
|
2004-07-29 19:41:39 +00:00
|
|
|
nsresult
|
2011-04-17 01:22:44 +00:00
|
|
|
nsPresContext::Init(nsDeviceContext* aDeviceContext)
|
1998-06-25 04:24:45 +00:00
|
|
|
{
|
2010-02-07 15:52:43 +00:00
|
|
|
NS_ASSERTION(!mInitialized, "attempt to reinit pres context");
|
2004-02-02 22:17:21 +00:00
|
|
|
NS_ENSURE_ARG(aDeviceContext);
|
1998-06-25 04:24:45 +00:00
|
|
|
|
2003-06-19 18:16:53 +00:00
|
|
|
mDeviceContext = aDeviceContext;
|
1998-07-31 05:54:59 +00:00
|
|
|
|
2014-11-10 02:47:55 +00:00
|
|
|
if (mDeviceContext->SetFullZoom(mFullZoom))
|
2007-11-27 04:54:30 +00:00
|
|
|
mDeviceContext->FlushFontCache();
|
2007-08-24 17:46:59 +00:00
|
|
|
mCurAppUnitsPerDevPixel = AppUnitsPerDevPixel();
|
|
|
|
|
2014-04-01 04:09:23 +00:00
|
|
|
mEventManager = new mozilla::EventStateManager();
|
2004-02-27 18:24:36 +00:00
|
|
|
|
2016-01-12 22:54:53 +00:00
|
|
|
mEffectCompositor = new mozilla::EffectCompositor(this);
|
2009-10-08 03:22:42 +00:00
|
|
|
mTransitionManager = new nsTransitionManager(this);
|
2011-04-12 06:18:44 +00:00
|
|
|
mAnimationManager = new nsAnimationManager(this);
|
|
|
|
|
2010-08-11 21:05:27 +00:00
|
|
|
if (mDocument->GetDisplayDocument()) {
|
|
|
|
NS_ASSERTION(mDocument->GetDisplayDocument()->GetShell() &&
|
|
|
|
mDocument->GetDisplayDocument()->GetShell()->GetPresContext(),
|
|
|
|
"Why are we being initialized?");
|
|
|
|
mRefreshDriver = mDocument->GetDisplayDocument()->GetShell()->
|
|
|
|
GetPresContext()->RefreshDriver();
|
|
|
|
} else {
|
2010-09-07 19:10:41 +00:00
|
|
|
nsIDocument* parent = mDocument->GetParentDocument();
|
|
|
|
// Unfortunately, sometimes |parent| here has no presshell because
|
|
|
|
// printing screws up things. Assert that in other cases it does,
|
|
|
|
// but whenever the shell is null just fall back on using our own
|
|
|
|
// refresh driver.
|
|
|
|
NS_ASSERTION(!parent || mDocument->IsStaticDocument() || parent->GetShell(),
|
|
|
|
"How did we end up with a presshell if our parent doesn't "
|
|
|
|
"have one?");
|
|
|
|
if (parent && parent->GetShell()) {
|
|
|
|
NS_ASSERTION(parent->GetShell()->GetPresContext(),
|
|
|
|
"How did we get a presshell?");
|
|
|
|
|
|
|
|
// We don't have our container set yet at this point
|
2013-11-15 16:32:12 +00:00
|
|
|
nsCOMPtr<nsIDocShellTreeItem> ourItem = mDocument->GetDocShell();
|
2010-09-07 19:10:41 +00:00
|
|
|
if (ourItem) {
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> parentItem;
|
|
|
|
ourItem->GetSameTypeParent(getter_AddRefs(parentItem));
|
|
|
|
if (parentItem) {
|
2013-02-22 14:56:28 +00:00
|
|
|
Element* containingElement =
|
|
|
|
parent->FindContentForSubDocument(mDocument);
|
2015-03-03 11:08:59 +00:00
|
|
|
if (!containingElement->IsXULElement() ||
|
2013-02-22 14:56:28 +00:00
|
|
|
!containingElement->
|
|
|
|
HasAttr(kNameSpaceID_None,
|
|
|
|
nsGkAtoms::forceOwnRefreshDriver)) {
|
|
|
|
mRefreshDriver = parent->GetShell()->GetPresContext()->RefreshDriver();
|
|
|
|
}
|
2010-08-11 21:05:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mRefreshDriver) {
|
|
|
|
mRefreshDriver = new nsRefreshDriver(this);
|
|
|
|
}
|
|
|
|
}
|
2009-10-08 03:22:42 +00:00
|
|
|
|
2014-07-25 04:35:34 +00:00
|
|
|
// Initialize restyle manager after initializing the refresh driver.
|
|
|
|
// Since RestyleManager is also the name of a method of nsPresContext,
|
|
|
|
// it is necessary to prefix the class with the mozilla namespace
|
|
|
|
// here.
|
|
|
|
mRestyleManager = new mozilla::RestyleManager(this);
|
2012-12-11 21:12:43 +00:00
|
|
|
|
2004-04-30 04:06:30 +00:00
|
|
|
mLangService = do_GetService(NS_LANGUAGEATOMSERVICE_CONTRACTID);
|
|
|
|
|
|
|
|
// Register callbacks so we're notified when the preferences change
|
2011-05-28 23:42:57 +00:00
|
|
|
Preferences::RegisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"font.",
|
|
|
|
this);
|
|
|
|
Preferences::RegisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"browser.display.",
|
|
|
|
this);
|
|
|
|
Preferences::RegisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"browser.underline_anchors",
|
|
|
|
this);
|
|
|
|
Preferences::RegisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"browser.anchor_color",
|
|
|
|
this);
|
|
|
|
Preferences::RegisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"browser.active_color",
|
|
|
|
this);
|
|
|
|
Preferences::RegisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"browser.visited_color",
|
|
|
|
this);
|
|
|
|
Preferences::RegisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"image.animation_mode",
|
|
|
|
this);
|
|
|
|
Preferences::RegisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"bidi.",
|
|
|
|
this);
|
|
|
|
Preferences::RegisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"dom.send_after_paint_to_content",
|
|
|
|
this);
|
|
|
|
Preferences::RegisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"gfx.font_rendering.",
|
|
|
|
this);
|
|
|
|
Preferences::RegisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"layout.css.dpi",
|
|
|
|
this);
|
|
|
|
Preferences::RegisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"layout.css.devPixelsPerPx",
|
|
|
|
this);
|
2013-07-22 15:51:38 +00:00
|
|
|
Preferences::RegisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"nglayout.debug.paint_flashing",
|
|
|
|
this);
|
|
|
|
Preferences::RegisterCallback(nsPresContext::PrefChangedCallback,
|
|
|
|
"nglayout.debug.paint_flashing_chrome",
|
|
|
|
this);
|
2004-04-30 04:06:30 +00:00
|
|
|
|
2011-09-09 02:27:13 +00:00
|
|
|
nsresult rv = mEventManager->Init();
|
2004-02-27 17:17:37 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
mEventManager->SetPresContext(this);
|
|
|
|
|
2014-09-25 05:45:36 +00:00
|
|
|
#ifdef RESTYLE_LOGGING
|
|
|
|
mRestyleLoggingEnabled = RestyleManager::RestyleLoggingInitiallyEnabled();
|
|
|
|
#endif
|
|
|
|
|
1998-06-25 04:24:45 +00:00
|
|
|
#ifdef DEBUG
|
2011-10-17 14:59:28 +00:00
|
|
|
mInitialized = true;
|
1998-06-25 04:24:45 +00:00
|
|
|
#endif
|
|
|
|
|
2007-02-07 07:46:44 +00:00
|
|
|
mBorderWidthTable[NS_STYLE_BORDER_WIDTH_THIN] = CSSPixelsToAppUnits(1);
|
|
|
|
mBorderWidthTable[NS_STYLE_BORDER_WIDTH_MEDIUM] = CSSPixelsToAppUnits(3);
|
|
|
|
mBorderWidthTable[NS_STYLE_BORDER_WIDTH_THICK] = CSSPixelsToAppUnits(5);
|
2004-11-26 18:40:58 +00:00
|
|
|
|
1998-06-25 04:24:45 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-04-13 20:24:54 +00:00
|
|
|
// Note: We don't hold a reference on the shell; it has a reference to
|
|
|
|
// us
|
2004-07-29 19:41:39 +00:00
|
|
|
void
|
2004-07-31 23:15:21 +00:00
|
|
|
nsPresContext::SetShell(nsIPresShell* aShell)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
2014-10-16 20:10:00 +00:00
|
|
|
if (mCounterStyleManager) {
|
|
|
|
mCounterStyleManager->Disconnect();
|
|
|
|
mCounterStyleManager = nullptr;
|
|
|
|
}
|
2009-01-19 09:21:29 +00:00
|
|
|
|
2003-04-24 22:44:48 +00:00
|
|
|
if (mShell) {
|
|
|
|
// Remove ourselves as the charset observer from the shell's doc, because
|
|
|
|
// this shell may be going away for good.
|
2004-08-02 04:52:55 +00:00
|
|
|
nsIDocument *doc = mShell->GetDocument();
|
2003-04-24 22:44:48 +00:00
|
|
|
if (doc) {
|
|
|
|
doc->RemoveCharSetObserver(this);
|
|
|
|
}
|
2014-03-20 06:49:25 +00:00
|
|
|
}
|
2003-04-24 22:44:48 +00:00
|
|
|
|
1998-04-13 20:24:54 +00:00
|
|
|
mShell = aShell;
|
2003-04-24 22:44:48 +00:00
|
|
|
|
|
|
|
if (mShell) {
|
2014-10-16 20:10:00 +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);
|
|
|
|
|
2006-07-28 06:22:19 +00:00
|
|
|
nsIDocument *doc = mShell->GetDocument();
|
|
|
|
NS_ASSERTION(doc, "expect document here");
|
|
|
|
if (doc) {
|
|
|
|
// Have to update PresContext's mDocument before calling any other methods.
|
|
|
|
mDocument = doc;
|
|
|
|
}
|
2005-11-08 22:45:49 +00:00
|
|
|
// Initialize our state from the user preferences, now that we
|
|
|
|
// have a presshell, and hence a document.
|
|
|
|
GetUserPreferences();
|
|
|
|
|
2004-08-02 04:52:55 +00:00
|
|
|
if (doc) {
|
2006-03-24 00:09:50 +00:00
|
|
|
nsIURI *docURI = doc->GetDocumentURI();
|
2004-08-02 04:52:55 +00:00
|
|
|
|
2006-04-01 01:19:28 +00:00
|
|
|
if (IsDynamic() && docURI) {
|
2011-09-29 06:19:26 +00:00
|
|
|
bool isChrome = false;
|
|
|
|
bool isRes = false;
|
2006-03-24 00:09:50 +00:00
|
|
|
docURI->SchemeIs("chrome", &isChrome);
|
|
|
|
docURI->SchemeIs("resource", &isRes);
|
2004-08-02 04:52:55 +00:00
|
|
|
|
|
|
|
if (!isChrome && !isRes)
|
|
|
|
mImageAnimationMode = mImageAnimationModePref;
|
|
|
|
else
|
|
|
|
mImageAnimationMode = imgIContainer::kNormalAnimMode;
|
|
|
|
}
|
2001-01-09 23:55:27 +00:00
|
|
|
|
2004-08-02 04:52:55 +00:00
|
|
|
if (mLangService) {
|
|
|
|
doc->AddCharSetObserver(this);
|
2004-08-09 21:19:15 +00:00
|
|
|
UpdateCharSet(doc->GetDocumentCharacterSet());
|
1999-02-12 17:45:58 +00:00
|
|
|
}
|
1998-09-05 03:52:40 +00:00
|
|
|
}
|
2010-01-14 02:30:05 +00:00
|
|
|
} else {
|
2016-01-12 22:54:53 +00:00
|
|
|
if (mEffectCompositor) {
|
|
|
|
mEffectCompositor->Disconnect();
|
|
|
|
mEffectCompositor = nullptr;
|
|
|
|
}
|
2010-12-18 04:45:18 +00:00
|
|
|
if (mTransitionManager) {
|
|
|
|
mTransitionManager->Disconnect();
|
2012-07-30 14:20:58 +00:00
|
|
|
mTransitionManager = nullptr;
|
2010-12-18 04:45:18 +00:00
|
|
|
}
|
2011-04-12 06:18:44 +00:00
|
|
|
if (mAnimationManager) {
|
|
|
|
mAnimationManager->Disconnect();
|
2012-07-30 14:20:58 +00:00
|
|
|
mAnimationManager = nullptr;
|
2011-04-12 06:18:44 +00:00
|
|
|
}
|
2013-07-20 19:14:24 +00:00
|
|
|
if (mRestyleManager) {
|
|
|
|
mRestyleManager->Disconnect();
|
|
|
|
mRestyleManager = nullptr;
|
|
|
|
}
|
2011-12-24 03:52:26 +00:00
|
|
|
|
|
|
|
if (IsRoot()) {
|
|
|
|
// Have to cancel our plugin geometry timer, because the
|
|
|
|
// callback for that depends on a non-null presshell.
|
2012-10-06 13:03:23 +00:00
|
|
|
static_cast<nsRootPresContext*>(this)->CancelApplyPluginGeometryTimer();
|
2011-12-24 03:52:26 +00:00
|
|
|
}
|
1998-09-05 03:52:40 +00:00
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
2000-09-20 22:59:20 +00:00
|
|
|
void
|
2012-01-11 20:58:44 +00:00
|
|
|
nsPresContext::DoChangeCharSet(const nsCString& aCharSet)
|
|
|
|
{
|
|
|
|
UpdateCharSet(aCharSet);
|
|
|
|
mDeviceContext->FlushFontCache();
|
2014-10-08 21:26:59 +00:00
|
|
|
RebuildAllStyleData(NS_STYLE_HINT_REFLOW, nsRestyleHint(0));
|
2012-01-11 20:58:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsPresContext::UpdateCharSet(const nsCString& aCharSet)
|
2000-09-20 22:59:20 +00:00
|
|
|
{
|
|
|
|
if (mLangService) {
|
2014-05-08 09:32:00 +00:00
|
|
|
mLanguage = mLangService->LookupCharSet(aCharSet);
|
2010-02-24 17:57:44 +00:00
|
|
|
// this will be a language group (or script) code rather than a true language code
|
2004-06-21 10:32:27 +00:00
|
|
|
|
|
|
|
// bug 39570: moved from nsLanguageAtomService::LookupCharSet()
|
2010-02-24 17:57:44 +00:00
|
|
|
if (mLanguage == nsGkAtoms::Unicode) {
|
2012-07-30 04:29:23 +00:00
|
|
|
mLanguage = mLangService->GetLocaleLanguage();
|
2004-06-21 10:32:27 +00:00
|
|
|
}
|
2012-01-25 23:52:26 +00:00
|
|
|
ResetCachedFontPrefs();
|
2000-09-20 22:59:20 +00:00
|
|
|
}
|
2001-03-09 03:13:03 +00:00
|
|
|
|
2005-11-08 22:45:49 +00:00
|
|
|
switch (GET_BIDI_OPTION_TEXTTYPE(GetBidi())) {
|
2004-08-05 21:38:08 +00:00
|
|
|
|
|
|
|
case IBMBIDI_TEXTTYPE_LOGICAL:
|
2011-10-17 14:59:28 +00:00
|
|
|
SetVisualMode(false);
|
2004-08-05 21:38:08 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case IBMBIDI_TEXTTYPE_VISUAL:
|
2011-10-17 14:59:28 +00:00
|
|
|
SetVisualMode(true);
|
2004-08-05 21:38:08 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case IBMBIDI_TEXTTYPE_CHARSET:
|
|
|
|
default:
|
2004-08-09 21:19:15 +00:00
|
|
|
SetVisualMode(IsVisualCharset(aCharSet));
|
2004-08-05 21:38:08 +00:00
|
|
|
}
|
2000-09-20 22:59:20 +00:00
|
|
|
}
|
|
|
|
|
2000-06-01 23:12:26 +00:00
|
|
|
NS_IMETHODIMP
|
2014-03-20 06:49:25 +00:00
|
|
|
nsPresContext::Observe(nsISupports* aSubject,
|
2004-07-29 19:41:39 +00:00
|
|
|
const char* aTopic,
|
2014-01-04 15:02:17 +00:00
|
|
|
const char16_t* aData)
|
2000-06-01 23:12:26 +00:00
|
|
|
{
|
2001-10-19 20:52:59 +00:00
|
|
|
if (!nsCRT::strcmp(aTopic, "charset")) {
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<CharSetChangingRunnable> runnable =
|
2012-01-11 20:58:44 +00:00
|
|
|
new CharSetChangingRunnable(this, NS_LossyConvertUTF16toASCII(aData));
|
|
|
|
return NS_DispatchToCurrentThread(runnable);
|
2000-09-20 22:59:20 +00:00
|
|
|
}
|
|
|
|
|
2004-07-31 23:15:21 +00:00
|
|
|
NS_WARNING("unrecognized topic in nsPresContext::Observe");
|
2001-10-19 20:52:59 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
2000-06-01 23:12:26 +00:00
|
|
|
}
|
|
|
|
|
2012-05-04 05:00:57 +00:00
|
|
|
nsPresContext*
|
|
|
|
nsPresContext::GetParentPresContext()
|
2011-01-15 09:40:33 +00:00
|
|
|
{
|
2012-05-04 05:00:57 +00:00
|
|
|
nsIPresShell* shell = GetPresShell();
|
2011-01-15 09:40:33 +00:00
|
|
|
if (shell) {
|
2013-02-27 20:52:06 +00:00
|
|
|
nsViewManager* viewManager = shell->GetViewManager();
|
|
|
|
if (viewManager) {
|
|
|
|
nsView* view = viewManager->GetRootView();
|
|
|
|
if (view) {
|
|
|
|
view = view->GetParent(); // anonymous inner view
|
|
|
|
if (view) {
|
|
|
|
view = view->GetParent(); // subdocumentframe's view
|
|
|
|
if (view) {
|
|
|
|
nsIFrame* f = view->GetFrame();
|
|
|
|
if (f) {
|
|
|
|
return f->PresContext();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-01-15 09:40:33 +00:00
|
|
|
}
|
|
|
|
}
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2011-01-15 09:40:33 +00:00
|
|
|
}
|
|
|
|
|
2012-05-04 05:00:57 +00:00
|
|
|
nsPresContext*
|
|
|
|
nsPresContext::GetToplevelContentDocumentPresContext()
|
|
|
|
{
|
|
|
|
if (IsChrome())
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2012-05-04 05:00:57 +00:00
|
|
|
nsPresContext* pc = this;
|
|
|
|
for (;;) {
|
|
|
|
nsPresContext* parent = pc->GetParentPresContext();
|
|
|
|
if (!parent || parent->IsChrome())
|
|
|
|
return pc;
|
|
|
|
pc = parent;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-26 05:47:45 +00:00
|
|
|
nsIWidget*
|
|
|
|
nsPresContext::GetNearestWidget(nsPoint* aOffset)
|
|
|
|
{
|
|
|
|
NS_ENSURE_TRUE(mShell, nullptr);
|
|
|
|
nsIFrame* frame = mShell->GetRootFrame();
|
|
|
|
NS_ENSURE_TRUE(frame, nullptr);
|
|
|
|
return frame->GetView()->GetNearestWidget(aOffset);
|
|
|
|
}
|
|
|
|
|
2013-02-06 02:50:02 +00:00
|
|
|
nsIWidget*
|
|
|
|
nsPresContext::GetRootWidget()
|
|
|
|
{
|
|
|
|
NS_ENSURE_TRUE(mShell, nullptr);
|
|
|
|
nsViewManager* vm = mShell->GetViewManager();
|
|
|
|
if (!vm) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsIWidget> widget;
|
|
|
|
vm->GetRootWidget(getter_AddRefs(widget));
|
|
|
|
return widget.get();
|
|
|
|
}
|
|
|
|
|
2006-11-29 23:09:13 +00:00
|
|
|
// We may want to replace this with something faster, maybe caching the root prescontext
|
2009-07-22 00:44:54 +00:00
|
|
|
nsRootPresContext*
|
2010-01-26 13:10:12 +00:00
|
|
|
nsPresContext::GetRootPresContext()
|
2006-11-29 23:09:13 +00:00
|
|
|
{
|
|
|
|
nsPresContext* pc = this;
|
|
|
|
for (;;) {
|
2012-05-04 05:00:57 +00:00
|
|
|
nsPresContext* parent = pc->GetParentPresContext();
|
2012-07-04 00:31:07 +00:00
|
|
|
if (!parent)
|
2011-01-15 09:40:33 +00:00
|
|
|
break;
|
|
|
|
pc = parent;
|
2006-11-29 23:09:13 +00:00
|
|
|
}
|
2012-07-30 14:20:58 +00:00
|
|
|
return pc->IsRoot() ? static_cast<nsRootPresContext*>(pc) : nullptr;
|
2006-11-29 23:09:13 +00:00
|
|
|
}
|
|
|
|
|
2003-12-24 21:51:50 +00:00
|
|
|
void
|
2006-12-05 15:46:18 +00:00
|
|
|
nsPresContext::CompatibilityModeChanged()
|
1998-07-31 05:54:59 +00:00
|
|
|
{
|
2015-06-26 03:49:58 +00:00
|
|
|
if (!mShell) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIDocument* doc = mShell->GetDocument();
|
|
|
|
if (!doc) {
|
2003-12-24 21:51:50 +00:00
|
|
|
return;
|
2015-06-26 03:49:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (doc->IsSVGDocument()) {
|
|
|
|
// SVG documents never load quirk.css.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool needsQuirkSheet = CompatibilityMode() == eCompatibility_NavQuirks;
|
|
|
|
if (mQuirkSheetAdded == needsQuirkSheet) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-02-24 07:01:11 +00:00
|
|
|
StyleSetHandle styleSet = mShell->StyleSet();
|
2016-02-24 07:01:12 +00:00
|
|
|
auto cache = nsLayoutStylesheetCache::For(styleSet->BackendType());
|
|
|
|
StyleSheetHandle 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);
|
2015-06-26 03:49:58 +00:00
|
|
|
NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "failed to insert quirk.css");
|
|
|
|
} else {
|
|
|
|
DebugOnly<nsresult> rv =
|
2015-10-19 23:16:20 +00:00
|
|
|
styleSet->RemoveStyleSheet(SheetType::Agent, sheet);
|
2015-06-26 03:49:58 +00:00
|
|
|
NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "failed to remove quirk.css");
|
|
|
|
}
|
2000-06-02 21:45:06 +00:00
|
|
|
|
2015-06-26 03:49:58 +00:00
|
|
|
mQuirkSheetAdded = needsQuirkSheet;
|
1998-07-31 05:54:59 +00:00
|
|
|
}
|
|
|
|
|
2001-11-14 11:21:54 +00:00
|
|
|
// Helper function for setting Anim Mode on image
|
2012-08-22 15:56:38 +00:00
|
|
|
static void SetImgAnimModeOnImgReq(imgIRequest* aImgReq, uint16_t aMode)
|
2001-11-14 11:21:54 +00:00
|
|
|
{
|
2003-03-19 03:47:09 +00:00
|
|
|
if (aImgReq) {
|
2001-11-14 11:21:54 +00:00
|
|
|
nsCOMPtr<imgIContainer> imgCon;
|
|
|
|
aImgReq->GetImage(getter_AddRefs(imgCon));
|
|
|
|
if (imgCon) {
|
|
|
|
imgCon->SetAnimationMode(aMode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-20 06:49:25 +00:00
|
|
|
// IMPORTANT: Assumption is that all images for a Presentation
|
2001-11-14 11:21:54 +00:00
|
|
|
// have the same Animation Mode (pavlov said this was OK)
|
|
|
|
//
|
|
|
|
// Walks content and set the animation mode
|
|
|
|
// this is a way to turn on/off image animations
|
2012-08-22 15:56:38 +00:00
|
|
|
void nsPresContext::SetImgAnimations(nsIContent *aParent, uint16_t aMode)
|
2001-11-14 11:21:54 +00:00
|
|
|
{
|
2003-03-19 03:47:09 +00:00
|
|
|
nsCOMPtr<nsIImageLoadingContent> imgContent(do_QueryInterface(aParent));
|
2001-11-14 11:21:54 +00:00
|
|
|
if (imgContent) {
|
2003-03-19 03:47:09 +00:00
|
|
|
nsCOMPtr<imgIRequest> imgReq;
|
|
|
|
imgContent->GetRequest(nsIImageLoadingContent::CURRENT_REQUEST,
|
|
|
|
getter_AddRefs(imgReq));
|
|
|
|
SetImgAnimModeOnImgReq(imgReq, aMode);
|
2001-11-14 11:21:54 +00:00
|
|
|
}
|
2014-03-20 06:49:25 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t count = aParent->GetChildCount();
|
|
|
|
for (uint32_t i = 0; i < count; ++i) {
|
2003-09-27 04:18:26 +00:00
|
|
|
SetImgAnimations(aParent->GetChildAt(i), aMode);
|
2001-11-14 11:21:54 +00:00
|
|
|
}
|
|
|
|
}
|
2000-05-13 01:39:20 +00:00
|
|
|
|
2009-01-15 04:38:07 +00:00
|
|
|
void
|
2012-08-22 15:56:38 +00:00
|
|
|
nsPresContext::SetSMILAnimations(nsIDocument *aDoc, uint16_t aNewMode,
|
|
|
|
uint16_t aOldMode)
|
2009-01-15 04:38:07 +00:00
|
|
|
{
|
2010-03-03 07:09:51 +00:00
|
|
|
if (aDoc->HasAnimationController()) {
|
|
|
|
nsSMILAnimationController* controller = aDoc->GetAnimationController();
|
2009-01-15 04:38:07 +00:00
|
|
|
switch (aNewMode)
|
|
|
|
{
|
|
|
|
case imgIContainer::kNormalAnimMode:
|
|
|
|
case imgIContainer::kLoopOnceAnimMode:
|
|
|
|
if (aOldMode == imgIContainer::kDontAnimMode)
|
|
|
|
controller->Resume(nsSMILTimeContainer::PAUSE_USERPREF);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case imgIContainer::kDontAnimMode:
|
|
|
|
if (aOldMode != imgIContainer::kDontAnimMode)
|
|
|
|
controller->Pause(nsSMILTimeContainer::PAUSE_USERPREF);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-12-26 04:24:11 +00:00
|
|
|
void
|
2012-08-22 15:56:38 +00:00
|
|
|
nsPresContext::SetImageAnimationModeInternal(uint16_t aMode)
|
2000-05-13 01:39:20 +00:00
|
|
|
{
|
2001-11-14 14:03:09 +00:00
|
|
|
NS_ASSERTION(aMode == imgIContainer::kNormalAnimMode ||
|
|
|
|
aMode == imgIContainer::kDontAnimMode ||
|
|
|
|
aMode == imgIContainer::kLoopOnceAnimMode, "Wrong Animation Mode is being set!");
|
|
|
|
|
2004-07-29 19:41:39 +00:00
|
|
|
// Image animation mode cannot be changed when rendering to a printer.
|
2006-04-01 01:19:28 +00:00
|
|
|
if (!IsDynamic())
|
2004-07-29 19:41:39 +00:00
|
|
|
return;
|
|
|
|
|
2014-03-20 06:49:25 +00:00
|
|
|
// Now walk the content tree and set the animation mode
|
2008-10-28 21:38:37 +00:00
|
|
|
// on all the images.
|
2012-07-30 14:20:58 +00:00
|
|
|
if (mShell != nullptr) {
|
2004-08-02 04:52:55 +00:00
|
|
|
nsIDocument *doc = mShell->GetDocument();
|
2001-11-14 11:21:54 +00:00
|
|
|
if (doc) {
|
2012-08-13 22:04:19 +00:00
|
|
|
doc->StyleImageLoader()->SetAnimationMode(aMode);
|
|
|
|
|
2010-04-30 13:12:05 +00:00
|
|
|
Element *rootElement = doc->GetRootElement();
|
|
|
|
if (rootElement) {
|
|
|
|
SetImgAnimations(rootElement, aMode);
|
2001-11-14 11:21:54 +00:00
|
|
|
}
|
2009-01-15 04:38:07 +00:00
|
|
|
SetSMILAnimations(doc, aMode, mImageAnimationMode);
|
2001-11-14 11:21:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-05-13 01:39:20 +00:00
|
|
|
mImageAnimationMode = aMode;
|
|
|
|
}
|
|
|
|
|
2004-07-29 19:41:39 +00:00
|
|
|
void
|
2012-08-22 15:56:38 +00:00
|
|
|
nsPresContext::SetImageAnimationModeExternal(uint16_t aMode)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
2004-07-29 19:41:39 +00:00
|
|
|
SetImageAnimationModeInternal(aMode);
|
|
|
|
}
|
1998-08-27 20:43:04 +00:00
|
|
|
|
2004-01-31 22:41:40 +00:00
|
|
|
const nsFont*
|
2012-08-22 15:56:38 +00:00
|
|
|
nsPresContext::GetDefaultFont(uint8_t aFontID, nsIAtom *aLanguage) const
|
1999-02-12 17:45:58 +00:00
|
|
|
{
|
2012-01-25 23:52:26 +00:00
|
|
|
const LangGroupFontPrefs *prefs = GetFontPrefsForLang(aLanguage);
|
|
|
|
|
2004-01-31 22:41:40 +00:00
|
|
|
const nsFont *font;
|
2001-09-27 18:34:30 +00:00
|
|
|
switch (aFontID) {
|
|
|
|
// Special (our default variable width font and fixed width font)
|
|
|
|
case kPresContext_DefaultVariableFont_ID:
|
2012-01-25 23:52:26 +00:00
|
|
|
font = &prefs->mDefaultVariableFont;
|
2001-09-27 18:34:30 +00:00
|
|
|
break;
|
|
|
|
case kPresContext_DefaultFixedFont_ID:
|
2012-01-25 23:52:26 +00:00
|
|
|
font = &prefs->mDefaultFixedFont;
|
2001-09-27 18:34:30 +00:00
|
|
|
break;
|
|
|
|
// CSS
|
|
|
|
case kGenericFont_serif:
|
2012-01-25 23:52:26 +00:00
|
|
|
font = &prefs->mDefaultSerifFont;
|
2001-09-27 18:34:30 +00:00
|
|
|
break;
|
|
|
|
case kGenericFont_sans_serif:
|
2012-01-25 23:52:26 +00:00
|
|
|
font = &prefs->mDefaultSansSerifFont;
|
2001-09-27 18:34:30 +00:00
|
|
|
break;
|
|
|
|
case kGenericFont_monospace:
|
2012-01-25 23:52:26 +00:00
|
|
|
font = &prefs->mDefaultMonospaceFont;
|
2001-09-27 18:34:30 +00:00
|
|
|
break;
|
|
|
|
case kGenericFont_cursive:
|
2012-01-25 23:52:26 +00:00
|
|
|
font = &prefs->mDefaultCursiveFont;
|
2001-09-27 18:34:30 +00:00
|
|
|
break;
|
2014-03-20 06:49:25 +00:00
|
|
|
case kGenericFont_fantasy:
|
2012-01-25 23:52:26 +00:00
|
|
|
font = &prefs->mDefaultFantasyFont;
|
2001-09-27 18:34:30 +00:00
|
|
|
break;
|
|
|
|
default:
|
2012-07-30 14:20:58 +00:00
|
|
|
font = nullptr;
|
2001-09-27 18:34:30 +00:00
|
|
|
NS_ERROR("invalid arg");
|
|
|
|
break;
|
|
|
|
}
|
2004-01-31 22:41:40 +00:00
|
|
|
return font;
|
1998-07-17 05:41:41 +00:00
|
|
|
}
|
|
|
|
|
2015-11-28 00:56:33 +00:00
|
|
|
already_AddRefed<nsIAtom>
|
|
|
|
nsPresContext::GetContentLanguage() const
|
|
|
|
{
|
|
|
|
nsAutoString language;
|
|
|
|
Document()->GetContentLanguage(language);
|
|
|
|
language.StripWhitespace();
|
|
|
|
|
|
|
|
// Content-Language may be a comma-separated list of language codes,
|
|
|
|
// in which case the HTML5 spec says to treat it as unknown
|
|
|
|
if (!language.IsEmpty() &&
|
|
|
|
!language.Contains(char16_t(','))) {
|
|
|
|
return do_GetAtom(language);
|
|
|
|
// NOTE: This does *not* count as an explicit language; in other
|
|
|
|
// words, it doesn't trigger language-specific hyphenation.
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2005-08-13 11:54:22 +00:00
|
|
|
void
|
2007-07-26 03:34:16 +00:00
|
|
|
nsPresContext::SetFullZoom(float aZoom)
|
2005-08-13 11:54:22 +00:00
|
|
|
{
|
2009-12-11 04:02:13 +00:00
|
|
|
if (!mShell || mFullZoom == aZoom) {
|
2007-07-26 03:34:16 +00:00
|
|
|
return;
|
|
|
|
}
|
2011-04-11 20:57:29 +00:00
|
|
|
|
2007-12-12 02:27:00 +00:00
|
|
|
// Re-fetch the view manager's window dimensions in case there's a deferred
|
|
|
|
// resize which hasn't affected our mVisibleArea yet
|
|
|
|
nscoord oldWidthAppUnits, oldHeightAppUnits;
|
2009-03-11 15:43:08 +00:00
|
|
|
mShell->GetViewManager()->GetWindowDimensions(&oldWidthAppUnits, &oldHeightAppUnits);
|
2007-12-12 02:27:00 +00:00
|
|
|
float oldWidthDevPixels = oldWidthAppUnits / float(mCurAppUnitsPerDevPixel);
|
|
|
|
float oldHeightDevPixels = oldHeightAppUnits / float(mCurAppUnitsPerDevPixel);
|
2014-11-10 02:47:55 +00:00
|
|
|
mDeviceContext->SetFullZoom(aZoom);
|
2008-01-29 04:10:59 +00:00
|
|
|
|
2015-05-07 00:56:00 +00:00
|
|
|
NS_ASSERTION(!mSuppressResizeReflow, "two zooms happening at the same time? impossible!");
|
|
|
|
mSuppressResizeReflow = true;
|
2008-01-29 04:10:59 +00:00
|
|
|
|
2007-11-26 08:35:22 +00:00
|
|
|
mFullZoom = aZoom;
|
2009-03-11 15:43:08 +00:00
|
|
|
mShell->GetViewManager()->
|
|
|
|
SetWindowDimensions(NSToCoordRound(oldWidthDevPixels * AppUnitsPerDevPixel()),
|
|
|
|
NSToCoordRound(oldHeightDevPixels * AppUnitsPerDevPixel()));
|
2011-04-11 20:57:29 +00:00
|
|
|
|
|
|
|
AppUnitsPerDevPixelChanged();
|
2008-01-29 04:10:59 +00:00
|
|
|
|
2015-05-07 00:56:00 +00:00
|
|
|
mSuppressResizeReflow = false;
|
2005-08-13 11:54:22 +00:00
|
|
|
}
|
|
|
|
|
2015-03-10 14:28:23 +00:00
|
|
|
gfxSize
|
|
|
|
nsPresContext::ScreenSizeInchesForFontInflation(bool* aChanged)
|
2012-05-05 13:25:45 +00:00
|
|
|
{
|
|
|
|
if (aChanged) {
|
|
|
|
*aChanged = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsDeviceContext *dx = DeviceContext();
|
|
|
|
nsRect clientRect;
|
|
|
|
dx->GetClientRect(clientRect); // FIXME: GetClientRect looks expensive
|
2015-03-10 14:28:23 +00:00
|
|
|
float unitsPerInch = dx->AppUnitsPerPhysicalInch();
|
|
|
|
gfxSize deviceSizeInches(float(clientRect.width) / unitsPerInch,
|
|
|
|
float(clientRect.height) / unitsPerInch);
|
2012-05-05 13:25:45 +00:00
|
|
|
|
2015-03-10 14:28:23 +00:00
|
|
|
if (mLastFontInflationScreenSize == gfxSize(-1.0, -1.0)) {
|
|
|
|
mLastFontInflationScreenSize = deviceSizeInches;
|
2012-06-12 05:43:31 +00:00
|
|
|
}
|
|
|
|
|
2015-03-10 14:28:23 +00:00
|
|
|
if (deviceSizeInches != mLastFontInflationScreenSize && aChanged) {
|
2012-06-12 05:43:31 +00:00
|
|
|
*aChanged = true;
|
2015-03-10 14:28:23 +00:00
|
|
|
mLastFontInflationScreenSize = deviceSizeInches;
|
2012-05-05 13:25:45 +00:00
|
|
|
}
|
|
|
|
|
2015-03-10 14:28:23 +00:00
|
|
|
return deviceSizeInches;
|
2012-05-05 13:25:45 +00:00
|
|
|
}
|
|
|
|
|
2015-09-30 00:48:41 +00:00
|
|
|
static bool
|
2015-09-30 00:48:41 +00:00
|
|
|
CheckOverflow(const nsStyleDisplay* aDisplay, ScrollbarStyles* aStyles)
|
2015-09-30 00:48:41 +00:00
|
|
|
{
|
|
|
|
if (aDisplay->mOverflowX == NS_STYLE_OVERFLOW_VISIBLE &&
|
|
|
|
aDisplay->mScrollBehavior == NS_STYLE_SCROLL_BEHAVIOR_AUTO &&
|
|
|
|
aDisplay->mScrollSnapTypeX == NS_STYLE_SCROLL_SNAP_TYPE_NONE &&
|
|
|
|
aDisplay->mScrollSnapTypeY == NS_STYLE_SCROLL_SNAP_TYPE_NONE &&
|
|
|
|
aDisplay->mScrollSnapPointsX == nsStyleCoord(eStyleUnit_None) &&
|
|
|
|
aDisplay->mScrollSnapPointsY == nsStyleCoord(eStyleUnit_None) &&
|
|
|
|
!aDisplay->mScrollSnapDestination.mXPosition.mHasPercent &&
|
|
|
|
!aDisplay->mScrollSnapDestination.mYPosition.mHasPercent &&
|
|
|
|
aDisplay->mScrollSnapDestination.mXPosition.mLength == 0 &&
|
|
|
|
aDisplay->mScrollSnapDestination.mYPosition.mLength == 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aDisplay->mOverflowX == NS_STYLE_OVERFLOW_CLIP) {
|
2015-09-30 00:48:41 +00:00
|
|
|
*aStyles = ScrollbarStyles(NS_STYLE_OVERFLOW_HIDDEN,
|
|
|
|
NS_STYLE_OVERFLOW_HIDDEN, aDisplay);
|
2015-09-30 00:48:41 +00:00
|
|
|
} else {
|
2015-09-30 00:48:41 +00:00
|
|
|
*aStyles = ScrollbarStyles(aDisplay);
|
2015-09-30 00:48:41 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-09-30 00:48:41 +00:00
|
|
|
static nsIContent*
|
|
|
|
GetPropagatedScrollbarStylesForViewport(nsPresContext* aPresContext,
|
|
|
|
ScrollbarStyles *aStyles)
|
2015-09-30 00:48:41 +00:00
|
|
|
{
|
|
|
|
// Set default
|
2015-09-30 00:48:41 +00:00
|
|
|
*aStyles = ScrollbarStyles(NS_STYLE_OVERFLOW_AUTO, NS_STYLE_OVERFLOW_AUTO);
|
2015-09-30 00:48:41 +00:00
|
|
|
|
|
|
|
// We never mess with the viewport scroll state
|
|
|
|
// when printing or in print preview
|
2015-09-30 00:48:41 +00:00
|
|
|
if (aPresContext->IsPaginated()) {
|
2015-09-30 00:48:41 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-09-30 00:48:41 +00:00
|
|
|
nsIDocument* document = aPresContext->Document();
|
|
|
|
Element* docElement = document->GetRootElement();
|
2015-09-30 00:48:41 +00:00
|
|
|
|
2015-12-08 19:55:50 +00:00
|
|
|
// docElement might be null if we're doing this after removing it.
|
|
|
|
if (!docElement) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-09-30 00:48:41 +00:00
|
|
|
// Check the style on the document root element
|
2016-02-24 07:01:11 +00:00
|
|
|
StyleSetHandle styleSet = aPresContext->StyleSet();
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<nsStyleContext> rootStyle;
|
2015-09-30 00:48:41 +00:00
|
|
|
rootStyle = styleSet->ResolveStyleFor(docElement, nullptr);
|
2015-09-30 00:48:41 +00:00
|
|
|
if (CheckOverflow(rootStyle->StyleDisplay(), aStyles)) {
|
2015-09-30 00:48:41 +00:00
|
|
|
// tell caller we stole the overflow style from the root element
|
|
|
|
return docElement;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Don't look in the BODY for non-HTML documents or HTML documents
|
|
|
|
// with non-HTML roots
|
|
|
|
// XXX this should be earlier; we shouldn't even look at the document root
|
|
|
|
// for non-HTML documents. Fix this once we support explicit CSS styling
|
|
|
|
// of the viewport
|
|
|
|
// XXX what about XHTML?
|
2015-09-30 00:48:41 +00:00
|
|
|
nsCOMPtr<nsIDOMHTMLDocument> htmlDoc(do_QueryInterface(document));
|
2015-09-30 00:48:41 +00:00
|
|
|
if (!htmlDoc || !docElement->IsHTMLElement()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMHTMLElement> body;
|
|
|
|
htmlDoc->GetBody(getter_AddRefs(body));
|
|
|
|
nsCOMPtr<nsIContent> bodyElement = do_QueryInterface(body);
|
|
|
|
|
|
|
|
if (!bodyElement ||
|
|
|
|
!bodyElement->NodeInfo()->Equals(nsGkAtoms::body)) {
|
|
|
|
// The body is not a <body> tag, it's a <frameset>.
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<nsStyleContext> bodyStyle;
|
2015-09-30 00:48:41 +00:00
|
|
|
bodyStyle = styleSet->ResolveStyleFor(bodyElement->AsElement(), rootStyle);
|
|
|
|
|
2015-09-30 00:48:41 +00:00
|
|
|
if (CheckOverflow(bodyStyle->StyleDisplay(), aStyles)) {
|
2015-09-30 00:48:41 +00:00
|
|
|
// tell caller we stole the overflow style from the body element
|
|
|
|
return bodyElement;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-09-30 00:48:41 +00:00
|
|
|
nsIContent*
|
|
|
|
nsPresContext::UpdateViewportScrollbarStylesOverride()
|
|
|
|
{
|
|
|
|
nsIContent* propagatedFrom =
|
|
|
|
GetPropagatedScrollbarStylesForViewport(this, &mViewportStyleScrollbar);
|
|
|
|
|
|
|
|
nsIDocument* document = Document();
|
2016-02-17 00:47:11 +00:00
|
|
|
if (Element* fullscreenElement = document->GetFullscreenElement()) {
|
2015-09-30 00:48:41 +00:00
|
|
|
// If the document is in fullscreen, but the fullscreen element is
|
|
|
|
// not the root element, we should explicitly suppress the scrollbar
|
|
|
|
// here. Note that, we still need to return the original element
|
|
|
|
// the styles are from, so that the state of those elements is not
|
|
|
|
// affected across fullscreen change.
|
|
|
|
if (fullscreenElement != document->GetRootElement() &&
|
|
|
|
fullscreenElement != propagatedFrom) {
|
|
|
|
mViewportStyleScrollbar = ScrollbarStyles(NS_STYLE_OVERFLOW_HIDDEN,
|
|
|
|
NS_STYLE_OVERFLOW_HIDDEN);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return propagatedFrom;
|
|
|
|
}
|
|
|
|
|
2004-02-01 10:09:07 +00:00
|
|
|
void
|
2013-11-20 19:18:25 +00:00
|
|
|
nsPresContext::SetContainer(nsIDocShell* aDocShell)
|
1999-04-30 09:04:36 +00:00
|
|
|
{
|
2013-11-20 19:18:25 +00:00
|
|
|
if (aDocShell) {
|
2015-08-04 00:13:08 +00:00
|
|
|
NS_ASSERTION(!(mContainer && mNeedsPrefUpdate),
|
2015-07-31 03:47:26 +00:00
|
|
|
"Should only need pref update if mContainer is null.");
|
2014-07-30 19:52:05 +00:00
|
|
|
mContainer = static_cast<nsDocShell*>(aDocShell);
|
2015-07-31 03:47:26 +00:00
|
|
|
if (mNeedsPrefUpdate) {
|
|
|
|
if (!mPrefChangedTimer) {
|
2015-08-04 00:13:07 +00:00
|
|
|
mPrefChangedTimer = CreateTimer(PrefChangedUpdateTimerCallback, 0);
|
2015-07-31 03:47:26 +00:00
|
|
|
}
|
|
|
|
mNeedsPrefUpdate = false;
|
|
|
|
}
|
2013-11-20 19:18:25 +00:00
|
|
|
} else {
|
|
|
|
mContainer = WeakPtr<nsDocShell>();
|
|
|
|
}
|
2014-02-07 03:08:49 +00:00
|
|
|
UpdateIsChrome();
|
2001-10-16 23:59:25 +00:00
|
|
|
if (mContainer) {
|
|
|
|
GetDocumentColorPreferences();
|
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
2013-11-20 19:18:25 +00:00
|
|
|
nsISupports*
|
|
|
|
nsPresContext::GetContainerWeakInternal() const
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
2013-11-20 19:18:25 +00:00
|
|
|
return static_cast<nsIDocShell*>(mContainer);
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
1998-06-23 21:53:02 +00:00
|
|
|
|
2013-11-20 19:18:25 +00:00
|
|
|
nsISupports*
|
|
|
|
nsPresContext::GetContainerWeakExternal() const
|
2004-07-29 19:41:39 +00:00
|
|
|
{
|
2013-11-20 19:18:25 +00:00
|
|
|
return GetContainerWeakInternal();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIDocShell*
|
|
|
|
nsPresContext::GetDocShell() const
|
|
|
|
{
|
|
|
|
return mContainer;
|
2004-07-29 19:41:39 +00:00
|
|
|
}
|
|
|
|
|
2014-02-03 23:47:57 +00:00
|
|
|
/* virtual */ void
|
|
|
|
nsPresContext::Detach()
|
|
|
|
{
|
|
|
|
SetContainer(nullptr);
|
|
|
|
SetLinkHandler(nullptr);
|
2014-02-21 08:40:45 +00:00
|
|
|
if (mShell) {
|
|
|
|
mShell->CancelInvalidatePresShellIfHidden();
|
|
|
|
}
|
2014-02-03 23:47:57 +00:00
|
|
|
}
|
|
|
|
|
2012-07-30 04:29:41 +00:00
|
|
|
bool
|
|
|
|
nsPresContext::BidiEnabledExternal() const
|
|
|
|
{
|
|
|
|
return BidiEnabledInternal();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsPresContext::BidiEnabledInternal() const
|
|
|
|
{
|
|
|
|
return Document()->GetBidiEnabled();
|
|
|
|
}
|
|
|
|
|
2004-04-13 00:28:44 +00:00
|
|
|
void
|
2008-06-16 09:28:17 +00:00
|
|
|
nsPresContext::SetBidiEnabled() const
|
2001-03-09 03:13:03 +00:00
|
|
|
{
|
|
|
|
if (mShell) {
|
2004-08-02 04:52:55 +00:00
|
|
|
nsIDocument *doc = mShell->GetDocument();
|
2001-03-09 03:13:03 +00:00
|
|
|
if (doc) {
|
2008-06-16 09:28:17 +00:00
|
|
|
doc->SetBidiEnabled();
|
2001-03-09 03:13:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-07-29 19:41:39 +00:00
|
|
|
void
|
2012-08-22 15:56:38 +00:00
|
|
|
nsPresContext::SetBidi(uint32_t aSource, bool aForceRestyle)
|
2001-03-09 03:13:03 +00:00
|
|
|
{
|
2005-11-13 09:55:09 +00:00
|
|
|
// Don't do all this stuff unless the options have changed.
|
|
|
|
if (aSource == GetBidi()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-03-20 06:49:25 +00:00
|
|
|
NS_ASSERTION(!(aForceRestyle && (GetBidi() == 0)),
|
2005-11-13 09:55:09 +00:00
|
|
|
"ForceReflow on new prescontext");
|
|
|
|
|
2006-05-19 10:26:44 +00:00
|
|
|
Document()->SetBidiOptions(aSource);
|
2005-11-08 22:45:49 +00:00
|
|
|
if (IBMBIDI_TEXTDIRECTION_RTL == GET_BIDI_OPTION_DIRECTION(aSource)
|
|
|
|
|| IBMBIDI_NUMERAL_HINDI == GET_BIDI_OPTION_NUMERAL(aSource)) {
|
2008-06-16 09:28:17 +00:00
|
|
|
SetBidiEnabled();
|
2001-03-09 03:13:03 +00:00
|
|
|
}
|
2005-11-08 22:45:49 +00:00
|
|
|
if (IBMBIDI_TEXTTYPE_VISUAL == GET_BIDI_OPTION_TEXTTYPE(aSource)) {
|
2011-10-17 14:59:28 +00:00
|
|
|
SetVisualMode(true);
|
2001-03-09 03:13:03 +00:00
|
|
|
}
|
2005-11-08 22:45:49 +00:00
|
|
|
else if (IBMBIDI_TEXTTYPE_LOGICAL == GET_BIDI_OPTION_TEXTTYPE(aSource)) {
|
2011-10-17 14:59:28 +00:00
|
|
|
SetVisualMode(false);
|
2001-03-09 03:13:03 +00:00
|
|
|
}
|
|
|
|
else {
|
2004-08-09 21:19:15 +00:00
|
|
|
nsIDocument* doc = mShell->GetDocument();
|
|
|
|
if (doc) {
|
|
|
|
SetVisualMode(IsVisualCharset(doc->GetDocumentCharacterSet()));
|
|
|
|
}
|
2001-03-09 03:13:03 +00:00
|
|
|
}
|
2010-12-15 20:26:54 +00:00
|
|
|
if (aForceRestyle && mShell) {
|
|
|
|
// Reconstruct the root document element's frame and its children,
|
|
|
|
// because we need to trigger frame reconstruction for direction change.
|
2015-06-27 01:39:54 +00:00
|
|
|
mDocument->RebuildUserFontSet();
|
2010-12-15 20:26:54 +00:00
|
|
|
mShell->ReconstructFrames();
|
2001-03-09 03:13:03 +00:00
|
|
|
}
|
|
|
|
}
|
2005-11-08 22:45:49 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t
|
2005-11-08 22:45:49 +00:00
|
|
|
nsPresContext::GetBidi() const
|
|
|
|
{
|
2006-05-19 10:26:44 +00:00
|
|
|
return Document()->GetBidiOptions();
|
2005-11-08 22:45:49 +00:00
|
|
|
}
|
2010-06-01 02:19:35 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2010-03-17 17:10:57 +00:00
|
|
|
nsPresContext::IsTopLevelWindowInactive()
|
|
|
|
{
|
2013-11-20 19:18:25 +00:00
|
|
|
nsCOMPtr<nsIDocShellTreeItem> treeItem(mContainer);
|
2010-03-17 17:10:57 +00:00
|
|
|
if (!treeItem)
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2010-03-17 17:10:57 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> rootItem;
|
|
|
|
treeItem->GetRootTreeItem(getter_AddRefs(rootItem));
|
2014-01-10 02:03:47 +00:00
|
|
|
if (!rootItem) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-01-30 17:05:36 +00:00
|
|
|
nsCOMPtr<nsPIDOMWindowOuter> domWindow = rootItem->GetWindow();
|
2010-03-17 17:10:57 +00:00
|
|
|
|
|
|
|
return domWindow && !domWindow->IsActive();
|
|
|
|
}
|
|
|
|
|
2004-07-29 19:41:39 +00:00
|
|
|
nsITheme*
|
2004-07-31 23:15:21 +00:00
|
|
|
nsPresContext::GetTheme()
|
2001-12-17 22:51:39 +00:00
|
|
|
{
|
2009-02-26 20:02:00 +00:00
|
|
|
if (!sNoTheme && !mTheme) {
|
2001-12-17 22:51:39 +00:00
|
|
|
mTheme = do_GetService("@mozilla.org/chrome/chrome-native-theme;1");
|
|
|
|
if (!mTheme)
|
2011-10-17 14:59:28 +00:00
|
|
|
sNoTheme = true;
|
2001-12-17 22:51:39 +00:00
|
|
|
}
|
|
|
|
|
2004-07-29 19:41:39 +00:00
|
|
|
return mTheme;
|
2001-12-17 22:51:39 +00:00
|
|
|
}
|
|
|
|
|
2004-07-29 19:41:39 +00:00
|
|
|
void
|
2004-07-31 23:15:21 +00:00
|
|
|
nsPresContext::ThemeChanged()
|
2001-12-17 22:51:39 +00:00
|
|
|
{
|
2006-09-12 04:36:03 +00:00
|
|
|
if (!mPendingThemeChanged) {
|
2011-10-17 14:59:28 +00:00
|
|
|
sLookAndFeelChanged = true;
|
|
|
|
sThemeChanged = true;
|
2006-09-12 04:36:03 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIRunnable> ev =
|
2010-04-20 23:21:35 +00:00
|
|
|
NS_NewRunnableMethod(this, &nsPresContext::ThemeChangedInternal);
|
2006-09-12 04:36:03 +00:00
|
|
|
if (NS_SUCCEEDED(NS_DispatchToCurrentThread(ev))) {
|
2011-10-17 14:59:28 +00:00
|
|
|
mPendingThemeChanged = true;
|
2006-09-12 04:36:03 +00:00
|
|
|
}
|
2014-03-20 06:49:25 +00:00
|
|
|
}
|
2006-09-12 04:36:03 +00:00
|
|
|
}
|
|
|
|
|
2015-04-22 14:58:33 +00:00
|
|
|
static void
|
|
|
|
NotifyThemeChanged(TabParent* aTabParent, void* aArg)
|
|
|
|
{
|
|
|
|
aTabParent->ThemeChanged();
|
|
|
|
}
|
|
|
|
|
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.)
|
|
|
|
mozilla::image::SurfaceCache::DiscardAll();
|
2006-09-12 04:36:03 +00:00
|
|
|
}
|
2004-09-17 06:27:01 +00:00
|
|
|
|
2008-08-05 20:02:43 +00:00
|
|
|
// This will force the system metrics to be generated the next time they're used
|
|
|
|
nsCSSRuleProcessor::FreeSystemMetrics();
|
|
|
|
|
2014-10-08 21:27:04 +00:00
|
|
|
// Changes to system metrics can change media queries on them, or
|
|
|
|
// :-moz-system-metric selectors (which requires eRestyle_Subtree).
|
2008-02-08 19:52:46 +00:00
|
|
|
// Changes in theme can change system colors (whose changes are
|
|
|
|
// properly reflected in computed style data), system fonts (whose
|
|
|
|
// changes are not), and -moz-appearance (whose changes likewise are
|
|
|
|
// not), so we need to reflow.
|
2014-10-08 21:27:03 +00:00
|
|
|
MediaFeatureValuesChanged(eRestyle_Subtree, NS_STYLE_HINT_REFLOW);
|
2015-04-22 14:58:33 +00:00
|
|
|
|
|
|
|
// Recursively notify all remote leaf descendants that the
|
|
|
|
// system theme has changed.
|
|
|
|
nsContentUtils::CallOnAllRemoteChildren(mDocument->GetWindow(),
|
|
|
|
NotifyThemeChanged, nullptr);
|
2001-12-17 22:51:39 +00:00
|
|
|
}
|
|
|
|
|
2004-07-29 19:41:39 +00:00
|
|
|
void
|
2004-07-31 23:15:21 +00:00
|
|
|
nsPresContext::SysColorChanged()
|
2002-06-04 17:47:54 +00:00
|
|
|
{
|
2006-09-12 04:36:03 +00:00
|
|
|
if (!mPendingSysColorChanged) {
|
2011-10-17 14:59:28 +00:00
|
|
|
sLookAndFeelChanged = true;
|
2006-09-12 04:36:03 +00:00
|
|
|
nsCOMPtr<nsIRunnable> ev =
|
2010-04-20 23:21:35 +00:00
|
|
|
NS_NewRunnableMethod(this, &nsPresContext::SysColorChangedInternal);
|
2006-09-12 04:36:03 +00:00
|
|
|
if (NS_SUCCEEDED(NS_DispatchToCurrentThread(ev))) {
|
2011-10-17 14:59:28 +00:00
|
|
|
mPendingSysColorChanged = true;
|
2006-09-12 04:36:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsPresContext::SysColorChangedInternal()
|
|
|
|
{
|
2011-10-17 14:59:28 +00:00
|
|
|
mPendingSysColorChanged = false;
|
2014-03-20 06:49:25 +00:00
|
|
|
|
2011-09-09 02:27:13 +00:00
|
|
|
if (sLookAndFeelChanged) {
|
2002-06-04 17:47:54 +00:00
|
|
|
// Don't use the cached values for the system colors
|
2011-09-09 02:27:13 +00:00
|
|
|
LookAndFeel::Refresh();
|
2011-10-17 14:59:28 +00:00
|
|
|
sLookAndFeelChanged = false;
|
2002-06-04 17:47:54 +00:00
|
|
|
}
|
2014-03-20 06:49:25 +00:00
|
|
|
|
2002-06-04 17:47:54 +00:00
|
|
|
// Reset default background and foreground colors for the document since
|
|
|
|
// they may be using system colors
|
|
|
|
GetDocumentColorPreferences();
|
|
|
|
|
2008-02-08 19:52:46 +00:00
|
|
|
// The system color values are computed to colors in the style data,
|
|
|
|
// so normal style data comparison is sufficient here.
|
2014-10-08 21:26:59 +00:00
|
|
|
RebuildAllStyleData(nsChangeHint(0), nsRestyleHint(0));
|
2008-01-09 09:38:28 +00:00
|
|
|
}
|
|
|
|
|
2012-10-16 19:41:20 +00:00
|
|
|
void
|
|
|
|
nsPresContext::UIResolutionChanged()
|
|
|
|
{
|
|
|
|
if (!mPendingUIResolutionChanged) {
|
|
|
|
nsCOMPtr<nsIRunnable> ev =
|
|
|
|
NS_NewRunnableMethod(this, &nsPresContext::UIResolutionChangedInternal);
|
|
|
|
if (NS_SUCCEEDED(NS_DispatchToCurrentThread(ev))) {
|
|
|
|
mPendingUIResolutionChanged = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-08 05:39:28 +00:00
|
|
|
void
|
|
|
|
nsPresContext::UIResolutionChangedSync()
|
|
|
|
{
|
|
|
|
if (!mPendingUIResolutionChanged) {
|
|
|
|
mPendingUIResolutionChanged = true;
|
|
|
|
UIResolutionChangedInternal();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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) {
|
|
|
|
pc->UIResolutionChangedInternal();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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()
|
|
|
|
{
|
|
|
|
mPendingUIResolutionChanged = false;
|
|
|
|
|
2013-01-30 12:04:19 +00:00
|
|
|
mDeviceContext->CheckDPIChange();
|
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,
|
|
|
|
nullptr);
|
|
|
|
}
|
|
|
|
|
2013-07-17 15:39:19 +00:00
|
|
|
void
|
|
|
|
nsPresContext::EmulateMedium(const nsAString& aMediaType)
|
|
|
|
{
|
|
|
|
nsIAtom* previousMedium = Medium();
|
|
|
|
mIsEmulatingMedia = true;
|
|
|
|
|
|
|
|
nsAutoString mediaType;
|
|
|
|
nsContentUtils::ASCIIToLower(aMediaType, mediaType);
|
|
|
|
|
|
|
|
mMediaEmulated = do_GetAtom(mediaType);
|
|
|
|
if (mMediaEmulated != previousMedium && mShell) {
|
2014-10-08 21:27:03 +00:00
|
|
|
MediaFeatureValuesChanged(nsRestyleHint(0), nsChangeHint(0));
|
2013-07-17 15:39:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsPresContext::StopEmulatingMedium()
|
|
|
|
{
|
|
|
|
nsIAtom* previousMedium = Medium();
|
|
|
|
mIsEmulatingMedia = false;
|
|
|
|
if (Medium() != previousMedium) {
|
2014-10-08 21:27:03 +00:00
|
|
|
MediaFeatureValuesChanged(nsRestyleHint(0), nsChangeHint(0));
|
2013-07-17 15:39:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-09 09:38:28 +00:00
|
|
|
void
|
2014-10-08 21:26:57 +00:00
|
|
|
nsPresContext::RebuildAllStyleData(nsChangeHint aExtraHint,
|
|
|
|
nsRestyleHint aRestyleHint)
|
2008-01-09 09:38:28 +00:00
|
|
|
{
|
|
|
|
if (!mShell) {
|
|
|
|
// We must have been torn down. Nothing to do here.
|
|
|
|
return;
|
|
|
|
}
|
2008-11-25 23:22:38 +00:00
|
|
|
|
2012-10-26 17:04:20 +00:00
|
|
|
mUsesRootEMUnits = false;
|
2015-03-06 08:44:14 +00:00
|
|
|
mUsesExChUnits = false;
|
2012-10-19 23:21:06 +00:00
|
|
|
mUsesViewportUnits = false;
|
2015-06-27 01:39:54 +00:00
|
|
|
mDocument->RebuildUserFontSet();
|
2014-06-12 01:12:00 +00:00
|
|
|
RebuildCounterStyles();
|
2008-11-25 23:22:38 +00:00
|
|
|
|
2014-10-08 21:26:57 +00:00
|
|
|
RestyleManager()->RebuildAllStyleData(aExtraHint, aRestyleHint);
|
2008-01-09 09:38:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-10-08 21:27:02 +00:00
|
|
|
nsPresContext::PostRebuildAllStyleDataEvent(nsChangeHint aExtraHint,
|
|
|
|
nsRestyleHint aRestyleHint)
|
2008-01-09 09:38:28 +00:00
|
|
|
{
|
|
|
|
if (!mShell) {
|
|
|
|
// We must have been torn down. Nothing to do here.
|
|
|
|
return;
|
|
|
|
}
|
2014-10-08 21:27:02 +00:00
|
|
|
RestyleManager()->PostRebuildAllStyleDataEvent(aExtraHint, aRestyleHint);
|
2004-07-29 19:41:39 +00:00
|
|
|
}
|
|
|
|
|
2016-02-23 16:10:00 +00:00
|
|
|
struct MediaFeatureHints
|
|
|
|
{
|
|
|
|
nsRestyleHint restyleHint;
|
|
|
|
nsChangeHint changeHint;
|
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
MediaFeatureValuesChangedAllDocumentsCallback(nsIDocument* aDocument, void* aHints)
|
|
|
|
{
|
|
|
|
MediaFeatureHints* hints = static_cast<MediaFeatureHints*>(aHints);
|
|
|
|
if (nsIPresShell* shell = aDocument->GetShell()) {
|
|
|
|
if (nsPresContext* pc = shell->GetPresContext()) {
|
|
|
|
pc->MediaFeatureValuesChangedAllDocuments(hints->restyleHint,
|
|
|
|
hints->changeHint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsPresContext::MediaFeatureValuesChangedAllDocuments(nsRestyleHint aRestyleHint,
|
|
|
|
nsChangeHint aChangeHint)
|
|
|
|
{
|
|
|
|
MediaFeatureValuesChanged(aRestyleHint, aChangeHint);
|
|
|
|
MediaFeatureHints hints = {
|
|
|
|
aRestyleHint,
|
|
|
|
aChangeHint
|
|
|
|
};
|
|
|
|
|
|
|
|
mDocument->EnumerateSubDocuments(MediaFeatureValuesChangedAllDocumentsCallback,
|
|
|
|
&hints);
|
|
|
|
}
|
|
|
|
|
2008-07-26 16:14:48 +00:00
|
|
|
void
|
2014-10-08 21:27:03 +00:00
|
|
|
nsPresContext::MediaFeatureValuesChanged(nsRestyleHint aRestyleHint,
|
2012-11-09 06:40:41 +00:00
|
|
|
nsChangeHint aChangeHint)
|
2008-07-26 16:14:48 +00:00
|
|
|
{
|
2011-10-17 14:59:28 +00:00
|
|
|
mPendingMediaFeatureValuesChanged = false;
|
2012-10-19 23:21:06 +00:00
|
|
|
|
|
|
|
// MediumFeaturesChanged updates the applied rules, so it always gets called.
|
2016-02-24 07:01:11 +00:00
|
|
|
if (mShell) {
|
|
|
|
// XXXheycam ServoStyleSets don't support responding to medium
|
|
|
|
// changes yet.
|
|
|
|
if (mShell->StyleSet()->IsGecko()) {
|
|
|
|
if (mShell->StyleSet()->AsGecko()->MediumFeaturesChanged()) {
|
|
|
|
aRestyleHint |= eRestyle_Subtree;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
NS_ERROR("stylo: ServoStyleSets don't support responding to medium "
|
|
|
|
"changes yet");
|
|
|
|
}
|
2014-10-08 21:27:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mUsesViewportUnits && mPendingViewportChange) {
|
|
|
|
// Rebuild all style data without rerunning selector matching.
|
|
|
|
aRestyleHint |= eRestyle_ForceDescendants;
|
|
|
|
}
|
2012-10-19 23:21:06 +00:00
|
|
|
|
2014-10-08 21:27:03 +00:00
|
|
|
if (aRestyleHint || aChangeHint) {
|
|
|
|
RebuildAllStyleData(aChangeHint, aRestyleHint);
|
2008-07-26 16:14:48 +00:00
|
|
|
}
|
2011-04-22 03:17:31 +00:00
|
|
|
|
2012-10-19 23:21:06 +00:00
|
|
|
mPendingViewportChange = false;
|
|
|
|
|
2014-08-06 04:44:59 +00:00
|
|
|
if (mDocument->IsBeingUsedAsImage()) {
|
2014-10-03 18:15:25 +00:00
|
|
|
MOZ_ASSERT(PR_CLIST_IS_EMPTY(mDocument->MediaQueryLists()));
|
2011-04-22 03:17:31 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-05-11 22:07:49 +00:00
|
|
|
mDocument->NotifyMediaFeatureValuesChanged();
|
|
|
|
|
2014-08-06 04:44:59 +00:00
|
|
|
MOZ_ASSERT(nsContentUtils::IsSafeToRunScript());
|
|
|
|
|
2011-04-22 03:17:31 +00:00
|
|
|
// Media query list listeners should be notified from a queued task
|
|
|
|
// (in HTML5 terms), although we also want to notify them on certain
|
|
|
|
// flushes. (We're already running off an event.)
|
|
|
|
//
|
|
|
|
// Note that we do this after the new style from media queries in
|
|
|
|
// style sheets has been computed.
|
|
|
|
|
2014-10-03 18:15:25 +00:00
|
|
|
if (!PR_CLIST_IS_EMPTY(mDocument->MediaQueryLists())) {
|
2011-04-22 03:17:31 +00:00
|
|
|
// We build a list of all the notifications we're going to send
|
|
|
|
// before we send any of them. (The spec says the notifications
|
|
|
|
// should be a queued task, so any removals that happen during the
|
|
|
|
// notifications shouldn't affect what gets notified.) Furthermore,
|
|
|
|
// we hold strong pointers to everything we're going to make
|
|
|
|
// notification calls to, since each notification involves calling
|
|
|
|
// arbitrary script that might otherwise destroy these objects, or,
|
|
|
|
// for that matter, |this|.
|
|
|
|
//
|
|
|
|
// Note that we intentionally send the notifications to media query
|
|
|
|
// list in the order they were created and, for each list, to the
|
|
|
|
// listeners in the order added.
|
2015-07-13 06:46:04 +00:00
|
|
|
nsTArray<MediaQueryList::HandleChangeData> notifyList;
|
2014-10-03 18:15:25 +00:00
|
|
|
for (PRCList *l = PR_LIST_HEAD(mDocument->MediaQueryLists());
|
|
|
|
l != mDocument->MediaQueryLists(); l = PR_NEXT_LINK(l)) {
|
2013-12-16 14:03:19 +00:00
|
|
|
MediaQueryList *mql = static_cast<MediaQueryList*>(l);
|
2011-04-22 03:17:31 +00:00
|
|
|
mql->MediumFeaturesChanged(notifyList);
|
|
|
|
}
|
|
|
|
|
2011-04-23 20:19:01 +00:00
|
|
|
if (!notifyList.IsEmpty()) {
|
2012-08-22 15:56:38 +00:00
|
|
|
for (uint32_t i = 0, i_end = notifyList.Length(); i != i_end; ++i) {
|
2014-08-07 18:44:03 +00:00
|
|
|
nsAutoMicroTask mt;
|
|
|
|
MediaQueryList::HandleChangeData &d = notifyList[i];
|
|
|
|
ErrorResult result;
|
|
|
|
d.callback->Call(*d.mql, result);
|
2011-04-23 20:19:01 +00:00
|
|
|
}
|
2011-04-22 03:17:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NOTE: When |notifyList| goes out of scope, our destructor could run.
|
|
|
|
}
|
2008-07-26 16:14:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsPresContext::PostMediaFeatureValuesChangedEvent()
|
|
|
|
{
|
2011-04-22 03:17:31 +00:00
|
|
|
// FIXME: We should probably replace this event with use of
|
|
|
|
// nsRefreshDriver::AddStyleFlushObserver (except the pres shell would
|
|
|
|
// need to track whether it's been added).
|
2008-07-26 16:14:48 +00:00
|
|
|
if (!mPendingMediaFeatureValuesChanged) {
|
|
|
|
nsCOMPtr<nsIRunnable> ev =
|
2010-04-20 23:21:35 +00:00
|
|
|
NS_NewRunnableMethod(this, &nsPresContext::HandleMediaFeatureValuesChangedEvent);
|
2008-07-26 16:14:48 +00:00
|
|
|
if (NS_SUCCEEDED(NS_DispatchToCurrentThread(ev))) {
|
2011-10-17 14:59:28 +00:00
|
|
|
mPendingMediaFeatureValuesChanged = true;
|
2011-12-15 04:42:15 +00:00
|
|
|
mDocument->SetNeedStyleFlush();
|
2008-07-26 16:14:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsPresContext::HandleMediaFeatureValuesChangedEvent()
|
|
|
|
{
|
|
|
|
// Null-check mShell in case the shell has been destroyed (and the
|
|
|
|
// event is the only thing holding the pres context alive).
|
|
|
|
if (mPendingMediaFeatureValuesChanged && mShell) {
|
2014-10-08 21:27:03 +00:00
|
|
|
MediaFeatureValuesChanged(nsRestyleHint(0));
|
2008-07-26 16:14:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-23 16:10:00 +00:00
|
|
|
static void
|
|
|
|
NotifyTabSizeModeChanged(TabParent* aTab, void* aArg)
|
|
|
|
{
|
|
|
|
nsSizeMode* sizeMode = static_cast<nsSizeMode*>(aArg);
|
|
|
|
aTab->SizeModeChanged(*sizeMode);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsPresContext::SizeModeChanged(nsSizeMode aSizeMode)
|
|
|
|
{
|
|
|
|
if (HasCachedStyleData()) {
|
|
|
|
nsContentUtils::CallOnAllRemoteChildren(mDocument->GetWindow(),
|
|
|
|
NotifyTabSizeModeChanged,
|
|
|
|
&aSizeMode);
|
|
|
|
MediaFeatureValuesChangedAllDocuments(eRestyle_Subtree,
|
|
|
|
NS_STYLE_HINT_REFLOW);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
/* virtual */ bool
|
2015-08-18 22:41:24 +00:00
|
|
|
nsPresContext::HasAuthorSpecifiedRules(const nsIFrame *aFrame,
|
|
|
|
uint32_t ruleTypeMask) const
|
2007-10-08 23:11:01 +00:00
|
|
|
{
|
2009-01-06 19:17:05 +00:00
|
|
|
return
|
2013-02-16 05:38:33 +00:00
|
|
|
nsRuleNode::HasAuthorSpecifiedRules(aFrame->StyleContext(),
|
2009-06-16 22:05:12 +00:00
|
|
|
ruleTypeMask,
|
|
|
|
UseDocumentColors());
|
2007-10-08 23:11:01 +00:00
|
|
|
}
|
2008-09-18 09:47:21 +00:00
|
|
|
|
2008-11-25 23:22:38 +00:00
|
|
|
gfxUserFontSet*
|
2015-06-27 01:39:54 +00:00
|
|
|
nsPresContext::GetUserFontSet()
|
2008-12-04 16:09:53 +00:00
|
|
|
{
|
2015-06-27 01:39:54 +00:00
|
|
|
return mDocument->GetUserFontSet();
|
2008-10-01 03:01:53 +00:00
|
|
|
}
|
|
|
|
|
2008-12-08 16:08:05 +00:00
|
|
|
void
|
2015-03-06 08:44:23 +00:00
|
|
|
nsPresContext::UserFontSetUpdated(gfxUserFontEntry* aUpdatedFont)
|
2008-12-08 16:08:05 +00:00
|
|
|
{
|
|
|
|
if (!mShell)
|
|
|
|
return;
|
|
|
|
|
2015-03-06 08:44:23 +00:00
|
|
|
bool usePlatformFontList = true;
|
2015-05-13 05:11:25 +00:00
|
|
|
#if defined(MOZ_WIDGET_GTK)
|
|
|
|
usePlatformFontList = gfxPlatformGtk::UseFcFontList();
|
|
|
|
#elif defined(MOZ_WIDGET_QT)
|
|
|
|
usePlatformFontList = false;
|
2015-03-06 08:44:23 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// xxx - until the Linux platform font list is always used, use full
|
|
|
|
// restyle to force updates with gfxPangoFontGroup usage
|
|
|
|
// Note: this method is called without a font when rules in the userfont set
|
|
|
|
// are updated, which may occur during reflow as a result of the lazy
|
|
|
|
// initialization of the userfont set. It would be better to avoid a full
|
|
|
|
// restyle but until this method is only called outside of reflow, schedule a
|
|
|
|
// full restyle in these cases.
|
|
|
|
if (!usePlatformFontList || !aUpdatedFont) {
|
|
|
|
PostRebuildAllStyleDataEvent(NS_STYLE_HINT_REFLOW, eRestyle_ForceDescendants);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Special case - if either the 'ex' or 'ch' units are used, these
|
|
|
|
// depend upon font metrics. Updating this information requires
|
|
|
|
// rebuilding the rule tree from the top, avoiding the reuse of cached
|
|
|
|
// data even when no style rules have changed.
|
|
|
|
if (UsesExChUnits()) {
|
2015-03-10 04:55:11 +00:00
|
|
|
PostRebuildAllStyleDataEvent(nsChangeHint(0), eRestyle_ForceDescendants);
|
2015-03-06 08:44:23 +00:00
|
|
|
}
|
2008-12-08 16:08:05 +00:00
|
|
|
|
2015-03-06 08:44:23 +00:00
|
|
|
// Iterate over the frame tree looking for frames associated with the
|
|
|
|
// downloadable font family in question. If a frame's nsStyleFont has
|
|
|
|
// the name, check the font group associated with the metrics to see if
|
|
|
|
// it contains that specific font (i.e. the one chosen within the family
|
|
|
|
// given the weight, width, and slant from the nsStyleFont). If it does,
|
|
|
|
// mark that frame dirty and skip inspecting its descendants.
|
2015-04-08 03:01:38 +00:00
|
|
|
nsIFrame* root = mShell->GetRootFrame();
|
|
|
|
if (root) {
|
|
|
|
nsFontFaceUtils::MarkDirtyForFontChange(root, aUpdatedFont);
|
|
|
|
}
|
2008-12-08 16:08:05 +00:00
|
|
|
}
|
|
|
|
|
2014-06-12 01:12:00 +00:00
|
|
|
void
|
|
|
|
nsPresContext::FlushCounterStyles()
|
|
|
|
{
|
|
|
|
if (!mShell) {
|
|
|
|
return; // we've been torn down
|
|
|
|
}
|
|
|
|
if (mCounterStyleManager->IsInitial()) {
|
|
|
|
// Still in its initial state, no need to clean.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mCounterStylesDirty) {
|
|
|
|
bool changed = mCounterStyleManager->NotifyRuleChanged();
|
|
|
|
if (changed) {
|
|
|
|
PresShell()->NotifyCounterStylesAreDirty();
|
2014-10-08 21:27:03 +00:00
|
|
|
PostRebuildAllStyleDataEvent(NS_STYLE_HINT_REFLOW,
|
|
|
|
eRestyle_ForceDescendants);
|
2014-06-12 01:12:00 +00:00
|
|
|
}
|
|
|
|
mCounterStylesDirty = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsPresContext::RebuildCounterStyles()
|
|
|
|
{
|
|
|
|
if (mCounterStyleManager->IsInitial()) {
|
|
|
|
// Still in its initial state, no need to reset.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mCounterStylesDirty = true;
|
|
|
|
mDocument->SetNeedStyleFlush();
|
|
|
|
if (!mPostedFlushCounterStyles) {
|
|
|
|
nsCOMPtr<nsIRunnable> ev =
|
|
|
|
NS_NewRunnableMethod(this, &nsPresContext::HandleRebuildCounterStyles);
|
|
|
|
if (NS_SUCCEEDED(NS_DispatchToCurrentThread(ev))) {
|
|
|
|
mPostedFlushCounterStyles = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-22 16:35:54 +00:00
|
|
|
void
|
|
|
|
nsPresContext::NotifyMissingFonts()
|
|
|
|
{
|
|
|
|
if (mMissingFonts) {
|
|
|
|
mMissingFonts->Flush();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-11 08:00:33 +00:00
|
|
|
void
|
2009-12-31 15:56:33 +00:00
|
|
|
nsPresContext::EnsureSafeToHandOutCSSRules()
|
|
|
|
{
|
2016-02-24 07:01:11 +00:00
|
|
|
nsStyleSet* styleSet = mShell->StyleSet()->GetAsGecko();
|
|
|
|
if (!styleSet) {
|
|
|
|
// ServoStyleSets do not need to handle copy-on-write style sheet
|
|
|
|
// innards like with CSSStyleSheets.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!styleSet->EnsureUniqueInnerOnCSSSheets()) {
|
2009-12-31 15:56:33 +00:00
|
|
|
// Nothing to do.
|
2013-11-11 08:00:33 +00:00
|
|
|
return;
|
2009-12-31 15:56:33 +00:00
|
|
|
}
|
|
|
|
|
2014-10-08 21:26:57 +00:00
|
|
|
RebuildAllStyleData(nsChangeHint(0), eRestyle_Subtree);
|
2009-12-31 15:56:33 +00:00
|
|
|
}
|
|
|
|
|
2008-09-18 09:47:21 +00:00
|
|
|
void
|
2012-10-19 04:50:34 +00:00
|
|
|
nsPresContext::FireDOMPaintEvent(nsInvalidateRequestList* aList)
|
2008-09-18 09:47:21 +00:00
|
|
|
{
|
2016-01-30 17:05:36 +00:00
|
|
|
nsPIDOMWindowInner* ourWindow = mDocument->GetInnerWindow();
|
2008-10-15 21:06:32 +00:00
|
|
|
if (!ourWindow)
|
2008-09-18 09:47:21 +00:00
|
|
|
return;
|
2008-10-15 21:06:32 +00:00
|
|
|
|
2013-03-09 11:34:29 +00:00
|
|
|
nsCOMPtr<EventTarget> dispatchTarget = do_QueryInterface(ourWindow);
|
|
|
|
nsCOMPtr<EventTarget> eventTarget = dispatchTarget;
|
2012-08-29 05:47:18 +00:00
|
|
|
if (!IsChrome() && !mSendAfterPaintToContent) {
|
|
|
|
// Don't tell the window about this event, it should not know that
|
|
|
|
// something happened in a subdocument. Tell only the chrome event handler.
|
|
|
|
// (Events sent to the window get propagated to the chrome event handler
|
|
|
|
// automatically.)
|
|
|
|
dispatchTarget = do_QueryInterface(ourWindow->GetParentTarget());
|
|
|
|
if (!dispatchTarget) {
|
|
|
|
return;
|
2008-10-18 20:10:19 +00:00
|
|
|
}
|
2008-09-18 09:47:21 +00:00
|
|
|
}
|
|
|
|
// Events sent to the window get propagated to the chrome event handler
|
|
|
|
// automatically.
|
2015-08-12 11:39:31 +00:00
|
|
|
//
|
2009-09-04 04:49:18 +00:00
|
|
|
// This will empty our list in case dispatching the event causes more damage
|
|
|
|
// (hopefully it won't, or we're likely to get an infinite loop! At least
|
|
|
|
// it won't be blocking app execution though).
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<NotifyPaintEvent> event =
|
2015-09-10 01:40:06 +00:00
|
|
|
NS_NewDOMNotifyPaintEvent(eventTarget, this, nullptr, eAfterPaint, aList);
|
2008-09-18 09:47:21 +00:00
|
|
|
|
|
|
|
// Even if we're not telling the window about the event (so eventTarget is
|
|
|
|
// the chrome event handler, not the window), the window is still
|
|
|
|
// logically the event target.
|
2012-06-10 23:44:50 +00:00
|
|
|
event->SetTarget(eventTarget);
|
|
|
|
event->SetTrusted(true);
|
2015-08-12 11:39:31 +00:00
|
|
|
EventDispatcher::DispatchDOMEvent(dispatchTarget, nullptr,
|
|
|
|
static_cast<Event*>(event), this, nullptr);
|
2008-09-18 09:47:21 +00:00
|
|
|
}
|
|
|
|
|
2012-08-29 05:47:18 +00:00
|
|
|
static bool
|
|
|
|
MayHavePaintEventListenerSubdocumentCallback(nsIDocument* aDocument, void* aData)
|
|
|
|
{
|
|
|
|
bool *result = static_cast<bool*>(aData);
|
|
|
|
nsIPresShell* shell = aDocument->GetShell();
|
|
|
|
if (shell) {
|
|
|
|
nsPresContext* pc = shell->GetPresContext();
|
|
|
|
if (pc) {
|
2012-08-29 05:47:18 +00:00
|
|
|
*result = pc->MayHavePaintEventListenerInSubDocument();
|
2012-08-29 05:47:18 +00:00
|
|
|
|
|
|
|
// If we found a paint event listener, then we can stop enumerating
|
|
|
|
// sub documents.
|
|
|
|
return !*result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
static bool
|
2016-01-30 17:05:36 +00:00
|
|
|
MayHavePaintEventListener(nsPIDOMWindowInner* aInnerWindow)
|
2008-10-15 21:06:32 +00:00
|
|
|
{
|
|
|
|
if (!aInnerWindow)
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2008-10-15 21:06:32 +00:00
|
|
|
if (aInnerWindow->HasPaintEventListeners())
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2008-10-15 21:06:32 +00:00
|
|
|
|
2013-04-19 22:18:33 +00:00
|
|
|
EventTarget* parentTarget = aInnerWindow->GetParentTarget();
|
2010-06-16 11:43:36 +00:00
|
|
|
if (!parentTarget)
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2008-10-15 21:06:32 +00:00
|
|
|
|
2014-03-17 06:56:53 +00:00
|
|
|
EventListenerManager* manager = nullptr;
|
2013-10-22 23:32:04 +00:00
|
|
|
if ((manager = parentTarget->GetExistingListenerManager()) &&
|
2010-06-16 11:43:36 +00:00
|
|
|
manager->MayHavePaintEventListener()) {
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2010-06-16 11:43:36 +00:00
|
|
|
}
|
|
|
|
|
2010-05-18 12:28:37 +00:00
|
|
|
nsCOMPtr<nsINode> node;
|
2010-06-16 11:43:36 +00:00
|
|
|
if (parentTarget != aInnerWindow->GetChromeEventHandler()) {
|
|
|
|
nsCOMPtr<nsIInProcessContentFrameMessageManager> mm =
|
|
|
|
do_QueryInterface(parentTarget);
|
|
|
|
if (mm) {
|
|
|
|
node = mm->GetOwnerContent();
|
2010-05-18 12:28:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!node) {
|
2010-06-16 11:43:36 +00:00
|
|
|
node = do_QueryInterface(parentTarget);
|
2010-05-18 12:28:37 +00:00
|
|
|
}
|
2008-10-15 21:06:32 +00:00
|
|
|
if (node)
|
2011-10-18 10:53:36 +00:00
|
|
|
return MayHavePaintEventListener(node->OwnerDoc()->GetInnerWindow());
|
2008-10-15 21:06:32 +00:00
|
|
|
|
2016-01-30 17:05:36 +00:00
|
|
|
nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface(parentTarget);
|
2008-10-15 21:06:32 +00:00
|
|
|
if (window)
|
|
|
|
return MayHavePaintEventListener(window);
|
|
|
|
|
2010-07-01 04:04:29 +00:00
|
|
|
nsCOMPtr<nsPIWindowRoot> root = do_QueryInterface(parentTarget);
|
2013-04-19 22:18:33 +00:00
|
|
|
EventTarget* tabChildGlobal;
|
2010-07-01 04:04:29 +00:00
|
|
|
return root &&
|
|
|
|
(tabChildGlobal = root->GetParentTarget()) &&
|
2013-10-22 23:32:04 +00:00
|
|
|
(manager = tabChildGlobal->GetExistingListenerManager()) &&
|
2010-07-01 04:04:29 +00:00
|
|
|
manager->MayHavePaintEventListener();
|
2008-10-15 21:06:32 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2009-09-04 04:49:18 +00:00
|
|
|
nsPresContext::MayHavePaintEventListener()
|
|
|
|
{
|
|
|
|
return ::MayHavePaintEventListener(mDocument->GetInnerWindow());
|
|
|
|
}
|
|
|
|
|
2012-08-29 05:47:18 +00:00
|
|
|
bool
|
|
|
|
nsPresContext::MayHavePaintEventListenerInSubDocument()
|
|
|
|
{
|
|
|
|
if (MayHavePaintEventListener()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool result = false;
|
|
|
|
mDocument->EnumerateSubDocuments(MayHavePaintEventListenerSubdocumentCallback, &result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2012-08-29 05:48:44 +00:00
|
|
|
void
|
|
|
|
nsPresContext::NotifyInvalidation(uint32_t aFlags)
|
|
|
|
{
|
|
|
|
nsIFrame* rootFrame = PresShell()->FrameManager()->GetRootFrame();
|
|
|
|
NotifyInvalidation(rootFrame->GetVisualOverflowRect(), aFlags);
|
|
|
|
mAllInvalidated = true;
|
|
|
|
}
|
|
|
|
|
2012-08-29 05:47:18 +00:00
|
|
|
void
|
|
|
|
nsPresContext::NotifyInvalidation(const nsIntRect& aRect, uint32_t aFlags)
|
|
|
|
{
|
2016-02-11 22:35:17 +00:00
|
|
|
// Prevent values from overflow after DevPixelsToAppUnits().
|
|
|
|
//
|
|
|
|
// DevPixelsTopAppUnits() will multiple a factor (60) to the value,
|
|
|
|
// it may make the result value over the edge (overflow) of max or
|
|
|
|
// min value of int32_t. Compute the max sized dev pixel rect that
|
|
|
|
// we can support and intersect with it.
|
|
|
|
nsIntRect clampedRect = nsIntRect::MaxIntRect();
|
|
|
|
clampedRect.ScaleInverseRoundIn(AppUnitsPerDevPixel());
|
|
|
|
|
|
|
|
clampedRect = clampedRect.Intersect(aRect);
|
|
|
|
|
|
|
|
nsRect rect(DevPixelsToAppUnits(clampedRect.x),
|
|
|
|
DevPixelsToAppUnits(clampedRect.y),
|
|
|
|
DevPixelsToAppUnits(clampedRect.width),
|
|
|
|
DevPixelsToAppUnits(clampedRect.height));
|
2012-08-29 05:47:18 +00:00
|
|
|
NotifyInvalidation(rect, aFlags);
|
|
|
|
}
|
|
|
|
|
2008-09-18 09:47:21 +00:00
|
|
|
void
|
2012-08-22 15:56:38 +00:00
|
|
|
nsPresContext::NotifyInvalidation(const nsRect& aRect, uint32_t aFlags)
|
2008-09-18 09:47:21 +00:00
|
|
|
{
|
2014-02-10 02:14:38 +00:00
|
|
|
MOZ_ASSERT(GetContainerWeak(), "Invalidation in detached pres context");
|
2014-02-03 23:47:57 +00:00
|
|
|
|
2008-10-15 21:06:32 +00:00
|
|
|
// If there is no paint event listener, then we don't need to fire
|
|
|
|
// the asynchronous event. We don't even need to record invalidation.
|
|
|
|
// MayHavePaintEventListener is pretty cheap and we could make it
|
|
|
|
// even cheaper by providing a more efficient
|
|
|
|
// nsPIDOMWindow::GetListenerManager.
|
2014-03-20 06:49:25 +00:00
|
|
|
|
2012-08-29 05:48:44 +00:00
|
|
|
if (mAllInvalidated) {
|
|
|
|
return;
|
|
|
|
}
|
2008-09-18 09:47:21 +00:00
|
|
|
|
2011-01-15 09:40:33 +00:00
|
|
|
nsPresContext* pc;
|
2012-05-04 05:00:57 +00:00
|
|
|
for (pc = this; pc; pc = pc->GetParentPresContext()) {
|
2011-01-15 09:40:33 +00:00
|
|
|
if (pc->mFireAfterPaintEvents)
|
|
|
|
break;
|
2011-10-17 14:59:28 +00:00
|
|
|
pc->mFireAfterPaintEvents = true;
|
2011-01-15 09:40:33 +00:00
|
|
|
}
|
|
|
|
if (!pc) {
|
|
|
|
nsRootPresContext* rpc = GetRootPresContext();
|
|
|
|
if (rpc) {
|
|
|
|
rpc->EnsureEventualDidPaintEvent();
|
|
|
|
}
|
2008-09-18 09:47:21 +00:00
|
|
|
}
|
|
|
|
|
2009-09-04 04:49:18 +00:00
|
|
|
nsInvalidateRequestList::Request* request =
|
2012-10-19 04:50:34 +00:00
|
|
|
mInvalidateRequestsSinceLastPaint.mRequests.AppendElement();
|
2009-09-04 04:49:18 +00:00
|
|
|
if (!request)
|
|
|
|
return;
|
|
|
|
|
|
|
|
request->mRect = aRect;
|
|
|
|
request->mFlags = aFlags;
|
2008-09-18 09:47:21 +00:00
|
|
|
}
|
2008-12-29 15:07:36 +00:00
|
|
|
|
2014-03-20 06:49:25 +00:00
|
|
|
/* static */ void
|
2012-08-29 05:47:18 +00:00
|
|
|
nsPresContext::NotifySubDocInvalidation(ContainerLayer* aContainer,
|
|
|
|
const nsIntRegion& aRegion)
|
|
|
|
{
|
2014-03-20 06:49:25 +00:00
|
|
|
ContainerLayerPresContext *data =
|
2012-08-29 05:47:18 +00:00
|
|
|
static_cast<ContainerLayerPresContext*>(
|
|
|
|
aContainer->GetUserData(&gNotifySubDocInvalidationData));
|
|
|
|
if (!data) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-11-29 07:07:55 +00:00
|
|
|
nsIntPoint topLeft = aContainer->GetVisibleRegion().ToUnknownRegion().GetBounds().TopLeft();
|
2012-08-29 05:47:18 +00:00
|
|
|
|
2016-01-19 01:20:59 +00:00
|
|
|
for (auto iter = aRegion.RectIter(); !iter.Done(); iter.Next()) {
|
|
|
|
nsIntRect rect(iter.Get());
|
2012-08-29 05:47:18 +00:00
|
|
|
//PresContext coordinate space is relative to the start of our visible
|
|
|
|
// region. Is this really true? This feels like the wrong way to get the right
|
|
|
|
// answer.
|
|
|
|
rect.MoveBy(-topLeft);
|
|
|
|
data->mPresContext->NotifyInvalidation(rect, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-14 11:33:03 +00:00
|
|
|
void
|
|
|
|
nsPresContext::SetNotifySubDocInvalidationData(ContainerLayer* aContainer)
|
|
|
|
{
|
|
|
|
ContainerLayerPresContext* pres = new ContainerLayerPresContext;
|
|
|
|
pres->mPresContext = this;
|
|
|
|
aContainer->SetUserData(&gNotifySubDocInvalidationData, pres);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ void
|
|
|
|
nsPresContext::ClearNotifySubDocInvalidationData(ContainerLayer* aContainer)
|
|
|
|
{
|
|
|
|
aContainer->SetUserData(&gNotifySubDocInvalidationData, nullptr);
|
|
|
|
}
|
|
|
|
|
2012-10-19 04:50:34 +00:00
|
|
|
struct NotifyDidPaintSubdocumentCallbackClosure {
|
|
|
|
uint32_t mFlags;
|
|
|
|
bool mNeedsAnotherDidPaintNotification;
|
|
|
|
};
|
2011-09-29 06:19:26 +00:00
|
|
|
static bool
|
2011-01-15 09:40:33 +00:00
|
|
|
NotifyDidPaintSubdocumentCallback(nsIDocument* aDocument, void* aData)
|
|
|
|
{
|
2012-10-19 04:50:34 +00:00
|
|
|
NotifyDidPaintSubdocumentCallbackClosure* closure =
|
|
|
|
static_cast<NotifyDidPaintSubdocumentCallbackClosure*>(aData);
|
2011-01-15 09:40:33 +00:00
|
|
|
nsIPresShell* shell = aDocument->GetShell();
|
|
|
|
if (shell) {
|
|
|
|
nsPresContext* pc = shell->GetPresContext();
|
|
|
|
if (pc) {
|
2012-10-19 04:50:34 +00:00
|
|
|
pc->NotifyDidPaintForSubtree(closure->mFlags);
|
|
|
|
if (pc->IsDOMPaintEventPending()) {
|
|
|
|
closure->mNeedsAnotherDidPaintNotification = true;
|
|
|
|
}
|
2011-01-15 09:40:33 +00:00
|
|
|
}
|
|
|
|
}
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2011-01-15 09:40:33 +00:00
|
|
|
}
|
|
|
|
|
2012-10-19 04:50:34 +00:00
|
|
|
class DelayedFireDOMPaintEvent : public nsRunnable {
|
|
|
|
public:
|
|
|
|
DelayedFireDOMPaintEvent(nsPresContext* aPresContext,
|
|
|
|
nsInvalidateRequestList* aList)
|
|
|
|
: mPresContext(aPresContext)
|
|
|
|
{
|
2014-02-03 23:47:57 +00:00
|
|
|
MOZ_ASSERT(mPresContext->GetContainerWeak(),
|
|
|
|
"DOMPaintEvent requested for a detached pres context");
|
2012-10-19 04:50:34 +00:00
|
|
|
mList.TakeFrom(aList);
|
|
|
|
}
|
2015-03-21 16:28:04 +00:00
|
|
|
NS_IMETHOD Run() override
|
2012-10-19 04:50:34 +00:00
|
|
|
{
|
2014-02-03 23:47:57 +00:00
|
|
|
// The pres context might have been detached during the delay -
|
|
|
|
// that's fine, just don't fire the event.
|
|
|
|
if (mPresContext->GetContainerWeak()) {
|
|
|
|
mPresContext->FireDOMPaintEvent(&mList);
|
|
|
|
}
|
2012-10-19 04:50:34 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<nsPresContext> mPresContext;
|
2012-10-19 04:50:34 +00:00
|
|
|
nsInvalidateRequestList mList;
|
|
|
|
};
|
|
|
|
|
2011-01-15 09:40:33 +00:00
|
|
|
void
|
2012-10-19 04:50:34 +00:00
|
|
|
nsPresContext::NotifyDidPaintForSubtree(uint32_t aFlags)
|
2011-01-15 09:40:33 +00:00
|
|
|
{
|
2012-09-27 15:34:46 +00:00
|
|
|
if (IsRoot()) {
|
2011-01-15 09:40:33 +00:00
|
|
|
static_cast<nsRootPresContext*>(this)->CancelDidPaintTimer();
|
|
|
|
|
2012-10-23 01:52:48 +00:00
|
|
|
if (!mFireAfterPaintEvents) {
|
|
|
|
return;
|
|
|
|
}
|
2012-10-19 04:50:34 +00:00
|
|
|
}
|
2014-10-21 08:59:59 +00:00
|
|
|
|
|
|
|
if (!PresShell()->IsVisible() && !mFireAfterPaintEvents) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-10-23 01:52:48 +00:00
|
|
|
// Non-root prescontexts fire MozAfterPaint to all their descendants
|
|
|
|
// unconditionally, even if no invalidations have been collected. This is
|
|
|
|
// because we don't want to eat the cost of collecting invalidations for
|
|
|
|
// every subdocument (which would require putting every subdocument in its
|
|
|
|
// own layer).
|
2012-08-29 05:47:18 +00:00
|
|
|
|
2012-10-19 04:50:34 +00:00
|
|
|
if (aFlags & nsIPresShell::PAINT_LAYERS) {
|
|
|
|
mUndeliveredInvalidateRequestsBeforeLastPaint.TakeFrom(
|
|
|
|
&mInvalidateRequestsSinceLastPaint);
|
|
|
|
mAllInvalidated = false;
|
|
|
|
}
|
|
|
|
if (aFlags & nsIPresShell::PAINT_COMPOSITE) {
|
|
|
|
nsCOMPtr<nsIRunnable> ev =
|
|
|
|
new DelayedFireDOMPaintEvent(this, &mUndeliveredInvalidateRequestsBeforeLastPaint);
|
|
|
|
nsContentUtils::AddScriptRunner(ev);
|
|
|
|
}
|
|
|
|
|
|
|
|
NotifyDidPaintSubdocumentCallbackClosure closure = { aFlags, false };
|
|
|
|
mDocument->EnumerateSubDocuments(NotifyDidPaintSubdocumentCallback, &closure);
|
2011-01-15 09:40:33 +00:00
|
|
|
|
2012-10-19 04:50:34 +00:00
|
|
|
if (!closure.mNeedsAnotherDidPaintNotification &&
|
|
|
|
mInvalidateRequestsSinceLastPaint.IsEmpty() &&
|
|
|
|
mUndeliveredInvalidateRequestsBeforeLastPaint.IsEmpty()) {
|
|
|
|
// Nothing more to do for the moment.
|
|
|
|
mFireAfterPaintEvents = false;
|
|
|
|
} else {
|
|
|
|
if (IsRoot()) {
|
|
|
|
static_cast<nsRootPresContext*>(this)->EnsureEventualDidPaintEvent();
|
|
|
|
}
|
|
|
|
}
|
2011-01-15 09:40:33 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2008-12-29 15:07:36 +00:00
|
|
|
nsPresContext::HasCachedStyleData()
|
|
|
|
{
|
2016-02-24 07:01:11 +00:00
|
|
|
if (!mShell) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsStyleSet* styleSet = mShell->StyleSet()->GetAsGecko();
|
|
|
|
if (!styleSet) {
|
|
|
|
// XXXheycam ServoStyleSets do not use the rule tree, so just assume for now
|
|
|
|
// that we need to restyle when e.g. dppx changes.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return styleSet->HasCachedStyleData();
|
2008-12-29 15:07:36 +00:00
|
|
|
}
|
2009-04-21 23:53:52 +00:00
|
|
|
|
2015-08-04 00:13:07 +00:00
|
|
|
already_AddRefed<nsITimer>
|
|
|
|
nsPresContext::CreateTimer(nsTimerCallbackFunc aCallback,
|
|
|
|
uint32_t aDelay)
|
2015-07-30 21:24:51 +00:00
|
|
|
{
|
2015-08-04 00:13:07 +00:00
|
|
|
nsCOMPtr<nsITimer> timer = do_CreateInstance("@mozilla.org/timer;1");
|
|
|
|
if (timer) {
|
|
|
|
nsresult rv = timer->InitWithFuncCallback(aCallback, this, aDelay,
|
|
|
|
nsITimer::TYPE_ONE_SHOT);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
return timer.forget();
|
|
|
|
}
|
2015-07-30 21:24:51 +00:00
|
|
|
}
|
|
|
|
|
2015-08-04 00:13:07 +00:00
|
|
|
return nullptr;
|
2015-07-30 21:24:51 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
static bool sGotInterruptEnv = false;
|
2009-04-21 23:53:52 +00:00
|
|
|
enum InterruptMode {
|
|
|
|
ModeRandom,
|
|
|
|
ModeCounter,
|
|
|
|
ModeEvent
|
|
|
|
};
|
2009-10-02 18:05:32 +00:00
|
|
|
// Controlled by the GECKO_REFLOW_INTERRUPT_MODE env var; allowed values are
|
|
|
|
// "random" (except on Windows) or "counter". If neither is used, the mode is
|
|
|
|
// ModeEvent.
|
2009-04-21 23:53:52 +00:00
|
|
|
static InterruptMode sInterruptMode = ModeEvent;
|
2013-01-10 07:04:09 +00:00
|
|
|
#ifndef XP_WIN
|
2009-10-02 18:05:32 +00:00
|
|
|
// Used for the "random" mode. Controlled by the GECKO_REFLOW_INTERRUPT_SEED
|
|
|
|
// env var.
|
2012-08-22 15:56:38 +00:00
|
|
|
static uint32_t sInterruptSeed = 1;
|
2013-01-10 07:04:09 +00:00
|
|
|
#endif
|
2009-10-02 18:05:32 +00:00
|
|
|
// Used for the "counter" mode. This is the number of unskipped interrupt
|
|
|
|
// checks that have to happen before we interrupt. Controlled by the
|
|
|
|
// GECKO_REFLOW_INTERRUPT_FREQUENCY env var.
|
2012-08-22 15:56:38 +00:00
|
|
|
static uint32_t sInterruptMaxCounter = 10;
|
2009-10-02 18:05:32 +00:00
|
|
|
// Used for the "counter" mode. This counts up to sInterruptMaxCounter and is
|
|
|
|
// then reset to 0.
|
2012-08-22 15:56:38 +00:00
|
|
|
static uint32_t sInterruptCounter;
|
2009-10-02 18:05:32 +00:00
|
|
|
// Number of interrupt checks to skip before really trying to interrupt.
|
|
|
|
// Controlled by the GECKO_REFLOW_INTERRUPT_CHECKS_TO_SKIP env var.
|
2012-08-22 15:56:38 +00:00
|
|
|
static uint32_t sInterruptChecksToSkip = 200;
|
2009-10-02 18:05:32 +00:00
|
|
|
// Number of milliseconds that a reflow should be allowed to run for before we
|
|
|
|
// actually allow interruption. Controlled by the
|
2011-10-11 21:29:12 +00:00
|
|
|
// GECKO_REFLOW_MIN_NOINTERRUPT_DURATION env var. Can't be initialized here,
|
|
|
|
// because TimeDuration/TimeStamp is not safe to use in static constructors..
|
|
|
|
static TimeDuration sInterruptTimeout;
|
2009-04-21 23:53:52 +00:00
|
|
|
|
|
|
|
static void GetInterruptEnv()
|
|
|
|
{
|
|
|
|
char *ev = PR_GetEnv("GECKO_REFLOW_INTERRUPT_MODE");
|
|
|
|
if (ev) {
|
|
|
|
#ifndef XP_WIN
|
|
|
|
if (PL_strcasecmp(ev, "random") == 0) {
|
|
|
|
ev = PR_GetEnv("GECKO_REFLOW_INTERRUPT_SEED");
|
|
|
|
if (ev) {
|
|
|
|
sInterruptSeed = atoi(ev);
|
|
|
|
}
|
|
|
|
srandom(sInterruptSeed);
|
|
|
|
sInterruptMode = ModeRandom;
|
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
if (PL_strcasecmp(ev, "counter") == 0) {
|
|
|
|
ev = PR_GetEnv("GECKO_REFLOW_INTERRUPT_FREQUENCY");
|
|
|
|
if (ev) {
|
|
|
|
sInterruptMaxCounter = atoi(ev);
|
|
|
|
}
|
|
|
|
sInterruptCounter = 0;
|
|
|
|
sInterruptMode = ModeCounter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ev = PR_GetEnv("GECKO_REFLOW_INTERRUPT_CHECKS_TO_SKIP");
|
|
|
|
if (ev) {
|
|
|
|
sInterruptChecksToSkip = atoi(ev);
|
|
|
|
}
|
2009-10-02 18:05:32 +00:00
|
|
|
|
|
|
|
ev = PR_GetEnv("GECKO_REFLOW_MIN_NOINTERRUPT_DURATION");
|
2011-10-11 21:29:12 +00:00
|
|
|
int duration_ms = ev ? atoi(ev) : 100;
|
|
|
|
sInterruptTimeout = TimeDuration::FromMilliseconds(duration_ms);
|
2009-04-21 23:53:52 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2009-04-21 23:53:52 +00:00
|
|
|
nsPresContext::HavePendingInputEvent()
|
|
|
|
{
|
|
|
|
switch (sInterruptMode) {
|
|
|
|
#ifndef XP_WIN
|
|
|
|
case ModeRandom:
|
|
|
|
return (random() & 1);
|
|
|
|
#endif
|
|
|
|
case ModeCounter:
|
|
|
|
if (sInterruptCounter < sInterruptMaxCounter) {
|
|
|
|
++sInterruptCounter;
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2009-04-21 23:53:52 +00:00
|
|
|
}
|
|
|
|
sInterruptCounter = 0;
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2009-04-21 23:53:52 +00:00
|
|
|
default:
|
|
|
|
case ModeEvent: {
|
|
|
|
nsIFrame* f = PresShell()->GetRootFrame();
|
|
|
|
if (f) {
|
2010-07-02 19:11:04 +00:00
|
|
|
nsIWidget* w = f->GetNearestWidget();
|
2009-04-21 23:53:52 +00:00
|
|
|
if (w) {
|
|
|
|
return w->HasPendingInputEvent();
|
|
|
|
}
|
|
|
|
}
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2009-04-21 23:53:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-02 02:32:09 +00:00
|
|
|
void
|
|
|
|
nsPresContext::NotifyFontFaceSetOnRefresh()
|
|
|
|
{
|
2015-06-27 01:39:54 +00:00
|
|
|
FontFaceSet* set = mDocument->GetFonts();
|
|
|
|
if (set) {
|
|
|
|
set->DidRefresh();
|
2014-10-02 02:32:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsPresContext::HasPendingRestyleOrReflow()
|
|
|
|
{
|
|
|
|
return (mRestyleManager && mRestyleManager->HasPendingRestyles()) ||
|
|
|
|
PresShell()->HasPendingReflow();
|
|
|
|
}
|
|
|
|
|
2009-04-21 23:53:52 +00:00
|
|
|
void
|
2011-09-29 06:19:26 +00:00
|
|
|
nsPresContext::ReflowStarted(bool aInterruptible)
|
2009-04-21 23:53:52 +00:00
|
|
|
{
|
2009-10-02 18:05:32 +00:00
|
|
|
#ifdef NOISY_INTERRUPTIBLE_REFLOW
|
|
|
|
if (!aInterruptible) {
|
|
|
|
printf("STARTING NONINTERRUPTIBLE REFLOW\n");
|
|
|
|
}
|
|
|
|
#endif
|
2009-04-21 23:53:52 +00:00
|
|
|
// We don't support interrupting in paginated contexts, since page
|
|
|
|
// sequences only handle initial reflow
|
2014-04-10 04:47:58 +00:00
|
|
|
mInterruptsEnabled = aInterruptible && !IsPaginated() &&
|
|
|
|
nsLayoutUtils::InterruptibleReflowEnabled();
|
2009-04-21 23:53:52 +00:00
|
|
|
|
|
|
|
// Don't set mHasPendingInterrupt based on HavePendingInputEvent() here. If
|
|
|
|
// we ever change that, then we need to update the code in
|
|
|
|
// PresShell::DoReflow to only add the just-reflown root to dirty roots if
|
|
|
|
// it's actually dirty. Otherwise we can end up adding a root that has no
|
|
|
|
// interruptible descendants, just because we detected an interrupt at reflow
|
|
|
|
// start.
|
2011-10-17 14:59:28 +00:00
|
|
|
mHasPendingInterrupt = false;
|
2009-04-21 23:53:52 +00:00
|
|
|
|
|
|
|
mInterruptChecksToSkip = sInterruptChecksToSkip;
|
2009-10-02 18:05:32 +00:00
|
|
|
|
|
|
|
if (mInterruptsEnabled) {
|
|
|
|
mReflowStartTime = TimeStamp::Now();
|
|
|
|
}
|
2009-04-21 23:53:52 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2009-04-21 23:53:52 +00:00
|
|
|
nsPresContext::CheckForInterrupt(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
if (mHasPendingInterrupt) {
|
|
|
|
mShell->FrameNeedsToContinueReflow(aFrame);
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2009-04-21 23:53:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!sGotInterruptEnv) {
|
2011-10-17 14:59:28 +00:00
|
|
|
sGotInterruptEnv = true;
|
2009-04-21 23:53:52 +00:00
|
|
|
GetInterruptEnv();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mInterruptsEnabled) {
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2009-04-21 23:53:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mInterruptChecksToSkip > 0) {
|
|
|
|
--mInterruptChecksToSkip;
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2009-04-21 23:53:52 +00:00
|
|
|
}
|
|
|
|
mInterruptChecksToSkip = sInterruptChecksToSkip;
|
|
|
|
|
2009-10-02 18:05:32 +00:00
|
|
|
// Don't interrupt if it's been less than sInterruptTimeout since we started
|
|
|
|
// the reflow.
|
|
|
|
mHasPendingInterrupt =
|
|
|
|
TimeStamp::Now() - mReflowStartTime > sInterruptTimeout &&
|
|
|
|
HavePendingInputEvent() &&
|
|
|
|
!IsChrome();
|
2009-04-21 23:53:52 +00:00
|
|
|
if (mHasPendingInterrupt) {
|
|
|
|
#ifdef NOISY_INTERRUPTIBLE_REFLOW
|
|
|
|
printf("*** DETECTED pending interrupt (time=%lld)\n", PR_Now());
|
|
|
|
#endif /* NOISY_INTERRUPTIBLE_REFLOW */
|
|
|
|
mShell->FrameNeedsToContinueReflow(aFrame);
|
|
|
|
}
|
|
|
|
return mHasPendingInterrupt;
|
|
|
|
}
|
2009-07-22 00:44:54 +00:00
|
|
|
|
2012-07-30 04:29:41 +00:00
|
|
|
nsIFrame*
|
|
|
|
nsPresContext::GetPrimaryFrameFor(nsIContent* aContent)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aContent, "Don't do that");
|
|
|
|
if (GetPresShell() &&
|
2014-08-05 23:23:02 +00:00
|
|
|
GetPresShell()->GetDocument() == aContent->GetComposedDoc()) {
|
2012-07-30 04:29:41 +00:00
|
|
|
return aContent->GetPrimaryFrame();
|
|
|
|
}
|
2012-07-30 14:28:15 +00:00
|
|
|
return nullptr;
|
2012-07-30 04:29:41 +00:00
|
|
|
}
|
|
|
|
|
2012-02-21 05:02:24 +00:00
|
|
|
size_t
|
2013-06-23 12:03:39 +00:00
|
|
|
nsPresContext::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const
|
2012-02-21 05:02:24 +00:00
|
|
|
{
|
2015-11-14 08:06:58 +00:00
|
|
|
return mPropertyTable.SizeOfExcludingThis(aMallocSizeOf) +
|
2012-02-21 05:02:24 +00:00
|
|
|
mLangGroupFontPrefs.SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
|
|
|
|
// Measurement of other members may be added later if DMD finds it is
|
|
|
|
// worthwhile.
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2010-09-11 18:24:50 +00:00
|
|
|
nsPresContext::IsRootContentDocument()
|
|
|
|
{
|
2010-10-09 19:09:22 +00:00
|
|
|
// We are a root content document if: we are not a resource doc, we are
|
|
|
|
// not chrome, and we either have no parent or our parent is chrome.
|
|
|
|
if (mDocument->IsResourceDoc()) {
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2010-10-09 19:09:22 +00:00
|
|
|
}
|
2010-09-11 18:24:50 +00:00
|
|
|
if (IsChrome()) {
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2010-09-11 18:24:50 +00:00
|
|
|
}
|
|
|
|
// We may not have a root frame, so use views.
|
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());
|
|
|
|
}
|
|
|
|
|
2012-09-05 16:23:45 +00:00
|
|
|
bool
|
|
|
|
nsPresContext::IsCrossProcessRootContentDocument()
|
|
|
|
{
|
|
|
|
if (!IsRootContentDocument()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-07-04 01:29:00 +00:00
|
|
|
if (XRE_IsParentProcess()) {
|
2012-09-05 16:23:45 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-09-12 19:24:11 +00:00
|
|
|
TabChild* tabChild = TabChild::GetFrom(mShell);
|
2012-09-05 16:23:45 +00:00
|
|
|
return (tabChild && tabChild->IsRootContentDocument());
|
|
|
|
}
|
|
|
|
|
2013-07-22 15:51:38 +00:00
|
|
|
bool nsPresContext::GetPaintFlashing() const
|
|
|
|
{
|
|
|
|
if (!mPaintFlashingInitialized) {
|
|
|
|
bool pref = Preferences::GetBool("nglayout.debug.paint_flashing");
|
|
|
|
if (!pref && IsChrome()) {
|
|
|
|
pref = Preferences::GetBool("nglayout.debug.paint_flashing_chrome");
|
|
|
|
}
|
|
|
|
mPaintFlashing = pref;
|
|
|
|
mPaintFlashingInitialized = true;
|
|
|
|
}
|
|
|
|
return mPaintFlashing;
|
|
|
|
}
|
|
|
|
|
2013-09-23 11:52:25 +00:00
|
|
|
int32_t
|
|
|
|
nsPresContext::AppUnitsPerDevPixel() const
|
|
|
|
{
|
|
|
|
return mDeviceContext->AppUnitsPerDevPixel();
|
|
|
|
}
|
|
|
|
|
|
|
|
nscoord
|
|
|
|
nsPresContext::GfxUnitsToAppUnits(gfxFloat aGfxUnits) const
|
|
|
|
{
|
|
|
|
return mDeviceContext->GfxUnitsToAppUnits(aGfxUnits);
|
|
|
|
}
|
|
|
|
|
|
|
|
gfxFloat
|
|
|
|
nsPresContext::AppUnitsToGfxUnits(nscoord aAppUnits) const
|
|
|
|
{
|
|
|
|
return mDeviceContext->AppUnitsToGfxUnits(aAppUnits);
|
|
|
|
}
|
|
|
|
|
2013-11-07 13:40:23 +00:00
|
|
|
bool
|
|
|
|
nsPresContext::IsDeviceSizePageSize()
|
|
|
|
{
|
|
|
|
bool isDeviceSizePageSize = false;
|
2013-11-20 19:18:25 +00:00
|
|
|
nsCOMPtr<nsIDocShell> docShell(mContainer);
|
2013-11-07 13:40:23 +00:00
|
|
|
if (docShell) {
|
|
|
|
isDeviceSizePageSize = docShell->GetDeviceSizeIsPageSize();
|
|
|
|
}
|
|
|
|
return isDeviceSizePageSize;
|
|
|
|
}
|
2015-09-17 02:08:20 +00:00
|
|
|
|
|
|
|
uint64_t
|
|
|
|
nsPresContext::GetRestyleGeneration() const
|
|
|
|
{
|
|
|
|
if (!mRestyleManager) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return mRestyleManager->GetRestyleGeneration();
|
|
|
|
}
|
2013-11-07 13:40:23 +00:00
|
|
|
|
2009-07-22 00:44:54 +00:00
|
|
|
nsRootPresContext::nsRootPresContext(nsIDocument* aDocument,
|
|
|
|
nsPresContextType aType)
|
2010-07-15 21:08:08 +00:00
|
|
|
: nsPresContext(aDocument, aType),
|
2012-10-06 13:03:23 +00:00
|
|
|
mDOMGeneration(0)
|
2009-07-22 00:44:54 +00:00
|
|
|
{
|
2010-07-15 21:08:08 +00:00
|
|
|
}
|
2009-07-22 00:45:00 +00:00
|
|
|
|
|
|
|
nsRootPresContext::~nsRootPresContext()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mRegisteredPlugins.Count() == 0,
|
|
|
|
"All plugins should have been unregistered");
|
2011-01-15 09:40:33 +00:00
|
|
|
CancelDidPaintTimer();
|
2012-10-06 13:03:23 +00:00
|
|
|
CancelApplyPluginGeometryTimer();
|
2009-07-22 00:45:00 +00:00
|
|
|
}
|
|
|
|
|
2014-02-03 23:47:57 +00:00
|
|
|
/* virtual */ void
|
|
|
|
nsRootPresContext::Detach()
|
|
|
|
{
|
|
|
|
CancelDidPaintTimer();
|
|
|
|
// XXXmats maybe also CancelApplyPluginGeometryTimer(); ?
|
|
|
|
nsPresContext::Detach();
|
|
|
|
}
|
|
|
|
|
2009-07-22 00:45:00 +00:00
|
|
|
void
|
2012-08-14 04:06:42 +00:00
|
|
|
nsRootPresContext::RegisterPluginForGeometryUpdates(nsIContent* aPlugin)
|
2009-07-22 00:45:00 +00:00
|
|
|
{
|
|
|
|
mRegisteredPlugins.PutEntry(aPlugin);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-08-14 04:06:42 +00:00
|
|
|
nsRootPresContext::UnregisterPluginForGeometryUpdates(nsIContent* aPlugin)
|
2009-07-22 00:45:00 +00:00
|
|
|
{
|
|
|
|
mRegisteredPlugins.RemoveEntry(aPlugin);
|
|
|
|
}
|
|
|
|
|
2012-10-06 13:03:23 +00:00
|
|
|
void
|
|
|
|
nsRootPresContext::ComputePluginGeometryUpdates(nsIFrame* aFrame,
|
|
|
|
nsDisplayListBuilder* aBuilder,
|
|
|
|
nsDisplayList* aList)
|
2009-07-22 00:45:00 +00:00
|
|
|
{
|
2012-10-06 13:03:23 +00:00
|
|
|
if (mRegisteredPlugins.Count() == 0) {
|
|
|
|
return;
|
2009-07-22 00:45:00 +00:00
|
|
|
}
|
|
|
|
|
2012-10-06 13:03:23 +00:00
|
|
|
// Initially make the next state for each plugin descendant of aFrame be
|
|
|
|
// "hidden". Plugins that are visible will have their next state set to
|
|
|
|
// unhidden by nsDisplayPlugin::ComputeVisibility.
|
2015-07-15 09:05:07 +00:00
|
|
|
for (auto iter = mRegisteredPlugins.Iter(); !iter.Done(); iter.Next()) {
|
|
|
|
auto f = static_cast<nsPluginFrame*>(iter.Get()->GetKey()->GetPrimaryFrame());
|
|
|
|
if (!f) {
|
|
|
|
NS_WARNING("Null frame in ComputePluginGeometryUpdates");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!nsLayoutUtils::IsAncestorFrameCrossDoc(aFrame, f)) {
|
|
|
|
// f is not managed by this frame so we should ignore it.
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
f->SetEmptyWidgetConfiguration();
|
|
|
|
}
|
2009-07-22 00:45:00 +00:00
|
|
|
|
2012-10-06 13:03:23 +00:00
|
|
|
nsIFrame* rootFrame = FrameManager()->GetRootFrame();
|
2009-07-22 00:45:00 +00:00
|
|
|
|
2012-10-18 05:34:58 +00:00
|
|
|
if (rootFrame && aBuilder->ContainsPluginItem()) {
|
|
|
|
aBuilder->SetForPluginGeometry();
|
|
|
|
aBuilder->SetAccurateVisibleRegions();
|
|
|
|
// Merging and flattening has already been done and we should not do it
|
|
|
|
// again. nsDisplayScroll(Info)Layer doesn't support trying to flatten
|
|
|
|
// again.
|
|
|
|
aBuilder->SetAllowMergingAndFlattening(false);
|
|
|
|
nsRegion region = rootFrame->GetVisualOverflowRectRelativeToSelf();
|
|
|
|
// nsDisplayPlugin::ComputeVisibility will automatically set a non-hidden
|
|
|
|
// widget configuration for the plugin, if it's visible.
|
|
|
|
aList->ComputeVisibilityForRoot(aBuilder, ®ion);
|
|
|
|
}
|
2009-07-22 00:45:00 +00:00
|
|
|
|
2012-11-06 20:38:11 +00:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
// We control painting of Mac plugins, so just apply geometry updates now.
|
|
|
|
// This is not happening during a paint event.
|
|
|
|
ApplyPluginGeometryUpdates();
|
|
|
|
#else
|
2015-07-04 01:29:00 +00:00
|
|
|
if (XRE_IsParentProcess()) {
|
2015-03-02 11:01:58 +00:00
|
|
|
InitApplyPluginGeometryTimer();
|
|
|
|
}
|
2012-11-06 20:38:11 +00:00
|
|
|
#endif
|
2012-10-06 13:03:23 +00:00
|
|
|
}
|
2009-08-20 21:52:48 +00:00
|
|
|
|
2012-10-06 13:03:23 +00:00
|
|
|
static void
|
|
|
|
ApplyPluginGeometryUpdatesCallback(nsITimer *aTimer, void *aClosure)
|
|
|
|
{
|
|
|
|
static_cast<nsRootPresContext*>(aClosure)->ApplyPluginGeometryUpdates();
|
|
|
|
}
|
2009-07-22 00:45:00 +00:00
|
|
|
|
2012-10-06 13:03:23 +00:00
|
|
|
void
|
|
|
|
nsRootPresContext::InitApplyPluginGeometryTimer()
|
|
|
|
{
|
|
|
|
if (mApplyPluginGeometryTimer) {
|
|
|
|
return;
|
|
|
|
}
|
2009-07-22 00:45:00 +00:00
|
|
|
|
2012-10-06 13:03:23 +00:00
|
|
|
// We'll apply the plugin geometry updates during the next compositing paint in this
|
|
|
|
// presContext (either from nsPresShell::WillPaintWindow or from
|
|
|
|
// nsPresShell::DidPaintWindow, depending on the platform). But paints might
|
|
|
|
// get optimized away if the old plugin geometry covers the invalid region,
|
|
|
|
// so set a backup timer to do this too. We want to make sure this
|
|
|
|
// won't fire before our normal paint notifications, if those would
|
|
|
|
// update the geometry, so set it for double the refresh driver interval.
|
2015-08-04 00:13:07 +00:00
|
|
|
mApplyPluginGeometryTimer = CreateTimer(ApplyPluginGeometryUpdatesCallback,
|
|
|
|
nsRefreshDriver::DefaultInterval() * 2);
|
2012-10-06 13:03:23 +00:00
|
|
|
}
|
2009-07-22 00:45:00 +00:00
|
|
|
|
2012-10-06 13:03:23 +00:00
|
|
|
void
|
|
|
|
nsRootPresContext::CancelApplyPluginGeometryTimer()
|
|
|
|
{
|
|
|
|
if (mApplyPluginGeometryTimer) {
|
|
|
|
mApplyPluginGeometryTimer->Cancel();
|
|
|
|
mApplyPluginGeometryTimer = nullptr;
|
|
|
|
}
|
2009-07-22 00:45:00 +00:00
|
|
|
}
|
|
|
|
|
2014-12-11 14:44:07 +00:00
|
|
|
#ifndef XP_MACOSX
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
static bool
|
2015-11-26 04:32:47 +00:00
|
|
|
HasOverlap(const LayoutDeviceIntPoint& aOffset1,
|
2015-12-02 22:32:55 +00:00
|
|
|
const nsTArray<LayoutDeviceIntRect>& aClipRects1,
|
2015-11-26 04:32:47 +00:00
|
|
|
const LayoutDeviceIntPoint& aOffset2,
|
2015-12-02 22:32:55 +00:00
|
|
|
const nsTArray<LayoutDeviceIntRect>& aClipRects2)
|
2010-07-15 21:08:08 +00:00
|
|
|
{
|
2015-12-02 22:32:55 +00:00
|
|
|
LayoutDeviceIntPoint offsetDelta = aOffset1 - aOffset2;
|
2012-08-22 15:56:38 +00:00
|
|
|
for (uint32_t i = 0; i < aClipRects1.Length(); ++i) {
|
|
|
|
for (uint32_t j = 0; j < aClipRects2.Length(); ++j) {
|
2015-11-26 04:32:47 +00:00
|
|
|
if ((aClipRects1[i] + offsetDelta).Intersects(aClipRects2[j])) {
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2015-11-26 04:32:47 +00:00
|
|
|
}
|
2010-07-15 21:08:08 +00:00
|
|
|
}
|
|
|
|
}
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2010-07-15 21:08:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Given a list of plugin windows to move to new locations, sort the list
|
|
|
|
* so that for each window move, the window moves to a location that
|
|
|
|
* does not intersect other windows. This minimizes flicker and repainting.
|
|
|
|
* It's not always possible to do this perfectly, since in general
|
|
|
|
* we might have cycles. But we do our best.
|
|
|
|
* We need to take into account that windows are clipped to particular
|
|
|
|
* regions and the clip regions change as the windows are moved.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
SortConfigurations(nsTArray<nsIWidget::Configuration>* aConfigurations)
|
|
|
|
{
|
|
|
|
if (aConfigurations->Length() > 10) {
|
|
|
|
// Give up, we don't want to get bogged down here
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsTArray<nsIWidget::Configuration> pluginsToMove;
|
|
|
|
pluginsToMove.SwapElements(*aConfigurations);
|
|
|
|
|
|
|
|
// Our algorithm is quite naive. At each step we try to identify
|
|
|
|
// a window that can be moved to its new location that won't overlap
|
|
|
|
// any other windows at the new location. If there is no such
|
|
|
|
// window, we just move the last window in the list anyway.
|
|
|
|
while (!pluginsToMove.IsEmpty()) {
|
|
|
|
// Find a window whose destination does not overlap any other window
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t i;
|
2010-07-15 21:08:08 +00:00
|
|
|
for (i = 0; i + 1 < pluginsToMove.Length(); ++i) {
|
|
|
|
nsIWidget::Configuration* config = &pluginsToMove[i];
|
2011-09-29 06:19:26 +00:00
|
|
|
bool foundOverlap = false;
|
2012-08-22 15:56:38 +00:00
|
|
|
for (uint32_t j = 0; j < pluginsToMove.Length(); ++j) {
|
2010-07-15 21:08:08 +00:00
|
|
|
if (i == j)
|
|
|
|
continue;
|
2015-11-26 04:32:47 +00:00
|
|
|
LayoutDeviceIntRect bounds;
|
|
|
|
pluginsToMove[j].mChild->GetBounds(bounds);
|
2016-02-02 15:36:30 +00:00
|
|
|
AutoTArray<LayoutDeviceIntRect,1> clipRects;
|
2010-07-15 21:08:08 +00:00
|
|
|
pluginsToMove[j].mChild->GetWindowClipRegion(&clipRects);
|
|
|
|
if (HasOverlap(bounds.TopLeft(), clipRects,
|
2015-11-26 04:32:47 +00:00
|
|
|
config->mBounds.TopLeft(),
|
2010-07-15 21:08:08 +00:00
|
|
|
config->mClipRegion)) {
|
2011-10-17 14:59:28 +00:00
|
|
|
foundOverlap = true;
|
2010-07-15 21:08:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!foundOverlap)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// Note that we always move the last plugin in pluginsToMove, if we
|
|
|
|
// can't find any other plugin to move
|
|
|
|
aConfigurations->AppendElement(pluginsToMove[i]);
|
|
|
|
pluginsToMove.RemoveElementAt(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-15 09:05:07 +00:00
|
|
|
static void
|
|
|
|
PluginGetGeometryUpdate(nsTHashtable<nsRefPtrHashKey<nsIContent>>& aPlugins,
|
|
|
|
nsTArray<nsIWidget::Configuration>* aConfigurations)
|
|
|
|
{
|
|
|
|
for (auto iter = aPlugins.Iter(); !iter.Done(); iter.Next()) {
|
|
|
|
auto f = static_cast<nsPluginFrame*>(iter.Get()->GetKey()->GetPrimaryFrame());
|
|
|
|
if (!f) {
|
|
|
|
NS_WARNING("Null frame in PluginGeometryUpdate");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
f->GetWidgetConfiguration(aConfigurations);
|
2010-07-15 21:08:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-11 14:44:07 +00:00
|
|
|
#endif // #ifndef XP_MACOSX
|
|
|
|
|
2015-07-15 09:05:07 +00:00
|
|
|
static void
|
|
|
|
PluginDidSetGeometry(nsTHashtable<nsRefPtrHashKey<nsIContent>>& aPlugins)
|
2009-07-22 00:45:02 +00:00
|
|
|
{
|
2015-07-15 09:05:07 +00:00
|
|
|
for (auto iter = aPlugins.Iter(); !iter.Done(); iter.Next()) {
|
|
|
|
auto f = static_cast<nsPluginFrame*>(iter.Get()->GetKey()->GetPrimaryFrame());
|
|
|
|
if (!f) {
|
|
|
|
NS_WARNING("Null frame in PluginDidSetGeometry");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
f->DidSetWidgetGeometry();
|
2012-08-14 04:06:42 +00:00
|
|
|
}
|
2009-07-22 00:45:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-10-06 13:03:23 +00:00
|
|
|
nsRootPresContext::ApplyPluginGeometryUpdates()
|
2009-07-22 00:45:02 +00:00
|
|
|
{
|
2014-12-11 14:44:07 +00:00
|
|
|
#ifndef XP_MACOSX
|
2012-10-06 13:03:23 +00:00
|
|
|
CancelApplyPluginGeometryTimer();
|
|
|
|
|
2015-07-15 09:05:07 +00:00
|
|
|
nsTArray<nsIWidget::Configuration> configurations;
|
|
|
|
PluginGetGeometryUpdate(mRegisteredPlugins, &configurations);
|
2012-10-06 13:03:23 +00:00
|
|
|
// Walk mRegisteredPlugins and ask each plugin for its configuration
|
2015-07-15 09:05:07 +00:00
|
|
|
if (!configurations.IsEmpty()) {
|
|
|
|
nsIWidget* widget = configurations[0].mChild->GetParent();
|
2012-10-06 13:03:23 +00:00
|
|
|
NS_ASSERTION(widget, "Plugins must have a parent window");
|
2015-07-15 09:05:07 +00:00
|
|
|
SortConfigurations(&configurations);
|
|
|
|
widget->ConfigureChildren(configurations);
|
2012-10-06 13:03:23 +00:00
|
|
|
}
|
2014-12-11 14:44:07 +00:00
|
|
|
#endif // #ifndef XP_MACOSX
|
|
|
|
|
2015-07-15 09:05:07 +00:00
|
|
|
PluginDidSetGeometry(mRegisteredPlugins);
|
2009-07-22 00:45:00 +00:00
|
|
|
}
|
2010-07-15 21:08:08 +00:00
|
|
|
|
2015-01-29 19:41:54 +00:00
|
|
|
void
|
|
|
|
nsRootPresContext::CollectPluginGeometryUpdates(LayerManager* aLayerManager)
|
|
|
|
{
|
|
|
|
#ifndef XP_MACOSX
|
|
|
|
// Collect and pass plugin widget configurations down to the compositor
|
|
|
|
// for transmission to the chrome process.
|
|
|
|
NS_ASSERTION(aLayerManager, "layer manager is invalid!");
|
|
|
|
mozilla::layers::ClientLayerManager* clm = aLayerManager->AsClientLayerManager();
|
2015-07-15 09:05:07 +00:00
|
|
|
|
|
|
|
nsTArray<nsIWidget::Configuration> configurations;
|
2015-11-25 18:11:00 +00:00
|
|
|
// If there aren't any plugins to configure, clear the plugin data cache
|
|
|
|
// in the layer system.
|
|
|
|
if (!mRegisteredPlugins.Count() && clm) {
|
|
|
|
clm->StorePluginWidgetConfigurations(configurations);
|
|
|
|
return;
|
|
|
|
}
|
2015-07-15 09:05:07 +00:00
|
|
|
PluginGetGeometryUpdate(mRegisteredPlugins, &configurations);
|
|
|
|
if (configurations.IsEmpty()) {
|
|
|
|
PluginDidSetGeometry(mRegisteredPlugins);
|
2015-01-29 19:41:54 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-07-15 09:05:07 +00:00
|
|
|
SortConfigurations(&configurations);
|
2015-01-29 19:41:54 +00:00
|
|
|
if (clm) {
|
2015-07-15 09:05:07 +00:00
|
|
|
clm->StorePluginWidgetConfigurations(configurations);
|
2015-01-29 19:41:54 +00:00
|
|
|
}
|
2015-07-15 09:05:07 +00:00
|
|
|
PluginDidSetGeometry(mRegisteredPlugins);
|
2015-01-29 19:41:54 +00:00
|
|
|
#endif // #ifndef XP_MACOSX
|
|
|
|
}
|
|
|
|
|
2011-01-15 09:40:33 +00:00
|
|
|
static void
|
|
|
|
NotifyDidPaintForSubtreeCallback(nsITimer *aTimer, void *aClosure)
|
|
|
|
{
|
|
|
|
nsPresContext* presContext = (nsPresContext*)aClosure;
|
|
|
|
nsAutoScriptBlocker blockScripts;
|
2012-10-19 04:50:34 +00:00
|
|
|
// This is a fallback if we don't get paint events for some reason
|
|
|
|
// so we'll just pretend both layer painting and compositing happened.
|
|
|
|
presContext->NotifyDidPaintForSubtree(
|
|
|
|
nsIPresShell::PAINT_LAYERS | nsIPresShell::PAINT_COMPOSITE);
|
2011-01-15 09:40:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsRootPresContext::EnsureEventualDidPaintEvent()
|
|
|
|
{
|
|
|
|
if (mNotifyDidPaintTimer)
|
|
|
|
return;
|
2015-07-30 21:24:51 +00:00
|
|
|
|
2015-08-04 00:13:07 +00:00
|
|
|
mNotifyDidPaintTimer = CreateTimer(NotifyDidPaintForSubtreeCallback, 100);
|
2011-01-15 09:40:33 +00:00
|
|
|
}
|
2011-10-26 04:14:31 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
nsRootPresContext::AddWillPaintObserver(nsIRunnable* aRunnable)
|
|
|
|
{
|
|
|
|
if (!mWillPaintFallbackEvent.IsPending()) {
|
|
|
|
mWillPaintFallbackEvent = new RunWillPaintObservers(this);
|
|
|
|
NS_DispatchToMainThread(mWillPaintFallbackEvent.get());
|
|
|
|
}
|
|
|
|
mWillPaintObservers.AppendElement(aRunnable);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Run all runnables that need to get called before the next paint.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
nsRootPresContext::FlushWillPaintObservers()
|
|
|
|
{
|
2012-07-30 14:20:58 +00:00
|
|
|
mWillPaintFallbackEvent = nullptr;
|
2011-10-26 04:14:31 +00:00
|
|
|
nsTArray<nsCOMPtr<nsIRunnable> > observers;
|
|
|
|
observers.SwapElements(mWillPaintObservers);
|
2012-08-22 15:56:38 +00:00
|
|
|
for (uint32_t i = 0; i < observers.Length(); ++i) {
|
2011-10-26 04:14:31 +00:00
|
|
|
observers[i]->Run();
|
|
|
|
}
|
|
|
|
}
|
2012-02-21 05:02:24 +00:00
|
|
|
|
|
|
|
size_t
|
2013-06-23 12:03:39 +00:00
|
|
|
nsRootPresContext::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const
|
2012-02-21 05:02:24 +00:00
|
|
|
{
|
|
|
|
return nsPresContext::SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
|
|
|
|
// Measurement of the following members may be added later if DMD finds it is
|
|
|
|
// worthwhile:
|
|
|
|
// - mNotifyDidPaintTimer
|
|
|
|
// - mRegisteredPlugins
|
|
|
|
// - mWillPaintObservers
|
|
|
|
// - mWillPaintFallbackEvent
|
|
|
|
}
|