summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/extensions/extension_browser_event_router.cc4
-rw-r--r--chrome/browser/extensions/extension_browser_event_router.h4
-rw-r--r--chrome/browser/ui/gtk/browser_titlebar.cc1
-rw-r--r--chrome/browser/ui/gtk/browser_titlebar.h8
-rw-r--r--chrome/browser/ui/gtk/browser_window_gtk.cc1
-rw-r--r--chrome/browser/ui/gtk/browser_window_gtk.h6
-rw-r--r--chrome/browser/ui/panels/panel_browser_window_gtk.cc8
-rw-r--r--chrome/browser/ui/panels/panel_browser_window_gtk.h12
-rw-r--r--ui/base/x/active_window_watcher_x.cc67
-rw-r--r--ui/base/x/active_window_watcher_x.h43
-rw-r--r--ui/base/x/active_window_watcher_x_observer.h26
-rw-r--r--ui/base/x/root_window_property_watcher_x.cc58
-rw-r--r--ui/base/x/root_window_property_watcher_x.h44
-rw-r--r--ui/base/x/work_area_watcher_x.cc52
-rw-r--r--ui/base/x/work_area_watcher_x.h55
-rw-r--r--ui/base/x/work_area_watcher_x_observer.h23
-rw-r--r--ui/base/x/x11_util.cc18
-rw-r--r--ui/base/x/x11_util.h3
-rw-r--r--ui/ui.gyp19
-rw-r--r--ui/views/widget/native_widget_gtk.cc3
-rw-r--r--ui/views/widget/native_widget_gtk.h6
21 files changed, 363 insertions, 98 deletions
diff --git a/chrome/browser/extensions/extension_browser_event_router.cc b/chrome/browser/extensions/extension_browser_event_router.cc
index 4d6e79a..66d8321 100644
--- a/chrome/browser/extensions/extension_browser_event_router.cc
+++ b/chrome/browser/extensions/extension_browser_event_router.cc
@@ -22,6 +22,10 @@
#include "content/browser/tab_contents/tab_contents.h"
#include "content/public/browser/notification_service.h"
+#if defined(TOOLKIT_GTK)
+#include "ui/base/x/active_window_watcher_x.h"
+#endif
+
namespace events = extension_event_names;
namespace tab_keys = extension_tabs_module_constants;
namespace page_action_keys = extension_page_actions_module_constants;
diff --git a/chrome/browser/extensions/extension_browser_event_router.h b/chrome/browser/extensions/extension_browser_event_router.h
index ce3937b..f0f1703 100644
--- a/chrome/browser/extensions/extension_browser_event_router.h
+++ b/chrome/browser/extensions/extension_browser_event_router.h
@@ -18,7 +18,7 @@
#if defined(TOOLKIT_VIEWS)
#include "ui/views/focus/widget_focus_manager.h"
#elif defined(TOOLKIT_GTK)
-#include "ui/base/x/active_window_watcher_x.h"
+#include "ui/base/x/active_window_watcher_x_observer.h"
#endif
// The ExtensionBrowserEventRouter listens to Browser window & tab events
@@ -30,7 +30,7 @@ class ExtensionBrowserEventRouter : public TabStripModelObserver,
#if defined(TOOLKIT_VIEWS)
public views::WidgetFocusChangeListener,
#elif defined(TOOLKIT_GTK)
- public ui::ActiveWindowWatcherX::Observer,
+ public ui::ActiveWindowWatcherXObserver,
#endif
public BrowserList::Observer,
public content::NotificationObserver {
diff --git a/chrome/browser/ui/gtk/browser_titlebar.cc b/chrome/browser/ui/gtk/browser_titlebar.cc
index 033df67..fe8ca33 100644
--- a/chrome/browser/ui/gtk/browser_titlebar.cc
+++ b/chrome/browser/ui/gtk/browser_titlebar.cc
@@ -49,6 +49,7 @@
#include "ui/base/gtk/gtk_hig_constants.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
+#include "ui/base/x/active_window_watcher_x.h"
#include "ui/gfx/gtk_util.h"
#include "ui/gfx/image/image.h"
#include "ui/gfx/skbitmap_operations.h"
diff --git a/chrome/browser/ui/gtk/browser_titlebar.h b/chrome/browser/ui/gtk/browser_titlebar.h
index 3fcfb4d..9ffbf0e 100644
--- a/chrome/browser/ui/gtk/browser_titlebar.h
+++ b/chrome/browser/ui/gtk/browser_titlebar.h
@@ -19,7 +19,7 @@
#include "content/public/browser/notification_registrar.h"
#include "ui/base/gtk/gtk_signal.h"
#include "ui/base/models/simple_menu_model.h"
-#include "ui/base/x/active_window_watcher_x.h"
+#include "ui/base/x/active_window_watcher_x_observer.h"
class AvatarMenuButtonGtk;
class BrowserWindowGtk;
@@ -30,7 +30,7 @@ class PopupPageMenuModel;
class TabContents;
class BrowserTitlebar : public content::NotificationObserver,
- public ui::ActiveWindowWatcherX::Observer,
+ public ui::ActiveWindowWatcherXObserver,
public ui::SimpleMenuModel::Delegate {
public:
// A default button order string for when we aren't asking gconf for the
@@ -176,8 +176,8 @@ class BrowserTitlebar : public content::NotificationObserver,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE;
- // Overriden from ActiveWindowWatcher::Observer.
- virtual void ActiveWindowChanged(GdkWindow* active_window);
+ // Overriden from ActiveWindowWatcherXObserver.
+ virtual void ActiveWindowChanged(GdkWindow* active_window) OVERRIDE;
bool IsTypePanel();
diff --git a/chrome/browser/ui/gtk/browser_window_gtk.cc b/chrome/browser/ui/gtk/browser_window_gtk.cc
index 5c05e0f..34ae1eb 100644
--- a/chrome/browser/ui/gtk/browser_window_gtk.cc
+++ b/chrome/browser/ui/gtk/browser_window_gtk.cc
@@ -95,6 +95,7 @@
#include "ui/base/gtk/gtk_hig_constants.h"
#include "ui/base/keycodes/keyboard_codes.h"
#include "ui/base/l10n/l10n_util.h"
+#include "ui/base/x/active_window_watcher_x.h"
#include "ui/gfx/gtk_util.h"
#include "ui/gfx/rect.h"
#include "ui/gfx/skia_utils_gtk.h"
diff --git a/chrome/browser/ui/gtk/browser_window_gtk.h b/chrome/browser/ui/gtk/browser_window_gtk.h
index 7f888fa..16ddccb 100644
--- a/chrome/browser/ui/gtk/browser_window_gtk.h
+++ b/chrome/browser/ui/gtk/browser_window_gtk.h
@@ -21,7 +21,7 @@
#include "chrome/browser/ui/browser_window.h"
#include "ui/base/gtk/gtk_signal.h"
#include "ui/base/ui_base_types.h"
-#include "ui/base/x/active_window_watcher_x.h"
+#include "ui/base/x/active_window_watcher_x_observer.h"
#include "ui/base/x/x11_util.h"
#include "ui/gfx/rect.h"
@@ -46,7 +46,7 @@ class TabStripGtk;
class BrowserWindowGtk : public BrowserWindow,
public content::NotificationObserver,
public TabStripModelObserver,
- public ui::ActiveWindowWatcherX::Observer,
+ public ui::ActiveWindowWatcherXObserver,
public InfoBarContainer::Delegate {
public:
enum TitleDecoration {
@@ -174,7 +174,7 @@ class BrowserWindowGtk : public BrowserWindow,
int index,
bool user_gesture) OVERRIDE;
- // Overridden from ActiveWindowWatcher::Observer.
+ // Overridden from ActiveWindowWatcherXObserver.
virtual void ActiveWindowChanged(GdkWindow* active_window) OVERRIDE;
// Overridden from InfoBarContainer::Delegate:
diff --git a/chrome/browser/ui/panels/panel_browser_window_gtk.cc b/chrome/browser/ui/panels/panel_browser_window_gtk.cc
index c9342e0..d934806 100644
--- a/chrome/browser/ui/panels/panel_browser_window_gtk.cc
+++ b/chrome/browser/ui/panels/panel_browser_window_gtk.cc
@@ -13,6 +13,7 @@
#include "content/public/browser/notification_service.h"
#include "ui/base/animation/slide_animation.h"
#include "ui/base/dragdrop/gtk_dnd_util.h"
+#include "ui/base/x/work_area_watcher_x.h"
namespace {
@@ -70,6 +71,7 @@ PanelBrowserWindowGtk::~PanelBrowserWindowGtk() {
DestroyDragWidget();
}
panel_->OnNativePanelClosed();
+ ui::WorkAreaWatcherX::RemoveObserver(this);
}
void PanelBrowserWindowGtk::Init() {
@@ -92,6 +94,8 @@ void PanelBrowserWindowGtk::Init() {
G_CALLBACK(OnTitlebarButtonPressEventThunk), this);
g_signal_connect(titlebar_widget(), "button-release-event",
G_CALLBACK(OnTitlebarButtonReleaseEventThunk), this);
+
+ ui::WorkAreaWatcherX::AddObserver(this);
}
bool PanelBrowserWindowGtk::GetWindowEdge(int x, int y, GdkWindowEdge* edge) {
@@ -225,6 +229,10 @@ BrowserWindowGtk::TitleDecoration PanelBrowserWindowGtk::GetWindowTitle(
}
}
+void PanelBrowserWindowGtk::WorkAreaChanged() {
+ panel_->manager()->OnDisplayChanged();
+}
+
void PanelBrowserWindowGtk::ShowPanel() {
Show();
}
diff --git a/chrome/browser/ui/panels/panel_browser_window_gtk.h b/chrome/browser/ui/panels/panel_browser_window_gtk.h
index 8f6c447..0b111bf 100644
--- a/chrome/browser/ui/panels/panel_browser_window_gtk.h
+++ b/chrome/browser/ui/panels/panel_browser_window_gtk.h
@@ -10,6 +10,7 @@
#include "chrome/browser/ui/gtk/menu_gtk.h"
#include "chrome/browser/ui/panels/native_panel.h"
#include "ui/base/animation/animation_delegate.h"
+#include "ui/base/x/work_area_watcher_x_observer.h"
class Panel;
class PanelSettingsMenuModel;
@@ -22,17 +23,18 @@ class SlideAnimation;
}
class PanelBrowserWindowGtk : public BrowserWindowGtk,
- public NativePanel,
public MenuGtk::Delegate,
public MessageLoopForUI::Observer,
- public ui::AnimationDelegate {
+ public NativePanel,
+ public ui::AnimationDelegate,
+ public ui::WorkAreaWatcherXObserver {
friend class NativePanelTestingGtk;
public:
PanelBrowserWindowGtk(Browser* browser, Panel* panel,
const gfx::Rect& bounds);
virtual ~PanelBrowserWindowGtk();
- // BrowserWindowGtk overrides
+ // BrowserWindowGtk override
virtual void Init() OVERRIDE;
// BrowserWindow overrides
@@ -41,6 +43,9 @@ class PanelBrowserWindowGtk : public BrowserWindowGtk,
GdkEventButton* event) OVERRIDE;
virtual TitleDecoration GetWindowTitle(std::string* title) const OVERRIDE;
+ // ui::WorkAreaWatcherXObserver override
+ virtual void WorkAreaChanged() OVERRIDE;
+
protected:
// BrowserWindowGtk overrides
virtual bool GetWindowEdge(int x, int y, GdkWindowEdge* edge) OVERRIDE;
@@ -59,7 +64,6 @@ class PanelBrowserWindowGtk : public BrowserWindowGtk,
virtual void HandleFocusIn(GtkWidget* widget,
GdkEventFocus* event) OVERRIDE;
-
// Overridden from NativePanel:
virtual void ShowPanel() OVERRIDE;
virtual void ShowPanelInactive() OVERRIDE;
diff --git a/ui/base/x/active_window_watcher_x.cc b/ui/base/x/active_window_watcher_x.cc
index 01c4a88..10cec2d 100644
--- a/ui/base/x/active_window_watcher_x.cc
+++ b/ui/base/x/active_window_watcher_x.cc
@@ -2,15 +2,18 @@
// 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 "ui/base/x/active_window_watcher_x.h"
+
#include <gdk/gdk.h>
#include <gdk/gdkx.h>
-#include "ui/base/x/active_window_watcher_x.h"
+#include "ui/base/x/active_window_watcher_x_observer.h"
+#include "ui/base/x/root_window_property_watcher_x.h"
+#include "ui/base/x/x11_util.h"
namespace ui {
-static Atom g_net_active_window_atom = None;
+static const char* const kNetActiveWindow = "_NET_ACTIVE_WINDOW";
// static
ActiveWindowWatcherX* ActiveWindowWatcherX::GetInstance() {
@@ -18,47 +21,41 @@ ActiveWindowWatcherX* ActiveWindowWatcherX::GetInstance() {
}
// static
-void ActiveWindowWatcherX::AddObserver(Observer* observer) {
+void ActiveWindowWatcherX::AddObserver(ActiveWindowWatcherXObserver* observer) {
+ // Ensure that RootWindowPropertyWatcherX exists.
+ internal::RootWindowPropertyWatcherX::GetInstance();
GetInstance()->observers_.AddObserver(observer);
}
// static
-void ActiveWindowWatcherX::RemoveObserver(Observer* observer) {
+void ActiveWindowWatcherX::RemoveObserver(
+ ActiveWindowWatcherXObserver* observer) {
GetInstance()->observers_.RemoveObserver(observer);
}
// static
+Atom ActiveWindowWatcherX::GetPropertyAtom() {
+ return GetAtom(kNetActiveWindow);
+}
+
+// static
+void ActiveWindowWatcherX::Notify() {
+ GetInstance()->NotifyActiveWindowChanged();
+}
+
+// static
bool ActiveWindowWatcherX::WMSupportsActivation() {
return gdk_x11_screen_supports_net_wm_hint(
gdk_screen_get_default(),
- gdk_atom_intern_static_string("_NET_ACTIVE_WINDOW"));
+ gdk_atom_intern_static_string(kNetActiveWindow));
}
ActiveWindowWatcherX::ActiveWindowWatcherX() {
- Init();
}
ActiveWindowWatcherX::~ActiveWindowWatcherX() {
}
-void ActiveWindowWatcherX::Init() {
- GdkAtom net_active_window =
- gdk_atom_intern_static_string("_NET_ACTIVE_WINDOW");
- g_net_active_window_atom = gdk_x11_atom_to_xatom_for_display(
- gdk_screen_get_display(gdk_screen_get_default()), net_active_window);
-
- GdkWindow* root = gdk_get_default_root_window();
-
- // Set up X Event filter to listen for PropertyChange X events. These events
- // tell us when the active window changes.
- // Don't use XSelectInput directly here, as gdk internally seems to cache the
- // mask and reapply XSelectInput after this, resetting any mask we set here.
- gdk_window_set_events(root,
- static_cast<GdkEventMask>(gdk_window_get_events(root) |
- GDK_PROPERTY_CHANGE_MASK));
- gdk_window_add_filter(NULL, &ActiveWindowWatcherX::OnWindowXEventThunk, this);
-}
-
void ActiveWindowWatcherX::NotifyActiveWindowChanged() {
// We don't use gdk_screen_get_active_window() because it caches
// whether or not the window manager supports _NET_ACTIVE_WINDOW.
@@ -70,7 +67,7 @@ void ActiveWindowWatcherX::NotifyActiveWindowChanged() {
XGetWindowProperty(gdk_x11_get_default_xdisplay(),
GDK_WINDOW_XID(gdk_get_default_root_window()),
- g_net_active_window_atom,
+ GetAtom(kNetActiveWindow),
0, // offset into property data to read
1, // length to get in 32-bit quantities
False, // deleted
@@ -88,25 +85,11 @@ void ActiveWindowWatcherX::NotifyActiveWindowChanged() {
if (format == 32 && num_items == 1) {
int xid = *reinterpret_cast<int*>(property);
GdkWindow* active_window = gdk_window_lookup(xid);
- FOR_EACH_OBSERVER(
- Observer,
- observers_,
- ActiveWindowChanged(active_window));
+ FOR_EACH_OBSERVER(ActiveWindowWatcherXObserver, observers_,
+ ActiveWindowChanged(active_window));
}
if (property)
XFree(property);
}
-GdkFilterReturn ActiveWindowWatcherX::OnWindowXEvent(GdkXEvent* xevent,
- GdkEvent* event) {
- XEvent* xev = static_cast<XEvent*>(xevent);
-
- if (xev->xany.type == PropertyNotify &&
- xev->xproperty.atom == g_net_active_window_atom) {
- NotifyActiveWindowChanged();
- }
-
- return GDK_FILTER_CONTINUE;
-}
-
} // namespace ui
diff --git a/ui/base/x/active_window_watcher_x.h b/ui/base/x/active_window_watcher_x.h
index 4fa6b65..0358ecb 100644
--- a/ui/base/x/active_window_watcher_x.h
+++ b/ui/base/x/active_window_watcher_x.h
@@ -6,34 +6,28 @@
#define UI_BASE_X_ACTIVE_WINDOW_WATCHER_X_H_
#pragma once
-#include <gdk/gdk.h>
-
#include "base/basictypes.h"
#include "base/memory/singleton.h"
#include "base/observer_list.h"
-#include "ui/base/gtk/gtk_signal.h"
#include "ui/base/ui_export.h"
+#include "ui/base/x/x11_util.h"
namespace ui {
+class ActiveWindowWatcherXObserver;
+
+namespace internal {
+class RootWindowPropertyWatcherX;
+}
+
// This is a helper class that is used to keep track of which window the X
-// window manager thinks is active. Add an Observer to listener for changes to
+// window manager thinks is active. Add an Observer to listen for changes to
// the active window.
class UI_EXPORT ActiveWindowWatcherX {
public:
- class Observer {
- public:
- // |active_window| will be NULL if the active window isn't one of Chrome's.
- virtual void ActiveWindowChanged(GdkWindow* active_window) = 0;
-
- protected:
- virtual ~Observer() {}
- };
-
static ActiveWindowWatcherX* GetInstance();
-
- static void AddObserver(Observer* observer);
- static void RemoveObserver(Observer* observer);
+ static void AddObserver(ActiveWindowWatcherXObserver* observer);
+ static void RemoveObserver(ActiveWindowWatcherXObserver* observer);
// Checks if the WM supports the active window property. Note that the return
// value can change, especially during system startup.
@@ -41,21 +35,22 @@ class UI_EXPORT ActiveWindowWatcherX {
private:
friend struct DefaultSingletonTraits<ActiveWindowWatcherX>;
+ friend class ui::internal::RootWindowPropertyWatcherX;
ActiveWindowWatcherX();
~ActiveWindowWatcherX();
- void Init();
+ // Gets the atom for the default display for the property this class is
+ // watching for.
+ static Atom GetPropertyAtom();
- // Sends a notification out through the NotificationService that the active
- // window has changed.
- void NotifyActiveWindowChanged();
+ // Notify observers that the active window has changed.
+ static void Notify();
- // Callback for PropertyChange XEvents.
- CHROMEG_CALLBACK_1(ActiveWindowWatcherX, GdkFilterReturn,
- OnWindowXEvent, GdkXEvent*, GdkEvent*);
+ // Instance method that implements Notify().
+ void NotifyActiveWindowChanged();
- ObserverList<Observer> observers_;
+ ObserverList<ActiveWindowWatcherXObserver> observers_;
DISALLOW_COPY_AND_ASSIGN(ActiveWindowWatcherX);
};
diff --git a/ui/base/x/active_window_watcher_x_observer.h b/ui/base/x/active_window_watcher_x_observer.h
new file mode 100644
index 0000000..5369676
--- /dev/null
+++ b/ui/base/x/active_window_watcher_x_observer.h
@@ -0,0 +1,26 @@
+// Copyright (c) 2011 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 UI_BASE_X_ACTIVE_WINDOW_WATCHER_X_OBSERVER_H_
+#define UI_BASE_X_ACTIVE_WINDOW_WATCHER_X_OBSERVER_H_
+#pragma once
+
+#include <gdk/gdk.h>
+
+#include "ui/base/ui_export.h"
+
+namespace ui {
+
+class UI_EXPORT ActiveWindowWatcherXObserver {
+ public:
+ // |active_window| will be NULL if the active window isn't one of Chrome's.
+ virtual void ActiveWindowChanged(GdkWindow* active_window) = 0;
+
+ protected:
+ virtual ~ActiveWindowWatcherXObserver() {}
+};
+
+} // namespace ui
+
+#endif // UI_BASE_X_ACTIVE_WINDOW_WATCHER_X_OBSERVER_H_
diff --git a/ui/base/x/root_window_property_watcher_x.cc b/ui/base/x/root_window_property_watcher_x.cc
new file mode 100644
index 0000000..de8b61e
--- /dev/null
+++ b/ui/base/x/root_window_property_watcher_x.cc
@@ -0,0 +1,58 @@
+// Copyright (c) 2011 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 "ui/base/x/root_window_property_watcher_x.h"
+
+#include <gdk/gdk.h>
+#include <gdk/gdkx.h>
+
+#include "ui/base/x/active_window_watcher_x.h"
+#include "ui/base/x/work_area_watcher_x.h"
+
+namespace ui {
+
+namespace internal {
+
+// static
+RootWindowPropertyWatcherX* RootWindowPropertyWatcherX::GetInstance() {
+ return Singleton<RootWindowPropertyWatcherX>::get();
+}
+
+RootWindowPropertyWatcherX::RootWindowPropertyWatcherX() {
+ GdkWindow* root = gdk_get_default_root_window();
+
+ // Set up X Event filter to listen for PropertyChange X events.
+ // Don't use XSelectInput directly here, as gdk internally seems to cache the
+ // mask and reapply XSelectInput after this, resetting any mask we set here.
+ gdk_window_set_events(root,
+ static_cast<GdkEventMask>(gdk_window_get_events(root) |
+ GDK_PROPERTY_CHANGE_MASK));
+ gdk_window_add_filter(root,
+ &RootWindowPropertyWatcherX::OnWindowXEventThunk,
+ this);
+}
+
+RootWindowPropertyWatcherX::~RootWindowPropertyWatcherX() {
+ gdk_window_remove_filter(NULL,
+ &RootWindowPropertyWatcherX::OnWindowXEventThunk,
+ this);
+}
+
+GdkFilterReturn RootWindowPropertyWatcherX::OnWindowXEvent(
+ GdkXEvent* xevent, GdkEvent* event) {
+ XEvent* xev = static_cast<XEvent*>(xevent);
+
+ if (xev->xany.type == PropertyNotify) {
+ if (xev->xproperty.atom == ActiveWindowWatcherX::GetPropertyAtom())
+ ActiveWindowWatcherX::Notify();
+ else if (xev->xproperty.atom == WorkAreaWatcherX::GetPropertyAtom())
+ WorkAreaWatcherX::Notify();
+ }
+
+ return GDK_FILTER_CONTINUE;
+}
+
+} // namespace internal
+
+} // namespace ui
diff --git a/ui/base/x/root_window_property_watcher_x.h b/ui/base/x/root_window_property_watcher_x.h
new file mode 100644
index 0000000..6684e83
--- /dev/null
+++ b/ui/base/x/root_window_property_watcher_x.h
@@ -0,0 +1,44 @@
+// Copyright (c) 2011 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 UI_BASE_X_ROOT_WINDOW_PROPERTY_WATCHER_X_H_
+#define UI_BASE_X_ROOT_WINDOW_PROPERTY_WATCHER_X_H_
+#pragma once
+
+#include <gdk/gdk.h>
+
+#include "base/basictypes.h"
+#include "base/memory/singleton.h"
+#include "ui/base/gtk/gtk_signal.h"
+#include "ui/base/ui_export.h"
+
+namespace ui {
+
+namespace internal {
+
+// This class keeps track of changes to properties on the root window. This is
+// not to be used directly. Implement a watcher for the specific property you're
+// interested in.
+class RootWindowPropertyWatcherX {
+ public:
+ static RootWindowPropertyWatcherX* GetInstance();
+
+ private:
+ friend struct DefaultSingletonTraits<RootWindowPropertyWatcherX>;
+
+ RootWindowPropertyWatcherX();
+ ~RootWindowPropertyWatcherX();
+
+ // Callback for PropertyChange XEvents.
+ CHROMEG_CALLBACK_1(RootWindowPropertyWatcherX, GdkFilterReturn,
+ OnWindowXEvent, GdkXEvent*, GdkEvent*);
+
+ DISALLOW_COPY_AND_ASSIGN(RootWindowPropertyWatcherX);
+};
+
+} // namespace internal
+
+} // namespace ui
+
+#endif // UI_BASE_X_ROOT_WINDOW_PROPERTY_WATCHER_X_H_
diff --git a/ui/base/x/work_area_watcher_x.cc b/ui/base/x/work_area_watcher_x.cc
new file mode 100644
index 0000000..4fd98c9
--- /dev/null
+++ b/ui/base/x/work_area_watcher_x.cc
@@ -0,0 +1,52 @@
+// Copyright (c) 2011 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 "ui/base/x/work_area_watcher_x.h"
+
+#include "ui/base/x/root_window_property_watcher_x.h"
+#include "ui/base/x/work_area_watcher_x_observer.h"
+#include "ui/base/x/x11_util.h"
+
+namespace ui {
+
+static const char* const kNetWorkArea = "_NET_WORKAREA";
+
+// static
+WorkAreaWatcherX* WorkAreaWatcherX::GetInstance() {
+ return Singleton<WorkAreaWatcherX>::get();
+}
+
+// static
+void WorkAreaWatcherX::AddObserver(WorkAreaWatcherXObserver* observer) {
+ // Ensure that RootWindowPropertyWatcherX exists.
+ internal::RootWindowPropertyWatcherX::GetInstance();
+ GetInstance()->observers_.AddObserver(observer);
+}
+
+// static
+void WorkAreaWatcherX::RemoveObserver(WorkAreaWatcherXObserver* observer) {
+ GetInstance()->observers_.RemoveObserver(observer);
+}
+
+// static
+void WorkAreaWatcherX::Notify() {
+ GetInstance()->NotifyWorkAreaChanged();
+}
+
+// static
+Atom WorkAreaWatcherX::GetPropertyAtom() {
+ return GetAtom(kNetWorkArea);
+}
+
+WorkAreaWatcherX::WorkAreaWatcherX() {
+}
+
+WorkAreaWatcherX::~WorkAreaWatcherX() {
+}
+
+void WorkAreaWatcherX::NotifyWorkAreaChanged() {
+ FOR_EACH_OBSERVER(WorkAreaWatcherXObserver, observers_, WorkAreaChanged());
+}
+
+} // namespace ui
diff --git a/ui/base/x/work_area_watcher_x.h b/ui/base/x/work_area_watcher_x.h
new file mode 100644
index 0000000..22fcb76
--- /dev/null
+++ b/ui/base/x/work_area_watcher_x.h
@@ -0,0 +1,55 @@
+// Copyright (c) 2011 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 UI_BASE_X_WORK_AREA_WATCHER_X_H_
+#define UI_BASE_X_WORK_AREA_WATCHER_X_H_
+#pragma once
+
+#include "base/basictypes.h"
+#include "base/memory/singleton.h"
+#include "base/observer_list.h"
+#include "ui/base/ui_export.h"
+#include "ui/base/x/x11_util.h"
+
+namespace ui {
+
+class WorkAreaWatcherXObserver;
+
+namespace internal {
+class RootWindowPropertyWatcherX;
+}
+
+// This is a helper class that is used to keep track of changes to work area.
+// Add an observer to track changes.
+class UI_EXPORT WorkAreaWatcherX {
+ public:
+ static WorkAreaWatcherX* GetInstance();
+ static void AddObserver(WorkAreaWatcherXObserver* observer);
+ static void RemoveObserver(WorkAreaWatcherXObserver* observer);
+
+ private:
+ friend struct DefaultSingletonTraits<WorkAreaWatcherX>;
+ friend class ui::internal::RootWindowPropertyWatcherX;
+
+ WorkAreaWatcherX();
+ ~WorkAreaWatcherX();
+
+ // Gets the atom for the default display for the property this class is
+ // watching for.
+ static Atom GetPropertyAtom();
+
+ // Notify observers that the work area has changed.
+ static void Notify();
+
+ // Instance method that implements Notify().
+ void NotifyWorkAreaChanged();
+
+ ObserverList<WorkAreaWatcherXObserver> observers_;
+
+ DISALLOW_COPY_AND_ASSIGN(WorkAreaWatcherX);
+};
+
+} // namespace ui
+
+#endif // UI_BASE_X_WORK_AREA_WATCHER_X_H_
diff --git a/ui/base/x/work_area_watcher_x_observer.h b/ui/base/x/work_area_watcher_x_observer.h
new file mode 100644
index 0000000..b0c562b
--- /dev/null
+++ b/ui/base/x/work_area_watcher_x_observer.h
@@ -0,0 +1,23 @@
+// Copyright (c) 2011 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 UI_BASE_X_WORK_AREA_WATCHER_X_OBSERVER_H_
+#define UI_BASE_X_WORK_AREA_WATCHER_X_OBSERVER_H_
+#pragma once
+
+#include "ui/base/ui_export.h"
+
+namespace ui {
+
+class UI_EXPORT WorkAreaWatcherXObserver {
+ public:
+ virtual void WorkAreaChanged() = 0;
+
+ protected:
+ virtual ~WorkAreaWatcherXObserver() {}
+};
+
+} // namespace ui
+
+#endif // UI_BASE_X_WORK_AREA_WATCHER_X_OBSERVER_H_
diff --git a/ui/base/x/x11_util.cc b/ui/base/x/x11_util.cc
index aa11de8..98faee5 100644
--- a/ui/base/x/x11_util.cc
+++ b/ui/base/x/x11_util.cc
@@ -80,15 +80,6 @@ int DefaultX11IOErrorHandler(Display* d) {
_exit(1);
}
-Atom GetAtom(const char* name) {
-#if defined(TOOLKIT_USES_GTK)
- return gdk_x11_get_xatom_by_name_for_display(
- gdk_display_get_default(), name);
-#else
- return XInternAtom(GetXDisplay(), name, false);
-#endif
-}
-
// Note: The caller should free the resulting value data.
bool GetProperty(XID window, const std::string& property_name, long max_length,
Atom* type, int* format, unsigned long* num_items,
@@ -429,6 +420,15 @@ bool GetStringProperty(
return true;
}
+Atom GetAtom(const char* name) {
+#if defined(TOOLKIT_USES_GTK)
+ return gdk_x11_get_xatom_by_name_for_display(
+ gdk_display_get_default(), name);
+#else
+ return XInternAtom(GetXDisplay(), name, false);
+#endif
+}
+
XID GetParentWindow(XID window) {
XID root = None;
XID parent = None;
diff --git a/ui/base/x/x11_util.h b/ui/base/x/x11_util.h
index 888e76a..4f2fe33 100644
--- a/ui/base/x/x11_util.h
+++ b/ui/base/x/x11_util.h
@@ -123,6 +123,9 @@ UI_EXPORT bool GetAtomArrayProperty(XID window,
UI_EXPORT bool GetStringProperty(
XID window, const std::string& property_name, std::string* value);
+// Gets the X atom for default display corresponding to atom_name.
+Atom GetAtom(const char* atom_name);
+
// Get |window|'s parent window, or None if |window| is the root window.
XID GetParentWindow(XID window);
diff --git a/ui/ui.gyp b/ui/ui.gyp
index d173b95..347ba80 100644
--- a/ui/ui.gyp
+++ b/ui/ui.gyp
@@ -225,7 +225,13 @@
'base/win/window_impl.h',
'base/x/active_window_watcher_x.cc',
'base/x/active_window_watcher_x.h',
+ 'base/x/active_window_watcher_x_observer.h',
'base/x/events_x.cc',
+ 'base/x/root_window_property_watcher_x.cc',
+ 'base/x/root_window_property_watcher_x.h',
+ 'base/x/work_area_watcher_x.cc',
+ 'base/x/work_area_watcher_x.h',
+ 'base/x/work_area_watcher_x_observer.h',
'base/x/x11_util.cc',
'base/x/x11_util.h',
'base/x/x11_util_internal.h',
@@ -346,6 +352,12 @@
['exclude', 'base/win/mouse_wheel_util.h'],
['exclude', 'base/x/active_window_watcher_x.cc'],
['exclude', 'base/x/active_window_watcher_x.h'],
+ ['exclude', 'base/x/active_window_watcher_x_observer.h'],
+ ['exclude', 'base/x/root_window_property_watcher_x.cc'],
+ ['exclude', 'base/x/root_window_property_watcher_x.h'],
+ ['exclude', 'base/x/work_area_watcher_x.cc'],
+ ['exclude', 'base/x/work_area_watcher_x.h'],
+ ['exclude', 'base/x/work_area_watcher_x_observer.h'],
],
}, { # use_aura!=1
'sources!': [
@@ -542,12 +554,7 @@
'sources!': [
'base/keycodes/keyboard_code_conversion_x.cc',
'base/keycodes/keyboard_code_conversion_x.h',
- 'base/x/active_window_watcher_x.cc',
- 'base/x/active_window_watcher_x.h',
- 'base/x/events_x.cc',
- 'base/x/x11_util.cc',
- 'base/x/x11_util.h',
- 'base/x/x11_util_internal.h',
+ 'base/x/',
],
}],
['chromeos==1', {
diff --git a/ui/views/widget/native_widget_gtk.cc b/ui/views/widget/native_widget_gtk.cc
index 2d6556f..4e60e70 100644
--- a/ui/views/widget/native_widget_gtk.cc
+++ b/ui/views/widget/native_widget_gtk.cc
@@ -26,6 +26,7 @@
#include "ui/base/gtk/gtk_windowing.h"
#include "ui/base/gtk/scoped_handle_gtk.h"
#include "ui/base/hit_test.h"
+#include "ui/base/x/active_window_watcher_x.h"
#include "ui/base/x/x11_util.h"
#include "ui/gfx/canvas_skia_paint.h"
#include "ui/gfx/compositor/compositor.h"
@@ -560,7 +561,7 @@ void NativeWidgetGtk::GetRequestedSize(gfx::Size* out) const {
}
////////////////////////////////////////////////////////////////////////////////
-// NativeWidgetGtk, ActiveWindowWatcherX::Observer implementation:
+// NativeWidgetGtk, ActiveWindowWatcherXObserver implementation:
void NativeWidgetGtk::ActiveWindowChanged(GdkWindow* active_window) {
if (!GetNativeView())
diff --git a/ui/views/widget/native_widget_gtk.h b/ui/views/widget/native_widget_gtk.h
index 327edb3..373eccb 100644
--- a/ui/views/widget/native_widget_gtk.h
+++ b/ui/views/widget/native_widget_gtk.h
@@ -12,7 +12,7 @@
#include "base/memory/weak_ptr.h"
#include "base/message_loop.h"
#include "ui/base/gtk/gtk_signal.h"
-#include "ui/base/x/active_window_watcher_x.h"
+#include "ui/base/x/active_window_watcher_x_observer.h"
#include "ui/gfx/compositor/compositor.h"
#include "ui/gfx/size.h"
#include "ui/views/focus/focus_manager.h"
@@ -44,7 +44,7 @@ class NativeWidgetDelegate;
// Widget implementation for GTK.
class VIEWS_EXPORT NativeWidgetGtk : public internal::NativeWidgetPrivate,
public ui::CompositorDelegate,
- public ui::ActiveWindowWatcherX::Observer {
+ public ui::ActiveWindowWatcherXObserver {
public:
explicit NativeWidgetGtk(internal::NativeWidgetDelegate* delegate);
virtual ~NativeWidgetGtk();
@@ -104,7 +104,7 @@ class VIEWS_EXPORT NativeWidgetGtk : public internal::NativeWidgetPrivate,
// size of other kinds of widgets.
void GetRequestedSize(gfx::Size* out) const;
- // Overridden from ui::ActiveWindowWatcherX::Observer.
+ // Overridden from ui::ActiveWindowWatcherXObserver.
virtual void ActiveWindowChanged(GdkWindow* active_window) OVERRIDE;
// Handles a keyboard event by sending it to our focus manager.