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