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

Side by Side Diff: base/message_pump_glib.h

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_loop.cc ('k') | base/message_pump_glib.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 #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 7
8 #include <gtk/gtk.h> 8 #include <gtk/gtk.h>
9 #include <glib.h> 9 #include <glib.h>
10 10
(...skipping 13 matching lines...) Expand all
24 public: 24 public:
25 virtual ~Observer() {} 25 virtual ~Observer() {}
26 26
27 // This method is called before processing a message. 27 // This method is called before processing a message.
28 virtual void WillProcessEvent(GdkEvent* event) = 0; 28 virtual void WillProcessEvent(GdkEvent* event) = 0;
29 29
30 // This method is called after processing a message. 30 // This method is called after processing a message.
31 virtual void DidProcessEvent(GdkEvent* event) = 0; 31 virtual void DidProcessEvent(GdkEvent* event) = 0;
32 }; 32 };
33 33
34 // Dispatcher is used during a nested invocation of Run to dispatch events.
35 // If Run is invoked with a non-NULL Dispatcher, MessageLoop does not
36 // dispatch events (or invoke gtk_main_do_event), rather every event is
37 // passed to Dispatcher's Dispatch method for dispatch. It is up to the
38 // Dispatcher to dispatch, or not, the event.
39 //
40 // The nested loop is exited by either posting a quit, or returning false
41 // from Dispatch.
42 class Dispatcher {
43 public:
44 virtual ~Dispatcher() {}
45 // Dispatches the event. If true is returned processing continues as
46 // normal. If false is returned, the nested loop exits immediately.
47 virtual bool Dispatch(GdkEvent* event) = 0;
48 };
49
34 MessagePumpForUI(); 50 MessagePumpForUI();
35 ~MessagePumpForUI(); 51 virtual ~MessagePumpForUI();
36 52
37 virtual void Run(Delegate* delegate); 53 // Like MessagePump::Run, but GdkEvent objects are routed through dispatcher.
54 virtual void RunWithDispatcher(Delegate* delegate, Dispatcher* dispatcher);
55
56 virtual void Run(Delegate* delegate) { RunWithDispatcher(delegate, NULL); }
38 virtual void Quit(); 57 virtual void Quit();
39 virtual void ScheduleWork(); 58 virtual void ScheduleWork();
40 virtual void ScheduleDelayedWork(const Time& delayed_work_time); 59 virtual void ScheduleDelayedWork(const Time& delayed_work_time);
41 60
42 // Internal methods used for processing the pump callbacks. They are 61 // Internal methods used for processing the pump callbacks. They are
43 // public for simplicity but should not be used directly. HandlePrepare 62 // public for simplicity but should not be used directly. HandlePrepare
44 // is called during the prepare step of glib, and returns a timeout that 63 // is called during the prepare step of glib, and returns a timeout that
45 // will be passed to the poll. HandleCheck is called after the poll 64 // will be passed to the poll. HandleCheck is called after the poll
46 // has completed, and returns whether or not HandleDispatch should be called. 65 // has completed, and returns whether or not HandleDispatch should be called.
47 // HandleDispatch is called if HandleCheck returned true. 66 // HandleDispatch is called if HandleCheck returned true.
48 int HandlePrepare(); 67 int HandlePrepare();
49 bool HandleCheck(); 68 bool HandleCheck();
50 void HandleDispatch(); 69 void HandleDispatch();
51 70
52 // Add an Observer, which will start receiving notifications immediately. 71 // Adds an Observer, which will start receiving notifications immediately.
53 void AddObserver(Observer* observer); 72 void AddObserver(Observer* observer);
54 73
55 // Remove an Observer. It is safe to call this method while an Observer is 74 // Removes an Observer. It is safe to call this method while an Observer is
56 // receiving a notification callback. 75 // receiving a notification callback.
57 void RemoveObserver(Observer* observer); 76 void RemoveObserver(Observer* observer);
58 77
59 private: 78 private:
60 // We may make recursive calls to Run, so we save state that needs to be 79 // We may make recursive calls to Run, so we save state that needs to be
61 // separate between them in this structure type. 80 // separate between them in this structure type.
62 struct RunState { 81 struct RunState {
63 Delegate* delegate; 82 Delegate* delegate;
83 Dispatcher* dispatcher;
64 84
65 // Used to flag that the current Run() invocation should return ASAP. 85 // Used to flag that the current Run() invocation should return ASAP.
66 bool should_quit; 86 bool should_quit;
67 87
68 // Used to count how many Run() invocations are on the stack. 88 // Used to count how many Run() invocations are on the stack.
69 int run_depth; 89 int run_depth;
70 90
71 // This keeps the state of whether the pump got signaled that there was new 91 // This keeps the state of whether the pump got signaled that there was new
72 // work to be done. Since we eat the message on the wake up pipe as soon as 92 // work to be done. Since we eat the message on the wake up pipe as soon as
73 // we get it, we keep that state here to stay consistent. 93 // we get it, we keep that state here to stay consistent.
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 129
110 // List of observers. 130 // List of observers.
111 ObserverList<Observer> observers_; 131 ObserverList<Observer> observers_;
112 132
113 DISALLOW_COPY_AND_ASSIGN(MessagePumpForUI); 133 DISALLOW_COPY_AND_ASSIGN(MessagePumpForUI);
114 }; 134 };
115 135
116 } // namespace base 136 } // namespace base
117 137
118 #endif // BASE_MESSAGE_PUMP_GLIB_H_ 138 #endif // BASE_MESSAGE_PUMP_GLIB_H_
OLDNEW
« no previous file with comments | « base/message_loop.cc ('k') | base/message_pump_glib.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698