nsSubDocumentFrame.h (8641B)
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 #ifndef NSSUBDOCUMENTFRAME_H_ 8 #define NSSUBDOCUMENTFRAME_H_ 9 10 #include "Units.h" 11 #include "mozilla/gfx/Matrix.h" 12 #include "nsAtomicContainerFrame.h" 13 #include "nsDisplayList.h" 14 #include "nsFrameLoader.h" 15 #include "nsIReflowCallback.h" 16 17 namespace mozilla { 18 class PresShell; 19 } // namespace mozilla 20 21 namespace mozilla::layers { 22 class Layer; 23 class RenderRootStateManager; 24 class WebRenderLayerScrollData; 25 class WebRenderScrollData; 26 } // namespace mozilla::layers 27 28 /****************************************************************************** 29 * nsSubDocumentFrame 30 *****************************************************************************/ 31 class nsSubDocumentFrame final : public nsAtomicContainerFrame, 32 public nsIReflowCallback { 33 public: 34 NS_DECL_FRAMEARENA_HELPERS(nsSubDocumentFrame) 35 36 explicit nsSubDocumentFrame(ComputedStyle* aStyle, 37 nsPresContext* aPresContext); 38 39 #ifdef DEBUG_FRAME_DUMP 40 void List(FILE* out = stderr, const char* aPrefix = "", 41 ListFlags aFlags = ListFlags()) const override; 42 nsresult GetFrameName(nsAString& aResult) const override; 43 #endif 44 45 NS_DECL_QUERYFRAME 46 47 void Init(nsIContent* aContent, nsContainerFrame* aParent, 48 nsIFrame* aPrevInFlow) override; 49 50 void Destroy(DestroyContext&) override; 51 52 nscoord IntrinsicISize(const mozilla::IntrinsicSizeInput& aInput, 53 mozilla::IntrinsicISizeType aType) override; 54 55 mozilla::IntrinsicSize GetIntrinsicSize() override; 56 mozilla::AspectRatio GetIntrinsicRatio() const override; 57 58 const nsPoint& GetExtraOffset() const { return mExtraOffset; } 59 60 SizeComputationResult ComputeSize( 61 const SizeComputationInput& aSizingInput, mozilla::WritingMode aWM, 62 const mozilla::LogicalSize& aCBSize, nscoord aAvailableISize, 63 const mozilla::LogicalSize& aMargin, 64 const mozilla::LogicalSize& aBorderPadding, 65 const mozilla::StyleSizeOverrides& aSizeOverrides, 66 mozilla::ComputeSizeFlags aFlags) override; 67 68 void Reflow(nsPresContext* aPresContext, ReflowOutput& aDesiredSize, 69 const ReflowInput& aReflowInput, 70 nsReflowStatus& aStatus) override; 71 72 void BuildDisplayList(nsDisplayListBuilder* aBuilder, 73 const nsDisplayListSet& aLists) override; 74 75 nsresult AttributeChanged(int32_t aNameSpaceID, nsAtom* aAttribute, 76 AttrModType aModType) override; 77 78 void DidSetComputedStyle(ComputedStyle* aOldComputedStyle) override; 79 80 // if the content is "visibility:hidden", then just hide the view 81 // and all our contents. We don't extend "visibility:hidden" to 82 // the child content ourselves, since it belongs to a different 83 // document and CSS doesn't inherit in there. 84 bool SupportsVisibilityHidden() override { return false; } 85 86 #ifdef ACCESSIBILITY 87 mozilla::a11y::AccType AccessibleType() override; 88 #endif 89 90 mozilla::IntrinsicSize ComputeIntrinsicSize( 91 bool aIgnoreContainment = false) const; 92 93 nsIDocShell* GetDocShell() const; 94 nsIDocShell* GetExtantDocShell() const; 95 nsresult BeginSwapDocShells(nsIFrame* aOther); 96 void EndSwapDocShells(nsIFrame* aOther); 97 98 mozilla::dom::Document* GetExtantSubdocument(); 99 mozilla::PresShell* GetSubdocumentPresShell(); 100 nsIFrame* GetSubdocumentRootFrame(); 101 enum { IGNORE_PAINT_SUPPRESSION = 0x1 }; 102 mozilla::PresShell* GetSubdocumentPresShellForPainting(uint32_t aFlags); 103 nsRect GetDestRect() const; 104 nsRect GetDestRect(const nsRect& aConstraintRect) const; 105 106 mozilla::LayoutDeviceIntSize GetInitialSubdocumentSize() const; 107 mozilla::LayoutDeviceIntSize GetSubdocumentSize() const; 108 109 bool ContentReactsToPointerEvents() const; 110 111 // nsIReflowCallback 112 bool ReflowFinished() override; 113 void ReflowCallbackCanceled() override; 114 115 /** 116 * Return true if pointer event hit-testing should be allowed to target 117 * content in the subdocument. 118 */ 119 bool PassPointerEventsToChildren(); 120 121 void MaybeShowViewer() { 122 if (!mDidCreateDoc && !mCallingShow) { 123 ShowViewer(); 124 } 125 } 126 127 nsFrameLoader* FrameLoader() const; 128 129 enum class RetainPaintData : bool { No, Yes }; 130 void ResetFrameLoader(RetainPaintData); 131 void ClearRetainedPaintData(); 132 133 void ClearDisplayItems(); 134 135 void SubdocumentIntrinsicSizeOrRatioChanged(); 136 137 struct RemoteFramePaintData { 138 mozilla::layers::LayersId mLayersId; 139 mozilla::dom::TabId mTabId{0}; 140 }; 141 142 RemoteFramePaintData GetRemotePaintData() const; 143 bool HasRetainedPaintData() const { return mRetainedRemoteFrame.isSome(); } 144 145 const mozilla::gfx::MatrixScales& GetRasterScale() const { 146 return mRasterScale; 147 } 148 void SetRasterScale(const mozilla::gfx::MatrixScales& aScale) { 149 mRasterScale = aScale; 150 } 151 const Maybe<nsRect>& GetVisibleRect() const { return mVisibleRect; } 152 void SetVisibleRect(const Maybe<nsRect>& aRect) { mVisibleRect = aRect; } 153 154 void AddEmbeddingPresShell(mozilla::PresShell*); 155 void EnsureEmbeddingPresShell(mozilla::PresShell*); 156 void RemoveEmbeddingPresShell(mozilla::PresShell*); 157 158 protected: 159 friend class AsyncFrameInit; 160 161 void MaybeUpdateEmbedderColorScheme(); 162 void MaybeUpdateEmbedderZoom(); 163 void MaybeUpdateRemoteStyle(ComputedStyle* aOldComputedStyle = nullptr); 164 void PropagateIsUnderHiddenEmbedderElement(bool aValue); 165 void UpdateEmbeddedBrowsingContextDependentData(); 166 167 // Makes sure that all the live pres shells are pointing to `this`. Returns 168 // true if there's any live shells. 169 bool FixUpInProcessPresShellsAfterAttach(); 170 void PrepareInProcessPresShellsForDetach(); 171 172 bool IsInline() const { return mIsInline; } 173 174 // Show our document viewer. The document viewer is hidden via a script 175 // runner, so that we can save and restore the presentation if we're 176 // being reframed. 177 void ShowViewer(); 178 179 mutable RefPtr<nsFrameLoader> mFrameLoader; 180 181 // The in-process pres shells that we're currently embedding. May be multiple 182 // because of in-process BFCache. 183 // TODO(emilio): Maybe that's not relevant anymore? We definitely hit that 184 // code-path, but maybe it could be simplified nowadays? 185 AutoTArray<nsWeakPtr, 1> mInProcessPresShells; 186 // When process-switching a remote tab, we might temporarily paint the old 187 // one. 188 Maybe<RemoteFramePaintData> mRetainedRemoteFrame; 189 nsWeakPtr mLastPaintedPresShell; 190 191 // The raster scale from our last paint. 192 mozilla::gfx::MatrixScales mRasterScale; 193 // The visible rect from our last paint. 194 Maybe<nsRect> mVisibleRect; 195 196 // The extra offset from our padding box to the child, needed to deal with 197 // object-fit and co. 198 nsPoint mExtraOffset; 199 200 bool mIsInline : 1; 201 bool mPostedReflowCallback : 1; 202 bool mDidCreateDoc : 1; 203 bool mCallingShow : 1; 204 bool mIsInObjectOrEmbed : 1; 205 }; 206 207 namespace mozilla { 208 209 /** 210 * A nsDisplayRemote will graft a remote frame's shadow layer tree (for a given 211 * nsFrameLoader) into its parent frame's layer tree. 212 */ 213 class nsDisplayRemote final : public nsPaintedDisplayItem { 214 typedef mozilla::dom::TabId TabId; 215 typedef mozilla::gfx::Matrix4x4 Matrix4x4; 216 typedef mozilla::layers::EventRegionsOverride EventRegionsOverride; 217 typedef mozilla::layers::LayersId LayersId; 218 typedef mozilla::layers::StackingContextHelper StackingContextHelper; 219 typedef mozilla::LayoutDeviceRect LayoutDeviceRect; 220 typedef mozilla::LayoutDevicePoint LayoutDevicePoint; 221 222 public: 223 nsDisplayRemote(nsDisplayListBuilder* aBuilder, nsSubDocumentFrame* aFrame); 224 225 void Paint(nsDisplayListBuilder* aBuilder, gfxContext* aCtx) override; 226 227 bool CreateWebRenderCommands( 228 mozilla::wr::DisplayListBuilder& aBuilder, 229 mozilla::wr::IpcResourceUpdateQueue& aResources, 230 const StackingContextHelper& aSc, 231 mozilla::layers::RenderRootStateManager* aManager, 232 nsDisplayListBuilder* aDisplayListBuilder) override; 233 bool UpdateScrollData( 234 mozilla::layers::WebRenderScrollData* aData, 235 mozilla::layers::WebRenderLayerScrollData* aLayerData) override; 236 237 NS_DISPLAY_DECL_NAME("Remote", TYPE_REMOTE) 238 239 private: 240 friend class nsDisplayItem; 241 using RemoteFramePaintData = nsSubDocumentFrame::RemoteFramePaintData; 242 243 nsFrameLoader* GetFrameLoader() const; 244 245 RemoteFramePaintData mPaintData; 246 LayoutDevicePoint mOffset; 247 EventRegionsOverride mEventRegionsOverride; 248 }; 249 250 } // namespace mozilla 251 252 #endif /* NSSUBDOCUMENTFRAME_H_ */