Chromium Code Reviews| 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_util.h" | 5 #include "chrome/browser/ui/libgtkui/gtk_util.h" |
| 6 | 6 |
| 7 #include <dlfcn.h> | 7 #include <dlfcn.h> |
| 8 #include <gdk/gdk.h> | 8 #include <gdk/gdk.h> |
| 9 #include <gdk/gdkx.h> | 9 #include <gdk/gdkx.h> |
| 10 #include <gtk/gtk.h> | 10 #include <gtk/gtk.h> |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 46 { | 46 { |
| 47 // http://crbug.com/423873 | 47 // http://crbug.com/423873 |
| 48 ANNOTATE_SCOPED_MEMORY_LEAK; | 48 ANNOTATE_SCOPED_MEMORY_LEAK; |
| 49 init_func(&argc, &argv_pointer); | 49 init_func(&argc, &argv_pointer); |
| 50 } | 50 } |
| 51 for (size_t i = 0; i < args.size(); ++i) { | 51 for (size_t i = 0; i < args.size(); ++i) { |
| 52 free(argv[i]); | 52 free(argv[i]); |
| 53 } | 53 } |
| 54 } | 54 } |
| 55 | 55 |
| 56 #if GTK_MAJOR_VERSION == 3 | |
| 57 void* GetGtk3SharedLibrary() { | |
| 58 static void* gtk3lib = dlopen("libgtk-3.so.0", RTLD_LAZY); | |
| 59 DCHECK(gtk3lib); | |
| 60 return gtk3lib; | |
| 61 } | |
| 62 #endif | |
| 63 | |
| 64 } // namespace | 56 } // namespace |
| 65 | 57 |
| 66 namespace libgtkui { | 58 namespace libgtkui { |
| 67 | 59 |
| 68 // TODO(erg): ThemeService has a whole interface just for reading default | 60 // TODO(erg): ThemeService has a whole interface just for reading default |
| 69 // constants. Figure out what to do with that more long term; for now, just | 61 // constants. Figure out what to do with that more long term; for now, just |
| 70 // copy the constants themselves here. | 62 // copy the constants themselves here. |
| 71 const color_utils::HSL kDefaultTintFrameIncognito = {-1, 0.2f, 0.35f}; | 63 const color_utils::HSL kDefaultTintFrameIncognito = {-1, 0.2f, 0.35f}; |
| 72 const color_utils::HSL kDefaultTintFrameIncognitoInactive = {-1, 0.3f, 0.6f}; | 64 const color_utils::HSL kDefaultTintFrameIncognitoInactive = {-1, 0.3f, 0.6f}; |
| 73 | 65 |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 200 aura::Window* GetAuraTransientParent(GtkWidget* dialog) { | 192 aura::Window* GetAuraTransientParent(GtkWidget* dialog) { |
| 201 return reinterpret_cast<aura::Window*>( | 193 return reinterpret_cast<aura::Window*>( |
| 202 g_object_get_data(G_OBJECT(dialog), kAuraTransientParent)); | 194 g_object_get_data(G_OBJECT(dialog), kAuraTransientParent)); |
| 203 } | 195 } |
| 204 | 196 |
| 205 void ClearAuraTransientParent(GtkWidget* dialog) { | 197 void ClearAuraTransientParent(GtkWidget* dialog) { |
| 206 g_object_set_data(G_OBJECT(dialog), kAuraTransientParent, nullptr); | 198 g_object_set_data(G_OBJECT(dialog), kAuraTransientParent, nullptr); |
| 207 } | 199 } |
| 208 | 200 |
| 209 #if GTK_MAJOR_VERSION > 2 | 201 #if GTK_MAJOR_VERSION > 2 |
| 202 void* GetGdkSharedLibrary() { | |
| 203 std::string lib_name = | |
| 204 "libgdk-" + std::to_string(GTK_MAJOR_VERSION) + ".so.0"; | |
|
Elliot Glaysher
2017/03/20 21:01:41
Is this ever not 3?
Tom (Use chromium acct)
2017/03/20 21:04:46
For now it is, but we'll need it for gtk4 ;)
| |
| 205 static void* gdk_lib = dlopen(lib_name.c_str(), RTLD_LAZY); | |
| 206 DCHECK(gdk_lib); | |
| 207 return gdk_lib; | |
| 208 } | |
| 209 | |
| 210 void* GetGtkSharedLibrary() { | |
| 211 std::string lib_name = | |
| 212 "libgtk-" + std::to_string(GTK_MAJOR_VERSION) + ".so.0"; | |
| 213 static void* gtk_lib = dlopen(lib_name.c_str(), RTLD_LAZY); | |
| 214 DCHECK(gtk_lib); | |
| 215 return gtk_lib; | |
| 216 } | |
| 217 | |
| 210 CairoSurface::CairoSurface(SkBitmap& bitmap) | 218 CairoSurface::CairoSurface(SkBitmap& bitmap) |
| 211 : surface_(cairo_image_surface_create_for_data( | 219 : surface_(cairo_image_surface_create_for_data( |
| 212 static_cast<unsigned char*>(bitmap.getAddr(0, 0)), | 220 static_cast<unsigned char*>(bitmap.getAddr(0, 0)), |
| 213 CAIRO_FORMAT_ARGB32, | 221 CAIRO_FORMAT_ARGB32, |
| 214 bitmap.width(), | 222 bitmap.width(), |
| 215 bitmap.height(), | 223 bitmap.height(), |
| 216 cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, bitmap.width()))), | 224 cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, bitmap.width()))), |
| 217 cairo_(cairo_create(surface_)) {} | 225 cairo_(cairo_create(surface_)) {} |
| 218 | 226 |
| 219 CairoSurface::CairoSurface(const gfx::Size& size) | 227 CairoSurface::CairoSurface(const gfx::Size& size) |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 340 break; | 348 break; |
| 341 case ':': | 349 case ':': |
| 342 part_type = CSS_PSEUDOCLASS; | 350 part_type = CSS_PSEUDOCLASS; |
| 343 break; | 351 break; |
| 344 default: | 352 default: |
| 345 NOTREACHED(); | 353 NOTREACHED(); |
| 346 } | 354 } |
| 347 } else { | 355 } else { |
| 348 static auto* _gtk_widget_path_iter_set_object_name = | 356 static auto* _gtk_widget_path_iter_set_object_name = |
| 349 reinterpret_cast<void (*)(GtkWidgetPath*, gint, const char*)>(dlsym( | 357 reinterpret_cast<void (*)(GtkWidgetPath*, gint, const char*)>(dlsym( |
| 350 GetGtk3SharedLibrary(), "gtk_widget_path_iter_set_object_name")); | 358 GetGtkSharedLibrary(), "gtk_widget_path_iter_set_object_name")); |
| 351 switch (part_type) { | 359 switch (part_type) { |
| 352 case CSS_NAME: { | 360 case CSS_NAME: { |
| 353 if (GtkVersionCheck(3, 20)) { | 361 if (GtkVersionCheck(3, 20)) { |
| 354 _gtk_widget_path_iter_set_object_name(path, -1, t.token().c_str()); | 362 _gtk_widget_path_iter_set_object_name(path, -1, t.token().c_str()); |
| 355 } else { | 363 } else { |
| 356 gtk_widget_path_iter_add_class(path, -1, t.token().c_str()); | 364 gtk_widget_path_iter_add_class(path, -1, t.token().c_str()); |
| 357 } | 365 } |
| 358 break; | 366 break; |
| 359 } | 367 } |
| 360 case CSS_TYPE: { | 368 case CSS_TYPE: { |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 386 } | 394 } |
| 387 } | 395 } |
| 388 | 396 |
| 389 // Always add a "chromium" class so that themes can style chromium | 397 // Always add a "chromium" class so that themes can style chromium |
| 390 // widgets specially if they want to. | 398 // widgets specially if they want to. |
| 391 gtk_widget_path_iter_add_class(path, -1, "chromium"); | 399 gtk_widget_path_iter_add_class(path, -1, "chromium"); |
| 392 | 400 |
| 393 if (GtkVersionCheck(3, 14)) { | 401 if (GtkVersionCheck(3, 14)) { |
| 394 static auto* _gtk_widget_path_iter_set_state = | 402 static auto* _gtk_widget_path_iter_set_state = |
| 395 reinterpret_cast<void (*)(GtkWidgetPath*, gint, GtkStateFlags)>( | 403 reinterpret_cast<void (*)(GtkWidgetPath*, gint, GtkStateFlags)>( |
| 396 dlsym(GetGtk3SharedLibrary(), "gtk_widget_path_iter_set_state")); | 404 dlsym(GetGtkSharedLibrary(), "gtk_widget_path_iter_set_state")); |
| 397 DCHECK(_gtk_widget_path_iter_set_state); | 405 DCHECK(_gtk_widget_path_iter_set_state); |
| 398 _gtk_widget_path_iter_set_state(path, -1, state); | 406 _gtk_widget_path_iter_set_state(path, -1, state); |
| 399 } | 407 } |
| 400 | 408 |
| 401 ScopedStyleContext child_context(gtk_style_context_new()); | 409 ScopedStyleContext child_context(gtk_style_context_new()); |
| 402 gtk_style_context_set_path(child_context, path); | 410 gtk_style_context_set_path(child_context, path); |
| 403 if (GtkVersionCheck(3, 14)) { | 411 if (GtkVersionCheck(3, 14)) { |
| 404 gtk_style_context_set_state(child_context, state); | 412 gtk_style_context_set_state(child_context, state); |
| 405 } else { | 413 } else { |
| 406 GtkStateFlags child_state = state; | 414 GtkStateFlags child_state = state; |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 548 } | 556 } |
| 549 | 557 |
| 550 CairoSurface surface(gfx::Size(w, h)); | 558 CairoSurface surface(gfx::Size(w, h)); |
| 551 gtk_render_background(context, surface.cairo(), 0, 0, w, h); | 559 gtk_render_background(context, surface.cairo(), 0, 0, w, h); |
| 552 gtk_render_frame(context, surface.cairo(), 0, 0, w, h); | 560 gtk_render_frame(context, surface.cairo(), 0, 0, w, h); |
| 553 return surface.GetAveragePixelValue(false); | 561 return surface.GetAveragePixelValue(false); |
| 554 } | 562 } |
| 555 #endif | 563 #endif |
| 556 | 564 |
| 557 } // namespace libgtkui | 565 } // namespace libgtkui |
| OLD | NEW |