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 <math.h> | 7 #include <math.h> |
8 #include <pango/pango.h> | 8 #include <pango/pango.h> |
9 #include <set> | 9 #include <set> |
10 #include <utility> | 10 #include <utility> |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 g_object_unref(ptr); | 275 g_object_unref(ptr); |
276 } | 276 } |
277 }; | 277 }; |
278 struct GtkIconInfoDeleter { | 278 struct GtkIconInfoDeleter { |
279 void operator()(GtkIconInfo* ptr) { | 279 void operator()(GtkIconInfo* ptr) { |
280 G_GNUC_BEGIN_IGNORE_DEPRECATIONS | 280 G_GNUC_BEGIN_IGNORE_DEPRECATIONS |
281 gtk_icon_info_free(ptr); | 281 gtk_icon_info_free(ptr); |
282 G_GNUC_END_IGNORE_DEPRECATIONS | 282 G_GNUC_END_IGNORE_DEPRECATIONS |
283 } | 283 } |
284 }; | 284 }; |
285 typedef scoped_ptr<GIcon, GObjectDeleter> ScopedGIcon; | 285 typedef std::unique_ptr<GIcon, GObjectDeleter> ScopedGIcon; |
286 typedef scoped_ptr<GtkIconInfo, GtkIconInfoDeleter> ScopedGtkIconInfo; | 286 typedef std::unique_ptr<GtkIconInfo, GtkIconInfoDeleter> ScopedGtkIconInfo; |
287 typedef scoped_ptr<GdkPixbuf, GObjectDeleter> ScopedGdkPixbuf; | 287 typedef std::unique_ptr<GdkPixbuf, GObjectDeleter> ScopedGdkPixbuf; |
288 | 288 |
289 // Prefix for app indicator ids | 289 // Prefix for app indicator ids |
290 const char kAppIndicatorIdPrefix[] = "chrome_app_indicator_"; | 290 const char kAppIndicatorIdPrefix[] = "chrome_app_indicator_"; |
291 | 291 |
292 // Number of app indicators used (used as part of app-indicator id). | 292 // Number of app indicators used (used as part of app-indicator id). |
293 int indicators_count; | 293 int indicators_count; |
294 | 294 |
295 // The unknown content type. | 295 // The unknown content type. |
296 const char* kUnknownContentType = "application/octet-stream"; | 296 const char* kUnknownContentType = "application/octet-stream"; |
297 | 297 |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
447 | 447 |
448 // Take device_scale_factor into account — if Chrome already scales the | 448 // Take device_scale_factor into account — if Chrome already scales the |
449 // entire UI up by 2x, we should not also scale up. | 449 // entire UI up by 2x, we should not also scale up. |
450 dpi /= device_scale_factor; | 450 dpi /= device_scale_factor; |
451 | 451 |
452 // There are 72 points in an inch. | 452 // There are 72 points in an inch. |
453 return dpi / 72.0; | 453 return dpi / 72.0; |
454 } | 454 } |
455 | 455 |
456 views::LinuxUI::NonClientMiddleClickAction GetDefaultMiddleClickAction() { | 456 views::LinuxUI::NonClientMiddleClickAction GetDefaultMiddleClickAction() { |
457 scoped_ptr<base::Environment> env(base::Environment::Create()); | 457 std::unique_ptr<base::Environment> env(base::Environment::Create()); |
458 switch (base::nix::GetDesktopEnvironment(env.get())) { | 458 switch (base::nix::GetDesktopEnvironment(env.get())) { |
459 case base::nix::DESKTOP_ENVIRONMENT_KDE4: | 459 case base::nix::DESKTOP_ENVIRONMENT_KDE4: |
460 case base::nix::DESKTOP_ENVIRONMENT_KDE5: | 460 case base::nix::DESKTOP_ENVIRONMENT_KDE5: |
461 // Starting with KDE 4.4, windows' titlebars can be dragged with the | 461 // Starting with KDE 4.4, windows' titlebars can be dragged with the |
462 // middle mouse button to create tab groups. We don't support that in | 462 // middle mouse button to create tab groups. We don't support that in |
463 // Chrome, but at least avoid lowering windows in response to middle | 463 // Chrome, but at least avoid lowering windows in response to middle |
464 // clicks to avoid surprising users who expect the KDE behavior. | 464 // clicks to avoid surprising users who expect the KDE behavior. |
465 return views::LinuxUI::MIDDLE_CLICK_ACTION_NONE; | 465 return views::LinuxUI::MIDDLE_CLICK_ACTION_NONE; |
466 default: | 466 default: |
467 return views::LinuxUI::MIDDLE_CLICK_ACTION_LOWER; | 467 return views::LinuxUI::MIDDLE_CLICK_ACTION_LOWER; |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
628 return native_theme_override; | 628 return native_theme_override; |
629 | 629 |
630 return NativeThemeGtk2::instance(); | 630 return NativeThemeGtk2::instance(); |
631 } | 631 } |
632 | 632 |
633 void Gtk2UI::SetNativeThemeOverride(const NativeThemeGetter& callback) { | 633 void Gtk2UI::SetNativeThemeOverride(const NativeThemeGetter& callback) { |
634 native_theme_overrider_ = callback; | 634 native_theme_overrider_ = callback; |
635 } | 635 } |
636 | 636 |
637 bool Gtk2UI::GetDefaultUsesSystemTheme() const { | 637 bool Gtk2UI::GetDefaultUsesSystemTheme() const { |
638 scoped_ptr<base::Environment> env(base::Environment::Create()); | 638 std::unique_ptr<base::Environment> env(base::Environment::Create()); |
639 | 639 |
640 switch (base::nix::GetDesktopEnvironment(env.get())) { | 640 switch (base::nix::GetDesktopEnvironment(env.get())) { |
641 case base::nix::DESKTOP_ENVIRONMENT_GNOME: | 641 case base::nix::DESKTOP_ENVIRONMENT_GNOME: |
642 case base::nix::DESKTOP_ENVIRONMENT_UNITY: | 642 case base::nix::DESKTOP_ENVIRONMENT_UNITY: |
643 case base::nix::DESKTOP_ENVIRONMENT_XFCE: | 643 case base::nix::DESKTOP_ENVIRONMENT_XFCE: |
644 return true; | 644 return true; |
645 case base::nix::DESKTOP_ENVIRONMENT_KDE3: | 645 case base::nix::DESKTOP_ENVIRONMENT_KDE3: |
646 case base::nix::DESKTOP_ENVIRONMENT_KDE4: | 646 case base::nix::DESKTOP_ENVIRONMENT_KDE4: |
647 case base::nix::DESKTOP_ENVIRONMENT_KDE5: | 647 case base::nix::DESKTOP_ENVIRONMENT_KDE5: |
648 case base::nix::DESKTOP_ENVIRONMENT_OTHER: | 648 case base::nix::DESKTOP_ENVIRONMENT_OTHER: |
(...skipping 11 matching lines...) Expand all Loading... |
660 | 660 |
661 void Gtk2UI::SetProgressFraction(float percentage) const { | 661 void Gtk2UI::SetProgressFraction(float percentage) const { |
662 if (unity::IsRunning()) | 662 if (unity::IsRunning()) |
663 unity::SetProgressFraction(percentage); | 663 unity::SetProgressFraction(percentage); |
664 } | 664 } |
665 | 665 |
666 bool Gtk2UI::IsStatusIconSupported() const { | 666 bool Gtk2UI::IsStatusIconSupported() const { |
667 return true; | 667 return true; |
668 } | 668 } |
669 | 669 |
670 scoped_ptr<views::StatusIconLinux> Gtk2UI::CreateLinuxStatusIcon( | 670 std::unique_ptr<views::StatusIconLinux> Gtk2UI::CreateLinuxStatusIcon( |
671 const gfx::ImageSkia& image, | 671 const gfx::ImageSkia& image, |
672 const base::string16& tool_tip) const { | 672 const base::string16& tool_tip) const { |
673 if (AppIndicatorIcon::CouldOpen()) { | 673 if (AppIndicatorIcon::CouldOpen()) { |
674 ++indicators_count; | 674 ++indicators_count; |
675 return scoped_ptr<views::StatusIconLinux>(new AppIndicatorIcon( | 675 return std::unique_ptr<views::StatusIconLinux>(new AppIndicatorIcon( |
676 base::StringPrintf("%s%d", kAppIndicatorIdPrefix, indicators_count), | 676 base::StringPrintf("%s%d", kAppIndicatorIdPrefix, indicators_count), |
677 image, | 677 image, tool_tip)); |
678 tool_tip)); | |
679 } else { | 678 } else { |
680 return scoped_ptr<views::StatusIconLinux>(new Gtk2StatusIcon( | 679 return std::unique_ptr<views::StatusIconLinux>( |
681 image, tool_tip)); | 680 new Gtk2StatusIcon(image, tool_tip)); |
682 } | 681 } |
683 } | 682 } |
684 | 683 |
685 gfx::Image Gtk2UI::GetIconForContentType( | 684 gfx::Image Gtk2UI::GetIconForContentType( |
686 const std::string& content_type, | 685 const std::string& content_type, |
687 int size) const { | 686 int size) const { |
688 // This call doesn't take a reference. | 687 // This call doesn't take a reference. |
689 GtkIconTheme* theme = gtk_icon_theme_get_default(); | 688 GtkIconTheme* theme = gtk_icon_theme_get_default(); |
690 | 689 |
691 std::string content_types[] = { | 690 std::string content_types[] = { |
(...skipping 15 matching lines...) Expand all Loading... |
707 SkBitmap bitmap = GdkPixbufToImageSkia(pixbuf.get()); | 706 SkBitmap bitmap = GdkPixbufToImageSkia(pixbuf.get()); |
708 DCHECK_EQ(size, bitmap.width()); | 707 DCHECK_EQ(size, bitmap.width()); |
709 DCHECK_EQ(size, bitmap.height()); | 708 DCHECK_EQ(size, bitmap.height()); |
710 gfx::ImageSkia image_skia = gfx::ImageSkia::CreateFrom1xBitmap(bitmap); | 709 gfx::ImageSkia image_skia = gfx::ImageSkia::CreateFrom1xBitmap(bitmap); |
711 image_skia.MakeThreadSafe(); | 710 image_skia.MakeThreadSafe(); |
712 return gfx::Image(image_skia); | 711 return gfx::Image(image_skia); |
713 } | 712 } |
714 return gfx::Image(); | 713 return gfx::Image(); |
715 } | 714 } |
716 | 715 |
717 scoped_ptr<views::Border> Gtk2UI::CreateNativeBorder( | 716 std::unique_ptr<views::Border> Gtk2UI::CreateNativeBorder( |
718 views::LabelButton* owning_button, | 717 views::LabelButton* owning_button, |
719 scoped_ptr<views::LabelButtonBorder> border) { | 718 std::unique_ptr<views::LabelButtonBorder> border) { |
720 if (owning_button->GetNativeTheme() != NativeThemeGtk2::instance()) | 719 if (owning_button->GetNativeTheme() != NativeThemeGtk2::instance()) |
721 return std::move(border); | 720 return std::move(border); |
722 | 721 |
723 scoped_ptr<views::LabelButtonAssetBorder> gtk_border( | 722 std::unique_ptr<views::LabelButtonAssetBorder> gtk_border( |
724 new views::LabelButtonAssetBorder(owning_button->style())); | 723 new views::LabelButtonAssetBorder(owning_button->style())); |
725 | 724 |
726 gtk_border->set_insets(border->GetInsets()); | 725 gtk_border->set_insets(border->GetInsets()); |
727 | 726 |
728 static struct { | 727 static struct { |
729 const char* idr; | 728 const char* idr; |
730 const char* idr_blue; | 729 const char* idr_blue; |
731 bool focus; | 730 bool focus; |
732 views::Button::ButtonState state; | 731 views::Button::ButtonState state; |
733 } const paintstate[] = { | 732 } const paintstate[] = { |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
798 | 797 |
799 FOR_EACH_OBSERVER(views::WindowButtonOrderObserver, observer_list_, | 798 FOR_EACH_OBSERVER(views::WindowButtonOrderObserver, observer_list_, |
800 OnWindowButtonOrderingChange(leading_buttons_, | 799 OnWindowButtonOrderingChange(leading_buttons_, |
801 trailing_buttons_)); | 800 trailing_buttons_)); |
802 } | 801 } |
803 | 802 |
804 void Gtk2UI::SetNonClientMiddleClickAction(NonClientMiddleClickAction action) { | 803 void Gtk2UI::SetNonClientMiddleClickAction(NonClientMiddleClickAction action) { |
805 middle_click_action_ = action; | 804 middle_click_action_ = action; |
806 } | 805 } |
807 | 806 |
808 scoped_ptr<ui::LinuxInputMethodContext> Gtk2UI::CreateInputMethodContext( | 807 std::unique_ptr<ui::LinuxInputMethodContext> Gtk2UI::CreateInputMethodContext( |
809 ui::LinuxInputMethodContextDelegate* delegate, | 808 ui::LinuxInputMethodContextDelegate* delegate, |
810 bool is_simple) const { | 809 bool is_simple) const { |
811 return scoped_ptr<ui::LinuxInputMethodContext>( | 810 return std::unique_ptr<ui::LinuxInputMethodContext>( |
812 new X11InputMethodContextImplGtk2(delegate, is_simple)); | 811 new X11InputMethodContextImplGtk2(delegate, is_simple)); |
813 } | 812 } |
814 | 813 |
815 gfx::FontRenderParams Gtk2UI::GetDefaultFontRenderParams() const { | 814 gfx::FontRenderParams Gtk2UI::GetDefaultFontRenderParams() const { |
816 static gfx::FontRenderParams params = GetGtkFontRenderParams(); | 815 static gfx::FontRenderParams params = GetGtkFontRenderParams(); |
817 return params; | 816 return params; |
818 } | 817 } |
819 | 818 |
820 void Gtk2UI::GetDefaultFontDescription( | 819 void Gtk2UI::GetDefaultFontDescription( |
821 std::string* family_out, | 820 std::string* family_out, |
(...skipping 555 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1377 // Blacklist scaling factors <130% (crbug.com/484400) and round | 1376 // Blacklist scaling factors <130% (crbug.com/484400) and round |
1378 // to 1 decimal to prevent rendering problems (crbug.com/485183). | 1377 // to 1 decimal to prevent rendering problems (crbug.com/485183). |
1379 return scale < 1.3f ? 1.0f : roundf(scale * 10) / 10; | 1378 return scale < 1.3f ? 1.0f : roundf(scale * 10) / 10; |
1380 } | 1379 } |
1381 | 1380 |
1382 } // namespace libgtk2ui | 1381 } // namespace libgtk2ui |
1383 | 1382 |
1384 views::LinuxUI* BuildGtk2UI() { | 1383 views::LinuxUI* BuildGtk2UI() { |
1385 return new libgtk2ui::Gtk2UI; | 1384 return new libgtk2ui::Gtk2UI; |
1386 } | 1385 } |
OLD | NEW |