Commit 0b046ae4 authored by Tom Anderson's avatar Tom Anderson Committed by Commit Bot

Cleanup outdated and unused parts of libgtkui

R=thestig
BUG=None

Change-Id: I848e251de4bdbb6d848751b7b04c96831bb78e8f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1848346
Commit-Queue: Thomas Anderson <thomasanderson@chromium.org>
Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#704328}
parent 348f1363
...@@ -20,7 +20,6 @@ jumbo_component("libgtkui") { ...@@ -20,7 +20,6 @@ jumbo_component("libgtkui") {
"gtk_util.h", "gtk_util.h",
"input_method_context_impl_gtk.cc", "input_method_context_impl_gtk.cc",
"input_method_context_impl_gtk.h", "input_method_context_impl_gtk.h",
"libgtkui_export.h",
"native_theme_gtk.cc", "native_theme_gtk.cc",
"native_theme_gtk.h", "native_theme_gtk.h",
"nav_button_provider_gtk.cc", "nav_button_provider_gtk.cc",
...@@ -37,14 +36,9 @@ jumbo_component("libgtkui") { ...@@ -37,14 +36,9 @@ jumbo_component("libgtkui") {
"settings_provider.h", "settings_provider.h",
"settings_provider_gtk.cc", "settings_provider_gtk.cc",
"settings_provider_gtk.h", "settings_provider_gtk.h",
"skia_utils_gtk.cc",
"skia_utils_gtk.h",
] ]
configs += [ configs += [ "//build/config/linux/pangocairo" ]
"//build/config/linux/pangocairo",
"//build/config/linux:x11",
]
if (use_gio) { if (use_gio) {
sources += [ sources += [
...@@ -58,26 +52,15 @@ jumbo_component("libgtkui") { ...@@ -58,26 +52,15 @@ jumbo_component("libgtkui") {
configs += [ "//printing:cups" ] configs += [ "//printing:cups" ]
} }
defines = [ "LIBGTKUI_IMPLEMENTATION" ] defines = [ "IS_LIBGTKUI_IMPL" ]
deps = [ deps = [
"//base", "//base",
"//base:i18n",
"//base/third_party/dynamic_annotations",
"//build:branding_buildflags",
"//build/config/linux/gtk", "//build/config/linux/gtk",
"//build/config/linux/gtk:gtkprint", "//build/config/linux/gtk:gtkprint",
"//cc/paint",
"//chrome:extra_resources",
"//chrome:resources",
"//chrome:strings",
"//chrome/app:command_ids",
"//chrome/app/theme:theme_resources",
"//chrome/browser/ui/views", "//chrome/browser/ui/views",
"//chrome/common:buildflags",
"//chrome/common:constants", "//chrome/common:constants",
"//components/prefs", "//components/prefs",
"//components/resources",
"//content/public/browser", "//content/public/browser",
"//printing", "//printing",
"//skia", "//skia",
...@@ -94,11 +77,9 @@ jumbo_component("libgtkui") { ...@@ -94,11 +77,9 @@ jumbo_component("libgtkui") {
"//ui/events", "//ui/events",
"//ui/events:dom_keyboard_layout", "//ui/events:dom_keyboard_layout",
"//ui/events:dom_keycode_converter", "//ui/events:dom_keycode_converter",
"//ui/events:events_base",
"//ui/gfx", "//ui/gfx",
"//ui/gfx/geometry", "//ui/gfx/geometry",
"//ui/native_theme", "//ui/native_theme",
"//ui/resources",
"//ui/shell_dialogs", "//ui/shell_dialogs",
"//ui/strings", "//ui/strings",
"//ui/views", "//ui/views",
...@@ -113,6 +94,8 @@ jumbo_component("libgtkui") { ...@@ -113,6 +94,8 @@ jumbo_component("libgtkui") {
"gtk_event_loop_x11.h", "gtk_event_loop_x11.h",
] ]
configs += [ "//build/config/linux:x11" ]
defines += [ "USE_GTK_EVENT_LOOP_X11" ] defines += [ "USE_GTK_EVENT_LOOP_X11" ]
deps += [ deps += [
......
...@@ -355,7 +355,7 @@ void GtkKeyBindingsHandler::MoveCursor(GtkTextView* text_view, ...@@ -355,7 +355,7 @@ void GtkKeyBindingsHandler::MoveCursor(GtkTextView* text_view,
void GtkKeyBindingsHandler::MoveViewport(GtkTextView* text_view, void GtkKeyBindingsHandler::MoveViewport(GtkTextView* text_view,
GtkScrollStep step, GtkScrollStep step,
gint count) { gint count) {
// Not supported by webkit. // Not supported by Blink.
} }
void GtkKeyBindingsHandler::PasteClipboard(GtkTextView* text_view) { void GtkKeyBindingsHandler::PasteClipboard(GtkTextView* text_view) {
...@@ -375,11 +375,11 @@ void GtkKeyBindingsHandler::SetAnchor(GtkTextView* text_view) { ...@@ -375,11 +375,11 @@ void GtkKeyBindingsHandler::SetAnchor(GtkTextView* text_view) {
} }
void GtkKeyBindingsHandler::ToggleCursorVisible(GtkTextView* text_view) { void GtkKeyBindingsHandler::ToggleCursorVisible(GtkTextView* text_view) {
// Not supported by webkit. // Not supported by Blink.
} }
void GtkKeyBindingsHandler::ToggleOverwrite(GtkTextView* text_view) { void GtkKeyBindingsHandler::ToggleOverwrite(GtkTextView* text_view) {
// Not supported by webkit. // Not supported by Blink.
} }
#if !GTK_CHECK_VERSION(3, 90, 0) #if !GTK_CHECK_VERSION(3, 90, 0)
......
...@@ -34,10 +34,8 @@ namespace libgtkui { ...@@ -34,10 +34,8 @@ namespace libgtkui {
// class derived from GtkTextView is used, which overrides all signals related // class derived from GtkTextView is used, which overrides all signals related
// to key bindings, to make sure GtkTextView won't receive them. // to key bindings, to make sure GtkTextView won't receive them.
// //
// See third_party/WebKit/Source/WebCore/editing/EditorCommand.cpp for detailed // See third_party/blink/renderer/core/editing/commands/editor_command.cc for
// definition of webkit edit commands. // detailed definition of Blink edit commands.
// See webkit/glue/editor_client_impl.cc for key bindings predefined in our
// webkit glue.
class GtkKeyBindingsHandler { class GtkKeyBindingsHandler {
public: public:
GtkKeyBindingsHandler(); GtkKeyBindingsHandler();
......
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
#include "base/containers/flat_map.h" #include "base/containers/flat_map.h"
#include "base/debug/leak_annotations.h" #include "base/debug/leak_annotations.h"
#include "base/environment.h" #include "base/environment.h"
#include "base/i18n/rtl.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/nix/mime_util_xdg.h" #include "base/nix/mime_util_xdg.h"
#include "base/nix/xdg_util.h" #include "base/nix/xdg_util.h"
...@@ -33,7 +32,6 @@ ...@@ -33,7 +32,6 @@
#include "chrome/browser/ui/libgtkui/printing_gtk_util.h" #include "chrome/browser/ui/libgtkui/printing_gtk_util.h"
#include "chrome/browser/ui/libgtkui/select_file_dialog_impl.h" #include "chrome/browser/ui/libgtkui/select_file_dialog_impl.h"
#include "chrome/browser/ui/libgtkui/settings_provider_gtk.h" #include "chrome/browser/ui/libgtkui/settings_provider_gtk.h"
#include "chrome/browser/ui/libgtkui/skia_utils_gtk.h"
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
#include "printing/buildflags/buildflags.h" #include "printing/buildflags/buildflags.h"
...@@ -44,7 +42,6 @@ ...@@ -44,7 +42,6 @@
#include "ui/base/ime/linux/fake_input_method_context.h" #include "ui/base/ime/linux/fake_input_method_context.h"
#include "ui/base/ime/linux/linux_input_method_context.h" #include "ui/base/ime/linux/linux_input_method_context.h"
#include "ui/base/ime/linux/linux_input_method_context_factory.h" #include "ui/base/ime/linux/linux_input_method_context_factory.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/display/display.h" #include "ui/display/display.h"
#include "ui/events/keycodes/dom/dom_code.h" #include "ui/events/keycodes/dom/dom_code.h"
#include "ui/events/keycodes/dom/dom_keyboard_layout_manager.h" #include "ui/events/keycodes/dom/dom_keyboard_layout_manager.h"
...@@ -64,7 +61,6 @@ ...@@ -64,7 +61,6 @@
#include "ui/views/controls/button/label_button_border.h" #include "ui/views/controls/button/label_button_border.h"
#include "ui/views/linux_ui/device_scale_factor_observer.h" #include "ui/views/linux_ui/device_scale_factor_observer.h"
#include "ui/views/linux_ui/window_button_order_observer.h" #include "ui/views/linux_ui/window_button_order_observer.h"
#include "ui/views/resources/grit/views_resources.h"
#if defined(USE_GIO) #if defined(USE_GIO)
#include "chrome/browser/ui/libgtkui/settings_provider_gsettings.h" #include "chrome/browser/ui/libgtkui/settings_provider_gsettings.h"
...@@ -89,14 +85,6 @@ ...@@ -89,14 +85,6 @@
#include "chrome/browser/ui/views/nav_button_provider.h" #include "chrome/browser/ui/views/nav_button_provider.h"
#endif #endif
// A minimized port of GtkThemeService into something that can provide colors
// and images for aura.
//
// TODO(erg): There's still a lot that needs ported or done for the first time:
//
// - Render and inject the omnibox background.
// - Make sure to test with a light on dark theme, too.
namespace libgtkui { namespace libgtkui {
namespace { namespace {
...@@ -338,6 +326,61 @@ bool ShouldCreateGtkEventLoopX11() { ...@@ -338,6 +326,61 @@ bool ShouldCreateGtkEventLoopX11() {
} }
#endif // defined(USE_GTK_EVENT_LOOP_X11) #endif // defined(USE_GTK_EVENT_LOOP_X11)
const SkBitmap GdkPixbufToSkBitmap(GdkPixbuf* pixbuf) {
// TODO(erg): What do we do in the case where the pixbuf fails these dchecks?
// I would prefer to use our gtk based canvas, but that would require
// recompiling half of our skia extensions with gtk support, which we can't
// do in this build.
DCHECK_EQ(GDK_COLORSPACE_RGB, gdk_pixbuf_get_colorspace(pixbuf));
int n_channels = gdk_pixbuf_get_n_channels(pixbuf);
int w = gdk_pixbuf_get_width(pixbuf);
int h = gdk_pixbuf_get_height(pixbuf);
SkBitmap ret;
ret.allocN32Pixels(w, h);
ret.eraseColor(0);
uint32_t* skia_data = static_cast<uint32_t*>(ret.getAddr(0, 0));
if (n_channels == 4) {
int total_length = w * h;
guchar* gdk_pixels = gdk_pixbuf_get_pixels(pixbuf);
// Now here's the trick: we need to convert the gdk data (which is RGBA and
// isn't premultiplied) to skia (which can be anything and premultiplied).
for (int i = 0; i < total_length; ++i, gdk_pixels += 4) {
const unsigned char& red = gdk_pixels[0];
const unsigned char& green = gdk_pixels[1];
const unsigned char& blue = gdk_pixels[2];
const unsigned char& alpha = gdk_pixels[3];
skia_data[i] = SkPreMultiplyARGB(alpha, red, green, blue);
}
} else if (n_channels == 3) {
// Because GDK makes rowstrides word aligned, we need to do something a bit
// more complex when a pixel isn't perfectly a word of memory.
int rowstride = gdk_pixbuf_get_rowstride(pixbuf);
guchar* gdk_pixels = gdk_pixbuf_get_pixels(pixbuf);
for (int y = 0; y < h; ++y) {
int row = y * rowstride;
for (int x = 0; x < w; ++x) {
guchar* pixel = gdk_pixels + row + (x * 3);
const unsigned char& red = pixel[0];
const unsigned char& green = pixel[1];
const unsigned char& blue = pixel[2];
skia_data[y * w + x] = SkPreMultiplyARGB(255, red, green, blue);
}
}
} else {
NOTREACHED();
}
return ret;
}
} // namespace } // namespace
GtkUi::GtkUi() { GtkUi::GtkUi() {
...@@ -493,8 +536,7 @@ base::TimeDelta GtkUi::GetCursorBlinkInterval() const { ...@@ -493,8 +536,7 @@ base::TimeDelta GtkUi::GetCursorBlinkInterval() const {
// Dividing GTK's cursor blink cycle time (in milliseconds) by this value // Dividing GTK's cursor blink cycle time (in milliseconds) by this value
// yields an appropriate value for // yields an appropriate value for
// blink::mojom::RendererPreferences::caret_blink_interval. This // blink::mojom::RendererPreferences::caret_blink_interval.
// matches the logic in the WebKit GTK port.
static const double kGtkCursorBlinkCycleFactor = 2000.0; static const double kGtkCursorBlinkCycleFactor = 2000.0;
gint cursor_blink_time = kGtkDefaultCursorBlinkTime; gint cursor_blink_time = kGtkDefaultCursorBlinkTime;
...@@ -560,7 +602,7 @@ gfx::Image GtkUi::GetIconForContentType(const std::string& content_type, ...@@ -560,7 +602,7 @@ gfx::Image GtkUi::GetIconForContentType(const std::string& content_type,
if (!pixbuf) if (!pixbuf)
continue; continue;
SkBitmap bitmap = GdkPixbufToImageSkia(pixbuf.get()); SkBitmap bitmap = GdkPixbufToSkBitmap(pixbuf.get());
DCHECK_EQ(size, bitmap.width()); DCHECK_EQ(size, bitmap.width());
DCHECK_EQ(size, bitmap.height()); DCHECK_EQ(size, bitmap.height());
gfx::ImageSkia image_skia = gfx::ImageSkia::CreateFrom1xBitmap(bitmap); gfx::ImageSkia image_skia = gfx::ImageSkia::CreateFrom1xBitmap(bitmap);
...@@ -837,7 +879,7 @@ void GtkUi::UpdateColors() { ...@@ -837,7 +879,7 @@ void GtkUi::UpdateColors() {
colors_[ThemeProperties::COLOR_NTP_LINK] = native_theme_->GetSystemColor( colors_[ThemeProperties::COLOR_NTP_LINK] = native_theme_->GetSystemColor(
ui::NativeTheme::kColorId_TextfieldSelectionBackgroundFocused); ui::NativeTheme::kColorId_TextfieldSelectionBackgroundFocused);
// Generate the colors that we pass to WebKit. // Generate the colors that we pass to Blink.
focus_ring_color_ = native_theme_->GetSystemColor( focus_ring_color_ = native_theme_->GetSystemColor(
ui::NativeTheme::kColorId_FocusedBorderColor); ui::NativeTheme::kColorId_FocusedBorderColor);
......
...@@ -10,10 +10,10 @@ ...@@ -10,10 +10,10 @@
#include <vector> #include <vector>
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "base/component_export.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/observer_list.h" #include "base/observer_list.h"
#include "build/buildflag.h" #include "build/buildflag.h"
#include "chrome/browser/ui/libgtkui/libgtkui_export.h"
#include "ui/base/glib/glib_signal.h" #include "ui/base/glib/glib_signal.h"
#include "ui/gfx/color_utils.h" #include "ui/gfx/color_utils.h"
#include "ui/views/linux_ui/linux_ui.h" #include "ui/views/linux_ui/linux_ui.h"
...@@ -124,7 +124,7 @@ class GtkUi : public views::LinuxUI { ...@@ -124,7 +124,7 @@ class GtkUi : public views::LinuxUI {
void LoadGtkValues(); void LoadGtkValues();
// Extracts colors and tints from the GTK theme, both for the // Extracts colors and tints from the GTK theme, both for the
// ThemeService interface and the colors we send to webkit. // ThemeService interface and the colors we send to Blink.
void UpdateColors(); void UpdateColors();
// Sets the Xcursor theme and size with the GTK theme and size. // Sets the Xcursor theme and size with the GTK theme and size.
...@@ -152,7 +152,7 @@ class GtkUi : public views::LinuxUI { ...@@ -152,7 +152,7 @@ class GtkUi : public views::LinuxUI {
// system-rendered borders and titlebar. // system-rendered borders and titlebar.
ColorMap native_frame_colors_; ColorMap native_frame_colors_;
// Colors that we pass to WebKit. These are generated each time the theme // Colors that we pass to Blink. These are generated each time the theme
// changes. // changes.
SkColor focus_ring_color_; SkColor focus_ring_color_;
SkColor active_selection_bg_color_; SkColor active_selection_bg_color_;
...@@ -203,6 +203,6 @@ class GtkUi : public views::LinuxUI { ...@@ -203,6 +203,6 @@ class GtkUi : public views::LinuxUI {
} // namespace libgtkui } // namespace libgtkui
// Access point to the GTK desktop system. // Access point to the GTK desktop system.
LIBGTKUI_EXPORT views::LinuxUI* BuildGtkUi(); COMPONENT_EXPORT(LIBGTKUI) views::LinuxUI* BuildGtkUi();
#endif // CHROME_BROWSER_UI_LIBGTKUI_GTK_UI_H_ #endif // CHROME_BROWSER_UI_LIBGTKUI_GTK_UI_H_
...@@ -20,7 +20,6 @@ ...@@ -20,7 +20,6 @@
#include "base/strings/string_split.h" #include "base/strings/string_split.h"
#include "base/strings/string_tokenizer.h" #include "base/strings/string_tokenizer.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "build/branding_buildflags.h"
#include "ui/aura/window_tree_host.h" #include "ui/aura/window_tree_host.h"
#include "ui/base/accelerators/accelerator.h" #include "ui/base/accelerators/accelerator.h"
#include "ui/events/event.h" #include "ui/events/event.h"
...@@ -138,37 +137,6 @@ void GtkInitFromCommandLine(const base::CommandLine& command_line) { ...@@ -138,37 +137,6 @@ void GtkInitFromCommandLine(const base::CommandLine& command_line) {
CommonInitFromCommandLine(command_line); CommonInitFromCommandLine(command_line);
} }
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_SHIFT_MASK) ? ui::EF_SHIFT_DOWN : ui::EF_NONE;
flags |= (state & GDK_LOCK_MASK) ? ui::EF_CAPS_LOCK_ON : ui::EF_NONE;
flags |= (state & GDK_CONTROL_MASK) ? ui::EF_CONTROL_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 TurnButtonBlue(GtkWidget* button) {
gtk_style_context_add_class(gtk_widget_get_style_context(button),
"suggested-action");
}
void SetGtkTransientForAura(GtkWidget* dialog, aura::Window* parent) { void SetGtkTransientForAura(GtkWidget* dialog, aura::Window* parent) {
if (!parent || !parent->GetHost()) if (!parent || !parent->GetHost())
return; return;
...@@ -243,14 +211,6 @@ PROTECTED_MEMORY_SECTION base::ProtectedMemory<GtkSetObjectName> ...@@ -243,14 +211,6 @@ PROTECTED_MEMORY_SECTION base::ProtectedMemory<GtkSetObjectName>
} // namespace } // namespace
void* GetGdkSharedLibrary() {
std::string lib_name =
"libgdk-" + std::to_string(GTK_MAJOR_VERSION) + ".so.0";
static void* gdk_lib = dlopen(lib_name.c_str(), RTLD_LAZY);
DCHECK(gdk_lib);
return gdk_lib;
}
void* GetGtkSharedLibrary() { void* GetGtkSharedLibrary() {
std::string lib_name = std::string lib_name =
"libgtk-" + std::to_string(GTK_MAJOR_VERSION) + ".so.0"; "libgtk-" + std::to_string(GTK_MAJOR_VERSION) + ".so.0";
...@@ -645,14 +605,6 @@ std::string GetGtkSettingsStringProperty(GtkSettings* settings, ...@@ -645,14 +605,6 @@ std::string GetGtkSettingsStringProperty(GtkSettings* settings,
return prop_value; return prop_value;
} }
#if defined(USE_X11)
guint GetGdkKeyCodeForAccelerator(const ui::Accelerator& accelerator) {
// The second parameter is false because accelerator keys are expressed in
// terms of the non-shift-modified key.
return XKeysymForWindowsKeyCode(accelerator.key_code(), false);
}
#endif
GdkDisplay* GetGdkDisplay() { GdkDisplay* GetGdkDisplay() {
GdkDisplay* display = nullptr; GdkDisplay* display = nullptr;
// TODO(crbug.com/1002674): Remove once GtkIM-based LinuxInputMethodContext // TODO(crbug.com/1002674): Remove once GtkIM-based LinuxInputMethodContext
......
...@@ -27,7 +27,6 @@ struct HSL; ...@@ -27,7 +27,6 @@ struct HSL;
} }
namespace ui { namespace ui {
class Accelerator;
class KeyEvent; class KeyEvent;
} }
...@@ -37,15 +36,6 @@ extern const color_utils::HSL kDefaultTintFrameIncognito; ...@@ -37,15 +36,6 @@ extern const color_utils::HSL kDefaultTintFrameIncognito;
void GtkInitFromCommandLine(const base::CommandLine& command_line); void GtkInitFromCommandLine(const base::CommandLine& command_line);
GdkModifierType GetGdkModifierForAccelerator(
const ui::Accelerator& accelerator);
// Translates event flags into plaform independent event flags.
int EventFlagsFromGdkState(guint state);
// Style a GTK button as a BlueButton
void TurnButtonBlue(GtkWidget* button);
// Sets |dialog| as transient for |parent|, which will keep it on top and center // Sets |dialog| as transient for |parent|, which will keep it on top and center
// it above |parent|. Do nothing if |parent| is nullptr. // it above |parent|. Do nothing if |parent| is nullptr.
void SetGtkTransientForAura(GtkWidget* dialog, aura::Window* parent); void SetGtkTransientForAura(GtkWidget* dialog, aura::Window* parent);
...@@ -64,7 +54,6 @@ void ParseButtonLayout(const std::string& button_string, ...@@ -64,7 +54,6 @@ void ParseButtonLayout(const std::string& button_string,
std::vector<views::FrameButton>* leading_buttons, std::vector<views::FrameButton>* leading_buttons,
std::vector<views::FrameButton>* trailing_buttons); std::vector<views::FrameButton>* trailing_buttons);
void* GetGdkSharedLibrary();
void* GetGtkSharedLibrary(); void* GetGtkSharedLibrary();
class CairoSurface { class CairoSurface {
...@@ -185,11 +174,6 @@ SkColor GetSeparatorColor(const std::string& css_selector); ...@@ -185,11 +174,6 @@ SkColor GetSeparatorColor(const std::string& css_selector);
std::string GetGtkSettingsStringProperty(GtkSettings* settings, std::string GetGtkSettingsStringProperty(GtkSettings* settings,
const gchar* prop_name); const gchar* prop_name);
#if defined(USE_X11)
// TODO(thomasanderson): Remove this once GtkStatusIcon is removed.
guint GetGdkKeyCodeForAccelerator(const ui::Accelerator& accelerator);
#endif
// Get current GdkDisplay instance // Get current GdkDisplay instance
GdkDisplay* GetGdkDisplay(); GdkDisplay* GetGdkDisplay();
......
// 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 CHROME_BROWSER_UI_LIBGTKUI_LIBGTKUI_EXPORT_H_
#define CHROME_BROWSER_UI_LIBGTKUI_LIBGTKUI_EXPORT_H_
// Defines LIBGTKUI_EXPORT so that functionality implemented by our limited
// gtk module can be exported to consumers.
#if defined(COMPONENT_BUILD)
#if defined(WIN32)
#error "LIBGTKUI does not build on Windows."
#else // defined(WIN32)
#if defined(LIBGTKUI_IMPLEMENTATION)
#define LIBGTKUI_EXPORT __attribute__((visibility("default")))
#else
#define LIBGTKUI_EXPORT
#endif
#endif
#else // defined(COMPONENT_BUILD)
#define LIBGTKUI_EXPORT
#endif
#endif // CHROME_BROWSER_UI_LIBGTKUI_LIBGTKUI_EXPORT_H_
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include "chrome/browser/ui/libgtkui/gtk_util.h" #include "chrome/browser/ui/libgtkui/gtk_util.h"
#include "chrome/browser/ui/libgtkui/skia_utils_gtk.h"
#include "ui/gfx/color_palette.h" #include "ui/gfx/color_palette.h"
#include "ui/gfx/color_utils.h" #include "ui/gfx/color_utils.h"
#include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/rect.h"
...@@ -159,7 +158,8 @@ SkColor SkColorFromColorId(ui::NativeTheme::ColorId color_id) { ...@@ -159,7 +158,8 @@ SkColor SkColorFromColorId(ui::NativeTheme::ColorId color_id) {
GdkColor* color; GdkColor* color;
gtk_style_context_get_style(link_context, "link-color", &color, nullptr); gtk_style_context_get_style(link_context, "link-color", &color, nullptr);
if (color) { if (color) {
SkColor ret_color = GdkColorToSkColor(*color); SkColor ret_color =
SkColorSetRGB(color->red >> 8, color->green >> 8, color->blue >> 8);
// gdk_color_free() was deprecated in Gtk3.14. This code path is only // gdk_color_free() was deprecated in Gtk3.14. This code path is only
// taken on versions earlier than Gtk3.12, but the compiler doesn't know // taken on versions earlier than Gtk3.12, but the compiler doesn't know
// that, so silence the deprecation warnings. // that, so silence the deprecation warnings.
......
...@@ -7,15 +7,16 @@ ...@@ -7,15 +7,16 @@
#include <map> #include <map>
#include "base/component_export.h"
#include "chrome/browser/ui/frame_button_display_types.h" #include "chrome/browser/ui/frame_button_display_types.h"
#include "chrome/browser/ui/libgtkui/libgtkui_export.h"
#include "chrome/browser/ui/views/nav_button_provider.h" #include "chrome/browser/ui/views/nav_button_provider.h"
#include "ui/gfx/image/image_skia.h" #include "ui/gfx/image/image_skia.h"
#include "ui/views/controls/button/button.h" #include "ui/views/controls/button/button.h"
namespace libgtkui { namespace libgtkui {
class LIBGTKUI_EXPORT NavButtonProviderGtk : public views::NavButtonProvider { class COMPONENT_EXPORT(LIBGTKUI) NavButtonProviderGtk
: public views::NavButtonProvider {
public: public:
NavButtonProviderGtk(); NavButtonProviderGtk();
~NavButtonProviderGtk() override; ~NavButtonProviderGtk() override;
......
...@@ -31,7 +31,6 @@ ...@@ -31,7 +31,6 @@
#include "ui/gfx/x/x11.h" #include "ui/gfx/x/x11.h"
#include "ui/strings/grit/ui_strings.h" #include "ui/strings/grit/ui_strings.h"
using content::BrowserThread; using content::BrowserThread;
namespace { namespace {
......
// 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 "chrome/browser/ui/libgtkui/skia_utils_gtk.h"
#include <gdk/gdk.h>
#include "base/logging.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkUnPreMultiply.h"
namespace libgtkui {
// GDK_COLOR_RGB multiplies by 257 (= 0x10001) to distribute the bits evenly
// See: http://www.mindcontrol.org/~hplus/graphics/expand-bits.html
// To get back, we can just right shift by eight
// (or, formulated differently, i == (i*257)/256 for all i < 256).
#if !GTK_CHECK_VERSION(3, 90, 0)
SkColor GdkColorToSkColor(GdkColor color) {
return SkColorSetRGB(color.red >> 8, color.green >> 8, color.blue >> 8);
}
GdkColor SkColorToGdkColor(SkColor color) {
GdkColor gdk_color = {
0, static_cast<guint16>(SkColorGetR(color) * kSkiaToGDKMultiplier),
static_cast<guint16>(SkColorGetG(color) * kSkiaToGDKMultiplier),
static_cast<guint16>(SkColorGetB(color) * kSkiaToGDKMultiplier)};
return gdk_color;
}
#endif
const SkBitmap GdkPixbufToImageSkia(GdkPixbuf* pixbuf) {
// TODO(erg): What do we do in the case where the pixbuf fails these dchecks?
// I would prefer to use our gtk based canvas, but that would require
// recompiling half of our skia extensions with gtk support, which we can't
// do in this build.
DCHECK_EQ(GDK_COLORSPACE_RGB, gdk_pixbuf_get_colorspace(pixbuf));
int n_channels = gdk_pixbuf_get_n_channels(pixbuf);
int w = gdk_pixbuf_get_width(pixbuf);
int h = gdk_pixbuf_get_height(pixbuf);
SkBitmap ret;
ret.allocN32Pixels(w, h);
ret.eraseColor(0);
uint32_t* skia_data = static_cast<uint32_t*>(ret.getAddr(0, 0));
if (n_channels == 4) {
int total_length = w * h;
guchar* gdk_pixels = gdk_pixbuf_get_pixels(pixbuf);
// Now here's the trick: we need to convert the gdk data (which is RGBA and
// isn't premultiplied) to skia (which can be anything and premultiplied).
for (int i = 0; i < total_length; ++i, gdk_pixels += 4) {
const unsigned char& red = gdk_pixels[0];
const unsigned char& green = gdk_pixels[1];
const unsigned char& blue = gdk_pixels[2];
const unsigned char& alpha = gdk_pixels[3];
skia_data[i] = SkPreMultiplyARGB(alpha, red, green, blue);
}
} else if (n_channels == 3) {
// Because GDK makes rowstrides word aligned, we need to do something a bit
// more complex when a pixel isn't perfectly a word of memory.
int rowstride = gdk_pixbuf_get_rowstride(pixbuf);
guchar* gdk_pixels = gdk_pixbuf_get_pixels(pixbuf);
for (int y = 0; y < h; ++y) {
int row = y * rowstride;
for (int x = 0; x < w; ++x) {
guchar* pixel = gdk_pixels + row + (x * 3);
const unsigned char& red = pixel[0];
const unsigned char& green = pixel[1];
const unsigned char& blue = pixel[2];
skia_data[y * w + x] = SkPreMultiplyARGB(255, red, green, blue);
}
}
} else {
NOTREACHED();
}
return ret;
}
GdkPixbuf* GdkPixbufFromSkBitmap(const SkBitmap& bitmap) {
if (bitmap.isNull())
return nullptr;
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_t* divided = gdk_pixbuf_get_pixels(pixbuf);
for (int y = 0, i = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
uint32_t 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;
}
} // namespace libgtkui
// 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 CHROME_BROWSER_UI_LIBGTKUI_SKIA_UTILS_GTK_H_
#define CHROME_BROWSER_UI_LIBGTKUI_SKIA_UTILS_GTK_H_
#include <gtk/gtk.h>
#include <stdint.h>
#include "third_party/skia/include/core/SkColor.h"
#if !GTK_CHECK_VERSION(3, 90, 0)
typedef struct _GdkColor GdkColor;
#endif
typedef struct _GdkPixbuf GdkPixbuf;
class SkBitmap;
#if !GTK_CHECK_VERSION(3, 90, 0)
// Define a macro for creating GdkColors from RGB values. This is a macro to
// allow static construction of literals, etc. Use this like:
// GdkColor white = GDK_COLOR_RGB(0xff, 0xff, 0xff);
#define GDK_COLOR_RGB(r, g, b) \
{ \
0, \
r * ::libgtkui::kSkiaToGDKMultiplier, \
g * ::libgtkui::kSkiaToGDKMultiplier, \
b * ::libgtkui::kSkiaToGDKMultiplier, \
}
#endif
namespace libgtkui {
#if !GTK_CHECK_VERSION(3, 90, 0)
// Multiply uint8_t color components by this.
const int kSkiaToGDKMultiplier = 257;
// Converts GdkColors to the ARGB layout Skia expects.
SkColor GdkColorToSkColor(GdkColor color);
// Converts ARGB to GdkColor.
GdkColor SkColorToGdkColor(SkColor color);
#endif
const SkBitmap GdkPixbufToImageSkia(GdkPixbuf* pixbuf);
// 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.
GdkPixbuf* GdkPixbufFromSkBitmap(const SkBitmap& bitmap);
} // namespace libgtkui
#endif // CHROME_BROWSER_UI_LIBGTKUI_SKIA_UTILS_GTK_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment