Blame layout/base/nsPresContext.h

Packit f0b94e
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
Packit f0b94e
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
Packit f0b94e
/* This Source Code Form is subject to the terms of the Mozilla Public
Packit f0b94e
 * License, v. 2.0. If a copy of the MPL was not distributed with this
Packit f0b94e
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
Packit f0b94e
Packit f0b94e
/* a presentation of a document, part 1 */
Packit f0b94e
Packit f0b94e
#ifndef nsPresContext_h___
Packit f0b94e
#define nsPresContext_h___
Packit f0b94e
Packit f0b94e
#include "mozilla/Attributes.h"
Packit f0b94e
#include "mozilla/MediaFeatureChange.h"
Packit f0b94e
#include "mozilla/NotNull.h"
Packit f0b94e
#include "mozilla/UniquePtr.h"
Packit f0b94e
#include "mozilla/WeakPtr.h"
Packit f0b94e
#include "nsColor.h"
Packit f0b94e
#include "nsCoord.h"
Packit f0b94e
#include "nsCOMPtr.h"
Packit f0b94e
#include "nsIPresShell.h"
Packit f0b94e
#include "nsIPresShellInlines.h"
Packit f0b94e
#include "nsRect.h"
Packit f0b94e
#include "nsStringFwd.h"
Packit f0b94e
#include "nsFont.h"
Packit f0b94e
#include "gfxFontConstants.h"
Packit f0b94e
#include "nsAtom.h"
Packit f0b94e
#include "nsITimer.h"
Packit f0b94e
#include "nsCRT.h"
Packit f0b94e
#include "nsIWidgetListener.h"
Packit f0b94e
#include "nsLanguageAtomService.h"
Packit f0b94e
#include "nsGkAtoms.h"
Packit f0b94e
#include "nsCycleCollectionParticipant.h"
Packit f0b94e
#include "nsChangeHint.h"
Packit f0b94e
#include <algorithm>
Packit f0b94e
#include "gfxTypes.h"
Packit f0b94e
#include "gfxRect.h"
Packit f0b94e
#include "nsTArray.h"
Packit f0b94e
#include "nsAutoPtr.h"
Packit f0b94e
#include "mozilla/MemoryReporting.h"
Packit f0b94e
#include "mozilla/TimeStamp.h"
Packit f0b94e
#include "mozilla/AppUnits.h"
Packit f0b94e
#include "prclist.h"
Packit f0b94e
#include "nsThreadUtils.h"
Packit f0b94e
#include "ScrollbarStyles.h"
Packit f0b94e
#include "nsIMessageManager.h"
Packit f0b94e
#include "mozilla/RestyleLogging.h"
Packit f0b94e
#include "Units.h"
Packit f0b94e
#include "prenv.h"
Packit f0b94e
#include "mozilla/StaticPresData.h"
Packit f0b94e
#include "mozilla/StyleBackendType.h"
Packit f0b94e
Packit f0b94e
class nsBidi;
Packit f0b94e
class nsIPrintSettings;
Packit f0b94e
class nsDocShell;
Packit f0b94e
class nsIDocShell;
Packit f0b94e
class nsIDocument;
Packit f0b94e
class nsITheme;
Packit f0b94e
class nsIContent;
Packit f0b94e
class nsIFrame;
Packit f0b94e
class nsFrameManager;
Packit f0b94e
class nsILinkHandler;
Packit f0b94e
class nsAtom;
Packit f0b94e
class nsIRunnable;
Packit f0b94e
class gfxFontFeatureValueSet;
Packit f0b94e
class gfxUserFontEntry;
Packit f0b94e
class gfxUserFontSet;
Packit f0b94e
class gfxTextPerfMetrics;
Packit f0b94e
class nsCSSFontFeatureValuesRule;
Packit f0b94e
class nsPluginFrame;
Packit f0b94e
class nsTransitionManager;
Packit f0b94e
class nsAnimationManager;
Packit f0b94e
class nsRefreshDriver;
Packit f0b94e
class nsIWidget;
Packit f0b94e
class nsDeviceContext;
Packit f0b94e
class gfxMissingFontRecorder;
Packit f0b94e
Packit f0b94e
namespace mozilla {
Packit f0b94e
class AnimationEventDispatcher;
Packit f0b94e
class EffectCompositor;
Packit f0b94e
class Encoding;
Packit f0b94e
class EventStateManager;
Packit f0b94e
class CounterStyleManager;
Packit f0b94e
class RestyleManager;
Packit f0b94e
namespace layers {
Packit f0b94e
class ContainerLayer;
Packit f0b94e
class LayerManager;
Packit f0b94e
}  // namespace layers
Packit f0b94e
namespace dom {
Packit f0b94e
class Element;
Packit f0b94e
}  // namespace dom
Packit f0b94e
}  // namespace mozilla
Packit f0b94e
Packit f0b94e
// supported values for cached bool types
Packit f0b94e
enum nsPresContext_CachedBoolPrefType {
Packit f0b94e
  kPresContext_UseDocumentFonts = 1,
Packit f0b94e
  kPresContext_UnderlineLinks
Packit f0b94e
};
Packit f0b94e
Packit f0b94e
// supported values for cached integer pref types
Packit f0b94e
enum nsPresContext_CachedIntPrefType {
Packit f0b94e
  kPresContext_ScrollbarSide = 1,
Packit f0b94e
  kPresContext_BidiDirection
Packit f0b94e
};
Packit f0b94e
Packit f0b94e
// IDs for the default variable and fixed fonts (not to be changed, see
Packit f0b94e
// nsFont.h) To be used for Get/SetDefaultFont(). The other IDs in nsFont.h are
Packit f0b94e
// also supported.
Packit f0b94e
const uint8_t kPresContext_DefaultVariableFont_ID =
Packit f0b94e
    0x00;  // kGenericFont_moz_variable
Packit f0b94e
const uint8_t kPresContext_DefaultFixedFont_ID =
Packit f0b94e
    0x01;  // kGenericFont_moz_fixed
