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 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 {"hover", GTK_STATE_FLAG_PRELIGHT}, | 298 {"hover", GTK_STATE_FLAG_PRELIGHT}, |
299 {"selected", GTK_STATE_FLAG_SELECTED}, | 299 {"selected", GTK_STATE_FLAG_SELECTED}, |
300 {"disabled", GTK_STATE_FLAG_INSENSITIVE}, | 300 {"disabled", GTK_STATE_FLAG_INSENSITIVE}, |
301 {"indeterminate", GTK_STATE_FLAG_INCONSISTENT}, | 301 {"indeterminate", GTK_STATE_FLAG_INCONSISTENT}, |
302 {"focus", GTK_STATE_FLAG_FOCUSED}, | 302 {"focus", GTK_STATE_FLAG_FOCUSED}, |
303 {"backdrop", GTK_STATE_FLAG_BACKDROP}, | 303 {"backdrop", GTK_STATE_FLAG_BACKDROP}, |
304 {"link", GTK_STATE_FLAG_LINK}, | 304 {"link", GTK_STATE_FLAG_LINK}, |
305 {"visited", GTK_STATE_FLAG_VISITED}, | 305 {"visited", GTK_STATE_FLAG_VISITED}, |
306 {"checked", GTK_STATE_FLAG_CHECKED}, | 306 {"checked", GTK_STATE_FLAG_CHECKED}, |
307 }; | 307 }; |
308 GtkStateFlags state = | 308 GtkStateFlags state = GTK_STATE_FLAG_NORMAL; |
309 context ? gtk_style_context_get_state(context) : GTK_STATE_FLAG_NORMAL; | |
310 base::StringTokenizer t(css_node, ".:#"); | 309 base::StringTokenizer t(css_node, ".:#"); |
311 t.set_options(base::StringTokenizer::RETURN_DELIMS); | 310 t.set_options(base::StringTokenizer::RETURN_DELIMS); |
312 while (t.GetNext()) { | 311 while (t.GetNext()) { |
313 if (t.token_is_delim()) { | 312 if (t.token_is_delim()) { |
314 if (t.token_begin() == css_node.begin()) { | 313 if (t.token_begin() == css_node.begin()) { |
315 // Special case for the first token. | 314 // Special case for the first token. |
316 gtk_widget_path_append_type(path, G_TYPE_NONE); | 315 gtk_widget_path_append_type(path, G_TYPE_NONE); |
317 } | 316 } |
318 switch (*t.token_begin()) { | 317 switch (*t.token_begin()) { |
319 case '#': | 318 case '#': |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 break; | 366 break; |
368 } | 367 } |
369 } | 368 } |
370 } | 369 } |
371 } | 370 } |
372 | 371 |
373 // Always add a "chromium" class so that themes can style chromium | 372 // Always add a "chromium" class so that themes can style chromium |
374 // widgets specially if they want to. | 373 // widgets specially if they want to. |
375 gtk_widget_path_iter_add_class(path, -1, "chromium"); | 374 gtk_widget_path_iter_add_class(path, -1, "chromium"); |
376 | 375 |
| 376 if (GtkVersionCheck(3, 14)) { |
| 377 static auto* _gtk_widget_path_iter_set_state = |
| 378 reinterpret_cast<void (*)(GtkWidgetPath*, gint, GtkStateFlags)>( |
| 379 dlsym(GetGtk3SharedLibrary(), "gtk_widget_path_iter_set_state")); |
| 380 DCHECK(_gtk_widget_path_iter_set_state); |
| 381 _gtk_widget_path_iter_set_state(path, -1, state); |
| 382 } |
| 383 |
377 ScopedStyleContext child_context(gtk_style_context_new()); | 384 ScopedStyleContext child_context(gtk_style_context_new()); |
378 gtk_style_context_set_path(child_context, path); | 385 gtk_style_context_set_path(child_context, path); |
379 gtk_style_context_set_state(child_context, state); | 386 if (GtkVersionCheck(3, 14)) { |
| 387 gtk_style_context_set_state(child_context, state); |
| 388 } else { |
| 389 GtkStateFlags child_state = state; |
| 390 if (context) { |
| 391 child_state = static_cast<GtkStateFlags>( |
| 392 child_state | gtk_style_context_get_state(context)); |
| 393 } |
| 394 gtk_style_context_set_state(child_context, child_state); |
| 395 } |
380 gtk_style_context_set_parent(child_context, context); | 396 gtk_style_context_set_parent(child_context, context); |
381 gtk_widget_path_unref(path); | 397 gtk_widget_path_unref(path); |
382 return child_context; | 398 return child_context; |
383 } | 399 } |
384 | 400 |
385 ScopedStyleContext GetStyleContextFromCss(const char* css_selector) { | 401 ScopedStyleContext GetStyleContextFromCss(const char* css_selector) { |
386 // Prepend a window node to the selector since all widgets must live | 402 // Prepend a window node to the selector since all widgets must live |
387 // in a window, but we don't want to specify that every time. | 403 // in a window, but we don't want to specify that every time. |
388 auto context = | 404 auto context = |
389 AppendCssNodeToStyleContext(nullptr, "GtkWindow#window.background"); | 405 AppendCssNodeToStyleContext(nullptr, "GtkWindow#window.background"); |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
531 } | 547 } |
532 | 548 |
533 CairoSurface surface(gfx::Size(w, h)); | 549 CairoSurface surface(gfx::Size(w, h)); |
534 gtk_render_background(context, surface.cairo(), 0, 0, w, h); | 550 gtk_render_background(context, surface.cairo(), 0, 0, w, h); |
535 gtk_render_frame(context, surface.cairo(), 0, 0, w, h); | 551 gtk_render_frame(context, surface.cairo(), 0, 0, w, h); |
536 return surface.GetAveragePixelValue(false); | 552 return surface.GetAveragePixelValue(false); |
537 } | 553 } |
538 #endif | 554 #endif |
539 | 555 |
540 } // namespace libgtkui | 556 } // namespace libgtkui |
OLD | NEW |