OLD | NEW |
---|---|
1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef BASE_MESSAGE_PUMP_GLIB_H_ | 5 #ifndef BASE_MESSAGE_PUMP_GLIB_H_ |
6 #define BASE_MESSAGE_PUMP_GLIB_H_ | 6 #define BASE_MESSAGE_PUMP_GLIB_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/message_pump.h" | 9 #include "base/message_pump.h" |
10 #include "base/observer_list.h" | 10 #include "base/observer_list.h" |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
85 void RemoveObserver(Observer* observer); | 85 void RemoveObserver(Observer* observer); |
86 | 86 |
87 // Dispatch an available GdkEvent. Essentially this allows a subclass to do | 87 // Dispatch an available GdkEvent. Essentially this allows a subclass to do |
88 // some task before/after calling the default handler (EventDispatcher). | 88 // some task before/after calling the default handler (EventDispatcher). |
89 virtual void DispatchEvents(GdkEvent* event); | 89 virtual void DispatchEvents(GdkEvent* event); |
90 | 90 |
91 protected: | 91 protected: |
92 // Returns the dispatcher for the current run state (|state_->dispatcher|). | 92 // Returns the dispatcher for the current run state (|state_->dispatcher|). |
93 Dispatcher* GetDispatcher(); | 93 Dispatcher* GetDispatcher(); |
94 | 94 |
95 private: | |
96 // We may make recursive calls to Run, so we save state that needs to be | 95 // We may make recursive calls to Run, so we save state that needs to be |
97 // separate between them in this structure type. | 96 // separate between them in this structure type. |
98 struct RunState; | 97 struct RunState { |
rjkroege
2010/11/23 23:38:54
why did you have to move this into the include? It
sadrul
2010/11/24 00:55:21
the |should_quit| needs to be set from inside Mess
| |
98 Delegate* delegate; | |
99 Dispatcher* dispatcher; | |
99 | 100 |
101 // Used to flag that the current Run() invocation should return ASAP. | |
102 bool should_quit; | |
103 | |
104 // Used to count how many Run() invocations are on the stack. | |
105 int run_depth; | |
106 | |
107 // This keeps the state of whether the pump got signaled that there was new | |
108 // work to be done. Since we eat the message on the wake up pipe as soon as | |
109 // we get it, we keep that state here to stay consistent. | |
110 bool has_work; | |
111 }; | |
112 | |
113 RunState* state_; | |
114 | |
115 private: | |
100 // Invoked from EventDispatcher. Notifies all observers we're about to | 116 // Invoked from EventDispatcher. Notifies all observers we're about to |
101 // process an event. | 117 // process an event. |
102 void WillProcessEvent(GdkEvent* event); | 118 void WillProcessEvent(GdkEvent* event); |
103 | 119 |
104 // Invoked from EventDispatcher. Notifies all observers we processed an | 120 // Invoked from EventDispatcher. Notifies all observers we processed an |
105 // event. | 121 // event. |
106 void DidProcessEvent(GdkEvent* event); | 122 void DidProcessEvent(GdkEvent* event); |
107 | 123 |
108 // Callback prior to gdk dispatching an event. | 124 // Callback prior to gdk dispatching an event. |
109 static void EventDispatcher(GdkEvent* event, void* data); | 125 static void EventDispatcher(GdkEvent* event, void* data); |
110 | 126 |
111 RunState* state_; | |
112 | |
113 // This is a GLib structure that we can add event sources to. We use the | 127 // This is a GLib structure that we can add event sources to. We use the |
114 // default GLib context, which is the one to which all GTK events are | 128 // default GLib context, which is the one to which all GTK events are |
115 // dispatched. | 129 // dispatched. |
116 GMainContext* context_; | 130 GMainContext* context_; |
117 | 131 |
118 // This is the time when we need to do delayed work. | 132 // This is the time when we need to do delayed work. |
119 TimeTicks delayed_work_time_; | 133 TimeTicks delayed_work_time_; |
120 | 134 |
121 // The work source. It is shared by all calls to Run and destroyed when | 135 // The work source. It is shared by all calls to Run and destroyed when |
122 // the message pump is destroyed. | 136 // the message pump is destroyed. |
(...skipping 10 matching lines...) Expand all Loading... | |
133 | 147 |
134 // List of observers. | 148 // List of observers. |
135 ObserverList<Observer> observers_; | 149 ObserverList<Observer> observers_; |
136 | 150 |
137 DISALLOW_COPY_AND_ASSIGN(MessagePumpForUI); | 151 DISALLOW_COPY_AND_ASSIGN(MessagePumpForUI); |
138 }; | 152 }; |
139 | 153 |
140 } // namespace base | 154 } // namespace base |
141 | 155 |
142 #endif // BASE_MESSAGE_PUMP_GLIB_H_ | 156 #endif // BASE_MESSAGE_PUMP_GLIB_H_ |
OLD | NEW |