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