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 if (hint_style) | |
368 g_free(hint_style); | |
msw
2014/07/18 19:14:43
nit: Remove the NULL checks for these two g_free c
msw
2014/07/18 19:59:46
ping, but you can leave them if you prefer.
Daniel Erat
2014/07/18 20:26:51
whoops, sorry. saw this comment, did other things,
| |
369 if (rgba) | |
370 g_free(rgba); | |
371 | |
372 return params; | |
373 } | |
374 | |
318 } // namespace | 375 } // namespace |
319 | 376 |
320 Gtk2UI::Gtk2UI() : middle_click_action_(MIDDLE_CLICK_ACTION_LOWER) { | 377 Gtk2UI::Gtk2UI() : middle_click_action_(MIDDLE_CLICK_ACTION_LOWER) { |
321 GtkInitFromCommandLine(*CommandLine::ForCurrentProcess()); | 378 GtkInitFromCommandLine(*CommandLine::ForCurrentProcess()); |
322 } | 379 } |
323 | 380 |
324 void Gtk2UI::Initialize() { | 381 void Gtk2UI::Initialize() { |
325 signals_.reset(new Gtk2SignalRegistrar); | 382 signals_.reset(new Gtk2SignalRegistrar); |
326 | 383 |
327 // Create our fake widgets. | 384 // Create our fake widgets. |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
581 void Gtk2UI::SetNonClientMiddleClickAction(NonClientMiddleClickAction action) { | 638 void Gtk2UI::SetNonClientMiddleClickAction(NonClientMiddleClickAction action) { |
582 middle_click_action_ = action; | 639 middle_click_action_ = action; |
583 } | 640 } |
584 | 641 |
585 scoped_ptr<ui::LinuxInputMethodContext> Gtk2UI::CreateInputMethodContext( | 642 scoped_ptr<ui::LinuxInputMethodContext> Gtk2UI::CreateInputMethodContext( |
586 ui::LinuxInputMethodContextDelegate* delegate) const { | 643 ui::LinuxInputMethodContextDelegate* delegate) const { |
587 return scoped_ptr<ui::LinuxInputMethodContext>( | 644 return scoped_ptr<ui::LinuxInputMethodContext>( |
588 new X11InputMethodContextImplGtk2(delegate)); | 645 new X11InputMethodContextImplGtk2(delegate)); |
589 } | 646 } |
590 | 647 |
591 bool Gtk2UI::UseAntialiasing() const { | 648 gfx::FontRenderParams Gtk2UI::GetDefaultFontRenderParams() const { |
592 GtkSettings* gtk_settings = gtk_settings_get_default(); | 649 static gfx::FontRenderParams params = GetGtkFontRenderParams(); |
593 CHECK(gtk_settings); | 650 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 } | 651 } |
600 | 652 |
601 gfx::FontRenderParams::Hinting Gtk2UI::GetHintingStyle() const { | 653 scoped_ptr<gfx::ScopedPangoFontDescription> |
602 GtkSettings* gtk_settings = gtk_settings_get_default(); | 654 Gtk2UI::GetDefaultPangoFontDescription() const { |
603 CHECK(gtk_settings); | 655 return scoped_ptr<gfx::ScopedPangoFontDescription>( |
604 gfx::FontRenderParams::Hinting hinting = | 656 new gfx::ScopedPangoFontDescription( |
605 gfx::FontRenderParams::HINTING_SLIGHT; | 657 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 } | 658 } |
661 | 659 |
662 ui::SelectFileDialog* Gtk2UI::CreateSelectFileDialog( | 660 ui::SelectFileDialog* Gtk2UI::CreateSelectFileDialog( |
663 ui::SelectFileDialog::Listener* listener, | 661 ui::SelectFileDialog::Listener* listener, |
664 ui::SelectFilePolicy* policy) const { | 662 ui::SelectFilePolicy* policy) const { |
665 return SelectFileDialogImpl::Create(listener, policy); | 663 return SelectFileDialogImpl::Create(listener, policy); |
666 } | 664 } |
667 | 665 |
668 bool Gtk2UI::UnityIsRunning() { | 666 bool Gtk2UI::UnityIsRunning() { |
669 return unity::IsRunning(); | 667 return unity::IsRunning(); |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
816 | 814 |
817 GdkColor button_color = window_style->bg[GTK_STATE_SELECTED]; | 815 GdkColor button_color = window_style->bg[GTK_STATE_SELECTED]; |
818 SetThemeTintFromGtk(ThemeProperties::TINT_BUTTONS, &button_color); | 816 SetThemeTintFromGtk(ThemeProperties::TINT_BUTTONS, &button_color); |
819 | 817 |
820 GtkStyle* label_style = gtk_rc_get_style(fake_label_.get()); | 818 GtkStyle* label_style = gtk_rc_get_style(fake_label_.get()); |
821 GdkColor label_color = label_style->fg[GTK_STATE_NORMAL]; | 819 GdkColor label_color = label_style->fg[GTK_STATE_NORMAL]; |
822 SetThemeColorFromGtk(ThemeProperties::COLOR_TAB_TEXT, &label_color); | 820 SetThemeColorFromGtk(ThemeProperties::COLOR_TAB_TEXT, &label_color); |
823 SetThemeColorFromGtk(ThemeProperties::COLOR_BOOKMARK_TEXT, &label_color); | 821 SetThemeColorFromGtk(ThemeProperties::COLOR_BOOKMARK_TEXT, &label_color); |
824 SetThemeColorFromGtk(ThemeProperties::COLOR_STATUS_BAR_TEXT, &label_color); | 822 SetThemeColorFromGtk(ThemeProperties::COLOR_STATUS_BAR_TEXT, &label_color); |
825 | 823 |
826 gchar* font_string = pango_font_description_to_string(label_style->font_desc); | 824 default_font_description_.reset(new gfx::ScopedPangoFontDescription( |
827 default_font_description_ = std::string(font_string); | 825 pango_font_description_copy(label_style->font_desc))); |
828 g_free(font_string); | |
829 | |
830 { | |
831 // TODO(derat): Remove this debugging code if/when http://crbug.com/375824 | |
msw
2014/07/18 19:14:43
Did this yield any useful info? Is it worth keepin
Daniel Erat
2014/07/18 19:39:08
no, i don't think so. i originally theorized that
msw
2014/07/18 19:59:46
Acknowledged.
| |
832 // is resolved. | |
833 GtkSettings* gtk_settings = gtk_settings_get_default(); | |
834 CHECK(gtk_settings); | |
835 gchar* font_name = NULL; | |
836 g_object_get(gtk_settings, "gtk-font-name", &font_name, NULL); | |
837 if (font_name) { | |
838 if (std::string(font_name) != default_font_description_) { | |
839 LOG(ERROR) << "Font specified in gtk-font-name property (" | |
840 << font_name << ") does not match font from GtkLabel (" | |
841 << default_font_description_ << "); see " | |
842 << "http://crbug.com/375824"; | |
843 } | |
844 g_free(font_name); | |
845 } | |
846 } | |
847 | 826 |
848 // Build the various icon tints. | 827 // Build the various icon tints. |
849 GetNormalButtonTintHSL(&button_tint_); | 828 GetNormalButtonTintHSL(&button_tint_); |
850 GetNormalEntryForegroundHSL(&entry_tint_); | 829 GetNormalEntryForegroundHSL(&entry_tint_); |
851 GetSelectedEntryForegroundHSL(&selected_entry_tint_); | 830 GetSelectedEntryForegroundHSL(&selected_entry_tint_); |
852 GdkColor frame_color = BuildFrameColors(frame_style); | 831 GdkColor frame_color = BuildFrameColors(frame_style); |
853 | 832 |
854 // The inactive frame color never occurs naturally in the theme, as it is a | 833 // The inactive frame color never occurs naturally in the theme, as it is a |
855 // tinted version of |frame_color|. We generate another color based on the | 834 // tinted version of |frame_color|. We generate another color based on the |
856 // background tab color, with the lightness and saturation moved in the | 835 // background tab color, with the lightness and saturation moved in the |
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1348 ClearAllThemeData(); | 1327 ClearAllThemeData(); |
1349 LoadGtkValues(); | 1328 LoadGtkValues(); |
1350 NativeThemeGtk2::instance()->NotifyObservers(); | 1329 NativeThemeGtk2::instance()->NotifyObservers(); |
1351 } | 1330 } |
1352 | 1331 |
1353 } // namespace libgtk2ui | 1332 } // namespace libgtk2ui |
1354 | 1333 |
1355 views::LinuxUI* BuildGtk2UI() { | 1334 views::LinuxUI* BuildGtk2UI() { |
1356 return new libgtk2ui::Gtk2UI; | 1335 return new libgtk2ui::Gtk2UI; |
1357 } | 1336 } |
OLD | NEW |