|
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
|
2 * vim: sw=2 ts=8 et : |
|
3 */ |
|
4 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
5 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
7 |
|
8 #ifndef mozilla_layout_RenderFrameParent_h |
|
9 #define mozilla_layout_RenderFrameParent_h |
|
10 |
|
11 #include "mozilla/Attributes.h" |
|
12 #include <map> |
|
13 |
|
14 #include "mozilla/layout/PRenderFrameParent.h" |
|
15 #include "mozilla/layers/ShadowLayersManager.h" |
|
16 #include "nsDisplayList.h" |
|
17 #include "RenderFrameUtils.h" |
|
18 |
|
19 class nsContentView; |
|
20 class nsFrameLoader; |
|
21 class nsSubDocumentFrame; |
|
22 |
|
23 namespace mozilla { |
|
24 |
|
25 class InputEvent; |
|
26 |
|
27 namespace layers { |
|
28 class APZCTreeManager; |
|
29 class GestureEventListener; |
|
30 class TargetConfig; |
|
31 class LayerTransactionParent; |
|
32 struct TextureFactoryIdentifier; |
|
33 struct ScrollableLayerGuid; |
|
34 } |
|
35 |
|
36 namespace layout { |
|
37 |
|
38 class RemoteContentController; |
|
39 |
|
40 class RenderFrameParent : public PRenderFrameParent, |
|
41 public mozilla::layers::ShadowLayersManager |
|
42 { |
|
43 typedef mozilla::layers::FrameMetrics FrameMetrics; |
|
44 typedef mozilla::layers::ContainerLayer ContainerLayer; |
|
45 typedef mozilla::layers::Layer Layer; |
|
46 typedef mozilla::layers::LayerManager LayerManager; |
|
47 typedef mozilla::layers::TargetConfig TargetConfig; |
|
48 typedef mozilla::layers::LayerTransactionParent LayerTransactionParent; |
|
49 typedef mozilla::ContainerLayerParameters ContainerLayerParameters; |
|
50 typedef mozilla::layers::TextureFactoryIdentifier TextureFactoryIdentifier; |
|
51 typedef mozilla::layers::ScrollableLayerGuid ScrollableLayerGuid; |
|
52 typedef mozilla::layers::ZoomConstraints ZoomConstraints; |
|
53 typedef FrameMetrics::ViewID ViewID; |
|
54 |
|
55 public: |
|
56 typedef std::map<ViewID, nsRefPtr<nsContentView> > ViewMap; |
|
57 |
|
58 /* Init should be called immediately after allocation. */ |
|
59 RenderFrameParent(); |
|
60 virtual ~RenderFrameParent(); |
|
61 |
|
62 /** |
|
63 * Select the desired scrolling behavior. If ASYNC_PAN_ZOOM is |
|
64 * chosen, then RenderFrameParent will watch input events and use |
|
65 * them to asynchronously pan and zoom. |
|
66 */ |
|
67 void |
|
68 Init(nsFrameLoader* aFrameLoader, |
|
69 ScrollingBehavior aScrollingBehavior, |
|
70 TextureFactoryIdentifier* aTextureFactoryIdentifier, |
|
71 uint64_t* aId); |
|
72 |
|
73 void Destroy(); |
|
74 |
|
75 /** |
|
76 * Helper functions for getting a non-owning reference to a scrollable. |
|
77 * @param aId The ID of the frame. |
|
78 */ |
|
79 nsContentView* GetContentView(ViewID aId); |
|
80 nsContentView* GetRootContentView(); |
|
81 |
|
82 void ContentViewScaleChanged(nsContentView* aView); |
|
83 |
|
84 virtual void ShadowLayersUpdated(LayerTransactionParent* aLayerTree, |
|
85 const TargetConfig& aTargetConfig, |
|
86 bool aIsFirstPaint, |
|
87 bool aScheduleComposite) MOZ_OVERRIDE; |
|
88 |
|
89 void BuildDisplayList(nsDisplayListBuilder* aBuilder, |
|
90 nsSubDocumentFrame* aFrame, |
|
91 const nsRect& aDirtyRect, |
|
92 const nsDisplayListSet& aLists); |
|
93 |
|
94 already_AddRefed<Layer> BuildLayer(nsDisplayListBuilder* aBuilder, |
|
95 nsIFrame* aFrame, |
|
96 LayerManager* aManager, |
|
97 const nsIntRect& aVisibleRect, |
|
98 nsDisplayItem* aItem, |
|
99 const ContainerLayerParameters& aContainerParameters); |
|
100 |
|
101 void OwnerContentChanged(nsIContent* aContent); |
|
102 |
|
103 void SetBackgroundColor(nscolor aColor) { mBackgroundColor = gfxRGBA(aColor); }; |
|
104 |
|
105 /** |
|
106 * Notify the APZ code of an input event, and get back the untransformed event. |
|
107 * @param aEvent the input event; this is modified in-place so that the async |
|
108 * transforms are unapplied. This can be passed to Gecko for hit testing |
|
109 * and normal event dispatch. |
|
110 * @param aOutTargetGuid An out-parameter that will contain the identifier |
|
111 * of the APZC instance that handled the event, if one was found. This |
|
112 * argument may be null. |
|
113 */ |
|
114 void NotifyInputEvent(WidgetInputEvent& aEvent, |
|
115 ScrollableLayerGuid* aOutTargetGuid); |
|
116 |
|
117 void ZoomToRect(uint32_t aPresShellId, ViewID aViewId, const CSSRect& aRect); |
|
118 |
|
119 void ContentReceivedTouch(const ScrollableLayerGuid& aGuid, |
|
120 bool aPreventDefault); |
|
121 |
|
122 void UpdateZoomConstraints(uint32_t aPresShellId, |
|
123 ViewID aViewId, |
|
124 bool aIsRoot, |
|
125 const ZoomConstraints& aConstraints); |
|
126 |
|
127 bool HitTest(const nsRect& aRect); |
|
128 |
|
129 protected: |
|
130 void ActorDestroy(ActorDestroyReason why) MOZ_OVERRIDE; |
|
131 |
|
132 virtual bool RecvNotifyCompositorTransaction() MOZ_OVERRIDE; |
|
133 |
|
134 virtual bool RecvUpdateHitRegion(const nsRegion& aRegion) MOZ_OVERRIDE; |
|
135 |
|
136 virtual PLayerTransactionParent* AllocPLayerTransactionParent() MOZ_OVERRIDE; |
|
137 virtual bool DeallocPLayerTransactionParent(PLayerTransactionParent* aLayers) MOZ_OVERRIDE; |
|
138 |
|
139 private: |
|
140 void BuildViewMap(); |
|
141 void TriggerRepaint(); |
|
142 void DispatchEventForPanZoomController(const InputEvent& aEvent); |
|
143 |
|
144 LayerTransactionParent* GetShadowLayers() const; |
|
145 uint64_t GetLayerTreeId() const; |
|
146 Layer* GetRootLayer() const; |
|
147 |
|
148 // When our child frame is pushing transactions directly to the |
|
149 // compositor, this is the ID of its layer tree in the compositor's |
|
150 // context. |
|
151 uint64_t mLayersId; |
|
152 |
|
153 nsRefPtr<nsFrameLoader> mFrameLoader; |
|
154 nsRefPtr<ContainerLayer> mContainer; |
|
155 // When our scrolling behavior is ASYNC_PAN_ZOOM, we have a nonnull |
|
156 // APZCTreeManager. It's used to manipulate the shadow layer tree |
|
157 // on the compositor thread. |
|
158 nsRefPtr<layers::APZCTreeManager> mApzcTreeManager; |
|
159 nsRefPtr<RemoteContentController> mContentController; |
|
160 |
|
161 layers::APZCTreeManager* GetApzcTreeManager(); |
|
162 |
|
163 // This contains the views for all the scrollable frames currently in the |
|
164 // painted region of our remote content. |
|
165 ViewMap mContentViews; |
|
166 |
|
167 // True after Destroy() has been called, which is triggered |
|
168 // originally by nsFrameLoader::Destroy(). After this point, we can |
|
169 // no longer safely ask the frame loader to find its nearest layer |
|
170 // manager, because it may have been disconnected from the DOM. |
|
171 // It's still OK to *tell* the frame loader that we've painted after |
|
172 // it's destroyed; it'll just ignore us, and we won't be able to |
|
173 // find an nsIFrame to invalidate. See ShadowLayersUpdated(). |
|
174 // |
|
175 // Prefer the extra bit of state to null'ing out mFrameLoader in |
|
176 // Destroy() so that less code needs to be special-cased for after |
|
177 // Destroy(). |
|
178 // |
|
179 // It's possible for mFrameLoader==null and |
|
180 // mFrameLoaderDestroyed==false. |
|
181 bool mFrameLoaderDestroyed; |
|
182 // this is gfxRGBA because that's what ColorLayer wants. |
|
183 gfxRGBA mBackgroundColor; |
|
184 |
|
185 nsRegion mTouchRegion; |
|
186 }; |
|
187 |
|
188 } // namespace layout |
|
189 } // namespace mozilla |
|
190 |
|
191 /** |
|
192 * A DisplayRemote exists solely to graft a child process's shadow |
|
193 * layer tree (for a given RenderFrameParent) into its parent |
|
194 * process's layer tree. |
|
195 */ |
|
196 class nsDisplayRemote : public nsDisplayItem |
|
197 { |
|
198 typedef mozilla::layout::RenderFrameParent RenderFrameParent; |
|
199 |
|
200 public: |
|
201 nsDisplayRemote(nsDisplayListBuilder* aBuilder, nsIFrame* aFrame, |
|
202 RenderFrameParent* aRemoteFrame) |
|
203 : nsDisplayItem(aBuilder, aFrame) |
|
204 , mRemoteFrame(aRemoteFrame) |
|
205 {} |
|
206 |
|
207 virtual LayerState GetLayerState(nsDisplayListBuilder* aBuilder, |
|
208 LayerManager* aManager, |
|
209 const ContainerLayerParameters& aParameters) MOZ_OVERRIDE |
|
210 { return mozilla::LAYER_ACTIVE_FORCE; } |
|
211 |
|
212 virtual already_AddRefed<Layer> |
|
213 BuildLayer(nsDisplayListBuilder* aBuilder, LayerManager* aManager, |
|
214 const ContainerLayerParameters& aContainerParameters) MOZ_OVERRIDE; |
|
215 |
|
216 void HitTest(nsDisplayListBuilder* aBuilder, const nsRect& aRect, |
|
217 HitTestState* aState, nsTArray<nsIFrame*> *aOutFrames) MOZ_OVERRIDE; |
|
218 |
|
219 NS_DISPLAY_DECL_NAME("Remote", TYPE_REMOTE) |
|
220 |
|
221 private: |
|
222 RenderFrameParent* mRemoteFrame; |
|
223 }; |
|
224 |
|
225 /** |
|
226 * nsDisplayRemoteShadow is a way of adding display items for frames in a |
|
227 * separate process, for hit testing only. After being processed, the hit |
|
228 * test state will contain IDs for any remote frames that were hit. |
|
229 * |
|
230 * The frame should be its respective render frame parent. |
|
231 */ |
|
232 class nsDisplayRemoteShadow : public nsDisplayItem |
|
233 { |
|
234 typedef mozilla::layout::RenderFrameParent RenderFrameParent; |
|
235 typedef mozilla::layers::FrameMetrics::ViewID ViewID; |
|
236 |
|
237 public: |
|
238 nsDisplayRemoteShadow(nsDisplayListBuilder* aBuilder, |
|
239 nsIFrame* aFrame, |
|
240 nsRect aRect, |
|
241 ViewID aId) |
|
242 : nsDisplayItem(aBuilder, aFrame) |
|
243 , mRect(aRect) |
|
244 , mId(aId) |
|
245 {} |
|
246 |
|
247 nsRect GetBounds(nsDisplayListBuilder* aBuilder, bool* aSnap) MOZ_OVERRIDE |
|
248 { |
|
249 *aSnap = false; |
|
250 return mRect; |
|
251 } |
|
252 |
|
253 virtual uint32_t GetPerFrameKey() MOZ_OVERRIDE |
|
254 { |
|
255 NS_ABORT(); |
|
256 return 0; |
|
257 } |
|
258 |
|
259 void HitTest(nsDisplayListBuilder* aBuilder, const nsRect& aRect, |
|
260 HitTestState* aState, nsTArray<nsIFrame*> *aOutFrames) MOZ_OVERRIDE; |
|
261 |
|
262 NS_DISPLAY_DECL_NAME("Remote-Shadow", TYPE_REMOTE_SHADOW) |
|
263 |
|
264 private: |
|
265 nsRect mRect; |
|
266 ViewID mId; |
|
267 }; |
|
268 |
|
269 #endif // mozilla_layout_RenderFrameParent_h |