layout/generic/nsObjectFrame.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 /* rendering objects for replaced elements implemented by a plugin */
michael@0 7
michael@0 8 #ifndef nsObjectFrame_h___
michael@0 9 #define nsObjectFrame_h___
michael@0 10
michael@0 11 #include "mozilla/Attributes.h"
michael@0 12 #include "nsIObjectFrame.h"
michael@0 13 #include "nsFrame.h"
michael@0 14 #include "nsRegion.h"
michael@0 15 #include "nsDisplayList.h"
michael@0 16 #include "nsIReflowCallback.h"
michael@0 17
michael@0 18 #ifdef XP_WIN
michael@0 19 #include <windows.h> // For HWND :(
michael@0 20 #endif
michael@0 21
michael@0 22 class nsPresContext;
michael@0 23 class nsRootPresContext;
michael@0 24 class nsDisplayPlugin;
michael@0 25 class nsIOSurface;
michael@0 26 class PluginBackgroundSink;
michael@0 27 class nsPluginInstanceOwner;
michael@0 28
michael@0 29 namespace mozilla {
michael@0 30 namespace layers {
michael@0 31 class ImageContainer;
michael@0 32 class Layer;
michael@0 33 class LayerManager;
michael@0 34 }
michael@0 35 }
michael@0 36
michael@0 37 typedef nsFrame nsObjectFrameSuper;
michael@0 38
michael@0 39 class nsObjectFrame : public nsObjectFrameSuper,
michael@0 40 public nsIObjectFrame,
michael@0 41 public nsIReflowCallback {
michael@0 42 public:
michael@0 43 typedef mozilla::LayerState LayerState;
michael@0 44 typedef mozilla::layers::Layer Layer;
michael@0 45 typedef mozilla::layers::LayerManager LayerManager;
michael@0 46 typedef mozilla::layers::ImageContainer ImageContainer;
michael@0 47 typedef mozilla::ContainerLayerParameters ContainerLayerParameters;
michael@0 48
michael@0 49 NS_DECL_FRAMEARENA_HELPERS
michael@0 50
michael@0 51 friend nsIFrame* NS_NewObjectFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
michael@0 52
michael@0 53 NS_DECL_QUERYFRAME
michael@0 54 NS_DECL_QUERYFRAME_TARGET(nsObjectFrame)
michael@0 55
michael@0 56 virtual void Init(nsIContent* aContent,
michael@0 57 nsIFrame* aParent,
michael@0 58 nsIFrame* aPrevInFlow) MOZ_OVERRIDE;
michael@0 59 virtual nscoord GetMinWidth(nsRenderingContext *aRenderingContext) MOZ_OVERRIDE;
michael@0 60 virtual nscoord GetPrefWidth(nsRenderingContext *aRenderingContext) MOZ_OVERRIDE;
michael@0 61 virtual nsresult Reflow(nsPresContext* aPresContext,
michael@0 62 nsHTMLReflowMetrics& aDesiredSize,
michael@0 63 const nsHTMLReflowState& aReflowState,
michael@0 64 nsReflowStatus& aStatus) MOZ_OVERRIDE;
michael@0 65 virtual nsresult DidReflow(nsPresContext* aPresContext,
michael@0 66 const nsHTMLReflowState* aReflowState,
michael@0 67 nsDidReflowStatus aStatus) MOZ_OVERRIDE;
michael@0 68 virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder,
michael@0 69 const nsRect& aDirtyRect,
michael@0 70 const nsDisplayListSet& aLists) MOZ_OVERRIDE;
michael@0 71
michael@0 72 virtual nsresult HandleEvent(nsPresContext* aPresContext,
michael@0 73 mozilla::WidgetGUIEvent* aEvent,
michael@0 74 nsEventStatus* aEventStatus) MOZ_OVERRIDE;
michael@0 75
michael@0 76 virtual nsIAtom* GetType() const MOZ_OVERRIDE;
michael@0 77
michael@0 78 virtual bool IsFrameOfType(uint32_t aFlags) const MOZ_OVERRIDE
michael@0 79 {
michael@0 80 return nsObjectFrameSuper::IsFrameOfType(aFlags & ~(nsIFrame::eReplaced));
michael@0 81 }
michael@0 82
michael@0 83 virtual bool NeedsView() MOZ_OVERRIDE { return true; }
michael@0 84
michael@0 85 #ifdef DEBUG_FRAME_DUMP
michael@0 86 virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE;
michael@0 87 #endif
michael@0 88
michael@0 89 virtual void DestroyFrom(nsIFrame* aDestructRoot) MOZ_OVERRIDE;
michael@0 90
michael@0 91 virtual void DidSetStyleContext(nsStyleContext* aOldStyleContext) MOZ_OVERRIDE;
michael@0 92
michael@0 93 NS_METHOD GetPluginInstance(nsNPAPIPluginInstance** aPluginInstance) MOZ_OVERRIDE;
michael@0 94
michael@0 95 virtual void SetIsDocumentActive(bool aIsActive) MOZ_OVERRIDE;
michael@0 96
michael@0 97 virtual nsresult GetCursor(const nsPoint& aPoint,
michael@0 98 nsIFrame::Cursor& aCursor) MOZ_OVERRIDE;
michael@0 99
michael@0 100 // APIs used by nsRootPresContext to set up the widget position/size/clip
michael@0 101 // region.
michael@0 102 /**
michael@0 103 * Set the next widget configuration for the plugin to the desired
michael@0 104 * position of the plugin's widget, on the assumption that it is not visible
michael@0 105 * (clipped out or covered by opaque content).
michael@0 106 * This will only be called for plugins which have been registered
michael@0 107 * with the root pres context for geometry updates.
michael@0 108 * If there is no widget associated with the plugin, this will have no effect.
michael@0 109 */
michael@0 110 void SetEmptyWidgetConfiguration()
michael@0 111 {
michael@0 112 mNextConfigurationBounds = nsIntRect(0,0,0,0);
michael@0 113 mNextConfigurationClipRegion.Clear();
michael@0 114 }
michael@0 115 /**
michael@0 116 * Append the desired widget configuration to aConfigurations.
michael@0 117 */
michael@0 118 void GetWidgetConfiguration(nsTArray<nsIWidget::Configuration>* aConfigurations)
michael@0 119 {
michael@0 120 if (mWidget) {
michael@0 121 if (!mWidget->GetParent()) {
michael@0 122 // Plugin widgets should not be toplevel except when they're out of the
michael@0 123 // document, in which case the plugin should not be registered for
michael@0 124 // geometry updates and this should not be called. But apparently we
michael@0 125 // have bugs where mWidget sometimes is toplevel here. Bail out.
michael@0 126 NS_ERROR("Plugin widgets registered for geometry updates should not be toplevel");
michael@0 127 return;
michael@0 128 }
michael@0 129 nsIWidget::Configuration* configuration = aConfigurations->AppendElement();
michael@0 130 configuration->mChild = mWidget;
michael@0 131 configuration->mBounds = mNextConfigurationBounds;
michael@0 132 configuration->mClipRegion = mNextConfigurationClipRegion;
michael@0 133 }
michael@0 134 }
michael@0 135 /**
michael@0 136 * Called after all widget position/size/clip regions have been changed
michael@0 137 * (even if there isn't a widget for this plugin).
michael@0 138 */
michael@0 139 void DidSetWidgetGeometry();
michael@0 140
michael@0 141 // accessibility support
michael@0 142 #ifdef ACCESSIBILITY
michael@0 143 virtual mozilla::a11y::AccType AccessibleType() MOZ_OVERRIDE;
michael@0 144 #ifdef XP_WIN
michael@0 145 NS_IMETHOD GetPluginPort(HWND *aPort);
michael@0 146 #endif
michael@0 147 #endif
michael@0 148
michael@0 149 //local methods
michael@0 150 nsresult PrepForDrawing(nsIWidget *aWidget);
michael@0 151
michael@0 152 // for a given aRoot, this walks the frame tree looking for the next outFrame
michael@0 153 static nsIObjectFrame* GetNextObjectFrame(nsPresContext* aPresContext,
michael@0 154 nsIFrame* aRoot);
michael@0 155
michael@0 156 // nsIReflowCallback
michael@0 157 virtual bool ReflowFinished() MOZ_OVERRIDE;
michael@0 158 virtual void ReflowCallbackCanceled() MOZ_OVERRIDE;
michael@0 159
michael@0 160 /**
michael@0 161 * Builds either an ImageLayer or a ReadbackLayer, depending on the type
michael@0 162 * of aItem (TYPE_PLUGIN or TYPE_PLUGIN_READBACK respectively).
michael@0 163 */
michael@0 164 already_AddRefed<Layer> BuildLayer(nsDisplayListBuilder* aBuilder,
michael@0 165 LayerManager* aManager,
michael@0 166 nsDisplayItem* aItem,
michael@0 167 const ContainerLayerParameters& aContainerParameters);
michael@0 168
michael@0 169 LayerState GetLayerState(nsDisplayListBuilder* aBuilder,
michael@0 170 LayerManager* aManager);
michael@0 171
michael@0 172 /**
michael@0 173 * Get the rectangle (relative to this frame) which it will paint. Normally
michael@0 174 * the frame's content-box but may be smaller if the plugin is rendering
michael@0 175 * asynchronously and has a different-sized image temporarily.
michael@0 176 */
michael@0 177 nsRect GetPaintedRect(nsDisplayPlugin* aItem);
michael@0 178
michael@0 179 /**
michael@0 180 * If aContent has a nsObjectFrame, then prepare it for a DocShell swap.
michael@0 181 * @see nsSubDocumentFrame::BeginSwapDocShells.
michael@0 182 * There will be a call to EndSwapDocShells after we were moved to the
michael@0 183 * new view tree.
michael@0 184 */
michael@0 185 static void BeginSwapDocShells(nsIContent* aContent, void*);
michael@0 186 /**
michael@0 187 * If aContent has a nsObjectFrame, then set it up after a DocShell swap.
michael@0 188 * @see nsSubDocumentFrame::EndSwapDocShells.
michael@0 189 */
michael@0 190 static void EndSwapDocShells(nsIContent* aContent, void*);
michael@0 191
michael@0 192 nsIWidget* GetWidget() MOZ_OVERRIDE { return mInnerView ? mWidget : nullptr; }
michael@0 193
michael@0 194 /**
michael@0 195 * Adjust the plugin's idea of its size, using aSize as its new size.
michael@0 196 * (aSize must be in twips)
michael@0 197 */
michael@0 198 void FixupWindow(const nsSize& aSize);
michael@0 199
michael@0 200 /*
michael@0 201 * Sets up the plugin window and calls SetWindow on the plugin.
michael@0 202 */
michael@0 203 nsresult CallSetWindow(bool aCheckIsHidden = true);
michael@0 204
michael@0 205 void SetInstanceOwner(nsPluginInstanceOwner* aOwner);
michael@0 206
michael@0 207 protected:
michael@0 208 nsObjectFrame(nsStyleContext* aContext);
michael@0 209 virtual ~nsObjectFrame();
michael@0 210
michael@0 211 // NOTE: This frame class does not inherit from |nsLeafFrame|, so
michael@0 212 // this is not a virtual method implementation.
michael@0 213 void GetDesiredSize(nsPresContext* aPresContext,
michael@0 214 const nsHTMLReflowState& aReflowState,
michael@0 215 nsHTMLReflowMetrics& aDesiredSize);
michael@0 216
michael@0 217 bool IsFocusable(int32_t *aTabIndex = nullptr,
michael@0 218 bool aWithMouse = false) MOZ_OVERRIDE;
michael@0 219
michael@0 220 // check attributes and optionally CSS to see if we should display anything
michael@0 221 bool IsHidden(bool aCheckVisibilityStyle = true) const;
michael@0 222
michael@0 223 bool IsOpaque() const;
michael@0 224 bool IsTransparentMode() const;
michael@0 225 bool IsPaintedByGecko() const;
michael@0 226
michael@0 227 nsIntPoint GetWindowOriginInPixels(bool aWindowless);
michael@0 228
michael@0 229 static void PaintPrintPlugin(nsIFrame* aFrame,
michael@0 230 nsRenderingContext* aRenderingContext,
michael@0 231 const nsRect& aDirtyRect, nsPoint aPt);
michael@0 232 void PrintPlugin(nsRenderingContext& aRenderingContext,
michael@0 233 const nsRect& aDirtyRect);
michael@0 234 void PaintPlugin(nsDisplayListBuilder* aBuilder,
michael@0 235 nsRenderingContext& aRenderingContext,
michael@0 236 const nsRect& aDirtyRect, const nsRect& aPluginRect);
michael@0 237
michael@0 238 void NotifyPluginReflowObservers();
michael@0 239
michael@0 240 friend class nsPluginInstanceOwner;
michael@0 241 friend class nsDisplayPlugin;
michael@0 242 friend class PluginBackgroundSink;
michael@0 243
michael@0 244 private:
michael@0 245 // Registers the plugin for a geometry update, and requests a geometry
michael@0 246 // update. This caches the root pres context in
michael@0 247 // mRootPresContextRegisteredWith, so that we can be sure we unregister
michael@0 248 // from the right root prest context in UnregisterPluginForGeometryUpdates.
michael@0 249 void RegisterPluginForGeometryUpdates();
michael@0 250
michael@0 251 // Unregisters the plugin for geometry updated with the root pres context
michael@0 252 // stored in mRootPresContextRegisteredWith.
michael@0 253 void UnregisterPluginForGeometryUpdates();
michael@0 254
michael@0 255 class PluginEventNotifier : public nsRunnable {
michael@0 256 public:
michael@0 257 PluginEventNotifier(const nsString &aEventType) :
michael@0 258 mEventType(aEventType) {}
michael@0 259
michael@0 260 NS_IMETHOD Run() MOZ_OVERRIDE;
michael@0 261 private:
michael@0 262 nsString mEventType;
michael@0 263 };
michael@0 264
michael@0 265 nsPluginInstanceOwner* mInstanceOwner; // WEAK
michael@0 266 nsView* mInnerView;
michael@0 267 nsCOMPtr<nsIWidget> mWidget;
michael@0 268 nsIntRect mWindowlessRect;
michael@0 269 /**
michael@0 270 * This is owned by the ReadbackLayer for this nsObjectFrame. It is
michael@0 271 * automatically cleared if the PluginBackgroundSink is destroyed.
michael@0 272 */
michael@0 273 PluginBackgroundSink* mBackgroundSink;
michael@0 274
michael@0 275 /**
michael@0 276 * Bounds that we should set the plugin's widget to in the next composite,
michael@0 277 * for plugins with widgets. For plugins without widgets, bounds in device
michael@0 278 * pixels relative to the nearest frame that's a display list reference frame.
michael@0 279 */
michael@0 280 nsIntRect mNextConfigurationBounds;
michael@0 281 /**
michael@0 282 * Clip region that we should set the plugin's widget to
michael@0 283 * in the next composite. Only meaningful for plugins with widgets.
michael@0 284 */
michael@0 285 nsTArray<nsIntRect> mNextConfigurationClipRegion;
michael@0 286
michael@0 287 bool mReflowCallbackPosted;
michael@0 288
michael@0 289 // We keep this reference to ensure we can always unregister the
michael@0 290 // plugins we register on the root PresContext.
michael@0 291 // This is only non-null while we have a plugin registered for geometry
michael@0 292 // updates.
michael@0 293 nsRefPtr<nsRootPresContext> mRootPresContextRegisteredWith;
michael@0 294 };
michael@0 295
michael@0 296 class nsDisplayPlugin : public nsDisplayItem {
michael@0 297 public:
michael@0 298 nsDisplayPlugin(nsDisplayListBuilder* aBuilder, nsIFrame* aFrame)
michael@0 299 : nsDisplayItem(aBuilder, aFrame)
michael@0 300 {
michael@0 301 MOZ_COUNT_CTOR(nsDisplayPlugin);
michael@0 302 aBuilder->SetContainsPluginItem();
michael@0 303 }
michael@0 304 #ifdef NS_BUILD_REFCNT_LOGGING
michael@0 305 virtual ~nsDisplayPlugin() {
michael@0 306 MOZ_COUNT_DTOR(nsDisplayPlugin);
michael@0 307 }
michael@0 308 #endif
michael@0 309
michael@0 310 virtual nsRect GetBounds(nsDisplayListBuilder* aBuilder, bool* aSnap) MOZ_OVERRIDE;
michael@0 311 virtual nsRegion GetOpaqueRegion(nsDisplayListBuilder* aBuilder,
michael@0 312 bool* aSnap) MOZ_OVERRIDE;
michael@0 313 virtual void Paint(nsDisplayListBuilder* aBuilder,
michael@0 314 nsRenderingContext* aCtx) MOZ_OVERRIDE;
michael@0 315 virtual bool ComputeVisibility(nsDisplayListBuilder* aBuilder,
michael@0 316 nsRegion* aVisibleRegion,
michael@0 317 const nsRect& aAllowVisibleRegionExpansion) MOZ_OVERRIDE;
michael@0 318
michael@0 319 NS_DISPLAY_DECL_NAME("Plugin", TYPE_PLUGIN)
michael@0 320
michael@0 321 virtual already_AddRefed<Layer> BuildLayer(nsDisplayListBuilder* aBuilder,
michael@0 322 LayerManager* aManager,
michael@0 323 const ContainerLayerParameters& aContainerParameters) MOZ_OVERRIDE
michael@0 324 {
michael@0 325 return static_cast<nsObjectFrame*>(mFrame)->BuildLayer(aBuilder,
michael@0 326 aManager,
michael@0 327 this,
michael@0 328 aContainerParameters);
michael@0 329 }
michael@0 330
michael@0 331 virtual LayerState GetLayerState(nsDisplayListBuilder* aBuilder,
michael@0 332 LayerManager* aManager,
michael@0 333 const ContainerLayerParameters& aParameters) MOZ_OVERRIDE
michael@0 334 {
michael@0 335 return static_cast<nsObjectFrame*>(mFrame)->GetLayerState(aBuilder,
michael@0 336 aManager);
michael@0 337 }
michael@0 338 };
michael@0 339
michael@0 340 #endif /* nsObjectFrame_h___ */

mercurial