michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- michael@0: * vim: sw=2 ts=8 et : michael@0: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef mozilla_layout_RenderFrameParent_h michael@0: #define mozilla_layout_RenderFrameParent_h michael@0: michael@0: #include "mozilla/Attributes.h" michael@0: #include michael@0: michael@0: #include "mozilla/layout/PRenderFrameParent.h" michael@0: #include "mozilla/layers/ShadowLayersManager.h" michael@0: #include "nsDisplayList.h" michael@0: #include "RenderFrameUtils.h" michael@0: michael@0: class nsContentView; michael@0: class nsFrameLoader; michael@0: class nsSubDocumentFrame; michael@0: michael@0: namespace mozilla { michael@0: michael@0: class InputEvent; michael@0: michael@0: namespace layers { michael@0: class APZCTreeManager; michael@0: class GestureEventListener; michael@0: class TargetConfig; michael@0: class LayerTransactionParent; michael@0: struct TextureFactoryIdentifier; michael@0: struct ScrollableLayerGuid; michael@0: } michael@0: michael@0: namespace layout { michael@0: michael@0: class RemoteContentController; michael@0: michael@0: class RenderFrameParent : public PRenderFrameParent, michael@0: public mozilla::layers::ShadowLayersManager michael@0: { michael@0: typedef mozilla::layers::FrameMetrics FrameMetrics; michael@0: typedef mozilla::layers::ContainerLayer ContainerLayer; michael@0: typedef mozilla::layers::Layer Layer; michael@0: typedef mozilla::layers::LayerManager LayerManager; michael@0: typedef mozilla::layers::TargetConfig TargetConfig; michael@0: typedef mozilla::layers::LayerTransactionParent LayerTransactionParent; michael@0: typedef mozilla::ContainerLayerParameters ContainerLayerParameters; michael@0: typedef mozilla::layers::TextureFactoryIdentifier TextureFactoryIdentifier; michael@0: typedef mozilla::layers::ScrollableLayerGuid ScrollableLayerGuid; michael@0: typedef mozilla::layers::ZoomConstraints ZoomConstraints; michael@0: typedef FrameMetrics::ViewID ViewID; michael@0: michael@0: public: michael@0: typedef std::map > ViewMap; michael@0: michael@0: /* Init should be called immediately after allocation. */ michael@0: RenderFrameParent(); michael@0: virtual ~RenderFrameParent(); michael@0: michael@0: /** michael@0: * Select the desired scrolling behavior. If ASYNC_PAN_ZOOM is michael@0: * chosen, then RenderFrameParent will watch input events and use michael@0: * them to asynchronously pan and zoom. michael@0: */ michael@0: void michael@0: Init(nsFrameLoader* aFrameLoader, michael@0: ScrollingBehavior aScrollingBehavior, michael@0: TextureFactoryIdentifier* aTextureFactoryIdentifier, michael@0: uint64_t* aId); michael@0: michael@0: void Destroy(); michael@0: michael@0: /** michael@0: * Helper functions for getting a non-owning reference to a scrollable. michael@0: * @param aId The ID of the frame. michael@0: */ michael@0: nsContentView* GetContentView(ViewID aId); michael@0: nsContentView* GetRootContentView(); michael@0: michael@0: void ContentViewScaleChanged(nsContentView* aView); michael@0: michael@0: virtual void ShadowLayersUpdated(LayerTransactionParent* aLayerTree, michael@0: const TargetConfig& aTargetConfig, michael@0: bool aIsFirstPaint, michael@0: bool aScheduleComposite) MOZ_OVERRIDE; michael@0: michael@0: void BuildDisplayList(nsDisplayListBuilder* aBuilder, michael@0: nsSubDocumentFrame* aFrame, michael@0: const nsRect& aDirtyRect, michael@0: const nsDisplayListSet& aLists); michael@0: michael@0: already_AddRefed BuildLayer(nsDisplayListBuilder* aBuilder, michael@0: nsIFrame* aFrame, michael@0: LayerManager* aManager, michael@0: const nsIntRect& aVisibleRect, michael@0: nsDisplayItem* aItem, michael@0: const ContainerLayerParameters& aContainerParameters); michael@0: michael@0: void OwnerContentChanged(nsIContent* aContent); michael@0: michael@0: void SetBackgroundColor(nscolor aColor) { mBackgroundColor = gfxRGBA(aColor); }; michael@0: michael@0: /** michael@0: * Notify the APZ code of an input event, and get back the untransformed event. michael@0: * @param aEvent the input event; this is modified in-place so that the async michael@0: * transforms are unapplied. This can be passed to Gecko for hit testing michael@0: * and normal event dispatch. michael@0: * @param aOutTargetGuid An out-parameter that will contain the identifier michael@0: * of the APZC instance that handled the event, if one was found. This michael@0: * argument may be null. michael@0: */ michael@0: void NotifyInputEvent(WidgetInputEvent& aEvent, michael@0: ScrollableLayerGuid* aOutTargetGuid); michael@0: michael@0: void ZoomToRect(uint32_t aPresShellId, ViewID aViewId, const CSSRect& aRect); michael@0: michael@0: void ContentReceivedTouch(const ScrollableLayerGuid& aGuid, michael@0: bool aPreventDefault); michael@0: michael@0: void UpdateZoomConstraints(uint32_t aPresShellId, michael@0: ViewID aViewId, michael@0: bool aIsRoot, michael@0: const ZoomConstraints& aConstraints); michael@0: michael@0: bool HitTest(const nsRect& aRect); michael@0: michael@0: protected: michael@0: void ActorDestroy(ActorDestroyReason why) MOZ_OVERRIDE; michael@0: michael@0: virtual bool RecvNotifyCompositorTransaction() MOZ_OVERRIDE; michael@0: michael@0: virtual bool RecvUpdateHitRegion(const nsRegion& aRegion) MOZ_OVERRIDE; michael@0: michael@0: virtual PLayerTransactionParent* AllocPLayerTransactionParent() MOZ_OVERRIDE; michael@0: virtual bool DeallocPLayerTransactionParent(PLayerTransactionParent* aLayers) MOZ_OVERRIDE; michael@0: michael@0: private: michael@0: void BuildViewMap(); michael@0: void TriggerRepaint(); michael@0: void DispatchEventForPanZoomController(const InputEvent& aEvent); michael@0: michael@0: LayerTransactionParent* GetShadowLayers() const; michael@0: uint64_t GetLayerTreeId() const; michael@0: Layer* GetRootLayer() const; michael@0: michael@0: // When our child frame is pushing transactions directly to the michael@0: // compositor, this is the ID of its layer tree in the compositor's michael@0: // context. michael@0: uint64_t mLayersId; michael@0: michael@0: nsRefPtr mFrameLoader; michael@0: nsRefPtr mContainer; michael@0: // When our scrolling behavior is ASYNC_PAN_ZOOM, we have a nonnull michael@0: // APZCTreeManager. It's used to manipulate the shadow layer tree michael@0: // on the compositor thread. michael@0: nsRefPtr mApzcTreeManager; michael@0: nsRefPtr mContentController; michael@0: michael@0: layers::APZCTreeManager* GetApzcTreeManager(); michael@0: michael@0: // This contains the views for all the scrollable frames currently in the michael@0: // painted region of our remote content. michael@0: ViewMap mContentViews; michael@0: michael@0: // True after Destroy() has been called, which is triggered michael@0: // originally by nsFrameLoader::Destroy(). After this point, we can michael@0: // no longer safely ask the frame loader to find its nearest layer michael@0: // manager, because it may have been disconnected from the DOM. michael@0: // It's still OK to *tell* the frame loader that we've painted after michael@0: // it's destroyed; it'll just ignore us, and we won't be able to michael@0: // find an nsIFrame to invalidate. See ShadowLayersUpdated(). michael@0: // michael@0: // Prefer the extra bit of state to null'ing out mFrameLoader in michael@0: // Destroy() so that less code needs to be special-cased for after michael@0: // Destroy(). michael@0: // michael@0: // It's possible for mFrameLoader==null and michael@0: // mFrameLoaderDestroyed==false. michael@0: bool mFrameLoaderDestroyed; michael@0: // this is gfxRGBA because that's what ColorLayer wants. michael@0: gfxRGBA mBackgroundColor; michael@0: michael@0: nsRegion mTouchRegion; michael@0: }; michael@0: michael@0: } // namespace layout michael@0: } // namespace mozilla michael@0: michael@0: /** michael@0: * A DisplayRemote exists solely to graft a child process's shadow michael@0: * layer tree (for a given RenderFrameParent) into its parent michael@0: * process's layer tree. michael@0: */ michael@0: class nsDisplayRemote : public nsDisplayItem michael@0: { michael@0: typedef mozilla::layout::RenderFrameParent RenderFrameParent; michael@0: michael@0: public: michael@0: nsDisplayRemote(nsDisplayListBuilder* aBuilder, nsIFrame* aFrame, michael@0: RenderFrameParent* aRemoteFrame) michael@0: : nsDisplayItem(aBuilder, aFrame) michael@0: , mRemoteFrame(aRemoteFrame) michael@0: {} michael@0: michael@0: virtual LayerState GetLayerState(nsDisplayListBuilder* aBuilder, michael@0: LayerManager* aManager, michael@0: const ContainerLayerParameters& aParameters) MOZ_OVERRIDE michael@0: { return mozilla::LAYER_ACTIVE_FORCE; } michael@0: michael@0: virtual already_AddRefed michael@0: BuildLayer(nsDisplayListBuilder* aBuilder, LayerManager* aManager, michael@0: const ContainerLayerParameters& aContainerParameters) MOZ_OVERRIDE; michael@0: michael@0: void HitTest(nsDisplayListBuilder* aBuilder, const nsRect& aRect, michael@0: HitTestState* aState, nsTArray *aOutFrames) MOZ_OVERRIDE; michael@0: michael@0: NS_DISPLAY_DECL_NAME("Remote", TYPE_REMOTE) michael@0: michael@0: private: michael@0: RenderFrameParent* mRemoteFrame; michael@0: }; michael@0: michael@0: /** michael@0: * nsDisplayRemoteShadow is a way of adding display items for frames in a michael@0: * separate process, for hit testing only. After being processed, the hit michael@0: * test state will contain IDs for any remote frames that were hit. michael@0: * michael@0: * The frame should be its respective render frame parent. michael@0: */ michael@0: class nsDisplayRemoteShadow : public nsDisplayItem michael@0: { michael@0: typedef mozilla::layout::RenderFrameParent RenderFrameParent; michael@0: typedef mozilla::layers::FrameMetrics::ViewID ViewID; michael@0: michael@0: public: michael@0: nsDisplayRemoteShadow(nsDisplayListBuilder* aBuilder, michael@0: nsIFrame* aFrame, michael@0: nsRect aRect, michael@0: ViewID aId) michael@0: : nsDisplayItem(aBuilder, aFrame) michael@0: , mRect(aRect) michael@0: , mId(aId) michael@0: {} michael@0: michael@0: nsRect GetBounds(nsDisplayListBuilder* aBuilder, bool* aSnap) MOZ_OVERRIDE michael@0: { michael@0: *aSnap = false; michael@0: return mRect; michael@0: } michael@0: michael@0: virtual uint32_t GetPerFrameKey() MOZ_OVERRIDE michael@0: { michael@0: NS_ABORT(); michael@0: return 0; michael@0: } michael@0: michael@0: void HitTest(nsDisplayListBuilder* aBuilder, const nsRect& aRect, michael@0: HitTestState* aState, nsTArray *aOutFrames) MOZ_OVERRIDE; michael@0: michael@0: NS_DISPLAY_DECL_NAME("Remote-Shadow", TYPE_REMOTE_SHADOW) michael@0: michael@0: private: michael@0: nsRect mRect; michael@0: ViewID mId; michael@0: }; michael@0: michael@0: #endif // mozilla_layout_RenderFrameParent_h