1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
24 * Alternatively, the contents of this file may be used under the terms of
25 * either of the GNU General Public License Version 2 or later (the "GPL"),
26 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
38 /* rendering objects for replaced elements implemented by a plugin */
40 #ifndef nsObjectFrame_h___
41 #define nsObjectFrame_h___
47 #include "nsIObjectFrame.h"
50 #include "nsDisplayList.h"
56 class nsPluginInstanceOwner
;
58 class nsIPluginInstance
;
60 class nsDisplayPlugin
;
63 #define nsObjectFrameSuper nsFrame
65 class nsObjectFrame
: public nsObjectFrameSuper
, public nsIObjectFrame
{
67 NS_DECL_FRAMEARENA_HELPERS
69 friend nsIFrame
* NS_NewObjectFrame(nsIPresShell
* aPresShell
, nsStyleContext
* aContext
);
73 NS_IMETHOD
Init(nsIContent
* aContent
,
75 nsIFrame
* aPrevInFlow
);
76 virtual nscoord
GetMinWidth(nsIRenderingContext
*aRenderingContext
);
77 virtual nscoord
GetPrefWidth(nsIRenderingContext
*aRenderingContext
);
78 NS_IMETHOD
Reflow(nsPresContext
* aPresContext
,
79 nsHTMLReflowMetrics
& aDesiredSize
,
80 const nsHTMLReflowState
& aReflowState
,
81 nsReflowStatus
& aStatus
);
82 NS_IMETHOD
DidReflow(nsPresContext
* aPresContext
,
83 const nsHTMLReflowState
* aReflowState
,
84 nsDidReflowStatus aStatus
);
85 NS_IMETHOD
BuildDisplayList(nsDisplayListBuilder
* aBuilder
,
86 const nsRect
& aDirtyRect
,
87 const nsDisplayListSet
& aLists
);
89 NS_IMETHOD
HandleEvent(nsPresContext
* aPresContext
,
91 nsEventStatus
* aEventStatus
);
94 NS_IMETHOD
HandlePress(nsPresContext
* aPresContext
,
96 nsEventStatus
* aEventStatus
);
99 virtual nsIAtom
* GetType() const;
101 virtual PRBool
IsFrameOfType(PRUint32 aFlags
) const
103 return nsObjectFrameSuper::IsFrameOfType(aFlags
& ~(nsIFrame::eReplaced
));
106 virtual PRBool
NeedsView() { return PR_TRUE
; }
109 NS_IMETHOD
GetFrameName(nsAString
& aResult
) const;
112 virtual void DestroyFrom(nsIFrame
* aDestructRoot
);
114 virtual void DidSetStyleContext(nsStyleContext
* aOldStyleContext
);
116 NS_IMETHOD
GetPluginInstance(nsIPluginInstance
*& aPluginInstance
);
117 virtual nsresult
Instantiate(nsIChannel
* aChannel
, nsIStreamListener
** aStreamListener
);
118 virtual nsresult
Instantiate(const char* aMimeType
, nsIURI
* aURI
);
119 virtual void TryNotifyContentObjectWrapper();
120 virtual void StopPlugin();
123 * Stop a plugin instance. If aDelayedStop is true, the plugin will
124 * be stopped at a later point when it's safe to do so (i.e. not
125 * while destroying the frame tree). Delayed stopping is only
126 * implemented on Win32 for now.
128 void StopPluginInternal(PRBool aDelayedStop
);
130 /* fail on any requests to get a cursor from us because plugins set their own! see bug 118877 */
131 NS_IMETHOD
GetCursor(const nsPoint
& aPoint
, nsIFrame::Cursor
& aCursor
)
133 return NS_ERROR_NOT_IMPLEMENTED
;
136 // Compute the desired position of the plugin's widget, on the assumption
137 // that it is not visible (clipped out or covered by opaque content).
138 // This will only be called for plugins which have been registered
139 // with the root pres context for geometry updates.
140 // The widget, its new position, size and (empty) clip region are appended
141 // as a Configuration record to aConfigurations.
142 // If there is no widget associated with the plugin, this
143 // simply does nothing.
144 void GetEmptyClipConfiguration(nsTArray
<nsIWidget::Configuration
>* aConfigurations
) {
145 ComputeWidgetGeometry(nsRegion(), nsPoint(0,0), aConfigurations
);
148 void DidSetWidgetGeometry();
150 // accessibility support
152 virtual already_AddRefed
<nsAccessible
> CreateAccessible();
154 NS_IMETHOD
GetPluginPort(HWND
*aPort
);
159 nsresult
CreateWidget(nscoord aWidth
, nscoord aHeight
, PRBool aViewOnly
);
161 // for a given aRoot, this walks the frame tree looking for the next outFrame
162 static nsIObjectFrame
* GetNextObjectFrame(nsPresContext
* aPresContext
,
166 nsObjectFrame(nsStyleContext
* aContext
);
167 virtual ~nsObjectFrame();
169 // NOTE: This frame class does not inherit from |nsLeafFrame|, so
170 // this is not a virtual method implementation.
171 void GetDesiredSize(nsPresContext
* aPresContext
,
172 const nsHTMLReflowState
& aReflowState
,
173 nsHTMLReflowMetrics
& aDesiredSize
);
175 nsresult
InstantiatePlugin(nsIPluginHost
* aPluginHost
,
176 const char* aMimetype
,
180 * Adjust the plugin's idea of its size, using aSize as its new size.
181 * (aSize must be in twips)
183 void FixupWindow(const nsSize
& aSize
);
186 * Sets up the plugin window and calls SetWindow on the plugin.
188 void CallSetWindow();
190 PRBool
IsFocusable(PRInt32
*aTabIndex
= nsnull
, PRBool aWithMouse
= PR_FALSE
);
192 // check attributes and optionally CSS to see if we should display anything
193 PRBool
IsHidden(PRBool aCheckVisibilityStyle
= PR_TRUE
) const;
195 PRBool
IsOpaque() const;
197 void NotifyContentObjectWrapper();
199 nsIntPoint
GetWindowOriginInPixels(PRBool aWindowless
);
201 static void PaintPrintPlugin(nsIFrame
* aFrame
,
202 nsIRenderingContext
* aRenderingContext
,
203 const nsRect
& aDirtyRect
, nsPoint aPt
);
204 void PrintPlugin(nsIRenderingContext
& aRenderingContext
,
205 const nsRect
& aDirtyRect
);
206 void PaintPlugin(nsIRenderingContext
& aRenderingContext
,
207 const nsRect
& aDirtyRect
, const nsRect
& aPluginRect
);
210 * Makes sure that mInstanceOwner is valid and without a current plugin
211 * instance. Essentially, this prepares the frame to receive a new plugin.
213 NS_HIDDEN_(nsresult
) PrepareInstanceOwner();
216 * Get the widget geometry for the plugin. aRegion is in some appunits
217 * coordinate system whose origin is device-pixel-aligned (if possible),
218 * and aPluginOrigin gives the top-left of the plugin frame's content-rect
219 * in that coordinate system. It doesn't matter what that coordinate
220 * system actually is, as long as aRegion and aPluginOrigin are consistent.
221 * This will append a Configuration object to aConfigurations
222 * containing the widget, its desired position, size and clip region.
224 void ComputeWidgetGeometry(const nsRegion
& aRegion
,
225 const nsPoint
& aPluginOrigin
,
226 nsTArray
<nsIWidget::Configuration
>* aConfigurations
);
228 nsIWidget
* GetWidget() { return mWidget
; }
230 nsresult
SetAbsoluteScreenPosition(nsIDOMElement
* element
,
231 nsIDOMClientRect
* position
,
232 nsIDOMClientRect
* clip
);
234 void NotifyPluginReflowObservers();
236 friend class nsPluginInstanceOwner
;
237 friend class nsDisplayPlugin
;
241 class PluginEventNotifier
: public nsRunnable
{
243 PluginEventNotifier(const nsString
&aEventType
) :
244 mEventType(aEventType
) {}
251 nsRefPtr
<nsPluginInstanceOwner
> mInstanceOwner
;
253 nsCOMPtr
<nsIWidget
> mWidget
;
254 nsIntRect mWindowlessRect
;
256 PRUint32 mDoublePassEvent
;
259 // For assertions that make it easier to determine if a crash is due
260 // to the underlying problem described in bug 136927, and to prevent
261 // reentry into instantiation.
262 PRBool mPreventInstantiation
;
265 class nsDisplayPlugin
: public nsDisplayItem
{
267 nsDisplayPlugin(nsIFrame
* aFrame
)
268 : nsDisplayItem(aFrame
)
270 MOZ_COUNT_CTOR(nsDisplayPlugin
);
272 #ifdef NS_BUILD_REFCNT_LOGGING
273 virtual ~nsDisplayPlugin() {
274 MOZ_COUNT_DTOR(nsDisplayPlugin
);
278 virtual nsRect
GetBounds(nsDisplayListBuilder
* aBuilder
);
279 virtual PRBool
IsOpaque(nsDisplayListBuilder
* aBuilder
);
280 virtual void Paint(nsDisplayListBuilder
* aBuilder
,
281 nsIRenderingContext
* aCtx
);
282 virtual PRBool
ComputeVisibility(nsDisplayListBuilder
* aBuilder
,
283 nsRegion
* aVisibleRegion
,
284 nsRegion
* aVisibleRegionBeforeMove
);
286 NS_DISPLAY_DECL_NAME("Plugin", TYPE_PLUGIN
)
288 // Compute the desired position and clip region of the plugin's widget.
289 // This will only be called for plugins which have been registered
290 // with the root pres context for geometry updates.
291 // The widget, its new position, size and clip region are appended as
292 // a Configuration record to aConfigurations.
293 // If there is no widget associated with the plugin, this
294 // simply does nothing.
295 void GetWidgetConfiguration(nsDisplayListBuilder
* aBuilder
,
296 nsTArray
<nsIWidget::Configuration
>* aConfigurations
);
299 nsRegion mVisibleRegion
;
302 #endif /* nsObjectFrame_h___ */