Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(82)

Side by Side Diff: blimp/client/input/blimp_input_manager.h

Issue 1430623004: blimp: Add support for input handling (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix build error. Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 BLIMP_CLIENT_INPUT_BLIMP_INPUT_MANAGER_H_
6 #define BLIMP_CLIENT_INPUT_BLIMP_INPUT_MANAGER_H_
7
8 #include "base/macros.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/single_thread_task_runner.h"
11 #include "base/synchronization/waitable_event.h"
12 #include "blimp/client/input/blimp_input_handler_wrapper.h"
13 #include "third_party/WebKit/public/web/WebInputEvent.h"
14 #include "ui/events/gesture_detection/filtered_gesture_provider.h"
15 #include "ui/events/gesture_detection/motion_event.h"
16
17 namespace blimp {
18
19 class BlimpInputManagerClient {
20 public:
21 virtual void SendWebInputEvent(
22 const blink::WebInputEvent& input_event) = 0;
23 };
24
25 // The BlimpInputManager handles input events for a specific web widget. The
26 // class processes ui::events to generate web input events which are forwarded
27 // to the compositor to be handled on the compositor thread. If the event can
28 // not be handled locally by the compositor, it is given to the
29 // BlimpInputManagerClient to be sent to the engine.
30 //
31 // The BlimpInputManager is created and destroyed on the main thread but can be
32 // called from the main or compositor thread. It is safe for the
33 // BlimpInputManager to be called on the compositor thread because:
34 // 1) The only compositor threaded callers of the BlimpInputManager are the
35 // BlimpInputManager itself.
36 // 2) BlimpInputManager blocks the main thread in its dtor to ensure that all
37 // tasks queued to call it on the compositor thread have been run before it is
38 // destroyed on the main thread.
39 //
40 // It is *important* to destroy the cc::InputHandler on the compositor thread
41 // before destroying the BlimpInputManager.
42
43 class BlimpInputManager : public ui::GestureProviderClient {
44 public:
45 static scoped_ptr<BlimpInputManager> Create(
46 BlimpInputManagerClient* client,
47 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
48 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner,
49 const base::WeakPtr<cc::InputHandler>& input_handler);
50
51 ~BlimpInputManager() override;
52
53 // Called to process a ui::MotionEvent. Returns true if the event was
54 // successfully processed.
55 bool OnTouchEvent(const ui::MotionEvent& motion_event);
56
57 // Called by the BlimpInputHandlerWrapper after an input event was handled on
58 // the compositor thread.
59 // |consumed| is false if the event was not handled by the compositor and
60 // should be sent to the engine.
61 void DidHandleWebInputEvent(const blink::WebInputEvent& input_event,
62 bool consumed);
63
64 private:
65 BlimpInputManager(
66 BlimpInputManagerClient* client,
67 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
68 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner,
69 const base::WeakPtr<cc::InputHandler>& input_handler);
70
71 // ui::GestureProviderClient implementation.
72 void OnGestureEvent(const ui::GestureEventData& gesture) override;
73
74 // Called on the compositor thread.
75 void CreateInputHandlerWrapperOnCompositorThread(
76 base::WeakPtr<BlimpInputManager> input_manager_weak_ptr,
77 const base::WeakPtr<cc::InputHandler>& input_handler);
78 void HandleWebInputEventOnCompositorThread(
79 const blink::WebInputEvent& input_event);
80 void ShutdownOnCompositorThread(base::WaitableEvent* shutdown_event);
81
82 bool IsMainThread() const;
83 bool IsCompositorThread() const;
84
85 BlimpInputManagerClient* client_;
86
87 ui::FilteredGestureProvider gesture_provider_;
88
89 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_;
90 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_;
91
92 // Used for debug assertions to ensure that the main thread is blocked during
93 // shutdown. Set in the destructor before the main thread is blocked and
94 // read in ShutdownOnCompositorThread.
95 bool main_thread_blocked_;
96
97 scoped_ptr<BlimpInputHandlerWrapper> input_handler_wrapper_;
98
99 base::WeakPtrFactory<BlimpInputManager> weak_factory_;
100
101 DISALLOW_COPY_AND_ASSIGN(BlimpInputManager);
102 };
103
104 } // namespace blimp
105
106 #endif // BLIMP_CLIENT_INPUT_BLIMP_INPUT_MANAGER_H_
OLDNEW
« no previous file with comments | « blimp/client/input/blimp_input_handler_wrapper.cc ('k') | blimp/client/input/blimp_input_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698