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 "LayerState.h" 11 #include "mozilla/Attributes.h" 12 #include "nsDisplayList.h" 13 #include "nsAtomicContainerFrame.h" 14 #include "nsIReflowCallback.h" 15 #include "nsFrameLoader.h" 16 #include "Units.h" 17 18 namespace mozilla { 19 class PresShell; 20 } // namespace mozilla 21 22 namespace mozilla::layers { 23 class Layer; 24 class RefLayer; 25 class RenderRootStateManager; 26 class WebRenderLayerScrollData; 27 class WebRenderScrollData; 28 } // namespace mozilla::layers 29 30 /****************************************************************************** 31 * nsSubDocumentFrame 32 *****************************************************************************/ 33 class nsSubDocumentFrame final : public nsAtomicContainerFrame, 34 public nsIReflowCallback { 35 public: 36 NS_DECL_FRAMEARENA_HELPERS(nsSubDocumentFrame) 37 38 explicit nsSubDocumentFrame(ComputedStyle* aStyle, 39 nsPresContext* aPresContext); 40 41 #ifdef DEBUG_FRAME_DUMP 42 void List(FILE* out = stderr, const char* aPrefix = "", 43 ListFlags aFlags = ListFlags()) const override; 44 nsresult GetFrameName(nsAString& aResult) const override; 45 #endif 46 47 NS_DECL_QUERYFRAME 48 IsFrameOfType(uint32_t aFlags)49 bool IsFrameOfType(uint32_t aFlags) const override { 50 return nsAtomicContainerFrame::IsFrameOfType( 51 aFlags & ~(nsIFrame::eReplaced | nsIFrame::eReplacedSizing | 52 nsIFrame::eReplacedContainsBlock)); 53 } 54 55 void Init(nsIContent* aContent, nsContainerFrame* aParent, 56 nsIFrame* aPrevInFlow) override; 57 58 void DestroyFrom(nsIFrame* aDestructRoot, 59 PostDestroyData& aPostDestroyData) override; 60 61 nscoord GetMinISize(gfxContext* aRenderingContext) override; 62 nscoord GetPrefISize(gfxContext* aRenderingContext) override; 63 64 mozilla::IntrinsicSize GetIntrinsicSize() override; 65 mozilla::AspectRatio GetIntrinsicRatio() const override; 66 67 mozilla::LogicalSize ComputeAutoSize( 68 gfxContext* aRenderingContext, mozilla::WritingMode aWritingMode, 69 const mozilla::LogicalSize& aCBSize, nscoord aAvailableISize, 70 const mozilla::LogicalSize& aMargin, 71 const mozilla::LogicalSize& aBorderPadding, 72 const mozilla::StyleSizeOverrides& aSizeOverrides, 73 mozilla::ComputeSizeFlags aFlags) override; 74 75 SizeComputationResult ComputeSize( 76 gfxContext* aRenderingContext, mozilla::WritingMode aWM, 77 const mozilla::LogicalSize& aCBSize, nscoord aAvailableISize, 78 const mozilla::LogicalSize& aMargin, 79 const mozilla::LogicalSize& aBorderPadding, 80 const mozilla::StyleSizeOverrides& aSizeOverrides, 81 mozilla::ComputeSizeFlags aFlags) override; 82 83 void Reflow(nsPresContext* aPresContext, ReflowOutput& aDesiredSize, 84 const ReflowInput& aReflowInput, 85 nsReflowStatus& aStatus) override; 86 87 void BuildDisplayList(nsDisplayListBuilder* aBuilder, 88 const nsDisplayListSet& aLists) override; 89 90 nsresult AttributeChanged(int32_t aNameSpaceID, nsAtom* aAttribute, 91 int32_t aModType) override; 92 93 void DidSetComputedStyle(ComputedStyle* aOldComputedStyle) override; 94 95 // if the content is "visibility:hidden", then just hide the view 96 // and all our contents. We don't extend "visibility:hidden" to 97 // the child content ourselves, since it belongs to a different 98 // document and CSS doesn't inherit in there. SupportsVisibilityHidden()99 bool SupportsVisibilityHidden() override { return false; } 100 101 #ifdef ACCESSIBILITY 102 mozilla::a11y::AccType AccessibleType() override; 103 #endif 104 105 nsIDocShell* GetDocShell() const; 106 nsresult BeginSwapDocShells(nsIFrame* aOther); 107 void EndSwapDocShells(nsIFrame* aOther); 108 nsView* EnsureInnerView(); 109 nsPoint GetExtraOffset() const; 110 nsIFrame* GetSubdocumentRootFrame(); 111 enum { IGNORE_PAINT_SUPPRESSION = 0x1 }; 112 mozilla::PresShell* GetSubdocumentPresShellForPainting(uint32_t aFlags); 113 mozilla::ScreenIntSize GetSubdocumentSize(); 114 115 // nsIReflowCallback 116 bool ReflowFinished() override; 117 void ReflowCallbackCanceled() override; 118 119 /** 120 * Return true if pointer event hit-testing should be allowed to target 121 * content in the subdocument. 122 */ 123 bool PassPointerEventsToChildren(); 124 MaybeShowViewer()125 void MaybeShowViewer() { 126 if (!mDidCreateDoc && !mCallingShow) { 127 ShowViewer(); 128 } 129 } 130 131 nsFrameLoader* FrameLoader() const; 132 void ResetFrameLoader(); 133 134 void PropagateIsUnderHiddenEmbedderElementToSubView( 135 bool aIsUnderHiddenEmbedderElement); 136 137 void ClearDisplayItems(); 138 139 void SubdocumentIntrinsicSizeOrRatioChanged(); 140 141 protected: 142 friend class AsyncFrameInit; 143 IsInline()144 bool IsInline() { return mIsInline; } 145 GetIntrinsicBSize()146 nscoord GetIntrinsicBSize() { 147 auto size = GetIntrinsicSize(); 148 Maybe<nscoord> bSize = 149 GetWritingMode().IsVertical() ? size.width : size.height; 150 return bSize.valueOr(0); 151 } 152 GetIntrinsicISize()153 nscoord GetIntrinsicISize() { 154 auto size = GetIntrinsicSize(); 155 Maybe<nscoord> iSize = 156 GetWritingMode().IsVertical() ? size.height : size.width; 157 return iSize.valueOr(0); 158 } 159 160 // Show our document viewer. The document viewer is hidden via a script 161 // runner, so that we can save and restore the presentation if we're 162 // being reframed. 163 void ShowViewer(); 164 GetViewInternal()165 nsView* GetViewInternal() const override { return mOuterView; } SetViewInternal(nsView * aView)166 void SetViewInternal(nsView* aView) override { mOuterView = aView; } 167 168 mutable RefPtr<nsFrameLoader> mFrameLoader; 169 170 nsView* mOuterView; 171 nsView* mInnerView; 172 173 bool mIsInline; 174 bool mPostedReflowCallback; 175 bool mDidCreateDoc; 176 bool mCallingShow; 177 }; 178 179 /** 180 * A nsDisplayRemote will graft a remote frame's shadow layer tree (for a given 181 * nsFrameLoader) into its parent frame's layer tree. 182 */ 183 class nsDisplayRemote final : public nsPaintedDisplayItem { 184 typedef mozilla::ContainerLayerParameters ContainerLayerParameters; 185 typedef mozilla::dom::TabId TabId; 186 typedef mozilla::gfx::Matrix4x4 Matrix4x4; 187 typedef mozilla::layers::EventRegionsOverride EventRegionsOverride; 188 typedef mozilla::layers::Layer Layer; 189 typedef mozilla::layers::LayersId LayersId; 190 typedef mozilla::layers::RefLayer RefLayer; 191 typedef mozilla::layers::StackingContextHelper StackingContextHelper; 192 typedef mozilla::LayerState LayerState; 193 typedef mozilla::LayoutDeviceRect LayoutDeviceRect; 194 typedef mozilla::LayoutDevicePoint LayoutDevicePoint; 195 196 public: 197 nsDisplayRemote(nsDisplayListBuilder* aBuilder, nsSubDocumentFrame* aFrame); 198 199 LayerState GetLayerState( 200 nsDisplayListBuilder* aBuilder, LayerManager* aManager, 201 const ContainerLayerParameters& aParameters) override; 202 203 already_AddRefed<Layer> BuildLayer( 204 nsDisplayListBuilder* aBuilder, LayerManager* aManager, 205 const ContainerLayerParameters& aContainerParameters) override; 206 207 void Paint(nsDisplayListBuilder* aBuilder, gfxContext* aCtx) override; 208 209 bool CreateWebRenderCommands( 210 mozilla::wr::DisplayListBuilder& aBuilder, 211 mozilla::wr::IpcResourceUpdateQueue& aResources, 212 const StackingContextHelper& aSc, 213 mozilla::layers::RenderRootStateManager* aManager, 214 nsDisplayListBuilder* aDisplayListBuilder) override; 215 bool UpdateScrollData( 216 mozilla::layers::WebRenderScrollData* aData, 217 mozilla::layers::WebRenderLayerScrollData* aLayerData) override; 218 219 NS_DISPLAY_DECL_NAME("Remote", TYPE_REMOTE) 220 221 private: 222 friend class nsDisplayItemBase; 223 nsFrameLoader* GetFrameLoader() const; 224 225 TabId mTabId; 226 LayersId mLayersId; 227 LayoutDevicePoint mOffset; 228 EventRegionsOverride mEventRegionsOverride; 229 }; 230 231 #endif /* NSSUBDOCUMENTFRAME_H_ */ 232