1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/ipc/chromium/src/base/message_pump_qt.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,83 @@ 1.4 +// Copyright (c) 2010 The Chromium Authors. All rights reserved. 1.5 +// Use of this source code is governed by a BSD-style license that can be 1.6 +// found in the LICENSE file. 1.7 + 1.8 +#ifndef BASE_MESSAGE_PUMP_QT_H_ 1.9 +#define BASE_MESSAGE_PUMP_QT_H_ 1.10 + 1.11 +#include <qobject.h> 1.12 + 1.13 +#include "base/message_pump.h" 1.14 +#include "base/time.h" 1.15 + 1.16 +class QTimer; 1.17 + 1.18 +namespace base { 1.19 + 1.20 +class MessagePumpForUI; 1.21 + 1.22 +class MessagePumpQt : public QObject { 1.23 + Q_OBJECT 1.24 + 1.25 + public: 1.26 + MessagePumpQt(MessagePumpForUI &pump); 1.27 + ~MessagePumpQt(); 1.28 + 1.29 + virtual bool event (QEvent *e); 1.30 + void scheduleDelayedIfNeeded(const TimeTicks& delayed_work_time); 1.31 + 1.32 + public Q_SLOTS: 1.33 + void dispatchDelayed(); 1.34 + 1.35 + private: 1.36 + base::MessagePumpForUI &pump; 1.37 + QTimer* mTimer; 1.38 +}; 1.39 + 1.40 +// This class implements a MessagePump needed for TYPE_UI MessageLoops on 1.41 +// OS_LINUX platforms using QApplication event loop 1.42 +class MessagePumpForUI : public MessagePump { 1.43 + 1.44 + public: 1.45 + MessagePumpForUI(); 1.46 + ~MessagePumpForUI(); 1.47 + 1.48 + virtual void Run(Delegate* delegate); 1.49 + virtual void Quit(); 1.50 + virtual void ScheduleWork(); 1.51 + virtual void ScheduleDelayedWork(const TimeTicks& delayed_work_time); 1.52 + 1.53 + // Internal methods used for processing the pump callbacks. They are 1.54 + // public for simplicity but should not be used directly. 1.55 + // HandleDispatch is called after the poll has completed. 1.56 + void HandleDispatch(); 1.57 + 1.58 + private: 1.59 + // We may make recursive calls to Run, so we save state that needs to be 1.60 + // separate between them in this structure type. 1.61 + struct RunState { 1.62 + Delegate* delegate; 1.63 + 1.64 + // Used to flag that the current Run() invocation should return ASAP. 1.65 + bool should_quit; 1.66 + 1.67 + // Used to count how many Run() invocations are on the stack. 1.68 + int run_depth; 1.69 + }; 1.70 + 1.71 + RunState* state_; 1.72 + 1.73 + // This is the time when we need to do delayed work. 1.74 + TimeTicks delayed_work_time_; 1.75 + 1.76 + // MessagePump implementation for Qt based on the GLib implement. 1.77 + // On Qt we use a QObject base class and the 1.78 + // default qApp in order to process events through QEventLoop. 1.79 + MessagePumpQt qt_pump; 1.80 + 1.81 + DISALLOW_COPY_AND_ASSIGN(MessagePumpForUI); 1.82 +}; 1.83 + 1.84 +} // namespace base 1.85 + 1.86 +#endif // BASE_MESSAGE_PUMP_QT_H_