diff options
author | sadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-20 20:29:52 +0000 |
---|---|---|
committer | sadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-20 20:29:52 +0000 |
commit | 9cabbaf78c3a3bbcb52c0ae6fbb06afd98224bf1 (patch) | |
tree | af8219e1a0d1be12649eb4b19f32025419d762f3 | |
parent | 177623b42c69743828b8bd0a40c0f07b072ba86d (diff) | |
download | chromium_src-9cabbaf78c3a3bbcb52c0ae6fbb06afd98224bf1.zip chromium_src-9cabbaf78c3a3bbcb52c0ae6fbb06afd98224bf1.tar.gz chromium_src-9cabbaf78c3a3bbcb52c0ae6fbb06afd98224bf1.tar.bz2 |
aura: Explicitly disable GTK.
Explicitly disable GTK by setting TOOLKIT_USES_GTK. This is the first in a series of changes required to have chrome on aura build and link without GTK. This CL makes base/ build without GTK. Subsequent CLs will do this for other components.
BUG=97131
TEST=none
Review URL: http://codereview.chromium.org/7904034
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@102005 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | base/base.gyp | 19 | ||||
-rw-r--r-- | base/base.gypi | 23 | ||||
-rw-r--r-- | base/message_loop.cc | 2 | ||||
-rw-r--r-- | base/message_pump_glib_unittest.cc | 19 | ||||
-rw-r--r-- | base/message_pump_x.cc | 92 | ||||
-rw-r--r-- | base/message_pump_x.h | 43 | ||||
-rw-r--r-- | build/build_config.h | 2 | ||||
-rw-r--r-- | build/common.gypi | 8 | ||||
-rw-r--r-- | build/linux/system.gyp | 1 |
9 files changed, 145 insertions, 64 deletions
diff --git a/base/base.gyp b/base/base.gyp index 8bca61bee..a4755e3 100644 --- a/base/base.gyp +++ b/base/base.gyp @@ -144,7 +144,7 @@ 'i18n/icu_string_conversions_unittest.cc', 'i18n/number_formatting_unittest.cc', 'i18n/rtl_unittest.cc', - 'i18n/string_search_unittest.cc', + 'i18n/string_search_unittest.cc', 'i18n/time_formatting_unittest.cc', 'json/json_reader_unittest.cc', 'json/json_writer_unittest.cc', @@ -257,13 +257,10 @@ 'module_dir': 'base' }, 'conditions': [ - ['toolkit_uses_gtk==1', { + ['use_glib==1', { 'sources!': [ 'file_version_info_unittest.cc', ], - 'sources': [ - 'nix/xdg_util_unittest.cc', - ], 'conditions': [ [ 'linux_use_tcmalloc==1', { 'dependencies': [ @@ -278,13 +275,21 @@ '-fno-strict-aliasing', ], }], + [ 'toolkit_uses_gtk==1', { + 'sources': [ + 'nix/xdg_util_unittest.cc', + ], + 'dependencies': [ + '../build/linux/system.gyp:gtk', + ] + }], ], 'dependencies': [ - '../build/linux/system.gyp:gtk', + '../build/linux/system.gyp:glib', '../build/linux/system.gyp:ssl', '../tools/xdisplaycheck/xdisplaycheck.gyp:xdisplaycheck', ], - }, { # toolkit_uses_gtk!=1 + }, { # use_glib!=1 'sources!': [ 'message_pump_glib_unittest.cc', ] diff --git a/base/base.gypi b/base/base.gypi index 3c23109be..0de2c24 100644 --- a/base/base.gypi +++ b/base/base.gypi @@ -381,21 +381,24 @@ 'message_pump_x.cc', ], }], - [ 'toolkit_uses_gtk==0', { + [ 'use_glib==0', { 'sources/': [ ['exclude', '^nix/'], ], 'sources!': [ 'atomicops_internals_x86_gcc.cc', 'message_pump_glib.cc', - 'message_pump_gtk.cc', 'message_pump_x.cc', ], }], + [ 'toolkit_uses_gtk==0', { + 'sources!': [ 'message_pump_gtk.cc', ], + }], [ 'touchui==0 and use_aura==0', { 'sources!' : [ 'message_pump_x.cc', ], }, { 'sources!' : [ 'message_pump_gtk.cc', ], + 'sources' : [ 'message_pump_x.cc', ], }], [ 'OS != "linux"', { 'sources!': [ @@ -474,7 +477,7 @@ ], }, 'conditions': [ - [ 'toolkit_uses_gtk==1', { + [ 'use_glib==1', { 'conditions': [ [ 'chromeos==1', { 'sources/': [ ['include', '_chromeos\\.cc$'] ] @@ -491,11 +494,19 @@ }, }, ], + [ 'toolkit_uses_gtk==1', { + 'dependencies': [ + '../build/linux/system.gyp:gtk', + ], + 'export_dependent_settings': [ + '../build/linux/system.gyp:gtk', + ], + }], ], 'dependencies': [ 'symbolize', '../build/util/build_util.gyp:lastchange#target', - '../build/linux/system.gyp:gtk', + '../build/linux/system.gyp:glib', '../build/linux/system.gyp:x11', 'xdg_mime', ], @@ -506,10 +517,10 @@ '-Wno-write-strings', ], 'export_dependent_settings': [ - '../build/linux/system.gyp:gtk', + '../build/linux/system.gyp:glib', '../build/linux/system.gyp:x11', ], - }, { # toolkit_uses_gtk!=1 + }, { # use_glib!=1 'sources/': [ ['exclude', '/xdg_user_dirs/'], ['exclude', '_nss\.cc$'], diff --git a/base/message_loop.cc b/base/message_loop.cc index 4a206e9..d96b57d 100644 --- a/base/message_loop.cc +++ b/base/message_loop.cc @@ -29,7 +29,7 @@ #if defined(OS_ANDROID) #include "base/message_pump_android.h" #endif -#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) +#if defined(TOOLKIT_USES_GTK) #include <gdk/gdk.h> #include <gdk/gdkx.h> #endif // defined(OS_POSIX) && !defined(OS_MACOSX) diff --git a/base/message_pump_glib_unittest.cc b/base/message_pump_glib_unittest.cc index 496fda6..69fbb95 100644 --- a/base/message_pump_glib_unittest.cc +++ b/base/message_pump_glib_unittest.cc @@ -4,7 +4,6 @@ #include "base/message_pump_glib.h" -#include <gtk/gtk.h> #include <math.h> #include <algorithm> @@ -15,6 +14,10 @@ #include "base/threading/thread.h" #include "testing/gtest/include/gtest/gtest.h" +#if defined(TOOLKIT_USES_GTK) +#include <gtk/gtk.h> +#endif + namespace { // This class injects dummy "events" into the GLib loop. When "handled" these @@ -395,6 +398,7 @@ TEST_F(MessagePumpGLibTest, TestDrainingGLib) { namespace { +#if defined(TOOLKIT_USES_GTK) void AddEventsAndDrainGtk(EventInjector* injector) { // Add a couple of dummy events injector->AddEvent(0, NULL); @@ -411,9 +415,11 @@ void AddEventsAndDrainGtk(EventInjector* injector) { gtk_main_iteration(); } } +#endif } // namespace +#if defined(TOOLKIT_USES_GTK) TEST_F(MessagePumpGLibTest, TestDrainingGtk) { // Tests that draining events using Gtk works. loop()->PostTask( @@ -422,6 +428,7 @@ TEST_F(MessagePumpGLibTest, TestDrainingGtk) { EXPECT_EQ(3, injector()->processed_events()); } +#endif namespace { @@ -436,10 +443,16 @@ class GLibLoopRunner : public base::RefCounted<GLibLoopRunner> { } } - void RunGtk() { + void RunLoop() { +#if defined(TOOLKIT_USES_GTK) while (!quit_) { gtk_main_iteration(); } +#else + while (!quit_) { + g_main_context_iteration(NULL, TRUE); + } +#endif } void Quit() { @@ -513,7 +526,7 @@ void TestGtkLoopInternal(EventInjector* injector) { FROM_HERE, NewRunnableMethod(runner.get(), &GLibLoopRunner::Quit), 40); // Run a nested, straight Gtk message loop. - runner->RunGtk(); + runner->RunLoop(); ASSERT_EQ(3, task_count); EXPECT_EQ(4, injector->processed_events()); diff --git a/base/message_pump_x.cc b/base/message_pump_x.cc index 8e098af..b0be50b 100644 --- a/base/message_pump_x.cc +++ b/base/message_pump_x.cc @@ -4,12 +4,15 @@ #include "base/message_pump_x.h" -#include <gdk/gdkx.h> #include <X11/extensions/XInput2.h> #include "base/basictypes.h" #include "base/message_loop.h" +#if defined(TOOLKIT_USES_GTK) +#include <gdk/gdkx.h> +#endif + namespace { gboolean XSourcePrepare(GSource* source, gint* timeout_ms) { @@ -40,10 +43,6 @@ GSourceFuncs XSourceFuncs = { NULL }; -// A flag to disable GTK's message pump. This is intermediate step -// to remove gtk and will be removed once migration is complete. -bool use_gtk_message_pump = true; - // The opcode used for checking events. int xiopcode = -1; @@ -51,11 +50,17 @@ int xiopcode = -1; // connection to the display and owns it. Display* g_xdisplay = NULL; +#if defined(TOOLKIT_USES_GTK) +// A flag to disable GTK's message pump. This is intermediate step +// to remove gtk and will be removed once migration is complete. +bool use_gtk_message_pump = true; + gboolean PlaceholderDispatch(GSource* source, GSourceFunc cb, gpointer data) { return TRUE; } +#endif // defined(TOOLKIT_USES_GTK) void InitializeXInput2(void) { Display* display = base::MessagePumpX::GetDefaultXDisplay(); @@ -83,57 +88,62 @@ void InitializeXInput2(void) { namespace base { MessagePumpX::MessagePumpX() : MessagePumpGlib(), - x_source_(NULL), +#if defined(TOOLKIT_USES_GTK) gdksource_(NULL), dispatching_event_(false), capture_x_events_(0), - capture_gdk_events_(0) { + capture_gdk_events_(0), +#endif + x_source_(NULL) { + InitializeXInput2(); +#if defined(TOOLKIT_USES_GTK) if (use_gtk_message_pump) { gdk_window_add_filter(NULL, &GdkEventFilter, this); gdk_event_handler_set(&EventDispatcherX, this, NULL); } else { - GPollFD* x_poll = new GPollFD(); - x_poll->fd = ConnectionNumber(g_xdisplay); - x_poll->events = G_IO_IN; - - x_source_ = g_source_new(&XSourceFuncs, sizeof(GSource)); - g_source_add_poll(x_source_, x_poll); - g_source_set_can_recurse(x_source_, FALSE); - g_source_attach(x_source_, g_main_context_default()); + InitXSource(); } - - InitializeXInput2(); if (use_gtk_message_pump) InitializeEventsToCapture(); +#else + InitXSource(); +#endif } MessagePumpX::~MessagePumpX() { +#if defined(TOOLKIT_USES_GTK) if (use_gtk_message_pump) { gdk_window_remove_filter(NULL, &GdkEventFilter, this); gdk_event_handler_set(reinterpret_cast<GdkEventFunc>(gtk_main_do_event), this, NULL); - } else { - g_source_destroy(x_source_); - g_source_unref(x_source_); - XCloseDisplay(g_xdisplay); - g_xdisplay = NULL; + return; } +#endif + + g_source_destroy(x_source_); + g_source_unref(x_source_); + XCloseDisplay(g_xdisplay); + g_xdisplay = NULL; } +#if defined(TOOLKIT_USES_GTK) // static void MessagePumpX::DisableGtkMessagePump() { use_gtk_message_pump = false; - g_xdisplay = XOpenDisplay(NULL); } +#endif // static Display* MessagePumpX::GetDefaultXDisplay() { +#if defined(TOOLKIT_USES_GTK) if (use_gtk_message_pump) { static GdkDisplay* display = gdk_display_get_default(); return display ? GDK_DISPLAY_XDISPLAY(display) : NULL; - } else { - return g_xdisplay; } +#endif + if (!g_xdisplay) + g_xdisplay = XOpenDisplay(NULL); + return g_xdisplay; } // static @@ -141,9 +151,24 @@ bool MessagePumpX::HasXInput2() { return xiopcode != -1; } +void MessagePumpX::InitXSource() { + DCHECK(!x_source_); + GPollFD* x_poll = new GPollFD(); + x_poll->fd = ConnectionNumber(g_xdisplay); + x_poll->events = G_IO_IN; + + x_source_ = g_source_new(&XSourceFuncs, sizeof(GSource)); + g_source_add_poll(x_source_, x_poll); + g_source_set_can_recurse(x_source_, FALSE); + g_source_attach(x_source_, g_main_context_default()); +} + bool MessagePumpX::ShouldCaptureXEvent(XEvent* xev) { - return (!use_gtk_message_pump || capture_x_events_[xev->type]) - && (xev->type != GenericEvent || xev->xcookie.extension == xiopcode); + return +#if defined(TOOLKIT_USES_GTK) + (!use_gtk_message_pump || capture_x_events_[xev->type]) && +#endif + (xev->type != GenericEvent || xev->xcookie.extension == xiopcode); } bool MessagePumpX::ProcessXEvent(XEvent* xev) { @@ -187,16 +212,19 @@ bool MessagePumpX::RunOnce(GMainContext* context, bool block) { XNextEvent(display, &xev); if (ProcessXEvent(&xev)) return true; +#if defined(TOOLKIT_USES_GTK) } else if (use_gtk_message_pump && gdksource_) { // TODO(sad): A couple of extra events can still sneak in during this. // Those should be sent back to the X queue from the dispatcher // EventDispatcherX. gdksource_->source_funcs->dispatch = gdkdispatcher_; g_main_context_iteration(context, FALSE); +#endif } } bool retvalue; +#if defined(TOOLKIT_USES_GTK) if (gdksource_ && use_gtk_message_pump) { // Replace the dispatch callback of the GDK event source temporarily so that // it doesn't read events from X. @@ -212,10 +240,14 @@ bool MessagePumpX::RunOnce(GMainContext* context, bool block) { } else { retvalue = g_main_context_iteration(context, block); } +#else + retvalue = g_main_context_iteration(context, block); +#endif return retvalue; } +#if defined(TOOLKIT_USES_GTK) GdkFilterReturn MessagePumpX::GdkEventFilter(GdkXEvent* gxevent, GdkEvent* gevent, gpointer data) { @@ -279,11 +311,13 @@ void MessagePumpX::InitializeEventsToCapture(void) { capture_x_events_[GenericEvent] = true; } +COMPILE_ASSERT(XLASTEvent >= LASTEvent, XLASTEvent_too_small); + +#endif // defined(TOOLKIT_USES_GTK) + MessagePumpObserver::EventStatus MessagePumpObserver::WillProcessXEvent(XEvent* xev) { return EVENT_CONTINUE; } -COMPILE_ASSERT(XLASTEvent >= LASTEvent, XLASTEvent_too_small); - } // namespace base diff --git a/base/message_pump_x.h b/base/message_pump_x.h index c13f323..eab6f6b 100644 --- a/base/message_pump_x.h +++ b/base/message_pump_x.h @@ -11,7 +11,10 @@ #include <bitset> #include <glib.h> + +#if defined(TOOLKIT_USES_GTK) #include <gtk/gtk.h> +#endif typedef union _XEvent XEvent; typedef struct _XDisplay Display; @@ -64,16 +67,14 @@ class BASE_EXPORT MessagePumpX : public MessagePumpGlib { MessagePumpX(); virtual ~MessagePumpX(); - // Indicates whether a GDK event was injected by chrome (when |true|) or if it - // was captured and being processed by GDK (when |false|). - bool IsDispatchingEvent(void) { return dispatching_event_; } - // Overridden from MessagePumpGlib: virtual bool RunOnce(GMainContext* context, bool block) OVERRIDE; +#if defined(TOOLKIT_USES_GTK) // Disables Gtk/Gdk event pumping. This will be used when // NativeWidgetX is enabled. static void DisableGtkMessagePump(); +#endif // Returns default X Display. static Display* GetDefaultXDisplay(); @@ -82,15 +83,8 @@ class BASE_EXPORT MessagePumpX : public MessagePumpGlib { static bool HasXInput2(); private: - // Some XEvent's can't be directly read from X event queue and will go - // through GDK's dispatching process and may get discarded. This function - // sets up a filter to intercept those XEvent's we are interested in - // and dispatches them so that they won't get lost. - static GdkFilterReturn GdkEventFilter(GdkXEvent* gxevent, - GdkEvent* gevent, - gpointer data); - - static void EventDispatcherX(GdkEvent* event, gpointer data); + // Initializes the glib event source for X. + void InitXSource(); // Decides whether we are interested in processing this XEvent. bool ShouldCaptureXEvent(XEvent* event); @@ -103,15 +97,25 @@ class BASE_EXPORT MessagePumpX : public MessagePumpGlib { // not send the event to any other observers and returns true. Returns false // if no observer returns true. bool WillProcessXEvent(XEvent* xevent); +#if defined(TOOLKIT_USES_GTK) + // Some XEvent's can't be directly read from X event queue and will go + // through GDK's dispatching process and may get discarded. This function + // sets up a filter to intercept those XEvent's we are interested in + // and dispatches them so that they won't get lost. + static GdkFilterReturn GdkEventFilter(GdkXEvent* gxevent, + GdkEvent* gevent, + gpointer data); + + static void EventDispatcherX(GdkEvent* event, gpointer data); + + // Indicates whether a GDK event was injected by chrome (when |true|) or if it + // was captured and being processed by GDK (when |false|). + bool IsDispatchingEvent(void) { return dispatching_event_; } // Update the lookup table and flag the events that should be captured and // processed so that GDK doesn't get to them. void InitializeEventsToCapture(void); - // The event source for X events (used only when GTK event processing is - // disabled). - GSource* x_source_; - // The event source for GDK events. GSource* gdksource_; @@ -140,6 +144,11 @@ class BASE_EXPORT MessagePumpX : public MessagePumpGlib { // it should be passed on to the default GDK handler. std::bitset<XLASTEvent> capture_x_events_; std::bitset<GDK_EVENT_LAST> capture_gdk_events_; +#endif // defined(TOOLKIT_USES_GTK) + + // The event source for X events (used only when GTK event processing is + // disabled). + GSource* x_source_; DISALLOW_COPY_AND_ASSIGN(MessagePumpX); }; diff --git a/build/build_config.h b/build/build_config.h index 5c09d45..0a42a47 100644 --- a/build/build_config.h +++ b/build/build_config.h @@ -45,7 +45,7 @@ // A flag derived from the above flags, used to cover GTK code in // both TOOLKIT_GTK and TOOLKIT_VIEWS. -#if defined(TOOLKIT_GTK) || (defined(TOOLKIT_VIEWS) && !defined(OS_WIN)) +#if defined(TOOLKIT_GTK) || (defined(TOOLKIT_VIEWS) && !defined(OS_WIN) && !defined(USE_AURA)) #define TOOLKIT_USES_GTK 1 #endif diff --git a/build/common.gypi b/build/common.gypi index f060eb5..dab183e 100644 --- a/build/common.gypi +++ b/build/common.gypi @@ -234,15 +234,22 @@ # Flags to use Gtk and X11 on non-Mac POSIX platforms ['OS=="win" or OS=="mac"', { + 'use_glib%': 0, 'toolkit_uses_gtk%': 0, 'use_x11%': 0, }, { # TODO(dnicoara) Wayland build should have these disabled, but # currently GTK and X is too spread and it's hard to completely # remove every dependency. + 'use_glib%': 1, 'toolkit_uses_gtk%': 1, 'use_x11%': 1, }], + ['use_aura==1', { + 'use_glib%': 1, + 'toolkit_uses_gtk%': 0, + 'use_x11%': 1, + }], # A flag to enable or disable our compile-time dependency # on gnome-keyring. If that dependency is disabled, no gnome-keyring @@ -300,6 +307,7 @@ 'views_compositor%': '<(views_compositor)', 'use_aura%': '<(use_aura)', 'os_posix%': '<(os_posix)', + 'use_glib%': '<(use_glib)', 'toolkit_uses_gtk%': '<(toolkit_uses_gtk)', 'use_skia%': '<(use_skia)', 'use_x11%': '<(use_x11)', diff --git a/build/linux/system.gyp b/build/linux/system.gyp index 7578552..0a0b4e0 100644 --- a/build/linux/system.gyp +++ b/build/linux/system.gyp @@ -468,6 +468,7 @@ { 'target_name': 'glib', 'type': 'settings', + 'toolsets': ['host', 'target'], 'direct_dependent_settings': { 'cflags': [ '<!@(<(pkg-config) --cflags glib-2.0)', |