layout/base/nsPresShell.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
     2  * vim: set ts=2 sw=2 et tw=78:
     3  * This Source Code Form is subject to the terms of the Mozilla Public
     4  * License, v. 2.0. If a copy of the MPL was not distributed with this
     5  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
     6  *
     7  * This Original Code has been modified by IBM Corporation.
     8  * Modifications made by IBM described herein are
     9  * Copyright (c) International Business Machines
    10  * Corporation, 2000
    11  *
    12  * Modifications to Mozilla code or documentation
    13  * identified per MPL Section 3.3
    14  *
    15  * Date         Modified by     Description of modification
    16  * 05/03/2000   IBM Corp.       Observer events for reflow states
    17  */
    19 /* a presentation of a document, part 2 */
    21 #ifndef nsPresShell_h_
    22 #define nsPresShell_h_
    24 #include "nsIPresShell.h"
    25 #include "nsStubDocumentObserver.h"
    26 #include "nsISelectionController.h"
    27 #include "nsIObserver.h"
    28 #include "nsWeakReference.h"
    29 #include "nsCRT.h"
    30 #include "nsAutoPtr.h"
    31 #include "nsIWidget.h"
    32 #include "nsStyleSet.h"
    33 #include "nsFrameSelection.h"
    34 #include "nsContentUtils.h" // For AddScriptBlocker().
    35 #include "nsRefreshDriver.h"
    36 #include "mozilla/Attributes.h"
    37 #include "mozilla/EventForwards.h"
    38 #include "mozilla/MemoryReporting.h"
    40 class nsRange;
    41 class nsIDragService;
    42 class nsCSSStyleSheet;
    44 struct RangePaintInfo;
    45 struct nsCallbackEventRequest;
    46 #ifdef MOZ_REFLOW_PERF
    47 class ReflowCountMgr;
    48 #endif
    50 class nsPresShellEventCB;
    51 class nsAutoCauseReflowNotifier;
    53 // 250ms.  This is actually pref-controlled, but we use this value if we fail
    54 // to get the pref for any reason.
    55 #define PAINTLOCK_EVENT_DELAY 250
    57 class PresShell : public nsIPresShell,
    58                   public nsStubDocumentObserver,
    59                   public nsISelectionController, public nsIObserver,
    60                   public nsSupportsWeakReference
    61 {
    62 public:
    63   PresShell();
    65   NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
    67   // nsISupports
    68   NS_DECL_ISUPPORTS
    70   void Init(nsIDocument* aDocument, nsPresContext* aPresContext,
    71             nsViewManager* aViewManager, nsStyleSet* aStyleSet,
    72             nsCompatibility aCompatMode);
    73   virtual NS_HIDDEN_(void) Destroy() MOZ_OVERRIDE;
    74   virtual NS_HIDDEN_(void) MakeZombie() MOZ_OVERRIDE;
    76   virtual NS_HIDDEN_(nsresult) SetPreferenceStyleRules(bool aForceReflow) MOZ_OVERRIDE;
    78   NS_IMETHOD GetSelection(SelectionType aType, nsISelection** aSelection);
    79   virtual mozilla::dom::Selection* GetCurrentSelection(SelectionType aType) MOZ_OVERRIDE;
    81   NS_IMETHOD SetDisplaySelection(int16_t aToggle) MOZ_OVERRIDE;
    82   NS_IMETHOD GetDisplaySelection(int16_t *aToggle) MOZ_OVERRIDE;
    83   NS_IMETHOD ScrollSelectionIntoView(SelectionType aType, SelectionRegion aRegion,
    84                                      int16_t aFlags) MOZ_OVERRIDE;
    85   NS_IMETHOD RepaintSelection(SelectionType aType) MOZ_OVERRIDE;
    87   virtual NS_HIDDEN_(void) BeginObservingDocument() MOZ_OVERRIDE;
    88   virtual NS_HIDDEN_(void) EndObservingDocument() MOZ_OVERRIDE;
    89   virtual NS_HIDDEN_(nsresult) Initialize(nscoord aWidth, nscoord aHeight) MOZ_OVERRIDE;
    90   virtual NS_HIDDEN_(nsresult) ResizeReflow(nscoord aWidth, nscoord aHeight) MOZ_OVERRIDE;
    91   virtual NS_HIDDEN_(nsresult) ResizeReflowOverride(nscoord aWidth, nscoord aHeight) MOZ_OVERRIDE;
    92   virtual NS_HIDDEN_(nsIPageSequenceFrame*) GetPageSequenceFrame() const MOZ_OVERRIDE;
    93   virtual NS_HIDDEN_(nsIFrame*) GetRealPrimaryFrameFor(nsIContent* aContent) const MOZ_OVERRIDE;
    95   virtual NS_HIDDEN_(nsIFrame*) GetPlaceholderFrameFor(nsIFrame* aFrame) const MOZ_OVERRIDE;
    96   virtual NS_HIDDEN_(void) FrameNeedsReflow(nsIFrame *aFrame, IntrinsicDirty aIntrinsicDirty,
    97                                             nsFrameState aBitToAdd) MOZ_OVERRIDE;
    98   virtual NS_HIDDEN_(void) FrameNeedsToContinueReflow(nsIFrame *aFrame) MOZ_OVERRIDE;
    99   virtual NS_HIDDEN_(void) CancelAllPendingReflows() MOZ_OVERRIDE;
   100   virtual NS_HIDDEN_(bool) IsSafeToFlush() const MOZ_OVERRIDE;
   101   virtual NS_HIDDEN_(void) FlushPendingNotifications(mozFlushType aType) MOZ_OVERRIDE;
   102   virtual NS_HIDDEN_(void) FlushPendingNotifications(mozilla::ChangesToFlush aType) MOZ_OVERRIDE;
   104   /**
   105    * Recreates the frames for a node
   106    */
   107   virtual NS_HIDDEN_(nsresult) RecreateFramesFor(nsIContent* aContent) MOZ_OVERRIDE;
   109   /**
   110    * Post a callback that should be handled after reflow has finished.
   111    */
   112   virtual NS_HIDDEN_(nsresult) PostReflowCallback(nsIReflowCallback* aCallback) MOZ_OVERRIDE;
   113   virtual NS_HIDDEN_(void) CancelReflowCallback(nsIReflowCallback* aCallback) MOZ_OVERRIDE;
   115   virtual NS_HIDDEN_(void) ClearFrameRefs(nsIFrame* aFrame) MOZ_OVERRIDE;
   116   virtual NS_HIDDEN_(already_AddRefed<nsRenderingContext>) CreateReferenceRenderingContext();
   117   virtual NS_HIDDEN_(nsresult) GoToAnchor(const nsAString& aAnchorName, bool aScroll) MOZ_OVERRIDE;
   118   virtual NS_HIDDEN_(nsresult) ScrollToAnchor() MOZ_OVERRIDE;
   120   virtual NS_HIDDEN_(nsresult) ScrollContentIntoView(nsIContent* aContent,
   121                                                      ScrollAxis  aVertical,
   122                                                      ScrollAxis  aHorizontal,
   123                                                      uint32_t    aFlags) MOZ_OVERRIDE;
   124   virtual bool ScrollFrameRectIntoView(nsIFrame*     aFrame,
   125                                        const nsRect& aRect,
   126                                        ScrollAxis    aVertical,
   127                                        ScrollAxis    aHorizontal,
   128                                        uint32_t      aFlags) MOZ_OVERRIDE;
   129   virtual nsRectVisibility GetRectVisibility(nsIFrame *aFrame,
   130                                              const nsRect &aRect,
   131                                              nscoord aMinTwips) const MOZ_OVERRIDE;
   133   virtual NS_HIDDEN_(void) SetIgnoreFrameDestruction(bool aIgnore) MOZ_OVERRIDE;
   134   virtual NS_HIDDEN_(void) NotifyDestroyingFrame(nsIFrame* aFrame) MOZ_OVERRIDE;
   136   virtual NS_HIDDEN_(nsresult) CaptureHistoryState(nsILayoutHistoryState** aLayoutHistoryState) MOZ_OVERRIDE;
   138   virtual NS_HIDDEN_(void) UnsuppressPainting() MOZ_OVERRIDE;
   140   virtual nsresult GetAgentStyleSheets(nsCOMArray<nsIStyleSheet>& aSheets) MOZ_OVERRIDE;
   141   virtual nsresult SetAgentStyleSheets(const nsCOMArray<nsIStyleSheet>& aSheets) MOZ_OVERRIDE;
   143   virtual nsresult AddOverrideStyleSheet(nsIStyleSheet *aSheet) MOZ_OVERRIDE;
   144   virtual nsresult RemoveOverrideStyleSheet(nsIStyleSheet *aSheet) MOZ_OVERRIDE;
   146   virtual NS_HIDDEN_(nsresult) HandleEventWithTarget(
   147                                  mozilla::WidgetEvent* aEvent,
   148                                  nsIFrame* aFrame,
   149                                  nsIContent* aContent,
   150                                  nsEventStatus* aStatus) MOZ_OVERRIDE;
   151   virtual NS_HIDDEN_(nsIFrame*) GetEventTargetFrame() MOZ_OVERRIDE;
   152   virtual NS_HIDDEN_(already_AddRefed<nsIContent>) GetEventTargetContent(
   153                                                      mozilla::WidgetEvent* aEvent) MOZ_OVERRIDE;
   156   virtual nsresult ReconstructFrames(void) MOZ_OVERRIDE;
   157   virtual void Freeze() MOZ_OVERRIDE;
   158   virtual void Thaw() MOZ_OVERRIDE;
   159   virtual void FireOrClearDelayedEvents(bool aFireEvents) MOZ_OVERRIDE;
   161   virtual NS_HIDDEN_(nsresult) RenderDocument(const nsRect& aRect, uint32_t aFlags,
   162                                               nscolor aBackgroundColor,
   163                                               gfxContext* aThebesContext) MOZ_OVERRIDE;
   165   virtual mozilla::TemporaryRef<SourceSurface>
   166   RenderNode(nsIDOMNode* aNode,
   167              nsIntRegion* aRegion,
   168              nsIntPoint& aPoint,
   169              nsIntRect* aScreenRect) MOZ_OVERRIDE;
   171   virtual mozilla::TemporaryRef<SourceSurface>
   172   RenderSelection(nsISelection* aSelection,
   173                   nsIntPoint& aPoint,
   174                   nsIntRect* aScreenRect) MOZ_OVERRIDE;
   176   virtual already_AddRefed<nsPIDOMWindow> GetRootWindow() MOZ_OVERRIDE;
   178   virtual LayerManager* GetLayerManager() MOZ_OVERRIDE;
   180   virtual void SetIgnoreViewportScrolling(bool aIgnore) MOZ_OVERRIDE;
   182   virtual nsresult SetResolution(float aXResolution, float aYResolution) MOZ_OVERRIDE;
   183   virtual gfxSize GetCumulativeResolution() MOZ_OVERRIDE;
   185   //nsIViewObserver interface
   187   virtual void Paint(nsView* aViewToPaint, const nsRegion& aDirtyRegion,
   188                      uint32_t aFlags) MOZ_OVERRIDE;
   189   virtual nsresult HandleEvent(nsIFrame* aFrame,
   190                                mozilla::WidgetGUIEvent* aEvent,
   191                                bool aDontRetargetEvents,
   192                                nsEventStatus* aEventStatus) MOZ_OVERRIDE;
   193   virtual NS_HIDDEN_(nsresult) HandleDOMEventWithTarget(
   194                                  nsIContent* aTargetContent,
   195                                  mozilla::WidgetEvent* aEvent,
   196                                  nsEventStatus* aStatus) MOZ_OVERRIDE;
   197   virtual NS_HIDDEN_(nsresult) HandleDOMEventWithTarget(nsIContent* aTargetContent,
   198                                                         nsIDOMEvent* aEvent,
   199                                                         nsEventStatus* aStatus) MOZ_OVERRIDE;
   200   virtual bool ShouldIgnoreInvalidation() MOZ_OVERRIDE;
   201   virtual void WillPaint() MOZ_OVERRIDE;
   202   virtual void WillPaintWindow() MOZ_OVERRIDE;
   203   virtual void DidPaintWindow() MOZ_OVERRIDE;
   204   virtual void ScheduleViewManagerFlush(PaintType aType = PAINT_DEFAULT) MOZ_OVERRIDE;
   205   virtual void DispatchSynthMouseMove(mozilla::WidgetGUIEvent* aEvent,
   206                                       bool aFlushOnHoverChange) MOZ_OVERRIDE;
   207   virtual void ClearMouseCaptureOnView(nsView* aView) MOZ_OVERRIDE;
   208   virtual bool IsVisible() MOZ_OVERRIDE;
   210   // caret handling
   211   virtual NS_HIDDEN_(already_AddRefed<nsCaret>) GetCaret() const MOZ_OVERRIDE;
   212   virtual NS_HIDDEN_(void) MaybeInvalidateCaretPosition() MOZ_OVERRIDE;
   213   NS_IMETHOD SetCaretEnabled(bool aInEnable) MOZ_OVERRIDE;
   214   NS_IMETHOD SetCaretReadOnly(bool aReadOnly) MOZ_OVERRIDE;
   215   NS_IMETHOD GetCaretEnabled(bool *aOutEnabled) MOZ_OVERRIDE;
   216   NS_IMETHOD SetCaretVisibilityDuringSelection(bool aVisibility) MOZ_OVERRIDE;
   217   NS_IMETHOD GetCaretVisible(bool *_retval) MOZ_OVERRIDE;
   218   virtual void SetCaret(nsCaret *aNewCaret) MOZ_OVERRIDE;
   219   virtual void RestoreCaret() MOZ_OVERRIDE;
   221   NS_IMETHOD SetSelectionFlags(int16_t aInEnable) MOZ_OVERRIDE;
   222   NS_IMETHOD GetSelectionFlags(int16_t *aOutEnable) MOZ_OVERRIDE;
   224   // nsISelectionController
   226   NS_IMETHOD CharacterMove(bool aForward, bool aExtend) MOZ_OVERRIDE;
   227   NS_IMETHOD CharacterExtendForDelete() MOZ_OVERRIDE;
   228   NS_IMETHOD CharacterExtendForBackspace() MOZ_OVERRIDE;
   229   NS_IMETHOD WordMove(bool aForward, bool aExtend) MOZ_OVERRIDE;
   230   NS_IMETHOD WordExtendForDelete(bool aForward) MOZ_OVERRIDE;
   231   NS_IMETHOD LineMove(bool aForward, bool aExtend) MOZ_OVERRIDE;
   232   NS_IMETHOD IntraLineMove(bool aForward, bool aExtend) MOZ_OVERRIDE;
   233   NS_IMETHOD PageMove(bool aForward, bool aExtend) MOZ_OVERRIDE;
   234   NS_IMETHOD ScrollPage(bool aForward) MOZ_OVERRIDE;
   235   NS_IMETHOD ScrollLine(bool aForward) MOZ_OVERRIDE;
   236   NS_IMETHOD ScrollCharacter(bool aRight) MOZ_OVERRIDE;
   237   NS_IMETHOD CompleteScroll(bool aForward) MOZ_OVERRIDE;
   238   NS_IMETHOD CompleteMove(bool aForward, bool aExtend) MOZ_OVERRIDE;
   239   NS_IMETHOD SelectAll() MOZ_OVERRIDE;
   240   NS_IMETHOD CheckVisibility(nsIDOMNode *node, int16_t startOffset, int16_t EndOffset, bool *_retval) MOZ_OVERRIDE;
   241   virtual nsresult CheckVisibilityContent(nsIContent* aNode, int16_t aStartOffset,
   242                                           int16_t aEndOffset, bool* aRetval) MOZ_OVERRIDE;
   244   // nsIDocumentObserver
   245   NS_DECL_NSIDOCUMENTOBSERVER_BEGINUPDATE
   246   NS_DECL_NSIDOCUMENTOBSERVER_ENDUPDATE
   247   NS_DECL_NSIDOCUMENTOBSERVER_BEGINLOAD
   248   NS_DECL_NSIDOCUMENTOBSERVER_ENDLOAD
   249   NS_DECL_NSIDOCUMENTOBSERVER_CONTENTSTATECHANGED
   250   NS_DECL_NSIDOCUMENTOBSERVER_DOCUMENTSTATESCHANGED
   251   NS_DECL_NSIDOCUMENTOBSERVER_STYLESHEETADDED
   252   NS_DECL_NSIDOCUMENTOBSERVER_STYLESHEETREMOVED
   253   NS_DECL_NSIDOCUMENTOBSERVER_STYLESHEETAPPLICABLESTATECHANGED
   254   NS_DECL_NSIDOCUMENTOBSERVER_STYLERULECHANGED
   255   NS_DECL_NSIDOCUMENTOBSERVER_STYLERULEADDED
   256   NS_DECL_NSIDOCUMENTOBSERVER_STYLERULEREMOVED
   258   // nsIMutationObserver
   259   NS_DECL_NSIMUTATIONOBSERVER_CHARACTERDATAWILLCHANGE
   260   NS_DECL_NSIMUTATIONOBSERVER_CHARACTERDATACHANGED
   261   NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTEWILLCHANGE
   262   NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTECHANGED
   263   NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED
   264   NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED
   265   NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED
   267   NS_DECL_NSIOBSERVER
   269 #ifdef MOZ_REFLOW_PERF
   270   virtual NS_HIDDEN_(void) DumpReflows() MOZ_OVERRIDE;
   271   virtual NS_HIDDEN_(void) CountReflows(const char * aName, nsIFrame * aFrame) MOZ_OVERRIDE;
   272   virtual NS_HIDDEN_(void) PaintCount(const char * aName,
   273                                       nsRenderingContext* aRenderingContext,
   274                                       nsPresContext* aPresContext,
   275                                       nsIFrame * aFrame,
   276                                       const nsPoint& aOffset,
   277                                       uint32_t aColor) MOZ_OVERRIDE;
   278   virtual NS_HIDDEN_(void) SetPaintFrameCount(bool aOn) MOZ_OVERRIDE;
   279   virtual bool IsPaintingFrameCounts() MOZ_OVERRIDE;
   280 #endif
   282 #ifdef DEBUG
   283   virtual void ListStyleContexts(nsIFrame *aRootFrame, FILE *out,
   284                                  int32_t aIndent = 0) MOZ_OVERRIDE;
   286   virtual void ListStyleSheets(FILE *out, int32_t aIndent = 0) MOZ_OVERRIDE;
   287   virtual void VerifyStyleTree() MOZ_OVERRIDE;
   288 #endif
   290 #ifdef PR_LOGGING
   291   static PRLogModuleInfo* gLog;
   292 #endif
   294   virtual NS_HIDDEN_(void) DisableNonTestMouseEvents(bool aDisable) MOZ_OVERRIDE;
   296   virtual void UpdateCanvasBackground() MOZ_OVERRIDE;
   298   virtual void AddCanvasBackgroundColorItem(nsDisplayListBuilder& aBuilder,
   299                                             nsDisplayList& aList,
   300                                             nsIFrame* aFrame,
   301                                             const nsRect& aBounds,
   302                                             nscolor aBackstopColor,
   303                                             uint32_t aFlags) MOZ_OVERRIDE;
   305   virtual void AddPrintPreviewBackgroundItem(nsDisplayListBuilder& aBuilder,
   306                                              nsDisplayList& aList,
   307                                              nsIFrame* aFrame,
   308                                              const nsRect& aBounds) MOZ_OVERRIDE;
   310   virtual nscolor ComputeBackstopColor(nsView* aDisplayRoot) MOZ_OVERRIDE;
   312   virtual NS_HIDDEN_(nsresult) SetIsActive(bool aIsActive) MOZ_OVERRIDE;
   314   virtual bool GetIsViewportOverridden() MOZ_OVERRIDE { return mViewportOverridden; }
   316   virtual bool IsLayoutFlushObserver() MOZ_OVERRIDE
   317   {
   318     return GetPresContext()->RefreshDriver()->
   319       IsLayoutFlushObserver(this);
   320   }
   322   virtual void LoadComplete() MOZ_OVERRIDE;
   324   void AddSizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf,
   325                               nsArenaMemoryStats *aArenaObjectsSize,
   326                               size_t *aPresShellSize,
   327                               size_t *aStyleSetsSize,
   328                               size_t *aTextRunsSize,
   329                               size_t *aPresContextSize) MOZ_OVERRIDE;
   330   size_t SizeOfTextRuns(mozilla::MallocSizeOf aMallocSizeOf) const;
   332   virtual void AddInvalidateHiddenPresShellObserver(nsRefreshDriver *aDriver) MOZ_OVERRIDE;
   334   // This data is stored as a content property (nsGkAtoms::scrolling) on
   335   // mContentToScrollTo when we have a pending ScrollIntoView.
   336   struct ScrollIntoViewData {
   337     ScrollAxis mContentScrollVAxis;
   338     ScrollAxis mContentScrollHAxis;
   339     uint32_t   mContentToScrollToFlags;
   340   };
   342   virtual void ScheduleImageVisibilityUpdate() MOZ_OVERRIDE;
   344   virtual void RebuildImageVisibility(const nsDisplayList& aList) MOZ_OVERRIDE;
   346   virtual void EnsureImageInVisibleList(nsIImageLoadingContent* aImage) MOZ_OVERRIDE;
   348   virtual void RemoveImageFromVisibleList(nsIImageLoadingContent* aImage) MOZ_OVERRIDE;
   350   virtual bool AssumeAllImagesVisible() MOZ_OVERRIDE;
   352   virtual void RestyleShadowRoot(mozilla::dom::ShadowRoot* aShadowRoot);
   354   void SetNextPaintCompressed() { mNextPaintCompressed = true; }
   356 protected:
   357   virtual ~PresShell();
   359   void HandlePostedReflowCallbacks(bool aInterruptible);
   360   void CancelPostedReflowCallbacks();
   362   void UnsuppressAndInvalidate();
   364   void WillCauseReflow() {
   365     nsContentUtils::AddScriptBlocker();
   366     ++mChangeNestCount;
   367   }
   368   nsresult DidCauseReflow();
   369   friend class nsAutoCauseReflowNotifier;
   371   void DispatchTouchEvent(mozilla::WidgetEvent* aEvent,
   372                           nsEventStatus* aStatus,
   373                           nsPresShellEventCB* aEventCB,
   374                           bool aTouchIsNew);
   376   void     WillDoReflow();
   378   /**
   379    * Callback handler for whether reflow happened.
   380    *
   381    * @param aInterruptible Whether or not reflow interruption is allowed.
   382    * @param aWasInterrupted Whether or not the reflow was interrupted earlier.
   383    *
   384    */
   385   void     DidDoReflow(bool aInterruptible, bool aWasInterrupted);
   386   // ProcessReflowCommands returns whether we processed all our dirty roots
   387   // without interruptions.
   388   bool     ProcessReflowCommands(bool aInterruptible);
   389   // MaybeScheduleReflow checks if posting a reflow is needed, then checks if
   390   // the last reflow was interrupted. In the interrupted case ScheduleReflow is
   391   // called off a timer, otherwise it is called directly.
   392   void     MaybeScheduleReflow();
   393   // Actually schedules a reflow.  This should only be called by
   394   // MaybeScheduleReflow and the reflow timer ScheduleReflowOffTimer
   395   // sets up.
   396   void     ScheduleReflow();
   398   // Reflow regardless of whether the override bit has been set.
   399   nsresult ResizeReflowIgnoreOverride(nscoord aWidth, nscoord aHeight);
   401   // DoReflow returns whether the reflow finished without interruption
   402   bool DoReflow(nsIFrame* aFrame, bool aInterruptible);
   403 #ifdef DEBUG
   404   void DoVerifyReflow();
   405   void VerifyHasDirtyRootAncestor(nsIFrame* aFrame);
   406 #endif
   408   // Helper for ScrollContentIntoView
   409   void DoScrollContentIntoView();
   411   /**
   412    * Initialize cached font inflation preference values and do an initial
   413    * computation to determine if font inflation is enabled.
   414    *
   415    * @see nsLayoutUtils::sFontSizeInflationEmPerLine
   416    * @see nsLayoutUtils::sFontSizeInflationMinTwips
   417    * @see nsLayoutUtils::sFontSizeInflationLineThreshold
   418    */
   419   void SetupFontInflation();
   421   friend struct AutoRenderingStateSaveRestore;
   422   friend struct RenderingState;
   424   struct RenderingState {
   425     RenderingState(PresShell* aPresShell)
   426       : mXResolution(aPresShell->mXResolution)
   427       , mYResolution(aPresShell->mYResolution)
   428       , mRenderFlags(aPresShell->mRenderFlags)
   429     { }
   430     float mXResolution;
   431     float mYResolution;
   432     RenderFlags mRenderFlags;
   433   };
   435   struct AutoSaveRestoreRenderingState {
   436     AutoSaveRestoreRenderingState(PresShell* aPresShell)
   437       : mPresShell(aPresShell)
   438       , mOldState(aPresShell)
   439     {}
   441     ~AutoSaveRestoreRenderingState()
   442     {
   443       mPresShell->mRenderFlags = mOldState.mRenderFlags;
   444       mPresShell->mXResolution = mOldState.mXResolution;
   445       mPresShell->mYResolution = mOldState.mYResolution;
   446     }
   448     PresShell* mPresShell;
   449     RenderingState mOldState;
   450   };
   451   static RenderFlags ChangeFlag(RenderFlags aFlags, bool aOnOff,
   452                                 eRenderFlag aFlag)
   453   {
   454     return aOnOff ? (aFlags | aFlag) : (aFlag & ~aFlag);
   455   }
   458   void SetRenderingState(const RenderingState& aState);
   460   friend class nsPresShellEventCB;
   462   bool mCaretEnabled;
   463 #ifdef DEBUG
   464   nsStyleSet* CloneStyleSet(nsStyleSet* aSet);
   465   bool VerifyIncrementalReflow();
   466   bool mInVerifyReflow;
   467   void ShowEventTargetDebug();
   468 #endif
   470   void RecordStyleSheetChange(nsIStyleSheet* aStyleSheet);
   472     /**
   473     * methods that manage rules that are used to implement the associated preferences
   474     *  - initially created for bugs 31816, 20760, 22963
   475     */
   476   nsresult ClearPreferenceStyleRules(void);
   477   nsresult CreatePreferenceStyleSheet(void);
   478   nsresult SetPrefLinkRules(void);
   479   nsresult SetPrefFocusRules(void);
   480   nsresult SetPrefNoScriptRule();
   481   nsresult SetPrefNoFramesRule(void);
   483   // methods for painting a range to an offscreen buffer
   485   // given a display list, clip the items within the list to
   486   // the range
   487   nsRect ClipListToRange(nsDisplayListBuilder *aBuilder,
   488                          nsDisplayList* aList,
   489                          nsRange* aRange);
   491   // create a RangePaintInfo for the range aRange containing the
   492   // display list needed to paint the range to a surface
   493   RangePaintInfo* CreateRangePaintInfo(nsIDOMRange* aRange,
   494                                        nsRect& aSurfaceRect,
   495                                        bool aForPrimarySelection);
   497   /*
   498    * Paint the items to a new surface and return it.
   499    *
   500    * aSelection - selection being painted, if any
   501    * aRegion - clip region, if any
   502    * aArea - area that the surface occupies, relative to the root frame
   503    * aPoint - reference point, typically the mouse position
   504    * aScreenRect - [out] set to the area of the screen the painted area should
   505    *               be displayed at
   506    */
   507   mozilla::TemporaryRef<SourceSurface>
   508   PaintRangePaintInfo(nsTArray<nsAutoPtr<RangePaintInfo> >* aItems,
   509                       nsISelection* aSelection,
   510                       nsIntRegion* aRegion,
   511                       nsRect aArea,
   512                       nsIntPoint& aPoint,
   513                       nsIntRect* aScreenRect);
   515   /**
   516    * Methods to handle changes to user and UA sheet lists that we get
   517    * notified about.
   518    */
   519   void AddUserSheet(nsISupports* aSheet);
   520   void AddAgentSheet(nsISupports* aSheet);
   521   void AddAuthorSheet(nsISupports* aSheet);
   522   void RemoveSheet(nsStyleSet::sheetType aType, nsISupports* aSheet);
   524   // Hide a view if it is a popup
   525   void HideViewIfPopup(nsView* aView);
   527   // Utility method to restore the root scrollframe state
   528   void RestoreRootScrollPosition();
   530   void MaybeReleaseCapturingContent()
   531   {
   532     nsRefPtr<nsFrameSelection> frameSelection = FrameSelection();
   533     if (frameSelection) {
   534       frameSelection->SetMouseDownState(false);
   535     }
   536     if (gCaptureInfo.mContent &&
   537         gCaptureInfo.mContent->OwnerDoc() == mDocument) {
   538       SetCapturingContent(nullptr, 0);
   539     }
   540   }
   542   nsresult HandleRetargetedEvent(mozilla::WidgetEvent* aEvent,
   543                                  nsEventStatus* aStatus,
   544                                  nsIContent* aTarget)
   545   {
   546     PushCurrentEventInfo(nullptr, nullptr);
   547     mCurrentEventContent = aTarget;
   548     nsresult rv = NS_OK;
   549     if (GetCurrentEventFrame()) {
   550       rv = HandleEventInternal(aEvent, aStatus);
   551     }
   552     PopCurrentEventInfo();
   553     return rv;
   554   }
   556   class DelayedEvent
   557   {
   558   public:
   559     virtual ~DelayedEvent() { }
   560     virtual void Dispatch() { }
   561   };
   563   class DelayedInputEvent : public DelayedEvent
   564   {
   565   public:
   566     virtual void Dispatch() MOZ_OVERRIDE;
   568   protected:
   569     DelayedInputEvent();
   570     virtual ~DelayedInputEvent();
   572     mozilla::WidgetInputEvent* mEvent;
   573   };
   575   class DelayedMouseEvent : public DelayedInputEvent
   576   {
   577   public:
   578     DelayedMouseEvent(mozilla::WidgetMouseEvent* aEvent);
   579   };
   581   class DelayedKeyEvent : public DelayedInputEvent
   582   {
   583   public:
   584     DelayedKeyEvent(mozilla::WidgetKeyboardEvent* aEvent);
   585   };
   587   // Check if aEvent is a mouse event and record the mouse location for later
   588   // synth mouse moves.
   589   void RecordMouseLocation(mozilla::WidgetGUIEvent* aEvent);
   590   class nsSynthMouseMoveEvent MOZ_FINAL : public nsARefreshObserver {
   591   public:
   592     nsSynthMouseMoveEvent(PresShell* aPresShell, bool aFromScroll)
   593       : mPresShell(aPresShell), mFromScroll(aFromScroll) {
   594       NS_ASSERTION(mPresShell, "null parameter");
   595     }
   597   private:
   598   // Private destructor, to discourage deletion outside of Release():
   599     ~nsSynthMouseMoveEvent() {
   600       Revoke();
   601     }
   603   public:
   604     NS_INLINE_DECL_REFCOUNTING(nsSynthMouseMoveEvent)
   606     void Revoke() {
   607       if (mPresShell) {
   608         mPresShell->GetPresContext()->RefreshDriver()->
   609           RemoveRefreshObserver(this, Flush_Display);
   610         mPresShell = nullptr;
   611       }
   612     }
   613     virtual void WillRefresh(mozilla::TimeStamp aTime) MOZ_OVERRIDE {
   614       if (mPresShell) {
   615         nsRefPtr<PresShell> shell = mPresShell;
   616         shell->ProcessSynthMouseMoveEvent(mFromScroll);
   617       }
   618     }
   619   private:
   620     PresShell* mPresShell;
   621     bool mFromScroll;
   622   };
   623   void ProcessSynthMouseMoveEvent(bool aFromScroll);
   625   void QueryIsActive();
   626   nsresult UpdateImageLockingState();
   628 #ifdef ANDROID
   629   nsIDocument* GetTouchEventTargetDocument();
   630 #endif
   631   bool InZombieDocument(nsIContent *aContent);
   632   already_AddRefed<nsIPresShell> GetParentPresShellForEventHandling();
   633   nsIContent* GetCurrentEventContent();
   634   nsIFrame* GetCurrentEventFrame();
   635   nsresult RetargetEventToParent(mozilla::WidgetGUIEvent* aEvent,
   636                                  nsEventStatus* aEventStatus);
   637   void PushCurrentEventInfo(nsIFrame* aFrame, nsIContent* aContent);
   638   void PopCurrentEventInfo();
   639   nsresult HandleEventInternal(mozilla::WidgetEvent* aEvent,
   640                                nsEventStatus* aStatus);
   641   nsresult HandlePositionedEvent(nsIFrame* aTargetFrame,
   642                                  mozilla::WidgetGUIEvent* aEvent,
   643                                  nsEventStatus* aEventStatus);
   644   // This returns the focused DOM window under our top level window.
   645   //  I.e., when we are deactive, this returns the *last* focused DOM window.
   646   already_AddRefed<nsPIDOMWindow> GetFocusedDOMWindowInOurWindow();
   648   /*
   649    * This and the next two helper methods are used to target and position the
   650    * context menu when the keyboard shortcut is used to open it.
   651    *
   652    * If another menu is open, the context menu is opened relative to the
   653    * active menuitem within the menu, or the menu itself if no item is active.
   654    * Otherwise, if the caret is visible, the menu is opened near the caret.
   655    * Otherwise, if a selectable list such as a listbox is focused, the
   656    * current item within the menu is opened relative to this item.
   657    * Otherwise, the context menu is opened at the topleft corner of the
   658    * view.
   659    *
   660    * Returns true if the context menu event should fire and false if it should
   661    * not.
   662    */
   663   bool AdjustContextMenuKeyEvent(mozilla::WidgetMouseEvent* aEvent);
   665   //
   666   bool PrepareToUseCaretPosition(nsIWidget* aEventWidget, nsIntPoint& aTargetPt);
   668   // Get the selected item and coordinates in device pixels relative to root
   669   // document's root view for element, first ensuring the element is onscreen
   670   void GetCurrentItemAndPositionForElement(nsIDOMElement *aCurrentEl,
   671                                            nsIContent **aTargetToUse,
   672                                            mozilla::LayoutDeviceIntPoint& aTargetPt,
   673                                            nsIWidget *aRootWidget);
   675   void FireResizeEvent();
   676   static void AsyncResizeEventCallback(nsITimer* aTimer, void* aPresShell);
   678   virtual void SynthesizeMouseMove(bool aFromScroll) MOZ_OVERRIDE;
   680   PresShell* GetRootPresShell();
   682   nscolor GetDefaultBackgroundColorToDraw();
   684   DOMHighResTimeStamp GetPerformanceNow();
   686   // The callback for the mPaintSuppressionTimer timer.
   687   static void sPaintSuppressionCallback(nsITimer* aTimer, void* aPresShell);
   689   // The callback for the mReflowContinueTimer timer.
   690   static void sReflowContinueCallback(nsITimer* aTimer, void* aPresShell);
   691   bool ScheduleReflowOffTimer();
   693   // Widget notificiations
   694   virtual void WindowSizeMoveDone() MOZ_OVERRIDE;
   695   virtual void SysColorChanged() MOZ_OVERRIDE { mPresContext->SysColorChanged(); }
   696   virtual void ThemeChanged() MOZ_OVERRIDE { mPresContext->ThemeChanged(); }
   697   virtual void BackingScaleFactorChanged() MOZ_OVERRIDE { mPresContext->UIResolutionChanged(); }
   699   virtual void PausePainting() MOZ_OVERRIDE;
   700   virtual void ResumePainting() MOZ_OVERRIDE;
   702   void UpdateImageVisibility();
   703   void UpdateActivePointerState(mozilla::WidgetGUIEvent* aEvent);
   705   nsRevocableEventPtr<nsRunnableMethod<PresShell> > mUpdateImageVisibilityEvent;
   707   void ClearVisibleImagesList();
   708   static void ClearImageVisibilityVisited(nsView* aView, bool aClear);
   709   static void MarkImagesInListVisible(const nsDisplayList& aList);
   711   void EvictTouches();
   713   // A list of images that are visible or almost visible.
   714   nsTHashtable< nsRefPtrHashKey<nsIImageLoadingContent> > mVisibleImages;
   716 #ifdef DEBUG
   717   // The reflow root under which we're currently reflowing.  Null when
   718   // not in reflow.
   719   nsIFrame*                 mCurrentReflowRoot;
   720   uint32_t                  mUpdateCount;
   721 #endif
   723 #ifdef MOZ_REFLOW_PERF
   724   ReflowCountMgr*           mReflowCountMgr;
   725 #endif
   727   // This is used for synthetic mouse events that are sent when what is under
   728   // the mouse pointer may have changed without the mouse moving (eg scrolling,
   729   // change to the document contents).
   730   // It is set only on a presshell for a root document, this value represents
   731   // the last observed location of the mouse relative to that root document. It
   732   // is set to (NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE) if the mouse isn't
   733   // over our window or there is no last observed mouse location for some
   734   // reason.
   735   nsPoint                   mMouseLocation;
   737   // mStyleSet owns it but we maintain a ref, may be null
   738   nsRefPtr<nsCSSStyleSheet> mPrefStyleSheet;
   740   // Set of frames that we should mark with NS_FRAME_HAS_DIRTY_CHILDREN after
   741   // we finish reflowing mCurrentReflowRoot.
   742   nsTHashtable<nsPtrHashKey<nsIFrame> > mFramesToDirty;
   744   // Reflow roots that need to be reflowed.
   745   nsTArray<nsIFrame*>       mDirtyRoots;
   747   nsTArray<nsAutoPtr<DelayedEvent> > mDelayedEvents;
   748   nsRevocableEventPtr<nsRunnableMethod<PresShell> > mResizeEvent;
   749   nsCOMPtr<nsITimer>        mAsyncResizeEventTimer;
   750 private:
   751   nsIFrame*                 mCurrentEventFrame;
   752   nsCOMPtr<nsIContent>      mCurrentEventContent;
   753   nsTArray<nsIFrame*>       mCurrentEventFrameStack;
   754   nsCOMArray<nsIContent>    mCurrentEventContentStack;
   755 protected:
   756   nsRevocableEventPtr<nsSynthMouseMoveEvent> mSynthMouseMoveEvent;
   757   nsCOMPtr<nsIContent>      mLastAnchorScrolledTo;
   758   nsRefPtr<nsCaret>         mCaret;
   759   nsRefPtr<nsCaret>         mOriginalCaret;
   760   nsCallbackEventRequest*   mFirstCallbackEventRequest;
   761   nsCallbackEventRequest*   mLastCallbackEventRequest;
   763   // This timer controls painting suppression.  Until it fires
   764   // or all frames are constructed, we won't paint anything but
   765   // our <body> background and scrollbars.
   766   nsCOMPtr<nsITimer>        mPaintSuppressionTimer;
   768   // At least on Win32 and Mac after interupting a reflow we need to post
   769   // the resume reflow event off a timer to avoid event starvation because
   770   // posted messages are processed before other messages when the modal
   771   // moving/sizing loop is running, see bug 491700 for details.
   772   nsCOMPtr<nsITimer>        mReflowContinueTimer;
   774   nsCOMPtr<nsITimer>        mDelayedPaintTimer;
   776   // The `performance.now()` value when we last started to process reflows.
   777   DOMHighResTimeStamp       mLastReflowStart;
   779   mozilla::TimeStamp        mLoadBegin;  // used to time loads
   781   // Information needed to properly handle scrolling content into view if the
   782   // pre-scroll reflow flush can be interrupted.  mContentToScrollTo is
   783   // non-null between the initial scroll attempt and the first time we finish
   784   // processing all our dirty roots.  mContentToScrollTo has a content property
   785   // storing the details for the scroll operation, see ScrollIntoViewData above.
   786   nsCOMPtr<nsIContent>      mContentToScrollTo;
   788   nscoord                   mLastAnchorScrollPositionY;
   790   // This is used to protect ourselves from triggering reflow while in the
   791   // middle of frame construction and the like... it really shouldn't be
   792   // needed, one hopes, but it is for now.
   793   uint16_t                  mChangeNestCount;
   795   bool                      mDocumentLoading : 1;
   796   bool                      mIgnoreFrameDestruction : 1;
   797   bool                      mHaveShutDown : 1;
   798   bool                      mViewportOverridden : 1;
   799   bool                      mLastRootReflowHadUnconstrainedHeight : 1;
   800   bool                      mNoDelayedMouseEvents : 1;
   801   bool                      mNoDelayedKeyEvents : 1;
   803   // We've been disconnected from the document.  We will refuse to paint the
   804   // document until either our timer fires or all frames are constructed.
   805   bool                      mIsDocumentGone : 1;
   807   // Indicates that it is safe to unlock painting once all pending reflows
   808   // have been processed.
   809   bool                      mShouldUnsuppressPainting : 1;
   811   bool                      mAsyncResizeTimerIsActive : 1;
   812   bool                      mInResize : 1;
   814   bool                      mImageVisibilityVisited : 1;
   816   bool                      mNextPaintCompressed : 1;
   818   static bool               sDisableNonTestMouseEvents;
   819 };
   821 #endif /* !defined(nsPresShell_h_) */

mercurial