| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/libgtk2ui/gtk2_ui.h" | 5 #include "chrome/browser/ui/libgtk2ui/gtk2_ui.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include <pango/pango.h> |
| 10 |
| 9 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 10 #include "base/debug/leak_annotations.h" | 12 #include "base/debug/leak_annotations.h" |
| 11 #include "base/environment.h" | 13 #include "base/environment.h" |
| 12 #include "base/i18n/rtl.h" | 14 #include "base/i18n/rtl.h" |
| 13 #include "base/logging.h" | 15 #include "base/logging.h" |
| 14 #include "base/nix/mime_util_xdg.h" | 16 #include "base/nix/mime_util_xdg.h" |
| 15 #include "base/stl_util.h" | 17 #include "base/stl_util.h" |
| 16 #include "base/strings/stringprintf.h" | 18 #include "base/strings/stringprintf.h" |
| 17 #include "chrome/browser/themes/theme_properties.h" | 19 #include "chrome/browser/themes/theme_properties.h" |
| 18 #include "chrome/browser/ui/libgtk2ui/app_indicator_icon.h" | 20 #include "chrome/browser/ui/libgtk2ui/app_indicator_icon.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 33 #include "grit/theme_resources.h" | 35 #include "grit/theme_resources.h" |
| 34 #include "grit/ui_resources.h" | 36 #include "grit/ui_resources.h" |
| 35 #include "printing/printing_context_linux.h" | 37 #include "printing/printing_context_linux.h" |
| 36 #include "third_party/skia/include/core/SkBitmap.h" | 38 #include "third_party/skia/include/core/SkBitmap.h" |
| 37 #include "third_party/skia/include/core/SkCanvas.h" | 39 #include "third_party/skia/include/core/SkCanvas.h" |
| 38 #include "third_party/skia/include/core/SkColor.h" | 40 #include "third_party/skia/include/core/SkColor.h" |
| 39 #include "third_party/skia/include/core/SkShader.h" | 41 #include "third_party/skia/include/core/SkShader.h" |
| 40 #include "ui/base/resource/resource_bundle.h" | 42 #include "ui/base/resource/resource_bundle.h" |
| 41 #include "ui/gfx/canvas.h" | 43 #include "ui/gfx/canvas.h" |
| 42 #include "ui/gfx/image/image.h" | 44 #include "ui/gfx/image/image.h" |
| 45 #include "ui/gfx/pango_util.h" |
| 43 #include "ui/gfx/rect.h" | 46 #include "ui/gfx/rect.h" |
| 44 #include "ui/gfx/size.h" | 47 #include "ui/gfx/size.h" |
| 45 #include "ui/gfx/skbitmap_operations.h" | 48 #include "ui/gfx/skbitmap_operations.h" |
| 46 #include "ui/gfx/skia_util.h" | 49 #include "ui/gfx/skia_util.h" |
| 47 #include "ui/views/controls/button/label_button.h" | 50 #include "ui/views/controls/button/label_button.h" |
| 48 #include "ui/views/controls/button/label_button_border.h" | 51 #include "ui/views/controls/button/label_button_border.h" |
| 49 #include "ui/views/linux_ui/window_button_order_observer.h" | 52 #include "ui/views/linux_ui/window_button_order_observer.h" |
| 50 | 53 |
| 51 #if defined(USE_GCONF) | 54 #if defined(USE_GCONF) |
| 52 #include "chrome/browser/ui/libgtk2ui/gconf_listener.h" | 55 #include "chrome/browser/ui/libgtk2ui/gconf_listener.h" |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 case ThemeProperties::TINT_BUTTONS: | 311 case ThemeProperties::TINT_BUTTONS: |
| 309 return kDefaultTintButtons; | 312 return kDefaultTintButtons; |
| 310 case ThemeProperties::TINT_BACKGROUND_TAB: | 313 case ThemeProperties::TINT_BACKGROUND_TAB: |
| 311 return kDefaultTintBackgroundTab; | 314 return kDefaultTintBackgroundTab; |
| 312 default: | 315 default: |
| 313 color_utils::HSL result = {-1, -1, -1}; | 316 color_utils::HSL result = {-1, -1, -1}; |
| 314 return result; | 317 return result; |
| 315 } | 318 } |
| 316 } | 319 } |
| 317 | 320 |
| 321 // Returns a FontRenderParams corresponding to GTK's configuration. |
| 322 gfx::FontRenderParams GetGtkFontRenderParams() { |
| 323 GtkSettings* gtk_settings = gtk_settings_get_default(); |
| 324 CHECK(gtk_settings); |
| 325 gint antialias = 0; |
| 326 gint hinting = 0; |
| 327 gchar* hint_style = NULL; |
| 328 gchar* rgba = NULL; |
| 329 g_object_get(gtk_settings, |
| 330 "gtk-xft-antialias", &antialias, |
| 331 "gtk-xft-hinting", &hinting, |
| 332 "gtk-xft-hintstyle", &hint_style, |
| 333 "gtk-xft-rgba", &rgba, |
| 334 NULL); |
| 335 |
| 336 gfx::FontRenderParams params; |
| 337 params.antialiasing = antialias != 0; |
| 338 |
| 339 if (hinting == 0 || !hint_style || strcmp(hint_style, "hintnone") == 0) { |
| 340 params.hinting = gfx::FontRenderParams::HINTING_NONE; |
| 341 } else if (strcmp(hint_style, "hintslight") == 0) { |
| 342 params.hinting = gfx::FontRenderParams::HINTING_SLIGHT; |
| 343 } else if (strcmp(hint_style, "hintmedium") == 0) { |
| 344 params.hinting = gfx::FontRenderParams::HINTING_MEDIUM; |
| 345 } else if (strcmp(hint_style, "hintfull") == 0) { |
| 346 params.hinting = gfx::FontRenderParams::HINTING_FULL; |
| 347 } else { |
| 348 LOG(WARNING) << "Unexpected gtk-xft-hintstyle \"" << hint_style << "\""; |
| 349 params.hinting = gfx::FontRenderParams::HINTING_NONE; |
| 350 } |
| 351 |
| 352 if (!rgba || strcmp(rgba, "none") == 0) { |
| 353 params.subpixel_rendering = gfx::FontRenderParams::SUBPIXEL_RENDERING_NONE; |
| 354 } else if (strcmp(rgba, "rgb") == 0) { |
| 355 params.subpixel_rendering = gfx::FontRenderParams::SUBPIXEL_RENDERING_RGB; |
| 356 } else if (strcmp(rgba, "bgr") == 0) { |
| 357 params.subpixel_rendering = gfx::FontRenderParams::SUBPIXEL_RENDERING_BGR; |
| 358 } else if (strcmp(rgba, "vrgb") == 0) { |
| 359 params.subpixel_rendering = gfx::FontRenderParams::SUBPIXEL_RENDERING_VRGB; |
| 360 } else if (strcmp(rgba, "vbgr") == 0) { |
| 361 params.subpixel_rendering = gfx::FontRenderParams::SUBPIXEL_RENDERING_VBGR; |
| 362 } else { |
| 363 LOG(WARNING) << "Unexpected gtk-xft-rgba \"" << rgba << "\""; |
| 364 params.subpixel_rendering = gfx::FontRenderParams::SUBPIXEL_RENDERING_NONE; |
| 365 } |
| 366 |
| 367 g_free(hint_style); |
| 368 g_free(rgba); |
| 369 |
| 370 return params; |
| 371 } |
| 372 |
| 318 } // namespace | 373 } // namespace |
| 319 | 374 |
| 320 Gtk2UI::Gtk2UI() : middle_click_action_(MIDDLE_CLICK_ACTION_LOWER) { | 375 Gtk2UI::Gtk2UI() : middle_click_action_(MIDDLE_CLICK_ACTION_LOWER) { |
| 321 GtkInitFromCommandLine(*CommandLine::ForCurrentProcess()); | 376 GtkInitFromCommandLine(*CommandLine::ForCurrentProcess()); |
| 322 } | 377 } |
| 323 | 378 |
| 324 void Gtk2UI::Initialize() { | 379 void Gtk2UI::Initialize() { |
| 325 signals_.reset(new Gtk2SignalRegistrar); | 380 signals_.reset(new Gtk2SignalRegistrar); |
| 326 | 381 |
| 327 // Create our fake widgets. | 382 // Create our fake widgets. |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 581 void Gtk2UI::SetNonClientMiddleClickAction(NonClientMiddleClickAction action) { | 636 void Gtk2UI::SetNonClientMiddleClickAction(NonClientMiddleClickAction action) { |
| 582 middle_click_action_ = action; | 637 middle_click_action_ = action; |
| 583 } | 638 } |
| 584 | 639 |
| 585 scoped_ptr<ui::LinuxInputMethodContext> Gtk2UI::CreateInputMethodContext( | 640 scoped_ptr<ui::LinuxInputMethodContext> Gtk2UI::CreateInputMethodContext( |
| 586 ui::LinuxInputMethodContextDelegate* delegate) const { | 641 ui::LinuxInputMethodContextDelegate* delegate) const { |
| 587 return scoped_ptr<ui::LinuxInputMethodContext>( | 642 return scoped_ptr<ui::LinuxInputMethodContext>( |
| 588 new X11InputMethodContextImplGtk2(delegate)); | 643 new X11InputMethodContextImplGtk2(delegate)); |
| 589 } | 644 } |
| 590 | 645 |
| 591 bool Gtk2UI::UseAntialiasing() const { | 646 gfx::FontRenderParams Gtk2UI::GetDefaultFontRenderParams() const { |
| 592 GtkSettings* gtk_settings = gtk_settings_get_default(); | 647 static gfx::FontRenderParams params = GetGtkFontRenderParams(); |
| 593 CHECK(gtk_settings); | 648 return params; |
| 594 gint gtk_antialias = 0; | |
| 595 g_object_get(gtk_settings, | |
| 596 "gtk-xft-antialias", >k_antialias, | |
| 597 NULL); | |
| 598 return gtk_antialias != 0; | |
| 599 } | 649 } |
| 600 | 650 |
| 601 gfx::FontRenderParams::Hinting Gtk2UI::GetHintingStyle() const { | 651 scoped_ptr<gfx::ScopedPangoFontDescription> |
| 602 GtkSettings* gtk_settings = gtk_settings_get_default(); | 652 Gtk2UI::GetDefaultPangoFontDescription() const { |
| 603 CHECK(gtk_settings); | 653 return scoped_ptr<gfx::ScopedPangoFontDescription>( |
| 604 gfx::FontRenderParams::Hinting hinting = | 654 new gfx::ScopedPangoFontDescription( |
| 605 gfx::FontRenderParams::HINTING_SLIGHT; | 655 pango_font_description_copy(default_font_description_->get()))); |
| 606 gint gtk_hinting = 0; | |
| 607 gchar* gtk_hint_style = NULL; | |
| 608 g_object_get(gtk_settings, | |
| 609 "gtk-xft-hinting", >k_hinting, | |
| 610 "gtk-xft-hintstyle", >k_hint_style, | |
| 611 NULL); | |
| 612 | |
| 613 if (gtk_hint_style) { | |
| 614 if (gtk_hinting == 0 || strcmp(gtk_hint_style, "hintnone") == 0) | |
| 615 hinting = gfx::FontRenderParams::HINTING_NONE; | |
| 616 else if (strcmp(gtk_hint_style, "hintslight") == 0) | |
| 617 hinting = gfx::FontRenderParams::HINTING_SLIGHT; | |
| 618 else if (strcmp(gtk_hint_style, "hintmedium") == 0) | |
| 619 hinting = gfx::FontRenderParams::HINTING_MEDIUM; | |
| 620 else if (strcmp(gtk_hint_style, "hintfull") == 0) | |
| 621 hinting = gfx::FontRenderParams::HINTING_FULL; | |
| 622 | |
| 623 g_free(gtk_hint_style); | |
| 624 } | |
| 625 | |
| 626 return hinting; | |
| 627 } | |
| 628 | |
| 629 gfx::FontRenderParams::SubpixelRendering | |
| 630 Gtk2UI::GetSubpixelRenderingStyle() const { | |
| 631 GtkSettings* gtk_settings = gtk_settings_get_default(); | |
| 632 CHECK(gtk_settings); | |
| 633 gfx::FontRenderParams::SubpixelRendering subpixel_rendering = | |
| 634 gfx::FontRenderParams::SUBPIXEL_RENDERING_NONE; | |
| 635 gchar* gtk_rgba = NULL; | |
| 636 g_object_get(gtk_settings, | |
| 637 "gtk-xft-rgba", >k_rgba, | |
| 638 NULL); | |
| 639 | |
| 640 if (gtk_rgba) { | |
| 641 if (strcmp(gtk_rgba, "none") == 0) | |
| 642 subpixel_rendering = gfx::FontRenderParams::SUBPIXEL_RENDERING_NONE; | |
| 643 else if (strcmp(gtk_rgba, "rgb") == 0) | |
| 644 subpixel_rendering = gfx::FontRenderParams::SUBPIXEL_RENDERING_RGB; | |
| 645 else if (strcmp(gtk_rgba, "bgr") == 0) | |
| 646 subpixel_rendering = gfx::FontRenderParams::SUBPIXEL_RENDERING_BGR; | |
| 647 else if (strcmp(gtk_rgba, "vrgb") == 0) | |
| 648 subpixel_rendering = gfx::FontRenderParams::SUBPIXEL_RENDERING_VRGB; | |
| 649 else if (strcmp(gtk_rgba, "vbgr") == 0) | |
| 650 subpixel_rendering = gfx::FontRenderParams::SUBPIXEL_RENDERING_VBGR; | |
| 651 | |
| 652 g_free(gtk_rgba); | |
| 653 } | |
| 654 | |
| 655 return subpixel_rendering; | |
| 656 } | |
| 657 | |
| 658 std::string Gtk2UI::GetDefaultFontDescription() const { | |
| 659 return default_font_description_; | |
| 660 } | 656 } |
| 661 | 657 |
| 662 double Gtk2UI::GetFontDPI() const { | 658 double Gtk2UI::GetFontDPI() const { |
| 663 GtkSettings* gtk_settings = gtk_settings_get_default(); | 659 GtkSettings* gtk_settings = gtk_settings_get_default(); |
| 664 CHECK(gtk_settings); | 660 CHECK(gtk_settings); |
| 665 gint dpi = -1; | 661 gint dpi = -1; |
| 666 g_object_get(gtk_settings, "gtk-xft-dpi", &dpi, NULL); | 662 g_object_get(gtk_settings, "gtk-xft-dpi", &dpi, NULL); |
| 667 | 663 |
| 668 // GTK multiplies the DPI by 1024 before storing it. | 664 // GTK multiplies the DPI by 1024 before storing it. |
| 669 return (dpi > 0) ? dpi / 1024.0 : dpi; | 665 return (dpi > 0) ? dpi / 1024.0 : dpi; |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 826 | 822 |
| 827 GdkColor button_color = window_style->bg[GTK_STATE_SELECTED]; | 823 GdkColor button_color = window_style->bg[GTK_STATE_SELECTED]; |
| 828 SetThemeTintFromGtk(ThemeProperties::TINT_BUTTONS, &button_color); | 824 SetThemeTintFromGtk(ThemeProperties::TINT_BUTTONS, &button_color); |
| 829 | 825 |
| 830 GtkStyle* label_style = gtk_rc_get_style(fake_label_.get()); | 826 GtkStyle* label_style = gtk_rc_get_style(fake_label_.get()); |
| 831 GdkColor label_color = label_style->fg[GTK_STATE_NORMAL]; | 827 GdkColor label_color = label_style->fg[GTK_STATE_NORMAL]; |
| 832 SetThemeColorFromGtk(ThemeProperties::COLOR_TAB_TEXT, &label_color); | 828 SetThemeColorFromGtk(ThemeProperties::COLOR_TAB_TEXT, &label_color); |
| 833 SetThemeColorFromGtk(ThemeProperties::COLOR_BOOKMARK_TEXT, &label_color); | 829 SetThemeColorFromGtk(ThemeProperties::COLOR_BOOKMARK_TEXT, &label_color); |
| 834 SetThemeColorFromGtk(ThemeProperties::COLOR_STATUS_BAR_TEXT, &label_color); | 830 SetThemeColorFromGtk(ThemeProperties::COLOR_STATUS_BAR_TEXT, &label_color); |
| 835 | 831 |
| 836 gchar* font_string = pango_font_description_to_string(label_style->font_desc); | 832 default_font_description_.reset(new gfx::ScopedPangoFontDescription( |
| 837 default_font_description_ = std::string(font_string); | 833 pango_font_description_copy(label_style->font_desc))); |
| 838 g_free(font_string); | |
| 839 | |
| 840 { | |
| 841 // TODO(derat): Remove this debugging code if/when http://crbug.com/375824 | |
| 842 // is resolved. | |
| 843 GtkSettings* gtk_settings = gtk_settings_get_default(); | |
| 844 CHECK(gtk_settings); | |
| 845 gchar* font_name = NULL; | |
| 846 g_object_get(gtk_settings, "gtk-font-name", &font_name, NULL); | |
| 847 if (font_name) { | |
| 848 if (std::string(font_name) != default_font_description_) { | |
| 849 LOG(ERROR) << "Font specified in gtk-font-name property (" | |
| 850 << font_name << ") does not match font from GtkLabel (" | |
| 851 << default_font_description_ << "); see " | |
| 852 << "http://crbug.com/375824"; | |
| 853 } | |
| 854 g_free(font_name); | |
| 855 } | |
| 856 } | |
| 857 | 834 |
| 858 // Build the various icon tints. | 835 // Build the various icon tints. |
| 859 GetNormalButtonTintHSL(&button_tint_); | 836 GetNormalButtonTintHSL(&button_tint_); |
| 860 GetNormalEntryForegroundHSL(&entry_tint_); | 837 GetNormalEntryForegroundHSL(&entry_tint_); |
| 861 GetSelectedEntryForegroundHSL(&selected_entry_tint_); | 838 GetSelectedEntryForegroundHSL(&selected_entry_tint_); |
| 862 GdkColor frame_color = BuildFrameColors(frame_style); | 839 GdkColor frame_color = BuildFrameColors(frame_style); |
| 863 | 840 |
| 864 // The inactive frame color never occurs naturally in the theme, as it is a | 841 // The inactive frame color never occurs naturally in the theme, as it is a |
| 865 // tinted version of |frame_color|. We generate another color based on the | 842 // tinted version of |frame_color|. We generate another color based on the |
| 866 // background tab color, with the lightness and saturation moved in the | 843 // background tab color, with the lightness and saturation moved in the |
| (...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1358 ClearAllThemeData(); | 1335 ClearAllThemeData(); |
| 1359 LoadGtkValues(); | 1336 LoadGtkValues(); |
| 1360 NativeThemeGtk2::instance()->NotifyObservers(); | 1337 NativeThemeGtk2::instance()->NotifyObservers(); |
| 1361 } | 1338 } |
| 1362 | 1339 |
| 1363 } // namespace libgtk2ui | 1340 } // namespace libgtk2ui |
| 1364 | 1341 |
| 1365 views::LinuxUI* BuildGtk2UI() { | 1342 views::LinuxUI* BuildGtk2UI() { |
| 1366 return new libgtk2ui::Gtk2UI; | 1343 return new libgtk2ui::Gtk2UI; |
| 1367 } | 1344 } |
| OLD | NEW |