|
1 // Copyright (c) 2010 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 BASE_MESSAGE_PUMP_QT_H_ |
|
6 #define BASE_MESSAGE_PUMP_QT_H_ |
|
7 |
|
8 #include <qobject.h> |
|
9 |
|
10 #include "base/message_pump.h" |
|
11 #include "base/time.h" |
|
12 |
|
13 class QTimer; |
|
14 |
|
15 namespace base { |
|
16 |
|
17 class MessagePumpForUI; |
|
18 |
|
19 class MessagePumpQt : public QObject { |
|
20 Q_OBJECT |
|
21 |
|
22 public: |
|
23 MessagePumpQt(MessagePumpForUI &pump); |
|
24 ~MessagePumpQt(); |
|
25 |
|
26 virtual bool event (QEvent *e); |
|
27 void scheduleDelayedIfNeeded(const TimeTicks& delayed_work_time); |
|
28 |
|
29 public Q_SLOTS: |
|
30 void dispatchDelayed(); |
|
31 |
|
32 private: |
|
33 base::MessagePumpForUI &pump; |
|
34 QTimer* mTimer; |
|
35 }; |
|
36 |
|
37 // This class implements a MessagePump needed for TYPE_UI MessageLoops on |
|
38 // OS_LINUX platforms using QApplication event loop |
|
39 class MessagePumpForUI : public MessagePump { |
|
40 |
|
41 public: |
|
42 MessagePumpForUI(); |
|
43 ~MessagePumpForUI(); |
|
44 |
|
45 virtual void Run(Delegate* delegate); |
|
46 virtual void Quit(); |
|
47 virtual void ScheduleWork(); |
|
48 virtual void ScheduleDelayedWork(const TimeTicks& delayed_work_time); |
|
49 |
|
50 // Internal methods used for processing the pump callbacks. They are |
|
51 // public for simplicity but should not be used directly. |
|
52 // HandleDispatch is called after the poll has completed. |
|
53 void HandleDispatch(); |
|
54 |
|
55 private: |
|
56 // We may make recursive calls to Run, so we save state that needs to be |
|
57 // separate between them in this structure type. |
|
58 struct RunState { |
|
59 Delegate* delegate; |
|
60 |
|
61 // Used to flag that the current Run() invocation should return ASAP. |
|
62 bool should_quit; |
|
63 |
|
64 // Used to count how many Run() invocations are on the stack. |
|
65 int run_depth; |
|
66 }; |
|
67 |
|
68 RunState* state_; |
|
69 |
|
70 // This is the time when we need to do delayed work. |
|
71 TimeTicks delayed_work_time_; |
|
72 |
|
73 // MessagePump implementation for Qt based on the GLib implement. |
|
74 // On Qt we use a QObject base class and the |
|
75 // default qApp in order to process events through QEventLoop. |
|
76 MessagePumpQt qt_pump; |
|
77 |
|
78 DISALLOW_COPY_AND_ASSIGN(MessagePumpForUI); |
|
79 }; |
|
80 |
|
81 } // namespace base |
|
82 |
|
83 #endif // BASE_MESSAGE_PUMP_QT_H_ |