Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(441)

Side by Side Diff: chrome/browser/ui/libgtkui/gtk_util.cc

Issue 2786703004: Gtk3: Fix DCHECK on 3.20 (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 512 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 return GetBgColorFromStyleContext(context); 523 return GetBgColorFromStyleContext(context);
524 // This is verbatim how Gtk gets the selection color on versions before 3.20. 524 // This is verbatim how Gtk gets the selection color on versions before 3.20.
525 GdkRGBA selection_color; 525 GdkRGBA selection_color;
526 G_GNUC_BEGIN_IGNORE_DEPRECATIONS; 526 G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
527 gtk_style_context_get_background_color( 527 gtk_style_context_get_background_color(
528 context, gtk_style_context_get_state(context), &selection_color); 528 context, gtk_style_context_get_state(context), &selection_color);
529 G_GNUC_END_IGNORE_DEPRECATIONS; 529 G_GNUC_END_IGNORE_DEPRECATIONS;
530 return GdkRgbaToSkColor(selection_color); 530 return GdkRgbaToSkColor(selection_color);
531 } 531 }
532 532
533 bool ContextHasClass(GtkStyleContext* context, const std::string& style_class) {
534 return gtk_style_context_has_class(context, style_class.c_str()) ||
535 gtk_widget_path_iter_has_class(gtk_style_context_get_path(context), -1,
536 style_class.c_str());
537 }
538
533 SkColor GetSeparatorColor(const std::string& css_selector) { 539 SkColor GetSeparatorColor(const std::string& css_selector) {
534 if (!GtkVersionCheck(3, 20)) 540 if (!GtkVersionCheck(3, 20))
535 return GetFgColor(css_selector); 541 return GetFgColor(css_selector);
536 542
537 auto context = GetStyleContextFromCss(css_selector); 543 auto context = GetStyleContextFromCss(css_selector);
538 int w = 1, h = 1; 544 int w = 1, h = 1;
539 gtk_style_context_get(context, gtk_style_context_get_state(context), 545 gtk_style_context_get(context, gtk_style_context_get_state(context),
540 "min-width", &w, "min-height", &h, nullptr); 546 "min-width", &w, "min-height", &h, nullptr);
541 GtkBorder border, padding; 547 GtkBorder border, padding;
542 GtkStateFlags state = gtk_style_context_get_state(context); 548 GtkStateFlags state = gtk_style_context_get_state(context);
543 gtk_style_context_get_border(context, state, &border); 549 gtk_style_context_get_border(context, state, &border);
544 gtk_style_context_get_padding(context, state, &padding); 550 gtk_style_context_get_padding(context, state, &padding);
545 w += border.left + padding.left + padding.right + border.right; 551 w += border.left + padding.left + padding.right + border.right;
546 h += border.top + padding.top + padding.bottom + border.bottom; 552 h += border.top + padding.top + padding.bottom + border.bottom;
547 553
548 bool horizontal = gtk_style_context_has_class(context, "horizontal"); 554 bool horizontal = ContextHasClass(context, "horizontal");
549 if (horizontal) { 555 if (horizontal) {
550 w = 24; 556 w = 24;
551 h = std::max(h, 1); 557 h = std::max(h, 1);
552 } else { 558 } else {
553 DCHECK(gtk_style_context_has_class(context, "vertical")); 559 DCHECK(ContextHasClass(context, "vertical"));
554 h = 24; 560 h = 24;
555 w = std::max(w, 1); 561 w = std::max(w, 1);
556 } 562 }
557 563
558 CairoSurface surface(gfx::Size(w, h)); 564 CairoSurface surface(gfx::Size(w, h));
559 gtk_render_background(context, surface.cairo(), 0, 0, w, h); 565 gtk_render_background(context, surface.cairo(), 0, 0, w, h);
560 gtk_render_frame(context, surface.cairo(), 0, 0, w, h); 566 gtk_render_frame(context, surface.cairo(), 0, 0, w, h);
561 return surface.GetAveragePixelValue(false); 567 return surface.GetAveragePixelValue(false);
562 } 568 }
563 #endif 569 #endif
564 570
565 } // namespace libgtkui 571 } // namespace libgtkui
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698