Move all chromium's code under chromium_src.

This commit is contained in:
Cheng Zhao 2014-06-29 05:53:24 +00:00
Родитель 1f99a97544
Коммит 64bf1bcb9f
39 изменённых файлов: 594 добавлений и 53 удалений

Просмотреть файл

@ -129,18 +129,10 @@
'atom/browser/ui/file_dialog_gtk.cc',
'atom/browser/ui/file_dialog_mac.mm',
'atom/browser/ui/file_dialog_win.cc',
'atom/browser/ui/gtk/active_window_watcher_x.cc',
'atom/browser/ui/gtk/active_window_watcher_x.h',
'atom/browser/ui/gtk/active_window_watcher_x_observer.h',
'atom/browser/ui/gtk/app_indicator_icon.cc',
'atom/browser/ui/gtk/app_indicator_icon.h',
'atom/browser/ui/gtk/root_window_property_watcher_x.cc',
'atom/browser/ui/gtk/root_window_property_watcher_x.h',
'atom/browser/ui/gtk/status_icon.cc',
'atom/browser/ui/gtk/status_icon.h',
'atom/browser/ui/gtk/work_area_watcher_x.cc',
'atom/browser/ui/gtk/work_area_watcher_x.h',
'atom/browser/ui/gtk/x11_util.cc',
'atom/browser/ui/message_box.h',
'atom/browser/ui/message_box_gtk.cc',
'atom/browser/ui/message_box_mac.mm',
@ -230,27 +222,41 @@
'atom/renderer/atom_render_view_observer.h',
'atom/renderer/atom_renderer_client.cc',
'atom/renderer/atom_renderer_client.h',
'chrome/browser/ui/gtk/event_utils.cc',
'chrome/browser/ui/gtk/event_utils.h',
'chrome/browser/ui/gtk/gtk_custom_menu.cc',
'chrome/browser/ui/gtk/gtk_custom_menu.h',
'chrome/browser/ui/gtk/gtk_custom_menu_item.cc',
'chrome/browser/ui/gtk/gtk_custom_menu_item.h',
'chrome/browser/ui/gtk/gtk_util.cc',
'chrome/browser/ui/gtk/gtk_util.h',
'chrome/browser/ui/gtk/gtk_window_util.cc',
'chrome/browser/ui/gtk/gtk_window_util.h',
'chrome/browser/ui/gtk/menu_gtk.cc',
'chrome/browser/ui/gtk/menu_gtk.h',
'chrome/browser/ui/libgtk2ui/g_object_destructor_filo.cc',
'chrome/browser/ui/libgtk2ui/g_object_destructor_filo.h',
'chrome/browser/ui/libgtk2ui/gtk2_signal.h',
'chrome/browser/ui/libgtk2ui/gtk2_signal_registrar.cc',
'chrome/browser/ui/libgtk2ui/gtk2_signal_registrar.h',
'chrome/browser/ui/libgtk2ui/skia_utils_gtk2.cc',
'chrome/browser/ui/libgtk2ui/skia_utils_gtk2.h',
'chrome/browser/ui/views/status_icons/status_tray_state_changer_win.cc',
'chrome/browser/ui/views/status_icons/status_tray_state_changer_win.h',
'chromium_src/chrome/browser/ui/gtk/event_utils.cc',
'chromium_src/chrome/browser/ui/gtk/event_utils.h',
'chromium_src/chrome/browser/ui/gtk/gtk_custom_menu.cc',
'chromium_src/chrome/browser/ui/gtk/gtk_custom_menu.h',
'chromium_src/chrome/browser/ui/gtk/gtk_custom_menu_item.cc',
'chromium_src/chrome/browser/ui/gtk/gtk_custom_menu_item.h',
'chromium_src/chrome/browser/ui/gtk/gtk_util.cc',
'chromium_src/chrome/browser/ui/gtk/gtk_util.h',
'chromium_src/chrome/browser/ui/gtk/gtk_window_util.cc',
'chromium_src/chrome/browser/ui/gtk/gtk_window_util.h',
'chromium_src/chrome/browser/ui/gtk/menu_gtk.cc',
'chromium_src/chrome/browser/ui/gtk/menu_gtk.h',
'chromium_src/chrome/browser/ui/libgtk2ui/g_object_destructor_filo.cc',
'chromium_src/chrome/browser/ui/libgtk2ui/g_object_destructor_filo.h',
'chromium_src/chrome/browser/ui/libgtk2ui/gtk2_signal.h',
'chromium_src/chrome/browser/ui/libgtk2ui/gtk2_signal_registrar.cc',
'chromium_src/chrome/browser/ui/libgtk2ui/gtk2_signal_registrar.h',
'chromium_src/chrome/browser/ui/libgtk2ui/skia_utils_gtk2.cc',
'chromium_src/chrome/browser/ui/libgtk2ui/skia_utils_gtk2.h',
'chromium_src/chrome/browser/ui/views/status_icons/status_tray_state_changer_win.cc',
'chromium_src/chrome/browser/ui/views/status_icons/status_tray_state_changer_win.h',
'chromium_src/ui/base/accelerators/platform_accelerator_gtk.cc',
'chromium_src/ui/base/accelerators/platform_accelerator_gtk.h',
'chromium_src/ui/base/x/active_window_watcher_x.cc',
'chromium_src/ui/base/x/active_window_watcher_x.h',
'chromium_src/ui/base/x/active_window_watcher_x_observer.h',
'chromium_src/ui/base/x/root_window_property_watcher_x.cc',
'chromium_src/ui/base/x/root_window_property_watcher_x.h',
'chromium_src/ui/base/x/work_area_watcher_x.cc',
'chromium_src/ui/base/x/work_area_watcher_x.h',
'chromium_src/ui/base/x/x11_util.cc',
'chromium_src/ui/events/keycodes/keyboard_code_conversion_gtk.cc',
'chromium_src/ui/events/keycodes/keyboard_code_conversion_gtk.h',
'chromium_src/ui/gfx/gfx_gtk_util.cc',
'chromium_src/ui/gfx/gtk_util.h',
'<@(native_mate_files)',
],
'framework_sources': [
@ -442,6 +448,7 @@
],
'include_dirs': [
'.',
'chromium_src',
'vendor/brightray',
'vendor/native_mate',
# Include directories for uv and node.

Просмотреть файл

@ -7,7 +7,6 @@
#include <string>
#include <vector>
#include "atom/browser/ui/gtk/active_window_watcher_x.h"
#include "atom/common/draggable_region.h"
#include "atom/common/options_switches.h"
#include "base/environment.h"
@ -21,6 +20,7 @@
#include "native_mate/dictionary.h"
#include "ui/base/accelerators/platform_accelerator_gtk.h"
#include "ui/base/models/simple_menu_model.h"
#include "ui/base/x/active_window_watcher_x.h"
#include "ui/base/x/x11_util.h"
#include "ui/gfx/font_render_params_linux.h"
#include "ui/gfx/gtk_util.h"

Просмотреть файл

Просмотреть файл

@ -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

Просмотреть файл

@ -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_

Просмотреть файл

@ -2,14 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "atom/browser/ui/gtk/active_window_watcher_x.h"
#include "ui/base/x/active_window_watcher_x.h"
#include <gdk/gdk.h>
#include <gdk/gdkx.h>
#include "atom/browser/ui/gtk/active_window_watcher_x_observer.h"
#include "atom/browser/ui/gtk/root_window_property_watcher_x.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"

Просмотреть файл

@ -2,11 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ATOM_BROWSER_UI_GTK_ACTIVE_WINDOW_WATCHER_X_H_
#define ATOM_BROWSER_UI_GTK_ACTIVE_WINDOW_WATCHER_X_H_
#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;
@ -22,7 +23,7 @@ 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 ActiveWindowWatcherX {
class UI_BASE_EXPORT ActiveWindowWatcherX {
public:
static ActiveWindowWatcherX* GetInstance();
static void AddObserver(ActiveWindowWatcherXObserver* observer);
@ -56,4 +57,4 @@ class ActiveWindowWatcherX {
} // namespace ui
#endif // ATOM_BROWSER_UI_GTK_ACTIVE_WINDOW_WATCHER_X_H_
#endif // UI_BASE_X_ACTIVE_WINDOW_WATCHER_X_H_

Просмотреть файл

@ -7,9 +7,11 @@
#include <gdk/gdk.h>
#include "ui/base/ui_base_export.h"
namespace ui {
class ActiveWindowWatcherXObserver {
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;

Просмотреть файл

@ -2,14 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "atom/browser/ui/gtk/root_window_property_watcher_x.h"
#include "ui/base/x/root_window_property_watcher_x.h"
#include <gdk/gdk.h>
#include <gdk/gdkx.h>
#include "base/memory/singleton.h"
#include "atom/browser/ui/gtk/active_window_watcher_x.h"
#include "atom/browser/ui/gtk/work_area_watcher_x.h"
#include "ui/base/x/active_window_watcher_x.h"
#include "ui/base/x/work_area_watcher_x.h"
namespace ui {

Просмотреть файл

@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ATOM_BROWSER_UI_GTK_ROOT_WINDOW_PROPERTY_WATCHER_X_H_
#define ATOM_BROWSER_UI_GTK_ROOT_WINDOW_PROPERTY_WATCHER_X_H_
#ifndef UI_BASE_X_ROOT_WINDOW_PROPERTY_WATCHER_X_H_
#define UI_BASE_X_ROOT_WINDOW_PROPERTY_WATCHER_X_H_
#include <gdk/gdk.h>
@ -13,7 +13,6 @@
template <typename T> struct DefaultSingletonTraits;
namespace ui {
namespace internal {
// This class keeps track of changes to properties on the root window. This is
@ -37,7 +36,6 @@ class RootWindowPropertyWatcherX {
};
} // namespace internal
} // namespace ui
#endif // ATOM_BROWSER_UI_GTK_ROOT_WINDOW_PROPERTY_WATCHER_X_H_
#endif // UI_BASE_X_ROOT_WINDOW_PROPERTY_WATCHER_X_H_

Просмотреть файл

@ -2,11 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "atom/browser/ui/gtk/work_area_watcher_x.h"
#include "ui/base/x/work_area_watcher_x.h"
#include "base/memory/singleton.h"
#include "ui/base/work_area_watcher_observer.h"
#include "atom/browser/ui/gtk/root_window_property_watcher_x.h"
#include "ui/base/x/root_window_property_watcher_x.h"
#include "ui/base/x/x11_util.h"
namespace ui {

Просмотреть файл

@ -2,11 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ATOM_BROWSER_UI_GTK_WORK_AREA_WATCHER_X_H_
#define ATOM_BROWSER_UI_GTK_WORK_AREA_WATCHER_X_H_
#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;
@ -21,7 +22,7 @@ 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 WorkAreaWatcherX {
class UI_BASE_EXPORT WorkAreaWatcherX {
public:
static WorkAreaWatcherX* GetInstance();
static void AddObserver(WorkAreaWatcherObserver* observer);
@ -51,4 +52,4 @@ class WorkAreaWatcherX {
} // namespace ui
#endif // ATOM_BROWSER_UI_GTK_WORK_AREA_WATCHER_X_H_
#endif // UI_BASE_X_WORK_AREA_WATCHER_X_H_

Просмотреть файл

Просмотреть файл

@ -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_

Просмотреть файл

@ -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

Просмотреть файл

@ -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_

Просмотреть файл

@ -38,7 +38,7 @@ to understand the source code better.
* **api** - The implementation of common APIs, and foundations of
atom-shell's built-in modules.
* **lib** - Javascript part of the API implementation.
* **chrome** - Source code modified from Chromium's `chrome` component.
* **chromium_src** - Source code that copied from Chromium.
* **docs** - Documentations.
* **spec** - Automatic tests.
* **atom.gyp** - Building rules of atom-shell.