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