This source file includes following definitions.
- CommonInitFromCommandLine
- GtkInitFromCommandLine
- GetDesktopName
- SetAlwaysShowImage
- GetGdkKeyCodeForAccelerator
- GetGdkModifierForAccelerator
- EventFlagsFromGdkState
- SetGtkTransientForAura
- GetAuraTransientParent
- ClearAuraTransientParent
#include "chrome/browser/ui/libgtk2ui/gtk2_util.h"
#include <gdk/gdk.h>
#include <gdk/gdkx.h>
#include <gtk/gtk.h>
#include "base/command_line.h"
#include "base/environment.h"
#include "base/memory/scoped_ptr.h"
#include "ui/aura/window.h"
#include "ui/aura/window_tree_host.h"
#include "ui/base/accelerators/accelerator.h"
#include "ui/events/event_constants.h"
#include "ui/events/keycodes/keyboard_code_conversion_x.h"
#include "ui/gfx/size.h"
namespace {
const char kAuraTransientParent[] = "aura-transient-parent";
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) {
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]);
}
}
}
namespace libgtk2ui {
void GtkInitFromCommandLine(const CommandLine& command_line) {
CommonInitFromCommandLine(command_line, gtk_init);
}
std::string GetDesktopName(base::Environment* env) {
#if defined(GOOGLE_CHROME_BUILD)
return "google-chrome.desktop";
#else
std::string name;
if (env->GetVar("CHROME_DESKTOP", &name) && !name.empty())
return name;
return "chromium-browser.desktop";
#endif
}
void SetAlwaysShowImage(GtkWidget* image_menu_item) {
gtk_image_menu_item_set_always_show_image(
GTK_IMAGE_MENU_ITEM(image_menu_item), TRUE);
}
guint GetGdkKeyCodeForAccelerator(const ui::Accelerator& accelerator) {
return XKeysymForWindowsKeyCode(accelerator.key_code(), false);
}
GdkModifierType GetGdkModifierForAccelerator(
const ui::Accelerator& accelerator) {
int event_flag = accelerator.modifiers();
int modifier = 0;
if (event_flag & ui::EF_SHIFT_DOWN)
modifier |= GDK_SHIFT_MASK;
if (event_flag & ui::EF_CONTROL_DOWN)
modifier |= GDK_CONTROL_MASK;
if (event_flag & ui::EF_ALT_DOWN)
modifier |= GDK_MOD1_MASK;
return static_cast<GdkModifierType>(modifier);
}
int EventFlagsFromGdkState(guint state) {
int flags = ui::EF_NONE;
flags |= (state & GDK_LOCK_MASK) ? ui::EF_CAPS_LOCK_DOWN : ui::EF_NONE;
flags |= (state & GDK_CONTROL_MASK) ? ui::EF_CONTROL_DOWN : ui::EF_NONE;
flags |= (state & GDK_SHIFT_MASK) ? ui::EF_SHIFT_DOWN : ui::EF_NONE;
flags |= (state & GDK_MOD1_MASK) ? ui::EF_ALT_DOWN : ui::EF_NONE;
flags |= (state & GDK_BUTTON1_MASK) ? ui::EF_LEFT_MOUSE_BUTTON : ui::EF_NONE;
flags |=
(state & GDK_BUTTON2_MASK) ? ui::EF_MIDDLE_MOUSE_BUTTON : ui::EF_NONE;
flags |= (state & GDK_BUTTON3_MASK) ? ui::EF_RIGHT_MOUSE_BUTTON : ui::EF_NONE;
return flags;
}
void SetGtkTransientForAura(GtkWidget* dialog, aura::Window* parent) {
gtk_widget_realize(dialog);
GdkWindow* gdk_window = gtk_widget_get_window(dialog);
XSetTransientForHint(GDK_WINDOW_XDISPLAY(gdk_window),
GDK_WINDOW_XID(gdk_window),
parent->GetHost()->GetAcceleratedWidget());
g_object_set_data(G_OBJECT(dialog), kAuraTransientParent, parent);
}
aura::Window* GetAuraTransientParent(GtkWidget* dialog) {
return reinterpret_cast<aura::Window*>(
g_object_get_data(G_OBJECT(dialog), kAuraTransientParent));
}
void ClearAuraTransientParent(GtkWidget* dialog) {
g_object_set_data(G_OBJECT(dialog), kAuraTransientParent, NULL);
}
}