Packit f0b94e
Packit f0b94e
#ifdef DEBUG
Packit f0b94e
struct nsAutoLayoutPhase;
Packit f0b94e
Packit f0b94e
enum nsLayoutPhase {
Packit f0b94e
  eLayoutPhase_Paint,
Packit f0b94e
  eLayoutPhase_DisplayListBuilding,  // sometimes a subset of the paint phase
Packit f0b94e
  eLayoutPhase_Reflow,
Packit f0b94e
  eLayoutPhase_FrameC,
Packit f0b94e
  eLayoutPhase_COUNT
Packit f0b94e
};
Packit f0b94e
#endif
Packit f0b94e
Packit f0b94e
/* Used by nsPresContext::HasAuthorSpecifiedRules */
Packit f0b94e
#define NS_AUTHOR_SPECIFIED_BACKGROUND (1 << 0)
Packit f0b94e
#define NS_AUTHOR_SPECIFIED_BORDER (1 << 1)
Packit f0b94e
#define NS_AUTHOR_SPECIFIED_PADDING (1 << 2)
Packit f0b94e
Packit f0b94e
class nsRootPresContext;
Packit f0b94e
Packit f0b94e
// An interface for presentation contexts. Presentation contexts are
Packit f0b94e
// objects that provide an outer context for a presentation shell.
Packit f0b94e
Packit f0b94e
class nsPresContext : public nsISupports,
Packit f0b94e
                      public mozilla::SupportsWeakPtr<nsPresContext> {
Packit f0b94e
 public:
Packit f0b94e
  using Encoding = mozilla::Encoding;
Packit f0b94e
  template <typename T>
Packit f0b94e
  using NotNull = mozilla::NotNull<T>;
Packit f0b94e
  typedef mozilla::LangGroupFontPrefs LangGroupFontPrefs;
Packit f0b94e
  typedef mozilla::ScrollbarStyles ScrollbarStyles;
Packit f0b94e
  typedef mozilla::StaticPresData StaticPresData;
Packit f0b94e
Packit f0b94e
  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
Packit f0b94e
  NS_DECL_CYCLE_COLLECTION_CLASS(nsPresContext)
Packit f0b94e
  MOZ_DECLARE_WEAKREFERENCE_TYPENAME(nsPresContext)
Packit f0b94e
Packit f0b94e
  enum nsPresContextType {
Packit f0b94e
    eContext_Galley,        // unpaginated screen presentation
Packit f0b94e
    eContext_PrintPreview,  // paginated screen presentation
Packit f0b94e
    eContext_Print,         // paginated printer presentation
Packit f0b94e
    eContext_PageLayout     // paginated & editable.
Packit f0b94e
  };
Packit f0b94e
Packit f0b94e
  nsPresContext(nsIDocument* aDocument, nsPresContextType aType);
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Initialize the presentation context from a particular device.
Packit f0b94e
   */
Packit f0b94e
  nsresult Init(nsDeviceContext* aDeviceContext);
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Set and detach presentation shell that this context is bound to.
Packit f0b94e
   * A presentation context may only be bound to a single shell.
Packit f0b94e
   */
Packit f0b94e
  void AttachShell(nsIPresShell* aShell,
Packit f0b94e
                   mozilla::StyleBackendType aBackendType);
Packit f0b94e
  void DetachShell();
Packit f0b94e
Packit f0b94e
  nsPresContextType Type() const { return mType; }
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Get the PresentationShell that this context is bound to.
Packit f0b94e
   */
Packit f0b94e
  nsIPresShell* PresShell() const {
Packit f0b94e
    NS_ASSERTION(mShell, "Null pres shell");
Packit f0b94e
    return mShell;
Packit f0b94e
  }
Packit f0b94e
Packit f0b94e
  nsIPresShell* GetPresShell() const { return mShell; }
Packit f0b94e
Packit f0b94e
  void DispatchCharSetChange(NotNull<const Encoding*> aCharSet);
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Returns the parent prescontext for this one. Returns null if this is a
Packit f0b94e
   * root.
Packit f0b94e
   */
Packit f0b94e
  nsPresContext* GetParentPresContext();
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Returns the prescontext of the toplevel content document that contains
Packit f0b94e
   * this presentation, or null if there isn't one.
Packit f0b94e
   */
Packit f0b94e
  nsPresContext* GetToplevelContentDocumentPresContext();
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Returns the nearest widget for the root frame of this.
Packit f0b94e
   *
Packit f0b94e
   * @param aOffset     If non-null the offset from the origin of the root
Packit f0b94e
   *                    frame's view to the widget's origin (usually positive)
Packit f0b94e
   *                    expressed in appunits of this will be returned in
Packit f0b94e
   *                    aOffset.
Packit f0b94e
   */
Packit f0b94e
  nsIWidget* GetNearestWidget(nsPoint* aOffset = nullptr);
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Returns the root widget for this.
Packit f0b94e
   * Note that the widget is a mediater with IME.
Packit f0b94e
   */
Packit f0b94e
  nsIWidget* GetRootWidget();
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Return the presentation context for the root of the view manager
Packit f0b94e
   * hierarchy that contains this presentation context, or nullptr if it can't
Packit f0b94e
   * be found (e.g. it's detached).
Packit f0b94e
   */
Packit f0b94e
  nsRootPresContext* GetRootPresContext();
Packit f0b94e
Packit f0b94e
  virtual bool IsRoot() { return false; }
Packit f0b94e
Packit f0b94e
  nsIDocument* Document() const {
Packit f0b94e
    NS_ASSERTION(
Packit f0b94e
        !mShell || !mShell->GetDocument() || mShell->GetDocument() == mDocument,
Packit f0b94e
        "nsPresContext doesn't have the same document as nsPresShell!");
Packit f0b94e
    return mDocument;
Packit f0b94e
  }
Packit f0b94e
Packit f0b94e
  mozilla::StyleSetHandle StyleSet() const {
Packit f0b94e
    return GetPresShell()->StyleSet();
Packit f0b94e
  }
Packit f0b94e
Packit f0b94e
  bool HasPendingMediaQueryUpdates() const {
Packit f0b94e
    return !!mPendingMediaFeatureValuesChange;
Packit f0b94e
  }
Packit f0b94e
Packit f0b94e
  nsCSSFrameConstructor* FrameConstructor() {
Packit f0b94e
    return PresShell()->FrameConstructor();
Packit f0b94e
  }
Packit f0b94e
Packit f0b94e
  mozilla::AnimationEventDispatcher* AnimationEventDispatcher() {
Packit f0b94e
    return mAnimationEventDispatcher;
Packit f0b94e
  }
Packit f0b94e
Packit f0b94e
  mozilla::EffectCompositor* EffectCompositor() { return mEffectCompositor; }
Packit f0b94e
  nsTransitionManager* TransitionManager() { return mTransitionManager; }
Packit f0b94e
  nsAnimationManager* AnimationManager() { return mAnimationManager; }
Packit f0b94e
  const nsAnimationManager* AnimationManager() const {
Packit f0b94e
    return mAnimationManager;
Packit f0b94e
  }
Packit f0b94e
Packit f0b94e
  nsRefreshDriver* RefreshDriver() { return mRefreshDriver; }
Packit f0b94e
Packit f0b94e
  mozilla::RestyleManager* RestyleManager() {
Packit f0b94e
    MOZ_ASSERT(mRestyleManager);
Packit f0b94e
    return mRestyleManager;
Packit f0b94e
  }
Packit f0b94e
Packit f0b94e
  mozilla::CounterStyleManager* CounterStyleManager() const {
Packit f0b94e
    return mCounterStyleManager;
Packit f0b94e
  }
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Rebuilds all style data by throwing out the old rule tree and
Packit f0b94e
   * building a new one, and additionally applying aExtraHint (which
Packit f0b94e
   * must not contain nsChangeHint_ReconstructFrame) to the root frame.
Packit f0b94e
   * For aRestyleHint, see RestyleManager::RebuildAllStyleData.
Packit f0b94e
   * Also rebuild the user font set and counter style manager.
Packit f0b94e
   */
Packit f0b94e
  void RebuildAllStyleData(nsChangeHint aExtraHint, nsRestyleHint aRestyleHint);
Packit f0b94e
  /**
Packit f0b94e
   * Just like RebuildAllStyleData, except (1) asynchronous and (2) it
Packit f0b94e
   * doesn't rebuild the user font set.
Packit f0b94e
   */
Packit f0b94e
  void PostRebuildAllStyleDataEvent(nsChangeHint aExtraHint,
Packit f0b94e
                                    nsRestyleHint aRestyleHint);
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Handle changes in the values of media features (used in media
Packit f0b94e
   * queries).
Packit f0b94e
   *
Packit f0b94e
   * There are three sensible values to use for aRestyleHint:
Packit f0b94e
   *  * nsRestyleHint(0) to rebuild style data, with rerunning of
Packit f0b94e
   *    selector matching, only if media features have changed
Packit f0b94e
   *  * eRestyle_ForceDescendants to force rebuilding of style data (but
Packit f0b94e
   *    still only rerun selector matching if media query results have
Packit f0b94e
   *    changed).  (RebuildAllStyleData always adds
Packit f0b94e
   *    eRestyle_ForceDescendants internally, so here we're only using
Packit f0b94e
   *    it to distinguish from nsRestyleHint(0) whether we need to call
Packit f0b94e
   *    RebuildAllStyleData at all.)
Packit f0b94e
   *  * eRestyle_Subtree to force rebuilding of style data with
Packit f0b94e
   *    rerunning of selector matching
Packit f0b94e
   *
Packit f0b94e
   * For aChangeHint, see RestyleManager::RebuildAllStyleData.  (Passing
Packit f0b94e
   * a nonzero aChangeHint forces rebuilding style data even if
Packit f0b94e
   * nsRestyleHint(0) is passed.)
Packit f0b94e
   */
Packit f0b94e
  void MediaFeatureValuesChanged(const mozilla::MediaFeatureChange& aChange) {
Packit f0b94e
    if (mShell) {
Packit f0b94e
      mShell->EnsureStyleFlush();
Packit f0b94e
    }
Packit f0b94e
Packit f0b94e
    if (!mPendingMediaFeatureValuesChange) {
Packit f0b94e
      mPendingMediaFeatureValuesChange.emplace(aChange);
Packit f0b94e
      return;
Packit f0b94e
    }
Packit f0b94e
Packit f0b94e
    *mPendingMediaFeatureValuesChange |= aChange;
Packit f0b94e
  }
Packit f0b94e
Packit f0b94e
  void FlushPendingMediaFeatureValuesChanged();
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Calls MediaFeatureValuesChanged for this pres context and all descendant
Packit f0b94e
   * subdocuments that have a pres context. This should be used for media
Packit f0b94e
   * features that must be updated in all subdocuments e.g. display-mode.
Packit f0b94e
   */
Packit f0b94e
  void MediaFeatureValuesChangedAllDocuments(
Packit f0b94e
      const mozilla::MediaFeatureChange&);
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Updates the size mode on all remote children and recursively notifies this
Packit f0b94e
   * document and all subdocuments (including remote children) that a media
Packit f0b94e
   * feature value has changed.
Packit f0b94e
   */
Packit f0b94e
  void SizeModeChanged(nsSizeMode aSizeMode);
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Access compatibility mode for this context.  This is the same as
Packit f0b94e
   * our document's compatibility mode.
Packit f0b94e
   */
Packit f0b94e
  nsCompatibility CompatibilityMode() const;
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Notify the context that the document's compatibility mode has changed
Packit f0b94e
   */
Packit f0b94e
  void CompatibilityModeChanged();
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Access the image animation mode for this context
Packit f0b94e
   */
Packit f0b94e
  uint16_t ImageAnimationMode() const { return mImageAnimationMode; }
Packit f0b94e
  void SetImageAnimationMode(uint16_t aMode);
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Get medium of presentation
Packit f0b94e
   */
Packit f0b94e
  nsAtom* Medium() {
Packit f0b94e
    if (!mIsEmulatingMedia) return mMedium;
Packit f0b94e
    return mMediaEmulated;
Packit f0b94e
  }
Packit f0b94e
Packit f0b94e
  /*
Packit f0b94e
   * Render the document as if being viewed on a device with the specified
Packit f0b94e
   * media type.
Packit f0b94e
   */
Packit f0b94e
  void EmulateMedium(const nsAString& aMediaType);
Packit f0b94e
Packit f0b94e
  /*
Packit f0b94e
   * Restore the viewer's natural medium
Packit f0b94e
   */
Packit f0b94e
  void StopEmulatingMedium();
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Get the default font for the given language and generic font ID.
Packit f0b94e
   * If aLanguage is nullptr, the document's language is used.
Packit f0b94e
   *
Packit f0b94e
   * See the comment in StaticPresData::GetDefaultFont.
Packit f0b94e
   */
Packit f0b94e
  const nsFont* GetDefaultFont(uint8_t aFontID, nsAtom* aLanguage,
Packit f0b94e
                               bool* aNeedsToCache = nullptr) const {
Packit f0b94e
    nsAtom* lang = aLanguage ? aLanguage : mLanguage.get();
Packit f0b94e
    const LangGroupFontPrefs* prefs = GetFontPrefsForLang(lang, aNeedsToCache);
Packit f0b94e
    if (aNeedsToCache && *aNeedsToCache) {
Packit f0b94e
      return nullptr;
Packit f0b94e
    }
Packit f0b94e
    return StaticPresData::Get()->GetDefaultFontHelper(aFontID, lang, prefs);
Packit f0b94e
  }
Packit f0b94e
Packit f0b94e
  void ForceCacheLang(nsAtom* aLanguage);
Packit f0b94e
  void CacheAllLangs();
Packit f0b94e
Packit f0b94e
  /** Get a cached boolean pref, by its type */
Packit f0b94e
  // *  - initially created for bugs 31816, 20760, 22963
Packit f0b94e
  bool GetCachedBoolPref(nsPresContext_CachedBoolPrefType aPrefType) const {
Packit f0b94e
    // If called with a constant parameter, the compiler should optimize
Packit f0b94e
    // this switch statement away.
Packit f0b94e
    switch (aPrefType) {
Packit f0b94e
      case kPresContext_UseDocumentFonts:
Packit f0b94e
        return mUseDocumentFonts;
Packit f0b94e
      case kPresContext_UnderlineLinks:
Packit f0b94e
        return mUnderlineLinks;
Packit f0b94e
      default:
Packit f0b94e
        NS_ERROR("Invalid arg passed to GetCachedBoolPref");
Packit f0b94e
    }
Packit f0b94e
Packit f0b94e
    return false;
Packit f0b94e
  }
Packit f0b94e
Packit f0b94e
  /** Get a cached integer pref, by its type */
Packit f0b94e
  // *  - initially created for bugs 30910, 61883, 74186, 84398
Packit f0b94e
  int32_t GetCachedIntPref(nsPresContext_CachedIntPrefType aPrefType) const {
Packit f0b94e
    // If called with a constant parameter, the compiler should optimize
Packit f0b94e
    // this switch statement away.
Packit f0b94e
    switch (aPrefType) {
Packit f0b94e
      case kPresContext_ScrollbarSide:
Packit f0b94e
        return mPrefScrollbarSide;
Packit f0b94e
      case kPresContext_BidiDirection:
Packit f0b94e
        return mPrefBidiDirection;
Packit f0b94e
      default:
Packit f0b94e
        NS_ERROR("invalid arg passed to GetCachedIntPref");
Packit f0b94e
    }
Packit f0b94e
Packit f0b94e
    return false;
Packit f0b94e
  }
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Get the default colors
Packit f0b94e
   */
Packit f0b94e
  nscolor DefaultColor() const { return mDefaultColor; }
Packit f0b94e
  nscolor DefaultBackgroundColor() const { return mBackgroundColor; }
Packit f0b94e
  nscolor DefaultLinkColor() const { return mLinkColor; }
Packit f0b94e
  nscolor DefaultActiveLinkColor() const { return mActiveLinkColor; }
Packit f0b94e
  nscolor DefaultVisitedLinkColor() const { return mVisitedLinkColor; }
Packit f0b94e
  nscolor FocusBackgroundColor() const { return mFocusBackgroundColor; }
Packit f0b94e
  nscolor FocusTextColor() const { return mFocusTextColor; }
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Body text color, for use in quirks mode only.
Packit f0b94e
   */
Packit f0b94e
  nscolor BodyTextColor() const { return mBodyTextColor; }
Packit f0b94e
  void SetBodyTextColor(nscolor aColor) { mBodyTextColor = aColor; }
Packit f0b94e
Packit f0b94e
  bool GetUseFocusColors() const { return mUseFocusColors; }
Packit f0b94e
  uint8_t FocusRingWidth() const { return mFocusRingWidth; }
Packit f0b94e
  bool GetFocusRingOnAnything() const { return mFocusRingOnAnything; }
Packit f0b94e
  uint8_t GetFocusRingStyle() const { return mFocusRingStyle; }
Packit f0b94e
Packit f0b94e
  void SetContainer(nsIDocShell* aContainer);
Packit f0b94e
Packit f0b94e
  nsISupports* GetContainerWeak() const;
Packit f0b94e
Packit f0b94e
  nsIDocShell* GetDocShell() const;
Packit f0b94e
Packit f0b94e
  // XXX this are going to be replaced with set/get container
Packit f0b94e
  void SetLinkHandler(nsILinkHandler* aHandler) { mLinkHandler = aHandler; }
Packit f0b94e
  nsILinkHandler* GetLinkHandler() { return mLinkHandler; }
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Detach this pres context - i.e. cancel relevant timers,
Packit f0b94e
   * SetLinkHandler(null), SetContainer(null) etc.
Packit f0b94e
   * Only to be used by the DocumentViewer.
Packit f0b94e
   */
Packit f0b94e
  virtual void Detach();
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Get the visible area associated with this presentation context.
Packit f0b94e
   * This is the size of the visible area that is used for
Packit f0b94e
   * presenting the document. The returned value is in the standard
Packit f0b94e
   * nscoord units (as scaled by the device context).
Packit f0b94e
   */
Packit f0b94e
  nsRect GetVisibleArea() const { return mVisibleArea; }
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Set the currently visible area. The units for r are standard
Packit f0b94e
   * nscoord units (as scaled by the device context).
Packit f0b94e
   */
Packit f0b94e
  void SetVisibleArea(const nsRect& r) {
Packit f0b94e
    if (!r.IsEqualEdges(mVisibleArea)) {
Packit f0b94e
      mVisibleArea = r;
Packit f0b94e
      // Visible area does not affect media queries when paginated.
Packit f0b94e
      if (!IsPaginated()) {
Packit f0b94e
        MediaFeatureValuesChanged(
Packit f0b94e
            {mozilla::MediaFeatureChangeReason::ViewportChange});
Packit f0b94e
      }
Packit f0b94e
    }
Packit f0b94e
  }
Packit f0b94e
Packit f0b94e
  bool ShouldFireResizeEvent() const {
Packit f0b94e
    return !mLastResizeEventVisibleArea.IsEqualEdges(mVisibleArea);
Packit f0b94e
  }
Packit f0b94e
Packit f0b94e
  void WillFireResizeEvent() { mLastResizeEventVisibleArea = mVisibleArea; }
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Return true if this presentation context is a paginated
Packit f0b94e
   * context.
Packit f0b94e
   */
Packit f0b94e
  bool IsPaginated() const { return mPaginated; }
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Sets whether the presentation context can scroll for a paginated
Packit f0b94e
   * context.
Packit f0b94e
   */
Packit f0b94e
  void SetPaginatedScrolling(bool aResult);
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Return true if this presentation context can scroll for paginated
Packit f0b94e
   * context.
Packit f0b94e
   */
Packit f0b94e
  bool HasPaginatedScrolling() const { return mCanPaginatedScroll; }
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Get/set the size of a page
Packit f0b94e
   */
Packit f0b94e
  nsSize GetPageSize() { return mPageSize; }
Packit f0b94e
  void SetPageSize(nsSize aSize) { mPageSize = aSize; }
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Get/set whether this document should be treated as having real pages
Packit f0b94e
   * XXX This raises the obvious question of why a document that isn't a page
Packit f0b94e
   *     is paginated; there isn't a good reason except history
Packit f0b94e
   */
Packit f0b94e
  bool IsRootPaginatedDocument() { return mIsRootPaginatedDocument; }
Packit f0b94e
  void SetIsRootPaginatedDocument(bool aIsRootPaginatedDocument) {
Packit f0b94e
    mIsRootPaginatedDocument = aIsRootPaginatedDocument;
Packit f0b94e
  }
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Get/set the print scaling level; used by nsPageFrame to scale up
Packit f0b94e
   * pages.  Set safe to call before reflow, get guaranteed to be set
Packit f0b94e
   * properly after reflow.
Packit f0b94e
   */
Packit f0b94e
Packit f0b94e
  float GetPageScale() { return mPageScale; }
Packit f0b94e
  void SetPageScale(float aScale) { mPageScale = aScale; }
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Get/set the scaling facor to use when rendering the pages for print
Packit f0b94e
   * preview. Only safe to get after print preview set up; safe to set anytime.
Packit f0b94e
   * This is a scaling factor for the display of the print preview.  It
Packit f0b94e
   * does not affect layout.  It only affects the size of the onscreen pages
Packit f0b94e
   * in print preview.
Packit f0b94e
   * XXX Temporary: see http://wiki.mozilla.org/Gecko:PrintPreview
Packit f0b94e
   */
Packit f0b94e
  float GetPrintPreviewScale() { return mPPScale; }
Packit f0b94e
  void SetPrintPreviewScale(float aScale) { mPPScale = aScale; }
Packit f0b94e
Packit f0b94e
  nsDeviceContext* DeviceContext() const { return mDeviceContext; }
Packit f0b94e
  mozilla::EventStateManager* EventStateManager() { return mEventManager; }
Packit f0b94e
  nsAtom* GetLanguageFromCharset() const { return mLanguage; }
Packit f0b94e
  already_AddRefed<nsAtom> GetContentLanguage() const;
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Get/set a text zoom factor that is applied on top of the normal text zoom
Packit f0b94e
   * set by the front-end/user.
Packit f0b94e
   */
Packit f0b94e
  float GetSystemFontScale() const { return mSystemFontScale; }
Packit f0b94e
  void SetSystemFontScale(float aFontScale) {
Packit f0b94e
    MOZ_ASSERT(aFontScale > 0.0f, "invalid font scale");
Packit f0b94e
    if (aFontScale == mSystemFontScale || IsPrintingOrPrintPreview()) {
Packit f0b94e
      return;
Packit f0b94e
    }
Packit f0b94e
Packit f0b94e
    mSystemFontScale = aFontScale;
Packit f0b94e
    UpdateEffectiveTextZoom();
Packit f0b94e
  }
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Get/set the text zoom factor in use.
Packit f0b94e
   * This value should be used if you're interested in the pure text zoom value
Packit f0b94e
   * controlled by the front-end, e.g. when transferring zoom levels to a new
Packit f0b94e
   * document.
Packit f0b94e
   * Code that wants to use this value for layouting and rendering purposes
Packit f0b94e
   * should consider using EffectiveTextZoom() instead, so as to take the system
Packit f0b94e
   * font scale into account as well.
Packit f0b94e
   */
Packit f0b94e
  float TextZoom() const { return mTextZoom; }
Packit f0b94e
  void SetTextZoom(float aZoom) {
Packit f0b94e
    MOZ_ASSERT(aZoom > 0.0f, "invalid zoom factor");
Packit f0b94e
    if (aZoom == mTextZoom) return;
Packit f0b94e
Packit f0b94e
    mTextZoom = aZoom;
Packit f0b94e
    UpdateEffectiveTextZoom();
Packit f0b94e
  }
Packit f0b94e
Packit f0b94e
 protected:
Packit f0b94e
  void UpdateEffectiveTextZoom();
Packit f0b94e
Packit f0b94e
 public:
Packit f0b94e
  /**
Packit f0b94e
   * Corresponds to the product of text zoom and system font scale, limited
Packit f0b94e
   * by zoom.maxPercent and minPercent.
Packit f0b94e
   * As the system font scale is automatically set by the PresShell, code that
Packit f0b94e
   * e.g. wants to transfer zoom levels to a new document should use TextZoom()
Packit f0b94e
   * instead, which corresponds to the text zoom level that was actually set by
Packit f0b94e
   * the front-end/user.
Packit f0b94e
   */
Packit f0b94e
  float EffectiveTextZoom() const { return mEffectiveTextZoom; }
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Get the minimum font size for the specified language. If aLanguage
Packit f0b94e
   * is nullptr, then the document's language is used.  This combines
Packit f0b94e
   * the language-specific global preference with the per-presentation
Packit f0b94e
   * base minimum font size.
Packit f0b94e
   */
Packit f0b94e
  int32_t MinFontSize(nsAtom* aLanguage, bool* aNeedsToCache = nullptr) const {
Packit f0b94e
    const LangGroupFontPrefs* prefs =
Packit f0b94e
        GetFontPrefsForLang(aLanguage, aNeedsToCache);
Packit f0b94e
    if (aNeedsToCache && *aNeedsToCache) {
Packit f0b94e
      return 0;
Packit f0b94e
    }
Packit f0b94e
    return std::max(mBaseMinFontSize, prefs->mMinimumFontSize);
Packit f0b94e
  }
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Get the per-presentation base minimum font size.  This size is
Packit f0b94e
   * independent of the language-specific global preference.
Packit f0b94e
   */
Packit f0b94e
  int32_t BaseMinFontSize() const { return mBaseMinFontSize; }
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Set the per-presentation base minimum font size.  This size is
Packit f0b94e
   * independent of the language-specific global preference.
Packit f0b94e
   */
Packit f0b94e
  void SetBaseMinFontSize(int32_t aMinFontSize) {
Packit f0b94e
    if (aMinFontSize == mBaseMinFontSize) {
Packit f0b94e
      return;
Packit f0b94e
    }
Packit f0b94e
Packit f0b94e
    mBaseMinFontSize = aMinFontSize;
Packit f0b94e
Packit f0b94e
    // Media queries could have changed, since we changed the meaning
Packit f0b94e
    // of 'em' units in them.
Packit f0b94e
    MediaFeatureValuesChanged(
Packit f0b94e
        {eRestyle_ForceDescendants, NS_STYLE_HINT_REFLOW,
Packit f0b94e
         mozilla::MediaFeatureChangeReason::MinFontSizeChange});
Packit f0b94e
  }
Packit f0b94e
Packit f0b94e
  float GetFullZoom() { return mFullZoom; }
Packit f0b94e
  /**
Packit f0b94e
   * Device full zoom differs from full zoom because it gets the zoom from
Packit f0b94e
   * the device context, which may be using a different zoom due to rounding
Packit f0b94e
   * of app units to device pixels.
Packit f0b94e
   */
Packit f0b94e
  float GetDeviceFullZoom();
Packit f0b94e
  void SetFullZoom(float aZoom);
Packit f0b94e
Packit f0b94e
  float GetOverrideDPPX() { return mOverrideDPPX; }
Packit f0b94e
  void SetOverrideDPPX(float aDPPX);
Packit f0b94e
Packit f0b94e
  nscoord GetAutoQualityMinFontSize() {
Packit f0b94e
    return DevPixelsToAppUnits(mAutoQualityMinFontSizePixelsPref);
Packit f0b94e
  }
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Return the device's screen size in inches, for font size
Packit f0b94e
   * inflation.
Packit f0b94e
   *
Packit f0b94e
   * If |aChanged| is non-null, then aChanged is filled in with whether
Packit f0b94e
   * the screen size value has changed since either:
Packit f0b94e
   *  a. the last time the function was called with non-null aChanged, or
Packit f0b94e
   *  b. the first time the function was called.
Packit f0b94e
   */
Packit f0b94e
  gfxSize ScreenSizeInchesForFontInflation(bool* aChanged = nullptr);
Packit f0b94e
Packit f0b94e
  static int32_t AppUnitsPerCSSPixel() {
Packit f0b94e
    return mozilla::AppUnitsPerCSSPixel();
Packit f0b94e
  }
Packit f0b94e
  int32_t AppUnitsPerDevPixel() const;
Packit f0b94e
  static int32_t AppUnitsPerCSSInch() { return mozilla::AppUnitsPerCSSInch(); }
Packit f0b94e
Packit f0b94e
  static nscoord CSSPixelsToAppUnits(int32_t aPixels) {
Packit f0b94e
    return NSToCoordRoundWithClamp(float(aPixels) *
Packit f0b94e
                                   float(AppUnitsPerCSSPixel()));
Packit f0b94e
  }
Packit f0b94e
Packit f0b94e
  static nscoord CSSPixelsToAppUnits(float aPixels) {
Packit f0b94e
    return NSToCoordRoundWithClamp(aPixels * float(AppUnitsPerCSSPixel()));
Packit f0b94e
  }
Packit f0b94e
Packit f0b94e
  static int32_t AppUnitsToIntCSSPixels(nscoord aAppUnits) {
Packit f0b94e
    return NSAppUnitsToIntPixels(aAppUnits, float(AppUnitsPerCSSPixel()));
Packit f0b94e
  }
Packit f0b94e
Packit f0b94e
  static float AppUnitsToFloatCSSPixels(nscoord aAppUnits) {
Packit f0b94e
    return NSAppUnitsToFloatPixels(aAppUnits, float(AppUnitsPerCSSPixel()));
Packit f0b94e
  }
Packit f0b94e
Packit f0b94e
  static double AppUnitsToDoubleCSSPixels(nscoord aAppUnits) {
Packit f0b94e
    return NSAppUnitsToDoublePixels(aAppUnits, double(AppUnitsPerCSSPixel()));
Packit f0b94e
  }
Packit f0b94e
Packit f0b94e
  nscoord DevPixelsToAppUnits(int32_t aPixels) const {
Packit f0b94e
    return NSIntPixelsToAppUnits(aPixels, AppUnitsPerDevPixel());
Packit f0b94e
  }
Packit f0b94e
Packit f0b94e
  int32_t AppUnitsToDevPixels(nscoord aAppUnits) const {
Packit f0b94e
    return NSAppUnitsToIntPixels(aAppUnits, float(AppUnitsPerDevPixel()));
Packit f0b94e
  }
Packit f0b94e
Packit f0b94e
  float AppUnitsToFloatDevPixels(nscoord aAppUnits) {
Packit f0b94e
    return aAppUnits / float(AppUnitsPerDevPixel());
Packit f0b94e
  }
Packit f0b94e
Packit f0b94e
  int32_t CSSPixelsToDevPixels(int32_t aPixels) {
Packit f0b94e
    return AppUnitsToDevPixels(CSSPixelsToAppUnits(aPixels));
Packit f0b94e
  }
Packit f0b94e
Packit f0b94e
  float CSSPixelsToDevPixels(float aPixels) {
Packit f0b94e
    return NSAppUnitsToFloatPixels(CSSPixelsToAppUnits(aPixels),
Packit f0b94e
                                   float(AppUnitsPerDevPixel()));
Packit f0b94e
  }
Packit f0b94e
Packit f0b94e
  int32_t DevPixelsToIntCSSPixels(int32_t aPixels) {
Packit f0b94e
    return AppUnitsToIntCSSPixels(DevPixelsToAppUnits(aPixels));
Packit f0b94e
  }
Packit f0b94e
Packit f0b94e
  float DevPixelsToFloatCSSPixels(int32_t aPixels) {
Packit f0b94e
    return AppUnitsToFloatCSSPixels(DevPixelsToAppUnits(aPixels));
Packit f0b94e
  }
Packit f0b94e
Packit f0b94e
  mozilla::CSSToLayoutDeviceScale CSSToDevPixelScale() const {
Packit f0b94e
    return mozilla::CSSToLayoutDeviceScale(float(AppUnitsPerCSSPixel()) /
Packit f0b94e
                                           float(AppUnitsPerDevPixel()));
Packit f0b94e
  }
Packit f0b94e
Packit f0b94e
  // If there is a remainder, it is rounded to nearest app units.
Packit f0b94e
  nscoord GfxUnitsToAppUnits(gfxFloat aGfxUnits) const;
Packit f0b94e
Packit f0b94e
  gfxFloat AppUnitsToGfxUnits(nscoord aAppUnits) const;
Packit f0b94e
Packit f0b94e
  gfxRect AppUnitsToGfxUnits(const nsRect& aAppRect) const {
Packit f0b94e
    return gfxRect(AppUnitsToGfxUnits(aAppRect.x),
Packit f0b94e
                   AppUnitsToGfxUnits(aAppRect.y),
Packit f0b94e
                   AppUnitsToGfxUnits(aAppRect.Width()),
Packit f0b94e
                   AppUnitsToGfxUnits(aAppRect.Height()));
Packit f0b94e
  }
Packit f0b94e
Packit f0b94e
  static nscoord CSSTwipsToAppUnits(float aTwips) {
Packit f0b94e
    return NSToCoordRoundWithClamp(mozilla::AppUnitsPerCSSInch() *
Packit f0b94e
                                   NS_TWIPS_TO_INCHES(aTwips));
Packit f0b94e
  }
Packit f0b94e
Packit f0b94e
  // Margin-specific version, since they often need TwipsToAppUnits
Packit f0b94e
  static nsMargin CSSTwipsToAppUnits(const nsIntMargin& marginInTwips) {
Packit f0b94e
    return nsMargin(CSSTwipsToAppUnits(float(marginInTwips.top)),
Packit f0b94e
                    CSSTwipsToAppUnits(float(marginInTwips.right)),
Packit f0b94e
                    CSSTwipsToAppUnits(float(marginInTwips.bottom)),
Packit f0b94e
                    CSSTwipsToAppUnits(float(marginInTwips.left)));
Packit f0b94e
  }
Packit f0b94e
Packit f0b94e
  static nscoord CSSPointsToAppUnits(float aPoints) {
Packit f0b94e
    return NSToCoordRound(aPoints * mozilla::AppUnitsPerCSSInch() /
Packit f0b94e
                          POINTS_PER_INCH_FLOAT);
Packit f0b94e
  }
Packit f0b94e
Packit f0b94e
  nscoord PhysicalMillimetersToAppUnits(float aMM) const;
Packit f0b94e
Packit f0b94e
  nscoord RoundAppUnitsToNearestDevPixels(nscoord aAppUnits) const {
Packit f0b94e
    return DevPixelsToAppUnits(AppUnitsToDevPixels(aAppUnits));
Packit f0b94e
  }
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * This checks the root element and the HTML BODY, if any, for an "overflow"
Packit f0b94e
   * property that should be applied to the viewport. If one is found then we
Packit f0b94e
   * return the element that we took the overflow from (which should then be
Packit f0b94e
   * treated as "overflow: visible"), and we store the overflow style here.
Packit f0b94e
   * If the document is in fullscreen, and the fullscreen element is not the
Packit f0b94e
   * root, the scrollbar of viewport will be suppressed.
Packit f0b94e
   * @return if scroll was propagated from some content node, the content node
Packit f0b94e
   *         it was propagated from.
Packit f0b94e
   */
Packit f0b94e
  mozilla::dom::Element* UpdateViewportScrollbarStylesOverride();
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Returns the cached result from the last call to
Packit f0b94e
   * UpdateViewportScrollbarStylesOverride() -- i.e. return the node
Packit f0b94e
   * whose scrollbar styles we have propagated to the viewport (or nullptr if
Packit f0b94e
   * there is no such node).
Packit f0b94e
   */
Packit f0b94e
  mozilla::dom::Element* GetViewportScrollbarStylesOverrideElement() const {
Packit f0b94e
    return mViewportScrollbarOverrideElement;
Packit f0b94e
  }
Packit f0b94e
Packit f0b94e
  const ScrollbarStyles& GetViewportScrollbarStylesOverride() const {
Packit f0b94e
    return mViewportStyleScrollbar;
Packit f0b94e
  }
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Check whether the given element would propagate its scrollbar styles to the
Packit f0b94e
   * viewport in non-paginated mode.  Must only be called if IsPaginated().
Packit f0b94e
   */
Packit f0b94e
  bool ElementWouldPropagateScrollbarStyles(mozilla::dom::Element* aElement);
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Set and get methods for controlling the background drawing
Packit f0b94e
   */
Packit f0b94e
  bool GetBackgroundImageDraw() const { return mDrawImageBackground; }
Packit f0b94e
  void SetBackgroundImageDraw(bool aCanDraw) {
Packit f0b94e
    mDrawImageBackground = aCanDraw;
Packit f0b94e
  }
Packit f0b94e
Packit f0b94e
  bool GetBackgroundColorDraw() const { return mDrawColorBackground; }
Packit f0b94e
  void SetBackgroundColorDraw(bool aCanDraw) {
Packit f0b94e
    mDrawColorBackground = aCanDraw;
Packit f0b94e
  }
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   *  Check if bidi enabled (set depending on the presence of RTL
Packit f0b94e
   *  characters or when default directionality is RTL).
Packit f0b94e
   *  If enabled, we should apply the Unicode Bidi Algorithm
Packit f0b94e
   *
Packit f0b94e
   *  @lina 07/12/2000
Packit f0b94e
   */
Packit f0b94e
  bool BidiEnabled() const;
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   *  Set bidi enabled. This means we should apply the Unicode Bidi Algorithm
Packit f0b94e
   *
Packit f0b94e
   *  @lina 07/12/2000
Packit f0b94e
   */
Packit f0b94e
  void SetBidiEnabled() const;
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   *  Set visual or implicit mode into the pres context.
Packit f0b94e
   *
Packit f0b94e
   *  Visual directionality is a presentation method that displays text
Packit f0b94e
   *  as if it were a uni-directional, according to the primary display
Packit f0b94e
   *  direction only.
Packit f0b94e
   *
Packit f0b94e
   *  Implicit directionality is a presentation method in which the
Packit f0b94e
   *  direction is determined by the Bidi algorithm according to the
Packit f0b94e
   *  category of the characters and the category of the adjacent
Packit f0b94e
   *  characters, and according to their primary direction.
Packit f0b94e
   *
Packit f0b94e
   *  @lina 05/02/2000
Packit f0b94e
   */
Packit f0b94e
  void SetVisualMode(bool aIsVisual) { mIsVisual = aIsVisual; }
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   *  Check whether the content should be treated as visual.
Packit f0b94e
   *
Packit f0b94e
   *  @lina 05/02/2000
Packit f0b94e
   */
Packit f0b94e
  bool IsVisualMode() const { return mIsVisual; }
Packit f0b94e
Packit f0b94e
  enum class InteractionType : uint32_t {
Packit f0b94e
    eClickInteraction,
Packit f0b94e
    eKeyInteraction,
Packit f0b94e
    eMouseMoveInteraction,
Packit f0b94e
    eScrollInteraction
Packit f0b94e
  };
Packit f0b94e
Packit f0b94e
  void RecordInteractionTime(InteractionType aType,
Packit f0b94e
                             const mozilla::TimeStamp& aTimeStamp);
Packit f0b94e
Packit f0b94e
  void DisableInteractionTimeRecording() { mInteractionTimeEnabled = false; }
Packit f0b94e
Packit f0b94e
  // Mohamed
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Set the Bidi options for the presentation context
Packit f0b94e
   */
Packit f0b94e
  void SetBidi(uint32_t aBidiOptions);
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Get the Bidi options for the presentation context
Packit f0b94e
   * Not inline so consumers of nsPresContext are not forced to
Packit f0b94e
   * include nsIDocument.
Packit f0b94e
   */
Packit f0b94e
  uint32_t GetBidi() const;
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Render only Selection
Packit f0b94e
   */
Packit f0b94e
  void SetIsRenderingOnlySelection(bool aResult) {
Packit f0b94e
    mIsRenderingOnlySelection = aResult;
Packit f0b94e
  }
Packit f0b94e
Packit f0b94e
  bool IsRenderingOnlySelection() const { return mIsRenderingOnlySelection; }
Packit f0b94e
Packit f0b94e
  bool IsTopLevelWindowInactive();
Packit f0b94e
Packit f0b94e
  /*
Packit f0b94e
   * Obtain a native them for rendering our widgets (both form controls and
Packit f0b94e
   * html)
Packit f0b94e
   */
Packit f0b94e
  nsITheme* GetTheme();
Packit f0b94e
Packit f0b94e
  /*
Packit f0b94e
   * Notify the pres context that the theme has changed.  An internal switch
Packit f0b94e
   * means it's one of our Mozilla themes that changed (e.g., Modern to
Packit f0b94e
   * Classic). Otherwise, the OS is telling us that the native theme for the
Packit f0b94e
   * platform has changed.
Packit f0b94e
   */
Packit f0b94e
  void ThemeChanged();
Packit f0b94e
Packit f0b94e
  /*
Packit f0b94e
   * Notify the pres context that the resolution of the user interface has
Packit f0b94e
   * changed. This happens if a window is moved between HiDPI and non-HiDPI
Packit f0b94e
   * displays, so that the ratio of points to device pixels changes.
Packit f0b94e
   * The notification happens asynchronously.
Packit f0b94e
   */
Packit f0b94e
  void UIResolutionChanged();
Packit f0b94e
Packit f0b94e
  /*
Packit f0b94e
   * Like UIResolutionChanged() but invalidates values immediately.
Packit f0b94e
   */
Packit f0b94e
  void UIResolutionChangedSync();
Packit f0b94e
Packit f0b94e
  /*
Packit f0b94e
   * Notify the pres context that a system color has changed
Packit f0b94e
   */
Packit f0b94e
  void SysColorChanged();
Packit f0b94e
Packit f0b94e
  /** Printing methods below should only be used for Medium() == print **/
Packit f0b94e
  void SetPrintSettings(nsIPrintSettings* aPrintSettings);
Packit f0b94e
Packit f0b94e
  nsIPrintSettings* GetPrintSettings() { return mPrintSettings; }
Packit f0b94e
Packit f0b94e
  /* Helper function that ensures that this prescontext is shown in its
Packit f0b94e
     docshell if it's the most recent prescontext for the docshell.  Returns
Packit f0b94e
     whether the prescontext is now being shown.
Packit f0b94e
  */
Packit f0b94e
  bool EnsureVisible();
Packit f0b94e
Packit f0b94e
#ifdef MOZ_REFLOW_PERF
Packit f0b94e
  void CountReflows(const char* aName, nsIFrame* aFrame);
Packit f0b94e
#endif
Packit f0b94e
Packit f0b94e
  void ConstructedFrame() { ++mFramesConstructed; }
Packit f0b94e
  void ReflowedFrame() { ++mFramesReflowed; }
Packit f0b94e
Packit f0b94e
  uint64_t FramesConstructedCount() { return mFramesConstructed; }
Packit f0b94e
  uint64_t FramesReflowedCount() { return mFramesReflowed; }
Packit f0b94e
Packit f0b94e
  /*
Packit f0b94e
   * Helper functions for a telemetry scroll probe
Packit f0b94e
   * for more information see bug 1340904
Packit f0b94e
   */
Packit f0b94e
  void SetTelemetryScrollY(nscoord aScrollY) {
Packit f0b94e
    nscoord delta = abs(aScrollY - mTelemetryScrollLastY);
Packit f0b94e
    mTelemetryScrollLastY = aScrollY;
Packit f0b94e
Packit f0b94e
    mTelemetryScrollTotalY += delta;
Packit f0b94e
    if (aScrollY > mTelemetryScrollMaxY) {
Packit f0b94e
      mTelemetryScrollMaxY = aScrollY;
Packit f0b94e
    }
Packit f0b94e
  }
Packit f0b94e
  nscoord TelemetryScrollMaxY() const { return mTelemetryScrollMaxY; }
Packit f0b94e
  nscoord TelemetryScrollTotalY() const { return mTelemetryScrollTotalY; }
Packit f0b94e
Packit f0b94e
  static nscoord GetBorderWidthForKeyword(unsigned int aBorderWidthKeyword) {
Packit f0b94e
    // This table maps border-width enums 'thin', 'medium', 'thick'
Packit f0b94e
    // to actual nscoord values.
Packit f0b94e
    static const nscoord kBorderWidths[] = {
Packit f0b94e
        CSSPixelsToAppUnits(1), CSSPixelsToAppUnits(3), CSSPixelsToAppUnits(5)};
Packit f0b94e
    MOZ_ASSERT(size_t(aBorderWidthKeyword) <
Packit f0b94e
               mozilla::ArrayLength(kBorderWidths));
Packit f0b94e
Packit f0b94e
    return kBorderWidths[aBorderWidthKeyword];
Packit f0b94e
  }
Packit f0b94e
Packit f0b94e
  gfxTextPerfMetrics* GetTextPerfMetrics() { return mTextPerf; }
Packit f0b94e
Packit f0b94e
  bool IsDynamic() {
Packit f0b94e
    return (mType == eContext_PageLayout || mType == eContext_Galley);
Packit f0b94e
  }
Packit f0b94e
  bool IsScreen() {
Packit f0b94e
    return (mMedium == nsGkAtoms::screen || mType == eContext_PageLayout ||
Packit f0b94e
            mType == eContext_PrintPreview);
Packit f0b94e
  }
Packit f0b94e
  bool IsPrintingOrPrintPreview() {
Packit f0b94e
    return (mType == eContext_Print || mType == eContext_PrintPreview);
Packit f0b94e
  }
Packit f0b94e
Packit f0b94e
  // Is this presentation in a chrome docshell?
Packit f0b94e
  bool IsChrome() const { return mIsChrome; }
Packit f0b94e
  bool IsChromeOriginImage() const { return mIsChromeOriginImage; }
Packit f0b94e
  void UpdateIsChrome();
Packit f0b94e
Packit f0b94e
  // Public API for native theme code to get style internals.
Packit f0b94e
  bool HasAuthorSpecifiedRules(const nsIFrame* aFrame,
Packit f0b94e
                               uint32_t ruleTypeMask) const;
Packit f0b94e
Packit f0b94e
  // Is it OK to let the page specify colors and backgrounds?
Packit f0b94e
  bool UseDocumentColors() const {
Packit f0b94e
    MOZ_ASSERT(mUseDocumentColors || !(IsChrome() || IsChromeOriginImage()),
Packit f0b94e
               "We should never have a chrome doc or image that can't use its "
Packit f0b94e
               "colors.");
Packit f0b94e
    return mUseDocumentColors;
Packit f0b94e
  }
Packit f0b94e
Packit f0b94e
  // Explicitly enable and disable paint flashing.
Packit f0b94e
  void SetPaintFlashing(bool aPaintFlashing) {
Packit f0b94e
    mPaintFlashing = aPaintFlashing;
Packit f0b94e
    mPaintFlashingInitialized = true;
Packit f0b94e
  }
Packit f0b94e
Packit f0b94e
  // This method should be used instead of directly accessing mPaintFlashing,
Packit f0b94e
  // as that value may be out of date when mPaintFlashingInitialized is false.
Packit f0b94e
  bool GetPaintFlashing() const;
Packit f0b94e
Packit f0b94e
  bool SuppressingResizeReflow() const { return mSuppressResizeReflow; }
Packit f0b94e
Packit f0b94e
  gfxUserFontSet* GetUserFontSet(bool aFlushUserFontSet = true);
Packit f0b94e
Packit f0b94e
  // Should be called whenever the set of fonts available in the user
Packit f0b94e
  // font set changes (e.g., because a new font loads, or because the
Packit f0b94e
  // user font set is changed and fonts become unavailable).
Packit f0b94e
  void UserFontSetUpdated(gfxUserFontEntry* aUpdatedFont = nullptr);
Packit f0b94e
Packit f0b94e
  gfxMissingFontRecorder* MissingFontRecorder() { return mMissingFonts; }
Packit f0b94e
  void NotifyMissingFonts();
Packit f0b94e
Packit f0b94e
  void FlushCounterStyles();
Packit f0b94e
  void MarkCounterStylesDirty();
Packit f0b94e
Packit f0b94e
  void FlushFontFeatureValues();
Packit f0b94e
  void MarkFontFeatureValuesDirty() { mFontFeatureValuesDirty = true; }
Packit f0b94e
Packit f0b94e
  // Ensure that it is safe to hand out CSS rules outside the layout
Packit f0b94e
  // engine by ensuring that all CSS style sheets have unique inners
Packit f0b94e
  // and, if necessary, synchronously rebuilding all style data.
Packit f0b94e
  void EnsureSafeToHandOutCSSRules();
Packit f0b94e
Packit f0b94e
  // Mark an area as invalidated, associated with a given transaction id
Packit f0b94e
  // (allocated by nsRefreshDriver::GetTransactionId). Invalidated regions will
Packit f0b94e
  // be dispatched to MozAfterPaint events when NotifyDidPaintForSubtree is
Packit f0b94e
  // called for the transaction id (or any higher id).
Packit f0b94e
  void NotifyInvalidation(uint64_t aTransactionId, const nsRect& aRect);
Packit f0b94e
  // aRect is in device pixels
Packit f0b94e
  void NotifyInvalidation(uint64_t aTransactionId, const nsIntRect& aRect);
Packit f0b94e
  void NotifyDidPaintForSubtree(
Packit f0b94e
      uint64_t aTransactionId = 0,
Packit f0b94e
      const mozilla::TimeStamp& aTimeStamp = mozilla::TimeStamp());
Packit f0b94e
  void FireDOMPaintEvent(nsTArray<nsRect>* aList, uint64_t aTransactionId,
Packit f0b94e
                         mozilla::TimeStamp aTimeStamp = mozilla::TimeStamp());
Packit f0b94e
Packit f0b94e
  // Callback for catching invalidations in ContainerLayers
Packit f0b94e
  // Passed to LayerProperties::ComputeDifference
Packit f0b94e
  static void NotifySubDocInvalidation(
Packit f0b94e
      mozilla::layers::ContainerLayer* aContainer, const nsIntRegion* aRegion);
Packit f0b94e
  void SetNotifySubDocInvalidationData(
Packit f0b94e
      mozilla::layers::ContainerLayer* aContainer);
Packit f0b94e
  static void ClearNotifySubDocInvalidationData(
Packit f0b94e
      mozilla::layers::ContainerLayer* aContainer);
Packit f0b94e
  bool IsDOMPaintEventPending();
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Returns the RestyleManager's restyle generation counter.
Packit f0b94e
   */
Packit f0b94e
  uint64_t GetRestyleGeneration() const;
Packit f0b94e
  uint64_t GetUndisplayedRestyleGeneration() const;
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Returns whether there are any pending restyles or reflows.
Packit f0b94e
   */
Packit f0b94e
  bool HasPendingRestyleOrReflow();
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Informs the document's FontFaceSet that the refresh driver ticked,
Packit f0b94e
   * flushing style and layout.
Packit f0b94e
   */
Packit f0b94e
  void NotifyFontFaceSetOnRefresh();
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Notify the prescontext that the presshell is about to reflow a reflow root.
Packit f0b94e
   * The single argument indicates whether this reflow should be interruptible.
Packit f0b94e
   * If aInterruptible is false then CheckForInterrupt and HasPendingInterrupt
Packit f0b94e
   * will always return false. If aInterruptible is true then CheckForInterrupt
Packit f0b94e
   * will return true when a pending event is detected.  This is for use by the
Packit f0b94e
   * presshell only.  Reflow code wanting to prevent interrupts should use
Packit f0b94e
   * InterruptPreventer.
Packit f0b94e
   */
Packit f0b94e
  void ReflowStarted(bool aInterruptible);
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * A class that can be used to temporarily disable reflow interruption.
Packit f0b94e
   */
Packit f0b94e
  class InterruptPreventer;
Packit f0b94e
  friend class InterruptPreventer;
Packit f0b94e
  class MOZ_STACK_CLASS InterruptPreventer {
Packit f0b94e
   public:
Packit f0b94e
    explicit InterruptPreventer(nsPresContext* aCtx)
Packit f0b94e
        : mCtx(aCtx),
Packit f0b94e
          mInterruptsEnabled(aCtx->mInterruptsEnabled),
Packit f0b94e
          mHasPendingInterrupt(aCtx->mHasPendingInterrupt) {
Packit f0b94e
      mCtx->mInterruptsEnabled = false;
Packit f0b94e
      mCtx->mHasPendingInterrupt = false;
Packit f0b94e
    }
Packit f0b94e
    ~InterruptPreventer() {
Packit f0b94e
      mCtx->mInterruptsEnabled = mInterruptsEnabled;
Packit f0b94e
      mCtx->mHasPendingInterrupt = mHasPendingInterrupt;
Packit f0b94e
    }
Packit f0b94e
Packit f0b94e
   private:
Packit f0b94e
    nsPresContext* mCtx;
Packit f0b94e
    bool mInterruptsEnabled;
Packit f0b94e
    bool mHasPendingInterrupt;
Packit f0b94e
  };
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Check for interrupts. This may return true if a pending event is
Packit f0b94e
   * detected. Once it has returned true, it will keep returning true
Packit f0b94e
   * until ReflowStarted is called. In all cases where this returns true,
Packit f0b94e
   * the passed-in frame (which should be the frame whose reflow will be
Packit f0b94e
   * interrupted if true is returned) will be passed to
Packit f0b94e
   * nsIPresShell::FrameNeedsToContinueReflow.
Packit f0b94e
   */
Packit f0b94e
  bool CheckForInterrupt(nsIFrame* aFrame);
Packit f0b94e
  /**
Packit f0b94e
   * Returns true if CheckForInterrupt has returned true since the last
Packit f0b94e
   * ReflowStarted call. Cannot itself trigger an interrupt check.
Packit f0b94e
   */
Packit f0b94e
  bool HasPendingInterrupt() { return mHasPendingInterrupt; }
Packit f0b94e
  /**
Packit f0b94e
   * Sets a flag that will trip a reflow interrupt. This only bypasses the
Packit f0b94e
   * interrupt timeout and the pending event check; other checks such as whether
Packit f0b94e
   * interrupts are enabled and the interrupt check skipping still take effect.
Packit f0b94e
   */
Packit f0b94e
  void SetPendingInterruptFromTest() { mPendingInterruptFromTest = true; }
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * If we have a presshell, and if the given content's current
Packit f0b94e
   * document is the same as our presshell's document, return the
Packit f0b94e
   * content's primary frame.  Otherwise, return null.  Only use this
Packit f0b94e
   * if you care about which presshell the primary frame is in.
Packit f0b94e
   */
Packit f0b94e
  nsIFrame* GetPrimaryFrameFor(nsIContent* aContent);
Packit f0b94e
Packit f0b94e
  virtual size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
Packit f0b94e
  virtual size_t SizeOfIncludingThis(
Packit f0b94e
      mozilla::MallocSizeOf aMallocSizeOf) const {
Packit f0b94e
    return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
Packit f0b94e
  }
Packit f0b94e
Packit f0b94e
  bool IsRootContentDocument() const;
Packit f0b94e
Packit f0b94e
  bool HadNonBlankPaint() const { return mHadNonBlankPaint; }
Packit f0b94e
Packit f0b94e
  void NotifyNonBlankPaint();
Packit f0b94e
Packit f0b94e
  bool UsesRootEMUnits() const { return mUsesRootEMUnits; }
Packit f0b94e
Packit f0b94e
  void SetUsesRootEMUnits(bool aValue) { mUsesRootEMUnits = aValue; }
Packit f0b94e
Packit f0b94e
  bool UsesExChUnits() const { return mUsesExChUnits; }
Packit f0b94e
Packit f0b94e
  void SetUsesExChUnits(bool aValue) { mUsesExChUnits = aValue; }
Packit f0b94e
Packit f0b94e
  // true if there are OMTA transition updates for the current document which
Packit f0b94e
  // have been throttled, and therefore some style information may not be up
Packit f0b94e
  // to date
Packit f0b94e
  bool ExistThrottledUpdates() const { return mExistThrottledUpdates; }
Packit f0b94e
Packit f0b94e
  void SetExistThrottledUpdates(bool aExistThrottledUpdates) {
Packit f0b94e
    mExistThrottledUpdates = aExistThrottledUpdates;
Packit f0b94e
  }
Packit f0b94e
Packit f0b94e
  bool IsDeviceSizePageSize();
Packit f0b94e
Packit f0b94e
  bool HasWarnedAboutPositionedTableParts() const {
Packit f0b94e
    return mHasWarnedAboutPositionedTableParts;
Packit f0b94e
  }
Packit f0b94e
Packit f0b94e
  void SetHasWarnedAboutPositionedTableParts() {
Packit f0b94e
    mHasWarnedAboutPositionedTableParts = true;
Packit f0b94e
  }
Packit f0b94e
Packit f0b94e
  bool HasWarnedAboutTooLargeDashedOrDottedRadius() const {
Packit f0b94e
    return mHasWarnedAboutTooLargeDashedOrDottedRadius;
Packit f0b94e
  }
Packit f0b94e
Packit f0b94e
  void SetHasWarnedAboutTooLargeDashedOrDottedRadius() {
Packit f0b94e
    mHasWarnedAboutTooLargeDashedOrDottedRadius = true;
Packit f0b94e
  }
Packit f0b94e
Packit f0b94e
  nsBidi& GetBidiEngine();
Packit f0b94e
Packit f0b94e
  gfxFontFeatureValueSet* GetFontFeatureValuesLookup() const {
Packit f0b94e
    return mFontFeatureValuesLookup;
Packit f0b94e
  }
Packit f0b94e
Packit f0b94e
 protected:
Packit f0b94e
  friend class nsRunnableMethod<nsPresContext>;
Packit f0b94e
  void ThemeChangedInternal();
Packit f0b94e
  void SysColorChangedInternal();
Packit f0b94e
  void RefreshSystemMetrics();
Packit f0b94e
Packit f0b94e
  // update device context's resolution from the widget
Packit f0b94e
  void UIResolutionChangedInternal();
Packit f0b94e
Packit f0b94e
  // if aScale > 0.0, use it as resolution scale factor to the device context
Packit f0b94e
  // (otherwise get it from the widget)
Packit f0b94e
  void UIResolutionChangedInternalScale(double aScale);
Packit f0b94e
Packit f0b94e
  // aData here is a pointer to a double that holds the CSS to device-pixel
Packit f0b94e
  // scale factor from the parent, which will be applied to the subdocument's
Packit f0b94e
  // device context instead of retrieving a scale from the widget.
Packit f0b94e
  static bool UIResolutionChangedSubdocumentCallback(nsIDocument* aDocument,
Packit f0b94e
                                                     void* aData);
Packit f0b94e
Packit f0b94e
  void SetImgAnimations(nsIContent* aParent, uint16_t aMode);
Packit f0b94e
  void SetSMILAnimations(nsIDocument* aDoc, uint16_t aNewMode,
Packit f0b94e
                         uint16_t aOldMode);
Packit f0b94e
  void GetDocumentColorPreferences();
Packit f0b94e
Packit f0b94e
  void PreferenceChanged(const char* aPrefName);
Packit f0b94e
  static void PrefChangedCallback(const char*, void*);
Packit f0b94e
Packit f0b94e
  void UpdateAfterPreferencesChanged();
Packit f0b94e
  void DispatchPrefChangedRunnableIfNeeded();
Packit f0b94e
Packit f0b94e
  void GetUserPreferences();
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Fetch the user's font preferences for the given aLanguage's
Packit f0b94e
   * langugage group.
Packit f0b94e
   */
Packit f0b94e
  const LangGroupFontPrefs* GetFontPrefsForLang(
Packit f0b94e
      nsAtom* aLanguage, bool* aNeedsToCache = nullptr) const {
Packit f0b94e
    nsAtom* lang = aLanguage ? aLanguage : mLanguage.get();
Packit f0b94e
    return StaticPresData::Get()->GetFontPrefsForLangHelper(
Packit f0b94e
        lang, &mLangGroupFontPrefs, aNeedsToCache);
Packit f0b94e
  }
Packit f0b94e
Packit f0b94e
  void UpdateCharSet(NotNull<const Encoding*> aCharSet);
Packit f0b94e
Packit f0b94e
  static bool NotifyDidPaintSubdocumentCallback(nsIDocument* aDocument,
Packit f0b94e
                                                void* aData);
Packit f0b94e
Packit f0b94e
 public:
Packit f0b94e
  // Used by the PresShell to force a reflow when some aspect of font info
Packit f0b94e
  // has been updated, potentially affecting font selection and layout.
Packit f0b94e
  void ForceReflowForFontInfoUpdate();
Packit f0b94e
Packit f0b94e
  void DoChangeCharSet(NotNull<const Encoding*> aCharSet);
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Checks for MozAfterPaint listeners on the document
Packit f0b94e
   */
Packit f0b94e
  bool MayHavePaintEventListener();
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Checks for MozAfterPaint listeners on the document and
Packit f0b94e
   * any subdocuments, except for subdocuments that are non-top-level
Packit f0b94e
   * content documents.
Packit f0b94e
   */
Packit f0b94e
  bool MayHavePaintEventListenerInSubDocument();
Packit f0b94e
Packit f0b94e
#ifdef RESTYLE_LOGGING
Packit f0b94e
  // Controls for whether debug information about restyling in this
Packit f0b94e
  // document should be output.
Packit f0b94e
  bool RestyleLoggingEnabled() const { return mRestyleLoggingEnabled; }
Packit f0b94e
  void StartRestyleLogging() { mRestyleLoggingEnabled = true; }
Packit f0b94e
  void StopRestyleLogging() { mRestyleLoggingEnabled = false; }
Packit f0b94e
#endif
Packit f0b94e
Packit f0b94e
  void InvalidatePaintedLayers();
Packit f0b94e
Packit f0b94e
 protected:
Packit f0b94e
  // May be called multiple times (unlink, destructor)
Packit f0b94e
  void Destroy();
Packit f0b94e
Packit f0b94e
  void AppUnitsPerDevPixelChanged();
Packit f0b94e
Packit f0b94e
  bool HavePendingInputEvent();
Packit f0b94e
Packit f0b94e
  // Creates a one-shot timer with the given aCallback & aDelay.
Packit f0b94e
  // Returns a refcounted pointer to the timer (or nullptr on failure).
Packit f0b94e
  already_AddRefed<nsITimer> CreateTimer(nsTimerCallbackFunc aCallback,
Packit f0b94e
                                         const char* aName, uint32_t aDelay);
Packit f0b94e
Packit f0b94e
  struct TransactionInvalidations {
Packit f0b94e
    uint64_t mTransactionId;
Packit f0b94e
    nsTArray<nsRect> mInvalidations;
Packit f0b94e
  };
Packit f0b94e
  TransactionInvalidations* GetInvalidations(uint64_t aTransactionId);
Packit f0b94e
Packit f0b94e
  // IMPORTANT: The ownership implicit in the following member variables
Packit f0b94e
  // has been explicitly checked.  If you add any members to this class,
Packit f0b94e
  // please make the ownership explicit (pinkerton, scc).
Packit f0b94e
Packit f0b94e
  nsPresContextType mType;
Packit f0b94e
  // the nsPresShell owns a strong reference to the nsPresContext, and is
Packit f0b94e
  // responsible for nulling this pointer before it is destroyed
Packit f0b94e
  nsIPresShell* MOZ_NON_OWNING_REF mShell;  // [WEAK]
Packit f0b94e
  nsCOMPtr<nsIDocument> mDocument;
Packit f0b94e
  RefPtr<nsDeviceContext> mDeviceContext;  // [STRONG] could be weak, but
Packit f0b94e
                                           // better safe than sorry.
Packit f0b94e
                                           // Cannot reintroduce cycles
Packit f0b94e
                                           // since there is no dependency
Packit f0b94e
                                           // from gfx back to layout.
Packit f0b94e
  RefPtr<mozilla::EventStateManager> mEventManager;
Packit f0b94e
  RefPtr<nsRefreshDriver> mRefreshDriver;
Packit f0b94e
  RefPtr<mozilla::AnimationEventDispatcher> mAnimationEventDispatcher;
Packit f0b94e
  RefPtr<mozilla::EffectCompositor> mEffectCompositor;
Packit f0b94e
  RefPtr<nsTransitionManager> mTransitionManager;
Packit f0b94e
  RefPtr<nsAnimationManager> mAnimationManager;
Packit f0b94e
  RefPtr<mozilla::RestyleManager> mRestyleManager;
Packit f0b94e
  RefPtr<mozilla::CounterStyleManager> mCounterStyleManager;
Packit f0b94e
  nsAtom* MOZ_UNSAFE_REF(
Packit f0b94e
      "always a static atom") mMedium;  // initialized by subclass ctors
Packit f0b94e
  RefPtr<nsAtom> mMediaEmulated;
Packit f0b94e
  RefPtr<gfxFontFeatureValueSet> mFontFeatureValuesLookup;
Packit f0b94e
Packit f0b94e
  // This pointer is nulled out through SetLinkHandler() in the destructors of
Packit f0b94e
  // the classes which set it. (using SetLinkHandler() again).
Packit f0b94e
  nsILinkHandler* MOZ_NON_OWNING_REF mLinkHandler;
Packit f0b94e
Packit f0b94e
  // Formerly mLangGroup; moving from charset-oriented langGroup to
Packit f0b94e
  // maintaining actual language settings everywhere (see bug 524107).
Packit f0b94e
  // This may in fact hold a langGroup such as x-western rather than
Packit f0b94e
  // a specific language, however (e.g, if it is inferred from the
Packit f0b94e
  // charset rather than explicitly specified as a lang attribute).
Packit f0b94e
  RefPtr<nsAtom> mLanguage;
Packit f0b94e
Packit f0b94e
 public:
Packit f0b94e
  // The following are public member variables so that we can use them
Packit f0b94e
  // with mozilla::AutoToggle or mozilla::AutoRestore.
Packit f0b94e
Packit f0b94e
  // Should we disable font size inflation because we're inside of
Packit f0b94e
  // shrink-wrapping calculations on an inflation container?
Packit f0b94e
  bool mInflationDisabledForShrinkWrap;
Packit f0b94e
Packit f0b94e
 protected:
Packit f0b94e
  mozilla::WeakPtr<nsDocShell> mContainer;
Packit f0b94e
Packit f0b94e
  // Base minimum font size, independent of the language-specific global
Packit f0b94e
  // preference. Defaults to 0
Packit f0b94e
  int32_t mBaseMinFontSize;
Packit f0b94e
  float mSystemFontScale;    // Internal text zoom factor, defaults to 1.0
Packit f0b94e
  float mTextZoom;           // Text zoom, defaults to 1.0
Packit f0b94e
  float mEffectiveTextZoom;  // Text zoom * system font scale
Packit f0b94e
  float mFullZoom;           // Page zoom, defaults to 1.0
Packit f0b94e
  float mOverrideDPPX;       // DPPX overrided, defaults to 0.0
Packit f0b94e
  gfxSize mLastFontInflationScreenSize;
Packit f0b94e
Packit f0b94e
  int32_t mCurAppUnitsPerDevPixel;
Packit f0b94e
  int32_t mAutoQualityMinFontSizePixelsPref;
Packit f0b94e
Packit f0b94e
  nsCOMPtr<nsITheme> mTheme;
Packit f0b94e
  nsLanguageAtomService* mLangService;
Packit f0b94e
  nsCOMPtr<nsIPrintSettings> mPrintSettings;
Packit f0b94e
Packit f0b94e
  mozilla::UniquePtr<nsBidi> mBidiEngine;
Packit f0b94e
Packit f0b94e
  AutoTArray<TransactionInvalidations, 4> mTransactions;
Packit f0b94e
Packit f0b94e
  // text performance metrics
Packit f0b94e
  nsAutoPtr<gfxTextPerfMetrics> mTextPerf;
Packit f0b94e
Packit f0b94e
  nsAutoPtr<gfxMissingFontRecorder> mMissingFonts;
Packit f0b94e
Packit f0b94e
  nsRect mVisibleArea;
Packit f0b94e
  nsRect mLastResizeEventVisibleArea;
Packit f0b94e
  nsSize mPageSize;
Packit f0b94e
  float mPageScale;
Packit f0b94e
  float mPPScale;
Packit f0b94e
Packit f0b94e
  nscolor mDefaultColor;
Packit f0b94e
  nscolor mBackgroundColor;
Packit f0b94e
Packit f0b94e
  nscolor mLinkColor;
Packit f0b94e
  nscolor mActiveLinkColor;
Packit f0b94e
  nscolor mVisitedLinkColor;
Packit f0b94e
Packit f0b94e
  nscolor mFocusBackgroundColor;
Packit f0b94e
  nscolor mFocusTextColor;
Packit f0b94e
Packit f0b94e
  nscolor mBodyTextColor;
Packit f0b94e
Packit f0b94e
  // This is a non-owning pointer. May be null. If non-null, it's guaranteed to
Packit f0b94e
  // be pointing to an element that's still alive, because we'll reset it in
Packit f0b94e
  // UpdateViewportScrollbarStylesOverride() as part of the cleanup code when
Packit f0b94e
  // this element is removed from the document. (For <body> and the root
Packit f0b94e
  // element, this call happens in nsCSSFrameConstructor::ContentRemoved(). For
Packit f0b94e
  // fullscreen elements, it happens in the fullscreen-specific cleanup invoked
Packit f0b94e
  // by Element::UnbindFromTree().)
Packit f0b94e
  mozilla::dom::Element* MOZ_NON_OWNING_REF mViewportScrollbarOverrideElement;
Packit f0b94e
  ScrollbarStyles mViewportStyleScrollbar;
Packit f0b94e
Packit f0b94e
  uint8_t mFocusRingWidth;
Packit f0b94e
Packit f0b94e
  bool mExistThrottledUpdates;
Packit f0b94e
Packit f0b94e
  uint16_t mImageAnimationMode;
Packit f0b94e
  uint16_t mImageAnimationModePref;
Packit f0b94e
Packit f0b94e
  // Most documents will only use one (or very few) language groups. Rather
Packit f0b94e
  // than have the overhead of a hash lookup, we simply look along what will
Packit f0b94e
  // typically be a very short (usually of length 1) linked list. There are 31
Packit f0b94e
  // language groups, so in the worst case scenario we'll need to traverse 31
Packit f0b94e
  // link items.
Packit f0b94e
  LangGroupFontPrefs mLangGroupFontPrefs;
Packit f0b94e
Packit f0b94e
  bool mFontGroupCacheDirty;
Packit f0b94e
  nsTHashtable<nsRefPtrHashKey<nsAtom>> mLanguagesUsed;
Packit f0b94e
Packit f0b94e
  nscoord mBorderWidthTable[3];
Packit f0b94e
Packit f0b94e
  uint32_t mInterruptChecksToSkip;
Packit f0b94e
Packit f0b94e
  // Counters for tests and tools that want to detect frame construction
Packit f0b94e
  // or reflow.
Packit f0b94e
  uint64_t mElementsRestyled;
Packit f0b94e
  uint64_t mFramesConstructed;
Packit f0b94e
  uint64_t mFramesReflowed;
Packit f0b94e
Packit f0b94e
  mozilla::TimeStamp mReflowStartTime;
Packit f0b94e
Packit f0b94e
  // Time of various first interaction types, used to report time from
Packit f0b94e
  // first paint of the top level content pres shell to first interaction.
Packit f0b94e
  mozilla::TimeStamp mFirstNonBlankPaintTime;
Packit f0b94e
  mozilla::TimeStamp mFirstClickTime;
Packit f0b94e
  mozilla::TimeStamp mFirstKeyTime;
Packit f0b94e
  mozilla::TimeStamp mFirstMouseMoveTime;
Packit f0b94e
  mozilla::TimeStamp mFirstScrollTime;
Packit f0b94e
  bool mInteractionTimeEnabled;
Packit f0b94e
Packit f0b94e
  // last time we did a full style flush
Packit f0b94e
  mozilla::TimeStamp mLastStyleUpdateForAllAnimations;
Packit f0b94e
Packit f0b94e
  nscoord mTelemetryScrollLastY;
Packit f0b94e
  nscoord mTelemetryScrollMaxY;
Packit f0b94e
  nscoord mTelemetryScrollTotalY;
Packit f0b94e
Packit f0b94e
  unsigned mHasPendingInterrupt : 1;
Packit f0b94e
  unsigned mPendingInterruptFromTest : 1;
Packit f0b94e
  unsigned mInterruptsEnabled : 1;
Packit f0b94e
  unsigned mUseDocumentFonts : 1;
Packit f0b94e
  unsigned mUseDocumentColors : 1;
Packit f0b94e
  unsigned mUnderlineLinks : 1;
Packit f0b94e
  unsigned mSendAfterPaintToContent : 1;
Packit f0b94e
  unsigned mUseFocusColors : 1;
Packit f0b94e
  unsigned mFocusRingOnAnything : 1;
Packit f0b94e
  unsigned mFocusRingStyle : 1;
Packit f0b94e
  unsigned mDrawImageBackground : 1;
Packit f0b94e
  unsigned mDrawColorBackground : 1;
Packit f0b94e
  unsigned mNeverAnimate : 1;
Packit f0b94e
  unsigned mIsRenderingOnlySelection : 1;
Packit f0b94e
  unsigned mPaginated : 1;
Packit f0b94e
  unsigned mCanPaginatedScroll : 1;
Packit f0b94e
  unsigned mDoScaledTwips : 1;
Packit f0b94e
  unsigned mIsRootPaginatedDocument : 1;
Packit f0b94e
  unsigned mPrefBidiDirection : 1;
Packit f0b94e
  unsigned mPrefScrollbarSide : 2;
Packit f0b94e
  unsigned mPendingSysColorChanged : 1;
Packit f0b94e
  unsigned mPendingThemeChanged : 1;
Packit f0b94e
  unsigned mPendingUIResolutionChanged : 1;
Packit f0b94e
  unsigned mPrefChangePendingNeedsReflow : 1;
Packit f0b94e
  unsigned mPostedPrefChangedRunnable : 1;
Packit f0b94e
  unsigned mIsEmulatingMedia : 1;
Packit f0b94e
Packit f0b94e
  // Are we currently drawing an SVG glyph?
Packit f0b94e
  unsigned mIsGlyph : 1;
Packit f0b94e
Packit f0b94e
  // Does the associated document use root-em (rem) units?
Packit f0b94e
  unsigned mUsesRootEMUnits : 1;
Packit f0b94e
  // Does the associated document use ex or ch units?
Packit f0b94e
  unsigned mUsesExChUnits : 1;
Packit f0b94e
Packit f0b94e
  // Is the current mCounterStyleManager valid?
Packit f0b94e
  unsigned mCounterStylesDirty : 1;
Packit f0b94e
Packit f0b94e
  // Is the current mFontFeatureValuesLookup valid?
Packit f0b94e
  unsigned mFontFeatureValuesDirty : 1;
Packit f0b94e
Packit f0b94e
  // resize reflow is suppressed when the only change has been to zoom
Packit f0b94e
  // the document rather than to change the document's dimensions
Packit f0b94e
  unsigned mSuppressResizeReflow : 1;
Packit f0b94e
Packit f0b94e
  unsigned mIsVisual : 1;
Packit f0b94e
Packit f0b94e
  unsigned mIsChrome : 1;
Packit f0b94e
  unsigned mIsChromeOriginImage : 1;
Packit f0b94e
Packit f0b94e
  // Should we paint flash in this context? Do not use this variable directly.
Packit f0b94e
  // Use GetPaintFlashing() method instead.
Packit f0b94e
  mutable unsigned mPaintFlashing : 1;
Packit f0b94e
  mutable unsigned mPaintFlashingInitialized : 1;
Packit f0b94e
Packit f0b94e
  unsigned mHasWarnedAboutPositionedTableParts : 1;
Packit f0b94e
Packit f0b94e
  unsigned mHasWarnedAboutTooLargeDashedOrDottedRadius : 1;
Packit f0b94e
Packit f0b94e
  // Have we added quirk.css to the style set?
Packit f0b94e
  unsigned mQuirkSheetAdded : 1;
Packit f0b94e
Packit f0b94e
  // Is there a pref update to process once we have a container?
Packit f0b94e
  unsigned mNeedsPrefUpdate : 1;
Packit f0b94e
Packit f0b94e
  // Has NotifyNonBlankPaint been called on this PresContext?
Packit f0b94e
  unsigned mHadNonBlankPaint : 1;
Packit f0b94e
Packit f0b94e
#ifdef RESTYLE_LOGGING
Packit f0b94e
  // Should we output debug information about restyling for this document?
Packit f0b94e
  unsigned mRestyleLoggingEnabled : 1;
Packit f0b94e
#endif
Packit f0b94e
Packit f0b94e
#ifdef DEBUG
Packit f0b94e
  unsigned mInitialized : 1;
Packit f0b94e
#endif
Packit f0b94e
Packit f0b94e
  mozilla::Maybe<mozilla::MediaFeatureChange> mPendingMediaFeatureValuesChange;
Packit f0b94e
Packit f0b94e
 protected:
Packit f0b94e
  virtual ~nsPresContext();
Packit f0b94e
Packit f0b94e
  nscolor MakeColorPref(const nsString& aColor);
Packit f0b94e
Packit f0b94e
  void LastRelease();
Packit f0b94e
Packit f0b94e
#ifdef DEBUG
Packit f0b94e
 private:
Packit f0b94e
  friend struct nsAutoLayoutPhase;
Packit f0b94e
  uint32_t mLayoutPhaseCount[eLayoutPhase_COUNT];
Packit f0b94e
Packit f0b94e
 public:
Packit f0b94e
  uint32_t LayoutPhaseCount(nsLayoutPhase aPhase) {
Packit f0b94e
    return mLayoutPhaseCount[aPhase];
Packit f0b94e
  }
Packit f0b94e
#endif
Packit f0b94e
};
Packit f0b94e
Packit f0b94e
class nsRootPresContext final : public nsPresContext {
Packit f0b94e
 public:
Packit f0b94e
  nsRootPresContext(nsIDocument* aDocument, nsPresContextType aType);
Packit f0b94e
  virtual ~nsRootPresContext();
Packit f0b94e
  virtual void Detach() override;
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Ensure that NotifyDidPaintForSubtree is eventually called on this
Packit f0b94e
   * object after a timeout.
Packit f0b94e
   */
Packit f0b94e
  void EnsureEventualDidPaintEvent(uint64_t aTransactionId);
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Cancels any pending eventual did paint timer for transaction
Packit f0b94e
   * ids up to and including aTransactionId.
Packit f0b94e
   */
Packit f0b94e
  void CancelDidPaintTimers(uint64_t aTransactionId);
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Cancel all pending eventual did paint timers.
Packit f0b94e
   */
Packit f0b94e
  void CancelAllDidPaintTimers();
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Registers a plugin to receive geometry updates (position and clip
Packit f0b94e
   * region) so it can update its widget.
Packit f0b94e
   * Callers must call UnregisterPluginForGeometryUpdates before
Packit f0b94e
   * the aPlugin frame is destroyed.
Packit f0b94e
   */
Packit f0b94e
  void RegisterPluginForGeometryUpdates(nsIContent* aPlugin);
Packit f0b94e
  /**
Packit f0b94e
   * Stops a plugin receiving geometry updates (position and clip
Packit f0b94e
   * region). If the plugin was not already registered, this does
Packit f0b94e
   * nothing.
Packit f0b94e
   */
Packit f0b94e
  void UnregisterPluginForGeometryUpdates(nsIContent* aPlugin);
Packit f0b94e
Packit f0b94e
  bool NeedToComputePluginGeometryUpdates() {
Packit f0b94e
    return mRegisteredPlugins.Count() > 0;
Packit f0b94e
  }
Packit f0b94e
  /**
Packit f0b94e
   * Compute geometry updates for each plugin given that aList is the display
Packit f0b94e
   * list for aFrame. The updates are not yet applied;
Packit f0b94e
   * ApplyPluginGeometryUpdates is responsible for that. In the meantime they
Packit f0b94e
   * are stored on each nsPluginFrame.
Packit f0b94e
   * This needs to be called even when aFrame is a popup, since although
Packit f0b94e
   * windowed plugins aren't allowed in popups, windowless plugins are
Packit f0b94e
   * and ComputePluginGeometryUpdates needs to be called for them.
Packit f0b94e
   * aBuilder and aList can be null. This indicates that all plugins are
Packit f0b94e
   * hidden because we're in a background tab.
Packit f0b94e
   */
Packit f0b94e
  void ComputePluginGeometryUpdates(nsIFrame* aFrame,
Packit f0b94e
                                    nsDisplayListBuilder* aBuilder,
Packit f0b94e
                                    nsDisplayList* aList);
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Apply the stored plugin geometry updates. This should normally be called
Packit f0b94e
   * in DidPaint so the plugins are moved/clipped immediately after we've
Packit f0b94e
   * updated our window, so they look in sync with our window.
Packit f0b94e
   */
Packit f0b94e
  void ApplyPluginGeometryUpdates();
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Transfer stored plugin geometry updates to the compositor. Called during
Packit f0b94e
   * reflow, data is shipped over with layer updates. e10s specific.
Packit f0b94e
   */
Packit f0b94e
  void CollectPluginGeometryUpdates(
Packit f0b94e
      mozilla::layers::LayerManager* aLayerManager);
Packit f0b94e
Packit f0b94e
  virtual bool IsRoot() override { return true; }
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Add a runnable that will get called before the next paint. They will get
Packit f0b94e
   * run eventually even if painting doesn't happen. They might run well before
Packit f0b94e
   * painting happens.
Packit f0b94e
   */
Packit f0b94e
  void AddWillPaintObserver(nsIRunnable* aRunnable);
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Run all runnables that need to get called before the next paint.
Packit f0b94e
   */
Packit f0b94e
  void FlushWillPaintObservers();
Packit f0b94e
Packit f0b94e
  virtual size_t SizeOfExcludingThis(
Packit f0b94e
      mozilla::MallocSizeOf aMallocSizeOf) const override;
Packit f0b94e
Packit f0b94e
 protected:
Packit f0b94e
  /**
Packit f0b94e
   * Start a timer to ensure we eventually run ApplyPluginGeometryUpdates.
Packit f0b94e
   */
Packit f0b94e
  void InitApplyPluginGeometryTimer();
Packit f0b94e
  /**
Packit f0b94e
   * Cancel the timer that ensures we eventually run ApplyPluginGeometryUpdates.
Packit f0b94e
   */
Packit f0b94e
  void CancelApplyPluginGeometryTimer();
Packit f0b94e
Packit f0b94e
  class RunWillPaintObservers : public mozilla::Runnable {
Packit f0b94e
   public:
Packit f0b94e
    explicit RunWillPaintObservers(nsRootPresContext* aPresContext)
Packit f0b94e
        : Runnable("nsPresContextType::RunWillPaintObservers"),
Packit f0b94e
          mPresContext(aPresContext) {}
Packit f0b94e
    void Revoke() { mPresContext = nullptr; }
Packit f0b94e
    NS_IMETHOD Run() override {
Packit f0b94e
      if (mPresContext) {
Packit f0b94e
        mPresContext->FlushWillPaintObservers();
Packit f0b94e
      }
Packit f0b94e
      return NS_OK;
Packit f0b94e
    }
Packit f0b94e
    // The lifetime of this reference is handled by an nsRevocableEventPtr
Packit f0b94e
    nsRootPresContext* MOZ_NON_OWNING_REF mPresContext;
Packit f0b94e
  };
Packit f0b94e
Packit f0b94e
  friend class nsPresContext;
Packit f0b94e
Packit f0b94e
  struct NotifyDidPaintTimer {
Packit f0b94e
    uint64_t mTransactionId;
Packit f0b94e
    nsCOMPtr<nsITimer> mTimer;
Packit f0b94e
  };
Packit f0b94e
  AutoTArray<NotifyDidPaintTimer, 4> mNotifyDidPaintTimers;
Packit f0b94e
Packit f0b94e
  nsCOMPtr<nsITimer> mApplyPluginGeometryTimer;
Packit f0b94e
  nsTHashtable<nsRefPtrHashKey<nsIContent>> mRegisteredPlugins;
Packit f0b94e
  nsTArray<nsCOMPtr<nsIRunnable>> mWillPaintObservers;
Packit f0b94e
  nsRevocableEventPtr<RunWillPaintObservers> mWillPaintFallbackEvent;
Packit f0b94e
};
Packit f0b94e
Packit f0b94e
#ifdef MOZ_REFLOW_PERF
Packit f0b94e
Packit f0b94e
#define DO_GLOBAL_REFLOW_COUNT(_name) \
Packit f0b94e
  aPresContext->CountReflows((_name), (nsIFrame*)this);
Packit f0b94e
#else
Packit f0b94e
#define DO_GLOBAL_REFLOW_COUNT(_name)
Packit f0b94e
#endif  // MOZ_REFLOW_PERF
Packit f0b94e
Packit f0b94e
#endif /* nsPresContext_h___ */