| 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 "base/command_line.h" | 9 #include "base/command_line.h" | 
| 10 #include "base/environment.h" | 10 #include "base/environment.h" | 
| 11 #include "base/i18n/rtl.h" | 11 #include "base/i18n/rtl.h" | 
| 12 #include "base/logging.h" | 12 #include "base/logging.h" | 
| 13 #include "base/nix/mime_util_xdg.h" | 13 #include "base/nix/mime_util_xdg.h" | 
| 14 #include "base/stl_util.h" | 14 #include "base/stl_util.h" | 
| 15 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" | 
| 16 #include "chrome/browser/themes/theme_properties.h" | 16 #include "chrome/browser/themes/theme_properties.h" | 
| 17 #include "chrome/browser/ui/libgtk2ui/app_indicator_icon.h" | 17 #include "chrome/browser/ui/libgtk2ui/app_indicator_icon.h" | 
| 18 #include "chrome/browser/ui/libgtk2ui/chrome_gtk_frame.h" | 18 #include "chrome/browser/ui/libgtk2ui/chrome_gtk_frame.h" | 
|  | 19 #include "chrome/browser/ui/libgtk2ui/gtk2_border.h" | 
| 19 #include "chrome/browser/ui/libgtk2ui/gtk2_util.h" | 20 #include "chrome/browser/ui/libgtk2ui/gtk2_util.h" | 
| 20 #include "chrome/browser/ui/libgtk2ui/native_theme_gtk2.h" | 21 #include "chrome/browser/ui/libgtk2ui/native_theme_gtk2.h" | 
| 21 #include "chrome/browser/ui/libgtk2ui/print_dialog_gtk2.h" | 22 #include "chrome/browser/ui/libgtk2ui/print_dialog_gtk2.h" | 
| 22 #include "chrome/browser/ui/libgtk2ui/printing_gtk2_util.h" | 23 #include "chrome/browser/ui/libgtk2ui/printing_gtk2_util.h" | 
| 23 #include "chrome/browser/ui/libgtk2ui/select_file_dialog_impl.h" | 24 #include "chrome/browser/ui/libgtk2ui/select_file_dialog_impl.h" | 
| 24 #include "chrome/browser/ui/libgtk2ui/skia_utils_gtk2.h" | 25 #include "chrome/browser/ui/libgtk2ui/skia_utils_gtk2.h" | 
| 25 #include "chrome/browser/ui/libgtk2ui/unity_service.h" | 26 #include "chrome/browser/ui/libgtk2ui/unity_service.h" | 
| 26 #include "chrome/browser/ui/libgtk2ui/x11_input_method_context_impl_gtk2.h" | 27 #include "chrome/browser/ui/libgtk2ui/x11_input_method_context_impl_gtk2.h" | 
| 27 #include "grit/theme_resources.h" | 28 #include "grit/theme_resources.h" | 
| 28 #include "grit/ui_resources.h" | 29 #include "grit/ui_resources.h" | 
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 156   { IDR_FORWARD,   GTK_STOCK_GO_FORWARD, GTK_STATE_NORMAL }, | 157   { IDR_FORWARD,   GTK_STOCK_GO_FORWARD, GTK_STATE_NORMAL }, | 
| 157   { IDR_FORWARD_D, GTK_STOCK_GO_FORWARD, GTK_STATE_INSENSITIVE }, | 158   { IDR_FORWARD_D, GTK_STOCK_GO_FORWARD, GTK_STATE_INSENSITIVE }, | 
| 158   { IDR_FORWARD_H, GTK_STOCK_GO_FORWARD, GTK_STATE_PRELIGHT }, | 159   { IDR_FORWARD_H, GTK_STOCK_GO_FORWARD, GTK_STATE_PRELIGHT }, | 
| 159   { IDR_FORWARD_P, GTK_STOCK_GO_FORWARD, GTK_STATE_ACTIVE }, | 160   { IDR_FORWARD_P, GTK_STOCK_GO_FORWARD, GTK_STATE_ACTIVE }, | 
| 160 | 161 | 
| 161   { IDR_HOME,      GTK_STOCK_HOME,       GTK_STATE_NORMAL }, | 162   { IDR_HOME,      GTK_STOCK_HOME,       GTK_STATE_NORMAL }, | 
| 162   { IDR_HOME_H,    GTK_STOCK_HOME,       GTK_STATE_PRELIGHT }, | 163   { IDR_HOME_H,    GTK_STOCK_HOME,       GTK_STATE_PRELIGHT }, | 
| 163   { IDR_HOME_P,    GTK_STOCK_HOME,       GTK_STATE_ACTIVE }, | 164   { IDR_HOME_P,    GTK_STOCK_HOME,       GTK_STATE_ACTIVE }, | 
| 164 | 165 | 
| 165   { IDR_RELOAD,    GTK_STOCK_REFRESH,    GTK_STATE_NORMAL }, | 166   { IDR_RELOAD,    GTK_STOCK_REFRESH,    GTK_STATE_NORMAL }, | 
|  | 167   { IDR_RELOAD_D,  GTK_STOCK_REFRESH,    GTK_STATE_INSENSITIVE }, | 
| 166   { IDR_RELOAD_H,  GTK_STOCK_REFRESH,    GTK_STATE_PRELIGHT }, | 168   { IDR_RELOAD_H,  GTK_STOCK_REFRESH,    GTK_STATE_PRELIGHT }, | 
| 167   { IDR_RELOAD_P,  GTK_STOCK_REFRESH,    GTK_STATE_ACTIVE }, | 169   { IDR_RELOAD_P,  GTK_STOCK_REFRESH,    GTK_STATE_ACTIVE }, | 
| 168 | 170 | 
| 169   { IDR_STOP,      GTK_STOCK_STOP,       GTK_STATE_NORMAL }, | 171   { IDR_STOP,      GTK_STOCK_STOP,       GTK_STATE_NORMAL }, | 
| 170   { IDR_STOP_D,    GTK_STOCK_STOP,       GTK_STATE_INSENSITIVE }, | 172   { IDR_STOP_D,    GTK_STOCK_STOP,       GTK_STATE_INSENSITIVE }, | 
| 171   { IDR_STOP_H,    GTK_STOCK_STOP,       GTK_STATE_PRELIGHT }, | 173   { IDR_STOP_H,    GTK_STOCK_STOP,       GTK_STATE_PRELIGHT }, | 
| 172   { IDR_STOP_P,    GTK_STOCK_STOP,       GTK_STATE_ACTIVE }, | 174   { IDR_STOP_P,    GTK_STOCK_STOP,       GTK_STATE_ACTIVE }, | 
| 173 }; | 175 }; | 
| 174 | 176 | 
| 175 // The image resources that will be tinted by the 'button' tint value. | 177 // The image resources that will be tinted by the 'button' tint value. | 
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 438   return cursor_blink ? (cursor_blink_time / kGtkCursorBlinkCycleFactor) : 0.0; | 440   return cursor_blink ? (cursor_blink_time / kGtkCursorBlinkCycleFactor) : 0.0; | 
| 439 } | 441 } | 
| 440 | 442 | 
| 441 ui::NativeTheme* Gtk2UI::GetNativeTheme() const { | 443 ui::NativeTheme* Gtk2UI::GetNativeTheme() const { | 
| 442   return use_gtk_ ? NativeThemeGtk2::instance() : | 444   return use_gtk_ ? NativeThemeGtk2::instance() : | 
| 443                     ui::NativeTheme::instance(); | 445                     ui::NativeTheme::instance(); | 
| 444 } | 446 } | 
| 445 | 447 | 
| 446 void Gtk2UI::SetUseSystemTheme(bool use_system_theme) { | 448 void Gtk2UI::SetUseSystemTheme(bool use_system_theme) { | 
| 447   use_gtk_ = use_system_theme; | 449   use_gtk_ = use_system_theme; | 
|  | 450 | 
|  | 451   FOR_EACH_OBSERVER(Gtk2Border, border_list_, | 
|  | 452                     InvalidateAndSetUsesGtk(use_system_theme)); | 
|  | 453 } | 
|  | 454 | 
|  | 455 bool Gtk2UI::GetUseSystemTheme() const { | 
|  | 456   return use_gtk_; | 
| 448 } | 457 } | 
| 449 | 458 | 
| 450 bool Gtk2UI::GetDefaultUsesSystemTheme() const { | 459 bool Gtk2UI::GetDefaultUsesSystemTheme() const { | 
| 451   scoped_ptr<base::Environment> env(base::Environment::Create()); | 460   scoped_ptr<base::Environment> env(base::Environment::Create()); | 
| 452 | 461 | 
| 453   switch (base::nix::GetDesktopEnvironment(env.get())) { | 462   switch (base::nix::GetDesktopEnvironment(env.get())) { | 
| 454     case base::nix::DESKTOP_ENVIRONMENT_GNOME: | 463     case base::nix::DESKTOP_ENVIRONMENT_GNOME: | 
| 455     case base::nix::DESKTOP_ENVIRONMENT_UNITY: | 464     case base::nix::DESKTOP_ENVIRONMENT_UNITY: | 
| 456     case base::nix::DESKTOP_ENVIRONMENT_XFCE: | 465     case base::nix::DESKTOP_ENVIRONMENT_XFCE: | 
| 457       return true; | 466       return true; | 
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 511     return gfx::Image(); | 520     return gfx::Image(); | 
| 512 | 521 | 
| 513   SkBitmap bitmap = GdkPixbufToImageSkia(pixbuf.get()); | 522   SkBitmap bitmap = GdkPixbufToImageSkia(pixbuf.get()); | 
| 514   DCHECK_EQ(size, bitmap.width()); | 523   DCHECK_EQ(size, bitmap.width()); | 
| 515   DCHECK_EQ(size, bitmap.height()); | 524   DCHECK_EQ(size, bitmap.height()); | 
| 516   gfx::ImageSkia image_skia = gfx::ImageSkia::CreateFrom1xBitmap(bitmap); | 525   gfx::ImageSkia image_skia = gfx::ImageSkia::CreateFrom1xBitmap(bitmap); | 
| 517   image_skia.MakeThreadSafe(); | 526   image_skia.MakeThreadSafe(); | 
| 518   return gfx::Image(image_skia); | 527   return gfx::Image(image_skia); | 
| 519 } | 528 } | 
| 520 | 529 | 
|  | 530 views::Border* Gtk2UI::CreateNativeBorder( | 
|  | 531     views::CustomButton* owning_button, | 
|  | 532     views::Border* border) { | 
|  | 533   return new Gtk2Border(this, owning_button, border); | 
|  | 534 } | 
|  | 535 | 
| 521 void Gtk2UI::AddWindowButtonOrderObserver( | 536 void Gtk2UI::AddWindowButtonOrderObserver( | 
| 522     views::WindowButtonOrderObserver* observer) { | 537     views::WindowButtonOrderObserver* observer) { | 
| 523   if (!leading_buttons_.empty() || !trailing_buttons_.empty()) { | 538   if (!leading_buttons_.empty() || !trailing_buttons_.empty()) { | 
| 524     observer->OnWindowButtonOrderingChange(leading_buttons_, | 539     observer->OnWindowButtonOrderingChange(leading_buttons_, | 
| 525                                            trailing_buttons_); | 540                                            trailing_buttons_); | 
| 526   } | 541   } | 
| 527 | 542 | 
| 528   observer_list_.AddObserver(observer); | 543   observer_list_.AddObserver(observer); | 
| 529 } | 544 } | 
| 530 | 545 | 
| (...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 864   // Some GTK themes only define the text selection colors on the GtkEntry | 879   // Some GTK themes only define the text selection colors on the GtkEntry | 
| 865   // class, so we need to use that for getting selection colors. | 880   // class, so we need to use that for getting selection colors. | 
| 866   active_selection_bg_color_ = | 881   active_selection_bg_color_ = | 
| 867       GdkColorToSkColor(entry_style->base[GTK_STATE_SELECTED]); | 882       GdkColorToSkColor(entry_style->base[GTK_STATE_SELECTED]); | 
| 868   active_selection_fg_color_ = | 883   active_selection_fg_color_ = | 
| 869       GdkColorToSkColor(entry_style->text[GTK_STATE_SELECTED]); | 884       GdkColorToSkColor(entry_style->text[GTK_STATE_SELECTED]); | 
| 870   inactive_selection_bg_color_ = | 885   inactive_selection_bg_color_ = | 
| 871       GdkColorToSkColor(entry_style->base[GTK_STATE_ACTIVE]); | 886       GdkColorToSkColor(entry_style->base[GTK_STATE_ACTIVE]); | 
| 872   inactive_selection_fg_color_ = | 887   inactive_selection_fg_color_ = | 
| 873       GdkColorToSkColor(entry_style->text[GTK_STATE_ACTIVE]); | 888       GdkColorToSkColor(entry_style->text[GTK_STATE_ACTIVE]); | 
|  | 889 | 
|  | 890   // Update the insets that we hand to Gtk2Border. | 
|  | 891   UpdateButtonInsets(); | 
| 874 } | 892 } | 
| 875 | 893 | 
| 876 GdkColor Gtk2UI::BuildFrameColors(GtkStyle* frame_style) { | 894 GdkColor Gtk2UI::BuildFrameColors(GtkStyle* frame_style) { | 
| 877   GdkColor* theme_frame = NULL; | 895   GdkColor* theme_frame = NULL; | 
| 878   GdkColor* theme_inactive_frame = NULL; | 896   GdkColor* theme_inactive_frame = NULL; | 
| 879   GdkColor* theme_incognito_frame = NULL; | 897   GdkColor* theme_incognito_frame = NULL; | 
| 880   GdkColor* theme_incognito_inactive_frame = NULL; | 898   GdkColor* theme_incognito_inactive_frame = NULL; | 
| 881   gtk_widget_style_get(GTK_WIDGET(fake_frame_), | 899   gtk_widget_style_get(GTK_WIDGET(fake_frame_), | 
| 882                        "frame-color", &theme_frame, | 900                        "frame-color", &theme_frame, | 
| 883                        "inactive-frame-color", &theme_inactive_frame, | 901                        "inactive-frame-color", &theme_inactive_frame, | 
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1024     case IDR_BACK_H: | 1042     case IDR_BACK_H: | 
| 1025     case IDR_BACK_P: | 1043     case IDR_BACK_P: | 
| 1026     case IDR_FORWARD: | 1044     case IDR_FORWARD: | 
| 1027     case IDR_FORWARD_D: | 1045     case IDR_FORWARD_D: | 
| 1028     case IDR_FORWARD_H: | 1046     case IDR_FORWARD_H: | 
| 1029     case IDR_FORWARD_P: | 1047     case IDR_FORWARD_P: | 
| 1030     case IDR_HOME: | 1048     case IDR_HOME: | 
| 1031     case IDR_HOME_H: | 1049     case IDR_HOME_H: | 
| 1032     case IDR_HOME_P: | 1050     case IDR_HOME_P: | 
| 1033     case IDR_RELOAD: | 1051     case IDR_RELOAD: | 
|  | 1052     case IDR_RELOAD_D: | 
| 1034     case IDR_RELOAD_H: | 1053     case IDR_RELOAD_H: | 
| 1035     case IDR_RELOAD_P: | 1054     case IDR_RELOAD_P: | 
| 1036     case IDR_STOP: | 1055     case IDR_STOP: | 
| 1037     case IDR_STOP_D: | 1056     case IDR_STOP_D: | 
| 1038     case IDR_STOP_H: | 1057     case IDR_STOP_H: | 
| 1039     case IDR_STOP_P: { | 1058     case IDR_STOP_P: { | 
| 1040       return GenerateGTKIcon(id); | 1059       return GenerateGTKIcon(id); | 
| 1041     } | 1060     } | 
| 1042     case IDR_TOOLBAR_BEZEL_HOVER: | 1061     case IDR_TOOLBAR_BEZEL_HOVER: | 
| 1043       return GenerateToolbarBezel(GTK_STATE_PRELIGHT, IDR_TOOLBAR_BEZEL_HOVER); | 1062       return GenerateToolbarBezel(GTK_STATE_PRELIGHT, IDR_TOOLBAR_BEZEL_HOVER); | 
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1258 | 1277 | 
| 1259   // Finally, we convert our pixbuf into a type we can use. | 1278   // Finally, we convert our pixbuf into a type we can use. | 
| 1260   SkBitmap border = GdkPixbufToImageSkia(pixbuf); | 1279   SkBitmap border = GdkPixbufToImageSkia(pixbuf); | 
| 1261   g_object_unref(pixbuf); | 1280   g_object_unref(pixbuf); | 
| 1262   g_object_unref(pixmap); | 1281   g_object_unref(pixmap); | 
| 1263   gtk_widget_destroy(window); | 1282   gtk_widget_destroy(window); | 
| 1264 | 1283 | 
| 1265   return border; | 1284   return border; | 
| 1266 } | 1285 } | 
| 1267 | 1286 | 
|  | 1287 gfx::Insets Gtk2UI::GetButtonInsets() const { | 
|  | 1288   return button_insets_; | 
|  | 1289 } | 
|  | 1290 | 
|  | 1291 void Gtk2UI::AddGtkBorder(Gtk2Border* border) { | 
|  | 1292   border_list_.AddObserver(border); | 
|  | 1293 } | 
|  | 1294 | 
|  | 1295 void Gtk2UI::RemoveGtkBorder(Gtk2Border* border) { | 
|  | 1296   border_list_.RemoveObserver(border); | 
|  | 1297 } | 
|  | 1298 | 
|  | 1299 void Gtk2UI::UpdateButtonInsets() { | 
|  | 1300   GtkWidget* window = gtk_offscreen_window_new(); | 
|  | 1301   GtkWidget* button = gtk_button_new(); | 
|  | 1302   gtk_container_add(GTK_CONTAINER(window), button); | 
|  | 1303 | 
|  | 1304   GtkBorder* border = NULL; | 
|  | 1305   gtk_widget_style_get(GTK_WIDGET(button), | 
|  | 1306                        "default-border", | 
|  | 1307                        &border, | 
|  | 1308                        NULL); | 
|  | 1309 | 
|  | 1310   gfx::Insets insets; | 
|  | 1311   if (border) { | 
|  | 1312     button_insets_ = gfx::Insets(border->top, border->left, | 
|  | 1313                                  border->bottom, border->right); | 
|  | 1314     gtk_border_free(border); | 
|  | 1315   } else { | 
|  | 1316     // Defined in gtkbutton.c: | 
|  | 1317     button_insets_ = gfx::Insets(1, 1, 1, 1); | 
|  | 1318   } | 
|  | 1319 | 
|  | 1320   gtk_widget_destroy(window); | 
|  | 1321 } | 
|  | 1322 | 
| 1268 void Gtk2UI::ClearAllThemeData() { | 1323 void Gtk2UI::ClearAllThemeData() { | 
| 1269   gtk_images_.clear(); | 1324   gtk_images_.clear(); | 
| 1270 } | 1325 } | 
| 1271 | 1326 | 
| 1272 }  // namespace libgtk2ui | 1327 }  // namespace libgtk2ui | 
| 1273 | 1328 | 
| 1274 views::LinuxUI* BuildGtk2UI() { | 1329 views::LinuxUI* BuildGtk2UI() { | 
| 1275   return new libgtk2ui::Gtk2UI; | 1330   return new libgtk2ui::Gtk2UI; | 
| 1276 } | 1331 } | 
| OLD | NEW | 
|---|