| 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 <gdk/gdk.h> | 8 #include <gdk/gdk.h> |
| 8 #include <gdk/gdkx.h> | 9 #include <gdk/gdkx.h> |
| 9 #include <gtk/gtk.h> | 10 #include <gtk/gtk.h> |
| 10 #include <stddef.h> | 11 #include <stddef.h> |
| 11 | 12 |
| 12 #include <memory> | 13 #include <memory> |
| 13 | 14 |
| 14 #include "base/command_line.h" | 15 #include "base/command_line.h" |
| 15 #include "base/debug/leak_annotations.h" | 16 #include "base/debug/leak_annotations.h" |
| 16 #include "base/environment.h" | 17 #include "base/environment.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 45 { | 46 { |
| 46 // http://crbug.com/423873 | 47 // http://crbug.com/423873 |
| 47 ANNOTATE_SCOPED_MEMORY_LEAK; | 48 ANNOTATE_SCOPED_MEMORY_LEAK; |
| 48 init_func(&argc, &argv_pointer); | 49 init_func(&argc, &argv_pointer); |
| 49 } | 50 } |
| 50 for (size_t i = 0; i < args.size(); ++i) { | 51 for (size_t i = 0; i < args.size(); ++i) { |
| 51 free(argv[i]); | 52 free(argv[i]); |
| 52 } | 53 } |
| 53 } | 54 } |
| 54 | 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 |
| 55 } // namespace | 64 } // namespace |
| 56 | 65 |
| 57 namespace libgtkui { | 66 namespace libgtkui { |
| 58 | 67 |
| 59 // Theme colors returned by GetSystemColor(). | 68 // Theme colors returned by GetSystemColor(). |
| 60 const SkColor kInvalidColorIdColor = SkColorSetRGB(255, 0, 128); | 69 const SkColor kInvalidColorIdColor = SkColorSetRGB(255, 0, 128); |
| 61 const SkColor kURLTextColor = SkColorSetRGB(0x0b, 0x80, 0x43); | 70 const SkColor kURLTextColor = SkColorSetRGB(0x0b, 0x80, 0x43); |
| 62 | 71 |
| 63 SkColor NormalURLColor(SkColor foreground) { | 72 SkColor NormalURLColor(SkColor foreground) { |
| 64 color_utils::HSL fg_hsl, hue_hsl; | 73 color_utils::HSL fg_hsl, hue_hsl; |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 } | 201 } |
| 193 | 202 |
| 194 #if GTK_MAJOR_VERSION > 2 | 203 #if GTK_MAJOR_VERSION > 2 |
| 195 ScopedStyleContext AppendNode(GtkStyleContext* context, | 204 ScopedStyleContext AppendNode(GtkStyleContext* context, |
| 196 const std::string& css_node) { | 205 const std::string& css_node) { |
| 197 GtkWidgetPath* path = | 206 GtkWidgetPath* path = |
| 198 context ? gtk_widget_path_copy(gtk_style_context_get_path(context)) | 207 context ? gtk_widget_path_copy(gtk_style_context_get_path(context)) |
| 199 : gtk_widget_path_new(); | 208 : gtk_widget_path_new(); |
| 200 | 209 |
| 201 enum { | 210 enum { |
| 202 // TODO(thomasanderson): Add CSS_NAME here to handle the Gtk3.20 case. | |
| 203 CSS_TYPE, | 211 CSS_TYPE, |
| 212 CSS_NAME, |
| 204 CSS_CLASS, | 213 CSS_CLASS, |
| 205 CSS_PSEUDOCLASS, | 214 CSS_PSEUDOCLASS, |
| 206 } part_type = CSS_TYPE; | 215 } part_type = CSS_TYPE; |
| 207 static const struct { | 216 static const struct { |
| 208 const char* name; | 217 const char* name; |
| 209 GtkStateFlags state_flag; | 218 GtkStateFlags state_flag; |
| 210 } pseudo_classes[] = { | 219 } pseudo_classes[] = { |
| 211 {"active", GTK_STATE_FLAG_ACTIVE}, | 220 {"active", GTK_STATE_FLAG_ACTIVE}, |
| 212 {"hover", GTK_STATE_FLAG_PRELIGHT}, | 221 {"hover", GTK_STATE_FLAG_PRELIGHT}, |
| 213 {"selected", GTK_STATE_FLAG_SELECTED}, | 222 {"selected", GTK_STATE_FLAG_SELECTED}, |
| 214 {"disabled", GTK_STATE_FLAG_INSENSITIVE}, | 223 {"disabled", GTK_STATE_FLAG_INSENSITIVE}, |
| 215 {"indeterminate", GTK_STATE_FLAG_INCONSISTENT}, | 224 {"indeterminate", GTK_STATE_FLAG_INCONSISTENT}, |
| 216 {"focus", GTK_STATE_FLAG_FOCUSED}, | 225 {"focus", GTK_STATE_FLAG_FOCUSED}, |
| 217 {"backdrop", GTK_STATE_FLAG_BACKDROP}, | 226 {"backdrop", GTK_STATE_FLAG_BACKDROP}, |
| 218 // TODO(thomasanderson): These state flags are only available in | 227 // TODO(thomasanderson): These state flags are only available in |
| 219 // GTK 3.10 or later, which is unavailable in the wheezy | 228 // GTK 3.10 or later, which is unavailable in the wheezy |
| 220 // sysroot. Add them once the sysroot is updated to jessie. | 229 // sysroot. Add them once the sysroot is updated to jessie. |
| 221 // { "link", GTK_STATE_FLAG_LINK }, | 230 // { "link", GTK_STATE_FLAG_LINK }, |
| 222 // { "visited", GTK_STATE_FLAG_VISITED }, | 231 // { "visited", GTK_STATE_FLAG_VISITED }, |
| 223 // { "checked", GTK_STATE_FLAG_CHECKED }, | 232 // { "checked", GTK_STATE_FLAG_CHECKED }, |
| 224 }; | 233 }; |
| 225 GtkStateFlags state = | 234 GtkStateFlags state = |
| 226 context ? gtk_style_context_get_state(context) : GTK_STATE_FLAG_NORMAL; | 235 context ? gtk_style_context_get_state(context) : GTK_STATE_FLAG_NORMAL; |
| 227 base::StringTokenizer t(css_node, ".:"); | 236 base::StringTokenizer t(css_node, ".:#"); |
| 228 t.set_options(base::StringTokenizer::RETURN_DELIMS); | 237 t.set_options(base::StringTokenizer::RETURN_DELIMS); |
| 229 while (t.GetNext()) { | 238 while (t.GetNext()) { |
| 230 if (t.token_is_delim()) { | 239 if (t.token_is_delim()) { |
| 231 if (t.token_begin() == css_node.begin()) { | 240 if (t.token_begin() == css_node.begin()) { |
| 232 // Special case for the first token. | 241 // Special case for the first token. |
| 233 gtk_widget_path_append_type(path, G_TYPE_NONE); | 242 gtk_widget_path_append_type(path, G_TYPE_NONE); |
| 234 } | 243 } |
| 235 switch (*t.token_begin()) { | 244 switch (*t.token_begin()) { |
| 245 case '#': |
| 246 part_type = CSS_NAME; |
| 247 break; |
| 236 case '.': | 248 case '.': |
| 237 part_type = CSS_CLASS; | 249 part_type = CSS_CLASS; |
| 238 break; | 250 break; |
| 239 case ':': | 251 case ':': |
| 240 part_type = CSS_PSEUDOCLASS; | 252 part_type = CSS_PSEUDOCLASS; |
| 241 break; | 253 break; |
| 242 default: | 254 default: |
| 243 NOTREACHED(); | 255 NOTREACHED(); |
| 244 } | 256 } |
| 245 } else { | 257 } else { |
| 246 switch (part_type) { | 258 switch (part_type) { |
| 259 case CSS_NAME: { |
| 260 if (gtk_get_major_version() > 3 || |
| 261 (gtk_get_major_version() == 3 && gtk_get_minor_version() >= 20)) { |
| 262 static auto* _gtk_widget_path_iter_set_object_name = |
| 263 reinterpret_cast<void (*)(GtkWidgetPath*, gint, const char*)>( |
| 264 dlsym(GetGtk3SharedLibrary(), |
| 265 "gtk_widget_path_iter_set_object_name")); |
| 266 DCHECK(_gtk_widget_path_iter_set_object_name); |
| 267 _gtk_widget_path_iter_set_object_name(path, -1, t.token().c_str()); |
| 268 } else { |
| 269 gtk_widget_path_iter_add_class(path, -1, t.token().c_str()); |
| 270 } |
| 271 break; |
| 272 } |
| 247 case CSS_TYPE: { | 273 case CSS_TYPE: { |
| 248 GType type = g_type_from_name(t.token().c_str()); | 274 GType type = g_type_from_name(t.token().c_str()); |
| 249 DCHECK(type); | 275 DCHECK(type); |
| 250 gtk_widget_path_append_type(path, type); | 276 gtk_widget_path_append_type(path, type); |
| 251 break; | 277 break; |
| 252 } | 278 } |
| 253 case CSS_CLASS: { | 279 case CSS_CLASS: { |
| 254 gtk_widget_path_iter_add_class(path, -1, t.token().c_str()); | 280 gtk_widget_path_iter_add_class(path, -1, t.token().c_str()); |
| 255 break; | 281 break; |
| 256 } | 282 } |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 } | 425 } |
| 400 | 426 |
| 401 AddBorders(context); | 427 AddBorders(context); |
| 402 PixelSurface surface; | 428 PixelSurface surface; |
| 403 gtk_render_frame(context, surface.cairo(), 0, 0, 1, 1); | 429 gtk_render_frame(context, surface.cairo(), 0, 0, 1, 1); |
| 404 return surface.GetPixelValue(); | 430 return surface.GetPixelValue(); |
| 405 } | 431 } |
| 406 #endif | 432 #endif |
| 407 | 433 |
| 408 } // namespace libgtkui | 434 } // namespace libgtkui |
| OLD | NEW |