OLD | NEW |
| (Empty) |
1 // Copyright 2015 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 CONTENT_RENDERER_MUS_COMPOSITOR_MUS_CONNECTION_H_ | |
6 #define CONTENT_RENDERER_MUS_COMPOSITOR_MUS_CONNECTION_H_ | |
7 | |
8 #include <memory> | |
9 | |
10 #include "base/bind.h" | |
11 #include "base/compiler_specific.h" | |
12 #include "base/macros.h" | |
13 #include "base/synchronization/lock.h" | |
14 #include "content/common/content_export.h" | |
15 #include "content/common/input/input_event_ack_state.h" | |
16 #include "services/ui/public/cpp/input_event_handler.h" | |
17 #include "services/ui/public/cpp/window.h" | |
18 #include "services/ui/public/cpp/window_tree_client.h" | |
19 #include "services/ui/public/cpp/window_tree_client_delegate.h" | |
20 #include "third_party/WebKit/public/platform/WebCoalescedInputEvent.h" | |
21 #include "ui/events/gestures/motion_event_aura.h" | |
22 | |
23 namespace ui { | |
24 struct DidOverscrollParams; | |
25 } | |
26 | |
27 namespace content { | |
28 | |
29 class InputHandlerManager; | |
30 | |
31 // CompositorMusConnection manages the connection to the Mandoline UI Service | |
32 // (Mus) on the compositor thread. For operations that need to happen on the | |
33 // main thread, CompositorMusConnection deals with passing information across | |
34 // threads. CompositorMusConnection is constructed on the main thread. By | |
35 // default all other methods are assumed to run on the compositor thread unless | |
36 // explicited suffixed with OnMainThread. | |
37 class CONTENT_EXPORT CompositorMusConnection | |
38 : NON_EXPORTED_BASE(public ui::WindowTreeClientDelegate), | |
39 NON_EXPORTED_BASE(public ui::InputEventHandler), | |
40 public base::RefCountedThreadSafe<CompositorMusConnection> { | |
41 public: | |
42 // Created on main thread. | |
43 CompositorMusConnection( | |
44 int routing_id, | |
45 const scoped_refptr<base::SingleThreadTaskRunner>& main_task_runner, | |
46 const scoped_refptr<base::SingleThreadTaskRunner>& compositor_task_runner, | |
47 mojo::InterfaceRequest<ui::mojom::WindowTreeClient> request, | |
48 InputHandlerManager* input_handler_manager); | |
49 | |
50 // Attaches the provided |compositor_frame_sink_binding| with the ui::Window | |
51 // for the renderer once it becomes available. | |
52 void AttachCompositorFrameSinkOnMainThread( | |
53 std::unique_ptr<ui::WindowCompositorFrameSinkBinding> | |
54 compositor_frame_sink_binding); | |
55 | |
56 private: | |
57 friend class CompositorMusConnectionTest; | |
58 friend class base::RefCountedThreadSafe<CompositorMusConnection>; | |
59 | |
60 ~CompositorMusConnection() override; | |
61 | |
62 void AttachCompositorFrameSinkOnCompositorThread( | |
63 std::unique_ptr<ui::WindowCompositorFrameSinkBinding> | |
64 compositor_frame_sink_binding); | |
65 | |
66 void CreateWindowTreeClientOnCompositorThread( | |
67 ui::mojom::WindowTreeClientRequest request); | |
68 | |
69 void OnConnectionLostOnMainThread(); | |
70 | |
71 void OnWindowInputEventOnMainThread( | |
72 blink::WebScopedInputEvent web_event, | |
73 const base::Callback<void(ui::mojom::EventResult)>& ack); | |
74 | |
75 void OnWindowInputEventAckOnMainThread( | |
76 const base::Callback<void(ui::mojom::EventResult)>& ack, | |
77 ui::mojom::EventResult result); | |
78 | |
79 std::unique_ptr<blink::WebInputEvent> Convert(const ui::Event& event); | |
80 | |
81 void DeleteWindowTreeClient(); | |
82 | |
83 // WindowTreeClientDelegate implementation: | |
84 void OnEmbed(ui::Window* root) override; | |
85 void OnEmbedRootDestroyed(ui::Window* root) override; | |
86 void OnLostConnection(ui::WindowTreeClient* client) override; | |
87 void OnPointerEventObserved(const ui::PointerEvent& event, | |
88 ui::Window* target) override; | |
89 | |
90 // InputEventHandler implementation: | |
91 void OnWindowInputEvent( | |
92 ui::Window* window, | |
93 const ui::Event& event, | |
94 std::unique_ptr<base::Callback<void(ui::mojom::EventResult)>>* | |
95 ack_callback) override; | |
96 void DidHandleWindowInputEventAndOverscroll( | |
97 std::unique_ptr<base::Callback<void(ui::mojom::EventResult)>> | |
98 ack_callback, | |
99 InputEventAckState ack_state, | |
100 blink::WebScopedInputEvent web_event, | |
101 const ui::LatencyInfo& latency_info, | |
102 std::unique_ptr<ui::DidOverscrollParams> overscroll_params); | |
103 | |
104 const int routing_id_; | |
105 // Use this lock when accessing |window_tree_client_|. Lock exists solely for | |
106 // DCHECK in destructor. | |
107 base::Lock window_tree_client_lock_; | |
108 std::unique_ptr<ui::WindowTreeClient> window_tree_client_; | |
109 ui::Window* root_; | |
110 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; | |
111 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_; | |
112 InputHandlerManager* const input_handler_manager_; | |
113 std::unique_ptr<ui::WindowCompositorFrameSinkBinding> | |
114 window_compositor_frame_sink_binding_; | |
115 | |
116 // Stores the current state of the active pointers targeting this object. | |
117 ui::MotionEventAura pointer_state_; | |
118 | |
119 DISALLOW_COPY_AND_ASSIGN(CompositorMusConnection); | |
120 }; | |
121 | |
122 } // namespace content | |
123 | |
124 #endif // CONTENT_RENDERER_MUS_COMPOSITOR_MUS_CONNECTION_H_ | |
OLD | NEW |