| 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/libgtkui/gtk_ui.h" | 5 #include "chrome/browser/ui/libgtkui/gtk_ui.h" |
| 6 | 6 |
| 7 #include <math.h> | 7 #include <math.h> |
| 8 #include <pango/pango.h> | 8 #include <pango/pango.h> |
| 9 #include <X11/Xcursor/Xcursor.h> | 9 #include <X11/Xcursor/Xcursor.h> |
| 10 | 10 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 #endif | 75 #endif |
| 76 | 76 |
| 77 // A minimized port of GtkThemeService into something that can provide colors | 77 // A minimized port of GtkThemeService into something that can provide colors |
| 78 // and images for aura. | 78 // and images for aura. |
| 79 // | 79 // |
| 80 // TODO(erg): There's still a lot that needs ported or done for the first time: | 80 // TODO(erg): There's still a lot that needs ported or done for the first time: |
| 81 // | 81 // |
| 82 // - Render and inject the omnibox background. | 82 // - Render and inject the omnibox background. |
| 83 // - Make sure to test with a light on dark theme, too. | 83 // - Make sure to test with a light on dark theme, too. |
| 84 | 84 |
| 85 // Work around a header bug: | |
| 86 // linux/debian_wheezy_i386-sysroot/usr/include/linux/stddef.h redefines NULL | |
| 87 // to 0, which breaks -Wsentinel. Get back the normal definition of NULL. | |
| 88 // TODO(thakis): Remove this once we update sysroots. | |
| 89 #define __need_NULL | |
| 90 #include <stddef.h> | |
| 91 | |
| 92 namespace libgtkui { | 85 namespace libgtkui { |
| 93 | 86 |
| 94 namespace { | 87 namespace { |
| 95 | 88 |
| 96 const double kDefaultDPI = 96; | 89 const double kDefaultDPI = 96; |
| 97 | 90 |
| 98 class GtkButtonImageSource : public gfx::ImageSkiaSource { | 91 class GtkButtonImageSource : public gfx::ImageSkiaSource { |
| 99 public: | 92 public: |
| 100 GtkButtonImageSource(const char* idr_string, gfx::Size size) | 93 GtkButtonImageSource(const char* idr_string, gfx::Size size) |
| 101 : width_(size.width()), height_(size.height()) { | 94 : width_(size.width()), height_(size.height()) { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 #if GTK_MAJOR_VERSION == 2 | 141 #if GTK_MAJOR_VERSION == 2 |
| 149 if (focus_) | 142 if (focus_) |
| 150 GTK_WIDGET_SET_FLAGS(button, GTK_HAS_FOCUS); | 143 GTK_WIDGET_SET_FLAGS(button, GTK_HAS_FOCUS); |
| 151 | 144 |
| 152 int w, h; | 145 int w, h; |
| 153 GdkPixmap* pixmap; | 146 GdkPixmap* pixmap; |
| 154 | 147 |
| 155 { | 148 { |
| 156 // http://crbug.com/346740 | 149 // http://crbug.com/346740 |
| 157 ANNOTATE_SCOPED_MEMORY_LEAK; | 150 ANNOTATE_SCOPED_MEMORY_LEAK; |
| 158 pixmap = gtk_widget_get_snapshot(button, NULL); | 151 pixmap = gtk_widget_get_snapshot(button, nullptr); |
| 159 } | 152 } |
| 160 | 153 |
| 161 gdk_drawable_get_size(GDK_DRAWABLE(pixmap), &w, &h); | 154 gdk_drawable_get_size(GDK_DRAWABLE(pixmap), &w, &h); |
| 162 GdkColormap* colormap = gdk_drawable_get_colormap(pixmap); | 155 GdkColormap* colormap = gdk_drawable_get_colormap(pixmap); |
| 163 GdkPixbuf* pixbuf = gdk_pixbuf_get_from_drawable( | 156 GdkPixbuf* pixbuf = gdk_pixbuf_get_from_drawable( |
| 164 NULL, GDK_DRAWABLE(pixmap), colormap, 0, 0, 0, 0, w, h); | 157 nullptr, GDK_DRAWABLE(pixmap), colormap, 0, 0, 0, 0, w, h); |
| 165 | 158 |
| 166 gdk_cairo_set_source_pixbuf(cr, pixbuf, 0, 0); | 159 gdk_cairo_set_source_pixbuf(cr, pixbuf, 0, 0); |
| 167 cairo_paint(cr); | 160 cairo_paint(cr); |
| 168 | 161 |
| 169 g_object_unref(pixbuf); | 162 g_object_unref(pixbuf); |
| 170 g_object_unref(pixmap); | 163 g_object_unref(pixmap); |
| 171 #else | 164 #else |
| 172 GtkStyleContext* context = gtk_widget_get_style_context(button); | 165 GtkStyleContext* context = gtk_widget_get_style_context(button); |
| 173 gtk_render_background(context, cr, 0, 0, width, height); | 166 gtk_render_background(context, cr, 0, 0, width, height); |
| 174 gtk_render_frame(context, cr, 0, 0, width, height); | 167 gtk_render_frame(context, cr, 0, 0, width, height); |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 tint->l = 0.9; | 288 tint->l = 0.9; |
| 296 } | 289 } |
| 297 } | 290 } |
| 298 | 291 |
| 299 // Returns a gfx::FontRenderParams corresponding to GTK's configuration. | 292 // Returns a gfx::FontRenderParams corresponding to GTK's configuration. |
| 300 gfx::FontRenderParams GetGtkFontRenderParams() { | 293 gfx::FontRenderParams GetGtkFontRenderParams() { |
| 301 GtkSettings* gtk_settings = gtk_settings_get_default(); | 294 GtkSettings* gtk_settings = gtk_settings_get_default(); |
| 302 CHECK(gtk_settings); | 295 CHECK(gtk_settings); |
| 303 gint antialias = 0; | 296 gint antialias = 0; |
| 304 gint hinting = 0; | 297 gint hinting = 0; |
| 305 gchar* hint_style = NULL; | 298 gchar* hint_style = nullptr; |
| 306 gchar* rgba = NULL; | 299 gchar* rgba = nullptr; |
| 307 g_object_get(gtk_settings, "gtk-xft-antialias", &antialias, "gtk-xft-hinting", | 300 g_object_get(gtk_settings, "gtk-xft-antialias", &antialias, "gtk-xft-hinting", |
| 308 &hinting, "gtk-xft-hintstyle", &hint_style, "gtk-xft-rgba", | 301 &hinting, "gtk-xft-hintstyle", &hint_style, "gtk-xft-rgba", |
| 309 &rgba, NULL); | 302 &rgba, nullptr); |
| 310 | 303 |
| 311 gfx::FontRenderParams params; | 304 gfx::FontRenderParams params; |
| 312 params.antialiasing = antialias != 0; | 305 params.antialiasing = antialias != 0; |
| 313 | 306 |
| 314 if (hinting == 0 || !hint_style || strcmp(hint_style, "hintnone") == 0) { | 307 if (hinting == 0 || !hint_style || strcmp(hint_style, "hintnone") == 0) { |
| 315 params.hinting = gfx::FontRenderParams::HINTING_NONE; | 308 params.hinting = gfx::FontRenderParams::HINTING_NONE; |
| 316 } else if (strcmp(hint_style, "hintslight") == 0) { | 309 } else if (strcmp(hint_style, "hintslight") == 0) { |
| 317 params.hinting = gfx::FontRenderParams::HINTING_SLIGHT; | 310 params.hinting = gfx::FontRenderParams::HINTING_SLIGHT; |
| 318 } else if (strcmp(hint_style, "hintmedium") == 0) { | 311 } else if (strcmp(hint_style, "hintmedium") == 0) { |
| 319 params.hinting = gfx::FontRenderParams::HINTING_MEDIUM; | 312 params.hinting = gfx::FontRenderParams::HINTING_MEDIUM; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 345 return params; | 338 return params; |
| 346 } | 339 } |
| 347 | 340 |
| 348 double GetDpi() { | 341 double GetDpi() { |
| 349 if (display::Display::HasForceDeviceScaleFactor()) | 342 if (display::Display::HasForceDeviceScaleFactor()) |
| 350 return display::Display::GetForcedDeviceScaleFactor() * kDefaultDPI; | 343 return display::Display::GetForcedDeviceScaleFactor() * kDefaultDPI; |
| 351 | 344 |
| 352 GtkSettings* gtk_settings = gtk_settings_get_default(); | 345 GtkSettings* gtk_settings = gtk_settings_get_default(); |
| 353 CHECK(gtk_settings); | 346 CHECK(gtk_settings); |
| 354 gint gtk_dpi = -1; | 347 gint gtk_dpi = -1; |
| 355 g_object_get(gtk_settings, "gtk-xft-dpi", >k_dpi, NULL); | 348 g_object_get(gtk_settings, "gtk-xft-dpi", >k_dpi, nullptr); |
| 356 | 349 |
| 357 // GTK multiplies the DPI by 1024 before storing it. | 350 // GTK multiplies the DPI by 1024 before storing it. |
| 358 return (gtk_dpi > 0) ? gtk_dpi / 1024.0 : kDefaultDPI; | 351 return (gtk_dpi > 0) ? gtk_dpi / 1024.0 : kDefaultDPI; |
| 359 } | 352 } |
| 360 | 353 |
| 361 float GetRawDeviceScaleFactor() { | 354 float GetRawDeviceScaleFactor() { |
| 362 if (display::Display::HasForceDeviceScaleFactor()) | 355 if (display::Display::HasForceDeviceScaleFactor()) |
| 363 return display::Display::GetForcedDeviceScaleFactor(); | 356 return display::Display::GetForcedDeviceScaleFactor(); |
| 364 return GetDpi() / kDefaultDPI; | 357 return GetDpi() / kDefaultDPI; |
| 365 } | 358 } |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 552 | 545 |
| 553 // Dividing GTK's cursor blink cycle time (in milliseconds) by this value | 546 // Dividing GTK's cursor blink cycle time (in milliseconds) by this value |
| 554 // yields an appropriate value for | 547 // yields an appropriate value for |
| 555 // content::RendererPreferences::caret_blink_interval. This matches the | 548 // content::RendererPreferences::caret_blink_interval. This matches the |
| 556 // logic in the WebKit GTK port. | 549 // logic in the WebKit GTK port. |
| 557 static const double kGtkCursorBlinkCycleFactor = 2000.0; | 550 static const double kGtkCursorBlinkCycleFactor = 2000.0; |
| 558 | 551 |
| 559 gint cursor_blink_time = kGtkDefaultCursorBlinkTime; | 552 gint cursor_blink_time = kGtkDefaultCursorBlinkTime; |
| 560 gboolean cursor_blink = TRUE; | 553 gboolean cursor_blink = TRUE; |
| 561 g_object_get(gtk_settings_get_default(), "gtk-cursor-blink-time", | 554 g_object_get(gtk_settings_get_default(), "gtk-cursor-blink-time", |
| 562 &cursor_blink_time, "gtk-cursor-blink", &cursor_blink, NULL); | 555 &cursor_blink_time, "gtk-cursor-blink", &cursor_blink, nullptr); |
| 563 return cursor_blink ? (cursor_blink_time / kGtkCursorBlinkCycleFactor) : 0.0; | 556 return cursor_blink ? (cursor_blink_time / kGtkCursorBlinkCycleFactor) : 0.0; |
| 564 } | 557 } |
| 565 | 558 |
| 566 ui::NativeTheme* GtkUi::GetNativeTheme(aura::Window* window) const { | 559 ui::NativeTheme* GtkUi::GetNativeTheme(aura::Window* window) const { |
| 567 ui::NativeTheme* native_theme_override = NULL; | 560 ui::NativeTheme* native_theme_override = nullptr; |
| 568 if (!native_theme_overrider_.is_null()) | 561 if (!native_theme_overrider_.is_null()) |
| 569 native_theme_override = native_theme_overrider_.Run(window); | 562 native_theme_override = native_theme_overrider_.Run(window); |
| 570 | 563 |
| 571 if (native_theme_override) | 564 if (native_theme_override) |
| 572 return native_theme_override; | 565 return native_theme_override; |
| 573 | 566 |
| 574 return native_theme_; | 567 return native_theme_; |
| 575 } | 568 } |
| 576 | 569 |
| 577 void GtkUi::SetNativeThemeOverride(const NativeThemeGetter& callback) { | 570 void GtkUi::SetNativeThemeOverride(const NativeThemeGetter& callback) { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 632 | 625 |
| 633 std::string content_types[] = {content_type, kUnknownContentType}; | 626 std::string content_types[] = {content_type, kUnknownContentType}; |
| 634 | 627 |
| 635 for (size_t i = 0; i < arraysize(content_types); ++i) { | 628 for (size_t i = 0; i < arraysize(content_types); ++i) { |
| 636 ScopedGIcon icon(g_content_type_get_icon(content_types[i].c_str())); | 629 ScopedGIcon icon(g_content_type_get_icon(content_types[i].c_str())); |
| 637 ScopedGtkIconInfo icon_info(gtk_icon_theme_lookup_by_gicon( | 630 ScopedGtkIconInfo icon_info(gtk_icon_theme_lookup_by_gicon( |
| 638 theme, icon.get(), size, | 631 theme, icon.get(), size, |
| 639 static_cast<GtkIconLookupFlags>(GTK_ICON_LOOKUP_FORCE_SIZE))); | 632 static_cast<GtkIconLookupFlags>(GTK_ICON_LOOKUP_FORCE_SIZE))); |
| 640 if (!icon_info) | 633 if (!icon_info) |
| 641 continue; | 634 continue; |
| 642 ScopedGdkPixbuf pixbuf(gtk_icon_info_load_icon(icon_info.get(), NULL)); | 635 ScopedGdkPixbuf pixbuf(gtk_icon_info_load_icon(icon_info.get(), nullptr)); |
| 643 if (!pixbuf) | 636 if (!pixbuf) |
| 644 continue; | 637 continue; |
| 645 | 638 |
| 646 SkBitmap bitmap = GdkPixbufToImageSkia(pixbuf.get()); | 639 SkBitmap bitmap = GdkPixbufToImageSkia(pixbuf.get()); |
| 647 DCHECK_EQ(size, bitmap.width()); | 640 DCHECK_EQ(size, bitmap.width()); |
| 648 DCHECK_EQ(size, bitmap.height()); | 641 DCHECK_EQ(size, bitmap.height()); |
| 649 gfx::ImageSkia image_skia = gfx::ImageSkia::CreateFrom1xBitmap(bitmap); | 642 gfx::ImageSkia image_skia = gfx::ImageSkia::CreateFrom1xBitmap(bitmap); |
| 650 image_skia.MakeThreadSafe(); | 643 image_skia.MakeThreadSafe(); |
| 651 return gfx::Image(image_skia); | 644 return gfx::Image(image_skia); |
| 652 } | 645 } |
| (...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1080 | 1073 |
| 1081 float GtkUi::GetDeviceScaleFactor() const { | 1074 float GtkUi::GetDeviceScaleFactor() const { |
| 1082 return device_scale_factor_; | 1075 return device_scale_factor_; |
| 1083 } | 1076 } |
| 1084 | 1077 |
| 1085 } // namespace libgtkui | 1078 } // namespace libgtkui |
| 1086 | 1079 |
| 1087 views::LinuxUI* BuildGtkUi() { | 1080 views::LinuxUI* BuildGtkUi() { |
| 1088 return new libgtkui::GtkUi; | 1081 return new libgtkui::GtkUi; |
| 1089 } | 1082 } |
| OLD | NEW |