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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 static void* gtk3lib = dlopen("libgtk-3.so.0", RTLD_LAZY); | 58 static void* gtk3lib = dlopen("libgtk-3.so.0", RTLD_LAZY); |
59 DCHECK(gtk3lib); | 59 DCHECK(gtk3lib); |
60 return gtk3lib; | 60 return gtk3lib; |
61 } | 61 } |
62 #endif | 62 #endif |
63 | 63 |
64 } // namespace | 64 } // namespace |
65 | 65 |
66 namespace libgtkui { | 66 namespace libgtkui { |
67 | 67 |
| 68 // 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 |
| 70 // copy the constants themselves here. |
| 71 const color_utils::HSL kDefaultTintFrameIncognito = {-1, 0.2f, 0.35f}; |
| 72 const color_utils::HSL kDefaultTintFrameIncognitoInactive = {-1, 0.3f, 0.6f}; |
| 73 |
68 // Theme colors returned by GetSystemColor(). | 74 // Theme colors returned by GetSystemColor(). |
69 const SkColor kInvalidColorIdColor = SkColorSetRGB(255, 0, 128); | 75 const SkColor kInvalidColorIdColor = SkColorSetRGB(255, 0, 128); |
70 const SkColor kURLTextColor = SkColorSetRGB(0x0b, 0x80, 0x43); | 76 const SkColor kURLTextColor = SkColorSetRGB(0x0b, 0x80, 0x43); |
71 | 77 |
72 SkColor NormalURLColor(SkColor foreground) { | 78 SkColor NormalURLColor(SkColor foreground) { |
73 color_utils::HSL fg_hsl, hue_hsl; | 79 color_utils::HSL fg_hsl, hue_hsl; |
74 color_utils::SkColorToHSL(foreground, &fg_hsl); | 80 color_utils::SkColorToHSL(foreground, &fg_hsl); |
75 color_utils::SkColorToHSL(kURLTextColor, &hue_hsl); | 81 color_utils::SkColorToHSL(kURLTextColor, &hue_hsl); |
76 | 82 |
77 // Only allow colors that have a fair amount of saturation in them (color vs | 83 // Only allow colors that have a fair amount of saturation in them (color vs |
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 // Get the color value of the single pixel. | 420 // Get the color value of the single pixel. |
415 SkColor GetPixelValue() { | 421 SkColor GetPixelValue() { |
416 return *reinterpret_cast<SkColor*>(cairo_image_surface_get_data(surface_)); | 422 return *reinterpret_cast<SkColor*>(cairo_image_surface_get_data(surface_)); |
417 } | 423 } |
418 | 424 |
419 private: | 425 private: |
420 cairo_surface_t* surface_; | 426 cairo_surface_t* surface_; |
421 cairo_t* cairo_; | 427 cairo_t* cairo_; |
422 }; | 428 }; |
423 | 429 |
424 void RenderBackground(cairo_t* cr, GtkStyleContext* context) { | 430 void RenderBackground(const gfx::Size& size, |
| 431 cairo_t* cr, |
| 432 GtkStyleContext* context) { |
425 if (!context) | 433 if (!context) |
426 return; | 434 return; |
427 RenderBackground(cr, gtk_style_context_get_parent(context)); | 435 RenderBackground(size, cr, gtk_style_context_get_parent(context)); |
428 gtk_render_background(context, cr, 0, 0, 1, 1); | 436 gtk_render_background(context, cr, 0, 0, size.width(), size.height()); |
429 } | 437 } |
430 | 438 |
431 SkColor GetBgColor(const char* css_selector) { | 439 SkColor GetBgColor(const char* css_selector) { |
432 // Backgrounds are more general than solid colors (eg. gradients), | 440 // Backgrounds are more general than solid colors (eg. gradients), |
433 // but chromium requires us to boil this down to one color. We | 441 // but chromium requires us to boil this down to one color. We |
434 // cannot use the background-color here because some themes leave it | 442 // cannot use the background-color here because some themes leave it |
435 // set to a garbage color because a background-image will cover it | 443 // set to a garbage color because a background-image will cover it |
436 // anyway. So we instead render the background into a single pixel, | 444 // anyway. So we instead render the background into a single pixel, |
437 // removing any borders, and hope that we get a good color. | 445 // removing any borders, and hope that we get a good color. |
438 auto context = GetStyleContextFromCss(css_selector); | 446 auto context = GetStyleContextFromCss(css_selector); |
439 RemoveBorders(context); | 447 RemoveBorders(context); |
440 PixelSurface surface; | 448 PixelSurface surface; |
441 RenderBackground(surface.cairo(), context); | 449 RenderBackground(gfx::Size(1, 1), surface.cairo(), context); |
442 return surface.GetPixelValue(); | 450 return surface.GetPixelValue(); |
443 } | 451 } |
444 | 452 |
445 SkColor GetBorderColor(const char* css_selector) { | 453 SkColor GetBorderColor(const char* css_selector) { |
446 // Borders have the same issue as backgrounds, due to the | 454 // Borders have the same issue as backgrounds, due to the |
447 // border-image property. | 455 // border-image property. |
448 auto context = GetStyleContextFromCss(css_selector); | 456 auto context = GetStyleContextFromCss(css_selector); |
449 GtkStateFlags state = gtk_style_context_get_state(context); | 457 GtkStateFlags state = gtk_style_context_get_state(context); |
450 GtkBorderStyle border_style = GTK_BORDER_STYLE_NONE; | 458 GtkBorderStyle border_style = GTK_BORDER_STYLE_NONE; |
451 gtk_style_context_get(context, state, GTK_STYLE_PROPERTY_BORDER_STYLE, | 459 gtk_style_context_get(context, state, GTK_STYLE_PROPERTY_BORDER_STYLE, |
452 &border_style, nullptr); | 460 &border_style, nullptr); |
453 GtkBorder border; | 461 GtkBorder border; |
454 gtk_style_context_get_border(context, state, &border); | 462 gtk_style_context_get_border(context, state, &border); |
455 if ((border_style == GTK_BORDER_STYLE_NONE || | 463 if ((border_style == GTK_BORDER_STYLE_NONE || |
456 border_style == GTK_BORDER_STYLE_HIDDEN) || | 464 border_style == GTK_BORDER_STYLE_HIDDEN) || |
457 (!border.left && !border.right && !border.top && !border.bottom)) { | 465 (!border.left && !border.right && !border.top && !border.bottom)) { |
458 return SK_ColorTRANSPARENT; | 466 return SK_ColorTRANSPARENT; |
459 } | 467 } |
460 | 468 |
461 AddBorders(context); | 469 AddBorders(context); |
462 PixelSurface surface; | 470 PixelSurface surface; |
463 RenderBackground(surface.cairo(), context); | 471 RenderBackground(gfx::Size(1, 1), surface.cairo(), context); |
464 gtk_render_frame(context, surface.cairo(), 0, 0, 1, 1); | 472 gtk_render_frame(context, surface.cairo(), 0, 0, 1, 1); |
465 return surface.GetPixelValue(); | 473 return surface.GetPixelValue(); |
466 } | 474 } |
467 #endif | 475 #endif |
468 | 476 |
469 } // namespace libgtkui | 477 } // namespace libgtkui |
OLD | NEW |