nsFrameManager.h (3450B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 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 /* Owns the frame tree and provides APIs to manipulate it */ 8 9 #ifndef _nsFrameManager_h_ 10 #define _nsFrameManager_h_ 11 12 #include "mozilla/Attributes.h" 13 #include "nsDebug.h" 14 #include "nsFrameList.h" 15 16 class nsContainerFrame; 17 class nsIFrame; 18 class nsILayoutHistoryState; 19 class nsPlaceholderFrame; 20 class nsWindowSizes; 21 22 namespace mozilla { 23 struct FrameDestroyContext; 24 class PresShell; 25 class ViewportFrame; 26 } // namespace mozilla 27 28 /** 29 * Frame manager interface. The frame manager owns the frame tree model, and 30 * handles structural manipulations to it, such as appending and inserting a 31 * list of frames to a parent frame, or removing a child frame from a parent 32 * frame. 33 */ 34 class nsFrameManager { 35 public: 36 using DestroyContext = mozilla::FrameDestroyContext; 37 38 explicit nsFrameManager(mozilla::PresShell* aPresShell) 39 : mPresShell(aPresShell) { 40 MOZ_ASSERT(mPresShell, "need a pres shell"); 41 } 42 ~nsFrameManager(); 43 44 /* 45 * Gets and sets the root frame (i.e. ViewportFrame). The lifetime of the 46 * root frame is controlled by the frame manager. When the frame manager is 47 * destroyed, it destroys the entire frame hierarchy. 48 */ 49 nsIFrame* GetRootFrame() const { return mRootFrame; } 50 void SetRootFrame(mozilla::ViewportFrame* aRootFrame); 51 52 /* 53 * After Destroy is called, it is an error to call any FrameManager methods. 54 * Destroy should be called when the frame tree managed by the frame 55 * manager is no longer being displayed. 56 */ 57 void Destroy(); 58 59 // Functions for manipulating the frame model 60 void AppendFrames(nsContainerFrame* aParentFrame, 61 mozilla::FrameChildListID aListID, 62 nsFrameList&& aFrameList); 63 64 void InsertFrames(nsContainerFrame* aParentFrame, 65 mozilla::FrameChildListID aListID, nsIFrame* aPrevFrame, 66 nsFrameList&& aFrameList); 67 68 void RemoveFrame(DestroyContext&, mozilla::FrameChildListID, nsIFrame*); 69 70 /* 71 * Capture/restore frame state for the frame subtree rooted at aFrame. 72 * aState is the document state storage object onto which each frame 73 * stores its state. Callers of CaptureFrameState are responsible for 74 * traversing next continuations of special siblings of aFrame as 75 * needed; this method will only work with actual frametree descendants 76 * of aFrame. 77 */ 78 79 void CaptureFrameState(nsIFrame* aFrame, nsILayoutHistoryState* aState); 80 81 void RestoreFrameState(nsIFrame* aFrame, nsILayoutHistoryState* aState); 82 83 /* 84 * Add/restore state for one frame 85 */ 86 void CaptureFrameStateFor(nsIFrame* aFrame, nsILayoutHistoryState* aState); 87 88 void RestoreFrameStateFor(nsIFrame* aFrame, nsILayoutHistoryState* aState); 89 90 void AddSizeOfIncludingThis(nsWindowSizes& aSizes) const; 91 92 protected: 93 // weak link, because the pres shell owns us 94 mozilla::PresShell* MOZ_NON_OWNING_REF mPresShell; 95 96 // Note: We use nsIFrame* instead of ViewportFrame* for mRootFrame to avoid 97 // exposing ViewportFrame to the callers via GetRootFrame(), since they do not 98 // depend on any ViewportFrame-specific APIs or details. 99 nsIFrame* mRootFrame = nullptr; 100 }; 101 102 #endif