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