michael@0: // Copyright (c) 2010 The Chromium Authors. All rights reserved. michael@0: // Use of this source code is governed by a BSD-style license that can be michael@0: // found in the LICENSE file. michael@0: michael@0: #ifndef BASE_MESSAGE_PUMP_QT_H_ michael@0: #define BASE_MESSAGE_PUMP_QT_H_ michael@0: michael@0: #include michael@0: michael@0: #include "base/message_pump.h" michael@0: #include "base/time.h" michael@0: michael@0: class QTimer; michael@0: michael@0: namespace base { michael@0: michael@0: class MessagePumpForUI; michael@0: michael@0: class MessagePumpQt : public QObject { michael@0: Q_OBJECT michael@0: michael@0: public: michael@0: MessagePumpQt(MessagePumpForUI &pump); michael@0: ~MessagePumpQt(); michael@0: michael@0: virtual bool event (QEvent *e); michael@0: void scheduleDelayedIfNeeded(const TimeTicks& delayed_work_time); michael@0: michael@0: public Q_SLOTS: michael@0: void dispatchDelayed(); michael@0: michael@0: private: michael@0: base::MessagePumpForUI &pump; michael@0: QTimer* mTimer; michael@0: }; michael@0: michael@0: // This class implements a MessagePump needed for TYPE_UI MessageLoops on michael@0: // OS_LINUX platforms using QApplication event loop michael@0: class MessagePumpForUI : public MessagePump { michael@0: michael@0: public: michael@0: MessagePumpForUI(); michael@0: ~MessagePumpForUI(); michael@0: michael@0: virtual void Run(Delegate* delegate); michael@0: virtual void Quit(); michael@0: virtual void ScheduleWork(); michael@0: virtual void ScheduleDelayedWork(const TimeTicks& delayed_work_time); michael@0: michael@0: // Internal methods used for processing the pump callbacks. They are michael@0: // public for simplicity but should not be used directly. michael@0: // HandleDispatch is called after the poll has completed. michael@0: void HandleDispatch(); michael@0: michael@0: private: michael@0: // We may make recursive calls to Run, so we save state that needs to be michael@0: // separate between them in this structure type. michael@0: struct RunState { michael@0: Delegate* delegate; michael@0: michael@0: // Used to flag that the current Run() invocation should return ASAP. michael@0: bool should_quit; michael@0: michael@0: // Used to count how many Run() invocations are on the stack. michael@0: int run_depth; michael@0: }; michael@0: michael@0: RunState* state_; michael@0: michael@0: // This is the time when we need to do delayed work. michael@0: TimeTicks delayed_work_time_; michael@0: michael@0: // MessagePump implementation for Qt based on the GLib implement. michael@0: // On Qt we use a QObject base class and the michael@0: // default qApp in order to process events through QEventLoop. michael@0: MessagePumpQt qt_pump; michael@0: michael@0: DISALLOW_COPY_AND_ASSIGN(MessagePumpForUI); michael@0: }; michael@0: michael@0: } // namespace base michael@0: michael@0: #endif // BASE_MESSAGE_PUMP_QT_H_