1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/layout/generic/nsObjectFrame.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,340 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +/* rendering objects for replaced elements implemented by a plugin */ 1.10 + 1.11 +#ifndef nsObjectFrame_h___ 1.12 +#define nsObjectFrame_h___ 1.13 + 1.14 +#include "mozilla/Attributes.h" 1.15 +#include "nsIObjectFrame.h" 1.16 +#include "nsFrame.h" 1.17 +#include "nsRegion.h" 1.18 +#include "nsDisplayList.h" 1.19 +#include "nsIReflowCallback.h" 1.20 + 1.21 +#ifdef XP_WIN 1.22 +#include <windows.h> // For HWND :( 1.23 +#endif 1.24 + 1.25 +class nsPresContext; 1.26 +class nsRootPresContext; 1.27 +class nsDisplayPlugin; 1.28 +class nsIOSurface; 1.29 +class PluginBackgroundSink; 1.30 +class nsPluginInstanceOwner; 1.31 + 1.32 +namespace mozilla { 1.33 +namespace layers { 1.34 +class ImageContainer; 1.35 +class Layer; 1.36 +class LayerManager; 1.37 +} 1.38 +} 1.39 + 1.40 +typedef nsFrame nsObjectFrameSuper; 1.41 + 1.42 +class nsObjectFrame : public nsObjectFrameSuper, 1.43 + public nsIObjectFrame, 1.44 + public nsIReflowCallback { 1.45 +public: 1.46 + typedef mozilla::LayerState LayerState; 1.47 + typedef mozilla::layers::Layer Layer; 1.48 + typedef mozilla::layers::LayerManager LayerManager; 1.49 + typedef mozilla::layers::ImageContainer ImageContainer; 1.50 + typedef mozilla::ContainerLayerParameters ContainerLayerParameters; 1.51 + 1.52 + NS_DECL_FRAMEARENA_HELPERS 1.53 + 1.54 + friend nsIFrame* NS_NewObjectFrame(nsIPresShell* aPresShell, nsStyleContext* aContext); 1.55 + 1.56 + NS_DECL_QUERYFRAME 1.57 + NS_DECL_QUERYFRAME_TARGET(nsObjectFrame) 1.58 + 1.59 + virtual void Init(nsIContent* aContent, 1.60 + nsIFrame* aParent, 1.61 + nsIFrame* aPrevInFlow) MOZ_OVERRIDE; 1.62 + virtual nscoord GetMinWidth(nsRenderingContext *aRenderingContext) MOZ_OVERRIDE; 1.63 + virtual nscoord GetPrefWidth(nsRenderingContext *aRenderingContext) MOZ_OVERRIDE; 1.64 + virtual nsresult Reflow(nsPresContext* aPresContext, 1.65 + nsHTMLReflowMetrics& aDesiredSize, 1.66 + const nsHTMLReflowState& aReflowState, 1.67 + nsReflowStatus& aStatus) MOZ_OVERRIDE; 1.68 + virtual nsresult DidReflow(nsPresContext* aPresContext, 1.69 + const nsHTMLReflowState* aReflowState, 1.70 + nsDidReflowStatus aStatus) MOZ_OVERRIDE; 1.71 + virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder, 1.72 + const nsRect& aDirtyRect, 1.73 + const nsDisplayListSet& aLists) MOZ_OVERRIDE; 1.74 + 1.75 + virtual nsresult HandleEvent(nsPresContext* aPresContext, 1.76 + mozilla::WidgetGUIEvent* aEvent, 1.77 + nsEventStatus* aEventStatus) MOZ_OVERRIDE; 1.78 + 1.79 + virtual nsIAtom* GetType() const MOZ_OVERRIDE; 1.80 + 1.81 + virtual bool IsFrameOfType(uint32_t aFlags) const MOZ_OVERRIDE 1.82 + { 1.83 + return nsObjectFrameSuper::IsFrameOfType(aFlags & ~(nsIFrame::eReplaced)); 1.84 + } 1.85 + 1.86 + virtual bool NeedsView() MOZ_OVERRIDE { return true; } 1.87 + 1.88 +#ifdef DEBUG_FRAME_DUMP 1.89 + virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE; 1.90 +#endif 1.91 + 1.92 + virtual void DestroyFrom(nsIFrame* aDestructRoot) MOZ_OVERRIDE; 1.93 + 1.94 + virtual void DidSetStyleContext(nsStyleContext* aOldStyleContext) MOZ_OVERRIDE; 1.95 + 1.96 + NS_METHOD GetPluginInstance(nsNPAPIPluginInstance** aPluginInstance) MOZ_OVERRIDE; 1.97 + 1.98 + virtual void SetIsDocumentActive(bool aIsActive) MOZ_OVERRIDE; 1.99 + 1.100 + virtual nsresult GetCursor(const nsPoint& aPoint, 1.101 + nsIFrame::Cursor& aCursor) MOZ_OVERRIDE; 1.102 + 1.103 + // APIs used by nsRootPresContext to set up the widget position/size/clip 1.104 + // region. 1.105 + /** 1.106 + * Set the next widget configuration for the plugin to the desired 1.107 + * position of the plugin's widget, on the assumption that it is not visible 1.108 + * (clipped out or covered by opaque content). 1.109 + * This will only be called for plugins which have been registered 1.110 + * with the root pres context for geometry updates. 1.111 + * If there is no widget associated with the plugin, this will have no effect. 1.112 + */ 1.113 + void SetEmptyWidgetConfiguration() 1.114 + { 1.115 + mNextConfigurationBounds = nsIntRect(0,0,0,0); 1.116 + mNextConfigurationClipRegion.Clear(); 1.117 + } 1.118 + /** 1.119 + * Append the desired widget configuration to aConfigurations. 1.120 + */ 1.121 + void GetWidgetConfiguration(nsTArray<nsIWidget::Configuration>* aConfigurations) 1.122 + { 1.123 + if (mWidget) { 1.124 + if (!mWidget->GetParent()) { 1.125 + // Plugin widgets should not be toplevel except when they're out of the 1.126 + // document, in which case the plugin should not be registered for 1.127 + // geometry updates and this should not be called. But apparently we 1.128 + // have bugs where mWidget sometimes is toplevel here. Bail out. 1.129 + NS_ERROR("Plugin widgets registered for geometry updates should not be toplevel"); 1.130 + return; 1.131 + } 1.132 + nsIWidget::Configuration* configuration = aConfigurations->AppendElement(); 1.133 + configuration->mChild = mWidget; 1.134 + configuration->mBounds = mNextConfigurationBounds; 1.135 + configuration->mClipRegion = mNextConfigurationClipRegion; 1.136 + } 1.137 + } 1.138 + /** 1.139 + * Called after all widget position/size/clip regions have been changed 1.140 + * (even if there isn't a widget for this plugin). 1.141 + */ 1.142 + void DidSetWidgetGeometry(); 1.143 + 1.144 + // accessibility support 1.145 +#ifdef ACCESSIBILITY 1.146 + virtual mozilla::a11y::AccType AccessibleType() MOZ_OVERRIDE; 1.147 +#ifdef XP_WIN 1.148 + NS_IMETHOD GetPluginPort(HWND *aPort); 1.149 +#endif 1.150 +#endif 1.151 + 1.152 + //local methods 1.153 + nsresult PrepForDrawing(nsIWidget *aWidget); 1.154 + 1.155 + // for a given aRoot, this walks the frame tree looking for the next outFrame 1.156 + static nsIObjectFrame* GetNextObjectFrame(nsPresContext* aPresContext, 1.157 + nsIFrame* aRoot); 1.158 + 1.159 + // nsIReflowCallback 1.160 + virtual bool ReflowFinished() MOZ_OVERRIDE; 1.161 + virtual void ReflowCallbackCanceled() MOZ_OVERRIDE; 1.162 + 1.163 + /** 1.164 + * Builds either an ImageLayer or a ReadbackLayer, depending on the type 1.165 + * of aItem (TYPE_PLUGIN or TYPE_PLUGIN_READBACK respectively). 1.166 + */ 1.167 + already_AddRefed<Layer> BuildLayer(nsDisplayListBuilder* aBuilder, 1.168 + LayerManager* aManager, 1.169 + nsDisplayItem* aItem, 1.170 + const ContainerLayerParameters& aContainerParameters); 1.171 + 1.172 + LayerState GetLayerState(nsDisplayListBuilder* aBuilder, 1.173 + LayerManager* aManager); 1.174 + 1.175 + /** 1.176 + * Get the rectangle (relative to this frame) which it will paint. Normally 1.177 + * the frame's content-box but may be smaller if the plugin is rendering 1.178 + * asynchronously and has a different-sized image temporarily. 1.179 + */ 1.180 + nsRect GetPaintedRect(nsDisplayPlugin* aItem); 1.181 + 1.182 + /** 1.183 + * If aContent has a nsObjectFrame, then prepare it for a DocShell swap. 1.184 + * @see nsSubDocumentFrame::BeginSwapDocShells. 1.185 + * There will be a call to EndSwapDocShells after we were moved to the 1.186 + * new view tree. 1.187 + */ 1.188 + static void BeginSwapDocShells(nsIContent* aContent, void*); 1.189 + /** 1.190 + * If aContent has a nsObjectFrame, then set it up after a DocShell swap. 1.191 + * @see nsSubDocumentFrame::EndSwapDocShells. 1.192 + */ 1.193 + static void EndSwapDocShells(nsIContent* aContent, void*); 1.194 + 1.195 + nsIWidget* GetWidget() MOZ_OVERRIDE { return mInnerView ? mWidget : nullptr; } 1.196 + 1.197 + /** 1.198 + * Adjust the plugin's idea of its size, using aSize as its new size. 1.199 + * (aSize must be in twips) 1.200 + */ 1.201 + void FixupWindow(const nsSize& aSize); 1.202 + 1.203 + /* 1.204 + * Sets up the plugin window and calls SetWindow on the plugin. 1.205 + */ 1.206 + nsresult CallSetWindow(bool aCheckIsHidden = true); 1.207 + 1.208 + void SetInstanceOwner(nsPluginInstanceOwner* aOwner); 1.209 + 1.210 +protected: 1.211 + nsObjectFrame(nsStyleContext* aContext); 1.212 + virtual ~nsObjectFrame(); 1.213 + 1.214 + // NOTE: This frame class does not inherit from |nsLeafFrame|, so 1.215 + // this is not a virtual method implementation. 1.216 + void GetDesiredSize(nsPresContext* aPresContext, 1.217 + const nsHTMLReflowState& aReflowState, 1.218 + nsHTMLReflowMetrics& aDesiredSize); 1.219 + 1.220 + bool IsFocusable(int32_t *aTabIndex = nullptr, 1.221 + bool aWithMouse = false) MOZ_OVERRIDE; 1.222 + 1.223 + // check attributes and optionally CSS to see if we should display anything 1.224 + bool IsHidden(bool aCheckVisibilityStyle = true) const; 1.225 + 1.226 + bool IsOpaque() const; 1.227 + bool IsTransparentMode() const; 1.228 + bool IsPaintedByGecko() const; 1.229 + 1.230 + nsIntPoint GetWindowOriginInPixels(bool aWindowless); 1.231 + 1.232 + static void PaintPrintPlugin(nsIFrame* aFrame, 1.233 + nsRenderingContext* aRenderingContext, 1.234 + const nsRect& aDirtyRect, nsPoint aPt); 1.235 + void PrintPlugin(nsRenderingContext& aRenderingContext, 1.236 + const nsRect& aDirtyRect); 1.237 + void PaintPlugin(nsDisplayListBuilder* aBuilder, 1.238 + nsRenderingContext& aRenderingContext, 1.239 + const nsRect& aDirtyRect, const nsRect& aPluginRect); 1.240 + 1.241 + void NotifyPluginReflowObservers(); 1.242 + 1.243 + friend class nsPluginInstanceOwner; 1.244 + friend class nsDisplayPlugin; 1.245 + friend class PluginBackgroundSink; 1.246 + 1.247 +private: 1.248 + // Registers the plugin for a geometry update, and requests a geometry 1.249 + // update. This caches the root pres context in 1.250 + // mRootPresContextRegisteredWith, so that we can be sure we unregister 1.251 + // from the right root prest context in UnregisterPluginForGeometryUpdates. 1.252 + void RegisterPluginForGeometryUpdates(); 1.253 + 1.254 + // Unregisters the plugin for geometry updated with the root pres context 1.255 + // stored in mRootPresContextRegisteredWith. 1.256 + void UnregisterPluginForGeometryUpdates(); 1.257 + 1.258 + class PluginEventNotifier : public nsRunnable { 1.259 + public: 1.260 + PluginEventNotifier(const nsString &aEventType) : 1.261 + mEventType(aEventType) {} 1.262 + 1.263 + NS_IMETHOD Run() MOZ_OVERRIDE; 1.264 + private: 1.265 + nsString mEventType; 1.266 + }; 1.267 + 1.268 + nsPluginInstanceOwner* mInstanceOwner; // WEAK 1.269 + nsView* mInnerView; 1.270 + nsCOMPtr<nsIWidget> mWidget; 1.271 + nsIntRect mWindowlessRect; 1.272 + /** 1.273 + * This is owned by the ReadbackLayer for this nsObjectFrame. It is 1.274 + * automatically cleared if the PluginBackgroundSink is destroyed. 1.275 + */ 1.276 + PluginBackgroundSink* mBackgroundSink; 1.277 + 1.278 + /** 1.279 + * Bounds that we should set the plugin's widget to in the next composite, 1.280 + * for plugins with widgets. For plugins without widgets, bounds in device 1.281 + * pixels relative to the nearest frame that's a display list reference frame. 1.282 + */ 1.283 + nsIntRect mNextConfigurationBounds; 1.284 + /** 1.285 + * Clip region that we should set the plugin's widget to 1.286 + * in the next composite. Only meaningful for plugins with widgets. 1.287 + */ 1.288 + nsTArray<nsIntRect> mNextConfigurationClipRegion; 1.289 + 1.290 + bool mReflowCallbackPosted; 1.291 + 1.292 + // We keep this reference to ensure we can always unregister the 1.293 + // plugins we register on the root PresContext. 1.294 + // This is only non-null while we have a plugin registered for geometry 1.295 + // updates. 1.296 + nsRefPtr<nsRootPresContext> mRootPresContextRegisteredWith; 1.297 +}; 1.298 + 1.299 +class nsDisplayPlugin : public nsDisplayItem { 1.300 +public: 1.301 + nsDisplayPlugin(nsDisplayListBuilder* aBuilder, nsIFrame* aFrame) 1.302 + : nsDisplayItem(aBuilder, aFrame) 1.303 + { 1.304 + MOZ_COUNT_CTOR(nsDisplayPlugin); 1.305 + aBuilder->SetContainsPluginItem(); 1.306 + } 1.307 +#ifdef NS_BUILD_REFCNT_LOGGING 1.308 + virtual ~nsDisplayPlugin() { 1.309 + MOZ_COUNT_DTOR(nsDisplayPlugin); 1.310 + } 1.311 +#endif 1.312 + 1.313 + virtual nsRect GetBounds(nsDisplayListBuilder* aBuilder, bool* aSnap) MOZ_OVERRIDE; 1.314 + virtual nsRegion GetOpaqueRegion(nsDisplayListBuilder* aBuilder, 1.315 + bool* aSnap) MOZ_OVERRIDE; 1.316 + virtual void Paint(nsDisplayListBuilder* aBuilder, 1.317 + nsRenderingContext* aCtx) MOZ_OVERRIDE; 1.318 + virtual bool ComputeVisibility(nsDisplayListBuilder* aBuilder, 1.319 + nsRegion* aVisibleRegion, 1.320 + const nsRect& aAllowVisibleRegionExpansion) MOZ_OVERRIDE; 1.321 + 1.322 + NS_DISPLAY_DECL_NAME("Plugin", TYPE_PLUGIN) 1.323 + 1.324 + virtual already_AddRefed<Layer> BuildLayer(nsDisplayListBuilder* aBuilder, 1.325 + LayerManager* aManager, 1.326 + const ContainerLayerParameters& aContainerParameters) MOZ_OVERRIDE 1.327 + { 1.328 + return static_cast<nsObjectFrame*>(mFrame)->BuildLayer(aBuilder, 1.329 + aManager, 1.330 + this, 1.331 + aContainerParameters); 1.332 + } 1.333 + 1.334 + virtual LayerState GetLayerState(nsDisplayListBuilder* aBuilder, 1.335 + LayerManager* aManager, 1.336 + const ContainerLayerParameters& aParameters) MOZ_OVERRIDE 1.337 + { 1.338 + return static_cast<nsObjectFrame*>(mFrame)->GetLayerState(aBuilder, 1.339 + aManager); 1.340 + } 1.341 +}; 1.342 + 1.343 +#endif /* nsObjectFrame_h___ */