OLD | NEW |
| (Empty) |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef BLIMP_CLIENT_CORE_RENDER_WIDGET_BLIMP_DOCUMENT_MANAGER_H_ | |
6 #define BLIMP_CLIENT_CORE_RENDER_WIDGET_BLIMP_DOCUMENT_MANAGER_H_ | |
7 | |
8 #include <map> | |
9 | |
10 #include "base/macros.h" | |
11 #include "blimp/client/core/compositor/blimp_compositor.h" | |
12 #include "blimp/client/core/render_widget/render_widget_feature.h" | |
13 #include "cc/layers/layer.h" | |
14 #include "cc/trees/layer_tree_settings.h" | |
15 #include "ui/events/gesture_detection/motion_event.h" | |
16 | |
17 namespace blimp { | |
18 namespace client { | |
19 | |
20 class BlimpDocument; | |
21 | |
22 // The BlimpDocumentManager is responsible for managing multiple BlimpDocument | |
23 // instances, each mapped to a render widget on the engine. | |
24 // The |document_id_| matches the |render_widget_id| of the | |
25 // render widget messages which are routed to the engine side render widget. | |
26 // | |
27 // The compositor corresponding to the render widget initialized on the | |
28 // engine will be the |active_document_|. | |
29 // All events from the native view are forwarded to this compositor. | |
30 class BlimpDocumentManager | |
31 : public RenderWidgetFeature::RenderWidgetFeatureDelegate { | |
32 public: | |
33 explicit BlimpDocumentManager( | |
34 int blimp_contents_id, | |
35 RenderWidgetFeature* render_widget_feature, | |
36 BlimpCompositorDependencies* compositor_dependencies); | |
37 ~BlimpDocumentManager() override; | |
38 | |
39 void SetVisible(bool visible); | |
40 bool visible() const { return visible_; } | |
41 | |
42 bool OnTouchEvent(const ui::MotionEvent& motion_event); | |
43 | |
44 void RequestCopyOfCompositorOutput( | |
45 std::unique_ptr<cc::CopyOutputRequest> copy_request, | |
46 bool flush_pending_update); | |
47 | |
48 // Sends input event to the engine, virtual for testing. | |
49 virtual void SendWebGestureEvent(int document_id, | |
50 const blink::WebGestureEvent& gesture_event); | |
51 | |
52 // Sends compositor message to the engine, virtual for testing. | |
53 virtual void SendCompositorMessage( | |
54 int document_id, | |
55 const cc::proto::CompositorMessage& message); | |
56 | |
57 scoped_refptr<cc::Layer> layer() const { return layer_; } | |
58 | |
59 protected: | |
60 // Creates a BlimpDocument, virtual for testing. | |
61 virtual std::unique_ptr<BlimpDocument> CreateBlimpDocument( | |
62 int document_id, | |
63 BlimpCompositorDependencies* compositor_dependencies); | |
64 | |
65 // Returns the blimp document from |document_id|, returns nullptr if | |
66 // the document is not found, protected for testing. | |
67 BlimpDocument* GetDocument(int document_id); | |
68 | |
69 private: | |
70 // RenderWidgetFeatureDelegate implementation. | |
71 void OnRenderWidgetCreated(int render_widget_id) override; | |
72 void OnRenderWidgetInitialized(int render_widget_id) override; | |
73 void OnRenderWidgetDeleted(int render_widget_id) override; | |
74 void OnCompositorMessageReceived( | |
75 int render_widget_id, | |
76 std::unique_ptr<cc::proto::CompositorMessage> message) override; | |
77 | |
78 // The unique id of BlimpContentImpl which owns this document manager. | |
79 int blimp_contents_id_; | |
80 | |
81 // The bridge to the network layer that does the proto/RenderWidget id work. | |
82 // BlimpCompositorManager does not own this and it is expected to outlive this | |
83 // BlimpCompositorManager instance. | |
84 RenderWidgetFeature* render_widget_feature_; | |
85 | |
86 bool visible_; | |
87 | |
88 // The layer which holds the content from the active compositor. | |
89 scoped_refptr<cc::Layer> layer_; | |
90 | |
91 // A map of document id to the BlimpDocument instance. | |
92 using DocumentMap = std::map<int, std::unique_ptr<BlimpDocument>>; | |
93 DocumentMap documents_; | |
94 | |
95 // The |active_document_| holds the compositor from the that is currently | |
96 // visible. It corresponds to the | |
97 // render widget currently initialized on the engine. | |
98 BlimpDocument* active_document_; | |
99 | |
100 BlimpCompositorDependencies* compositor_dependencies_; | |
101 | |
102 DISALLOW_COPY_AND_ASSIGN(BlimpDocumentManager); | |
103 }; | |
104 | |
105 } // namespace client | |
106 } // namespace blimp | |
107 | |
108 #endif // BLIMP_CLIENT_CORE_RENDER_WIDGET_BLIMP_DOCUMENT_MANAGER_H_ | |
OLD | NEW |