1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4  * License, v. 2.0. If a copy of the MPL was not distributed with this
5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 
7 #ifndef mozilla_layers_ChromeProcessController_h
8 #define mozilla_layers_ChromeProcessController_h
9 
10 #include "mozilla/layers/GeckoContentController.h"
11 #include "nsCOMPtr.h"
12 #include "mozilla/RefPtr.h"
13 #include "mozilla/layers/MatrixMessage.h"
14 
15 class nsIDOMWindowUtils;
16 class nsISerialEventTarget;
17 class nsIWidget;
18 
19 namespace mozilla {
20 class PresShell;
21 namespace dom {
22 class Document;
23 }
24 
25 namespace layers {
26 
27 class IAPZCTreeManager;
28 class APZEventState;
29 
30 /**
31  * ChromeProcessController is a GeckoContentController attached to the root of
32  * a compositor's layer tree. It's used directly by APZ by default, and remoted
33  * using PAPZ if there is a gpu process.
34  *
35  * If ChromeProcessController needs to implement a new method on
36  * GeckoContentController PAPZ, APZChild, and RemoteContentController must be
37  * updated to handle it.
38  */
39 class ChromeProcessController : public mozilla::layers::GeckoContentController {
40  protected:
41   typedef mozilla::layers::FrameMetrics FrameMetrics;
42   typedef mozilla::layers::ScrollableLayerGuid ScrollableLayerGuid;
43 
44  public:
45   explicit ChromeProcessController(nsIWidget* aWidget,
46                                    APZEventState* aAPZEventState,
47                                    IAPZCTreeManager* aAPZCTreeManager);
48   virtual ~ChromeProcessController();
49   void Destroy() override;
50 
51   // GeckoContentController interface
52   void NotifyLayerTransforms(nsTArray<MatrixMessage>&& aTransforms) override;
53   void RequestContentRepaint(const RepaintRequest& aRequest) override;
54   bool IsRepaintThread() override;
55   void DispatchToRepaintThread(already_AddRefed<Runnable> aTask) override;
56   MOZ_CAN_RUN_SCRIPT
57   void HandleTap(TapType aType, const mozilla::LayoutDevicePoint& aPoint,
58                  Modifiers aModifiers, const ScrollableLayerGuid& aGuid,
59                  uint64_t aInputBlockId) override;
60   void NotifyPinchGesture(PinchGestureInput::PinchGestureType aType,
61                           const ScrollableLayerGuid& aGuid,
62                           const LayoutDevicePoint& aFocusPoint,
63                           LayoutDeviceCoord aSpanChange,
64                           Modifiers aModifiers) override;
65   void NotifyAPZStateChange(const ScrollableLayerGuid& aGuid,
66                             APZStateChange aChange, int aArg) override;
67   void NotifyMozMouseScrollEvent(const ScrollableLayerGuid::ViewID& aScrollId,
68                                  const nsString& aEvent) override;
69   void NotifyFlushComplete() override;
70   void NotifyAsyncScrollbarDragInitiated(
71       uint64_t aDragBlockId, const ScrollableLayerGuid::ViewID& aScrollId,
72       ScrollDirection aDirection) override;
73   void NotifyAsyncScrollbarDragRejected(
74       const ScrollableLayerGuid::ViewID& aScrollId) override;
75   void NotifyAsyncAutoscrollRejected(
76       const ScrollableLayerGuid::ViewID& aScrollId) override;
77   void CancelAutoscroll(const ScrollableLayerGuid& aGuid) override;
78 
GetTopLevelPresShell()79   PresShell* GetTopLevelPresShell() const override { return GetPresShell(); }
80 
81  private:
82   nsCOMPtr<nsIWidget> mWidget;
83   RefPtr<APZEventState> mAPZEventState;
84   RefPtr<IAPZCTreeManager> mAPZCTreeManager;
85   nsCOMPtr<nsISerialEventTarget> mUIThread;
86 
87   void InitializeRoot();
88   PresShell* GetPresShell() const;
89   dom::Document* GetRootDocument() const;
90   dom::Document* GetRootContentDocument(
91       const ScrollableLayerGuid::ViewID& aScrollId) const;
92   void HandleDoubleTap(const mozilla::CSSPoint& aPoint, Modifiers aModifiers,
93                        const ScrollableLayerGuid& aGuid);
94 };
95 
96 }  // namespace layers
97 }  // namespace mozilla
98 
99 #endif /* mozilla_layers_ChromeProcessController_h */
100