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 "mozilla/Attributes.h"
11 #include "nsAtomicContainerFrame.h"
12 #include "nsIReflowCallback.h"
13 #include "nsFrameLoader.h"
14 #include "Units.h"
15 
16 /******************************************************************************
17  * nsSubDocumentFrame
18  *****************************************************************************/
19 class nsSubDocumentFrame final : public nsAtomicContainerFrame,
20                                  public nsIReflowCallback {
21  public:
22   NS_DECL_FRAMEARENA_HELPERS(nsSubDocumentFrame)
23 
24   explicit nsSubDocumentFrame(nsStyleContext* aContext);
25 
26 #ifdef DEBUG_FRAME_DUMP
27   void List(FILE* out = stderr, const char* aPrefix = "",
28             uint32_t aFlags = 0) const override;
29   nsresult GetFrameName(nsAString& aResult) const override;
30 #endif
31 
32   NS_DECL_QUERYFRAME
33 
IsFrameOfType(uint32_t aFlags)34   bool IsFrameOfType(uint32_t aFlags) const override {
35     return nsAtomicContainerFrame::IsFrameOfType(
36         aFlags & ~(nsIFrame::eReplaced | nsIFrame::eReplacedSizing |
37                    nsIFrame::eReplacedContainsBlock));
38   }
39 
40   void Init(nsIContent* aContent, nsContainerFrame* aParent,
41             nsIFrame* aPrevInFlow) override;
42 
43   void DestroyFrom(nsIFrame* aDestructRoot,
44                    PostDestroyData& aPostDestroyData) override;
45 
46   nscoord GetMinISize(gfxContext* aRenderingContext) override;
47   nscoord GetPrefISize(gfxContext* aRenderingContext) override;
48 
49   mozilla::IntrinsicSize GetIntrinsicSize() override;
50   nsSize GetIntrinsicRatio() override;
51 
52   mozilla::LogicalSize ComputeAutoSize(
53       gfxContext* aRenderingContext, mozilla::WritingMode aWritingMode,
54       const mozilla::LogicalSize& aCBSize, nscoord aAvailableISize,
55       const mozilla::LogicalSize& aMargin, const mozilla::LogicalSize& aBorder,
56       const mozilla::LogicalSize& aPadding, ComputeSizeFlags aFlags) override;
57 
58   mozilla::LogicalSize ComputeSize(
59       gfxContext* aRenderingContext, mozilla::WritingMode aWritingMode,
60       const mozilla::LogicalSize& aCBSize, nscoord aAvailableISize,
61       const mozilla::LogicalSize& aMargin, const mozilla::LogicalSize& aBorder,
62       const mozilla::LogicalSize& aPadding, ComputeSizeFlags aFlags) override;
63 
64   void Reflow(nsPresContext* aPresContext, ReflowOutput& aDesiredSize,
65               const ReflowInput& aReflowInput,
66               nsReflowStatus& aStatus) override;
67 
68   void BuildDisplayList(nsDisplayListBuilder* aBuilder,
69                         const nsDisplayListSet& aLists) override;
70 
71   nsresult AttributeChanged(int32_t aNameSpaceID, nsAtom* aAttribute,
72                             int32_t aModType) override;
73 
74   // if the content is "visibility:hidden", then just hide the view
75   // and all our contents. We don't extend "visibility:hidden" to
76   // the child content ourselves, since it belongs to a different
77   // document and CSS doesn't inherit in there.
SupportsVisibilityHidden()78   bool SupportsVisibilityHidden() override { return false; }
79 
80 #ifdef ACCESSIBILITY
81   mozilla::a11y::AccType AccessibleType() override;
82 #endif
83 
84   nsresult GetDocShell(nsIDocShell** aDocShell);
85   nsresult BeginSwapDocShells(nsIFrame* aOther);
86   void EndSwapDocShells(nsIFrame* aOther);
87   nsView* EnsureInnerView();
88   nsIFrame* GetSubdocumentRootFrame();
89   enum { IGNORE_PAINT_SUPPRESSION = 0x1 };
90   nsIPresShell* GetSubdocumentPresShellForPainting(uint32_t aFlags);
91   mozilla::ScreenIntSize GetSubdocumentSize();
92 
93   // nsIReflowCallback
94   bool ReflowFinished() override;
95   void ReflowCallbackCanceled() override;
96 
ShouldClipSubdocument()97   bool ShouldClipSubdocument() {
98     nsFrameLoader* frameLoader = FrameLoader();
99     return !frameLoader || frameLoader->ShouldClipSubdocument();
100   }
101 
ShouldClampScrollPosition()102   bool ShouldClampScrollPosition() {
103     nsFrameLoader* frameLoader = FrameLoader();
104     return !frameLoader || frameLoader->ShouldClampScrollPosition();
105   }
106 
107   /**
108    * Return true if pointer event hit-testing should be allowed to target
109    * content in the subdocument.
110    */
111   bool PassPointerEventsToChildren();
112 
MaybeShowViewer()113   void MaybeShowViewer() {
114     if (!mDidCreateDoc && !mCallingShow) {
115       ShowViewer();
116     }
117   }
118 
119  protected:
120   friend class AsyncFrameInit;
121 
122   // Helper method to look up the HTML marginwidth & marginheight attributes.
123   mozilla::CSSIntSize GetMarginAttributes();
124 
125   nsFrameLoader* FrameLoader();
126 
IsInline()127   bool IsInline() { return mIsInline; }
128 
129   nscoord GetIntrinsicISize();
130   nscoord GetIntrinsicBSize();
131 
132   // Show our document viewer. The document viewer is hidden via a script
133   // runner, so that we can save and restore the presentation if we're
134   // being reframed.
135   void ShowViewer();
136 
137   /* Obtains the frame we should use for intrinsic size information if we are
138    * an HTML <object> or <embed>  (a replaced element - not <iframe>)
139    * and our sub-document has an intrinsic size. The frame returned is the
140    * frame for the document element of the document we're embedding.
141    *
142    * Called "Obtain*" and not "Get*" because of comment on GetDocShell that
143    * says it should be called ObtainDocShell because of its side effects.
144    */
145   nsIFrame* ObtainIntrinsicSizeFrame();
146 
GetViewInternal()147   nsView* GetViewInternal() const override { return mOuterView; }
SetViewInternal(nsView * aView)148   void SetViewInternal(nsView* aView) override { mOuterView = aView; }
149 
150   RefPtr<nsFrameLoader> mFrameLoader;
151   nsView* mOuterView;
152   nsView* mInnerView;
153   Maybe<bool> mPreviouslyNeededLayer;
154   bool mIsInline;
155   bool mPostedReflowCallback;
156   bool mDidCreateDoc;
157   bool mCallingShow;
158   WeakFrame mPreviousCaret;
159 };
160 
161 #endif /* NSSUBDOCUMENTFRAME_H_ */
162