| Index: chrome/browser/ui/libgtk2ui/gtk2_ui.cc
|
| diff --git a/chrome/browser/ui/libgtk2ui/gtk2_ui.cc b/chrome/browser/ui/libgtk2ui/gtk2_ui.cc
|
| index dc44417c7072ebe40b3bf8b74e8b8983d240ccba..de1bcc8c14f282e276cd63cac3fdfb54bd289d9f 100644
|
| --- a/chrome/browser/ui/libgtk2ui/gtk2_ui.cc
|
| +++ b/chrome/browser/ui/libgtk2ui/gtk2_ui.cc
|
| @@ -6,6 +6,8 @@
|
|
|
| #include <set>
|
|
|
| +#include <pango/pango.h>
|
| +
|
| #include "base/command_line.h"
|
| #include "base/debug/leak_annotations.h"
|
| #include "base/environment.h"
|
| @@ -40,6 +42,7 @@
|
| #include "ui/base/resource/resource_bundle.h"
|
| #include "ui/gfx/canvas.h"
|
| #include "ui/gfx/image/image.h"
|
| +#include "ui/gfx/pango_util.h"
|
| #include "ui/gfx/rect.h"
|
| #include "ui/gfx/size.h"
|
| #include "ui/gfx/skbitmap_operations.h"
|
| @@ -315,6 +318,58 @@ color_utils::HSL GetDefaultTint(int id) {
|
| }
|
| }
|
|
|
| +// Returns a FontRenderParams corresponding to GTK's configuration.
|
| +gfx::FontRenderParams GetGtkFontRenderParams() {
|
| + GtkSettings* gtk_settings = gtk_settings_get_default();
|
| + CHECK(gtk_settings);
|
| + gint antialias = 0;
|
| + gint hinting = 0;
|
| + gchar* hint_style = NULL;
|
| + gchar* rgba = NULL;
|
| + g_object_get(gtk_settings,
|
| + "gtk-xft-antialias", &antialias,
|
| + "gtk-xft-hinting", &hinting,
|
| + "gtk-xft-hintstyle", &hint_style,
|
| + "gtk-xft-rgba", &rgba,
|
| + NULL);
|
| +
|
| + gfx::FontRenderParams params;
|
| + params.antialiasing = antialias != 0;
|
| +
|
| + if (hinting == 0 || !hint_style || strcmp(hint_style, "hintnone") == 0) {
|
| + params.hinting = gfx::FontRenderParams::HINTING_NONE;
|
| + } else if (strcmp(hint_style, "hintslight") == 0) {
|
| + params.hinting = gfx::FontRenderParams::HINTING_SLIGHT;
|
| + } else if (strcmp(hint_style, "hintmedium") == 0) {
|
| + params.hinting = gfx::FontRenderParams::HINTING_MEDIUM;
|
| + } else if (strcmp(hint_style, "hintfull") == 0) {
|
| + params.hinting = gfx::FontRenderParams::HINTING_FULL;
|
| + } else {
|
| + LOG(WARNING) << "Unexpected gtk-xft-hintstyle \"" << hint_style << "\"";
|
| + params.hinting = gfx::FontRenderParams::HINTING_NONE;
|
| + }
|
| +
|
| + if (!rgba || strcmp(rgba, "none") == 0) {
|
| + params.subpixel_rendering = gfx::FontRenderParams::SUBPIXEL_RENDERING_NONE;
|
| + } else if (strcmp(rgba, "rgb") == 0) {
|
| + params.subpixel_rendering = gfx::FontRenderParams::SUBPIXEL_RENDERING_RGB;
|
| + } else if (strcmp(rgba, "bgr") == 0) {
|
| + params.subpixel_rendering = gfx::FontRenderParams::SUBPIXEL_RENDERING_BGR;
|
| + } else if (strcmp(rgba, "vrgb") == 0) {
|
| + params.subpixel_rendering = gfx::FontRenderParams::SUBPIXEL_RENDERING_VRGB;
|
| + } else if (strcmp(rgba, "vbgr") == 0) {
|
| + params.subpixel_rendering = gfx::FontRenderParams::SUBPIXEL_RENDERING_VBGR;
|
| + } else {
|
| + LOG(WARNING) << "Unexpected gtk-xft-rgba \"" << rgba << "\"";
|
| + params.subpixel_rendering = gfx::FontRenderParams::SUBPIXEL_RENDERING_NONE;
|
| + }
|
| +
|
| + g_free(hint_style);
|
| + g_free(rgba);
|
| +
|
| + return params;
|
| +}
|
| +
|
| } // namespace
|
|
|
| Gtk2UI::Gtk2UI() : middle_click_action_(MIDDLE_CLICK_ACTION_LOWER) {
|
| @@ -588,75 +643,16 @@ scoped_ptr<ui::LinuxInputMethodContext> Gtk2UI::CreateInputMethodContext(
|
| new X11InputMethodContextImplGtk2(delegate));
|
| }
|
|
|
| -bool Gtk2UI::UseAntialiasing() const {
|
| - GtkSettings* gtk_settings = gtk_settings_get_default();
|
| - CHECK(gtk_settings);
|
| - gint gtk_antialias = 0;
|
| - g_object_get(gtk_settings,
|
| - "gtk-xft-antialias", >k_antialias,
|
| - NULL);
|
| - return gtk_antialias != 0;
|
| -}
|
| -
|
| -gfx::FontRenderParams::Hinting Gtk2UI::GetHintingStyle() const {
|
| - GtkSettings* gtk_settings = gtk_settings_get_default();
|
| - CHECK(gtk_settings);
|
| - gfx::FontRenderParams::Hinting hinting =
|
| - gfx::FontRenderParams::HINTING_SLIGHT;
|
| - gint gtk_hinting = 0;
|
| - gchar* gtk_hint_style = NULL;
|
| - g_object_get(gtk_settings,
|
| - "gtk-xft-hinting", >k_hinting,
|
| - "gtk-xft-hintstyle", >k_hint_style,
|
| - NULL);
|
| -
|
| - if (gtk_hint_style) {
|
| - if (gtk_hinting == 0 || strcmp(gtk_hint_style, "hintnone") == 0)
|
| - hinting = gfx::FontRenderParams::HINTING_NONE;
|
| - else if (strcmp(gtk_hint_style, "hintslight") == 0)
|
| - hinting = gfx::FontRenderParams::HINTING_SLIGHT;
|
| - else if (strcmp(gtk_hint_style, "hintmedium") == 0)
|
| - hinting = gfx::FontRenderParams::HINTING_MEDIUM;
|
| - else if (strcmp(gtk_hint_style, "hintfull") == 0)
|
| - hinting = gfx::FontRenderParams::HINTING_FULL;
|
| -
|
| - g_free(gtk_hint_style);
|
| - }
|
| -
|
| - return hinting;
|
| +gfx::FontRenderParams Gtk2UI::GetDefaultFontRenderParams() const {
|
| + static gfx::FontRenderParams params = GetGtkFontRenderParams();
|
| + return params;
|
| }
|
|
|
| -gfx::FontRenderParams::SubpixelRendering
|
| -Gtk2UI::GetSubpixelRenderingStyle() const {
|
| - GtkSettings* gtk_settings = gtk_settings_get_default();
|
| - CHECK(gtk_settings);
|
| - gfx::FontRenderParams::SubpixelRendering subpixel_rendering =
|
| - gfx::FontRenderParams::SUBPIXEL_RENDERING_NONE;
|
| - gchar* gtk_rgba = NULL;
|
| - g_object_get(gtk_settings,
|
| - "gtk-xft-rgba", >k_rgba,
|
| - NULL);
|
| -
|
| - if (gtk_rgba) {
|
| - if (strcmp(gtk_rgba, "none") == 0)
|
| - subpixel_rendering = gfx::FontRenderParams::SUBPIXEL_RENDERING_NONE;
|
| - else if (strcmp(gtk_rgba, "rgb") == 0)
|
| - subpixel_rendering = gfx::FontRenderParams::SUBPIXEL_RENDERING_RGB;
|
| - else if (strcmp(gtk_rgba, "bgr") == 0)
|
| - subpixel_rendering = gfx::FontRenderParams::SUBPIXEL_RENDERING_BGR;
|
| - else if (strcmp(gtk_rgba, "vrgb") == 0)
|
| - subpixel_rendering = gfx::FontRenderParams::SUBPIXEL_RENDERING_VRGB;
|
| - else if (strcmp(gtk_rgba, "vbgr") == 0)
|
| - subpixel_rendering = gfx::FontRenderParams::SUBPIXEL_RENDERING_VBGR;
|
| -
|
| - g_free(gtk_rgba);
|
| - }
|
| -
|
| - return subpixel_rendering;
|
| -}
|
| -
|
| -std::string Gtk2UI::GetDefaultFontDescription() const {
|
| - return default_font_description_;
|
| +scoped_ptr<gfx::ScopedPangoFontDescription>
|
| +Gtk2UI::GetDefaultPangoFontDescription() const {
|
| + return scoped_ptr<gfx::ScopedPangoFontDescription>(
|
| + new gfx::ScopedPangoFontDescription(
|
| + pango_font_description_copy(default_font_description_->get())));
|
| }
|
|
|
| double Gtk2UI::GetFontDPI() const {
|
| @@ -833,27 +829,8 @@ void Gtk2UI::LoadGtkValues() {
|
| SetThemeColorFromGtk(ThemeProperties::COLOR_BOOKMARK_TEXT, &label_color);
|
| SetThemeColorFromGtk(ThemeProperties::COLOR_STATUS_BAR_TEXT, &label_color);
|
|
|
| - gchar* font_string = pango_font_description_to_string(label_style->font_desc);
|
| - default_font_description_ = std::string(font_string);
|
| - g_free(font_string);
|
| -
|
| - {
|
| - // TODO(derat): Remove this debugging code if/when http://crbug.com/375824
|
| - // is resolved.
|
| - GtkSettings* gtk_settings = gtk_settings_get_default();
|
| - CHECK(gtk_settings);
|
| - gchar* font_name = NULL;
|
| - g_object_get(gtk_settings, "gtk-font-name", &font_name, NULL);
|
| - if (font_name) {
|
| - if (std::string(font_name) != default_font_description_) {
|
| - LOG(ERROR) << "Font specified in gtk-font-name property ("
|
| - << font_name << ") does not match font from GtkLabel ("
|
| - << default_font_description_ << "); see "
|
| - << "http://crbug.com/375824";
|
| - }
|
| - g_free(font_name);
|
| - }
|
| - }
|
| + default_font_description_.reset(new gfx::ScopedPangoFontDescription(
|
| + pango_font_description_copy(label_style->font_desc)));
|
|
|
| // Build the various icon tints.
|
| GetNormalButtonTintHSL(&button_tint_);
|
|
|