Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(500)

Side by Side Diff: base/message_pump_glib.cc

Issue 3748002: Add a message pump for touchui=1 (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: gyp magic to fix build failure (hopefully). Created 10 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/message_pump_glib.h ('k') | base/message_pump_glib_x.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "base/message_pump_glib.h" 5 #include "base/message_pump_glib.h"
6 6
7 #include <fcntl.h> 7 #include <fcntl.h>
8 #include <math.h> 8 #include <math.h>
9 9
10 #include <gtk/gtk.h> 10 #include <gtk/gtk.h>
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 // first iteration of the loop, so RunAllPending() works correctly. 200 // first iteration of the loop, so RunAllPending() works correctly.
201 bool more_work_is_plausible = true; 201 bool more_work_is_plausible = true;
202 202
203 // We run our own loop instead of using g_main_loop_quit in one of the 203 // We run our own loop instead of using g_main_loop_quit in one of the
204 // callbacks. This is so we only quit our own loops, and we don't quit 204 // callbacks. This is so we only quit our own loops, and we don't quit
205 // nested loops run by others. TODO(deanm): Is this what we want? 205 // nested loops run by others. TODO(deanm): Is this what we want?
206 for (;;) { 206 for (;;) {
207 // Don't block if we think we have more work to do. 207 // Don't block if we think we have more work to do.
208 bool block = !more_work_is_plausible; 208 bool block = !more_work_is_plausible;
209 209
210 // g_main_context_iteration returns true if events have been dispatched. 210 more_work_is_plausible = RunOnce(context_, block);
211 more_work_is_plausible = g_main_context_iteration(context_, block);
212 if (state_->should_quit) 211 if (state_->should_quit)
213 break; 212 break;
214 213
215 more_work_is_plausible |= state_->delegate->DoWork(); 214 more_work_is_plausible |= state_->delegate->DoWork();
216 if (state_->should_quit) 215 if (state_->should_quit)
217 break; 216 break;
218 217
219 more_work_is_plausible |= 218 more_work_is_plausible |=
220 state_->delegate->DoDelayedWork(&delayed_work_time_); 219 state_->delegate->DoDelayedWork(&delayed_work_time_);
221 if (state_->should_quit) 220 if (state_->should_quit)
222 break; 221 break;
223 222
224 if (more_work_is_plausible) 223 if (more_work_is_plausible)
225 continue; 224 continue;
226 225
227 more_work_is_plausible = state_->delegate->DoIdleWork(); 226 more_work_is_plausible = state_->delegate->DoIdleWork();
228 if (state_->should_quit) 227 if (state_->should_quit)
229 break; 228 break;
230 } 229 }
231 230
232 state_ = previous_state; 231 state_ = previous_state;
233 } 232 }
234 233
234 bool MessagePumpForUI::RunOnce(GMainContext* context, bool block) {
235 // g_main_context_iteration returns true if events have been dispatched.
236 return g_main_context_iteration(context, block);
237 }
238
235 // Return the timeout we want passed to poll. 239 // Return the timeout we want passed to poll.
236 int MessagePumpForUI::HandlePrepare() { 240 int MessagePumpForUI::HandlePrepare() {
237 // We know we have work, but we haven't called HandleDispatch yet. Don't let 241 // We know we have work, but we haven't called HandleDispatch yet. Don't let
238 // the pump block so that we can do some processing. 242 // the pump block so that we can do some processing.
239 if (state_ && // state_ may be null during tests. 243 if (state_ && // state_ may be null during tests.
240 state_->has_work) 244 state_->has_work)
241 return 0; 245 return 0;
242 246
243 // We don't think we have work to do, but make sure not to block 247 // We don't think we have work to do, but make sure not to block
244 // longer than the next time we need to run delayed work. 248 // longer than the next time we need to run delayed work.
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 } 329 }
326 } 330 }
327 331
328 void MessagePumpForUI::ScheduleDelayedWork(const Time& delayed_work_time) { 332 void MessagePumpForUI::ScheduleDelayedWork(const Time& delayed_work_time) {
329 // We need to wake up the loop in case the poll timeout needs to be 333 // We need to wake up the loop in case the poll timeout needs to be
330 // adjusted. This will cause us to try to do work, but that's ok. 334 // adjusted. This will cause us to try to do work, but that's ok.
331 delayed_work_time_ = delayed_work_time; 335 delayed_work_time_ = delayed_work_time;
332 ScheduleWork(); 336 ScheduleWork();
333 } 337 }
334 338
339 void MessagePumpForUI::DispatchEvents(GdkEvent* event) {
340 WillProcessEvent(event);
341 if (state_ && state_->dispatcher) { // state_ may be null during tests.
342 if (!state_->dispatcher->Dispatch(event))
343 state_->should_quit = true;
344 } else {
345 gtk_main_do_event(event);
346 }
347 DidProcessEvent(event);
348 }
349
335 // static 350 // static
336 void MessagePumpForUI::EventDispatcher(GdkEvent* event, gpointer data) { 351 void MessagePumpForUI::EventDispatcher(GdkEvent* event, gpointer data) {
337 MessagePumpForUI* message_pump = reinterpret_cast<MessagePumpForUI*>(data); 352 MessagePumpForUI* message_pump = reinterpret_cast<MessagePumpForUI*>(data);
338 353 message_pump->DispatchEvents(event);
339 message_pump->WillProcessEvent(event);
340 if (message_pump->state_ && // state_ may be null during tests.
341 message_pump->state_->dispatcher) {
342 if (!message_pump->state_->dispatcher->Dispatch(event))
343 message_pump->state_->should_quit = true;
344 } else {
345 gtk_main_do_event(event);
346 }
347 message_pump->DidProcessEvent(event);
348 } 354 }
349 355
350 } // namespace base 356 } // namespace base
OLDNEW
« no previous file with comments | « base/message_pump_glib.h ('k') | base/message_pump_glib_x.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698