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

Side by Side Diff: base/message_pump_glib.cc

Issue 159046: Implementing accelerators for Linux toolkit_views (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « base/message_pump_glib.h ('k') | chrome/browser/autocomplete/search_provider_unittest.cc » ('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 "base/eintr_wrapper.h" 10 #include "base/eintr_wrapper.h"
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 146
147 MessagePumpForUI::~MessagePumpForUI() { 147 MessagePumpForUI::~MessagePumpForUI() {
148 gdk_event_handler_set(reinterpret_cast<GdkEventFunc>(gtk_main_do_event), 148 gdk_event_handler_set(reinterpret_cast<GdkEventFunc>(gtk_main_do_event),
149 this, NULL); 149 this, NULL);
150 g_source_destroy(work_source_); 150 g_source_destroy(work_source_);
151 g_source_unref(work_source_); 151 g_source_unref(work_source_);
152 close(wakeup_pipe_read_); 152 close(wakeup_pipe_read_);
153 close(wakeup_pipe_write_); 153 close(wakeup_pipe_write_);
154 } 154 }
155 155
156 void MessagePumpForUI::Run(Delegate* delegate) { 156 void MessagePumpForUI::RunWithDispatcher(Delegate* delegate,
157 Dispatcher* dispatcher) {
157 #ifndef NDEBUG 158 #ifndef NDEBUG
158 // Make sure we only run this on one thread. GTK only has one message pump 159 // Make sure we only run this on one thread. GTK only has one message pump
159 // so we can only have one UI loop per process. 160 // so we can only have one UI loop per process.
160 static PlatformThreadId thread_id = PlatformThread::CurrentId(); 161 static PlatformThreadId thread_id = PlatformThread::CurrentId();
161 DCHECK(thread_id == PlatformThread::CurrentId()) << 162 DCHECK(thread_id == PlatformThread::CurrentId()) <<
162 "Running MessagePumpForUI on two different threads; " 163 "Running MessagePumpForUI on two different threads; "
163 "this is unsupported by GLib!"; 164 "this is unsupported by GLib!";
164 #endif 165 #endif
165 166
166 RunState state; 167 RunState state;
167 state.delegate = delegate; 168 state.delegate = delegate;
169 state.dispatcher = dispatcher;
168 state.should_quit = false; 170 state.should_quit = false;
169 state.run_depth = state_ ? state_->run_depth + 1 : 1; 171 state.run_depth = state_ ? state_->run_depth + 1 : 1;
170 state.has_work = false; 172 state.has_work = false;
171 173
172 RunState* previous_state = state_; 174 RunState* previous_state = state_;
173 state_ = &state; 175 state_ = &state;
174 176
175 // We really only do a single task for each iteration of the loop. If we 177 // We really only do a single task for each iteration of the loop. If we
176 // have done something, assume there is likely something more to do. This 178 // have done something, assume there is likely something more to do. This
177 // will mean that we don't block on the message pump until there was nothing 179 // will mean that we don't block on the message pump until there was nothing
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 304
303 void MessagePumpForUI::ScheduleDelayedWork(const Time& delayed_work_time) { 305 void MessagePumpForUI::ScheduleDelayedWork(const Time& delayed_work_time) {
304 // We need to wake up the loop in case the poll timeout needs to be 306 // We need to wake up the loop in case the poll timeout needs to be
305 // adjusted. This will cause us to try to do work, but that's ok. 307 // adjusted. This will cause us to try to do work, but that's ok.
306 delayed_work_time_ = delayed_work_time; 308 delayed_work_time_ = delayed_work_time;
307 ScheduleWork(); 309 ScheduleWork();
308 } 310 }
309 311
310 // static 312 // static
311 void MessagePumpForUI::EventDispatcher(GdkEvent* event, gpointer data) { 313 void MessagePumpForUI::EventDispatcher(GdkEvent* event, gpointer data) {
312 reinterpret_cast<MessagePumpForUI*>(data)->WillProcessEvent(event); 314 MessagePumpForUI* message_pump = reinterpret_cast<MessagePumpForUI*>(data);
313 gtk_main_do_event(event); 315
314 reinterpret_cast<MessagePumpForUI*>(data)->DidProcessEvent(event); 316 message_pump->WillProcessEvent(event);
317 if (message_pump->state_->dispatcher) {
318 if (!message_pump->state_->dispatcher->Dispatch(event))
319 message_pump->state_->should_quit = true;
320 } else {
321 gtk_main_do_event(event);
322 }
323 message_pump->DidProcessEvent(event);
315 } 324 }
316 325
317 } // namespace base 326 } // namespace base
OLDNEW
« no previous file with comments | « base/message_pump_glib.h ('k') | chrome/browser/autocomplete/search_provider_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698