OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 } | 296 } |
297 | 297 |
298 void MessagePumpForUI::AddObserver(Observer* observer) { | 298 void MessagePumpForUI::AddObserver(Observer* observer) { |
299 observers_.AddObserver(observer); | 299 observers_.AddObserver(observer); |
300 } | 300 } |
301 | 301 |
302 void MessagePumpForUI::RemoveObserver(Observer* observer) { | 302 void MessagePumpForUI::RemoveObserver(Observer* observer) { |
303 observers_.RemoveObserver(observer); | 303 observers_.RemoveObserver(observer); |
304 } | 304 } |
305 | 305 |
306 MessagePumpForUI::Dispatcher* MessagePumpForUI::GetDispatcher() { | 306 void MessagePumpForUI::DispatchEvents(GdkEvent* event) { |
307 return state_ ? state_->dispatcher : NULL; | 307 WillProcessEvent(event); |
308 } | 308 if (state_ && state_->dispatcher) { // state_ may be null during tests. |
309 | 309 if (!state_->dispatcher->Dispatch(event)) |
310 void MessagePumpForUI::WillProcessEvent(GdkEvent* event) { | 310 state_->should_quit = true; |
311 FOR_EACH_OBSERVER(Observer, observers_, WillProcessEvent(event)); | 311 } else { |
312 } | 312 gtk_main_do_event(event); |
313 | 313 } |
314 void MessagePumpForUI::DidProcessEvent(GdkEvent* event) { | 314 DidProcessEvent(event); |
315 FOR_EACH_OBSERVER(Observer, observers_, DidProcessEvent(event)); | |
316 } | 315 } |
317 | 316 |
318 void MessagePumpForUI::Run(Delegate* delegate) { | 317 void MessagePumpForUI::Run(Delegate* delegate) { |
319 RunWithDispatcher(delegate, NULL); | 318 RunWithDispatcher(delegate, NULL); |
320 } | 319 } |
321 | 320 |
322 void MessagePumpForUI::Quit() { | 321 void MessagePumpForUI::Quit() { |
323 if (state_) { | 322 if (state_) { |
324 state_->should_quit = true; | 323 state_->should_quit = true; |
325 } else { | 324 } else { |
(...skipping 11 matching lines...) Expand all Loading... |
337 } | 336 } |
338 } | 337 } |
339 | 338 |
340 void MessagePumpForUI::ScheduleDelayedWork(const TimeTicks& delayed_work_time) { | 339 void MessagePumpForUI::ScheduleDelayedWork(const TimeTicks& delayed_work_time) { |
341 // We need to wake up the loop in case the poll timeout needs to be | 340 // We need to wake up the loop in case the poll timeout needs to be |
342 // adjusted. This will cause us to try to do work, but that's ok. | 341 // adjusted. This will cause us to try to do work, but that's ok. |
343 delayed_work_time_ = delayed_work_time; | 342 delayed_work_time_ = delayed_work_time; |
344 ScheduleWork(); | 343 ScheduleWork(); |
345 } | 344 } |
346 | 345 |
347 void MessagePumpForUI::DispatchEvents(GdkEvent* event) { | 346 MessagePumpForUI::Dispatcher* MessagePumpForUI::GetDispatcher() { |
348 WillProcessEvent(event); | 347 return state_ ? state_->dispatcher : NULL; |
349 if (state_ && state_->dispatcher) { // state_ may be null during tests. | 348 } |
350 if (!state_->dispatcher->Dispatch(event)) | 349 |
351 state_->should_quit = true; | 350 void MessagePumpForUI::WillProcessEvent(GdkEvent* event) { |
352 } else { | 351 FOR_EACH_OBSERVER(Observer, observers_, WillProcessEvent(event)); |
353 gtk_main_do_event(event); | 352 } |
354 } | 353 |
355 DidProcessEvent(event); | 354 void MessagePumpForUI::DidProcessEvent(GdkEvent* event) { |
| 355 FOR_EACH_OBSERVER(Observer, observers_, DidProcessEvent(event)); |
356 } | 356 } |
357 | 357 |
358 // static | 358 // static |
359 void MessagePumpForUI::EventDispatcher(GdkEvent* event, gpointer data) { | 359 void MessagePumpForUI::EventDispatcher(GdkEvent* event, gpointer data) { |
360 MessagePumpForUI* message_pump = reinterpret_cast<MessagePumpForUI*>(data); | 360 MessagePumpForUI* message_pump = reinterpret_cast<MessagePumpForUI*>(data); |
361 message_pump->DispatchEvents(event); | 361 message_pump->DispatchEvents(event); |
362 } | 362 } |
363 | 363 |
364 } // namespace base | 364 } // namespace base |
OLD | NEW |