Move all chromium's code under chromium_src.
This commit is contained in:
parent
1f99a97544
commit
64bf1bcb9f
39 changed files with 594 additions and 53 deletions
|
@ -0,0 +1,93 @@
|
|||
// Copyright (c) 2012 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/accelerators/platform_accelerator_gtk.h"
|
||||
|
||||
#include "ui/events/keycodes/keyboard_code_conversion_gtk.h"
|
||||
|
||||
namespace ui {
|
||||
|
||||
namespace {
|
||||
|
||||
int GdkModifierToEventFlag(GdkModifierType gdk_modifier) {
|
||||
int event_flags = 0;
|
||||
if (gdk_modifier & GDK_SHIFT_MASK)
|
||||
event_flags |= EF_SHIFT_DOWN;
|
||||
if (gdk_modifier & GDK_CONTROL_MASK)
|
||||
event_flags |= EF_CONTROL_DOWN;
|
||||
if (gdk_modifier & GDK_MOD1_MASK)
|
||||
event_flags |= EF_ALT_DOWN;
|
||||
return event_flags;
|
||||
}
|
||||
|
||||
GdkModifierType EventFlagToGdkModifier(int event_flag) {
|
||||
int modifier = 0;
|
||||
if (event_flag & EF_SHIFT_DOWN)
|
||||
modifier |= GDK_SHIFT_MASK;
|
||||
if (event_flag & EF_CONTROL_DOWN)
|
||||
modifier |= GDK_CONTROL_MASK;
|
||||
if (event_flag & EF_ALT_DOWN)
|
||||
modifier |= GDK_MOD1_MASK;
|
||||
return static_cast<GdkModifierType>(modifier);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
PlatformAcceleratorGtk::PlatformAcceleratorGtk()
|
||||
: gdk_key_code_(0),
|
||||
gdk_modifier_(static_cast<GdkModifierType>(0)) {
|
||||
}
|
||||
|
||||
PlatformAcceleratorGtk::PlatformAcceleratorGtk(guint gdk_key_code,
|
||||
GdkModifierType gdk_modifier)
|
||||
: gdk_key_code_(gdk_key_code),
|
||||
gdk_modifier_(gdk_modifier) {
|
||||
}
|
||||
|
||||
PlatformAcceleratorGtk::~PlatformAcceleratorGtk() {
|
||||
}
|
||||
|
||||
scoped_ptr<PlatformAccelerator> PlatformAcceleratorGtk::CreateCopy() const {
|
||||
scoped_ptr<PlatformAcceleratorGtk> copy(new PlatformAcceleratorGtk);
|
||||
copy->gdk_key_code_ = gdk_key_code_;
|
||||
copy->gdk_modifier_ = gdk_modifier_;
|
||||
return scoped_ptr<PlatformAccelerator>(copy.release());
|
||||
}
|
||||
|
||||
bool PlatformAcceleratorGtk::Equals(const PlatformAccelerator& rhs) const {
|
||||
const PlatformAcceleratorGtk& rhs_gtk =
|
||||
static_cast<const PlatformAcceleratorGtk&>(rhs);
|
||||
return gdk_key_code_ == rhs_gtk.gdk_key_code_ &&
|
||||
gdk_modifier_ == rhs_gtk.gdk_modifier_;
|
||||
}
|
||||
|
||||
Accelerator AcceleratorForGdkKeyCodeAndModifier(guint gdk_key_code,
|
||||
GdkModifierType gdk_modifier) {
|
||||
ui::Accelerator accelerator(ui::WindowsKeyCodeForGdkKeyCode(gdk_key_code),
|
||||
ui::GdkModifierToEventFlag(gdk_modifier));
|
||||
scoped_ptr<PlatformAccelerator> platform_accelerator(
|
||||
new PlatformAcceleratorGtk(gdk_key_code, gdk_modifier));
|
||||
accelerator.set_platform_accelerator(platform_accelerator.Pass());
|
||||
return accelerator;
|
||||
}
|
||||
|
||||
guint GetGdkKeyCodeForAccelerator(const Accelerator& accelerator) {
|
||||
if (accelerator.platform_accelerator()) {
|
||||
return static_cast<const PlatformAcceleratorGtk*>(
|
||||
accelerator.platform_accelerator())->gdk_key_code();
|
||||
}
|
||||
// The second parameter is false because accelerator keys are expressed in
|
||||
// terms of the non-shift-modified key.
|
||||
return GdkKeyCodeForWindowsKeyCode(accelerator.key_code(), false);
|
||||
}
|
||||
|
||||
GdkModifierType GetGdkModifierForAccelerator(const Accelerator& accelerator) {
|
||||
if (accelerator.platform_accelerator()) {
|
||||
return static_cast<const PlatformAcceleratorGtk*>(
|
||||
accelerator.platform_accelerator())->gdk_modifier();
|
||||
}
|
||||
return EventFlagToGdkModifier(accelerator.modifiers());
|
||||
}
|
||||
|
||||
} // namespace ui
|
49
chromium_src/ui/base/accelerators/platform_accelerator_gtk.h
Normal file
49
chromium_src/ui/base/accelerators/platform_accelerator_gtk.h
Normal file
|
@ -0,0 +1,49 @@
|
|||
// Copyright (c) 2012 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_ACCELERATORS_PLATFORM_ACCELERATOR_GTK_H_
|
||||
#define UI_BASE_ACCELERATORS_PLATFORM_ACCELERATOR_GTK_H_
|
||||
|
||||
#include <gdk/gdk.h>
|
||||
|
||||
#include "base/compiler_specific.h"
|
||||
#include "ui/base/accelerators/accelerator.h"
|
||||
#include "ui/base/accelerators/platform_accelerator.h"
|
||||
|
||||
namespace ui {
|
||||
|
||||
class Accelerator;
|
||||
|
||||
// This is a GTK specific class for specifing accelerator keys.
|
||||
class UI_BASE_EXPORT PlatformAcceleratorGtk : public PlatformAccelerator {
|
||||
public:
|
||||
PlatformAcceleratorGtk();
|
||||
PlatformAcceleratorGtk(guint gdk_key_code, GdkModifierType gdk_modifier);
|
||||
virtual ~PlatformAcceleratorGtk();
|
||||
|
||||
// PlatformAccelerator:
|
||||
virtual scoped_ptr<PlatformAccelerator> CreateCopy() const OVERRIDE;
|
||||
virtual bool Equals(const PlatformAccelerator& rhs) const OVERRIDE;
|
||||
|
||||
guint gdk_key_code() const { return gdk_key_code_; }
|
||||
GdkModifierType gdk_modifier() const { return gdk_modifier_; }
|
||||
|
||||
private:
|
||||
guint gdk_key_code_;
|
||||
GdkModifierType gdk_modifier_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(PlatformAcceleratorGtk);
|
||||
};
|
||||
|
||||
UI_BASE_EXPORT Accelerator AcceleratorForGdkKeyCodeAndModifier(
|
||||
guint gdk_key_code,
|
||||
GdkModifierType gdk_modifier);
|
||||
UI_BASE_EXPORT guint
|
||||
GetGdkKeyCodeForAccelerator(const Accelerator& accelerator);
|
||||
UI_BASE_EXPORT GdkModifierType GetGdkModifierForAccelerator(
|
||||
const Accelerator& accelerator);
|
||||
|
||||
} // namespace ui
|
||||
|
||||
#endif // UI_BASE_ACCELERATORS_PLATFORM_ACCELERATOR_GTK_H_
|
99
chromium_src/ui/base/x/active_window_watcher_x.cc
Normal file
99
chromium_src/ui/base/x/active_window_watcher_x.cc
Normal file
|
@ -0,0 +1,99 @@
|
|||
// Copyright (c) 2012 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/active_window_watcher_x.h"
|
||||
|
||||
#include <gdk/gdk.h>
|
||||
#include <gdk/gdkx.h>
|
||||
|
||||
#include "base/memory/singleton.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"
|
||||
#include "ui/gfx/gdk_compat.h"
|
||||
#include "ui/gfx/gtk_compat.h"
|
||||
|
||||
namespace ui {
|
||||
|
||||
static const char* const kNetActiveWindow = "_NET_ACTIVE_WINDOW";
|
||||
|
||||
// static
|
||||
ActiveWindowWatcherX* ActiveWindowWatcherX::GetInstance() {
|
||||
return Singleton<ActiveWindowWatcherX>::get();
|
||||
}
|
||||
|
||||
// static
|
||||
void ActiveWindowWatcherX::AddObserver(ActiveWindowWatcherXObserver* observer) {
|
||||
// Ensure that RootWindowPropertyWatcherX exists.
|
||||
internal::RootWindowPropertyWatcherX::GetInstance();
|
||||
GetInstance()->observers_.AddObserver(observer);
|
||||
}
|
||||
|
||||
// static
|
||||
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(kNetActiveWindow));
|
||||
}
|
||||
|
||||
ActiveWindowWatcherX::ActiveWindowWatcherX() {
|
||||
}
|
||||
|
||||
ActiveWindowWatcherX::~ActiveWindowWatcherX() {
|
||||
}
|
||||
|
||||
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.
|
||||
// This causes problems at startup for chromiumos.
|
||||
Atom type = None;
|
||||
int format = 0; // size in bits of each item in 'property'
|
||||
long unsigned int num_items = 0, remaining_bytes = 0;
|
||||
unsigned char* property = NULL;
|
||||
|
||||
XGetWindowProperty(gdk_x11_get_default_xdisplay(),
|
||||
GDK_WINDOW_XID(gdk_get_default_root_window()),
|
||||
GetAtom(kNetActiveWindow),
|
||||
0, // offset into property data to read
|
||||
1, // length to get in 32-bit quantities
|
||||
False, // deleted
|
||||
AnyPropertyType,
|
||||
&type,
|
||||
&format,
|
||||
&num_items,
|
||||
&remaining_bytes,
|
||||
&property);
|
||||
|
||||
// Check that the property was set and contained a single 32-bit item (we
|
||||
// don't check that remaining_bytes is 0, though, as XFCE's window manager
|
||||
// seems to actually store two values in the property for some unknown
|
||||
// reason.)
|
||||
if (format == 32 && num_items == 1) {
|
||||
int xid = *reinterpret_cast<int*>(property);
|
||||
GdkDisplay* display = gdk_display_get_default();
|
||||
GdkWindow* active_window = gdk_x11_window_lookup_for_display(display, xid);
|
||||
FOR_EACH_OBSERVER(ActiveWindowWatcherXObserver, observers_,
|
||||
ActiveWindowChanged(active_window));
|
||||
}
|
||||
if (property)
|
||||
XFree(property);
|
||||
}
|
||||
|
||||
} // namespace ui
|
60
chromium_src/ui/base/x/active_window_watcher_x.h
Normal file
60
chromium_src/ui/base/x/active_window_watcher_x.h
Normal file
|
@ -0,0 +1,60 @@
|
|||
// Copyright (c) 2012 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_H_
|
||||
#define UI_BASE_X_ACTIVE_WINDOW_WATCHER_X_H_
|
||||
|
||||
#include "base/basictypes.h"
|
||||
#include "base/observer_list.h"
|
||||
#include "ui/base/ui_base_export.h"
|
||||
#include "ui/base/x/x11_util.h"
|
||||
|
||||
template <typename T> struct DefaultSingletonTraits;
|
||||
|
||||
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 listen for changes to
|
||||
// the active window.
|
||||
class UI_BASE_EXPORT ActiveWindowWatcherX {
|
||||
public:
|
||||
static ActiveWindowWatcherX* GetInstance();
|
||||
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.
|
||||
static bool WMSupportsActivation();
|
||||
|
||||
private:
|
||||
friend struct DefaultSingletonTraits<ActiveWindowWatcherX>;
|
||||
friend class ui::internal::RootWindowPropertyWatcherX;
|
||||
|
||||
ActiveWindowWatcherX();
|
||||
~ActiveWindowWatcherX();
|
||||
|
||||
// Gets the atom for the default display for the property this class is
|
||||
// watching for.
|
||||
static Atom GetPropertyAtom();
|
||||
|
||||
// Notify observers that the active window has changed.
|
||||
static void Notify();
|
||||
|
||||
// Instance method that implements Notify().
|
||||
void NotifyActiveWindowChanged();
|
||||
|
||||
ObserverList<ActiveWindowWatcherXObserver> observers_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(ActiveWindowWatcherX);
|
||||
};
|
||||
|
||||
} // namespace ui
|
||||
|
||||
#endif // UI_BASE_X_ACTIVE_WINDOW_WATCHER_X_H_
|
25
chromium_src/ui/base/x/active_window_watcher_x_observer.h
Normal file
25
chromium_src/ui/base/x/active_window_watcher_x_observer.h
Normal file
|
@ -0,0 +1,25 @@
|
|||
// 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_
|
||||
|
||||
#include <gdk/gdk.h>
|
||||
|
||||
#include "ui/base/ui_base_export.h"
|
||||
|
||||
namespace ui {
|
||||
|
||||
class UI_BASE_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_
|
59
chromium_src/ui/base/x/root_window_property_watcher_x.cc
Normal file
59
chromium_src/ui/base/x/root_window_property_watcher_x.cc
Normal file
|
@ -0,0 +1,59 @@
|
|||
// Copyright (c) 2012 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 "base/memory/singleton.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
|
41
chromium_src/ui/base/x/root_window_property_watcher_x.h
Normal file
41
chromium_src/ui/base/x/root_window_property_watcher_x.h
Normal file
|
@ -0,0 +1,41 @@
|
|||
// Copyright (c) 2012 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_
|
||||
|
||||
#include <gdk/gdk.h>
|
||||
|
||||
#include "base/basictypes.h"
|
||||
#include "ui/base/gtk/gtk_signal.h"
|
||||
|
||||
template <typename T> struct DefaultSingletonTraits;
|
||||
|
||||
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_
|
53
chromium_src/ui/base/x/work_area_watcher_x.cc
Normal file
53
chromium_src/ui/base/x/work_area_watcher_x.cc
Normal file
|
@ -0,0 +1,53 @@
|
|||
// Copyright (c) 2012 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 "base/memory/singleton.h"
|
||||
#include "ui/base/work_area_watcher_observer.h"
|
||||
#include "ui/base/x/root_window_property_watcher_x.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(WorkAreaWatcherObserver* observer) {
|
||||
// Ensure that RootWindowPropertyWatcherX exists.
|
||||
internal::RootWindowPropertyWatcherX::GetInstance();
|
||||
GetInstance()->observers_.AddObserver(observer);
|
||||
}
|
||||
|
||||
// static
|
||||
void WorkAreaWatcherX::RemoveObserver(WorkAreaWatcherObserver* 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(WorkAreaWatcherObserver, observers_, WorkAreaChanged());
|
||||
}
|
||||
|
||||
} // namespace ui
|
55
chromium_src/ui/base/x/work_area_watcher_x.h
Normal file
55
chromium_src/ui/base/x/work_area_watcher_x.h
Normal file
|
@ -0,0 +1,55 @@
|
|||
// Copyright (c) 2012 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_
|
||||
|
||||
#include "base/basictypes.h"
|
||||
#include "base/observer_list.h"
|
||||
#include "ui/base/ui_base_export.h"
|
||||
#include "ui/base/x/x11_util.h"
|
||||
|
||||
template <typename T> struct DefaultSingletonTraits;
|
||||
|
||||
namespace ui {
|
||||
|
||||
class WorkAreaWatcherObserver;
|
||||
|
||||
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_BASE_EXPORT WorkAreaWatcherX {
|
||||
public:
|
||||
static WorkAreaWatcherX* GetInstance();
|
||||
static void AddObserver(WorkAreaWatcherObserver* observer);
|
||||
static void RemoveObserver(WorkAreaWatcherObserver* 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<WorkAreaWatcherObserver> observers_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(WorkAreaWatcherX);
|
||||
};
|
||||
|
||||
} // namespace ui
|
||||
|
||||
#endif // UI_BASE_X_WORK_AREA_WATCHER_X_H_
|
25
chromium_src/ui/base/x/x11_util.cc
Normal file
25
chromium_src/ui/base/x/x11_util.cc
Normal file
|
@ -0,0 +1,25 @@
|
|||
// Copyright (c) 2012 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.
|
||||
|
||||
// This file defines utility functions for X11 (Linux only). This code has been
|
||||
// ported from XCB since we can't use XCB on Ubuntu while its 32-bit support
|
||||
// remains woefully incomplete.
|
||||
|
||||
#include "ui/base/x/x11_util.h"
|
||||
|
||||
#include "ui/gfx/gdk_compat.h"
|
||||
|
||||
namespace ui {
|
||||
|
||||
Atom GetAtom(const char* name) {
|
||||
#if defined(TOOLKIT_GTK)
|
||||
return gdk_x11_get_xatom_by_name_for_display(
|
||||
gdk_display_get_default(), name);
|
||||
#else
|
||||
// TODO(derat): Cache atoms to avoid round-trips to the server.
|
||||
return XInternAtom(gfx::GetXDisplay(), name, false);
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace ui
|
|
@ -0,0 +1,85 @@
|
|||
// 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.
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
|
||||
* Copyright (C) 2006 Michael Emmel mike.emmel@gmail.com
|
||||
* Copyright (C) 2007 Holger Hans Peter Freyther
|
||||
* Copyright (C) 2008 Collabora, Ltd. All rights reserved.
|
||||
* Copyright (C) 2008, 2009 Google Inc.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
// WindowsKeyCodeForGdkKeyCode is copied from platform/gtk/KeyEventGtk.cpp
|
||||
|
||||
#include "ui/events/keycodes/keyboard_code_conversion_gtk.h"
|
||||
|
||||
#include <gdk/gdk.h>
|
||||
#include <gdk/gdkkeysyms.h>
|
||||
#include <X11/keysym.h>
|
||||
|
||||
#include "base/basictypes.h"
|
||||
#include "build/build_config.h"
|
||||
#include "ui/events/keycodes/keyboard_code_conversion_x.h"
|
||||
#include "ui/events/keycodes/keyboard_codes_posix.h"
|
||||
|
||||
namespace ui {
|
||||
|
||||
KeyboardCode WindowsKeyCodeForGdkKeyCode(int keycode) {
|
||||
// Gdk key codes (e.g. GDK_BackSpace) and X keysyms (e.g. XK_BackSpace) share
|
||||
// the same values.
|
||||
return KeyboardCodeFromXKeysym(keycode);
|
||||
}
|
||||
|
||||
int GdkKeyCodeForWindowsKeyCode(KeyboardCode keycode, bool shift) {
|
||||
// Gdk key codes and X keysyms share the same values.
|
||||
return XKeysymForWindowsKeyCode(keycode, shift);
|
||||
}
|
||||
|
||||
// Just in case, test whether Gdk key codes match X ones.
|
||||
COMPILE_ASSERT(GDK_KP_0 == XK_KP_0, keycode_check);
|
||||
COMPILE_ASSERT(GDK_A == XK_A, keycode_check);
|
||||
COMPILE_ASSERT(GDK_Escape == XK_Escape, keycode_check);
|
||||
COMPILE_ASSERT(GDK_F1 == XK_F1, keycode_check);
|
||||
COMPILE_ASSERT(GDK_Kanji == XK_Kanji, keycode_check);
|
||||
COMPILE_ASSERT(GDK_Page_Up == XK_Page_Up, keycode_check);
|
||||
COMPILE_ASSERT(GDK_Tab == XK_Tab, keycode_check);
|
||||
COMPILE_ASSERT(GDK_a == XK_a, keycode_check);
|
||||
COMPILE_ASSERT(GDK_space == XK_space, keycode_check);
|
||||
|
||||
int GdkNativeKeyCodeForWindowsKeyCode(KeyboardCode keycode, bool shift) {
|
||||
int keyval = GdkKeyCodeForWindowsKeyCode(keycode, shift);
|
||||
GdkKeymapKey* keys;
|
||||
gint n_keys;
|
||||
|
||||
int native_keycode = 0;
|
||||
if (keyval && gdk_keymap_get_entries_for_keyval(0, keyval, &keys, &n_keys)) {
|
||||
native_keycode = keys[0].keycode;
|
||||
g_free(keys);
|
||||
}
|
||||
|
||||
return native_keycode;
|
||||
}
|
||||
|
||||
} // namespace ui
|
|
@ -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.
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
|
||||
* Copyright (C) 2006 Michael Emmel mike.emmel@gmail.com
|
||||
* Copyright (C) 2007 Holger Hans Peter Freyther
|
||||
* Copyright (C) 2008 Collabora, Ltd. All rights reserved.
|
||||
* Copyright (C) 2008, 2009 Google Inc.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
// WindowsKeyCodeForGdkKeyCode is copied from platform/gtk/KeyEventGtk.cpp
|
||||
|
||||
#ifndef UI_EVENTS_KEYCODES_KEYBOARD_CODE_CONVERSION_GTK_H_
|
||||
#define UI_EVENTS_KEYCODES_KEYBOARD_CODE_CONVERSION_GTK_H_
|
||||
|
||||
#include "ui/events/events_base_export.h"
|
||||
#include "ui/events/keycodes/keyboard_codes_posix.h"
|
||||
|
||||
typedef struct _GdkEventKey GdkEventKey;
|
||||
|
||||
namespace ui {
|
||||
|
||||
EVENTS_BASE_EXPORT KeyboardCode WindowsKeyCodeForGdkKeyCode(int keycode);
|
||||
|
||||
EVENTS_BASE_EXPORT int GdkKeyCodeForWindowsKeyCode(KeyboardCode keycode,
|
||||
bool shift);
|
||||
|
||||
// For WebKit DRT testing: simulate the native keycode for the given
|
||||
// input |keycode|. Return the native keycode.
|
||||
EVENTS_BASE_EXPORT int GdkNativeKeyCodeForWindowsKeyCode(KeyboardCode keycode,
|
||||
bool shift);
|
||||
|
||||
} // namespace ui
|
||||
|
||||
#endif // UI_EVENTS_KEYCODES_KEYBOARD_CODE_CONVERSION_GTK_H_
|
192
chromium_src/ui/gfx/gfx_gtk_util.cc
Normal file
192
chromium_src/ui/gfx/gfx_gtk_util.cc
Normal file
|
@ -0,0 +1,192 @@
|
|||
// Copyright (c) 2012 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/gfx/gtk_util.h"
|
||||
|
||||
#include <gdk/gdk.h>
|
||||
#include <gtk/gtk.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "base/basictypes.h"
|
||||
#include "base/command_line.h"
|
||||
#include "base/memory/scoped_ptr.h"
|
||||
#include "third_party/skia/include/core/SkBitmap.h"
|
||||
#include "third_party/skia/include/core/SkUnPreMultiply.h"
|
||||
#include "ui/gfx/rect.h"
|
||||
|
||||
namespace {
|
||||
|
||||
// A process wide singleton that manages our usage of gdk cursors.
|
||||
// gdk_cursor_new() hits the disk in several places and GdkCursor instances can
|
||||
// be reused throughout the process.
|
||||
class GdkCursorCache {
|
||||
public:
|
||||
GdkCursorCache() {}
|
||||
~GdkCursorCache() {
|
||||
for (GdkCursorMap::iterator i(cursors_.begin()); i != cursors_.end(); ++i) {
|
||||
gdk_cursor_unref(i->second);
|
||||
}
|
||||
cursors_.clear();
|
||||
}
|
||||
|
||||
GdkCursor* GetCursorImpl(GdkCursorType type) {
|
||||
GdkCursorMap::iterator it = cursors_.find(type);
|
||||
GdkCursor* cursor = NULL;
|
||||
if (it == cursors_.end()) {
|
||||
cursor = gdk_cursor_new(type);
|
||||
cursors_.insert(std::make_pair(type, cursor));
|
||||
} else {
|
||||
cursor = it->second;
|
||||
}
|
||||
|
||||
// It is not necessary to add a reference here. The callers can ref the
|
||||
// cursor if they need it for something.
|
||||
return cursor;
|
||||
}
|
||||
|
||||
private:
|
||||
typedef std::map<GdkCursorType, GdkCursor*> GdkCursorMap;
|
||||
GdkCursorMap cursors_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(GdkCursorCache);
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace gfx {
|
||||
|
||||
static void CommonInitFromCommandLine(const CommandLine& command_line,
|
||||
void (*init_func)(gint*, gchar***)) {
|
||||
const std::vector<std::string>& args = command_line.argv();
|
||||
int argc = args.size();
|
||||
scoped_ptr<char *[]> argv(new char *[argc + 1]);
|
||||
for (size_t i = 0; i < args.size(); ++i) {
|
||||
// TODO(piman@google.com): can gtk_init modify argv? Just being safe
|
||||
// here.
|
||||
argv[i] = strdup(args[i].c_str());
|
||||
}
|
||||
argv[argc] = NULL;
|
||||
char **argv_pointer = argv.get();
|
||||
|
||||
init_func(&argc, &argv_pointer);
|
||||
for (size_t i = 0; i < args.size(); ++i) {
|
||||
free(argv[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void GtkInitFromCommandLine(const CommandLine& command_line) {
|
||||
CommonInitFromCommandLine(command_line, gtk_init);
|
||||
}
|
||||
|
||||
void GdkInitFromCommandLine(const CommandLine& command_line) {
|
||||
CommonInitFromCommandLine(command_line, gdk_init);
|
||||
}
|
||||
|
||||
GdkPixbuf* GdkPixbufFromSkBitmap(const SkBitmap& bitmap) {
|
||||
if (bitmap.isNull())
|
||||
return NULL;
|
||||
|
||||
SkAutoLockPixels lock_pixels(bitmap);
|
||||
|
||||
int width = bitmap.width();
|
||||
int height = bitmap.height();
|
||||
|
||||
GdkPixbuf* pixbuf = gdk_pixbuf_new(
|
||||
GDK_COLORSPACE_RGB, // The only colorspace gtk supports.
|
||||
TRUE, // There is an alpha channel.
|
||||
8,
|
||||
width, height);
|
||||
|
||||
// SkBitmaps are premultiplied, we need to unpremultiply them.
|
||||
const int kBytesPerPixel = 4;
|
||||
uint8* divided = gdk_pixbuf_get_pixels(pixbuf);
|
||||
|
||||
for (int y = 0, i = 0; y < height; y++) {
|
||||
for (int x = 0; x < width; x++) {
|
||||
uint32 pixel = bitmap.getAddr32(0, y)[x];
|
||||
|
||||
int alpha = SkColorGetA(pixel);
|
||||
if (alpha != 0 && alpha != 255) {
|
||||
SkColor unmultiplied = SkUnPreMultiply::PMColorToColor(pixel);
|
||||
divided[i + 0] = SkColorGetR(unmultiplied);
|
||||
divided[i + 1] = SkColorGetG(unmultiplied);
|
||||
divided[i + 2] = SkColorGetB(unmultiplied);
|
||||
divided[i + 3] = alpha;
|
||||
} else {
|
||||
divided[i + 0] = SkColorGetR(pixel);
|
||||
divided[i + 1] = SkColorGetG(pixel);
|
||||
divided[i + 2] = SkColorGetB(pixel);
|
||||
divided[i + 3] = alpha;
|
||||
}
|
||||
i += kBytesPerPixel;
|
||||
}
|
||||
}
|
||||
|
||||
return pixbuf;
|
||||
}
|
||||
|
||||
void SubtractRectanglesFromRegion(GdkRegion* region,
|
||||
const std::vector<Rect>& cutouts) {
|
||||
for (size_t i = 0; i < cutouts.size(); ++i) {
|
||||
GdkRectangle rect = {
|
||||
cutouts[i].x(), cutouts[i].y(), cutouts[i].width(), cutouts[i].height()
|
||||
};
|
||||
GdkRegion* rect_region = gdk_region_rectangle(&rect);
|
||||
gdk_region_subtract(region, rect_region);
|
||||
// TODO(deanm): It would be nice to be able to reuse the GdkRegion here.
|
||||
gdk_region_destroy(rect_region);
|
||||
}
|
||||
}
|
||||
|
||||
GdkCursor* GetCursor(int type) {
|
||||
CR_DEFINE_STATIC_LOCAL(GdkCursorCache, impl, ());
|
||||
return impl.GetCursorImpl(static_cast<GdkCursorType>(type));
|
||||
}
|
||||
|
||||
void InitRCStyles() {
|
||||
static const char kRCText[] =
|
||||
// Make our dialogs styled like the GNOME HIG.
|
||||
//
|
||||
// TODO(evanm): content-area-spacing was introduced in a later
|
||||
// version of GTK, so we need to set that manually on all dialogs.
|
||||
// Perhaps it would make sense to have a shared FixupDialog() function.
|
||||
"style \"gnome-dialog\" {\n"
|
||||
" xthickness = 12\n"
|
||||
" GtkDialog::action-area-border = 0\n"
|
||||
" GtkDialog::button-spacing = 6\n"
|
||||
" GtkDialog::content-area-spacing = 18\n"
|
||||
" GtkDialog::content-area-border = 12\n"
|
||||
"}\n"
|
||||
// Note we set it at the "application" priority, so users can override.
|
||||
"widget \"GtkDialog\" style : application \"gnome-dialog\"\n"
|
||||
|
||||
// Make our about dialog special, so the image is flush with the edge.
|
||||
"style \"about-dialog\" {\n"
|
||||
" GtkDialog::action-area-border = 12\n"
|
||||
" GtkDialog::button-spacing = 6\n"
|
||||
" GtkDialog::content-area-spacing = 18\n"
|
||||
" GtkDialog::content-area-border = 0\n"
|
||||
"}\n"
|
||||
"widget \"about-dialog\" style : application \"about-dialog\"\n";
|
||||
|
||||
gtk_rc_parse_string(kRCText);
|
||||
}
|
||||
|
||||
base::TimeDelta GetCursorBlinkCycle() {
|
||||
// From http://library.gnome.org/devel/gtk/unstable/GtkSettings.html, this is
|
||||
// the default value for gtk-cursor-blink-time.
|
||||
static const gint kGtkDefaultCursorBlinkTime = 1200;
|
||||
|
||||
gint cursor_blink_time = kGtkDefaultCursorBlinkTime;
|
||||
gboolean cursor_blink = TRUE;
|
||||
g_object_get(gtk_settings_get_default(),
|
||||
"gtk-cursor-blink-time", &cursor_blink_time,
|
||||
"gtk-cursor-blink", &cursor_blink,
|
||||
NULL);
|
||||
return cursor_blink ?
|
||||
base::TimeDelta::FromMilliseconds(cursor_blink_time) :
|
||||
base::TimeDelta();
|
||||
}
|
||||
|
||||
} // namespace gfx
|
55
chromium_src/ui/gfx/gtk_util.h
Normal file
55
chromium_src/ui/gfx/gtk_util.h
Normal file
|
@ -0,0 +1,55 @@
|
|||
// Copyright (c) 2012 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_GFX_GTK_UTIL_H_
|
||||
#define UI_GFX_GTK_UTIL_H_
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "base/time/time.h"
|
||||
#include "ui/gfx/gfx_export.h"
|
||||
|
||||
typedef struct _GdkPixbuf GdkPixbuf;
|
||||
typedef struct _GdkRegion GdkRegion;
|
||||
typedef struct _GdkCursor GdkCursor;
|
||||
|
||||
class SkBitmap;
|
||||
|
||||
namespace base {
|
||||
class CommandLine;
|
||||
}
|
||||
|
||||
namespace gfx {
|
||||
|
||||
class Rect;
|
||||
|
||||
// Call gtk_init() / gdk_init() using the argc and argv from command_line.
|
||||
// These init functions want an argc and argv that they can mutate; we provide
|
||||
// those, but leave the original CommandLine unaltered.
|
||||
GFX_EXPORT void GtkInitFromCommandLine(const base::CommandLine& command_line);
|
||||
GFX_EXPORT void GdkInitFromCommandLine(const base::CommandLine& command_line);
|
||||
|
||||
// Convert and copy a SkBitmap to a GdkPixbuf. NOTE: this uses BGRAToRGBA, so
|
||||
// it is an expensive operation. The returned GdkPixbuf will have a refcount of
|
||||
// 1, and the caller is responsible for unrefing it when done.
|
||||
GFX_EXPORT GdkPixbuf* GdkPixbufFromSkBitmap(const SkBitmap& bitmap);
|
||||
|
||||
// Modify the given region by subtracting the given rectangles.
|
||||
GFX_EXPORT void SubtractRectanglesFromRegion(GdkRegion* region,
|
||||
const std::vector<Rect>& cutouts);
|
||||
|
||||
// Returns a static instance of a GdkCursor* object, sharable across the
|
||||
// process. Caller must gdk_cursor_ref() it if they want to assume ownership.
|
||||
GFX_EXPORT GdkCursor* GetCursor(int type);
|
||||
|
||||
// Initialize some GTK settings so that our dialogs are consistent.
|
||||
GFX_EXPORT void InitRCStyles();
|
||||
|
||||
// Queries GtkSettings for the cursor blink cycle time. Returns a 0 duration if
|
||||
// blinking is disabled.
|
||||
GFX_EXPORT base::TimeDelta GetCursorBlinkCycle();
|
||||
|
||||
} // namespace gfx
|
||||
|
||||
#endif // UI_GFX_GTK_UTIL_H_
|
Loading…
Add table
Add a link
Reference in a new issue