1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/layout/ipc/RenderFrameParent.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,269 @@ 1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- 1.5 + * vim: sw=2 ts=8 et : 1.6 + */ 1.7 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.8 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.9 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.10 + 1.11 +#ifndef mozilla_layout_RenderFrameParent_h 1.12 +#define mozilla_layout_RenderFrameParent_h 1.13 + 1.14 +#include "mozilla/Attributes.h" 1.15 +#include <map> 1.16 + 1.17 +#include "mozilla/layout/PRenderFrameParent.h" 1.18 +#include "mozilla/layers/ShadowLayersManager.h" 1.19 +#include "nsDisplayList.h" 1.20 +#include "RenderFrameUtils.h" 1.21 + 1.22 +class nsContentView; 1.23 +class nsFrameLoader; 1.24 +class nsSubDocumentFrame; 1.25 + 1.26 +namespace mozilla { 1.27 + 1.28 +class InputEvent; 1.29 + 1.30 +namespace layers { 1.31 +class APZCTreeManager; 1.32 +class GestureEventListener; 1.33 +class TargetConfig; 1.34 +class LayerTransactionParent; 1.35 +struct TextureFactoryIdentifier; 1.36 +struct ScrollableLayerGuid; 1.37 +} 1.38 + 1.39 +namespace layout { 1.40 + 1.41 +class RemoteContentController; 1.42 + 1.43 +class RenderFrameParent : public PRenderFrameParent, 1.44 + public mozilla::layers::ShadowLayersManager 1.45 +{ 1.46 + typedef mozilla::layers::FrameMetrics FrameMetrics; 1.47 + typedef mozilla::layers::ContainerLayer ContainerLayer; 1.48 + typedef mozilla::layers::Layer Layer; 1.49 + typedef mozilla::layers::LayerManager LayerManager; 1.50 + typedef mozilla::layers::TargetConfig TargetConfig; 1.51 + typedef mozilla::layers::LayerTransactionParent LayerTransactionParent; 1.52 + typedef mozilla::ContainerLayerParameters ContainerLayerParameters; 1.53 + typedef mozilla::layers::TextureFactoryIdentifier TextureFactoryIdentifier; 1.54 + typedef mozilla::layers::ScrollableLayerGuid ScrollableLayerGuid; 1.55 + typedef mozilla::layers::ZoomConstraints ZoomConstraints; 1.56 + typedef FrameMetrics::ViewID ViewID; 1.57 + 1.58 +public: 1.59 + typedef std::map<ViewID, nsRefPtr<nsContentView> > ViewMap; 1.60 + 1.61 + /* Init should be called immediately after allocation. */ 1.62 + RenderFrameParent(); 1.63 + virtual ~RenderFrameParent(); 1.64 + 1.65 + /** 1.66 + * Select the desired scrolling behavior. If ASYNC_PAN_ZOOM is 1.67 + * chosen, then RenderFrameParent will watch input events and use 1.68 + * them to asynchronously pan and zoom. 1.69 + */ 1.70 + void 1.71 + Init(nsFrameLoader* aFrameLoader, 1.72 + ScrollingBehavior aScrollingBehavior, 1.73 + TextureFactoryIdentifier* aTextureFactoryIdentifier, 1.74 + uint64_t* aId); 1.75 + 1.76 + void Destroy(); 1.77 + 1.78 + /** 1.79 + * Helper functions for getting a non-owning reference to a scrollable. 1.80 + * @param aId The ID of the frame. 1.81 + */ 1.82 + nsContentView* GetContentView(ViewID aId); 1.83 + nsContentView* GetRootContentView(); 1.84 + 1.85 + void ContentViewScaleChanged(nsContentView* aView); 1.86 + 1.87 + virtual void ShadowLayersUpdated(LayerTransactionParent* aLayerTree, 1.88 + const TargetConfig& aTargetConfig, 1.89 + bool aIsFirstPaint, 1.90 + bool aScheduleComposite) MOZ_OVERRIDE; 1.91 + 1.92 + void BuildDisplayList(nsDisplayListBuilder* aBuilder, 1.93 + nsSubDocumentFrame* aFrame, 1.94 + const nsRect& aDirtyRect, 1.95 + const nsDisplayListSet& aLists); 1.96 + 1.97 + already_AddRefed<Layer> BuildLayer(nsDisplayListBuilder* aBuilder, 1.98 + nsIFrame* aFrame, 1.99 + LayerManager* aManager, 1.100 + const nsIntRect& aVisibleRect, 1.101 + nsDisplayItem* aItem, 1.102 + const ContainerLayerParameters& aContainerParameters); 1.103 + 1.104 + void OwnerContentChanged(nsIContent* aContent); 1.105 + 1.106 + void SetBackgroundColor(nscolor aColor) { mBackgroundColor = gfxRGBA(aColor); }; 1.107 + 1.108 + /** 1.109 + * Notify the APZ code of an input event, and get back the untransformed event. 1.110 + * @param aEvent the input event; this is modified in-place so that the async 1.111 + * transforms are unapplied. This can be passed to Gecko for hit testing 1.112 + * and normal event dispatch. 1.113 + * @param aOutTargetGuid An out-parameter that will contain the identifier 1.114 + * of the APZC instance that handled the event, if one was found. This 1.115 + * argument may be null. 1.116 + */ 1.117 + void NotifyInputEvent(WidgetInputEvent& aEvent, 1.118 + ScrollableLayerGuid* aOutTargetGuid); 1.119 + 1.120 + void ZoomToRect(uint32_t aPresShellId, ViewID aViewId, const CSSRect& aRect); 1.121 + 1.122 + void ContentReceivedTouch(const ScrollableLayerGuid& aGuid, 1.123 + bool aPreventDefault); 1.124 + 1.125 + void UpdateZoomConstraints(uint32_t aPresShellId, 1.126 + ViewID aViewId, 1.127 + bool aIsRoot, 1.128 + const ZoomConstraints& aConstraints); 1.129 + 1.130 + bool HitTest(const nsRect& aRect); 1.131 + 1.132 +protected: 1.133 + void ActorDestroy(ActorDestroyReason why) MOZ_OVERRIDE; 1.134 + 1.135 + virtual bool RecvNotifyCompositorTransaction() MOZ_OVERRIDE; 1.136 + 1.137 + virtual bool RecvUpdateHitRegion(const nsRegion& aRegion) MOZ_OVERRIDE; 1.138 + 1.139 + virtual PLayerTransactionParent* AllocPLayerTransactionParent() MOZ_OVERRIDE; 1.140 + virtual bool DeallocPLayerTransactionParent(PLayerTransactionParent* aLayers) MOZ_OVERRIDE; 1.141 + 1.142 +private: 1.143 + void BuildViewMap(); 1.144 + void TriggerRepaint(); 1.145 + void DispatchEventForPanZoomController(const InputEvent& aEvent); 1.146 + 1.147 + LayerTransactionParent* GetShadowLayers() const; 1.148 + uint64_t GetLayerTreeId() const; 1.149 + Layer* GetRootLayer() const; 1.150 + 1.151 + // When our child frame is pushing transactions directly to the 1.152 + // compositor, this is the ID of its layer tree in the compositor's 1.153 + // context. 1.154 + uint64_t mLayersId; 1.155 + 1.156 + nsRefPtr<nsFrameLoader> mFrameLoader; 1.157 + nsRefPtr<ContainerLayer> mContainer; 1.158 + // When our scrolling behavior is ASYNC_PAN_ZOOM, we have a nonnull 1.159 + // APZCTreeManager. It's used to manipulate the shadow layer tree 1.160 + // on the compositor thread. 1.161 + nsRefPtr<layers::APZCTreeManager> mApzcTreeManager; 1.162 + nsRefPtr<RemoteContentController> mContentController; 1.163 + 1.164 + layers::APZCTreeManager* GetApzcTreeManager(); 1.165 + 1.166 + // This contains the views for all the scrollable frames currently in the 1.167 + // painted region of our remote content. 1.168 + ViewMap mContentViews; 1.169 + 1.170 + // True after Destroy() has been called, which is triggered 1.171 + // originally by nsFrameLoader::Destroy(). After this point, we can 1.172 + // no longer safely ask the frame loader to find its nearest layer 1.173 + // manager, because it may have been disconnected from the DOM. 1.174 + // It's still OK to *tell* the frame loader that we've painted after 1.175 + // it's destroyed; it'll just ignore us, and we won't be able to 1.176 + // find an nsIFrame to invalidate. See ShadowLayersUpdated(). 1.177 + // 1.178 + // Prefer the extra bit of state to null'ing out mFrameLoader in 1.179 + // Destroy() so that less code needs to be special-cased for after 1.180 + // Destroy(). 1.181 + // 1.182 + // It's possible for mFrameLoader==null and 1.183 + // mFrameLoaderDestroyed==false. 1.184 + bool mFrameLoaderDestroyed; 1.185 + // this is gfxRGBA because that's what ColorLayer wants. 1.186 + gfxRGBA mBackgroundColor; 1.187 + 1.188 + nsRegion mTouchRegion; 1.189 +}; 1.190 + 1.191 +} // namespace layout 1.192 +} // namespace mozilla 1.193 + 1.194 +/** 1.195 + * A DisplayRemote exists solely to graft a child process's shadow 1.196 + * layer tree (for a given RenderFrameParent) into its parent 1.197 + * process's layer tree. 1.198 + */ 1.199 +class nsDisplayRemote : public nsDisplayItem 1.200 +{ 1.201 + typedef mozilla::layout::RenderFrameParent RenderFrameParent; 1.202 + 1.203 +public: 1.204 + nsDisplayRemote(nsDisplayListBuilder* aBuilder, nsIFrame* aFrame, 1.205 + RenderFrameParent* aRemoteFrame) 1.206 + : nsDisplayItem(aBuilder, aFrame) 1.207 + , mRemoteFrame(aRemoteFrame) 1.208 + {} 1.209 + 1.210 + virtual LayerState GetLayerState(nsDisplayListBuilder* aBuilder, 1.211 + LayerManager* aManager, 1.212 + const ContainerLayerParameters& aParameters) MOZ_OVERRIDE 1.213 + { return mozilla::LAYER_ACTIVE_FORCE; } 1.214 + 1.215 + virtual already_AddRefed<Layer> 1.216 + BuildLayer(nsDisplayListBuilder* aBuilder, LayerManager* aManager, 1.217 + const ContainerLayerParameters& aContainerParameters) MOZ_OVERRIDE; 1.218 + 1.219 + void HitTest(nsDisplayListBuilder* aBuilder, const nsRect& aRect, 1.220 + HitTestState* aState, nsTArray<nsIFrame*> *aOutFrames) MOZ_OVERRIDE; 1.221 + 1.222 + NS_DISPLAY_DECL_NAME("Remote", TYPE_REMOTE) 1.223 + 1.224 +private: 1.225 + RenderFrameParent* mRemoteFrame; 1.226 +}; 1.227 + 1.228 +/** 1.229 + * nsDisplayRemoteShadow is a way of adding display items for frames in a 1.230 + * separate process, for hit testing only. After being processed, the hit 1.231 + * test state will contain IDs for any remote frames that were hit. 1.232 + * 1.233 + * The frame should be its respective render frame parent. 1.234 + */ 1.235 +class nsDisplayRemoteShadow : public nsDisplayItem 1.236 +{ 1.237 + typedef mozilla::layout::RenderFrameParent RenderFrameParent; 1.238 + typedef mozilla::layers::FrameMetrics::ViewID ViewID; 1.239 + 1.240 +public: 1.241 + nsDisplayRemoteShadow(nsDisplayListBuilder* aBuilder, 1.242 + nsIFrame* aFrame, 1.243 + nsRect aRect, 1.244 + ViewID aId) 1.245 + : nsDisplayItem(aBuilder, aFrame) 1.246 + , mRect(aRect) 1.247 + , mId(aId) 1.248 + {} 1.249 + 1.250 + nsRect GetBounds(nsDisplayListBuilder* aBuilder, bool* aSnap) MOZ_OVERRIDE 1.251 + { 1.252 + *aSnap = false; 1.253 + return mRect; 1.254 + } 1.255 + 1.256 + virtual uint32_t GetPerFrameKey() MOZ_OVERRIDE 1.257 + { 1.258 + NS_ABORT(); 1.259 + return 0; 1.260 + } 1.261 + 1.262 + void HitTest(nsDisplayListBuilder* aBuilder, const nsRect& aRect, 1.263 + HitTestState* aState, nsTArray<nsIFrame*> *aOutFrames) MOZ_OVERRIDE; 1.264 + 1.265 + NS_DISPLAY_DECL_NAME("Remote-Shadow", TYPE_REMOTE_SHADOW) 1.266 + 1.267 +private: 1.268 + nsRect mRect; 1.269 + ViewID mId; 1.270 +}; 1.271 + 1.272 +#endif // mozilla_layout_RenderFrameParent_h