diff options
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/gtk/active_window_watcher.cc | 57 | ||||
-rw-r--r-- | chrome/browser/gtk/active_window_watcher.h | 35 | ||||
-rw-r--r-- | chrome/browser/gtk/browser_titlebar.cc | 29 | ||||
-rw-r--r-- | chrome/browser/gtk/browser_titlebar.h | 9 | ||||
-rw-r--r-- | chrome/browser/gtk/browser_window_gtk.cc | 85 | ||||
-rw-r--r-- | chrome/browser/gtk/browser_window_gtk.h | 7 | ||||
-rw-r--r-- | chrome/chrome.gyp | 2 | ||||
-rw-r--r-- | chrome/common/notification_type.h | 4 |
8 files changed, 68 insertions, 160 deletions
diff --git a/chrome/browser/gtk/active_window_watcher.cc b/chrome/browser/gtk/active_window_watcher.cc deleted file mode 100644 index 5028b25..0000000 --- a/chrome/browser/gtk/active_window_watcher.cc +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include <X11/Xlib.h> -#include <gdk/gdk.h> -#include <gdk/gdkx.h> - -#include "chrome/browser/gtk/active_window_watcher.h" -#include "chrome/common/notification_service.h" - -ActiveWindowWatcher::ActiveWindowWatcher() { - Init(); -} - -void ActiveWindowWatcher::Init() { - // Set up X Event filter to listen for PropertyChange X events. These events - // tell us when the active window changes. - GdkWindow* root = gdk_screen_get_root_window(gdk_screen_get_default()); - gdk_window_add_filter(root, &ActiveWindowWatcher::OnWindowXEvent, this); - XSelectInput(GDK_WINDOW_XDISPLAY(root), GDK_WINDOW_XID(root), - PropertyChangeMask); -} - -void ActiveWindowWatcher::NotifyActiveWindowChanged() { - GdkWindow* active_window = gdk_screen_get_active_window( - gdk_screen_get_default()); - - // If the window manager doesn't support _NET_ACTIVE_WINDOW, we don't know - // which window is active and just give up. - if (!active_window) - return; - - NotificationService::current()->Notify( - NotificationType::ACTIVE_WINDOW_CHANGED, - Source<ActiveWindowWatcher>(this), - Details<const GdkWindow>(active_window)); -} - -GdkFilterReturn ActiveWindowWatcher::OnWindowXEvent(GdkXEvent* xevent, - GdkEvent* event, gpointer window_watcher) { - static const GdkAtom kNetActiveWindow = gdk_atom_intern( - "_NET_ACTIVE_WINDOW", FALSE); - static const Atom kNetActiveWindowAtom = gdk_x11_atom_to_xatom_for_display( - gdk_screen_get_display(gdk_screen_get_default()), kNetActiveWindow); - - ActiveWindowWatcher* watcher = reinterpret_cast<ActiveWindowWatcher*>( - window_watcher); - XEvent* xev = static_cast<XEvent*>(xevent); - - if (xev->xany.type == PropertyNotify && - xev->xproperty.atom == kNetActiveWindowAtom) { - watcher->NotifyActiveWindowChanged(); - } - - return GDK_FILTER_CONTINUE; -} diff --git a/chrome/browser/gtk/active_window_watcher.h b/chrome/browser/gtk/active_window_watcher.h deleted file mode 100644 index dc115c6..0000000 --- a/chrome/browser/gtk/active_window_watcher.h +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_GTK_ACTIVE_WINDOW_WATCHER_H_ -#define CHROME_BROWSER_GTK_ACTIVE_WINDOW_WATCHER_H_ - -#include "base/basictypes.h" - -typedef void* gpointer; -typedef void GdkXEvent; -typedef union _GdkEvent GdkEvent; - -// This is a helper class that is used to keep track of which window the window -// manager thinks is active. -class ActiveWindowWatcher { - public: - ActiveWindowWatcher(); - - private: - void Init(); - - // Sends a notification out through the NotificationService that the active - // window has changed. - void NotifyActiveWindowChanged(); - - // Callback for PropertyChange XEvents. - static GdkFilterReturn OnWindowXEvent(GdkXEvent* xevent, - GdkEvent* event, - gpointer window_watcher); - - DISALLOW_COPY_AND_ASSIGN(ActiveWindowWatcher); -}; - -#endif // CHROME_BROWSER_GTK_ACTIVE_WINDOW_WATCHER_H_ diff --git a/chrome/browser/gtk/browser_titlebar.cc b/chrome/browser/gtk/browser_titlebar.cc index 72e03a9..705b4f1 100644 --- a/chrome/browser/gtk/browser_titlebar.cc +++ b/chrome/browser/gtk/browser_titlebar.cc @@ -273,8 +273,11 @@ void BrowserTitlebar::Init() { gtk_widget_show_all(container_); - registrar_.Add(this, NotificationType::ACTIVE_WINDOW_CHANGED, - NotificationService::AllSources()); + ActiveWindowWatcherX::AddObserver(this); +} + +BrowserTitlebar::~BrowserTitlebar() { + ActiveWindowWatcherX::RemoveObserver(this); } CustomDrawButton* BrowserTitlebar::BuildTitlebarButton(int image, @@ -553,22 +556,22 @@ void BrowserTitlebar::Observe(NotificationType type, case NotificationType::BROWSER_THEME_CHANGED: UpdateTextColor(); break; - case NotificationType::ACTIVE_WINDOW_CHANGED: { - // Can be called during shutdown; BrowserWindowGtk will set our |window_| - // to NULL during that time. - if (!window_) - return; - - const GdkWindow* active_window = Details<const GdkWindow>(details).ptr(); - window_has_focus_ = GTK_WIDGET(window_)->window == active_window; - UpdateTextColor(); - break; - } + default: NOTREACHED(); } } +void BrowserTitlebar::ActiveWindowChanged(GdkWindow* active_window) { + // Can be called during shutdown; BrowserWindowGtk will set our |window_| + // to NULL during that time. + if (!window_) + return; + + window_has_focus_ = GTK_WIDGET(window_)->window == active_window; + UpdateTextColor(); +} + /////////////////////////////////////////////////////////////////////////////// // BrowserTitlebar::Throbber implementation // TODO(tc): Handle anti-clockwise spinning when waiting for a connection. diff --git a/chrome/browser/gtk/browser_titlebar.h b/chrome/browser/gtk/browser_titlebar.h index f4508be..84d9236 100644 --- a/chrome/browser/gtk/browser_titlebar.h +++ b/chrome/browser/gtk/browser_titlebar.h @@ -12,6 +12,7 @@ #include <gtk/gtk.h> +#include "app/active_window_watcher_x.h" #include "base/scoped_ptr.h" #include "chrome/browser/gtk/menu_gtk.h" #include "chrome/common/notification_observer.h" @@ -24,10 +25,11 @@ class TabContents; class TabStripGtk; class BrowserTitlebar : public MenuGtk::Delegate, - public NotificationObserver { + public NotificationObserver, + public ActiveWindowWatcherX::Observer { public: BrowserTitlebar(BrowserWindowGtk* browser_window, GtkWindow* window); - virtual ~BrowserTitlebar() { } + virtual ~BrowserTitlebar(); GtkWidget* widget() { return container_; @@ -118,6 +120,9 @@ class BrowserTitlebar : public MenuGtk::Delegate, const NotificationSource& source, const NotificationDetails& details); + // Overriden from ActiveWindowWatcher::Observer. + virtual void ActiveWindowChanged(GdkWindow* active_window); + // Pointers to the browser window that owns us and it's GtkWindow. BrowserWindowGtk* browser_window_; GtkWindow* window_; diff --git a/chrome/browser/gtk/browser_window_gtk.cc b/chrome/browser/gtk/browser_window_gtk.cc index 5bdc1ab..cdcf562 100644 --- a/chrome/browser/gtk/browser_window_gtk.cc +++ b/chrome/browser/gtk/browser_window_gtk.cc @@ -17,7 +17,6 @@ #include "base/command_line.h" #include "base/gfx/gtk_util.h" #include "base/gfx/rect.h" -#include "base/lazy_instance.h" #include "base/logging.h" #include "base/message_loop.h" #include "base/path_service.h" @@ -37,7 +36,6 @@ #include "chrome/browser/download/download_manager.h" #include "chrome/browser/find_bar_controller.h" #include "chrome/browser/gtk/about_chrome_dialog.h" -#include "chrome/browser/gtk/active_window_watcher.h" #include "chrome/browser/gtk/bookmark_bar_gtk.h" #include "chrome/browser/gtk/bookmark_manager_gtk.h" #include "chrome/browser/gtk/browser_titlebar.h" @@ -125,9 +123,6 @@ const int kCustomFrameBackgroundVerticalOffset = 15; // gtk_window_get_position() after the last GTK configure-event signal. const int kDebounceTimeoutMilliseconds = 100; -base::LazyInstance<ActiveWindowWatcher> - g_active_window_watcher(base::LINKER_INITIALIZED); - gboolean MainWindowConfigured(GtkWindow* window, GdkEventConfigure* event, BrowserWindowGtk* browser_win) { gfx::Rect bounds = gfx::Rect(event->x, event->y, event->width, event->height); @@ -568,13 +563,13 @@ BrowserWindowGtk::BrowserWindowGtk(Browser* browser) registrar_.Add(this, NotificationType::BOOKMARK_BAR_VISIBILITY_PREF_CHANGED, NotificationService::AllSources()); - registrar_.Add(this, NotificationType::ACTIVE_WINDOW_CHANGED, - NotificationService::AllSources()); - // Make sure the ActiveWindowWatcher instance exists (it's a lazy instance). - g_active_window_watcher.Get(); + + ActiveWindowWatcherX::AddObserver(this); } BrowserWindowGtk::~BrowserWindowGtk() { + ActiveWindowWatcherX::RemoveObserver(this); + browser_->tabstrip_model()->RemoveObserver(this); if (frame_cursor_) { @@ -1180,43 +1175,6 @@ void BrowserWindowGtk::Observe(NotificationType type, break; } - case NotificationType::ACTIVE_WINDOW_CHANGED: { - // Do nothing if we're in the process of closing the browser window. - if (!window_) - break; - - // If we lose focus to an info bubble, we don't want to seem inactive. - // However we can only control this when we are painting a custom - // frame. So if we lose focus BUT it's to one of our info bubbles AND we - // are painting a custom frame, then paint as if we are active. - const GdkWindow* active_window = Details<const GdkWindow>(details).ptr(); - const GtkWindow* info_bubble_toplevel = - InfoBubbleGtk::GetToplevelForInfoBubble(active_window); - bool is_active = (GTK_WIDGET(window_)->window == active_window || - (window_ == info_bubble_toplevel && UseCustomFrame())); - bool changed = (is_active != is_active_); - - if (is_active && changed) { - // If there's an app modal dialog (e.g., JS alert), try to redirect - // the user's attention to the window owning the dialog. - if (Singleton<AppModalDialogQueue>()->HasActiveDialog()) { - Singleton<AppModalDialogQueue>()->ActivateModalDialog(); - break; - } - } - - is_active_ = is_active; - if (changed) { - SetBackgroundColor(); - gdk_window_invalidate_rect(GTK_WIDGET(window_)->window, - >K_WIDGET(window_)->allocation, TRUE); - // For some reason, the above two calls cause the window shape to be - // lost so reset it. - UpdateWindowShape(bounds_.width(), bounds_.height()); - } - break; - } - default: NOTREACHED() << "Got a notification we didn't register for!"; } @@ -1267,6 +1225,41 @@ void BrowserWindowGtk::TabStripEmpty() { UpdateUIForContents(NULL); } +void BrowserWindowGtk::ActiveWindowChanged(GdkWindow* active_window) { + // Do nothing if we're in the process of closing the browser window. + if (!window_) + return; + + // If we lose focus to an info bubble, we don't want to seem inactive. + // However we can only control this when we are painting a custom + // frame. So if we lose focus BUT it's to one of our info bubbles AND we + // are painting a custom frame, then paint as if we are active. + const GtkWindow* info_bubble_toplevel = + InfoBubbleGtk::GetToplevelForInfoBubble(active_window); + bool is_active = (GTK_WIDGET(window_)->window == active_window || + (window_ == info_bubble_toplevel && UseCustomFrame())); + bool changed = (is_active != is_active_); + + if (is_active && changed) { + // If there's an app modal dialog (e.g., JS alert), try to redirect + // the user's attention to the window owning the dialog. + if (Singleton<AppModalDialogQueue>()->HasActiveDialog()) { + Singleton<AppModalDialogQueue>()->ActivateModalDialog(); + return; + } + } + + is_active_ = is_active; + if (changed) { + SetBackgroundColor(); + gdk_window_invalidate_rect(GTK_WIDGET(window_)->window, + >K_WIDGET(window_)->allocation, TRUE); + // For some reason, the above two calls cause the window shape to be + // lost so reset it. + UpdateWindowShape(bounds_.width(), bounds_.height()); + } +} + void BrowserWindowGtk::MaybeShowBookmarkBar(TabContents* contents, bool animate) { // Don't change the visibility state when the browser is full screen or if diff --git a/chrome/browser/gtk/browser_window_gtk.h b/chrome/browser/gtk/browser_window_gtk.h index 172529a..e216266 100644 --- a/chrome/browser/gtk/browser_window_gtk.h +++ b/chrome/browser/gtk/browser_window_gtk.h @@ -9,6 +9,7 @@ #include <map> +#include "app/active_window_watcher_x.h" #include "base/gfx/rect.h" #include "base/scoped_ptr.h" #include "base/timer.h" @@ -48,7 +49,8 @@ class PanelController; class BrowserWindowGtk : public BrowserWindow, public NotificationObserver, - public TabStripModelObserver { + public TabStripModelObserver, + public ActiveWindowWatcherX::Observer { public: explicit BrowserWindowGtk(Browser* browser); virtual ~BrowserWindowGtk(); @@ -133,6 +135,9 @@ class BrowserWindowGtk : public BrowserWindow, bool user_gesture); virtual void TabStripEmpty(); + // Overriden from ActiveWindowWatcher::Observer. + virtual void ActiveWindowChanged(GdkWindow* active_window); + // Accessor for the tab strip. TabStripGtk* tabstrip() const { return tabstrip_.get(); } diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp index 98c90e1..5cc92e6 100644 --- a/chrome/chrome.gyp +++ b/chrome/chrome.gyp @@ -1315,8 +1315,6 @@ 'browser/google_util.h', 'browser/gtk/about_chrome_dialog.cc', 'browser/gtk/about_chrome_dialog.h', - 'browser/gtk/active_window_watcher.cc', - 'browser/gtk/active_window_watcher.h', 'browser/gtk/back_forward_button_gtk.cc', 'browser/gtk/back_forward_button_gtk.h', 'browser/gtk/back_forward_menu_model_gtk.cc', diff --git a/chrome/common/notification_type.h b/chrome/common/notification_type.h index a11fa49..a3cfd33 100644 --- a/chrome/common/notification_type.h +++ b/chrome/common/notification_type.h @@ -223,10 +223,6 @@ class NotificationType { // The user has changed the browser theme. BROWSER_THEME_CHANGED, - // Fired when the active window changes. This is currently only used on - // Linux. - ACTIVE_WINDOW_CHANGED, - // Sent when the renderer returns focus to the browser, as part of focus // traversal. The source is the browser, there are no details. FOCUS_RETURNED_TO_BROWSER, |